# jyansir/tp-berta architecture

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

- Interactive diagram: https://gitdiagram.com/jyansir/tp-berta
- Repository: https://github.com/jyansir/tp-berta

## Overview

##### Core Purpose and Project Type
- This is a research-oriented project that adapts a pre-trained language model (RoBERTa) for tabular data prediction by incorporating techniques such as Relative Magnitude Tokenization (RMT) and Intra-feature Attention (IFA).
- Its architecture includes both baseline DNN models (like autoint, dcnv2, mlp, and saint) and the special TP-BERTa model that leverages language modeling techniques.

##### Break Down the Main Components
a. Model Implementations (bin):
– Contains the implementation of various tabular models.
– Key files include tpberta_modeling.py for the TP-BERTa base class and other baseline models (e.g., autoint.py, dcn2.py, mlp.py, saint.py).
b. Utilities and Core Libraries (lib):
– Includes helper modules for data processing (data.py, data_utils.py), feature engineering (feature_encoder.py), training utilities (optim.py), environmental settings (env.py), and additional modules dedicated to TP-BERTa (lib/saint_lib).
c. Configuration Management (configs):
– Offers default and tuned configuration files for different model types (autoint, catboost, dcnv2, tabnet, xgboost), which help tailor model parameters and training settings.
d. Experiment and Execution Scripts (scripts):
– Houses examples and actual experiment scripts for pre-training (scripts/pretrain) and fine-tuning (scripts/finetune) scenarios. These scripts coordinate the execution of training pipelines and hyperparameter tuning.
e. External Assets:
– External pre-trained models/checkpoints (e.g., RoBERTa under checkpoints/roberta-base) and data preparations (data directory, not shown in the file tree excerpt but mentioned in the README).

##### Relationships and Interactions
- Data Pipeline: External data (CSV files in the data directory, as per README instructions) is ingested and processed using the classes and utilities defined in lib (data.py, data_utils.py, feature_encoder.py).
- Model Training Flow:
- The configuration files from configs provide the experiment parameters.
- Scripts (in scripts/) drive the training workflow: pre-training TP-BERTa (scripts/pretrain) and fine-tuning (scripts/finetune, with examples provided in scripts/examples).
- These scripts make calls to the model implementations in bin (such as tpberta_modeling.py) and use the helper modules in lib.
- Pre-trained and Fine-tuned Models:
- The system uses pre-trained RoBERTa weights (from checkpoints/roberta-base) that are adapted by TP-BERTa.
- Fine-tuning experiments align with the downstream tabular prediction tasks.

