liveBook · Manning

Chapter 2: Large language models: A deep dive into language modeling

What you will learn in chapter 2 of LLMs in Production

This introduction maps the chapter’s path from linguistic foundations and earlier language models to transformers and LLMs, and explains why that background matters in production.

After this chapter you will be able to

Section by section

Introduction

This introduction maps the chapter’s path from linguistic foundations and earlier language models to transformers and LLMs, and explains why that background matters in production.

Key terms: syntax, semantics, pragmatics, semiotics, N-grams, naive Bayes classifiers, multilayer perceptrons (MLPs), recurrent neural networks (RNNs), long short-term memory (LSTM) networks, transformer-based models

2.1 Language modeling

The section uses layers of abstraction to explain why conveying an idea to an LLM is difficult and introduces the language features the chapter will examine.

Key terms: abstraction, language, math, binary, assembly, disconnect point, failure points, tokenization, embeddings, linguistic features

2.1.1 Linguistic features

The section explains five linguistic features and how each affects what language models can represent, learn, and miss.

Key terms: phonetics, phonology, International Phonetic Alphabet, IPA, tone, syntax, word order, syntactic ambiguity, semantics, pragmatics

2.1.2 Semiotics

The section uses semiotics to show how people assemble meaning from multiple kinds of cues, why LLMs have an incomplete version of that process, and how prompting can help.

Key terms: semiotics, Peircean semiotic triangle, firstness, secondness, thirdness, interpretation, orthography, semantics, ritual, scripts

2.1.3 Multilingual NLP

The section argues that multilingual access and contested language boundaries matter in LLM design, then contrasts localization with internationalization as early design directions.

Key terms: multilingual models, Anglocentric, languages and dialects, localization, l10n, internationalization, i18n, structure of language, meaning, linguistic features

2.2 Language modeling techniques

This section introduces the processing choices common to language models, then uses bag-of-words to show both the value and the limits of a simple baseline.

Key terms: token, tokenized inputs, numerical values, bag-of-words (BoW), vocabulary, CountVectorizer, frequency, baseline, whitespace, tokenization

2.2.1 N-gram and corpus-based techniques

This section introduces N-gram language models as practical, frequency-based baselines, shows how a trigram generates text, and explains why fixed-length context cannot capture all aspects of language.

Key terms: N-gram, BoW, context, probabilistic connections, linguistic features, trigram, everygrams, padding, tokens, Listing 2.1

2.2.2 Bayesian techniques

This section introduces Bayes’ theorem as a basis for text classification, then explains why the simple Bayesian model shown is limited for language generation and sequence modeling.

Key terms: Bayes’ theorem, hypothesis, evidence, prior, naive Bayes, classification, generative language models, Listing 2.2, LogPrior, LogLikelihood

2.2.3 Markov chains

The section explains how Markov models generate language from state-dependent probabilities, where they are useful, and why their limited context motivates continuous models.

Key terms: Markov chains, hidden Markov models, state, stochasticity, N-gram models, generative language model, whitespace, tokenizer, document, part-of-speech tagging

2.2.4 Continuous language modeling

The section uses a continuous bag-of-words model to show how surrounding words can produce embeddings, while introducing a neural-network training loop and its activation choices.

Key terms: continuous bag-of-words (CBoW), context window, target word, embeddings, continuous modeling, BoW model, neural network, N-grams, naive Bayes, model weights

2.2.5 Embeddings

This section explains how embeddings derive useful semantic relationships from word usage, where they fall short of human understanding, and how visualization can help assess them.

Key terms: embeddings, tokenized vectors, collocation, Word2Vec, nearest neighbor, semantics, pragmatics, representative data, pyplot, model explainability

2.2.6 Multilayer perceptrons

This section presents MLPs as flexible neural-network building blocks while emphasizing that an LLM’s capabilities depend on how data moves through its architecture, not just on its layer count.

Key terms: MLP, weights, biases, features, fully connected layers, Listing 2.6, num_hidden_layers, CBoW, RNNs, CNNs

2.2.7 Recurrent neural networks and long short-term memory networks

This section explains how RNNs and LSTMs model sequences, compares their sentiment-analysis performance, and shows why their computational costs motivate attention.

Key terms: RNN, sequence, internal state, variable length inputs, vanishing gradient, exploding gradients, LSTM, memory cells, gating mechanisms, bidirectional

2.2.8 Attention

This section explains how attention uses queries, keys, and values to select relevant context, distinguishes attention patterns, and introduces its benefits and limits before transformers.

Key terms: Query, Key, Value, dot product similarity, attention score, dot product attention, bi-directional self-attention, causal attention, masked attention, context windows

2.3 Attention is all you need

Introduces transformers as a shift from earlier NLP techniques to an architecture based on attention rather than recurrence or convolution.

Key terms: attention, recurrence, convolutions, Q, K, and V, transformer architecture, rule-based methods, statistical models, neural networks, state-of-the-art language models

2.3.1 Encoders

This section explains how transformer encoders preserve useful token meanings while incorporating position, then describes BERT as an encoder-only model and weighs encoder strengths against their costs.

Key terms: encoder, embeddings, tokens, self-attention, positional encoding, semantic similarity, BERT, encoder-only transformer, Word2Vec, few-shot learning

2.3.2 Decoders

This section describes decoder structure, why decoders suit language generation, and where syntax-focused generation can fail.

Key terms: decoder, encoder, multihead attention blocks, sum and normalize layers, natural language generation (NLG), natural language understanding (NLU), next token, shifted right, decoder-only, Generative Pre-trained Transformer (GPT)

2.3.3 Transformers

This section explains how a full transformer combines an encoder and decoder for conditional generation, then discusses its practical tradeoffs, linguistic limitations, and the value of finetuning pretrained models.

Key terms: full transformer, encoder, decoder, second multihead attention block, conditional generation, T5, parallelization of inputs, LSTMs, memory intensive, VRAM

2.4 Really big transformers

This section explains what larger transformers make possible, where their language abilities fall short, and the practical risks of using them.

Key terms: LLMs, transformer-based models, parameters, emergent behavior, transfer learning, finetuning, few-shot prompting, one-shot prompting, zero-shot prompting, input space

2.5 Summary

This summary connects linguistic features and language-modeling advances to modern LLM architectures and the effects of model scale.

Where this is used later

Concepts explained in this chapter

← Chapter 1: Generative AI: Why large language models have captured attention Chapter 3: Large language model operations: Building a platform for LLMs →

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.