Hassanin M. Al-Barhamtoshy

Slides:



Advertisements
Similar presentations
Angelo Dalli Department of Intelligent Computing Systems
Advertisements

Russell and Norvig, AIMA : Chapter 15 Part B – 15.3,
Introduction to Hidden Markov Models
Hidden Markov Models Eine Einführung.
Hidden Markov Models Bonnie Dorr Christof Monz CMSC 723: Introduction to Computational Linguistics Lecture 5 October 6, 2004.
 CpG is a pair of nucleotides C and G, appearing successively, in this order, along one DNA strand.  CpG islands are particular short subsequences in.
Page 1 Hidden Markov Models for Automatic Speech Recognition Dr. Mike Johnson Marquette University, EECE Dept.
Hidden Markov Models Adapted from Dr Catherine Sweeney-Reed’s slides.
Ch 9. Markov Models 고려대학교 자연어처리연구실 한 경 수
Statistical NLP: Lecture 11
Ch-9: Markov Models Prepared by Qaiser Abbas ( )
Hidden Markov Models Theory By Johan Walters (SR 2003)
Statistical NLP: Hidden Markov Models Updated 8/12/2005.
1 Hidden Markov Models (HMMs) Probabilistic Automata Ubiquitous in Speech/Speaker Recognition/Verification Suitable for modelling phenomena which are dynamic.
Hidden Markov Models Fundamentals and applications to bioinformatics.
Hidden Markov Models in NLP
Lecture 15 Hidden Markov Models Dr. Jianjun Hu mleg.cse.sc.edu/edu/csce833 CSCE833 Machine Learning University of South Carolina Department of Computer.
Apaydin slides with a several modifications and additions by Christoph Eick.
INTRODUCTION TO Machine Learning 3rd Edition
Part II. Statistical NLP Advanced Artificial Intelligence (Hidden) Markov Models Wolfram Burgard, Luc De Raedt, Bernhard Nebel, Lars Schmidt-Thieme Most.
Part II. Statistical NLP Advanced Artificial Intelligence Hidden Markov Models Wolfram Burgard, Luc De Raedt, Bernhard Nebel, Lars Schmidt-Thieme Most.
ETHEM ALPAYDIN © The MIT Press, Lecture Slides for.
HMM-BASED PATTERN DETECTION. Outline  Markov Process  Hidden Markov Models Elements Basic Problems Evaluation Optimization Training Implementation 2-D.
Part 4 b Forward-Backward Algorithm & Viterbi Algorithm CSE717, SPRING 2008 CUBS, Univ at Buffalo.
Hidden Markov Models K 1 … 2. Outline Hidden Markov Models – Formalism The Three Basic Problems of HMMs Solutions Applications of HMMs for Automatic Speech.
1 Hidden Markov Model Instructor : Saeed Shiry  CHAPTER 13 ETHEM ALPAYDIN © The MIT Press, 2004.
Hidden Markov Models David Meir Blei November 1, 1999.
Hidden Markov Models 戴玉書
INTRODUCTION TO Machine Learning ETHEM ALPAYDIN © The MIT Press, Lecture Slides for.
Fall 2001 EE669: Natural Language Processing 1 Lecture 9: Hidden Markov Models (HMMs) (Chapter 9 of Manning and Schutze) Dr. Mary P. Harper ECE, Purdue.
Visual Recognition Tutorial1 Markov models Hidden Markov models Forward/Backward algorithm Viterbi algorithm Baum-Welch estimation algorithm Hidden.
ETHEM ALPAYDIN © The MIT Press, Lecture Slides for.
Ch10 HMM Model 10.1 Discrete-Time Markov Process 10.2 Hidden Markov Models 10.3 The three Basic Problems for HMMS and the solutions 10.4 Types of HMMS.
THE HIDDEN MARKOV MODEL (HMM)
7-Speech Recognition Speech Recognition Concepts
Fundamentals of Hidden Markov Model Mehmet Yunus Dönmez.
1 HMM - Part 2 Review of the last lecture The EM algorithm Continuous density HMM.
Sequence Models With slides by me, Joshua Goodman, Fei Xia.
Hidden Markov Models & POS Tagging Corpora and Statistical Methods Lecture 9.
1 Hidden Markov Model Observation : O1,O2,... States in time : q1, q2,... All states : s1, s2,... Si Sj.
Dongfang Xu School of Information
Hidden Markov Models (HMMs) –probabilistic models for learning patterns in sequences (e.g. DNA, speech, weather, cards...) (2 nd order model)
1 Hidden Markov Models Hsin-min Wang References: 1.L. R. Rabiner and B. H. Juang, (1993) Fundamentals of Speech Recognition, Chapter.
1 Hidden Markov Model Observation : O1,O2,... States in time : q1, q2,... All states : s1, s2,..., sN Si Sj.
CPSC 7373: Artificial Intelligence Lecture 12: Hidden Markov Models and Filters Jiang Bian, Fall 2012 University of Arkansas at Little Rock.
Hidden Markov Model Parameter Estimation BMI/CS 576 Colin Dewey Fall 2015.
Data-Intensive Computing with MapReduce Jimmy Lin University of Maryland Thursday, March 14, 2013 Session 8: Sequence Labeling This work is licensed under.
Definition of the Hidden Markov Model A Seminar Speech Recognition presentation A Seminar Speech Recognition presentation October 24 th 2002 Pieter Bas.
Visual Recognition Tutorial1 Markov models Hidden Markov models Forward/Backward algorithm Viterbi algorithm Baum-Welch estimation algorithm Hidden.
Hidden Markov Models HMM Hassanin M. Al-Barhamtoshy
MACHINE LEARNING 16. HMM. Introduction Lecture Notes for E Alpaydın 2004 Introduction to Machine Learning © The MIT Press (V1.1) 2  Modeling dependencies.
Hidden Markov Models BMI/CS 576
CS 224S / LINGUIST 285 Spoken Language Processing
Learning, Uncertainty, and Information: Learning Parameters
CSCE 771 Natural Language Processing
Statistical Models for Automatic Speech Recognition
An INTRODUCTION TO HIDDEN MARKOV MODEL
CHAPTER 15: Hidden Markov Models
Hidden Markov Models - Training
CSC 594 Topics in AI – Natural Language Processing
Hidden Markov Models Part 2: Algorithms
CHAPTER 15: Hidden Markov Models
Hidden Markov Model LR Rabiner
4.0 More about Hidden Markov Models
CONTEXT DEPENDENT CLASSIFICATION
Speech Processing Speech Recognition
Handwritten Characters Recognition Based on an HMM Model
Introduction to HMM (cont)
Hidden Markov Models By Manish Shrivastava.
Non-Standard-Datenbanken
Presentation transcript:

