+ All Categories
Home > Documents > Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same...

Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same...

Date post: 04-Oct-2020
Category:
Upload: others
View: 5 times
Download: 0 times
Share this document with a friend
37
Hidden Markov Models COSC 6336 Intro to Natural Language Processing Spring 2018 With adapted material from Yang Liu, who borrowed material from Tanja Schultz and Dan Jurafsky
Transcript
Page 1: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

Hidden Markov Models

COSC 6336 Intro to Natural Language ProcessingSpring 2018

With adapted material from Yang Liu, who borrowed material from Tanja Schultz and Dan Jurafsky

Page 2: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

2

In This Lecture

§ Introduction to Hidden Markov Models (HMMs)§ Forward algorithm§ Viterbi algorithm

Page 3: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

3

More Formally: Toward HMMsMarkov Models§ A Weighted Finite-State Automaton (WFSA)

§ An FSA with probabilities on the arcs§ The sum of the probabilities leaving any arc must sum to one

§ A Markov chain (or observable Markov Model)§ a special case of a WFSA in which the input sequence uniquely

determines which states the automaton will go through§ Markov chains can’t represent inherently ambiguous

problems§ Useful for assigning probabilities to unambiguous sequences

Page 4: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

4

Markov Chain for Weather

!"#$"%

&'()

*+,-.

/012

30456

#66

#%6

#22

#26

#%.

#%2

#62

#2.

#..

#6)

#2)

#6.

#.)

#.6

#.2

Page 5: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

5

First-order Observable Markov Model

§ A set of states § Q = q1, q2…qN; the state at time t is qt

§ Current state only depends on previous state

§ Transition probability matrix A

§ Special initial probability vector p

§ Constraints:€

P(qi |q1...qi−1) = P(qi |qi−1)

π i = P(q1 = i) 1≤ i ≤ N

aij =1; 1≤ i ≤ Nj=1

N

π j =1j=1

N

∑€

aij = P(qt = j |qt−1 = i) 1≤ i, j ≤ N

Page 6: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

6

Markov Model for Dow Jones

Page 7: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

7

Markov Model for Dow Jones

§ What is the probability of 5 consecutive up days?

§ Sequence is up-up-up-up-up§ I.e., state sequence is 1-1-1-1-1§ P(1,1,1,1,1) = ?

Page 8: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

8

Markov Model for Dow Jones

§ P(1,1,1,1,1) = § p1a11a11a11a11 = 0.5 x (0.6)4 = 0.0648

Page 9: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

9

Hidden Markov Model

§ For Markov chains, the output symbols are the same as the states§ See up one day: we’re in state up

§ But in many NLP tasks: § output symbols are words§ hidden states are something else

§ So we need an extension!§ A Hidden Markov Model is an extension of a Markov

chain in which the input symbols are not the same as the states.

§ This means we don’t know which state we are in.

Page 10: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

10

Hidden Markov Models

Page 11: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

11

Assumptions

§ Markov assumption:

§ Output-independence assumption

P(qi |q1...qi−1) = P(qi |qi−1)

P(ot |O1t−1,q1

t ) = P(ot |qt )

Page 12: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

12

HMM for Dow Jones

From Huang et al.

Page 13: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

13

HMMs for Weather and Ice-cream

§ Jason Eisner’s cute HMM in Excel, showing Viterbi and EM:http://www.cs.jhu.edu/~jason/papers/#teachingIdea:§ You are climatologists in 3004§ Want to know about Baltimore weather in 2004§ Only data you have is Jason Eisner’s diary§ Which records how much ice cream he ate each day

§ Observation:§ Number of ice creams

§ Hidden State: Simplify to only 2 states§ Weather is Hot or Cold that day.

Page 14: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

14

The Three Basic Problems for HMMs

§ (From the classic formulation by Larry Rabiner after Jack Ferguson)

§ L. R. Rabiner. 1989. A tutorial on Hidden Markov Models and Selected Applications in Speech Recognition. Proc IEEE 77(2), 257-286. Also in Waibel and Lee volume.

Page 15: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

15

The Three Basic Problems for HMMs

§ Problem 1 (Evaluation/Likelihood): Given the observation sequence O=(o1o2…oT), and an HMM model F = (A,B), how do we efficiently compute P(O| F), the probability of the observation sequence, given F

