# markocvjetko/transformer architecture

> Architecture diagram of the GitHub repository markocvjetko/transformer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/markocvjetko/transformer
- Repository: https://github.com/markocvjetko/transformer

## Overview

This is a learning-oriented NLP/transformer project: it prepares text and translation corpora, tokenizes them, trains causal language models and an encoder–decoder Transformer, and evaluates models. The main workflows are corpus-to-token-sequences-to-language-model training, and bilingual sentence pairs-to-translation training. The graph includes the documented BPE and Transformer capabilities plus the GPT-2-style and evaluation branches visible in the tree. Some preparation and generation scripts were not sampled, so uncertain runtime links are omitted.

Main entry points: [`src/tokenizers/BPE.py`](https://github.com/markocvjetko/transformer/blob/main/src/tokenizers/BPE.py) (Byte-pair tokenizer), [`src/scripts/gpt2-test-large/train_gpt2.py`](https://github.com/markocvjetko/transformer/blob/main/src/scripts/gpt2-test-large/train_gpt2.py) (GPT-2 training entry), [`src/lightning/lit_gpt.py`](https://github.com/markocvjetko/transformer/blob/main/src/lightning/lit_gpt.py) (GPT training module), [`src/scripts/gpt2-test-large/train_lm.py`](https://github.com/markocvjetko/transformer/blob/main/src/scripts/gpt2-test-large/train_lm.py) (Language-model training entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_corpora["Corpus preparation"]
  node_prep["Corpus preprocessing"]
  node_prep_scripts["Corpus preparation scripts"]
  node_translation_prep["Translation experiments"]
end

subgraph group_data["Data and tokenization"]
  node_tokenizer["Byte-pair tokenizer<br/>[BPE.py]"]
  node_pretokenizer["Pretokenizers<br/>[pretokenizers.py]"]
  node_translation_data["Translation dataset<br/>[translation.py]"]
  node_next_token["Next-token dataset<br/>[next_token.py]"]
  node_mixture["Token mixture sampler<br/>[token_mixture.py]"]
  node_token_arrays[("Tokenized corpus arrays")]
  node_paths["Data and experiment paths<br/>[paths.py]"]
end

subgraph group_models["Models and training"]
  node_gpt2["GPT-2 model<br/>[gpt2.py]"]
  node_decoder_lm["Decoder language model<br/>[lm.py]"]
  node_transformer["Encoder–decoder Transformer<br/>[transformer.py]"]
  node_lit_gpt["GPT training module<br/>[lit_gpt.py]"]
  node_lit_transformer["Transformer training module<br/>[lit_transformer.py]"]
  node_train_gpt2["GPT-2 training entry<br/>[train_gpt2.py]"]
  node_train_lm["Language-model training entry<br/>[train_lm.py]"]
  node_train_translation["Translation training entry<br/>[train_hr_en.py]"]
  node_scheduler["Learning-rate scheduler<br/>[scheduler.py]"]
end

subgraph group_evaluation["Evaluation"]
  node_metrics["Language-model metrics<br/>[metrics.py]"]
  node_belebele["Belebele evaluation<br/>[belebele.py]"]
  node_translation_eval["Translation evaluation<br/>[eval_hr_en.py]"]
end

node_user(("Researcher"))

node_user -->|"prepares corpora"| node_prep_scripts
node_user -->|"trains models"| node_train_gpt2
node_user -->|"trains translation"| node_train_translation
node_prep -->|"uses data paths"| node_paths
node_prep_scripts -->|"uses tokenizer"| node_tokenizer
node_prep_scripts -->|"uses data paths"| node_paths
node_translation_prep -->|"uses tokenizer"| node_tokenizer
node_translation_prep -->|"uses dataset"| node_translation_data
node_translation_prep -->|"uses model"| node_transformer
node_tokenizer -->|"uses pretokenizer"| node_pretokenizer
node_translation_data -->|"tokenizes pairs"| node_tokenizer
node_next_token -->|"decodes tokens"| node_tokenizer
node_next_token -->|"reads sequences"| node_token_arrays
node_mixture -->|"samples arrays"| node_token_arrays
node_train_gpt2 -->|"loads dataset"| node_next_token
node_train_gpt2 -->|"loads dataset"| node_mixture
node_train_gpt2 -->|"trains module"| node_lit_gpt
node_train_gpt2 -->|"constructs model"| node_gpt2
node_train_gpt2 -->|"uses metrics"| node_metrics
node_train_lm -->|"loads dataset"| node_next_token
node_train_lm -->|"loads dataset"| node_mixture
node_train_lm -->|"trains module"| node_lit_gpt
node_train_lm -->|"constructs model"| node_decoder_lm
node_train_lm -->|"uses metrics"| node_metrics
node_lit_gpt -->|"uses dataset"| node_next_token
node_lit_gpt -->|"imports model"| node_gpt2
node_lit_gpt -->|"configures scheduler"| node_scheduler
node_lit_transformer -->|"uses dataset"| node_translation_data
node_lit_transformer -->|"imports model"| node_transformer
node_train_translation -->|"trains module"| node_lit_transformer
node_train_translation -->|"loads dataset"| node_translation_data
node_train_translation -->|"constructs model"| node_transformer
node_belebele -->|"loads checkpoint"| node_lit_gpt
node_belebele -->|"constructs model"| node_decoder_lm
node_belebele -->|"tokenizes prompts"| node_tokenizer
node_translation_eval -->|"loads dataset"| node_translation_data
node_translation_eval -->|"uses model"| node_transformer
node_translation_eval -->|"uses tokenizer"| node_tokenizer

click node_prep "https://github.com/markocvjetko/transformer/tree/main/src/datasets/preprocess"
click node_prep_scripts "https://github.com/markocvjetko/transformer/tree/main/src/scripts/gpt2-test-large"
click node_translation_prep "https://github.com/markocvjetko/transformer/tree/main/src/scripts/hr-en"
click node_tokenizer "https://github.com/markocvjetko/transformer/blob/main/src/tokenizers/BPE.py"
click node_pretokenizer "https://github.com/markocvjetko/transformer/blob/main/src/tokenizers/pretokenizers.py"
click node_translation_data "https://github.com/markocvjetko/transformer/blob/main/src/datasets/translation.py"
click node_next_token "https://github.com/markocvjetko/transformer/blob/main/src/datasets/next_token.py"
click node_mixture "https://github.com/markocvjetko/transformer/blob/main/src/datasets/token_mixture.py"
click node_gpt2 "https://github.com/markocvjetko/transformer/blob/main/src/models/gpt2.py"
click node_decoder_lm "https://github.com/markocvjetko/transformer/blob/main/src/models/lm.py"
click node_transformer "https://github.com/markocvjetko/transformer/blob/main/src/models/transformer.py"
click node_lit_gpt "https://github.com/markocvjetko/transformer/blob/main/src/lightning/lit_gpt.py"
click node_lit_transformer "https://github.com/markocvjetko/transformer/blob/main/src/lightning/lit_transformer.py"
click node_train_gpt2 "https://github.com/markocvjetko/transformer/blob/main/src/scripts/gpt2-test-large/train_gpt2.py"
click node_train_lm "https://github.com/markocvjetko/transformer/blob/main/src/scripts/gpt2-test-large/train_lm.py"
click node_train_translation "https://github.com/markocvjetko/transformer/blob/main/src/scripts/hr-en/train_hr_en.py"
click node_scheduler "https://github.com/markocvjetko/transformer/blob/main/src/optim/scheduler.py"
click node_metrics "https://github.com/markocvjetko/transformer/blob/main/src/metrics/metrics.py"
click node_belebele "https://github.com/markocvjetko/transformer/blob/main/src/eval/belebele.py"
click node_translation_eval "https://github.com/markocvjetko/transformer/blob/main/src/scripts/hr-en/eval_hr_en.py"
click node_paths "https://github.com/markocvjetko/transformer/blob/main/src/utils/paths.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_prep,node_prep_scripts,node_translation_prep toneBlue
class node_tokenizer,node_pretokenizer,node_translation_data,node_next_token,node_mixture,node_token_arrays,node_paths toneAmber
class node_gpt2,node_decoder_lm,node_transformer,node_lit_gpt,node_lit_transformer,node_train_gpt2,node_train_lm,node_train_translation,node_scheduler toneMint
class node_metrics,node_belebele,node_translation_eval toneRose
class node_user toneIndigo
```

## Components

### Corpus preparation

- [Corpus preprocessing](https://github.com/markocvjetko/transformer/tree/main/src/datasets/preprocess): `src/datasets/preprocess`
- [Corpus preparation scripts](https://github.com/markocvjetko/transformer/tree/main/src/scripts/gpt2-test-large): `src/scripts/gpt2-test-large`
- [Translation experiments](https://github.com/markocvjetko/transformer/tree/main/src/scripts/hr-en): `src/scripts/hr-en`

### Data and tokenization

- [Byte-pair tokenizer](https://github.com/markocvjetko/transformer/blob/main/src/tokenizers/BPE.py): `src/tokenizers/BPE.py`
- [Pretokenizers](https://github.com/markocvjetko/transformer/blob/main/src/tokenizers/pretokenizers.py): `src/tokenizers/pretokenizers.py`
- [Translation dataset](https://github.com/markocvjetko/transformer/blob/main/src/datasets/translation.py): `src/datasets/translation.py`
- [Next-token dataset](https://github.com/markocvjetko/transformer/blob/main/src/datasets/next_token.py): `src/datasets/next_token.py`
- [Token mixture sampler](https://github.com/markocvjetko/transformer/blob/main/src/datasets/token_mixture.py): `src/datasets/token_mixture.py`
- **Tokenized corpus arrays**
- [Data and experiment paths](https://github.com/markocvjetko/transformer/blob/main/src/utils/paths.py): `src/utils/paths.py`

### Models and training

- [GPT-2 model](https://github.com/markocvjetko/transformer/blob/main/src/models/gpt2.py): `src/models/gpt2.py`
- [Decoder language model](https://github.com/markocvjetko/transformer/blob/main/src/models/lm.py): `src/models/lm.py`
- [Encoder–decoder Transformer](https://github.com/markocvjetko/transformer/blob/main/src/models/transformer.py): `src/models/transformer.py`
- [GPT training module](https://github.com/markocvjetko/transformer/blob/main/src/lightning/lit_gpt.py): `src/lightning/lit_gpt.py`
- [Transformer training module](https://github.com/markocvjetko/transformer/blob/main/src/lightning/lit_transformer.py): `src/lightning/lit_transformer.py`
- [GPT-2 training entry](https://github.com/markocvjetko/transformer/blob/main/src/scripts/gpt2-test-large/train_gpt2.py): `src/scripts/gpt2-test-large/train_gpt2.py`
- [Language-model training entry](https://github.com/markocvjetko/transformer/blob/main/src/scripts/gpt2-test-large/train_lm.py): `src/scripts/gpt2-test-large/train_lm.py`
- [Translation training entry](https://github.com/markocvjetko/transformer/blob/main/src/scripts/hr-en/train_hr_en.py): `src/scripts/hr-en/train_hr_en.py`
- [Learning-rate scheduler](https://github.com/markocvjetko/transformer/blob/main/src/optim/scheduler.py): `src/optim/scheduler.py`

### Evaluation

- [Language-model metrics](https://github.com/markocvjetko/transformer/blob/main/src/metrics/metrics.py): `src/metrics/metrics.py`
- [Belebele evaluation](https://github.com/markocvjetko/transformer/blob/main/src/eval/belebele.py): `src/eval/belebele.py`
- [Translation evaluation](https://github.com/markocvjetko/transformer/blob/main/src/scripts/hr-en/eval_hr_en.py): `src/scripts/hr-en/eval_hr_en.py`

### Other components

- **Researcher**

## Connections

- Researcher → Corpus preparation scripts: prepares corpora (evidence: `README.md`)
- Researcher → GPT-2 training entry: trains models (evidence: `README.md`)
- Researcher → Translation training entry: trains translation (evidence: `README.md`)
- Corpus preprocessing → Data and experiment paths: uses data paths (evidence: `src/datasets/preprocess/hrenwac_v2.py`)
- Corpus preparation scripts → Byte-pair tokenizer: uses tokenizer (evidence: `src/scripts/gpt2-test-large/prepare_classla_v2.py`)
- Corpus preparation scripts → Data and experiment paths: uses data paths (evidence: `src/scripts/gpt2-test-large/prepare_classla_v2.py`)
- Translation experiments → Byte-pair tokenizer: uses tokenizer (evidence: `src/scripts/hr-en/train_hr_en.py`)
- Translation experiments → Translation dataset: uses dataset (evidence: `src/scripts/hr-en/train_hr_en.py`)
- Translation experiments → Encoder–decoder Transformer: uses model (evidence: `src/scripts/hr-en/train_hr_en.py`)
- Byte-pair tokenizer → Pretokenizers: uses pretokenizer (evidence: `src/tokenizers/BPE.py`)
- Translation dataset → Byte-pair tokenizer: tokenizes pairs (evidence: `src/datasets/translation.py`)
- Next-token dataset → Byte-pair tokenizer: decodes tokens (evidence: `src/datasets/next_token.py`)
- Next-token dataset → Tokenized corpus arrays: reads sequences (evidence: `src/datasets/next_token.py`)
- Token mixture sampler → Tokenized corpus arrays: samples arrays (evidence: `src/datasets/token_mixture.py`)
- GPT-2 training entry → Next-token dataset: loads dataset (evidence: `src/scripts/gpt2-test-large/train_gpt2.py`)
- GPT-2 training entry → Token mixture sampler: loads dataset (evidence: `src/scripts/gpt2-test-large/train_gpt2.py`)
- GPT-2 training entry → GPT training module: trains module (evidence: `src/scripts/gpt2-test-large/train_gpt2.py`)
- GPT-2 training entry → GPT-2 model: constructs model (evidence: `src/scripts/gpt2-test-large/train_gpt2.py`)
- GPT-2 training entry → Language-model metrics: uses metrics (evidence: `src/scripts/gpt2-test-large/train_gpt2.py`)
- Language-model training entry → Next-token dataset: loads dataset (evidence: `src/scripts/gpt2-test-large/train_lm.py`)
- Language-model training entry → Token mixture sampler: loads dataset (evidence: `src/scripts/gpt2-test-large/train_lm.py`)
- Language-model training entry → GPT training module: trains module (evidence: `src/scripts/gpt2-test-large/train_lm.py`)
- Language-model training entry → Decoder language model: constructs model (evidence: `src/scripts/gpt2-test-large/train_lm.py`)
- Language-model training entry → Language-model metrics: uses metrics (evidence: `src/scripts/gpt2-test-large/train_lm.py`)
- GPT training module → Next-token dataset: uses dataset (evidence: `src/lightning/lit_gpt.py`)
- GPT training module → GPT-2 model: imports model (evidence: `src/lightning/lit_gpt.py`)
- GPT training module → Learning-rate scheduler: configures scheduler (evidence: `src/lightning/lit_gpt.py`)
- Transformer training module → Translation dataset: uses dataset (evidence: `src/lightning/lit_transformer.py`)
- Transformer training module → Encoder–decoder Transformer: imports model (evidence: `src/lightning/lit_transformer.py`)
- Translation training entry → Transformer training module: trains module (evidence: `src/scripts/hr-en/train_hr_en.py`)
- Translation training entry → Translation dataset: loads dataset (evidence: `src/scripts/hr-en/train_hr_en.py`)
- Translation training entry → Encoder–decoder Transformer: constructs model (evidence: `src/scripts/hr-en/train_hr_en.py`)
- Belebele evaluation → GPT training module: loads checkpoint (evidence: `src/eval/belebele.py`)
- Belebele evaluation → Decoder language model: constructs model (evidence: `src/eval/belebele.py`)
- Belebele evaluation → Byte-pair tokenizer: tokenizes prompts (evidence: `src/eval/belebele.py`)
- Translation evaluation → Translation dataset: loads dataset (evidence: `src/scripts/hr-en/eval_hr_en.py`)
- Translation evaluation → Encoder–decoder Transformer: uses model (evidence: `src/scripts/hr-en/eval_hr_en.py`)
- Translation evaluation → Byte-pair tokenizer: uses tokenizer (evidence: `src/scripts/hr-en/eval_hr_en.py`)
