Skip to content

sequence_accuracy

allennlp.training.metrics.sequence_accuracy

[SOURCE]


SequenceAccuracy#

@Metric.register("sequence_accuracy")
class SequenceAccuracy(Metric):
 | def __init__(self) -> None

Sequence Top-K accuracy. Assumes integer labels, with each item to be classified having a single correct class.

__call__#

class SequenceAccuracy(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, k, sequence_length).
  • gold_labels : torch.Tensor
    A tensor of integer class label of shape (batch_size, sequence_length).
  • mask : torch.BoolTensor, optional (default = None)
    A masking tensor the same size as gold_labels.

get_metric#

class SequenceAccuracy(Metric):
 | ...
 | def get_metric(self, reset: bool = False)

Returns

  • The accumulated accuracy.

reset#

class SequenceAccuracy(Metric):
 | ...
 | @overrides
 | def reset(self)