explaingit

huggingface/transformers.js

15,998JavaScriptAudience · developerComplexity · 2/5Setup · easy

TLDR

Transformers.js lets you run Hugging Face machine-learning models directly in a browser or Node.js app with no server needed, covering text, image, audio, and multimodal tasks through a simple pipeline API.

Mindmap

mindmap
  root((transformers.js))
    Supported tasks
      Text classification
      Image detection
      Speech recognition
      Text generation
    How it works
      ONNX Runtime
      WebAssembly CPU
      WebGPU acceleration
    Installation
      npm package
      CDN script tag
    Use cases
      Privacy-first apps
      Offline extensions
      No-server AI
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add in-browser sentiment analysis or text classification to a web app without sending user data to a server.

USE CASE 2

Build a privacy-friendly browser extension that does speech recognition or translation entirely on the user's device.

USE CASE 3

Run image object detection in a Node.js script without a GPU or cloud API.

USE CASE 4

Create an offline-capable web app that generates text embeddings for semantic search without a backend.

Tech stack

JavaScriptONNX RuntimeWebAssemblyWebGPUnpm

Getting it running

Difficulty · easy Time to first run · 30min

Models must be in ONNX format, most popular models are pre-converted on the Hugging Face Hub, but custom models need an Optimum conversion step.

In plain English

Transformers.js is a JavaScript library that lets web pages and Node.js apps run pretrained machine-learning models directly on the user's device, with no server doing the work. The README pitches it as state-of-the-art machine learning for the web and describes it as functionally equivalent to Hugging Face's Python transformers library, so similar code works in both places. The library covers a broad mix of tasks. For text it can do sentiment classification, named-entity recognition, question answering, summarization, translation, and text generation. For images it handles classification, object detection, segmentation, and depth estimation. For sound there is automatic speech recognition, audio classification, and text-to-speech. Multimodal tasks like embeddings and zero-shot classification across text, images, and audio are also supported. The main entry point is a pipeline function that bundles a model with input preprocessing and output postprocessing, so a sentiment-analysis call is a one-liner returning labels and scores. Under the hood it uses ONNX Runtime to execute models, which is why you convert PyTorch, TensorFlow, or JAX models to the ONNX format (typically via Optimum) before using them. By default it runs on the CPU through WebAssembly, setting a device option to webgpu uses the GPU through the experimental WebGPU API, and a dtype option picks a quantized variant such as fp16, q8, or q4 to shrink downloads. Someone would reach for Transformers.js to build privacy-friendly browser demos, offline-capable extensions, or embedded AI features that avoid the cost and latency of a server. It is JavaScript, installed via npm or loaded directly from a CDN.

Copy-paste prompts

Prompt 1
Using Transformers.js pipeline API, add a sentiment-analysis widget to my HTML page that classifies user-typed text in the browser with no server calls. Show me the complete code.
Prompt 2
I want to run a speech recognition model in the browser with Transformers.js. Walk me through loading the model from the CDN and transcribing a microphone recording.
Prompt 3
Help me use Transformers.js in a Node.js script to generate text embeddings for a list of sentences and compute cosine similarity between them.
Prompt 4
I want to run a Transformers.js image classification model faster using WebGPU. Show me how to set the device and dtype options and check browser compatibility.
Prompt 5
Convert a Hugging Face PyTorch model to ONNX format using Optimum so I can load it in Transformers.js. Show me the exact Optimum command and the JS loading code.
Open on GitHub → Explain another repo

← huggingface on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.