Last Updated: November 21, 2025
Hugging Face
Transformers and model hub
Core Libraries
| Item | Description |
|---|---|
transformers
|
Pre-trained models |
datasets
|
Dataset library |
tokenizers
|
Fast tokenization |
accelerate
|
Multi-GPU training |
Hub
|
Model and dataset repository |
Spaces
|
ML app hosting |
Using Pre-trained Models
from transformers import pipeline
# Text generation
generator = pipeline('text-generation', model='gpt2')
result = generator("Once upon a time", max_length=50)
# Sentiment analysis
classifier = pipeline('sentiment-analysis')
result = classifier("I love this product!")
# Question answering
qa = pipeline('question-answering')
result = qa(question="What is AI?", context="AI stands for...")
# Translation
translator = pipeline('translation_en_to_fr')
result = translator("Hello, how are you?")
Fine-tuning
from transformers import AutoModelForSequenceClassification, AutoTokenizer, Trainer
model = AutoModelForSequenceClassification.from_pretrained("bert-base-uncased", num_labels=2)
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
trainer = Trainer(
model=model,
args=training_args,
train_dataset=train_dataset,
eval_dataset=eval_dataset
)
trainer.train()
Best Practices
- Use pipelines for quick prototyping
- Fine-tune on your specific task
- Use datasets library for data loading
- Share models on Hugging Face Hub
💡 Pro Tips
Quick Reference
Hugging Face Hub has 100k+ pre-trained models