Views
No views yet
roberta-base architecture (PuoBERTa variant)[1.0, 2.0]| Metric | Value |
|---|---|
| Accuracy | 0.8673 |
| Macro F1-score | 0.8662 |
| Recall (Offensive = 1) | 0.8444 |
| Matthews Correlation Coefficient (MCC) | 0.7326 |
| ROC-AUC | 0.9288 |
| Loss | 0.3381 |
| Runtime (seconds) | 0.5897 |
| Samples per second | 332.398 |
| Steps per second | 6.784 |
1from transformers import RobertaTokenizer, RobertaForSequenceClassification
2
3tokenizer = RobertaTokenizer.from_pretrained("mopatik/PuoBERTa-offensive-detection-v1")
4model = RobertaForSequenceClassification.from_pretrained("mopatik/PuoBERTa-offensive-detection-v1")
5
6# Ensure model is in evaluation mode
7model.eval()
8
9# Sample text (replace with your actual text)
10#sample_text = "o seso tota" # Example Setswana text
11sample_text = "modimo a le segofatse" # Example Setswana text
12
13# Tokenize and prepare input
14inputs = tokenizer(
15 sample_text,
16 padding='max_length',
17 truncation=True,
18 max_length=128,
19 return_tensors="pt"
20)
21
22# Make prediction
23with torch.no_grad():
24 outputs = model(**inputs)
25 probs = torch.softmax(outputs.logits, dim=1)
26 predicted_class = torch.argmax(probs).item()
27
28# Get class label and confidence
29class_names = ["Non-offensive", "Offensive"]
30confidence = probs[0][predicted_class].item()
31
32print(f"Text: {sample_text}")
33print(f"Predicted class: {class_names[predicted_class]} (confidence: {confidence:.2%})")
34print(f"Class probabilities: {dict(zip(class_names, [f'{p:.2%}' for p in probs[0].tolist()]))}")