def decode(self, sentence, src=True):
'''
Given an encoded sentence matrix,
return the represented sentence string (tokenized).
'''
words = []
for word in sentence:
idxs = np.nonzero(word)[0]
if len(idxs) > 1:
raise Exception("Multiple hot bits on word vec")
elif len(idxs) == 0:
continue
if src:
words.append(self.words_src[0][idxs[0]])
else:
words.append(self.words_dst[0][idxs[0]])
return ' '.join(words)
评论列表
文章目录