Built to order

Customer Review Sentiment Analysis using BERT (Amazon Product Reviews)

This project fine-tunes BERT-base on Amazon product reviews to classify each review as positive or negative, and ships a working web app where any review text can be pasted in and scored with per-class probabilities. The training notebook documents tokenization, fine-tuning and evaluation on the Amazon polarity dataset, so the full pipeline can be explained and defended. A browser demo of the same pipeline is included for live demonstration. Suitable for B.E./B.Tech final-year projects in AI & Machine Learning and Computer Science.

AI & Machine Learning PythonJupyter notebookGitHTML · CSS · JavaScript demobert-base-uncasedPyTorch · Hugging Face TransformersAmazon polarity datasetSoftware
Customer Review Sentiment Analysis using BERT (Amazon Product Reviews) — project thumbnail preview
More project photos (2)

The problem

Customer Review Sentiment Analysis using BERT (Amazon Product Reviews) is a text-classification project that fine-tunes the BERT-base language model on Amazon product reviews so that any review can be classified as positive or negative with a confidence score. Online shoppers write millions of product reviews, and sellers, brands and researchers need a reliable way to read that feedback at scale instead of sampling reviews by hand. Manual reading is slow, inconsistent between readers, and impossible once review counts reach thousands. This project solves that reading problem with a transformer model that understands word meaning in context: BERT reads every word together with the words around it, so phrases like "not good" and "battery drains fast" are judged by their full sentence meaning rather than by single keywords. The shipped system includes the fine-tuning notebook, the trained model, an evaluation report and a web app where review text can be pasted in and scored live.

SYSTEM FLOW

5 components 4 connections

Live flow
Drag to explore
100%
userProduct review

A typed or pasted Amazon product review enters the scoring web app.

How it works

Every review passes through the same four-stage pipeline, from raw text to a sentiment label. First, the review text is cleaned and split into WordPiece tokens, the subword units BERT was pre-trained on, with a special classification token placed at the start and padding added to a fixed length of 256 tokens. Next, the token sequence passes through BERT's 12 transformer layers, where self-attention lets each word gather meaning from the words on both sides of it, so negation and context change the representation instead of being ignored. The vector produced for the classification token is then passed through a small classification head that outputs two scores, one per class. Finally, a softmax turns those scores into probabilities, and the higher-probability class becomes the predicted label, with the probability shown as the model's confidence.

  1. Amazon polarity reviews are loaded and labelled by star rating: 1–2 stars become negative, 4–5 stars become positive, and 3-star reviews are set aside.
  2. A stratified sample of the training split is drawn and split into train and validation sets, keeping the positive/negative balance identical in both.
  3. Each review is cleaned and WordPiece-tokenized, truncated or padded to 256 tokens, with attention masks marking the real tokens.
  4. BERT-base uncased is loaded with a two-class classification head and fine-tuned with AdamW and cross-entropy loss, with validation accuracy checked after each epoch and the best checkpoint kept.
  5. The held-out test split is evaluated once: accuracy, per-class precision/recall/F1 and the confusion matrix are generated for the report.
  6. In the web app, a pasted review is scored and shown with its label, confidence, per-class probabilities and word-level highlights; the browser demo uses the transparent lexicon scorer, while the notebook runs the fine-tuned BERT model itself.

Tech stack:

  • Python 3, PyTorch
  • Hugging Face Transformers (BERT-base uncased)
  • Amazon polarity dataset
  • Jupyter Notebook (training & evaluation)
  • scikit-learn (metrics)
  • HTML · CSS · JavaScript (review-scoring demo)
  • NumPy, pandas (data handling)
  • Git

