text-generation Β· conversational Β· text Β· WASM Β· ~130 MB
DialoGPT is GPT-2 fine-tuned on 147M multi-turn conversations scraped from
Reddit. It has one clever trick for holding a conversation: the entire dialogue so far is fed back
as a single sequence, with each turn separated by the model's
end-of-text token (<|endoftext|>). The model just continues that
sequence β and whatever it writes up to the next end-of-text token is its reply. It's old (2019) and
can be terse or odd, but it's a wonderfully legible window into how a chatbot is really just a text
completer with a turn separator.
| Model | onnx-community/DialoGPT-small-ONNX (ONNX build of microsoft/DialoGPT-small) |
|---|---|
| Task / pipeline | text-generation (conversational) β loaded via AutoModelForCausalLM for a custom decode loop |
| Architecture | GPT-2 small decoder-only transformer, 124M params, byte-level BPE, 1024-token context; fine-tuned on Reddit dialogue |
| Turn mechanism | Conversation history joined by the end-of-text token <|endoftext|> (id 50256); the model continues to the next EOS |
| Quantization | q8 (8-bit) ONNX |
| Backend | WebAssembly (runs anywhere; no WebGPU needed) |
| Download | ~130 MB, cached after first load |
| License | MIT |
| Web APIs | WebAssembly, Web Workers β all Baseline widely available |
Heads up: DialoGPT is a 2019 research model trained on unfiltered Reddit. Replies can be short, repetitive, off-topic, or blunt β that's the model being itself, not a bug. It's here as a legible teaching example of the conversational mechanism, not as a modern assistant.
Send a message and DialoGPT replies, streaming token by token from a Web Worker. Every turn you both say is kept and re-fed as the EOS-joined context, so it (loosely) remembers the conversation. Switch between greedy (always the single most likely token β safe, terse) and sampling (temperature + top-k β livelier, riskier).
This is the exact string DialoGPT sees. Every turn β yours and its β is concatenated into one
sequence, with the <|endoftext|> token marking each
boundary. There is no separate "memory"; the whole conversation is just re-tokenised and re-fed each
time, and the model completes it. When the model emits its own end-of-text token, the reply is done.
latest reply step β what it was choosing between
DialoGPT makes the anatomy of a chatbot obvious: there is no state machine and no memory store β just a text completer and a turn-separator token. Every modern chat model, from tiny on-device assistants to the largest hosted ones, still works this way underneath (with fancier turn formats and alignment on top). Seeing it in a 124M model that runs on plain WASM demystifies the whole idea.
A minimal chat: one message in, one streamed reply out, with the context tokens shown.
Quick-reply suggestions β generate three candidate responses to a message and pick one.
Give it a personality by seeding the history with example turns, then chat in character.
DialoGPT replies, then an emotion model reads the mood of what it just said.
The turn format is the whole idea β join the dialogue with the end-of-text token and let the model continue:
import { AutoTokenizer, AutoModelForCausalLM, Tensor } from "@huggingface/transformers";
const tok = await AutoTokenizer.from_pretrained("onnx-community/DialoGPT-small-ONNX");
const model = await AutoModelForCausalLM.from_pretrained("onnx-community/DialoGPT-small-ONNX", { dtype: "q8" });
const EOS = tok.decode([model.config.eos_token_id]); // "<|endoftext|>"
// The conversation so far, each turn separated (and terminated) by EOS:
const context = ["Cats or dogs?", "Dogs, definitely.", "Why dogs?"].join(EOS) + EOS;
let ids = Array.from(tok(context).input_ids.data, Number);
// then a greedy/sampling forward-pass loop over model(ids) until it emits EOS β that span is the reply.
We run the decode loop ourselves with AutoModelForCausalLM (rather than the
text-generation pipeline) for two reasons: this single-file ONNX export doesn't drive
transformers.js's generate() KV-cache path, and running the loop by hand lets us stream
every token and show the real next-token distribution. It all runs in a Web Worker so the chat stays
responsive.