Hassanin M. Al-Barhamtoshy Hidden Markov Models HMM Hassanin M. Al-Barhamtoshy hassanin@kau.edu.sa

Agenda Markov Models Description: What is HMM HMM Applications Demonstration

Markov Models Set of states or number of states : Q = {q1; q2; : : : ; qT} Process moves from one state to another generating a sequence of states : Markov chain property: probability of each subsequent state depends only on what was the previous state: To define Markov model, the following probabilities have to be specified: transition probabilities and initial probabilities

Example 1 of Markov Model Rain Dry 0.7 0.3 0.2 0.8 Two states : ‘Rain’ and ‘Dry’. Transition probabilities: P(‘Rain’ | ‘Rain’) = 0.3 , P(‘Dry’ | ‘Rain’) = 0.7, P(‘Rain’ | ‘Dry’) = 0.2 , P(‘Dry’ | ‘Dry’) = 0.8 Initial probabilities: say P(‘Rain’) = 0.4 , P(‘Dry’) = 0.6 .

Calculation of Sequence probability By Markov chain property, probability of state sequence can be found by the formula: Suppose we want to calculate a probability of a sequence of states in our example, {‘Dry’, ’Dry’, ’Rain’, ‘Rain’}. P({‘Dry’, ’Dry’, ’Rain’, ‘Rain’} ) = P(‘Rain’|’Rain’) P(‘Rain’|’Dry’) P(‘Dry’|’Dry’) P(‘Dry’) = 0.3 x 0.2 x 0.8 x 0.6 Rain Dry 0.7 0.3 0.2 0.8

