huggingface /transformers.js

State-of-the-art Machine Learning for the web. Run 🤗 Transformers directly in your browser, with no need for a server!

★ 16,418⑂ 1,232👁 100⑃ 890● 1,025▤ 90
JavaScriptApache-2.0Created 2023-02-13huggingface.co/docs/transformers.js
Download: 4.3.24.3.2 ↓4.3.22026-10-28
+1
Daily
16,418
stars
1,232
forks
100
watchers
890
prs
1,025
issues
90
releases

README

State-of-the-art Machine Learning for the Web


Run 🤗 Transformers directly in your browser, with no need for a server!

Transformers.js is designed to be functionally equivalent to Hugging Face's transformers python library, meaning you can run the same pretrained models using a very similar API. These models support common tasks in different modalities, such as:
  - 📝 Natural Language Processing: text classification, named entity recognition, question answering, language modeling, summarization, translation, multiple choice, and text generation.
  - 🖼️ Computer Vision: image classification, object detection, segmentation, and depth estimation.
  - 🗣️ Audio: automatic speech recognition, audio classification, and text-to-speech.
  - 🐙 Multimodal: embeddings, zero-shot audio classification, zero-shot image classification, and zero-shot object detection.

Transformers.js uses ONNX Runtime to run models in the browser. The best part about it, is that you can easily convert your pretrained PyTorch, TensorFlow, or JAX models to ONNX using 🤗 Optimum.

For more information, check out the full documentation.


 Installation


To install via NPM, run:
bash
npm i @huggingface/transformers


Alternatively, you can use it in vanilla JS, without any bundler, by using a CDN or static hosting. For example, using ES Modules, you can import the library with:
html

    import { pipeline } from 'https://cdn.jsdelivr.net/npm/@huggingface/[email protected]';




 Quick tour


It's super simple to translate from existing code! Just like the python library, we support the pipeline API. Pipelines group together a pretrained model with preprocessing of inputs and postprocessing of outputs, making it the easiest way to run models with the library.



Python (original)
Javascript (ours)




python
from transformers import pipeline

 Allocate a pipeline for sentiment-analysis
pipe = pipeline('sentiment-analysis')

out = pipe('I love transformers!')
 [{'label': 'POSITIVE', 'score': 0.999806941}]





javascript
import { pipeline } from '@huggingface/transformers';

// Allocate a pipeline for sentiment-analysis
const pipe = await pipeline('sentiment-analysis');

const out = await pipe('I love transformers!');
// [{'label': 'POSITIVE', 'score': 0.999817686}]







You can also use a different model by specifying the model id or path as the second argument to the pipeline function. For example:
javascript
// Use a different model for sentiment-analysis
const pipe = await pipeline('sentiment-analysis', 'Xenova/bert-base-multilingual-uncased-sentiment');


By default, when running in the browser, the model will be run on your CPU (via WASM). If you would like
to run the model on your GPU (via WebGPU), you can do this by setting device: 'webgpu', for example:
javascript
// Run the model on WebGPU
const pipe = await pipeline('sentiment-analysis', 'Xenova/distilbert-base-uncased-finetuned-sst-2-english', {
  device: 'webgpu',
});


For more information, check out the WebGPU guide

Top issues

Latest release

4.3.2 4.3.2 2026-10-28
What's new?
 Add support for LFM3 and LFM3-VL by @xenova in https://github.com/huggingface/transformers.js/pull/1821
 test: stabilize Whisper, Idefics3, and tokenizer CI timeouts by @nico-martin in https://github.com/huggingface/transformers.js/pull/1808
 Expose getSupportedDevices() under env.backends.onnx by @Amarnath10i in https://github.com/huggingface/transformers.js/pull/1753
 Fix negative integer random seeds by @original4422 in https://github.com/huggingface/transformers.js/pull/1798
 fix: external data download failure no longer hangs from_pretrained by @iamdgarcia in https://git

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON