LFM2.5-350M-IT-Extract: a fine-tuned version of liquid ai model for document key information extraction
Model details
- Base model: LiquidAI/LFM2.5-350M
- Task: Key Information Extraction (KIE) from Italian form/document images (structured JSON extraction)
- Dataset:
xfund-kie(derived from XFUND Italian split, seexfund-kie/README.md) - Language: Italian (
it) - Fine-tuning framework: TRL.TRL.
- Adapted original colab: https://colab.research.google.com/drive/1j5Hk_SyBb2soUsuhU0eIEA9GwLNRnElF?usp=sharing
Performance (on xfund-kie validation)
| Model | Avg F1 | JSON parse failures |
|---|---|---|
LiquidAI/LFM2-350M-Extract (reference) | 0.2532 | 6 / 50 |
LiquidAI/LFM2.5-350M (base) | 0.2138 | 0 / 50 |
andreagemelli/LFM2.5-350M-IT-Extract | 0.5311 | 10 / 50 |
| same, Q4_K_M GGUF | 0.5307 | 10 / 50 |
| same, Q4_K_M on the app's own OCR text | 0.4362 | 10 / 50 |
How to use for inference
from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
import torch, json
from datasets import load_dataset
model_id = "andreagemelli/LFM2.5-350M-IT-Extract"
device = "cuda" if torch.cuda.is_available() else "cpu"
model = AutoModelForCausalLM.from_pretrained(model_id, dtype=torch.bfloat16).to(device)
tokenizer = AutoTokenizer.from_pretrained(model_id)
# Load dataset from Hugging Face Hub (no local repo needed)
dataset = load_dataset("andreagemelli/xfund-kie-it", split="validation")
doc = dataset.filter(lambda x: x["source"] == "it_val_0")[0]
annotation = doc["annotation"] # from dataset messages or annotation field
schema_text = "".join([f"{k}: {v}.\n" for k, v in REF_SCHEMA.items() if k in annotation]) # cognome: surname of the person.\nnome: ...
user_text = doc["text"] if "text" in doc else doc["messages"][1]["content"]
messages = [
{"role": "system", "content": SYTEM_PROMPT_DEFAULT + schema_text},
{"role": "user", "content": user_text},
]
inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(device)
streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
output = model.generate(inputs, max_new_tokens=1024, do_sample=False, streamer=streamer)
Expected snippet output (ref: it_val_0 from xfund-kie/it.val.json):
{
"cognome": "VALLE",
"nome": "LUISA",
...
}
Defaults I used in my experiments:
REF_SCHEMA = json.load('/path/to/schema/json') # https://huggingface.co/datasets/andreagemelli/xfund-kie-it/blob/main/schema.json
SYTEM_PROMPT_DEFAULT = f"""Identify and extract information matching the following schema.
Return data as a JSON object. Missing data should be omitted.
"""
Cite this project
@misc{gemelli2026LFM2.5-350M-IT-Extract
title = {LFM2.5-350M-IT-Extract: A tiny model for italian document key information extraction},
author = {Gemelli, Andrea},
year = {2026},
howpublished = {\url{https://huggingface.co/andreagemelli/LFM2.5-350M-IT-Extract}}
}