§ Problem 2 (Decoding): Given the observation sequence O=(o1o2…oT), and an HMM model F = (A,B), how do we choose a corresponding state sequence Q=(q1q2…qT)that is optimal in some sense (i.e., best explains the observations)

§ Problem 3 (Learning): How do we adjust the model parameters F = (A,B) to maximize P(O| F )?

Page 16: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

Problem 1: Computing the Observation Likelihood

§ Given the following HMM:

§ How likely is the sequence 3 1 3?

Page 17: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

How to Compute Likelihood

§ For a Markov chain, we just follow the states 3 1 3 and multiply the probabilities

§ But for an HMM, we don’t know what the states are!

§ So let’s start with a simpler situation§ Computing the observation likelihood for a given

hidden state sequence§ Suppose we knew the weather and wanted to predict

how much ice cream Jason would eat§ i.e. P( 3 1 3 | H H C)

Page 18: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

Computing Likelihood of 3 1 3 Given Hidden State Sequence

Page 19: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

Computing Joint Probability of Observation and a Particular State Sequence

Page 20: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

Computing Total Likelihood of 3 1 3

§ We would need to sum over§ Hot hot cold§ Hot hot hot§ Hot cold hot§ ….

§ How many possible hidden state sequences are there for this sequence?

§ How about in general for an HMM with N hidden states and a sequence of T observations?§ NT

Page 21: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

21

Computing Observation Likelihood P(O|F)

§ Why can’t we do an explicit sum over all paths?§ Because it’s intractable, there are O(NT) paths§ What we do instead:§ The Forward Algorithm. O(N2T)§ A kind of dynamic programming algorithm

§ Uses a table to store intermediate values§ Idea:

§ Compute the likelihood of the observation sequence by summing over all possible hidden state sequences

Page 22: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

The Forward Algorithm

§ The goal of the forward algorithm is to compute

§ We’ll do this by recursion

P(o1,o2,...,oT ,qT = qF | λ)

Page 23: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

The Forward Algorithm

§ Each cell of the forward algorithm trellis at(j)§ Represents the probability of being in state j§ After seeing the first t observations§ Given the automaton

§ Each cell thus expresses the following probability

Page 24: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

The Forward Trellis

0464.08.02.14.32.)2(2 =´+´=a

Page 25: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

We update each cell

Page 26: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

2006 Yang Liu: CS6V81 – Speech Processing

26

The Forward Algorithm

Page 27: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

The Forward Algorithm

Page 28: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

28

Forward Trellis for Dow Jones

Page 29: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

29

The Three Basic Problems for HMMs

§ Problem 1 (Evaluation): Given the observation sequence O=(o1o2…oT), and an HMM model F = (A,B), how do we efficiently compute P(O| F), the probability of the observation sequence, given the model

§ Problem 2 (Decoding): Given the observation sequence O=(o1o2…oT), and an HMM model F = (A,B), how do we choose a corresponding state sequence Q=(q1q2…qT)that is optimal in some sense (i.e., best explains the observations)

§ Problem 3 (Learning): How do we adjust the model parameters F = (A,B) to maximize P(O| F )?

Page 30: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

30

Decoding

§ Given an observation sequence§ up up down

§ And an HMM§ The task of the decoder

§ To find the best hidden state sequence§ We can calculate P(O|path) for each path§ Could find the best one§ But we can’t do this, since again the number of paths is

O(NT). Instead:§ Viterbi Decoding: dynamic programming, slight modification of

the forward algorithm

Page 31: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

Viterbi intuition

§ We want to compute the joint probability of the observation sequence together with the best state sequence

maxq 0,q1,...,qT

P(q0,q1,...,qT ,o1,o2,...,oT ,qT = qF | λ)

Page 32: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

Viterbi Recursion

Page 33: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

The Viterbi trellis

0448.)08.02,.14.32max(.)2(2 =´´=v

Page 34: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

Viterbi for Dow Jones

34

Page 35: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

35

Viterbi Intuition

§ Process observation sequence left to right§ Filling out the trellis§ Each cell:

Page 36: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

36

The Viterbi Algorithm

Page 37: Hidden Markov Models · Hidden Markov Model § For Markov chains, the output symbols are the same as the states § See up one day: we’re in state up § But in many NLP tasks: §

So Far…

§ Forward algorithm for evaluation§ Viterbi algorithm for decoding§ Next topic: the learning problem

37


Recommended