Charan | AI Journey › 🔬 MiniLLM Lab
🔬 MiniLLM Lab · Project-Driven Learning

Build Your Own LLM

Instead of learning AI concepts individually and connecting them later — choose one meaningful project, build it progressively, and learn every concept when you need it. You won't just know how an LLM works. You'll understand why each component exists because you'll have built it yourself.

🎯
One project
A single thread through all topics
📈
Progressive build
Each stage adds a real capability
🔬
Learn by need
Concepts arrive when the project demands them
✅
Verify outputs
A topic is done when something works

The learning loop — apply it to every single topic

Step 1
❓
Understand
What problem does this concept solve?
Step 2
👁️
Visualize
See it with a diagram or animation
Step 3
🧪
Experiment
Calculate a tiny example or inspect real behavior
Step 4
🔨
Implement
Add this concept to MiniLLM Lab
Step 5
🗣️
Verify & Connect
Test it, explain the result, bridge to the next topic

The 7-Stage Build

Each stage adds a new capability to MiniLLM Lab. The project evolves as your knowledge grows — nothing is built before it's understood.

🔤
Stage 1 · Teach it to Read

Text → Numbers

Before a model can do anything, it must convert raw text into a form it can process.

What you'll understand

  • Why tokens, not characters or words
  • How BPE merges produce a vocabulary
  • Why embeddings are learned, not programmed
  • The distributional hypothesis
  • Sparse vs dense vectors
🔨
Build milestone
A tokenizer that converts raw text into numerical IDs using BPE merge rules. Then an embedding lookup that converts those IDs into dense vectors. Verify by printing the embedding for "cat" and "dog" and computing cosine similarity.
→ Output: tokenizer.py + embeddings.py · cos(cat, dog) > 0.7 after 1k steps
🧠
Stage 2 · Teach it Context

Sequential Understanding

A single vector per token is not enough — words change meaning based on context. This stage teaches the model to look at sequences.

What you'll understand

  • Why RNNs fail on long sequences
  • How LSTMs extend memory with gates
  • Why attention fixes the bottleneck
  • How "bank" gets different vectors in context
🔨
Build milestone
A tiny next-token predictor using a 1-layer RNN, then replace the RNN with a simplified attention layer. Compare: does attention produce better context-aware predictions for the same sentence?
→ Output: rnn_predictor.py + attention_predictor.py · visible improvement in perplexity
⚙️
Stage 3 · Build the Transformer

The Architecture

Combine everything learned so far — attention, embeddings, position — into the architecture that powers all modern LLMs.

What you'll understand

  • Why Q/K/V decomposition works
  • How multiple attention heads see different patterns
  • Why position must be injected
  • How decoder-only vs encoder-decoder differ
🔨
Build milestone
Assemble a small decoder-only Transformer (2 layers, 2 heads, 64-dim) in ~200 lines of NumPy/Python. It should accept a token sequence and output a probability distribution over the vocabulary for the next token.
→ Output: transformer.py · forward pass produces logits of shape (vocab_size,)
🎓
Stage 4 · Train the Model

Learning from Data

A model with random weights knows nothing. Training is the process that gives the weights meaning through exposure to data.

Learn these topics

What you'll understand

  • How next-token prediction teaches language
  • Why loss curves look the way they do
  • What a gradient actually represents
  • When to freeze vs fine-tune embeddings
🔨
Build milestone
Train your Stage 3 Transformer on a small text corpus (Shakespeare, Wikipedia intro, or a curated dataset). Plot the loss curve. Compare generated text at step 0 vs step 5000. The difference IS what "training" means.
→ Output: train.py · loss_curve.png · generated samples before/after — visible coherence improvement
💬
Stage 5 · Make it Answer Questions

Inference

Training is done. Now: how do you take a trained model and get it to produce useful responses from a prompt?

Learn these topics

  • Prompts & instruction formats
  • Context windows
  • Token generation & autoregressive decoding
  • Temperature, top-p, top-k sampling
  • Stopping criteria & EOS tokens
  • LLM text generation

What you'll understand

  • What happens token-by-token during inference
  • Why temperature changes "creativity"
  • Why context length is a hard limit
  • The difference between greedy, beam, and sampling
🔨
Build milestone
A working inference interface: type a prompt, trace the complete generation loop step-by-step — tokenize, embed, forward pass, sample next token, decode, repeat. Print the token-by-token log so you can see each decision the model makes.
→ Output: infer.py · prompt → token trace → decoded output, visible per-step probabilities
📚
Stage 6 · Give it Useful Knowledge

Retrieval-Augmented Generation

Your tiny model can't memorize everything. But it doesn't have to — attach a retrieval layer and it can look things up at inference time.

What you'll understand

  • Why RAG beats fine-tuning for factual recall
  • How chunk size affects retrieval quality
  • Why cosine similarity works as a relevance signal
  • How to evaluate a RAG system (precision, faithfulness)
🔨
Build milestone
A question-answering assistant grounded in a small curated document collection (e.g. your AI Journey notes, a set of research paper abstracts). Embed the docs, store in a simple vector index, retrieve top-k at query time, inject into prompt, generate answer.
→ Output: rag.py · question → retrieved chunks → grounded answer · measurable precision@3
🤖
Stage 7 · Turn it into an Application

Tools, Agents & Production

The final stage: your model stops being a demo and becomes something that retrieves, reasons, calls tools, and produces verifiable answers.

What you'll understand

  • The agent loop: perceive → plan → act → observe
  • How tool schemas are declared and called
  • Why quantization reduces memory without killing quality
  • How to evaluate agentic behavior
🔨
Build milestone
An assistant that (1) retrieves relevant docs, (2) decides whether to call a tool (e.g. a calculator, a search API), (3) invokes the tool if needed, and (4) produces a final verifiable answer. Swap in a pretrained model via API for the generation step — your small model handled the mechanics; a real model handles the capability.
→ Output: agent.py · end-to-end query → tool call → grounded, verifiable answer

🏁 The Destination: Two Layers, One Project

At the end of MiniLLM Lab you'll have built two things. The first teaches you AI from the inside out. The second proves the knowledge is real by solving an actual user problem.

🔬 Learning engine

Your tiny language model — inspectable internals, hand-coded components, visible math. This is where you understand why every piece of the architecture exists.

🚀 Real-world product

A personal knowledge assistant that answers questions from your own documents. RAG + tool use + a pretrained model for generation. This proves the learning is applicable, not just conceptual.