Dataset & model details

  • Dataset: Amazon polarity — Amazon product reviews compiled by Zhang et al. (2015) for character-level text classification research: 3,600,000 training reviews and 400,000 test reviews, 2 classes. Reviews rated 1–2 stars are labelled negative, reviews rated 4–5 stars are labelled positive, and 3-star reviews are excluded from the dataset.
  • Task: Binary text classification; input = one product review as raw text, output = probability distribution over 2 classes (positive, negative).
  • Model: BERT-base uncased fine-tuning (approximately 110 million parameters, datasheet value; 12 transformer layers, 768 hidden units): WordPiece tokenization, maximum sequence length 256 tokens (design choice), a classification head on the [CLS] token output, trained with AdamW and cross-entropy loss.
  • Metrics: Held-out test accuracy, per-class precision/recall/F1 and confusion matrix. Design target: at least 90% accuracy on the held-out test split (labelled design target, not a measured claim). No accuracy is claimed as measured until the training run is executed for the order; the report records the actual achieved figure.
Parameter Value
Input One product review as raw text, up to 256 tokens (design choice)
Output Probability distribution over 2 classes (positive, negative)
Model BERT-base uncased, approximately 110 million parameters (datasheet value)
Training sample 200,000 reviews, stratified sample of the Amazon polarity train split (design choice)
Test split 400,000 reviews (Amazon polarity test split)
Target accuracy At least 90% on the held-out test split (design target, not measured)
Training time Approximately 3–5 hours on a single consumer GPU (expected)
Inference Approximately 100 ms per review on a laptop CPU (expected)
Demo Single-file web app, runs offline after download

Project features

The build centres on four capabilities that together make the full sentiment pipeline demonstrable. First, a BERT-base model fine-tuned on Amazon product reviews classifies review text as positive or negative with per-class probabilities, so predictions are inspectable rather than opaque. Second, a complete training notebook documents tokenization, fine-tuning and evaluation end to end, making every design decision available for viva questions. Third, a live review-scoring web app accepts any typed or pasted review and returns its label, confidence and word-level contribution highlights. Fourth, an evaluation report records accuracy, precision, recall, F1 and the confusion matrix on a held-out test split, so the results section of the report is evidence rather than assertion. A fifth element, the honest browser demo, keeps the live demonstration independent of GPU access, since it runs a transparent lexicon scorer that is labelled as a pipeline demo rather than a BERT inference.

  • [BERT-base fine-tuning] BERT-base uncased (approximately 110 million parameters, datasheet value) is fine-tuned on a stratified sample of Amazon polarity reviews, with a two-class classification head trained on top of the pre-trained encoder.
  • [Live review-scoring web app] Paste or type any review and get its predicted label, confidence and per-class probability bars instantly, plus word-level contribution highlights showing which words pushed the prediction.
  • [Full training notebook] Data loading, star-rating mapping, WordPiece tokenization, fine-tuning loop and evaluation in one reproducible Jupyter notebook, with every hyperparameter choice documented.
  • [Evaluation report with confusion matrix] Accuracy, precision, recall and F1 on a held-out test split, plus a confusion matrix showing exactly which class the model confuses and how often.
  • [Batch review scoring] A notebook script scores a list of reviews at once and aggregates the share of positive versus negative reviews, so a whole product's feedback can be summarised in one table.
  • [Star-rating mapping documented] The label rule is explicit: 1–2 star reviews map to negative, 4–5 star reviews map to positive, and 3-star reviews are excluded from training, with the reason recorded in the report.
  • [Honest browser demo] The single-file browser demo runs a transparent lexicon-weighted scorer with negation handling, clearly labelled as a pipeline demo rather than a BERT inference, so a live demonstration never depends on a GPU.
    Optional add-ons (available on request): aspect-based sentiment (separate scores for battery, delivery, build quality), a neutral-class variant trained with 3-star reviews, and a batch CSV upload in the web app.
    Future scope: sarcasm and irony handling, multilingual and code-mixed review support, and aspect-based sentiment with opinion-term extraction.

What is included

  • Complete training & fine-tuning Jupyter notebook
  • Fine-tuned BERT-base model weights with inference script
  • Review-scoring web demo (browser demo + notebook inference)
  • Evaluation report: accuracy, precision, recall, F1 and confusion matrix
  • Batch review-scoring script with aggregate sentiment summary
  • Project report PDF (background, transformer theory, methodology, results)
  • PPT presentation for final review
  • Viva Q&A preparation document (attention, tokenization, fine-tuning, evaluation)

