The H-Net paper tests models on HellaSwag under five character-level perturbations, following the protocol in the Byte Latent Transformer paper, and summarizes each model with a robustness score. Implement the noise and the score. That paper states only the rates, so the seeding and the exact draws below are this problem's choices.
All randomness comes from one random.Random(seed), created inside each function and used character by character in order.
ant_speak(text): uppercase the whole text, and put a single space between every pair of adjacent characters (spaces in the text count as characters).
drop(text, seed, rate=0.1): for each character draw rng.random(), and remove the character if the draw is below rate.
random_case(text, seed): for each character draw rng.random(). Uppercase it if the draw is below 0.5, otherwise lowercase it.
repeat(text, seed, rate=0.2, max_times=4): for each character draw rng.random(). If the draw is below rate, draw rng.randint(2, max_times) and write the character that many times in total. Otherwise write it once.
upper_case(text): uppercase the whole text.
robustness_score(perturbed_acc, unperturbed_acc, chance=0.25)
float. If the denominator is 0, return 0.0.robustness_row(perturbed, unperturbed_acc, chance=0.25)
perturbed maps a perturbation name to its accuracy. Return (average, score), where average is the mean of the values and score is robustness_score(average, unperturbed_acc, chance).rng.random() per input character in repeat, plus one randint only for selected characters, so your stream matches.0.25 comes from.