Views
No views yet
facebook/nllb-200-distilled-600M using the local Ghana NLP
Twi-English parallel text dataset included in the Sukuupath project.facebook/nllb-200-distilled-600Mtwi_Latneng_LatnTWI_ENGLISH_PARALLEL_TEXTtext as the Twi source column and label as the English
target/reference column.checkpoint-900| Metric | Value | Interpretation |
|---|---|---|
| BLEU | 27.18 | Decent/useful translation quality for a low-resource language pair. |
| chrF | 48.36 | Good character-level similarity; useful for spelling/morphology variation. |
| Eval loss | 1.5420 | Lower is better; improved from 1.9584 at step 100. |
1from peft import PeftConfig, PeftModel
2from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
3import torch
4
5model_id = "Lanor-and-Nick/twi-english-nllb-lora"
6source_lang = "twi_Latn"
7target_lang = "eng_Latn"
8
9def normalize_twi_keyboard_text(text: str) -> str:
10 return text.replace("C", "Ɔ").replace("c", "ɔ").replace("3", "ɛ")
11
12config = PeftConfig.from_pretrained(model_id)
13tokenizer = AutoTokenizer.from_pretrained(model_id, src_lang=source_lang, tgt_lang=target_lang)
14base_model = AutoModelForSeq2SeqLM.from_pretrained(config.base_model_name_or_path)
15model = PeftModel.from_pretrained(base_model, model_id)
16
17device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
18model.to(device)
19model.eval()
20
21text = normalize_twi_keyboard_text("3he na wowc? M'ani gye w'as3m ho")
22inputs = tokenizer(text, return_tensors="pt").to(device)
23forced_bos_token_id = tokenizer.convert_tokens_to_ids(target_lang)
24
25with torch.no_grad():
26 output = model.generate(
27 **inputs,
28 forced_bos_token_id=forced_bos_token_id,
29 max_new_tokens=192,
30 num_beams=5,
31 no_repeat_ngram_size=3,
32 )
33
34print(tokenizer.batch_decode(output, skip_special_tokens=True)[0])| Twi input | Model output |
|---|---|
me dc wo | i love you |
3he na wowc? | where are you? |
3he na wowc? M'ani gye w'as3m ho | where are you? I love your story |
Yei nti, ama nnipa pii ani agye ho pa ara. | For this reason, it has made it very popular among many people. |