batch.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:nmt 作者: westrik 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号