categorical_accuracy
allennlp.training.metrics.categorical_accuracy
CategoricalAccuracy#
@Metric.register("categorical_accuracy")
class CategoricalAccuracy(Metric):
| def __init__(self, top_k: int = 1, tie_break: bool = False) -> None
Categorical Top-K accuracy. Assumes integer labels, with each item to be classified having a single correct class. Tie break enables equal distribution of scores among the classes with same maximum predicted scores.
supports_distributed#
class CategoricalAccuracy(Metric):
| ...
| supports_distributed = True
__call__#
class CategoricalAccuracy(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, ..., num_classes). - gold_labels :
torch.Tensor
A tensor of integer class label of shape (batch_size, ...). It must be the same shape as thepredictions
tensor without thenum_classes
dimension. - mask :
torch.BoolTensor
, optional (default =None
)
A masking tensor the same size asgold_labels
.
get_metric#
class CategoricalAccuracy(Metric):
| ...
| def get_metric(self, reset: bool = False)
Returns
- The accumulated accuracy.
reset#
class CategoricalAccuracy(Metric):
| ...
| @overrides
| def reset(self)