transformers

This skill should be used when working with pre-trained transformer models for natural language processing, computer vision, audio, or multimodal tasks. Use for text generation, classification, question answering, translation, summarization, image classification, object detection, speech recognition, and fine-tuning models on custom datasets.

Install

Hot:9

Download and extract to your skills directory

Copy command and send to OpenClaw for auto-install:

Download and install this skill https://openskills.cc/api/download?slug=k-dense-ai-scientific-skills-transformers&locale=en&source=copy

Transformers Skill - Hugging Face Pretrained Model Development Guide

Skill Overview


The Transformers skill provides a complete workflow for loading Hugging Face Transformers pretrained models, performing inference, and fine-tuning on custom data, covering NLP, computer vision, speech, and multimodal tasks.

Applicable Scenarios

1. Natural Language Processing Projects


Suitable for common NLP tasks such as text generation, sentiment analysis, named entity recognition, machine translation, text summarization, and question answering. The Pipeline API enables rapid prototyping, and the Trainer API allows fine-tuning on custom datasets to achieve better domain adaptation.

2. Computer Vision and Audio Processing


Supports tasks like image classification, object detection, audio classification, and speech recognition. With dependencies such as timm, pillow, or librosa, it can handle visual and audio data and enable multimodal AI application development.

3. Model Research and Fine-tuning


Appropriate for scenarios that require in-depth model architecture study, custom loading configurations, device placement management, and precision control. Provides complete tokenization, text generation strategies (greedy, beam search, sampling), and distributed training support, meeting needs from quick experiments to production deployment.

Core Features

1. Pipeline for Fast Inference


Offers out-of-the-box inference interfaces, supporting dozens of tasks including text generation, classification, NER, QA, summarization, translation, image classification, object detection, and audio classification. No need to manually configure preprocessing and postprocessing, making it ideal for rapid prototyping and simple inference tasks.

2. Model Loading and Management


Supports automatic loading with AutoModel and AutoTokenizer, and provides advanced features such as device automatic mapping (device_map="auto"), precision control (FP16/BF16), and model checkpoint saving and restoration. Suitable for scenarios that require fine-grained control over model initialization and deployment.

3. Training and Fine-tuning


Integrates the Trainer API and supports automatic mixed precision training, distributed training, logging, and evaluation. Efficiently fine-tune pretrained models like BERT, GPT, and T5 on custom datasets to achieve task-specific adaptation and inject domain knowledge.

Frequently Asked Questions

How to get started with Transformers?


Install the core dependencies with pip: uv pip install torch transformers datasets evaluate accelerate, then get started quickly with the Pipeline API: from transformers import pipeline; classifier = pipeline("text-classification"). Some models require a Hugging Face Hub token, which can be set via login() or an environment variable.

What's the difference between Pipeline and manually loading models?


Pipeline is suited for rapid prototyping and standard inference tasks, automatically handling preprocessing and postprocessing; manually loading a model is better for scenarios that require custom configurations, in-depth model study, or performance optimizations. Use Pipeline for simple inference and manual loading when you need fine-grained control or special handling.

How to fine-tune a model on your own dataset?


Configure training parameters (epochs, batch size, learning rate, etc.) using the Trainer API, prepare the training dataset, then call trainer.train() to start training. Transformers supports automatic mixed precision, distributed training, and progress logging to efficiently complete model fine-tuning. See references/training.md for the full workflow.