Skip to content

Repository files navigation

LLM & Transformer Series

A hands-on, beginner-friendly series of Jupyter notebooks that teaches how Large Language Models work — from raw text all the way to the full Transformer architecture.

Every concept is built from scratch first, then shown with real-world libraries.


Series Overview

# Topic Key Concepts
1 Tokenization Character, Word, BPE, tiktoken, HuggingFace
2 Vectorization Integer Encoding, One-Hot, Bag of Words, TF-IDF
3 Embeddings Co-occurrence, SVD, Word2Vec, Sentence Transformers
4 Attention Mechanism Scaled Dot-Product, Self-Attention, Multi-Head, BERT
5 Transformer Architecture Positional Encoding, FFN, LayerNorm, Encoder, Decoder, GPT-2

How the Pieces Fit Together

Raw Text
   │
   ▼
┌─────────────────┐
│  Tokenization   │  "Hello world" → ["Hello", "world"]
└────────┬────────┘
         │
         ▼
┌─────────────────┐
│  Vectorization  │  ["Hello", "world"] → [0, 1]  (integer IDs)
└────────┬────────┘
         │
         ▼
┌─────────────────┐
│   Embeddings    │  [0, 1] → [[0.2, -0.5, ...], [0.8, 0.1, ...]]
└────────┬────────┘
         │
         ▼
┌─────────────────┐
│    Attention    │  each token looks at every other token
└────────┬────────┘
         │
         ▼
┌─────────────────┐
│   Transformer   │  stack of attention + FFN blocks → output
└─────────────────┘

Getting Started

1. Clone the repository

git clone <repo-url>
cd llm-series

2. Create a virtual environment

python -m venv .venv

3. Activate the virtual environment

On macOS / Linux:

source .venv/bin/activate

On Windows:

.venv\Scripts\activate

You should see (.venv) at the start of your terminal prompt — that means the environment is active.

4. Install dependencies

pip install -r requirements.txt

5. Launch Jupyter

jupyter notebook

Open any notebook from its folder and run the cells top to bottom.

Tip: To deactivate the virtual environment when you are done, just run deactivate.


Prerequisites

  • Basic Python (loops, functions, classes)
  • No prior ML or NLP experience needed

Folder Structure

llm-series/
├── 01-tokenization/
│   └── tokenization.ipynb
├── 02-vectorization/
│   └── vectorization.ipynb
├── 03-embeddings/
│   └── embeddings.ipynb
├── 04-attention-mechanism/
│   └── attention_mechanism.ipynb
├── 05-transformer-architecture/
│   └── transformer_architecture.ipynb
├── requirements.txt
└── README.md

What You Will Build From Scratch

  • Character, word, and BPE tokenizers
  • Integer encoder, one-hot encoder, Bag of Words, TF-IDF
  • Co-occurrence matrix and SVD-based embeddings
  • Cosine similarity search
  • Scaled dot-product attention
  • Multi-head attention
  • Positional encoding
  • Feed-forward network and layer normalization
  • Encoder block, decoder block, full Transformer

Libraries Used

Library Used for
numpy All from-scratch implementations
matplotlib Visualizations and heatmaps
tiktoken GPT-style tokenization
transformers BERT, GPT-2, tokenizers
torch Model inference
gensim Word2Vec training
sentence-transformers Sentence embeddings
scikit-learn PCA, t-SNE, TF-IDF

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages