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/
The live application provides real-time offensive language classification, confidence scores, cleaned-text visibility, and sentiment-aware output. The production inference backend is not exposed as a public portfolio endpoint.
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
- Only the Streamlit frontend is intended to be publicly accessible in production.
- The FastAPI inference service should use internal ingress within the Azure Container Apps environment.
- Production credentials, tokens, registry passwords, connection strings, and
.envfiles must never be committed to the repository. - Public deployment documentation intentionally omits production backend addresses and sensitive cloud configuration.
- Cost controls, scaling limits, and monitoring should be configured separately in Azure.
User
โ
โผ
Streamlit Frontend
Public Azure Container App
โ
โ Internal HTTPS
โผ
FastAPI Backend
Internal 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 provides application-internal endpoints for service information, health checks, and offensive-language prediction.
| Method | Endpoint | Description |
|---|---|---|
GET |
/ |
API information |
GET |
/health |
Backend and model health check |
POST |
/predict |
Offensive language prediction |
The production backend is intended for communication from the deployed frontend within the application environment. Local development can access these endpoints through http://127.0.0.1:8000.
For local development:
curl -X POST \
"http://127.0.0.1:8000/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
โ
โผ
Azure Container Apps Environment
โ
โโโ Streamlit Frontend
โ Public HTTPS ingress
โ
โโโ FastAPI Backend
Internal application ingress
The frontend is the public portfolio entry point. The inference backend is deployed as a separate service and is intended to communicate with the frontend through the Azure Container Apps environment.
| Resource Type | Purpose |
|---|---|
| Resource Group | Groups project cloud resources |
| Container Registry | Stores frontend and backend container images |
| Container Apps Environment | Hosts the application services |
| Frontend Container App | Public Streamlit portfolio interface |
| Backend Container App | Internal FastAPI inference service |
| Azure Region | Central India |
Application updates follow a container-based deployment workflow:
- Modify and test the application locally.
- Build updated frontend or backend Docker images.
- Push versioned images to Azure Container Registry.
- Update the corresponding Azure Container App revision.
- Validate frontend availability and backend health.
- Keep production credentials and service configuration outside the repository.
Deployment commands depend on the target Azure subscription, registry, resource group, and application configuration, so production-specific values are intentionally omitted from this public README.
The backend includes an internal 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
In production, health checks are used for application monitoring and service-to-service validation rather than being advertised as a public endpoint.
The frontend connects to the backend through the API_URL environment variable.
Local default:
http://127.0.0.1:8000
Example local configuration:
export API_URL=http://127.0.0.1:8000Production service addresses, credentials, registry authentication, and other environment-specific values are intentionally excluded from the public repository and should be configured through the deployment environment.
This 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
