Amazon Review Sentiment: TF-IDF + Logistic Regression

A small, fast sentiment classifier for product reviews: negative / neutral / positive. Built by Hamza Shabbir & Yasaman Najafi Jozani (Ironhack AI Engineering, Project 4).

What is inside

File What it is
sentiment_model.joblib scikit-learn Pipeline: text cleaning -> TF-IDF (1-2 word n-grams, 50,000 features) -> Logistic Regression (class_weight="balanced", C=10)
text_cleaning.py the cleaning step (lowercase, letters only, stopwords removed but "not", "no", "too" kept)
requirements.txt library versions used for training

Training data

Consumer Reviews of Amazon Products (Datafiniti, 1429_1.csv), 27,863 cleaned reviews. Input = review title + ". " + review text. Labels: 1-2 stars negative, 3 neutral, 4-5 positive. Split 70% train / 30% test, stratified, random_state=42.

Results (8,359 test reviews)

Metric Score
Accuracy 0.925
Macro-F1 0.605
F1 negative 0.495
F1 neutral 0.355
F1 positive 0.966

How to use

import os, sys, joblib
from huggingface_hub import hf_hub_download

REPO = "hamza-shabbir94/amazon-review-sentiment-analysis"
model_path = hf_hub_download(REPO, "sentiment_model.joblib")
clean_path = hf_hub_download(REPO, "text_cleaning.py")
sys.path.insert(0, os.path.dirname(clean_path))   # the pipeline imports text_cleaning
model = joblib.load(model_path)
print(model.predict(["Battery died after two days, very disappointed."]))

Limitations

  • Trained almost only on Amazon devices (Kindle, Fire, Echo).
  • Weak on neutral (mixed 3-star) reviews. A pretrained transformer (cardiffnlp/twitter-roberta-base-sentiment-latest) handles unseen negative wording better.
  • .joblib files are Python pickles: only load them from sources you trust.
Downloads last month
-
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support