Fill-Mask
Transformers
Safetensors
modernbert
african-languages
masked-language-modeling
long-context

AfriModernBERT-small

AfriModernBERT-small is a compact ModernBERT encoder pretrained from scratch on a ~3B-token dataset covering 16 African languages, with a native 4,096-token context window and a tokenizer built specifically for these languages.

Model details

Architecture ModernBERT (pre-norm, GeGLU, RoPE, alternating local/global attention)
Layers × hidden size 16 × 384
Attention heads 6 (head dim 64)
Feed-forward size 1,152
Attention global every 3rd layer, 128-token sliding window otherwise
RoPE θ 160,000 (global) / 10,000 (local)
Context length 4,096 tokens
Vocabulary 65,152 (BPE, trained on the pretraining mix)
Parameters 56M total (~31M non-embedding)

Languages

Amharic, Tigrinya, Afaan Oromo, Somali, Swahili, Hausa, Yoruba, Igbo, Kinyarwanda, Kirundi, Luganda, Chichewa, Shona, Sesotho, isiXhosa and isiZulu.

Training

  • Data: ~3B tokens of web text from the FineWeb-2 subsets of the 16 languages
  • Phase 1: 7 epochs at 512 tokens, 30% masking, peak learning rate 5e-4 with linear decay to 1.5e-4.
  • Phase 2 (context extension): 3 epochs at 4,096 tokens, 15% masking, learning rate 1.5e-4 decaying linearly to 0.
  • Hardware: a single NVIDIA RTX PRO 6000 Blackwell GPU (96 GB), with bf16 mixed precision and FlashAttention-2.

Usage

from transformers import pipeline

fill = pipeline("fill-mask", model="rasyosef/AfriModernBERT-small")
print(fill("አዲስ አበባ የኢትዮጵያ ዋና [MASK] ናት።"))
print(fill("Nairobi ni mji [MASK] wa Kenya."))

For fine-tuning, load it with AutoModelForSequenceClassification, AutoModelForTokenClassification, etc. Installing FlashAttention-2 and loading with attn_implementation="flash_attention_2" gives a large speedup on long inputs.

Evaluation

Downstream results (e.g. MasakhaNER 2.0, MasakhaNEWS, AfriSenti) coming soon.

Limitations

  • Trained only on web text, which can contain errors, bias and offensive content despite filtering.
  • Not trained on English or other high-resource languages, so code-switched text and foreign named entities may be handled less well.

Acknowledgements

Built on the ModernBERT architecture and trained on FineWeb-2.

Downloads last month
76
Safetensors
Model size
55.9M params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Dataset used to train rasyosef/AfriModernBERT-small

Papers for rasyosef/AfriModernBERT-small