mopatik/setswana-offensive-977
Preview • Updated • 6
This repository contains a fine-tuned version of Afro-XLM-R, a multilingual transformer model optimised for African languages.
The model has been fine-tuned to classify Setswana text into:
Afro-XLM-R provides a multilingual baseline to benchmark performance against monolingual Setswana models such as PuoBERTa.
Its cross-lingual capabilities make it particularly useful when dealing with:
A curated dataset of 977 Setswana social media text samples was used.
[1.0, 2.0] (non-offensive, offensive)The dataset split follows:
Evaluation uses the following metrics:
| Metric | Value |
|---|---|
| Accuracy | 0.8622 |
| Macro F1-score | 0.8603 |
| Recall (Offensive = 1) | 0.8111 |
| MCC | 0.7229 |
| ROC-AUC | 0.9015 |
| Loss | 0.3895 |
| Runtime (seconds) | 1.1634 |
| Samples per second | 168.468 |
| Steps per second | 3.438 |
Overall, Afro-XLM-R performs strongly as a multilingual baseline for Setswana offensive-language detection.
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model_name = "mopatik/Afro-XLM-R-offensive-detection-v1"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
# Ensure model is in evaluation mode
model.eval()
# Sample text (replace with your actual text)
#sample_text = "o seso tota" # (you are insanely stupid) Example Setswana text
sample_text = "modimo a le segofatse" # (God bless you all) Example Setswana text
# Tokenize and prepare input
inputs = tokenizer(
sample_text,
padding='max_length',
truncation=True,
max_length=128,
return_tensors="pt"
)
# Make prediction
with torch.no_grad():
outputs = model(**inputs)
probs = torch.softmax(outputs.logits, dim=1)
predicted_class = torch.argmax(probs).item()
# Get class label and confidence
class_names = ["Non-offensive", "Offensive"]
confidence = probs[0][predicted_class].item()
print(f"Text: {sample_text}")
print(f"Predicted class: {class_names[predicted_class]} (confidence: {confidence:.2%})")
print(f"Class probabilities: {dict(zip(class_names, [f'{p:.2%}' for p in probs[0].tolist()]))}")
Base model
Davlan/afro-xlmr-base