AfriSentiLID

AfriSentiLID is a language identification model for African social media text. It is AfroXLMR-large fine-tuned to tell apart the 12 languages of the AfriSenti Twitter sentiment corpus.

It is part of the AfriLID project. For broader coverage (116 labels), see AfriSentiLID-115.

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")

texts = [
    "Ina kwana? Yaya aiki yau?",
    "How far, wetin dey happen for your side?",
]
for text, pred in zip(texts, lid(texts, truncation=True, max_length=128)):
    print(text, pred["label"], round(pred["score"], 3))

Pass top_k=3 to the pipeline to get the three most likely languages.

Languages

Code Language
amh Amharic
arq Algerian Arabic
ary Moroccan Arabic
hau Hausa
ibo Igbo
kin Kinyarwanda
pcm Nigerian Pidgin
por Mozambican Portuguese
swa Swahili
tso Xitsonga
twi Twi
yor Yorรนbรก

Training data

HausaNLP/afrisenti-lid-data: tweets from the AfriSenti corpus labelled with their language.

Split Tweets
Train 97,128
Validation 5,452
Test 5,754

Evaluation

On the test split (500 tweets per language, 254 for tso): accuracy 0.990, macro F1 0.989.

Language Precision Recall F1-score support
amh 1.000 1.000 1.000 500
arq 1.000 0.980 0.990 500
ary 0.980 0.994 0.987 500
hau 0.975 0.998 0.986 500
ibo 0.986 0.992 0.989 500
kin 0.992 0.998 0.995 500
pcm 0.988 0.990 0.989 500
por 0.992 1.000 0.996 500
swa 0.994 0.996 0.995 500
tso 0.996 0.921 0.957 254
twi 0.988 0.984 0.986 500
yor 0.996 0.996 0.996 500

Limitations

  • Only these 12 languages are supported. Text in any other language is still given one of the 12 labels, so use AfriSentiLID-115 when the input may be in other languages.
  • Trained on tweets: it is tuned to short, informal text, and code-switched tweets get a single label.
  • Inputs are truncated to 128 tokens.

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")
model = AutoModelForSequenceClassification.from_pretrained("HausaNLP/AfriSentiLID")
# 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, the same as the AfriSenti data.

Citation

@misc{abdulmumin2023afrisentilid,
  title  = {AfriSentiLID: Language Identification for African Social Media Text},
  author = {Abdulmumin, Idris and Muhammad, Shamsuddeen Hassan and Ahmad, Ibrahim Said},
  year   = {2023},
  publisher = {HausaNLP},
  howpublished = {\url{https://huggingface.co/HausaNLP/AfriSentiLID}}
}

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
7
Safetensors
Model size
0.6B 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

Finetuned
(26)
this model

Dataset used to train HausaNLP/AfriSentiLID