TokenTown:一种理解大语言模型运作方式的可视化方法
TokenTown: A visual way to understand how LLMs work

原始链接: https://laurentiugabriel.github.io/token-town/

TokenTown 是一款基于浏览器的交互式可视化工具,它将 Transformer 语言模型呈现为一座等距视角的城市。每个区域对应模型架构的特定阶段,例如嵌入(embedding)、注意力机制(attention)、前馈网络(feed-forward networks)和采样(sampling)。 当代表“隐藏状态”的车队穿行于城市时,该网站会使用一个缩减版模型(12 维,2 个注意力头)实时计算各项数学运算,包括位置编码、层归一化和因果掩码。虽然其中的权重是随机的,输出结果也融合了模型逻辑与二元模型先验,但其运作机制是真实的。 该工具提供了一项教育性的“导览”功能,车队会在每个站点停留,并解释其背后的处理过程。用户可以控制进度、手动逐步执行,或缩小视图以纵览整座城市。TokenTown 并非旨在作为功能性 AI,而是作为一种教育辅助工具,将 Transformer 架构抽象的复杂性转化为一个直观且可探索的景观。

Hacker News 最新 | 过往 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 TokenTown:一种理解大语言模型(LLM)工作原理的可视化方式 (laurentiugabriel.github.io) 28 分,由 laurentiurad 发布于 1 小时前 | 隐藏 | 过往 | 收藏 | 2 条评论 | 帮助 lionel-messi 9 分钟前 | 下一条 [–] 这根本没用 回复 laurentiurad 1 小时前 | 上一条 [–] 你可以粘贴文本,并立即查看它如何被拆分为 Token,以及 Token ID、计数和其他详细信息。这有助于理解为什么提示词会有相应的成本、上下文限制为何如此表现,以及为什么模型有时会在意想不到的地方拆分单词。 我制作它是为了向朋友解释分词(Tokenization)时,发现没有一个简单、交互式的工具专注于学习而非文档说明。 我很希望能得到以下反馈: - 有什么功能可以让它更有用 - UI 改进建议 - 你发现的 Bug 或极端情况 希望它对你有用! 回复 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

What this is

TokenTown is an isometric city where every district is one stage of a transformer language model. A convoy carries a hidden state along the roads: it is cut into tokens at the docks, cast into a vector at the foundry, stamped with its position, then driven around the layer ring (attention, residual, feed-forward, residual) once per layer, before the stadium turns it into a probability distribution and the sampler picks one token. That token drives back up the feedback highway and the whole city runs again.

How much of it is real

Genuinely computed, live, in your browser: the tokenizer split; the embedding lookup; sinusoidal positional encoding; LayerNorm; multi-head scaled dot-product attention with causal masking over a real growing KV cache; the residual adds; a GELU feed-forward; and temperature / top-p sampling. The bars on the truck are the actual vector. The beams over the warehouse are the actual softmax weights. Prefill really does process every prompt token at once while decode really does process only one.

Scaled down: 12 dimensions instead of thousands, 2 attention heads instead of dozens, 2–12 layers instead of 80, and a vocabulary of a few hundred words instead of 100k+.

Deliberately faked: the weights are random, and nothing here was trained, so a random-weight model would emit noise. To keep the output readable, the final logits blend the real hidden-state projection with a bigram prior built from a small fixed corpus. The attention scores are also sharpened, and given a small first-token ("sink") and recency bias, so the map looks like the patterns trained models actually produce. Treat the text this city writes as scenery; treat the mechanism as the lesson.

Pacing

The first time the convoy reaches a district it stops long enough to read that district's explanation, between 9 and 26 seconds depending on how much there is to say. A progress bar under the panel text shows how long the stop has left. Once every district has been explained the city runs at a watchable pace instead of a readable one, and the repeated layers fast-forward because they are the same road with different weights. Space holds any stop indefinitely, S steps one stage at a time, and the Speed slider scales everything, including the reading stops, from 0.4× to 8×. Reset (⟲) replays the slow tour from the beginning; Run keeps what you have already read.

Controls

  • Space play / pause · S advance one stage · R reset and replay the tour · F follow camera · L labels
  • Drag to pan, scroll to zoom, click any district for its explanation.
  • The view starts close on the convoy and rides along with it. The button on the left (or a double-click on the map) pulls back to the whole city; turning off Follow lets you wander on your own.

Inspired by the idea behind PGSimCity (a city-shaped model of PostgreSQL); all code, art and copy here are original.

联系我们 contact @ memedata.com