Seinfeld Scene Generator — AI dialogue in your browser

4 min read Original article ↗

Generate a Seinfeld scene

MODEL

~1.9 GB download · better quality · 1-4 min generation

TOPIC / SITUATION

TOKENS PER TURN 50–500

MIN WORDS PER TURN 3–100

How it works

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

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

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

Generation pipeline

When you click "generate", here's what happens under the hood:

P

Prompt

TOPIC + CHARS + [LOCATION]

θ

Model

LoRA weights via WASM

R

Raw tokens

multi-round generation

F

Filter

6-stage post-process

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

TOPIC: losing a parking spot

CHARACTERS: JERRY, GEORGE, ELAINE, KRAMER

[JERRY'S APARTMENT]



JS-side filtering

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

  • 1. Character typo correction — fixes common hallucinations: JERREY→JERRY, GEROGE→GEORGE, KRAMRE→KRAMER (15 known patterns)
  • 2. Punctuation normalization — collapses !!!!! to !!, strips stray brackets, ensures spaces after periods
  • 3. Repetition removal — deduplicates repeated sentences and detects looping n-gram patterns
  • 4. Monologue capping — trims any single character turn to 80 words max, cutting at sentence boundary
  • 5. Trailing trim — cuts off incomplete sentences at the end of generation
  • 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.
GEORGE: Six inches? That's nothing. I had a woman once...
...
[END]

LoRA (Low-Rank Adaptation) freezes the original model weights and inserts small trainable matrices into the attention layers. This means we only update ~1-7% of the parameters, which is enough to teach the model the Seinfeld format and character voices while keeping its general language ability intact.

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

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

Libraries

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

WASM GGUF

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

ONNX WASM

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

SSG

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

TRAINING