Open Klingefjord opened 2 years ago
I see that there are interfaces for pow
in https://github.com/OpenMined/TenSEAL/blob/main/tenseal/tensors/abstract_tensor.py, which means the only missing component for being able to calculate cosine similarity is an abs
function.
def abs(a):
return a.square().pow(0.5)
def norm(a):
return abs(a).square().sum().pow(0.5)
def cosine_similarity(a, b):
return a * b / (norm(a) * norm(b))
Something like this could work, but unfortunately .pow(0.5)
is not allowed, as the function takes an integer value.
If there was a .sqrt()
interface, that would be solved.
Hi, were you able to find a way around this?
@wcappel unfortunately not
Although I think this might not be possible with current FHE algorithms
Feature Description
I would love to have the option to calculate either the cosine similarity between two vectors, or the norm of a vector (so as to be able to manually calculate the cosine similarity).
Is your feature request related to a problem?
I'm working with encrypted word embeddings and would love the ability to perform similarity checks against encrypted word embedding vectors.
What alternatives have you considered?
There are no other libraries or alternatives that offer this as far as I'm aware.
Additional Context