Hate-speech-CNERG/hatexplain
Updated โข 1.43k โข 23
How to use venkateshmedasani/tinyllama-hatexplain-lora with PEFT:
from peft import PeftModel
from transformers import AutoModelForSequenceClassification
base_model = AutoModelForSequenceClassification.from_pretrained("TinyLlama/TinyLlama-1.1B-Chat-v1.0")
model = PeftModel.from_pretrained(base_model, "venkateshmedasani/tinyllama-hatexplain-lora")LoRA adapter (plus classification head) that turns TinyLlama/TinyLlama-1.1B-Chat-v1.0 into a 3-way
hate speech classifier (hate, normal, offensive), trained on HateXplain.
Code, training script and evaluation: https://github.com/venkateshmedasani/SLM-based-hate-speech-recognition
| Metric | Value |
|---|---|
| Accuracy | 0.677 |
| Macro F1 | 0.671 |
| Weighted F1 | 0.679 |
| Class | Precision | Recall | F1 |
|---|---|---|---|
| hate | 0.760 | 0.768 | 0.764 |
| normal | 0.751 | 0.698 | 0.724 |
| offensive | 0.504 | 0.549 | 0.525 |
from peft import PeftModel
from transformers import AutoModelForSequenceClassification, AutoTokenizer
tok = AutoTokenizer.from_pretrained("venkateshmedasani/tinyllama-hatexplain-lora")
base = AutoModelForSequenceClassification.from_pretrained("TinyLlama/TinyLlama-1.1B-Chat-v1.0", num_labels=3)
base.config.pad_token_id = tok.pad_token_id
model = PeftModel.from_pretrained(base, "venkateshmedasani/tinyllama-hatexplain-lora").merge_and_unload().eval()
Input text should be normalised with clean_text from src/text_utils.py in the GitHub repo
(lower-case, punctuation stripped, @mentions to <user>), matching HateXplain's format.
Labels: 0 = hate, 1 = normal, 2 = offensive.
Research artefact. Inherits the annotation biases of HateXplain, is English-only, and confuses hate with offensive more than any other pair of classes.
Base model
TinyLlama/TinyLlama-1.1B-Chat-v1.0