transformers

Load, run inference on, and fine-tune pre-trained Hugging Face transformer models.

Updated Oct 7, 2022
One-click install
npx skills add https://github.com/tamagusko/linux-cfg --skill transformers-tamagusko
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: transformers
Source: https://github.com/tamagusko/linux-cfg/tree/main/dotfiles/claude/skills/transformers
Command: npx skills add https://github.com/tamagusko/linux-cfg --skill transformers-tamagusko

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires torch, transformers, datasets, evaluate, accelerate, and includes references (resource) components.

What problem does it solve? Working with pre-trained transformer models involves repetitive boilerplate for loading models, tokenizing inputs, configuring generation, and setting up training loops. This Skill provides structured guidance and code patterns for the Hugging Face Transformers library across NLP, vision, audio, and multimodal tasks. ## Core Features & Use Cases - Pipeline Inference: Run text generation, classification, question answering, translation, summarization, image classification, object detection, and speech recognition with the Pipeline API. - Model Management: Load models with control over device placement, precision (float16/bfloat16), quantization (8-bit/4-bit), and attention implementations. - Fine-Tuning: Train models on custom datasets using the Trainer API with mixed precision, gradient accumulation, LoRA/PEFT, and DeepSpeed support. - Use Case: Fine-tune a BERT classifier on your own labeled dataset, then generate text with a causal language model using sampling parameters like temperature and top-p. ## Quick Start Use the transformers skill to load a pre-trained model and run text classification on my input text.

Frequently Asked Questions about transformers

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use Hugging Face transformers for text classification?

Use the pipeline API with the text-classification task: create a pipeline with pipeline("text-classification") and pass your text directly. For custom models, load AutoModelForSequenceClassification and AutoTokenizer from the same checkpoint.

How to fine-tune a pre-trained transformer model on a custom dataset?

Tokenize your dataset with AutoTokenizer, load a model with AutoModelForSequenceClassification, configure TrainingArguments with learning rate and batch size, then pass everything to the Trainer API and call trainer.train().

Does transformers support GPU acceleration and mixed precision?

Yes. Pass device=0 to pipelines for GPU usage, or use device_map="auto" for automatic placement of large models. Enable fp16 or bf16 in TrainingArguments for mixed precision training on supported NVIDIA GPUs.

How do I reduce memory usage when loading large language models?

Load with torch_dtype=torch.float16, enable low_cpu_mem_usage=True, or apply 8-bit/4-bit quantization via BitsAndBytesConfig. Combining quantization with device_map="auto" distributes layers across GPUs and CPU.

Why is my text generation output repetitive?

Repetition usually comes from greedy decoding on open-ended prompts. Increase repetition_penalty to 1.2-1.5, set no_repeat_ngram_size to 2-3, or switch to sampling with temperature around 0.7-0.8 and top_p of 0.95.

Do I need a Hugging Face token to use transformer models?

Public models work without authentication, but gated or private models require a token. Set the HUGGINGFACE_TOKEN environment variable or call huggingface_hub.login() before loading the model.