Skip to content
DeepForgeby svx
All problems
EasyNLPnlp-341

Token Jaccard Similarity

Problem

The Jaccard similarity of two token sets is |A intersect B| / |A union B|; define it as 1.0 when both are empty.

Given two token lists, return the similarity.

Hint

Deduplicate tokens before intersecting.

Test cases

case 1
in: [["a","b"],["b","c"]]
expected: 0.3333333333333333
case 2
in: [["x"],["x"]]
expected: 1
case 3
in: [[],[]]
expected: 1
Starter codePython
def token_jaccard_similarity(tokens_a, tokens_b):
    # Your code here
    pass

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