napistu_torch.labels.apply

Utilities for applying and decoding labels in napistu-torch.

Functions

decode_labels(encoded_labels, labeling_manager)

Decode integer-encoded labels back to their original values.

napistu_torch.labels.apply.decode_labels(encoded_labels: torch.Tensor, labeling_manager: LabelingManager, missing_value: int = -1) List[str | int | float | None]

Decode integer-encoded labels back to their original values.

This function takes encoded labels (typically from a NapistuData.y tensor) and decodes them back to their original string/numeric values using the label_names mapping from a LabelingManager.

Parameters:
  • encoded_labels (torch.Tensor) – Tensor of integer-encoded labels (typically from NapistuData.y)

  • labeling_manager (LabelingManager) – The labeling manager containing the label_names mapping

  • missing_value (int, default=-1) – The integer value used to represent missing labels

Returns:

List of decoded labels, with None for missing values

Return type:

List[Optional[Union[str, int, float]]]

Examples

>>> # Assuming we have encoded labels and a labeling manager
>>> encoded_labels = torch.tensor([0, 1, 0, -1, 2])
>>> decoded = decode_labels(encoded_labels, labeling_manager)
>>> print(decoded)  # ['protein', 'metabolite', 'protein', None, 'drug']