Skip to content
Merged
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
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

Comment on lines +68 to +76
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this bug.

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