# karunya-475/product-review-sentiment-analysis architecture

> Architecture diagram of the GitHub repository karunya-475/product-review-sentiment-analysis, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/karunya-475/product-review-sentiment-analysis
- Repository: https://github.com/karunya-475/product-review-sentiment-analysis

## Overview

#### Purpose and execution model
This is a notebook-centric Python NLP project for three-class product-review sentiment classification: POSITIVE, NEUTRAL, and NEGATIVE. The primary executable and end-to-end workflow is `Product Review Analysis.ipynb`; it is designed for Jupyter/Google Colab rather than as a packaged service or CLI.

#### Data boundary
`Product_Reviews.csv` is the sole local input dataset. It supplies product identifiers, free-text reviews, and labeled sentiment targets. The notebook loads and validates this tabular data, separating review text as model input from the `Sentiment` label used for supervised training and evaluation.

#### Semantic feature extraction
The central representation stage uses the external Sentence Transformers model `all-MiniLM-L6-v2`, executed through PyTorch, to convert review text into 384-dimensional dense embeddings. This forms the principal boundary between raw natural-language input and conventional numerical ML:
- Input: review strings from `Product_Reviews.csv`
- Output: embedding matrix consumed by scikit-learn classifiers
- Implementation workflow: `Product Review Analysis.ipynb`

#### Training and model comparison
The notebook splits labeled embeddings into training and test data, then trains four scikit-learn classifiers: Random Forest, Gradient Boosting, class-balanced Logistic Regression, and Linear SVM. Class-balanced weighting is specifically applied to address minority NEGATIVE and NEUTRAL labels. The comparative model-selection flow is implemented in `Product Review Analysis.ipynb`.

#### Evaluation and decision criteria
Models are evaluated using accuracy plus imbalance-aware F1 metrics, including macro and weighted/class-level reporting. This is an important quality boundary: accuracy captures overall fit, while macro F1 and per-class recall expose performance on underrepresented sentiment classes. The README identifies Linear SVM as the strongest candidate for high-dimensional embedding features, while balanced logistic regression favors negative-review recall.

#### Unseen-review inference
After training/evaluation, the selected embedding-plus-classifier path is applied to previously unseen review text. Inference must preserve the same Sentence Transformer encoder used for training before passing vectors to the selected classifier. This flow remains notebook-local in `Product Review Analysis.ipynb`; no serialized model artifact, API, or deployment application is present.

#### Runtime and external dependencies
Execution requires Python 3.8+ with Jupyter or Google Colab. Material dependencies are `sentence-transformers`, PyTorch, scikit-learn, pandas, NumPy, matplotlib, and seaborn. The embedding model is an external pretrained model dependency and may require model retrieval/caching at runtime. Repository documentation and usage context are in `README.md`.

Main entry points: [`Product Review Analysis.ipynb`](https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb) (Train/Test Split), [`README.md`](https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/README.md) (Project Documentation), [`Product_Reviews.csv`](https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product_Reviews.csv) (Product Reviews)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Notebook Runtime"]
  node_notebook["Analysis Notebook<br/>Jupyter workflow"]
  node_dependencies["ML Dependencies<br/>Python libraries"]
end

subgraph group_ml["Sentiment ML Pipeline"]
  node_validation["Load &amp; Validate Data<br/>pandas processing"]
  node_encoder{{"MiniLM Encoder<br/>Sentence Transformers"}}
  node_embeddings["Review Embeddings<br/>feature matrix"]
  node_split["Train/Test Split<br/>scikit-learn split"]
  node_random_forest["Random Forest<br/>scikit-learn classifier"]
  node_gradient_boosting["Gradient Boosting<br/>scikit-learn classifier"]
  node_logistic_regression["Balanced Logistic Regression<br/>scikit-learn classifier"]
  node_linear_svm["Linear SVM<br/>scikit-learn classifier"]
  node_evaluation["Model Evaluation<br/>metrics reporting"]
  node_selected_model["Selected Classifier<br/>notebook-local model"]
  node_unseen_reviews["Unseen Review Text<br/>inference input"]
  node_sentiment_output["Sentiment Prediction"]
end

node_readme["Project Documentation<br/>[README.md]"]
node_dataset[("Product Reviews<br/>CSV dataset")]

node_readme -.->|"documents"| node_notebook
node_dependencies -.->|"runtime dependencies"| node_notebook
node_dataset -->|"CSV input"| node_validation
node_notebook -->|"executes"| node_validation
node_validation -->|"review strings"| node_encoder
node_encoder -->|"384-d vectors"| node_embeddings
node_embeddings -->|"labeled features"| node_split
node_split -->|"training data"| node_random_forest
node_split -->|"training data"| node_gradient_boosting
node_split -->|"training data"| node_logistic_regression
node_split -->|"training data"| node_linear_svm
node_random_forest -->|"test predictions"| node_evaluation
node_gradient_boosting -->|"test predictions"| node_evaluation
node_logistic_regression -->|"test predictions"| node_evaluation
node_linear_svm -->|"test predictions"| node_evaluation
node_evaluation -->|"selects"| node_selected_model
node_unseen_reviews -->|"same encoder"| node_encoder
node_encoder -->|"inference vectors"| node_selected_model
node_selected_model -->|"predicts"| node_sentiment_output

