Skip to content
DeepForgeby svx
All problems
EasyNLPnlp-347

Multiset Token F1

Problem

For token multisets, the overlap is sum over tokens of min(count_a, count_b). Precision is overlap / len(a), recall is overlap / len(b), and F1 is their harmonic mean.

Given the two token lists, return F1, or 0.0 when either is empty.

Hint

Count multiplicities rather than using set intersection.

Test cases

case 1
in: [["a","a","b"],["a","b","b"]]
expected: 0.6666666666666666
case 2
in: [["x"],["y"]]
expected: 0
case 3
in: [["a"],[]]
expected: 0
Starter codePython
def multiset_token_f1(tokens_a, tokens_b):
    # Your code here
    pass

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