text-generation ยท text ยท WebAssembly / WebGPU ยท ~430 MB (q8)
ERNIE 4.5 is Baidu's 2025 open model family, and the 0.3B is its smallest post-trained chat model โ deliberately built to be capable at a size that runs anywhere. This page runs it entirely in your browser via Transformers.js: it streams tokens on the universal WebAssembly/CPU path (no GPU required) and automatically takes the WebGPU fast path when your device has one. Chat with it, steer it with a system prompt and sampling controls, and watch the real probability distribution behind every token. Nothing is uploaded; there is no API key and no server.
A different family from the other small chat models here (Qwen2, Llama, Gemma, Falcon3, SmolLM):
ERNIE 4.5 is Baidu's own ernie4_5 architecture, notably strong in
Chinese and English at its size. Because that model class is newer than the repo's
shared Transformers.js pin, this one demo loads Transformers.js 4.3.0 in its worker
(an isolated version pin; every other page stays on 3.7.5).
| Model | onnx-community/ERNIE-4.5-0.3B-ONNX (ONNX build of baidu/ERNIE-4.5-0.3B-PT) |
|---|---|
| Task | text-generation (causal LM, instruction-tuned chat) |
| Architecture | ERNIE 4.5 โ a dense decoder-only transformer (model_type: ernie4_5), ~0.36B params, 1024 hidden, 18 layers, 103k-token vocab |
| Params / dtype | ~0.36B ยท q8 on WASM (onnx/model_quantized.onnx) ยท q4f16 on WebGPU (onnx/model_q4f16.onnx) |
| Backend | WebAssembly (CPU) by default โ no WebGPU required; auto-upgrades to WebGPU when a real adapter is present |
| Runtime | Transformers.js 4.3.0, pinned locally in this worker only (the ernie4_5 class is newer than the shared 3.7.5) |
| Download | ~430 MB (q8, WASM) or ~390 MB (q4f16, WebGPU), cached after first load |
| Languages | Bilingual โ English and Chinese (ERNIE's core strength), plus some coverage of other languages |
| License | Apache-2.0 (Baidu ERNIE 4.5) |
| Web APIs | WebAssembly, Web Workers, ES module imports (WebGPU optional) |
Heads up: the first load transfers the weights (~430 MB on CPU, ~390 MB on WebGPU), then it's cached. At ~0.36B this is one of the lightest real chat LLMs here โ it's small, so expect small-model answers: fluent and on-topic, but less reliable than a multi-billion-parameter model.
An LLM never "picks a word" โ every step it produces a probability over all 103,424 tokens in its vocabulary, and the sampler chooses one. Below is the exact templated prompt the model receives, and โ from one real forward pass over the current conversation โ the actual top candidates for the very next token, with their probabilities. Raise the temperature and the tail fattens; drop it and the top token dominates. This is the real distribution, computed on your device, not a mock-up.
Load the model and click "Show next-token distribution".
ERNIE-4.5-0.3B is the "runs anywhere" tier of a serious open family from one of the largest Chinese-and-English model labs. Because it is small and bilingual, it makes client-side language a universal primitive: it works on the locked-down work laptop, the older phone, the kiosk with the GPU blocklisted โ and it reads and replies in Chinese and English without a translation API. Private, offline-capable once cached, free to run, no key.
Ask a question, watch the answer stream on your device โ the core chat loop.
Bilingual structured extraction: free text in English or Chinese โ schema-shaped JSON.
Bilingual persona engine: the same model role-plays a character in the language you pick.
Cross-lingual RAG: Granite Embedding retrieves, ERNIE answers with citations.
It's the standard Transformers.js text-generation pipeline โ pass a messages array
(the pipeline applies ERNIE's chat template), a TextStreamer for token-by-token
output, and your sampling settings. The only device-specific choice is device +
dtype, which this page picks by probing for a real WebGPU adapter. Note the pinned
version โ the ernie4_5 class needs Transformers.js โฅ 4.2.0:
import { pipeline, TextStreamer } from "@huggingface/transformers"; // v4.2.0+
// Probe for a real adapter โ WebGPU (q4f16) fast path, else universal WASM (q8) on the CPU.
const adapter = navigator.gpu && await navigator.gpu.requestAdapter().catch(() => null);
const [device, dtype] = adapter ? ["webgpu", "q4f16"] : ["wasm", "q8"];
const generator = await pipeline(
"text-generation", "onnx-community/ERNIE-4.5-0.3B-ONNX", { device, dtype },
);
const messages = [
{ role: "system", content: "You are a helpful, concise assistant." },
{ role: "user", content: "Translate 'hello' into Chinese." },
];
const streamer = new TextStreamer(generator.tokenizer,
{ skip_prompt: true, skip_special_tokens: true, callback_function: (t) => append(t) });
await generator(messages, {
max_new_tokens: 200, do_sample: true, temperature: 0.7, top_p: 0.9, streamer,
});
The "see inside" panel runs one raw forward pass โ
generator.model(generator.tokenizer(prompt)) โ reads the last position's
logits, softmaxes them, and shows the real top-k. Everything runs in a Web Worker so
generation never blocks the page; the loader auto-inits an already-cached copy and never silently
re-downloads.