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})
评论列表
文章目录