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
related reading
- Byte-Pair Encoding tokenization · Hugging Facehuggingface.co
- Byte-pair encoding - Wikipediaen.wikipedia.org
- The Bitter Lesson is coming for Tokenization – ⛰️ lucalplucalp.dev
- [2605.22821] Tokenisation via Convex Relaxationsarxiv.org
- Sampling from Your Language Model One Byte at a Timearxiv.org
- microgptkarpathy.github.io
- The End of Tokenizationronaldyu.substack.com
- Llama 2 · Hugging Facehuggingface.co
- Tokenizers · Hugging Facehuggingface.co
- GitHub - rasbt/LLMs-from-scratch: Implement a ChatGPT-like LLM in PyTorch from scratch, step by stepgithub.com
- Byte Latent Transformer: Patches Scale Better Than Tokensarxiv.org
- GitHub - brexhq/prompt-engineering: Tips and tricks for working with Large Language Models like OpenAI's GPT-4.github.com