Views
No views yet
Trainer framework, demonstrating stable convergence with both training and validation loss plateauing around epoch 8.1Starting training...
2 [1130/1130 27:40, Epoch 10/10]
3Epoch Training Loss Validation Loss
41 4.760233 3.660645
52 3.665481 3.144127
63 3.284355 2.871792
74 2.910443 2.698959
85 2.716799 2.608596
96 2.567515 2.554176
107 2.334619 2.507996
118 2.326849 2.465583
129 2.173708 2.468309
1310 2.190471 2.469198
14Writing model shards: 100%
15 1/1 [00:25<00:00, 25.28s/it]4.76 → 2.192.46–2.47, indicating effective learning without severe overfitting.11,300 (1,130 steps/epoch × 10 epochs)google/mt5-[base/small/large] (update to your exact variant)[Source Language] ↔ Ossetian)transformers + Trainer[e.g., 1× NVIDIA A100 40GB / Colab Pro / etc.][Link or name of your translation dataset]1import os
2import json
3import torch
4from pathlib import Path
5from huggingface_hub import snapshot_download
6from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, T5Tokenizer
7
8MODEL_ID = "ajsbsd/mt5-ossetian-translator"
9
10print("⬇️ Downloading model (with auth)...")
11local_path = snapshot_download(
12 repo_id=MODEL_ID,
13 resume_download=True,
14 ignore_patterns=["optimizer.pt", "*.pt"] # Skip training artifacts
15)
16
17print(f"📁 Model downloaded to: {local_path}")
18
19# 🔍 Find the SentencePiece model file
20spm_candidates = ["spiece.model", "sentencepiece.bpe.model", "tokenizer.model"]
21spm_file = None
22for candidate in spm_candidates:
23 path = os.path.join(local_path, candidate)
24 if os.path.exists(path):
25 spm_file = path
26 print(f"✅ Found SentencePiece model: {spm_file}")
27 break
28
29if not spm_file:
30 print("⚠️ No SentencePiece model found — falling back to base mT5 tokenizer")
31 tokenizer = AutoTokenizer.from_pretrained("google/mt5-small", use_fast=False)
32else:
33 # ✅ Load tokenizer with EXPLICIT string path (critical!)
34 print("🔧 Loading tokenizer with explicit spm path...")
35 tokenizer = T5Tokenizer(
36 vocab_file=str(spm_file), # ← Must be string, not Path object
37 eos_token="</s>",
38 unk_token="<unk>",
39 pad_token="<pad>",
40 extra_ids=100, # mT5 uses 100 sentinel tokens
41 legacy=True
42 )
43
44# Patch config to avoid future issues
45config_file = os.path.join(local_path, "tokenizer_config.json")
46if os.path.exists(config_file):
47 with open(config_file, "r", encoding="utf-8") as f:
48 config = json.load(f)
49 # Fix known issues
50 if "extra_special_tokens" in config and isinstance(config["extra_special_tokens"], list):
51 config["extra_special_tokens"] = {}
52 if "vocab_file" in config and config["vocab_file"] is None:
53 config["vocab_file"] = str(spm_file) if spm_file else "spiece.model"
54 if "spm_model_file" in config and config["spm_model_file"] is None:
55 config["spm_model_file"] = str(spm_file) if spm_file else "spiece.model"
56 with open(config_file, "w", encoding="utf-8") as f:
57 json.dump(config, f, indent=2, ensure_ascii=False)
58 print("🔧 Patched tokenizer_config.json")
59
60# Load model
61print("📦 Loading model weights...")
62model = AutoModelForSeq2SeqLM.from_pretrained(local_path)
63if torch.cuda.is_available():
64 model = model.to("cuda")
65 print("✅ Model moved to CUDA")
66
67# 🧪 Run translation test
68prompt = "translate english to ossetian: Hello, how are you?"
69print(f"\n🔄 Translating: '{prompt}'")
70
71inputs = tokenizer(prompt, return_tensors="pt")
72if torch.cuda.is_available():
73 inputs = inputs.to("cuda")
74
75outputs = model.generate(
76 **inputs,
77 max_new_tokens=128,
78 num_beams=4,
79 early_stopping=True,
80 no_repeat_ngram_size=2
81)
82
83result = tokenizer.decode(outputs[0], skip_special_tokens=True)
84print(f"✅ Output: {result}")
851from transformers import pipeline
2
3translator = pipeline("translation", model="ajsbsd/mt5-ossetian-translator", tokenizer=model_id)
4result = translator("translate [source_lang] to ossetian: Your text here.")
5print(result[0]["translation_text"])1@misc{mt5_ossetian_translator,
2 title={mt5-ossetian-translator},
3 author={ajsbsd},
4 year={2026},
5 url={https://huggingface.co/ajsbsd/mt5-ossetian-translator}
6}