Statistical Methods for NLP

Similar documents
Statistical Sequence Recognition and Training: An Introduction to HMMs

EECS E6870: Lecture 4: Hidden Markov Models

Statistical Methods for NLP

Part of Speech Tagging: Viterbi, Forward, Backward, Forward- Backward, Baum-Welch. COMP-599 Oct 1, 2015

Statistical Methods for NLP

Lecture 4. Hidden Markov Models. Michael Picheny, Bhuvana Ramabhadran, Stanley F. Chen, Markus Nussbaum-Thom

Statistical NLP: Hidden Markov Models. Updated 12/15

HIDDEN MARKOV MODELS IN SPEECH RECOGNITION

Lecture 12: Algorithms for HMMs

Lecture 12: Algorithms for HMMs

CMSC 723: Computational Linguistics I Session #5 Hidden Markov Models. The ischool University of Maryland. Wednesday, September 30, 2009

Recap: HMM. ANLP Lecture 9: Algorithms for HMMs. More general notation. Recap: HMM. Elements of HMM: Sharon Goldwater 4 Oct 2018.

Hidden Markov Models in Language Processing

CSCI 5832 Natural Language Processing. Today 2/19. Statistical Sequence Classification. Lecture 9

STA 414/2104: Machine Learning

Sequence Labeling: HMMs & Structured Perceptron

Hidden Markov Models

Hidden Markov Modelling

Dept. of Linguistics, Indiana University Fall 2009

Hidden Markov Models. Aarti Singh Slides courtesy: Eric Xing. Machine Learning / Nov 8, 2010

Hidden Markov Models and Gaussian Mixture Models

Hidden Markov Models. By Parisa Abedi. Slides courtesy: Eric Xing

Brief Introduction of Machine Learning Techniques for Content Analysis

Sequence labeling. Taking collective a set of interrelated instances x 1,, x T and jointly labeling them

Statistical NLP for the Web Log Linear Models, MEMM, Conditional Random Fields

Hidden Markov Models

Hidden Markov Models

STA 4273H: Statistical Machine Learning

CS838-1 Advanced NLP: Hidden Markov Models

CS 136a Lecture 7 Speech Recognition Architecture: Training models with the Forward backward algorithm

A gentle introduction to Hidden Markov Models

More on HMMs and other sequence models. Intro to NLP - ETHZ - 18/03/2013

Empirical Methods in Natural Language Processing Lecture 11 Part-of-speech tagging and HMMs

Basic Text Analysis. Hidden Markov Models. Joakim Nivre. Uppsala University Department of Linguistics and Philology

10. Hidden Markov Models (HMM) for Speech Processing. (some slides taken from Glass and Zue course)

Intelligent Systems (AI-2)

Lecture 11: Hidden Markov Models

Introduction to Machine Learning CMU-10701

Automatic Speech Recognition (CS753)

CISC 889 Bioinformatics (Spring 2004) Hidden Markov Models (II)

Hidden Markov Models The three basic HMM problems (note: change in notation) Mitch Marcus CSE 391

An Introduction to Bioinformatics Algorithms Hidden Markov Models

order is number of previous outputs

Intelligent Systems (AI-2)

Hidden Markov Models

Lecture 3: ASR: HMMs, Forward, Viterbi

We Live in Exciting Times. CSCI-567: Machine Learning (Spring 2019) Outline. Outline. ACM (an international computing research society) has named

Parametric Models Part III: Hidden Markov Models

Sequence Modelling with Features: Linear-Chain Conditional Random Fields. COMP-599 Oct 6, 2015

Machine Learning for natural language processing

Hidden Markov Models

Midterm sample questions

Data-Intensive Computing with MapReduce

Sequential Supervised Learning

Directed Probabilistic Graphical Models CMSC 678 UMBC

Machine Learning & Data Mining Caltech CS/CNS/EE 155 Hidden Markov Models Last Updated: Feb 7th, 2017

Hidden Markov Models

COMP90051 Statistical Machine Learning

What s an HMM? Extraction with Finite State Machines e.g. Hidden Markov Models (HMMs) Hidden Markov Models (HMMs) for Information Extraction

Page 1. References. Hidden Markov models and multiple sequence alignment. Markov chains. Probability review. Example. Markovian sequence

Lecture 13: Structured Prediction

Note Set 5: Hidden Markov Models

A brief introduction to Conditional Random Fields

Statistical Processing of Natural Language

Hidden Markov Models and Gaussian Mixture Models

L23: hidden Markov models

Statistical Pattern Recognition

HMM: Parameter Estimation

A Gentle Tutorial of the EM Algorithm and its Application to Parameter Estimation for Gaussian Mixture and Hidden Markov Models

Conditional Random Field

Hidden Markov Models

A.I. in health informatics lecture 8 structured learning. kevin small & byron wallace

Bayesian Methods: Naïve Bayes

Natural Language Processing

Cheng Soon Ong & Christian Walder. Canberra February June 2018

10/17/04. Today s Main Points

Robert Collins CSE586 CSE 586, Spring 2015 Computer Vision II

Machine Learning CMPT 726 Simon Fraser University. Binomial Parameter Estimation

