MCPcopy Index your code
hub / github.com/QData/TextAttack / get_results

Method get_results

textattack/goal_functions/goal_function.py:84–115  ·  view source on GitHub ↗

For each attacked_text object in attacked_text_list, returns a result consisting of whether or not the goal has been achieved, the output for display purposes, and a score. Additionally returns whether the search is over due to the query budget.

(self, attacked_text_list, check_skip=False)

Source from the content-addressed store, hash-verified

82 return result, search_over
83
84 def get_results(self, attacked_text_list, check_skip=False):
85 """For each attacked_text object in attacked_text_list, returns a
86 result consisting of whether or not the goal has been achieved, the
87 output for display purposes, and a score.
88
89 Additionally returns whether the search is over due to the query
90 budget.
91 """
92 results = []
93 if self.query_budget < float("inf"):
94 queries_left = self.query_budget - self.num_queries
95 attacked_text_list = attacked_text_list[:queries_left]
96 self.num_queries += len(attacked_text_list)
97 model_outputs = self._call_model(attacked_text_list)
98 for attacked_text, raw_output in zip(attacked_text_list, model_outputs):
99 displayed_output = self._get_displayed_output(raw_output)
100 goal_status = self._get_goal_status(
101 raw_output, attacked_text, check_skip=check_skip
102 )
103 goal_function_score = self._get_score(raw_output, attacked_text)
104 results.append(
105 self._goal_function_result_type()(
106 attacked_text,
107 raw_output,
108 displayed_output,
109 goal_status,
110 goal_function_score,
111 self.num_queries,
112 self.ground_truth_output,
113 )
114 )
115 return results, self.num_queries == self.query_budget
116
117 def _get_goal_status(self, model_output, attacked_text, check_skip=False):
118 should_skip = (

Callers 1

get_resultMethod · 0.95

Calls 5

_call_modelMethod · 0.95
_get_displayed_outputMethod · 0.95
_get_goal_statusMethod · 0.95
_get_scoreMethod · 0.95

Tested by

no test coverage detected