Instructions to use AletheiaAING/gemma-3-270m-african-diacritizer with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use AletheiaAING/gemma-3-270m-african-diacritizer with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="AletheiaAING/gemma-3-270m-african-diacritizer")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("AletheiaAING/gemma-3-270m-african-diacritizer") model = AutoModelForCausalLM.from_pretrained("AletheiaAING/gemma-3-270m-african-diacritizer", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use AletheiaAING/gemma-3-270m-african-diacritizer with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "AletheiaAING/gemma-3-270m-african-diacritizer" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "AletheiaAING/gemma-3-270m-african-diacritizer", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/AletheiaAING/gemma-3-270m-african-diacritizer
- SGLang
How to use AletheiaAING/gemma-3-270m-african-diacritizer with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "AletheiaAING/gemma-3-270m-african-diacritizer" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "AletheiaAING/gemma-3-270m-african-diacritizer", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "AletheiaAING/gemma-3-270m-african-diacritizer" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "AletheiaAING/gemma-3-270m-african-diacritizer", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use AletheiaAING/gemma-3-270m-african-diacritizer with Docker Model Runner:
docker model run hf.co/AletheiaAING/gemma-3-270m-african-diacritizer
gemma-3-270m African diacritizer
Restores diacritics to undiacritised text in 39 African languages. A fine-tune of
google/gemma-3-270m on 135,116 examples.
Final checkpoint, optimizer step 12000 of 12,414, 3 epochs.
Prompt format
Training used exactly this template, with no chat wrapper — it is a base model, not an instruction-tuned one:
Diacritize this text: {undiacritized} <tgt> {diacritized}<eos>
Everything up to and including <tgt> is the prompt; loss was computed on the
completion only.
Usage
from transformers import AutoTokenizer, AutoModelForCausalLM
rid = "AletheiaAING/gemma-3-270m-african-diacritizer"
tok = AutoTokenizer.from_pretrained(rid)
model = AutoModelForCausalLM.from_pretrained(rid).eval()
text = "Nneema dodoo a se odiyifoo no kasa wo Awurade din mu"
p = tok(f"Diacritize this text: {text} <tgt> ", return_tensors="pt",
add_special_tokens=False)
out = model.generate(**p, max_new_tokens=256, do_sample=False)
print(tok.decode(out[0][p["input_ids"].shape[1]:], skip_special_tokens=True))
A note on stopping
google/gemma-3-270m ships generation_config.eos_token_id = None. generate()
reads generation_config, not config, so with the stock setting it never stops: it
runs the full max_new_tokens budget and pads the overflow by repeating the passage.
The model itself is not at fault — it puts probability 1.0 on <eos> at the correct
position. This repo sets eos_token_id explicitly, so the snippet above stops
correctly. If you load the weights some other way, pass eos_token_id=tok.eos_token_id
to generate().
Evaluation
Held-out rows, free generation (greedy), measured on the step-12000 checkpoint.
Latest in-distribution eval: EVAL {'step': 12000, 'val_loss': 0.09718, 'exact_strip': 0.0, 'exact_identity': 0.0, 'char_acc': 0.9066}
Read these as follows. Identity rows are Zulu, Xhosa and Swahili — languages that take no diacritics — and test the opposite failure from the rest: adding marks where none belong. Exact match is whole-passage, and passages average 145 characters, so it is a demanding measure. Restored-site accuracy counts only the positions that were actually stripped, which is what the task is about; a copy-the-input baseline scores 0% there by construction, against 82.5% character accuracy overall.
Character- and word-level figures use positional alignment, so a single inserted or deleted character shifts the rest and is counted wrong. They are floors, not estimates.
External benchmark: masakhane/AfriADR
The figures above are in-distribution — our own held-out split, same generator as the training data. On an independent benchmark the model is much weaker, and on three of five languages it is no better than doing nothing. Both numbers belong here.
masakhane/AfriADR is the purpose-built African diacritic-restoration benchmark (apache-2.0, MAFAND news). Its train split is in v2's training data; this model saw none of it, and its test split overlaps our training targets by at most 0.5% (in Igbo), so this is a clean measure. 400 test sentences per language, greedy decoding.
| language | exact | copy baseline | word acc | copy word acc | beats copying? | rows in training |
|---|---|---|---|---|---|---|
Igbo (ibo) |
0.3525 | 0.0925 | 0.9081 | 0.6685 | yes | 4,710 |
Yorùbá (yor) |
0.0325 | 0.0050 | 0.4992 | 0.1793 | yes | 14,579 |
Wolof (wol) |
0.0300 | 0.0275 | 0.7787 | 0.7870 | no | 895 |
Fon (fon) |
0.0000 | 0.0000 | 0.3485 | 0.3578 | no | 12,301 |
Ghomálá' (bbj) |
0.0000 | 0.0000 | 0.2894 | 0.3515 | no | no |
Mean exact match 0.0830, against 0.3670 in-distribution.
The pattern is not noise
Igbo and Yorùbá are exactly the two languages where the two stripping definitions coincide — their diacritics are combining marks, so removing marks and folding to ASCII give the same string — and they are the only two that beat the copy baseline. Fon and Ghomálá' are where the definitions diverge completely: AfriADR's stripped side matches a marks-only strip 398/400 and an ASCII-fold 0/400, because those orthographies write ɔ ɛ ɖ ə ŋ as distinct letters of the alphabet, not as accented vowels.
This model was trained only on ASCII-folded inputs. On Fon it has therefore never seen an input containing ɔ ɛ ɖ — it was trained to produce them from o, e, d. AfriADR hands it text that already looks half-restored, which is out of distribution. Ghomálá' is absent from this model's training data entirely.
The fix is in the v2 dataset: marks-only rows for these languages, Ghomálá' added, Wolof raised from 895 to 7,394 rows.
Reading these numbers
exact and word acc are alignment-free and are the ones to trust. A positional
site_acc was also computed but is unreliable here: NFC composition makes a toned vowel
one or two codepoints, so the stripped and reference strings differ in length and
positional alignment fails — on Yorùbá only 4% of rows aligned, on Ghomálá' none.
Exact match is whole-passage. Sentences average 145 characters, so it is demanding by design: a diacritiser that gets one word wrong has produced a wrong sentence.
Training data
AletheiaAING/Data-Quality,
config diacritics_sft. 135,116 rows over 39 languages.
Each source document was stripped two ways: 40% fully (every diacritic removed) and 60% partially (10–60% of diacritic sites removed), so the model sees both a cold start and the common real case of partially-marked text.
Rows were filtered two ways before inclusion: documents carrying task tags such as
<translate> were dropped (they are parallel-corpus rows whose halves are different
languages, and a density filter selects them preferentially), and every snippet was
validated against its own language's lexicon. That rejected 31,900 task-formatted and
1,429 wrong-language candidates.
| language | rows | full-strip | partial-strip | diacritic density |
|---|---|---|---|---|
| aka | 3,233 | 1,294 | 1,939 | 0.0714 |
| bam | 4,303 | 1,722 | 2,581 | 0.0848 |
| bin | 7,970 | 3,188 | 4,782 | 0.0823 |
| din | 13 | 6 | 7 | 0.0201 |
| dyu | 1,209 | 484 | 725 | 0.0691 |
| efi | 3,592 | 1,437 | 2,155 | 0.0821 |
| ewe | 6,226 | 2,491 | 3,735 | 0.0935 |
| fat | 2,005 | 802 | 1,203 | 0.0527 |
| fon | 12,301 | 4,921 | 7,380 | 0.2766 |
| ful | 292 | 117 | 175 | 0.0406 |
| fuv | 754 | 302 | 452 | 0.0203 |
| gaa | 4,025 | 1,610 | 2,415 | 0.1550 |
| hau | 949 | 380 | 569 | 0.0071 |
| ibb | 128 | 52 | 76 | 0.0319 |
| ibo | 4,710 | 1,884 | 2,826 | 0.0887 |
| igl | 1,064 | 426 | 638 | 0.0196 |
| ijo | 69 | 28 | 41 | 0.1911 |
| kab | 2,251 | 901 | 1,350 | 0.0511 |
| kam | 3,532 | 1,413 | 2,119 | 0.1216 |
| kbp | 11,482 | 4,593 | 6,889 | 0.1955 |
| kik | 1,533 | 614 | 919 | 0.1088 |
| kmb | 19 | 8 | 11 | 0.0161 |
| mos | 3,712 | 1,485 | 2,227 | 0.0823 |
| nso | 70 | 28 | 42 | 0.0178 |
| nus | 7,274 | 2,910 | 4,364 | 0.1777 |
| oke | 3,952 | 1,581 | 2,371 | 0.0841 |
| pcm | 132 | 53 | 79 | 0.0471 |
| sag | 267 | 107 | 160 | 0.0249 |
| shi | 791 | 317 | 474 | 0.0309 |
| swh | 4,000 | 0 | 0 | 0.0001 |
| tiv | 37 | 15 | 22 | 0.0168 |
| tum | 757 | 303 | 454 | 0.0152 |
| twi | 9,316 | 3,727 | 5,589 | 0.0752 |
| urh | 7,940 | 3,176 | 4,764 | 0.0983 |
| wol | 895 | 358 | 537 | 0.0388 |
| xho | 4,000 | 0 | 0 | 0.0002 |
| xsm | 1,734 | 694 | 1,040 | 0.0874 |
| yor | 14,579 | 5,832 | 8,747 | 0.2731 |
| zul | 4,000 | 0 | 0 | 0.0000 |
Training
| base | google/gemma-3-270m |
| epochs | 3 |
| effective batch | 32 (batch 2 x accum 16) |
| lr | 2e-5, cosine, 3% warmup |
| max length | 512 |
| precision | fp32 weights, bf16 autocast |
| loss | completion only (prompt masked to -100) |
| hardware | 1x RTX 5070 |
Limits
- Languages with few source rows (Dinka, 13 rows) are present but not meaningfully trained.
- Hausa was included at a lowered site threshold; its diacritic density is low enough that fewer rows carry usable signal.
- The model restores diacritics; it does not correct spelling, and it will not fix text that was wrong before the diacritics were removed.
Generated with Claude Code.
- Downloads last month
- 26
Model tree for AletheiaAING/gemma-3-270m-african-diacritizer
Base model
google/gemma-3-270m