# ogunlao/saint architecture

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

- Interactive diagram: https://gitdiagram.com/ogunlao/saint
- Repository: https://github.com/ogunlao/saint

## Overview

##### Main Components

a) Data Processing Layer:
- Data input flow starting from raw tabular data
- Preprocessing components (z-transform, label encoding)
- Data segregation (categorical vs. numerical columns)

b) Model Architecture Layer:
- Three main model variants: SAINT, SAINT-I (Intersample), and SAINT-S
- Embedding layer for categorical and numerical features
- Transformer architecture components
- Attention mechanisms (Self-attention and Intersample attention)

c) Training Components:
- Supervised learning path
- Self-supervised learning path
- Loss functions (Contrastive Loss, Denoising Loss)
- Data augmentation methods (Mixup, CutMix)

##### Component Relationships

**[Raw Data] → [Preprocessing] → [Data Loader] → [Model Architecture] → [Training Loop] → [Predictions]**

##### Specific Implementation Details

- Configuration Management (Hydra)
- Training Framework (PyTorch Lightning)
- Model Variants (SAINT, SAINT-I, SAINT-S)
- Data Augmentation Techniques
- Loss Functions

##### Key Elements to Highlight

a) Data Flow:
- How data moves from raw input through preprocessing
- Split between categorical and numerical features
- How data augmentation is applied

b) Model Architecture:
- Embedding layer structure
- Transformer architecture
- Attention mechanism flow

c) Training Flow:
- Separate paths for supervised and self-supervised training
- How loss functions are integrated
- Validation and prediction paths

##### Technical Details

- Input Layer: Show categorical and numerical feature handling
- Embedding Layer: Indicate separate embeddings for different feature types
- Transformer Block: Show self-attention and intersample attention mechanisms
- Output Layer: Show classification head

##### Implementation Notes

**configs/ → Data and experiment configurations**
**models/ → Model implementations**
**src/ → Core functionality**
**utils/ → Helper functions**

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Data["Data Processing Layer"]
        RawData[Raw Tabular Data]
        Preprocess["Preprocessing"]
        DataLoader["Data Loader"]:::file
        Dataset["Dataset Handler"]:::file
    end

    subgraph ModelArch["Model Architecture Layer"]
        direction TB
        subgraph Models["Model Variants"]
            SAINT["SAINT Base"]:::file
            SAINTI["SAINT-I"]:::file
            SAINTS["SAINT-S"]:::file
        end
        
        subgraph Components["Core Components"]
            Embed["Embedding Layer"]:::file
            Trans["Transformer Block"]:::file
            ModelGen["Model Generator"]:::file
        end
    end

    subgraph Training["Training Components"]
        direction TB
        Train["Training Logic"]:::file
        Trainer["Trainer Implementation"]:::file
        
        subgraph Loss["Loss Functions"]
            ContLoss["Contrastive Loss"]:::file
            DenoiseLoss["Denoising Loss"]:::file
        end
        
        subgraph Augment["Data Augmentation"]
            Mixup["Mixup"]:::file
            CutMix["CutMix"]:::file
        end
    end

    subgraph Config["Configuration Management"]
        direction TB
        SupConfig["Supervised Config"]:::file
        SSLConfig["Self-supervised Config"]:::file
        PredConfig["Prediction Config"]:::file
        
        subgraph DataConfig["Dataset Configs"]
            BankSSL["Bank SSL"]:::file
            BankSup["Bank Supervised"]:::file
            Insurance["Insurance"]:::file
        end
    end

    subgraph Predict["Prediction Pipeline"]
        PredImpl["Prediction Implementation"]:::file
        MainEntry["Main Entry Point"]:::file
    end

    Utils["Utility Functions"]:::file

    %% Relationships
    RawData --> Preprocess
    Preprocess --> DataLoader
    DataLoader --> Dataset
    Dataset --> Models
    Components --> Models
    Models --> Train
    Train --> Trainer
    Loss --> Train
    Augment --> Train
    Config --> Train
    Train --> PredImpl
    PredImpl --> MainEntry
    Utils --> Train

    %% Styling
    classDef file fill:#f9f,stroke:#333,stroke-width:2px
    classDef default fill:#ddd,stroke:#333,stroke-width:2px

    %% Click Events
    click DataLoader "https://github.com/ogunlao/saint/blob/main/src/dataloader.py"
    click Dataset "https://github.com/ogunlao/saint/blob/main/src/dataset.py"
    click SAINT "https://github.com/ogunlao/saint/blob/main/models/saint.py"
    click SAINTI "https://github.com/ogunlao/saint/blob/main/models/saint_i.py"
    click SAINTS "https://github.com/ogunlao/saint/blob/main/models/saint_s.py"
    click Embed "https://github.com/ogunlao/saint/blob/main/models/embedding.py"
    click Trans "https://github.com/ogunlao/saint/blob/main/models/transformer.py"
    click ModelGen "https://github.com/ogunlao/saint/blob/main/models/model_generator.py"
    click Train "https://github.com/ogunlao/saint/blob/main/src/train.py"
    click Trainer "https://github.com/ogunlao/saint/blob/main/src/trainer.py"
    click ContLoss,DenoiseLoss "https://github.com/ogunlao/saint/blob/main/utils/loss.py"
    click Mixup,CutMix "https://github.com/ogunlao/saint/blob/main/utils/augment.py"
    click SupConfig "https://github.com/ogunlao/saint/blob/main/configs/experiment/supervised.yaml"
    click SSLConfig "https://github.com/ogunlao/saint/blob/main/configs/experiment/self-supervised.yaml"
    click PredConfig "https://github.com/ogunlao/saint/blob/main/configs/experiment/predict.yaml"
    click BankSSL "https://github.com/ogunlao/saint/blob/main/configs/data/bank_ssl.yaml"
    click BankSup "https://github.com/ogunlao/saint/blob/main/configs/data/bank_sup.yaml"
    click Insurance "https://github.com/ogunlao/saint/blob/main/configs/data/insurance_sup.yaml"
    click PredImpl "https://github.com/ogunlao/saint/blob/main/predict.py"
    click MainEntry "https://github.com/ogunlao/saint/blob/main/main.py"
    click Utils "https://github.com/ogunlao/saint/blob/main/utils/utils.py"
```
