GIZA++运行情况记录和结果对比

   这篇文章主要详细记录了GIZA++的运行报告,所使用的语言模型为CMU-Cam_Toolkit-v2,解码器使用的是isi-rewrite-decoder-r1.0.0a,使用的操作系统是Ubuntu9.10 ,gcc 的版本是G++4.4.1.都是比较新的运行环境,有需要的学习者可以参考。有不明白的可以留言。其中文中参考的论文为刘洋老师的《利用现有软件构建统计机器翻译系统》。

   

                           -----------------------------------------------

                          GIZA++运行情况记录和结果对比

                                       

 田亮          澳门大学

                                   

                                          2009-12-15——2009-12-22

                                ----------------------------------------------

       

本次总结主要是对运行过程中的步骤及其出现的情况进行记录,并对运行中出现的可执行文件的功能进行说明与讲解。目的就是总结出一份详细的运行报告,以便其他试图运行该软件的研究者能够顺利调试。文章的结构是在正文的部分给出运行成功的过程,而在文中的附录部分给出各种异常的情况和各种可执行文件的解释,最后给出相关的论文。

      文章的总体结构图如下(这里省略):

 

    1.   工具的准备

  1. 安装linux系统,这里我使用的是Ubuntu 9.10gcc版本是4.4.1
  2. 双语语料库。这里使用1000句中英文对照翻译的句子。
  3. CMU-Cambridge Statistical Language Modeling Toolkit v2。语言模型工具,用于生成语言模型,以便解码器调用。
  4. GIZA++。这里使用最新版本“giza-pp-v1.0.3.tar”,里面包含其辅助工具“mkcls”,用于生成word class
  5. 汉语和英语的分词工具。汉语使用ICTCAL,英语使用EGYPT自带的一个工具:tokenizeE.perl.tmpl

2.   处理语料库

1.下载中英文语料库

从网上下载的1500句(http://www.nlp.org.cn/中文自然语言开放平台)是有问题的,主要是有部分中文语句占据了两行,导致对齐效果不好,所以事先更正了一下。这里为了和语言模型使用的句子相区别,使用了前1000句,作为对齐语料库,而把英文的1500句作为语言模型。

 其中源语言1500——1500.txt的输入形式为:

 For this reason it is often convenient to overlay the geochemical map with a geological map transparency.

由于这个缘故,最好用透明的地质图蒙在地球化学图上。

Trains and tunnels are overlaid with the multicoloured names and slogans of youths.

青年人在车辆上和隧道中涂满了各种颜色的姓名和口号。

….

2.分离语料库

接下来,我们要做的就是对其进行分离,也就是说,把这个文档分别分成中文和英文,并把它们命名为:chineseenglish。在linux中可以使用如下的命令把它分离:

   tianliang@ubuntu:~$grep '[aeiou]' 1500.txt > english

 分离后,会有四句含有中文,然后将english中含有中文句手工删除。

 tianliang@ubuntu:~$grep -v  '[aeiou]' 1500.txt > chinese

然后将chinese中含有全角标点的英文句手工删除。

选择分离后的语言文件:englishchinese中的前1000句作为接下来的输入文件。并把分离后的1500句重命名为english1500

分离后的语言englishchinese的格式 如下:

english

For this reason it is often convenient to overlay the geochemical map with a geological map transparency.

Trains and tunnels are overlaid with the multicolored names and slogans of youths.

chinese

由于这个缘故,最好用透明的地质图蒙在地球化学图上。

青年人在车辆上和隧道中涂满了各种颜色的姓名和口号。

3.添加语言模型的识别标志

由于这次使用的解码器isi-rewrite-decoder采用XML文件格式作为输入文件,而它把<s></s>作为语句的区别的标志,为了能够让解码器识别语句,这里需要事先对语言模型的语句做些处理,即要对“english1500”添加<s></s>标记。使用如下的步骤即可:

     1 运行命令:

tianliang@ubuntu:~$cp english1500 english.tag

生成了english1500的一个复本english.tag当然可以使用图形化的操作直接复制一份即可。做这步的目的是保留源文件,以免出现异常情况后,源文件损坏。

     2vi打开english.tag,使用如下两个命令:

:%s#^#<s> #

:%s#$# </s>#

注意<s>之后以及</s>之前各有一个空格。这样就给每个句子的头和尾加上了标记。保存( wq!)并退出vi

最终生成的加标记的文件的形式为:

<s> For this reason it is often convenient to overlay the geochemical map with a geological map transparency. </s>

 

<s> Trains and tunnels are overlaid with the multicolored names and slogans of youths. </s>

….

3.   安装软件

1.     下载软件

  分别下载所需的软件

语言模型工具:CMU-Cambridge Statistical Language Modeling Toolkit v2

 下载地址:http://svr-www.eng.cam.ac.uk/~prc14/toolkit.html

解码器:isi-rewrite-decoder-r1.0.0a.tar.gz

 下载地址:http://www.isi.edu/natural-language/software/decoder/

                http://download.csdn.net/detail/tianliang0123/3712116

翻译模型工具:Giza-pp-v1.0.3.tar(里面包含GIZA++-v2mkcls-v2

 下载地址:http://code.google.com/p/giza-pp/

分词工具包:EGYPT(这里仅使用它自带的英语分词功能)

 下载地址:http://www.clsp.jhu.edu/ws99/projects/mt/toolkit/

 这里介绍一个统计机器翻译的专门网站http://www.statmt.org/,从这里你可以了解到相关的统计机器的论文和会议情况,还可以下载所需要的各种有关的语料库和工具。

2.     编译安装软件

 首先,建立一个文件夹用来放置本次调试的软件包:/home/tianliang/research

 然后,把解压后的软件包复制到该目录下即可。这里解压可以使用图形化的操作方式,直接右键解压,或者使用命令行,如解压EGYPT包:# tar –xzvf EGYPT.tar.gz

 最后,从终端进入该目录,然后输入命令“make”编译即可。

 详细过程如下:

1)把三个解压后的文件包放置在research目录下,使用如下的命令,以及查询目录下的软件包情况:

tianliang@ubuntu:~$mkdir research

tianliang@ubuntu:~$cd research

tianliang@ubuntu:~/research$ls

CMU-Cam_Toolkit_v2 giza-pp isi-rewrite-decoder-r1.0.0a

2)安装CMU-Cam_Tookit_v2

 安装这个软件前,要事先更改一下代码,方法就是进入该包的src目录下,找到Makefile,将里面的“#BYTESWAP_FLAG=-DSLM_SWAP_BYTES”中的“#”去掉。

tianliang@ubuntu:~/research$cd CMU-Cam_Toolkit_v2

tianliang@ubuntu:~/research/CMU-Cam_Toolkit_v2$cd src

tianliang@ubuntu:~/research/CMU-Cam_Toolkit_v2/src$make install

gcc -O -DSLM_SWAP_BYTES -c -o bo_ng_prob.o bo_ng_prob.c

gcc -O -DSLM_SWAP_BYTES -c -o calc_mem_req.o calc_mem_req.c

gcc -O -DSLM_SWAP_BYTES -c -o compute_back_off.o compute_back_off.c

gcc -O -DSLM_SWAP_BYTES -c -o compute_discount.o compute_discount.c

gcc -O -DSLM_SWAP_BYTES -c -o compute_unigram.o compute_unigram.c

gcc -O -DSLM_SWAP_BYTES -c -o get_ngram.o get_ngram.c

gcc -O -DSLM_SWAP_BYTES -c -o increment_context.o increment_context.c

gcc -O -DSLM_SWAP_BYTES -c -o lookup_index_of.o lookup_index_of.c

gcc -O -DSLM_SWAP_BYTES -c -o short_indices.o short_indices.c

gcc -O -DSLM_SWAP_BYTES -c -o two_byte_alphas.o two_byte_alphas.c

gcc -O -DSLM_SWAP_BYTES -c -o write_lms.o write_lms.c

gcc -O -DSLM_SWAP_BYTES -c -o num_of_types.o num_of_types.c

gcc -O -DSLM_SWAP_BYTES -c -o guess_mem.o guess_mem.c

gcc -O -DSLM_SWAP_BYTES -c -o counts.o counts.c

gcc -O -DSLM_SWAP_BYTES -c -o arpa_bo_ng_prob.o arpa_bo_ng_prob.c

gcc -O -DSLM_SWAP_BYTES -c -o calc_prob_of.o calc_prob_of.c

gcc -O -DSLM_SWAP_BYTES -c -o decode_bo_case.o decode_bo_case.c

