Spreadsheets (in Browsers) are all you need: GPT2 in your browser

What is This?

Experience GPT2 (an early precursor to ChatGPT) running entirely in your browser. This project reimagines the "Spreadsheets-are-all-you-need" Excel implementation as an interactive web experience, making LLM architecture more accessible to a wider audience, especially web developers.

See It In Action

Watch how GPT2 works in your browser:

Why This Matters

The original "Spreadsheets-are-all-you-need" Excel project evolved into:

This browser-based version takes the next step in accessibility. Just as the web's "View Source" feature democratized web development, this project aims to demystify AI by letting anyone peek under the hood of a real language model. No Python or even Excel required, just your browser. You don't even need a server since everything runs locally (i.e. "offline first").

Want to dive deeper? Check out my highly rated AI course on Maven to master the inner workings of language models. We use this tool plus Google Sheets, Excel, and Python notebooks to provide a gentle introduction to how AI and LLMs work.

It's perfect for web developers, technical product managers, and engineering managers who need to get up to speed on AI quickly.

Subscribe to get the latest updates and AI tutorials!

* indicates required

How It Works

The entire implementation uses web components ("cells") to perform GPT2's inference calculations right in your browser:

  • The sheet components contain the mathematical formulas that power GPT2
  • The code components define the JavaScript functions that support these calculations

This layered approach lets you explore the model at different levels of abstraction:

  1. Start with high-level sheet formulas to grasp the basic concepts
  2. Dive into the code components to understand the detailed implementation

Built with web components, the implementation is:

  • Easy to edit and enhance with additional educational content
  • Compatible with learning management systems (LMS)
  • Prepared for future features like AI-powered copilots that provide learning assistance (hopefully coming soon)

Current Limitations

  • Developed and tested on desktop Chrome browser
  • Does not currently support mobile devices (including iPhone)

Getting Started

To run GPT2 in your browser, you'll need to load the model parameters:

  1. Download the gpt2-small-csv.zip (~500MB) file to your computer.
  2. Extract the ZIP file
  3. Drag and drop all the extracted CSV files into the upload area below.

The model weights (about 1.5GB) will be stored in your browser's local database. You won't need to reload them unless you clear your browser data.

Enter Your Prompt

Now you're ready to run the model.

  1. Enter a prompt below or use the one predefined for you (our canonical "Mike is quick. He moves").
  2. Then just click the Run button and watch the model go to work!
Prompt

Define Basic Matrix Operations

This section defines some basic matrix operations. Matricies are just simple 2D JavaScript arrays.

Tokenization Steps

This section tokenizes the prompt you entered into token using the Byte Pair Encoding (BPE) algorithm.

This step simply takes the prompt and parses it into separate words and punctuation.

Tokens to token embeddings steps

Positional Embedding Steps

Block (aka "Layer") Steps

The numbering of each step is designed to match the original Spreadsheets-are-all-you-need.ai Excel sheet. However, the numbering and breakdown of steps is arbitrary and can be rearranged.

Step 0: Reset the formulas

Step 1: Get the input embedding

Steps 2 - 3: First LayerNorm

Steps 4 - 9: Multi-head attention

Step 10: Residual Connection

Steps 11 - 12: Second LayerNorm

Steps 13 - 15: Multilayer Perceptron

Steps 16: Second Residual Connection

Run all the Block steps again for 11 more times

Final LayerNorm

Unembedding into Logits

Logits into predicted token

Achievement Unlocked!

If you've gotten this far in using Spreadsheets-are-all-you-need then you'll definitely love what's coming next. Subscribe so you don't miss it!

* indicates required