Instructions to use iankamar/amazon-food-sentiment-models with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Scikit-learn
How to use iankamar/amazon-food-sentiment-models with Scikit-learn:
from huggingface_hub import hf_hub_download import joblib model = joblib.load( hf_hub_download("iankamar/amazon-food-sentiment-models", "sklearn_model.joblib") ) # only load pickle files from sources you trust # read more about it here https://skops.readthedocs.io/en/stable/persistence.html - Notebooks
- Google Colab
- Kaggle
Amazon Food Sentiment Models
Bag-of-words and TF-IDF logistic regression models, each trained with and without balanced class weights.
Results
| Model | Test accuracy | Test macro F1 | Test ROC AUC |
|---|---|---|---|
| Bag of words | 93.12% | 0.8682 | 0.9581 |
| Bag of words balanced | 93.05% | 0.8750 | 0.9574 |
| TF-IDF | 92.06% | 0.8290 | 0.9663 |
| TF-IDF balanced | 91.76% | 0.8644 | 0.9683 |
The default, Bag of words balanced, is selected by validation macro F1, not test results. The constant training-majority baseline has test accuracy 83.69% and macro F1 0.4556.
Data and evaluation
The source has 568,454 reviews. Three-star reviews are excluded. After normalization, 30 conflicting-label rows and 162,446 duplicate rows are removed. A uniform 60,000-review sample is selected from the 363,338 remaining non-neutral reviews using seed 42. The chronological split, with whole-day boundaries, contains 41,973 training, 9,020 validation, and 9,007 test reviews.
Both vectorizers are fitted only on training text. Features include unigrams and bigrams, with a 20,000-feature cap and minimum document frequency 3. Logistic regression uses C=1, liblinear, and a fixed 0.5 decision threshold. The comparison uses class weighting, not synthetic reviews or SMOTE. Reviews from the same product may appear in different time partitions; this is not a new-product generalization test.
Run
Use Python 3.12 and obtain Reviews.csv from Kaggle.
python -m pip install -r requirements.txt
python train.py --csv path/to/Reviews.csv
To use a saved pipeline:
import joblib
from preprocessing import clean_text
models = joblib.load("models.joblib")
model = models["Bag of words balanced"]
print(model.predict_proba([clean_text("The flavor was excellent and delivery was quick.")]))
The output columns are negative and positive. Load joblib files only from trusted sources. metrics.json records the source hash, split IDs, and evaluation; test-predictions.npz supports metric checks. Raw reviews are not redistributed.
Data credit: Stanford SNAP Fine Foods, Julian McAuley and Jure Leskovec; preserve the original data terms. Results describe sentiment prediction, not causal drivers of satisfaction. This update fixes the original full-data vocabulary fit and adds the actual TF-IDF comparison.
- Downloads last month
- -