fibber.paraphrase_strategies.textattack_strategy module¶
This module implements the paraphrase strategy using TextFooler.
-
class
fibber.paraphrase_strategies.textattack_strategy.
CLFModel
(clf_metric, field)[source]¶ Bases:
object
A classifier wrapper for textattack package.
-
class
fibber.paraphrase_strategies.textattack_strategy.
TextAttackStrategy
(arg_dict, dataset_name, strategy_gpu_id, output_dir, metric_bundle, field)[source]¶ Bases:
fibber.paraphrase_strategies.strategy_base.StrategyBase
This strategy is a wrapper for strategies implemented in TextAttack Package.
- The recipe is used to attack the classifier in metric_bundle.
If the attack succeeds, we use the adversarial sentence as a paraphrase. If the attack fails, we use the original sentence as a paraphrase.
This strategy always returns one paraphrase for one data record, regardless of n.
Initialize the paraphrase_strategies.
This function initialize the
self._strategy_config
,self._metric_bundle
,self._device
,self._output_dir
,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._output_dir (str): the dir name where the strategy can 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.
output_dir (str) – a directory to save any models or temporary files.
metric_bundle (MetricBundle) – a MetricBundle object.