Hidden Markov Models

8: Hidden Markov Models

Expectation-Maximization (EM) algorithm

Hidden Markov Models Part 2: Algorithms

Lecture 4: Hidden Markov Models: An Introduction to Dynamic Decision Making. November 11, 2010

Hidden Markov Models

Advanced Data Science

Hidden Markov Models

LECTURER: BURCU CAN Spring

Lecture 9. Intro to Hidden Markov Models (finish up)

Hidden Markov Models. based on chapters from the book Durbin, Eddy, Krogh and Mitchison Biological Sequence Analysis via Shamir s lecture notes

Expectation Maximization (EM)

University of Cambridge. MPhil in Computer Speech Text & Internet Technology. Module: Speech Processing II. Lecture 2: Hidden Markov Models I

Hidden Markov Models. Hosein Mohimani GHC7717

CSCI-567: Machine Learning (Spring 2019)

CSC401/2511 Spring CSC401/2511 Natural Language Computing Spring 2019 Lecture 5 Frank Rudzicz and Chloé Pou-Prom University of Toronto

An Introduction to Bioinformatics Algorithms Hidden Markov Models

Expectation Maximization (EM)

Parametric Models. Dr. Shuang LIANG. School of Software Engineering TongJi University Fall, 2012

Hidden Markov Model. Ying Wu. Electrical Engineering and Computer Science Northwestern University Evanston, IL 60208

Unit 1: Sequence Models

Data Mining in Bioinformatics HMM

Transcription:

Statistical Methods for NLP Information Extraction, Hidden Markov Models Sameer Maskey Week 5, Oct 3, 2012 *many slides provided by Bhuvana Ramabhadran, Stanley Chen, Michael Picheny Speech Recognition Lecture 4: Hidden Markov Models

Announcement Homework 1 Due Thursday Oct 4 (11:59pm) Project Intermediate Report I Due Oct 17 Wednesday (11:59pm) Homework 2 will be out Friday Oct 5. Homework 2 Due Oct 25 Thursday (11:59pm) Speech Recognition Lecture 4: Hidden Markov Models 2

Topics for Today Information Extraction Hidden Markov Models Speech Recognition Lecture 4: Hidden Markov Models 3

Information Extraction Extract relevant information from large amount of unstructured text Extracted information can be in structured form Can be used to populate databases for example We can define the kind of information we want to extract Speech Recognition Lecture 4: Hidden Markov Models 4

Examples of Information Extraction Tasks Named Entity Identification Relation Extraction Coreference resolution Term Extraction Lexical Disambiguation Event Detection and Classification Speech Recognition Lecture 4: Hidden Markov Models 5

Classifiers for Information Extraction Sometimes extracted information can be a sequence Extract Parts of Speech for the given sentence DET VB AA ADJ NN This is a good book What kind of classifier may work well for this kind of sequence classification? Speech Recognition Lecture 4: Hidden Markov Models 6

Classification without Memory CLASS1 CLASS2 CLASS1 CLASS2 CLASS1 CLASS2 CLASS1CLASS2 PREDICT PREDICT PREDICT PREDICT PREDICT X X X X Features Features Features Features Speech Recognition Lecture 4: Hidden Markov Models 7

Classification without Memory P(NN book) = 0.62 P(VB book) = 0.14 P(ADV book) = 0.004 C C C C C X1 X2 X3 book XN C(t) (class) is dependent on current observations X(t) C(t) can be POS tags, document class, word class, X(t) can be text based features Perceptron is an example of classifier without memory Speech Recognition Lecture 4: Hidden Markov Models 8

Probability Sequence Computation for Models without Memory A coin has probability of heads = p, probability of tails = 1-p Flip the coin 10 times. Assume I.I.D. random sequence. There are 2 10 possible sequences. Sequence: 1 0 1 0 0 0 1 0 0 1 Probability: p(1-p)p(1-p)(1-p)(1-p) p(1-p)(1-p)p = p 4 (1-p) 6 Models without memory: Observations are Independent. Probability is the same for all sequences with 4 heads & 6 tails. Order of heads & tails does not matter in assigning a probability to the sequence, only the number of heads & number of tails Probability of 0 heads (1-p) 10 1 head p(1-p) 9 10 heads p 10 Speech Recognition Lecture 4: Hidden Markov Models 9

Models without Memory: Learning Model Parameters If p is known, then it is easy to compute the probability of the sequence. Now suppose p is unknown. We toss the coin N times, obtaining H heads and T tails, where H+T=N We want to estimate p A reasonable estimate is p=h/n. Is this actually the best choice for p? What is best? Consider the probability of the observed sequence. Prob(seq)=p H (1-p) T Prob(seq) p mle p The value of p for which Prob(seq) is maximized is the Maximum Likelihood Estimate (MLE) of p. (Denote p mle ) Speech Recognition Lecture 4: Hidden Markov Models 10

Models without Memory: Example, cont d Assertion: p mle = H/N Proof: Prob(seq)=p H (1-p) T Maximizing Prob is equivalent to maximizing log(prob) L=log(Prob(seq)) = H log p + T log (1-p) L = Η/p + Τ/(1 p) p L L maximized when = 0 p H/p mle - T/(1-p mle ) = 0 H H p mle = T p mle H = T p mle + H p mle = p mle (T + H) = p mle N p mle = H/N Speech Recognition Lecture 4: Hidden Markov Models 11

