how to use HTK?

From:: http://wenwenweiwei.com/blog/?p=127

 

Hiddent Markov Model (MATLAB & HTK)

This page is written to remind myself of how to verify the results from my MATLAB implementation of HMM using HTK . Note that throughout this page, it is assumed that the HMM is implemented in MATLAB, and MATLAB is used to call all the HTK functions. But the same can be done with any other programming languages.

Helpful resources:

1. A Tutorial on Hidden Markov Models and Selected Applications in Speech Recognition [link ]

2. HTKBook [link ]

Pattern Classification text did not do a good job in presenting materials related to HMM. Do not bother with it.  

Assumptions: 

1. Have implemented a complete suite of HMM functions, which includes, the generation, evaluation, estimation and decoding of HMMs. 

2. All the HTK executables are complied correctly and are place in the correct path. 

Procedures: 

 

1. Constructing the HMM model 

Chapter 7 of HTKBooks (p. 106-126) covers the methods that HTK uses to define HMMs. Please read it through before proceeding.  

A HMM can be defined in a text file in HTK. Things are pretty straightforward as long as you know what all the parameters means. That is why it is very important to fully understand the definition language first. 

Things to look out for: 

DProb. The discrete probability is a bit tricky because all the values between 0 and 1 are converted to log scale first. The equation used in the conversion is Prob = exp(-Dprob / 2371.8 ) (p. 120). For any probability that should be 0, DProb of 32767 is used instead. 

Below is an example of discrete HMM definition. Four-state discrete HMM with a 1-d feature vector. 

~o  <STREAMINFO> 1 1
<VECSIZE> 1<NULLD><DISCRETE>
~h "dhmm"
<BEGINHMM>
<NUMSTATES> 4
<STATE> 2
<NumMixes> 3
<DProb> 1212 2173 32767*1
<STATE> 3
<numMixes> 3
<DProb> 2173 1212 32767*1
<TRANSP> 4
0 0.3 0.7 0
0 0.4 0.4 0.2
0 0.5 0.4 0.1
0 0 0 0
<ENDHMM>

Below is an example of continuous HMM definition. Four-state continous HMM with a 2-d feature vector.


~o <STREAMINFO> 1 2
<VECSIZE> 2 <NULLD> <USER> <DIAGC>
~h "htm2"
<BEGINHMM>
<NUMSTATES> 4
<STATE> 2 <NUMMIXES> 2
<MIXTURE> 1 0.5
<MEAN> 2
-0.5 -0.5
<VARIANCE> 2
1 1
<MIXTURE> 2 0.5
<MEAN> 2
-0.5 0.5
<VARIANCE> 2
1 1
<STATE> 3 <NUMMIXES> 2
<MIXTURE> 1 0.5
<MEAN> 2
0.5 -0.5
<VARIANCE> 2
1 1
<MIXTURE> 2 0.5
<MEAN> 2
0.5 0.5
<VARIANCE> 2
1 1
<TRANSP> 4
0 0.3 0.7 0
0 0.4 0.4 0.2
0 0.5 0.4 0.1
0 0 0 0
<ENDHMM>

The HMM definition can be saved in a text file that has the same name as the HMM model declared. Note that when calling any HMM that could update the HMM model, the ‘-M’ should be used so that any update is recorded in a different HMM definition file. Otherwise, the updates will overwrite the existing HMM definition file. 

2. Preparing the data files

My data was generated in MATLAB and they were written as HTK file format (read 5.10.1 HTK Format Parameter Files on p.78).

Note that the files has to be opened in ‘ieee-be’ (’b') IEEE floating point with big-endian byte ordering machine format. Otherwise, there will be error when reading in the htk format files in the htk functions. 

There are four fields in the header of a htk format file, and they are: 

 

  • nSamples – (4-byte integer) number of samples (sample vectors) in file, the data sequence is truncated if it is longer than nSamples; if nSamples is greater than the number of samples in the file, then nSamples is taken as the number of samples in the file instead 
  • sampPeriod – (4 byte integer) sample period in 100ns units. not important if the data is not speech-related 
  • sampSize – (2-byte integer) number of bytes per sample, or in other words, number of bytes per sample vector. 
  • parmKind – (2-byte integer) a code indicating the sample kind, we will use 9 – USER and 10 – DISCRETE 

The data sequence should be order one sample vector after another sample vector, thus, for a 2-d vector sequence, you will see x1(1), x2(1), x1(2), x2(2), … .  

For continuous HMM, the data should be float32 (4-byte); for discrete HMM, the data should be int16 (2-byte). 

hlist function from htk can be used to checked the data files written. A sample of the command is

!hlist -o -h ./data/data1.htk

Multiple data files can be generated using a for-loop. By default, at least three data files are needed before calling HRest. The option ‘-m’ can be used to remove such restriction so that obervations can be made from the parameters alpha, beta, gamma, and etc. 

 

3. Calling the HTK function HRest

!HRest -e 0.000001 -i 100 -M ./hmms/ -T 1 -F HTK htm trainFiles

The newly estiamted parameters are recored in ./hmms/htm text file.

 

 

Notes: 

  • Null exit state: HTk has non-emitting exit state implemented. However, “the use of non-emitting states and multiple data streams leads to various special cases which are usually not covered fully in the literature.” (8.8 Parameter Re-Estimation Formulae p. 140)
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值