What is an HMM? Graphical Model Circles indicate states Arrows indicate probabilistic dependencies between states

What is an HMM? Green circles are hidden states Dependent only on the previous state

What is an HMM? Purple nodes are observed states Dependent only on their corresponding hidden state

HMM Formalism S S S S S K K K K K { S, K, P, A, B } S : {s1…sN } are the values for the hidden states K : {k1…kM } are the values for the observations

HMM Formalism A A A A S S S S S B B B K K K K K {S, K, P, A, B} P = {pi} are the initial state probabilities A = {aij} are the state transition probabilities B = {bik} are the observation state probabilities

Inference in an HMM Compute the probability of a given observation sequence Given an observation sequence, compute the most likely hidden state sequence Given an observation sequence and set of possible models, which model most closely fits the data?

Decoding oT o1 ot-1 ot ot+1 Given an observation sequence and a model, compute the probability of the observation sequence

Decoding oT o1 ot ot-1 ot+1 x1 xt+1 xT xt xt-1

Decoding oT o1 ot ot-1 ot+1 x1 xt+1 xT xt xt-1

Decoding oT o1 ot ot-1 ot+1 x1 xt+1 xT xt xt-1

Decoding oT o1 ot ot-1 ot+1 x1 xt+1 xT xt xt-1

Decoding oT o1 ot ot-1 ot+1 x1 xt+1 xT xt xt-1

Forward Procedure oT o1 ot ot-1 ot+1 x1 xt+1 xT xt xt-1 Special structure gives us an efficient solution using dynamic programming. Intuition: Probability of the first t observations is the same for all possible t+1 length state sequences. Define:

Forward Procedure oT o1 ot ot-1 ot+1 x1 xt+1 xT xt xt-1

Forward Procedure oT o1 ot ot-1 ot+1 x1 xt+1 xT xt xt-1

Forward Procedure oT o1 ot ot-1 ot+1 x1 xt+1 xT xt xt-1

Forward Procedure oT o1 ot ot-1 ot+1 x1 xt+1 xT xt xt-1

Forward Procedure oT o1 ot ot-1 ot+1 x1 xt+1 xT xt xt-1

Forward Procedure oT o1 ot ot-1 ot+1 x1 xt+1 xT xt xt-1

Forward Procedure oT o1 ot ot-1 ot+1 x1 xt+1 xT xt xt-1

Forward Procedure oT o1 ot ot-1 ot+1 x1 xt+1 xT xt xt-1

Backward Procedure x1 xt-1 xt xt+1 xT o1 ot-1 ot ot+1 oT Probability of the rest of the states given the first state

Decoding Solution Forward Procedure Backward Procedure Combination x1 xt-1 xt xt+1 xT o1 ot-1 ot ot+1 oT Forward Procedure Backward Procedure Combination

Best State Sequence oT o1 ot ot-1 ot+1 Find the state sequence that best explains the observations Viterbi algorithm

Viterbi Algorithm x1 xt-1 j o1 ot-1 ot ot+1 oT The state sequence which maximizes the probability of seeing the observations to time t-1, landing in state j, and seeing the observation at time t

Viterbi Algorithm Recursive Computation oT o1 ot ot-1 ot+1 x1 xt-1 xt

Viterbi Algorithm oT o1 ot ot-1 ot+1 x1 xt-1 xt xt+1 xT Compute the most likely state sequence by working backwards

Parameter Estimation A A A A oT o1 ot ot-1 ot+1 x1 xt-1 xT B B B B B Given an observation sequence, find the model that is most likely to produce that sequence. No analytic method Given a model and observation sequence, update the model parameters to better fit the observations.

