天天看點

語言模型訓練工具SRILM

     SRILM是著名的約翰霍普金斯夏季研讨會(Johns Hopkins Summer Workshop)的産物,誕生于1995年,由SRI實驗室的Andreas Stolcke負責開發維護。

  關于SRILM的安裝,我已經在前面關于moses平台搭建的文章(參見:《Moses相關介紹》和《Ubuntu8-10下moses測試平台搭建全記錄》)中介紹過了,這裡就不再重複。準确的說,SRILM并不是因機器翻譯而誕生的,它主要是為語音識别所開發的,全稱為Stanford Research Institute Language Modeling Toolkit。事實上統計機器翻譯與語音識别關系千絲萬縷,我會在以後的文章中介紹。

  SRILM用來建構和應用統計語言模型,主要用于語音識别,統計标注和切分,以及機器翻譯,可運作在UNIX及Windows平台上。它主要包含以下幾個部分:

  • 一組實作的語言模型、支援這些模型的資料結構和各種有用的函數的C++類庫;

  • 一組建立在這些類庫基礎上的用于執行标準任務的可執行程式,如訓練語言模型,在資料集上對這些語言模型進行測試,對文本進行标注或切分等任務。

  • 一組使相關任務變得容易的各種腳本。

  SRILM的主要目标是支援語言模型的估計和評測。估計是從訓練資料(訓練集)中得到一個模型,包括最大似然估計及相應的平滑算法;而評測則是從測試集中計算其困惑度(MIT自然語言處理機率語言模型有相關介紹)。其最基礎和最核心的子產品是n-gram子產品,這也是最早實作的子產品,包括兩個工具:ngram-count和ngram,相應的被用來估計語言模型和計算語言模型的困惑度。一個标準的語言模型(三元語言模型(trigram),使用 Good-Truing打折法和katz回退進行平衡)可以用如下的指令建構:

   ngram-count -text TRAINDATA -lm LM

  其中LM是輸出的語言模型檔案,可以用如下的指令進行評測:

   ngram -lm LM -ppl TESTDATA -debug 2

  其中具體的參數可參看官方網站的幫助文檔,如果你已經在linux下編譯好了,可以直接使用man調用幫助文檔。事實上,統計機器翻譯架構主要用的就是 n-gram這個子產品來訓練語言模型。下面我們以歐洲語料庫的英語語料為例,解析這個工具的作用。語料庫下載下傳位址見:歐洲議會平行語料庫。本例子使用的是wmt08裡面用于英語語言模型訓練的europarl-v3b.en,用于機器翻譯的預處理過程tokenize和lowercase此處省略,其規模為1412546句:

  1、從語料庫中生成n-gram計數檔案:

   ngram-count -text europarl-v3b.en -order 3 -write europarl.en.count

  其中參數-text指向輸入檔案,此處為europarl-v3b.en;-order指向生成幾元的n-gram,即n,此處為3元;-write指向輸出檔案,此處為europarl.en.count,輸出内容為:

   …

   sweeteners 66

   sweeteners should 1

   sweeteners should be 1

   …

  分為兩列,第一列為n元詞,第二列為相應的頻率。如一進制詞sweeteners在語料庫中的頻率統計為66次;二進制詞sweeteners shoul在語料庫中的頻率統計為1次;三元sweeteners should be在語料庫中的頻率統計為1次。

  2、從上一步生成的計數檔案中訓練語言模型:

   ngram-count -read europarl.en.count -order 3 -lm europarl.en.lm -interpolate -kndiscount

  其中參數-read指向輸入檔案,此處為 europarl.en.count;-order與上同;-lm指向訓練好的語言模型輸出檔案,此處為europarl.en.lm;最後兩個參數為所采用的平滑方法,-interpolate為插值平滑,-kndiscount為 modified Kneser-Ney 打折法,這兩個是聯合使用的。需要補充的是,一般我們訓練語言模型時,這兩步是合二為一的,這裡主要是為了介紹清楚n-gram語言模型訓練的步驟細節。

  語言模型europarl.en.lm的檔案格式如下,為 ARPA檔案格式。為了說明友善,檔案中的括号是我加上的注釋:

 data

 ngram 1=262627 (注:一進制詞有262627個 )

 ngram 2=3708250 (注:二進制詞有 3708250個)

 ngram 3=2707112 (注:三元詞有 2707112個)

 1-grams:(注:以下為一進制詞的基本情況)

 -4.891179(注:log(機率),以10為底) ! -1.361815

 -6.482389 !) -0.1282758

 -6.482389 !’ -0.1282758

 -5.254417 “(注:一進制詞) -0.1470514

 -6.482389 “‘ -0.1282758(注:log(回退權重),以10為底)

 …

 2-grams:

 -0.02140159 !

 -2.266701 ! –

 -0.5719482 !)

 -0.5719482 !’

 -2.023553 ” ‘Biomass’

 -2.023553 ” ‘vertical’

 …

 3-grams:

 -0.01154674 the !

 -0.01154674 urgent !

 -0.01154674 us’ !

 -1.075004 the “.EU” Top

 -0.827616 the “.EU” domain

 -0.9724987 the “.EU” top-level …

