liveBook · Manning

What you will learn in Learn Generative AI with PyTorch

by Mark Liu

Chapter by chapter

Chapter 1: What is generative AI and why PyTorch?

1.1 Introducing generative AI and PyTorch · 1.1.1 What is generative AI? · 1.1.2 The Python programming language · 1.1.3 Using PyTorch as our AI framework · 1.2 GANs · 1.2.1 A high-level overview of GANs · 1.2.2 An illustrating example: Generating anime faces · 1.2.3 Why should you care about GANs? · 1.3 Transformers · 1.3.1 The attention mechanism · 1.3.2 The Transformer architecture · 1.3.3 Multimodal Transformers and pretrained LLMs · 1.4 Why build generative models from scratch? · 1.5 Summary

What you learn in chapter 1 →

Chapter 2: Deep learning with PyTorch

2.1 Data types in PyTorch · 2.1.1 Creating PyTorch tensors · 2.1.2 Index and slice PyTorch tensors · 2.1.3 PyTorch tensor shapes · 2.1.4 Mathematical operations on PyTorch tensors · 2.2 An end-to-end deep learning project with PyTorch · 2.2.1 Deep learning in PyTorch: A high-level overview · 2.2.2 Preprocessing data · 2.3 Binary classification · 2.3.1 Creating batches · 2.3.2 Building and training a binary classification model · 2.3.3 Testing the binary classification model · 2.4 Multicategory classification · 2.4.1 Validation set and early stopping · 2.4.2 Building and training a multicategory classification model · 2.5 Summary

What you learn in chapter 2 →

Chapter 3: Generative adversarial networks: Shape and number generation

3.1 Steps involved in training GANs · 3.2 Preparing training data · 3.2.1 A training dataset that forms an exponential growth curve · 3.2.2 Preparing the training dataset · 3.3 Creating GANs · 3.3.1 The discriminator network · 3.3.2 The generator network · 3.3.3 Loss functions, optimizers, and early stopping · 3.4 Training and using GANs for shape generation · 3.4.1 The training of GANs · 3.4.2 Saving and using the trained generator · 3.5 Generating numbers with patterns · 3.5.1 What are one-hot variables? · 3.5.2 GANs to generate numbers with patterns · 3.5.3 Training the GANs to generate numbers with patterns · 3.5.4 Saving and using the trained model · 3.6 Summary

What you learn in chapter 3 →

Chapter 4: Image generation with generative adversarial networks

4.1 GANs to generate grayscale images of clothing items · 4.1.1 Training samples and the discriminator · 4.1.2 A generator to create grayscale images · 4.1.3 Training GANs to generate images of clothing items · 4.2 Convolutional layers · 4.2.1 How do convolutional operations work? · 4.2.2 How do stride and padding affect convolutional operations? · 4.3 Transposed convolution and batch normalization · 4.3.1 How do transposed convolutional layers work? · 4.3.2 Batch normalization · 4.4 Color images of anime faces · 4.4.1 Downloading anime faces · 4.4.2 Channels-first color images in PyTorch · 4.5 Deep convolutional GAN · 4.5.1 Building a DCGAN · 4.5.2 Training and using DCGAN · 4.6 Summary

What you learn in chapter 4 →

Chapter 5: Selecting characteristics in generated images

5.1 The eyeglasses dataset · 5.1.1 Downloading the eyeglasses dataset · 5.1.2 Visualizing images in the eyeglasses dataset · 5.2 cGAN and Wasserstein distance · 5.2.1 WGAN with gradient penalty · 5.2.2 cGANs · 5.3 Create a cGAN · 5.3.1 A critic in cGAN · 5.3.2 A generator in cGAN · 5.3.3 Weight initialization and the gradient penalty function · 5.4 Training the cGAN · 5.4.1 Adding labels to inputs · 5.4.2 Training the cGAN · 5.5 Selecting characteristics in generated images · 5.5.1 Selecting images with or without eyeglasses · 5.5.2 Vector arithmetic in latent space · 5.5.3 Selecting two characteristics simultaneously · 5.6 Summary

What you learn in chapter 5 →

Chapter 6: CycleGAN: Converting blond hair to black hair

