GPT Seinfeld Inference on Browser

kekqqq1 pts0 comments

Seinfeld Scene Generator — AI dialogue in your browser seinfeld.ai Scene Generator how it works pipeline libraries github

Generate a Seinfeld scene

MODEL Llama 3.2 3B GPT-2 Medium<br>~1.9 GB download &middot; better quality &middot; 1-4 min generation

Loading model…

TOPIC / SITUATION<br>TOKENS PER TURN 50–500<br>MIN WORDS PER TURN 3–100

generate scene GENERATED SCENE<br>Writing scene

regenerate copy share

How it works

Two language models were fine-tuned on ~0 Seinfeld script excerpts to learn<br>the show's dialogue style, character voices, and scene structure. Both models<br>run entirely in your browser using WebAssembly — no server,<br>no API keys, no data leaves your machine.

Llama 3.2 3B was trained with QLoRA (quantized<br>low-rank adaptation) — only 0 of the model's parameters were updated,<br>but that was enough to teach it Seinfeld's format and tone. The model is served as<br>a 4-bit GGUF file (~0, sharded into 4 chunks for browser memory limits) and<br>executed via WebAssembly with optional multi-threading.

GPT-2 Medium (0 params) was fine-tuned with a deeper LoRA<br>configuration targeting both attention and MLP layers (r=64, 0 trainable params).<br>It's served as an int8 ONNX model (~0) and runs through the ONNX Runtime<br>WebAssembly backend.

Generation pipeline<br>When you click "generate", here's what happens under the hood:<br>Topic<br>your input text

Prompt<br>TOPIC + CHARS + [LOCATION]

&theta;<br>Model<br>LoRA weights via WASM

Raw tokens<br>multi-round generation

Filter<br>6-stage post-process

Scene<br>parsed dialogue

The Llama backend uses multi-round generation : it generates the first<br>character's turn, then injects the next character's name into the prompt and generates<br>again, repeating 4 times to ensure all main characters speak. Each round uses<br>top-k sampling (k=8, temp=0.7) with a repetition penalty.

// Prompt format (Llama 3B)<br>TOPIC: losing a parking spot

CHARACTERS: JERRY, GEORGE, ELAINE, KRAMER

[JERRY'S APARTMENT]

// Round 1: model generates first character's turn freely<br>// Round 2-4: inject "GEORGE: ", "ELAINE: ", "KRAMER: "<br>// → forces each character to speak<br>JS-side filtering

Raw model output is noisy — small models hallucinate character names, repeat<br>phrases, and ramble past natural endpoints. A 6-stage post-processing pipeline<br>cleans this up entirely in JavaScript before rendering:

1. Character typo correction — fixes common hallucinations: JERREY&rarr;JERRY, GEROGE&rarr;GEORGE, KRAMRE&rarr;KRAMER (15 known patterns)<br>2. Punctuation normalization — collapses !!!!! to !!, strips stray brackets, ensures spaces after periods<br>3. Repetition removal — deduplicates repeated sentences and detects looping n-gram patterns<br>4. Monologue capping — trims any single character turn to 80 words max, cutting at sentence boundary<br>5. Trailing trim — cuts off incomplete sentences at the end of generation<br>6. Scene parsing — extracts [LOCATION] tags and CHARACTER: text pairs from both line-by-line and inline formats

LoRA fine-tuning

Both models were trained on the same dataset of 2,295 Seinfeld script excerpts, formatted as:

TOPIC: Jerry finds out his new girlfriend is a close talker

[JERRY'S APARTMENT]

JERRY: So I'm standing there, and she's like six inches from my face.<br>GEORGE: Six inches? That's nothing. I had a woman once...<br>...<br>[END] LoRA (Low-Rank Adaptation) freezes the original model weights and<br>inserts small trainable matrices into the attention layers. This means we only update<br>~1-7% of the parameters, which is enough to teach the model the Seinfeld format<br>and character voices while keeping its general language ability intact.

The Llama model used QLoRA (4-bit quantized base + LoRA adapters)<br>with r=32 and alpha=64, trained for 5 epochs on a single A100 GPU in ~25 minutes.<br>GPT-2 used a deeper LoRA with r=64 targeting both attention and MLP layers, trained<br>for 20 epochs in ~19 minutes.

We tried Qwen2.5-7B (both base and instruct) but the base model's code/math priors<br>were too strong, and the instruct model's RLHF training fought our plain-text format.<br>Smaller models with weaker priors turned out to be easier to steer.

Libraries<br>wllama

WebAssembly port of llama.cpp. Loads GGUF models, runs inference<br>with optional multi-threading via SharedArrayBuffer.<br>Powers the Llama 3.2 3B backend.

WASM GGUF<br>Transformers.js

Hugging Face's JS port of the Transformers library.<br>Runs ONNX models via ONNX Runtime Web (WASM backend).<br>Powers the GPT-2 Medium backend.

ONNX WASM<br>Astro

Static site generator. Zero JS by default — only our<br>inline module scripts ship to the browser. Built and deployed to Vercel.

SSG<br>PEFT + bitsandbytes

Hugging Face's parameter-efficient fine-tuning library.<br>Used with bitsandbytes for 4-bit QLoRA training on a single A100 GPU.

TRAINING

source &middot;<br>models on huggingface &middot;<br>made by daniel herman<br>This is a fan project made out of love for the show.<br>Not affiliated with or endorsed by the creators of Seinfeld, Castle Rock Entertainment, or Sony Pictures Television.

model character seinfeld scene models llama

Related Articles