Models without Memory Example, cont d We showed that in this case MLE = Relative Frequency = H/N We will use this idea many times. Often, parameter estimation reduces to counting and normalizing. Speech Recognition Lecture 4: Hidden Markov Models 12

Models with Memory: Markov Models Flipping a coin was memory-less. The outcome of each flip did not depend on the outcome of the other flips. Adding memory to a memory-less model gives us a Markov Model. Useful for modeling sequences of events. For POS tagging adding memory to classifier could be useful Speech Recognition Lecture 4: Hidden Markov Models 13

Classification with Memory CLASS1 CLASS2 CLASS1 CLASS2 CLASS1 CLASS2 CLASS1CLASS2 PREDICT PREDICT PREDICT PREDICT PREDICT X X X X Features Features Features Features Current Prediction depends only previous predictions and current observation Speech Recognition Lecture 4: Hidden Markov Models 14

Classification without Memory P(NN book) = 0.62 P(VB book) = 0.14 P(ADV book) = 0.004 C C C C C X1 X2 X3 book XN C(t) (class) is dependent on current observations X(t) C(t) can be POS tags, document class, word class, X(t) can be text based features Perceptron is an example of classifier without memory Speech Recognition Lecture 4: Hidden Markov Models 15

Classification with Memory P(NN book, prevadj) = 0.80 P(VB book, prevadj) = 0.04 P(VB book, prevadv) = 0.10 C C ADJ C C X1 X2 good book XN C(t) (class) is dependent on current observations X(t) and previous state of classification (C(t-1)) C(t) can be POS tags, document class, word class, X(t) can be text based features Speech Recognition Lecture 4: Hidden Markov Models 16

Sequential Stochastic Models We can add memory to learning model by adding dependencies across classification labels over time Probabilistic models that can model such dependencies across time is useful for many tasks Information Extraction Speech Recognition Computational Biology We can build Markov model for underlying sequence of labels and associate the observations with each state Speech Recognition Lecture 4: Hidden Markov Models 17

Adding Memory to Coin Example Consider 2 coins. Coin 1: p H = 0.9, p T = 0.1 Coin 2: p H = 0.2, p T = 0.8 Experiment: Flip Coin 1. for J = 2 ; J<=4; J++ if (previous flip == H ) flip Coin 1; else flip Coin 2; Consider the following 2 sequences: H H T T prob = 0.9 x 0.9 x 0.1 x 0.8 =.0648 H T H T prob = 0.9 x 0.1 x 0.2 x 0.1 =.0018 ADDING MEMORY what would be probability if no memory was added? Sequences with consecutive heads or tails are more likely. The sequence has memory - order matters. Order matters for language. Adjective noun probably more common than adjective adjective Speech Recognition Lecture 4: Hidden Markov Models 18

Markov Models State Space Representation Consider 2 coins. Coin 1: p H = 0.9, p T = 0.1 Coin 2: p H = 0.2, p T = 0.8 State-space representation of previous example H 0.9 T 0.1 T 0.8 1 2 H 0.2 Speech Recognition Lecture 4: Hidden Markov Models 19

Markov Models State Space Representation (Con t) State sequence can be uniquely determined from the outcome sequence, given the initial state. Output probability is easy to compute. It is the product of the transition probs for state sequence. H 0.9 T 0.1 T 0.8 1 2 H 0.2 Example: O: H T T T S: 1(given) 1 2 2 Prob: 0.9 x 0.1 x 0.8 x 0.8 Speech Recognition Lecture 4: Hidden Markov Models 20

Back to Memory-Less Models: Hidden Information Let s return to the memory-less coin flip model Consider 3 coins. Coin 0: p H = 0.7 ADDING HIDDEN VARIABLE Coin 1: p H = 0.9 Coin 2 p H = 0.2 Experiment: For J=1..4 Flip coin 0. If outcome == H Flip coin 1 and record. else Flip coin 2 and record. Speech Recognition Lecture 4: Hidden Markov Models 21

Hiding Information (cont.) Coin 0: p H = 0.7 Coin 1: p H = 0.9 Coin 2: p H = 0.2 We cannot uniquely determine the output of the Coin 0 flips. This is hidden. Consider the sequence H T T T. What is the probability of the sequence? Order doesn t matter (memory-less) p(head)=p(head coin0=h)p(coin0=h)+ p(head coin0=t)p(coin0=t)= 0.9x0.7 + 0.2x0.3 = 0.69 p(tail) = 0.1 x 0.7 + 0.8 x 0.3 = 0.31 P(HTTT) =.69 x.31 3 Speech Recognition Lecture 4: Hidden Markov Models 22

Hidden Information + Markov Model We added Memory We introduced Hidden Variable Speech Recognition Lecture 4: Hidden Markov Models 23

