Skip to content
Merged
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
remove "Ġ" in replacement words
  • Loading branch information
Hanyu-Liu-123 committed Oct 22, 2021
commit bb53d7cc9b42d047a3711f8eb7da47211d56fa33
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions textattack/transformations/word_swaps/word_swap_masked_lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down