git404hub

what is minbpe fr?

karpathy/minbpe — explained in plain English

Analysis updated 2026-06-24

10,480PythonAudience · researcherComplexity · 2/5Setup · easy

tl;dr

A minimal, heavily commented Python library by Andrej Karpathy that shows exactly how GPT-4's tokenization works, train a tokenizer, encode text to token numbers, decode back, written to be read and understood, not just used.

vibe map

mindmap
  root((minbpe))
    Tokenizer types
      Basic BPE
      Regex tokenizer
      GPT-4 tokenizer
    Operations
      Train on text
      Encode to tokens
      Decode to text
    Purpose
      Learning tool
      GPT-4 reproduction
      Minimal codebase
    Audience
      AI learners
      Researchers

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

what do people make with this?

VIBE 1

Learn how Byte Pair Encoding tokenization works by reading and stepping through the short, heavily commented source code.

VIBE 2

Train a custom BPE tokenizer on your own text corpus and encode or decode text with it.

VIBE 3

Reproduce exact GPT-4 tokenization output and compare it side by side with OpenAI's tiktoken library.

what's the stack?

Python

how it stacks up fr

karpathy/minbpemoesnow/march7thassistantthumbor/thumbor
Stars10,48010,48110,479
LanguagePythonPythonPython
Setup difficultyeasymoderatemoderate
Complexity2/53/53/5
Audienceresearchergeneralops devops

Figures from each repo's GitHub metadata at analysis time.

how do i run it?

Difficulty · easy time til it works · 5min

in plain english

minbpe is a small, clearly written Python library that implements the tokenization algorithm used by modern AI language models like GPT-4. Tokenization is the process of splitting text into smaller pieces called tokens before an AI model can process it. The specific algorithm used here is called Byte Pair Encoding, or BPE, which works by repeatedly finding the most common pair of bytes or characters in a text and merging them into a single new token. Over many passes, this builds up a vocabulary of common words and word fragments. The library is written by Andrej Karpathy as a teaching tool. The code is short and heavily commented, meant to be read and understood rather than used at production scale. It shows how the tokenization that powers tools like GPT-4 actually works under the hood, step by step. There are three tokenizer implementations included. The basic one runs BPE directly on text in the simplest possible way. The regex tokenizer adds a preprocessing step that splits text into categories like letters, numbers, and punctuation before merging, which matches the approach OpenAI introduced with GPT-2 and still uses in GPT-4. The GPT-4 tokenizer is a thin layer on top of that which reproduces the exact tokenization output of GPT-4, and the README shows a side-by-side comparison with OpenAI's own tiktoken library to confirm they match. All three tokenizers support the same three operations: training on a body of text to build a vocabulary, encoding text into a list of token numbers, and decoding a list of token numbers back into text. You can also save and load trained tokenizers to disk. The repository is primarily a learning resource. If you want to understand what a language model actually sees when you give it a prompt, or how a tokenizer vocabulary gets built, this code gives you a minimal working example you can run and modify.

prompts (copy fr)

prompt 1
Using minbpe, train a basic BPE tokenizer on this text sample and show me the 50 most common token merges it learned and why.
prompt 2
How does the regex tokenizer in minbpe differ from the basic one, and what does that have to do with how GPT-4 splits punctuation and numbers?
prompt 3
I want to understand why my prompt is so many tokens. Use minbpe to encode it and walk me through which text pieces each token corresponds to.
prompt 4
Walk me through the minbpe training loop step by step so I understand exactly how new tokens get added to the vocabulary during BPE training.

Frequently asked questions

what is minbpe fr?

A minimal, heavily commented Python library by Andrej Karpathy that shows exactly how GPT-4's tokenization works, train a tokenizer, encode text to token numbers, decode back, written to be read and understood, not just used.

What language is minbpe written in?

Mainly Python. The stack also includes Python.

How hard is minbpe to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is minbpe for?

Mainly researcher.

peek the repo → explain another one

This repo across BitVibe Labs

double-check against the repo, no cap.