6.1 CycleGAN and cycle consistency loss · 6.1.1 What is CycleGAN? · 6.1.2 Cycle consistency loss · 6.2 The celebrity faces dataset · 6.2.1 Downloading the celebrity faces dataset · 6.2.2 Process the black and blond hair image data · 6.3 Building a CycleGAN model · 6.3.1 Creating two discriminators · 6.3.2 Creating two generators · 6.4 Using CycleGAN to translate between black and blond hair · 6.4.1 Training a CycleGAN to translate between black and blond hair · 6.4.2 Round-trip conversions of black hair images and blond hair images · 6.5 Summary

What you learn in chapter 6 →

Chapter 7: Image generation with variational autoencoders

7.1 An overview of AEs · 7.1.1 What is an AE? · 7.1.2 Steps in building and training an AE · 7.2 Building and training an AE to generate digits · 7.2.1 Gathering handwritten digits · 7.2.2 Building and training an AE · 7.2.3 Saving and using the trained AE · 7.3 What are VAEs? · 7.3.1 Differences between AEs and VAEs · 7.3.2 The blueprint to train a VAE to generate human face images · 7.4 A VAE to generate human face images · 7.4.1 Building a VAE · 7.4.2 Training the VAE · 7.4.3 Generating images with the trained VAE · 7.4.4 Encoding arithmetic with the trained VAE · 7.5 Summary

What you learn in chapter 7 →

Chapter 8: Text generation with recurrent neural networks

8.1 Introduction to RNNs · 8.1.1 Challenges in generating text · 8.1.2 How do RNNs work? · 8.1.3 Steps in training a LSTM model · 8.2 Fundamentals of NLP · 8.2.1 Different tokenization methods · 8.2.2 Word embedding · 8.3 Preparing data to train the LSTM model · 8.3.1 Downloading and cleaning up the text · 8.3.2 Creating batches of training data · 8.4 Building and training the LSTM model · 8.4.1 Building an LSTM model · 8.4.2 Training the LSTM model · 8.5 Generating text with the trained LSTM model · 8.5.1 Generating text by predicting the next token · 8.5.2 Temperature and top-K sampling in text generation · 8.6 Summary

What you learn in chapter 8 →

Chapter 9: A line-by-line implementation of attention and Transformer

9.1 Introduction to attention and Transformer · 9.1.1 The attention mechanism · 9.1.2 The Transformer architecture · 9.1.3 Different types of Transformers · 9.2 Building an encoder · 9.2.1 The attention mechanism · 9.2.2 Creating an encoder · 9.3 Building an encoder-decoder Transformer · 9.3.1 Creating a decoder layer · 9.3.2 Creating an encoder-decoder Transformer · 9.4 Putting all the pieces together · 9.4.1 Defining a generator · 9.4.2 Creating a model to translate between two languages · 9.5 Summary

What you learn in chapter 9 →

Chapter 10: Training a Transformer to translate English to French

10.1 Subword tokenization · 10.1.1 Tokenizing English and French phrases · 10.1.2 Sequence padding and batch creation · 10.2 Word embedding and positional encoding · 10.2.1 Word embedding · 10.2.2 Positional encoding · 10.3 Training the Transformer for English-to-French translation · 10.3.1 Loss function and the optimizer · 10.3.2 The training loop · 10.4 Translating English to French with the trained model · 10.5 Summary

What you learn in chapter 10 →

Chapter 11: Building a generative pretrained Transformer from scratch

11.1 GPT-2 architecture and causal self-attention · 11.1.1 The architecture of GPT-2 · 11.1.2 Word embedding and positional encoding in GPT-2 · 11.1.3 Causal self-attention in GPT-2 · 11.2 Building GPT-2XL from scratch · 11.2.1 BPE tokenization · 11.2.2 The Gaussian error linear unit activation function · 11.2.3 Causal self-attention · 11.2.4 Constructing the GPT-2XL model · 11.3 Loading up pretrained weights and generating text · 11.3.1 Loading up pretrained parameters in GPT-2XL · 11.3.2 Defining a generate() function to produce text · 11.3.3 Text generation with GPT-2XL · 11.4 Summary

What you learn in chapter 11 →

Chapter 12: Training a Transformer to generate text

12.1 Building and training a GPT from scratch · 12.1.1 The architecture of a GPT to generate text · 12.1.2 The training process of the GPT model to generate text · 12.2 Tokenizing text of Hemingway novels · 12.2.1 Tokenizing the text · 12.2.2 Creating batches for training · 12.3 Building a GPT to generate text · 12.3.1 Model hyperparameters · 12.3.2 Modeling the causal self-attention mechanism · 12.3.3 Building the GPT model · 12.4 Training the GPT model to generate text · 12.4.1 Training the GPT model · 12.4.2 A function to generate text · 12.4.3 Text generation with different versions of the trained model · 12.5 Summary

What you learn in chapter 12 →

Chapter 13: Music generation with MuseGAN

13.1 Digital music representation · 13.1.1 Musical notes, octave, and pitch · 13.1.2 An introduction to multitrack music · 13.1.3 Digitally represent music: Piano rolls · 13.2 A blueprint for music generation · 13.2.1 Constructing music with chords, style, melody, and groove · 13.2.2 A blueprint to train a MuseGAN · 13.3 Preparing the training data for MuseGAN · 13.3.1 Downloading the training data · 13.3.2 Converting multidimensional objects to music pieces · 13.4 Building a MuseGAN · 13.4.1 A critic in MuseGAN · 13.4.2 A generator in MuseGAN · 13.4.3 Optimizers and the loss function · 13.5 Training the MuseGAN to generate music · 13.5.1 Training the MuseGAN · 13.5.2 Generating music with the trained MuseGAN · 13.6 Summary

What you learn in chapter 13 →

Chapter 14: Building and training a music Transformer

14.1 Introduction to the music Transformer · 14.1.1 Performance-based music representation · 14.1.2 The music Transformer architecture · 14.1.3 Training the music Transformer · 14.2 Tokenizing music pieces · 14.2.1 Downloading training data · 14.2.2 Tokenizing MIDI files · 14.2.3 Preparing the training data · 14.3 Building a GPT to generate music · 14.3.1 Hyperparameters in the music Transformer · 14.3.2 Building a music Transformer · 14.4 Training and using the music Transformer · 14.4.1 Training the music Transformer · 14.4.2 Music generation with the trained Transformer · 14.5 Summary

What you learn in chapter 14 →

Chapter 15: Diffusion models and text-to-image Transformers

15.1 Introduction to denoising diffusion models · 15.1.1 The forward diffusion process · 15.1.2 Using the U-Net model to denoise images · 15.1.3 A blueprint to train the denoising U-Net model · 15.2 Preparing the training data · 15.2.1 Flower images as the training data · 15.2.2 Visualizing the forward diffusion process · 15.3 Building a denoising U-Net model · 15.3.1 The attention mechanism in the denoising U-Net model · 15.3.2 The denoising U-Net model · 15.4 Training and using the denoising U-Net model · 15.4.1 Training the denoising U-Net model · 15.4.2 Using the trained model to generate flower images · 15.5 Text-to-image Transformers · 15.5.1 CLIP: A multimodal Transformer · 15.5.2 Text-to-image generation with DALL-E 2 · 15.6 Summary

What you learn in chapter 15 →

Chapter 16: Pretrained large language models and the LangChain library

16.1 Content generation with the OpenAI API · 16.1.1 Text generation tasks with OpenAI API · 16.1.2 Code generation with OpenAI API · 16.1.3 Image generation with OpenAI DALL-E 2 · 16.1.4 Speech generation with OpenAI API · 16.2 Introduction to LangChain · 16.2.1 The need for the LangChain library · 16.2.2 Using the OpenAI API in LangChain · 16.2.3 Zero-shot, one-shot, and few-shot prompting · 16.3 A zero-shot know-it-all agent in LangChain · 16.3.1 Applying for a Wolfram Alpha API Key · 16.3.2 Creating an agent in LangChain · 16.3.3 Adding tools by using OpenAI GPTs · 16.3.4 Adding tools to generate code and images · 16.4 Limitations and ethical concerns of LLMs · 16.4.1 Limitations of LLMs · 16.4.2 Ethical concerns for LLMs · 16.5 Summary

What you learn in chapter 16 →

Concepts explained in this book

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.