CoolFace
Apppublic

tamim65/BanglaHateSpeech

sourceHugging Faceapache-2.0updated 11mo agoView on Hugging Face
1likes
App README

🛡️ 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

  1. 1.normal - Non-hate speech
  2. 2.political - Political hate speech
  3. 3.religious - Religious hate speech
  4. 4.geopolitical - Geopolitical hate speech
  5. 5.gender - Gender-based hate speech
  6. 6.person - Personal attacks
  7. 7.organization - Organization-targeted hate speech

🔗 API Endpoints

1. Health Check

bash
GET /
GET /health

2. Single Text Prediction

bash
POST /predict
Content-Type: application/json

{
  "text": "আপনার বাংলা টেক্সট এখানে"
}

Response:

json
{
  "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

bash
POST /predict-lines
Content-Type: application/json

{
  "text": "প্রথম লাইন\nদ্বিতীয় লাইন\nতৃতীয় লাইন"
}

Response:

json
{
  "original_text": "প্রথম লাইন\nদ্বিতীয় লাইন\nতৃতীয় লাইন",
  "total_lines": 3,
  "results": [
    {
      "line_number": 1,
      "text": "প্রথম লাইন",
      "binary": {...},
      "multiclass": {...}
    },
    ...
  ]
}

4. Get Categories

bash
GET /categories

🧪 Testing

Using cURL:

bash
curl -X POST https://tamim65-banglahatespeech.hf.space/predict \
  -H "Content-Type: application/json" \
  -d '{"text": "এটি একটি পরীক্ষা"}'

Using Python:

python
import requests

url = "https://tamim65-banglahatespeech.hf.space/predict"
data = {"text": "আপনার বাংলা টেক্সট"}

response = requests.post(url, json=data)
print(response.json())

Using JavaScript:

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

bash
# 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