Phrase-based Statistical Machine Translation

Download Report

Transcript Phrase-based Statistical Machine Translation

Phrase-base
Statistical Machine Translation
2008年8月29日 勉強会
D2 中澤 敏明
参考文献
• “Statistical Phrase-Based Translation”, Koehn et al.,
HLT/NAACL 2003
– http://www.iccs.inf.ed.ac.uk/~pkoehn/publications/phrase2003.pdf
• Statistical Machine Translation: the basic, the novel,
and the speculative, Philipp Koehn, Tutorial at EACL
2006
– http://www.iccs.inf.ed.ac.uk/~pkoehn/publications/tutorial2006.pdf
• SMT講習会の資料 by 山本幹雄先生
– http://iflab.slis.tsukuba.ac.jp/fujii/ntc7patmt/SMT_tutorial2007/myama.pdf
今日話すこと
1. Training
i. 対象化単語アライメント
ii. フレーズ抽出
iii. フレーズ翻訳確率などの計算(Log-linear Model)
2. MERT (Minimum Error Rate Training)
3. Decoding
i. Decoding Process
ii. Multistack Beam-search
実習
• Phrase-based SMTのツールキット、mosesを実
際に動かしてみる(英日翻訳実験)
1.
2.
3.
4.
5.
言語モデルの構築
翻訳モデルの構築
チューニング(MERT)
翻訳
翻訳結果の評価
注意
• orchidで動かしてください
– 64bitマシン以外では動かない設定になっています
• 混んでいるノードで動かすのはやめましょう
– できれば全員別々のノードで
• orchid[[01-40]]を使いましょう
– orchidに負荷をかけるのはやめましょう
実習
1. 言語モデルの構築
– srilmというツールを利用
– http://www.speech.sri.com/projects/srilm/
– ngram-count
-order 5
-interpolate
-kndiscount
-text /avocado3/moses/data/train_lm.ja
-lm 1M.ja.lm
統計翻訳の気持ち(1/2)
• ある原言語文fが与えられたとき、 P(e | f ) を
^
最大とするような目的言語文eがfの翻訳
eˆ  arg max P(e | f )
e
• ここでBayes
P ( e )  P ( f | e)
Ruleを適用すると、 P(e | f ) 
P( f )
eˆ  arg max P(e)  P( f | e)
e
言語モデル
翻訳モデル
※ Noisy Channel Model と呼ばれる
統計翻訳の気持ち(2/2)
• P(e | f ) を使って翻訳する場合、かなり良いモ
デルを作る必要がある
• Bayes Ruleを使っていくつかのモデルに分け
ることにより、各モデルがある程度良いもの
であれば、それらが相補的に働く
• 言語モデルと翻訳モデルをより良いものにし
ていき、精度を向上させよう!
実習
2. 翻訳モデルの構築
– 双方向でのGIZA++から翻訳モデルの構築まで
– train-factored-phrase-model.perl
-scripts-root-dir /avocado3/moses/scripts
-corpus ../data/train -f en -e ja
-alignment grow-diag-final-and
-reordering msd-bidirectional-fe
-lm 0:5:/avocado3/moses/lm/1M.ja.lm:0
-factor-delimiter ‘|||’
今日話すこと
1. Training
i. 対象化単語アライメント
ii. フレーズ抽出
iii. フレーズ翻訳確率などの計算(Log-linear Model)
2. MERT (Minimum Error Rate Training)
3. Decoding
i. Decoding Process
ii. Multistack Beam-search
Training
1. 対称化単語アライメントを生成
– GIZA++を双方向に実行し、ヒューリスティックスによ
り統合
2. 単語アライメントに無矛盾なphraseペアを抽出
– 全ての無矛盾な単語列ペアをphraseとする
3. フレーズ翻訳確率、lexicalized-reorderingモデ
ルなどを計算・生成
– 抽出されたphraseから計算
対称化単語アライメント
• MosesはGIZA++による単語アライメント結果を
利用
• GIZA++には方向性があり、1対多のアライメン
トしか生成できない(多対多が生成不可能)
• GIZA++を双方向に実行し、2つの1対多アライ
メント結果を統合(対称化)して、多対多のア
ライメント結果とする
対称化単語アライメント
Intersection
Union
Precision
High
Low
Recall
Low
High
対称化ヒューリスティックス
• 基本4種
– intersection
– union
– grow
– grow-diag
両方向ともにある対応点のみ
各方向の対応点すべて
intersectionからスタートして拡張
grow=縦・横 grow-diag=縦・横・対角
• 最終処理3種(未対応の単語に関する処理)
– なし
– final
– final-and
少なくとも片方の言語で対応がない
両言語ともに対応がない
intersection
grow-diag-final
abstract code
diag
Phraseペアの抽出
• 対称化単語アライメント結果を元に、矛盾しな
いphraseペアを全て抽出
• ここで言うphraseとは単純に連続する単語列
を意味し、統語的な意味は一切ない
• 「矛盾しない」とは・・・
Phraseペアの抽出
Log-linear Model
eˆ  arg max p(e | f )
e
M
arg max m hm (e, f )
e
m 1
• Feature functions(moses default: 14 params)
– language model (1 param)
– phrase translation table (5 params)
– reordering model (7 params)
– word penalty (1 param)
phrase translation table
• 5 parameters
– phrase translation probability
– lexical weighting
– phrase translation probability
– lexical weighting
– phrase penalty
C( f , e )
p( f | e ) 
 f C( f , e )
p( f | e )
pw ( f | e , a)
p(e | f )
pw (e | f , a)
exp(1)  2.718
lexical weighting
• phraseペアの質を評価するための重み
n
1
pw ( f | e , a)  
w( f i | e j )

i 1  j | (i, j )  a ( i , j )a
lexicalized reordering
• MSD vs monotonicity
– monotone, swap, discontinuous
– monotone, non-monotone
• f vs fe
– model is conditioned on f vs both f and e
• unidirectional vs bidirectional
– For each phrase, the ordering of itself in respect to
the previous is considered. For bidirectional
models, also the ordering of the next phrase in
respect to the currect phrase is modeled.
reordering model
• 7 parameters (msd-bidirectional-fe)
–
–
–
–
–
–
–
p previous (monotone| f , e )
p previous (swap | f , e )
p previous (discontinuous| f , e )
p following (monotone| f , e )
p following (swap | f , e )
p following (discontinuous| f , e )
simple distance-base model
Log-linear Model
M
arg max m hm (e, f )
e
m 1
• Feature functions
– language model (1 param)
– phrase translation table (5 params)
– reordering model (7 params)
– word penalty (1 param)
0.5
0.2
0.3
-1
今日話すこと
1. Training
i. 対象化単語アライメント
ii. フレーズ抽出
iii. フレーズ翻訳確率などの計算(Log-linear Model)
2. MERT (Minimum Error Rate Training)
3. Decoding
i. Decoding Process
ii. Multistack Beam-search
実習
3. チューニング(MERT)
– development setを用いてlog-linear modelのλを
BLEUが向上するように調整
– mert-moses.pl
--rootdir /avocado3/moses/scripts
--working-dir .
../data/dev.en ../data/dev.ja
/share/usr-x86_64/bin/moses
../tm/model/moses.ini
Minimum Error Rate Training
[Och, 2003]
• eˆ がよくなるようにm を調整
– Developmentセットを利用して、評価関数を最大
にするような翻訳結果が選択されるように調整
– Developmentセットは1000文程度
– 評価関数はBLEUを用いるのが一般的
– 各文についてn-bestの翻訳候補を出力し、正解と
比較してよりよい候補が上位に来るように調整
– 10~20回程度繰り返して重みを徐々に変化
– データサイズにもよるが、終わるまで数日かかる
ことも・・・
Param Default
1
2
3
6
9
12
13
BLEU
---
---
14.0
14.4
17.5
21.5
22.1
22.1
LM
0.5
1
0.039
0.038
0.104
0.047
0.052
0.051
TM1
0.2
0.3
0.011
0.010
0.042
0.012
0.042
0.042
TM2
0.2
0.2
0.020
0.020
0.031
0.038
0.031
0.031
TM3
0.2
0.3
0.051
0.049
0.030
0.008
0.034
0.034
TM4
0.2
0.2
0.016
0.068
0.011
0.018
0.016
0.016
TM5
0.2
0
0.003
0.003
0.034
-0.055
0.115
0.114
D1
0.3
1
-0.001
-0.001
0.017
-0.004
0.005
0.005
D2
0.3
1
-0.065
-0.061
0.034
0.087
0.045
0.044
D3
0.3
1
-0.191
-0.186
0.058
-0.032
0.109
0.108
D4
0.3
1
0.055
0.008
0.133
0.383
0.215
0.215
D5
0.3
1
-0.004
-0.010
0.133
0.025
0.123
0.123
D6
0.3
1
0.045
0.045
0.062
0.122
-0.007
-0.009
D7
0.3
1
0.062
0.072
0.130
0.085
0.134
0.133
W
-1
0
-0.438
-0.428
-0.181
-0.084
-0.074
-0.074
今日話すこと
1. Training
i. 対象化単語アライメント
ii. フレーズ抽出
iii. フレーズ翻訳確率などの計算(Log-linear Model)
2. MERT (Minimum Error Rate Training)
3. Decoding
i. Decoding Process
ii. Multistack Beam-search
実習
4. 翻訳
– MERTによって調整されたλを用いて翻訳
– phrase table全てを読み込むとメモリが足らなくなる
ので、翻訳する文に必要なphrase tableのみをあら
かじめfiltering
– filter-model-given-input.pl
filterd ../tune/moses.ini ../data/test.ja
– filteringされたphrase tableを用いて翻訳
– moses -f filterd/moses.ini < ../data/test.en
Decoding
• 翻訳文は左側(先頭)から順に生成
• Multistack Beam-searchで最適な翻訳を探索
– 翻訳が完了している単語数ごとにstackを用意し、
それぞれのstackで上位n個のみを保持
Decoding
Input sentence:
Maria
no
Mary
did not
Output sentence:
dio
una
slap
bofetada
a
la
the
bruja
verde
green
witch
Translation Options
• 翻訳するphraseの順番や、そのphraseの翻訳
候補はたくさんある
• 全てを探索することは不可能
Multistack Beam-search
• 翻訳が完了している単語数ごとにstackを用意
し、それぞれのstackで確率上位n個の「仮説」
のみを保持
• 確率は、その時点までの翻訳確率と、未翻訳
部の推定翻訳確率とから求める
Future Cost
• 全てのtranslation optionについて、phrase翻
訳確率とphrase内言語モデル確率を掛け算
• reordering(訳す順序)は考慮しない
– ほんとは正しい翻訳仮説がn-bestから外れる可
能性がある
• あらかじめ全ての部分についてfuture costを
計算しておけるので、decode時はfuture cost
tableを引くだけでよい
実習
5. 翻訳結果の評価
– mtevalというツールを使ってBLEU(NIST)を計算
– http://www.nist.gov/speech/tests/mt/2008/scori
ng.html
– mteval.pl -s src.sgm -r ref.sgm -t tst.sgm
– BLEUのみ、NISTのみ計算するオプションや、文
ごとのBLEUを出すオプションなどがある
– multi referenceのときにバグがあるという噂・・・