PIXELBANKv8.2.1
Menu
Back to NLP Study Plan
Week 9

Chapter 9: Language Modeling

Understand language modeling from statistical n-grams to neural approaches, including BERT's masked language modeling, GPT's causal modeling, and how perplexity measures model quality.

Chapter Overview

Language modeling is the task of assigning probabilities to sequences of words. Given a sequence w1,w2,,wn1w_1, w_2, \ldots, w_{n-1}, a language model estimates P(wnw1,,wn1)P(w_n \mid w_1, \ldots, w_{n-1}) --- the probability of the next word given all preceding context. This deceptively simple objective underlies virtually every modern NLP system: machine translation, speech recognition, text generation, and even code completion all rely on language models to score or generate fluent text.

The history of language modeling traces a path from counting word co-occurrences to learning distributed representations. Statistical n-gram models dominated for decades, approximating context with fixed-length windows and smoothing techniques to handle unseen word combinations. Neural language models, starting with Bengio's feedforward architecture in 2003, replaced discrete counts with continuous vector representations, enabling generalization across similar contexts. Recurrent neural networks extended the context window to arbitrary lengths, and the transformer architecture eliminated sequential bottlenecks entirely.

Today, two paradigms define the field. BERT's masked language modeling (MLM) trains bidirectional representations by predicting randomly masked tokens from surrounding context in both directions. GPT's causal language modeling (CLM) trains left-to-right autoregressive models that generate text one token at a time. These two approaches --- predicting masked tokens versus predicting next tokens --- lead to fundamentally different model architectures and downstream capabilities. This chapter covers the full trajectory from n-grams to transformers, the mathematics of perplexity as an evaluation metric, and the architectural choices that distinguish BERT from GPT.

Chapter Roadmap

Click any topic to jump in

1
Statistical Language Models

N-gram probabilities, MLE, smoothing techniques, and backoff/interpolation strategies.

From counts to vectors

Neural approaches and their evaluation metric

2
Neural Language Models

Bengio's NNLM, learned embeddings, and the transition from feedforward to recurrent models.

3
Perplexity

The standard evaluation metric for language models, rooted in information theory.

The pretraining revolution
4
BERT Architecture

Masked language modeling, WordPiece tokenization, and bidirectional pretraining.

Two paradigms for language understanding and generation

Autoregressive vs masked pretraining and their trade-offs

5
GPT Architecture

Causal language modeling, decoder-only design, and in-context learning.

6
Masked vs Causal LM

Comparing bidirectional and unidirectional pretraining for different downstream tasks.

Sign up to unlock this chapter

This chapter is part of PixelBank Premium. Create a free account, then upgrade to read the full lesson — concepts, walkthroughs, and exercises.