CoolFace
Modelpublic

balaaathi/sentiment-analysis-model

sourceHugging Faceapache-2.0updated 9mo agoView on Hugging Face
0likes10downloads
Model Card

DistilBERT Sentiment Analysis Model

This model is a fine-tuned version of distilbert-base-uncased for 2-class sentiment analysis (Positive, Negative) on movie reviews.

๐ŸŽฏ Model Description

  • โ€”Model Type: Text Classification
  • โ€”Base Architecture: DistilBERT (Distilled BERT)
  • โ€”Language: English
  • โ€”Task: Sentiment Analysis
  • โ€”Classes: 2 (Negative, Positive)
  • โ€”Parameters: ~66M
  • โ€”Model Size: ~250MB

๐Ÿš€ Quick Start

Using Transformers Pipeline

python
from transformers import pipeline

# Load the model
classifier = pipeline("sentiment-analysis", 
                     model="your-username/sentiment-analysis-distilbert")

# Single prediction
result = classifier("This movie is fantastic!")
print(result)
# Output: [{'label': 'POSITIVE', 'score': 0.9987}]

# Batch prediction
texts = [
    "Amazing cinematography and great acting!",
    "Boring and predictable storyline.",
    "It was an okay movie, nothing extraordinary."
]
results = classifier(texts)
for text, result in zip(texts, results):
    print(f"Text: {text}")
    print(f"Sentiment: {result['label']} (Confidence: {result['score']:.3f})")

Using AutoModel and AutoTokenizer

python
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

# Load model and tokenizer
model_name = "your-username/sentiment-analysis-distilbert"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)

# Prepare input
text = "This movie exceeded my expectations!"
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)

# Get prediction
with torch.no_grad():
    outputs = model(**inputs)
    predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
    
# Get predicted class
predicted_class = torch.argmax(predictions, dim=-1).item()
confidence = predictions[0][predicted_class].item()

labels = ["NEGATIVE", POSITIVE"]
print(f"Sentiment: {labels[predicted_class]} (Confidence: {confidence:.3f})")

๐Ÿ“Š Training Details

Dataset

  • โ€”Source: IMDB Movie Reviews Dataset
  • โ€”Training Samples: 5,000 (balanced: 1,667 per class)
  • โ€”Evaluation Samples: 1,000
  • โ€”Data Split: 80% train, 20% validation
  • โ€”Preprocessing: Tokenization with DistilBERT tokenizer, max length 256

Training Configuration

  • โ€”Base Model: distilbert-base-uncased
  • โ€”Training Framework: PyTorch + Transformers
  • โ€”Optimizer: AdamW
  • โ€”Learning Rate: 2e-5
  • โ€”Batch Size: 8
  • โ€”Epochs: 3
  • โ€”Warmup Steps: 100
  • โ€”Weight Decay: 0.01
  • โ€”Max Sequence Length: 256 tokens

Hardware

  • โ€”Platform: Google Colab
  • โ€”GPU: Tesla T4 (15GB VRAM)
  • โ€”Training Time: ~30-45 minutes

๐Ÿ“ˆ Performance

MetricScore
Training Accuracy~95%
Validation Accuracy~93%
Training Loss0.12
Validation Loss0.18

Class Distribution

  • โ€”Negative: 33.3% (2500 samples)
  • โ€”Positive: 33.3% (2500 samples)

๐ŸŽฏ Intended Use

Primary Use Cases

  • โ€”Movie Review Analysis: Classify sentiment of movie reviews
  • โ€”Product Review Sentiment: Analyze customer feedback
  • โ€”Social Media Monitoring: Track sentiment in posts and comments
  • โ€”Content Moderation: Identify negative sentiment in user-generated content

Suitable Domains

  • โ€”Entertainment and media reviews
  • โ€”E-commerce product feedback
  • โ€”Social media posts
  • โ€”Customer service interactions
  • โ€”General English text sentiment analysis

โš ๏ธ Limitations and Biases

Known Limitations

  • โ€”Domain Specificity: Primarily trained on movie reviews, may not generalize well to other domains
  • โ€”Language: English only, no multilingual support
  • โ€”Context Length: Limited to 256 tokens, longer texts are truncated
  • โ€”Cultural Bias: May reflect biases present in IMDB dataset

Potential Biases

  • โ€”Genre Bias: May perform differently across movie genres
  • โ€”Temporal Bias: Training data may reflect sentiment patterns from specific time periods
  • โ€”Demographic Bias: May not equally represent all demographic groups' sentiment expressions

Not Recommended For

  • โ€”Non-English text
  • โ€”Highly specialized domains (medical, legal, technical)
  • โ€”Real-time critical applications
  • โ€”Texts longer than 256 tokens without preprocessing
  • โ€”Sarcasm or irony detection

๐Ÿ”ง Technical Specifications

Model Architecture

DistilBERT Base
โ”œโ”€โ”€ Transformer Layers: 6
โ”œโ”€โ”€ Hidden Size: 768
โ”œโ”€โ”€ Attention Heads: 12
โ”œโ”€โ”€ Intermediate Size: 3072
โ””โ”€โ”€ Classification Head: Linear(768 โ†’ 3)

Input Format

  • โ€”Text Encoding: UTF-8
  • โ€”Tokenization: WordPiece
  • โ€”Special Tokens: [CLS], [SEP]
  • โ€”Max Length: 256 tokens
  • โ€”Padding: Right padding with [PAD] tokens

Output Format

python
{
    'label': 'POSITIVE',  # One of: NEGATIVE, POSITIVE
    'score': 0.9987       # Confidence score (0-1)
}

๐Ÿ“ Citation

If you use this model in your research or applications, please cite:

bibtex
@misc{sentiment-analysis-distilbert,
  title={Fine-tuned DistilBERT for Sentiment Analysis},
  author={Your Name},
  year={2024},
  publisher={Hugging Face},
  url={https://huggingface.co/your-username/sentiment-analysis-distilbert}
}

๐Ÿ“„ License

This model is released under the Apache 2.0 License. See the LICENSE file for details.

๐Ÿค Contributing

Issues and pull requests are welcome! Please feel free to:

  • โ€”Report bugs or issues
  • โ€”Suggest improvements
  • โ€”Share your use cases
  • โ€”Contribute to documentation

๐Ÿ™ Acknowledgments

  • โ€”Hugging Face for the Transformers library and model hosting
  • โ€”Google Research for the original BERT and DistilBERT models
  • โ€”Stanford AI Lab for the IMDB dataset
  • โ€”Google Colab for providing free GPU resources for training

This model was created as part of a sentiment analysis fine-tuning project using modern NLP techniques and best practices.