Hidden Markov Model The state sequence is hidden. Unlike Markov Models, the state sequence cannot be uniquely deduced from the output sequence. Experiment: Flip the same two coins. This time, flip each coin twice. The first flip gets recorded as the output sequence. The second flip determines which coin gets flipped next. Now, consider output sequence H T T T. No way to know the results of the even numbered flips, so no way to know which coin is flipped each time. Unlike previous example, order now matters (start with coin 1, p H = 0.9) H H T T T H T =.9 x.9 x.1 x.1 x.8 x.2 x.1 =.0001296 T T T H T T H =.1 x.1 x.8 x.2 x.1 x.1 x.2 =.0000032 Even worse, same output sequence corresponds to multiple probabilities! H T T H T T T =.9 x.1 x.8 x.2 x.1 x.1 x.8 =.0001152 Speech Recognition Lecture 4: Hidden Markov Models 24

Hidden Markov Model The state sequence is hidden. Unlike Markov Models, the state sequence cannot be uniquely deduced from the output sequence. 0.9 0.1 0.9 0.1 0.2 0.8 0.9 0.1 0.8 1 2 0.2 0.8 0.2 Speech Recognition Lecture 4: Hidden Markov Models 25

Is a Markov Model Hidden or Not? A necessary and sufficient condition for being state-observable is that all transitions from each state produce different outputs a, b a, b c b d State-observable d Hidden Speech Recognition Lecture 4: Hidden Markov Models 26

Three problems of general interest for an HMM 3 problems need to be solved before we can use HMM s: 1. Given an observed output sequence X=x 1 x 2..x T, compute P θ (X) for a given model θ (scoring) 2. Given X, find the most likely state sequence (Viterbi algorithm) 3. Estimate the parameters of the model (training) These problems are easy to solve for a state-observable Markov model. More complicated for an HMM because we need to consider all possible state sequences. Must develop a generalization. Speech Recognition Lecture 4: Hidden Markov Models 27

Problem 1 1. Given an observed output sequence X=x 1 x 2..x T, compute Pθ(X) for a given model θ Recall the state-observable case H 0.9 T 0.1 T 0.8 1 2 H 0.2 Example: O: H T T T S: 1(given) 1 2 2 Prob: 0.9 x 0.1 x 0.8 x 0.8 Speech Recognition Lecture 4: Hidden Markov Models 28

Problem 1 1. Given an observed output sequence X=x 1 x 2..x T, compute Pθ(X) for a given model θ Sum over all possible state sequences: Pθ(X)=Σ S Pθ(X,S) The obvious way of calculating Pθ(X) is to enumerate all state sequences that produce X Unfortunately, this calculation is exponential in the length of the sequence Speech Recognition Lecture 4: Hidden Markov Models 29

Example for Problem 1 0.5 0.8 0.2 a b 0.4 0.5 0.5 0.7 0.3 0.3 0.7 0.3 0.5 1 2 3 0.2 0.1 Compute Pθ(X) for X=aabb, assuming we start in state 1 Speech Recognition Lecture 4: Hidden Markov Models 30

0.5 EECS E6870 Example for Problem 1,cont d 0.8 0.2 0.7 0.3 0.3 0.5 1 2 3 0.2 a b 0.4 0.5 0.5 0.1 0.3 0.7 1 0.2 0.2 0.5 x 0.8 0.5 x 0.8 2 0.3 x 0.7 0.3 x 0.7 2 0.5 x 0.8 0.4 x 0.5 1 0.4 1 1 2 0.21 2 0.2 0.2 2 0.08 2 2 0.1 3 0.021 0.4 x 0.5 2 0.04 0.1 3 0.004 0.1 3 0.008 0.5 x 0.3 3 0.03 Let s enumerate all possible ways of producing x 1 =a, assuming we start in state 1. Speech Recognition Lecture 4: Hidden Markov Models 31 0.2 2

Example for Problem 1, cont d Now let s think about ways of generating x1x2=aa, for all paths from state 2 after the first observation 2 1 1 2 0.21 2 0.08 2 3 3 2 2 3 2 2 0.04 3 2 2 3 3 Speech Recognition Lecture 4: Hidden Markov Models 32

Example for Problem 1,cont d We can save computations by combining paths. This is a result of the Markov property, that the future doesn t depend on the past if we know the current state 1 2 1 2 0.33 0.4 x 0.5 0.4 x 0.5 0.5 x 0.3 2 2 3 0.1 3 Speech Recognition Lecture 4: Hidden Markov Models 33

Problem 1: Trellis Diagram Expand the state-transition diagram in time. Create a 2-D lattice indexed by state and time. Each state transition sequence is represented exactly once. State: 1 2 3 Time: 0 1 2 3 4 Obs: φ a aa aab aabb.5x.8.5x.8.5x.2.5x.2.3x.7.2.2.2.2.2.4x.5.4x.5.4x.5.4x.5.5x.3.3x.7.5x.3.1.1.1.3x.3.5x.7.3x.3.5x.7.1.1 Speech Recognition Lecture 4: Hidden Markov Models 34

