SW-FillMask is a BERT-based transformer model pre-trained on a large corpus of Swahili text in a self-supervised fashion. The model was trained specifically to handle real-world Kenyan Swahili, which frequently involves code-mixing with English - a limitation of most existing Swahili NLP models trained on formal, clean text.
It was pre-trained on raw texts only, with no human labeling, using an automatic process to generate inputs and labels. More precisely, it was pre-trained with one objective:
Masked language modeling (MLM):
taking a sentence, the model randomly masks 15% of the words in the input then runs the entire masked sentence through the model and has to predict the masked words. This is different from traditional recurrent neural networks (RNNs) that usually see the terms one after the other, or from autoregressive models like GPT which internally masks the future tokens. It allows the model to learn a bidirectional representation of the sentence.
This way, the model learns an inner representation of the Swahili language that can then be used to extract features useful for downstream tasks e.g.
The model was pre-trained on a curated corpus of Swahili text scraped from publicly available sources, with particular attention to Kenyan Swahili usage patterns including natural code-switching between Swahili and English. Standard preprocessing was applied including tokenisation and text cleaning.
Intended uses & limitations
You can use the raw model for masked language modeling, but it is primarily intended to be fine-tuned on a downstream task.
Best suited for:
Swahili NLP research and applications
Low-resource language modelling
Downstream fine-tuning for NER, text classification, sentiment analysis
Not recommended for:
Direct use in production without fine-tuning
Tasks requiring formal or standardised Swahili only
How to use
You can use this model directly with a pipeline for masked language modeling:
Fill Mask Pipeline
from transformers import pipeline
fill_mask = pipeline("fill-mask", model="eolang/sw-fillmask")
sample_text = "Tumefanya mabadiliko muhimu [MASK] sera zetu za faragha na vidakuzi"for prediction in fill_mask(sample_text):
print(f"{prediction['sequence']}, confidence: {prediction['score']:.4f}")
Tokenizer
from transformers import AutoTokenizer, AutoModelForMaskedLM
tokenizer = AutoTokenizer.from_pretrained("eolang/sw-fillmask")
model = AutoModelForMaskedLM.from_pretrained("eolang/sw-fillmask")
text = "Hii ni tovuti ya idhaa ya Kiswahili ya BBC ambayo hukuletea habari na makala kutoka Afrika na kote duniani kwa lugha ya Kiswahili."
encoded_input = tokenizer(text, return_tensors='pt')
output = model(**encoded_input)
print(output)
Fine-tuning for Token Classification (NER)
from transformers import AutoTokenizer, AutoModelForTokenClassification
tokenizer = AutoTokenizer.from_pretrained("eolang/sw-fillmask")
model = AutoModelForTokenClassification.from_pretrained("eolang/sw-fillmask", num_labels=NUM_LABELS)
Limitations and Bias
Even if the training data used for this model could be reasonably neutral, this model can have biased predictions. The model's performance on formal or standardised Swahili may also differ from its performance on informal or code-mixed text. This is something I'm still working on improving. Feel free to share suggestions/comments via
Discussions
Citation
If you use this model in your research, please cite:
@misc{olang2026swfillmask,
author = {Olang', Emmanuel},
title = {SW-FillMask: A Swahili Masked Language Model},
year = {2026},
publisher = {HuggingFace},
url = {https://huggingface.co/eolang/sw-fillmask}
}
sw-fillmask huggingface.co is an AI model on huggingface.co that provides sw-fillmask's model effect (), which can be used instantly with this eolang sw-fillmask model. huggingface.co supports a free trial of the sw-fillmask model, and also provides paid use of the sw-fillmask. Support call sw-fillmask model through api, including Node.js, Python, http.
sw-fillmask huggingface.co is an online trial and call api platform, which integrates sw-fillmask's modeling effects, including api services, and provides a free online trial of sw-fillmask, you can try sw-fillmask online for free by clicking the link below.
eolang sw-fillmask online free url in huggingface.co:
sw-fillmask is an open source model from GitHub that offers a free installation service, and any user can find sw-fillmask on GitHub to install. At the same time, huggingface.co provides the effect of sw-fillmask install, users can directly use sw-fillmask installed effect in huggingface.co for debugging and trial. It also supports api for free installation.