karpathy/minbpe
Minimal, clean, code for the Byte Pair Encoding (BPE) algorithm commonly used in LLM tokenization. Minimal, clean code for the (byte-level) Byte Pair Encoding (BPE) algorithm commonly used in LLM tokenization. The BPE algorithm is "byte-level" because it runs on UTF-8 encoded strings. This algorithm was popularized for LLMs by the GPT-2 paper and the associated GPT-2 code release from OpenAI. Sennrich et al. 2015 is cited as the original reference for the use of BPE in NLP applications. Today, all modern LLMs (e.g. GPT, Llama, Mistral) use this algorithm to train their tokenizers. There are two Tokenizers in this repository, both of which can perform the 3 primary functions of a Tokenizer: 1) train the tokenizer vocabulary and merges on a given text, 2) encode from text to tokens, 3) decode from tokens to text. The files of the repo are as follows: Finally, the script train.py trains the two major tokenizers on the input text taylorswift.txt (this is the Wikipedia entry for her kek) an
minbpe Minimal, clean code for the (byte-level) Byte Pair Encoding (BPE) algorithm commonly used in LLM tokenization. The BPE algorithm is "byte-level" because it runs on UTF-8 encoded strings. This algorithm was popularized for LLMs by the GPT-2 paper and the associated GPT-2 code release from OpenAI. Sennrich et al. 2015 is cited as the original reference for the use of BPE in NLP applications. Today, all modern LLMs (e.g. GPT, Llama, Mistral) use this algorithm to train their tokenizers. There are two Tokenizers in this repository, both of which can perform the 3 primary functions of a Toke
Explore this link on the map →related reading
- Byte-pair encoding - Wikipediaen.wikipedia.org
- The Bitter Lesson is coming for Tokenization – ⛰️ lucalplucalp.dev
- [2605.22821] Tokenisation via Convex Relaxationsarxiv.org
- microgptkarpathy.github.io
- Byte Latent Transformer: Patches Scale Better Than Tokensarxiv.org
- Tokenizers · Hugging Facehuggingface.co
- Llama 2 · Hugging Facehuggingface.co
- GitHub - openai/parameter-golf: Train the smallest LM you can that fits in 16MB. Best model wins! · GitHubgithub.com
- The Annotated Transformernlp.seas.harvard.edu
- I blame the tokenizer | David Quareldavidquarel.github.io
- GPT in 60 Lines of NumPy | Jay Modyjaykmody.com
- Can gzip be a language model?nathan.rs