Skip to content

🧠 Interactive LLM Attention Simulation β€” Visualize how GPT-2 transformers process text through tokenization, Q/K/V projections, masked self-attention, and next-token sampling. Zero dependencies.

Notifications You must be signed in to change notification settings

romizone/simulasiLLM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Transformer Explainer

🧠 Transformer Explainer

Interactive LLM Attention Simulation β€” GPT-2 Style

Visualize how transformers think, one attention head at a time.

Live Demo Β  Research Paper

HTML5 CSS3 JavaScript Vercel Zero Dependencies


πŸ” Overview

An interactive, educational web simulation that lets you see inside a transformer model β€” from tokenization to next-token prediction. No black boxes. No abstract equations. Just a live, explorable pipeline modeled after GPT-2 Small.

πŸ’‘ Built for students, educators, and anyone curious about how Large Language Models actually work under the hood.


✨ Key Features

Feature Description
πŸ”€ Token Embedding Watch input text split into tokens and map to embedding vectors with positional encoding
πŸ”‘ Q/K/V Inspector Examine Query, Key, and Value projections for each attention head
πŸ—ΊοΈ Attention Heatmap Interactive matrix with causal masking β€” see which tokens attend to which
πŸ“Š Probability Distribution Real-time softmax output showing candidate tokens and their probabilities
⚑ Autoregressive Generation Generate tokens step-by-step and observe how each new token reshapes attention
πŸŽ›οΈ Sampling Controls Tune Temperature (0.3–1.5), Top-k (1–12), and generation length live
πŸ‘οΈ Multi-Head View Switch between attention heads to compare learned patterns

πŸ—οΈ Architecture (Simulated)

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              GPT-2 Small (Simulation)            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  🧱 Layers       β”‚  12                          β”‚
β”‚  🧠 Attn Heads   β”‚  4 (visual)                  β”‚
β”‚  πŸ“ Hidden Size  β”‚  16                          β”‚
β”‚  πŸ”’ Head Dim     β”‚  4                           β”‚
β”‚  🎭 Causal Mask  β”‚  Active                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› οΈ Tech Stack

Technology Purpose
πŸ“„ HTML5 Semantic layout & SVG attention diagrams
🎨 CSS3 Custom properties, Grid, Flexbox
βš™οΈ Vanilla JS Simulation engine β€” zero dependencies
πŸ”€ Google Fonts Orbitron, Space Grotesk, IBM Plex Mono
🌐 Vercel Static hosting & CDN

No frameworks. No build step. No bundler. Just clean, dependency-free code.


πŸ“ Project Structure

simulasiLLM/
β”œβ”€β”€ πŸ“„ index.html        # UI layout β€” toolbar, attention SVG, token stream, panels
β”œβ”€β”€ 🎨 style.css         # Styling with CSS custom properties
β”œβ”€β”€ βš™οΈ app.js            # Engine β€” tokenizer, attention math, rendering, generation
β”œβ”€β”€ πŸš€ DEPLOY.md         # Deployment guide (Vercel, Cloudflare, Netlify, GH Pages)
└── πŸ“¦ .github/
    └── workflows/       # CI/CD configuration

πŸš€ Getting Started

Run Locally

No install required β€” just serve the static files:

git clone https://github.com/romizone/simulasiLLM.git
cd simulasiLLM
python3 -m http.server 8081

Open http://127.0.0.1:8081 in your browser.

Alternatively:

# Node.js
npx serve .

# PHP
php -S localhost:8081

Deploy

See DEPLOY.md for guides on Vercel, Cloudflare Pages, Netlify, and GitHub Pages.


βš™οΈ How It Works

  πŸ“ Input Text
       β”‚
       β–Ό
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚ πŸ”€ Token β”‚  Split text into tokens (Unicode-aware regex)
  β”‚   izer   β”‚
  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚ πŸ“ Embed β”‚  Map tokens β†’ dense vectors + positional encoding
  β”‚   ding   β”‚
  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚ πŸ”‘ Q/K/V β”‚  Project embeddings into Query, Key, Value spaces
  β”‚  Project β”‚
  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚ πŸ—ΊοΈ Attn  β”‚  score = (Q Β· Kα΅€) / √d_k  β†’  causal mask  β†’  softmax
  β”‚  Matrix  β”‚
  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚ 🎲 Sampleβ”‚  Apply temperature & top-k filtering
  β”‚          β”‚
  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
  ⚑ Next Token  ──→  (autoregressive loop)

πŸ“„ Research Paper

πŸ“„ "Simulating the Attention Mechanism in Large Language Models Based on the GPT-2 Architecture"

πŸ“– Read the full paper β†’

Topics covered:

  • πŸ”€ Token processing pipeline (BPE tokenization, embedding, positional encoding)
  • πŸ“ Mathematical formulation of scaled dot-product attention
  • 🎭 Causal masking in autoregressive generation
  • 🌑️ Temperature scaling and top-k sampling strategies
  • πŸ—οΈ GPT-2 Small architecture specifications

πŸ”— Links

Link
πŸš€ Live Simulation β€” simulasillm.vercel.app
πŸ“„ Research Paper β€” paper-llm-attention.vercel.app
πŸ’» Source Code β€” github.com/romizone/simulasiLLM

πŸ“œ License

This project is open source and available for educational purposes.


Made with ❀️ by Romi Nur Ismanto

About

🧠 Interactive LLM Attention Simulation β€” Visualize how GPT-2 transformers process text through tokenization, Q/K/V projections, masked self-attention, and next-token sampling. Zero dependencies.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published