transformers-js
できること
このスキルは、Pythonのサーバーを使わずに、JavaScriptやTypeScriptのアプリに機械学習の機能を加えさせます。ブラウザやNode.jsでモデルを動かしたいWebやアプリの開発者向けです。
使う場面
- ✓テキストの分析、翻訳、要約をJavaScriptアプリの中で動かしたいとき。
- ✓ブラウザで画像の分類や物体検出をしたいとき。
- ✓バックエンドなしで音声認識や音声の分類をしたいとき。
スキルのリンク
https://github.com/huggingface/skills/blob/main/skills/transformers-js/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“私のReactアプリに、ブラウザでモデルを動かす感情分析の機能を加えてください。サーバーは不要にしてください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
AIは、Transformers.jsライブラリを使います。このライブラリは、パイプラインのAPIを通じて事前学習済みのモデルを動かします。選んだタスクに応じて前処理と出力を扱い、利用できる場合はWebGPUやWebAssemblyで動かします。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Transformers.js - Machine Learning for JavaScript
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.
When to Use This Skill
Use this skill when you need to:
- Run ML models for text analysis, generation, or translation in JavaScript
- Perform image classification, object detection, or segmentation
- Implement speech recognition or audio processing
- Build multimodal AI applications (text-to-image, image-to-text, etc.)
- Run models client-side in the browser without a backend
Installation
NPM Installation
npm install @huggingface/transformers
Browser Usage (CDN)
<script type="module">
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers';
</script>
Core Concepts
1. Pipeline API
The pipeline API is the easiest way to use models. It groups together preprocessing, model inference, and postprocessing:
import { 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 pipe.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.
2. Model Selection
You can specify a custom model as the second argument:
const pipe = await pipeline(
'sentiment-analysis',
'Xenova/bert-base-multilingual-uncased-sentiment'
);
Finding Models:
Browse available Transformers.js models on Hugging Face Hub:
- All models: https://huggingface.co/models?library=transformers.js&sort=trending
- By task: Add
pipeline_tagparameter- Text generation: https://huggingface.co/models?pipeline_tag=text-generation&library=transformers.js&sort=trending
- Image classification: https://huggingface.co/models?pipeline_tag=image-classification&library=transformers.js&sort=trending
- Speech recognition: https://huggingface.co/models?pipeline_tag=automatic-speech-recognition&library=transformers.js&sort=trending
Tip: Filter by task type, sort by trending/downloads, and check model cards for performance metrics and usage examples.
3. Device Selection
Choose where to run the model:
// Run on CPU (default for WASM)
const pipe = await pipeline('sentiment-analysis', 'model-id');
// Run on GPU (WebGPU)
const pipe = await pipeline('sentiment-analysis', 'model-id', {
device: 'webgpu',
});
4. Quantization Options
Control model precision vs. performance:
// Use quantized model (faster, smaller)
const pipe = await pipeline('sentiment-analysis', 'model-id', {
dtype: 'q4', // Options: 'fp32', 'fp16', 'q8', 'q4'
});
Supported Tasks
Note: All examples below show basic usage.
Natural Language Processing
Text Classification
const classifier = await pipeline('text-classification');
const result = await classifier('This movie was amazing!');
Named Entity Recognition (NER)
const ner = await pipeline('token-classification');
const entities = await ner('My name is John and I live in New York.');
Question Answering
const 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.'
});
Text Generation
const 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:
- Streaming token-by-token output with
TextStreamer - Chat/conversation format with system/user/assistant roles
- Generation parameters (temperature, top_k, top_p)
- Browser and Node.js examples
- React components and API endpoints
Translation
const translator = await pipeline('translation', 'Xenova/nllb-200-distilled-600M');
const output = await translator('Hello, how are you?'
よくある質問
バックエンドのサーバーが必要ですか?
いいえ。モデルはブラウザ内で直接、またはNode.js、Bun、Denoなどのサーバーのランタイムで動かせます。
パイプラインのAPIとは何ですか?
タスクのためにモデルを読み込む簡単な方法で、モデルの実行前後の手順を扱います。
どのようにインストールしますか?
npmでインストールするか、ブラウザのページからCDNで読み込みます。
詳細
作者による元の説明
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.
repo: huggingface/skills
人気
- GitHubのスター
- 11k
- ランキング
- #11782
- ライセンス
- Apache-2.0
- 更新日
- 2026/10/30
コメント
- …
このリポジトリの他のスキル
hf-cli
11kエージェントが、Hugging Faceのコマンドラインツールhfでモデル、データセット、Spaces、リポジトリ、ローカルのキャッシュをダウンロード、アップロード、管理できるよう支援します。
hf-cloud-aws-context-discovery
11kエージェントが、クラウドの作業を始める前にAWSのプロファイル、リージョン、アカウントの詳細を見つけ、どのアカウントを使うかを推測しないよう支援します。
hf-cloud-python-env-setup
11kエージェントが、SageMakerやAWSの自動化を実行する前に、適切なPythonのバージョンと最新のライブラリで、クリーンなPython環境を設定できるよう支援します。
hf-cloud-sagemaker-deployment-planner
11kエージェントが、モデルをAmazon SageMakerにデプロイする方法を計画し、リアルタイム、サーバーレス、非同期、バッチのホスティングから、適切な既定値とともに選べるよう支援します。
似ているスキル
angular-developer
280kエージェントがAngularのコードを作成し、プロジェクト構成についてアドバイスできるようにします。新しいプロジェクトの開始、コード部品の作成、パフォーマンスやアクセシビリティの改善に役立ちます。
frontend-a11y
280kエージェントが Web インターフェースを誰にとっても使いやすくするよう支援します。スクリーンリーダーやキーボード操作に対応し、サイトやアプリが適切に動作するようにします。
frontend-patterns
280kエージェントがフロントエンド開発の最新パターンを適用できるようにします。React と Next.js において、パフォーマンスの最適化、状態管理、ベストプラクティスの遵守を行います。