10. hidden markov models (hmm) for speech processing · 2015-08-25 · the viterbi algorithm • it...

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

Upload: others

Post on 12-Jan-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

10. Hidden Markov Models (HMM) for Speech Processing

(some slides taken from Glass and Zue course)

Page 2: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

Definition of an HMM

•  The HMM are powerful statistical methods to characterize the observed samples of a discrete-time series.

•  The data samples in the time series can be discretely or continuously distributed, scalars or vectors.

•  The basic HMM theory was published in a set of papers by Baum et al. around 1967.

•  The HMMs derive from the (simpler) Markov chains

Page 3: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

Markov Chains •  Markov chain is a discrete (discrete-time) random process with the

Markov property. •  It is a discrete-time random process because it is in a discrete state

(from among a finite number of possible states) at each “step”. •  The Markov property states that the probability of being in any

particular state only depends on the previous state it was at before.

•  Then, at every state, a given observable event is produced (knowing the state we are at, we know the event)

Page 4: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

Markov chain= first order markov model Markov chain = “First-order observable Markov Model”

•! a set of states !! Q = q1, q2…qN; the state at time t is qt

•! Transition probabilities:

!! a set of probabilities A = a01a02…an1…ann.

!! Each aij represents the probability of transitioning

from state i to state j

!! The set of these is the transition probability matrix A

•! Distinguished start and end states !

aij = P(qt = j |qt"1 = i) 1# i, j # N

!

aij =1; 1" i " Nj=1

N

#Markov chain = “First-order observable Markov Model”

•! Current state only depends on previous state

!

Markov Assumption : P(qi |q1...qi"1) = P(qi |qi"1)

Page 5: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

Different types of HMM Different types of HMM

structure

Bakis = left-to-right Ergodic =

fully-connected

Page 6: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

Example: markov chain for the weather Markov chain for weather

Page 7: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

From Markov chains to HMM

•  While in a Markov chain the output in each state is known, in an HMM each state incorporates a probabilistic function to generate the output.

•  An HMM can be thought of a double stochastic process (state sequence + output in each state), where the state sequence being not directly observable -> it is therefore hidden

•  The output in each state can either be one from a discrete number of options (with a probability associated to each option) or a continuous value/vector (with a probability density function associated to it).

Page 8: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

TDP: HMM 8

HMM Example: The Urn and Ball Model

An N-state urn and ball model illustrates the general case of a discrete symbol HMM. HMM observable output: sequence of colours which we would like to model

Page 9: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

TDP: HMM 9

Elements of a discrete HMM

  N : number of states of the model (number of urns)   S = {S1, S2, …, SN } : individual states   qt : state at time t

  M : number of observation symbols (in the case of a discrete alphabet size). (number of colors of balls)

  V = {V1, V2, …, VM } : individual symbols   A = {aij} : state transition probability distribution (NxN matrix)

  B = {bj(k)} : observation symbol probability distribution in state j (MxN matrix)

  π = {πi} : initial state distribution

An HMM is typically written as:

Page 10: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

TDP: HMM 10

Statistical modeling of nonstationary processes such as speech or the singing voice. A HMM consists of a number of states. Each state has an associated observation probability distribution which determines the probability of generating an observation at a given time and each pair of states has an associated transition probability.

Phoneme k-1 Phoneme k Phoneme k+1

HMM Example for continuous observations: Speech

Page 11: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

Phonetic modeling

HMMs for speech

Each phone has 3 subphones

!"#$

%&&

'()& *"+,-.%/.01#+2

%,, %$$

%0& %&, %,$ %$2

Resulting HMM word model for “six”

!"#

!"$

!"%

&'()' *+,-#

-$

-%

.#

.$

.%

-#

-$

-%

Page 12: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

TDP: HMM 12

The three basic problems for HMMs 1.   Scoring: Given the observation sequence O = (o1 o2 … oT), and a model

λ=(A,B, π), how do we efficiently compute P(O| λ), the probability of the observation sequence, given the model?

SOLUTION-> The Forward Algorithm

2. Matching/Decoding: Given the observation sequence O = O1 O2 … OT, and a model λ, how do we choose a corresponding state sequence Q = (q1 q2 … qT) which is optimal in some meaningful sense (i.e., best “explains” the observations)?

SOLUTION-> The Viterbi Algorithm

3. Training: How do we adjust the model parameters model λ=(A,B, π) to maximize P(O| λ)?

SOLUTION-> The Baum-Welch Re-estimation Procedures (also known as the forward-backward algorithm)

Page 13: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

!"#$%%&'' (

!"#$%&'()*(+,#"-./

!"#$%&'#'(#)%*)+*%'"#,-./#01#-23(4%45*5'6#(7#'8"#(49"3:%'5(&9#

9";+"&)"#.#<#.!".##=#.$>#?5:"&#'8"#@(A"*#01B#C8"#@(9'#

