跳到主内容
@wquguru
精选88r/LLMDevs(Reddit)技巧与观点

GPT-4o分词器对strawberry的处理动画演示

I animated what GPT-4o's tokenizer does to "strawberry": real token ids, a tiny BPE run, and why the space belongs to the word (6 min video)

原文
发到 X
推荐理由

用可视化直观拆解GPT-4o分词机制,解释Token隐藏与空间归属问题,对优化Prompt和调试Agent有直接参考价值。

I made this explainer for my small channel and would like feedback from people learning this, especially if anything is wrong.

我为自己的小频道制作了这段解释视频,希望得到正在学习相关知识的人的反馈,特别是如果内容有误的话。

It follows one word the whole way:

整段内容围绕一个词展开:

  • "How many r's are in strawberry?" is 8 tokens in o200k_base (the GPT-4o / GPT-5 tokenizer). " strawberry" is a single token, id 101830, so the three r's are hidden inside one id.
  • Why pieces of words: letters make sequences about 4x longer, whole words need a huge vocabulary and can't handle new words.
  • A tiny byte pair encoding run on a made-up text, merge by merge, until strawberry becomes st | raw | berry.
  • The space belongs to the word: "strawberry", " strawberry" and "Strawberry" are three different token sequences.
  • Why reasoning models count letters better: in OpenAI's 2025 paper "Why Language Models Hallucinate", DeepSeek-R1 spells DEEPSEEK out letter by letter before counting, while DeepSeek-V3 answered 2 or 3 (the answer is 1).
  • Bonus: the same Hindi sentence took 21 tokens with GPT-4's tokenizer and 5 with GPT-4o's.
  • "strawberry(草莓)里有几个 r?"在 o200k_base(GPT-4o / GPT-5 的分词器)中是 8 个 token。" strawberry"是一个单独的 token,ID 为 101830,因此三个 r 隐藏在一个 ID 内部。
  • 为什么使用词的片段:字母会使序列长度增加约 4 倍,而整个词汇需要巨大的词表且无法处理新词。
  • 在一个虚构文本上运行微小的字节对编码(BPE),逐个合并,直到 strawberry 变成 st | raw | berry。
  • 空格归属于单词:"strawberry"、" strawberry"和"Strawberry"是三种不同的 token 序列。
  • 为什么推理模型能更好地数清字母:在 OpenAI 2025 年的论文《语言模型为何会产生幻觉》中,DeepSeek-R1 在计数前会逐字母拼写 DEEPSEEK,而 DeepSeek-V3 回答的是 2 或 3(正确答案是 1)。
  • 补充:同一句印地语句子用 GPT-4 的分词器需要 21 个 token,而用 GPT-4o 只需要 5 个。

Every split comes from running tiktoken 0.14.0. The narration is an AI voice reading my own script.

所有分词结果均通过运行 tiktoken 0.14.0 生成。旁白由 AI 语音朗读我自己的脚本。

Video: https://www.youtube.com/watch?v=FdWcUJAhfpo&pp=0gcJCSsMAYcqIYzv

视频:https://www.youtube.com/watch?v=FdWcUJAhfpo&pp=0gcJCSsMAYcqIYzv

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

关联信息,但可能不是同一事件