1 / 27

CSCE833 Machine Learning

CSCE833 Machine Learning. Lecture 15 Hidden Markov Models Dr. Jianjun Hu mleg.cse.sc.edu/edu/csce833. University of South Carolina Department of Computer Science and Engineering. Outline. Evaluation problem of HMM Decoding problem of HMM Learning problem of HMM

maire
Download Presentation

CSCE833 Machine Learning

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSCE833 Machine Learning Lecture 15 Hidden Markov Models Dr. Jianjun Humleg.cse.sc.edu/edu/csce833 University of South Carolina Department of Computer Science and Engineering

  2. Outline • Evaluation problem of HMM • Decoding problem of HMM • Learning problem of HMM • A multi-million dollar algorithm—viterbi algorithm

  3. Main issues using HMMs : • Evaluation problem. Given the HMM M=(A, B, ) and the observation sequence O=o1 o2 ... oK , calculate the probability that model M has generated sequence O . • Decoding problem. Given the HMM M=(A, B, ) and the observation sequence O=o1 o2 ... oK , calculate the most likely sequence of hidden states si that produced this observation sequence O. • Learning problem. Given some training observation sequences O=o1 o2 ... oK and general structure of HMM (numbers of hidden and visible states), determine HMM parameters M=(A, B, ) that best fit training data. • O=o1...oK denotes a sequence of observations ok{v1,…,vM}.

  4. Word recognition example(1). Amherst a 0.5 0.03 b A c 0.005 0.31 z • Typed word recognition, assume all characters are separated. • Character recognizer outputs probability of the image being particular character, P(image|character). Hidden state Observation

  5. Word recognition example(2). m a m r t h e s Buffalo b u a o f f l A • If lexicon is given, we can construct separate HMM models for each lexicon word. Amherst 0.03 0.5 0.4 0.6 • Here recognition of word image is equivalent to the problem of evaluating few HMM models. • This is an application of Evaluation problem.

  6. Word recognition example(3). a b v f o m r t h e s • We can construct a single HMM for all words. • Hidden states = all characters in the alphabet. • Transition probabilities and initial probabilities are calculated from language model. • Observations and observation probabilities are as before. • Here we have to determine the best sequence of hidden states, the one that most likely produced word image. • This is an application of Decoding problem.

  7. Evaluation Problem. • Evaluation problem. Given the HMM M=(A, B, ) and the observation sequence O=o1 o2 ... oK , calculate the probability that model M has generated sequence O . • Trying to find probability of observations O=o1 o2 ... oK by means of considering all hidden state sequences (as was done in example) is impractical: • NK hidden state sequences - exponential complexity. • Use Forward-Backward HMM algorithms for efficient calculations. (Dynamic programming!) • Define the forward variable k(i) as the joint probability of the partial observation sequence o1 o2 ... ok and that the hidden state at time k is si : k(i)= P(o1 o2 ... ok , qk=si)

  8. Trellis representation of an HMM s1 sN s2 si sN s2 si s1 s1 s2 sj s1 s2 si sN sN o1 okok+1 oK = Observations a1j a2j aij aNj Time= 1 k k+1 K

  9. Forward recursion for HMM • Initialization: • 1(i)= P(o1 , q1=si) = ibi (o1) , 1<=i<=N. • Forward recursion: • k+1(i)= P(o1 o2 ... ok+1 , qk+1=sj) = • iP(o1 o2 ... ok+1 , qk=si, qk+1=sj) = • iP(o1 o2 ... ok , qk=si) aij bj (ok+1 ) = • [i k(i) aij ] bj (ok+1 ) , 1<=j<=N, 1<=k<=K-1. • Termination: • P(o1 o2 ... oK) = iP(o1 o2 ... oK , qK=si) = i K(i) • Complexity : • N2K operations.

  10. Trellis representation of an HMM s1 sN s2 si sN s2 sj s1 s1 s2 si s1 s2 si sN sN o1 okok+1 oK = Observations aj1 aj2 aji ajN Time= 1 k k+1 K

  11. Backward recursion for HMM • Define the forward variable k(i) as the joint probability of the partial observation sequence ok+1 ok+2 ... oK given that the hidden state at time k is si : k(i)= P(ok+1 ok+2 ... oK |qk=si) • Initialization: • K(i)= 1 , 1<=i<=N. • Backward recursion: • k(j)= P(ok+1 ok+2 ... oK |qk=sj) = • iP(ok+1 ok+2 ... oK , qk+1=si|qk=sj) = • iP(ok+2 ok+3 ... oK |qk+1=si) aji bi (ok+1 ) = • i k+1(i) aji bi (ok+1 ) , 1<=j<=N, 1<=k<=K-1. • Termination: • P(o1 o2 ... oK) = iP(o1 o2 ... oK , q1=si) = • iP(o1 o2 ... oK |q1=si) P(q1=si) = i 1(i) bi (o1) i

  12. Decoding problem • Decoding problem. Given the HMM M=(A, B, ) and the observation sequence O=o1 o2 ... oK , calculate the most likely sequence of hidden states si that produced this observation sequence. • We want to find the state sequence Q= q1…qK which maximizes P(Q | o1 o2 ... oK ) , or equivalently P(Q , o1 o2 ... oK ) . • Brute force consideration of all paths takes exponential time. Use efficient Viterbi algorithm instead. • Define variable k(i) as the maximum probability of producing observation sequence o1 o2 ... ok when moving along any hidden state sequence q1… qk-1 and getting into qk= si . • k(i) = max P(q1… qk-1 ,qk= si,o1 o2 ... ok) • where max is taken over all possible paths q1… qk-1 .

  13. Andrew Viterbi • In 1967 he invented the Viterbi algorithm, which he used for decoding convolutionally encoded data. It is still used widely in cellular phones for error correcting codes, as well as for speech recognition, DNA analysis, and many other applications of Hidden Markov models • In September 2008, he was awarded the National Medal of Science for developing "the 'Viterbi algorithm,' and for his contributions to Code Division Multiple Access (CDMA) wireless technology that transformed the theory and practice of digital communications."

  14. Viterbi algorithm (1) s1 si sN sj qk-1 qk a1j aij aNj • General idea: • if best path ending in qk= sjgoes through qk-1= sithen it should coincide with best path ending in qk-1= si. • k(i) = max P(q1… qk-1 ,qk= sj,o1 o2 ... ok) = • maxi [ aij bj (ok ) max P(q1… qk-1= si,o1 o2 ... ok-1) ] • To backtrack best path keep info that predecessor of sj was si.

  15. Viterbi algorithm (2) • Initialization: • 1(i) = max P(q1= si,o1) = ibi (o1) , 1<=i<=N. • Forward recursion: • k(j) = max P(q1… qk-1 ,qk= sj,o1 o2 ... ok) = • maxi [ aij bj (ok ) max P(q1… qk-1= si,o1 o2 ... ok-1) ]= • maxi [ aij bj (ok ) k-1(i) ] , 1<=j<=N, 2<=k<=K. • Termination: choose best path ending at time K • maxi [ K(i) ] • Backtrack best path. This algorithm is similar to the forward recursion of evaluation problem, with  replaced by max and additional backtracking.

  16. Learning problem (1) • Learning problem. Given some training observation sequences O=o1 o2 ... oK and general structure of HMM (numbers of hidden and visible states), determine HMM parameters M=(A, B, ) that best fit training data, that is maximizes P(O |M) . • There is no algorithm producing optimal parameter values.

  17. Learning problem (2) Number of times observation vm occurs in state si Number of times in state si bi(vm )= P(vm| si)= • If training data has information about sequence of hidden states (as in word recognition example), then use maximum likelihood estimation of parameters: • aij= P(si| sj) = Number of transitions from state sj to state si Number of transitions out of state sj The state sequence is generated by Viterbi algoritm

  18. Example: Training Unambiguous Models transitions emissions

  19. HMM Training Ambiguous Models • The Problem: • We have training sequences, but not the associated paths (state labels) • Two Solutions: • 1. Viterbi Training: Start with random HMM parameters. Use Viterbi to find the most probable path for each training sequence, and then label the sequence with that path. Use labeled sequence training on the resulting set of sequences and paths. • 2. Baum-Welch Training: sum over all possible paths (rather than the single most probable one) to estimate expected counts Ai,j and Ei,k; then use the same formulas as for labeled sequence training on these expected counts:

  20. Viterbi Training training features Labeled Sequence Trainer initial submodel M final submodel M* Viterbi Decoder Sequence Labeler labeled features paths {i} new submodel M repeat n times (iterate over the training sequences) (find most probable path for this sequence) (label the sequence with that path)

  21. Baum-Welch algorithm aij= P(si| sj) = Expected number of transitions from statesjto statesi Expected number of transitions out of statesj Expected number of times observationvmoccurs in statesi Expected number of times in statesi bi(vm )= P(vm| si)= i = P(si) = Expected frequency in statesiat time k=1. General idea:

  22. Trellis representation of an HMM s1 s2 si sN s1 s2 sN si s2 sN s1 s2 si sN s1 sj o1 okok+1 oK = Observations k+1(j) k(i) aij Time= 1 k k+1 K

  23. Baum-Welch algorithm: expectation step(1) • Define variable k(i,j) as the probability of being in state si at time k and in state sj at time k+1, given the observation sequence o1 o2 ... oK . • k(i,j)= P(qk= si,qk+1= sj|o1 o2 ... oK) P(qk= si,qk+1= sj,o1 o2 ... ok) P(o1 o2 ... ok) k(i,j)= = P(qk= si,o1 o2 ... ok) aij bj (ok+1 ) P(ok+2 ... oK |qk+1= sj) P(o1 o2 ... ok) = k(i)aij bj (ok+1 )k+1(j) i jk(i)aij bj (ok+1 )k+1(j)

  24. Baum-Welch algorithm: expectation step(2) k(i)k(i) i k(i)k(i) P(qk= si,o1 o2 ... ok) P(o1 o2 ... ok) k(i)= = • Define variable k(i) as the probability of being in state si at time k, given the observation sequence o1 o2 ... oK . • k(i)= P(qk= si|o1 o2 ... oK)

  25. Baum-Welch algorithm: expectation step(3) • We calculated k(i,j) = P(qk= si,qk+1= sj|o1 o2 ... oK) • and k(i)= P(qk= si|o1 o2 ... oK) • Expected number of transitions from state si to state sj = • = k k(i,j) • Expected number of transitions out of state si = k k(i) • Expected number of times observation vm occurs in state si = • = k k(i) , k is such that ok= vm • Expected frequency in state siat time k=1 : 1(i) .

  26. Baum-Welch algorithm: maximization step k k(i,j) k k(i) = Expected number of transitions from statesjto statesi Expected number of transitions out of statesj aij = k k(i,j) k,ok= vmk(i) Expected number of times observation vmoccurs in state si Expected number of times in state si bi(vm )= = i = (Expected frequency in statesiat time k=1) =1(i).

  27. Baum-Welch Training compute Fwd & Bkwd DP matrices accumulate expected counts for E & A

More Related