Skip to content
DeepForgeby svx
All problems
EasyNLPnlp-174

Vocabulary Shift Rate

Problem

Return the vocabulary shift rate: the size of the symmetric difference of the old and new vocabularies divided by the size of their union.

Duplicates are ignored. Return 0.0 when both vocabularies are empty.

Hint

The caret operator on sets gives the symmetric difference.

Test cases

case 1
in: [["a","b","c"],["b","c","d"]]
expected: 0.5
case 2
in: [["a","b"],["a","b"]]
expected: 0
case 3
in: [[],[]]
expected: 0
case 4
in: [[],["x"]]
expected: 1
case 5
in: [["a","a"],["a"]]
expected: 0
Starter codePython
def vocabulary_shift_rate(old_vocab, new_vocab):
    # Your code here
    pass

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