The Problem
Understanding how transformer LLMs like GPT work internally is genuinely hard—the math (attention, embeddings, layer norm) is abstract and buried behind framework APIs. This tool makes it concrete by running a live GPT-2 model in the browser and letting you watch each internal operation as it predicts the next token.
What This Does
An interactive visualization tool that runs a real GPT-2 model in-browser via ONNX. You type text, and it shows, step by step, how embeddings, attention, MLP layers, and softmax produce the next-token probability distribution.
The UI is SvelteKit with Tailwind. Each transformer stage has its own component in src/components/: Attention.svelte, Embedding.svelte, QKV.svelte, Mlp.svelte, LinearSoftmax.svelte, Sampling.svelte, Temperature.svelte. Popover components in src/components/Popovers/ explain each operation, and src/components/textbook/ holds guided tutorial pages. It also ships a research paper (arXiv 2408.04619, IEEE VIS 2024).
How It Is Wired
Execution starts in src/routes/+page.svelte. All state flows through src/store/index.ts, the central Svelte store that coordinates the model, inputs, and UI. The model itself is a chunked ONNX GPT-2 in static/model-v2/gpt2.onnx.part0 through .part62, fetched by src/utils/fetchChunks.js. The Python scripts in src/utils/model/ (model.py, export_to_onnx.py, quantize.py, chunk.py) generated and split that model.
The module graph is small and clean: 25 internal modules, 6 import edges, zero circular dependencies. The most-connected modules are tailwind.config (imported by 3 files) and src/utils/animation.ts (imported by 2, itself imports 1)—animation is the shared utility most components depend on for transitions. No module carries a wide blast radius; the risk is concentrated in the two oversized components instead.
How To Use It
Per the README, prerequisites are Node.js 20+ and NPM 10+. No environment variables or config files are required.
git clone https://github.com/moses-y/transformer-explainer
cd transformer-explainer
npm install
npm run dev
Then open http://localhost:5173.
Real-World Use
This fits in teaching and onboarding: ML courses, conference demos, or a team getting familiar with transformer internals. A lecturer can fork it, add custom example inputs in src/constants/examples/, and demonstrate attention patterns live. It is also a reference implementation for anyone building similar model-visualization tools.
Code Health & Issues
Measured static analysis (not opinion) found 32 findings: 12 high, 20 medium. The high findings are deep nesting (max indentation depth 9 across Attention.svelte, Embedding.svelte, InputForm.svelte) and 243 duplicated 6-line code blocks across 23 files. The medium findings are two oversized files—Sankey.svelte and article/Article.svelte at 645 lines each.
SDLC gaps from the structure: no test files anywhere, no CI configuration, and no dependency-update bot. The repository also carries 63 blobs over 5MB—the ONNX model parts are 10MB each—which bloats every clone and CI checkout. 19 of 39 declared dependencies are behind their current major version, with @sveltejs/adapter-auto and @sveltejs/vite-plugin-svelte four majors behind.
The Bottom Line
A solid, well-documented educational tool that works as described and is easy to run. It is not production code: add tests, a CI build step, and move the ONNX model files to Git LFS before treating it as anything but a demo or teaching aid.