Real-time AI-based hate speech and abusive language detection for social media platforms using a Chrome Extension, FastAPI backend, and multilingual NLP inference.
Harmful social media content, including hate speech and abusive language, has become a major issue on digital platforms. Manual moderation is difficult due to the massive volume of user-generated content and the use of multilingual, code-mixed, and informal text.
This project provides an automated solution using a Chrome browser extension that works in real time. The extension extracts text content directly from social media webpages, sends it to a local FastAPI backend for analysis, and displays the classification result directly on the page using inline badges. The system can optionally blur harmful content to protect users from immediate exposure.
Automated content moderation systems face several technical challenges:
| Feature | Description |
|---|---|
| Real-time Analysis | Analyzes supported social media posts and comments as the user browses. |
| Three User-facing Labels | Classifies content into three categories: Hate, Offensive, or Neutral. |
| Confidence Display | Displays model prediction confidence as a percentage in the extension popup. |
| Inline Badges | Automatically inserts color-coded labels directly next to social media posts. |
| Blur Mode | Optionally blurs text identified as Hate or Offensive, revealing content on hover. |
| Multilingual Enhancement | Applies rule-based checks for slang, Hinglish, and transliterated terms. |
| Telugu Support | Employs custom pattern checks for specific Romanized Telugu slangs and threat expressions. |
| Context Rules | Uses safe-phrase checks to filter out non-literal violent terms like "killing it". |
| Dynamic Content Support | Monitors page additions to scan content loaded during infinite scroll. |
| Duplicate Prevention | Uses text hashing and element attributes to prevent redundant API calls. |
| Extension Settings | Persists user scanning and blurring options using the Chrome Storage API. |
| Platform | Content Type | Status |
|---|---|---|
| X / Twitter | Timeline posts | Supported |
| X / Twitter | Post detail view | Supported |
| YouTube | Video comments | Supported |
| YouTube | Shorts comments | Supported |
| Post comments | Supported | |
| Reels comments | Supported | |
| Posts and comments | Experimental (Inactive in Manifest) |
Note: Reddit selectors and extraction logic exist in the content script, but the domain is not declared in the manifest matches list, making it experimental.
flowchart LR
A[Social Media Page] --> B[Chrome Extension]
B --> C[DOM Text Extraction]
C --> D[FastAPI Backend]
D --> E[Tokenizer]
E --> F[Hugging Face Model]
F --> G[Probability Processing]
G --> H[Context and Multilingual Rules]
H --> I[Final Label and Confidence]
I --> J[Inline Badge]
I --> K[Optional Blur]
flowchart TD
A[User Opens Supported Platform] --> B[Content Script Starts]
B --> C[Scan Visible Content]
C --> D[Extract Text]
D --> E{Already Processed?}
E -->|Yes| C
E -->|No| F[Send POST Request to /analyze]
F --> G[FastAPI Analyze Endpoint]
G --> H[Tokenize Text]
H --> I[Run Model Inference]
I --> J[Extract Probabilities]
J --> K[Apply Threshold Logic]
K --> L[Apply Context Rules]
L --> M[Apply Multilingual Rules]
M --> N[Return Label and Confidence]
N --> O[Inject Inline Badge]
O --> P{Blur Enabled?}
P -->|Yes and Harmful| Q[Blur Content]
P -->|No| R[Keep Content Visible]
Q --> S[Continue Scanning]
R --> S
/analyze endpoint.Hate-speech-CNERG/indic-abusive-allInOne-MuRILnormal vs abusive)The inference engine executes the following steps to analyze input text:
normal and abusive classes.abusive_prob is greater than 0.90, the text is categorized as hate.abusive_prob is greater than 0.60, the text is categorized as offensive.neutral.Following the primary threshold mapping, the backend applies post-processing rules in strict priority order to refine classification accuracy:
neutral with a confidence score of at least 0.70.hate with a confidence score of at least 0.85.hate, matches force the label to offensive with a confidence score of at least 0.75.Single-word filters create high rates of false positives because they fail to capture context. To resolve this, this project incorporates local pattern matching to differentiate between literal and figurative language.
| Input Type | Intended Handling | Example Category |
|---|---|---|
| Direct Threat | Force Hate | Explicit violent statement targeting a user |
| Personal Insult | Force Offensive | Slangs or insults without extreme violent threats |
| Safe Metaphor | Force Neutral | Figurative phrases like "killing time" |
| Transliterated Abuse | Force Offensive | Hindi, Hinglish, or Telugu abusive slang |
| Transliterated Threat | Force Hate | Regional language phrases indicating direct physical threat |
The browser extension is structured as a Manifest V3 extension containing the following core files:
The backend is built with FastAPI and runs on a local ASGI server.
Checks if the backend and the inference model are loaded and active.
{
"status": "healthy",
"model_loaded": true,
"version": "1.0.0"
}
Analyzes a single text string.
{
"text": "Sample text for classification"
}
{
"label": "neutral",
"confidence": 0.965,
"sentiment_score": 0.0,
"explanation": "Human-readable explanation of the prediction",
"keywords": [],
"raw_probabilities": {
"normal": 0.965,
"abusive": 0.035
}
}
Processes a batch of multiple text strings in a single call.
{
"texts": ["First sample text", "Second sample text"]
}
{
"results": [
{
"label": "neutral",
"confidence": 0.965,
"sentiment_score": 0.0,
"explanation": "Explanation text",
"keywords": [],
"raw_probabilities": {
"normal": 0.965,
"abusive": 0.035
}
}
],
"total": 1
}
| Layer | Technology |
|---|---|
| Programming Languages | Python, JavaScript |
| Backend Framework | FastAPI |
| Web Server | Uvicorn |
| NLP & Deep Learning | Hugging Face Transformers |
| Model Runtime | PyTorch (CPU optimized) |
| Web Integration | Chrome Extension APIs (Manifest V3) |
| Extension Frontend | HTML, CSS, JavaScript |
| Dynamic Tracking | MutationObserver API |
| Settings Storage | Chrome Storage API |
| Version Control | Git, GitHub |
FINAL-YEAR-PROJECT/
├── backend/
│ ├── main.py
│ ├── inference.py
│ └── rules.py
├── data/
│ ├── collect_datasets.py
│ ├── preprocess.py
│ └── datasets/
│ ├── bengali_dataset.csv
│ ├── context_dataset.csv
│ ├── english_dataset.csv
│ ├── hindi_hinglish_dataset.csv
│ ├── label_map.json
│ ├── merged_dataset.csv
│ ├── telugu_dataset.csv
│ ├── train.csv
│ └── val.csv
├── extension/
│ ├── manifest.json
│ ├── content.js
│ ├── content.css
│ ├── popup.html
│ ├── popup.js
│ ├── background.js
│ └── icons/
│ ├── icon16.png
│ ├── icon48.png
│ └── icon128.png
├── tests/
│ ├── test_model.py
│ └── backtest_results.json
├── training/
│ ├── config.py
│ └── train.py
├── .gitattributes
├── .gitignore
├── download_model.py
├── GRP_29_PROJECT_DEMO.mp4
├── requirements.txt
└── run_pipeline.py
Ensure Python is installed on your Windows machine, then run:
# Create a virtual environment
python -m venv venv
# Activate the virtual environment
.\venv\Scripts\Activate.ps1
# Install required dependencies
pip install -r requirements.txt
Start the FastAPI backend with the master pipeline script:
python run_pipeline.py --serve
The server will start at http://127.0.0.1:8000. You can access interactive API documentation at http://127.0.0.1:8000/docs.
chrome://extensions/.extension/ directory of this project.| Label | Meaning |
|---|---|
| Hate | Language targeting groups or individuals with violent, discriminatory, or threatening intent. |
| Offensive | Vulgar, insulting, or disrespectful language that does not rise to direct threats of violence. |
| Neutral | Standard non-harmful communication. |
Note: These are application-level classifications based on model probabilities and rule-based adjustments. Real-world text may occasionally result in prediction errors.
The complete demonstration video is included in this repository: View Project Demo
The demonstration video shows:
The proposed multilingual hate speech detection system was evaluated using standard classification metrics, including Accuracy, Precision, Recall, F1-score, and Confusion Matrix analysis.
| Metric | Result |
|---|---|
| Accuracy | 88.5% |
| Precision | 0.86 |
| Recall | 0.86 |
| F1 Score | 0.86 |
The evaluation results demonstrate that the proposed system provides effective classification of multilingual social media text into three user-facing categories: Hate, Offensive, and Neutral. The model achieves an overall accuracy of 88.5%, with balanced precision, recall, and F1-score values of approximately 0.86.
| Class | Precision | Recall | F1 Score |
|---|---|---|---|
| Hate Speech | 0.82 | 0.78 | 0.80 |
| Offensive Language | 0.91 | 0.93 | 0.92 |
| Neutral | 0.85 | 0.88 | 0.86 |
| Macro Average | 0.86 | 0.86 | 0.86 |
The results indicate strong performance for Offensive Language detection, while Hate Speech remains comparatively more challenging because of contextual ambiguity, implicit expressions, sarcasm, multilingual variations, and overlap between hate and offensive language.
The confusion matrix provides a detailed view of correct predictions and misclassifications across the three output categories. Most samples are correctly classified, while some confusion occurs between semantically similar categories, particularly Neutral and Offensive content.
The evaluated confusion matrix contains the following values:
| Actual Class | Predicted Neutral | Predicted Offensive | Predicted Hate |
|---|---|---|---|
| Neutral | 1836 | 159 | 5 |
| Offensive | 90 | 1822 | 88 |
| Hate | 0 | 0 | 2000 |
This analysis demonstrates the effectiveness of the classification pipeline while also highlighting the importance of continued improvement for ambiguous, context-dependent, multilingual, and code-mixed expressions.
During model training, accuracy improved progressively across epochs, indicating effective learning and convergence. Training loss decreased steadily as the model learned patterns from the training data. Validation loss showed a slight increase during later epochs, indicating mild overfitting and suggesting opportunities for future regularization and calibration improvements.
The proposed model was compared with baseline machine learning approaches.
| Model | Accuracy | Precision | Recall | F1 Score |
|---|---|---|---|---|
| Naive Bayes | 78.2% | 0.75 | 0.72 | 0.73 |
| Decision Tree | 81.4% | 0.80 | 0.79 | 0.79 |
| Random Forest | 85.6% | 0.84 | 0.83 | 0.83 |
| Proposed Model | 88.5% | 0.86 | 0.86 | 0.86 |
The comparison indicates that the proposed approach provides the strongest overall performance among the evaluated methods.
To support large-scale concurrent users, the following infrastructure changes would be needed:
http://127.0.0.1:8000) and are not cached, saved, or uploaded to external servers.This project is developed for academic and research purposes. Automated content moderation systems can produce incorrect predictions. Results should not be treated as a substitute for human judgment in high-impact moderation decisions.
Developed as a final-year academic project. Built using PyTorch, Hugging Face Transformers, and FastAPI.
3 commits
Python
71.7%
JavaScript
18.7%
HTML
8.9%
Real-time AI-based hate speech and abusive language detection for social media platforms using a Chrome Extension, FastAPI backend, and multilingual NLP inference.
Harmful social media content, including hate speech and abusive language, has become a major issue on digital platforms. Manual moderation is difficult due to the massive volume of user-generated content and the use of multilingual, code-mixed, and informal text.
This project provides an automated solution using a Chrome browser extension that works in real time. The extension extracts text content directly from social media webpages, sends it to a local FastAPI backend for analysis, and displays the classification result directly on the page using inline badges. The system can optionally blur harmful content to protect users from immediate exposure.
Automated content moderation systems face several technical challenges:
| Feature | Description |
|---|---|
| Real-time Analysis | Analyzes supported social media posts and comments as the user browses. |
| Three User-facing Labels | Classifies content into three categories: Hate, Offensive, or Neutral. |
| Confidence Display | Displays model prediction confidence as a percentage in the extension popup. |
| Inline Badges | Automatically inserts color-coded labels directly next to social media posts. |
| Blur Mode | Optionally blurs text identified as Hate or Offensive, revealing content on hover. |
| Multilingual Enhancement | Applies rule-based checks for slang, Hinglish, and transliterated terms. |
| Telugu Support | Employs custom pattern checks for specific Romanized Telugu slangs and threat expressions. |
| Context Rules | Uses safe-phrase checks to filter out non-literal violent terms like "killing it". |
| Dynamic Content Support | Monitors page additions to scan content loaded during infinite scroll. |
| Duplicate Prevention | Uses text hashing and element attributes to prevent redundant API calls. |
| Extension Settings | Persists user scanning and blurring options using the Chrome Storage API. |
| Platform | Content Type | Status |
|---|---|---|
| X / Twitter | Timeline posts | Supported |
| X / Twitter | Post detail view | Supported |
| YouTube | Video comments | Supported |
| YouTube | Shorts comments | Supported |
| Post comments | Supported | |
| Reels comments | Supported | |
| Posts and comments | Experimental (Inactive in Manifest) |
Note: Reddit selectors and extraction logic exist in the content script, but the domain is not declared in the manifest matches list, making it experimental.
flowchart LR
A[Social Media Page] --> B[Chrome Extension]
B --> C[DOM Text Extraction]
C --> D[FastAPI Backend]
D --> E[Tokenizer]
E --> F[Hugging Face Model]
F --> G[Probability Processing]
G --> H[Context and Multilingual Rules]
H --> I[Final Label and Confidence]
I --> J[Inline Badge]
I --> K[Optional Blur]
flowchart TD
A[User Opens Supported Platform] --> B[Content Script Starts]
B --> C[Scan Visible Content]
C --> D[Extract Text]
D --> E{Already Processed?}
E -->|Yes| C
E -->|No| F[Send POST Request to /analyze]
F --> G[FastAPI Analyze Endpoint]
G --> H[Tokenize Text]
H --> I[Run Model Inference]
I --> J[Extract Probabilities]
J --> K[Apply Threshold Logic]
K --> L[Apply Context Rules]
L --> M[Apply Multilingual Rules]
M --> N[Return Label and Confidence]
N --> O[Inject Inline Badge]
O --> P{Blur Enabled?}
P -->|Yes and Harmful| Q[Blur Content]
P -->|No| R[Keep Content Visible]
Q --> S[Continue Scanning]
R --> S
/analyze endpoint.Hate-speech-CNERG/indic-abusive-allInOne-MuRILnormal vs abusive)The inference engine executes the following steps to analyze input text:
normal and abusive classes.abusive_prob is greater than 0.90, the text is categorized as hate.abusive_prob is greater than 0.60, the text is categorized as offensive.neutral.Following the primary threshold mapping, the backend applies post-processing rules in strict priority order to refine classification accuracy:
neutral with a confidence score of at least 0.70.hate with a confidence score of at least 0.85.hate, matches force the label to offensive with a confidence score of at least 0.75.Single-word filters create high rates of false positives because they fail to capture context. To resolve this, this project incorporates local pattern matching to differentiate between literal and figurative language.
| Input Type | Intended Handling | Example Category |
|---|---|---|
| Direct Threat | Force Hate | Explicit violent statement targeting a user |
| Personal Insult | Force Offensive | Slangs or insults without extreme violent threats |
| Safe Metaphor | Force Neutral | Figurative phrases like "killing time" |
| Transliterated Abuse | Force Offensive | Hindi, Hinglish, or Telugu abusive slang |
| Transliterated Threat | Force Hate | Regional language phrases indicating direct physical threat |
The browser extension is structured as a Manifest V3 extension containing the following core files:
The backend is built with FastAPI and runs on a local ASGI server.
Checks if the backend and the inference model are loaded and active.
{
"status": "healthy",
"model_loaded": true,
"version": "1.0.0"
}
Analyzes a single text string.
{
"text": "Sample text for classification"
}
{
"label": "neutral",
"confidence": 0.965,
"sentiment_score": 0.0,
"explanation": "Human-readable explanation of the prediction",
"keywords": [],
"raw_probabilities": {
"normal": 0.965,
"abusive": 0.035
}
}
Processes a batch of multiple text strings in a single call.
{
"texts": ["First sample text", "Second sample text"]
}
{
"results": [
{
"label": "neutral",
"confidence": 0.965,
"sentiment_score": 0.0,
"explanation": "Explanation text",
"keywords": [],
"raw_probabilities": {
"normal": 0.965,
"abusive": 0.035
}
}
],
"total": 1
}
| Layer | Technology |
|---|---|
| Programming Languages | Python, JavaScript |
| Backend Framework | FastAPI |
| Web Server | Uvicorn |
| NLP & Deep Learning | Hugging Face Transformers |
| Model Runtime | PyTorch (CPU optimized) |
| Web Integration | Chrome Extension APIs (Manifest V3) |
| Extension Frontend | HTML, CSS, JavaScript |
| Dynamic Tracking | MutationObserver API |
| Settings Storage | Chrome Storage API |
| Version Control | Git, GitHub |
FINAL-YEAR-PROJECT/
├── backend/
│ ├── main.py
│ ├── inference.py
│ └── rules.py
├── data/
│ ├── collect_datasets.py
│ ├── preprocess.py
│ └── datasets/
│ ├── bengali_dataset.csv
│ ├── context_dataset.csv
│ ├── english_dataset.csv
│ ├── hindi_hinglish_dataset.csv
│ ├── label_map.json
│ ├── merged_dataset.csv
│ ├── telugu_dataset.csv
│ ├── train.csv
│ └── val.csv
├── extension/
│ ├── manifest.json
│ ├── content.js
│ ├── content.css
│ ├── popup.html
│ ├── popup.js
│ ├── background.js
│ └── icons/
│ ├── icon16.png
│ ├── icon48.png
│ └── icon128.png
├── tests/
│ ├── test_model.py
│ └── backtest_results.json
├── training/
│ ├── config.py
│ └── train.py
├── .gitattributes
├── .gitignore
├── download_model.py
├── GRP_29_PROJECT_DEMO.mp4
├── requirements.txt
└── run_pipeline.py
Ensure Python is installed on your Windows machine, then run:
# Create a virtual environment
python -m venv venv
# Activate the virtual environment
.\venv\Scripts\Activate.ps1
# Install required dependencies
pip install -r requirements.txt
Start the FastAPI backend with the master pipeline script:
python run_pipeline.py --serve
The server will start at http://127.0.0.1:8000. You can access interactive API documentation at http://127.0.0.1:8000/docs.
chrome://extensions/.extension/ directory of this project.| Label | Meaning |
|---|---|
| Hate | Language targeting groups or individuals with violent, discriminatory, or threatening intent. |
| Offensive | Vulgar, insulting, or disrespectful language that does not rise to direct threats of violence. |
| Neutral | Standard non-harmful communication. |
Note: These are application-level classifications based on model probabilities and rule-based adjustments. Real-world text may occasionally result in prediction errors.
The complete demonstration video is included in this repository: View Project Demo
The demonstration video shows:
The proposed multilingual hate speech detection system was evaluated using standard classification metrics, including Accuracy, Precision, Recall, F1-score, and Confusion Matrix analysis.
| Metric | Result |
|---|---|
| Accuracy | 88.5% |
| Precision | 0.86 |
| Recall | 0.86 |
| F1 Score | 0.86 |
The evaluation results demonstrate that the proposed system provides effective classification of multilingual social media text into three user-facing categories: Hate, Offensive, and Neutral. The model achieves an overall accuracy of 88.5%, with balanced precision, recall, and F1-score values of approximately 0.86.
| Class | Precision | Recall | F1 Score |
|---|---|---|---|
| Hate Speech | 0.82 | 0.78 | 0.80 |
| Offensive Language | 0.91 | 0.93 | 0.92 |
| Neutral | 0.85 | 0.88 | 0.86 |
| Macro Average | 0.86 | 0.86 | 0.86 |
The results indicate strong performance for Offensive Language detection, while Hate Speech remains comparatively more challenging because of contextual ambiguity, implicit expressions, sarcasm, multilingual variations, and overlap between hate and offensive language.
The confusion matrix provides a detailed view of correct predictions and misclassifications across the three output categories. Most samples are correctly classified, while some confusion occurs between semantically similar categories, particularly Neutral and Offensive content.
The evaluated confusion matrix contains the following values:
| Actual Class | Predicted Neutral | Predicted Offensive | Predicted Hate |
|---|---|---|---|
| Neutral | 1836 | 159 | 5 |
| Offensive | 90 | 1822 | 88 |
| Hate | 0 | 0 | 2000 |
This analysis demonstrates the effectiveness of the classification pipeline while also highlighting the importance of continued improvement for ambiguous, context-dependent, multilingual, and code-mixed expressions.
During model training, accuracy improved progressively across epochs, indicating effective learning and convergence. Training loss decreased steadily as the model learned patterns from the training data. Validation loss showed a slight increase during later epochs, indicating mild overfitting and suggesting opportunities for future regularization and calibration improvements.
The proposed model was compared with baseline machine learning approaches.
| Model | Accuracy | Precision | Recall | F1 Score |
|---|---|---|---|---|
| Naive Bayes | 78.2% | 0.75 | 0.72 | 0.73 |
| Decision Tree | 81.4% | 0.80 | 0.79 | 0.79 |
| Random Forest | 85.6% | 0.84 | 0.83 | 0.83 |
| Proposed Model | 88.5% | 0.86 | 0.86 | 0.86 |
The comparison indicates that the proposed approach provides the strongest overall performance among the evaluated methods.
To support large-scale concurrent users, the following infrastructure changes would be needed:
http://127.0.0.1:8000) and are not cached, saved, or uploaded to external servers.This project is developed for academic and research purposes. Automated content moderation systems can produce incorrect predictions. Results should not be treated as a substitute for human judgment in high-impact moderation decisions.
Developed as a final-year academic project. Built using PyTorch, Hugging Face Transformers, and FastAPI.
3 commits
Python
71.7%
JavaScript
18.7%
HTML
8.9%