# ankit-gupta-11/aspect-based-sentiment-analysis architecture

> Architecture diagram of the GitHub repository ankit-gupta-11/aspect-based-sentiment-analysis, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ankit-gupta-11/aspect-based-sentiment-analysis
- Repository: https://github.com/ankit-gupta-11/aspect-based-sentiment-analysis

## Overview

##### Project type and purpose
- This is a Python‐based NLP/ML pipeline for Aspect-Based Sentiment Analysis (ABSA) on Flipkart product reviews.
- It ingests scraped CSV data, preprocesses text, trains or loads a PyTorch model, and runs inference to assign aspect-level sentiments.

##### File structure
- Top‐level scripts:
- preprocessing.py – text cleaning, normalization, tokenization
- CustomDataset.py – PyTorch Dataset wrapper over the cleaned CSV
- model.py – defines the neural network architecture (embeddings → encoder → classifier)
- inference.py – loads the saved model (.pt) and runs sentiment prediction on new text
- aspect-based-sentiment-analysis.ipynb – exploratory notebook with pipeline walkthrough
- Data folder: raw/cleaned CSVs of Flipkart reviews
- Model folder: stores the serialized trained model (My-Model.pt)
- requirements.txt: dependency list (PyTorch, pandas, scikit-learn, gensim or similar)

##### Key architectural patterns
- Modular pipeline: clear separation of data ingestion, preprocessing, dataset management, model definition, training/inference
- Use of PyTorch’s Dataset/DataLoader abstractions
- Optional topic-modeling (LDA) step for unsupervised aspect extraction (not explicit in code, but mentioned in README)

##### Main components and their interactions
A. Data Layer
– Raw CSV files (Data/)
B. Preprocessing Module (preprocessing.py)
– Takes raw CSV → outputs cleaned, tokenized texts
– Outputs stored as intermediate CSV or in memory
C. Dataset Abstraction (CustomDataset.py)
– Wraps cleaned text + labels → PyTorch Dataset
D. Model Definition (model.py)
– Embedding → Encoder (e.g., LSTM/Transformer) → Classifier per aspect
E. Training & Checkpointing
– (Notebook or separate train script inside notebook)
– Saves best model to Model/My-Model.pt
F. Inference Endpoint (inference.py)
– Loads My-Model.pt → accepts new text → outputs aspect-sentiment scores
G. Notebook (aspect-based-sentiment-analysis.ipynb)
– Orchestrates entire pipeline for experimentation, visualization

– Rectangles for modules (Preprocessing, Dataset, Model, Inference)
– Data → Preprocessing → Dataset → Model → Checkpoint
– Checkpoint + Inference script → Predictions
– Notebook taps into each stage for visualization & manual runs
– Blue for data/storage, green for processing modules, orange for model components, purple for experimentation
d. Interactions:
– Dependencies (e.g., preprocessing.py imports nltk, gensim for LDA)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Storage
    subgraph "Data Storage"
        direction TB
        Data1["Clean_Flipkart_Product.csv"]:::data
        Data2["Clean_Flipkart_Product-1.csv"]:::data
    end

    %% Pipeline Modules
    subgraph "Pipeline Modules"
        direction TB
        Preprocessing["Preprocessing Module"]:::processing
        LDA["LDA Aspect Extractor"]:::processing
        Dataset["PyTorch Dataset Wrapper"]:::processing
    end

    %% Model Training
    subgraph "Model Training"
        direction TB
        ModelDef["Model Definition (Embedding→Encoder→Classifier)"]:::model
        Checkpoint["Saved Model Artifact (.pt)"]:::data
    end

    %% Inference
    subgraph "Inference"
        direction TB
        Inference["Inference Script"]:::processing
        Predictions["Aspect-Sentiment Predictions"]:::model
    end

    %% Administration
    subgraph "Administrative"
        direction TB
        Requirements["requirements.txt"]:::admin
        README["README.md"]:::admin
    end

    %% Notebook
    Notebook["aspect-based-sentiment-analysis.ipynb"]:::notebook

    %% Data Flow
    Data1 -->|raw CSVs| Preprocessing
    Data2 -->|raw CSVs| Preprocessing
    Preprocessing -->|cleaned tokens| LDA
    LDA -->|aspects| Dataset
    Preprocessing -->|cleaned CSV| Dataset
    Dataset -->|batches| ModelDef
    ModelDef -->|trained weights| Checkpoint
    Checkpoint -->|load model| Inference
    Inference -->|predicts| Predictions

    %% Notebook interactions
    Notebook -->|visualizes & runs| Preprocessing
    Notebook -->|uses| Dataset
    Notebook -->|trains| ModelDef
    Notebook -->|loads/saves| Checkpoint
    Notebook -->|runs| Inference

    %% Click Events
    click Data1 "https://github.com/ankit-gupta-11/aspect-based-sentiment-analysis/blob/master/Data/Clean_Flipkart_Product.csv"
    click Data2 "https://github.com/ankit-gupta-11/aspect-based-sentiment-analysis/blob/master/Data/Clean_Flipkart_Product-1.csv"
    click Preprocessing "https://github.com/ankit-gupta-11/aspect-based-sentiment-analysis/blob/master/preprocessing.py"
    click LDA "https://github.com/ankit-gupta-11/aspect-based-sentiment-analysis/blob/master/preprocessing.py"
    click Dataset "https://github.com/ankit-gupta-11/aspect-based-sentiment-analysis/blob/master/CustomDataset.py"
    click ModelDef "https://github.com/ankit-gupta-11/aspect-based-sentiment-analysis/blob/master/model.py"
    click Checkpoint "https://github.com/ankit-gupta-11/aspect-based-sentiment-analysis/blob/master/Model/My-Model.pt"
    click Inference "https://github.com/ankit-gupta-11/aspect-based-sentiment-analysis/blob/master/inference.py"
    click Notebook "https://github.com/ankit-gupta-11/aspect-based-sentiment-analysis/blob/master/aspect-based-sentiment-analysis.ipynb"
    click Requirements "https://github.com/ankit-gupta-11/aspect-based-sentiment-analysis/blob/master/requirements.txt"
    click README "https://github.com/ankit-gupta-11/aspect-based-sentiment-analysis/blob/master/README.md"

    %% Styles
    classDef data fill:#c6dbef,stroke:#2171b5,color:#08306b;
    classDef processing fill:#c7e9c0,stroke:#31a354,color:#00441b;
    classDef model fill:#fdcc8a,stroke:#e6550d,color:#7f2704;
    classDef notebook fill:#efedf5,stroke:#756bb1,color:#3f007d;
    classDef admin fill:#f7f7f7,stroke:#bbbbbb,color:#333333;
```
