ucberkeley-dlab/measuring-hate-speech
Viewer • Updated • 136k • 5.07k • 56
Fine-tuned roberta-base for binary classification of hate speech targeting immigrants in US social media contexts.
roberta-base (125M params)Filtered subset of UC Berkeley Measuring Hate Speech dataset targeting immigrants:
target_origin_immigrant > 0| Metric | Value |
|---|---|
| Accuracy | 0.9527 |
| Macro-F1 | 0.9520 |
| Weighted-F1 | 0.9527 |
| Gap | 0.0007 |
| Class | Precision | Recall | F1 |
|---|---|---|---|
| not-hate | 0.951 | 0.942 | 0.946 |
| hate | 0.954 | 0.962 | 0.958 |
The near-zero accuracy-macro-F1 gap (0.0007) on this balanced dataset (ratio 1.25) validates the diagnostic framework: when class distribution is balanced, accuracy and macro-F1 agree. This contrasts with imbalanced datasets like X-Fact Hindi, where the gap reaches 0.412 and reveals complete minority-class failure.
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
tokenizer = AutoTokenizer.from_pretrained("nusaiba19/roberta-immigrant-hate-speech")
model = AutoModelForSequenceClassification.from_pretrained("nusaiba19/roberta-immigrant-hate-speech")
text = "Example comment here"
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=256)
with torch.no_grad():
pred = model(**inputs).logits.argmax(-1).item()
print(["not-hate", "hate"][pred])