Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

leet_letters (LeetLetters) returning an error when the leet candidates is empty #384

Open
lydianish opened this issue Sep 28, 2023 · 0 comments

Comments

@lydianish
Copy link

lydianish commented Sep 28, 2023

Bug description:

Running the LeetLetters transformation on a sentence that produces no leet candidates return an IndexError: list index out of range:

To reproduce the error:

For example, a sentence with no alphanumeric characters.

from nlaugmenter.transformations.leet_letters.transformation import LeetLetters

sentence = "-----------------------"
t = LeetLetters(seed=0, max_outputs=5, max_leet=0.05)
t.generate(sentence)

Cause:

The error comes from this section in the code:

leet_replacements = random.choices(
         leet_candidates, k=max_leet_replacements
)

Since random.choices does not accept an empty list as argument, it returns an error whenleet_candidates is empty.

Possible fix:

if not leet_candidates:
      leet_replacements = []
else:
      leet_replacements = random.choices(
              leet_candidates, k=max_leet_replacements
       )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant