Book description
Learn how to use and implement transformers with Hugging Face and OpenAI (and others) by reading, running examples, investigating issues, asking the author questions, and interacting with our AI/ML community
Key Features
- Pretrain a BERT-based model from scratch using Hugging Face
- Fine-tune powerful transformer models, including OpenAI's GPT-3, to learn the logic of your data
- Perform root cause analysis on hard NLP problems
Book Description
Transformers are...well...transforming the world of AI. There are many platforms and models out there, but which ones best suit your needs?
Transformers for Natural Language Processing, 2nd Edition, guides you through the world of transformers, highlighting the strengths of different models and platforms, while teaching you the problem-solving skills you need to tackle model weaknesses.
You'll use Hugging Face to pretrain a RoBERTa model from scratch, from building the dataset to defining the data collator to training the model.
If you're looking to fine-tune a pretrained model, including GPT-3, then Transformers for Natural Language Processing, 2nd Edition, shows you how with step-by-step guides.
The book investigates machine translations, speech-to-text, text-to-speech, question-answering, and many more NLP tasks. It provides techniques to solve hard language problems and may even help with fake news anxiety (read chapter 13 for more details).
You'll see how cutting-edge platforms, such as OpenAI, have taken transformers beyond language into computer vision tasks and code creation using Codex.
By the end of this book, you'll know how transformers work and how to implement them and resolve issues like an AI detective!
What you will learn
- Find out how ViT and CLIP label images (including blurry ones!) and create images from a sentence using DALL-E
- Discover new techniques to investigate complex language problems
- Compare and contrast the results of GPT-3 against T5, GPT-2, and BERT-based transformers
- Carry out sentiment analysis, text summarization, casual speech analysis, machine translations, and more using TensorFlow, PyTorch, and GPT-3
- Measure the productivity of key transformers to define their scope, potential, and limits in production
Who this book is for
If you want to learn about and apply transformers to your natural language (and image) data, this book is for you.
You'll need a good understanding of Python and deep learning and a basic understanding of NLP to benefit most from this book. Many platforms covered in this book provide interactive user interfaces, which allow readers with a general interest in NLP and AI to follow several chapters. And, don't worry if you get stuck or have questions; this book gives you direct access to our AI/ML community and author, Denis Rothman. So, he'll be there to guide you on your transformers journey!
Publisher resources
Table of contents
- Preface
- What are Transformers?
- Getting Started with the Architecture of the Transformer Model
-
Fine-Tuning BERT Models
- The architecture of BERT
-
Fine-tuning BERT
- Hardware constraints
- Installing the Hugging Face PyTorch interface for BERT
- Importing the modules
- Specifying CUDA as the device for torch
- Loading the dataset
- Creating sentences, label lists, and adding BERT tokens
- Activating the BERT tokenizer
- Processing the data
- Creating attention masks
- Splitting the data into training and validation sets
- Converting all the data into torch tensors
- Selecting a batch size and creating an iterator
- BERT model configuration
- Loading the Hugging Face BERT uncased base model
- Optimizer grouped parameters
- The hyperparameters for the training loop
- The training loop
- Training evaluation
- Predicting and evaluating using the holdout dataset
- Evaluating using the Matthews Correlation Coefficient
- The scores of individual batches
- Matthews evaluation for the whole dataset
- Summary
- Questions
- References
-
Pretraining a RoBERTa Model from Scratch
- Training a tokenizer and pretraining a transformer
-
Building KantaiBERT from scratch
- Step 1: Loading the dataset
- Step 2: Installing Hugging Face transformers
- Step 3: Training a tokenizer
- Step 4: Saving the files to disk
- Step 5: Loading the trained tokenizer files
- Step 6: Checking resource constraints: GPU and CUDA
- Step 7: Defining the configuration of the model
- Step 8: Reloading the tokenizer in transformers
- Step 9: Initializing a model from scratch
- Step 10: Building the dataset
- Step 11: Defining a data collator
- Step 12: Initializing the trainer
- Step 13: Pretraining the model
- Step 14: Saving the final model (+tokenizer + config) to disk
- Step 15: Language modeling with FillMaskPipeline
- Next steps
- Summary
- Questions
- References
- Downstream NLP Tasks with Transformers
- Machine Translation with the Transformer
-
The Rise of Suprahuman Transformers with GPT-3 Engines
- Suprahuman NLP with GPT-3 transformer models
- The architecture of OpenAI GPT transformer models
- Generic text completion with GPT-2
- Training a custom GPT-2 language model
- Running OpenAI GPT-3 tasks
- Comparing the output of GPT-2 and GPT-3
- Fine-tuning GPT-3
- The role of an Industry 4.0 AI specialist
- Summary
- Questions
- References
- Applying Transformers to Legal and Financial Documents for AI Text Summarization
- Matching Tokenizers and Datasets
- Semantic Role Labeling with BERT-Based Transformers
- Let Your Data Do the Talking: Story, Questions, and Answers
- Detecting Customer Emotions to Make Predictions
- Analyzing Fake News with Transformers
- Interpreting Black Box Transformer Models
- From NLP to Task-Agnostic Transformer Models
- The Emergence of Transformer-Driven Copilots
- Appendix I â Terminology of Transformer Models
- Appendix II â Hardware Constraints for Transformer Models
-
Appendix III â Generic Text Completion with GPT-2
- Step 1: Activating the GPU
- Step 2: Cloning the OpenAI GPT-2 repository
- Step 3: Installing the requirements
- Step 4: Checking the version of TensorFlow
- Step 5: Downloading the 345M-parameter GPT-2 model
- Steps 6-7: Intermediate instructions
- Steps 7b-8: Importing and defining the model
- Step 9: Interacting with GPT-2
- References
-
Appendix IV â Custom Text Completion with GPT-2
-
Training a GPT-2 language model
- Step 1: Prerequisites
- Steps 2 to 6: Initial steps of the training process
- Step 7: The N Shepperd training files
- Step 8: Encoding the dataset
- Step 9: Training a GPT-2 model
- Step 10: Creating a training model directory
- Step 11: Generating unconditional samples
- Step 12: Interactive context and completion examples
- References
-
Training a GPT-2 language model
-
Appendix V â Answers to the Questions
- Chapter 1, What are Transformers?
- Chapter 2, Getting Started with the Architecture of the Transformer Model
- Chapter 3, Fine-Tuning BERT Models
- Chapter 4, Pretraining a RoBERTa Model from Scratch
- Chapter 5, Downstream NLP Tasks with Transformers
- Chapter 6, Machine Translation with the Transformer
- Chapter 7, The Rise of Suprahuman Transformers with GPT-3 Engines
- Chapter 8, Applying Transformers to Legal and Financial Documents for AI Text Summarization
- Chapter 9, Matching Tokenizers and Datasets
- Chapter 10, Semantic Role Labeling with BERT-Based Transformers
- Chapter 11, Let Your Data Do the Talking: Story, Questions, and Answers
- Chapter 12, Detecting Customer Emotions to Make Predictions
- Chapter 13, Analyzing Fake News with Transformers
- Chapter 14, Interpreting Black Box Transformer Models
- Chapter 15, From NLP to Task-Agnostic Transformer Models
- Chapter 16, The Emergence of Transformer-Driven Copilots
- Other Books You May Enjoy
- Index
Product information
- Title: Transformers for Natural Language Processing - Second Edition
- Author(s):
- Release date: March 2022
- Publisher(s): Packt Publishing
- ISBN: 9781803247335
You might also like
book
Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow, 3rd Edition
Through a recent series of breakthroughs, deep learning has boosted the entire field of machine learning. …
book
Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow, 2nd Edition
Through a series of recent breakthroughs, deep learning has boosted the entire field of machine learning. …
book
Reinforcement Learning and Stochastic Optimization
REINFORCEMENT LEARNING AND STOCHASTIC OPTIMIZATION Clearing the jungle of stochastic optimization Sequential decision problems, which consist …
book
Python Challenges: 100 Proven Programming Tasks Designed to Prepare You for Anything
Augment your knowledge of Python with this entertaining learning guide, which features 100 exercises and programming …