Skip to content
DeepForgeby svx
All problems
HardNLPnlp-085

Seeded MLM Masking

Problem

Select token positions to mask for masked language modeling. Using random.Random(seed), draw one random number per token in order and mask token i when the draw is strictly less than mask_prob.

Return the sorted list of masked indices, which makes the result reproducible across runs.

Hint

random.Random(seed) gives an independent deterministic generator; random() is always below 1.0.

Test cases

case 1
in: [["t0","t1","t2","t3","t4","t5","t6","t7","t8","t9"],0.5,42]
expected: [1,2,3,7,8,9]
case 2
in: [["t0","t1","t2","t3","t4","t5","t6","t7","t8","t9"],0,7]
expected: []
case 3
in: [["t0","t1","t2","t3","t4","t5","t6","t7","t8","t9"],1,7]
expected: [0,1,2,3,4,5,6,7,8,9]
case 4
in: [["a","b","c"],0.5,1]
expected: [0]
case 5
in: [[],0.5,1]
expected: []
Starter codePython
import random
def mlm_masking_seeded(tokens, mask_prob, seed):
    # Your code here
    pass

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