LLM From Scratch
  • Home
  • Parts
    • Part 1: Character-Level LM
    • Part 2: Shakespeare
    • Part 3: BPE Tokenization
    • Part 4: Self-Attention
    • Part 5: Instruction Tuning
    • Part 6: DPO Alignment
    • Part 7: Python Code Gen

LLM From Scratch

Build a Large Language Model from the ground up.
Seven notebooks. Pure PyTorch. No magic.

7
Parts
600K
Parameters
100%
From Scratch

The Series

01

Character-Level Language Model

Learn next-token prediction by building a model that generates names

›
02

Shakespeare Text Generation

Scale up to literature with temperature sampling and creative text generation

›
03

BPE Tokenization

Implement Byte-Pair Encoding to understand subword tokenization

›
04

Self-Attention & Transformers

Build the transformer architecture: attention, multi-head, positional encoding

›
05

Instruction Tuning

Transform your base model into an instruction-following assistant with SFT

›
06

DPO Alignment

Implement Direct Preference Optimization for human preference alignment

›
07

Python Code Generation

Train a model to generate working Python code with automated testing

›

Get Started

git clone https://github.com/nipunbatra/llm-from-scratch.git
cd llm-from-scratch
pip install torch matplotlib jupyter

Built by Nipun Batra · View on GitHub

 

Built with PyTorch. Rendered with Quarto.

  • Report an issue