question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to compute the cosine similarity between two cryptensors?

See original GitHub issue

Feature

I wonder how to compute the cosine similarity between two cryptensors. Could anyone give me some suggestions?

For example,

import crypten

x = torch.tensor([1, 2, 3], dtype = torch.float)
x_enc = crypten.cryptensor(x)

y_enc = crypten.cryptensor([2.0, 3.0, 4.0])

Alternatives

Additional context

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
lvdmaatencommented, Jul 8, 2021

@knottb Note that PyTorch implementation does something to prevent division by zero. We may need something similar if we were to add cosine similarity in CrypTen.

0reactions
hobbitlzycommented, Oct 28, 2022

Actually, this epsilon for numerical precision only matters when the reciprocal of the norms is very small (product is less than 1e-8), which means the norms are large (product is at least 1e8). If our norms are this large, then the inverse square root will fail. Currently our precision allows for inputs up to around [0.05, 200] (it may be useful to work on improving this). Screen Shot 2021-07-08 at 3 17 49 PM

Hi, what if the data is beyond the valid range [0.05,200]? Is there any way to compute them correctly now?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cosine Similarity - LearnDataSci
Cosine similarity is a metric used to measure the similarity of two vectors. ... we have two vectors, A and B, the similarity...
Read more >
Cosine Similarity - GeeksforGeeks
Consider an example to find the similarity between two vectors – 'x' and 'y', using Cosine Similarity. The 'x' vector has values, x...
Read more >
Cosine Similarity – Understanding the math and how it ...
Cosine similarity is a metric used to measure how similar the documents are irrespective of their size. It is the cosine of the...
Read more >
How to compute the Cosine Similarity between two tensors in ...
To compute the cosine similarity between two tensors, we use the CosineSimilarity() function provided by the torch.nn module.
Read more >
How to calculate the Cosine similarity between two tensors?
With the latest TF API, this can be computed by calling tf.losses.cosine_distance . Example: import tensorflow as tf import numpy as np x...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found