AfriSentiLID-115

AfriSentiLID-115 is a language identification model for African languages. It is an XLM-RoBERTa sequence classifier built on AfroXLMR-base. It predicts one of 116 labels: 108 African languages and language varieties, plus Arabic varieties used in and around Africa, French, Portuguese, Hebrew and Maltese.

It is part of the AfriLID project. For a smaller, tweet-only model covering 12 languages, see AfriSentiLID.

Authors: Idris Abdulmumin, Shamsuddeen Hassan Muhammad and Ibrahim Said Ahmad

Usage

pip install transformers torch
from transformers import pipeline

lid = pipeline("text-classification", model="HausaNLP/AfriSentiLID-115", top_k=3)

texts = [
    "Yara sun tafi makaranta da safe, amma malaminsu bai zo ba saboda ruwan sama.",
    "Gọọmentị etiti ekwuputala na a ga-amalite ịkwụ ụgwọ ọnwa ọhụrụ n'ọnwa na-abịa.",
]
for text, preds in zip(texts, lid(texts, truncation=True, max_length=128)):
    print(text, [(p["label"], round(p["score"], 3)) for p in preds])

Labels are ISO 639-3 codes (see the table below). Use top_k=1 for the single best guess, or top_k=None for scores over every label.

To label a CSV file:

import pandas as pd

df = pd.read_csv("data.csv")              # a column named "text"
preds = lid(df["text"].tolist(), truncation=True, max_length=128)
df["lang"] = [p[0]["label"] for p in preds]
df["score"] = [p[0]["score"] for p in preds]

Evaluation

On a held-out test set of 10,918 sentences (mostly 100 per label):

Metric Score
Accuracy 0.956
Macro F1 0.892
Weighted F1 0.948

93 of the 116 labels reach an F1 of 0.95 or more.

Known weaknesses

  • Nine labels are never predicted correctly (F1 0.000): acm, afb, aka, apc, bam, fuc, fuv, rif and swh. Most had very few examples (3 to 35), and their text is absorbed by a close relative. For example, swh (Swahili, individual language) is predicted as swc or swa, and the Arabic varieties fall into ara or arz.
  • Closely related languages are confused with each other: Arabic varieties, the Swahili labels, and Kinyarwanda and Rundi.
  • Standard (Tanzanian/Kenyan) Swahili is often labelled swc rather than swa.
  • Yorùbá written without tone marks, as is common on social media, can be labelled Gun (guw).
  • Treat swa, swc and swh as one language, and the Arabic labels as one family, unless you have checked the model on your own data.
  • Inputs are truncated to 128 tokens, and very short texts (one or two words) are unreliable.
