Byte Pair Encoding (BPE): the tokenizer that made GPTs practical

Introduction Byte Pair Encoding (BPE) is a subword tokenization scheme that gives us the best of both worlds: compact vocabulary sizes (not the full wordlist), the ability to represent any unknown word (by falling back to subwords/characters), and meaningful shared pieces (roots, suffixes) that help models generalize. GPT-2 used a BPE tokenizer with a vocabulary of ≈50,257 tokens, and OpenAI’s tiktoken is a fast Rust-backed implementation you can use today. Below I explain the why, the how (intuition + algorithm), and a short hands-on demo using tiktoken. ...

September 27, 2025 · 4 min · Nitin

Tokenization in Large Language Models: A Hands-On Guide

Introduction In this blog post, we dive deep into tokenization, the very first step in preparing data for training large language models (LLMs). Tokenization is more than just splitting sentences into words—it’s about transforming raw text into a structured format that neural networks can process. We’ll build a tokenizer, encoder, and decoder from scratch in Python, and walk through handling unknown tokens and special context markers. By the end, you’ll not only understand how tokenization works but also have working Python code you can adapt for your own projects. ...

September 27, 2025 · 4 min · Nitin

Tokenization

Natural Language Processing (NLP) has revolutionized the way machines understand human language. But before models can learn from text, they need a way to break it down into smaller, understandable units. This is where tokenization comes in — a critical preprocessing step that transforms raw text into a sequence of meaningful components, or tokens.## 🧠 What is Tokenization? Tokenization is the process of splitting text into smaller units called tokens. These tokens can be as large as words, or as small as characters or subwords. ...

April 18, 2025 · 3 min · Nitin

Understanding Tokenization in Large Language Models: A Deep Dive – Part 1

Tokenization is a fundamental yet often misunderstood process in the realm of large language models (LLMs). Despite its crucial role, it is a part of working with LLMs that many find daunting due to its complexity and the numerous challenges it introduces. In this blog post, we will explore the concept of tokenization, its importance in language models like GPT-2, and the various issues associated with it. Introduction to Tokenization Tokenization is the process of converting raw text into smaller units called tokens. These tokens can be as small as individual characters or as large as entire words or subwords, depending on the specific tokenizer being used. Tokenization is the first step in feeding text data into a neural network, making it a critical component in the performance of LLMs. ...

August 17, 2024 · 6 min · Nitin

Unveiling the Secrets Behind ChatGPT – Part 1

Introduction Hello everyone! By now, you’ve likely heard of ChatGPT, the revolutionary AI system that has taken the world and the AI community by storm. This remarkable technology allows you to interact with an AI through text-based tasks. The Technology Behind ChatGPT: Transformers The neural network that powers ChatGPT is based on the Transformer architecture, introduced in the 2017 paper “Attention is All You Need.” GPT stands for “Generatively Pre-trained Transformer.” The Transformer architecture is a landmark development in AI that revolutionized the field, primarily in natural language processing (NLP). The Transformer architecture, initially designed for machine translation, became the backbone for numerous AI applications, including ChatGPT. ...

June 17, 2024 · 5 min · Nitin