CoolFace
Apppublic

FrancescoConte/Sentiment_analysis_app

sourceHugging Facegplupdated 1mo agoView on Hugging Face
0likes
App README

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:

![Live demo](https://huggingface.co/spaces/FrancescoConte/Sentimentanalysisapp)


Results

Evaluated on 3,000 held-out IMDB test samples:

MetricScore
Accuracy91.27%
F10.9132

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

Basedistilbert-base-uncased-finetuned-sst-2-english
DatasetIMDB (3,000 train / 3,000 test samples)
Training2 epochs · lr=2e-5 · batch size=16
Hosted`FrancescoConte/FC_finetuning-sentiment-model-3000-samples`

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

bash
pip install -r requirements-app.txt
streamlit run app.py

Run with Docker

bash
docker build -t sentiment-app .
docker run -p 8501:8501 sentiment-app

Re-train

Requires a Hugging Face account with write access.

bash
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 25000

After training, run evaluation to regenerate metrics.json:

bash
python evaluate_model.py

Stack

Python · Hugging Face Transformers · Streamlit · Docker · Hugging Face Spaces · Plotly