# althariqfairuz/tubes-ml-2 architecture

> Architecture diagram of the GitHub repository althariqfairuz/tubes-ml-2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/althariqfairuz/tubes-ml-2
- Repository: https://github.com/althariqfairuz/tubes-ml-2

## Overview

##### Project Type and Purpose
- This is a research-style machine-learning experiment repository, not a web or full-stack application. Its goal is to implement and benchmark three deep-learning architectures (CNN, RNN, LSTM) “from scratch” using NumPy, compare them against Keras/TensorFlow baselines, and systematically explore hyperparameter settings.

##### File Structure
- Top-level directories:
- datasets/ ‑ raw CSV files (train, valid, test)
- models/ ‑ saved model binaries (.h5, .keras) from Keras runs
- src/ ‑ source code grouped by algorithm: cnn/, rnn/, lstm/, plus shared utils/
- docs/ ‑ static report PDF
- In each algorithm folder (e.g., src/cnn/):
- \*_from_scratch.py: pure-NumPy implementation
- model_training.py: training scripts that wrap both scratch and Keras variants
- .ipynb: Jupyter notebook that orchestrates experiments, visualization, and evaluation
- Shared utils: data_preprocessing.py handles tokenization and sequence/vector preparation for text.

##### README for Additional Insights
- Confirms that:
- CNN is applied to CIFAR-10 image classification.
- RNN and LSTM are applied to NusaX-Sentiment text classification.
- Experiments compare depth, width, pooling, bidirectionality.
- Metrics: training/validation loss curves, macro F1-score, Keras vs scratch difference ≤0.001.

##### Main Components of the System
a. Data Layer:
- Raw datasets in CSV form (text)
- CIFAR-10 auto-download module (inside TensorFlow calls in notebooks)
b. Preprocessing Layer (utils):
- Text tokenization, sequence padding (src/utils/data_preprocessing.py)
- Image scaling / batch preparation (built into model_training notebooks)
c. Model Implementation Layer:
- Scratch implementations (cnn_from_scratch.py, rnn_from_scratch.py, lstm_from_scratch.py)
- Keras/TensorFlow implementations (inside model_training.py)
d. Training & Evaluation Layer:
- model_training.py orchestrates data → model → training loop → evaluation metrics
- Experiment notebooks (.ipynb) that call training scripts, plot curves, compute F1
e. Persistence Layer:
- models/ directory stores serialized checkpoints/configurations
f. Reporting & Visualization:
- Jupyter notebooks generate plots (Matplotlib/Seaborn) and result tables
- docs/K01-G65-Laporan.pdf contains the formal write-up

##### Relationships and Data Flow
- Data (CSV or CIFAR-10) → Preprocessing Utilities → Two parallel paths:
- Scratch Model Implementation → Training Loop → Evaluation → Model Checkpoint
- Keras Model Implementation → Training Loop → Evaluation → Model Checkpoint
- Both paths feed results back into the Notebooks for visualization and comparison.

##### Architectural Patterns and Design Principles
- Modular separation: one folder per algorithm prevents cross-contamination and eases extension.
- Reusability: shared preprocessing utilities.
- Experimentation pipelines: notebooks drive parameter sweeps and visual feedback.

