重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
transformers by k-dense-ai/claude-scientific-skills
npx skills add https://github.com/k-dense-ai/claude-scientific-skills --skill transformersHugging Face Transformers 库提供了数千个预训练模型,覆盖 NLP、计算机视觉、音频和多模态领域的任务。使用此技能来加载模型、执行推理以及在自定义数据上进行微调。
安装 transformers 及其核心依赖:
uv pip install torch transformers datasets evaluate accelerate
对于视觉任务,添加:
uv pip install timm pillow
对于音频任务,添加:
uv pip install librosa soundfile
Hugging Face Hub 上的许多模型需要认证。设置访问权限:
from huggingface_hub import login
login() # 按照提示输入令牌
或者设置环境变量:
export HUGGINGFACE_TOKEN="your_token_here"
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
使用 Pipeline API 进行快速推理,无需手动配置:
from transformers import pipeline
# 文本生成
generator = pipeline("text-generation", model="gpt2")
result = generator("The future of AI is", max_length=50)
# 文本分类
classifier = pipeline("text-classification")
result = classifier("This movie was excellent!")
# 问答
qa = pipeline("question-answering")
result = qa(question="What is AI?", context="AI is artificial intelligence...")
用于跨多种任务的简单、优化的推理。支持文本生成、分类、命名实体识别、问答、摘要、翻译、图像分类、目标检测、音频分类等。
使用场景:快速原型设计、简单的推理任务、无需自定义预处理。
有关全面的任务覆盖和优化,请参阅 references/pipelines.md。
加载预训练模型,可精细控制配置、设备放置和精度。
使用场景:自定义模型初始化、高级设备管理、模型检查。
有关加载模式和最佳实践,请参阅 references/models.md。
使用各种解码策略(贪婪、束搜索、采样)和控制参数(temperature、top-k、top-p)通过 LLMs 生成文本。
使用场景:创意文本生成、代码生成、对话式 AI、文本补全。
有关生成策略和参数,请参阅 references/generation.md。
使用 Trainer API 在自定义数据集上微调预训练模型,支持自动混合精度、分布式训练和日志记录。
使用场景:特定任务模型适配、领域适配、提升模型性能。
有关训练工作流和最佳实践,请参阅 references/training.md。
将文本转换为模型输入的 token 和 token ID,并处理填充、截断和特殊 token。
使用场景:自定义预处理流水线、理解模型输入、批处理。
有关分词细节,请参阅 references/tokenizers.md。
对于直接的任务,使用 pipelines:
pipe = pipeline("task-name", model="model-id")
output = pipe(input_data)
对于高级控制,分别加载模型和分词器:
from transformers import AutoModelForCausalLM, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("model-id")
model = AutoModelForCausalLM.from_pretrained("model-id", device_map="auto")
inputs = tokenizer("text", return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=100)
result = tokenizer.decode(outputs[0])
对于任务适配,使用 Trainer:
from transformers import Trainer, TrainingArguments
training_args = TrainingArguments(
output_dir="./results",
num_train_epochs=3,
per_device_train_batch_size=8,
)
trainer = Trainer(
model=model,
args=training_args,
train_dataset=train_dataset,
)
trainer.train()
有关特定组件的详细信息:
references/pipelines.md - 所有支持的任务和优化references/models.md - 加载、保存和配置references/generation.md - 文本生成策略和参数references/training.md - 使用 Trainer API 进行微调references/tokenizers.md - 分词和预处理每周安装数
58
代码仓库
GitHub 星标数
17.3K
首次出现时间
2026 年 1 月 20 日
安全审计
安装于
opencode50
codex49
gemini-cli49
claude-code46
cursor46
github-copilot45
The Hugging Face Transformers library provides access to thousands of pre-trained models for tasks across NLP, computer vision, audio, and multimodal domains. Use this skill to load models, perform inference, and fine-tune on custom data.
Install transformers and core dependencies:
uv pip install torch transformers datasets evaluate accelerate
For vision tasks, add:
uv pip install timm pillow
For audio tasks, add:
uv pip install librosa soundfile
Many models on the Hugging Face Hub require authentication. Set up access:
from huggingface_hub import login
login() # Follow prompts to enter token
Or set environment variable:
export HUGGINGFACE_TOKEN="your_token_here"
Get tokens at: https://huggingface.co/settings/tokens
Use the Pipeline API for fast inference without manual configuration:
from transformers import pipeline
# Text generation
generator = pipeline("text-generation", model="gpt2")
result = generator("The future of AI is", max_length=50)
# Text classification
classifier = pipeline("text-classification")
result = classifier("This movie was excellent!")
# Question answering
qa = pipeline("question-answering")
result = qa(question="What is AI?", context="AI is artificial intelligence...")
Use for simple, optimized inference across many tasks. Supports text generation, classification, NER, question answering, summarization, translation, image classification, object detection, audio classification, and more.
When to use : Quick prototyping, simple inference tasks, no custom preprocessing needed.
See references/pipelines.md for comprehensive task coverage and optimization.
Load pre-trained models with fine-grained control over configuration, device placement, and precision.
When to use : Custom model initialization, advanced device management, model inspection.
See references/models.md for loading patterns and best practices.
Generate text with LLMs using various decoding strategies (greedy, beam search, sampling) and control parameters (temperature, top-k, top-p).
When to use : Creative text generation, code generation, conversational AI, text completion.
See references/generation.md for generation strategies and parameters.
Fine-tune pre-trained models on custom datasets using the Trainer API with automatic mixed precision, distributed training, and logging.
When to use : Task-specific model adaptation, domain adaptation, improving model performance.
See references/training.md for training workflows and best practices.
Convert text to tokens and token IDs for model input, with padding, truncation, and special token handling.
When to use : Custom preprocessing pipelines, understanding model inputs, batch processing.
See references/tokenizers.md for tokenization details.
For straightforward tasks, use pipelines:
pipe = pipeline("task-name", model="model-id")
output = pipe(input_data)
For advanced control, load model and tokenizer separately:
from transformers import AutoModelForCausalLM, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("model-id")
model = AutoModelForCausalLM.from_pretrained("model-id", device_map="auto")
inputs = tokenizer("text", return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=100)
result = tokenizer.decode(outputs[0])
For task adaptation, use Trainer:
from transformers import Trainer, TrainingArguments
training_args = TrainingArguments(
output_dir="./results",
num_train_epochs=3,
per_device_train_batch_size=8,
)
trainer = Trainer(
model=model,
args=training_args,
train_dataset=train_dataset,
)
trainer.train()
For detailed information on specific components:
references/pipelines.md - All supported tasks and optimizationreferences/models.md - Loading, saving, and configurationreferences/generation.md - Text generation strategies and parametersreferences/training.md - Fine-tuning with Trainer APIreferences/tokenizers.md - Tokenization and preprocessingWeekly Installs
58
Repository
GitHub Stars
17.3K
First Seen
Jan 20, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
opencode50
codex49
gemini-cli49
claude-code46
cursor46
github-copilot45
AI界面设计评审工具 - 全面评估UI/UX设计质量、检测AI生成痕迹与优化用户体验
58,500 周安装