JA_Hybrid_BiGRU.py 文件源码

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

项目:NANHM-for-GEC 作者: shinochin 项目源码 文件源码
def __call__(self, trainer):
        with chainer.no_backprop_mode():
            references = []
            hypotheses = []
            for i in range(0, len(self.test_data[0:100]), self.batch):
                sources, targets = zip(*self.test_data[i:i + self.batch])
                references.extend([[t[0].tolist()] for t in targets])

                sources = [
                    chainer.dataset.to_device(self.device, x) for x in sources]
                ys = self.model.translate(sources, self.max_length)
                ys = [y.tolist() for y in ys]
                hypotheses.extend(ys)

            source, target = zip(*self.test_data[0:100])
            loss = self.model.CalculateValLoss(source, target)
        bleu = bleu_score.corpus_bleu(
            references, hypotheses,
            smoothing_function=bleu_score.SmoothingFunction().method1)
        reporter.report({self.key[0]: bleu})
        reporter.report({self.key[1]: loss})
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号