Skip to content

Commit

Permalink
Merge pull request #674 from VijayKalmath/patch-1
Browse files Browse the repository at this point in the history
Handle when saliency_scores not equal to len_text
  • Loading branch information
jxmorris12 committed Jun 29, 2022
2 parents 9468cd3 + 1d429b1 commit 4560fae
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions textattack/search_methods/greedy_word_swap_wir.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ def _get_index_order(self, initial_text):
# compute the largest change in score we can find by swapping each word
delta_ps = []
for idx in indices_to_order:

# Exit Loop when search_over is True - but we need to make sure delta_ps
# is the same size as softmax_saliency_scores
if search_over:
delta_ps = delta_ps + [0.0] * (
len(softmax_saliency_scores) - len(delta_ps)
)
break

transformed_text_candidates = self.get_transformations(
initial_text,
original_text=initial_text,
Expand All @@ -84,12 +93,6 @@ def _get_index_order(self, initial_text):
max_score_change = np.max(score_change)
delta_ps.append(max_score_change)

# Exit Loop when search_over is True - but we need to make sure delta_ps
# is the same size as softmax_saliency_scores
if search_over:
delta_ps = delta_ps + [0.0] * (len_text - len(delta_ps))
break

index_scores = softmax_saliency_scores * np.array(delta_ps)

elif self.wir_method == "delete":
Expand Down

0 comments on commit 4560fae

Please sign in to comment.