Parameter Estimation Probability of traversing an arc oT o1 ot ot-1 ot+1 B B B B B Probability of traversing an arc Probability of being in state i

Parameter Estimation A A A A oT o1 ot ot-1 ot+1 B B B B B Now we can compute the new estimates of the model parameters.

HMM Applications Generating parameters for n-gram models Tagging speech Speech recognition

The Most Important Thing oT o1 ot ot-1 ot+1 B B B B B We can use the special structure of this model to do a lot of neat math and solve problems that are otherwise not solvable.

Remember: Hidden Markov Models. Set of states: Process moves from one state to another generating a sequence of states : Markov chain property: probability of each subsequent state depends only on what was the previous state: States are not visible, but each state randomly generates one of M observations (or visible states) To define hidden Markov model, the following probabilities have to be specified: matrix of transition probabilities A=(aij), aij= P(si | sj) , matrix of observation probabilities B=(bi (vm )), bi(vm ) = P(vm | si) and a vector of initial probabilities =(i), i = P(si) . Model is represented by M=(A, B, ).

Example of Hidden Markov Model Low High 0.7 0.3 0.2 0.8 Dry Rain 0.6 0.4

Example of Hidden Markov Model Low High 0.7 0.3 0.2 0.8 Dry Rain 0.6 0.4 Two states : ‘Low’ and ‘High’ atmospheric pressure. Two observations : ‘Rain’ and ‘Dry’. Transition probabilities: P(‘Low’|‘Low’)=0.3 , P(‘High’|‘Low’)=0.7 , P(‘Low’|‘High’)=0.2, P(‘High’|‘High’)=0.8 Observation probabilities: P(‘Rain’|‘Low’)= 0.6, P(‘Dry’|‘Low’)= 0.4 , P(‘Rain’|‘High’)= 0.4 , P(‘Dry’|‘High’)= 0.3 . Initial probabilities: say P(‘Low’)=0.4 , P(‘High’)=0.6 .

Calculation of observation sequence probability Low High 0.7 0.3 0.2 0.8 Dry Rain 0.6 0.4 A oT o1 ot ot-1 ot+1 A A A x1 Xt-1 xT B B B B B Suppose we want to calculate a probability of a sequence of observations in our example, {‘Dry’, ’Rain’}. Consider all possible hidden state sequences: P({‘Dry’,’Rain’} ) = P({‘Dry’,’Rain’} , {‘Low’,’Low’}) + P({‘Dry’,’Rain’} , {‘Low’,’High’}) + P({‘Dry’,’Rain’} , {‘High’,’Low’}) + P({‘Dry’,’Rain’} , {‘High’,’High’}) where first term is : P({‘Dry’,’Rain’} , {‘Low’,’Low’}) = P({‘Dry’,’Rain’} | {‘Low’,’Low’}) P({‘Low’,’Low’}) = P(‘Dry’|’Low’)P(‘Rain’|’Low’) P(‘Low’)P(‘Low’|’Low) = 0.4*0.6*0.4*0.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}.

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

Word Recognition example(2). Hidden states of HMM = characters. Observations = typed images of characters segmented from the image . Note that there is an infinite number of observations Observation probabilities = character recognizer scores. Transition probabilities will be defined differently in two subsequent models.

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

Word Recognition example(4). 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. m r a f t o v b h e s 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.

Character Recognition with HMM example. The structure of hidden states is chosen. Observations are feature vectors extracted from vertical slices. A Probabilistic mapping from hidden state to feature vectors: 1. Use mixture of Gaussian models 2. Quantize feature vector space.

Exercise: Character Recognition with HMM(1) The structure of hidden states: s1 s2 s3 Observation = number of islands in the vertical slice. A HMM for character ‘A’ : Transition probabilities: {aij} = Observation probabilities: {bjk}=  .8 .2 0   0 .8 .2   0 0 1   .9 .1 0   .1 .8 .1   .9 .1 0  HMM for character ‘B’ : Transition probabilities: {aij} = Observation probabilities: {bjk}=  .8 .2 0   0 .8 .2   0 0 1  B  .9 .1 0   0 .2 .8   .6 .4 0 