9'3%5?8'7(3$%3A#$%6#(7#A(5&?#5'#59#'83(+?8#"&+@"3%'5&?#":"36#

2(9954*"#9'%'"#9";+"&)"#(7#*"&?'8#CD##E#<#;!";##=#;$

! !""#$#$%&%%!

&

! !"%"'% $#$

%('!

!"!$ )('"

!""$###('&!"& $

!"#$%&'()(*+*,-$'.$/01"$)$/,),#$/#20#31#$4$1)3$(#$5&*,,#3$)/

! !#"#$%''!

*'!'"

*'"'$

###*'&(!

'&

!"#$6'*3$%&'()(*+*,-$,"),$7$)38$4$'110&&#$/*90+,)3#'0/+-$*/

! !"$#"#$%! !""#$#$! !#$#$)38

! !""#$%)*++#

! !""#$#$! !#$#$

% )'!%'"%### $'&

''!

('!

!"!$*'!'"

('"

!""$ ###*'&(!'&('&

!"& $

Page 14: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

TDP: HMM 14

Problem 1: Interpretation of the computation

  Initially (at time t = 1) we are in state q1 with probability πq1, and generate the symbol O1 (in this state) with probability bq1 (O1).

  The clock changes from time t to t +1 (t=2) and we make a

transition to state q2 from state q1 with probability aq1 q2 , and generate symbol O2 with probability bq2 (O2).

  This process continues in this manner until we make the list

transition (at time T) from state qT-1 to state qT with probability aqT-1 qT and generate symbol OT with probability bqT (OT).

Page 15: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

TDP: HMM 15

Problem 1: Interpretation of the computation

  Computationally very expensive: 2 T * NT calculations (every time t=1..T there are N possible states that can be

reached) So, there are NT possible states sequences!   For each term in the sum of P(O| λ) we have 2T calculations   (2T - 1)NT multiplications and NT – 1 additions   This is computationally unfeasible. One solution:

  The Forward algorithm

Page 16: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

The forward algorithm

•  In order to save computation in computing the probability of a given observation sequence we store intermediate results and use them for subsequence calculations.

•  A partial forward probability is defined as

the probability that the HMM is in state “i” at time “t” having generates the partial sequence of observations O1

t={o1, …, ot} •  Given the Markov assumptions, this partial probability on a

given “t” only depends on the probabilities at time “t-1”. It can therefore be computed recursively from time 1 to time T

•  One can prove that the total complexity is O(N2T)

!t (i) = P(O1t,qt = i | ")

Page 17: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

The forward algorithm

The steps in the algorithm are: 1.  Initialization

2.  Induction

3.  Termination

!1(i) = " ibi (o1) 1! i ! N

!t ( j) = !t!1(i)aiji=1

N

"#

$%

&

'(bj (ot ) 2 ) t ) T;1) j ) N

P(O | !) = "T (i)i=1

N

!

Page 18: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

TDP: HMM 18

The forward algorithm The forward probability calculation is based on a Trellis structure,

as shows this figure:

Page 19: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

TDP: HMM 19

Problem 2: Matching/decoding

  Given the observation sequence O = o1 o2 … oT, and a model λ, how do we choose a corresponding state sequence Q = q1 q2 … qT which is optimal in some meaningful sense (i.e., best “explains” the observations)? i.e. maximizes P(Q, O|λ)

  The forward algorithm provides the total probability through all paths, but not the optimum path sequence

  Several alternative solutions can be proposed, although they are not ensured to reach the optimal solution (which would be to evaluate the probability of ALL possible state sequences and choose the best)

  One possible optimal criterion is to choose the states qt which are individually most likely.   This optimality criterion maximizes the expected number of correct

individual states.   It very easily reaches suboptimal global solutions

  Another possible criterion is to maximize with respect to the whole sequence -> Viterbi algorithm

Page 20: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

The Viterbi Algorithm

•  It is a dynamic programming algorithm for finding the most likely sequence of hidden states – called the Viterbi path – that results in a sequence of observed events.

•  Proposed in 1967 by Andrew Viterbi as a decoding algorithm for convolutional codes over noisy digital communication links.

•  The algorithm makes 3 assumptions: •  Both observed events and hidden events must be in a sequence (for example

temporal sequence). •  One instance of an observed event corresponds to an instance of a hidden

event. •  The computation of the most probable hidden sequence at time t only

depends on the value in t and the sequence up to t-1 (Markov assumption)

Page 21: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

The Viterbi Algorithm

•  It is very similar to the forward algorithm, although in this case at each step we only choose the best path, and remember it to later retrieve it among all possible.

•  In this case we want to compute the optimum joint probability of the observation sequence together with the state sequence.

•  Making use of the Markov assumption we can easily compute the probability of the most likely state sequence at time “t” as

for any given time “t” and state “i”

!t ( j) =max1!i!N!t"1(i)aij#$ %&bj (ot )

Page 22: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

TDP: HMM 22

Viterbi Algorithm recursion

Page 23: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

Viterbi example

1 2

3

aij =0.3 0.6 0.10.5 0.2 0.30.4 0.1 0.5

!

"

###

$

%

&&&

bi =1/ 21/ 2

1/ 32 / 3

3 / 41/ 4

!

"#

$

%&

Red balls Blue Balls

We have three urns, each one with several red and blue balls. We do a ball extraction and find the sequence of balls Red+blue+red All urns have the same probability to start, i.e. πi=1/3

Urn1 Urn2 Urn3

Page 24: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

Viterbi example

1 1 1

2 2 2

3 3 3

!1( j) = " jbj (R) !2 ( j) =max1!i!3[!1(i)aij ]bj (B) !3( j) =max1!i!3

[!2 (i)aij ]bj (R)

j=1

j=2

j=3

13!12=16

13!13=19

13!34=14

[14!0.4]! 1

2= 0.05

0.3

0.5 0.3

0.6 0.2

0.1

0.1 0.3

0.5 0.5

0.3 0.1

0.1

0.2

0.4

0.6

0.5

0.3

[16!0.6]! 2

3= 0.06

[14!0.5]! 1

4= 0.03125 [0.06 !0.3]! 3

4= 0.015

[0.05 !0.6]! 13= 0.01

[0.06 !0.5]! 12= 0.016

Page 25: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

TDP: HMM 25

Problem 3. Training

  How do we adjust the model parameters model λ=(A,B, π) to maximize P(O| λ), where O is one or several training sequences

  The observation sequence used to adjust the model parameters is called training sequence. The training problem is the crucial one for most applications of HMMs.

  This is the most difficult problem of the 3, as there is no analytical solution to it.

  We can solve it using the Baum-Welch Re-estimation Procedures, which is an iterative algorithm

1.  Compute some statistics on the current model given the training data 2.  Adapt the model given the previous statistics 3.  Return to step 1 until convergence

Page 26: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

TDP: HMM 26

Word Models

Page 27: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

TDP: HMM 27

Phone Models

Page 28: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

TDP: HMM 28

Continuous Density HMMs

Page 29: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

TDP: HMM 29

Training an Univariate Gaussian A (single) univariate Gaussian is characterized by mean µ and variance σ Imagine that we had observed n feature vectors xi which all have the same label i

associated. Compute the mean and variance from the data:

Page 30: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

MFCC of vowels

!"#$%%&'' ()

!"##$%&$'%()*+

Fitting the distribution of MFCC values into a Gaussian PDF is not an optimum solution, but it is handy

Page 31: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

!"#$%%&'' ((

!"#$%%&'' ()

!"#$%%&'' ()

Page 32: 10. Hidden Markov Models (HMM) for Speech Processing · 2015-08-25 · The Viterbi Algorithm • It is a dynamic programming algorithm for finding the most likely sequence of hidden

Example: modeling instruments using GMMs We can use MFCC and GMMs to model and differentiate between

instruments

Images obtained from http://cnx.org/content/m13205