Skip to content

Commit

Permalink
Merge pull request #556 from QData/fix-clare-bug
Browse files Browse the repository at this point in the history
Fix CLARE Extra Character Bug
  • Loading branch information
qiyanjun committed Nov 1, 2021
2 parents c014fc1 + bb53d7c commit 74ba1ff
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 0 deletions.
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

0 comments on commit 74ba1ff

Please sign in to comment.