neuraltrain.metrics.metrics.Rank

class neuraltrain.metrics.metrics.Rank(reduction: Literal['mean', 'median', 'std'] = 'median', relative: bool = False, torchmetrics_kwargs: dict[str, Any] | None = None)[source][source]

Rank of predictions based on a retrieval set, using cosine similarity.

Parameters:
  • reduction ({"mean", "median", "std"}) – How to reduce the example-wise ranks.

  • relative (bool) – If True, divide ranks by the retrieval-set size so that values lie in [0, 1].

  • torchmetrics_kwargs (dict or None) – Extra keyword arguments forwarded to the torchmetrics.Metric constructor.

compute() Tensor[source][source]

Override this method to compute the final metric value.

This method will automatically synchronize state variables when running in distributed backend.

update(x: Tensor, y: Tensor, x_labels: None | list[str] = None, y_labels: None | list[str] = None) None[source][source]

Update internal list of ranks.

Parameters:
  • x – Tensor of predictions, of shape (N, F).

  • y – Tensor of retrieval set examples, of shape (M, F).

  • x_labels – If provided, used to match predictions and ground truths that don’t have the same number of examples. Should have length of N and M, respectively

  • y_labels – If provided, used to match predictions and ground truths that don’t have the same number of examples. Should have length of N and M, respectively