Show HN: LLM Attention Visualization
TL;DR Highlight
Hovering over tokens shows why LLMs copy-paste so accurately: they pull straight from past tokens.
Who Should Read
An LLM API or RAG developer who lacks intuition for why models copy source text so accurately.
Core Mechanics
- Hover shows which past tokens fed each generated token
- Hovering a generated token highlights the past tokens that influenced it.
- The value is attention weight scaled by value vector magnitude, summed across all heads and layers.
- The largest value gets opacity 1 and the rest are interpolated.
- It is a heavily simplified view
- Much information was discarded to keep one number per past token.
- The author first doubted it would be comprehensible, but it produced interesting patterns.
- It shows why copying is accurate
- For verbatim text like addresses and dates, the source data stands out strongly.
- The model doesn't predict the whole sequence from limited internal state but draws from past tokens directly.
- So the chance of copy errors can be very low.
- A 600M-parameter model copies a whole function
- In the 'Debugging an Average Function' example it reproduced a JS function except for the intended change.
- It couldn't find the bug itself and needed hints.
- It also blends info from two phrases
- 'remain' draws from 'work' in 'will work' and 'stay the same' in another phrase.
- Built with Transformers.js plus a modified onnx
- A React app with a custom generation loop to track internal values.
- A script edits the onnx file to expose internals, and the modified model is hosted on the author's Hugging Face repo.
- Prompts are pre-generated because the model download is hundreds of MB.
Community Reactions
- Praised as a teaching tool
- A commenter teaching this topic said the weighting scheme alone doesn't build intuition and the visualization helps a lot.
- Another said it was the clearest example after reading books and watching videos.
- UX complaints about playback controls
- One report says pause resets the animation on Chromium/Linux instead of pausing.
- Commenters suggested slow playback or single-step buttons.
- Doubts about the method
- One commenter questioned equating high vector magnitude with high influence.
- Another asked whether summing across layers lets the more numerous early layers drown out later ones.
- Compared with Bertviz
- One commenter found it simpler than Bertviz and good for beginners.
How to Apply
- Ask for verbatim copying explicitly
- Spend 30 minutes on the demo comparing copied spans with summarized ones.
- Tell the model to quote exact values like addresses, dates, and IDs verbatim.
- Put exact values directly in context
- In RAG, pass raw chunks for numbers or code that must not be wrong instead of summaries.
- This lets the model draw straight from past tokens.
- Check the repo if you need internal visualization
- Look at the onnx modification approach in the GitHub repo.
- Host the instrumented model separately since stock onnx models hide internals.
Try It
# Paste into Claude or ChatGPT (simplified version of the idea: copy-accuracy check)
Read the {{document}} below and answer {{question}}.
Rules:
1. Copy addresses, dates, numbers, and IDs exactly from the document and put them in quotes.
2. For anything inferred by combining sentences, say which sentences you combined.
[Document]
{{document}}
[Question]
{{question}}
Next: diff the quoted parts against the source to confirm they match character for character.Terminology
Related Papers
Gemini 4 Neon is the new #1 on the Models Engineering Index
Gemini 4 Neon ranks first on the Models Engineering Index with 68.0, combining multiple benchmarks.
LLMs can read and write executables byte by byte from a hex dump
Given only a hex dump and no tools, an LLM analyzed, patched and wrote working executables.
Claude was trained on protein sequences at scale
Next-amino-acid tests on obscure proteins show only the latest Claude models predict them
Remembered as Brief: Stored Preferences SilentlyRemove Decision-Critical Information
A stored 'keep it short' preference silently drops warnings; listing must-know points first restores content.
All AI-generated code should be Open Source
A blog argues AI-generated code should be open source; most HN commenters disagreed.
What thousands of conversations look like inside a language model
Mapping Qwen3-1.7B states showed Chinese sitting apart from English, while German and Croatian overlapped it.
AI, activity, and outcomes in software engineering
AI sped up writing code, but shipping speed did not rise as much, says a talk
LLMs Play Zachtronics' TIS-100
16 LLMs played TIS-100 and set 133 new Pareto frontier points across 18 puzzles