# uditsharma29/learn-transformers architecture

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

- Interactive diagram: https://gitdiagram.com/uditsharma29/learn-transformers
- Repository: https://github.com/uditsharma29/learn-transformers

## Overview

Learn Transformers is a hands-on educational playground, not a single application pipeline. Its main user journey moves from Transformer building blocks to model-specific demonstrations and advanced topics. The graph preserves the README’s BERT, GPT-2, T5, efficiency, training, and interactive-notebook branches. Source excerpts show implementation details for the core examples; unsampled notebook content and the README-described learning order are represented only at that documented level.

Main entry points: [`scratch_transformer.py`](https://github.com/uditsharma29/learn-transformers/blob/main/scratch_transformer.py) (Scratch Transformer), [`training_loop_template.py`](https://github.com/uditsharma29/learn-transformers/blob/main/training_loop_template.py) (Fine-tuning template), [`encoder_only_bert_example.py`](https://github.com/uditsharma29/learn-transformers/blob/main/encoder_only_bert_example.py) (BERT classifier), [`decoder_only_gpt2_example.py`](https://github.com/uditsharma29/learn-transformers/blob/main/decoder_only_gpt2_example.py) (GPT-2 generation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_fundamentals["Building blocks"]
  node_vanilla["Encoder block"]
  node_scratch["Scratch Transformer"]
  node_attention["Attention layers"]
  node_feedforward["Feed-forward"]
end

subgraph group_architectures["Model architectures"]
  node_encoder["Encoder stack"]
  node_decoder["Decoder stack"]
  node_seq2seq["Seq2seq model"]
end

subgraph group_applications["Model demonstrations"]
  node_bert["BERT classifier"]
  node_gpt2["GPT-2 generation"]
  node_t5["T5 summarization"]
end

subgraph group_advanced["Advanced learning"]
  node_efficiency["Efficient variants"]
  node_training["Fine-tuning template"]
  node_notebook["Interactive tutorial"]
end

node_learner(("Learner"))
node_modelhub["Hugging Face models"]
node_newsdata[("AG News dataset")]

node_learner -->|"starts with"| node_vanilla
node_learner -->|"builds from scratch"| node_scratch
node_learner -->|"tries classification"| node_bert
node_learner -->|"tries generation"| node_gpt2
node_learner -->|"tries summarization"| node_t5
node_learner -->|"explores variants"| node_efficiency
node_learner -->|"explores fine-tuning"| node_training
node_learner -->|"opens exercises"| node_notebook
node_scratch -->|"uses"| node_attention
node_scratch -->|"uses"| node_feedforward
node_scratch -->|"defines"| node_encoder
node_scratch -->|"defines"| node_decoder
node_scratch -->|"constructs"| node_encoder
node_scratch -->|"constructs"| node_decoder
node_scratch -->|"assembles"| node_seq2seq
node_encoder -->|"calls"| node_attention
node_encoder -->|"calls"| node_feedforward
node_decoder -->|"uses self and cross"| node_attention
node_decoder -->|"calls"| node_feedforward
node_seq2seq -->|"encodes input"| node_encoder
node_seq2seq -->|"decodes memory"| node_decoder
node_bert -->|"loads model and tokenizer"| node_modelhub
node_gpt2 -->|"loads model and tokenizer"| node_modelhub
node_t5 -->|"loads model and tokenizer"| node_modelhub
node_efficiency -->|"loads variants"| node_modelhub
node_training -->|"loads BERT"| node_modelhub
node_training -->|"loads dataset"| node_newsdata

click node_vanilla "https://github.com/uditsharma29/learn-transformers/blob/main/vanilla_transformer_block.py"
click node_scratch "https://github.com/uditsharma29/learn-transformers/blob/main/scratch_transformer.py"
click node_attention "https://github.com/uditsharma29/learn-transformers/blob/main/scratch_transformer.py"
click node_feedforward "https://github.com/uditsharma29/learn-transformers/blob/main/scratch_transformer.py"
click node_encoder "https://github.com/uditsharma29/learn-transformers/blob/main/scratch_transformer.py"
click node_decoder "https://github.com/uditsharma29/learn-transformers/blob/main/scratch_transformer.py"
click node_seq2seq "https://github.com/uditsharma29/learn-transformers/blob/main/scratch_transformer.py"
click node_bert "https://github.com/uditsharma29/learn-transformers/blob/main/encoder_only_bert_example.py"
click node_gpt2 "https://github.com/uditsharma29/learn-transformers/blob/main/decoder_only_gpt2_example.py"
click node_t5 "https://github.com/uditsharma29/learn-transformers/blob/main/seq2seq_t5_example.py"
click node_efficiency "https://github.com/uditsharma29/learn-transformers/blob/main/efficiency_models_examples.py"
click node_training "https://github.com/uditsharma29/learn-transformers/blob/main/training_loop_template.py"
click node_notebook "https://github.com/uditsharma29/learn-transformers/blob/main/transformer_tutorial.ipynb"

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_vanilla,node_scratch,node_attention,node_feedforward toneBlue
class node_encoder,node_decoder,node_seq2seq,node_newsdata toneAmber
class node_bert,node_gpt2,node_t5 toneMint
class node_efficiency,node_training,node_notebook toneRose
class node_learner,node_modelhub toneIndigo
```

## Components

### Building blocks

- [Encoder block](https://github.com/uditsharma29/learn-transformers/blob/main/vanilla_transformer_block.py): `vanilla_transformer_block.py`
- [Scratch Transformer](https://github.com/uditsharma29/learn-transformers/blob/main/scratch_transformer.py): `scratch_transformer.py`
- [Attention layers](https://github.com/uditsharma29/learn-transformers/blob/main/scratch_transformer.py): `scratch_transformer.py`
- [Feed-forward](https://github.com/uditsharma29/learn-transformers/blob/main/scratch_transformer.py): `scratch_transformer.py`

### Model architectures

- [Encoder stack](https://github.com/uditsharma29/learn-transformers/blob/main/scratch_transformer.py): `scratch_transformer.py`
- [Decoder stack](https://github.com/uditsharma29/learn-transformers/blob/main/scratch_transformer.py): `scratch_transformer.py`
- [Seq2seq model](https://github.com/uditsharma29/learn-transformers/blob/main/scratch_transformer.py): `scratch_transformer.py`

### Model demonstrations

- [BERT classifier](https://github.com/uditsharma29/learn-transformers/blob/main/encoder_only_bert_example.py): `encoder_only_bert_example.py`
- [GPT-2 generation](https://github.com/uditsharma29/learn-transformers/blob/main/decoder_only_gpt2_example.py): `decoder_only_gpt2_example.py`
- [T5 summarization](https://github.com/uditsharma29/learn-transformers/blob/main/seq2seq_t5_example.py): `seq2seq_t5_example.py`

### Advanced learning

- [Efficient variants](https://github.com/uditsharma29/learn-transformers/blob/main/efficiency_models_examples.py): `efficiency_models_examples.py`
- [Fine-tuning template](https://github.com/uditsharma29/learn-transformers/blob/main/training_loop_template.py): `training_loop_template.py`
- [Interactive tutorial](https://github.com/uditsharma29/learn-transformers/blob/main/transformer_tutorial.ipynb): `transformer_tutorial.ipynb`

### Other components

- **Learner**
- **Hugging Face models**
- **AG News dataset**

## Connections

- Learner → Encoder block: starts with (evidence: `README.md`)
- Learner → Scratch Transformer: builds from scratch (evidence: `README.md`)
- Learner → BERT classifier: tries classification (evidence: `README.md`)
- Learner → GPT-2 generation: tries generation (evidence: `README.md`)
- Learner → T5 summarization: tries summarization (evidence: `README.md`)
- Learner → Efficient variants: explores variants (evidence: `README.md`)
- Learner → Fine-tuning template: explores fine-tuning (evidence: `README.md`)
- Learner → Interactive tutorial: opens exercises (evidence: `README.md`)
- Scratch Transformer → Attention layers: uses (evidence: `scratch_transformer.py`)
- Scratch Transformer → Feed-forward: uses (evidence: `scratch_transformer.py`)
- Scratch Transformer → Encoder stack: defines (evidence: `scratch_transformer.py`)
- Scratch Transformer → Decoder stack: defines (evidence: `scratch_transformer.py`)
- Scratch Transformer → Encoder stack: constructs (evidence: `scratch_transformer.py`)
- Scratch Transformer → Decoder stack: constructs (evidence: `scratch_transformer.py`)
- Scratch Transformer → Seq2seq model: assembles (evidence: `scratch_transformer.py`)
- Encoder stack → Attention layers: calls (evidence: `scratch_transformer.py`)
- Encoder stack → Feed-forward: calls (evidence: `scratch_transformer.py`)
- Decoder stack → Attention layers: uses self and cross (evidence: `scratch_transformer.py`)
- Decoder stack → Feed-forward: calls (evidence: `scratch_transformer.py`)
- Seq2seq model → Encoder stack: encodes input (evidence: `scratch_transformer.py`)
- Seq2seq model → Decoder stack: decodes memory (evidence: `scratch_transformer.py`)
- BERT classifier → Hugging Face models: loads model and tokenizer (evidence: `encoder_only_bert_example.py`)
- GPT-2 generation → Hugging Face models: loads model and tokenizer (evidence: `decoder_only_gpt2_example.py`)
- T5 summarization → Hugging Face models: loads model and tokenizer (evidence: `seq2seq_t5_example.py`)
- Efficient variants → Hugging Face models: loads variants (evidence: `efficiency_models_examples.py`)
- Fine-tuning template → Hugging Face models: loads BERT (evidence: `training_loop_template.py`)
- Fine-tuning template → AG News dataset: loads dataset (evidence: `training_loop_template.py`)
