WhoBuilt

How LLMs work for Web Devs: GPT in 600 lines of Vanilla JS

Jul 13, 2025· 1 h 42 min· 8.8K views·Watch on YouTube

Speaker

Ishan Anand, an AI educator and creator of Spreadsheets Are All You Need, explains how GPT-2 works for web developers at AI Engineer World's Fair 2025.

Run GPT-2 in the browser

Anand introduces a vanilla JavaScript implementation of GPT-2 Small that runs in the browser. Users load about 1.5 GB of model parameters into IndexedDB, then inspect and debug the model with familiar browser tools. He frames the workshop as an accessible route to understanding transformers without deep machine learning or calculus knowledge.

Turn text into tokens and embeddings

Anand explains that a language model predicts one next token at a time, and generates longer text by feeding each prediction back into the prompt. He describes byte-pair encoding as a way to represent text with reusable subword tokens, balancing vocabulary size against sequence length. Token IDs identify entries, while embeddings represent learned relationships between tokens; GPT-2 uses 768 dimensions.

Add position and context

Because word order affects meaning, GPT-2 adds learned position embeddings to token embeddings, with a maximum context length of 1,024 tokens. Anand describes attention as a way for tokens to exchange context, such as helping “moves” reflect that Mike moves quickly. GPT-2’s causal attention lets each token attend only to earlier tokens.

Learn predictions with neural networks

Anand explains the multilayer perceptron as a network of weighted inputs, matrix operations, and activation functions. During training, backpropagation adjusts model parameters to reduce prediction errors across many text examples. GPT-2 repeats attention and MLP operations through 12 blocks, then scores vocabulary tokens and uses softmax or a sampling method to choose the next token.

From text predictor to assistant

GPT-2 learns to imitate internet text, so its outputs can continue forms or code instead of answering like a helpful assistant. Anand outlines how later systems add examples of ideal assistant responses, learn human preferences from chosen and rejected answers, and use reinforcement learning to encourage preferred behavior. He closes by describing modern changes such as RoPE, reasoning models, and mixture-of-experts architectures.

Takeaways

  • A browser and familiar JavaScript tools can make model internals inspectable without a Python workflow.
  • Next-token prediction is the core operation; longer outputs come from repeatedly feeding predictions back into the model.
  • Subword tokenization balances vocabulary size with the cost of processing longer sequences.
  • GPT-2’s attention, MLP, and output stages can be understood as repeated numerical operations trained by reducing prediction error.
  • A base model that imitates internet text needs additional training to behave like a helpful assistant.

Mentioned in this talk

Search inside this talk

What was claimed 16

  • built
    “I gave a talk called “Spreadsheets Are All You Need,” where I showed an Excel worksheet”
    YouTube
    Verified2 sources· Talk, Web· archived
  • built
    “GPT-2 Small specifically. ... It came out in 2019”
    YouTube
    Verified2 sources· Talk, Web· archived
  • feature
    GPT-2: Predicts the next token from preceding text
    “it simply predicts the next word—technically, the next token”
    YouTube
    Unverified1 source· Talk
  • uses
    “Here's how they did their training in BPE”
    YouTube
    Unverified1 source· Talk
  • feature
    OpenAI: released model parameters and tokenizer vocabulary
    released model parameters and tokenizer vocabulary
    “This is a file that came from OpenAI when they trained the model's tokenization.”
    YouTube
    Unverified1 source· Talk
  • metric
    GPT-2: 768 embedding dimensions
    “In the case of GPT-2, the dimensionality—the list size—is 768.”
    YouTube
    Unverified1 source· Talk
  • feature
    backpropagation: Adjusts parameters to reduce prediction error
    “Can you adjust the parameters to get closer to that value?”
    YouTube
    Unverified1 source· Talk
  • metric
    GPT-2: 50,257 vocabulary tokens
    “50,257 tokens is how many tokens GPT-2 uses.”
    YouTube
    Unverified1 source· Talk
Show all 16 facts

Related talks