import random


def perturb(sent_dict):
    """
    Given a dictionary of the format {'sentence': {whitespace-separated string}, 'label': {integer label}}
    Return an identical dictionary but with 15% of the tokens replaced with '[MASK]'
    """
    sentence_mod_array = sent_dict['sentence'].split()
    for i, word in enumerate(sentence_mod_array):
        if random.random() < 0.15:
            sentence_mod_array[i] = "[MASK]"
    sentence_mod = " ".join(sentence_mod_array)
    sent_dict_mod = {'sentence': sentence_mod, 'label': sent_dict['label']}
    return sent_dict_mod