transformers by davila7/claude-code-templates
npx skills add https://github.com/davila7/claude-code-templates --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)通过 LLM 生成文本。
使用场景:创意文本生成、代码生成、对话式 AI、文本补全。
有关生成策略和参数,请参阅 references/generation.md。
使用 Trainer API 在自定义数据集上微调预训练模型,支持自动混合精度、分布式训练和日志记录。
使用场景:特定任务模型适配、领域适配、提升模型性能。
有关训练工作流和最佳实践,请参阅 references/training.md。
将文本转换为模型输入的标记和标记 ID,并处理填充、截断和特殊标记。
使用场景:自定义预处理流水线、理解模型输入、批处理。
有关分词详细信息,请参阅 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 - 分词和预处理每周安装次数
171
代码仓库
GitHub 星标数
22.6K
首次出现
2026年1月21日
安全审计
安装于
opencode135
claude-code130
gemini-cli129
cursor124
codex119
antigravity110
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
171
Repository
GitHub Stars
22.6K
First Seen
Jan 21, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
opencode135
claude-code130
gemini-cli129
cursor124
codex119
antigravity110
AI 代码实施计划编写技能 | 自动化开发任务分解与 TDD 流程规划工具
49,800 周安装
Ghostling libghostty 终端模拟器 - 基于 libghostty-vt 的轻量级终端实现
78 周安装
Windows路径故障排除指南:解决Claude Code文件操作错误与反斜杠使用
78 周安装
规模化个性化AI工具:快速生成销售外联开场白,提升转化率
78 周安装
TypeScript 整洁代码指南 - 开发原则、工作流程与代码质量最佳实践
78 周安装
Skills Vetter - Claude Code 技能安全审核工具 | 恶意代码检测 | 敏感信息扫描
78 周安装
test-generator:AI驱动的自动化测试代码生成工具,支持单元/集成/端到端测试
78 周安装