liveBook · Manning

Hugging Face

As explained in Deep Learning with PyTorch, Second Edition

A repository service for discovering, sharing, and exchanging pretrained models and weights.

Hugging Face is a prominent model repository and high-level deep-learning wrapper. It gives practitioners a practical way to find pretrained transformer and diffusion models instead of building every model from scratch. section 1.4.1 section 2.3

Its role becomes clearer through three connected ideas:

  • A model zoo collects pretrained models behind more consistent access patterns than historically available. section 2.3
  • The transformers package provides access to transformer models, including GPT-2 for text generation. section 2.3
  • Transformer workflows connect models with tokenizers, which convert raw text into numerical inputs. section 9.12

Generate text with GPT-2

A pipeline can download a pretrained GPT-2 model and complete a short prompt: `from transformers import pipeline\ngenerator = pipeline('text-generation', model='gpt2')\ngenerator('AI models are so smart they can replace my', max_length=10)`. The generated continuation uses learned language patterns, context, and a sampling strategy. section 2.3

from transformers import pipeline
generator = pipeline('text-generation', model='gpt2')   #1
generator("AI models are so smart they can replace my",
 max_length=10)   #2

# [{'generated_text': 'AI models are so smart they can replace my brain with a totally different one.'}]

Inspect the complete pipeline listing and its generated output. section 2.3

How Deep Learning with PyTorch, Second Edition covers it

How deep it goes
Defines model zoos and demonstrates one text-generation pipeline, while deferring transformer mechanics to a later treatment.
Examples
Uses a GPT-2 pipeline to complete a nine-word prompt and produce a generated continuation.
What it assumes
Assumes basic deep-learning context but introduces model zoos and pretrained-model access through a concrete example.
What you can do after
Apply pretrained text-generation models through the transformers pipeline interface.
How it connects
Connects pretrained models with transformers, diffusion models, tokenizers, text generation, and PyTorch.

Also explained in

Compare how 5 books explain Hugging Face →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with PyTorch, Second Edition. The section links point to the parts of the book it draws on.