dataeval.utils.arrays.ensure_embeddings

dataeval.utils.arrays.ensure_embeddings(embeddings: T, dtype: torch.dtype, unit_interval: True | False | 'force' = False) torch.Tensor
dataeval.utils.arrays.ensure_embeddings(embeddings: T, dtype: type[_np_dtype], unit_interval: True | False | 'force' = False) numpy.typing.NDArray[_np_dtype]
dataeval.utils.arrays.ensure_embeddings(embeddings: T, dtype: None = None, unit_interval: True | False | 'force' = False) T

Validates the embeddings array and converts it to the specified type.

Parameters:
embeddings : ArrayLike

Embeddings array

dtype : numpy dtype or torch dtype or None, default None

The desired dtype of the output array, None to skip conversion

unit_interval : bool or "force", default False

Whether to validate or force the embeddings to unit interval

Returns:

Converted embeddings array

Return type:

torch.Tensor or NDArray or T

Raises:
  • ValueError – If the embeddings array is not 2D

  • ValueError – If the embeddings array has a zero dimension

  • ValueError – If the embeddings array is not unit interval [0, 1] (when unit_interval=True)