Exemple #1
0
 def on_batch_end(self, data: Data) -> None:
     y_pred, y_true = to_number(data['pred']), to_number(data['target_real'])
     if y_true.shape[-1] > 1 and y_true.ndim > 2:
         y_true = np.argmax(y_true, axis=-1)
     if y_pred.shape[-1] > 1 and y_pred.ndim > 2:
         y_pred = np.argmax(y_pred, axis=-1)
     sentence_level_scores = self.batch_precision_parameters(y_true, y_pred)
     data.write_per_instance_log(self.outputs[0], sentence_level_scores)
Exemple #2
0
 def on_batch_end(self, data: Data) -> None:
     y_true, y_pred = to_number(data[self.true_key]), to_number(data[self.pred_key])
     if y_true.shape[-1] > 1 and y_true.ndim > 1:
         y_true = np.argmax(y_true, axis=-1)
     if y_pred.shape[-1] > 1 and y_pred.ndim > 1:
         y_pred = np.argmax(y_pred, axis=-1)
     else:  # binaray classification (pred shape is [batch, 1])
         if self.from_logits:
             y_pred = 1 / (1 + np.exp(-y_pred))
         y_pred = np.round(y_pred)
     assert y_pred.size == y_true.size
     self.correct += np.sum(y_pred.ravel() == y_true.ravel())
     self.total += len(y_pred.ravel())
     data.write_per_instance_log(self.outputs[0], np.array(y_pred.ravel() == y_true.ravel(), dtype=np.int8))