Downloads · 30 days
9
7% of all-time downloads
abdirisak874/finetune-donut-cord-v3
finetune-donut-cord-v3 is a image-to-text model from abdirisak874. Use it when you need a caption or text from an image. It is set up for transformers. The card lists the license as openrail.
This model is a fine-tuned version of naver-clova-ix/donut-base on the CORD v2 (Consolidated Receipt Dataset) for OCR-free receipt understanding and structured information extraction.
Downloads · 30 days
9
7% of all-time downloads
All-time downloads
131
Public
Repo size
1.6 GB
Likes
0
Public
Click a slice to open those files.
.bin809 MB · 99%
From the Hugging Face model README
This model is a fine-tuned version of naver-clova-ix/donut-base on the CORD v2 (Consolidated Receipt Dataset) for OCR-free receipt understanding and structured information extraction.
Donut (Document Understanding Transformer) is an end-to-end vision-language model that processes document images directly to extract structured information without requiring an intermediate OCR step. This approach eliminates error propagation from OCR mistakes and provides a more streamlined solution for document understanding tasks.
Accuracy is calculated using the JSONParseEvaluator from the Donut framework, which performs field-level comparison of extracted information:
Accuracy = (Number of Correctly Extracted Fields) / (Total Number of Fields)
The evaluator compares predicted and ground truth JSON objects by matching key-value pairs across multiple fields including:
Note: The 90.73% accuracy means that on average, approximately 9 out of every 10 information fields are correctly extracted from unseen receipts.
| Parameter | Value |
|---|---|
| Optimizer | AdamW |
| Learning Rate | 3×10⁻⁵ |
| Weight Decay | 0.01 |
| Batch Size | 1 |
| Gradient Clipping | 1.0 |
| Warmup Steps | 300 |
| Max Epochs | 100 |
| Early Stopping Patience | 3 epochs |
| Precision | BF16 (mixed precision) |
pip install transformers torch pillow
import re
import json
import torch
from PIL import Image
from transformers import DonutProcessor, VisionEncoderDecoderModel
# Load model and processor
processor = DonutProcessor.from_pretrained("abdirisak874/finetune-donut-cord-v3")
model = VisionEncoderDecoderModel.from_pretrained("abdirisak874/finetune-donut-cord-v3")
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)
# Load and preprocess image
image = Image.open("path/to/receipt.jpg").convert("RGB")
pixel_values = processor(image, return_tensors="pt").pixel_values
pixel_values = pixel_values.to(device)
# Prepare decoder input
task_prompt = "<s_cord-v2>"
decoder_input_ids = processor.tokenizer(task_prompt, add_special_tokens=False, return_tensors="pt").input_ids
decoder_input_ids = decoder_input_ids.to(device)
# Generate prediction
outputs = model.generate(
pixel_values,
decoder_input_ids=decoder_input_ids,
max_length=model.decoder.config.max_position_embeddings,
early_stopping=True,
pad_token_id=processor.tokenizer.pad_token_id,
eos_token_id=processor.tokenizer.eos_token_id,
use_cache=True,
num_beams=1,
bad_words_ids=[[processor.tokenizer.unk_token_id]],
return_dict_in_generate=True,
)
# Decode output
sequence = processor.batch_decode(outputs.sequences)[0]
sequence = sequence.replace(processor.tokenizer.eos_token, "").replace(processor.tokenizer.pad_token, "")
sequence = re.sub(r"<.*?>", "", sequence, count=1).strip() # remove first task start token
result = processor.token2json(sequence)
print(json.dumps(result, indent=2))
{
"menu": [
{
"nm": "ITEM NAME",
"cnt": "1",
"price": "10.00"
}
],
"sub_total": {
"subtotal_price": "10.00"
},
"total": {
"total_price": "11.00",
"tax_price": "1.00"
}
}
| Error Type | Frequency | Impact |
|---|---|---|
| Character Substitution | 32% | Low |
| Price Formatting | 18% | Medium |
| Item Name Truncation | 25% | High |
| Token Hallucination | 15% | Medium |
| Missing Items | 10% | High |
✅ Good for:
⚠️ Use with caution:
This model was trained using full fine-tuning (updating all 201M parameters) rather than parameter-efficient methods like LoRA. The comparison:
| Approach | Parameters Updated | Accuracy | Training Time |
|---|---|---|---|
| LoRA (rank-8) | 4.2M (2.1%) | ~13% | 18 min/epoch |
| Full Fine-tuning | 201M (100%) | 90.73% | 45 min/epoch |
Full fine-tuning proved essential for document understanding tasks requiring complex visual-linguistic alignment, despite higher computational costs.
This model was developed as part of research on OCR-free document understanding. For detailed methodology, training procedures, and analysis, please refer to the accompanying research paper.
Potential areas for enhancement:
For questions, issues, or suggestions for improvement, please open an issue on the model repository or contact the model author.
This model is released under the OpenRAIL license, inheriting from the base Donut model license.