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
+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 guideTop issues
#1182There is no way to stop / abort / cancel a pipeline()27 comments · 2025-02-04#824The data is not on CPU. Use getData() to download GPU data to CPU, or use texture or gpuBuffer property to access the GPU data directly. 26 comments · 2024-06-27#1242🐛 v3 crashes on iOS and macOS devices due to increasing memory usage24 comments · 2025-03-17#1159I am getting no available backend found error in a browser environment20 comments · 2025-01-19#1581Incorrect model selection by pipeline dtype parameter18 comments · 2026-03-16#363[Question] Build step process for Vercel18 comments · 2023-10-18#1518Still crashing using WebGPU with translation pipeline17 comments · 2026-02-09#264[Question] TypeScript rewrite16 comments · 2023-08-28
Latest release
4.3.2 4.3.2 2026-10-28What'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