RT,蛋疼的MT实验~
伪代码请参见《统计机器翻译》中文版61页。
ps:输入只是参考了书上的例子——三个对齐句对~保证和书上输出的概率相同
该代码还没有经过大规模平行语料的检验。。后续有待优化~
输入:data.e
the house
the book
a book
data.f
das Haus
das Buch
ein Buch
python代码ibmModel1.py:
#coding=utf-8
import os
#Read File to pairs
fp_en = open('data.e','r')
fp_cn = open('data.f','r')
iters = 1
pairDic = {}
#生成原始序对字典
countPair = 0
for line_cn,line_en in zip(fp_cn,fp_en):
f = line_cn.split()
e = line_en.split()
for word1 in f:
for word2 in e:
pairDic[countPair] = (word1,word2)
countPair += 1
iters += 1
fp_en.close()
fp_cn.close()
#先将序对字典一次性去重
lst = list(set(pairDic.values()