All problems
Embedding Drift Rate
Problem
Return the average embedding drift 1 - cosine(old, new) over words present in both vector dictionaries.
Return 0.0 when there is no overlap between the two vocabularies.
Hint
Cosine distance is 1 minus cosine similarity, and the rate averages it over shared words.
Test cases
case 1
in: [{"a":[1,0],"b":[0,1]},{"a":[1,0],"b":[1,0]}]
expected: 0.5
case 2
in: [{"a":[1,0]},{"b":[1,0]}]
expected: 0
case 3
in: [{"a":[1,0]},{"a":[1,0]}]
expected: 0
case 4
in: [{},{}]
expected: 0
case 5
in: [{"a":[1,0]},{"a":[-1,0]}]
expected: 2
Starter codePython
import math
def embedding_drift_rate(old_vectors, new_vectors):
# Your code here
pass5 test cases · run your code against them in the editor