How to quickly calculate the similarity of two vectors?

it takes too long to calculate online 200-dimensional vectors using cosine similarity

is there any fast calculation method

Thank you for java

Mar.16,2021

In [18]: a.shape
Out[18]: (200,)

In [19]: b.shape
Out[19]: (200,)

In [20]: timeit dot(a, b)/(norm(a)*norm(b))
8.56 s  929 ns per loop (mean  std. dev. of 7 runs, 100000 loops each)

the time I tested with numpy is 8 s , and there is no reason for java to be slower than this. Is it too slow for your system to require even s ?

or your problem is not clearly described, is there a large number of 200-dimensional arrays, and then find the one that is most similar to the input array?

in this case, a certain pre-filter is required to filter out a small range of candidate arrays.

for example, if there are 100,000 articles, each article is vectorized into a 200-dimensional array, then about 100 candidate articles should be selected by article category, publication time, etc., and then the similarity of the article vector should be calculated.

Menu