# svijayan-b/tiny_shakespear_from_llm architecture

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

- Interactive diagram: https://gitdiagram.com/svijayan-b/tiny_shakespear_from_llm
- Repository: https://github.com/svijayan-b/tiny_shakespear_from_llm

## Overview

ShakespeareGPT turns Shakespeare text into chat-formatted training data, tokenizes it, trains a decoder-only GPT, and uses the saved model for local multi-turn chat. The graph includes documented capabilities whose implementation was not sampled; those links are dashed where source-level wiring is unavailable. The GPT implementation itself was not excerpted, so its connection to the sampled transformer layers is unverified.

Main entry points: [`inference/chat.py`](https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/inference/chat.py) (Interactive chat), [`training/train.py`](https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/training/train.py) (Training loop), [`data/processed/chat_data.txt`](https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/data/processed/chat_data.txt) (Chat-formatted data), [`tokenizer/bpe_tokenizer.py`](https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/tokenizer/bpe_tokenizer.py) (BPE tokenizer training)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_shakespeare["Shakespeare corpus<br/>[shakespeare.txt]"]
  node_builder["Chat data builder<br/>[build_chat_data.py]"]
  node_chatdata["Chat-formatted data<br/>[chat_data.txt]"]
end

subgraph group_model["Model and tokenization"]
  node_tokenizer_train["BPE tokenizer training<br/>[bpe_tokenizer.py]"]
  node_tokenizer_model["SentencePiece model<br/>[spm.model]"]
  node_tokenizer_vocab["Tokenizer vocabulary<br/>[spm.vocab]"]
  node_config["Runtime configuration<br/>[config.py]"]
  node_gpt["GPT language model<br/>[gpt.py]"]
  node_layers["Transformer layers<br/>[layers.py]"]
end

subgraph group_training["Training"]
  node_dataset["Token sequence dataset<br/>[dataset.py]"]
  node_trainer["Training loop<br/>[train.py]"]
  node_checkpoint["Model checkpoint"]
end

subgraph group_inference["Chat inference"]
  node_chat["Interactive chat<br/>[chat.py]"]
  node_reply["Generated reply"]
end

node_user(("Chat user"))

node_shakespeare -.->|"provides text"| node_builder
node_builder -.->|"formats conversations"| node_chatdata
node_chatdata -->|"trains on"| node_tokenizer_train
node_tokenizer_train -->|"saves model"| node_tokenizer_model
node_tokenizer_train -->|"saves vocabulary"| node_tokenizer_vocab
node_chatdata -->|"loads text"| node_dataset
node_tokenizer_model -->|"encodes with"| node_dataset
node_config -->|"sets training parameters"| node_trainer
node_config -->|"sets model and sampling parameters"| node_chat
node_dataset -->|"provides batches"| node_trainer
node_trainer -->|"trains"| node_gpt
node_trainer -->|"saves weights"| node_checkpoint
node_chat -->|"loads tokenizer"| node_tokenizer_model
node_chat -->|"generates with"| node_gpt
node_chat -->|"loads weights"| node_checkpoint
node_gpt -.->|"uses transformer blocks"| node_layers
node_user -->|"enters prompt"| node_chat
node_chat -->|"returns response"| node_reply
node_chat -->|"displays reply"| node_user

click node_shakespeare "https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/data/raw/shakespeare.txt"
click node_builder "https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/data/processed/build_chat_data.py"
click node_chatdata "https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/data/processed/chat_data.txt"
click node_tokenizer_train "https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/tokenizer/bpe_tokenizer.py"
click node_tokenizer_model "https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/tokenizer/spm.model"
click node_tokenizer_vocab "https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/tokenizer/spm.vocab"
click node_config "https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/config.py"
click node_dataset "https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/training/dataset.py"
click node_trainer "https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/training/train.py"
click node_gpt "https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/model/gpt.py"
click node_layers "https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/model/layers.py"
click node_chat "https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/inference/chat.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_shakespeare,node_builder,node_chatdata,node_user toneBlue
class node_tokenizer_train,node_tokenizer_model,node_tokenizer_vocab,node_config,node_gpt,node_layers toneAmber
class node_dataset,node_trainer,node_checkpoint toneMint
class node_chat,node_reply toneRose
```

## Components

### Data preparation

- [Shakespeare corpus](https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/data/raw/shakespeare.txt): `data/raw/shakespeare.txt`
- [Chat data builder](https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/data/processed/build_chat_data.py): `data/processed/build_chat_data.py`
- [Chat-formatted data](https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/data/processed/chat_data.txt): `data/processed/chat_data.txt`

### Model and tokenization

- [BPE tokenizer training](https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/tokenizer/bpe_tokenizer.py): `tokenizer/bpe_tokenizer.py`
- [SentencePiece model](https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/tokenizer/spm.model): `tokenizer/spm.model`
- [Tokenizer vocabulary](https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/tokenizer/spm.vocab): `tokenizer/spm.vocab`
- [Runtime configuration](https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/config.py): `config.py`
- [GPT language model](https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/model/gpt.py): `model/gpt.py`
- [Transformer layers](https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/model/layers.py): `model/layers.py`

### Training

- [Token sequence dataset](https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/training/dataset.py): `training/dataset.py`
- [Training loop](https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/training/train.py): `training/train.py`
- **Model checkpoint**

### Chat inference

- [Interactive chat](https://github.com/svijayan-b/tiny_shakespear_from_llm/blob/main/inference/chat.py): `inference/chat.py`
- **Generated reply**

### Other components

- **Chat user**

## Connections

- Shakespeare corpus → Chat data builder: provides text (evidence: `README.md`)
- Chat data builder → Chat-formatted data: formats conversations (evidence: `README.md`)
- Chat-formatted data → BPE tokenizer training: trains on (evidence: `tokenizer/bpe_tokenizer.py`)
- BPE tokenizer training → SentencePiece model: saves model (evidence: `tokenizer/bpe_tokenizer.py`)
- BPE tokenizer training → Tokenizer vocabulary: saves vocabulary (evidence: `tokenizer/bpe_tokenizer.py`)
- Chat-formatted data → Token sequence dataset: loads text
- SentencePiece model → Token sequence dataset: encodes with (evidence: `training/dataset.py`)
- Runtime configuration → Training loop: sets training parameters (evidence: `training/train.py`)
- Runtime configuration → Interactive chat: sets model and sampling parameters (evidence: `inference/chat.py`)
- Token sequence dataset → Training loop: provides batches (evidence: `training/train.py`)
- Training loop → GPT language model: trains (evidence: `training/train.py`)
- Training loop → Model checkpoint: saves weights (evidence: `training/train.py`)
- Interactive chat → SentencePiece model: loads tokenizer (evidence: `inference/chat.py`)
- Interactive chat → GPT language model: generates with (evidence: `inference/chat.py`)
- Interactive chat → Model checkpoint: loads weights (evidence: `inference/chat.py`)
- GPT language model → Transformer layers: uses transformer blocks
- Chat user → Interactive chat: enters prompt (evidence: `inference/chat.py`)
- Interactive chat → Generated reply: returns response (evidence: `inference/chat.py`)
- Interactive chat → Chat user: displays reply (evidence: `inference/chat.py`)
