transformers-js
Fungsinya
Skill ini memungkinkan AI menambahkan fitur machine learning ke aplikasi JavaScript atau TypeScript tanpa server Python. Skill ini ditujukan untuk developer web dan aplikasi yang ingin model berjalan di browser atau Node.js.
Kapan dipakai
- ✓Saat Anda ingin analisis teks, terjemahan atau ringkasan berjalan di dalam aplikasi JavaScript.
- ✓Saat Anda membutuhkan klasifikasi gambar atau deteksi objek di browser.
- ✓Saat Anda ingin pengenalan suara atau klasifikasi audio tanpa backend.
Link skill
https://github.com/huggingface/skills/blob/main/skills/transformers-js/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
“Tambahkan pemeriksaan sentimen ke aplikasi React saya yang menjalankan model di browser, tanpa perlu server.”
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
AI memakai pustaka Transformers.js, yang menjalankan model pra-latih lewat API pipeline. AI menangani pemrosesan awal dan keluaran untuk tugas yang Anda pilih, dan berjalan di WebGPU atau WebAssembly jika tersedia.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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?'
Pertanyaan umum
Apakah perlu server backend?
Tidak. Model bisa berjalan langsung di browser atau di runtime server seperti Node.js, Bun atau Deno.
Apa itu API pipeline?
Cara sederhana untuk memuat model untuk sebuah tugas, dengan menangani langkah sebelum dan sesudah model dijalankan.
Bagaimana cara memasangnya?
Dipasang dengan npm, atau dimuat dari CDN di halaman browser.
Detail
Deskripsi asli dari pembuat
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
Popularitas
- Bintang GitHub
- 11k
- Peringkat
- #11782
- Lisensi
- Apache-2.0
- Diperbarui
- 30/10/2026
Komentar
- …
Skill lain dari repositori ini
hf-cli
11kMembantu agent Anda memakai alat baris perintah Hugging Face untuk mengunduh, mengunggah dan mengelola model, dataset, Space, repositori serta cache lokal.
hf-cloud-aws-context-discovery
11kMembantu agent Anda menemukan profil, wilayah dan detail akun AWS Anda sebelum pekerjaan cloud apa pun, sehingga agent tidak menebak akun mana yang harus dipakai.
hf-cloud-python-env-setup
11kMembantu agent Anda menyiapkan lingkungan Python yang bersih dengan versi Python yang sesuai dan pustaka terbaru, sebelum menjalankan SageMaker atau otomatisasi AWS.
hf-cloud-sagemaker-deployment-planner
11kMembantu agent Anda merencanakan cara men-deploy model ke Amazon SageMaker, memilih hosting real-time, serverless, async atau batch dengan default yang masuk akal.
Skill serupa
angular-developer
280kMembantu agent Anda membuat kode Angular dan memberi saran struktur proyek. Berguna saat memulai proyek baru, membuat komponen, atau meningkatkan performa.
frontend-a11y
280kMembantu agent Anda membuat antarmuka web dapat diakses semua orang. Memastikan website dan aplikasi berfungsi baik dengan screen reader dan navigasi keyboard.
frontend-patterns
280kMembuat agent Anda menerapkan pola modern dalam frontend. Mengoptimalkan performa, mengelola state, dan mengikuti praktik terbaik React dan Next.js.