Commit ·
3087ede
1
Parent(s): 5a2ee52
Enhance README.md with detailed model description, usage examples, metrics, limitations, and training data for the IMDb sentiment analysis model.
Browse files
README.md
CHANGED
|
@@ -1,37 +1,103 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
|
| 5 |
-
## Model
|
| 6 |
-
- Logistic Regression: ~88.47% accuracy
|
| 7 |
-
- Naive Bayes: ~85.2% accuracy
|
| 8 |
|
| 9 |
-
|
| 10 |
-
-
|
| 11 |
-
- `inference.py`: Script for making predictions
|
| 12 |
-
- `train_and_save_model.py`: Script to train and save models
|
| 13 |
-
- `requirements.txt`: Python dependencies
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
### Load and Use the Model
|
| 18 |
```python
|
| 19 |
from inference import SentimentAnalyzer
|
| 20 |
|
| 21 |
-
# Initialize analyzer
|
| 22 |
-
analyzer = SentimentAnalyzer()
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
|
|
|
|
| 26 |
print(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
```
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
|
| 35 |
-
-
|
| 36 |
-
- **Preprocessing**: Lowercase, special char removal, tokenization, stopword removal, lemmatization
|
| 37 |
-
- **Models**: Logistic Regression and Naive Bayes
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: en
|
| 3 |
+
license: mit
|
| 4 |
+
tags:
|
| 5 |
+
- sentiment-analysis
|
| 6 |
+
- text-classification
|
| 7 |
+
- imdb
|
| 8 |
+
- scikit-learn
|
| 9 |
+
- tfidf
|
| 10 |
+
- logistic-regression
|
| 11 |
+
- naive-bayes
|
| 12 |
+
model-index:
|
| 13 |
+
- name: imdb-movie-review-sentiment-analysis
|
| 14 |
+
results:
|
| 15 |
+
- task:
|
| 16 |
+
type: text-classification
|
| 17 |
+
name: Sentiment Analysis
|
| 18 |
+
dataset:
|
| 19 |
+
name: IMDb Large Movie Review Dataset
|
| 20 |
+
type: imdb
|
| 21 |
+
metrics:
|
| 22 |
+
- type: accuracy
|
| 23 |
+
value: 0.8847
|
| 24 |
+
name: Logistic Regression Accuracy
|
| 25 |
+
- type: accuracy
|
| 26 |
+
value: 0.8520
|
| 27 |
+
name: Naive Bayes Accuracy
|
| 28 |
+
---
|
| 29 |
|
| 30 |
+
# IMDb Movie Review Sentiment Analysis
|
| 31 |
|
| 32 |
+
## Model description
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
**imdb-movie-review-sentiment-analysis** is a machine learning model that predicts the sentiment (positive or negative) of movie reviews from IMDb.
|
| 35 |
+
It uses a TF-IDF vectorizer for feature extraction and an ensemble of two classic machine learning classifiers: Logistic Regression and Multinomial Naive Bayes.
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
The model was trained on the official IMDb Large Movie Review Dataset (50,000 labeled reviews) with standard NLP preprocessing: lowercasing, special character removal, tokenization, stopword removal, and lemmatization.
|
| 38 |
+
|
| 39 |
+
**Intended use:**
|
| 40 |
+
- Sentiment analysis of English-language movie reviews
|
| 41 |
+
- Educational and research purposes
|
| 42 |
+
- As a baseline for more advanced NLP projects
|
| 43 |
+
|
| 44 |
+
---
|
| 45 |
+
|
| 46 |
+
## Example usage
|
| 47 |
|
|
|
|
| 48 |
```python
|
| 49 |
from inference import SentimentAnalyzer
|
| 50 |
|
| 51 |
+
# Initialize the analyzer (make sure model files are in 'saved_models/')
|
| 52 |
+
analyzer = SentimentAnalyzer(model_dir="saved_models")
|
| 53 |
|
| 54 |
+
# Predict sentiment for a new review
|
| 55 |
+
review = "This movie was absolutely fantastic! I loved every minute of it."
|
| 56 |
+
result = analyzer.predict(review)
|
| 57 |
print(result)
|
| 58 |
+
# Output example:
|
| 59 |
+
# {
|
| 60 |
+
# 'logistic_regression': {'prediction': 'positive', 'confidence': 0.98, ...},
|
| 61 |
+
# 'naive_bayes': {'prediction': 'positive', 'confidence': 0.95, ...}
|
| 62 |
+
# }
|
| 63 |
```
|
| 64 |
|
| 65 |
+
---
|
| 66 |
+
|
| 67 |
+
## Metrics
|
| 68 |
+
|
| 69 |
+
- **Logistic Regression Accuracy:** 88.47%
|
| 70 |
+
- **Naive Bayes Accuracy:** 85.20%
|
| 71 |
+
- Evaluated on a held-out test set (20% of the IMDb dataset, 10,000 reviews).
|
| 72 |
+
|
| 73 |
+
---
|
| 74 |
+
|
| 75 |
+
## Limitations
|
| 76 |
+
|
| 77 |
+
- Only works for **English** text.
|
| 78 |
+
- Not robust to sarcasm, irony, or highly ambiguous reviews.
|
| 79 |
+
- May not generalize well to domains outside of movie reviews.
|
| 80 |
+
- Does not handle emojis, slang, or non-standard text well.
|
| 81 |
+
- Classic ML models (not deep learning): may underperform on very complex language.
|
| 82 |
+
|
| 83 |
+
---
|
| 84 |
+
|
| 85 |
+
## Training data
|
| 86 |
+
|
| 87 |
+
- **IMDb Large Movie Review Dataset**: 50,000 movie reviews labeled as positive or negative.
|
| 88 |
+
- Balanced: 25,000 positive and 25,000 negative reviews.
|
| 89 |
+
- Reviews are preprocessed (lowercased, cleaned, tokenized, stopwords removed, lemmatized).
|
| 90 |
+
- Dataset is widely used for benchmarking sentiment analysis models.
|
| 91 |
+
|
| 92 |
+
---
|
| 93 |
+
|
| 94 |
+
## License
|
| 95 |
+
|
| 96 |
+
MIT
|
| 97 |
+
|
| 98 |
+
---
|
| 99 |
+
|
| 100 |
+
## Author
|
| 101 |
|
| 102 |
+
Abdelmonem Hatem
|
| 103 |
+
---
|
|
|
|
|
|