Attack the dataset. Returns: :obj:`list[AttackResult]` - List of :class:`~textattack.attack_results.AttackResult` obtained after attacking the given dataset..
(self)
| 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 |