transformers-js
Skill531 starsChanged 3 months agoMITView on GitHub
Run Hugging Face models in JavaScript or TypeScript with Transformers.js, WebGPU, or WASM across browser, Node.js, Bun, and Deno. Use for client-side or JS-runtime inference, not Python training.
- Installs packages
4 other projects use a version of this.
Adopted by
Most recently taken up by
- huggingface/skillstheir own version, first seen Oct 1, 2026
- PracticalSwan/agent-skillstheir own version, first seen Sep 14, 2026
- huggingface/transformers.jstheir own version, first seen Sep 7, 2026
- hyf020908/modelscope-skillstheir own version, first seen Mar 23, 2026
Other versions4 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 4
- huggingface/transformers.js★ 16ksame name
- huggingface/skills★ 11ksame name
- PracticalSwan/agent-skills★ 18same name
- hyf020908/modelscope-skills★ 4same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository53 other files it gives its agents.
- agentic-actions-auditorSkill
- agents-md-improverSkill
- agents-md-reviseSkill
- ai-slopSkill
- code-architectSkill
- code-explorerSkill
- codeqlSkill
- code-qualitySkill
- code-reviewerSkill
- code-reviewSkill
- design-patternsSkill
- differential-reviewSkill
- feature-devSkill
- fp-checkSkill
- frontend-designSkill
- hf-cliSkill
- hf-cloud-aws-context-discoverySkill
- hf-cloud-python-env-setupSkill
- hf-cloud-sagemaker-deployment-plannerSkill
- hf-cloud-sagemaker-iam-preflightSkill
- hf-cloud-sagemaker-production-defaultsSkill
- hf-cloud-serving-image-selectionSkill
- hf-memSkill
- huggingface-bestSkill
- huggingface-community-evalsSkill
- huggingface-datasetsSkill
- huggingface-gradioSkill
- huggingface-llm-trainerSkill
- huggingface-local-modelsSkill
- huggingface-lora-space-builderSkill
- huggingface-paper-publisherSkill
- huggingface-papersSkill
- huggingface-spacesSkill
- huggingface-tool-builderSkill
- huggingface-trackioSkill
- huggingface-vision-trainerSkill
- huggingface-zerogpuSkill
- insecure-defaultsSkill
- mcp-builderSkill
- paper-summarizerSkill
- sarif-parsingSkill
- security-reviewSkill
- security-threat-modelSkill
- semgrep-rule-creatorSkill
- semgrep-rule-variant-creatorSkill
- semgrepSkill
- sharp-edgesSkill
- skill-creatorSkill
- supply-chain-risk-auditorSkill
- train-sentence-transformersSkill
- trl-trainingSkill
- variant-analysisSkill
- vuln-reportSkill
The file
We split this skill into the rules it gives an agent
4 rules. 0 are common, 0 are distinctive, and 4 are very specific to this project.
0
Common
Most of the 4 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 108
Always call
pipe.dispose(): when finished (app shutdown, component unmount, before loading a different model, after batch processing) — … - Very specific: line 112
Model not found: verify it exists on the Hub, check spelling, confirm it has ONNX files (an onnx folder in the repo).
- Very specific: line 113
Memory issues: use a smaller/quantized model (dtype: 'q4'), reduce batch size, limit max_length.
- Very specific: line 114
WebGPU errors: check browser support (Chrome/Edge 113+), try fp16 if fp32 fails, or fall back to WASM.
“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Transformers.js — Machine Learning for JavaScript
Runs state-of-the-art ML models directly in JavaScript, in browsers and server-side runtimes (Node.js, Bun, Deno), with no Python server required.
Installation
npm install @huggingface/transformers// Browser (CDN)
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers';Core Concepts
Pipeline API — groups preprocessing, inference, and postprocessing. Always dispose() when done to free memory (see references/EXAMPLES.md for cleanup patterns):
import { pipeline } from '@huggingface/transformers';
const pipe = await pipeline('sentiment-analysis');
const result = await pipe('I love transformers!');
await pipe.dispose();Model selection — pass a model ID as the second argument, e.g. pipeline('sentiment-analysis', 'Xenova/bert-base-multilingual-uncased-sentiment'). Browse compatible models at https://huggingface.co/models?library=transformers.js&sort=trending, filtered by pipeline_tag for a specific task.
Device: { device: 'webgpu' } for GPU acceleration (falls back to WASM/CPU when unsupported); omit for CPU/WASM default.
Quantization: { dtype: 'q4' } — options fp32 (largest/most accurate), fp16, q8, q4 (smallest, some accuracy loss).
Supported Tasks
One pipeline call per task, e.g. await pipeline('image-classification')('https://example.com/image.jpg'). Task IDs by category:
- NLP:
text-classification/sentiment-analysis,token-classification/ner,question-answering,fill-mask,summarization,translation,text-generation,text2text-generation,zero-shot-classification - Vision:
image-classification,object-detection,image-segmentation,depth-estimation,zero-shot-image-classification,image-to-image - Audio:
automatic-speech-recognition,audio-classification,text-to-speech/text-to-audio - Multimodal:
image-to-text,document-question-answering,zero-shot-object-detection - Embeddings:
feature-extraction(add{ pooling: 'mean', normalize: true }for sentence embeddings),sentence-similarity
For streaming/chat text generation (system/user/assistant roles, TextStreamer, generation params), see references/TEXT_GENERATION.md.
Finding and Choosing Models
Filter the Hub by library=transformers.js and pipeline_tag=<task>, sort by trending/downloads/likes/modified. Consider: size (<100MB fast/browser-friendly, 100-500MB balanced, >500MB high-accuracy/Node.js), quantization (fp32/fp16/q8/q4 trade accuracy for size/speed), task compatibility (check the model card for supported tasks, I/O format, language, license), and performance metrics on the model card. Start with a smaller model, verify it has ONNX files, and pin a specific revision in production for stability.
Advanced Configuration
Environment (env) controls caching and model loading globally:
import { env, LogLevel } from '@huggingface/transformers';
env.allowRemoteModels = true; // load from Hugging Face Hub
env.allowLocalModels = false; // load from file system
env.localModelPath = '/models/';
env.useFSCache = true; // Node.js disk cache
env.useBrowserCache = true;
env.cacheDir = './.cache';
env.logLevel = LogLevel.INFO; // default WARNING
env.fetch = (url, options) => fetch(url, { ...options, headers: { ...options?.headers, Authorization: `Bearer ${HF_TOKEN}` } });Typical patterns: development uses remote models + FS cache; production uses local-only models from a fixed path; testing disables both caches. Full option/caching reference: references/CONFIGURATION.md.
ModelRegistry (v4) inspects model assets before loading — required files, cache status, available dtypes:
import { ModelRegistry } from '@huggingface/transformers';
const files = await ModelRegistry.get_pipeline_files(task, modelId, modelOptions);
const cached = await ModelRegistry.is_pipeline_cached(task, modelId, modelOptions);
const dtypes = await ModelRegistry.get_available_dtypes(modelId);See references/MODEL_REGISTRY.md for full API coverage.
Standalone tokenization: npm install @huggingface/tokenizers for fast tokenization without loading a full inference pipeline.
Manual tokenizer + model for finer control:
import { AutoTokenizer, AutoModel } from '@huggingface/transformers';
const tokenizer = await AutoTokenizer.from_pretrained('bert-base-uncased');
const model = await AutoModel.from_pretrained('bert-base-uncased');
const outputs = await model(await tokenizer('Hello world!'));Batch processing: pass an array of inputs to any pipeline, e.g. classifier(['I love this!', 'This is terrible.']).
Runtime Considerations
WebGPU accelerates browsers and supporting server runtimes — use it when available, fall back to WASM/CPU otherwise. WASM is the most portable backend; combine with q8/q4 quantization for smaller, faster models.
Progress tracking for large multi-file downloads — pass progress_callback to pipeline(); the callback receives {status: 'initiate'|'download'|'progress'|'progress_total'|'done'|'ready', name, file?, progress?, loaded?, total?}. Full patterns (browser UI, React, CLI, retries) in references/PIPELINE_OPTIONS.md#progress-callback.
Error Handling & Memory Management
try {
const pipe = await pipeline('sentiment-analysis', 'model-id');
const result = await pipe('text to analyze');
} catch (error) {
// error.message mentions 'fetch' -> download/network issue
// error.message mentions 'ONNX' -> model execution/compatibility issue
}Always call pipe.dispose() when finished (app shutdown, component unmount, before loading a different model, after batch processing) — models hold 100MB-several GB of memory/GPU resources. See references/CACHE.md and references/EXAMPLES.md for cache and cleanup patterns across runtimes.
Troubleshooting
- Model not found: verify it exists on the Hub, check spelling, confirm it has ONNX files (an
onnxfolder in the repo). - Memory issues: use a smaller/quantized model (
dtype: 'q4'), reduce batch size, limitmax_length. - WebGPU errors: check browser support (Chrome/Edge 113+), try
fp16iffp32fails, or fall back to WASM.
Best Practices
Always dispose pipelines; prefer the pipeline API unless fine-grained control is needed; test with small inputs first; watch download sizes for web apps; show progress indicators; pin model versions in production; wrap pipeline calls in try/catch; provide fallbacks for unsupported browsers/backends; reuse loaded pipelines rather than recreating them; dispose models on SIGTERM/SIGINT in servers.
Resources
This skill: references/PIPELINE_OPTIONS.md, CONFIGURATION.md, MODEL_REGISTRY.md, CACHE.md, TEXT_GENERATION.md, MODEL_ARCHITECTURES.md, EXAMPLES.md.
Official: docs, API reference, model hub, GitHub, examples.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

