Skip to content
DeepForgeby svx
All problems
EasyDeep Learningdl-145

Span Corruption Ratio

Problem

Compute the fraction of tokens hidden by span corruption: the total length of the masked spans divided by the total number of tokens. Spans are given as [start, end) pairs.

The signature is span_corruption_ratio(masked_spans, total_tokens).

Hint

T5-style span corruption hides contiguous runs rather than individual tokens.

Test cases

case 1
in: [[[0,2],[5,7]],10]
expected: 0.4
case 2
in: [[[0,3]],3]
expected: 1
case 3
in: [[],5]
expected: 0
case 4
in: [[[1,2],[3,4],[5,6]],12]
expected: 0.25
Starter codePython
def span_corruption_ratio(masked_spans, total_tokens):
    # Your code here
    pass

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