FrancescoConte/Sentiment_analysis_app
Sentiment Analysis App
A fine-tuned DistilBERT model for binary sentiment classification (positive / negative), served as an interactive web app via Streamlit and deployed on Hugging Face Spaces with Docker.
Live demo:

Results
Evaluated on 3,000 held-out IMDB test samples:
Confusion matrix and per-class breakdown are available in the live app.
What fine-tuning on IMDB adds
Training on domain-specific data changes how the model interprets ambiguous language. A few examples where the IMDB-fine-tuned model outperforms the base SST-2 model:
- "The best part of the movie is the money spent on the ticket." — the base model reads "best part" as positive; the fine-tuned model recognises the dismissal.
- "It made me laugh. It was a tragedy." — the base model splits the two clauses and leans positive; the fine-tuned model understands that "laugh" and "tragedy" in the same review rarely signal a compliment.
- "It compels you to face all the protagonist's worst feelings, as the director intended them." — surface-level negative words ("worst feelings", "compels") confuse the base model; the fine-tuned model recognises deliberate emotional impact as a mark of quality.
The app also includes a curated set of adversarial examples where the model fails — cases where surface-level word associations (sarcasm, emotional ambiguity, complex negation) override sentence-level meaning. These are documented transparently in the Adversarial examples tab.
App features
Beyond basic inference, the app includes several analytical layers:
- Comparison mode — runs the same input through the fine-tuned model and the base
distilbert-base-uncased-finetuned-sst-2-english(SST-2) side by side, making the effect of domain-specific fine-tuning visible - Batch mode — classify multiple sentences at once, with a confidence distribution chart per result
- Domain advantage — curated film-criticism sentences where IMDB fine-tuning demonstrably outperforms the general model, run live through both models
- Adversarial examples — sentences that expose known failure modes (sarcasm, double negation, emotional ambiguity, structural ambiguity), run live through the model
- Metrics panel — accuracy, F1, and an interactive confusion matrix from held-out test evaluation
- Token counter — real-time token count with truncation warning at the 512-token DistilBERT limit
Model
The model outputs POSITIVE / NEGATIVE with a confidence score. Known limitations include sarcasm (high-confidence failures), complex negation, and out-of-domain text (trained on movie reviews only).
A 25000-sample variant (FrancescoConte/FC_finetuning-sentiment-model-sst2-25000-samples) is also available on the Hub. It scores ~2 points higher on aggregate metrics but shows the same lexical biases on adversarial edge cases (at the expense of a 10x computing time). This build is kept light to allow for testing with computers without GPU capabilities.
Run locally
pip install -r requirements-app.txt
streamlit run app.pyRun with Docker
docker build -t sentiment-app .
docker run -p 8501:8501 sentiment-appRe-train
Requires a Hugging Face account with write access.
pip install -r requirements.txt
python train.py --model distilbert-base-uncased-finetuned-sst-2-english --dataset imdb --samples 3000 --epochs 2 --repo your-repo-name
# Scale up to full IMDB with --samples 25000After training, run evaluation to regenerate metrics.json:
python evaluate_model.pyStack
Python · Hugging Face Transformers · Streamlit · Docker · Hugging Face Spaces · Plotly
