Chapter 1: Understanding large language models
The introduction contrasts LLMs with earlier NLP models, clarifies what their apparent understanding means, and attributes their broader capabilities to transformer architectures and large-scale text training.
After this chapter you will be able to
- Broader Language Task Capabilities. Distinguish contemporary LLMs from earlier NLP models: earlier models often excelled at narrow tasks or simple patterns, while LLMs can perform a wider range of tasks requiring context-sensitive language processing and generation.
- Sources of LLM Success. Explain the two factors the introduction attributes LLM success to, and describe what large-scale training helps models capture.
- LLM purpose and scale. Describe an LLM as a deep neural network for understanding, generating, and responding to human-like text, and explain that “large” refers to both its parameter count and its training dataset.
- Next-word prediction rationale. Explain that training adjusts an LLM’s parameters to predict the next word in a sequence, and why this simple task helps it learn context, structure, and relationships in text.
- Manual features versus deep learning. Distinguish traditional machine learning’s manual feature extraction from deep learning’s lack of that requirement, using the spam example, and state that both approaches still need labels for that classification task.
- Text processing applications. Explain why LLMs are useful across many text-based tasks, and give examples such as translation, text generation, sentiment analysis, and summarization.
- Two stage LLM training. Describe the order and different purposes of pretraining and fine-tuning.
- Raw text pretraining. Explain how an LLM can be pretrained without externally supplied labels and what kind of model this produces.
- Fine tuning dataset types. Distinguish instruction fine-tuning from classification fine-tuning by the labeled examples each uses.
- Encoder and decoder roles. Trace how the original transformer uses an encoder and a decoder for translation: the encoder turns source text into contextual numerical representations, and the decoder uses those representations to generate target text.
- Self-attention and context. Explain that self-attention weighs the importance of words or tokens relative to one another, helping the model capture long-range dependencies and contextual relationships.
- BERT and GPT contrast. Distinguish BERT's encoder-based masked-word prediction and classification strengths from GPT's decoder-based focus on generating text.
- Training Data Scale and Diversity. Explain how the scale and diversity of pretraining text help LLMs perform across different language tasks.
- Pretrained Model Reuse. Explain why pretrained LLMs are called base or foundation models and why fine-tuning them can be more practical than pretraining anew.
- Self-supervised next-word training. Explain how GPT can use the next word in existing text as a training label, allowing it to learn from large unlabeled text datasets.
- Decoder-only autoregressive generation. Describe how GPT differs from the original transformer and how it generates coherent text one word at a time.
- Emergent translation capability. Explain why GPT’s ability to translate is called an emergent behavior despite its next-word pretraining task.
- Practical limits of pretraining. Explain why the book implements pretraining on a small dataset for educational purposes instead of pretraining a full-scale GPT-like model from scratch.
Section by section
Introduction
The introduction contrasts LLMs with earlier NLP models, clarifies what their apparent understanding means, and attributes their broader capabilities to transformer architectures and large-scale text training.
- Broader Language Task Capabilities: Distinguish contemporary LLMs from earlier NLP models: earlier models often excelled at narrow tasks or simple patterns, while LLMs can perform a wider range of tasks requiring context-sensitive language processing and generation.
Why it matters: This contrast explains why LLMs changed what language-processing systems can be used for. - Meaning of Model Understanding: Explain what it means here to say an LLM understands language, and distinguish that usage from human-like consciousness or comprehension.
Why it matters: This qualification keeps claims about LLM capabilities from being mistaken for claims about human-like minds. - Sources of LLM Success: Explain the two factors the introduction attributes LLM success to, and describe what large-scale training helps models capture.
Why it matters: These are the introduction's stated reasons LLMs can handle language more broadly than earlier approaches.
Key terms: LLMs, NLP, earlier NLP models, understand, contextually relevant, human-like consciousness, transformer architecture, vast amounts of data, linguistic nuances
1.1 What is an LLM?
This section defines LLMs, explains why they are called large and how next-word prediction relates to language learning, and places them within the broader fields of AI and deep learning.
- LLM purpose and scale: Describe an LLM as a deep neural network for understanding, generating, and responding to human-like text, and explain that “large” refers to both its parameter count and its training dataset.
Why it matters: This definition establishes what kind of model the rest of the book builds. - Next-word prediction rationale: Explain that training adjusts an LLM’s parameters to predict the next word in a sequence, and why this simple task helps it learn context, structure, and relationships in text.
Why it matters: It connects a simple training objective to the language patterns an LLM can learn. - Transformer selective attention: Describe the transformer as the architecture LLMs use and state that it can pay selective attention to different parts of an input when making predictions.
Why it matters: It identifies the architectural idea behind the model without requiring the later implementation details. - AI field relationships: Explain how LLMs fit within generative AI, deep learning, machine learning, and AI, including that machine learning learns from data rather than relying solely on explicitly programmed rules.
Why it matters: These relationships clarify that an LLM is a particular kind of AI model, not a synonym for all AI. - Manual features versus deep learning: Distinguish traditional machine learning’s manual feature extraction from deep learning’s lack of that requirement, using the spam example, and state that both approaches still need labels for that classification task.
Why it matters: The spam example makes the practical distinction between manually chosen features and deep learning concrete.
Key terms: LLM, deep neural network, parameters, text data, next-word prediction, context, transformer, selective attention, input, generative AI
1.2 Applications of LLMs
This section surveys how LLMs are used for text tasks, conversational assistance, and knowledge retrieval.
- Text processing applications: Explain why LLMs are useful across many text-based tasks, and give examples such as translation, text generation, sentiment analysis, and summarization.
Why it matters: These examples show what kinds of work the models built later in the book can support. - Conversational and retrieval uses: Describe how LLMs can serve users through chatbots or virtual assistants and help retrieve information from large collections of specialized text.
Why it matters: These uses illustrate how text-processing capabilities can make information easier for people to access.
Key terms: unstructured text data, machine translation, generation of novel texts, sentiment analysis, text summarization, chatbots, virtual assistants, knowledge retrieval
1.3 Stages of building and using LLMs
This section explains why someone might build a custom LLM and how pretraining on raw text leads to a base model that can be fine-tuned for specific tasks.
- Reasons for custom LLMs: Explain why building or using a custom LLM can be worthwhile, including both what developers learn and advantages a tailored model may offer.
Why it matters: These reasons explain why a team might choose a tailored model rather than rely on a general-purpose provider. - Two stage LLM training: Describe the order and different purposes of pretraining and fine-tuning.
Why it matters: This distinction provides the framework for the book's later training and fine-tuning work. - Raw text pretraining: Explain how an LLM can be pretrained without externally supplied labels and what kind of model this produces.
Why it matters: It explains why a large text collection can support initial training without people labeling each example. - Fine tuning dataset types: Distinguish instruction fine-tuning from classification fine-tuning by the labeled examples each uses.
Why it matters: The distinction identifies what sort of labeled data is needed for two common ways to specialize a pretrained model.
Key terms: custom-built LLMs, domain-specific datasets, data privacy, pretraining, pretrained model, fine-tuning, raw text, self-supervised learning, next word, base or foundation model
1.4 Introducing the transformer architecture
Introduces the transformer's encoder, decoder, and self-attention, then contrasts BERT and GPT and clarifies how transformers relate to LLMs.
- Encoder and decoder roles: Trace how the original transformer uses an encoder and a decoder for translation: the encoder turns source text into contextual numerical representations, and the decoder uses those representations to generate target text.
Why it matters: This distinction makes the original translation architecture and its later variants easier to compare. - Self-attention and context: Explain that self-attention weighs the importance of words or tokens relative to one another, helping the model capture long-range dependencies and contextual relationships.
Why it matters: It explains why self-attention is central to producing contextually relevant text. - BERT and GPT contrast: Distinguish BERT's encoder-based masked-word prediction and classification strengths from GPT's decoder-based focus on generating text.
Why it matters: The contrast shows how transformer variants serve different kinds of language tasks. - Zero-shot and few-shot tasks: Distinguish zero-shot performance on an unseen task without specific examples from few-shot performance using a small number of user-provided examples as input.
Why it matters: It shows that a text-completion model can respond to tasks beyond straightforward continuation. - Transformers versus LLMs: Explain why transformer and LLM are not interchangeable categories, even though this book uses LLM to mean GPT-like transformer-based LLMs.
Why it matters: It keeps the book's shorthand from becoming a false claim about every transformer or LLM.
Key terms: transformer architecture, encoder, decoder, vectors, self-attention mechanism, tokens, long-range dependencies, contextual relationships, BERT, GPT
1.5 Utilizing large datasets
This section explains why large, diverse text datasets matter for LLMs and why reusing pretrained models is more practical than pretraining from scratch.
- Training Data Scale and Diversity: Explain how the scale and diversity of pretraining text help LLMs perform across different language tasks.
Why it matters: It connects the breadth of an LLM’s training data to the range of tasks it can handle. - Dataset Token Counts: Describe what the section means by tokens and distinguish GPT-3’s listed dataset total from the amount used in training.
Why it matters: It helps you read the dataset example without mistaking available text for text actually used in training. - Pretrained Model Reuse: Explain why pretrained LLMs are called base or foundation models and why fine-tuning them can be more practical than pretraining anew.
Why it matters: It explains the practical value of starting with an existing model rather than paying the full cost of pretraining.
Key terms: pretraining, text corpora, scale, diversity, token, Number of Tokens, GPT-3, pretrained LLMs, base models, foundation models
1.6 A closer look at the GPT architecture
The section explains how GPT’s decoder-only architecture and next-word pretraining produce coherent text and can support tasks beyond text completion.
- Self-supervised next-word training: Explain how GPT can use the next word in existing text as a training label, allowing it to learn from large unlabeled text datasets.
Why it matters: It explains how a simple prediction task makes large-scale pretraining possible. - Decoder-only autoregressive generation: Describe how GPT differs from the original transformer and how it generates coherent text one word at a time.
Why it matters: This connects GPT’s architecture to the way it produces a continuing, coherent sequence. - Emergent translation capability: Explain why GPT’s ability to translate is called an emergent behavior despite its next-word pretraining task.
Why it matters: It shows why a model pretrained for text prediction can be useful beyond text completion.
Key terms: next-word prediction, self-supervised learning, self-labeling, unlabeled text datasets, decoder, encoder, autoregressive model, previous outputs, emergent behavior, translation
1.7 Building a large language model
The section explains why the book uses a small dataset to demonstrate LLM pretraining rather than attempting a full-scale GPT-like pretraining run.
- Practical limits of pretraining: Explain why the book implements pretraining on a small dataset for educational purposes instead of pretraining a full-scale GPT-like model from scratch.
Why it matters: This distinction sets realistic expectations for what the book’s training exercise demonstrates.
Key terms: pretraining, GPT-like models, small dataset
1.8 Summary
The section summarizes how LLMs are trained, how transformer architecture supports text generation, and why next-word prediction can produce broader language capabilities.
Where this is used later
- Training an LLM (chapter 5) · Training an LLM builds on the stated next-word prediction objective.
- Using the LLM as a spam classifier (chapter 6) · The spam-classifier application revisits the classification task used here to illustrate features and labels.
- (chapter intro) (chapter 2) · Introduces the stages of building and using LLMs.
- Different categories of fine-tuning (chapter 6) · Builds on the distinction between a pretrained model and task-specific fine-tuning.
- Introduction to instruction fine-tuning (chapter 7) · Introduces instruction fine-tuning.
- Capturing data dependencies with attention mechanisms (chapter 3) · The introduction to the transformer architecture
- Tokenizing text (chapter 2) · Develops the brief introduction to tokens into an explanation of tokenization.
- Fine-tuning the model on supervised data (chapter 6) · Applies a pretrained model to supervised fine-tuning.
Concepts explained in this chapter
- language modelA large neural language model trained on text to understand and generate language, typically using transformer self-attention.
- fine-tuningFurther training of a pretrained model on a smaller task-specific dataset to improve downstream performance.
- pretrainingThe initial training phase in which a language model learns general patterns from a large text corpus before task-specific adaptation.
- next-token predictionA language-model training objective in which the model predicts the next token or word from preceding context.
- GPT modelA family of decoder-only generative pretrained transformer language models.
- few-shot learningThe ability to learn a new task from only a few examples rather than extensive training data.
- self-supervised learningA training approach in which the model derives supervision signals from the input data itself rather than from human-provided labels.
- attentionA neural-network mechanism that weights input tokens or values by relevance so the model can focus on important context.
- transformer architecturea neural network architecture based on self-attention mechanisms that enables processing of sequential data and underpins many large language models.
- PyTorchThe deep learning library used here to normalize attention scores along a specified tensor dimension with softmax.
- BERTA transformer-based model built on the encoder stack and trained for bidirectional masked-word prediction.
- zero-shot learningA learning setup where a model handles a task without having seen any task-specific examples beforehand.
- tokenA discrete unit of text that a language model processes, roughly corresponding to words or punctuation marks in this section.
- tokenizationThe process of splitting raw text into tokens for further processing by a language model.
- training datasetThe subset of data used to fit model parameters during development.
- spam classificationThe text classification task of deciding whether an email or message is spam or legitimate.
- Alpaca datasetA dataset of instruction-style input-output examples used to adapt a language model to follow natural-language instructions.
- embeddingA numerical representation used to encode text or other objects for neural computation.
- classifierThe task of classifying text into predefined categories.
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.
