Professional Documents
Culture Documents
4-Hidden Markov Models
4-Hidden Markov Models
4-Hidden Markov Models
1~3, KAIST
2006 2 2 jyha@kangwon.ac.kr
Contents
Introduction Markov Model Hidden Markov model (HMM) Three algorithms of HMM
Model evaluation Most probable path decoding Model training
Pattern classification using HMMs HMM Applications and Software Summary References
A Tutorial on HMMs
Sequential Data
Examples
Speech data ( )
Handwriting data
A Tutorial on HMMs 3
A Tutorial on HMMs
Proven technology!
Successful stories in many applications
A Tutorial on HMMs
A Tutorial on HMMs
Whats HMM?
Hidden
Markov Model
What is hidden?
A Tutorial on HMMs
Markov Model
Scenario Graphical representation Definition Sequence probability State probability
8
A Tutorial on HMMs
By carefully examining the weather of some city for a long time, we found following weather change pattern
Tomorrow Rain/snow Today Rain/Snow Cloudy Sunny 0.4 0.2 0.1 Cloudy 0.3 0.6 0.1 Sunny 0.3 0.2 0.8
1: rain
2: cloudy
0.6
- Each state corresponds to one observation - Sum of outgoing edge weights is one
A Tutorial on HMMs 10
Observable states
2: cloudy
0.6
{1, 2 , L , N }
Observed sequence
q1 , q2 , L , qT
1st order Markov assumption
P ( qt = j | qt 1 = i, qt 2 = k , L) = P ( qt = j | qt 1 = i )
q1 q2
qt 1
qt
qt 1
qt
Stationary
A Tutorial on HMMs
P ( qt = j | qt 1 = i ) = P (qt +l = j | qt +l 1 = i )
11
2: cloudy
0.6
a11 a A = 21 M a N1
Where
a12 a 22 M a NN
L L M L
a1 N a2 N M a NN
aij = P (qt = j | qt 1 = i ),
1 i, j N
ij
With constraints
a ij 0,
Initial state probability
a
j =1
=1
= P ( q 1 = i ),
1 i N
12
A Tutorial on HMMs
P ( A, B ) = P ( A | B ) P ( B )
Sequence probability of Markov model
P (q1 , q2 , L , qT )
Chain rule
A Tutorial on HMMs
13
P ( qt = i )
O( N t )
P ( qt = i ) =
A Tutorial on HMMs
all Qt ( i )' s
P(Q (i))
t
15
a 1i
Each node stores the sum of probabilities of partial paths
P (qt = i) = = =
j =1
P ( q t 1 = j , q t = i )
j =1
P ( q t 1 = j ) P ( q t = i | q t 1 = j ) P ( q t 1 = j ) a
A Tutorial on HMMs
j =1
ji
Time complexity: O ( N 2t ) 16
Whats HMM?
Hidden
Markov Model
What is hidden?
A Tutorial on HMMs
17
A Tutorial on HMMs
A Tutorial on HMMs
19
P (s p iy iy iy ch ch ch ch ) = ? Method I
P(s) P( ) P(p) P(iy) P(ch )
3 3 4
A Tutorial on HMMs
20
P( xt | x1 x2 x3 L xt 1 ) = P ( xt | xt 1 )
|V||V| matrix model 5050 not very bad 105105 doubly outrageous!!
A Tutorial on HMMs
21
A Tutorial on HMMs
22
q 0 q1 q 2 L qT
P(s, q ) P(s, q
1 Q
| q1 ) P ( , q3 | q2 ) L P (ch, qT | qT 1 ) = P ( xt , qt | qt 1 )
Q t
A Tutorial on HMMs
23
qt S = {1, K, N }
N is also conjectured {qt:t0} is conjectured, not visible is Q = q1 q 2 L qT
is Markovian
A Tutorial on HMMs
24
= P (Q) P ( X | Q)
= P ( q1 q 2 L qT ) P ( x1 x 2 L xT | q1 q 2 L qT )
Q
= P(qt | qt 1 ) p( xt | qt )
Q t =1 t =1
Output process
A Tutorial on HMMs
25
is also called as
Hidden Markov chain Probabilistic function of Markov chain
A Tutorial on HMMs
26
P(Q | )P(X | Q, )
Q
27
Graphical Example
= [ 1.0 0 0 0 ] 0.6 1 0.4 0.5 2 p 0.5 0.7 3 0.3 1.0 4 ch 1 2 A= 3 4 1 2 B= 3 4
A Tutorial on HMMs
iypsch
iy
ch iy p
Data interpretation
P(s s p p iy iy iy ch ch ch|) = Q P(ssppiyiyiychchch,Q|) = Q P(Q|) p(ssppiyiyiychchch|Q,) Let Q = 1 1 2 2 3 3 3 4 4 4
0.6 0.0 0.0 0.0 0.2 0.0 0.0 0.6 0.4 0.5 0.0 0.0 0.2 0.2 0.8 0.0 0.0 0.5 0.7 0.0 0.0 0.0 0.3 1.0
Difficult problems
4. efficient computation methods 5. probability parameters ()
A Tutorial on HMMs
30
Factors
Pattern complexity/length and variability The number of samples
Ex:
rrgbbgbbbr
A Tutorial on HMMs
31
1 1 1 1 1 1 P(r r g b b g b b b r | 1 ) = 1 1 1 1 1 1 3 3 6 2 2 6 1 1 1 1 1 1 1 1 2 2 3 2
A Tutorial on HMMs
32
1 1 1 1 2 2 P(r r g b b g b b b r | 1 ) = .5 .6 .6 .4 .4 .6 2 2 3 3 3 3 2 2 2 1 .4 .4 .4 .6 + LL 3 3 3 2 =?
A Tutorial on HMMs 33
P( X | )
The best topology comes from insight and experience
the # classes/symbols/samples
A Tutorial on HMMs
35
A trained HMM
.5
1
.1 .2 .6 .5 2 .3 .4 .0 3 .3 .7
.4
R .6 G .2 B .2
=
1 2 3 1 2 3
1. 0. 0.
1 2 3
A=
.5 .4 .1 .0 .6 .4 .0 .0 .0
R G B
B=
.6 .2 .2 .2 .5 .3 .0 .3 .7
A Tutorial on HMMs
36
0.6
N pots containing color balls M distinct colors Each pot contains different number of color balls
A Tutorial on HMMs
37
We can just see the chosen balls We cant see which pot is selected at a time So, pot selection (state transition) information is hidden
A Tutorial on HMMs 39
V = { v1 , L , v M }
(3) A : State transition probability distribution
A = { a ij },
1 i, j N
B = { b i ( v k )},
1 i N ,1 j M
1 i N
= P ( q 1 = i ),
A Tutorial on HMMs
40
A Tutorial on HMMs
Definition
Given a model Observation sequence: X = x 1 , x 2 , L , x T P(X| ) = ? P(X | ) =
P ( X , Q | ) = P ( X | Q , ) P (Q | )
Q
x1 x2 x3 x4 x5 x6 x7 x8
A Tutorial on HMMs
43
Solution
Easy but slow solution: exhaustive enumeration
P(X | ) = =
P ( X , Q | ) = P ( X | Q , ) P (Q | )
Q
b
Q
q1
( x 1 ) b q 2 ( x 2 ) L b q T ( x T ) q 1 a q 1 q 2 a q 2 q 3 L a q T 1 q T
O(N T )
A Tutorial on HMMs
44
Forward Algorithm
Key idea
Span a lattice of N states and T times Keep the sum of probabilities of all the paths coming to each state i at time t
= t 1 (i )aij b j ( xt )
A Tutorial on HMMs
i =1
45
Forward Algorithm
Initialization 1 (i ) = i bi (x1 ) Induction
1 i N
t ( j ) = t 1 (i )aij b j (x t )
i =1
1 j N , t = 2, 3, L , T
Termination
P ( X | ) = T (i )
i =1 N
A Tutorial on HMMs
46
R .5.6
R .5.2
G .5.2
.6
.18
.018
.0018
.4.5 .6.5
.4.3 .6.3
.4
.1 .2 .5 .3 .0 .3 .7
.048 .0504 .01123 .1.0 .1.3 .1.7 .4.0 .4.3 .4.7 .0 .01116 .01537
0.0
.0
A Tutorial on HMMs
47
= P( xt +1 xt + 2 ...xT , Qt +1 = qt +1...qT | qt = Si , )
j =1 A Tutorial on HMMs
= aij b j ( xt +1 ) t +1 ( j )
48
T (i ) = 1
Induction
1 i N
t (i ) = aij b j (x t +1 ) t +1 ( j )
j =1
1 i N , t = T 1, T 2, L, 1
A Tutorial on HMMs
49
x1 x2 x3 x4 x5 x6 x7 x8
x1 x2 x3 x4 x5 x6 x7 x8
A Tutorial on HMMs
51
Viterbi Algorithm
Purpose
An analysis for internal processing result The best, the most likely state sequence Internal segmentation
Viterbi Algorithm
Alignment of observation and state transition Dynamic programming technique
A Tutorial on HMMs
52
1i N
t (1) a 1 j b j ( x t + 1 ) t ( i ) a ij b j ( x t + 1 )
A Tutorial on HMMs
53
Viterbi Algorithm
Introduction: Recursion:
1 j N
Termination:
Path backtracking:
1
qt = t +1 (qt+1 ), t = T 1, K ,1
states
2 3
A Tutorial on HMMs
54
R .5.6
R .5.2
G .5.2
.6
.18
.018
.0018
.4.5 .6.5
.4.3 .6.3
.4
.1 .2 .5 .3 .0 .3 .7
.048 .036 .00648 .1.0 .1.3 .1.7 .4.7 .4.0 .4.3 .0 .00576 .01008
0.0
.0
A Tutorial on HMMs
55
P(X | ) =
P ( X | Q , ) P ( Q | )
P(X|)
:HMM parameters
57
A Tutorial on HMMs
58
MLE Example
Scenario
Known: 3 balls inside pot (some red; some white) Unknown: R = # red balls Observation: (two reds)
Two models
P ( P (
2 1 |R=2) = 2 0
3 1 = 2 3
|R=3) =
3 2
3 =1 2
Which model?
A Tutorial on HMMs
ML method chooses the set of parameters that maximizes the likelihood of the given observation. It makes parameters maximally adapted to training data.
A Tutorial on HMMs
60
EM Algorithm for Training With ( t ) =< { a ij }, { b ik }, i > , estimate EXPECTATION of following quantities:
Expected number of state i visiting Expected number of transitions from i to j
A Tutorial on HMMs
62
A Tutorial on HMMs
63
T 1
t =1 T 1
t (i, j ) t (i)
t =1 s .t . x t = v k T
P(X|)
t =1
t ( j)
:HMM parameters
b j (vk ) =
= 1 (i)
t =1
t ( j)
( t +1)
) P( X | (t ) )
64
Other issues
Other method of training
MAP (Maximum A Posteriori) estimation for adaptation MMI (Maximum Mutual Information) estimation MDI (Minimum Discrimination Information) estimation Viterbi training Discriminant/reinforcement training
A Tutorial on HMMs
65
Semi-continuous HMM
Mix of CHMM and DHMM, using parameter sharing
State-duration HMM
More accurate temporal behavior
Other extensions
HMM+NN, Autoregressive HMM 2D models: MRF, Hidden Mesh model, pseudo-2D HMM
A Tutorial on HMMs
66
A Tutorial on HMMs
67
A Tutorial on HMMs
68
Pattern Classification
Construct one HMM per each class k
1 , L , N
Calculate model likelihood of 1 , L , N with observation X Forward algorithm: P ( X | k ) Find the model with maximum a posteriori probability
= argmax k
P( X ) = argmax k P(k ) P( X | k )
A Tutorial on HMMs 69
Transition-output HMM
HMM output functions are attached to transitions rather than states
A Tutorial on HMMs
70
V I = max log P ( X =1
*
| v ) log
P(X
w =1
| w )
Initial estimates
A, : adequate with random or uniform initial values B : good initial estimates are essential for CHMM
ergodic
A Tutorial on HMMs
left-right
parallel path
72
a b (x )
s , s +1 s s s =1 s =1
t 1
A Tutorial on HMMs
73
Methods
Heuristic methods
# of states from average (or mod) length of input frames
Split / merge
# of states from iterative split / merge
A Tutorial on HMMs
74
A Tutorial on HMMs
75
HMM Applications
On-line handwriting recognition
BongNet: HMM network-based handwriting recognition system
Speech applications
CMU Sphinx : Speech recognition toolkit Dr.Speaking : English pronunciation correction system
A Tutorial on HMMs
76
BongNet
Consortium of CAIR(Center for Artificial Intelligence Research) at KAIST
The name BongNet from its major inventor, BongKee Shin
Prominent performance for unconstrained on-line Hangul recognition Modeling of Hangul handwriting
considers ligature between letters as well as consonants and vowels
(initial consonant)+(ligature)+(vowel) (initial consonant)+(ligature)+(vowel)+(ligature)+(final consonant)
connects letter models and ligature models using Hangul composition principle further improvements
BongNet+ : incorporating structural information explicitly Circular BongNet : successive character recognition Unified BongNet : Hangul and alphanumeric recognition dictionary look-up
A Tutorial on HMMs
77
Network structure
A Tutorial on HMMs
78
A Modification to BongNet
16-dir Chaincode Structure Code Generation
Distance Rotation 18.213 45.934 41.238 45.796 18.299 16.531 45.957 52.815 26.917 53.588 56.840
Straightness 96.828 87.675 99.997 97.941 98.820 88.824 100.000 99.999 99.961 99.881 80.187
Direction 46.813 146.230 0.301 138.221 8.777 298.276 293.199 95.421 356.488 156.188 17.449 1 1 1 1 1 1 0 1 1 1 1
Real 1 1 0 1 0 -1 0 0 0 0 -1
3 37 0 37 0 31 54 11 28 15 5
A Tutorial on HMMs
79
Dr. Speaking
1 2 , ,
A Tutorial on HMMs
80
Feature Extraction & Acoustic Analysis Score Estimation
speech
Decoder
Acoustic Score
Evaluation Score
Target Speech DB spoken by Native Speaker Target Speech DB spoken by Non-native Speaker (mis-pronunciation)
A Tutorial on HMMs
81
Acoustic modeling
Native HMM Non-Native HMM
B C
standard
Language modeling
standard
error
error
: , , , , ,
A Tutorial on HMMs
83
1 - 2 - 3 - , ,
A Tutorial on HMMs 84
A Tutorial on HMMs
85
What is HTK ?
Hidden Markov Model Toolkit Set of tools for training and evaluation HMMs Primarily used in automatic speech recognition and economic modeling Modular implementation, (relatively) easy to extend
A Tutorial on HMMs
86
Designed to run with a traditional command-line style interface Each tool has a number of required argument plus optional arguments
HFoo -T 1 -f 34.3 -a -s myfile file1 file2
This tool has two main arguments called file1 and file2 plus four optional arguments -f : real number, -T : integer, -s : string, -a : no following value
HFoo -C config -f 34.3 -a -s myfile file1 file2
HFoo will load the parameters stored in the configuration file config during its initialization procedures Configuration parameters can sometimes by used as an alternative to using command line arguments
A Tutorial on HMMs 88
The Toolkit
There are 4 main phases
data preparation, training, testing and analysis
The Toolkit
Data Preparation Tools Training Tools Recognition Tools Analysis Tools
< HTK Processing Stages >
A Tutorial on HMMs 89
A Tutorial on HMMs
Training Tools
If there is some speech data available for which the location of the sub-word boundaries have been marked, this can be used as bootstrap data HInit and HRest provide isolated word style training using the fully labeled bootstrap data Each of the required HMMs is generated individually
A Tutorial on HMMs 91
A Tutorial on HMMs
92
Recognition Tools
HVite : use the token passing algorithm to perform Viterbi-based speech recognition HBuild : allow sub-networks to be created and used within higher level networks HParse : convert EBNF into the equivalent word network HSgen : compute the empirical perplexity of the task HDman : dictionary management tool
A Tutorial on HMMs
93
Analysis Tools
HResults
Use dynamic programming to align the two transcriptions and count substitution, deletion and insertion errors Provide speaker-by-speaker breakdowns, confusion matrices and time aligned transcriptions Compute Figure of Merit scores and Receiver Operation Curve information
A Tutorial on HMMs
94
HTK Example
Isolated word recognition
A Tutorial on HMMs
95
A Tutorial on HMMs
96
Recognizer
digit strings, limited set of names sub-word based
A Tutorial on HMMs
97
1> gram .
- gram grammar . ------------------------ gram -------------------------$digit = | | | | |..... | | ; $name = | | ..... | ; ( SENT-START ( <$digit> | $name) SENT-ENT ) -------------------------------------------------------$ . < > | or() . SENT-START SENT-END . 2> HParse gram wdnet . - HParse.exe gram wdnet .
A Tutorial on HMMs 98
3> dict
- . -------------------- dict -------------------------SENT-END[] sil SENT-START[] sil kc oxc ngc sp kc uxc sp .... jeoc ngc hc euic sp .... phc axc lc sp hc oxc chc uxc lc sp ---------------------------------------------------A Tutorial on HMMs 99
5> HSGen .
- HSLab
A Tutorial on HMMs
100
6> words.mlf .
- words.mlf . --------------------- words.mlf ---------------------#!MLF!# "*/s0001.lab" . #*/s0002.lab" . ..... ------------------------------------------------------
A Tutorial on HMMs
101
7> mkphones0.led
-mkphones0.led words.mlf . ------------- mkphones0.led ---------------EX IS sil sil DE sp ------------------------------------------- sil sp .
A Tutorial on HMMs
102
A Tutorial on HMMs
103
9> config
-config mfc . -------------- config --------------------TARGETKIND = MFCC_0 TARGETRATE = 100000.0 SOURCEFORMAT = NOHEAD SOURCERATE = 1250 WINDOWSIZE = 250000.0 ...... -------------------------------------------
A Tutorial on HMMs
104
10> codetr.scp
- *.mfc ------------- codetr.scp ----------------DB\s0001.wav DB\s0001.mfc DB\s0002.wav DB\s0002.mfc ... DB\s0010.wav DB\s0010.mfc ...... ------------------------------------------
A Tutorial on HMMs
105
A Tutorial on HMMs
106
13> config1
- HMM config MFCC_0 MFCC_0_D_A config1 .
A Tutorial on HMMs
107
vFloors ~o macros .
----------------- macros ----------------------~o <VecSize> 39 <MFCC_0_D_A> ~v "varFoorl" <Variance> 39 ... ----------------------------------------------Proto
Hmm0/vFloors
A Tutorial on HMMs
108
16> HVite -H hmm7/macros H hmm7/hmmdefs -S test.scp -l * -i recout.mlf -w wdnet -p 0.0 -s 5.0 dict monophones
A Tutorial on HMMs
109
A Tutorial on HMMs
110
Summary
Markov model
1-st order Markov assumption on state transition Visible: observation sequence determines state transition seq.
Acknowledgement
HMM , .
A Tutorial on HMMs
111
References
Hidden Markov Model
L.R. Rabiner, A Tutorial on Hidden Markov Models and Selected Applications in Speech Recognition, IEEE Proc. pp. 267-295, 1989. L.R. Bahl et. al, A Maximum Likelihood Approach to Continuous Speech Recognition, IEEE PAMI, pp. 179-190, May. 1983. M. Ostendorf, From HMMs to Segment Models: a Unified View of Stochastic Modeling for Speech Recognition, IEEE SPA, pp 360-378, Sep., 1996.
HMM Tutorials
, HMM Theory and Applications, 2003
.
, ILVB Tutorial, 2005.04.16, . Sam Roweis, Hidden Markov Models (SCIA Tutorial 2003), http://www.cs.toronto.edu/~roweis/notes/scia03h.pdf Andrew Moore, Hidden Markov Models, http://www-2.cs.cmu.edu/~awm/tutorials/hmm.html
A Tutorial on HMMs 112
References (Cont.)
HMM Applications
B.-K. Sin, J.-Y. Ha, S.-C. Oh, Jin H. Kim, Network-Based Approach to Online Cursive Script Recognition, IEEE Transactions on Systems Man and Cybernetics Part B-Cybernetics, Vol. 29, No. 2, pp.321-328, 1999. J.-Y. Ha, "Structure Code for HMM Network-Based Hangul Recognition", 18th International Conference on Computer Processing of Oriental Languages, pp.165-170, 1999. , , , , , , , , 46, pp.87-102, 2003.
HMM Software
Kevin Murphy, HMM toolbox for Matlab, freely downloadable SW written in Matlab, http://www.cs.ubc.ca/~murphyk/Software/HMM/hmm.html Speech Vision and Robotics Group of Cambridge University, HTK (Hidden Markov toolkit), freely downloadable SW written in C, http://htk.eng.cam.ac.uk/ Sphinx at CMU http://cmusphinx.sourceforge.net/html/cmusphinx.php 113
A Tutorial on HMMs