Attack arguments to be passed to :class:`~textattack.Attacker`. Args: num_examples (:obj:`int`, 'optional`, defaults to :obj:`10`): The number of examples to attack. :obj:`-1` for entire dataset. num_successful_examples (:obj:`int`, `optional`, defaults to :obj:`None
| 141 | |
| 142 | @dataclass |
| 143 | class AttackArgs: |
| 144 | """Attack arguments to be passed to :class:`~textattack.Attacker`. |
| 145 | |
| 146 | Args: |
| 147 | num_examples (:obj:`int`, 'optional`, defaults to :obj:`10`): |
| 148 | The number of examples to attack. :obj:`-1` for entire dataset. |
| 149 | num_successful_examples (:obj:`int`, `optional`, defaults to :obj:`None`): |
| 150 | The number of successful adversarial examples we want. This is different from :obj:`num_examples` |
| 151 | as :obj:`num_examples` only cares about attacking `N` samples while :obj:`num_successful_examples` aims to keep attacking |
| 152 | until we have `N` successful cases. |
| 153 | .. note:: |
| 154 | If set, this argument overrides `num_examples` argument. |
| 155 | num_examples_offset (:obj: `int`, `optional`, defaults to :obj:`0`): |
| 156 | The offset index to start at in the dataset. |
| 157 | attack_n (:obj:`bool`, `optional`, defaults to :obj:`False`): |
| 158 | Whether to run attack until total of `N` examples have been attacked (and not skipped). |
| 159 | shuffle (:obj:`bool`, `optional`, defaults to :obj:`False`): |
| 160 | If :obj:`True`, we randomly shuffle the dataset before attacking. However, this avoids actually shuffling |
| 161 | the dataset internally and opts for shuffling the list of indices of examples we want to attack. This means |
| 162 | :obj:`shuffle` can now be used with checkpoint saving. |
| 163 | query_budget (:obj:`int`, `optional`, defaults to :obj:`None`): |
| 164 | The maximum number of model queries allowed per example attacked. |
| 165 | If not set, we use the query budget set in the :class:`~textattack.goal_functions.GoalFunction` object (which by default is :obj:`float("inf")`). |
| 166 | .. note:: |
| 167 | Setting this overwrites the query budget set in :class:`~textattack.goal_functions.GoalFunction` object. |
| 168 | checkpoint_interval (:obj:`int`, `optional`, defaults to :obj:`None`): |
| 169 | If set, checkpoint will be saved after attacking every `N` examples. If :obj:`None` is passed, no checkpoints will be saved. |
| 170 | checkpoint_dir (:obj:`str`, `optional`, defaults to :obj:`"checkpoints"`): |
| 171 | The directory to save checkpoint files. |
| 172 | random_seed (:obj:`int`, `optional`, defaults to :obj:`765`): |
| 173 | Random seed for reproducibility. |
| 174 | parallel (:obj:`False`, `optional`, defaults to :obj:`False`): |
| 175 | If :obj:`True`, run attack using multiple CPUs/GPUs. |
| 176 | num_workers_per_device (:obj:`int`, `optional`, defaults to :obj:`1`): |
| 177 | Number of worker processes to run per device in parallel mode (i.e. :obj:`parallel=True`). For example, if you are using GPUs and :obj:`num_workers_per_device=2`, |
| 178 | then 2 processes will be running in each GPU. |
| 179 | log_to_txt (:obj:`str`, `optional`, defaults to :obj:`None`): |
| 180 | If set, save attack logs as a `.txt` file to the directory specified by this argument. |
| 181 | If the last part of the provided path ends with `.txt` extension, it is assumed to the desired path of the log file. |
| 182 | log_to_csv (:obj:`str`, `optional`, defaults to :obj:`None`): |
| 183 | If set, save attack logs as a CSV file to the directory specified by this argument. |
| 184 | If the last part of the provided path ends with `.csv` extension, it is assumed to the desired path of the log file. |
| 185 | csv_coloring_style (:obj:`str`, `optional`, defaults to :obj:`"file"`): |
| 186 | Method for choosing how to mark perturbed parts of the text. Options are :obj:`"file"`, :obj:`"plain"`, and :obj:`"html"`. |
| 187 | :obj:`"file"` wraps perturbed parts with double brackets :obj:`[[ <text> ]]` while :obj:`"plain"` does not mark the text in any way. |
| 188 | log_to_visdom (:obj:`dict`, `optional`, defaults to :obj:`None`): |
| 189 | If set, Visdom logger is used with the provided dictionary passed as a keyword arguments to :class:`~textattack.loggers.VisdomLogger`. |
| 190 | Pass in empty dictionary to use default arguments. For custom logger, the dictionary should have the following |
| 191 | three keys and their corresponding values: :obj:`"env", "port", "hostname"`. |
| 192 | log_to_wandb(:obj:`dict`, `optional`, defaults to :obj:`None`): |
| 193 | If set, WandB logger is used with the provided dictionary passed as a keyword arguments to :class:`~textattack.loggers.WeightsAndBiasesLogger`. |
| 194 | Pass in empty dictionary to use default arguments. For custom logger, the dictionary should have the following |
| 195 | key and its corresponding value: :obj:`"project"`. |
| 196 | disable_stdout (:obj:`bool`, `optional`, defaults to :obj:`False`): |
| 197 | Disable displaying individual attack results to stdout. |
| 198 | silent (:obj:`bool`, `optional`, defaults to :obj:`False`): |
| 199 | Disable all logging (except for errors). This is stronger than :obj:`disable_stdout`. |
| 200 | enable_advance_metrics (:obj:`bool`, `optional`, defaults to :obj:`False`): |
no outgoing calls