Hugging Face Course

repositoryยทmainยทIndexed 26 days ago

https://github.com/huggingface/course

Educational resources for the Hugging Face course, including guides on using the ๐Ÿค— Transformers library, the pipeline() function for NLP, image, and audio tasks, and Transformer architectures (Encoder-only, Decoder-only, and Encoder-decoder). The repository also provides utility scripts for managing and translating course video subtitles and instructions for setting up environments in Google Colab or Python virtual environments.

Tokens
127K
Snippets
315
Records
592
Agent score
87%

What's inside huggingface-course

  1. Overview of Transformer Model History

    main

    The Transformer architecture was introduced in June 2017, primarily focused on translation tasks. Since then, several influential model families have emerged, which can be broadly categorized into three types:

    • GPT-style (also known as Auto-regressive Transformer models)
    • BERT-style (also known as Auto-encoding Transformer models)
    • T5-style (also known as Sequence-to-Sequence Transformer models)

    Key milestones in Transformer evolution include:

    • GPT (June 2018): First pre-trained Transformer for various NLP tasks.
    • BERT (October 2018): Designed for creating better sentence representations.
    • GPT-2 (February 2019): An improved, larger version of GPT.
    • T5 (October 2019): A multi-task centric implementation of the sequence-to-sequence architecture.
    • GPT-3 (May 2020): Capable of zero-shot learning without fine-tuning.
    • InstructGPT (January 2022): Optimized to follow instructions.
    • Llama (January 2023): Large language model capable of text generation in various languages.
    • Mistral (March 2023): Uses group-query attention and sliding window attention.
    • Gemma 2 (May 2024): A family of lightweight, state-of-the-art open models using interleaved local-global attention.
    • SmolLM2 (November 2024): State-of-the-art small language models (135M to 1.7B parameters) optimized for mobile and edge devices.
  2. Overview of the Hugging Face Hub

    main

    The Hugging Face Hub is a central platform for discovering, using, and contributing to state-of-the-art models and datasets.

    Key features include:

    • Model Hosting: Supports various frameworks including ๐Ÿค— Transformers, Flair, AllenNLP, Asteroid, pyannote, and timm.
    • Git-based Versioning: Each model is hosted as a Git repository, ensuring versioning and reproducibility.
    • Inference API: Sharing a model on the Hub automatically deploys a hosted Inference API, allowing users to test models directly on their model pages using custom inputs and widgets.
    • Accessibility: Public models are free to use and share. Private model sharing is available via paid plans.
  3. Overview of Translation as a Sequence-to-Sequence Task

    main

    Translation is a sequence-to-sequence (seq2seq) task where the goal is to transform one sequence of tokens into another. This approach can be adapted to other tasks such as:

    • Style transfer: Translating text from one style to another (e.g., formal to casual).
    • Generative question answering: Generating answers to questions based on a provided context.

    For translation, you can either train a model from scratch using a large multilingual corpus or fine-tune an existing pretrained model. Common pretrained models for fine-tuning include multilingual models like mT5 or mBART, or specialized translation models like Marian.

  4. Introduction to Gradio Blocks

    main

    Gradio provides two main APIs for building machine learning demos:

    • Interface: A high-level API for quickly creating demos by providing a list of inputs and outputs.
    • Blocks: A low-level API that offers full control over data flows, layout, and complex multi-step application logic.

    Use Blocks when you need to group demos into tabs, customize layouts, create multi-step interfaces, or dynamically change component properties based on user input.

  5. Overview of the ๐Ÿค— Transformers library

    main

    The ๐Ÿค— Transformers library provides a unified API for loading, training, and saving Transformer models. It is designed for ease of use, flexibility, and simplicity. Key characteristics include:

    • Ease of use: Inference can be performed with minimal code (typically two lines).
    • Flexibility: Models are implemented as standard PyTorch nn.Module classes, allowing them to be used within existing ML workflows.
    • Simplicity: The library follows an "All in one file" concept where a model's forward pass is defined in a single file, making the code easy to understand and modify without relying on complex shared abstractions.
  6. Overview of Extractive Question Answering

    main

    Extractive question answering involves posing questions about a document and identifying the answers as specific spans of text within that document.

    Key Concepts:

    • Extractive QA: Identifying text spans as answers. Typically performed using encoder-only models like BERT.
    • Generative QA: Synthesizing answers to open-ended questions (e.g., "Why is the sky blue?"). This is typically performed using encoder-decoder models like T5 or BART.
    • SQuAD Dataset: A common dataset used for training extractive QA models, consisting of questions posed on Wikipedia articles.
  7. Overview of the Hugging Face Course

    main

    This course teaches how to use the Hugging Face ecosystem to work with Large Language Models (LLMs) and Natural Language Processing (NLP). You will learn to use core libraries including:

    • ๐Ÿค— Transformers: For working with transformer-based models.
    • ๐Ÿค— Datasets: For accessing and managing datasets.
    • ๐Ÿค— Tokenizers: For text preprocessing.
    • ๐Ÿค— Accelerate: For efficient model training and inference.
    • Hugging Face Hub: For discovering and sharing models and datasets.

    The course also covers external AI community tools and libraries.

  8. Introduction to Text Summarization with Transformers

    main
    Text summarization involves using Transformer models to condense long documents into concise summaries. This task requires the model to understand long passages and generate coherent text that captures main topics. While many fine-tuned models on the Hugging Face Hub are English-only, this section demonstrates how to train a bilingual model (e.g., English and Spanish) using models like mt5 to summarize multilingual content such as customer reviews.
  9. Overview of Open R1 and Reinforcement Learning for LLMs

    main

    Open R1 is a community project aimed at enabling Large Language Models (LLMs) to reason through complex problems using Reinforcement Learning (RL). The project focuses on training models to generate structured 'thoughts' alongside their final answers. This allows users to separate the reasoning process from the final output.

    Models trained with this approach typically use a specific format to encapsulate reasoning:

    <think>Reasoning process goes here</think>
    Final answer goes here
  10. Overview of Transformer architectures and tasks

    main

    Transformer models solve various tasks using three primary architectural variants: encoders, decoders, or encoder-decoder structures. The specific task is determined by how input data is prepared, which architecture variant is used, and how the output is processed.

    Common task-to-model mappings include:

    • Audio Classification & Automatic Speech Recognition (ASR): Wav2Vec2
    • Image Classification: Vision Transformer (ViT) and ConvNeXT
    • Object Detection: DETR
    • Image Segmentation: Mask2Former
    • Depth Estimation: GLPN
    • NLP (Encoder-based): BERT for tasks like text classification, token classification, and question answering.
    • NLP (Decoder-based): GPT2 for text generation.
    • NLP (Encoder-Decoder): BART for summarization and translation.
  11. Overview of fine-tuning models in Chapter 3

    main

    Chapter 3 focuses on fine-tuning pretrained models for specific tasks using PyTorch. It covers the following core competencies:

    • Dataset Preparation: Using the ๐Ÿค— Datasets library to prepare large datasets from the Hub.
    • High-level Training: Using the Trainer API for fine-tuning with modern best practices.
    • Custom Training: Implementing custom training loops with optimization techniques.
    • Distributed Training: Leveraging the ๐Ÿค— Accelerate library to run distributed training on various hardware setups.
    • Performance Optimization: Applying current fine-tuning best practices.

    By the end of the chapter, you will have fine-tuned a BERT model for text classification.

  12. Understand common NLP tasks

    main

    Natural Language Processing (NLP) involves understanding human language by analyzing both individual words and their context. Common NLP tasks include:

    • Classifying whole sentences: Sentiment analysis, spam detection, grammar checking, or logical relationship detection.
    • Classifying each word in a sentence: Part-of-speech tagging (noun, verb, etc.) or Named Entity Recognition (NER) (identifying persons, locations, organizations).
    • Generating text content: Prompt completion or masked word filling.
    • Extracting an answer from a text: Question answering based on a provided context.
    • Generating a new sentence from an input text: Machine translation or text summarization.
    • Multimodal NLP: Speech recognition (audio transcripts) and image captioning (computer vision).