microgpt Playground
Overview
microgpt Playground is a browser-native interactive demo for building, training, and running miniature GPT language models entirely inside the browser — zero server required. It is a faithful JavaScript port of Andrej Karpathy's microgpt.py gist, preserving the algorithm line-for-line while adapting it for JavaScript environments (browsers and Node.js). Users supply plain text, watch the model train in real time, and generate outputs — all without any ML framework dependencies or network calls.
Problem Addressed
| Problem |
Solution |
| LLM training/inference requires backend infrastructure |
Full training and inference loop runs natively in browser with no server |
| ML frameworks are heavy, installation-intensive barriers |
Zero-dependency pure JavaScript — no PyTorch, TensorFlow, or npm packages |
| GPT internals are abstracted away by high-level APIs |
Every step (autograd, attention, Adam) hand-rolled in ~200 lines for full transparency |
| Demos that send data to external APIs compromise privacy |
All computation is local; no data leaves the user's device |
| Python-centric ML is inaccessible to web developers |
JavaScript port unlocks browser/Node.js/Deno/Bun environments for LLM prototyping |
Key Statistics
| Metric |
Value |
Date Gathered |
| HF Space Likes |
30 |
2026-02-23 |
| GitHub Stars |
65 (xenova/microgpt.js) |
2026-02-23 |
| GitHub Forks |
7 |
2026-02-23 |
| Primary Language |
JavaScript |
2026-02-23 |
| Repository Size |
Single file (~200 lines) |
2026-02-23 |
| License |
MIT |
2026-02-23 |
Key Features
Browser-Native Execution
- Runs entirely client-side with no backend, no npm install, and no build step
- Uses Web Workers to execute the training loop off the main thread, keeping the UI responsive
- Works in any modern browser as well as Node.js, Deno, and Bun runtimes
Zero-Dependency GPT Implementation
- Implements full GPT-2-style architecture in pure JavaScript (ES modules or CommonJS)
- No external ML libraries — only native JavaScript
Math operations and arrays
- Line-for-line translation of Karpathy's
microgpt.py, making it ideal for comparing Python vs JS implementations
Custom Autograd Engine
Value class tracks scalar operations and computes gradients via reverse-mode autodiff (backprop)
- Implements
add, mul, tanh, exp, pow, and composite ops with associated backward functions
- Inspired by Karpathy's micrograd
Miniature GPT Architecture
- Character-level tokenizer: each unique character (+ BOS token) mapped to an integer
- Token embeddings (
wte) and positional embeddings (wpe), summed per position
- Single transformer decoder block: multi-head self-attention (4 heads, 16-dim, 16-token context) + feedforward MLP
- RMSNorm (no learnable parameters) applied before each sublayer (pre-norm)
- Adam optimizer hand-rolled from first principles
Interactive Training Playground
- Upload any
.txt file or use the bundled names.txt example dataset
- Live loss display during training with periodic inference samples
- Demonstrated on character-level name generation (baby names dataset)
Technical Architecture
Input Text
│
▼
Character-level Tokenizer
│ (unique chars + BOS → int IDs)
▼
Embedding Lookup
│ wte[token_id] + wpe[position]
▼
Transformer Decoder Block
│ ┌─ RMSNorm
│ ├─ Multi-Head Self-Attention (Q/K/V projections, causal mask)
│ ├─ Residual Add
│ ├─ RMSNorm
│ ├─ Feedforward MLP (Linear → GELU → Linear)
│ └─ Residual Add
▼
LM Head (unembedding: Linear → logits)
│
▼
Softmax → Cross-Entropy Loss (training) / Sampling (inference)
│
▼
Adam Optimizer Update (custom, scalar autograd)
All operations are implemented as scalar arithmetic using the Value autograd class; no tensor library is used.
Installation & Usage
HuggingFace Space (no install):
https://huggingface.co/spaces/webml-community/microgpt-playground
Node.js / CLI:
# Clone and run directly — no npm install required
git clone https://github.com/xenova/microgpt.js
node microgpt.js
Browser (script tag):
<script type="module">
import { train, generate } from './microgpt.js';
// Load text, call train(), then generate()
</script>
Web Worker (non-blocking training):
const worker = new Worker('./microgpt-worker.js');
worker.postMessage({ text: myTextData });
worker.onmessage = (e) => console.log('Loss:', e.data.loss);
Relevance to Claude Code Development
Applications
- Educational reference: Demonstrates the complete GPT pipeline in ~200 lines — useful when building skills that explain transformer internals or LLM concepts
- Browser-hosted agent tools: The pattern of full ML inference running client-side (no server) applies to lightweight Claude Code plugins that need embedded inference
- Algorithm verification: Compare Python and JavaScript implementations side-by-side to validate porting exercises or cross-language agent skills
Patterns Worth Adopting
- Zero-dependency single-file design: Ship complete functionality as one file with no external dependencies — applies to Claude Code skill scripts that need to be portable
- Web Worker pattern for CPU-bound tasks: Offload long-running Claude Code hooks or background skill logic to Web Workers to avoid blocking the main thread in browser-based UIs
- Scalar autograd as teaching tool: When building skills that teach AI concepts, a minimal autograd engine is more pedagogically effective than importing a full framework
Integration Opportunities
- Could power a Claude Code skill that trains a tiny character-level LM on the user's codebase for local completion suggestions (no external API calls)
- Demonstrates how to run any Python ML algorithm in-browser — relevant for Claude Code plugins deployed as HuggingFace Spaces
- The HF Space deployment model (static files + JS) is a replicable pattern for lightweight Claude Code demos
References
Freshness Tracking
| Field |
Value |
| Last Verified |
2026-02-23 |
| Version at Verification |
n/a (single-file, no releases) |
| Next Review Recommended |
2026-05-23 |
1---2name: microgpt-playground3description: microgpt Playground is a browser-native interactive demo for building, training, and running miniature GPT language models entirely inside the browser — zero server required.4---5# microgpt Playground67| Field | Value |8| ------------- | -------------------------------------------------------------------------------- |9| Research Date | 2026-02-23 |10| Primary URL | <https://huggingface.co/spaces/webml-community/microgpt-playground> |11| GitHub | <https://github.com/xenova/microgpt.js> |12| Original | <https://gist.github.com/karpathy/8627fe009c40f57531cb18360106ce95> |13| Version | Single-file implementation (no versioned releases) |14| License | MIT |15| Author | [Xenova](https://huggingface.co/Xenova) (HF Staff) / webml-community |1617---1819## Overview2021microgpt Playground is a browser-native interactive demo for building, training, and running miniature GPT language models entirely inside the browser — zero server required. It is a faithful JavaScript port of Andrej Karpathy's [microgpt.py](https://gist.github.com/karpathy/8627fe009c40f57531cb18360106ce95) gist, preserving the algorithm line-for-line while adapting it for JavaScript environments (browsers and Node.js). Users supply plain text, watch the model train in real time, and generate outputs — all without any ML framework dependencies or network calls.2223---2425## Problem Addressed2627| Problem | Solution |28| -------------------------------------------------------- | ---------------------------------------------------------------------------------- |29| LLM training/inference requires backend infrastructure | Full training and inference loop runs natively in browser with no server |30| ML frameworks are heavy, installation-intensive barriers | Zero-dependency pure JavaScript — no PyTorch, TensorFlow, or npm packages |31| GPT internals are abstracted away by high-level APIs | Every step (autograd, attention, Adam) hand-rolled in ~200 lines for full transparency |32| Demos that send data to external APIs compromise privacy | All computation is local; no data leaves the user's device |33| Python-centric ML is inaccessible to web developers | JavaScript port unlocks browser/Node.js/Deno/Bun environments for LLM prototyping |3435---3637## Key Statistics3839| Metric | Value | Date Gathered |40| ------------------ | --------------------------- | ------------- |41| HF Space Likes | 30 | 2026-02-23 |42| GitHub Stars | 65 (xenova/microgpt.js) | 2026-02-23 |43| GitHub Forks | 7 | 2026-02-23 |44| Primary Language | JavaScript | 2026-02-23 |45| Repository Size | Single file (~200 lines) | 2026-02-23 |46| License | MIT | 2026-02-23 |4748---4950## Key Features5152### Browser-Native Execution5354- Runs entirely client-side with no backend, no npm install, and no build step55- Uses Web Workers to execute the training loop off the main thread, keeping the UI responsive56- Works in any modern browser as well as Node.js, Deno, and Bun runtimes5758### Zero-Dependency GPT Implementation5960- Implements full GPT-2-style architecture in pure JavaScript (ES modules or CommonJS)61- No external ML libraries — only native JavaScript `Math` operations and arrays62- Line-for-line translation of Karpathy's `microgpt.py`, making it ideal for comparing Python vs JS implementations6364### Custom Autograd Engine6566- `Value` class tracks scalar operations and computes gradients via reverse-mode autodiff (backprop)67- Implements `add`, `mul`, `tanh`, `exp`, `pow`, and composite ops with associated backward functions68- Inspired by Karpathy's [micrograd](https://github.com/karpathy/micrograd)6970### Miniature GPT Architecture7172- Character-level tokenizer: each unique character (+ BOS token) mapped to an integer73- Token embeddings (`wte`) and positional embeddings (`wpe`), summed per position74- Single transformer decoder block: multi-head self-attention (4 heads, 16-dim, 16-token context) + feedforward MLP75- RMSNorm (no learnable parameters) applied before each sublayer (pre-norm)76- Adam optimizer hand-rolled from first principles7778### Interactive Training Playground7980- Upload any `.txt` file or use the bundled `names.txt` example dataset81- Live loss display during training with periodic inference samples82- Demonstrated on character-level name generation (baby names dataset)8384---8586## Technical Architecture8788```text89Input Text90 │91 ▼92Character-level Tokenizer93 │ (unique chars + BOS → int IDs)94 ▼95Embedding Lookup96 │ wte[token_id] + wpe[position]97 ▼98Transformer Decoder Block99 │ ┌─ RMSNorm100 │ ├─ Multi-Head Self-Attention (Q/K/V projections, causal mask)101 │ ├─ Residual Add102 │ ├─ RMSNorm103 │ ├─ Feedforward MLP (Linear → GELU → Linear)104 │ └─ Residual Add105 ▼106LM Head (unembedding: Linear → logits)107 │108 ▼109Softmax → Cross-Entropy Loss (training) / Sampling (inference)110 │111 ▼112Adam Optimizer Update (custom, scalar autograd)113```114115All operations are implemented as scalar arithmetic using the `Value` autograd class; no tensor library is used.116117---118119## Installation & Usage120121**HuggingFace Space (no install)**:122123```124https://huggingface.co/spaces/webml-community/microgpt-playground125```126127**Node.js / CLI**:128129```bash130# Clone and run directly — no npm install required131git clone https://github.com/xenova/microgpt.js132node microgpt.js133```134135**Browser (script tag)**:136137```html138<script type="module">139 import { train, generate } from './microgpt.js';140 // Load text, call train(), then generate()141</script>142```143144**Web Worker (non-blocking training)**:145146```js147const worker = new Worker('./microgpt-worker.js');148worker.postMessage({ text: myTextData });149worker.onmessage = (e) => console.log('Loss:', e.data.loss);150```151152---153154## Relevance to Claude Code Development155156### Applications157158- **Educational reference**: Demonstrates the complete GPT pipeline in ~200 lines — useful when building skills that explain transformer internals or LLM concepts159- **Browser-hosted agent tools**: The pattern of full ML inference running client-side (no server) applies to lightweight Claude Code plugins that need embedded inference160- **Algorithm verification**: Compare Python and JavaScript implementations side-by-side to validate porting exercises or cross-language agent skills161162### Patterns Worth Adopting163164- **Zero-dependency single-file design**: Ship complete functionality as one file with no external dependencies — applies to Claude Code skill scripts that need to be portable165- **Web Worker pattern for CPU-bound tasks**: Offload long-running Claude Code hooks or background skill logic to Web Workers to avoid blocking the main thread in browser-based UIs166- **Scalar autograd as teaching tool**: When building skills that teach AI concepts, a minimal autograd engine is more pedagogically effective than importing a full framework167168### Integration Opportunities169170- Could power a Claude Code skill that trains a tiny character-level LM on the user's codebase for local completion suggestions (no external API calls)171- Demonstrates how to run any Python ML algorithm in-browser — relevant for Claude Code plugins deployed as HuggingFace Spaces172- The HF Space deployment model (static files + JS) is a replicable pattern for lightweight Claude Code demos173174---175176## References177178- [microgpt Playground (HuggingFace Space)](https://huggingface.co/spaces/webml-community/microgpt-playground) (accessed 2026-02-23)179- [xenova/microgpt.js (GitHub)](https://github.com/xenova/microgpt.js) (accessed 2026-02-23)180- [Karpathy's microgpt.py gist](https://gist.github.com/karpathy/8627fe009c40f57531cb18360106ce95) (accessed 2026-02-23)181- [webml-community on HuggingFace](https://huggingface.co/webml-community) (accessed 2026-02-23)182- [Andrej Karpathy's microGPT Architecture — Complete Guide](https://dev.to/rsrini7/andrej-karpathys-microgpt-architecture-complete-guide-em8) (accessed 2026-02-23)183- [Karpathy's microgpt.py Dissected](https://blog.sotaaz.com/post/microgpt-en) (accessed 2026-02-23)184185---186187## Freshness Tracking188189| Field | Value |190| ------------------------- | ---------- |191| Last Verified | 2026-02-23 |192| Version at Verification | n/a (single-file, no releases) |193| Next Review Recommended | 2026-05-23 |