tamim65/BanglaHateSpeech
1
🛡️ Bangla Hate Speech Detection API
Detect hate speech in Bangla text using BanglaBERT-based models.
🚀 Features
- Binary Classification: Detect if text is Hate or Non-Hate
- Multi-class Classification: Categorize into 7 categories
- Line-by-Line Analysis: Analyze multiple lines separately
- Fast Inference: Optimized for real-time predictions
- RESTful API: Easy integration with any frontend
📊 Categories
- normal - Non-hate speech
- political - Political hate speech
- religious - Religious hate speech
- geopolitical - Geopolitical hate speech
- gender - Gender-based hate speech
- person - Personal attacks
- organization - Organization-targeted hate speech
🔗 API Endpoints
1. Health Check
GET /
GET /health2. Single Text Prediction
POST /predict
Content-Type: application/json
{
"text": "আপনার বাংলা টেক্সট এখানে"
}Response:
{
"text": "আপনার বাংলা টেক্সট এখানে",
"cleaned_text": "আপনার বাংলা টেক্সট এখানে",
"binary": {
"label": "Non-Hate",
"confidence": 0.95,
"probabilities": {
"Non-Hate": 0.95,
"Hate": 0.05
}
},
"multiclass": {
"label": "normal",
"confidence": 0.92,
"probabilities": {
"normal": 0.92,
"political": 0.03,
"religious": 0.02,
"geopolitical": 0.01,
"gender": 0.01,
"person": 0.01,
"organization": 0.00
}
}
}3. Line-by-Line Prediction
POST /predict-lines
Content-Type: application/json
{
"text": "প্রথম লাইন\nদ্বিতীয় লাইন\nতৃতীয় লাইন"
}Response:
{
"original_text": "প্রথম লাইন\nদ্বিতীয় লাইন\nতৃতীয় লাইন",
"total_lines": 3,
"results": [
{
"line_number": 1,
"text": "প্রথম লাইন",
"binary": {...},
"multiclass": {...}
},
...
]
}4. Get Categories
GET /categories🧪 Testing
Using cURL:
curl -X POST https://tamim65-banglahatespeech.hf.space/predict \
-H "Content-Type: application/json" \
-d '{"text": "এটি একটি পরীক্ষা"}'Using Python:
import requests
url = "https://tamim65-banglahatespeech.hf.space/predict"
data = {"text": "আপনার বাংলা টেক্সট"}
response = requests.post(url, json=data)
print(response.json())Using JavaScript:
fetch('https://tamim65-banglahatespeech.hf.space/predict', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text: 'আপনার বাংলা টেক্সট' })
})
.then(res => res.json())
.then(data => console.log(data));🏗️ Model Architecture
- Base Model: BanglaBERT (
sagorsarker/bangla-bert-base) - Binary Classifier: 2 labels (Hate/Non-Hate)
- Multi-class Classifier: 7 categories
- Max Sequence Length: 512 tokens
📈 Performance
- Accuracy: ~93% (binary classification)
- Inference Time: ~1-2 seconds per request
- Supported Languages: Bangla (বাংলা)
🔧 Local Development
# Clone the repository
git clone https://huggingface.co/spaces/tamim65/BanglaHateSpeech
cd BanglaHateSpeech
# Install dependencies
pip install -r requirements.txt
# Run locally
uvicorn app:app --host 0.0.0.0 --port 7860📝 License
Apache 2.0
👨💻 Author
Tamim
🤝 Contributing
Contributions are welcome! Please open an issue or submit a pull request.
📧 Contact
For questions or support, please open an issue on this Space.
Built with ❤️ for a hate-free Bangla internet