gcc -O -DSLM_SWAP_BYTES -c -o gen_fb_list.o gen_fb_list.c

gcc -O -DSLM_SWAP_BYTES -c -o load_lm.o load_lm.c

load_lm.c: In function ‘load_arpa_lm’:

load_lm.c:350: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result

gcc -O -DSLM_SWAP_BYTES -c -o parse_comline.o parse_comline.c

gcc -O -DSLM_SWAP_BYTES -c -o perplexity.o perplexity.c

gcc -O -DSLM_SWAP_BYTES -c -o stats.o stats.c

gcc -O -DSLM_SWAP_BYTES -c -o validate.o validate.c

gcc -O -DSLM_SWAP_BYTES -c -o pc_libs/pc_comline.o pc_libs/pc_comline.c

gcc -O -DSLM_SWAP_BYTES -c -o pc_libs/pc_message.o pc_libs/pc_message.c

gcc -O -DSLM_SWAP_BYTES -c -o rr_libs/parse_line.o rr_libs/parse_line.c

gcc -O -DSLM_SWAP_BYTES -c -o rr_libs/quit.o rr_libs/quit.c

rr_libs/quit.c: In function ‘quit’:

rr_libs/quit.c:30: warning: incompatible implicit declaration of built-in function ‘exit’

gcc -O -DSLM_SWAP_BYTES -c -o rr_libs/rd_wlist_arry.o rr_libs/rd_wlist_arry.c

gcc -O -DSLM_SWAP_BYTES -c -o rr_libs/read_voc.o rr_libs/read_voc.c

gcc -O -DSLM_SWAP_BYTES -c -o rr_libs/read_wlist_si.o rr_libs/read_wlist_si.c

gcc -O -DSLM_SWAP_BYTES -c -o rr_libs/rr_calloc.o rr_libs/rr_calloc.c

gcc -O -DSLM_SWAP_BYTES -c -o rr_libs/rr_feof.o rr_libs/rr_feof.c

gcc -O -DSLM_SWAP_BYTES -c -o rr_libs/rr_fexists.o rr_libs/rr_fexists.c

gcc -O -DSLM_SWAP_BYTES -c -o rr_libs/rr_filesize.o rr_libs/rr_filesize.c

gcc -O -DSLM_SWAP_BYTES -c -o rr_libs/rr_fopen.o rr_libs/rr_fopen.c

gcc -O -DSLM_SWAP_BYTES -c -o rr_libs/rr_fread.o rr_libs/rr_fread.c

gcc -O -DSLM_SWAP_BYTES -c -o rr_libs/rr_fseek.o rr_libs/rr_fseek.c

gcc -O -DSLM_SWAP_BYTES -c -o rr_libs/rr_fwrite.o rr_libs/rr_fwrite.c

gcc -O -DSLM_SWAP_BYTES -c -o rr_libs/rr_iopen.o rr_libs/rr_iopen.c

gcc -O -DSLM_SWAP_BYTES -c -o rr_libs/rr_malloc.o rr_libs/rr_malloc.c

gcc -O -DSLM_SWAP_BYTES -c -o rr_libs/rr_oopen.o rr_libs/rr_oopen.c

gcc -O -DSLM_SWAP_BYTES -c -o rr_libs/salloc.o rr_libs/salloc.c

gcc -O -DSLM_SWAP_BYTES -c -o rr_libs/sih.o rr_libs/sih.c

rr_libs/sih.c: In function ‘sih_val_read_from_file’:

rr_libs/sih.c:255: warning: comparison between pointer and integer

rm -f SLM2.a

ar r SLM2.a bo_ng_prob.o calc_mem_req.o compute_back_off.o compute_discount.o compute_unigram.o get_ngram.o increment_context.o lookup_index_of.o short_indices.o two_byte_alphas.o write_lms.o num_of_types.o guess_mem.o counts.o arpa_bo_ng_prob.o bo_ng_prob.o calc_prob_of.o decode_bo_case.o gen_fb_list.o load_lm.o lookup_index_of.o parse_comline.o perplexity.o short_indices.o stats.o two_byte_alphas.o validate.o num_of_types.o counts.o load_lm.o write_lms.o short_indices.o two_byte_alphas.o num_of_types.o stats.o counts.o get_ngram.o pc_libs/pc_comline.o pc_libs/pc_message.o rr_libs/parse_line.o rr_libs/quit.o rr_libs/rd_wlist_arry.o rr_libs/read_voc.o rr_libs/read_wlist_si.o rr_libs/rr_calloc.o rr_libs/rr_feof.o rr_libs/rr_fexists.o rr_libs/rr_filesize.o rr_libs/rr_fopen.o rr_libs/rr_fread.o rr_libs/rr_fseek.o rr_libs/rr_fwrite.o rr_libs/rr_iopen.o rr_libs/rr_malloc.o rr_libs/rr_oopen.o rr_libs/salloc.o rr_libs/rr_malloc.o rr_libs/rr_oopen.o rr_libs/salloc.o rr_libs/sih.o

ar: creating SLM2.a

if [ `uname` = SunOS -o `uname` = Linux ] ; then ranlib SLM2.a ; fi

gcc -O -DSLM_SWAP_BYTES -o idngram2lm idngram2lm.c SLM2.a -lm

gcc -O -DSLM_SWAP_BYTES -o evallm evallm.c SLM2.a -lm

gcc -O -DSLM_SWAP_BYTES -o text2wngram text2wngram.c SLM2.a -lm

gcc -O -DSLM_SWAP_BYTES -o text2idngram text2idngram.c SLM2.a -lm

gcc -O -DSLM_SWAP_BYTES -o binlm2arpa binlm2arpa.c SLM2.a -lm

gcc -O -DSLM_SWAP_BYTES -o ngram2mgram ngram2mgram.c SLM2.a -lm

gcc -O -DSLM_SWAP_BYTES -o idngram2stats idngram2stats.c SLM2.a -lm

gcc -O -DSLM_SWAP_BYTES -o wfreq2vocab wfreq2vocab.c SLM2.a -lm

gcc -O -DSLM_SWAP_BYTES -o text2wfreq text2wfreq.c SLM2.a -lm

gcc -O -DSLM_SWAP_BYTES -o wngram2idngram wngram2idngram.c SLM2.a -lm

gcc -O -DSLM_SWAP_BYTES -o mergeidngram mergeidngram.c SLM2.a -lm

gcc -O -DSLM_SWAP_BYTES -o interpolate interpolate.c SLM2.a -lm

for i in idngram2lm evallm text2wngram text2idngram binlm2arpa ngram2mgram idngram2stats wfreq2vocab text2wfreq wngram2idngram mergeidngram interpolate; do /

./install-sh $i ../bin; /

done

./install-sh SLM2.a ../lib

 

然后进入giza-pp目录,安装mkclsGIZA++

 

3)安装mkcls-v2

tianliang@ubuntu:~/research/CMU-Cam_Toolkit_v2/src$cd ..

tianliang@ubuntu:~/research/CMU-Cam_Toolkit_v2$cd ..

tianliang@ubuntu:~/research$cd giza-pp

tianliang@ubuntu:~/research/giza-pp$cd mkcls-v2

tianliang@ubuntu:~/research/giza-pp/mkcls-v2$make

 

g++ -Wall -W -DNDEBUG -O3 -Wno-deprecated -c HCOptimization.cpp -o HCOptimization.o
g++ -Wall -W -DNDEBUG -O3 -Wno-deprecated -c IterOptimization.cpp -IterOptimization.o
g++ -Wall -W -DNDEBUG -O3 -Wno-deprecated -c RRTOptimization.cpp -o RRTOptimization.o
g++ -Wall -W -DNDEBUG -O3 -Wno-deprecated -c SAOptimization.cpp -o SAOptimization.o
g++ -Wall -W -DNDEBUG -O3 -Wno-deprecated -c Optimization.cpp -o Optimization.o
g++ -Wall -W -DNDEBUG -O3 -Wno-deprecated -c KategProblemKBC.cpp -o KategProblemKBC.o
g++ -Wall -W -DNDEBUG -O3 -Wno-deprecated -c KategProblem.cpp -o KategProblem.o
g++ -Wall -W -DNDEBUG -O3 -Wno-deprecated -c general.cpp -o general.o
g++ -Wall -W -DNDEBUG -O3 -Wno-deprecated -o mkcls GDAOptimization.o HCOptimization.o Problem.o IterOptimization.o ProblemTest.o RRTOptimization.o MYOptimization.o SAOptimization.o TAOptimization.o Optimization.o KategProblemTest.o KategProblemKBC.o KategProblemWBC.o KategProblem.o StatVar.o general.o mkcls.o 
 

