This repository contains LoRA adapters for a modified mT5-base model fine-tuned on Hungarian date conversion tasks. The adapters can convert written dates to numeric format and vice versa.
1LoraConfig(
2 r=16,
3 lora_alpha=32,
4 lora_dropout=0.05,
5 target_modules=["q", "v", "k", "o"],
6 task_type="SEQ_2_SEQ_LM"
7)
1from peft import PeftModel
2from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
3import torch
4
5# Load base model and adapter
6model_id = "GaborMadarasz/hut5-base"
7adapter_path = "SilentSynapse/hut5-date-converter"
8
9base_model = AutoModelForSeq2SeqLM.from_pretrained(
10 model_id,
11 torch_dtype=torch.float16
12)
13model = PeftModel.from_pretrained(base_model, adapter_path)
14model = model.merge_and_unload().to("cuda").eval()
15
16tokenizer = AutoTokenizer.from_pretrained(model_id)
17
18# Inference function
19def convert_date(text, mode="word2date"):
20 """
21 mode: "word2date" or "date2word"
22 """
23 prompt = f"{mode}: {text}"
24 inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
25
26 with torch.no_grad():
27 outputs = model.generate(
28 **inputs,
29 max_length=64,
30 num_beams=4,
31 early_stopping=True
32 )
33
34 return tokenizer.decode(outputs[0], skip_special_tokens=True)
35
36# Examples
37print(convert_date("ezerkilencszáztizenegy május tizenöt", "word2date"))
38# Output: 1911. május 15.
39
40print(convert_date("1978. október 5", "date2word"))
41# Output: ezerkilencszázhetvennyolc október öt
1def convert_batch(texts, modes):
2 prompts = [f"{m}: {t}" for m, t in zip(modes, texts)]
3 inputs = tokenizer(prompts, return_tensors="pt", padding=True).to("cuda")
4
5 with torch.no_grad():
6 outputs = model.generate(**inputs, max_length=64, num_beams=4)
7
8 return tokenizer.batch_decode(outputs, skip_special_tokens=True)
9
10texts = ["ezerkilencszáztizenegy május tizenöt", "1978. október 5."]
11modes = ["word2date", "date2word"]
12results = convert_batch(texts, modes)
1# Remove .to("cuda") and use float32
2base_model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
3model = PeftModel.from_pretrained(base_model, adapter_path)
4model = model.merge_and_unload().eval()
-
Output Length: The model is optimized for 64-token outputs. Longer texts may be truncated.
-
date2word Performance: Written date conversion has lower accuracy (65% EM) due to complex Hungarian number words.
-
Date Formats: Follows Hungarian conventions only (e.g., "1991. május 15."). Other formats (ISO 8601, US style) are not supported.
-
Context Preservation: The model converts dates while preserving surrounding text. Very long passages may lose information due to the token limit.
-
Language: Hungarian only. Not suitable for other languages.
-
Edge Cases:
- Roman numerals (e.g., "XIX. század") are not converted
- Date ranges (1978–1991) may have inconsistent conversion