Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Run Hugging Face models in JavaScript or TypeScript with Transformers.js in Node.js or the browser.
.claude/skills/lingxling-transformers-js/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 142% | 0% |
| case-02 | ✗→✓ | ▲ Improved | 235% | 0% |
| case-10 | ✗→✓ | ▲ Improved | 206% | 0% |
| case-08 | ✓→✓ | = Same ✓ | 236% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 114% | 0% |
Transformers.js enables running state-of-the-art machine learning models directly in JavaScript, both in browsers and Node.js environments, with no server required.
Use this skill when you need to:
bashnpm install @huggingface/transformers
javascript<script type="module"> import { pipeline } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers'; </script>
The pipeline API is the easiest way to use models. It groups together preprocessing, model inference, and postprocessing:
javascriptimport { pipeline } from '@huggingface/transformers'; // Create a pipeline for a specific task const pipe = await pipeline('sentiment-analysis'); // Use the pipeline const result = await pipe('I love transformers!'); // Output: [{ label: 'POSITIVE', score: 0.999817686 }] // IMPORTANT: Always dispose when done to free memory await classifier.dispose();
⚠️ 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:
javascriptconst pipe = await pipeline( 'sentiment-analysis', 'Xenova/bert-base-multilingual-uncased-sentiment' );
Finding Models:
Browse available Transformers.js models on Hugging Face Hub:
pipeline_tag parameterTip: Filter by task type, sort by trending/downloads, and check model cards for performance metrics and usage examples.
Choose where to run the model:
javascript// Run on CPU (default for WASM) const pipe = await pipeline('sentiment-analysis', 'model-id'); // Run on GPU (WebGPU - experimental) const pipe = await pipeline('sentiment-analysis', 'model-id', { device: 'webgpu', });
Control model precision vs. performance:
javascript// Use quantized model (faster, smaller) const pipe = await pipeline('sentiment-analysis', 'model-id', { dtype: 'q4', // Options: 'fp32', 'fp16', 'q8', 'q4' });
Note: All examples below show basic usage.
javascriptconst classifier = await pipeline('text-classification'); const result = await classifier('This movie was amazing!');
javascriptconst ner = await pipeline('token-classification'); const entities = await ner('My name is John and I live in New York.');
javascriptconst qa = await pipeline('question-answering'); const answer = await qa({ question: 'What is the capital of France?', context: 'Paris is the capital and largest city of France.' });
javascriptconst generator = await pipeline('text-generation', 'onnx-community/gemma-3-270m-it-ONNX'); const text = await generator('Once upon a time', { max_new_tokens: 100, temperature: 0.7 });
For streaming and chat: See Text Generation Guide for:
TextStreamerjavascriptconst translator = await pipeline('translation', 'Xenova/nllb-200-distilled-600M'); const output = await translator('Hello, how are you?', { src_lang: 'eng_Latn', tgt_lang: 'fra_Latn' });
javascriptconst summarizer = await pipeline('summarization'); const summary = await summarizer(longText, { max_length: 100, min_length: 30 });
javascriptconst classifier = await pipeline('zero-shot-classification'); const result = await classifier('This is a story about sports.', ['politics', 'sports', 'technology']);
javascriptconst classifier = await pipeline('image-classification'); const result = await classifier('https://example.com/image.jpg'); // Or with local file const result = await classifier(imageUrl);
javascriptconst detector = await pipeline('object-detection'); const objects = await detector('https://example.com/image.jpg'); // Returns: [{ label: 'person', score: 0.95, box: { xmin, ymin, xmax, ymax } }, ...]
javascriptconst segmenter = await pipeline('image-segmentation'); const segments = await segmenter('https://example.com/image.jpg');
javascriptconst depthEstimator = await pipeline('depth-estimation'); const depth = await depthEstimator('https://example.com/image.jpg');
javascriptconst classifier = await pipeline('zero-shot-image-classification'); const result = await classifier('image.jpg', ['cat', 'dog', 'bird']);
javascriptconst transcriber = await pipeline('automatic-speech-recognition'); const result = await transcriber('audio.wav'); // Returns: { text: 'transcribed text here' }
javascriptconst classifier = await pipeline('audio-classification'); const result = await classifier('audio.wav');
javascriptconst synthesizer = await pipeline('text-to-speech', 'Xenova/speecht5_tts'); const audio = await synthesizer('Hello, this is a test.', { speaker_embeddings: speakerEmbeddings });
javascriptconst captioner = await pipeline('image-to-text'); const caption = await captioner('image.jpg');
javascriptconst docQA = await pipeline('document-question-answering'); const answer = await docQA('document-image.jpg', 'What is the total amount?');
javascriptconst detector = await pipeline('zero-shot-object-detection'); const objects = await detector('image.jpg', ['person', 'car', 'tree']);
javascriptconst extractor = await pipeline('feature-extraction'); const embeddings = await extractor('This is a sentence to embed.'); // Returns: tensor of shape [1, sequence_length, hidden_size] // For sentence embeddings (mean pooling) const extractor = await pipeline('feature-extraction', 'onnx-community/all-MiniLM-L6-v2-ONNX'); const embeddings = await extractor('Text to embed', { pooling: 'mean', normalize: true });
Discover compatible Transformers.js models on Hugging Face Hub:
Base URL (all models):
https://huggingface.co/models?library=transformers.js&sort=trendingFilter by task using the pipeline_tag parameter:
| Task | URL | |------|-----| | Text Generation | https://huggingface.co/models?pipeline_tag=text-generation&library=transformers.js&sort=trending | | Text Classification | https://huggingface.co/models?pipeline_tag=text-classification&library=transformers.js&sort=trending | | Translation | https://huggingface.co/models?pipeline_tag=translation&library=transformers.js&sort=trending | | Summarization | https://huggingface.co/models?pipeline_tag=summarization&library=transformers.js&sort=trending | | Question Answering | https://huggingface.co/models?pipeline_tag=question-answering&library=transformers.js&sort=trending | | Image Classification | https://huggingface.co/models?pipeline_tag=image-classification&library=transformers.js&sort=trending | | Object Detection | https://huggingface.co/models?pipeline_tag=object-detection&library=transformers.js&sort=trending | | Image Segmentation | https://huggingface.co/models?pipeline_tag=image-segmentation&library=transformers.js&sort=trending | | Speech Recognition | https://huggingface.co/models?pipeline_tag=automatic-speech-recognition&library=transformers.js&sort=trending | | Audio Classification | https://huggingface.co/models?pipeline_tag=audio-classification&library=transformers.js&sort=trending | | Image-to-Text | https://huggingface.co/models?pipeline_tag=image-to-text&library=transformers.js&sort=trending | | Feature Extraction | https://huggingface.co/models?pipeline_tag=feature-extraction&library=transformers.js&sort=trending | | Zero-Shot Classification | https://huggingface.co/models?pipeline_tag=zero-shot-classification&library=transformers.js&sort=trending |
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:
javascript// 1. Visit: https://huggingface.co/models?pipeline_tag=text-generation&library=transformers.js&sort=trending // 2. Browse and select a model (e.g., onnx-community/gemma-3-270m-it-ONNX) // 3. Check model card for: // - Model size: ~270M parameters // - Quantization: q4 available // - Language: English // - Use case: Instruction-following chat // 4. Use the model: import { pipeline } from '@huggingface/transformers'; const generator = await pipeline( 'text-generation', 'onnx-community/gemma-3-270m-it-ONNX', { dtype: 'q4' } // Use quantized version for faster inference ); const output = await generator('Explain quantum computing in simple terms.', { max_new_tokens: 100 }); await generator.dispose();
onnx folder in model repo)Xenova (Transformers.js maintainer) or onnx-communityjavascript const pipe = await pipeline('task', 'model-id', { revision: 'abc123' });
env)The env object provides comprehensive control over Transformers.js execution, caching, and model loading.
Quick Overview:
javascriptimport { env } from '@huggingface/transformers'; // View version console.log(env.version); // e.g., '3.8.1' // Common settings env.allowRemoteModels = true; // Load from Hugging Face Hub env.allowLocalModels = false; // Load from file system env.localModelPath = '/models/'; // Local model directory env.useFSCache = true; // Cache models on disk (Node.js) env.useBrowserCache = true; // Cache models in browser env.cacheDir = './.cache'; // Cache directory location
Configuration Patterns:
javascript// Development: Fast iteration with remote models env.allowRemoteModels = true; env.useFSCache = true; // Production: Local models only env.allowRemoteModels = false; env.allowLocalModels = true; env.localModelPath = '/app/models/'; // Custom CDN env.remoteHost = 'https://cdn.example.com/models'; // Disable caching (testing) env.useFSCache = false; env.useBrowserCache = false;
For complete documentation on all configuration options, caching strategies, cache management, pre-downloading models, and more, see:
→ Configuration Reference
javascriptimport { AutoTokenizer, AutoModel } from '@huggingface/transformers'; // Load tokenizer and model separately for more control const tokenizer = await AutoTokenizer.from_pretrained('bert-base-uncased'); const model = await AutoModel.from_pretrained('bert-base-uncased'); // Tokenize input const inputs = await tokenizer('Hello world!'); // Run model const outputs = await model(inputs);
javascriptconst classifier = await pipeline('sentiment-analysis'); // Process multiple texts const results = await classifier([ 'I love this!', 'This is terrible.', 'It was okay.' ]);
WebGPU provides GPU acceleration in browsers:
javascriptconst pipe = await pipeline('text-generation', 'onnx-community/gemma-3-270m-it-ONNX', { device: 'webgpu', dtype: 'fp32' });
Note: WebGPU is experimental. Check browser compatibility and file issues if problems occur.
Default browser execution uses WASM:
javascript// Optimized for browsers with quantization const pipe = await pipeline('sentiment-analysis', 'model-id', { dtype: 'q8' // or 'q4' for even smaller size });
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:
javascriptimport { pipeline } from '@huggingface/transformers'; // Track progress for each file const fileProgress = {}; function onProgress(info) { console.log(`${info.status}: ${info.file}`); if (info.status === 'progress') { fileProgress[info.file] = info.progress; console.log(`${info.file}: ${info.progress.toFixed(1)}%`); } if (info.status === 'done') { console.log(`✓ ${info.file} complete`); } } // Pass callback to pipeline const classifier = await pipeline('sentiment-analysis', null, { progress_callback: onProgress });
Progress Info Properties:
typescriptinterface ProgressInfo { status: 'initiate' | 'download' | 'progress' | 'done' | 'ready'; name: string; // Model id or path file: string; // File being processed progress?: number; // Percentage (0-100, only for 'progress' status) loaded?: number; // Bytes downloaded (only for 'progress' status) total?: number; // Total bytes (only for 'progress' status) }
For complete examples including browser UIs, React components, CLI progress bars, and retry logic, see:
→ Pipeline Options - Progress Callback
javascripttry { const pipe = await pipeline('sentiment-analysis', 'model-id'); const result = await pipe('text to analyze'); } catch (error) { if (error.message.includes('fetch')) { console.error('Model download failed. Check internet connection.'); } else if (error.message.includes('ONNX')) { console.error('Model execution failed. Check model compatibility.'); } else { console.error('Unknown error:', error); } }
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.
javascriptconst pipe = await pipeline('sentiment-analysis'); const result = await pipe('Great product!'); await pipe.dispose(); // ✓ Free memory (100MB - several GB per model)
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.
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-08 | pass→pass | 15,260 | 8,774 | -43% | 1 | 1 | 0% | 2,092 | 7,039 | +236% | 0 | 0 | — |
case-01 | fail→pass | 21,775 | 14,134 | -35% | 1 | 1 | 0% | 3,117 | 7,552 | +142% | 0 | 0 | — |
case-02 | fail→pass | 14,628 | 16,361 | +12% | 1 | 1 | 0% | 2,223 | 7,450 | +235% | 0 | 0 | — |
case-03 | pass→pass | 19,036 | 10,972 | -42% | 1 | 1 | 0% | 3,450 | 7,390 | +114% | 0 | 0 | — |
case-04 | pass→pass | 14,659 | 12,931 | -12% | 1 | 1 | 0% | 2,308 | 7,603 | +229% | 0 | 0 | — |
case-05 | pass→pass | 15,621 | 21,740 | +39% | 1 | 1 | 0% | 2,757 | 7,411 | +169% | 0 | 0 | — |
case-06 | pass→pass | 12,870 | 7,695 | -40% | 1 | 1 | 0% | 2,221 | 7,132 | +221% | 0 | 0 | — |
case-07 | pass→pass | 10,476 | 9,741 | -7% | 1 | 1 | 0% | 1,959 | 7,587 | +287% | 0 | 0 | — |
case-09 | pass→pass | 16,883 | 10,516 | -38% | 1 | 1 | 0% | 2,887 | 7,517 | +160% | 0 | 0 | — |
case-10 | fail→pass | 12,427 | 10,079 | -19% | 1 | 1 | 0% | 2,350 | 7,195 | +206% | 0 | 0 | — |
case-11 | pass→pass | 12,303 | 8,717 | -29% | 1 | 1 | 0% | 2,345 | 7,345 | +213% | 0 | 0 | — |
case-12 | pass→pass | 15,570 | 7,828 | -50% | 1 | 1 | 0% | 1,603 | 6,787 | +323% | 0 | 0 | — |
case-13 | pass→pass | 18,682 | 12,681 | -32% | 1 | 1 | 0% | 3,244 | 7,479 | +131% | 0 | 0 | — |
case-14 | pass→pass | 18,102 | 9,814 | -46% | 1 | 1 | 0% | 2,728 | 7,620 | +179% | 0 | 0 | — |
case-15 | pass→pass | 20,557 | 6,860 | -67% | 1 | 1 | 0% | 2,495 | 6,926 | +178% | 0 | 0 | — |
case-16 | pass→pass | 11,164 | 8,651 | -23% | 1 | 1 | 0% | 1,915 | 6,865 | +258% | 0 | 0 | — |
case-17 | pass→pass | 11,963 | 6,348 | -47% | 1 | 1 | 0% | 1,705 | 6,856 | +302% | 0 | 0 | — |
case-18 | pass→pass | 28,968 | 18,387 | -37% | 1 | 1 | 0% | 4,138 | 9,225 | +123% | 0 | 0 | — |
case-19 | pass→pass | 11,954 | 8,845 | -26% | 1 | 1 | 0% | 2,252 | 7,408 | +229% | 0 | 0 | — |
case-20 | pass→pass | 15,807 | 16,350 | +3% | 1 | 1 | 0% | 3,242 | 8,793 | +171% | 0 | 0 | — |
case-21 | pass→pass | 29,458 | 17,450 | -41% | 1 | 1 | 0% | 6,006 | 9,481 | +58% | 0 | 0 | — |
case-22 | pass→pass | 23,883 | 14,155 | -41% | 1 | 1 | 0% | 3,512 | 8,311 | +137% | 0 | 0 | — |
case-23 | pass→pass | 17,646 | 10,833 | -39% | 1 | 1 | 0% | 2,685 | 7,773 | +189% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 23 cases were attempted. The headline lift of +13 percentage points is the difference between those two pass rates over the 23 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.