Skip to main content

Detect Romanized Sinhala hate speech using mBERT.

Project description

Romanized Sinhala Hate Speech Detection

Detect hate speech in Romanized Sinhala text using a fine-tuned deep learning model based on mBERT.
This project includes:
✅ Training code
✅ Inference code
✅ Pip-installable package
✅ REST API (FastAPI)
✅ CLI tool


📚 About

This project was developed as part of my MSc research to address hate speech detection in Romanized Sinhala, commonly used in Sri Lankan social media.

The model is trained on the SOLD dataset, fine-tuned on mBERT, and exposes predictions through a REST API, a CLI, and as a reusable Python package.


🚀 Features

  • Fine-tuned multilingual transformer for Romanized Sinhala text.
  • Inference available via:
    • Python package (romsi_hate_speech)
    • CLI command: romsi-detect
    • REST API (FastAPI server)
  • Training pipeline to reproduce experiments.
  • MIT licensed and open source.

🗂️ Project Structure

romanized_hate_speech_detection/
├── romsi_hate_speech/         # Inference package (pip-installable)
│   ├── __init__.py
│   ├── predictor.py
│   ├── api.py
│   ├── cli.py
├── training/                  # Training and evaluation code
│   ├── trainer.py
│   ├── evaluator.py
│   ├── data_loader.py
│   └── ...
├── models/                    # Saved models
├── data/                      # Datasets and preprocessing scripts
├── README.md                  # This file
├── setup.py                   # Packaging metadata
├── requirements.txt
├── .gitignore
├── LICENSE

🔷 Installation

You can install the inference package locally:

pip install .

Or (once published):

pip install romsi-hate-speech

🧪 Usage

🐍 Python

from romsi_hate_speech import Predictor

predictor = Predictor(model_path="sakunchamikara/romsi-hate-speech")
label, confidence = predictor.predict("meka thamai mage msc research project eka")
print(label, confidence)

💻 CLI

romsi-detect "meka thamai mage msc research project eka"

or for multiple Texts

from romsi_hate_speech.predictor import Predictor

predictor = Predictor(model_path="sakunchamikara/romsi-hate-speech")
texts = [
    "patta horekta yahapalanayen adhyaksha thanathurak",
    "marila palayan balla"
]
results = predictor.predict(texts)

for r in results:
    print(f'"{r["text"]}" → {r["label"]} (confidence: {r["confidence"]})')

🌐 REST API

Run the API server:

uvicorn romsi_hate_speech.api:app --reload

Then open: http://127.0.0.1:8000/docs

Or POST to /predict:

{
  "texts": ["patta horekta yahapalanayen"]
}

📈 Training

To reproduce training:

python training/model_trainer.py

You can configure hyperparameters in training/config.py.


⚖️ License

This project is licensed under the MIT License.


👤 Author

  • Sakun Chamikara
  • MSc Research Project, 2025

🌐 Links


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

romsi_hate_speech-1.0.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

romsi_hate_speech-1.0.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file romsi_hate_speech-1.0.1.tar.gz.

File metadata

  • Download URL: romsi_hate_speech-1.0.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for romsi_hate_speech-1.0.1.tar.gz
Algorithm Hash digest
SHA256 870951df6e68ad7a598f3e93ad27a536881132f1033158cba8158fe52f9e5d2d
MD5 c828316e2d391a0080b7785fa37fa947
BLAKE2b-256 0b5155aedfb31f5d6e1246711545ab85baea30b0940455fe55dd091d962c63f2

See more details on using hashes here.

File details

Details for the file romsi_hate_speech-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for romsi_hate_speech-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ebdcd36f4f7c2a74db59f8cee7932896fc868d139f0303fc54e59eae86b0359c
MD5 27a9d71d9fa9095cd5eb502465f5ef6f
BLAKE2b-256 344d1462254e0cba56ffb9646ed5016c038af2a8729887c7737cc5a37eb30d62

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page