Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/test_augment_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,32 @@ def test_deletion_augmenter():
assert augmented_s in augmented_text_list


def test_augment_text_with_ids_keeps_each_original_once(monkeypatch):
from textattack.augmentation import Augmenter
from textattack.transformations import WordDeletion

augmenter = Augmenter(WordDeletion())
monkeypatch.setattr(
augmenter,
"augment",
lambda text: [f"{text} augmented-1", f"{text} augmented-2"],
)

texts, ids = augmenter.augment_text_with_ids(
["first", "second"], [1, 2], show_progress=False
)

assert texts == [
"first",
"first augmented-1",
"first augmented-2",
"second",
"second augmented-1",
"second augmented-2",
]
assert ids == [1, 1, 1, 2, 2, 2]


def test_high_yield_scales_with_transformations_per_example():
# Regression test: the retry-bound fix for issue #800 (stop a
# low-diversity transformation from silently returning fewer than
Expand Down
5 changes: 2 additions & 3 deletions textattack/augmentation/augmenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,8 @@ def augment_text_with_ids(self, text_list, id_list, show_progress=True):
all_text_list.append(text)
all_id_list.append(_id)
augmented_texts = self.augment(text)
all_text_list.extend
all_text_list.extend([text] + augmented_texts)
all_id_list.extend([_id] * (1 + len(augmented_texts)))
all_text_list.extend(augmented_texts)
all_id_list.extend([_id] * len(augmented_texts))
return all_text_list, all_id_list

def __repr__(self):
Expand Down