Problem 1: Trellis Diagram, cont d Now let s accumulate the scores. Note that the inputs to a node are from the left and top, so if we work to the right and down all necessary input scores will be available. State: 1 2 3 Time: 0 1 2 3 4 Obs: φ a aa aab aabb.5x.8.5x.8.5x.2.5x.2 1 0.4.16.2.02.3x.7.3x.7.2.2.2.2.2.4x.5.4x.5.4x.5.4x.5.21+.04+.08=.33.5x.3.5x.3.1.1.1.3x.3.084+.066+.32=.182.5x.7.033+.03=.063.0495+.0182=.0677.3x.3.5x.7.1.1 Speech Recognition Lecture 4: Hidden Markov Models 35

Problem 1: Trellis Diagram, cont d Boundary condition: Score of (state 1, φ) = 1. Basic recursion: Score of node i = 0 For the set of predecessor nodes j: Score of node i += score of predecessor node j x the transition probability from j to i x observation probability along that transition if the transition is not null. Speech Recognition Lecture 4: Hidden Markov Models 36

Problem 1: Forward Pass Algorithm Let α t (s) for t ε {1..T} be the probability of being in state s at time t and having produced output x 1t =x 1..x t α t (s) = Σ s α t-1 (s ) P θ (s s ) P θ (x t s ->s) + Σ s α t (s ) P θ (s s ) 1 st term: sum over all output producing arcs 2 nd term: all null arcs This is called the Forward Pass algorithm. This calculation allows us to solve Problem 1 efficiently: P(x 1,x 2,...,x T ;θ)= s α T(s) N^2 * T N^T P(x 1,x 2,...,x T ;θ)= s 1,...S T P(x 1,x 2,...,x T,s 1,s 2,...,s T ) Speech Recognition Lecture 4: Hidden Markov Models 37

Problem 2 Given the observations X, find the most likely state sequence This is solved using the Viterbi algorithm Preview: The computation is similar to the forward algorithm, except we use max( ) instead of + Also, we need to remember which partial path led to the max Speech Recognition Lecture 4: Hidden Markov Models 38

Problem 2: Viterbi algorithm Returning to our example, let s find the most likely path for producing aabb. At each node, remember the max of predecessor score x transition probability. Also store the best predecessor for each node. State: 1 2 3 Time: 0 1 2 3 4 Obs: φ a aa aab aabb.5x.8.5x.8.5x.2.5x.2 1 0.4.16.016.0016.3x.7.3x.7.2.2.2.2.2.4x.5.4x.5.4x.5.4x.5 max(.08.21.04).5x.3.5x.3.1.1.1.3x.3 max(.084.042.032).5x.7.0168.3x.3.5x.7.00336.1.1.00588 max(.03.021) Max(.0084.0315).0294 Speech Recognition Lecture 4: Hidden Markov Models 39

Problem 2: Viterbi algorithm, cont d Starting at the end, find the node with the highest score. Trace back the path to the beginning, following best arc leading into each node along the best path. State: 1 2 3 Time: 0 1 2 3 4 Obs: φ a aa aab aabb.5x.8.5x.8.5x.2.5x.2 1 0.4 0.2.3x.7.3x.7.2.2.2.2.2.4x.5.4x.5.4x.5.4x.5.5x.3.21.5x.3.1.1.1.16.016.084.3x.3.5x.7.0168.3x.3.5x.7.1.1.0016.00336 0.02.00588.03.0315.0294 Speech Recognition Lecture 4: Hidden Markov Models 40

Hidden Markov Models State : Q=q 1 q 2 q N Transition Probabilities Emission Probabilities T =a 11 a 12 a nn B=b i (o t ) Observation Sequence Start and Final State O=o 1 o 2 o T q 0,q F Markov Model with 5 states with 10 possible observation in each state will have T and B of what sizes? Speech Recognition Lecture 4: Hidden Markov Models 41

Three problems of general interest for an HMM 3 problems need to be solved for HMM s: Given an observed output sequence X=x 1 x 2..x T, compute P θ (X) for a given model θ (scoring) P(x 1,x 2,,x T ;θ) Given X, find the most likely state sequence (Viterbi algorithm) Ŝ 1,...,Ŝ T find best using ˆx 1,...,ˆx T Estimate the parameters of the model (training) using n observed sequences of varying length q(s t S t 1 ), b i (o t S t ) Speech Recognition Lecture 4: Hidden Markov Models 42

Detour: Unsupervised Learning Given the training data with class labels we saw we can compute Maximum Likelihood estimate for Naïve Bayes by getting relative frequencies of the word in the class When we do not have labels we can run E-M algorithm E step compute fractional counts M step maximize based on the fractional counts Speech Recognition Lecture 4: Hidden Markov Models 43

Classification with Hidden Variables Hockey Baseball ~ Do not know the class labels ~ Treat class labels as hidden variables ~ Maximize log-likelihood of unlabeled training data ~ Fractional counts can be thought of as assignment to a given class Speech Recognition Lecture 4: Hidden Markov Models 44

Explaining Expectation Maximization EM is like fuzzy K-means Parameters to estimate for K classes Hockey Baseball Let us assume we can model this data with mixture of two Gaussians Start with 2 Gaussians (initialize mu and sigma values) Expectation Compute distance of each point to the mu of 2 Gaussians and assign it a soft class label (Ck) Use the assigned points to recompute mu and sigma for 2 Gaussians; but weight the updates with soft labels Maximization Speech Recognition Lecture 4: Hidden Markov Models 45

