add get_top_k_cosine_similarity method to get max top k score and index #5059
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Row-wise cosine similarity between two equal-width matrices and return the max top_k score and index, the score all greater than threshold_score. @vowelparrot @dev2049 @hwchase17
it's useful when we want to get the top k score and index after similarity compute. just like the following example:
input example
x = [[1, 2, 3, 4], [1, 2, 2, 2]]
y = [[1, 2, 3, 5], [1, 2, 9, 5], [2, 2, 3, 5]]
index_score_list = get_top_k_cosine_similarity(x, y, top_k=2, threshold_score=0.94)
print('index_score_list:', index_score_list)
output result
index_score_list: [[(0, 0.9939990885479664), (2, 0.9860132971832692)], [(2, 0.9415130835240085)]]