Fine-tuned distilbert-base-uncased that classifies an Amazon food review as Negative, Neutral, or Positive.
Built by Group Psi for the CSE 3521 (Survey of Artificial Intelligence) group project at The Ohio State University, Autumn 2026. Project repository: https://github.com/ColinWenzel24/amazon-food-review-sentiment-analysis
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
name = "thekluna/amazon-food-sentiment-distilbert"
tokenizer = AutoTokenizer.from_pretrained(name)
model = AutoModelForSequenceClassification.from_pretrained(name)
text = "Not soft cookies at all. These were very hard and dry."
inputs = tokenizer(text, truncation=True, max_length=256, return_tensors="pt")
with torch.no_grad():
probs = torch.softmax(model(**inputs).logits, dim=-1)[0]
print({model.config.id2label[i]: round(p.item(), 3) for i, p in enumerate(probs)})
For best results, format the input like the training data: the review summary followed by a space and the review text, with HTML tags (e.g. <br />) removed.
| Setting | Value |
|---|---|
| Max sequence length | 256 tokens |
| Batch size | 32 |
| Epochs | 2 |
| Optimizer | AdamW, learning rate 3e-5, weight decay 0.01 |
| Schedule | Linear warmup (10% of steps), then linear decay |
| Loss | Cross-entropy with balanced class weights (to counter class imbalance) |
| Precision | Mixed (fp16) |
| Checkpoint | Best validation macro-F1 (evaluated every 200 steps) |
| Hardware / time | AMD Radeon RX 9070 XT (ROCm), 3.6 minutes |
| Metric | Score |
|---|---|
| Accuracy | 0.8835 |
| Macro precision | 0.7299 |
| Macro recall | 0.7864 |
| Macro F1 | 0.7482 |
| Majority-class baseline accuracy (always "Positive") | 0.7795 |
| Class | Precision | Recall | F1 | Support |
|---|---|---|---|---|
| Negative | 0.808 | 0.784 | 0.796 | 1,331 |
| Neutral | 0.403 | 0.650 | 0.498 | 709 |
| Positive | 0.978 | 0.925 | 0.951 | 7,213 |