liveBook · Manning

Chapter 7: Deep transfer learning for NLP with the transformer and GPT

What you will learn in chapter 7 of Transfer Learning for Natural Language Processing

This introduction contrasts transformer attention and scaling with earlier NLP architectures and summarizes GPT, BERT, and multilingual BERT.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This introduction contrasts transformer attention and scaling with earlier NLP architectures and summarizes GPT, BERT, and multilingual BERT.

Key terms: transformer, attention, recurrent, convolutional, parallel computing, GPT, causal modeling objective, BERT, masked modeling objective, next sentence prediction

7.1 The transformer

This section introduces the motivation and high-level structure of the transformer encoder-decoder architecture.

Key terms: self-attention, recurrence, parallelization, encoder, decoder, embeddings, positional encodings, encoder-decoder attention, feedforward neural network, masked

7.1.1 An introduction to the transformers library and attention visualization

This section introduces pretrained BERT tokenization and uses attention visualization to explore its encoder layers.

Key terms: transformers, tokenizer, vocabulary, indices, special tokens, [CLS], [SEP], subword, bertviz, self-attention

7.1.2 Self-attention

This section explains how transformer self-attention detects contextual relationships, computes attention weights in parallel, and extends to multiple attention heads.

Key terms: self-attention, tokens, dependencies, context, query vector, key vector, value vector, input embedding, dot product, softmax

7.1.3 Residual connections, encoder-decoder attention, and positional encoding

This section briefly explains residual connections and normalization, encoder-decoder attention, and positional encoding in the transformer.

Key terms: residual connection, normalization layer, vanishing and/or exploding gradients, encoder-decoder attention, keys, values, queries, encoder stack, positional encoding, positional embeddings

7.1.4 Application of pretrained encoder-decoder to translation

This section uses a pretrained encoder-decoder model to translate English into Twi and examines its output and limitations as a low-resource translation baseline.

Key terms: MarianMTModel, encoder-decoder, Helsinki-NLP, tokenizer, JW300, parallel translated datasets, baseline, transfer learning, SentencePiece, WordPiece

7.2 The Generative Pretrained Transformer

This section introduces GPT’s semisupervised transfer-learning approach and contrasts its language-modeling objective with BERT’s.

Key terms: Generative Pretrained Transformer, semisupervised learning, unsupervised pretraining, self-supervised pretraining, supervised fine-tuning, causal modeling objective, CLM, masked language modeling, MLM, text generation

7.2.1 Architecture overview

This section explains GPT’s decoder-based architecture and how input transformations adapt it to different tasks.

Key terms: decoders, masked self-attention, encoder-decoder attention, causality, input transformation, textual entailment, premise, hypothesis, special delimiter token, question answering

7.2.2 Transformers pipelines introduction and application to text generation

This section introduces transformers pipelines and uses GPT-2 text generation to illustrate both the usefulness and limitations of generated continuations.

Key terms: pipelines, pretrained models, inference, transformers, GPT-2, pipeline, primed, maximum of 100 tokens, max_length, semantic coherence

7.2.3 Application to chatbots

This section applies pretrained DialoGPT to chatbot conversations and discusses its model interface and context-length trade-offs.

Key terms: DialoGPT, GPT, special tokens, fine-tuning, tokenizer, chat history, conversational contribution, pretrained DialoGPT model, GPT2LMHeadModel, GPT2Tokenizer

7.3 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 6: Deep transfer learning for NLP with recurrent neural networks Chapter 8: Deep transfer learning for NLP with BERT and multilingual BERT →

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.