參考資源:http://cmusphinx.sourceforge.net/wiki/tutoriallm sphinx官方教程php
1)文本準備ios
生成文本文件,內含一行一個的單詞。頭尾有<s> </s>標記,以下所示,其中單詞先後都有空格。文件爲utf-8格式,文件名爲test.txt。windows
<s> 蘇菲 </s> <s> 百事 </s> <s> 雀巢 </s> <s> 寶潔 </s> <s> 殼牌 </s> <s> 統一 </s> <s> 高通 </s> <s> 科勒 </s>
2)上傳此文件到服務器上,生成詞頻分析文件服務器
text2wfreq < test.txt | wfreq2vocab > test.vocab
中間過程以下:app
text2wfreq : Reading text from standard input...
wfreq2vocab : Will generate a vocabulary containing the most
frequent 20000 words. Reading wfreq stream from stdin...
text2wfreq : Done.
wfreq2vocab : Done.
結果文件爲test.vocab,其中格式爲:工具
## Vocab generated by v2 of the CMU-Cambridge Statistcal ## Language Modeling toolkit. ## ## Includes 178 words ## </s> <s> 一號店 上好佳 上海灘 絲塔芙 絲芙蘭
3)生成arpa文件性能
text2idngram -vocab test.vocab -idngram test.idngram < test.txt idngram2lm -vocab_type 0 -idngram test.idngram -vocab test.vocab -arpa test.lm
第一條命令中間過程爲spa
text2idngram
Vocab : test.vocab
Output idngram : test.idngram
N-gram buffer size : 100
Hash table size : 2000000
Temp directory : cmuclmtk-Mtadbf
Max open files : 20
FOF size : 10
n : 3
Initialising hash table...
Reading vocabulary...
Allocating memory for the n-gram buffer...
Reading text into the n-gram buffer...
20,000 n-grams processed for each ".", 1,000,000 for each line.
Sorting n-grams...
Writing sorted n-grams to temporary file cmuclmtk-Mtadbf/1
Merging 1 temporary files...
2-grams occurring: N times > N times Sug. -spec_num value
0 351 364
1 348 3 13
2 2 1 11
3 0 1 11
4 0 1 11
5 0 1 11
6 0 1 11
7 0 1 11
8 0 1 11
9 0 1 11
10 0 1 11
3-grams occurring: N times > N times Sug. -spec_num value
0 525 540
1 522 3 13
2 3 0 10
3 0 0 10
4 0 0 10
5 0 0 10
6 0 0 10
7 0 0 10
8 0 0 10
9 0 0 10
10 0 0 10
text2idngram : Done.
結果文件爲test.idngram,其中格式爲.net
^@^@^@^A^@^@^@^B^@^@^@^C^@^@^@^A^@^@^@^A^@^@^@^B^@^@^@^D^@^@^@^A^@^@^@^A^@^@^@^B^@^@^@^E^@^@^@^A^@^@^@^A^@^@^@^B^@^@^@^F^@^@^@^A^@^@^@^A^@^@^@^B^@^@^@^G^@^@^@^A^@^@^@^A^@^@^@^B^@^@^@^H^@^@^@^A^@^@^@^A^@^@^@^B^@^@^@ ^@^@^@^A^@^@^@^A^@^@^@^B^@^@^@
@
@
第二條命令,中間過程爲產生不少warning,可是最後顯示done,這裏語言模型應該是有問題了。code
Warning : P(2) = 0 (0 / 177)
ncount = 1
Warning : P(2) = 0 (0 / 177)
ncount = 1
Warning : P(2) = 0 (0 / 177)
ncount = 1
Warning : P(2) = 0 (0 / 177)
ncount = 1
。。。。。。。
Writing out language model...
ARPA-style 3-gram will be written to test.lm
idngram2lm : Done.
結果文件爲test.lm,打開查看內容
This is a CLOSED-vocabulary model
(OOVs eliminated from training data and are forbidden in test data)
Good-Turing discounting was applied.
1-gram frequency of frequency : 174
2-gram frequency of frequency : 348 2 0 0 0 0 0
3-gram frequency of frequency : 522 3 0 0 0 0 0
1-gram discounting ratios : 0.99
2-gram discounting ratios : 0.00
3-gram discounting ratios : 0.00
This file is in the ARPA-standard format introduced by Doug Paul.
此處意思是隻有1-gram,缺少2-gram和3-gram,事實上翻看後面這個lm中的內容, 列出的2-gram對和3-gram,是以行爲分界。
使用sphinx官網自帶的中文聲學模型,和中文詞典,以及此處訓練獲得的語言模型。識別特定的一些字串。此處有160個單詞,和這160個單詞的發音獲得的詞典,以及包含這些詞的一個龐大豐富的聲學模型,因此按照邏輯,識別過程找到對應的每一個字後,再依據這個語言模型中不一樣字的組合造成的詞語,能識別出正確的詞組。
windows上安裝了pocketsphinx,使用以下:
pocketsphinx_continuous.exe -inmic yes -lm test.lm -dict test.dic -hmm zh_broadcastnews_ptm256_8000
此處,-lm引入的模型是直接生成的lm後綴的模型,而武林祕籍中是先把lm模型轉爲dmp模型,再在此處使用,不知道問題是否在這裏。
三 nextplan
1)使用所有詞串,詞串都通過分詞,訓練語言模型,而後和固有聲學模型一塊兒使用
在線分詞工具,先不論性能好壞,以下可直接用:
php分詞系統演示: http://www.phpbone.com/phpanalysis/demo.php?ac=done
SCWS中文分詞: http://www.xunsearch.com/scws/demo.php
NLPIR 中科院計算機所NLP: http://ictclas.nlpir.org/nlpir/ (只想說這就是我心目中的NLP有趣的方式)
這個結果還須要作處理,當下不太實用。
2)錄製300個句子,訓練聲學模型,和對應的語言模型一塊兒使用。