A fullstack web application that classifies movie reviews as Positive or Negative using a fine-tuned DistilBERT model with LoRA.
This project demonstrates an end-to-end machine learning pipeline:
- Fine-tuned DistilBERT on the IMDB dataset using LoRA (Low-Rank Adaptation)
- Built a Flask API to serve predictions
- Created a SvelteKit frontend for user interaction
| Component | Technology |
|---|---|
| Model | DistilBERT + LoRA |
| Training | Google Colab, Hugging Face Transformers, PEFT |
| Backend | Flask, PyTorch |
| Frontend | SvelteKit, Tailwind CSS |
sentiment-app/
├── server.py # Flask API
├── my-sentiment-model/ # LoRA adapter files
│ ├── adapter_config.json
│ ├── adapter_model.safetensors
│ └── tokenizer files
└── frontend/ # SvelteKit app
└── src/
└── routes/
└── +page.svelte
- Base Model: distilbert-base-uncased
- Fine-tuning Method: LoRA (Parameter-Efficient Fine-Tuning)
- Dataset: IMDB Movie Reviews (25,000 training samples)
- Task: Binary Sentiment Classification (Positive/Negative)
- Trainable Parameters: 739,586 (1.09% of total)
- Training Time: ~4 minutes on Google Colab
| Epoch | Training Loss | Validation Loss |
|---|---|---|
| 1 | 0.3236 | 0.3291 |
| 2 | 0.2881 | 0.3239 |
| 3 | 0.2659 | 0.3179 |
git clone https://github.com/YOUR_USERNAME/sentiment-app.git
cd sentiment-appDownload the LoRA adapter files and place them in the my-sentiment-model/ folder.
pip install flask flask-cors transformers torch peftpython server.pyThe API will be available at http://127.0.0.1:5000
cd frontend
npm install
npm run devThe app will be available at http://localhost:5173
Endpoint: POST /api/analyze
Request:
{
"text": "This movie was absolutely fantastic!"
}Response:
{
"sentiment": "Positive",
"confidence": 97.85
}Endpoint: GET /api/health
Response:
{
"status": "ok"
}User Input --> SvelteKit Frontend --> Flask API --> LoRA Model --> Prediction
| |
<-------------------------- Response ---------------------------
- User enters a movie review in the frontend
- Frontend sends POST request to Flask API
- API tokenizes text and runs it through the model
- Model returns sentiment prediction with confidence score
- Frontend displays the result
- Trained only on movie reviews; may not generalize to other domains
- Binary classification only (no neutral option)
- Maximum input length of 512 tokens
- English language only
- Deploy to Hugging Face Spaces
- Add multi-class sentiment (positive, neutral, negative)
- Support for other languages
- Batch analysis for multiple reviews
MIT
Michael Fafore
- Hugging Face for Transformers and PEFT libraries
- IMDB dataset
- Google Colab for free GPU access