3、利用上一步生成的語言模型計算測試集的困惑度:

   ngram -ppl devtest2006.en -order 3 -lm europarl.en.lm > europarl.en.lm.ppl

  其中測試集采用wmt08用于機器翻譯的測試集devtest2006.en,2000句;參數-ppl為對測試集句子進行評分(logP(T),其中P(T)為所有句子的機率乘積)和計算測試集困惑度的參數;europarl.en.lm.ppl為輸出結果檔案;其他參數同上。輸出檔案結果如下:

 file devtest2006.en: 2000 sentences, 52388 words, 249 OOVs

 0 zeroprobs, logprob= -105980 ppl= 90.6875 ppl1= 107.805

  第一行檔案devtest2006.en的基本資訊:2000句,52888個單詞,249個未登入詞;

  第二行為評分的基本情況:無0機率;logP(T)=-105980,ppl==90.6875, ppl1= 107.805,均為困惑度。

附:SRILM首頁推薦的書目和文獻。

 入門——了解語言模型尤其是n-gram模型的參考書目章節:

  • 《自然語言處理綜論》第一版第6章,第二版第4章(Speech and Language Processing by Dan Jurafsky and Jim Martin (chapter 6 in the 1st edition, chapter 4 in the 2nd edition) )

  • 《統計自然語言處理基礎》第6章。(Foundations of Statistical Natural Language Processing by Chris Manning and Hinrich Schütze (chapter 6))

 深入學習相關文獻:

  • A. Stolcke, SRILM – An Extensible Language Modeling Toolkit, in Proc. Intl. Conf. Spoken Language Processing, Denver, Colorado, September 2002. Gives an overview of SRILM design and functionality.

  • D. Jurafsky, Language Modeling, Lecture 11 of his course on “Speech Recognition and Synthesis” at Stanford. Excellent introduction to the basic concepts in LM.

  • J. Goodman, The State of The Art in Language Modeling, presented at the 6th Conference of the Association for Machine Translation in the Americas (AMTA), Tiburon, CA, October, 2002. Tutorial presentation and overview of current LM techniques (with emphasis on machine translation).

  • K. Kirchhoff, J. Bilmes, and K. Duh, Factored Language Models Tutorial, Tech. Report UWEETR-2007-0003, Dept. of EE, U. Washington, June 2007. This report serves as both a tutorial and reference manual on FLMs.

  • S. F. Chen and J. Goodman, An Empirical Study of Smoothing Techniques for Language Modeling, Tech. Report TR-10-98, Computer Science Group, Harvard U., Cambridge, MA, August 1998 (original postscript document). Excellent overview and comparative study of smoothing methods. Served as a reference for many of the methods implemented in SRILM.

注:原創文章,轉載請注明出處“我愛自然語言處理”:www.52nlp.cn

本文連結位址:http://www.52nlp.cn/language-model-training-tools-srilm-details/

相關文章

  • 語言模型訓練工具SRILM詳解
  • SRILM 的編譯
  • Moses相關介紹
  • Ubuntu8-10下moses測試平台搭建全記錄
  • Ubuntu 64位系統下SRILM的配置詳解
  • srilm 閱讀文檔1
  • srilm 閱讀文檔2
  • srilm 閱讀文檔3
  • srilm 閱讀文檔4
  • srilm 閱讀文檔5
  • srilm 閱讀文檔6
  • srilm 閱讀文檔7
  • srilm 閱讀文檔8
  • srilm 閱讀文檔9
  • srilm 閱讀文檔10
  • srilm 閱讀文檔11
  • srilm 閱讀文檔12
  • srilm 閱讀文檔13
  • srilm 閱讀文檔14
  • srilm 閱讀文檔15
  • srilm 閱讀文檔15-Version2
  • srilm ngram trie資料結構

取自" http://wiki.52nlp.cn/SRILM"

繼續閱讀