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

Method attack_dataset

textattack/attacker.py:405–446  ·  view source on GitHub ↗

Attack the dataset. Returns: :obj:`list[AttackResult]` - List of :class:`~textattack.attack_results.AttackResult` obtained after attacking the given dataset..

(self)

Source from the content-addressed store, hash-verified

403 print()
404
405 def attack_dataset(self):
406 """Attack the dataset.
407
408 Returns:
409 :obj:`list[AttackResult]` - List of :class:`~textattack.attack_results.AttackResult` obtained after attacking the given dataset..
410 """
411 if self.attack_args.silent:
412 logger.setLevel(logging.ERROR)
413
414 if self.attack_args.query_budget:
415 self.attack.goal_function.query_budget = self.attack_args.query_budget
416
417 if not self.attack_log_manager:
418 self.attack_log_manager = AttackArgs.create_loggers_from_args(
419 self.attack_args
420 )
421
422 textattack.shared.utils.set_seed(self.attack_args.random_seed)
423 if self.dataset.shuffled and self.attack_args.checkpoint_interval:
424 # Not allowed b/c we cannot recover order of shuffled data
425 raise ValueError(
426 "Cannot use `--checkpoint-interval` with dataset that has been internally shuffled."
427 )
428
429 self.attack_args.num_examples = (
430 len(self.dataset)
431 if self.attack_args.num_examples == -1
432 else self.attack_args.num_examples
433 )
434 if self.attack_args.parallel:
435 if torch.cuda.device_count() == 0:
436 raise Exception(
437 "Found no GPU on your system. To run attacks in parallel, GPU is required."
438 )
439 self._attack_parallel()
440 else:
441 self._attack()
442
443 if self.attack_args.silent:
444 logger.setLevel(logging.INFO)
445
446 return self.attack_log_manager.results
447
448 def update_attack_args(self, **kwargs):
449 """To update any attack args, pass the new argument as keyword argument

Callers 7

runMethod · 0.95
test_useFunction · 0.95
test_metric_recipeFunction · 0.95
runMethod · 0.80

Calls 3

_attack_parallelMethod · 0.95
_attackMethod · 0.95

Tested by 2

test_useFunction · 0.76
test_metric_recipeFunction · 0.76