YAML Metadata Warning:empty or missing yaml metadata in repo card

Check out the documentation for more information.

# 🎬 Movie Review Sentiment Analyzer

> Fine-tuned FLAN-T5 for binary sentiment classification on movie reviews.

![Accuracy](https://img.shields.io/badge/Accuracy-96.00%25-brightgreen)
![F1 Score](https://img.shields.io/badge/F1%20Score-0.9596-brightgreen)
![Model](https://img.shields.io/badge/Model-FLAN--T5%20Base-blue)
![Dataset](https://img.shields.io/badge/Dataset-IMDB%2050K-blue)
![Python](https://img.shields.io/badge/Python-3.10+-yellow)

---

## πŸ“‹ Overview

This project fine-tunes Google's **FLAN-T5 Base** model on the Stanford IMDB dataset to classify movie reviews as **positive** or **negative**. It includes a full ML pipeline from dataset analysis to a deployed interactive web application.

| | Baseline | Fine-tuned | Improvement |
|---|---|---|---|
| **Accuracy** | 93.50% | **96.00%** | +2.50% βœ… |
| **F1 Score** | 0.9372 | **0.9596** | +0.0224 βœ… |

---

## πŸ—‚οΈ Project Structure

sentiment-analysis/ β”‚ β”œβ”€β”€ πŸ““ 1_dataset_analysis.ipynb # Exploratory data analysis β”œβ”€β”€ πŸ““ 2_baseline_evaluation.ipynb # Zero-shot FLAN-T5 evaluation β”œβ”€β”€ πŸ““ 3_finetuning.ipynb # Model fine-tuning β”œβ”€β”€ πŸ““ 4_posttuning_evaluation.ipynb # Post-tuning evaluation & comparison β”œβ”€β”€ πŸ““ 5_app.ipynb # Dashboard HTML generation β”œβ”€β”€ 🐍 server.py # FastAPI inference server β”œβ”€β”€ 🌐 dashboard.html # Interactive web dashboard β”œβ”€β”€ πŸ“Š baseline_metrics.json # Baseline results β”œβ”€β”€ πŸ“Š finetuned_metrics.json # Fine-tuned results └── πŸ–ΌοΈ *.png # Generated charts


---

## πŸš€ Quick Start

### 1. Clone the repository
```bash
git clone https://github.com/TerryPotato/clasificador-rese-as-ia.git
cd sentiment-analysis

2. Create and activate virtual environment

python -m venv sentiment_env
sentiment_env\Scripts\activate  # Windows
source sentiment_env/bin/activate  # Mac/Linux

3. Install dependencies

pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128
pip install transformers datasets evaluate accelerate scikit-learn
pip install pandas matplotlib seaborn jupyter
pip install fastapi uvicorn python-multipart

4. Download the fine-tuned model

The model is hosted on HuggingFace Hub. Download it by running this in Python:

from huggingface_hub import snapshot_download
snapshot_download(repo_id="TerryPotato/sentiment-analysis-ai", local_dir="./flan-t5-sentiment-model")

5. Start the server

uvicorn server:app --host 0.0.0.0 --port 8000

6. Open the dashboard

Open dashboard.html in your browser. The green dot confirms the server is online βœ…


🧠 Model Details

Feature Value
Base Model google/flan-t5-base
Parameters 250M
Task Binary Sentiment Classification
Input Movie review text (English)
Output "positive" or "negative"
Max Input Length 512 tokens

πŸ”§ Fine-tuning Techniques

Technique Purpose
Early Stopping (patience=2) Stops training when Validation Loss stops improving, prevents overfitting
Cosine LR Scheduler Gradually reduces learning rate for more stable convergence
Gradient Clipping (max_norm=1.0) Prevents exploding gradients during backpropagation
BF16 Precision Faster training on modern GPUs with numerical stability

πŸ“Š Training Results

Epoch Training Loss Validation Loss Status
1 0.1694 0.2474 Decreasing
2 0.0632 0.1743 Decreasing
3 0.0480 0.1450 ⭐ Best Model
4 0.0256 0.1639 Overfitting
5 0.0261 0.1924 πŸ›‘ Early Stop

πŸ“¦ Dataset

Feature Value
Name Stanford IMDB Large Movie Review Dataset
Source stanfordnlp/imdb on HuggingFace
Total Reviews 50,000
Class Balance 50% positive / 50% negative
Language English
Used for Fine-tuning 2,000 reviews (balanced)

πŸ’» Hardware Used

Component Spec
GPU NVIDIA RTX 5060 Ti
CPU AMD Ryzen 5 9600X
RAM 32 GB
Training Time ~15 minutes

πŸ“ Notebooks Guide

Notebook Description
1_dataset_analysis.ipynb Load IMDB dataset, visualize class distribution, word frequency, review lengths
2_baseline_evaluation.ipynb Evaluate FLAN-T5 without fine-tuning on 200 balanced reviews
3_finetuning.ipynb Fine-tune with Early Stopping, Cosine LR, Gradient Clipping
4_posttuning_evaluation.ipynb Compare baseline vs fine-tuned metrics with charts
5_app.ipynb Generate the interactive HTML dashboard

πŸ–₯️ Application

The web dashboard includes 4 tabs:

  • πŸ“ Analyze β€” Submit any review and get real-time sentiment prediction from the model
  • πŸ“Š Metrics β€” Baseline vs Fine-tuned comparison with charts and technique descriptions
  • πŸ“ˆ Training β€” Epoch-by-epoch loss table and training curve visualization
  • πŸ” Dataset β€” IMDB dataset statistics and exploratory analysis charts

πŸ“š References

  • Maas et al. (2011). Learning word vectors for sentiment analysis. ACL.
  • Chung et al. (2022). Scaling instruction-finetuned language models. arXiv:2210.11416.
  • Wolf et al. (2020). Transformers: State-of-the-art NLP. EMNLP.

---
Downloads last month
3
Safetensors
Model size
0.2B params
Tensor type
F32
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Paper for TerryPotato/sentiment-analysis-ai