Skip to content

nachammai779/Large-Language-Models-from-Scratch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

22 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿง  Large Language Models from Scratch

Demystifying the inner workings of LLMs โ€” one building block at a time.

Python Jupyter NLP

A hands-on collection of notebooks that build core LLM components entirely from scratch โ€” no black boxes, just pure understanding.


๐ŸŒŸ Overview

Ever wondered what really happens inside a Large Language Model? This repository strips away the abstraction layers and rebuilds the foundational components of LLMs from the ground up. Each notebook is a self-contained deep dive into a critical piece of the LLM puzzle, written with clarity and rich explanations.

Whether you're a student, researcher, or engineer looking to solidify your understanding of how modern language models work under the hood, this repository is your hands-on companion.


๐Ÿ“‚ What's Inside

๐Ÿ“˜ Byte Pair Encoding from Scratch

Byte_Pair_Encoding_from_Scratch.ipynb

A complete implementation of the BPE tokenization algorithm โ€” the same subword tokenization strategy used by GPT and many modern LLMs. Learn how raw text is broken down into tokens that a model can understand, starting from individual characters and iteratively merging the most frequent pairs.

๐Ÿ“Š BPE Compression Ratio Comparison

BPE_Compression_Ratio_Comparison_Notebook.ipynb

How efficient is BPE really? This notebook benchmarks compression ratios across different vocabulary sizes and text corpora, giving you an intuitive feel for the tradeoffs between vocabulary size, token granularity, and compression efficiency.

๐Ÿ”ง Building an LLM Tokenizer, Encoder & Decoder from Scratch

Build_LLM_Scratch_tokenizer_encoder_decoder.ipynb

The full pipeline: from raw text โ†’ tokens โ†’ encoded IDs โ†’ decoded text. This notebook walks through building a complete tokenizer with encoder and decoder functions, mirroring the preprocessing steps that every LLM relies on before a single weight is trained.

๐Ÿ”ฎ Next Token Prediction Probability

Next_Token_Prediction_Probability.ipynb

The heart of autoregressive language modeling โ€” predicting the next token. This notebook implements the probability distributions and sampling strategies that allow a language model to generate coherent text, one token at a time.

๐Ÿณ Deployment Ready

Dockerfile + handler.py

Production-ready containerization with a Docker setup and handler script, demonstrating how to package and deploy LLM components as a service.


๐ŸŽฏ Key Learning Outcomes

  • Tokenization Mastery โ€” Understand BPE at the algorithmic level, not just as an API call
    • Encoding & Decoding Pipelines โ€” Build the bridge between human-readable text and model-ready numerical representations
      • Probability & Sampling โ€” Grasp how next-token prediction drives text generation
        • Compression Analysis โ€” Evaluate tokenizer efficiency with real metrics

          • Deployment Skills โ€” Package NLP components into deployable containers

๐Ÿš€ Getting Started

# Clone the repository
git clone https://github.com/nachammai779/Large-Language-Models-from-Scratch.git

# Navigate into the project
cd Large-Language-Models-from-Scratch

# Launch Jupyter
jupyter notebook

๐Ÿ› ๏ธ Tech Stack

Technology Purpose
๐Ÿ Python Core language
๐Ÿ““ Jupyter Notebook Interactive development
๐Ÿณ Docker Containerization & deployment

๐Ÿ‘ฉโ€๐Ÿ’ป Author

Nachammai Palaniappan Data Engineer ยท Machine Learning Researcher ยท LLM Enthusiast

GitHub LinkedIn


โญ If this repository helped you understand LLMs better, consider giving it a star!

About

๐Ÿง  Building Large Language Models from the ground up โ€” BPE tokenization, encoder-decoder architectures, and next-token prediction, all implemented from scratch in Python.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages