diff --git a/textattack/search_methods/greedy_word_swap_wir.py b/textattack/search_methods/greedy_word_swap_wir.py index 398a178d4..ac17fbf30 100644 --- a/textattack/search_methods/greedy_word_swap_wir.py +++ b/textattack/search_methods/greedy_word_swap_wir.py @@ -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, @@ -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":