click node_readme "https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/README.md"
click node_notebook "https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb"
click node_dataset "https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product_Reviews.csv"
click node_validation "https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb"
click node_encoder "https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb"
click node_embeddings "https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb"
click node_split "https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb"
click node_random_forest "https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb"
click node_gradient_boosting "https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb"
click node_logistic_regression "https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb"
click node_linear_svm "https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb"
click node_evaluation "https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb"
click node_selected_model "https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb"
click node_unseen_reviews "https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb"
click node_sentiment_output "https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_notebook,node_dependencies toneBlue
class node_validation,node_encoder,node_embeddings,node_split,node_random_forest,node_gradient_boosting,node_logistic_regression,node_linear_svm,node_evaluation,node_selected_model,node_unseen_reviews,node_sentiment_output toneAmber
class node_readme,node_dataset toneNeutral
```

## Components

### Notebook Runtime

Interactive Python 3.8+ execution in Jupyter or Colab.

- [Analysis Notebook](https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb): Jupyter workflow · Primary end-to-end training and inference workflow. · `Product Review Analysis.ipynb`
- **ML Dependencies**: Python libraries · sentence-transformers, PyTorch, scikit-learn, pandas, NumPy, matplotlib, and seaborn.

### Sentiment ML Pipeline

- [Load & Validate Data](https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb): pandas processing · Separates review text from the Sentiment target. · `Product Review Analysis.ipynb`
- [MiniLM Encoder](https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb): Sentence Transformers · all-MiniLM-L6-v2 converts reviews into 384-dimensional vectors. · `Product Review Analysis.ipynb`
- [Review Embeddings](https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb): feature matrix · Dense numerical representation consumed by classifiers. · `Product Review Analysis.ipynb`
- [Train/Test Split](https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb): scikit-learn split · Partitions labeled embeddings for fitting and evaluation. · `Product Review Analysis.ipynb`
- [Random Forest](https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb): scikit-learn classifier · `Product Review Analysis.ipynb`
- [Gradient Boosting](https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb): scikit-learn classifier · `Product Review Analysis.ipynb`
- [Balanced Logistic Regression](https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb): scikit-learn classifier · Class weighting improves minority sentiment handling. · `Product Review Analysis.ipynb`
- [Linear SVM](https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb): scikit-learn classifier · Documented strongest candidate for embedding features. · `Product Review Analysis.ipynb`
- [Model Evaluation](https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb): metrics reporting · Accuracy, macro/weighted F1, per-class metrics, and recall guide selection. · `Product Review Analysis.ipynb`
- [Selected Classifier](https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb): notebook-local model · Chosen from comparative evaluation; no serialized artifact exists. · `Product Review Analysis.ipynb`
- [Unseen Review Text](https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb): inference input · `Product Review Analysis.ipynb`
- [Sentiment Prediction](https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product%20Review%20Analysis.ipynb): POSITIVE / NEUTRAL / NEGATIVE · `Product Review Analysis.ipynb`

### Other components

- [Project Documentation](https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/README.md): documentation · Describes usage, dependencies, and model tradeoffs. · `README.md`
- [Product Reviews](https://github.com/karunya-475/product-review-sentiment-analysis/blob/main/Product_Reviews.csv): CSV dataset · Review text, product identifiers, and sentiment labels. · `Product_Reviews.csv`

## Connections

- Project Documentation → Analysis Notebook: documents
- ML Dependencies → Analysis Notebook: runtime dependencies
- Product Reviews → Load & Validate Data: CSV input
- Analysis Notebook → Load & Validate Data: executes
- Load & Validate Data → MiniLM Encoder: review strings
- MiniLM Encoder → Review Embeddings: 384-d vectors
- Review Embeddings → Train/Test Split: labeled features
- Train/Test Split → Random Forest: training data
- Train/Test Split → Gradient Boosting: training data
- Train/Test Split → Balanced Logistic Regression: training data
- Train/Test Split → Linear SVM: training data
- Random Forest → Model Evaluation: test predictions
- Gradient Boosting → Model Evaluation: test predictions
- Balanced Logistic Regression → Model Evaluation: test predictions
- Linear SVM → Model Evaluation: test predictions
- Model Evaluation → Selected Classifier: selects
- Unseen Review Text → MiniLM Encoder: same encoder
- MiniLM Encoder → Selected Classifier: inference vectors
- Selected Classifier → Sentiment Prediction: predicts
