Views
No views yet
meta-llama/Llama-2-7b-hf for Amharic-to-English translation,
after extending its tokenizer with Ge'ez-script tokens (vocab 32,000 → 61,819)
so Amharic text isn't shredded into near-meaningless byte fragments by
Llama-2's original Latin-script-oriented vocabulary. New embedding rows for
embed_tokens/lm_head are trained in full (not frozen, unlike the rest of
the LoRA-adapted weights) since they start from a rough mean+random
initialization.Translate the following Amharic text to English.
Amharic: {source}
English: {target}seed_<N>/ subfolder (LoRA adapter only — base model must be
loaded separately and its embeddings resized to 61,819 tokens before applying
the adapter; see finetune_model.py/evaluate.py in the code repo).| Seed | Best eval_loss (training) | BLEU | chrF | COMET (Unbabel/wmt22-comet-da) |
|---|---|---|---|---|
| 10 | 1.531 | 7.66 | 23.34 | 0.6318 |
| 11 | 1.530 | 7.81 | 23.73 | 0.6353 |
| 12 | 1.514 | 7.82 | 23.36 | 0.6330 |
| 13 | 1.523 | 7.85 | 23.55 | 0.6335 |
| 14 | 1.528 | 8.12 | 23.91 | 0.6339 |
seed_<N>/eval_report.json.meta-llama/Llama-2-7b-hf
requires accepting Meta's license before you can download it. Visit
meta-llama/Llama-2-7b-hf
while logged in to Hugging Face and request/accept access (usually granted
instantly), then authenticate wherever you run the code below:1from huggingface_hub import notebook_login # in a notebook/Colab
2notebook_login()
3# or, in a plain script/terminal:
4# huggingface-cli login
5# or pass a token directly to each from_pretrained() call below: token="hf_..."HTTPStatusError (401/403) partway through from_pretrained.1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3from peft import PeftModel
4
5SEED_DIR = "Hailay/llama2-amharic-english-mt" # + subfolder="seed_12"
6BASE = "meta-llama/Llama-2-7b-hf"
7
8tokenizer = AutoTokenizer.from_pretrained(SEED_DIR, subfolder="seed_12")
9model = AutoModelForCausalLM.from_pretrained(BASE, torch_dtype=torch.bfloat16)
10model.resize_token_embeddings(len(tokenizer), mean_resizing=False)
11model = PeftModel.from_pretrained(model, SEED_DIR, subfolder="seed_12")
12
13prompt = "Translate the following Amharic text to English.\nAmharic: ሰላም ከመይ ኣለኻ?\nEnglish:"
14inputs = tokenizer(prompt, return_tensors="pt")
15out = model.generate(**inputs, max_new_tokens=64)
16print(tokenizer.decode(out[0][inputs['input_ids'].shape[1]:], skip_special_tokens=True))EXLMR/vocab.json); not independently verified against a linguistic
reference beyond the Ethiopic-script filter described in the code repo.pip install transformers peft torchseed_10/adapter_config.json.| Parameter | Value |
|---|---|
| PEFT type | LoRA |
| Task type | CAUSAL_LM |
Rank (r) | 16 |
lora_alpha | 32 |
lora_dropout | 0.05 |
bias | none |
| Target modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
| Modules saved | embed_tokens, lm_head |
| Base model | meta-llama/Llama-2-7b-hf |