Repolode
huggingface

huggingface/transformers.js

Run Hugging Face Transformers models directly in the browser or JavaScript runtimes with no server, using ONNX Runtime.

Stars
16,359
Forks
1,206
Open issues
279
Last commit
yesterday

What is it?

Transformers.js is a JavaScript library that runs pretrained Hugging Face Transformers models in the browser. Its pipeline API is designed to mirror the Python transformers library, so code written for Python can be ported with a similar structure. It covers tasks across text, vision, audio, and multimodal inputs, including classification, object detection, speech recognition, text-to-speech, and zero-shot classification.

The library runs models through ONNX Runtime, defaulting to CPU execution via WASM, with an option to run on GPU through WebGPU. Developers can choose quantization levels such as q8 or q4 to reduce model size and bandwidth. Models from the Hugging Face Hub can be loaded by id, and PyTorch, TensorFlow, or JAX models can be converted to ONNX using Optimum.

It installs via npm or can be loaded from a CDN with an ES module import, so it works without a bundler. Local model paths and WASM file locations can be configured.

Key features

  • 01Pipeline API that mirrors the Python transformers library.
  • 02Supports NLP, computer vision, audio, and multimodal tasks.
  • 03Runs on CPU via WASM by default, with optional WebGPU acceleration.
  • 04Supports quantized models such as q8 and q4 via the dtype option.
  • 05Installable via npm or usable directly from a CDN without a bundler.

Use cases

  • Adding client-side sentiment analysis or classification to a web app without a backend.
  • Running speech recognition or text-to-speech in the browser for privacy-sensitive input.
  • Computing text embeddings for semantic search in a static site.
  • Prototyping Hugging Face models in JavaScript before deploying a server.

Quick start

  1. 1

    Install the package from NPM

    npm i @huggingface/transformers
  2. 2

    Import pipeline and run a sentiment-analysis model in your JavaScript code

Things to know

  • WebGPU support is still experimental in many browsers.
  • Models must be in ONNX format, so PyTorch, TensorFlow or JAX models need converting first.

Topics

FAQ

What is transformers.js?
Run Hugging Face Transformers models directly in the browser or JavaScript runtimes with no server, using ONNX Runtime. Transformers.js is a JavaScript library that runs pretrained Hugging Face Transformers models in the browser. Its pipeline API is designed to mirror the Python transformers library, so code written for Python can be ported with a similar structure. It covers tasks across text, vision, audio, and multimodal inputs, including classification, object detection, speech recognition, text-to-speech, and zero-shot classification.
Is transformers.js free to use? What license does it have?
transformers.js is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
Is transformers.js still maintained?
Actively maintained. The last commit to transformers.js was on Oct 20, 2026.
What can I use transformers.js for?
Adding client-side sentiment analysis or classification to a web app without a backend. Running speech recognition or text-to-speech in the browser for privacy-sensitive input. Computing text embeddings for semantic search in a static site. Prototyping Hugging Face models in JavaScript before deploying a server.
How do I install transformers.js?
Install the package from NPM: npm i @huggingface/transformers Import pipeline and run a sentiment-analysis model in your JavaScript code
Where can I get transformers.js?
The source code and installation instructions are on GitHub: https://github.com/huggingface/transformers.js

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects