Skip to content

Commit

Permalink
Merge pull request #477 from cogeid/Fix-RandomSwap-and-RandomSynonymI…
Browse files Browse the repository at this point in the history
…nsertion-bug

 Fix-RandomSwap-and-RandomSynonymInsertion-bug pr 368 to pass pytest
  • Loading branch information
qiyanjun committed Jul 21, 2021
2 parents 8918e8f + 79db189 commit e29a01a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions textattack/augmentation/augmenter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Augmenter Class
===================
"""
import random

Expand Down Expand Up @@ -103,7 +102,10 @@ def augment(self, text):
current_text = random.choice(transformed_texts)

# update words_swapped based on modified indices
words_swapped = len(current_text.attack_attrs["modified_indices"])
words_swapped = max(
len(current_text.attack_attrs["modified_indices"]),
words_swapped + 1,
)
all_transformed_texts.add(current_text)
return sorted([at.printable_text() for at in all_transformed_texts])

Expand All @@ -113,7 +115,6 @@ def augment_many(self, text_list, show_progress=False):
Args:
text_list (list(string)): a list of strings for data augmentation
Returns a list(string) of augmented texts.
"""
if show_progress:
Expand Down
1 change: 1 addition & 0 deletions textattack/augmentation/recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def augment(self, text):
augmented_text += self.random_deletion.augment(text)
augmented_text += self.random_swap.augment(text)
augmented_text += self.random_insertion.augment(text)
augmented_text = list(set(augmented_text))
random.shuffle(augmented_text)
return augmented_text[: self.transformations_per_example]

Expand Down

0 comments on commit e29a01a

Please sign in to comment.