# aimat-lab/llm-data-extraction architecture

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

- Interactive diagram: https://gitdiagram.com/aimat-lab/llm-data-extraction
- Repository: https://github.com/aimat-lab/llm-data-extraction

## Overview

##### Project type and purpose
- This is an academic “mthesis” repository for a Master’s thesis. It contains four main subsystems:
- expose: initial planning document (LaTeX)
- code: final experiment code, configs, and job scripts
- thesis_document: LaTeX source for the written thesis
- defense: LaTeX source and assets for the defense presentation
- The heart of the system is the `code` directory, which implements data loading, model definition, training, evaluation, and experiment orchestration.

##### File structure
- Top-level directories separate concerns:
- code/ – Python project (pyproject.toml, shell.nix, settings/, jobs/, src/)
- thesis_document/, expose/, defense/ – LaTeX projects for write-up and presentations
- Inside code/:
- settings/: YAML configs for different model sizes (7B, 13B, large)
- jobs/: batch job scripts (.job) that invoke the training pipeline on HPC
- src/mthesis/: Python package with modules:
– main.py (CLI entrypoint)
– dataloader.py (data ingestion)
– conversion.py (pre/post-processing)
– models.py (model instantiation)
– trainer.py (training loop orchestration)
– stats.py, confusion.py (evaluation metrics & confusion matrices)
– utils.py (shared utilities)
– train_example.py (demo or quick-start)
- Configuration: shell.nix fixes dependencies; pyproject.toml manages the Python package.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "LaTeX Projects"
        EXPOSE["Expose"]:::latex
        THESIS["Thesis Document"]:::latex
        DEFENSE["Defense Presentation"]:::latex
    end

    subgraph "Environment & Deployment"
        NIX["shell.nix"]:::deployment
        PYPROJ["pyproject.toml"]:::deployment
        JOB7["run_7b.job"]:::deployment
        JOB13["run_13b.job"]:::deployment
        JOBL["run_large.job"]:::deployment
    end

    subgraph "Code Subsystem"
        CLI["Experiment Runner / CLI"]:::python
        CONFIG["Configuration Loader"]:::config
        DATA["Data Layer"]:::python
        CONV["Pre/Post Processing"]:::python
        MODEL["Model Definition"]:::python
        TRAIN["Training Engine"]:::python
        EVAL["Evaluation & Metrics"]:::python
        UTILS["Utility Layer"]:::python
    end

    OUTPUT["stats.yml"]:::output

    %% Data Flow
    NIX -->|provides env| CLI
    PYPROJ -->|provides deps| CLI
    JOB7 -->|submits| CLI
    JOB13 -->|submits| CLI
    JOBL -->|submits| CLI

    CLI -->|"load settings"| CONFIG
    CONFIG -->|"config params"| DATA
    DATA -->|"raw data"| CONV
    CONV -->|"processed data"| TRAIN
    TRAIN -->|"training loops"| MODEL
    MODEL -->|"model outputs"| TRAIN
    TRAIN -->|"results"| EVAL
    EVAL -->|"metrics"| OUTPUT

    %% Utilities used by modules
    UTILS -.-> CLI
    UTILS -.-> DATA
    UTILS -.-> CONV
    UTILS -.-> TRAIN
    UTILS -.-> EVAL

    %% Click Events
    click CLI "https://github.com/aimat-lab/llm-data-extraction/blob/main/code/src/mthesis/main.py"
    click CONFIG "https://github.com/aimat-lab/llm-data-extraction/blob/main/code/settings/settings_7b.yml"
    click CONFIG "https://github.com/aimat-lab/llm-data-extraction/blob/main/code/settings/settings_13b.yml"
    click CONFIG "https://github.com/aimat-lab/llm-data-extraction/blob/main/code/settings/settings_large.yml"
    click DATA "https://github.com/aimat-lab/llm-data-extraction/blob/main/code/src/mthesis/dataloader.py"
    click CONV "https://github.com/aimat-lab/llm-data-extraction/blob/main/code/src/mthesis/conversion.py"
    click MODEL "https://github.com/aimat-lab/llm-data-extraction/blob/main/code/src/mthesis/models.py"
    click TRAIN "https://github.com/aimat-lab/llm-data-extraction/blob/main/code/src/mthesis/trainer.py"
    click EVAL "https://github.com/aimat-lab/llm-data-extraction/blob/main/code/src/mthesis/stats.py"
    click EVAL "https://github.com/aimat-lab/llm-data-extraction/blob/main/code/src/mthesis/confusion.py"
    click UTILS "https://github.com/aimat-lab/llm-data-extraction/blob/main/code/src/mthesis/utils.py"
    click JOB7 "https://github.com/aimat-lab/llm-data-extraction/blob/main/code/jobs/run_7b.job"
    click JOB13 "https://github.com/aimat-lab/llm-data-extraction/blob/main/code/jobs/run_13b.job"
    click JOBL "https://github.com/aimat-lab/llm-data-extraction/blob/main/code/jobs/run_large.job"
    click NIX "https://github.com/aimat-lab/llm-data-extraction/blob/main/code/shell.nix"
    click PYPROJ "https://github.com/aimat-lab/llm-data-extraction/blob/main/code/pyproject.toml"
    click OUTPUT "https://github.com/aimat-lab/llm-data-extraction/blob/main/code/stats.yml"
    click EXPOSE "https://github.com/aimat-lab/llm-data-extraction/tree/main/expose/"
    click THESIS "https://github.com/aimat-lab/llm-data-extraction/tree/main/thesis_document/"
    click DEFENSE "https://github.com/aimat-lab/llm-data-extraction/tree/main/defense/"

    %% Styles
    classDef python fill:#D0E6FF,stroke:#034EA2,stroke-width:1px
    classDef config fill:#DFFFD0,stroke:#4A7E00,stroke-width:1px
    classDef deployment fill:#FFE6C7,stroke:#B25F00,stroke-width:1px
    classDef output fill:#E0E0E0,stroke:#666666,stroke-width:1px,stroke-dasharray: 5 5
    classDef latex fill:#F0E6FF,stroke:#5C2E91,stroke-width:1px
```
