def angular(embedding, other_embedding=None):
"""Compute angular distance
Parameters
----------
embedding : (n_samples, n_dimension) numpy array
other_embedding : (n_other_samples, n_dimension, ) numpy array, optional
L2-normalized embeddings
Returns
-------
distance : (n_samples, n_other_samples) numpy array or float
Angular distance
"""
n_samples, _ = embedding.shape
if other_embedding is None:
other_embedding = embedding
return arccos(ag_np.stack(
ag_np.sum(embedding[i] * other_embedding, axis=1)
for i in range(n_samples)))
评论列表
文章目录