CoolFace
Modelpublic

balaaathi/sentiment-analysis-model

sourceHugging Faceapache-2.0updated 9mo agoView on Hugging Face
0likes10downloads
README.md227 linesDownload Raw Back to root
1---2license: apache-2.03base_model: distilbert-base-uncased4tags:5- sentiment-analysis6- text-classification7- pytorch8- distilbert9- fine-tuned10datasets:11- imdb12language:13- en14pipeline_tag: text-classification15widget:16- text: "This movie is absolutely amazing! I loved every minute of it."17  example_title: "Positive Example"18- text: "Terrible film, complete waste of time and money."19  example_title: "Negative Example"20---21 22# DistilBERT Sentiment Analysis Model23 24This model is a fine-tuned version of [distilbert-base-uncased](https://huggingface.co/distilbert-base-uncased) for **2-class sentiment analysis** (Positive, Negative) on movie reviews.25 26## ๐ŸŽฏ Model Description27 28- **Model Type:** Text Classification29- **Base Architecture:** DistilBERT (Distilled BERT)30- **Language:** English31- **Task:** Sentiment Analysis32- **Classes:** 2 (Negative, Positive)33- **Parameters:** ~66M34- **Model Size:** ~250MB35 36## ๐Ÿš€ Quick Start37 38### Using Transformers Pipeline39 40```python41from transformers import pipeline42 43# Load the model44classifier = pipeline("sentiment-analysis", 45                     model="your-username/sentiment-analysis-distilbert")46 47# Single prediction48result = classifier("This movie is fantastic!")49print(result)50# Output: [{'label': 'POSITIVE', 'score': 0.9987}]51 52# Batch prediction53texts = [54    "Amazing cinematography and great acting!",55    "Boring and predictable storyline.",56    "It was an okay movie, nothing extraordinary."57]58results = classifier(texts)59for text, result in zip(texts, results):60    print(f"Text: {text}")61    print(f"Sentiment: {result['label']} (Confidence: {result['score']:.3f})")62```63 64### Using AutoModel and AutoTokenizer65 66```python67from transformers import AutoTokenizer, AutoModelForSequenceClassification68import torch69 70# Load model and tokenizer71model_name = "your-username/sentiment-analysis-distilbert"72tokenizer = AutoTokenizer.from_pretrained(model_name)73model = AutoModelForSequenceClassification.from_pretrained(model_name)74 75# Prepare input76text = "This movie exceeded my expectations!"77inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)78 79# Get prediction80with torch.no_grad():81    outputs = model(**inputs)82    predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)83    84# Get predicted class85predicted_class = torch.argmax(predictions, dim=-1).item()86confidence = predictions[0][predicted_class].item()87 88labels = ["NEGATIVE", POSITIVE"]89print(f"Sentiment: {labels[predicted_class]} (Confidence: {confidence:.3f})")90```91 92## ๐Ÿ“Š Training Details93 94### Dataset95- **Source:** IMDB Movie Reviews Dataset96- **Training Samples:** 5,000 (balanced: 1,667 per class)97- **Evaluation Samples:** 1,00098- **Data Split:** 80% train, 20% validation99- **Preprocessing:** Tokenization with DistilBERT tokenizer, max length 256100 101### Training Configuration102- **Base Model:** `distilbert-base-uncased`103- **Training Framework:** PyTorch + Transformers104- **Optimizer:** AdamW105- **Learning Rate:** 2e-5106- **Batch Size:** 8107- **Epochs:** 3108- **Warmup Steps:** 100109- **Weight Decay:** 0.01110- **Max Sequence Length:** 256 tokens111 112### Hardware113- **Platform:** Google Colab114- **GPU:** Tesla T4 (15GB VRAM)115- **Training Time:** ~30-45 minutes116 117## ๐Ÿ“ˆ Performance118 119| Metric | Score |120|--------|-------|121| Training Accuracy | ~95% |122| Validation Accuracy | ~93% |123| Training Loss | 0.12 |124| Validation Loss | 0.18 |125 126### Class Distribution127- **Negative:** 33.3% (2500 samples)128- **Positive:** 33.3% (2500 samples)129 130## ๐ŸŽฏ Intended Use131 132### Primary Use Cases133- **Movie Review Analysis:** Classify sentiment of movie reviews134- **Product Review Sentiment:** Analyze customer feedback135- **Social Media Monitoring:** Track sentiment in posts and comments136- **Content Moderation:** Identify negative sentiment in user-generated content137 138### Suitable Domains139- Entertainment and media reviews140- E-commerce product feedback141- Social media posts142- Customer service interactions143- General English text sentiment analysis144 145## โš ๏ธ Limitations and Biases146 147### Known Limitations148- **Domain Specificity:** Primarily trained on movie reviews, may not generalize well to other domains149- **Language:** English only, no multilingual support150- **Context Length:** Limited to 256 tokens, longer texts are truncated151- **Cultural Bias:** May reflect biases present in IMDB dataset152 153### Potential Biases154- **Genre Bias:** May perform differently across movie genres155- **Temporal Bias:** Training data may reflect sentiment patterns from specific time periods156- **Demographic Bias:** May not equally represent all demographic groups' sentiment expressions157 158### Not Recommended For159- Non-English text160- Highly specialized domains (medical, legal, technical)161- Real-time critical applications162- Texts longer than 256 tokens without preprocessing163- Sarcasm or irony detection164 165## ๐Ÿ”ง Technical Specifications166 167### Model Architecture168```169DistilBERT Base170โ”œโ”€โ”€ Transformer Layers: 6171โ”œโ”€โ”€ Hidden Size: 768172โ”œโ”€โ”€ Attention Heads: 12173โ”œโ”€โ”€ Intermediate Size: 3072174โ””โ”€โ”€ Classification Head: Linear(768 โ†’ 3)175```176 177### Input Format178- **Text Encoding:** UTF-8179- **Tokenization:** WordPiece180- **Special Tokens:** [CLS], [SEP]181- **Max Length:** 256 tokens182- **Padding:** Right padding with [PAD] tokens183 184### Output Format185```python186{187    'label': 'POSITIVE',  # One of: NEGATIVE, POSITIVE188    'score': 0.9987       # Confidence score (0-1)189}190```191 192## ๐Ÿ“ Citation193 194If you use this model in your research or applications, please cite:195 196```bibtex197@misc{sentiment-analysis-distilbert,198  title={Fine-tuned DistilBERT for Sentiment Analysis},199  author={Your Name},200  year={2024},201  publisher={Hugging Face},202  url={https://huggingface.co/your-username/sentiment-analysis-distilbert}203}204```205 206## ๐Ÿ“„ License207 208This model is released under the Apache 2.0 License. See the [LICENSE](LICENSE) file for details.209 210## ๐Ÿค Contributing211 212Issues and pull requests are welcome! Please feel free to:213- Report bugs or issues214- Suggest improvements215- Share your use cases216- Contribute to documentation217 218## ๐Ÿ™ Acknowledgments219 220- **Hugging Face** for the Transformers library and model hosting221- **Google Research** for the original BERT and DistilBERT models222- **Stanford AI Lab** for the IMDB dataset223- **Google Colab** for providing free GPU resources for training224 225---226 227*This model was created as part of a sentiment analysis fine-tuning project using modern NLP techniques and best practices.*