##### Important Architectural Patterns and Design Principles
- Modularity: There’s a clear separation of concerns – the project separates model code from utilities, configurations, and experiment orchestration.
- Experimentation-Driven: Dedicated scripts and configuration folders support various experiments including pre-training, fine-tuning, and hyperparameter tuning.
- Extensibility: The structure permits adding more baseline models and different configurations (default versus tuned) to experiment with alternative architectures.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Data & Preprocessing
    subgraph "Data & Preprocessing"
        DS("Raw Data (CSV)"):::data
        DP1("Data Loader (data.py)"):::data
        DP2("Data Utils (data_utils.py)"):::data
        FP("Feature Encoder (feature_encoder.py)"):::data
    end

    %% Configuration Manager
    subgraph "Configuration Manager"
        CONF("Configs (configs/default)"):::config
    end

    %% Model Components
    subgraph "Model Components"
        TPB("TP-BERTa Model (tpberta_modeling.py)"):::model
        AUT("Autoint Model (autoint.py)"):::model
        DCN("DCN Model (dcn2.py)"):::model
        MLP("MLP Model (mlp.py)"):::model
        SAINT("SAINT Model (saint.py)"):::model
    end

    %% Utilities & Training Infrastructure
    subgraph "Utilities & Training Infrastructure"
        OPT("Optimizer (optim.py)"):::util
        ENV("Environment (env.py)"):::util
        SAINT_LIB("SAINT Lib (lib/saint_lib)"):::util
    end

    %% Experiment Scripts
    subgraph "Experiment Scripts"
        PRE("Pre-training Script (pretrain_tpberta.py)"):::script
        FT("Fine-tuning Scripts (scripts/finetune)"):::script
        EX("Example Scripts (scripts/examples)"):::script
    end

    %% External Dependencies
    subgraph "External Dependencies"
        EXT1("Pre-trained RoBERTa (checkpoints/roberta-base)"):::external
        EXT2("Data Directory"):::external
    end

    %% Connections
    %% Data Flow
    DS --> DP1
    DS --> DP2
    DP1 --> FP
    DP2 --> FP
    FP --> TPB
    FP --> AUT
    FP --> DCN
    FP --> MLP
    FP --> SAINT

    %% Configurations impact Experiments and Models
    CONF --> PRE
    CONF --> FT
    CONF --> TPB
    CONF --> AUT
    CONF --> DCN
    CONF --> MLP
    CONF --> SAINT

    %% Experiment Scripts invoke Utilities and Model Training
    PRE --> OPT
    PRE --> ENV
    PRE --> TPB
    FT --> OPT
    FT --> ENV
    FT --> TPB
    PRE --> SAINT_LIB
    FT --> SAINT_LIB
    FT --- EX

    %% Utilities support Models
    OPT --> TPB
    ENV --> TPB
    SAINT_LIB --> SAINT

    %% External Dependencies provide Resources to Models and Data Pipeline
    EXT1 --> TPB
    EXT2 --> DS

    %% Styles
    classDef data fill:#F4EFEF,stroke:#333,stroke-width:2px;
    classDef config fill:#CDE7FF,stroke:#333,stroke-width:2px;
    classDef model fill:#DFF2BF,stroke:#333,stroke-width:2px;
    classDef util fill:#FFE4B5,stroke:#333,stroke-width:2px;
    classDef script fill:#E6E6FA,stroke:#333,stroke-width:2px;
    classDef external fill:#FFF2CC,stroke:#333,stroke-width:2px;

    %% Click Events for Model Implementations
    click TPB "https://github.com/jyansir/tp-berta/blob/main/bin/tpberta_modeling.py"
    click AUT "https://github.com/jyansir/tp-berta/blob/main/bin/autoint.py"
    click DCN "https://github.com/jyansir/tp-berta/blob/main/bin/dcn2.py"
    click MLP "https://github.com/jyansir/tp-berta/blob/main/bin/mlp.py"
    click SAINT "https://github.com/jyansir/tp-berta/blob/main/bin/saint.py"

    %% Click Events for Utilities & Core Libraries
    click DP1 "https://github.com/jyansir/tp-berta/blob/main/lib/data.py"
    click DP2 "https://github.com/jyansir/tp-berta/blob/main/lib/data_utils.py"
    click FP "https://github.com/jyansir/tp-berta/blob/main/lib/feature_encoder.py"
    click OPT "https://github.com/jyansir/tp-berta/blob/main/lib/optim.py"
    click ENV "https://github.com/jyansir/tp-berta/blob/main/lib/env.py"
    click SAINT_LIB "https://github.com/jyansir/tp-berta/tree/main/lib/saint_lib"

    %% Click Events for Configuration Management
    click CONF "https://github.com/jyansir/tp-berta/tree/main/configs/default"

    %% Click Events for Experiment and Execution Scripts
    click PRE "https://github.com/jyansir/tp-berta/blob/main/scripts/pretrain/pretrain_tpberta.py"
    click FT "https://github.com/jyansir/tp-berta/tree/main/scripts/finetune"
    click EX "https://github.com/jyansir/tp-berta/tree/main/scripts/examples"

    %% Click Events for External Assets
    click EXT1 "https://github.com/jyansir/tp-berta/tree/main/checkpoints/roberta-base"
    click EXT2 "https://github.com/jyansir/tp-berta/tree/main/data"
```
