huggingface-transformers

huggingface-transformers is a skill for Claude Code, Codex from znlgis/opengis-skills. It costs 86 tokens per session (4,427 once invoked), scanned A, original, MIT.

A Python guide for using Hugging Face Transformers, a library for running and training machine-learning models for text, images, audio, and combined inputs. It covers model loading, text processing, inference, fine-tuning, memory settings, and BGE embeddings for Chinese retrieval-augmented generation (RAG).

In plain words
What is it for?
Use it to run text classification or text generation, load models and tokenizers, fine-tune models with Trainer, manage CPU or GPU memory, or create embeddings for Chinese RAG systems.
Why use it?
It gives coding agents practical instructions for choosing the right model interfaces and handling model inputs, training, device memory, and supporting libraries. This reduces guesswork when adding model features to a Python project.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to run text classification or text generation, load models and tokenizers, fine-tune models with Trainer, manage CPU or GPU memory, or create embeddings for Chinese RAG systems.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/znlgis/opengis-skills/huggingface-transformers
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add znlgis/opengis-skills --skill huggingface-transformers
Clone the repo
git clone --depth 1 https://github.com/znlgis/opengis-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for huggingface-transformers

README.md
[![agentmods](https://agentmods.dev/badge/skills/znlgis/opengis-skills/huggingface-transformers/github.svg)](https://agentmods.dev/skills/znlgis/opengis-skills/huggingface-transformers)
Your own site
<a href="https://agentmods.dev/skills/znlgis/opengis-skills/huggingface-transformers"><img src="https://agentmods.dev/badge/skills/znlgis/opengis-skills/huggingface-transformers/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for huggingface-transformers

Your own site · 80×15
<a href="https://agentmods.dev/skills/znlgis/opengis-skills/huggingface-transformers"><img src="https://agentmods.dev/badge/skills/znlgis/opengis-skills/huggingface-transformers.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 86 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 4,427 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00086 $0.04427
Opus 5.5 $0.00034 $0.01771
Sonnet 5.5 $0.00017 $0.00885
Haiku 4.5 $0.00009 $0.00443

Measured today against content hash 19b1348b45d0, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

huggingface-transformers scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured today.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

ai/huggingface-transformers/SKILL.md · 360 lines

How it starts

The opening of the file, as written. The whole thing — 360 lines — stays where its author put it; the contents beside it link to each section on GitHub.

项目地址: https://github.com/huggingface/transformers

官方文档: https://huggingface.co/docs/transformers/

许可证: Apache-2.0 最新版本: v5.19.0(PyPI 与 GitHub Releases 双核实,截至 2026-10)

概述

Transformers 是 Hugging Face 开源的模型定义框架,为文本、视觉、音频与多模态模型提供统一的推理与训练接口。它把「配置、模型、预处理器」抽象为三类基类,并只用 pipeline 与 Trainer 两个 API 覆盖推理与微调两条主线。模型权重托管在 Hugging Face Hub,from_pretrained() 可按名称或路径自动下载并缓存。

  • AutoClass:AutoModel / AutoTokenizer / AutoModelForCausalLM / AutoModelForSequenceClassification / AutoModelForSeq2SeqLM 等按任务自动推断架构
  • pipeline():任务级推理封装,一行完成预处理、前向与后处理
  • Trainer:PyTorch 训练/评估循环,配合 TrainingArguments 配置超参
  • 显存管理:device_map="auto"、dtype="auto"、BitsAndBytesConfig 量化
  • 生态:datasets、evaluate、accelerate、huggingface_hub、safetensors 协同工作

Transformers 是库(进程内推理/训练),与 Ollama 这类独立推理服务定位不同,详见「最佳实践」。


环境准备

要求 Python >= 3.10(v5 起)。

# 核心:Transformers 与 PyTorch
pip install -U transformers torch

# 常用配套:数据集、评估指标、多设备调度
pip install -U datasets evaluate accelerate

可选 GPU 加速:

# NVIDIA CUDA(按显卡驱动选择 cu 版本,示例)
pip install torch --index-url https://download.pytorch.org/whl/cu124

量化推理(8bit/4bit)需额外安装:

pip install -U bitsandbytes

验证安装:

python -X utf8 -c "import torch, transformers; print(transformers.__version__, torch.__version__, torch.cuda.is_available())"

登录 Hub(拉取受限模型或推送模型时需要,Token 从账号设置生成):

hf auth login

核心 API/命令

pipeline() 快速推理

pipeline(task, model=..., device=..., dtype=...) 返回任务流水线;不传 model 时使用该任务的默认模型。

from transformers import pipeline

# 文本分类(情感分析别名 sentiment-analysis)
clf = pipeline("text-classification", model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")
clf("This restaurant is awesome")
# [{'label': 'POSITIVE', 'score': 0.9998...}]

# 文本生成
gen = pipeline("text-generation", model="openai-community/gpt2")
gen("the secret to baking a good cake is", max_new_tokens=40, return_full_text=False)

# 特征抽取(嵌入)
feat = pipeline("feature-extraction", model="BAAI/bge-large-zh-v1.5")
feat("地理信息系统")

Read the full file on GitHub · 360 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. today First seen · 360 lines · 86 tokens per session scan A 19b1348b45d0

Subscribe to this mod's changes

huggingface-transformers is a skill published in the GitHub repository znlgis/opengis-skills (64 stars, last pushed yesterday), licensed MIT. It adds 86 tokens to every session and 4,427 once invoked, about $0.0003 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-10-16.

Related

Other skills, from other repositories