COMP5046 — Natural Language Processing

Lecture 4: Inference — Greedy and Search

Model scores outputs · exhaustive · greedy · sampling · beam · graph search · Viterbi.

How to use: map each algorithm to complexity vs optimality · answer Recall without scrolling.

Roles

Model vs inference

RecallIn one sentence: what does inference optimize if the model is fixed?

Exact

Exhaustive search

RecallWhy is exhaustive tagging OK for 4 words but not 20 (order of magnitude)?

Approximate

Greedy & decoding variants

RecallTop-p vs top-k in one phrase each.

Prune

Beam search

Beam Search (K=2) <start> the (0.4) a (0.3) an (0.2) ← pruned the cat (0.3) a small (0.25) the big ← pruned
Beam search (K=2): expand all candidates at each step, keep only the top-K scoring hypotheses, prune the rest.

RecallWhat does beam width \(K\) trade off?

Heuristics

Graph search

Structure

Sequence tagging

RecallWhy can greedy tagging break BIO constraints?

Structure

Dependency parsing

RecallWhat constraint must a dependency parse satisfy that general graphs do not?

Discourse

Coreference resolution

RecallThree steps to simplify coreference search.

Lab

Workshop 4

Quick practice

Why does greedy tagging reduce complexity compared to exhaustive?
Greedy is \(O(n|T|)\) — picks one tag per position; exhaustive is \(O(|T|^n)\)
Greedy uses dynamic programming
Greedy skips low-probability tags
Greedy only considers bigrams
What does beam width K trade off?
K trades off vocabulary size vs speed
Larger K always finds the global optimum
Larger K explores more hypotheses but costs more compute
K controls the learning rate

Chapter quizzes

Retrieval practice.

Open Quiz Hub Chapter flashcards