Per-language results
Language Precision Recall F1-score support
ach 0.980 0.970 0.975 100
acm 0.000 0.000 0.000 6
ada 0.990 1.000 0.995 100
afb 0.000 0.000 0.000 35
afr 0.980 1.000 0.990 100
aka 0.000 0.000 0.000 31
alz 0.970 0.980 0.975 100
amh 0.980 0.990 0.985 100
apc 0.000 0.000 0.000 8
ara 0.793 0.960 0.869 100
arq 0.889 0.960 0.923 100
ary 0.960 0.950 0.955 100
arz 0.807 0.960 0.877 100
bam 0.000 0.000 0.000 3
bas 0.980 0.990 0.985 100
bci 0.990 1.000 0.995 100
bem 0.960 0.970 0.965 100
bin 0.990 0.970 0.980 100
bum 0.951 0.980 0.966 100
cce 0.971 0.990 0.980 100
chw 0.980 0.990 0.985 100
cjk 0.891 0.980 0.933 100
cop 1.000 1.000 1.000 100
dik 1.000 1.000 1.000 100
dje 1.000 1.000 1.000 100
dop 1.000 1.000 1.000 100
dua 0.990 0.970 0.980 100
dyu 0.961 0.990 0.975 100
efi 0.990 0.990 0.990 100
ewe 0.980 0.990 0.985 100
fon 1.000 0.980 0.990 100
fra 0.980 1.000 0.990 100
fuc 0.000 0.000 0.000 3
fuv 0.000 0.000 0.000 15
gaa 0.980 0.980 0.980 100
guw 1.000 0.980 0.990 100
hau 0.943 0.990 0.966 100
heb 0.990 1.000 0.995 100
her 1.000 0.960 0.980 100
ibo 0.990 0.980 0.985 100
ish 0.980 0.990 0.985 100
iso 0.971 0.990 0.980 100
kab 0.840 1.000 0.913 100
kam 0.990 0.990 0.990 100
kbp 1.000 1.000 1.000 100
kik 0.990 0.980 0.985 100
kin 0.833 0.900 0.865 100
kmb 0.980 0.990 0.985 100
koo 0.990 0.980 0.985 100
kqn 0.942 0.970 0.956 100
kss 0.990 0.990 0.990 100
kua 0.980 0.970 0.975 100
kwn 0.980 0.990 0.985 100
kwy 0.970 0.980 0.975 100
lam 0.969 0.940 0.954 100
lin 0.980 0.990 0.985 100
loz 0.970 0.970 0.970 100
lua 0.990 0.980 0.985 100
lub 0.960 0.960 0.960 100
lue 0.951 0.970 0.960 100
lug 0.943 1.000 0.971 100
lun 0.960 0.970 0.965 100
luo 0.990 0.990 0.990 100
men 0.990 0.990 0.990 100
mgr 0.979 0.950 0.964 100
mlt 0.951 0.970 0.960 100
mos 0.990 0.990 0.990 100
nba 1.000 0.980 0.990 100
ndc 1.000 0.960 0.980 100
ndo 0.980 0.980 0.980 100
ngl 0.951 0.970 0.960 100
nso 0.970 0.980 0.975 100
nya 0.969 0.940 0.954 100
nyk 0.990 0.980 0.985 100
nyn 0.949 0.940 0.945 100
nyu 0.990 0.980 0.985 100
nzi 0.861 0.990 0.921 100
oke 0.970 0.980 0.975 100
pcm 0.962 1.000 0.980 100
por 0.990 0.970 0.980 100
rif 0.000 0.000 0.000 17
rnd 0.970 0.980 0.975 100
run 0.876 0.850 0.863 100
seh 0.980 0.970 0.975 100
shi 1.000 1.000 1.000 100
sid 0.933 0.980 0.956 100
sna 0.943 0.990 0.966 100
som 0.990 0.980 0.985 100
sop 0.961 0.980 0.970 100
ssw 0.903 0.930 0.916 100
swa 0.979 0.950 0.964 100
swc 0.558 0.960 0.706 100
swh 0.000 0.000 0.000 100
tir 0.990 0.990 0.990 100
tiv 1.000 1.000 1.000 100
tll 0.990 0.990 0.990 100
tog 0.960 0.970 0.965 100
toh 1.000 0.990 0.995 100
toi 0.952 0.990 0.971 100
tsc 1.000 0.980 0.990 100
tsn 0.979 0.940 0.959 100
tso 0.990 1.000 0.995 100
ttj 0.960 0.950 0.955 100
tum 0.980 0.970 0.975 100
twi 0.915 0.970 0.942 100
umb 0.980 0.980 0.980 100
urh 0.970 0.960 0.965 100
ven 0.933 0.970 0.951 100
vmw 0.971 0.990 0.980 100
wal 0.980 0.990 0.985 100
wol 0.990 1.000 0.995 100
xho 0.879 0.870 0.874 100
yao 0.970 0.980 0.975 100
yor 0.980 1.000 0.990 100
zne 0.934 0.990 0.961 100
zul 0.865 0.900 0.882 100

Languages

All 116 labels
Code Language
ach Acoli
acm Mesopotamian Arabic
ada Adangme
afb Gulf Arabic
afr Afrikaans
aka Akan
alz Alur
amh Amharic
apc North Levantine Arabic
ara Arabic
arq Algerian Arabic
ary Moroccan Arabic
arz Egyptian Arabic
bam Bambara
bas Basa (Cameroon)
bci Baoulé
bem Bemba (Zambia)
bin Bini
bum Bulu (Cameroon)
cce Chopi
chw Chuwabu
cjk Chokwe
cop Coptic
dik Southwestern Dinka
dje Zarma
dop Lukpa
dua Duala
dyu Dyula
efi Efik
ewe Ewe
fon Fon
fra French
fuc Pulaar
fuv Nigerian Fulfulde
gaa Ga
guw Gun
hau Hausa
heb Hebrew
her Herero
ibo Igbo
ish Esan
iso Isoko
kab Kabyle
kam Kamba (Kenya)
kbp Kabiyè
kik Kikuyu
kin Kinyarwanda
kmb Kimbundu
koo Konzo
kqn Kaonde
kss Southern Kisi
kua Kuanyama
kwn Kwangali
kwy San Salvador Kongo
lam Lamba
lin Lingala
loz Lozi
lua Luba-Lulua
lub Luba-Katanga
lue Luvale
lug Ganda
lun Lunda
luo Luo (Kenya and Tanzania)
men Mende (Sierra Leone)
mgr Mambwe-Lungu
mlt Maltese
mos Mossi
nba Nyemba
ndc Ndau
ndo Ndonga
ngl Lomwe
nso Pedi
nya Nyanja
nyk Nyaneka
nyn Nyankole
nyu Nyungwe
nzi Nzima
oke Okpe (Southwestern Edo)
pcm Nigerian Pidgin
por Portuguese
rif Tarifit
rnd Ruund
run Rundi
seh Sena
shi Tachelhit
sid Sidamo
sna Shona
som Somali
sop Songe
ssw Swati
swa Swahili (macrolanguage)
swc Congo Swahili
swh Swahili (individual language)
tir Tigrinya
tiv Tiv
tll Tetela
tog Tonga (Nyasa)
toh Gitonga
toi Tonga (Zambia)
tsc Tswa
tsn Tswana
tso Tsonga
ttj Tooro
tum Tumbuka
twi Twi
umb Umbundu
urh Urhobo
ven Venda
vmw Makhuwa
wal Wolaytta
wol Wolof
xho Xhosa
yao Yao
yor Yoruba
zne Zande (individual language)
zul Zulu

