CoolFace
Modelpublic

katoernest/afro-xlmr-swahili-news-classifier

sourceHugging Facemitupdated 4mo agoView on Hugging Face
0likes8downloads
Model Card

๐ŸŒ AfroXLMR Swahili News Classifier

Fine-tuned Davlan/afro-xlmr-mini on the MasakhaNEWS Swahili dataset for multi-class news and community report classification.

Built for civic reporting platforms operating across East Africa where community reports arrive in Swahili and need to be categorised for decision-making.

Model Summary

PropertyValue
Base modelDavlan/afro-xlmr-mini
LanguageSwahili (sw)
TaskMulti-class text classification
DatasetMasakhaNEWS Swahili
Training samples1,658
Validation samples237
Test samples476
Epochs5
Best F10.4736
Best Accuracy59.49%

Training Results

EpochTrain LossVal LossAccuracyF1
11.93171.894732.49%0.2068
21.84701.810841.35%0.2943
31.75361.710755.27%0.4362
41.67921.655159.49%0.4705
51.64021.633759.49%0.4736

The model shows consistent improvement across all 5 epochs with both training and validation loss decreasing โ€” no overfitting.

Why These Results Are Expected

MasakhaNEWS Swahili is a genuinely hard classification task:

  • โ€”7 categories with overlapping vocabulary (politics vs elections, health vs science)
  • โ€”Small dataset โ€” only 1,658 training samples for 7 classes
  • โ€”Low-resource language โ€” limited pre-training data for Swahili even in AfroXLMR
  • โ€”Baseline random would be ~14% accuracy โ€” this model is at 59.49%

Accuracy improves significantly with more training data from the target platform.

Usage

python
from transformers import pipeline

classifier = pipeline(
    'text-classification',
    model     = 'katoernest/afro-xlmr-swahili-news-classifier',
    tokenizer = 'katoernest/afro-xlmr-swahili-news-classifier'
)

result = classifier("mafuriko makubwa yameharibu mazao shambani")
print(result)
# [{'label': 'environment', 'score': 0.62}]

Full Pipeline Usage

python
from transformers import pipeline
from langdetect import detect
import re

classifier = pipeline(
    'text-classification',
    model = 'katoernest/afro-xlmr-swahili-news-classifier'
)

def classify_report(text):
    # Step 1: detect language
    language = detect(text)

    # Step 2: clean text
    clean = re.sub(r'http\S+|@\w+', '', text)
    clean = re.sub(r'\s+', ' ', clean).strip()

    # Step 3: classify
    result = classifier(clean)[0]

    return {
        'text'      : text,
        'language'  : language,
        'category'  : result['label'],
        'confidence': round(result['score'] * 100, 1)
    }

# Test
reports = [
    'mafuriko makubwa yameharibu mazao shambani mashariki',
    'wapigakura wanakataliwa kupiga kura kituo namba nne',
    'mlipuko wa ugonjwa umethibitishwa kaskazini mwa nchi',
]

for r in reports:
    print(classify_report(r))

Pipeline Position

This model sits at the classification stage of the Distant Voices data pipeline:

Community report (SMS / WhatsApp / voice note)
            โ†“
   Whisper transcription
            โ†“
   Language detection
            โ†“
   Text cleaning
            โ†“
[This model] โ€” category classification
            โ†“
   Confidence routing
   > 0.80 โ†’ auto-approve
   0.50โ€“0.80 โ†’ human review
   < 0.50 โ†’ flag for manual classification
            โ†“
   Dashboard

Improving Accuracy

This model was trained on general Swahili news. Accuracy improves significantly when fine-tuned further on:

  • โ€”Platform-specific community reports
  • โ€”Domain vocabulary (elections, climate, crisis, humanitarian)
  • โ€”More training samples per category

The model is designed as a starting point โ€” it improves as real platform data accumulates through the human review feedback loop.

Framework Versions

  • โ€”Transformers: 4.44.0
  • โ€”PyTorch: 2.3.0+cu121
  • โ€”Datasets: 2.14.0
  • โ€”Tokenizers: 0.19.1

Author

Kato Ernest Henry AI Research and MLOps Engineer โ€” Kampala, Uganda henry38ernest@gmail.com HuggingFace GitHub