Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Hugging Face Transformers for loading Hub models, running pipeline inference, text generation, and Trainer fine-tuning on NLP, vision, audio, and multimodal tasks. Use when working with AutoModel, pipelines, tokenizers, or TrainingArguments—not for general ML outside the Transformers library.
.claude/skills/bilal140202-transformers/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-02 | ✗→✓ | ▲ Improved | 2% | 0% |
| case-05 | ✗→✓ | ▲ Improved | 58% | 0% |
| case-07 | ✗→✓ | ▲ Improved | -13% | 0% |
| case-13 | ✗→✓ | ▲ Improved | 99% | 0% |
| case-16 | ✗→✓ | ▲ Improved | 34% | 0% |
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.
Tested against transformers 5.12.0 (current PyPI release; June 2026). Requires Python 3.10+; the torch extra currently requires PyTorch 2.4+.
bashuv pip install "transformers[torch]==5.12.0" huggingface_hub==1.19.0 datasets==5.0.0 evaluate==0.4.6 accelerate==1.14.0
For vision tasks, add:
bashuv pip install timm==1.0.27 pillow==12.2.0
For audio tasks, add:
bashuv pip install librosa==0.11.0 soundfile==0.14.0
These pins are for reproducible examples. For exploratory work, loosen them only after checking the Transformers and Hub release notes for API changes.
Check your version:
pythonimport transformers print(transformers.__version__)
Many models on the Hugging Face Hub are gated or private. Authenticate before loading them.
Recommended: CLI login (stores token in ~/.cache/huggingface/token):
bashhf auth login
Python:
pythonfrom huggingface_hub import login login() # Interactive prompt; do not hardcode tokens in scripts
Servers / CI: set HF_TOKEN in the environment (never commit tokens to git or shell profiles):
bashexport HF_TOKEN="..." # Read token from a secret manager, not source code
Get tokens at: https://huggingface.co/settings/tokens
Security: Never paste tokens into notebooks, repos, or shared configs. Prefer hf auth login over exporting tokens in .bashrc or .zshrc.
Use the narrowest token scope that works: read for private or gated model downloads, write only for uploads. If a long-running environment should not send the stored token on every Hub request, set HF_HUB_DISABLE_IMPLICIT_TOKEN=1 and pass a token only where authentication is required.
Transformers v5 is PyTorch-only (TensorFlow and JAX backends were removed). For upgrades from v4, see the v5 migration guide. New projects should pair transformers 5.x with huggingface_hub 1.x.
Gated or custom architectures: accept the model license on the Hub, then load with trust_remote_code=True only when the model card requires custom code you have reviewed.
Cache location: set HF_HOME for all Hugging Face caches, or HF_HUB_CACHE just for Hub files. Use HF_HUB_OFFLINE=1 only after required model snapshots are already cached.
Use the Pipeline API for fast inference without manual configuration:
pythonfrom transformers import pipeline # Text generation (prefer max_new_tokens for causal LMs) generator = pipeline("text-generation", model="Qwen/Qwen2.5-1.5B") result = generator("The future of AI is", max_new_tokens=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:
pythonpipe = pipeline("task-name", model="model-id") output = pipe(input_data)
For advanced control, load model and tokenizer separately:
pythonfrom 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:
pythonfrom 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 preprocessing| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-21 | pass→pass | 4,073 | 3,273 | -20% | 1 | 1 | 0% | 839 | 2,252 | +168% | 0 | 0 | — |
case-01 | pass→pass | 4,367 | 2,681 | -39% | 1 | 1 | 0% | 724 | 2,103 | +190% | 0 | 0 | — |
case-02 | fail→pass | 9,732 | 2,829 | -71% | 1 | 1 | 0% | 2,094 | 2,143 | +2% | 0 | 0 | — |
case-03 | pass→pass | 5,422 | 3,553 | -34% | 1 | 1 | 0% | 1,222 | 2,453 | +101% | 0 | 0 | — |
case-04 | pass→pass | 8,551 | 5,855 | -32% | 1 | 1 | 0% | 1,657 | 2,708 | +63% | 0 | 0 | — |
case-05 | fail→pass | 7,193 | 3,454 | -52% | 1 | 1 | 0% | 1,403 | 2,213 | +58% | 0 | 0 | — |
case-06 | pass→pass | 4,904 | 3,721 | -24% | 1 | 1 | 0% | 871 | 2,184 | +151% | 0 | 0 | — |
case-07 | fail→pass | 12,421 | 4,029 | -68% | 1 | 1 | 0% | 2,426 | 2,101 | -13% | 0 | 0 | — |
case-08 | pass→pass | 5,811 | 3,261 | -44% | 1 | 1 | 0% | 1,191 | 2,259 | +90% | 0 | 0 | — |
case-09 | pass→pass | 5,216 | 5,008 | -4% | 1 | 1 | 0% | 1,075 | 2,568 | +139% | 0 | 0 | — |
case-10 | pass→pass | 4,808 | 4,249 | -12% | 1 | 1 | 0% | 895 | 2,470 | +176% | 0 | 0 | — |
case-11 | pass→pass | 2,339 | 2,345 | +0% | 1 | 1 | 0% | 518 | 2,079 | +301% | 0 | 0 | — |
case-12 | pass→pass | 4,929 | 4,183 | -15% | 1 | 1 | 0% | 937 | 2,412 | +157% | 0 | 0 | — |
case-13 | fail→pass | 6,497 | 5,484 | -16% | 1 | 1 | 0% | 1,259 | 2,504 | +99% | 0 | 0 | — |
case-14 | pass→pass | 7,890 | 2,648 | -66% | 1 | 1 | 0% | 1,412 | 2,138 | +51% | 0 | 0 | — |
case-15 | pass→pass | 9,515 | 2,373 | -75% | 1 | 1 | 0% | 1,878 | 2,067 | +10% | 0 | 0 | — |
case-16 | fail→pass | 7,854 | 2,088 | -73% | 1 | 1 | 0% | 1,535 | 2,064 | +34% | 0 | 0 | — |
case-22 | pass→pass | 3,380 | 3,288 | -3% | 1 | 1 | 0% | 733 | 2,251 | +207% | 0 | 0 | — |
case-17 | pass→pass | 7,754 | 3,931 | -49% | 1 | 1 | 0% | 1,608 | 2,376 | +48% | 0 | 0 | — |
case-18 | pass→pass | 3,263 | 3,433 | +5% | 1 | 1 | 0% | 674 | 1,909 | +183% | 0 | 0 | — |
case-19 | pass→pass | 2,048 | 2,377 | +16% | 1 | 1 | 0% | 379 | 1,990 | +425% | 0 | 0 | — |
case-20 | pass→pass | 2,495 | 2,073 | -17% | 1 | 1 | 0% | 491 | 1,985 | +304% | 0 | 0 | — |
case-23 | fail→pass | 14,847 | 7,300 | -51% | 1 | 1 | 0% | 3,059 | 3,225 | +5% | 0 | 0 | — |
case-24 | pass→fail | 32,735 | 20,648 | -37% | 1 | 1 | 0% | 3,471 | 6,220 | +79% | 0 | 0 | — |
case-25 | pass→pass | 8,879 | 9,225 | +4% | 1 | 1 | 0% | 2,028 | 3,504 | +73% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 25 cases were attempted. The headline lift of +20 percentage points is the difference between those two pass rates over the 25 comparable cases. 1 case got worse with the skill loaded, and it is included in that figure.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.