2018年2月6日 星期二

HTK Tools (7): 馬可夫模型 - 處理可辨識的模型並測試

前面章節已經將分別狀態的馬可夫模型建立完成,本篇文章則需要將馬可夫模型狀態成為三個狀態的馬可夫模型,並用 HVite 即時辨識與測試。
HTK Tools 會基於文法上進行辨識的測試,會在文章最後面進行;本篇基於 HTK Books 章節 3.3 Creating Tied-State Triphones - Step 10. Making Tied-State Triphones (p. 38)。

字典整理


本文所使用的字典 (beep) 等,未經過整理,請複製一份 beep-1.0 出來 (備份),變成新的字典,以下取名為 dict。

字典被使用 HTK Tools 建模時,最主要的問題是,字典如果沒有按照 ASCII 排序,就會出錯,特殊字元也必須用 // 兩個斜號處理。

請先用 Sublime Text 之類的軟體,把所有特殊字元,如 &, ", <, >, ', $, !, % 前面加上 // 兩個斜線。

然後,請到這個 GitHub repo 下載排序字典的工具 (sort.py):

prosodylab/Prosodylab-Aligner (GitHub)

下載後,對字典使用指令 (注意,請使用處理過的字典 dict):
python sort.py dict > sorted_dict

(如果之後執行程式有誤,嘗試刪除字典字母 A 以前的資料,讓 A 字母在第一個執行)

產生清單


產生清單需要使用指令檔來處理,請建立一個 maketriphones.ded 檔案,並寫入:
AS sp
MP sil sil sp
TC

然後,執行指令來產生指令檔:
HDMan -A -D -T 1 -b sp -n fulllist0 -g maketriphones.ded -l flog dict-tri sorted_dict

如果你的步驟有問題,像是這樣:


就檢查 A 以前的字母,如果不是太多,就把它們都刪掉,或把第一格空白刪掉後,重新排序。 (尤其是 DOUBLE-QUOTES 第一格有空白,刪掉後重新排序)

產生清單後,需要用 Perl 程式幫助把 pohnes 加入新的 fulllist (即將新產生) ,並且移除重複的項目。
從這裡下載 fixfulllist.prl 程式:

http://www.voxforge.org/uploads/LU/Di/LUDii_uUSzSweNNPpU-6iQ/fixfulllist_pl.txt

然後,在目錄底下使用指令:
perl fixfulllist.prl fulllist0 fulllist

這樣,就會產生一個 fulllist 的檔案,完成這一步驟。


tree.hed 指令檔處理



Tree.hed 是包含文字組合的一個指令檔案,本文取得的方式是使用範本,可以從這裡下載到:

https://raw.githubusercontent.com/VoxForge/develop/master/tutorial/tree1.hed

下載後,請複製一份空的 tree1.hed 變成 tree.hed (請檢查最後尾是否有斷行)。

然後,還需要使用一個 Perl 程式來幫助處理添加一些指令到腳本中,可以在 HTK Tools 的 samples 資料夾的 RMHTK > perl_scripts 找到 mkclscript.prl,複製到工作目錄中。

接著,使用指令處理它:
perl -w mkclscript.prl TB 350 monophones >> tree.hed

這個指令將會把 monophones 組合一併列到 tree.hed 上,再手動把以下指令輸入到 tree.hed 文件最後尾 (請記得最後要斷行):

TR 1
 
AU "fulllist" 
CO "tiedlist" 
 
ST "trees" 

建立 tiedlist


Tiedlist 是將未知馬可夫模型的所有字列出來,請建立一個 hmm13 的資料夾後,使用指令:
HHEd -A -D -T 1 -H hmm12/macros -H hmm12/hmmdefs -M hmm13 tree.hed triphones1

如果執行指令出錯的話,回到在前面章節做 hmm9 到 hmm10 步驟時,假如出現了一些警告,這些字就是在訓練資料裡沒出現的字,所以會導致接下來的指令錯,如圖:


請在 fulllist 檔案中,移除所有跟上列字有關的行數,除了 sil, sp 以外都刪除。

根本解決這樣問題的方法是,給足夠的訓練資料,才能夠避免這樣的問題。

如下圖的錯誤訊息,就是因為資料不足,無法提取該字訓練,就將上面圖片中的 monophones 相關文字行段在 fulllist 檔案中刪除,就可以避免錯誤訊息發生。


錯誤除了沒有找到相關訓練資料外,如果大寫字母出錯,請一併在 Sublime Text 之類的編輯器,用正規表達式把 fulllist 中的大寫字刪除。

參數重估


完成後,需要再做最後的參數評估兩次,請建立 hmm14 和 hmm15 的目錄後,使用指令:

HMM14
HERest -A -D -T 1 -T 1 -C config -I wintri.mlf -t 250.0 150.0 1000.0 -S train.scp -H hmm13/macros -H hmm13/hmmdefs -M hmm14 tiedlist 

如果第一次使用 HERest 指令出錯,如圖:


此時,需要把 label 檔案 (.lab 檔案) ,應放置在跟 .mfc 檔案同目錄下,將所有錯誤訊息 *Unknown 提到的 Triphones 行段刪除為止,再重新執行 HERest 才會通過。

