langtest.metrics.embedding_distance.EmbeddingDistance#
- class EmbeddingDistance#
Bases:
object
A utility class for calculating various types of distances and similarities between vectors or arrays. This class provides methods for calculating the following distance/similarity measures: - Cosine Similarity: Measures the cosine of the angle between two non-zero vectors. - Euclidean Distance: Measures the straight-line distance between two points in Euclidean space. - Manhattan Distance: Measures the sum of absolute differences between the coordinates of two points. - Chebyshev Distance: Measures the maximum absolute difference between coordinates of two points. - Hamming Distance: Measures the fraction of differing elements in two binary vectors.
- __init__()#
Methods
__init__
()available_embedding_distance
([distance])Get the specified distance metric for embedding calculations.
A decorator function for validating input arrays.
- classmethod available_embedding_distance(distance: str = 'cosine')#
Get the specified distance metric for embedding calculations.
- Parameters:
distance (str, optional) – The desired distance metric. Defaults to “cosine”.
- Returns:
The corresponding distance calculation method.
- Return type:
callable
- Raises:
ValueError – If the specified distance metric is not supported.
- validate_input()#
A decorator function for validating input arrays.
- Parameters:
func – The function to be decorated.
- Returns:
The decorated function.