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

Word Swap Qwerty Can Fail With Non Textual Characters #717

Open
OGordon100 opened this issue Feb 28, 2023 · 0 comments
Open

Word Swap Qwerty Can Fail With Non Textual Characters #717

OGordon100 opened this issue Feb 28, 2023 · 0 comments

Comments

@OGordon100
Copy link

OGordon100 commented Feb 28, 2023

Describe the bug
When running a qwerty word swap, there can be a crash if the input string contains numeric/special characters

To Reproduce
Steps to reproduce the behavior:

    from textattack import transformations
    from textattack.augmentation import Augmenter
    transformation = transformations.WordSwapQWERTY()
    augmenter = Augmenter(transformation=transformation)
    augmenter.augment("12345@-")

This can occur with a single non textual character, e.g. myemail@hotmail.com , with the random generator in this case selecting i=8

Expected behavior
Non-alphabet characters are excluded

Screenshots or Traceback

Traceback (most recent call last):
  File "C:\Users\Oliver Gordon\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\223.8617.48\plugins\python\helpers\pydev\pydevconsole.py", line 364, in runcode
    coro = func()
  File "<input>", line 6, in <module>
  File "C:\Users\Oliver Gordon\Documents\GitHub\Artificial-Data-Modelling\venvm\lib\site-packages\textattack\augmentation\augmenter.py", line 125, in augment
    transformed_texts = self.transformation(
  File "C:\Users\Oliver Gordon\Documents\GitHub\Artificial-Data-Modelling\venvm\lib\site-packages\textattack\transformations\transformation.py", line 57, in __call__
    transformed_texts = self._get_transformations(current_text, indices_to_modify)
  File "C:\Users\Oliver Gordon\Documents\GitHub\Artificial-Data-Modelling\venvm\lib\site-packages\textattack\transformations\word_swaps\word_swap.py", line 46, in _get_transformations
    replacement_words = self._get_replacement_words(word_to_replace)
  File "C:\Users\Oliver Gordon\Documents\GitHub\Artificial-Data-Modelling\venvm\lib\site-packages\textattack\transformations\word_swaps\word_swap_qwerty.py", line 95, in _get_replacement_words
    word[:i] + random.choice(self._get_adjacent(word[i])) + word[i + 1 :]
  File "C:\Users\Oliver Gordon\AppData\Local\Programs\Python\Python39\lib\random.py", line 346, in choice
    return seq[self._randbelow(len(seq))]
IndexError: list index out of range

System Information (please complete the following information):

  • OS: Windows
  • Textattack version: 0.3.8

Additional context
Add any other context about the problem here.

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