HMM15
HERest -A -D -T 1 -T 1 -C config -I wintri.mlf -t 250.0 150.0 1000.0 -S train.scp -H hmm13/macros -H hmm13/hmmdefs -M hmm14 tiedlist 

執行測試


完成後的 Model 要進行測試的話,可以使用內建的 HTK 指令 HVite 完成,請先設置好麥克風。

文法部分

HTK 要執行測試,要先對照現有需要辨識的文法來使用,請先建立一個空檔案 gram ,輸入範例需要辨識的腳本 (請使用訓練資料的文本資料隨機單字):

$digit = EVENING | NEWS | SAYS;

($digit)


然後,將 gram 轉成 wdnet 檔案,請使用指令:
HParse gram wdnet

設定檔部分

請新增一個 config2 的檔案,輸入內容:
SOURCERATE=625.0
SOURCEKIND=HAUDIO
SOURCEFORMAT=HTK
ENORMALISE=F
USESILDET=T
MEASURESIL=F
OUTSILWARN=T

TARGETKIND=MFCC_0_D_A
TARGETRATE=100000
我對照別人製作的 config2 設定檔,對我製作的 model 沒有效果,執行即時辨識測試時會失敗,所以我加了最後兩行才使辨識成功。

執行測試部分

請使用指令:
HVite -A -D 1 -H hmm15\proto -H hmm15\hmmdefs -C config2 -w wdnet -p 0.0 -s 5.0 beep-1.0 tiedlist

在 READY[1] 的時候請靜待一下 HTK Tools 錄製靜音調適,再說話。

調適


完成模型後,可能會對其他人的辨識失去精準度,這時候需要執行 HTK Books 3.6 章節的 Adapting the HMMs 之後的章節進行調適。


Reference:
http://www.voxforge.org/home/dev/acousticmodels/linux/create/htkjulius/tutorial/triphones/step-10
https://raw.githubusercontent.com/VoxForge/develop/master/tutorial/tree1.hed
https://equatorian.wordpress.com/2010/04/23/understanding-htk-error-messages/
http://hts.sp.nitech.ac.jp/hts-users/spool/2009/msg00271.html
http://www.voxforge.org/home/dev/acousticmodels/linux/create/htkjulius/tutorial/monophones/step-6/comments/error-7321-createinsts-unknown-label-
https://github.com/pmdartus/HTK-Digit/blob/master/REPORT.md
http://www.voxforge.org/home/dev/acousticmodels/linux/create/htkjulius/tutorial/triphones/step-9/comments/untitled
https://github.com/prosodylab/Prosodylab-Aligner
https://github.com/prosodylab/Prosodylab-Aligner/issues/48
http://www.voxforge.org/home/dev/acousticmodels/linux/create/htkjulius/tutorial/triphones/step-10/comments/error-2662
http://www.voxforge.org/home/dev/acousticmodels/linux/create/htkjulius/tutorial/triphones/step-10/comments/error-find-proto
https://raw.githubusercontent.com/VoxForge/develop/master/tutorial/hmm15/hmmdefs
https://raw.githubusercontent.com/VoxForge/voxshell/master/language/en/lexicon/VoxForgeDict.txt
https://stackoverflow.com/questions/31093781/htk-error-5010-initsource-cannot-open-source-file-f-ihmk
http://www.voxforge.org/home/dev/acousticmodels/linux/create/htkjulius/tutorial/triphones/step-10/comments/hhed-error
http://www.voxforge.org/home/dev/acousticmodels/linux/create/htkjulius/tutorial/data-prep/step-2/comments/-error-5013--readstring-string-too-long
http://www.voxforge.org/home/dev/acousticmodels/linux/create/htkjulius/tutorial/triphones/step-10/comments/error-in-hdman
https://raw.githubusercontent.com/pjt/modernize/master/resources/bigdict.txt
https://sourceforge.net/projects/cmusphinx/files/Acoustic%20and%20Language%20Models/
https://raw.githubusercontent.com/VoxForge/develop/master/tutorial/fulllist0
http://www.voxforge.org/uploads/LU/Di/LUDii_uUSzSweNNPpU-6iQ/fixfulllist_pl.txt
https://raw.githubusercontent.com/VoxForge/develop/master/tutorial/tree1.hed
https://raw.githubusercontent.com/VoxForge/develop/master/tutorial/tree.hed
https://raw.githubusercontent.com/VoxForge/develop/master/tutorial/tiedlist
https://raw.githubusercontent.com/VoxForge/develop/master/tutorial/tree1.hed
http://levinboim.blogspot.tw/2012/05/htk-tutorial-microblogging-may-27.html

1 則留言:

  1. 按照您的做法 phone 中並沒有用到sp
    從hmm9到hmm10後就沒有sp在hmmdefs中
    到hmm12 至 hmm13發生錯誤
    No proto for sp in hset
    想問您的看法,我完全按照您的做法實作

    回覆刪除

© Mac Taylor, 歡迎自由轉貼。
Background Email Pattern by Toby Elliott
Since 2014