Turn thousands of raw e‑commerce reviews into trustworthy product insights using a lightweight Flask app, a fine‑tuned sentiment model, and an LLM assistant for explainability and auditability.
This repo contains:
- A minimal web UI to import reviews, initialize products, run automated checks, and review results
- A Flask backend with a SQLite database for quick local demos
- A fine‑tuned sequence classification model (DistilBERT) in the
model/folder - An optional GenAI step (Groq Llama‑3.3‑70B‑Versatile) to explain and validate suspect ratings
- A Colab notebook (
individual.ipynb) showing the training and evaluation pipeline
- Business case and approach
- System architecture
- Quick start (local)
- CSV format and data model
- Using the web app (3–5 min walkthrough cues)
- API endpoints
- Evaluation criteria mapping
- Extending to production
- Troubleshooting
Problem: Retailers receive massive volumes of text reviews (often with images) daily. We need to convert this noisy signal into reliable insight for product, CX, and trust & safety teams.
Approach in this demo:
- Preprocess → classify sentiment with a fine‑tuned DistilBERT model (NEGATIVE/NEUTRAL/POSITIVE)
- Cross‑check the user’s star rating against the text sentiment to flag potential mismatches
- Optionally ask an LLM to explain “why this rating looks inappropriate” and provide a short reason
- Present results in a simple UI so a human can quickly review and confirm
Outcomes:
- Higher accuracy (DL model) + faster triage (UI) + better trust (LLM explanations)
- Modular, reusable components that you can swap or scale
- UI:
templates/index.html(modern) andtemplates/index_retro.html(retro) - Backend:
app.py(Flask) - Database:
database.db(SQLite) - Model:
model/(HF format) - LLM: Groq API (Llama‑3.3‑70B‑Versatile) for short reasoned judgments
Processing states per product (products.check_flag):
- 0 Not checked
- 1 Model checking
- 2 Ready for GenAI check
- 3 GenAI checking
- 4 Automatic checks done, pending review
- 5 All checks done
Requirements
- Python 3.12+
- Linux/macOS/WSL (Windows works via WSL)
- Create and activate a virtual environment
python3 -m venv bc3415_env
source .venv/bin/activate- Install dependencies & torch
pip install -r requirements.txt- (Optional) Configure Groq API key for GenAI step
export GROQ_API_KEY="<your_key>"Note: The app can run without GenAI; the DL step works standalone.
- Run the app
python app.pyOpen http://127.0.0.1:5000/ (modern UI). Retro UI is at http://127.0.0.1:5000/retro.
Required CSV columns for /loadCSV:
reviewerID,asin,reviewerName,reviewText,overall,summary,unixReviewTime,reviewTime,helpful_yes,total_vote
Notes
overallis the 1–5 star rating (int)unixReviewTimeis an integer epoch time- The app stores reviews in table
reviewsand products inproducts
SQLite schema (simplified)
products(asin PRIMARY KEY, image_link, title, seller, length, check_flag, num_checked, num_total)
reviews(uuid PRIMARY KEY, reviewerID, asin, reviewerName, reviewText, overall, summary,
unixReviewTime, reviewTime, helpful_yes, total_vote,
model_flag, genai_flag, genai_reason, user_flag)
Flags (per review)
- model_flag: 0 not processed, 1 pass, 2 fail (text contradicts rating)
- genai_flag: 0 not processed, 1 pass, 2 fail (LLM says rating is inappropriate)
- user_flag: 0 unreviewed, 1 showing (valid), -1 invalid/hidden
Prep tips
- Trim the CSV to ~1,000 reviews for a single ASIN to keep the demo within 3–5 min
- Duplicate a product’s reviews and change the ASIN to simulate a new product
- Intentionally edit 1–2 ratings to be “wrong” for demonstration
Walkthrough flow (suggested)
- Open the app at “modern UI” and state the problem briefly
- Screen: Header and Import section
- Import CSV (Upload → Import CSV)
- Screen: Status chip shows progress; uninitialized products appear
- Initialize product (click Initialize Product)
- Screen: Fill Title/Image/Seller; save
- Start Model Check
- Screen: Product card shows progress bar and state badges
- Start GenAI Check
- Screen: After model completes, run GenAI; progress updates
- Review flagged reviews
- Screen: Open “All Reviews” or “Filtered”; show badges and reasons
- (Optional) Human confirmation
- Screen: Flag/Unflag; watch product state reach “All checks done”
Retro UI
- Visit
/retroto quickly show the earlier UI for contrast.
GET
/→ modern UI/retro→ retro UI/allProducts→ list products and processing state/uninitializedAsins→ ASINs in reviews without a product entry/allReviews/<asin>→ all reviews for an ASIN/modelFlag2Reviews/<asin>→ reviews with model_flag = 2/genaiFlag2Reviews/<asin>→ reviews with genai_flag = 2
POST
/loadCSV→ multipart/form‑data with file fieldfile/initProduct→ JSON body{ asin, image_link, title, seller, length }
DELETE
/deleteProduct/<asin>→ deletes product and its reviews
Actions
/modelCheck/<asin>→ launch DL check in background/genAiCheck/<asin>→ launch GenAI check in background/userFlag/<uuid>/<asin>/<flag>→ set user_flag for a review (0, 1, or -1)
- Accuracy & performance
- DistilBERT fine‑tuned classifier with truncation and dynamic padding
- Async background processing to keep UI responsive
- Data preprocessing pipeline
- See
individual.ipynb: tokenization, cleaning, label mapping, train/test split
- See
- Explainability & commentary
- GenAI returns a brief reason for “inappropriate rating” decisions
- UI surfaces status badges, counts, and reasons
- Creativity (text + image)
- Demo focuses on text; image signals are planned as an extension (see next section)
- Usability & reusability
- Minimal dependencies, simple CSV import, modular endpoints, and a clean UI
- Add image features: CLIP or ViT embeddings for image‑text consistency checks
- Confidence thresholds and calibration for model decisions
- Batch/stream processing with a job queue (Celery) and a Postgres backend
- Auth, audit logs, and role‑based approvals (human‑in‑the‑loop)
- BI integration: push aggregates to a dashboard (e.g., Metabase/Looker)
- CSV import fails: ensure all required columns exist and datatypes are valid
- “database is locked”: stop other processes or remove
database.dbto reset demo - GenAI step fails: confirm
GROQ_API_KEYis set and network access is available - No products after import: check
/uninitializedAsinsor verifyasinvalues
CC-BY-SA @SyntaxaR