npx skills add ...
npx skills add huggingface/skills --skill transformers-js
Use Transformers.js to run state-of-the-art machine learning models directly in JavaScript/TypeScript. Supports NLP (text classification, translation, summarization), computer vision (image classification, object detection), audio (speech recognition, audio classification), and multimodal tasks. Works in browsers and server-side runtimes (Node.js, Bun, Deno) with WebGPU/WASM using pre-trained models from Hugging Face Hub.
npx skills add huggingface/skills --skill transformers-js
Transformers.js enables running state-of-the-art machine learning models directly in JavaScript across browsers and server-side runtimes (Node.js, Bun, Deno), with no Python server required.
Use this skill when you need to:
The pipeline API is the easiest way to use models. It groups together preprocessing, model inference, and postprocessing:
⚠️ Memory Management: All pipelines must be disposed with pipe.dispose() when finished to prevent memory leaks. See examples in Code Examples for cleanup patterns across different environments.
You can specify a custom model as the second argument:
Finding Models:
Browse available Transformers.js models on Hugging Face Hub:
pipeline_tag parameter
Tip: Filter by task type, sort by trending/downloads, and check model cards for performance metrics and usage examples.
Choose where to run the model:
Control model precision vs. performance:
Note: All examples below show basic usage.
For streaming and chat: See Text Generation Guide for:
TextStreamerDiscover compatible Transformers.js models on Hugging Face Hub:
Base URL (all models):
Filter by task using the pipeline_tag parameter:
Sort options:
&sort=trending - Most popular recently&sort=downloads - Most downloaded overall&sort=likes - Most liked by community&sort=modified - Recently updatedConsider these factors when selecting a model:
1. Model Size
2. Quantization Models are often available in different quantization levels:
fp32 - Full precision (largest, most accurate)fp16 - Half precision (smaller, still accurate)q8 - 8-bit quantized (much smaller, slight accuracy loss)q4 - 4-bit quantized (smallest, noticeable accuracy loss)3. Task Compatibility Check the model card for:
4. Performance Metrics Model cards typically show:
onnx folder in model repo)library=transformers.js to find compatible models: https://huggingface.co/models?library=transformers.jsenv)The env object provides comprehensive control over Transformers.js execution, caching, and model loading.
Quick Overview:
Configuration Patterns:
For complete documentation on all configuration options, caching strategies, cache management, pre-downloading models, and more, see:
ModelRegistry gives you visibility and control over model assets before loading a pipeline. Use it to estimate download size, check cache status, inspect available dtypes, and clear cached artifacts for a specific task/model/options tuple.
For production patterns and full API coverage, see ModelRegistry Reference.
@huggingface/tokenizers)For tokenization-only workflows, use @huggingface/tokenizers. It is a separate lightweight package useful when you need fast tokenization/encoding without loading full model inference pipelines.
WebGPU provides GPU acceleration in browsers and server-side runtimes (when supported):
Note: Use webgpu when available and fall back to WASM/CPU when not supported in the current runtime.
WASM is the most compatible execution backend across runtimes:
Models can be large (ranging from a few MB to several GB) and consist of multiple files. Track download progress by passing a callback to the pipeline() function:
Progress Info Properties:
For complete examples including browser UIs, React components, CLI progress bars, and retry logic, see:
→ Pipeline Options - Progress Callback
q8 or q4 for faster inferencemax_new_tokens to avoid memory issuespipe.dispose() when done to free memoryIMPORTANT: Always call pipe.dispose() when finished to prevent memory leaks.
When to dispose:
Models consume significant memory and hold GPU/CPU resources. Disposal is critical for browser memory limits and server stability.
For detailed patterns (React cleanup, servers, browser), see Code Examples
onnx folder in model repo)dtype: 'q4')max_lengthdtype: 'fp16' if fp32 failspipeline() with progress_callback, device, dtype, etc.env configuration for caching and model loadingpipe.dispose() when done - critical for preventing memory leaks| Task | Task ID |
|---|---|
| Text classification | text-classification or sentiment-analysis |
| Token classification | token-classification or ner |
| Question answering | question-answering |
| Fill mask | fill-mask |
| Summarization | summarization |
| Translation | translation |
| Text generation | text-generation |
| Text-to-text generation | text2text-generation |
| Zero-shot classification | zero-shot-classification |
| Image classification | image-classification |
| Image segmentation | image-segmentation |
| Object detection | object-detection |
| Depth estimation | depth-estimation |
| Image-to-image | image-to-image |
| Zero-shot image classification | zero-shot-image-classification |
| Zero-shot object detection | zero-shot-object-detection |
| Automatic speech recognition | automatic-speech-recognition |
| Audio classification | audio-classification |
| Text-to-speech | text-to-speech or text-to-audio |
| Image-to-text | image-to-text |
| Document question answering | document-question-answering |
| Feature extraction | feature-extraction |
| Sentence similarity | sentence-similarity |
This skill enables you to integrate state-of-the-art machine learning capabilities directly into JavaScript applications without requiring separate ML servers or Python environments.