##### Relevant Technologies and Frameworks
- Core: Python 3.8+, NumPy (scratch math), Pandas (CSV), Scikit-learn (metrics), Matplotlib/Seaborn (plots)
- Deep Learning: TensorFlow/Keras (baseline models, CIFAR-10 loader)
- Environment: Jupyter notebooks for interactive runs

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    Datasets["Raw Datasets (CSV)"]:::data
    click Datasets "https://github.com/althariqfairuz/tubes-ml-2/tree/main/datasets/"

    %% Preprocessing Layer
    Preprocessing["Data Preprocessing\n(tokenization, padding)"]:::utils
    click Preprocessing "https://github.com/althariqfairuz/tubes-ml-2/blob/main/src/utils/data_preprocessing.py"

    %% CNN Module
    subgraph "CNN Module"
        direction TB
        ScratchCNN["cnn_from_scratch.py"]:::code
        click ScratchCNN "https://github.com/althariqfairuz/tubes-ml-2/blob/main/src/cnn/cnn_from_scratch.py"
        WrapperCNN["model_training.py\n(scratch & Keras)"]:::code
        click WrapperCNN "https://github.com/althariqfairuz/tubes-ml-2/blob/main/src/cnn/model_training.py"
        NotebookCNN["cnn.ipynb"]:::notebook
        click NotebookCNN "https://github.com/althariqfairuz/tubes-ml-2/blob/main/src/cnn/cnn.ipynb"
    end

    %% RNN Module
    subgraph "RNN Module"
        direction TB
        ScratchRNN["rnn_from_scratch.py"]:::code
        click ScratchRNN "https://github.com/althariqfairuz/tubes-ml-2/blob/main/src/rnn/rnn_from_scratch.py"
        WrapperRNN["model_training.py\n(scratch & Keras)"]:::code
        click WrapperRNN "https://github.com/althariqfairuz/tubes-ml-2/blob/main/src/rnn/model_training.py"
        NotebookRNN["rnn.ipynb"]:::notebook
        click NotebookRNN "https://github.com/althariqfairuz/tubes-ml-2/blob/main/src/rnn/rnn.ipynb"
    end

    %% LSTM Module
    subgraph "LSTM Module"
        direction TB
        ScratchLSTM["lstm_from_scratch.py"]:::code
        click ScratchLSTM "https://github.com/althariqfairuz/tubes-ml-2/blob/main/src/lstm/lstm_from_scratch.py"
        WrapperLSTM["model_training.py\n(scratch & Keras)"]:::code
        click WrapperLSTM "https://github.com/althariqfairuz/tubes-ml-2/blob/main/src/lstm/model_training.py"
        NotebookLSTM["lstm.ipynb"]:::notebook
        click NotebookLSTM "https://github.com/althariqfairuz/tubes-ml-2/blob/main/src/lstm/lstm.ipynb"
    end

    %% Persistence Layer
    Models["Models Storage\n(serialized checkpoints)"]:::output
    click Models "https://github.com/althariqfairuz/tubes-ml-2/tree/main/models/"

    %% Reporting
    Docs["Static Report (PDF)"]:::output
    click Docs "https://github.com/althariqfairuz/tubes-ml-2/blob/main/docs/K01-G65-Laporan.pdf"

    %% Flow arrows
    Datasets -->|raw CSV| Preprocessing
    Preprocessing -->|"tokenized sequences\nor image batches"| ScratchCNN
    Preprocessing -->|"tokenized sequences\nor image batches"| WrapperCNN
    Preprocessing -->|"tokenized sequences"| ScratchRNN
    Preprocessing -->|"tokenized sequences"| WrapperRNN
    Preprocessing -->|"tokenized sequences"| ScratchLSTM
    Preprocessing -->|"tokenized sequences"| WrapperLSTM

    ScratchCNN -->|forward/backprop| WrapperCNN
    ScratchRNN -->|forward/backprop| WrapperRNN
    ScratchLSTM -->|forward/backprop| WrapperLSTM

    WrapperCNN -->|trained models| Models
    WrapperRNN -->|trained models| Models
    WrapperLSTM -->|trained models| Models

    Models -->|"load & compare"| NotebookCNN
    Models -->|"load & compare"| NotebookRNN
    Models -->|"load & compare"| NotebookLSTM

    NotebookCNN -->|report figures| Docs
    NotebookRNN -->|report figures| Docs
    NotebookLSTM -->|report figures| Docs

    %% Legend or external frameworks can be implied
    classDef data fill:#D6EFFF,stroke:#0277BD;
    classDef utils fill:#E8F5E9,stroke:#388E3C;
    classDef code fill:#F1F8E9,stroke:#689F38;
    classDef notebook fill:#FFF3E0,stroke:#FB8C00;
    classDef output fill:#ECEFF1,stroke:#607D8B;
```
