boolean_accuracy
allennlp.training.metrics.boolean_accuracy
BooleanAccuracy¶
@Metric.register("boolean_accuracy")
class BooleanAccuracy(Metric):
| def __init__(self) -> None
Just checks batch-equality of two tensors and computes an accuracy metric based on that.
That is, if your prediction has shape (batch_size, dim_1, ..., dim_n), this metric considers that
as a set of batch_size
predictions and checks that each is entirely correct across the remaining dims.
This means the denominator in the accuracy computation is batch_size
, with the caveat that predictions
that are totally masked are ignored (in which case the denominator is the number of predictions that have
at least one unmasked element).
This is similar to CategoricalAccuracy
, if you've already done a .max()
on your predictions. If you have categorical output, though, you should typically just use
CategoricalAccuracy
. The reason you might want to use this instead is if you've done
some kind of constrained inference and don't have a prediction tensor that matches the API of
CategoricalAccuracy
, which assumes a final dimension of size num_classes
.
__call__¶
class BooleanAccuracy(Metric):
| ...
| def __call__(
| self,
| predictions: torch.Tensor,
| gold_labels: torch.Tensor,
| mask: Optional[torch.BoolTensor] = None
| )
Parameters¶
- predictions :
torch.Tensor
A tensor of predictions of shape (batch_size, ...). - gold_labels :
torch.Tensor
A tensor of the same shape aspredictions
. - mask :
torch.BoolTensor
, optional (default =None
)
A tensor of the same shape aspredictions
.
get_metric¶
class BooleanAccuracy(Metric):
| ...
| def get_metric(self, reset: bool = False)
Returns¶
- The accumulated accuracy.
reset¶
class BooleanAccuracy(Metric):
| ...
| def reset(self)