fibber.defense_strategies.defense_strategy_base module¶
-
class
fibber.defense_strategies.defense_strategy_base.
DefenseStrategyBase
(arg_dict, dataset_name, strategy_gpu_id, defense_desc, metric_bundle, attack_strategy, field)[source]¶ Bases:
object
Base class for Tuning strategy
Initialize the paraphrase_strategies.
This function initialize the
self._strategy_config
,self._metric_bundle
,self._device
,self._defense_desc
,self._dataset_name
.You should not overwrite this function.
self._strategy_config (dict): a dictionary that stores the strategy name and all hyperparameter values. The dict is also saved to the results.
self._metric_bundle (MetricBundle): the metrics that will be used to evaluate paraphrases. Strategies can compute metrics during paraphrasing.
self._device (torch.Device): any computation that requires a GPU accelerator should use this device.
self._defense_desc (str): the dir name where the defense will save files.
self._dataset_name (str): the dataset name.
- Parameters
arg_dict (dict) – all args load from command line.
dataset_name (str) – the name of the dataset.
strategy_gpu_id (int) – the gpu id to run the strategy.
metric_bundle (MetricBundle) – a MetricBundle object.
attack_strategy (ParaphraseStrategyBase or None) – the attack strategy. Used in some defense methods.
field (str) – the field that perturbation can happen.
-
classmethod
add_parser_args
(parser)[source]¶ create commandline args for all hyperparameters in
__hyperparameters__
.- Parameters
parser – an arg parser.