Llama 3.1 8B – Invoice & Purchase Order Extraction (GGUF)
A fine-tuned Llama 3.1 8B model for extracting structured information from invoice and purchase order (PO) text, published as merged full weights (safetensors) and a GGUF file for fast local inference with Ollama, llama.cpp and other GGUF-compatible tools.
Model Details
- Developed by: Muhammed Afsal P M
- Base model: meta-llama/Llama-3.1-8B-Instruct
- Method: Supervised Fine-Tuning (SFT) with LoRA, merged into full weights
- Formats: GGUF (
afsal_llm.gguf) and BF16 safetensors - Context length: 131,072 tokens
- Parameters: 8B
- Language: English
- License: Llama 3.1 Community License
- LoRA adapter version: llama-3.1-8b-invoice-lora
Intended Use
Direct use
- Extracting key fields from invoices and purchase orders, such as invoice number, dates, vendor and buyer details, line items, tax and totals
- Local, private document processing without sending data to external APIs
Downstream use
- Accounts payable and accounting automation
- OCR-to-LLM extraction pipelines and RPA workflows
- Extraction component inside document intelligence or agentic AI systems
Out of scope
- Financial or legal decisions without human review
- Non-English documents (not evaluated)
- Direct image input; scanned documents need OCR first
How to Use
Ollama
Download afsal_llm.gguf, then create a file named Modelfile:
FROM ./afsal_llm.gguf
PARAMETER temperature 0
SYSTEM "Extract the key invoice fields and return them as JSON."
Then run:
ollama create invoice-extractor -f Modelfile
ollama run invoice-extractor "PASTE INVOICE OR PURCHASE ORDER TEXT HERE"
llama.cpp
llama-cli -m afsal_llm.gguf --temp 0 -p "Extract the key invoice fields as JSON from: PASTE INVOICE TEXT HERE"
Transformers (safetensors)
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "muhammed-afsal-p-m/Llama-base-3.1-8B-invoice-gguf-sft"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", torch_dtype="auto")
messages = [
{"role": "system", "content": "Extract the key invoice fields and return them as JSON."},
{"role": "user", "content": "PASTE INVOICE OR PURCHASE ORDER TEXT HERE"},
]
inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
outputs = model.generate(inputs, max_new_tokens=512, do_sample=False)
print(tokenizer.decode(outputs[0][inputs.shape[-1]:], skip_special_tokens=True))
Training Details
- Method: LoRA fine-tuning with SFT (TRL), merged into the base model and converted to GGUF
- LoRA configuration: rank 128, alpha 64, dropout 0.05, target modules q_proj, k_proj, v_proj, o_proj
- Frameworks: PEFT, TRL, Transformers 4.57.3, llama.cpp (GGUF conversion)
Bias, Risks and Limitations
- Accuracy depends on the quality of the input text; poor OCR output reduces reliability.
- The model may hallucinate fields that are missing from the document.
- Unusual or unseen invoice layouts may reduce accuracy.
Recommendations: use deterministic decoding (temperature 0), validate outputs with rule-based checks, and keep a human in the loop for financial workflows.