4)安装GIZA++-v2

  首先进入该目录下的Makefile文件夹中,把“-DBINARY_SEARCH_FOR_TTABLE”删除。

tianliang@ubuntu:~/research/giza-pp/mkcls-v2$cd ..

tianliang@ubuntu:~/research/giza-pp$cd GIZA++-v2

tianliang@ubuntu:~/research/giza-pp/GIZA++-v2$make

 

g++   -Wall -W -Wno-deprecated -O3 -DNDEBUG -DWORDINDEX_WITH_4_BYTE -DBINARY_SEARCH_FOR_TTABLE  -c Parameter.cpp -o optimized/Parameter.o
g++   -Wall -W -Wno-deprecated -O3 -DNDEBUG -DWORDINDEX_WITH_4_BYTE -DBINARY_SEARCH_FOR_TTABLE  -c Perplexity.cpp -o optimized/Perplexity.o
g++   -Wall -W -Wno-deprecated -O3 -DNDEBUG -DWORDINDEX_WITH_4_BYTE -DBINARY_SEARCH_FOR_TTABLE  -c model2.cpp -o optimized/model2.o
g++   -Wall -W -Wno-deprecated -O3 -DNDEBUG -DWORDINDEX_WITH_4_BYTE -DBINARY_SEARCH_FOR_TTABLE  -c getSentence.cpp -o optimized/getSentence.o
g++   -Wall -W -Wno-deprecated -O3 -DNDEBUG -DWORDINDEX_WITH_4_BYTE -DBINARY_SEARCH_FOR_TTABLE  -c ATables.cpp -o optimized/ATables.o
g++   -Wall -W -Wno-deprecated -O3 -DNDEBUG -DWORDINDEX_WITH_4_BYTE -DBINARY_SEARCH_FOR_TTABLE  -c main.cpp -o optimized/main.o
g++   -Wall -W -Wno-deprecated -O3 -DNDEBUG -DWORDINDEX_WITH_4_BYTE -DBINARY_SEARCH_FOR_TTABLE  -c model2to3.cpp -o optimized/model2to3.o
g++   -Wall -W -Wno-deprecated -O3 -DNDEBUG -DWORDINDEX_WITH_4_BYTE -DBINARY_SEARCH_FOR_TTABLE  -c alignment.cpp -o optimized/alignment.o
g++   -Wall -W -Wno-deprecated -O3 -DNDEBUG -DWORDINDEX_WITH_4_BYTE -DBINARY_SEARCH_FOR_TTABLE  -c MoveSwapMatrix.cpp -o optimized/MoveSwapMatrix.o
g++   -Wall -W -Wno-deprecated -O3 -DNDEBUG -DWORDINDEX_WITH_4_BYTE -DBINARY_SEARCH_FOR_TTABLE  -c transpair_model5.cpp -o optimized/transpair_model5.o
g++   -Wall -W -Wno-deprecated -O3 -DNDEBUG -DWORDINDEX_WITH_4_BYTE -DBINARY_SEARCH_FOR_TTABLE  -c utility.cpp -o optimized/utility.o
g++   -Wall -W -Wno-deprecated -O3 -DNDEBUG -DWORDINDEX_WITH_4_BYTE -DBINARY_SEARCH_FOR_TTABLE  -c reports.cpp -o optimized/reports.o
g++   -Wall -W -Wno-deprecated -O3 -DNDEBUG -DWORDINDEX_WITH_4_BYTE -DBINARY_SEARCH_FOR_TTABLE  -c model3_viterbi_with_tricks.cpp -o optimized/model3_viterbi_with_tricks.o
g++   -Wall -W -Wno-deprecated -O3 -DNDEBUG -DWORDINDEX_WITH_4_BYTE -DBINARY_SEARCH_FOR_TTABLE  -c model345-peg.cpp -o optimized/model345-peg.o
g++   -Wall -W -Wno-deprecated -O3 -DNDEBUG -DWORDINDEX_WITH_4_BYTE -DBINARY_SEARCH_FOR_TTABLE  -c HMMTables.cpp -o optimized/HMMTables.o
g++  -Wall -W -Wno-deprecated -O3 -DNDEBUG -DWORDINDEX_WITH_4_BYTE -DBINARY_SEARCH_FOR_TTABLE optimized/Parameter.o optimized/myassert.o optimized/Perplexity.o optimized/model1.o optimized/model2.o optimized/model3.o optimized/getSentence.o optimized/TTables.o optimized/ATables.o optimized/AlignTables.o optimized/main.o optimized/NTables.o optimized/model2to3.o optimized/collCounts.o optimized/alignment.o optimized/vocab.o optimized/MoveSwapMatrix.o optimized/transpair_model3.o optimized/transpair_model5.o optimized/transpair_model4.o optimized/utility.o optimized/parse.o optimized/reports.o optimized/model3_viterbi.o optimized/model3_viterbi_with_tricks.o optimized/Dictionary.o optimized/model345-peg.o optimized/hmm.o optimized/HMMTables.o optimized/ForwardBackward.o -static -o GIZA++
g++ -O3 -Wno-deprecated -W -Wall plain2snt.cpp -o plain2snt.out
 
  事实上,在这个系统下运行编译并不是这么顺利,由于都是最新的版本,GIZA++mkcls根本就不能运行,我们可以做的就是更换操作系统或者安装旧版本的软件,不过这些方法我都没有使用,我采用更改软件的源代码或者下载所需的软件的方法,使其正确运行。具体的情况,可以参考附录部分。

其他的软件不需要安装,需要的时候我们会稍加处理的使用。

 

4.    构建语言模型

 

  构建语言模型所用的语料库可以由任何英文句子组成。你甚至可以找一本电子版英文小说作为语料库。这里使用那个1500句英文文档“english1500”添加标记后的english.tag来构建语言模型。分别输入如下的命令:

tianliang@ubuntu:~/research/CMU-Cam_Toolkit_v2/bin$./text2wfreq <english.tag> english.wfreq

 

text2wfreq : Reading text from standard input...

text2wfreq : Done.

 

这里将会生成一个叫english.wfreq  的文件,里面的内容是english文件中所有单词的列表和该单词出现的次数。其中文件的格式如下:

states 2

injections 1

uninteresting 1

halves 1

...

tianliang@ubuntu:~/research/CMU-Cam_Toolkit_v2/bin$./wfreq2vocab <english.wfreq> english.vocab

 

wfreq2vocab : Will generate a vocabulary containing the most

frequent 20000 words. Reading wfreq stream from stdin...

wfreq2vocab : Done.

这里将会生成文中出现的最常用的20000个单词的词汇表文件。文件的格式如下:

A

APO

Aaron

About

Adam

Administrative

….

   更换root身份进入bin目录输入命令

tianliang@ubuntu:~/research/CMU-Cam_Toolkit_v2/bin$ su

Password:

root@ubuntu:/home/tianliang/research/CMU-Cam_Toolkit_v2/bin# ./text2idngram -vocab english.vocab -buffer 5 <english.tag> english.idngram

 

Vocab : english.vocab

N-gram buffer size : 5

Hash table size : 200000

Temp directory : /usr/tmp/

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 /usr/tmp/text2idngram.temp.ubuntu.2923.1

Merging temporary files...

2-grams occurring:             N times           > N times          Sug. -spec_num value

0                                                       15067                     15227

1                              13259               1808                        1836

2                               1005                 803                         821

3                               338                   465                         479

4                               141                   324                         337

5                                76                    248                         260

6                                67                    181                         192

7                                33                    148                         159

8                               25                     123                         134

9                               17                     106                         117

10                             13                      93                           103

3-grams occurring:          N times           > N times          Sug. -spec_num value

0                                                     19835                      20043

1                           18977                858                          876

2                            548                   310                          323

3                            131                   179                          190

4                            57                     122                          133

5                            35                      87                            97

6                            18                      69                            79

7                            15                      54                            64

8                            10                      44                            54

9                             6                       38                             48

10                           4                       34                            44

text2idngram : Done.

这里将会生成一个 english.idngram”文件,其中记录着文本中所有出现的n元模型,以及其出现的次数。

(一般情况下我们不能打开该文件,因为我们使用这种命令运行生成的文件是二进制的形式,里面全部都是01的形式。所以这里不在给出文件的格式。)

