1from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
2
3model_id = "dsfsi/m2m100_1.2b-eng-hau"
4model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
5tokenizer = AutoTokenizer.from_pretrained(model_id)
6
7# Set source language
8tokenizer.src_lang = "en"
9
10# Translate
11text = "The mitochondria is the powerhouse of the cell."
12inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=256)
13
14# Generate with target language
15forced_bos_token_id = tokenizer.get_lang_id("ha")
16outputs = model.generate(**inputs, forced_bos_token_id=forced_bos_token_id, max_length=256, num_beams=5)
17translation = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
18print(translation)
1texts = [
2 "Climate change affects agricultural productivity.",
3 "The study analyzed genetic markers in the population.",
4 "Renewable energy sources are essential for sustainable development."
5]
6
7inputs = tokenizer(texts, return_tensors="pt", padding=True, truncation=True, max_length=256)
8outputs = model.generate(**inputs, forced_bos_token_id=forced_bos_token_id, max_length=256, num_beams=5)
9translations = tokenizer.batch_decode(outputs, skip_special_tokens=True)
10for src, tgt in zip(texts, translations):
11 print(f"{src}\n→ {tgt}\n")
1# Clone the AfriScience-MT repository
2git clone https://github.com/afriscience-mt/afriscience-mt.git
3cd afriscience-mt
4
5# Install dependencies
6pip install -r requirements.txt
7
8# Run training
9python -m afriscience_mt.scripts.run_seq2seq_training \
10 --data_dir ./data \
11 --source_lang eng \
12 --target_lang hau \
13 --model_name facebook/m2m100_1.2B \
14 --model_type m2m100 \
15 --output_dir ./output \
16 --num_epochs 10 \
17 --batch_size 16 \
18 --learning_rate 2e-5
If you use this model, please cite the AfriScience-MT paper (
arXiv:2605.29741):
1@article{abdulmumin2026afriscience,
2 title = {AfriScience-MT: Towards Decolonizing Science in Africa through Text Translation},
3 author = {Abdulmumin, Idris and Gwadabe, Tajuddeen and Muhammad, Shamsuddeen Hassan and Adelani, David Ifeoluwa and Khalo, Nomonde and Ahmad, Ibrahim Said and Modupe, Abiodun and Mumm, Anina and Biyela, Sibusiso and Rabie, Michelle and Havemann, Johanna and Rei, Marek and Abbott, Jade and Marivate, Vukosi},
4 journal = {arXiv preprint arXiv:2605.29741},
5 year = {2026},
6 url = {https://arxiv.org/abs/2605.29741}
7}
This model is released under the
Apache 2.0 License.