Module 4 of 13

Language Models & N-grams

Lessons

About This Module

A language model assigns a probability to a sequence of words, which in practice means it can predict what word is likely to come next. This one idea sits behind autocomplete, spell correction, speech recognition and, at much larger scale, today's chatbots.

The lessons start with n-grams, sequences of n words, and show how counting them in a large text gives you unigram, bigram and trigram probabilities. You will then see why raw counts break down on unseen word combinations, and how smoothing fixes that, and how perplexity measures whether one model is better than another.

The module ends by looking at where n-gram models run out of road: they only see a few words of context and need huge amounts of data as n grows. That limit is what motivates the neural approaches in later modules. Watch the lessons in order, then continue on to Word Embeddings.

Lessons

6 videos
01

N-Grams in Natural Language Processing (NLP) Explained For Beginners

A beginner-friendly introduction to what n-grams are and how unigrams and bigrams are pulled out of a sentence.

Video 5min
02

How to Find N-Gram Probabilities: Unigram, Bigram, Trigram

A worked example of calculating unigram, bigram and trigram probabilities from counts, by Vidya Mahesh Huddar.

Video 8min
03

N-gram Language Modeling

Introduces building a simple n-gram based language model, with code and slides linked by the creator.

Video 17min
04

N-Grams & N-Gram Language Models

A full lecture covering n-gram language models, Laplace (add-one) smoothing for unseen n-grams, and perplexity, with numerical examples.

Video 47min
05

The Spelled-Out Intro to Language Modeling: Building makemore

Andrej Karpathy builds a character-level bigram language model from scratch, then shows the same model as a tiny neural network. A longer, hands-on watch.

Video 1h 57min
06

Stanford CS224N: Language Models and RNNs (Winter 2019, Lecture 6)

Reviews n-gram language models and perplexity, then shows how neural language models and RNNs overcome their short context and sparse data problems.

Video 1h 8min