The Baum-Welch algorithm The Baum-Welch algorithm is a generalized expectationmaximization algorithm for computing maximum likelihood estimates for the parameters of a Hidden Markov Model when given only observations as training data. It is a special case of the EM algorithm for HMMs. Speech Recognition Lecture 4: Hidden Markov Models 46

Problem 3 Estimate the parameters of the model. (training) Given a model topology and an output sequence, find the transition and output probabilities such that the probability of the output sequence is maximized. Speech Recognition Lecture 4: Hidden Markov Models 47

Problem 3 State Observable Example Assume the output sequence X=abbab, and we start in state 1. a b a b b a Observed counts along transitions: 1 0 2 1 0 1 Speech Recognition Lecture 4: Hidden Markov Models 48

Problem 3 State Observable Example Observed counts along transitions: 1 0 2 1 0 Estimated transition probabilities. (this is of course too little data to estimate these well.) 1 0.33 0 0.67 1 0 Speech Recognition Lecture 4: Hidden Markov Models 49 1 Recall in the state-observable case, we simply followed the unique path, giving a count to each transition.

Generalization to Hidden MM case State-observable Unique path Give a count of 1 to each transition along the path Hidden states Many paths Assign a fractional count to each path For each transition on a given path, give the fractional count for that path Sum of the fractional counts =1 How to assign the fractional counts?? Speech Recognition Lecture 4: Hidden Markov Models 50

How to assign the fractional counts to the paths Guess some values for the parameters Compute the probability for each path using these parameter values Assign path counts in proportion to these probabilities Re-estimate parameter values Iterate until parameters converge Speech Recognition Lecture 4: Hidden Markov Models 51

Estimating Transition and Emission Probabilities a ij = count(i j) q Q count(i q) â ij = Expected number of transitions from state i to j Expected number of transitions from state i ˆbj (x t ) = Expected number of times in state j and observing symbol xt Expected number of time in state j Speech Recognition Lecture 4: Hidden Markov Models 52

Problem 3: Enumerative Example Assigning fractional counts For the following model, estimate the transition probabilities and the output probabilities for the sequence X=abaa a 1 a 4 a 2 a 5 a 3 Speech Recognition Lecture 4: Hidden Markov Models 53

Problem 3: Enumerative Example - Assigning fractional counts Initial guess: equiprobable 1/3 1/2 ½ ½ 1/3 ½ ½ ½ ½ 1/3 1/2 ½ ½ Speech Recognition Lecture 4: Hidden Markov Models 54

Problem 3: Enumerative Example cont d ½ ½ 1/3 7 paths corresponding to an output of abaa 1/3 ½ ½ 1/3 1/2 ½ ½ 1/2 1. pr(x,path1)=1/3x1/2x1/3x1/2x1/3x1/2x1/3x1/2x1/2=.000385 ½ ½ 2. pr(x,path2)=1/3x1/2x1/3x1/2x1/3x1/2x1/2x1/2x1/2=.000578 3. pr(x,path3)=1/3x1/2x1/3x1/2x1/3x1/2x1/2x1/2=.001157 4. pr(x,path4)=1/3x1/2x1/3x1/2x1/2x1/2x1/2x1/2x1/2=.000868 Speech Recognition Lecture 4: Hidden Markov Models 55

Problem 3: Enumerative Example cont d 7 paths: 5. pr(x,path5)=1/3x1/2x1/3x1/2x1/2x1/2x1/2x1/2=.001736 ½ ½ 1/3 1/3 ½ ½ 1/3 1/2 ½ ½ 1/2 ½ ½ 6. pr(x,path6)=1/3x1/2x1/2x1/2x1/2x1/2x1/2x1/2x1/2=.001302 7. pr(x,path7)=1/3x1/2x1/2x1/2x1/2x1/2x1/2x1/2=.002604 Pr(X) = Σ i pr(x,path i ) =.008632 Speech Recognition Lecture 4: Hidden Markov Models 56

Problem 3: Enumerative Example cont d a 1 a2 a 4 a5 Let C i be the a posteriori probability of path i C i = pr(x,path i )/pr(x) a 3 C 1 =.045 C 2 =.067 C 3 =.134 C 4 =.100 C 5 =.201 C 6 =.150 C 7 =.301 Count(a 1 )= 3C 1 +2C 2 +2C 3 +C 4 +C 5 =.838 Count(a 2 )=C 3 +C 5 +C 7 =.637 Count(a 3 )=C 1 +C 2 +C 4 +C 6 =.363 New estimates: a 1 =.46 a 2 =.34 a 3 =.20 a1= C(a1)/{C(a1) + C(a2) + C(a3)} Count(a 1, a ) = 2C 1 +C 2 +C 3 +C 4 +C 5 =.592 Count(a 1, b )=C 1 +C 2 +C 3 =.246 New estimates: p(a 1, a )=.71 p(a 1, b )=.29 1 st term 2C1 because in abaa, last a by a5 so 2 a s in aba Speech Recognition Lecture 4: Hidden Markov Models 57

