transformers-js
ما الذي تفعله
تتيح هذه المهارة للذكاء الاصطناعي إضافة ميزات تعلم الآلة إلى تطبيق JavaScript أو TypeScript دون خادم بلغة Python. وهي لمطوري الويب والتطبيقات الذين يريدون تشغيل النماذج في المتصفح أو على Node.js.
متى تستخدمها
- ✓عندما تريد تحليل النصوص أو الترجمة أو التلخيص داخل تطبيق JavaScript.
- ✓عندما تحتاج إلى تصنيف الصور أو كشف الأشياء في المتصفح.
- ✓عندما تريد التعرف على الكلام أو تصنيف الصوت دون خلفية خادم.
رابط المهارة
https://github.com/huggingface/skills/blob/main/skills/transformers-js/SKILL.mdانسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.
طريقة الاستخدام
أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.
رسالة جاهزة للصق
لـ Claude Code أو Codex أو Cursor: شغّله داخل مجلد مشروعك وستُثبَّت المهارة.
نزّل ملف SKILL.md وضعه في مجلد مهارات وكيلك.
مثال على ما تطلبه من الذكاء الاصطناعي
“أضف فحص مشاعر إلى تطبيق React الخاص بي يعمل بالنموذج في المتصفح، دون حاجة إلى خادم.”
5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.
كيف تعمل
يستخدم الذكاء الاصطناعي مكتبة Transformers.js، التي تشغّل نماذج مدرّبة مسبقاً عبر واجهة pipeline. تتولى المعالجة قبل النموذج وبعده للمهمة التي تختارها، وتعمل على 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.
ما هي واجهة pipeline؟
طريقة بسيطة لتحميل نموذج لمهمة، تتولى الخطوات قبل تشغيله وبعده.
كيف تُثبَّت؟
تُثبَّت بـ 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
- آخر تحديث
- 30/10/2026
التعليقات
- …
المزيد من المهارات من هذا المستودع
hf-cli
11kيساعد وكيلك على استخدام أداة Hugging Face في سطر الأوامر لتنزيل النماذج ومجموعات البيانات والـ Spaces والمستودعات ورفعها وإدارة الذاكرة المؤقتة المحلية.
hf-cloud-aws-context-discovery
11kيساعد وكيلك على معرفة ملف تعريف AWS والمنطقة وتفاصيل الحساب قبل أي عمل سحابي، حتى لا يخمّن أي حساب يستخدم.
hf-cloud-python-env-setup
11kيساعد وكيلك على إعداد بيئة Python نظيفة بإصدار مناسب ومكتبات حديثة، قبل تشغيل أتمتة SageMaker أو AWS.
hf-cloud-sagemaker-deployment-planner
11kيساعد وكيلك على التخطيط لنشر نموذج على Amazon SageMaker، فيختار الاستضافة الفورية أو بلا خادم أو غير المتزامنة أو الدفعية بإعدادات افتراضية مناسبة.
مهارات مشابهة
angular-developer
280kيساعد وكيلك على كتابة شيفرة Angular وتقديم نصائح لبنية المشروع، ويفيد في بدء المشاريع الجديدة وإنشاء المكونات وتحسين الأداء وإمكانية الوصول.
frontend-a11y
280kيساعد وكيلك على جعل واجهات الويب متاحة للجميع، فيضمن أن المواقع والتطبيقات تعمل جيدًا مع قارئات الشاشة والتنقل بلوحة المفاتيح.
frontend-patterns
280kيطبّق وكيلك أنماط تطوير الواجهات الحديثة، فيحسّن الأداء ويدير الحالة ويتبع أفضل الممارسات في React وNext.js.