成功编译这个文件后,可以继续以root的身份继续运行其他的程序,这里我选择使用管理员的身份“tianliang”来运行其他的过程。

 要想运行最终得到想要的语言模型,我们首先要做些准备,那就是添加一个语言格式。这里很简单,只需新建一个文件命名为english.ccs,里面输入如下的内容后保存即可:

<s>

</s>

tianliang@ubuntu:~/research/CMU-Cam_Toolkit_v2/bin$./idngram2lm -idngram english.idngram -vocab english.vocab -context english.ccs -binary english.binlm

 

n : 3

Input file : english.idngram (binary format)

Output files :

Binary format : english.binlm

Vocabulary file : english.vocab

Context cues file : english.ccs

Cutoffs :

2-gram : 0 3-gram : 0

Vocabulary type : Open - type 1

Minimum unigram count : 0

Zeroton fraction : 1

Counts will be stored in two bytes.

Count table size : 65535

Discounting method : Good-Turing

Discounting ranges :

1-gram : 1 2-gram : 7 3-gram : 7

Memory allocation for tree structure :

Allocate 100 MB of memory, shared equally between all n-gram tables.

Back-off weight storage :

Back-off weights will be stored in four bytes.

Reading vocabulary.

read_wlist_into_siht: a list of 4857 words was read from "english.vocab".

read_wlist_into_array: a list of 4857 words was read from "english.vocab".

Context cue word : <s> id = 43

Context cue word : </s> id = 42

Allocated space for 5000000 2-grams.

Allocated space for 12500000 3-grams.

Allocated 50000000 bytes to table for 2-grams.

Allocated 50000000 bytes to table for 3-grams.

Processing id n-gram file.

20,000 n-grams processed for each ".", 1,000,000 for each line.

Calculating discounted counts.

Warning : 1-gram : Discounting range is 1; setting P(zeroton)=P(singleton).

Discounted value : 1.00

Warning : 2-gram : Some discount values are out of range;

lowering discounting range to 6.

Warning : 2-gram : Some discount values are out of range;

lowering discounting range to 5.

Warning : 2-gram : Some discount values are out of range;

lowering discounting range to 4.

Unigrams's discount mass is 0.000144609 (n1/N = 0.1529)

1 zerotons, P(zeroton) = 0.000144609 P(singleton) = 4.82029e-05

P(zeroton) was reduced to 0.0000482029 (1.000 of P(singleton))

Unigram was renormalized to absorb a mass of 9.64059e-05

prob[UNK] = 4.82076e-05

Incrementing contexts...

Calculating back-off weights...

Writing out language model...

Binary 3-gram language model will be written to english.binlm

idngram2lm : Done.

  接下来我们可以进行简单的语言模型的计算。比如说,我们可以利用刚才生成的可执行命令:evallm来进行一句话的perplexity。比如我们要计算“”perplexity,首先我们在./bin目录下新建一个文件命名为“english.text”,然后在命令行中输入命令即可执行计算,过程如下:

 tianliang@ubuntu:/home/tianliang/research/CMU-Cam_Toolkit_v21/bin# ./evallm -binary english.binlm

 

Reading in language model from file english.binlm

Done.

 

evallm :perplexity -text english.text

 

Computing perplexity of the language model with respect

 

  to the text english.text

 

Perplexity = 37.52, Entropy = 5.23 bits

 

Computation based on 18 words.

 

Number of 3-grams hit = 16 (88.89%)

 

Number of 2-grams hit = 1 (5.56%)

 

Number of 1-grams hit = 1 (5.56%)

 

0 OOVs (0.00%) and 0 context cues were removed from the calculation.

 

5.   构建翻译模型

 

     翻译模型的构建是利用mkclsGIZA++来完成的,我们首先要利用mkcls来进行单词聚类,然后利用GIZA++来进行单词的统计和中英词语的对齐。首先来进行单词的归类;

    1.进入mkcls-v2目录下,把1000句的英文和中文对照语料库拷贝到该目录下。使用如下的命令,分别输出中文和英文的分类后的文件:

     mkcls [-cnum] -nnumm –planguage–Vlanguage.vcb.classes opt

       -c:表示把生成的文件分成多少类。这里我们把输出的.vcb.classes文件中的单词进行归成80个类。
-n:
表示训练迭代的次数,一般迭代次数越多输出的结果越好,默认值是1
-p:
要聚类的文本,一行一句(已分词)
-V:
输出信息

opt:
优化运行

  程序的运行结果将生成两个文件:language.vcb.classeslanguage.vcb.classes.cats

  注:这里的catscategories的缩写。

(1)mkcls-v2目录下进行汉语单词的归类。

tianliang@ubuntu:~/research$cd giza-pp

tianliang@ubuntu:~/research/giza-pp$cd mkcls-v2

tianliang~/research/giza-pp/mkcls-v2$./mkcls -c80 -n10 -pchinese -Vchinese.vcb.classes opt

 

***** 10 runs. (algorithm:TA)*****

;KategProblem:cats: 80 words: 4533

start-costs: MEAN: 143716 (143465-144630) SIGMA:333.132

end-costs: MEAN: 123877 (123766-124181) SIGMA:119.003

start-pp: MEAN: 408.642 (402.046-433.035) SIGMA:8.85202

end-pp: MEAN: 115.403 (114.584-117.654) SIGMA:0.880529

iterations: MEAN: 105580 (102618-108697) SIGMA:2001.06

time: MEAN: 3.94505 (3.83224-4.05625) SIGMA:0.0745121

 这里将生成两个文件:chinese.vcb.classeschinese.vcb.classes.cats,两个文件的格式如下:

chinese.vcb.classes

!  22

"  18

