All problems
Most Similar Token by Cosine
Problem
Given a target vector and a dictionary of candidate name to vector, return the candidate name with the highest cosine similarity. Return None when the dictionary is empty.
Given the target vector and candidates, return the best name.
Hint
Score each candidate and track the best name.
Test cases
case 1
in: [[1,0],{"x":[1,0],"y":[0,1]}]
expected: "x"
case 2
in: [[1,1],{"a":[1,0],"b":[1,1]}]
expected: "b"
case 3
in: [[1,0],{}]
expected: null
Starter codePython
def most_similar_token_by_cosine(target, candidates):
# Your code here
pass3 test cases · run your code against them in the editor