diff --git a/textattack/transformations/word_insertions/word_insertion_masked_lm.py b/textattack/transformations/word_insertions/word_insertion_masked_lm.py index abc155a4d..df1067050 100644 --- a/textattack/transformations/word_insertions/word_insertion_masked_lm.py +++ b/textattack/transformations/word_insertions/word_insertion_masked_lm.py @@ -155,6 +155,7 @@ def _get_transformations(self, current_text, indices_to_modify): index_to_modify = indices_to_modify[i] word_at_index = current_text.words[index_to_modify] for word in new_words[i]: + word = word.strip("Ġ") if word != word_at_index: transformed_texts.append( current_text.insert_text_before_word_index( diff --git a/textattack/transformations/word_merges/word_merge_masked_lm.py b/textattack/transformations/word_merges/word_merge_masked_lm.py index f0bb54a0f..cff2fa16e 100644 --- a/textattack/transformations/word_merges/word_merge_masked_lm.py +++ b/textattack/transformations/word_merges/word_merge_masked_lm.py @@ -162,6 +162,7 @@ def _get_transformations(self, current_text, indices_to_modify): index_to_modify = merge_indices[i] word_at_index = current_text.words[index_to_modify] for word in merged_words[i]: + word = word.strip("Ġ") if word != word_at_index: temp_text = current_text.delete_word_at_index(index_to_modify + 1) transformed_texts.append( diff --git a/textattack/transformations/word_swaps/word_swap_masked_lm.py b/textattack/transformations/word_swaps/word_swap_masked_lm.py index dd79adf05..bb5f4a380 100644 --- a/textattack/transformations/word_swaps/word_swap_masked_lm.py +++ b/textattack/transformations/word_swaps/word_swap_masked_lm.py @@ -272,6 +272,7 @@ def _get_transformations(self, current_text, indices_to_modify): ) for r in replacement_words: + r = r.strip("Ġ") if r != word_at_index: transformed_texts.append( current_text.replace_word_at_index(i, r) @@ -288,6 +289,7 @@ def _get_transformations(self, current_text, indices_to_modify): index_to_modify = indices_to_modify[i] word_at_index = current_text.words[index_to_modify] for word in replacement_words[i]: + word = word.strip("Ġ") if word != word_at_index and len(utils.words_from_text(word)) == 1: transformed_texts.append( current_text.replace_word_at_index(index_to_modify, word)