Limitations

The model always returns one of its 116 labels, even for text in a language it does not know. Low scores are a useful signal that the text may be in an unsupported language, mixed, or too short. Code-switched text (common on African social media) gets a single label.

Fine-tune further

The repository is a standard transformers model, so you can continue training it on your own labelled data:

from transformers import AutoTokenizer, AutoModelForSequenceClassification

tok = AutoTokenizer.from_pretrained("HausaNLP/AfriSentiLID-115")
model = AutoModelForSequenceClassification.from_pretrained("HausaNLP/AfriSentiLID-115")
# then train with Trainer as for any text classifier. To add new languages, pass
# num_labels, id2label, label2id and ignore_mismatched_sizes=True to from_pretrained.

License

CC BY-NC-SA 4.0: free for non-commercial use with attribution; derivatives must use the same licence.

Citation

@misc{abdulmumin2023afrisentilid115,
  title  = {AfriSentiLID-115: Language Identification for 116 African Languages and Varieties},
  author = {Abdulmumin, Idris and Muhammad, Shamsuddeen Hassan and Ahmad, Ibrahim Said},
  year   = {2023},
  publisher = {HausaNLP},
  howpublished = {\url{https://huggingface.co/HausaNLP/AfriSentiLID-115}}
}

Please also cite the AfriSenti and AfriHate papers:

@inproceedings{muhammad-etal-2023-afrisenti,
    title = "{A}fri{S}enti: A {T}witter Sentiment Analysis Benchmark for {A}frican Languages",
    author = "Muhammad, Shamsuddeen Hassan  and
      Abdulmumin, Idris  and
      Ayele, Abinew Ali  and
      Ousidhoum, Nedjma  and
      Adelani, David Ifeoluwa  and
      Yimam, Seid Muhie  and
      Ahmad, Ibrahim Sa'id  and
      Beloucif, Meriem  and
      Mohammad, Saif M.  and
      Ruder, Sebastian  and
      Hourrane, Oumaima  and
      Brazdil, Pavel  and
      Jorge, Alipio  and
      Ali, Felermino D{\'a}rio M{\'a}rio Ant{\'o}nio  and
      David, Davis  and
      Osei, Salomey  and
      Shehu Bello, Bello  and
      Ibrahim, Falalu  and
      Gwadabe, Tajuddeen  and
      Rutunda, Samuel  and
      Belay, Tadesse  and
      Messelle, Wendimu Baye  and
      Balcha, Hailu Beshada  and
      Chala, Sisay Adugna  and
      Gebremichael, Hagos Tesfahun  and
      Opoku, Bernard  and
      Arthur, Stephen",
    editor = "Bouamor, Houda  and
      Pino, Juan  and
      Bali, Kalika",
    booktitle = "Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing",
    month = dec,
    year = "2023",
    address = "Singapore",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2023.emnlp-main.862/",
    doi = "10.18653/v1/2023.emnlp-main.862",
    pages = "13968--13981"
}

@inproceedings{muhammad-etal-2025-afrihate,
    title = "{A}fri{H}ate: A Multilingual Collection of Hate Speech and Abusive Language Datasets for {A}frican Languages",
    author = {Muhammad, Shamsuddeen Hassan  and
      Abdulmumin, Idris  and
      Ayele, Abinew Ali  and
      Adelani, David Ifeoluwa  and
      Ahmad, Ibrahim Said  and
      Aliyu, Saminu Mohammad  and
      R{\"o}ttger, Paul  and
      Oppong, Abigail  and
      Bukula, Andiswa  and
      Chukwuneke, Chiamaka Ijeoma  and
      Jibril, Ebrahim Chekol  and
      Ismail, Elyas Abdi  and
      Alemneh, Esubalew  and
      Gebremichael, Hagos Tesfahun  and
      Aliyu, Lukman Jibril  and
      Beloucif, Meriem  and
      Hourrane, Oumaima  and
      Mabuya, Rooweither  and
      Osei, Salomey  and
      Rutunda, Samuel  and
      Belay, Tadesse Destaw  and
      Guge, Tadesse Kebede  and
      Asfaw, Tesfa Tegegne  and
      Wanzare, Lilian Diana Awuor  and
      Onyango, Nelson Odhiambo  and
      Yimam, Seid Muhie  and
      Ousidhoum, Nedjma},
    editor = "Chiruzzo, Luis  and
      Ritter, Alan  and
      Wang, Lu",
    booktitle = "Proceedings of the 2025 Conference of the Nations of the {A}mericas Chapter of the {A}ssociation for {C}omputational {L}inguistics: Human Language Technologies (Volume 1: Long Papers)",
    month = apr,
    year = "2025",
    address = "Albuquerque, New Mexico",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2025.naacl-long.92/",
    doi = "10.18653/v1/2025.naacl-long.92",
    pages = "1854--1871",
    ISBN = "979-8-89176-189-6"
}
Downloads last month
-
Safetensors
Model size
0.3B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for HausaNLP/AfriSentiLID-115

Finetuned
(111)
this model