Favicon of Transformers.js

Transformers.js

A JavaScript library that runs AI models in the browser through ONNX Runtime, with CPU execution by default and optional WebGPU acceleration.

Screenshot of Transformers.js website

Transformers.js is a JavaScript library for developers adding on-device AI to web apps. It runs models in the browser, so processing inputs doesn't require a separate inference server.

  • Text processing. Generate text, summarize documents, translate languages, classify sentiment or answer questions using supplied text.
  • Image analysis. Detect objects, segment images, remove backgrounds and estimate depth with compatible models.
  • Speech and audio. Transcribe speech, classify audio or generate speech from text.
  • Embeddings and documents. Compare text through embeddings, produce text from images and answer questions about document images.

Its API resembles Hugging Face's Python Transformers library, including a pipeline interface that handles input preparation and output processing. Compatible models are available through the Hugging Face Hub; supported architectures include BERT, BART and CLIP.

The library is open source under Apache 2.0. ONNX Runtime executes models on the CPU through WebAssembly by default, with optional WebGPU acceleration where the browser supports it. Quantized models can reduce download size and resource demands. Developers can also use compatible PyTorch, TensorFlow or JAX models converted to ONNX through Hugging Face Optimum.

Similar to Transformers.js