Limitations & prerequisites

  • Binary only: the shipped BERT model outputs positive or negative only, with no neutral class, so genuinely mixed reviews are forced to the nearer pole.
  • 3-star reviews are excluded from training, so mid-range sentiment is the weakest zone for this model.
  • Trained on English Amazon reviews only; Hinglish or code-mixed text is out of scope and will score unreliably.
  • Sarcasm and irony are frequently misclassified — a known weakness of text-only sentiment models with no audio or author context.
  • The 90% accuracy figure is a design target, stated honestly — the report documents the actual achieved figure after the training run.
  • Accuracy on review categories outside the evaluated split will differ; the report documents results for the evaluated split only.
  • The browser demo's lexicon scorer is not BERT, so demo scores will differ from the fine-tuned model's scores on the same review.

Frequently Asked Questions

Which dataset is used and why?

Amazon polarity, a widely used benchmark built from Amazon product reviews with 3.6 million training and 400,000 test reviews. It is chosen because its star-rating labels are unambiguous (1–2 stars negative, 4–5 stars positive), its scale supports genuine transformer fine-tuning, and results on it are comparable with published text-classification work. The notebook documents the exact split and sampling used for the order.

How does BERT read a review differently from older models?

BERT reads the whole review at once with self-attention, so each word's representation is shaped by the words on both sides of it. A keyword counter treats "not good" as containing "good"; BERT's attention lets "not" change how "good" is represented, which is why it handles negation, contrast ("great design, terrible battery") and word order far better than bag-of-words or single-direction models. The report explains this mechanism with a worked example.

Is the accuracy figure real?

No measured accuracy is claimed before the training run. 90% on the held-out test split is a labelled design target for the build, and the shipped report records the actual figure achieved after training, together with per-class precision, recall, F1 and the confusion matrix. If the run lands below target, the report says so and the confusion matrix shows which class is responsible.

Can it handle mixed or neutral reviews?

The shipped BERT model is binary, so a mixed review is forced to the nearer pole and its confidence will usually be lower, which the web app shows honestly. The browser demo adds a mixed band for balanced evidence, but that is a demo display, not a third BERT class. A neutral-class variant trained with 3-star reviews is available as an optional add-on.

Is this project suitable for a final-year project?

Yes — it fits AI & Machine Learning and Computer Science programmes well, because it demonstrates transformer fine-tuning, dataset handling at scale, evaluation discipline and a working deployment demo, with every design decision documented so viva questions can be answered from the report itself.

Components & software requirements
  • Python 3, PyTorch
  • Hugging Face Transformers (BERT-base uncased)
  • Amazon polarity dataset
  • Jupyter Notebook (training & evaluation)
  • scikit-learn (metrics)
  • HTML · CSS · JavaScript (review-scoring demo)
  • NumPy, pandas (data handling)
  • Git

Dataset & model details

  • Dataset: Amazon polarity — Amazon product reviews compiled by Zhang et al. (2015) for character-level text classification research: 3,600,000 training reviews and 400,000 test reviews, 2 classes. Reviews rated 1–2 stars are labelled negative, reviews rated 4–5 stars are labelled positive, and 3-star reviews are excluded from the dataset.
  • Task: Binary text classification; input = one product review as raw text, output = probability distribution over 2 classes (positive, negative).
  • Model: BERT-base uncased fine-tuning (approximately 110 million parameters, datasheet value; 12 transformer layers, 768 hidden units): WordPiece tokenization, maximum sequence length 256 tokens (design choice), a classification head on the [CLS] token output, trained with AdamW and cross-entropy loss.
  • Metrics: Held-out test accuracy, per-class precision/recall/F1 and confusion matrix. Design target: at least 90% accuracy on the held-out test split (labelled design target, not a measured claim). No accuracy is claimed as measured until the training run is executed for the order; the report records the actual achieved figure.
Delivery information

Built-to-order project. Delivery timeline is shared after order confirmation based on current queue.

Support terms

Complete documentation, setup guide, and viva preparation included. Support for setup and explanation provided.

Download free synopsis (PDF)

Enter your name and WhatsApp number — the synopsis PDF downloads immediately. We may send occasional project updates on WhatsApp; no spam.

Get a quotation