Transformers.js runs pretrained Hugging Face-style models in the browser via ONNX Runtime, with a pipeline API for NLP, vision, audio, and multimodal tasks.
Overview
Transformers.js brings Hugging Face transformers workflows to JavaScript so models can run in the browser without a dedicated inference server. The API is intended to mirror the Python transformers library closely so many of the same pretrained models can be used with familiar call patterns.
The pipeline API bundles preprocessing, model inference, and postprocessing for tasks across modalities. Documented support includes text classification, question answering, summarization, translation, generation, image classification, object detection, segmentation, depth estimation, speech recognition, audio classification, text-to-speech, and several multimodal zero-shot tasks.
Inference uses ONNX Runtime in the browser, with models runnable on CPU through WASM by default or on WebGPU when configured. Quantized dtypes such as q8 or q4 can reduce bandwidth and memory use in constrained environments. Models can be loaded from the Hub or custom paths, and PyTorch, TensorFlow, or JAX checkpoints can be converted to ONNX using Optimum.
Installation is available through NPM or CDN import for vanilla pages. By default the library fetches hosted pretrained weights and WASM binaries, with settings to override those paths for custom hosting.
Key features
- Pipeline API aligned with Python transformers
- ONNX Runtime in-browser inference
- WebGPU or WASM CPU execution
- Quantized model dtype options
- NLP, vision, audio, and multimodal tasks
- Hub model IDs or local ONNX paths
- CDN and NPM distribution
- Optimum-based model conversion path
Use cases
- Client-side sentiment analysis
- In-browser speech transcription
- Image classification without a server
- Privacy-sensitive local inference
- Prototyping transformer models in web apps