Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-197

Speaker Cosine Similarity

Problem

Return the cosine similarity between the mean embeddings (centroids) of two speaker embedding sets.

Return 0.0 when either set is empty or a centroid has zero norm.

Hint

Average each embedding set first, then take the cosine of the two centroids.

Test cases

case 1
in: [[[1,0],[1,0]],[[1,0]]]
expected: 1
case 2
in: [[[1,0]],[[0,1]]]
expected: 0
case 3
in: [[[1,2],[3,4]],[[2,3]]]
expected: 1.0000000000000002
case 4
in: [[],[[1]]]
expected: 0
case 5
in: [[[1,0]],[[-1,0]]]
expected: -1
Starter codePython
def speaker_cosine(embeddings_a, embeddings_b):
    # Your code here
    pass

5 test cases · run your code against them in the editor