Index of every page on this site: llms.txt
All skills
huggingface avatar

/transformers-js

@205e9c2
Run it yourself

Run state-of-the-art machine learning models directly in JavaScript. `@huggingface/transformers` supports text, vision, audio, and multimodal tasks in browsers and Node.js / Bun / Deno, with WebGPU or WASM execution.

  • 4 files
  • 77.1 KB
  • Apache-2
  • Updated 2 months ago
  • GitHub
Use this Skill: https://skilld.dev/gh/huggingface/transformers.js/transformers-js

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈58 tokens for metadata: the name and description. ≈2.4k when used: this file. ≈17k more on demand in 3 files.

Description uses 2.9% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈234 characters, or 2.9%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

transformers.js

ML inference for JavaScript, without a Python server. Supports text, vision, audio, and multimodal tasks through a single pipeline() entry point.

Install

npm install @huggingface/transformers

Quick start

import { pipeline } from "@huggingface/transformers";

const classifier = await pipeline("sentiment-analysis");
const output = await classifier("I love transformers!");
// [{ label: "POSITIVE", score: 0.9998 }]

pipeline(task, model?, options?) is the one function you need 90% of the time. Passing no model uses the default for that task.

Supported tasks

<!-- @generated:start id=task-list --> <!-- @generated:end id=task-list -->

For full recipes — every task, grouped by modality, with runnable code — see references/TASKS.md.

Choosing a model

Browse models compatible with transformers.js on the Hub: https://huggingface.co/models?library=transformers.js

Filter by task with the pipeline_tag parameter, e.g. https://huggingface.co/models?library=transformers.js&pipeline_tag=text-generation.

Before recommending a model, confirm it actually has ONNX weights — the library cannot load a model without them. Two ways to check:

  1. Open the model page on the Hub and look for an onnx/ directory in the "Files and versions" tab.
  2. Programmatically, with ModelRegistry.get_available_dtypes(modelId) — returns the list of dtypes shipped. An empty array means the model exists but ships no ONNX files. It throws a ModelFileNotFoundError if the model does not exist or is not accessible (private/gated — the Hub cannot tell these apart), and a regular error on network failures, so an unreachable model is never mistaken for one without ONNX files.
import { ModelRegistry, ModelFileNotFoundError } from "@huggingface/transformers";

// "Xenova/some-model" is a placeholder — substitute the ID you want to check.
try {
  const dtypes = await ModelRegistry.get_available_dtypes("Xenova/some-model");
  if (dtypes.length === 0) {
    // Model exists but has no ONNX files — not usable with transformers.js.
  }
} catch (e) {
  if (e instanceof ModelFileNotFoundError) {
    // Model does not exist, or is private/gated without a token.
  } else {
    throw e; // network failure — retry rather than blacklisting the model
  }
}

Don't suggest a model without verifying this; the failure mode at runtime is a download error that's harder to diagnose than a pre-flight check. For a fuller pre-flight pattern (cache checks, dtype fallback), see references/CONFIGURATION.md.

Quantization

Most pipelines accept a dtype option. Smaller dtypes download and run faster at the cost of some accuracy:

dtype Size Use when
fp32 Largest Maximum accuracy, Node.js with lots of RAM
fp16 ~50% of fp32 GPU / WebGPU inference
q8 ~25% of fp32 Good default for browsers
q4 ~12% of fp32 Tight memory budgets, large language models
q4f16 ~12% of fp32 Like q4 but with fp16 activations — pairs well with WebGPU LLMs
const pipe = await pipeline("text-generation", "onnx-community/Qwen3-0.6B-ONNX", {
  dtype: "q4",
});

Device

Default is CPU/WASM. Pass device: "webgpu" to run on the GPU when available:

const pipe = await pipeline("sentiment-analysis", null, { device: "webgpu" });

Memory management

Pipelines hold onto model weights and backend sessions. Always call pipe.dispose() when you're done with one — especially in long-running servers, before loading a replacement, or on component unmount.

const pipe = await pipeline("sentiment-analysis");
try {
  const result = await pipe("Great!");
} finally {
  await pipe.dispose();
}

Configuration

The env export lets you control model sources, caching, logging, and the fetch function.

import { env, LogLevel } from "@huggingface/transformers";

env.allowRemoteModels = true;
env.useFSCache = true;           // Node.js: cache downloaded models on disk
env.useBrowserCache = true;      // Browser: cache via the Cache API
env.logLevel = LogLevel.WARNING;

See references/CONFIGURATION.md for the full set of environment options, cache management, and private / gated models.

Pipeline options

Every pipeline accepts a progress_callback for download progress plus options controlling device, dtype, and caching. The per-task recipes in references/TASKS.md show common call options (e.g. top_k, max_new_tokens) in use; shared loading options, generation parameters, streaming, and KV-cache reuse are documented in references/PIPELINE_OPTIONS.md. For the exhaustive per-task option types, see the API reference.

Things to never do

  • Don't reuse a disposed pipeline. Create a new one with pipeline(...) after dispose().
  • Don't recreate pipelines inside hot loops. Create once, call many times.
  • Don't block startup on model downloads. Show progress via progress_callback.
  • Don't fabricate model IDs. Confirm a model exists on the Hub and has ONNX files (look for an onnx/ directory in the repo) before suggesting it to a user.

Reference documentation

This skill's local references:

  • TASKS.md — recipes for every task, grouped by modality (generated)
  • CONFIGURATION.md — env options, caching, model inspection
  • PIPELINE_OPTIONS.md — common pipeline options, dtype, device, generation parameters

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at 205e9c2. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last week.

Activeupdated 2 months ago
Other metadata
metadata
{
  "author": "huggingface",
  "repository": "https://github.com/huggingface/transformers.js"
}
compatibility
Node.js 20+ (or equivalent Bun / Deno), or a modern browser with ES modules. WebGPU requires runtime and hardware support; WASM is the fallback. Model downloads from the Hugging Face Hub require network access unless you ship models locally.

README badge

README badge for huggingface/transformers.js