The Problem
Understanding how transformer models like GPT-2 process text is typically abstract, requiring Python runtimes, PyTorch graphs, or paper-reading to grasp internal mechanics. This repo addresses that by providing an in-browser, interactive visualization that lets users type text and watch how attention, embeddings, and MLPs transform tokens in real time.
What This Does
The core is a Svelte-based UI (src/components/) that renders GPT-2 internals alongside a live model loaded from ONNX chunks in static/model-v2/. Components like Attention.svelte, AttentionMatrix.svelte, and QKV.svelte break down the query-key-value computation, while Mlp.svelte and LinearSoftmax.svelte visualize the feed-forward and softmax stages. State is managed via src/store/index.ts, and example prompts are defined in src/constants/examples/index.js. Styling is handled by Tailwind (tailwind.config.js, src/styles/), and the whole app is bootstrapped with Vite (vite.config.ts). Python utilities under src/utils/model/ (model.py, exporttoonnx.py, quantize.py) handle model conversion and chunking, but the runtime execution stays in the browser.
How To Use It
Setup git clone https://github.com/poloclub/transformer-explainer.git cd transformer-explainer npm install npm run dev
Per the README, this starts the Vite dev server at http://localhost:5173. No environment variables or secret keys are required;