Downloads · 30 days
20
33% of all-time downloads
albertdatzira/qwen3-8b-htr-vines-lora
qwen3-8b-htr-vines-lora is a text generation model from albertdatzira. Use it when you need the model to write or continue text. It is set up for peft. The card lists the license as mit.
Fine-tuned LoRA adapters for Handwritten Text Recognition (HTR) post-correction, trained on the manuscript diaries of Catalan pianist Ramon Viñes (1890–1915).
Downloads · 30 days
20
33% of all-time downloads
All-time downloads
60
Public
Repo size
186 MB
Likes
0
Public
Click a slice to open those files.
.safetensors175 MB · 94%
From the Hugging Face model README
Fine-tuned LoRA adapters for Handwritten Text Recognition (HTR) post-correction, trained on the manuscript diaries of Catalan pianist Ramon Viñes (1890–1915).
| Approach | CER | Pages worsened |
|---|---|---|
| HTR only (Balakirev) | 10.86% | — |
| Llama 3.1 70B (general, no fine-tuning) | 21.20% | all |
| This model + fallback | 7.80% | 0 |
The fine-tuned 8B model outperforms a general 70B model by 2.7× — demonstrating that domain-specific fine-tuning is essential for historical manuscript correction.
import torch
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
# Load base model + LoRA adapters
base_model = AutoModelForCausalLM.from_pretrained(
"Qwen/Qwen3-8B",
trust_remote_code=True,
device_map="auto",
torch_dtype=torch.bfloat16,
)
model = PeftModel.from_pretrained(base_model, "albertdatzira/qwen3-8b-htr-vines-lora")
tokenizer = AutoTokenizer.from_pretrained("albertdatzira/qwen3-8b-htr-vines-lora")
model.eval()
# Correct HTR text
system_prompt = (
"Ets un expert en post-correcció d'HTR dels diaris de Ramon Viñes. "
"Corregeix els errors de reconeixement del text manuscrit. "
"Només corregeix errors d'HTR evidents. No modifiquis l'ortografia "
"de l'autor, noms propis, ni símbols especials (¶, ¬, ⟦ ⟧)."
)
htr_text = "para el almuerzo (á mediddia). Me hristes son todos estos aniversarios"
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": f"Corregeix el següent text HTR:\n{htr_text}"},
]
text = tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True,
enable_thinking=False,
)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model.generate(
**inputs, max_new_tokens=4096, do_sample=False,
pad_token_id=tokenizer.pad_token_id,
)
generated = outputs[0][inputs["input_ids"].shape[-1]:]
corrected = tokenizer.decode(generated, skip_special_tokens=True)
print(corrected)
# -> "para el almuerzo (á mediodia). Qué tristes son todos estos aniversarios"
The model was trained on 583 page-level pairs from the RV-training repository:
For production use, always apply a fallback:
This guarantees zero pages are ever worsened.
@mastersthesis{perez2026finetuning,
title={Fine-tuning Large Language Models for HTR Post-correction:
A Case Study on the Ramon Viñes Manuscript Diaries},
author={Pérez Datsira, Albert},
school={Universitat de Lleida},
year={2026},
type={Master's Thesis}
}