Problem 3: Enumerative Example cont d a 1 a2 a 4 a5 Count(a 2, a ) = C 3 +C 7 =.436 Count(a 2, b )=C 5 =.201 a 3 New estimates: p(a 2, a )=.68 p(a 2, b )=.32 Count(a 4 )=C 2 +2C 4 +C 5 +3C 6 +2C 7 = 1.52 Count(a 5 )=C 1 +C 2 +C 3 +C 4 +C 5 +C 6 +C 7 = 1.00 New estimates: a 4 =.60 a 5 =.40 Count(a 4, a ) = C 2 +C 4 +C 5 +2C 6 +C 7 =.972 Count(a 4, b )=C 4 +C 6 +C 7 =.553 New estimates: p(a 4, a )=.64 p(a 4, b )=.36 Count(a 5, a ) = C 1 +C 2 +C 3 +C 4 +C 5 +2C 6 +C 7 = 1.0 Count(a 5, b )=0 New estimates: p(a 5, a )= 1.0 p(a 5, b )= 0 Speech Recognition Lecture 4: Hidden Markov Models 58

Problem 3: Enumerative Example cont d New parameters.46.71.29.68.32.34.20.60.64.36.40 1 0 Recompute Pr(X) =.02438 >.008632 Keep on repeating.. Speech Recognition Lecture 4: Hidden Markov Models 59

Problem 3: Enumerative Example cont d Step Pr(X) 1 0.008632 2 0.02438 3 0.02508 100 0.03125004 600 0.037037037 converged 0 1 1 0 2/3 1/2 1/2 0 Speech Recognition Lecture 4: Hidden Markov Models 60 1/3 1 0

Problem 3: Enumerative Example cont d Let s try a different initial parameter set Only change 1/3.6.4 ½ ½ 1/3 1/3 1/2 ½ ½ 1/2 ½ ½ Speech Recognition Lecture 4: Hidden Markov Models 61

Problem 3: Enumerative Example cont d Step Pr(X) 1 0.00914 2 0.02437 3 0.02507 10 0.04341 16 0.0625 converged 1 0 1/2 1/2 0 1 1/2 1 0 0 Speech Recognition Lecture 4: Hidden Markov Models 62 1/2 1 0

Problem 3: Parameter Estimation Performance The above re-estimation algorithm converges to a local maximum. The final solution depends on the starting point. The speed of convergence depends on the starting point. Speech Recognition Lecture 4: Hidden Markov Models 63

Problem 3: Forward-Backward Algorithm The forward-backward algorithm improves on the enumerative algorithm by using the trellis Instead of computing counts for each path, we compute counts for each transition at each time in the trellis. This results in the reduction from exponential computation to linear computation. Speech Recognition Lecture 4: Hidden Markov Models 64

Problem 3: Forward-Backward Algorithm Consider transition from state i to j, tr ij Let p t (tr ij,x) be the probability that tr ij is taken at time t, and the complete output is X. x t S i S j α t-1 (i) β t (j) p t (tr ij,x) = α t-1 (i) a ij b ij (x t ) β t (j) Speech Recognition Lecture 4: Hidden Markov Models 65

Problem 3: F-B algorithm cont d p t (tr ij,x) = α t-1 (i) a ij b ij (x t ) β t (j) where: α t-1 (i) = Pr(state=i, x 1 x t-1 ) = probability of being in state i and having produced x 1 x t-1 a ij = transition probability from state i to j b ij (x t ) = probability of output symbol x t along transition ij β t (j) = Pr(x t+1 x T state= j) = probability of producing x t+1 x T given you are in state j Speech Recognition Lecture 4: Hidden Markov Models 66

Problem 3: F-B algorithm cont d Transition count c t (tr ij X) = p t (tr ij,x) / Pr(X) The β s are computed recursively in a backward pass (analogous to the forward pass for the α s) β t (j) = Σ k β t+1 (k) a jk b jk (x t+1 ) (for all output producing arcs) + Σ k β t (k) a jk (for all null arcs) Speech Recognition Lecture 4: Hidden Markov Models 67

Problem 3: F-B algorithm cont d Let s return to our previous example, and work out the trellis calculations 1/3 1/2 ½ ½ 1/3 ½ ½ ½ ½ 1/3 1/2 ½ ½ Speech Recognition Lecture 4: Hidden Markov Models 68

Problem 3: F-B algorithm, cont d State: 1 2 3 Time: 0 1 2 3 4 Obs: φ a ab aba abaa 1/3x1/2 1/3x1/2 1/3x1/2 1/3x1/2 1/3x1/2 1/3x1/2 1/3x1/2 1/3x1/2 1/3 1/3 1/3 1/3 1/3 1/2x1/2 1/2x1/2 1/2x1/2 1/2x1/2 1/2x1/2 1/2x1/2 1/2x1/2 1/2x1/2 Speech Recognition Lecture 4: Hidden Markov Models 69

