0
$\begingroup$

I've computed the cosine similarity between a & b (=x) and b & c (=y). I can use the same embeddings to compute the similarity between a and c (assuming it's = z).

I've a situation wherein I've only the similarity measures x and y. How can I find the similarity between a & c, without the original embeddings? If I use a plane to represent this then I will have infinite number of solutions. Are there any approaches which provides some insights about the relation between a and c?

a = torch.Tensor([1, 2])
b = torch.Tensor([1, -1])
c = torch.Tensor([2, 3])

sim_ab = torch.dot(a, b) / (torch.sqrt(sum(torch.square(a)) * sum(torch.square(b))))
sim_ac = torch.dot(a, c) / (torch.sqrt(sum(torch.square(a)) * sum(torch.square(c))))
sim_bc = torch.dot(b, c) / (torch.sqrt(sum(torch.square(b)) * sum(torch.square(c))))

print("Actual similarity between b and c: ", sim_bc)

x = torch.arccos(sim_ab)
y = torch.arccos(sim_ac)

print("Measured similarity between b and c: ", torch.cos(x-y))

>>> Actual similarity between b and c:  tensor(-0.1961)
>>> Measured similarity between b and c:  tensor(-0.1961)

geometric representation

$\endgroup$
1
  • 1
    $\begingroup$ With a single point B you simply can't. With a large number of points B you could maybe do some estimation. $\endgroup$
    – Erwan
    Commented Aug 12, 2021 at 17:33

1 Answer 1

1
$\begingroup$

It's often useful to think of simple cases, e.g. even in a 2-D (planar) case, you can't determine z. Similarity between two vectors is identical to the angle (at the origin) between them, so:

  • for a fixed vector $b$, if $a$ had angle $x$ to $b$, then $a$ lies in one of two lines either side of $b$.
  • if another vector $c$ has angle $y$ to $b$, then it is also in one of two lines either side of $b$.

This already gives 2 different answers for the angle between $a$ and $c$: $x+y$ or $x-y$, depending on whether $a$ and $c$ lie on the "same side" of $b$ or not.

In higher dimensions, the number of possible angles for $z$ increases, e.g. in 3-D, $a$ and $c$ each lie on a cone around $b$, with a range of possible angles between them.

This isn't a proof, but I think from this you can bound $z$ between $x+y$ and $x-y$ (perhaps useful if one value is very small, perhaps not), but you can't uniquely define z.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.