craniumon Hacker News • Recommends
On “Probably pay attention to tokenizers”
#tokenizer#bytepairencoding#gpt
1.7M subscribers • 6 videos on Hallway
Intermediate. Assumes working knowledge.
1.2M views2 years ago5 recommendations
AI and machine learningComputer scienceTransformers and LLMsAlgorithms
Andrej Karpathy builds a GPT-style tokenizer from scratch, explaining Byte Pair Encoding and how tokenization issues cause common LLM limitations.
The Tokenizer is a necessary and pervasive component of Large Language Models (LLMs), where it translates between strings and tokens (text chunks). Tokenizers are a completely separate stage of the LLM pipeline: they have their own training sets, training algorithms (Byte Pair Encoding), and after training implement two fundamental functions: encode() from strings to tokens, and decode() back from tokens to strings. In this lecture we build from scratch the Tokenizer used in the GPT series from OpenAI. In the process, we will see that a lot of weird behaviors and problems of LLMs actually trace back to tokenization. We'll go through a number of these issues, discuss why tokenization is at fault, and why someone out there ideally finds a way to delete this stage entirely. Chapters: intro: Tokenization, GPT-2 paper, tokenization-related issues tokenization by example in a Web UI (tiktokenizer) strings in Python, Unicode code points Unicode byte encodings, ASCII, UTF-8, UTF-16, UTF-32 daydreaming: deleting tokenization Byte Pair Encoding (BPE) algorithm walkthrough starting the implementation counting consecutive pairs, finding most common pair merging the most common pair training the tokenizer: adding the while loop, compression ratio tokenizer/LLM diagram: it is a completely separate stage decoding tokens to strings encoding strings to tokens regex patterns to force splits across categories tiktoken library intro, differences between GPT-2/GPT-4 regex GPT-2 encoder.py released by OpenAI walkthrough special tokens, tiktoken handling of, GPT-2/GPT-4 differences minbpe exercise time! write your own GPT-4 tokenizer sentencepiece library intro, used to train Llama 2 vocabulary how to set vocabulary set? revisiting gpt.py transformer training new tokens, example of prompt compression multimodal [image, video, audio] tokenization with vector quantization revisiting and explaining the quirks of LLM tokenization final recommendations ??? :) Exercises: - Advised flow: reference this document and try to implement the steps before I give away the partial solutions in the video. The full solutions if you're getting stuck are in the minbpe code github.com/karpathy/minbpe/blob/master/exercise.md Links: - Google colab for the video: colab.research.google.com/drive/1y0KnCFZvGVf_odSfcNAws6kcDD7… - GitHub repo for the video: minBPE github.com/karpathy/minbpe - Playlist of the whole Zero to Hero series so far: youtube.com/watch?v=VMj-3S1tku0&list=PLAqhIrjkxbuWI23v9cThsA… - our Discord channel: discord.gg/3zy8kqD9Cp - my Twitter: twitter.com/karpathy Supplementary links: - tiktokenizer tiktokenizer.vercel.app - tiktoken from OpenAI: github.com/openaiWhat people say. Highly recommended as the definitive, clearest deep dive into how LLM tokenizers work and why they cause odd model behaviors.
craniumon Hacker News • Recommends
On “Probably pay attention to tokenizers”
moozillaon Hacker News • Recommends
On “Ask HN: Did you encounter any leap year bugs today?”
Chironoon Hacker News • Recommends
On “Artificial intelligence is losing hype”
zellynon Hacker News • Recommends
On “Why Does Claude Speak Byzantine Music Notation?”
vismit2000on Hacker News • Recommends
On “UTF-8 is a brilliant design”
anonymouse008on Hacker News • Mentions
On “Claude 3 model family”
dist-epochon Hacker News • Mentions
On “Chronos: Learning the Language of Time Series”
pquki4on Hacker News • Mentions
On “Notebooks Are McDonalds of Code”