def compute_accuracy(self, y, t):
arc_logits, label_logits = y
true_arcs, true_labels = t.T
b, l1, l2 = arc_logits.shape
true_arcs = F.pad_sequence(true_arcs, padding=-1)
if not self.model._cpu:
true_arcs.to_gpu()
arc_accuracy = F.accuracy(
F.reshape(arc_logits, (b * l1, l2)),
F.reshape(true_arcs, (b * l1,)),
ignore_label=-1)
b, l1, d = label_logits.shape
true_labels = F.pad_sequence(true_labels, padding=-1)
if not self.model._cpu:
true_labels.to_gpu()
label_accuracy = F.accuracy(
F.reshape(label_logits, (b * l1, d)),
F.reshape(true_labels, (b * l1,)),
ignore_label=-1)
accuracy = (arc_accuracy + label_accuracy) / 2
return accuracy
评论列表
文章目录