in src/fmeval/transforms/semantic_perturbations.py [0:0]
def perturb(self, text: str) -> List[str]:
"""Return a list where each element is a copy of the original text with a fraction of characters capitalized.
:param text: The input text to be perturbed.
:returns: A list of perturbed text outputs.
"""
def random_uppercase_text():
"""Return a copy of `text` where a fraction of the characters are converted to uppercase.
:returns: A copy of `text` where a fraction of the characters are converted to uppercase.
"""
positions = self.rng.choice(
range(len(text)),
int(len(text) * self.uppercase_fraction),
False,
)
new_text = [letter if index not in positions else letter.upper() for index, letter in enumerate(text)]
return "".join(new_text)
return [random_uppercase_text() for _ in range(self.num_perturbations)]