Exercise: Character Recognition with HMM(2) Suppose that after character image segmentation the following sequence of island numbers in 4 slices was observed: { 1, 3, 2, 1} What HMM is more likely to generate this observation sequence , HMM for ‘A’ or HMM for ‘B’ ?

Exercise: Character Recognition with HMM(3) Consider likelihood of generating given observation for each possible sequence of hidden states:  .8 .2 0   0 .8 .2   0 0 1   .9 .1 0   .1 .8 .1   .9 .1 0  HMM for character ‘A’: Hidden state sequence Transition probabilities Observation probabilities s1 s1 s2s3 .8  .2  .2  .9  0  .8  .9 = 0 s1 s2 s2s3 .2  .8  .2  .9  .1  .8  .9 = 0.0020736 s1 s2 s3s3 .2  .2  1  .9  .1  .1  .9 = 0.000324 Total = 0.0023976 HMM for character ‘B’: Hidden state sequence Transition probabilities Observation probabilities s1 s1 s2s3 .8  .2  .2  .9  0  .2  .6 = 0 s1 s2 s2s3 .2  .8  .2  .9  .8  .2  .6 = 0.0027648 s1 s2 s3s3 .2  .2  1  .9  .8  .4  .6 = 0.006912 Total = 0.0096768

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. 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 )

Lattice Representation of an HMM o1 ok ok+1 oK = Observations s1 s2 si sN s1 s2 si sN s1 s2 sj sN s1 s2 si sN a1j a2j aij aNj Time= 1 k k+1 K

Forward Recursion for HMM Initialization: 1(i)= P(o1 , q1= si ) = i bi (o1) , 1<=i<=N. Forward recursion: k+1(i)= P(o1 o2 ... ok+1 , qk+1= sj ) = i P(o1 o2 ... ok+1 , qk= si , qk+1= sj ) = i P(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) = i P(o1 o2 ... oK , qK= si) = i K(i) Complexity : N2K operations.

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 ) = i P(ok+1 ok+2 ... oK , qk+1= si | qk= sj ) = i P(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) = i P(o1 o2 ... oK , q1= si) = i P(o1 o2 ... oK |q1= si) P(q1= si) = i 1(i) bi (o1) i

Decoding Problem where max is taken over all possible paths q1… qk-1 . 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 .

Specification of an HMM Description Specification of an HMM N - number of states Q = {q1; q2; : : : ; qT} - set of states M - the number of symbols (observables) O = {o1; o2; : : : ;oT} - set of symbols

Specification of an HMM A - the state transition probability matrix aij = P(qt+1 = j | qt = i) B- observation probability distribution bj(k) = P(ot = k | qt = j) i ≤ k ≤ M π - the initial state distribution Full HMM is thus specified as a triplet: λ = (A , B , π)

Central problems in HMM modelling Evaluation: Probability of occurrence of a particular observation sequence, O = {o1,…,ok}, given the model P(O|λ) Complicated – hidden states Useful in sequence classification

Central problems in HMM modelling Decoding: Optimal state sequence to produce given observations, O = {o1,…,ok}, given model Optimality criterion Useful in recognition problems

Central problems in HMM modelling Learning: Determine optimum model, given a training set of observations Find λ, such that P(O|λ) is maximal

Viterbi Algorithm (1) s1 si sj sN General idea: if best path ending in qk= sj goes through qk-1= si then it should coincide with best path ending in qk-1= si . s1 si sN sj aij aNj a1j qk-1 qk 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.

Viterbi algorithm (2) Initialization: 1(i) = max P(q1= si , o1) = i bi (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.

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. Use iterative expectation-maximization algorithm to find local maximum of P(O | M) - Baum-Welch algorithm.

Learning Problem (2) 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 bi(vm ) = P(vm | si)= Number of times observation vm occurs in state si Number of times in state si