(  75

1824 8

1837 18

1889 81

一举一动   62

一些   78

一会   41

chinese.vcb.classes.cats

2:OACB,,,,内普丘,冒充,后肢,听到,国会,,填充,处于,容许,,彼此,扮演,,抚摸,护照,按照,时不时,时而,,本来,沿着,看看,看见,综合,表明,驶抵,

5:x,”,伦敦,,做到,,,凡夫俗子,分离,劝告,包裹,,回来,妙语,定下,射线,小径,,庆典,库存,,开辟,,拍摄,,,架次,歉意,母亲,气味,治标,法令,,火鸡,,,画笔,,,瘫痪,盘桓,,,站住,,繁荣,,良药,芝加哥,花园,行囊,行李,观赏,赶走,身份,身手,过度,进步,适用,通行,那天,

80...

...

这个文件总共有80个类(categories),刚才提到的-c80也就是这个意思。实际上仔细观察文件的内容可以看到,单词的排列也是有点规则的,先是标点,然后是英文,最后才是汉语的单词。当然这里前提是我已经提前对汉语进行了分词。

(2)mkcls-v2目录下进行英语的归类

tianliang@~/research/giza-pp/mkcls-v2$./mkcls -c80 -n10 -penglish -Venglish.vcb.classes opt

***** 10 runs. (algorithm:TA)*****

;KategProblem:cats: 80 words: 3787

start-costs: MEAN: 135707 (135556-136084) SIGMA:152.356

end-costs: MEAN: 115873 (115693-116045) SIGMA:132.413

start-pp: MEAN: 294.859 (291.883-302.333) SIGMA:3.01245

end-pp: MEAN: 78.6815 (77.7415-79.5838) SIGMA:0.69391

iterations: MEAN: 91183.9 (88015-99855) SIGMA:3249.42

time: MEAN: 3.44782 (3.32821-3.78424) SIGMA:0.126858

这里将生成两个文件:english.vcb.classesenglish.vcb.classes.cats,两个文件的格式如下:

english.vcb.classes

!     47

"     41

%   37

10   32

11   68

115 76

A    80

APO      12

Aaron    50

About    80

english.vcb.classes.cats

2:After,Again,All,Along,Although,Among,And,Are,As,Because,Bernard,Between,Briefly,But,By,Clearly,Clifton...Water,Were,Western,When,Whenever,While,Wine,With,Would,Yet,Your,“,

5:',1950,52,Corps,named,newly,

   英语的归类是按照字母的顺序进行的。

注意:这里文件生成的速度相对来讲较慢,这要视我们所选择的语言文件的大小决定,这里仅仅是1000句的中英文对照语料库,还不是特别的大,基本上,如果电脑还可以的话,都能在一分钟内运行完毕。

2. 进入GIZA++-v2目录下,把1000句的英文和中文对照语料库拷贝到该目录下。使用如下的命令,生成相应的文件:
./plain2snt.outlanguage1 language2

 其中“plain2snt.out”是编译GIZA++自动生成的一个可执行文件,其作用是统计单词数以及单词格式的转换。

tianliang@ubuntu:~/research/giza-pp/GIZA++-v2$./plain2snt.out chinese english

chinese -> chinese

english -> english

 

成功运行后将会生成以下四个文件:

chinese.vcb :统计中文单词数。格式是:单词编号单词单词出现次数。如下所示:

2由于 22

3这个 39

4缘故 1

5 965

chinese_english.snt :统计汉英句子。格式是:

句子出现次数
汉语句子
英语句子

  形式如下:

1

2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 13 17 18

english.vcb :统计英文单词数。格式是:单词编号单词单词出现次数。如下所示:

2 For 12

3 this 61

4 reason 5

5 it 84

english_chinese.snt :统计英汉句子。格式是:

句子出现次数

英语句子

汉语句子

  形式如下:

1

2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 13 17 18

2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

 

  由于接下来的词语的对齐将会产生很多的文件,为了便于查找和访问,这里我们可以在GIZA++-v2目录下建立一个test子目录。这里只须把刚才生成的四个文件和mkcls生成的四个类文件,再加上编译后的可执行文件GIZA++一同拷贝到该子目录下即可编译运行.这样生成后的文件全都在这个目录下,我们可以便于以后的运用。

  进入test目录,然后使用下面的词语对齐命令:

   ./GIZA++ -S chinese.vcb -T english.vcb -C chinese_english.snt (-O c2e)
-S:
源语言单词表

-T:
目标语言单词表
-C:
源语言〉目标语言句子对
-O:
输出文件夹
运行结束后,输出很多文件到c2e/文件夹中,主要是产生的对齐文件。由于我们已经事先建立了一个test目录,所以我们就不必使用-O c2e”参数了。

tianliang@ubuntu:~/research/giza-pp/GIZA++-v2$cd test

tianliang@ubuntu:~/research/giza-pp/GIZA++-v2/test$./GIZA++ -S english.vcb -T chinese.vcb -C english_chinese.snt

Parameter 's' changed from '' to 'english.vcb'

Parameter 't' changed from '' to 'chinese.vcb'

Parameter 'c' changed from '' to 'english_chinese.snt'

general parameters:

-------------------

ml = 101 (maximum sentence length)

No. of iterations:

-------------------

hmmiterations = 5 (mh)

model1iterations = 5 (number of iterations for Model 1)

model2iterations = 0 (number of iterations for Model 2)

model3iterations = 5 (number of iterations for Model 3)

model4iterations = 5 (number of iterations for Model 4)

model5iterations = 0 (number of iterations for Model 5)

model6iterations = 0 (number of iterations for Model 6)

parameter for various heuristics in GIZA++ for efficient training:

------------------------------------------------------------------

countincreasecutoff = 1e-06 (Counts increment cutoff threshold)

countincreasecutoffal = 1e-05 (Counts increment cutoff threshold for alignments in training of fertility models)

mincountincrease = 1e-07 (minimal count increase)

peggedcutoff = 0.03 (relative cutoff probability for alignment-centers in pegging)

probcutoff = 1e-07 (Probability cutoff threshold for lexicon probabilities)

probsmooth = 1e-07 (probability smoothing (floor) value )

parameters for describing the type and amount of output:

-----------------------------------------------------------

compactalignmentformat = 0 (0: detailled alignment format, 1: compact alignment format )

hmmdumpfrequency = 0 (dump frequency of HMM)

l = 2009-12-22.210058.tianliang.log (log file name)

log = 0 (0: no logfile; 1: logfile)

model1dumpfrequency = 0 (dump frequency of Model 1)

model2dumpfrequency = 0 (dump frequency of Model 2)

model345dumpfrequency = 0 (dump frequency of Model 3/4/5)

nbestalignments = 0 (for printing the n best alignments)

nodumps = 0 (1: do not write any files)

o = 2009-12-22.210058.tianliang (output file prefix)

onlyaldumps = 0 (1: do not write any files)

outputpath = (output path)

transferdumpfrequency = 0 (output: dump of transfer from Model 2 to 3)

verbose = 0 (0: not verbose; 1: verbose)

verbosesentence = -10 (number of sentence for which a lot of information should be printed (negative: no output))

parameters describing input files:

----------------------------------

c = english_chinese.snt (training corpus file name)

d = (dictionary file name)

s = english.vcb (source vocabulary file name)

t = chinese.vcb (target vocabulary file name)

tc = (test corpus file name)

smoothing parameters:

---------------------

emalsmooth = 0.2 (f-b-trn: smoothing factor for HMM alignment model (can be ignored by -emSmoothHMM))

model23smoothfactor = 0 (smoothing parameter for IBM-2/3 (interpolation with constant))

model4smoothfactor = 0.2 (smooting parameter for alignment probabilities in Model 4)

model5smoothfactor = 0.1 (smooting parameter for distortion probabilities in Model 5 (linear interpolation with constant))

nsmooth = 64 (smoothing for fertility parameters (good value: 64): weight for wordlength-dependent fertility parameters)

nsmoothgeneral = 0 (smoothing for fertility parameters (default: 0): weight for word-independent fertility parameters)

parameters modifying the models:

--------------------------------

compactadtable = 1 (1: only 3-dimensional alignment table for IBM-2 and IBM-3)

deficientdistortionforemptyword = 0 (0: IBM-3/IBM-4 as described in (Brown et al. 1993); 1: distortion model of empty word is deficient; 2: distoriton model of empty word is deficient (differently); setting this parameter also helps to avoid that during IBM-3 and IBM-4 training too many words are aligned with the empty word)

depm4 = 76 (d_{=1}: &1:l, &2:m, &4:F, &8:E, d_{>1}&16:l, &32:m, &64:F, &128:E)

depm5 = 68 (d_{=1}: &1:l, &2:m, &4:F, &8:E, d_{>1}&16:l, &32:m, &64:F, &128:E)

emalignmentdependencies = 2 (lextrain: dependencies in the HMM alignment model. &1: sentence length; &2: previous class; &4: previous position; &8: French position; &16: French class)

emprobforempty = 0.4 (f-b-trn: probability for empty word)

parameters modifying the EM-algorithm:

--------------------------------------

m5p0 = -1 (fixed value for parameter p_0 in IBM-5 (if negative then it is determined in training))

manlexfactor1 = 0 ()

manlexfactor2 = 0 ()

manlexmaxmultiplicity = 20 ()

maxfertility = 10 (maximal fertility for fertility models)

p0 = -1 (fixed value for parameter p_0 in IBM-3/4 (if negative then it is determined in training))

pegging = 0 (0: no pegging; 1: do pegging)

general parameters:

-------------------

ml = 101 (maximum sentence length)

No. of iterations:

-------------------

hmmiterations = 5 (mh)

model1iterations = 5 (number of iterations for Model 1)

model2iterations = 0 (number of iterations for Model 2)

model3iterations = 5 (number of iterations for Model 3)

model4iterations = 5 (number of iterations for Model 4)

model5iterations = 0 (number of iterations for Model 5)

model6iterations = 0 (number of iterations for Model 6)

parameter for various heuristics in GIZA++ for efficient training:

------------------------------------------------------------------

countincreasecutoff = 1e-06 (Counts increment cutoff threshold)

countincreasecutoffal = 1e-05 (Counts increment cutoff threshold for alignments in training of fertility models)

mincountincrease = 1e-07 (minimal count increase)

peggedcutoff = 0.03 (relative cutoff probability for alignment-centers in pegging)

probcutoff = 1e-07 (Probability cutoff threshold for lexicon probabilities)

probsmooth = 1e-07 (probability smoothing (floor) value )

parameters for describing the type and amount of output:

-----------------------------------------------------------

compactalignmentformat = 0 (0: detailled alignment format, 1: compact alignment format )

hmmdumpfrequency = 0 (dump frequency of HMM)

l = 2009-12-22.210058.tianliang.log (log file name)

log = 0 (0: no logfile; 1: logfile)

model1dumpfrequency = 0 (dump frequency of Model 1)

model2dumpfrequency = 0 (dump frequency of Model 2)

model345dumpfrequency = 0 (dump frequency of Model 3/4/5)

nbestalignments = 0 (for printing the n best alignments)

nodumps = 0 (1: do not write any files)

o = 2009-12-22.210058.tianliang (output file prefix)

onlyaldumps = 0 (1: do not write any files)

outputpath = (output path)

transferdumpfrequency = 0 (output: dump of transfer from Model 2 to 3)

verbose = 0 (0: not verbose; 1: verbose)

verbosesentence = -10 (number of sentence for which a lot of information should be printed (negative: no output))

parameters describing input files:

----------------------------------

c = english_chinese.snt (training corpus file name)

d = (dictionary file name)

s = english.vcb (source vocabulary file name)

t = chinese.vcb (target vocabulary file name)

tc = (test corpus file name)

smoothing parameters:

---------------------

emalsmooth = 0.2 (f-b-trn: smoothing factor for HMM alignment model (can be ignored by -emSmoothHMM))

model23smoothfactor = 0 (smoothing parameter for IBM-2/3 (interpolation with constant))

model4smoothfactor = 0.2 (smooting parameter for alignment probabilities in Model 4)

model5smoothfactor = 0.1 (smooting parameter for distortion probabilities in Model 5 (linear interpolation with constant))

nsmooth = 64 (smoothing for fertility parameters (good value: 64): weight for wordlength-dependent fertility parameters)

nsmoothgeneral = 0 (smoothing for fertility parameters (default: 0): weight for word-independent fertility parameters)

parameters modifying the models:

--------------------------------

compactadtable = 1 (1: only 3-dimensional alignment table for IBM-2 and IBM-3)

deficientdistortionforemptyword = 0 (0: IBM-3/IBM-4 as described in (Brown et al. 1993); 1: distortion model of empty word is deficient; 2: distoriton model of empty word is deficient (differently); setting this parameter also helps to avoid that during IBM-3 and IBM-4 training too many words are aligned with the empty word)

depm4 = 76 (d_{=1}: &1:l, &2:m, &4:F, &8:E, d_{>1}&16:l, &32:m, &64:F, &128:E)

depm5 = 68 (d_{=1}: &1:l, &2:m, &4:F, &8:E, d_{>1}&16:l, &32:m, &64:F, &128:E)

emalignmentdependencies = 2 (lextrain: dependencies in the HMM alignment model. &1: sentence length; &2: previous class; &4: previous position; &8: French position; &16: French class)

emprobforempty = 0.4 (f-b-trn: probability for empty word)

parameters modifying the EM-algorithm:

--------------------------------------

m5p0 = -1 (fixed value for parameter p_0 in IBM-5 (if negative then it is determined in training))

manlexfactor1 = 0 ()

manlexfactor2 = 0 ()

manlexmaxmultiplicity = 20 ()

maxfertility = 10 (maximal fertility for fertility models)

p0 = -1 (fixed value for parameter p_0 in IBM-3/4 (if negative then it is determined in training))

pegging = 0 (0: no pegging; 1: do pegging)

reading vocabulary files

Reading vocabulary file from:english.vcb

Reading vocabulary file from:chinese.vcb

Source vocabulary list has 3788 unique tokens

Target vocabulary list has 4534 unique tokens

Calculating vocabulary frequencies from corpus english_chinese.snt

Reading more sentence pairs into memory ...

Corpus fits in memory, corpus has: 1000 sentence pairs.

Train total # sentence pairs (weighted): 1000

Size of source portion of the training corpus: 14014 tokens

Size of the target portion of the training corpus: 14693 tokens

In source portion of the training corpus, only 3787 unique tokens appeared

In target portion of the training corpus, only 4532 unique tokens appeared

lambda for PP calculation in IBM-1,IBM-2,HMM:= 14693/(15014-1000)== 1.04845

==========================================================

Model1 Training Started at: Tue Dec 22 21:00:58 2009

-----------

Model1: Iteration 1

Model1: (1) TRAIN CROSS-ENTROPY 12.4032 PERPLEXITY 5416.78

Model1: (1) VITERBI TRAIN CROSS-ENTROPY 16.3995 PERPLEXITY 86445.7

Model 1 Iteration: 1 took: 0 seconds

-----------

Model1: Iteration 2

Model1: (2) TRAIN CROSS-ENTROPY 5.67807 PERPLEXITY 51.2

Model1: (2) VITERBI TRAIN CROSS-ENTROPY 8.10303 PERPLEXITY 274.951

Model 1 Iteration: 2 took: 0 seconds

-----------

Model1: Iteration 3

Model1: (3) TRAIN CROSS-ENTROPY 5.28748 PERPLEXITY 39.0563

Model1: (3) VITERBI TRAIN CROSS-ENTROPY 7.44039 PERPLEXITY 173.693

Model 1 Iteration: 3 took: 0 seconds

-----------

Model1: Iteration 4

Model1: (4) TRAIN CROSS-ENTROPY 5.12503 PERPLEXITY 34.8969

Model1: (4) VITERBI TRAIN CROSS-ENTROPY 7.06572 PERPLEXITY 133.966

Model 1 Iteration: 4 took: 0 seconds

-----------

Model1: Iteration 5

Model1: (5) TRAIN CROSS-ENTROPY 5.0467 PERPLEXITY 33.0529

Model1: (5) VITERBI TRAIN CROSS-ENTROPY 6.84159 PERPLEXITY 114.69

Model 1 Iteration: 5 took: 0 seconds

Entire Model1 Training took: 0 seconds

NOTE: I am doing iterations with the HMM model!

Read classes: #words: 3787 #classes: 81

Read classes: #words: 4533 #classes: 81

==========================================================

Hmm Training Started at: Tue Dec 22 21:00:58 2009

-----------

Hmm: Iteration 1

A/D table contains 18310 parameters.

Hmm: (1) TRAIN CROSS-ENTROPY 5.00283 PERPLEXITY 32.0629

Hmm: (1) VITERBI TRAIN CROSS-ENTROPY 6.69706 PERPLEXITY 103.757

Hmm Iteration: 1 took: 0 seconds

-----------

Hmm: Iteration 2

A/D table contains 18310 parameters.

Hmm: (2) TRAIN CROSS-ENTROPY 4.9798 PERPLEXITY 31.5551

Hmm: (2) VITERBI TRAIN CROSS-ENTROPY 5.95189 PERPLEXITY 61.9011

Hmm Iteration: 2 took: 0 seconds

-----------

Hmm: Iteration 3

A/D table contains 18310 parameters.

Hmm: (3) TRAIN CROSS-ENTROPY 4.63323 PERPLEXITY 24.8165

Hmm: (3) VITERBI TRAIN CROSS-ENTROPY 5.22902 PERPLEXITY 37.5053

Hmm Iteration: 3 took: 1 seconds

-----------

Hmm: Iteration 4

A/D table contains 18310 parameters.

Hmm: (4) TRAIN CROSS-ENTROPY 4.25292 PERPLEXITY 19.0659

Hmm: (4) VITERBI TRAIN CROSS-ENTROPY 4.65021 PERPLEXITY 25.1103

Hmm Iteration: 4 took: 0 seconds

-----------

Hmm: Iteration 5

A/D table contains 18310 parameters.

Hmm: (5) TRAIN CROSS-ENTROPY 3.94249 PERPLEXITY 15.3748

Hmm: (5) VITERBI TRAIN CROSS-ENTROPY 4.23564 PERPLEXITY 18.8388

Hmm Iteration: 5 took: 0 seconds

Entire Hmm Training took: 1 seconds

==========================================================

Read classes: #words: 3787 #classes: 81

Read classes: #words: 4533 #classes: 81

Read classes: #words: 3787 #classes: 81

Read classes: #words: 4533 #classes: 81

==========================================================

Starting H3333344444: Viterbi Training

H3333344444 Training Started at: Tue Dec 22 21:00:59 2009

---------------------

THTo3: Iteration 1

#centers(pre/hillclimbed/real): 1 1 1 #al: 338.455 #alsophisticatedcountcollection: 0 #hcsteps: 0

#peggingImprovements: 0

A/D table contains 18310 parameters.

A/D table contains 19646 parameters.

NTable contains 37880 parameter.

p0_count is 12011.1 and p1 is 1340.96; p0 is 0.899569 p1: 0.100431

THTo3: TRAIN CROSS-ENTROPY 3.63184 PERPLEXITY 12.3964

THTo3: (1) TRAIN VITERBI CROSS-ENTROPY 3.74642 PERPLEXITY 13.421

THTo3 Viterbi Iteration : 1 took: 0 seconds

---------------------

Model3: Iteration 2

#centers(pre/hillclimbed/real): 1 1 1 #al: 338.214 #alsophisticatedcountcollection: 0 #hcsteps: 1.884

#peggingImprovements: 0

A/D table contains 18310 parameters.

A/D table contains 19612 parameters.

NTable contains 37880 parameter.

p0_count is 11492.8 and p1 is 1600.12; p0 is 0.877787 p1: 0.122213

Model3: TRAIN CROSS-ENTROPY 4.81531 PERPLEXITY 28.1548

Model3: (2) TRAIN VITERBI CROSS-ENTROPY 4.90601 PERPLEXITY 29.9818

Model3 Viterbi Iteration : 2 took: 1 seconds

---------------------

Model3: Iteration 3

#centers(pre/hillclimbed/real): 1 1 1 #al: 338.47 #alsophisticatedcountcollection: 0 #hcsteps: 1.939

#peggingImprovements: 0

A/D table contains 18310 parameters.

A/D table contains 19612 parameters.

NTable contains 37880 parameter.

p0_count is 11369 and p1 is 1662.02; p0 is 0.872456 p1: 0.127544

Model3: TRAIN CROSS-ENTROPY 4.69194 PERPLEXITY 25.8473

Model3: (3) TRAIN VITERBI CROSS-ENTROPY 4.76687 PERPLEXITY 27.2251

Model3 Viterbi Iteration : 3 took: 0 seconds

---------------------

Model3: Iteration 4

#centers(pre/hillclimbed/real): 1 1 1 #al: 338.913 #alsophisticatedcountcollection: 0 #hcsteps: 1.974

#peggingImprovements: 0

A/D table contains 18310 parameters.

A/D table contains 19458 parameters.

NTable contains 37880 parameter.

p0_count is 11342.3 and p1 is 1675.34; p0 is 0.871303 p1: 0.128697

Model3: TRAIN CROSS-ENTROPY 4.6338 PERPLEXITY 24.8263

Model3: (4) TRAIN VITERBI CROSS-ENTROPY 4.7028 PERPLEXITY 26.0425

Model3 Viterbi Iteration : 4 took: 0 seconds

---------------------

Model3: Iteration 5

#centers(pre/hillclimbed/real): 1 1 1 #al: 339.198 #alsophisticatedcountcollection: 0 #hcsteps: 2.014

#peggingImprovements: 0

A/D table contains 18310 parameters.

A/D table contains 19317 parameters.

NTable contains 37880 parameter.

p0_count is 11341.2 and p1 is 1675.89; p0 is 0.871255 p1: 0.128745

Model3: TRAIN CROSS-ENTROPY 4.59112 PERPLEXITY 24.1027

Model3: (5) TRAIN VITERBI CROSS-ENTROPY 4.65553 PERPLEXITY 25.2032

Model3 Viterbi Iteration : 5 took: 0 seconds

---------------------

T3To4: Iteration 6

#centers(pre/hillclimbed/real): 1 1 1 #al: 339.466 #alsophisticatedcountcollection: 17.663 #hcsteps: 1.992

#peggingImprovements: 0

D4 table contains 1081381 parameters.

A/D table contains 18310 parameters.

A/D table contains 19215 parameters.

NTable contains 37880 parameter.

p0_count is 11345.3 and p1 is 1673.87; p0 is 0.87143 p1: 0.12857

T3To4: TRAIN CROSS-ENTROPY 4.55514 PERPLEXITY 23.5091

T3To4: (6) TRAIN VITERBI CROSS-ENTROPY 4.6155 PERPLEXITY 24.5134

T3To4 Viterbi Iteration : 6 took: 0 seconds

---------------------

Model4: Iteration 7

#centers(pre/hillclimbed/real): 1 1 1 #al: 339.667 #alsophisticatedcountcollection: 11.1 #hcsteps: 1.861

#peggingImprovements: 0

D4 table contains 1081381 parameters.

A/D table contains 18310 parameters.

A/D table contains 18626 parameters.

NTable contains 37880 parameter.

p0_count is 11365.5 and p1 is 1663.76; p0 is 0.872306 p1: 0.127694

Model4: TRAIN CROSS-ENTROPY 3.81553 PERPLEXITY 14.0796

Model4: (7) TRAIN VITERBI CROSS-ENTROPY 3.85087 PERPLEXITY 14.4287

Model4 Viterbi Iteration : 7 took: 1 seconds

---------------------

Model4: Iteration 8

#centers(pre/hillclimbed/real): 1 1 1 #al: 339.814 #alsophisticatedcountcollection: 8.38 #hcsteps: 1.763

#peggingImprovements: 0

D4 table contains 1081381 parameters.

A/D table contains 18310 parameters.

A/D table contains 18312 parameters.

NTable contains 37880 parameter.

p0_count is 11401.9 and p1 is 1645.53; p0 is 0.873881 p1: 0.126119

Model4: TRAIN CROSS-ENTROPY 3.71244 PERPLEXITY 13.1086

Model4: (8) TRAIN VITERBI CROSS-ENTROPY 3.74074 PERPLEXITY 13.3683

Model4 Viterbi Iteration : 8 took: 0 seconds

---------------------

Model4: Iteration 9

#centers(pre/hillclimbed/real): 1 1 1 #al: 339.954 #alsophisticatedcountcollection: 7.256 #hcsteps: 1.717

#peggingImprovements: 0

D4 table contains 1081381 parameters.

A/D table contains 18310 parameters.

A/D table contains 18114 parameters.

NTable contains 37880 parameter.

p0_count is 11431.4 and p1 is 1630.8; p0 is 0.875151 p1: 0.124849

Model4: TRAIN CROSS-ENTROPY 3.66637 PERPLEXITY 12.6966

Model4: (9) TRAIN VITERBI CROSS-ENTROPY 3.69192 PERPLEXITY 12.9234

Model4 Viterbi Iteration : 9 took: 1 seconds

---------------------

Model4: Iteration 10

#centers(pre/hillclimbed/real): 1 1 1 #al: 340.049 #alsophisticatedcountcollection: 6.616 #hcsteps: 1.698

#peggingImprovements: 0

D4 table contains 1081381 parameters.

A/D table contains 18310 parameters.

A/D table contains 18046 parameters.

NTable contains 37880 parameter.

p0_count is 11453.8 and p1 is 1619.61; p0 is 0.876114 p1: 0.123886

Model4: TRAIN CROSS-ENTROPY 3.64139 PERPLEXITY 12.4787

Model4: (10) TRAIN VITERBI CROSS-ENTROPY 3.66511 PERPLEXITY 12.6855

Dumping alignment table (a) to file:2009-12-22.210058.tianliang.a3.final

Dumping distortion table (d) to file:2009-12-22.210058.tianliang.d3.final

Dumping nTable to: 2009-12-22.210058.tianliang.n3.final

Model4 Viterbi Iteration : 10 took: 1 seconds

H3333344444 Training Finished at: Tue Dec 22 21:01:03 2009

Entire Viterbi H3333344444 Training took: 4 seconds

==========================================================

writing Final tables to Disk

Dumping the t table inverse to file: 2009-12-22.210058.tianliang.ti.final

Dumping the t table inverse to file: 2009-12-22.210058.tianliang.actual.ti.final

Writing PERPLEXITY report to: 2009-12-22.210058.tianliang.perp

Writing source vocabulary list to : 2009-12-22.210058.tianliang.trn.src.vcb

Writing source vocabulary list to : 2009-12-22.210058.tianliang.trn.trg.vcb

Writing source vocabulary list to : 2009-12-22.210058.tianliang.tst.src.vcb

Writing source vocabulary list to : 2009-12-22.210058.tianliang.tst.trg.vcb

writing decoder configuration file to 2009-12-22.210058.tianliang.Decoder.config

Entire Training took: 5 seconds

Program Finished at: Tue Dec 22 21:01:03 2009

 

  运行结束后将会生成许多文件,这里简单的给出部分运行的结果的形式:

对齐文件~.A3.final

# Sentence pair (1) source length 18 target length 17 alignment score : 2.64625e-21

由于这个缘故透明地质图地球化学

NULL ({ 4 9 }) For ({ }) this ({ }) reason ({ }) it ({ }) is ({ }) often ({ }) convenient ({ 5 6 7 8 10 }) to ({ }) overlay ({ 11 }) the ({ }) geochemical ({ 12 13 14 15 }) map ({ 16 }) with ({ }) a ({ }) geological ({ }) map ({ }) transparency ({ 1 2 3 }) . ({ 17 })

解码器调用模板~.Decoder.config

  这是个很重要的文件,在接下来的解码器将会使用这个文件,其中这里还有一个FZeroWords,这个文件将会调用绝大部分文件,详细的内容如下:

TTable = 110-01-18.093912.tianliang.t3.final # translation table

InverseTTable = 110-01-18.093912.tianliang.ti.final# inverse translation table

NTable = 110-01-18.093912.tianliang.n3.final# fertility table

D3Table = 110-01-18.093912.tianliang.d3.final# distortion table for model 3

D4Table = 110-01-18.093912.tianliang.D4.final# distortion table for model 4

PZero = 110-01-18.093912.tianliang.p0_3.final# contains p0 for the model

Source.vcb = english.vcb# maps from words to word IDs

Target.vcb = chinese.vcb# maps from words to word IDs

Source.classes = english.vcb.classes

Target.classes = chinese.vcb.classes

FZeroWords      = 2009-12-22.210058.tianliang.fe0_3.final# file with (English) zero fertility words

 

6.   构建解码器

 

1.编写配置文件和输入文件

进入解码器isi-rewrite-decoder-r1.0.0a目录下的linux子目录,分别新建文件“decoder.cfg”“input.xml”,内容如下:

decoder.cfg

LanguageModelFile=/home/tianliang/research/CMU-Cam_Toolkit_v2/bin/English.binlm

TranslationModelConfigFile=/home/tianliang/research/giza-pp/GIZA++-v2/test/2009-12 22.210058.Decoder.config

PrintAlignment=true

PrintProbabilities=true

input.xml

 

<?xml version="1.0" encoding="utf-8"?>

<doc>

<s id="1">中国 孩子  十分 活泼</s>

<s id="2">美国  中国 </s>

<s id="3">由于 这个 缘故     透明  地质图   地球化学    </s>

</doc>

     

    2.复制文件

/home/tianliang/research/giza-pp/GIZA++-v2/test/中的文件全部复制到~/isi-rewrite-decoder-r1.0.0a/linux

     3.生成FZeroWords

 /home/tianliang/research/isi-rewrite-decoder-r1.0.0a/linux中的”2009-12-22.210058.tianliang.trn.src.vcb””2009-12-22.210058.tianliang.n3.final”复制到/home/tianliang/research/isi-rewrite-decoder-r1.0.0a/util中,然后执行如下的命令;

ianliang@ubuntu:~/research/giza-pp$ cd ..

tianliang@ubuntu:~/research$ cd isi-rewrite-decoder-r1.0.0a

tianliang@ubuntu:~/research/isi-rewrite-decoder-r1.0.0a$ cd util

tianliang@ubuntu:~/research/isi-rewrite-decoder-r1.0.0a/util$ ./rewrite.mkZeroFert.perl 2009-12-22.210058.tianliang.trn.src.vcb 2009-12-22.210058.tianliang.n3.final

of 0.97179

the 0.970341

to 0.964017

, 0.877812

a 0.775534

and 0.730173

 然后在/home/tianliang/research/isi-rewrite-decoder-r1.0.0a/linux下新建一个新文件命名为“2009-12-22.210058.tianliang.fe0_3.final”,把刚才运行出现的单词每行一个单词存入文档。

 这个文档中的单词就是繁殖概率(fertility)为零的单词,也就是说这几个单词没有对应的中文翻译。格式如下所示:

 

of

the

to

,

a,

and

注意:文件中的输入为每行一个单词,即使每行又多输入其他的单词,在运行的时候,也会忽略。

 

3.     设定环境变量

 

还是在linux目录下,输入命令:

[tianliang@localhost isi-rewrite-decoder-r1.0.0a]$cd linux

[tianliang@localhost linux]$export LD_LIBRARY_PATH=/home/tianliang/research/isi-rewrite-decoder-r1.0.0a/linux

7.   运行结果

输入命令:

tianliang@ubuntu:~/research/isi-rewrite-decoder-r1.0.0a/linux$ ./decoder.linux.public --config decoder.cfg input.xml

 

+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+ ++++++++++++++++++++++++++++++++++++

|            ISI ReWrite Decoder, Release 1.0.0a             |

|      (c) 2000­2003 University of Southern California |

|        Written by Ulrich Germann and Daniel Marcu. |

+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+ +++++++++++++++++++++++++++++++++++

starting decoder, please be patient ...

Warning: No Decoding Algorithm was specified. Will use default (greedy1).

Using Fast Greedy Decoding (by Daniel Marcu and Ulrich Germann)

Loading Translation Model ... NTable ... DTable (Model 4) ... Source Vocabulary ... Target

Vocabulary ... TTable ... inverse TTable ... FZeroWords ... 0 seconds.

Alignment | [t0]  中国      <­­  China [s0 ­­> t0]

Alignment | [t1]  孩子      <­­  kids [s2 ­­> t1, t2]

Alignment | [t2]         <­­  kids [s2 ­­> t1, t2]

Alignment | [t3]  十分      <­­  changeable [s3 ­­> t3]

Alignment | [t4]  活泼      <­­  活泼 [s1 ­­> t4]

Alignment | [t5]         <­­  . [s4 ­­> t5]

中国孩子十分活泼

China活泼 kids changeable .

Alignment | [t0]  美国      <­­  America [s0 ­­> t0]

Alignment | [t1]         <­­  and [s1 ­­> t1]

Alignment | [t2]  中国      <­­  China [s2 ­­> t2]

Alignment | [t3]         <­­  . [s3 ­­> t3]

美国中国

America and China .

Alignment | [t0]     由于 <­­  As [s0 ­­> t0]

Alignment | [t1]     这个 <­­  transparency [s1 ­­> t1, t2]

Alignment | [t2]     缘故 <­­  transparency [s1 ­­> t1, t2]

Alignment | [t3]        , <­­   ­ [s2 ­­> t3]

Alignment | [t4]         <­­  convenient [s3 ­­> t4, t5, t6, t7, t9]

Alignment | [t5]         <­­  convenient [s3 ­­> t4, t5, t6, t7, t9]

Alignment | [t6]         <­­  convenient [s3 ­­> t4, t5, t6, t7, t9]

Alignment | [t7]     透明 <­­  convenient [s3 ­­> t4, t5, t6, t7, t9]

Alignment | [t8]         <­­  NULL [s0 ­­> t8]

Alignment | [t9]  地质图 <­­  convenient [s3 ­­> t4, t5, t6, t7, t9]

Alignment | [t10]         <­­  overlay [s5 ­­> t10]

Alignment | [t11]         <­­  the [s6 ­­> t11]

Alignment | [t12]     地球 <­­  geochemical [s7 ­­> t12, t13, t14]

Alignment | [t13]     化学 <­­  geochemical [s7 ­­> t12, t13, t14]

Alignment | [t14]         <­­  geochemical [s7 ­­> t12, t13, t14]

Alignment | [t15]         <­­  upon [s8 ­­> t15]

Alignment | [t16]         <­­  . [s9 ­­> t16]

由于这个缘故 ,透明地质图地球化学

As transparency ­ convenient to overlay the geochemical upon .

`Pure' translation time (includes time spent on logging): 0.32 seconds.

                 Time spent on output (without logging): 0.00 seconds

­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­

                                             Total time: 0.32 seconds.

 

  这里的三个句子,前两个句子没有在原文中出现过,最后一个句子是语料库中的训练语句。我们可以看到,如果原文中出现过的单词或者词组,译文的质量能够好些,如果没有出现过,那么翻译的时候会直接把对应的汉文直接翻译过来,比如例句中的活泼,这两个词训练语料库中没有,翻译的时候就找不着对应的英文单词,于是翻译的出来的就是原汉语单词活泼。当然如果我们提高训练语料库的数量,效果会得到改善。

说明:文中并没有给出分词的具体步骤,其原因就是不同的分词方法得到的翻译效果不一样,最主要的是在最后解码的过程中,在输入文件“input.xml”中不同的分词组合将会得到不同的翻译,有些人为的分词甚至不会给出翻译结果,而仅仅是给出中文的重新的排列而已。比如要是采用汉语分词工具ICTCAL,其分词后所有的语句将会自动带上各个词语的词性,如果你在输入文件“input.xml”中不带上这些词性,就不会得到预期的结果。如果我们采用LDC Chinese Segmenter进行分词,那么分词后就不需要带词性,只要按照分词的结果输入到输入文件“input.xml”中就能够得到翻译的结果。不过这里可以给出一个分词的一种常用perl命令:

 $ perl tokenize.perl.tmpl <inputfile> outputfile

 

 个人主页:http://nlp2ct.com/tianliang/index.php 

 

你可能感兴趣的:(ubuntu,table,search,Parameters,alignment,Training)