How ankit-gupta-11/aspect-based-sentiment-analysis works
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)