# da505819/sentiment_analysis_with_deep_learning_using_bert architecture

> Architecture diagram of the GitHub repository da505819/sentiment_analysis_with_deep_learning_using_bert, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/da505819/sentiment_analysis_with_deep_learning_using_bert
- Repository: https://github.com/da505819/sentiment_analysis_with_deep_learning_using_bert

## Overview

##### Project type and purpose
- This is a machine-learning pipeline for multi-class sentiment analysis built in a single Jupyter notebook (“Sentiment_Analysis.ipynb”) using PyTorch and a pre-trained BERT transformer.
- It ingests a labeled dataset (CSV/JSON), performs exploratory data analysis (EDA), tokenizes and encodes text, constructs data loaders, fine-tunes BERT, and evaluates performance.

##### File structure
- Top level:
- Data/ – raw and annotated dataset (CSV + JSON)
- Sentiment_Analysis.ipynb – orchestration of all steps
- README.md, LICENSE
- No separate “src” folder – all code lives in the notebook, but the logical pipeline can be broken out into modular stages.
- No explicit deployment or API layer – focus is on training & evaluation.

##### Key insights from the README
- Uses BERT large-scale pre-trained transformer via the Hugging Face library.
- Framework: PyTorch, with custom optimizer and scheduler.
- Workflow stages: EDA → Tokenizer/Encoding → DataLoaders → Optimizer/Scheduler setup → Training loop → Model evaluation.

a. Main components:
1. Data Ingestion Layer
– Raw CSV/JSON files in Data/
2. EDA & Preprocessing
– Data cleaning, visualization (Images/)
3. Tokenization & Encoding
– Hugging Face BERT tokenizer → padded token IDs + attention masks
4. DataLoader Module
– PyTorch Dataset & DataLoader for batching
5. Model Training
– Pre-trained BERT model + classification head
– Optimizer (e.g., AdamW) & learning rate scheduler
6. Training Loop Controller
– Epochs, backprop, loss computation
7. Evaluation & Metrics
– Accuracy, F1, confusion matrix
8. Model Artifact Output
– Fine-tuned weights saved to disk for later use

b. Relationships & data flow:
– Show that Tokenization and Model both rely on the pre-trained BERT library (external service)

c. Architectural patterns & design principles:
– Pipeline pattern: clear linear flow of data transformations
– Separation of concerns: ingest/clean vs. encode vs. train vs. evaluate
– Batch processing via DataLoader

d. Key technologies/frameworks:
– Python, Jupyter Notebook (orchestrator)
– PyTorch (Dataset, DataLoader, model fine-tuning)
– Hugging Face Transformers (BERT tokenizer & model)
– CSV/JSON file storage for data

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Data Ingestion Layer
    RawCSV["Raw Dataset CSV"]:::data
    RawJSON["Raw Dataset JSON"]:::data
    DataIngestion["Data Ingestion Layer\n(Data/)"]:::data

    %% EDA & Preprocessing
    EDA["EDA & Preprocessing\n(Sentiment_Analysis.ipynb)"]:::data
    Images["Images\n(Plots & Figures)"]:::data

    %% Tokenization & Encoding
    Tokenizer["Tokenization & Encoding\n(BERT Tokenizer)"]:::data

    %% DataLoader Module
    DataLoader["DataLoader Module\n(PyTorch Dataset & DataLoader)"]:::compute

    %% Training Loop & Model Training
    TrainingLoop["Training Loop Controller\n(Epochs, Backprop, Loss)"]:::compute
    ModelTraining["Model Training\n(BERT + Classification Head)"]:::compute

    %% External Services
    ExternalHF["Hugging Face Transformers"]:::external
    GPU["GPU Acceleration"]:::external

    %% Evaluation & Metrics
    SavedModel["Model Artifact Output\n(models/bert_sentiment.bin)"]:::storage
    Evaluation["Evaluation & Metrics\n(Sentiment_Analysis.ipynb)"]:::compute

    %% Documentation
    ProjectDoc["Project Documentation\n(README.md & LICENSE)"]:::data

    %% Connections
    RawCSV --> DataIngestion
    RawJSON --> DataIngestion
    DataIngestion --> EDA
    EDA --> Images
    EDA --> Tokenizer
    Tokenizer --> DataLoader
    DataLoader --> TrainingLoop
    TrainingLoop --> ModelTraining
    TrainingLoop --> SavedModel
    SavedModel --> Evaluation

    ExternalHF --> Tokenizer
    ExternalHF --> ModelTraining
    GPU --> TrainingLoop

    ProjectDoc

    %% Click Events
    click RawCSV "https://github.com/da505819/sentiment_analysis_with_deep_learning_using_bert/blob/master/Data/smile-annotations-final.csv"
    click RawJSON "https://github.com/da505819/sentiment_analysis_with_deep_learning_using_bert/blob/master/Data/smile-annotations-final.json"
    click DataIngestion "https://github.com/da505819/sentiment_analysis_with_deep_learning_using_bert/tree/master/Data/"
    click EDA "https://github.com/da505819/sentiment_analysis_with_deep_learning_using_bert/blob/master/Sentiment_Analysis.ipynb"
    click Images "https://github.com/da505819/sentiment_analysis_with_deep_learning_using_bert/tree/master/Images/"
    click Tokenizer "https://github.com/da505819/sentiment_analysis_with_deep_learning_using_bert/blob/master/Sentiment_Analysis.ipynb"
    click DataLoader "https://github.com/da505819/sentiment_analysis_with_deep_learning_using_bert/blob/master/Sentiment_Analysis.ipynb"
    click ModelTraining "https://github.com/da505819/sentiment_analysis_with_deep_learning_using_bert/blob/master/Sentiment_Analysis.ipynb"
    click TrainingLoop "https://github.com/da505819/sentiment_analysis_with_deep_learning_using_bert/blob/master/Sentiment_Analysis.ipynb"
    click Evaluation "https://github.com/da505819/sentiment_analysis_with_deep_learning_using_bert/blob/master/Sentiment_Analysis.ipynb"
    click ProjectDoc "https://github.com/da505819/sentiment_analysis_with_deep_learning_using_bert/blob/master/README.md"

    %% Styles
    classDef data fill:#D6EAF8,stroke:#21618C,color:#0B5345
    classDef compute fill:#D5F5E3,stroke:#1D8348,color:#145A32
    classDef external fill:#FDEBD0,stroke:#B9770E,color:#7E5109
    classDef storage fill:#FADBD8,stroke:#922B21,color:#641E16
```
