Skip to content

metric

[ allennlp.training.metrics.metric ]


Metric Objects#

class Metric(Registrable)

A very general abstract class representing a metric which can be accumulated.

get_metric#

 | def get_metric(
 |     self,
 |     reset: bool
 | ) -> Union[float, Tuple[float, ...], Dict[str, float], Dict[str, List[float]]]

Compute and return the metric. Optionally also call self.reset.

reset#

 | def reset(self) -> None

Reset any accumulators or internal state.

detach_tensors#

 | @staticmethod
 | def detach_tensors(*tensors: torch.Tensor) -> Iterable[torch.Tensor]

If you actually passed gradient-tracking Tensors to a Metric, there will be a huge memory leak, because it will prevent garbage collection for the computation graph. This method ensures the tensors are detached.