MCPcopy
hub / github.com/QData/TextAttack / log_attack_result

Method log_attack_result

textattack/loggers/csv_logger.py:26–44  ·  view source on GitHub ↗
(self, result)

Source from the content-addressed store, hash-verified

24 self.df = pd.DataFrame()
25
26 def log_attack_result(self, result):
27 original_text, perturbed_text = result.diff_color(self.color_method)
28 original_text = original_text.replace("\n", AttackedText.SPLIT_TOKEN)
29 perturbed_text = perturbed_text.replace("\n", AttackedText.SPLIT_TOKEN)
30 result_type = result.__class__.__name__.replace("AttackResult", "")
31 row = {
32 "original_text": original_text,
33 "perturbed_text": perturbed_text,
34 "original_score": result.original_result.score,
35 "perturbed_score": result.perturbed_result.score,
36 "original_output": result.original_result.output,
37 "perturbed_output": result.perturbed_result.output,
38 "ground_truth_output": result.original_result.ground_truth_output,
39 "num_queries": result.num_queries,
40 "result_type": result_type,
41 }
42 self.row_list.append(row)
43 self.df = pd.DataFrame.from_records(self.row_list)
44 self._flushed = False
45
46 def flush(self):
47 self.df.to_csv(self.filename, quoting=csv.QUOTE_NONNUMERIC, index=False)

Callers

nothing calls this directly

Calls 1

diff_colorMethod · 0.80

Tested by

no test coverage detected