Problem 3: F-B algorithm, cont d Compute α s. since forced to end at state 3, α T =.008632=Pr(X) State: 1 2 3 Time: 0 1 2 3 4 Obs: φ a ab aba abaa 1/3x1/2 1/3x1/2 1/3x1/2 1/3x1/2 1.167.027.0046.00077.33 1/3x1/2 1/3x1/2 1/3x1/2 1/3x1/2 1/3 1/3 1/3 1/3 1/3 1/2x1/2 1/2x1/2 1/2x1/2 1/2x1/2.306.113.035.0097 1/2x1/2 1/2x1/2 1/2x1/2 1/2x1/2 0.083.076.028.008632 Speech Recognition Lecture 4: Hidden Markov Models 70

Problem 3: F-B algorithm, cont d Compute β s. State: 1 2 3 Time: 0 1 2 3 4 Obs: φ a ab aba abaa 1/3x1/2 1/3x1/2 1/3x1/2 1/3x1/2.0086.0039 1/3x1/2 1/3x1/2 1/3x1/2 1/3x1/2 1/3 1/3 1/3 1/3 1/3 1/2x1/2 1/2x1/2 1/2x1/2 1/2x1/2.016.0625.25 0 1/2x1/2.028 1/2x1/2.076 1/2x1/2.083 1/2x1/2 0 0 0 0 1 0 Speech Recognition Lecture 4: Hidden Markov Models 71

Problem 3: F-B algorithm, cont d Compute counts. (a posteriori probability of each transition) c t (tr ij X) = α t-1 (i) a ij b ij (x t ) β t (j)/ Pr(X) State: 1 2 3.167x.0625x.333x.5/.008632 Time: 0 1 2 3 4 Obs: φ a ab aba abaa.547.246.045 0.302.201.134.151.101.067.045 0.151.553.821 0 0 0 0 0 1 Speech Recognition Lecture 4: Hidden Markov Models 72

Problem 3: F-B algorithm cont d a 1 a 4 C(a 1 )=.547+.246+.045 C(a 2 )=.302+.201+.134 C(a 3 )=.151+.101+.067+.045 C(a 4 )=.151+.553+.821 C(a 5 )=1 a2 a 3 a5 C(a1, a )=.547+.045, C(a1, b )=.246 C(a2, a )=.302+.134, C(a2, b )=.201 C(a4, a )=.151+.821, C(a4, b )=.553 C(a5, a )=1, C(a5, b )=0 Speech Recognition Lecture 4: Hidden Markov Models 73

Remember our Enumerative a 1 Example? a2 a 4 a5 Let C i be the a posteriori probability of path i C i = pr(x,path i )/pr(x) a 3 C 1 =.045 C 2 =.067 C 3 =.134 C 4 =.100 C 5 =.201 C 6 =.150 C 7 =.301 Count(a 1 )= 3C 1 +2C 2 +2C 3 +C 4 +C 5 =.838 Count(a 2 )=C 3 +C 5 +C 7 =.637 Count(a 3 )=C 1 +C 2 +C 4 +C 6 =.363 New estimates: a 1 =.46 a 2 =.34 a 3 =.20 a1= C(a1)/{C(a1) + C(a2) + C(a3)} Count(a 1, a ) = 2C 1 +C 2 +C 3 +C 4 +C 5 =.592 Count(a 1, b )=C 1 +C 2 +C 3 =.246 New estimates: p(a 1, a )=.71 p(a 1, b )=.29 1 st term 2C1 because in abaa, last a by a5 so 2 a s in aba Speech Recognition Lecture 4: Hidden Markov Models 74

Problem 3: F-B algorithm cont d a 1 a 4 C(a 1 )=.547+.246+.045 = 0.838 C(a 2 )=.302+.201+.134 C(a 3 )=.151+.101+.067+.045 C(a 4 )=.151+.553+.821 C(a 5 )=1 a2 a 3 a5 C(a1, a )=.547+.045, C(a2, a )=.302+.134, C(a4, a )=.151+.821, C(a5, a )=1, =0.592 C(a1, b )=.246 C(a2, b )=.201 C(a4, b )=.553 C(a5, b )=0 Speech Recognition Lecture 4: Hidden Markov Models 75

Problem 3: F-B algorithm cont d Normalize counts to get new parameter values..46.71.29.68.32.34.20.60.64.36.40 1 0 Result is the same as from the enumerative algorithm!! Speech Recognition Lecture 4: Hidden Markov Models 76

Summary of Markov Modeling Basics Key idea 1: States for modeling sequences Markov introduced the idea of state to capture the dependence on the past (time evolution). A state embodies all the relevant information about the past. Each state represents an equivalence class of pasts that influence the future in the same manner. Key idea 2: Marginal probabilities To compute Pr(X), sum up over all of the state sequences than can produce X Pr(X) = Σ s Pr(X,S) For a given S, it is easy to compute Pr(X,S) Key idea 3: Trellis The trellis representation is a clever way to enumerate all sequences. It uses the Markov property to reduce exponential-time enumeration algorithms to linear-time trellis algorithms. Speech Recognition Lecture 4: Hidden Markov Models 77

Reference http://www.cs.jhu.edu/~jason/papers/#tnlp02 http://www.ee.columbia.edu/~stanchen/fall09/e6870/ Speech Recognition Lecture 4: Hidden Markov Models 78