Hugging Face Transformers Tutorial

Welcome to the Hugging Face tutorial. The homepage card is titled Hugging Face; the content focuses on the Transformers library and the Hub (models, datasets, Spaces). It follows the official Transformers docs and huggingface/transformers—from first inference to fine-tuning and sharing.

Transformers is the model-definition framework for text, vision, audio, video, and multimodal models. The Hub hosts 1M+ checkpoints. Runnable examples use ungated small models so you are not blocked by Llama-style license walls.


Table of Contents

Basics

  1. Introduction — Hub, Transformers, the ecosystem, and how this course relates to PyTorch / Ollama
  2. Installation — venv, PyTorch, transformers, hf auth login; GPU optional
  3. Quick Start — Classification or generation with pipeline

Core APIs

  1. Pipeline — Task table; text, vision, and audio examples
  2. Tokenizers and ModelsAutoTokenizer, AutoModelForCausalLM, encode / decode
  3. Text Generationgenerate(), greedy vs sampling, max_new_tokens

Data and Training

  1. Datasetsload_dataset, map, DataCollator
  2. Fine-tuningTrainer + rotten_tomatoes, or LoRA on a small causal LM
  3. The Hub — Search, model cards, push_to_hub, Spaces teaser

Practice

  1. Practical Examples — Sentiment, a RAG-less chatbot, fine-tune outline
  2. Resources — Official docs and related courses on this site

Learning path

StageGoalChapters
Day 1Run inferenceIntro → Install → Quick Start → Pipeline
Days 2–3Weights and generationTokenizers and Models → Generation
Week 1Data and fine-tuningDatasets → Fine-tune → Hub
Week 2A small projectExamples → Resources

Models used here (all publicly downloadable)

UseModel / dataWhy
Text classificationdistilbert/distilbert-base-uncased + rotten_tomatoesSmall, ungated, ideal for Trainer
Off-the-shelf sentimentdistilbert/distilbert-base-uncased-finetuned-sst-2-englishCommon official pipeline example
Generationdistilbert/distilgpt2 or Qwen/Qwen2.5-0.5B-InstructQwen is stronger in Chinese; Qwen / DeepSeek are CN-friendly
Speech recognitionopenai/whisper-tinyASR you can try on CPU
  • Tensors and training loops: start with the PyTorch tutorial, then return for Trainer / generate().
  • Local chat only: the Ollama tutorial is easier; this course is for research, fine-tuning, and custom pipelines.
  • Coding agents: Hugging Face Skills (SKILL.md) can drive Hub operations—not the main path here.

Prerequisites

  • Python 3.10+ (functions, virtual environments)
  • The idea of pretrain → fine-tune → infer; you do not need to implement Transformer blocks
  • A GPU helps; classification and tiny generation work on CPU

Study tips

  1. Follow the chapter order; every page has runnable code
  2. First downloads fill the Hub cache—leave disk space
  3. If you hit a gated repo, switch to the ungated IDs listed above
  4. Read the model card (license, VRAM) before fine-tuning
  5. Coding agents can use Hugging Face Skills—run a Pipeline yourself first

Next steps

评论