A cloud-deployed NLP application for real-time offensive language detection using DistilBERT sentence embeddings, VADER sentiment features, and a Logistic Regression classifier.
The system is implemented using a production-style architecture with a FastAPI inference backend, an interactive Streamlit frontend, Docker containers, Azure Container Registry, and Azure Container Apps.
https://offenseval-frontend.icysea-bc6cd350.centralindia.azurecontainerapps.io/
https://offenseval-backend.icysea-bc6cd350.centralindia.azurecontainerapps.io/docs
https://offenseval-backend.icysea-bc6cd350.centralindia.azurecontainerapps.io/health
The live application provides real-time offensive language classification, confidence scores, cleaned-text visibility, and sentiment-aware output.
OffensEval NLP is an end-to-end machine learning application designed to identify offensive language in user-provided text.
The project combines transformer-based semantic representations with sentiment information to improve contextual understanding. DistilBERT sentence embeddings are generated through SentenceTransformers, while VADER sentiment scores are added as an additional numerical feature. The combined feature vector is passed to a Logistic Regression classifier for binary prediction.
The application is divided into two independently deployed services:
- A FastAPI backend responsible for preprocessing, model loading, sentiment analysis, and prediction
- A Streamlit frontend responsible for user interaction and result presentation
Both services are containerized using Docker, stored in Azure Container Registry, and deployed through Azure Container Apps.
- ๐ DistilBERT sentence embeddings through SentenceTransformers
- ๐ Sentiment-aware feature augmentation using VADER
- โ๏ธ Interpretable Logistic Regression classifier
- ๐ Prediction confidence and sentiment distribution
- ๐งน Centralized text preprocessing
- โก FastAPI REST inference service
- ๐ Interactive Streamlit frontend
- ๐ณ Dockerized frontend and backend
- โ๏ธ Deployment through Azure Container Apps
- ๐ฆ Container storage through Azure Container Registry
- ๐งช Automated testing with PyTest
- โค๏ธ Backend health monitoring
- ๐ Modular production-style repository structure
User
โ
โผ
Streamlit Frontend
Azure Container App
โ
HTTPS REST API
โ
โผ
FastAPI Backend
Azure Container App
โ
Text Cleaning and Normalization
โ
โผ
DistilBERT Sentence Embeddings (768D)
โ
โโโโโโโโโโโโโโโโโ
โ โ
โผ โผ
Semantic Features VADER Sentiment
โ โ
โโโโโโโโโฌโโโโโโโโ
โผ
Feature Concatenation (769D)
โ
โผ
Logistic Regression Model
โ
โผ
Prediction, Confidence, Sentiment
Input Text
โ
Text Cleaning and Normalization
โ
DistilBERT Sentence Embedding
โ
VADER Sentiment Feature
โ
Feature Concatenation
โ
Logistic Regression Classification
โ
Offensive / Not Offensive Prediction
| Component | Dimensions |
|---|---|
| DistilBERT sentence embedding | 768 |
| VADER compound sentiment score | 1 |
| Final feature vector | 769 |
| Category | Technology |
|---|---|
| Programming Language | Python 3.12 |
| Backend Framework | FastAPI |
| Frontend Framework | Streamlit |
| ASGI Server | Uvicorn |
| Machine Learning | Scikit-learn |
| Embeddings | SentenceTransformers |
| Transformer Model | DistilBERT |
| Sentiment Analysis | VADER |
| Validation | Pydantic |
| Testing | PyTest |
| Containerization | Docker |
| Local Orchestration | Docker Compose |
| Container Registry | Azure Container Registry |
| Cloud Deployment | Azure Container Apps |
| Version Control | Git and GitHub |
-
Dataset: TweetEval โ Offensive Language
-
Task: Binary text classification
-
Classes:
OffensiveNot Offensive
TweetEval provides benchmark datasets for evaluating language models on social media classification tasks. This project uses the offensive language subset for supervised model development and validation.
| Metric | Validation Score |
|---|---|
| Macro F1 | ~0.72 |
| ROC-AUC | ~0.81 |
The reported values are based on a held-out validation set used during model development.
The Streamlit frontend provides:
- Preprocessed text preview
- Offensive or non-offensive prediction
- Prediction confidence
- VADER compound sentiment score
- Positive, neutral, and negative sentiment percentages
- Sentiment category
- Color-coded sentiment visualizations
- Backend availability check
- Error handling for failed API requests
- Clear usage disclaimer
The FastAPI backend exposes the following endpoints:
| Method | Endpoint | Description |
|---|---|---|
GET |
/ |
API information |
GET |
/health |
Backend and model health check |
POST |
/predict |
Offensive language prediction |
curl -X POST \
"https://offenseval-backend.icysea-bc6cd350.centralindia.azurecontainerapps.io/predict" \
-H "Content-Type: application/json" \
-d '{
"text": "You are an idiot."
}'{
"prediction": "Offensive",
"confidence": 0.94,
"cleaned_text": "you are an idiot",
"sentiment_score": -0.73,
"sentiment_category": "Negative",
"positive_score": 0.0,
"neutral_score": 0.29,
"negative_score": 0.71
}Exact prediction values depend on the trained model and input text.
offenseval-nlp/
โ
โโโ assets/
โ โโโ offenseval-nlp-banner.png
โ
โโโ backend/
โ โโโ __init__.py
โ โโโ config.py
โ โโโ inference.py
โ โโโ main.py
โ โโโ preprocessing.py
โ โโโ schemas.py
โ
โโโ frontend/
โ โโโ app.py
โ
โโโ embeddings/
โ โโโ X_train_distil.npy
โ โโโ X_val_distil.npy
โ โโโ X_test_distil.npy
โ โโโ X_train_minilm.npy
โ โโโ X_val_minilm.npy
โ โโโ X_test_minilm.npy
โ โโโ y_train.npy
โ โโโ y_val.npy
โ โโโ y_test.npy
โ
โโโ model/
โ โโโ final_model_tuned_distilbert.joblib
โ โโโ label_encoder.json
โ
โโโ tests/
โ โโโ __init__.py
โ โโโ pytest.ini
โ โโโ test_api.py
โ โโโ test_inference.py
โ โโโ test_preprocessing.py
โ
โโโ Dockerfile.backend
โโโ Dockerfile.frontend
โโโ docker-compose.yml
โโโ requirements.txt
โโโ Model_Training_and_Evaluation.ipynb
โโโ .dockerignore
โโโ .gitignore
โโโ LICENSE
โโโ README.md
git clone https://github.com/ArunavaKumar/offenseval-nlp.git
cd offenseval-nlppython -m venv .venv
source .venv/bin/activateFor Windows:
.venv\Scripts\activatepip install --upgrade pip
pip install -r requirements.txtuvicorn backend.main:app --reloadThe backend will be available at:
http://127.0.0.1:8000
API documentation:
http://127.0.0.1:8000/docs
Open another terminal and run:
streamlit run frontend/app.pyThe frontend will usually be available at:
http://localhost:8501
Build and start both services:
docker compose up --buildThe services will be available at:
| Service | Local Address |
|---|---|
| Streamlit frontend | http://localhost:8501 |
| FastAPI backend | http://localhost:8000 |
| FastAPI documentation | http://localhost:8000/docs |
Stop the services with:
docker compose downRun the complete test suite:
python -m pytest -vThe tests validate:
- Root endpoint availability
- Health endpoint response
- Prediction endpoint response
- Model loading
- Request and response schema compatibility
- Text preprocessing
- Prediction confidence range
- Sentiment score output
Local Development
โ
โผ
Docker Images
โ
โผ
Azure Container Registry
โ
โโโ offenseval-backend:v1
โ
โโโ offenseval-frontend:v1
โ
โผ
Azure Container Apps Environment
โ
โโโ FastAPI Backend Container App
โ
โโโ Streamlit Frontend Container App
โ
โผ
Public HTTPS Endpoints
| Resource | Name |
|---|---|
| Resource Group | offenseval-rg |
| Container Registry | offensevalacr |
| Container Apps Environment | offenseval-env |
| Backend Container App | offenseval-backend |
| Frontend Container App | offenseval-frontend |
| Azure Region | Central India |
After modifying the application, rebuild and push the updated Docker image.
docker build \
-f Dockerfile.backend \
-t offensevalacr.azurecr.io/offenseval-backend:v2 \
.docker push offensevalacr.azurecr.io/offenseval-backend:v2az containerapp update \
--name offenseval-backend \
--resource-group offenseval-rg \
--image offensevalacr.azurecr.io/offenseval-backend:v2docker build \
-f Dockerfile.frontend \
-t offensevalacr.azurecr.io/offenseval-frontend:v2 \
.docker push offensevalacr.azurecr.io/offenseval-frontend:v2az containerapp update \
--name offenseval-frontend \
--resource-group offenseval-rg \
--image offensevalacr.azurecr.io/offenseval-frontend:v2The backend exposes a health endpoint:
GET /health
Example response:
{
"status": "healthy",
"model_ready": true
}This endpoint verifies that:
- The FastAPI service is running
- The trained model has loaded successfully
- The backend is ready to accept prediction requests
The frontend connects to the backend through the API_URL environment variable.
Local default:
http://127.0.0.1:8000
Azure deployment value:
https://offenseval-backend.icysea-bc6cd350.centralindia.azurecontainerapps.io
Example:
export API_URL=https://offenseval-backend.icysea-bc6cd350.centralindia.azurecontainerapps.ioThis application predicts offensive language based on patterns learned from social media text.
Known limitations include:
- Sarcasm and humor may be interpreted incorrectly
- Cultural and regional language differences may be missed
- Indirect insults may not always be detected
- Quoted offensive language may be classified without understanding intent
- Very short or ambiguous text may produce uncertain predictions
- Sentiment does not always correspond directly to offensiveness
- Model outputs may reflect biases present in the training data
The application is intended to support content analysis and experimentation. It should not replace human review in high-impact moderation or disciplinary decisions.
- Multi-class toxicity detection
- Hate-speech category classification
- Explainable AI using SHAP or LIME
- Batch prediction endpoint
- Authentication and rate limiting
- GitHub Actions CI/CD
- Azure Monitor and Application Insights
- Structured application logging
- Model version tracking
- Drift monitoring
- Database-backed prediction history
- Kubernetes deployment
- Transformer fine-tuning instead of fixed embeddings
Arunava Kumar Chakraborty
Data Analyst | Machine Learning Enthusiast
- LinkedIn: https://www.linkedin.com/in/arunava-kr-chakraborty
- GitHub: https://github.com/ArunavaKumar
This project is licensed under the MIT License.
See the LICENSE file for details.
- Hugging Face
- SentenceTransformers
- DistilBERT
- VADER Sentiment Analysis
- TweetEval
- FastAPI
- Streamlit
- Docker
- Microsoft Azure
