Views
No views yet
ruk_Cyrl, was added to the tokenizer to represent it. This repo contains
only the LoRA adapter weights — you need the base NLLB model plus this
adapter's tokenizer (which includes the added ruk_Cyrl token) to use it.midwestcyr/nllb-200-distilled-600m-rus-ruskaromani.q_proj, k_proj, v_proj, out_proj,
fc1, fc2)ruk_Cyrl (Ruska Romani, Cyrillic script) — added
to the tokenizer vocabulary and warm-started from the embedding of
rom_Latn (Vlax Romani, the closest existing NLLB language) rather than
a random vectorrus_Cyrl ↔ ruk_Cyrl
extracted from a JSON corpus, split 95% train / 5% validationSeq2SeqTrainer with LoRA adapters on parallel Russian ↔ Ruska Romani sentence pairs.| Parameter | Value |
|---|---|
| Epochs | 8 |
| Per-device train batch size | 4 |
| Per-device evaluation batch size | 4 |
| Gradient accumulation steps | 2 |
| Effective training batch size | 8 |
| Learning rate | 3e-4 |
| Mixed precision | FP16 |
| Evaluation strategy | Every epoch |
| Checkpoint saving | Every epoch |
| Logging frequency | Every 50 steps |
| Generation during evaluation | Enabled |
| Maximum generation length | MAX_LEN |
| Best model selection | Highest validation SacreBLEU |
| Trainer | Hugging Face Seq2SeqTrainer |
| Metric | Value |
|---|---|
| Total epochs completed | 8 |
| Total optimization steps | 7,432 |
| Best validation SacreBLEU | 22.93 |
| Best model epoch | 8 |
load_best_model_at_end=True) using the validation SacreBLEU score as the model selection criterion.1from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
2from peft import PeftModel
3import torch
4
5BASE_MODEL = "facebook/nllb-200-distilled-600M"
6ADAPTER_REPO = "midwestcyr/nllb-200-distilled-600m-rus-ruskaromani-lora"
7
8# load base model
9base_model = AutoModelForSeq2SeqLM.from_pretrained(BASE_MODEL)
10
11# load tokenizer from the ADAPTER repo, not the base model —
12# it includes the new ruk_Cyrl token and resized vocab
13tokenizer = AutoTokenizer.from_pretrained(ADAPTER_REPO)
14
15# resize the base model's embeddings to match the tokenizer
16# BEFORE loading the adapter
17base_model.resize_token_embeddings(len(tokenizer))
18
19# load the LoRA adapter on top
20model = PeftModel.from_pretrained(base_model, ADAPTER_REPO)
21
22device = torch.device("cuda" if torch.cuda.is_available() else
23 "mps" if torch.backends.mps.is_available() else "cpu")
24model = model.to(device)
25model.eval()
26
27def translate(text, src_lang, tgt_lang, max_length=128, num_beams=5):
28 new_lang_id = tokenizer.convert_tokens_to_ids(tgt_lang)
29 tokenizer.src_lang = src_lang
30 inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=max_length).to(device)
31 generated = model.generate(
32 **inputs,
33 forced_bos_token_id=new_lang_id,
34 max_length=max_length,
35 num_beams=num_beams,
36 )
37 return tokenizer.batch_decode(generated, skip_special_tokens=True)[0]
38
39# Russian -> Ruska Romani
40src_lang = "rus_Cyrl"
41tgt_lang = "ruk_Cyrl"
42print(translate("Владимир разорвал их, не читая.", src_lang, tgt_lang))
43### Output: Владимиро розрискирдя лэн на гины.
44
45# Ruska Romani -> Russian
46src_lang = "ruk_Cyrl"
47tgt_lang = "rus_Cyrl"
48print(translate("Владимиро розрискирдя лэн на гины.", src_lang, tgt_lang))
49### Output: Владимир разорвал их, не читая.1merged = model.merge_and_unload()
2merged.save_pretrained("nllb-ru-ruskaromani-merged")
3tokenizer.save_pretrained("nllb-ru-ruskaromani-merged")ruk_Cyrl is not a standard NLLB/FLORES code.
If you use this adapter with a different base checkpoint or tokenizer,
you must add the same token yourself before loading the adapter.1@inproceedings{koncha-etal-2024-parallel,
2 title = "The Parallel Corpus of {R}ussian and Ruska {R}omani Languages",
3 author = "Koncha, Kirill and
4 Kukanova, Abina and
5 Tatiana, Kazakova and
6 Rozovskaya, Gloria",
7 editor = "Serikov, Oleg and
8 Voloshina, Ekaterina and
9 Postnikova, Anna and
10 Muradoglu, Saliha and
11 Le Ferrand, Eric and
12 Klyachko, Elena and
13 Vylomova, Ekaterina and
14 Shavrina, Tatiana and
15 Tyers, Francis",
16 booktitle = "Proceedings of the Third Workshop on NLP Applications to Field Linguistics",
17 month = aug,
18 year = "2024",
19 address = "Bangkok, Thailand",
20 publisher = "Association for Computational Linguistics",
21 url = "https://aclanthology.org/2024.fieldmatters-1.1/",
22 doi = "10.18653/v1/2024.fieldmatters-1.1",
23 pages = "1--5"
24}1@inproceedings{koishekenov-etal-2023-memory,
2 title = "Memory-efficient {NLLB}-200: Language-specific Expert Pruning of a Massively Multilingual Machine Translation Model",
3 author = "Koishekenov, Yeskendir and
4 Berard, Alexandre and
5 Nikoulina, Vassilina",
6 editor = "Rogers, Anna and
7 Boyd-Graber, Jordan and
8 Okazaki, Naoaki",
9 booktitle = "Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)",
10 month = jul,
11 year = "2023",
12 address = "Toronto, Canada",
13 publisher = "Association for Computational Linguistics",
14 url = "https://aclanthology.org/2023.acl-long.198/",
15 doi = "10.18653/v1/2023.acl-long.198",
16 pages = "3567--3585",
17 abstract = "The recently released NLLB-200 is a set of multilingual Neural Machine Translation models that cover 202 languages. The largest model is based on a Mixture of Experts architecture and achieves SoTA results across many language pairs. It contains 54.5B parameters and requires at least four 32GB GPUs just for inference. In this work, we propose a pruning method that enables the removal of up to 80{\%} of experts without further finetuning and with a negligible loss in translation quality, which makes it feasible to run the model on a single 32GB GPU. Further analysis suggests that our pruning metrics can identify language-specific experts."
18}