Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Build Your Own Language Model

A step-by-step book for engineers, using Sanskrit, Urdu, Tamil, Telgu

Deploy Book

Content: CC BY 4.0 Code: MIT

Read the book online: https://amitxshukla.github.io/LLM/


What this book is

Most engineers today only fine-tune models that other people built. This book goes one level deeper.

You start by writing a tiny transformer by hand, line by line. You break it on purpose, so you learn what each part does. Then you build a proper tokenizer for Sanskrit, collect and clean a real corpus, and adapt a large open model into a genuine Sanskrit specialist that runs on your own machine.

The whole book is written in simple English. Every technical word is explained the first time it appears. There is a glossary at the end.

Who it is for

You know some Python. You have touched PyTorch, or you are willing to learn it as you go. You do not need a PhD, and you do not need a GPU cluster.

Why Sanskrit and Urdu

Sanskrit teaches you structure and scarcity: sandhi, long compound words, and the hard fact that there is not much clean text. Urdu teaches you mess and script: right-to-left writing, unwritten short vowels, and half the internet's Urdu written in English letters.

Together they cover almost every problem you will meet in a real low-resource language project.


Chapters

πŸ’‘ Many chapters now end with a πŸ§‘β€πŸ’» Runnable code section containing tested, copy-paste code, colored callouts, and diagrams. The full code lives in code/; see the table below the chapter list.

Part 1 β€” Understand the machine

Step Chapter Status
0 Get your workspace ready Draft
1 Build a tiny Sanskrit transformer Draft
2 Break your model on purpose Draft

Part 2 β€” Feed the machine

Step Chapter Status
3 Understand tokenizers Draft
4 Build a Sanskrit tokenizer Draft
5 Build an Urdu tokenizer Draft
6 Collect your data Draft
7 Clean your data Draft

Part 3 β€” Train it properly

Step Chapter Status
8 Rebuild with the modern design Draft
9 Run a real training job Draft
10 Test it honestly Draft

Part 4 β€” Make it useful

Step Chapter Status
11 Adapt a large open model Draft
12 Teach it to follow instructions Draft
13 Teach it what a good answer looks like Draft
14 Teach it to reason Draft
15 Panini: add the rules back in Draft

Part 5 β€” Make it small and fast

Step Chapter Status
16 Mixture of Experts Outline
17 Distillation Outline
18 Make it small and serve it Draft
19 Long text and RAG Outline

Part 6 β€” Go beyond text

Step Chapter Status
20 Speech Outline
21 Images and manuscript OCR Outline
22 Video Outline
23 Agents and tools Outline
24 Medical images and heart sounds Outline

Part 7 β€” Ship it

Step Chapter Status
25 Release your model responsibly Draft

Appendix


πŸ§‘β€πŸ’» Runnable code

Every core step now ships with tested, runnable code in code/. Each folder is self-contained with its own README (what it does, how to run, hardware, and time).

Folder What it runs Used in
🧠 code/step-01-tiny-transformer/ A ~250-line GPT from scratch that babbles Sanskrit Steps 1–2, 9
πŸ”€ code/step-04-sanskrit-tokenizer/ Code-point vs. grapheme (akshara) tokenizers Step 4
🧹 code/step-06-data-audit/ PDFs β†’ clean corpus, with an OCR health check Steps 6–7
πŸš€ code/step-11-adapt-base-model/ LoRA/QLoRA fine-tuning: dataset β†’ train β†’ chat Steps 11–13
🧩 code/step-14-reasoning/ Verifiable rewards + GRPO, and a distillation set Steps 14, 17
❀️ code/step-24-medical-ecg/ 1D-CNN heartbeat β†’ arrhythmia, imbalance-aware Step 24
🦴 code/step-24-medical-xray/ X-ray β†’ fracture by transfer learning Steps 21, 24
πŸŽ₯ code/step-22-video/ Per-frame CNN + temporal Transformer for behaviour Step 22
# quickest taste β€” see the Sanskrit tokenization "gotcha" in 5 seconds
pip install regex && python code/step-04-sanskrit-tokenizer/devanagari_tokenizer.py

πŸ“š Companion materials & downloads

Longer-form notes, a full course PDF, and diagrams live in docs/ and are indexed in docs/references.md.

Resource Format What it is
πŸ“˜ Fine-Tuning Foundation Models PDF (58 pp) Full companion course: language, healthcare multimodal (ECG/X-ray/video), reasoning, private NVIDIA deployment, and an interview Q&A bank
🧠 Tiny-transformer teaching notes Markdown Every concept in the from-scratch model, mapped to the code
✍️ Blog: I built a tiny Sanskrit GPT Markdown Publish-ready narrative of the tokenization gotcha
πŸš€ Fine-tuning teaching notes Markdown LoRA/QLoRA, SFT, DPO, and the road to reasoning
πŸ—ΊοΈ Fine-tuning architecture Markdown (Mermaid) The full pipeline + LoRA concept + roadmap diagrams
πŸ–₯️ GPU primer (CuTile) Markdown Beginner explainer of GPU programming

Build the book locally

The book is written in MyST Markdown. You need Node.js 20 or newer.

# install the MyST command line tool, once
npm install -g mystmd

# start a live preview at http://localhost:3000
myst start

# build the static site into ./_build/html
myst build --html

To build a PDF you also need a LaTeX installation:

myst build --pdf

How publishing works

Every push to main triggers the deploy.yml workflow. It builds the site with MyST and publishes it to GitHub Pages.

To turn it on the first time:

  1. Go to Settings β†’ Pages in this repository.
  2. Under Source, choose GitHub Actions.
  3. Push to main.

Repository layout

.
β”œβ”€β”€ book/            # the chapters, one Markdown file per step
β”‚   β”œβ”€β”€ intro.md     # the long introduction
β”‚   β”œβ”€β”€ appendix/    # glossary, hardware, corpora, reading list
β”‚   └── images/      # figures used in chapters
β”œβ”€β”€ docs/            # reference PDFs, papers, and notes (not built into the book)
β”œβ”€β”€ code/            # runnable example code for each chapter
β”œβ”€β”€ myst.yml         # book config and table of contents
└── .github/workflows/deploy.yml

Adding a new chapter: create the Markdown file in book/, then add one line for it in the toc: section of myst.yml.


Contributing

Corrections and additions are welcome. The most useful contributions are:

  • Tokenizer fertility measurements for languages not covered here
  • Evaluation sets written by native speakers
  • Reports of what failed for you and why

Please read CONTRIBUTING.md and open an issue before sending a large pull request.


Author

Amit Shukla

If this book helped you, a star on the repository is genuinely appreciated.

Citing this book

See CITATION.cff, or use:

Amit Shukla. Build Your Own Language Model: A step-by-step book for engineers, using Sanskrit and Urdu. 2026. https://github.com/AmitXShukla/llm

Licence

Two licences, because a book is two things at once:

  • The writing (everything in book/ and docs/) is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You may share and adapt it, including commercially, as long as you give credit.
  • The code (everything in code/, and all code samples inside chapters) is licensed under the MIT Licence. Use it freely.

Reference PDFs placed in docs/ remain under the licence of their original authors. Do not commit anything you do not have the right to redistribute.

About

Build Your Own 🧠 Language Model πŸ’»βœ¨ From basic character-level GPT-2 (SanskritGPT Β· UrduGPT Β· TamilGPT Β· TeluguGPT Β· KannadaGPT) β†’ Fine-tuning Β· Mixture-of-Experts (MoE) Β· Knowledge Distillation Β· Model Serving Β· Scaling to Trillions of Parameters

Resources

Contributing

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages