我正在进行一个项目,目的是在句子和其他语言的翻译之间建立一个高精度的词对齐,以衡量翻译质量。我知道Giza++和其他单词对齐工具被用作统计机器翻译管道的一部分,但这不是我想要的。我正在寻找一种算法,可以将单词从源句映射到目标句子中的相应单词,并以透明和准确的方式给出这些限制:
以下是我所做的:
下面是英语和德语句子之间关联矩阵的一个例子。我们可以看到上面讨论的挑战。

在图像中,有一个英语和德语句子对齐的例子,显示单词之间的相关性,绿色单元格是正确的对齐点,应该通过单词对齐算法来识别。
以下是我尝试过的一些内容:
下面是我使用的代码:
import random
src_words=["I","know","this"]
trg_words=["Ich","kenne","das"]
def match_indexes(word1,word2):
return random.random() #adjust this to get the actual correlation value
all_pairs_vals=[] #list for all the source (src) and taget (trg) indexes and the corresponding correlation values
for i in range(len(src_words)): #iterate over src indexes
src_word=src_words[i] #identify the correponding src word
for j in range(len(trg_words)): #iterate over trg indexes
trg_word=trg_words[j] #identify the correponding trg word
val=match_indexes(src_word,trg_word) #get the matching value from the inverted indexes of each word (or from the data provided in the speadsheet)
all_pairs_vals.append((i,j,val)) #add the sentence indexes for scr and trg, and the corresponding val
all_pairs_vals.sort(key=lambda x:-x[-1]) #sort the list in descending order, to get the pairs with the highest correlation first
selected_alignments=[]
used_i,used_j=[],[] #exclude the used rows and column indexes
for i0,j0,val0 in all_pairs_vals:
if i0 in used_i: continue #if the current column index i0 has been used before, exclude current pair-value
if j0 in used_j: continue #same if the current row was used before
selected_alignments.append((i0,j0)) #otherwise, add the current pair to the final alignment point selection
used_i.append(i0) #and include it in the used row and column indexes so that it will not be used again
used_j.append(j0)
for a in all_pairs_vals: #list all pairs and indicate which ones were selected
i0,j0,val0=a
if (i0,j0) in selected_alignments: print(a, "<<<<")
else: print(a)这是有问题的,因为它不包含多对多,甚至是一对到多对齐,而且在开始时很容易出错,因为它选择了一个相关性最高的错误对,不包括它的行和列在未来选择中。一个好的算法将考虑到一个对在其各自的行/列中具有最高的相关性,但也会考虑到与其他具有高度相关性的对的接近性。
以下是一些数据,如果您愿意的话,可以在Google中找到:https://docs.google.com/spreadsheets/d/1-eO47RH6SLwtYxnYygow1mvbqwMWVqSoAhW64aZrubo/edit?usp=sharing
发布于 2021-03-16 19:20:18
我强烈建议测试太棒了-对齐。它依赖于多语言的BERT (mBERT),其结果看起来非常有希望。我甚至用阿拉伯语测试了它,它在一个困难的对齐例子上做了很好的工作,因为阿拉伯语是一种丰富的词法语言,我相信它比德语这样的拉丁语言更具挑战性。

正如你所看到的,阿拉伯语中的一个单词对应于英语中的多个单词,然而,令人惊奇的-对齐在很大程度上成功地处理了多到多的映射。你可以试一试,我相信它能满足你的需要。
在https://colab.research.google.com/drive/1205ubqebM0OsZa1nRgbGJBtitgHqIVv6?usp=sharing#scrollTo=smW6s5JJflCN也有Google Colab的演示
祝好运!
发布于 2020-01-06 16:51:47
词对齐在一定程度上仍是一个开放的研究课题。Giza++背后的概率模型相当重要,参见:http://www.ee.columbia.edu/~sfchang/course/svia/papers/brown-machine-translate-93.pdf。
您可以采取许多现有的方法,例如:
fast_align https://www.aclweb.org/anthology/N13-1073/背后的(简单得多的)算法这是一个非常困难的机器学习问题,虽然像您这样的简单方法可以工作并不是不可能的,但是最好先研究现有的工作。尽管如此,我们在这一领域看到了相当多的技术突破,所以谁知道呢?)
https://stackoverflow.com/questions/59615759
复制相似问题