Skip to content
DeepForgeby svx
All problems
EasyNLPnlp-055

OOV Rate

Problem

Return the token-level out-of-vocabulary rate: the fraction of token occurrences in tokens that are not in vocab.

Return 0.0 for an empty token list.

Hint

Count occurrences, not distinct types, and divide by the token count.

Test cases

case 1
in: [["a","b","z"],["a","b"]]
expected: 0.3333333333333333
case 2
in: [["a","b"],["a","b","c"]]
expected: 0
case 3
in: [["x","y"],[]]
expected: 1
case 4
in: [[],["a"]]
expected: 0
Starter codePython
def oov_rate(tokens, vocab):
    # Your code here
    pass

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