cosine
Functions:
Name | Description |
---|---|
normalized_cosine_distance |
Calculate the cosine distance (negative cosine similarity) between two tensors, scaled and shifted into the range [0, 1]. |
normalized_cosine_similarity |
Calculate the cosine similarity between two tensors, scaled and shifted into the range [0, 1]. |
normalized_cosine_distance
¶
normalized_cosine_distance(
x1: Tensor, x2: Tensor, dim: int = 1, eps: float = 1e-08
) -> torch.Tensor
Calculate the cosine distance (negative cosine similarity) between two tensors, scaled and shifted into the range [0, 1].
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Tensor
|
The first tensor. |
required |
|
Tensor
|
The second tensor. |
required |
|
int
|
The dimension along which cosine distance is computed. |
1
|
|
float
|
A small value to prevent division by zero. |
1e-08
|
Returns:
Type | Description |
---|---|
torch.Tensor
|
The cosine distance of the tensors, scaled and shifted to between 0 and 1. |
Added in version 0.82.0.
normalized_cosine_similarity
¶
normalized_cosine_similarity(
x1: Tensor, x2: Tensor, dim: int = 1, eps: float = 1e-08
) -> torch.Tensor
Calculate the cosine similarity between two tensors, scaled and shifted into the range [0, 1].
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Tensor
|
The first tensor. |
required |
|
Tensor
|
The second tensor. |
required |
|
int
|
The dimension along which cosine similarity is computed. |
1
|
|
float
|
A small value to prevent division by zero. |
1e-08
|
Returns:
Type | Description |
---|---|
torch.Tensor
|
The cosine similarity of the tensors, scaled and shifted to between 0 and 1. |
Added in version 0.82.0.