Skip to content

Transformers.js in your browser: a practical local AI playground

Browser AI is more than a chatbot. The SysSeder Transformers.js Playground now lets you explore three different tasks: text classification, text embeddings and Whisper speech recognition. Start with a small preset, or select Advanced mode to inspect another public Hugging Face model. This is a task-aware laboratory, not a promise that every model on the Hub will run.

What runs in your browser?

Transformers.js pipelines combine preprocessing, model execution and post-processing. A tokenizer prepares text; a speech processor prepares audio; ONNX Runtime evaluates compatible model files. The playground pins Transformers.js to version 3.8.1 and performs inference in a worker. It does not train models, change their weights or require a server API key.

The default backend is single-threaded WebAssembly on the CPU. WebGPU is an optional selection with an adapter check, not a universal acceleration guarantee. Browser support, available memory, model operators and chosen precision can still cause errors. Select WASM and reload if WebGPU fails. Successful CPU tests do not establish GPU compatibility.

Inspect first, download second

Choose a task and model, then press Inspect model metadata. Inspection requests public repository information and config.json from Hugging Face, but not model weights. It resolves the requested branch, tag or commit to an immutable commit, lists the declared architecture and license, and estimates matching ONNX file sizes. Review the model card and license yourself; a metadata label is not legal advice.

Only Load inspected model downloads the ML library and model assets. The q8 presets have approximately 67.6 MB of sentiment weights, 23.0 MB of embedding weights, or 40.9 MB for Whisper’s encoder and merged decoder. Allow about 23 MB more for shared library/runtime assets, plus tokenizer and configuration files. Alternative ONNX files shown during inspection are not necessarily all downloaded. External tensor files, incomplete metadata, transfer compression and cache reuse make custom-model totals less predictable.

Do not casually start large downloads on mobile data. Runtime memory can be much larger than downloaded weights. Browser caching may make later loads cheaper, but storage eviction or private browsing can require another download. Cancel / unload terminates the worker; it does not erase browser caches. Changing the model, task, precision or backend unloads the old selection and requires another inspection and explicit load.

Three tasks, three kinds of input

Text classification: the sentiment preset assigns positive and negative scores to English text. Try the synthetic examples, then change a word or add sarcasm. Inputs are limited to 1,000 characters and truncated to 128 tokens; tokens are not necessarily words. Other compatible classification models may have entirely different labels. A high score is a model preference, not a verified fact or diagnosis.

Embeddings: enter two short texts and compare their normalized vectors and cosine similarity. The MiniLM model card demonstrates mean pooling with normalization, which is the preset approach here. CLS pooling is also available for models that require it. Similarity is not a probability, plagiarism verdict or proof that two claims are true. Raw vectors and other outputs are available in the JSON disclosure.

Whisper: choose a local audio file, then run speech recognition. The adapter accepts files up to 10 MB and audio between 0.1 and 30 seconds. Decoding depends on the browser’s supported formats; WAV is a sensible first test. Web Audio decodes and resamples to 16 kHz, and the tool averages channels to mono before inference. There is no microphone recording or automatic external audio fetch.

The Whisper tiny.en preset is English-only. In a cloud Chromium test, a synthetic stereo WAV produced the expected sentence: “The quick brown fox jumps over the lazy dog. This is a local speech recognition test.” That confirms this tested path, not accuracy for your accent, noisy recordings or every device. Whisper can omit words or invent text, particularly with silence or unusual audio. Check transcripts against the recording.

Bring another model—with boundaries

Advanced mode accepts an owner/model ID and revision, not an arbitrary URL, access token or executable code. Use public, ungated repositories with standard Transformers.js-compatible ONNX assets. PyTorch-only repositories will not work. The audio adapter currently supports Whisper architecture; it is not a generic audio-generation interface. q8 and fp32 are offered, but a repository must actually provide compatible files. Unsupported combinations produce errors rather than substitute predictions.

Text and decoded audio are not intentionally uploaded by the playground’s inference code. Nevertheless, library/model downloads contact external services, and the surrounding blog can load third-party scripts. “Local inference” is not a guarantee that this page is an appropriate place for confidential material. Use invented text and nonsensitive audio, inspect outputs critically, and treat this as a practical learning environment rather than a production decision system.

Post a Comment

Previous Post Next Post