繁体   English   中英

用 MT 中的源词替换 UNKNOWN 词

[英]Replacing UNKNOWN words with the sorce word in MT

我正在研究机器学习 AI 翻译系统,我想让我的代码现在更适应我的代码,当这个词是新词时,将放置代表UNKNOWN 的UNK并保留它,但我想复制同一个词并将其过去而不是打印UNK ,所以如果出现一个新词,它应该传回与翻译相同的词而不是UNK我的代码现在看起来像这样:

任何想法我应该改变什么:

# Adding the word 'UNK' to the end of the array (stands for UNKNOWN words)
    X_ix_to_word.append('UNK')

    # Creating the word-to-index dictionary from the array created above
    X_word_to_ix = {word:ix for ix, word in enumerate(X_ix_to_word)}

    # Converting each word to its index value
    for i, sentence in enumerate(X):
        for j, word in enumerate(sentence):
            if word in X_word_to_ix:
                X[i][j] = X_word_to_ix[word]
            else:
                X[i][j] = X_word_to_ix['UNK']

    y_ix_to_word = [word[0] for word in y_vocab]
    y_ix_to_word.insert(0, 'ZERO')
    y_ix_to_word.append('UNK')
    y_word_to_ix = {word:ix for ix, word in enumerate(y_ix_to_word)}
    for i, sentence in enumerate(y):
        for j, word in enumerate(sentence):
            if word in y_word_to_ix:
                y[i][j] = y_word_to_ix[word]
            else:
                y[i][j] = y_word_to_ix['UNK']
    return (X, len(X_vocab)+2, X_word_to_ix, X_ix_to_word, y, len(y_vocab)+2, y_word_to_ix, y_ix_to_word)

def load_test_data(source, X_word_to_ix, max_len):
    f = open(source, 'r')
    X_data = f.read()
    f.close()

    X = [text_to_word_sequence(x)[::-1] for x in X_data.split('\n') if len(x) > 0 and len(x) <= max_len]
    for i, sentence in enumerate(X):
        for j, word in enumerate(sentence):
            if word in X_word_to_ix:
                X[i][j] = X_word_to_ix[word]
            else:
                X[i][j] = X_word_to_ix['UNK']
    return X

这不是一个容易的问题。

您建议在数据预处理级别替换单词。 为此,您需要单词对齐来告诉您哪些源词与您的目标词匹配。 有像FastAlign这样的工具 即使你有对齐,也不能保证复制的源词会在目标词汇表中。

一些人试图在建模层面解决这个问题,并在他们的网络中包含显式复制机制(如本文),但是它使网络变得相当复杂并且只提供了一点改进。

此问题最常见的解决方法是使用基于子词的词汇,如BPESentencePiece 使用这些方法,不常用的词被分割成更小的单元,所以最终没有词汇量。 如果单词在源端和目标端都相同(这经常发生在专有名词上),它将在源端和目标端以相同的方式进行分割,模型将学习复制单词片段是它通常的做法应该做。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM