Spaces:
Runtime error
Runtime error
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,12 +1,29 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ToxiFilter: AI-Based Hate Speech Classifier π«
|
| 2 |
+
|
| 3 |
+
A fine-tuned BERT model that detects hate speech and offensive language in real-time messages. Developed as part of a capstone project, it powers a Gradio-based chat simulation where offensive content is automatically censored.
|
| 4 |
+
|
| 5 |
+
## π Model Info
|
| 6 |
+
|
| 7 |
+
- **Base**: `bert-base-uncased`
|
| 8 |
+
- **Task**: Binary Classification
|
| 9 |
+
- **Labels**:
|
| 10 |
+
- `1`: Hate/Offensive
|
| 11 |
+
- `0`: Not Offensive
|
| 12 |
+
- **Accuracy**: ~92%
|
| 13 |
+
- **Dataset**: [tdavidson/hate_speech_offensive](https://huggingface.co/datasets/tdavidson/hate_speech_offensive)
|
| 14 |
+
(Labels 0 and 1 combined as "offensive")
|
| 15 |
+
|
| 16 |
+
## π Usage
|
| 17 |
+
|
| 18 |
+
```python
|
| 19 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 20 |
+
import torch
|
| 21 |
+
|
| 22 |
+
model = AutoModelForSequenceClassification.from_pretrained("chaitravi/hate-speech-classifier")
|
| 23 |
+
tokenizer = AutoTokenizer.from_pretrained("chaitravi/hate-speech-classifier")
|
| 24 |
+
|
| 25 |
+
def classify(text):
|
| 26 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
| 27 |
+
outputs = model(**inputs)
|
| 28 |
+
pred = torch.argmax(outputs.logits, dim=1).item()
|
| 29 |
+
return "Hate/Offensive" if pred == 1 else "Not Offensive"
|