Downloads · 30 days
21
13% of all-time downloads
YousefXEisa/amazon-roberta-sentiment
amazon-roberta-sentiment is a text classification model from YousefXEisa. Use it when you need a label for a piece of text. It is set up for transformers. The card lists the license as mit.
A fine-tuned RoBERTa-base model that classifies Amazon product reviews as Positive or Negative.
Downloads · 30 days
21
13% of all-time downloads
All-time downloads
167
Public
Parameters
125M
499 MB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors499 MB · 99%
From the Hugging Face model README
A fine-tuned RoBERTa-base model that classifies Amazon product reviews as Positive or Negative.
This model is a fine-tuned version of roberta-base trained on the Amazon Polarity dataset for binary sentiment classification (Positive / Negative). The title and content fields of each review were used jointly as model input.
The final model was selected after three training experiments comparing architectures and regularization strategies — see Training Details below. (Or the full details of the experiment, including all three rounds, on GitHub).
roberta-baseThe model takes a review's title and body text and outputs a sentiment label (Positive / Negative) with a confidence score. It can be used directly for classifying Amazon-style product reviews, or similar English-language e-commerce review text.
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model_name = "YousefXEisa/amazon-roberta-sentiment"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
text = "This product is absolutely amazing! Very high quality."
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
with torch.no_grad():
logits = model(**inputs).logits
probs = torch.softmax(logits, dim=-1)
label = "Positive" if probs.argmax().item() == 1 else "Negative"
print(label, probs)
Or with the pipeline API:
from transformers import pipeline
classifier = pipeline("text-classification", model="YousefXEisa/amazon-roberta-sentiment")
classifier("Terrible quality. Arrived broken and stopped working.")
Amazon Polarity — Amazon product reviews labeled Positive/Negative. title and content were concatenated as input.
The final model (RoBERTa-base) was trained in fp32 on 250k samples for 3 epochs (early stopping enabled), with the following regularization recipe, arrived at after diagnosing overfitting in an initial BERT baseline run:
max_norm=1.0)Training was run on Google Colab (free GPU tier).
Evaluated on a held-out test set of 10,000 samples, unseen during training or validation.
| Metric | Score |
|---|---|
| Accuracy | 0.9697 |
| Precision | 0.9671 |
| Recall | 0.9730 |
| F1 Score | 0.9700 |
Classification Report:
precision recall f1-score support
0 0.97 0.97 0.97 4958
1 0.97 0.97 0.97 5042
accuracy 0.97 10000
macro avg 0.97 0.97 0.97 10000
weighted avg 0.97 0.97 0.97 10000
RoBERTa outperformed a comparably-regularized BERT baseline (best val F1 0.9674 vs 0.9590) trained under identical conditions, which is why RoBERTa was selected as the final model.
If you use this model, please reference the Hugging Face repo:
YousefXEisa/amazon-roberta-sentiment