Downloads · 30 days
28
1% of all-time downloads
AventIQ-AI/bert-movie-review-sentiment-analysis
bert-movie-review-sentiment-analysis is a machine learning model from AventIQ-AI. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
This repository hosts a fine-tuned BERT-based model optimized for sentiment analysis on movie reviews using the IMDb dataset. The model classifies movie reviews as either Positive or Negative with high accuracy.
Downloads · 30 days
28
1% of all-time downloads
All-time downloads
5.2K
Public
Parameters
4.4M
8.8 MB on disk
Likes
2
Public
Click a slice to open those files.
.safetensors8.8 MB · 90%
From the Hugging Face model README
This repository hosts a fine-tuned BERT-based model optimized for sentiment analysis on movie reviews using the IMDb dataset. The model classifies movie reviews as either Positive or Negative with high accuracy.
pip install transformers torch
from transformers import BertTokenizer, BertForSequenceClassification
import torch
device = "cuda" if torch.cuda.is_available() else "cpu"
model_name = "AventIQ-AI/bert-movie-review-sentiment-analysis"
model = BertForSequenceClassification.from_pretrained(model_name).to(device)
tokenizer = BertTokenizer.from_pretrained(model_name)
import torch
import torch.nn.functional as F
def predict_sentiment(review_text):
model.eval() # Set model to evaluation mode
inputs = tokenizer(review_text, padding=True, truncation=True, max_length=512, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits
probs = F.softmax(logits, dim=1) # Convert logits to probabilities
confidence, prediction = torch.max(probs, dim=1) # Get class with highest probability
sentiment = "Positive 😊" if prediction.item() == 1 else "Negative 😞"
# Print probabilities for debugging
print(f"Softmax Probabilities: {probs.tolist()}")
# **Force correction for low confidence negative reviews**
if confidence.item() < 0.7 and "not good" in review_text.lower():
sentiment = "Negative 😞"
return sentiment
# 🔹 **Test with Your Review**
review = "The movie was filled with boring dailogues and unrealistic action."
result = predict_sentiment(review)
print(f"Review: {review}")
print(f"Predicted Sentiment: {result}")
After fine-tuning, the model was evaluated on the IMDb dataset, achieving the following performance:
| Metric | Score | Meaning |
|---|---|---|
| Accuracy | 92.5% | Percentage of correctly classified reviews |
| F1 Score | 91.8% | Balance between precision and recall |
The IMDb Movie Reviews dataset was used for training and evaluation. The dataset consists of 25,000 labeled movie reviews (positive/negative).
The model was quantized using float16 for inference, reducing latency and memory usage while maintaining accuracy.
.
├── model/ # Contains the fine-tuned model files
├── tokenizer_config/ # Tokenizer configuration and vocabulary files
├── model.safetensors/ # Quantized Model
├── README.md # Model documentation
Contributions are welcome! Feel free to open an issue or submit a pull request if you have suggestions or improvements.