Downloads · 30 days
97
12% of all-time downloads
andreagemelli/LFM2.5-350M-IT-Extract
LFM2.5-350M-IT-Extract is a text generation model from andreagemelli. Use it when you need the model to write or continue text. It is set up for transformers.
- 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, see xfund-kie/README.m…
Downloads · 30 days
97
12% of all-time downloads
All-time downloads
826
Public
Parameters
354M
5 GB on disk
Likes
1
Public
Click a slice to open those files.
.pt2.8 GB · 57%
From the Hugging Face model README
xfund-kie (derived from XFUND Italian split, see xfund-kie/README.md)it)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 |
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.
"""
@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}}
}