From 4a7cf0a3ce58c1818918dd1202c0262c2f8d3687 Mon Sep 17 00:00:00 2001 From: Marco Rosa Date: Fri, 23 Feb 2024 15:29:57 +0100 Subject: [PATCH 01/11] Remove unused dependencies --- requirements.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/requirements.txt b/requirements.txt index 4dd1ad24..5e9cbb8f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,6 @@ flair filelock language_tool_python lemminflect -lru-dict datasets>=2.4.0 nltk numpy>=1.21.0 @@ -17,11 +16,7 @@ tqdm word2number num2words more-itertools -PySocks!=1.5.7,>=1.5.6 pinyin>=0.4.0 jieba OpenHowNet -pycld2 -click<8.1.0 pinyin - From af3054e3aeb638eea6d4a938bc49b02bd18f5079 Mon Sep 17 00:00:00 2001 From: Marco Rosa Date: Fri, 23 Feb 2024 15:30:19 +0100 Subject: [PATCH 02/11] Remove duplicated dependency --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 5e9cbb8f..e36d756c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,4 +19,3 @@ more-itertools pinyin>=0.4.0 jieba OpenHowNet -pinyin From bb70a08ba70bfa27bf675773c4a135c53eb22403 Mon Sep 17 00:00:00 2001 From: Marco Rosa Date: Fri, 23 Feb 2024 15:52:48 +0100 Subject: [PATCH 03/11] Reintroduce lru-dict --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index e36d756c..246421e3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,6 +4,7 @@ flair filelock language_tool_python lemminflect +lru-dict datasets>=2.4.0 nltk numpy>=1.21.0 From aa33526e3a367b6ad24ff46d17b15b695673e199 Mon Sep 17 00:00:00 2001 From: Marco Rosa Date: Fri, 23 Feb 2024 15:53:27 +0100 Subject: [PATCH 04/11] Add tensorflow_hub to dependencies --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 246421e3..f16f6d6b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,6 +12,7 @@ pandas>=1.0.1 scipy>=1.4.1 torch>=1.7.0,!=1.8 transformers>=4.30.0 +tensorflow_hub terminaltables tqdm word2number From bec5f517121e3952e888d9cbcb7293b3942e19d9 Mon Sep 17 00:00:00 2001 From: Marco Rosa Date: Mon, 26 Feb 2024 11:56:53 +0100 Subject: [PATCH 05/11] Remove package already present in extras --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index f16f6d6b..246421e3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,6 @@ pandas>=1.0.1 scipy>=1.4.1 torch>=1.7.0,!=1.8 transformers>=4.30.0 -tensorflow_hub terminaltables tqdm word2number From ab011f4db79f4df384658250c275481accd5ae19 Mon Sep 17 00:00:00 2001 From: Marco Rosa Date: Mon, 26 Feb 2024 14:09:37 +0100 Subject: [PATCH 06/11] Use py311-supported tf dependencies --- setup.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 6053e30b..79f8ae28 100644 --- a/setup.py +++ b/setup.py @@ -27,11 +27,11 @@ ] extras["tensorflow"] = [ - "tensorflow==2.9.1", + "tensorflow~=2.13.1", "tensorflow_hub", - "tensorflow_text>=2", + "tensorflow_text~=2.13.0", "tensorboardX", - "tensorflow-estimator==2.9.0", + "tensorflow-estimator~=2.13.0", ] extras["optional"] = [ @@ -78,6 +78,6 @@ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", ], - python_requires=">=3.6", + python_requires=">=3.8", install_requires=open("requirements.txt").readlines(), ) From 1629ffc6248aa15a779bc54bc800ad0cb742fdfc Mon Sep 17 00:00:00 2001 From: Marco Rosa Date: Mon, 26 Feb 2024 15:20:56 +0100 Subject: [PATCH 07/11] Support python3.11 --- setup.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 79f8ae28..effda6cc 100644 --- a/setup.py +++ b/setup.py @@ -27,11 +27,11 @@ ] extras["tensorflow"] = [ - "tensorflow~=2.13.1", + "tensorflow>=2.9.1", "tensorflow_hub", - "tensorflow_text~=2.13.0", + "tensorflow_text>=2.9.0", "tensorboardX", - "tensorflow-estimator~=2.13.0", + "tensorflow-estimator>=2.9.0", ] extras["optional"] = [ @@ -39,7 +39,7 @@ "stanza", "visdom", "wandb", - "gensim==4.1.2", + "gensim", ] # For developers, install development tools along with all optional dependencies. From 3ad4fe1a3f6ba9a72d3e64da7be9d5907727ff91 Mon Sep 17 00:00:00 2001 From: Yanjun Qi Date: Sun, 10 Mar 2024 16:37:30 -0400 Subject: [PATCH 08/11] trying to solve the black and click confilct issue --- .gitignore | 1 + requirements.txt | 1 + textattack/attack.py | 4 ++-- textattack/attack_args.py | 4 ++-- textattack/constraints/grammaticality/cola.py | 2 +- .../google_language_model/alzantot_goog_lm.py | 2 +- .../constraints/grammaticality/part_of_speech.py | 2 +- .../semantics/sentence_encoders/thought_vector.py | 2 +- textattack/goal_functions/goal_function.py | 2 +- textattack/goal_functions/text/minimize_bleu.py | 2 +- .../goal_functions/text/non_overlapping_output.py | 4 ++-- .../metrics/attack_metrics/words_perturbed.py | 2 +- textattack/shared/validators.py | 5 +---- .../chn_transformations/chinese_word_swap_masked.py | 13 ++++++++++--- 14 files changed, 26 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 88086835..8c0f14f0 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,4 @@ checkpoints/ *.csv !tests/sample_outputs/csv_attack_log.csv tests/test_command_line/attack_log.txt +textattack/=22.3.0 diff --git a/requirements.txt b/requirements.txt index 246421e3..59db81e3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,3 +20,4 @@ more-itertools pinyin>=0.4.0 jieba OpenHowNet +click==8.0.2 diff --git a/textattack/attack.py b/textattack/attack.py index 47537d1b..7743817a 100644 --- a/textattack/attack.py +++ b/textattack/attack.py @@ -83,8 +83,8 @@ def __init__( constraints: List[Union[Constraint, PreTransformationConstraint]], transformation: Transformation, search_method: SearchMethod, - transformation_cache_size=2**15, - constraint_cache_size=2**15, + transformation_cache_size=2 ** 15, + constraint_cache_size=2 ** 15, ): """Initialize an attack object. diff --git a/textattack/attack_args.py b/textattack/attack_args.py index b99f6dc5..7558c47f 100644 --- a/textattack/attack_args.py +++ b/textattack/attack_args.py @@ -507,8 +507,8 @@ class _CommandLineAttackArgs: interactive: bool = False parallel: bool = False model_batch_size: int = 32 - model_cache_size: int = 2**18 - constraint_cache_size: int = 2**18 + model_cache_size: int = 2 ** 18 + constraint_cache_size: int = 2 ** 18 @classmethod def _add_parser_args(cls, parser): diff --git a/textattack/constraints/grammaticality/cola.py b/textattack/constraints/grammaticality/cola.py index 190bad25..beb7c30a 100644 --- a/textattack/constraints/grammaticality/cola.py +++ b/textattack/constraints/grammaticality/cola.py @@ -43,7 +43,7 @@ def __init__( self.max_diff = max_diff self.model_name = model_name - self._reference_score_cache = lru.LRU(2**10) + self._reference_score_cache = lru.LRU(2 ** 10) model = AutoModelForSequenceClassification.from_pretrained(model_name) tokenizer = AutoTokenizer.from_pretrained(model_name) self.model = HuggingFaceModelWrapper(model, tokenizer) diff --git a/textattack/constraints/grammaticality/language_models/google_language_model/alzantot_goog_lm.py b/textattack/constraints/grammaticality/language_models/google_language_model/alzantot_goog_lm.py index 005dda55..d47bfd6e 100644 --- a/textattack/constraints/grammaticality/language_models/google_language_model/alzantot_goog_lm.py +++ b/textattack/constraints/grammaticality/language_models/google_language_model/alzantot_goog_lm.py @@ -49,7 +49,7 @@ def __init__(self): self.sess, self.graph, self.PBTXT_PATH, self.CKPT_PATH ) - self.lm_cache = lru.LRU(2**18) + self.lm_cache = lru.LRU(2 ** 18) def clear_cache(self): self.lm_cache.clear() diff --git a/textattack/constraints/grammaticality/part_of_speech.py b/textattack/constraints/grammaticality/part_of_speech.py index f531f33c..e686efdb 100644 --- a/textattack/constraints/grammaticality/part_of_speech.py +++ b/textattack/constraints/grammaticality/part_of_speech.py @@ -56,7 +56,7 @@ def __init__( self.language_nltk = language_nltk self.language_stanza = language_stanza - self._pos_tag_cache = lru.LRU(2**14) + self._pos_tag_cache = lru.LRU(2 ** 14) if tagger_type == "flair": if tagset == "universal": self._flair_pos_tagger = SequenceTagger.load("upos-fast") diff --git a/textattack/constraints/semantics/sentence_encoders/thought_vector.py b/textattack/constraints/semantics/sentence_encoders/thought_vector.py index 4a7978b0..60bac23b 100644 --- a/textattack/constraints/semantics/sentence_encoders/thought_vector.py +++ b/textattack/constraints/semantics/sentence_encoders/thought_vector.py @@ -32,7 +32,7 @@ def __init__(self, embedding=None, **kwargs): def clear_cache(self): self._get_thought_vector.cache_clear() - @functools.lru_cache(maxsize=2**10) + @functools.lru_cache(maxsize=2 ** 10) def _get_thought_vector(self, text): """Sums the embeddings of all the words in ``text`` into a "thought vector".""" diff --git a/textattack/goal_functions/goal_function.py b/textattack/goal_functions/goal_function.py index 5d51bdf0..7fa6a7c3 100644 --- a/textattack/goal_functions/goal_function.py +++ b/textattack/goal_functions/goal_function.py @@ -40,7 +40,7 @@ def __init__( use_cache=True, query_budget=float("inf"), model_batch_size=32, - model_cache_size=2**20, + model_cache_size=2 ** 20, ): validators.validate_model_goal_function_compatibility( self.__class__, model_wrapper.model.__class__ diff --git a/textattack/goal_functions/text/minimize_bleu.py b/textattack/goal_functions/text/minimize_bleu.py index 92613be5..33999577 100644 --- a/textattack/goal_functions/text/minimize_bleu.py +++ b/textattack/goal_functions/text/minimize_bleu.py @@ -59,7 +59,7 @@ def extra_repr_keys(self): return ["maximizable", "target_bleu"] -@functools.lru_cache(maxsize=2**12) +@functools.lru_cache(maxsize=2 ** 12) def get_bleu(a, b): ref = a.words hyp = b.words diff --git a/textattack/goal_functions/text/non_overlapping_output.py b/textattack/goal_functions/text/non_overlapping_output.py index e2cb4982..443aa236 100644 --- a/textattack/goal_functions/text/non_overlapping_output.py +++ b/textattack/goal_functions/text/non_overlapping_output.py @@ -38,12 +38,12 @@ def _get_score(self, model_output, _): return num_words_diff / len(get_words_cached(self.ground_truth_output)) -@functools.lru_cache(maxsize=2**12) +@functools.lru_cache(maxsize=2 ** 12) def get_words_cached(s): return np.array(words_from_text(s)) -@functools.lru_cache(maxsize=2**12) +@functools.lru_cache(maxsize=2 ** 12) def word_difference_score(s1, s2): """Returns the number of words that are non-overlapping between s1 and s2.""" diff --git a/textattack/metrics/attack_metrics/words_perturbed.py b/textattack/metrics/attack_metrics/words_perturbed.py index 6104de1b..d4b12824 100644 --- a/textattack/metrics/attack_metrics/words_perturbed.py +++ b/textattack/metrics/attack_metrics/words_perturbed.py @@ -31,7 +31,7 @@ def calculate(self, results): self.total_attacks = len(self.results) self.all_num_words = np.zeros(len(self.results)) self.perturbed_word_percentages = np.zeros(len(self.results)) - self.num_words_changed_until_success = np.zeros(2**16) + self.num_words_changed_until_success = np.zeros(2 ** 16) self.max_words_changed = 0 for i, result in enumerate(self.results): diff --git a/textattack/shared/validators.py b/textattack/shared/validators.py index 45513a2a..55f4ed08 100644 --- a/textattack/shared/validators.py +++ b/textattack/shared/validators.py @@ -25,10 +25,7 @@ r"^textattack.models.helpers.word_cnn_for_classification.*", r"^transformers.modeling_\w*\.\w*ForSequenceClassification$", ], - ( - NonOverlappingOutput, - MinimizeBleu, - ): [ + (NonOverlappingOutput, MinimizeBleu,): [ r"^textattack.models.helpers.t5_for_text_to_text.*", ], } diff --git a/textattack/transformations/word_swaps/chn_transformations/chinese_word_swap_masked.py b/textattack/transformations/word_swaps/chn_transformations/chinese_word_swap_masked.py index a0b33096..ce217d50 100644 --- a/textattack/transformations/word_swaps/chn_transformations/chinese_word_swap_masked.py +++ b/textattack/transformations/word_swaps/chn_transformations/chinese_word_swap_masked.py @@ -15,21 +15,28 @@ class ChineseWordSwapMaskedLM(WordSwap): def __init__(self, task="fill-mask", model="xlm-roberta-base", **kwargs): from transformers import BertTokenizer, BertForMaskedLM import torch + self.tt = BertTokenizer.from_pretrained(model) self.mm = BertForMaskedLM.from_pretrained(model) self.mm.to("cuda") super().__init__(**kwargs) def get_replacement_words(self, current_text, indice_to_modify): - masked_text = current_text.replace_word_at_index(indice_to_modify, "[MASK]") # 修改前,xlmrberta的模型 + masked_text = current_text.replace_word_at_index( + indice_to_modify, "[MASK]" + ) # 修改前,xlmrberta的模型 tokens = self.tt.tokenize(masked_text.text) input_ids = self.tt.convert_tokens_to_ids(tokens) input_tensor = torch.tensor([input_ids]).to("cuda") with torch.no_grad(): outputs = self.mm(input_tensor) predictions = outputs.logits - predicted_token_ids = torch.argsort(predictions[0, indice_to_modify], descending=True)[:50] - predicted_tokens = self.tt.convert_ids_to_tokens(predicted_token_ids.tolist()[1:]) + predicted_token_ids = torch.argsort( + predictions[0, indice_to_modify], descending=True + )[:50] + predicted_tokens = self.tt.convert_ids_to_tokens( + predicted_token_ids.tolist()[1:] + ) return predicted_tokens def _get_transformations(self, current_text, indices_to_modify): From c5af16cc68a7f98e64dd9aea37bb3213fdc93c4b Mon Sep 17 00:00:00 2001 From: Yanjun Qi Date: Sun, 10 Mar 2024 16:43:47 -0400 Subject: [PATCH 09/11] Update check-formatting.yml --- .github/workflows/check-formatting.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-formatting.yml b/.github/workflows/check-formatting.yml index 73dcfd77..3151fa51 100644 --- a/.github/workflows/check-formatting.yml +++ b/.github/workflows/check-formatting.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.8] + python-version: [3.9] steps: - uses: actions/checkout@v2 From 996610015585dce4c5052a085b3ccabdeacbbd3f Mon Sep 17 00:00:00 2001 From: Yanjun Qi Date: Sun, 10 Mar 2024 16:52:46 -0400 Subject: [PATCH 10/11] reformatting with python3.9 black --- textattack/__init__.py | 1 + textattack/attack.py | 10 +++--- textattack/attack_args.py | 4 +-- textattack/attack_recipes/bae_garg_2019.py | 1 + .../attack_recipes/bert_attack_li_2020.py | 1 + .../attack_recipes/checklist_ribeiro_2020.py | 1 + .../attack_recipes/hotflip_ebrahimi_2017.py | 1 + textattack/attack_recipes/iga_wang_2019.py | 1 + .../input_reduction_feng_2018.py | 1 + textattack/attack_recipes/kuleshov_2017.py | 1 + .../attack_recipes/morpheus_tan_2020.py | 1 + textattack/attack_recipes/pruthi_2019.py | 1 + textattack/attack_recipes/pso_zang_2020.py | 1 + textattack/attack_recipes/pwws_ren_2019.py | 1 + .../seq2sick_cheng_2018_blackbox.py | 1 + .../successful_attack_result.py | 1 - textattack/augment_args.py | 1 - textattack/augmentation/__init__.py | 1 - textattack/augmentation/augmenter.py | 1 + textattack/augmentation/recipes.py | 1 + textattack/commands/__init__.py | 1 - textattack/commands/eval_model_command.py | 1 - textattack/commands/textattack_cli.py | 1 - textattack/commands/train_model_command.py | 1 - textattack/constraints/grammaticality/cola.py | 3 +- .../language_models/__init__.py | 1 - .../google_language_model/__init__.py | 1 - .../google_language_model/alzantot_goog_lm.py | 3 +- .../google_language_model.py | 1 + .../google_language_model/lm_utils.py | 1 + .../grammaticality/language_models/gpt2.py | 1 - .../learning_to_write/__init__.py | 1 + .../learning_to_write/adaptive_softmax.py | 1 - .../learning_to_write/rnn_model.py | 1 - .../grammaticality/language_tool.py | 1 + .../grammaticality/part_of_speech.py | 3 +- .../constraints/overlap/meteor_score.py | 1 - .../pre_transformation/__init__.py | 1 + .../max_modification_rate.py | 1 + .../max_word_index_modification.py | 1 + textattack/constraints/semantics/__init__.py | 1 + .../semantics/sentence_encoders/__init__.py | 1 - .../sentence_encoders/infer_sent/__init__.py | 1 - .../infer_sent/infer_sent_model.py | 9 ++--- .../sentence_encoders/thought_vector.py | 2 +- .../universal_sentence_encoder/__init__.py | 1 - textattack/datasets/helpers/ted_multi.py | 1 - textattack/goal_function_results/__init__.py | 1 + .../classification_goal_function.py | 1 - .../hardlabel_classification.py | 1 - .../classification/input_reduction.py | 1 - .../classification/targeted_classification.py | 1 - .../untargeted_classification.py | 1 - textattack/goal_functions/goal_function.py | 3 +- .../goal_functions/text/minimize_bleu.py | 2 +- .../text/non_overlapping_output.py | 5 ++- textattack/loggers/logger.py | 1 - textattack/loggers/visdom_logger.py | 1 - .../loggers/weights_and_biases_logger.py | 1 - .../metrics/attack_metrics/words_perturbed.py | 8 ++--- textattack/model_args.py | 1 - textattack/models/__init__.py | 1 - textattack/models/helpers/__init__.py | 1 - .../models/helpers/lstm_for_classification.py | 1 + .../models/helpers/t5_for_text_to_text.py | 1 + textattack/models/helpers/utils.py | 1 - .../helpers/word_cnn_for_classification.py | 1 + textattack/models/tokenizers/__init__.py | 1 - .../models/tokenizers/glove_tokenizer.py | 1 - .../models/wrappers/pytorch_model_wrapper.py | 1 - .../models/wrappers/sklearn_model_wrapper.py | 1 - .../wrappers/tensorflow_model_wrapper.py | 1 - textattack/search_methods/__init__.py | 1 + textattack/search_methods/beam_search.py | 1 + .../search_methods/genetic_algorithm.py | 1 + textattack/search_methods/greedy_search.py | 1 + .../particle_swarm_optimization.py | 7 ++-- textattack/search_methods/search_method.py | 1 - textattack/shared/__init__.py | 1 - textattack/shared/checkpoint.py | 1 + textattack/shared/data.py | 36 +++++++++++++++++-- textattack/shared/validators.py | 5 ++- textattack/transformations/__init__.py | 1 + .../back_transcription.py | 1 - .../back_translation.py | 1 - .../sentence_transformation.py | 1 - .../transformations/word_innerswap_random.py | 1 - .../word_insertions/word_insertion.py | 1 + .../word_insertion_masked_lm.py | 1 + .../transformations/word_merges/word_merge.py | 1 + .../word_merges/word_merge_masked_lm.py | 1 + .../transformations/word_swaps/__init__.py | 1 - .../chinese_homophone_character_swap.py | 1 - .../transformations/word_swaps/word_swap.py | 1 + .../word_swaps/word_swap_change_location.py | 1 + .../word_swaps/word_swap_change_number.py | 1 + .../word_swaps/word_swap_embedding.py | 1 + .../word_swaps/word_swap_gradient_based.py | 1 + .../word_swaps/word_swap_homoglyph_swap.py | 1 + .../word_swaps/word_swap_hownet.py | 1 - .../word_swaps/word_swap_inflections.py | 1 - .../word_swaps/word_swap_masked_lm.py | 1 - .../word_swap_random_character_insertion.py | 1 + ...word_swap_random_character_substitution.py | 1 + .../word_swaps/word_swap_wordnet.py | 1 - 105 files changed, 112 insertions(+), 79 deletions(-) diff --git a/textattack/__init__.py b/textattack/__init__.py index 30629406..28c5c856 100644 --- a/textattack/__init__.py +++ b/textattack/__init__.py @@ -9,6 +9,7 @@ TextAttack provides components for common NLP tasks like sentence encoding, grammar-checking, and word replacement that can be used on their own. """ + from .attack_args import AttackArgs, CommandLineAttackArgs from .augment_args import AugmenterArgs from .dataset_args import DatasetArgs diff --git a/textattack/attack.py b/textattack/attack.py index 7743817a..7e05f93e 100644 --- a/textattack/attack.py +++ b/textattack/attack.py @@ -83,8 +83,8 @@ def __init__( constraints: List[Union[Constraint, PreTransformationConstraint]], transformation: Transformation, search_method: SearchMethod, - transformation_cache_size=2 ** 15, - constraint_cache_size=2 ** 15, + transformation_cache_size=2**15, + constraint_cache_size=2**15, ): """Initialize an attack object. @@ -372,9 +372,9 @@ def filter_transformations( uncached_texts.append(transformed_text) else: # promote transformed_text to the top of the LRU cache - self.constraints_cache[ - (current_text, transformed_text) - ] = self.constraints_cache[(current_text, transformed_text)] + self.constraints_cache[(current_text, transformed_text)] = ( + self.constraints_cache[(current_text, transformed_text)] + ) if self.constraints_cache[(current_text, transformed_text)]: filtered_texts.append(transformed_text) filtered_texts += self._filter_transformations_uncached( diff --git a/textattack/attack_args.py b/textattack/attack_args.py index 7558c47f..b99f6dc5 100644 --- a/textattack/attack_args.py +++ b/textattack/attack_args.py @@ -507,8 +507,8 @@ class _CommandLineAttackArgs: interactive: bool = False parallel: bool = False model_batch_size: int = 32 - model_cache_size: int = 2 ** 18 - constraint_cache_size: int = 2 ** 18 + model_cache_size: int = 2**18 + constraint_cache_size: int = 2**18 @classmethod def _add_parser_args(cls, parser): diff --git a/textattack/attack_recipes/bae_garg_2019.py b/textattack/attack_recipes/bae_garg_2019.py index 76ed108c..f670d8f6 100644 --- a/textattack/attack_recipes/bae_garg_2019.py +++ b/textattack/attack_recipes/bae_garg_2019.py @@ -3,6 +3,7 @@ ============================================ """ + from textattack.constraints.grammaticality import PartOfSpeech from textattack.constraints.pre_transformation import ( RepeatModification, diff --git a/textattack/attack_recipes/bert_attack_li_2020.py b/textattack/attack_recipes/bert_attack_li_2020.py index 1801a6dc..360b8863 100644 --- a/textattack/attack_recipes/bert_attack_li_2020.py +++ b/textattack/attack_recipes/bert_attack_li_2020.py @@ -10,6 +10,7 @@ Consider using smaller values for "max_candidates". """ + from textattack import Attack from textattack.constraints.overlap import MaxWordsPerturbed from textattack.constraints.pre_transformation import ( diff --git a/textattack/attack_recipes/checklist_ribeiro_2020.py b/textattack/attack_recipes/checklist_ribeiro_2020.py index 3fb7a0e3..6491e046 100644 --- a/textattack/attack_recipes/checklist_ribeiro_2020.py +++ b/textattack/attack_recipes/checklist_ribeiro_2020.py @@ -5,6 +5,7 @@ (Beyond Accuracy: Behavioral Testing of NLP models with CheckList) """ + from textattack import Attack from textattack.constraints.pre_transformation import RepeatModification from textattack.goal_functions import UntargetedClassification diff --git a/textattack/attack_recipes/hotflip_ebrahimi_2017.py b/textattack/attack_recipes/hotflip_ebrahimi_2017.py index fa4ba944..18724907 100644 --- a/textattack/attack_recipes/hotflip_ebrahimi_2017.py +++ b/textattack/attack_recipes/hotflip_ebrahimi_2017.py @@ -5,6 +5,7 @@ (HotFlip: White-Box Adversarial Examples for Text Classification) """ + from textattack import Attack from textattack.constraints.grammaticality import PartOfSpeech from textattack.constraints.overlap import MaxWordsPerturbed diff --git a/textattack/attack_recipes/iga_wang_2019.py b/textattack/attack_recipes/iga_wang_2019.py index cb7dce22..a925d987 100644 --- a/textattack/attack_recipes/iga_wang_2019.py +++ b/textattack/attack_recipes/iga_wang_2019.py @@ -6,6 +6,7 @@ (Natural Language Adversarial Attacks and Defenses in Word Level) """ + from textattack import Attack from textattack.constraints.overlap import MaxWordsPerturbed from textattack.constraints.pre_transformation import StopwordModification diff --git a/textattack/attack_recipes/input_reduction_feng_2018.py b/textattack/attack_recipes/input_reduction_feng_2018.py index 85be1c2e..226edf99 100644 --- a/textattack/attack_recipes/input_reduction_feng_2018.py +++ b/textattack/attack_recipes/input_reduction_feng_2018.py @@ -5,6 +5,7 @@ (Pathologies of Neural Models Make Interpretations Difficult) """ + from textattack import Attack from textattack.constraints.pre_transformation import ( RepeatModification, diff --git a/textattack/attack_recipes/kuleshov_2017.py b/textattack/attack_recipes/kuleshov_2017.py index 8d2b7bf9..70ab5853 100644 --- a/textattack/attack_recipes/kuleshov_2017.py +++ b/textattack/attack_recipes/kuleshov_2017.py @@ -4,6 +4,7 @@ (Adversarial Examples for Natural Language Classification Problems) """ + from textattack import Attack from textattack.constraints.grammaticality.language_models import GPT2 from textattack.constraints.overlap import MaxWordsPerturbed diff --git a/textattack/attack_recipes/morpheus_tan_2020.py b/textattack/attack_recipes/morpheus_tan_2020.py index 74b61f04..e8f57d2d 100644 --- a/textattack/attack_recipes/morpheus_tan_2020.py +++ b/textattack/attack_recipes/morpheus_tan_2020.py @@ -5,6 +5,7 @@ """ + from textattack import Attack from textattack.constraints.pre_transformation import ( RepeatModification, diff --git a/textattack/attack_recipes/pruthi_2019.py b/textattack/attack_recipes/pruthi_2019.py index fb3804a9..213506eb 100644 --- a/textattack/attack_recipes/pruthi_2019.py +++ b/textattack/attack_recipes/pruthi_2019.py @@ -3,6 +3,7 @@ ================================================================= """ + from textattack import Attack from textattack.constraints.overlap import MaxWordsPerturbed from textattack.constraints.pre_transformation import ( diff --git a/textattack/attack_recipes/pso_zang_2020.py b/textattack/attack_recipes/pso_zang_2020.py index 0812c892..4147b3b8 100644 --- a/textattack/attack_recipes/pso_zang_2020.py +++ b/textattack/attack_recipes/pso_zang_2020.py @@ -6,6 +6,7 @@ (Word-level Textual Adversarial Attacking as Combinatorial Optimization) """ + from textattack import Attack from textattack.constraints.pre_transformation import ( InputColumnModification, diff --git a/textattack/attack_recipes/pwws_ren_2019.py b/textattack/attack_recipes/pwws_ren_2019.py index bf544c30..cd75c690 100644 --- a/textattack/attack_recipes/pwws_ren_2019.py +++ b/textattack/attack_recipes/pwws_ren_2019.py @@ -6,6 +6,7 @@ (Generating Natural Language Adversarial Examples through Probability Weighted Word Saliency) """ + from textattack import Attack from textattack.constraints.pre_transformation import ( RepeatModification, diff --git a/textattack/attack_recipes/seq2sick_cheng_2018_blackbox.py b/textattack/attack_recipes/seq2sick_cheng_2018_blackbox.py index 86b79aa2..a0122aa6 100644 --- a/textattack/attack_recipes/seq2sick_cheng_2018_blackbox.py +++ b/textattack/attack_recipes/seq2sick_cheng_2018_blackbox.py @@ -4,6 +4,7 @@ ================================================ (Seq2Sick: Evaluating the Robustness of Sequence-to-Sequence Models with Adversarial Examples) """ + from textattack import Attack from textattack.constraints.overlap import LevenshteinEditDistance from textattack.constraints.pre_transformation import ( diff --git a/textattack/attack_results/successful_attack_result.py b/textattack/attack_results/successful_attack_result.py index 2d1e489e..3ece9cee 100644 --- a/textattack/attack_results/successful_attack_result.py +++ b/textattack/attack_results/successful_attack_result.py @@ -4,7 +4,6 @@ """ - from .attack_result import AttackResult diff --git a/textattack/augment_args.py b/textattack/augment_args.py index c7ce2e78..ef4bc4d4 100644 --- a/textattack/augment_args.py +++ b/textattack/augment_args.py @@ -3,7 +3,6 @@ =================== """ - from dataclasses import dataclass AUGMENTATION_RECIPE_NAMES = { diff --git a/textattack/augmentation/__init__.py b/textattack/augmentation/__init__.py index c59a1141..25b32169 100644 --- a/textattack/augmentation/__init__.py +++ b/textattack/augmentation/__init__.py @@ -6,7 +6,6 @@ Transformations and constraints can be used outside of an attack for simple NLP data augmentation with the ``Augmenter`` class that returns all possible transformations for a given string. """ - from .augmenter import Augmenter from .recipes import ( WordNetAugmenter, diff --git a/textattack/augmentation/augmenter.py b/textattack/augmentation/augmenter.py index 1b8200e2..39b8269e 100644 --- a/textattack/augmentation/augmenter.py +++ b/textattack/augmentation/augmenter.py @@ -2,6 +2,7 @@ Augmenter Class =================== """ + import random import tqdm diff --git a/textattack/augmentation/recipes.py b/textattack/augmentation/recipes.py index 4c0f87f7..9f9e8bb5 100644 --- a/textattack/augmentation/recipes.py +++ b/textattack/augmentation/recipes.py @@ -5,6 +5,7 @@ Transformations and constraints can be used for simple NLP data augmentations. Here is a list of recipes for NLP data augmentations """ + import random from textattack.constraints.pre_transformation import ( diff --git a/textattack/commands/__init__.py b/textattack/commands/__init__.py index b4446d34..b741e3c5 100644 --- a/textattack/commands/__init__.py +++ b/textattack/commands/__init__.py @@ -5,7 +5,6 @@ """ - from abc import ABC, abstractmethod from .textattack_command import TextAttackCommand from . import textattack_cli diff --git a/textattack/commands/eval_model_command.py b/textattack/commands/eval_model_command.py index 7957fbfe..c4dbb6b3 100644 --- a/textattack/commands/eval_model_command.py +++ b/textattack/commands/eval_model_command.py @@ -5,7 +5,6 @@ """ - from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser from dataclasses import dataclass diff --git a/textattack/commands/textattack_cli.py b/textattack/commands/textattack_cli.py index 219d6500..02ad8c5b 100644 --- a/textattack/commands/textattack_cli.py +++ b/textattack/commands/textattack_cli.py @@ -5,7 +5,6 @@ """ - # !/usr/bin/env python import argparse diff --git a/textattack/commands/train_model_command.py b/textattack/commands/train_model_command.py index b069c94b..36aa1bea 100644 --- a/textattack/commands/train_model_command.py +++ b/textattack/commands/train_model_command.py @@ -5,7 +5,6 @@ """ - from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser from textattack import CommandLineTrainingArgs, Trainer diff --git a/textattack/constraints/grammaticality/cola.py b/textattack/constraints/grammaticality/cola.py index beb7c30a..0a4f1a05 100644 --- a/textattack/constraints/grammaticality/cola.py +++ b/textattack/constraints/grammaticality/cola.py @@ -3,6 +3,7 @@ -------------------------- """ + import lru import nltk from transformers import AutoModelForSequenceClassification, AutoTokenizer @@ -43,7 +44,7 @@ def __init__( self.max_diff = max_diff self.model_name = model_name - self._reference_score_cache = lru.LRU(2 ** 10) + self._reference_score_cache = lru.LRU(2**10) model = AutoModelForSequenceClassification.from_pretrained(model_name) tokenizer = AutoTokenizer.from_pretrained(model_name) self.model = HuggingFaceModelWrapper(model, tokenizer) diff --git a/textattack/constraints/grammaticality/language_models/__init__.py b/textattack/constraints/grammaticality/language_models/__init__.py index ce726fc6..ddc20b98 100644 --- a/textattack/constraints/grammaticality/language_models/__init__.py +++ b/textattack/constraints/grammaticality/language_models/__init__.py @@ -4,7 +4,6 @@ """ - from .language_model_constraint import LanguageModelConstraint from .google_language_model import Google1BillionWordsLanguageModel diff --git a/textattack/constraints/grammaticality/language_models/google_language_model/__init__.py b/textattack/constraints/grammaticality/language_models/google_language_model/__init__.py index 803d2125..26045b75 100644 --- a/textattack/constraints/grammaticality/language_models/google_language_model/__init__.py +++ b/textattack/constraints/grammaticality/language_models/google_language_model/__init__.py @@ -4,7 +4,6 @@ """ - from .google_language_model import ( GoogleLanguageModel as Google1BillionWordsLanguageModel, ) diff --git a/textattack/constraints/grammaticality/language_models/google_language_model/alzantot_goog_lm.py b/textattack/constraints/grammaticality/language_models/google_language_model/alzantot_goog_lm.py index d47bfd6e..e23fcc61 100644 --- a/textattack/constraints/grammaticality/language_models/google_language_model/alzantot_goog_lm.py +++ b/textattack/constraints/grammaticality/language_models/google_language_model/alzantot_goog_lm.py @@ -7,7 +7,6 @@ All rights reserved. """ - import os import lru @@ -49,7 +48,7 @@ def __init__(self): self.sess, self.graph, self.PBTXT_PATH, self.CKPT_PATH ) - self.lm_cache = lru.LRU(2 ** 18) + self.lm_cache = lru.LRU(2**18) def clear_cache(self): self.lm_cache.clear() diff --git a/textattack/constraints/grammaticality/language_models/google_language_model/google_language_model.py b/textattack/constraints/grammaticality/language_models/google_language_model/google_language_model.py index 8e042ea5..fc79cc9c 100644 --- a/textattack/constraints/grammaticality/language_models/google_language_model/google_language_model.py +++ b/textattack/constraints/grammaticality/language_models/google_language_model/google_language_model.py @@ -3,6 +3,7 @@ -------------------------------------- """ + from collections import defaultdict import numpy as np diff --git a/textattack/constraints/grammaticality/language_models/google_language_model/lm_utils.py b/textattack/constraints/grammaticality/language_models/google_language_model/lm_utils.py index b4b15e0f..382a5977 100644 --- a/textattack/constraints/grammaticality/language_models/google_language_model/lm_utils.py +++ b/textattack/constraints/grammaticality/language_models/google_language_model/lm_utils.py @@ -5,6 +5,7 @@ Author: Moustafa Alzantot (malzantot@ucla.edu) All rights reserved. """ + import sys from textattack.shared.utils import LazyLoader diff --git a/textattack/constraints/grammaticality/language_models/gpt2.py b/textattack/constraints/grammaticality/language_models/gpt2.py index 7a8e862b..a7f8922d 100644 --- a/textattack/constraints/grammaticality/language_models/gpt2.py +++ b/textattack/constraints/grammaticality/language_models/gpt2.py @@ -4,7 +4,6 @@ """ - import os import torch diff --git a/textattack/constraints/grammaticality/language_models/learning_to_write/__init__.py b/textattack/constraints/grammaticality/language_models/learning_to_write/__init__.py index 16aa770d..a16e57b4 100644 --- a/textattack/constraints/grammaticality/language_models/learning_to_write/__init__.py +++ b/textattack/constraints/grammaticality/language_models/learning_to_write/__init__.py @@ -3,4 +3,5 @@ -------------------------- """ + from .learning_to_write import LearningToWriteLanguageModel diff --git a/textattack/constraints/grammaticality/language_models/learning_to_write/adaptive_softmax.py b/textattack/constraints/grammaticality/language_models/learning_to_write/adaptive_softmax.py index 610754f5..7de7ee58 100644 --- a/textattack/constraints/grammaticality/language_models/learning_to_write/adaptive_softmax.py +++ b/textattack/constraints/grammaticality/language_models/learning_to_write/adaptive_softmax.py @@ -3,7 +3,6 @@ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ """ - import torch from torch import nn from torch.autograd import Variable diff --git a/textattack/constraints/grammaticality/language_models/learning_to_write/rnn_model.py b/textattack/constraints/grammaticality/language_models/learning_to_write/rnn_model.py index d43370eb..f486aadc 100644 --- a/textattack/constraints/grammaticality/language_models/learning_to_write/rnn_model.py +++ b/textattack/constraints/grammaticality/language_models/learning_to_write/rnn_model.py @@ -4,7 +4,6 @@ """ - from torch import nn as nn from torch.autograd import Variable diff --git a/textattack/constraints/grammaticality/language_tool.py b/textattack/constraints/grammaticality/language_tool.py index 0781b49f..50abcf0b 100644 --- a/textattack/constraints/grammaticality/language_tool.py +++ b/textattack/constraints/grammaticality/language_tool.py @@ -2,6 +2,7 @@ LanguageTool Grammar Checker ------------------------------ """ + import language_tool_python from textattack.constraints import Constraint diff --git a/textattack/constraints/grammaticality/part_of_speech.py b/textattack/constraints/grammaticality/part_of_speech.py index e686efdb..1cf2a404 100644 --- a/textattack/constraints/grammaticality/part_of_speech.py +++ b/textattack/constraints/grammaticality/part_of_speech.py @@ -2,6 +2,7 @@ Part of Speech Constraint -------------------------- """ + import flair from flair.data import Sentence from flair.models import SequenceTagger @@ -56,7 +57,7 @@ def __init__( self.language_nltk = language_nltk self.language_stanza = language_stanza - self._pos_tag_cache = lru.LRU(2 ** 14) + self._pos_tag_cache = lru.LRU(2**14) if tagger_type == "flair": if tagset == "universal": self._flair_pos_tagger = SequenceTagger.load("upos-fast") diff --git a/textattack/constraints/overlap/meteor_score.py b/textattack/constraints/overlap/meteor_score.py index 7a4eb9f1..fecb6256 100644 --- a/textattack/constraints/overlap/meteor_score.py +++ b/textattack/constraints/overlap/meteor_score.py @@ -6,7 +6,6 @@ """ - import nltk from textattack.constraints import Constraint diff --git a/textattack/constraints/pre_transformation/__init__.py b/textattack/constraints/pre_transformation/__init__.py index 9cfdd8cf..89261f35 100644 --- a/textattack/constraints/pre_transformation/__init__.py +++ b/textattack/constraints/pre_transformation/__init__.py @@ -5,6 +5,7 @@ Pre-transformation constraints determine if a transformation is valid based on only the original input and the position of the replacement. These constraints are applied before the transformation is even called. For example, these constraints can prevent search methods from swapping words at the same index twice, or from replacing stopwords. """ + from .stopword_modification import StopwordModification from .repeat_modification import RepeatModification from .input_column_modification import InputColumnModification diff --git a/textattack/constraints/pre_transformation/max_modification_rate.py b/textattack/constraints/pre_transformation/max_modification_rate.py index 0eba7b50..67a1e5a7 100644 --- a/textattack/constraints/pre_transformation/max_modification_rate.py +++ b/textattack/constraints/pre_transformation/max_modification_rate.py @@ -4,6 +4,7 @@ ----------------------------- """ + import math from textattack.constraints import PreTransformationConstraint diff --git a/textattack/constraints/pre_transformation/max_word_index_modification.py b/textattack/constraints/pre_transformation/max_word_index_modification.py index b0c796fc..520130e1 100644 --- a/textattack/constraints/pre_transformation/max_word_index_modification.py +++ b/textattack/constraints/pre_transformation/max_word_index_modification.py @@ -4,6 +4,7 @@ ----------------------------- """ + from textattack.constraints import PreTransformationConstraint diff --git a/textattack/constraints/semantics/__init__.py b/textattack/constraints/semantics/__init__.py index 716554eb..5f0d30d5 100644 --- a/textattack/constraints/semantics/__init__.py +++ b/textattack/constraints/semantics/__init__.py @@ -4,6 +4,7 @@ --------------------- Semantic constraints determine if a transformation is valid based on similarity of the semantics of the orignal input and the transformed input. """ + from . import sentence_encoders from .word_embedding_distance import WordEmbeddingDistance diff --git a/textattack/constraints/semantics/sentence_encoders/__init__.py b/textattack/constraints/semantics/sentence_encoders/__init__.py index d60166b4..5a2862ed 100644 --- a/textattack/constraints/semantics/sentence_encoders/__init__.py +++ b/textattack/constraints/semantics/sentence_encoders/__init__.py @@ -3,7 +3,6 @@ ---------------------------- """ - from .sentence_encoder import SentenceEncoder from .sentence_bert import SBERT diff --git a/textattack/constraints/semantics/sentence_encoders/infer_sent/__init__.py b/textattack/constraints/semantics/sentence_encoders/infer_sent/__init__.py index ecfaa05f..e4228248 100644 --- a/textattack/constraints/semantics/sentence_encoders/infer_sent/__init__.py +++ b/textattack/constraints/semantics/sentence_encoders/infer_sent/__init__.py @@ -3,5 +3,4 @@ ^^^^^^^^^^^^ """ - from .infer_sent import InferSent diff --git a/textattack/constraints/semantics/sentence_encoders/infer_sent/infer_sent_model.py b/textattack/constraints/semantics/sentence_encoders/infer_sent/infer_sent_model.py index 927d277d..b068960b 100644 --- a/textattack/constraints/semantics/sentence_encoders/infer_sent/infer_sent_model.py +++ b/textattack/constraints/semantics/sentence_encoders/infer_sent/infer_sent_model.py @@ -7,7 +7,6 @@ """ - # Copyright (c) 2017-present, Facebook, Inc. # All rights reserved. # @@ -209,9 +208,11 @@ def tokenize(self, s): def prepare_samples(self, sentences, bsize, tokenize, verbose): sentences = [ - [self.bos] + s.split() + [self.eos] - if not tokenize - else [self.bos] + self.tokenize(s) + [self.eos] + ( + [self.bos] + s.split() + [self.eos] + if not tokenize + else [self.bos] + self.tokenize(s) + [self.eos] + ) for s in sentences ] n_w = np.sum([len(x) for x in sentences]) diff --git a/textattack/constraints/semantics/sentence_encoders/thought_vector.py b/textattack/constraints/semantics/sentence_encoders/thought_vector.py index 60bac23b..4a7978b0 100644 --- a/textattack/constraints/semantics/sentence_encoders/thought_vector.py +++ b/textattack/constraints/semantics/sentence_encoders/thought_vector.py @@ -32,7 +32,7 @@ def __init__(self, embedding=None, **kwargs): def clear_cache(self): self._get_thought_vector.cache_clear() - @functools.lru_cache(maxsize=2 ** 10) + @functools.lru_cache(maxsize=2**10) def _get_thought_vector(self, text): """Sums the embeddings of all the words in ``text`` into a "thought vector".""" diff --git a/textattack/constraints/semantics/sentence_encoders/universal_sentence_encoder/__init__.py b/textattack/constraints/semantics/sentence_encoders/universal_sentence_encoder/__init__.py index 2e3b5f10..4967402c 100644 --- a/textattack/constraints/semantics/sentence_encoders/universal_sentence_encoder/__init__.py +++ b/textattack/constraints/semantics/sentence_encoders/universal_sentence_encoder/__init__.py @@ -3,7 +3,6 @@ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ """ - from .universal_sentence_encoder import UniversalSentenceEncoder from .multilingual_universal_sentence_encoder import ( MultilingualUniversalSentenceEncoder, diff --git a/textattack/datasets/helpers/ted_multi.py b/textattack/datasets/helpers/ted_multi.py index 9e36c269..2093b0a7 100644 --- a/textattack/datasets/helpers/ted_multi.py +++ b/textattack/datasets/helpers/ted_multi.py @@ -4,7 +4,6 @@ ------------------------------------ """ - import collections import datasets diff --git a/textattack/goal_function_results/__init__.py b/textattack/goal_function_results/__init__.py index 31891ecd..26b922dc 100644 --- a/textattack/goal_function_results/__init__.py +++ b/textattack/goal_function_results/__init__.py @@ -5,6 +5,7 @@ Goal function results report the result of a goal function evaluation, indicating whether an attack succeeded for a given example. """ + from .goal_function_result import GoalFunctionResult, GoalFunctionResultStatus from .classification_goal_function_result import ClassificationGoalFunctionResult diff --git a/textattack/goal_functions/classification/classification_goal_function.py b/textattack/goal_functions/classification/classification_goal_function.py index 77fb10b1..3c08ccef 100644 --- a/textattack/goal_functions/classification/classification_goal_function.py +++ b/textattack/goal_functions/classification/classification_goal_function.py @@ -3,7 +3,6 @@ --------------------------------------------------------------------- """ - import numpy as np import torch diff --git a/textattack/goal_functions/classification/hardlabel_classification.py b/textattack/goal_functions/classification/hardlabel_classification.py index 354225d8..5c707496 100644 --- a/textattack/goal_functions/classification/hardlabel_classification.py +++ b/textattack/goal_functions/classification/hardlabel_classification.py @@ -3,7 +3,6 @@ ------------------------------------------------------------------------ """ - from .classification_goal_function import ClassificationGoalFunction diff --git a/textattack/goal_functions/classification/input_reduction.py b/textattack/goal_functions/classification/input_reduction.py index 40769ae7..686a7a6a 100644 --- a/textattack/goal_functions/classification/input_reduction.py +++ b/textattack/goal_functions/classification/input_reduction.py @@ -4,7 +4,6 @@ --------------------------------------------------------------------- """ - from .classification_goal_function import ClassificationGoalFunction diff --git a/textattack/goal_functions/classification/targeted_classification.py b/textattack/goal_functions/classification/targeted_classification.py index 25336521..3b1ad3ac 100644 --- a/textattack/goal_functions/classification/targeted_classification.py +++ b/textattack/goal_functions/classification/targeted_classification.py @@ -4,7 +4,6 @@ ----------------------------------------------------------------------- """ - from .classification_goal_function import ClassificationGoalFunction diff --git a/textattack/goal_functions/classification/untargeted_classification.py b/textattack/goal_functions/classification/untargeted_classification.py index 5540488d..c9577b2b 100644 --- a/textattack/goal_functions/classification/untargeted_classification.py +++ b/textattack/goal_functions/classification/untargeted_classification.py @@ -4,7 +4,6 @@ ---------------------------------------------------- """ - from .classification_goal_function import ClassificationGoalFunction diff --git a/textattack/goal_functions/goal_function.py b/textattack/goal_functions/goal_function.py index 7fa6a7c3..712ed703 100644 --- a/textattack/goal_functions/goal_function.py +++ b/textattack/goal_functions/goal_function.py @@ -4,7 +4,6 @@ =========================================================== """ - from abc import ABC, abstractmethod import lru @@ -40,7 +39,7 @@ def __init__( use_cache=True, query_budget=float("inf"), model_batch_size=32, - model_cache_size=2 ** 20, + model_cache_size=2**20, ): validators.validate_model_goal_function_compatibility( self.__class__, model_wrapper.model.__class__ diff --git a/textattack/goal_functions/text/minimize_bleu.py b/textattack/goal_functions/text/minimize_bleu.py index 33999577..92613be5 100644 --- a/textattack/goal_functions/text/minimize_bleu.py +++ b/textattack/goal_functions/text/minimize_bleu.py @@ -59,7 +59,7 @@ def extra_repr_keys(self): return ["maximizable", "target_bleu"] -@functools.lru_cache(maxsize=2 ** 12) +@functools.lru_cache(maxsize=2**12) def get_bleu(a, b): ref = a.words hyp = b.words diff --git a/textattack/goal_functions/text/non_overlapping_output.py b/textattack/goal_functions/text/non_overlapping_output.py index 443aa236..347f163f 100644 --- a/textattack/goal_functions/text/non_overlapping_output.py +++ b/textattack/goal_functions/text/non_overlapping_output.py @@ -4,7 +4,6 @@ ------------------------------------------------------- """ - import functools import numpy as np @@ -38,12 +37,12 @@ def _get_score(self, model_output, _): return num_words_diff / len(get_words_cached(self.ground_truth_output)) -@functools.lru_cache(maxsize=2 ** 12) +@functools.lru_cache(maxsize=2**12) def get_words_cached(s): return np.array(words_from_text(s)) -@functools.lru_cache(maxsize=2 ** 12) +@functools.lru_cache(maxsize=2**12) def word_difference_score(s1, s2): """Returns the number of words that are non-overlapping between s1 and s2.""" diff --git a/textattack/loggers/logger.py b/textattack/loggers/logger.py index 7e979b2b..2c85cd12 100644 --- a/textattack/loggers/logger.py +++ b/textattack/loggers/logger.py @@ -3,7 +3,6 @@ ======================== """ - from abc import ABC diff --git a/textattack/loggers/visdom_logger.py b/textattack/loggers/visdom_logger.py index 80ab1b90..ccd3d10b 100644 --- a/textattack/loggers/visdom_logger.py +++ b/textattack/loggers/visdom_logger.py @@ -3,7 +3,6 @@ ======================== """ - import socket from textattack.shared.utils import LazyLoader, html_table_from_rows diff --git a/textattack/loggers/weights_and_biases_logger.py b/textattack/loggers/weights_and_biases_logger.py index 7b999042..92c47a38 100644 --- a/textattack/loggers/weights_and_biases_logger.py +++ b/textattack/loggers/weights_and_biases_logger.py @@ -3,7 +3,6 @@ ======================== """ - from textattack.shared.utils import LazyLoader, html_table_from_rows from .logger import Logger diff --git a/textattack/metrics/attack_metrics/words_perturbed.py b/textattack/metrics/attack_metrics/words_perturbed.py index d4b12824..38c11b29 100644 --- a/textattack/metrics/attack_metrics/words_perturbed.py +++ b/textattack/metrics/attack_metrics/words_perturbed.py @@ -31,7 +31,7 @@ def calculate(self, results): self.total_attacks = len(self.results) self.all_num_words = np.zeros(len(self.results)) self.perturbed_word_percentages = np.zeros(len(self.results)) - self.num_words_changed_until_success = np.zeros(2 ** 16) + self.num_words_changed_until_success = np.zeros(2**16) self.max_words_changed = 0 for i, result in enumerate(self.results): @@ -65,9 +65,9 @@ def calculate(self, results): self.all_metrics["avg_word_perturbed"] = self.avg_number_word_perturbed_num() self.all_metrics["avg_word_perturbed_perc"] = self.avg_perturbation_perc() self.all_metrics["max_words_changed"] = self.max_words_changed - self.all_metrics[ - "num_words_changed_until_success" - ] = self.num_words_changed_until_success + self.all_metrics["num_words_changed_until_success"] = ( + self.num_words_changed_until_success + ) return self.all_metrics diff --git a/textattack/model_args.py b/textattack/model_args.py index 73c133cf..a0086d43 100644 --- a/textattack/model_args.py +++ b/textattack/model_args.py @@ -3,7 +3,6 @@ =============== """ - from dataclasses import dataclass import json import os diff --git a/textattack/models/__init__.py b/textattack/models/__init__.py index c267e7b1..a3e96e24 100644 --- a/textattack/models/__init__.py +++ b/textattack/models/__init__.py @@ -35,7 +35,6 @@ We've also provided implementations of model wrappers for common patterns in some popular machine learning frameworks: including pytorch / sklearn / tensorflow. """ - from . import helpers from . import tokenizers from . import wrappers diff --git a/textattack/models/helpers/__init__.py b/textattack/models/helpers/__init__.py index 74adc8b2..04a90ae1 100644 --- a/textattack/models/helpers/__init__.py +++ b/textattack/models/helpers/__init__.py @@ -3,7 +3,6 @@ ------------------ """ - # Helper stuff, like embeddings. from . import utils from .glove_embedding_layer import GloveEmbeddingLayer diff --git a/textattack/models/helpers/lstm_for_classification.py b/textattack/models/helpers/lstm_for_classification.py index 8e2f32a0..1183b1a6 100644 --- a/textattack/models/helpers/lstm_for_classification.py +++ b/textattack/models/helpers/lstm_for_classification.py @@ -3,6 +3,7 @@ --------------------------------------------------------------------- """ + import json import os diff --git a/textattack/models/helpers/t5_for_text_to_text.py b/textattack/models/helpers/t5_for_text_to_text.py index e6df4df7..b044f580 100644 --- a/textattack/models/helpers/t5_for_text_to_text.py +++ b/textattack/models/helpers/t5_for_text_to_text.py @@ -3,6 +3,7 @@ --------------------------------------------------------------------- """ + import json import os diff --git a/textattack/models/helpers/utils.py b/textattack/models/helpers/utils.py index 445872a6..347e7e96 100644 --- a/textattack/models/helpers/utils.py +++ b/textattack/models/helpers/utils.py @@ -4,7 +4,6 @@ """ - import glob import os diff --git a/textattack/models/helpers/word_cnn_for_classification.py b/textattack/models/helpers/word_cnn_for_classification.py index d015f9dd..d7f57f9a 100644 --- a/textattack/models/helpers/word_cnn_for_classification.py +++ b/textattack/models/helpers/word_cnn_for_classification.py @@ -3,6 +3,7 @@ --------------------------------------------------------------------- """ + import json import os diff --git a/textattack/models/tokenizers/__init__.py b/textattack/models/tokenizers/__init__.py index 5c5cba32..4d483606 100644 --- a/textattack/models/tokenizers/__init__.py +++ b/textattack/models/tokenizers/__init__.py @@ -3,6 +3,5 @@ ------------------------------- """ - from .glove_tokenizer import GloveTokenizer from .t5_tokenizer import T5Tokenizer diff --git a/textattack/models/tokenizers/glove_tokenizer.py b/textattack/models/tokenizers/glove_tokenizer.py index 6deb616f..004bed24 100644 --- a/textattack/models/tokenizers/glove_tokenizer.py +++ b/textattack/models/tokenizers/glove_tokenizer.py @@ -4,7 +4,6 @@ """ - import json import tempfile diff --git a/textattack/models/wrappers/pytorch_model_wrapper.py b/textattack/models/wrappers/pytorch_model_wrapper.py index 054f8e33..094b4d8f 100644 --- a/textattack/models/wrappers/pytorch_model_wrapper.py +++ b/textattack/models/wrappers/pytorch_model_wrapper.py @@ -3,7 +3,6 @@ -------------------------- """ - import torch from torch.nn import CrossEntropyLoss diff --git a/textattack/models/wrappers/sklearn_model_wrapper.py b/textattack/models/wrappers/sklearn_model_wrapper.py index 728e02ac..9c9d8074 100644 --- a/textattack/models/wrappers/sklearn_model_wrapper.py +++ b/textattack/models/wrappers/sklearn_model_wrapper.py @@ -3,7 +3,6 @@ -------------------------- """ - import pandas as pd from .model_wrapper import ModelWrapper diff --git a/textattack/models/wrappers/tensorflow_model_wrapper.py b/textattack/models/wrappers/tensorflow_model_wrapper.py index 25d0a2b5..8ef13ac2 100644 --- a/textattack/models/wrappers/tensorflow_model_wrapper.py +++ b/textattack/models/wrappers/tensorflow_model_wrapper.py @@ -3,7 +3,6 @@ -------------------------- """ - import numpy as np from .model_wrapper import ModelWrapper diff --git a/textattack/search_methods/__init__.py b/textattack/search_methods/__init__.py index 660a1e1d..b5e26291 100644 --- a/textattack/search_methods/__init__.py +++ b/textattack/search_methods/__init__.py @@ -5,6 +5,7 @@ Search methods explore the transformation space in an attempt to find a successful attack as determined by a :ref:`Goal Functions ` and list of :ref:`Constraints ` """ + from .search_method import SearchMethod from .beam_search import BeamSearch from .greedy_search import GreedySearch diff --git a/textattack/search_methods/beam_search.py b/textattack/search_methods/beam_search.py index 49b9c855..208911a8 100644 --- a/textattack/search_methods/beam_search.py +++ b/textattack/search_methods/beam_search.py @@ -3,6 +3,7 @@ =============== """ + import numpy as np from textattack.goal_function_results import GoalFunctionResultStatus diff --git a/textattack/search_methods/genetic_algorithm.py b/textattack/search_methods/genetic_algorithm.py index b5d97cf1..c857f20c 100644 --- a/textattack/search_methods/genetic_algorithm.py +++ b/textattack/search_methods/genetic_algorithm.py @@ -2,6 +2,7 @@ Genetic Algorithm Word Swap ==================================== """ + from abc import ABC, abstractmethod import numpy as np diff --git a/textattack/search_methods/greedy_search.py b/textattack/search_methods/greedy_search.py index f59570ed..54c4a40f 100644 --- a/textattack/search_methods/greedy_search.py +++ b/textattack/search_methods/greedy_search.py @@ -2,6 +2,7 @@ Greedy Search ================= """ + from .beam_search import BeamSearch diff --git a/textattack/search_methods/particle_swarm_optimization.py b/textattack/search_methods/particle_swarm_optimization.py index b731c9ed..fdc48aa0 100644 --- a/textattack/search_methods/particle_swarm_optimization.py +++ b/textattack/search_methods/particle_swarm_optimization.py @@ -10,6 +10,7 @@ ``_ ``_ """ + import copy import numpy as np @@ -119,9 +120,9 @@ def _turn(self, source_text, target_text, prob, original_text): & indices_to_replace ) if "last_transformation" in source_text.attacked_text.attack_attrs: - new_text.attack_attrs[ - "last_transformation" - ] = source_text.attacked_text.attack_attrs["last_transformation"] + new_text.attack_attrs["last_transformation"] = ( + source_text.attacked_text.attack_attrs["last_transformation"] + ) if not self.post_turn_check or (new_text.words == source_text.words): break diff --git a/textattack/search_methods/search_method.py b/textattack/search_methods/search_method.py index 76b5981b..39026281 100644 --- a/textattack/search_methods/search_method.py +++ b/textattack/search_methods/search_method.py @@ -3,7 +3,6 @@ =============================== """ - from abc import ABC, abstractmethod from textattack.shared.utils import ReprMixin diff --git a/textattack/shared/__init__.py b/textattack/shared/__init__.py index 2855c219..2adaf6b2 100644 --- a/textattack/shared/__init__.py +++ b/textattack/shared/__init__.py @@ -6,7 +6,6 @@ """ - from . import data from . import utils from .utils import logger diff --git a/textattack/shared/checkpoint.py b/textattack/shared/checkpoint.py index f0e91d9f..1f78a5da 100644 --- a/textattack/shared/checkpoint.py +++ b/textattack/shared/checkpoint.py @@ -4,6 +4,7 @@ The ``AttackCheckpoint`` class saves in-progress attacks and loads saved attacks from disk. """ + import copy import datetime import os diff --git a/textattack/shared/data.py b/textattack/shared/data.py index 37594f57..59db4f36 100644 --- a/textattack/shared/data.py +++ b/textattack/shared/data.py @@ -8,7 +8,6 @@ """ - # fmt: off NAMED_ENTITIES = { "country": [ @@ -9431,7 +9430,23 @@ ["切", "彻", "砌", "沏"], ["高", "稿", "搞"], ["鬲", "隔", "融", "嗝"], - ["亘", "恒", "宣", "喧", "楦", "渲", "桓", "垣", "晅", "萱", "暄", "喧", "瑄", "烜", "楦"], + [ + "亘", + "恒", + "宣", + "喧", + "楦", + "渲", + "桓", + "垣", + "晅", + "萱", + "暄", + "喧", + "瑄", + "烜", + "楦", + ], ["更", "硬", "便", "梗", "更"], ["勾", "构", "钩", "沟"], ["谷", "俗", "裕", "豁", "浴"], @@ -9548,7 +9563,22 @@ ["正", "证", "症", "政", "征"], ["留", "溜", "榴", "榴"], ["旦", "担", "坦"], - ["非", "韭", "徘", "辈", "悲", "斐", "裴", "靠", "扉", "霏", "菲", "匪", "蜚", "排"], + [ + "非", + "韭", + "徘", + "辈", + "悲", + "斐", + "裴", + "靠", + "扉", + "霏", + "菲", + "匪", + "蜚", + "排", + ], ["旬", "询", "殉"], ["刑", "型"], ["弟", "第", "递", "梯", "剃", "涕"], diff --git a/textattack/shared/validators.py b/textattack/shared/validators.py index 55f4ed08..45513a2a 100644 --- a/textattack/shared/validators.py +++ b/textattack/shared/validators.py @@ -25,7 +25,10 @@ r"^textattack.models.helpers.word_cnn_for_classification.*", r"^transformers.modeling_\w*\.\w*ForSequenceClassification$", ], - (NonOverlappingOutput, MinimizeBleu,): [ + ( + NonOverlappingOutput, + MinimizeBleu, + ): [ r"^textattack.models.helpers.t5_for_text_to_text.*", ], } diff --git a/textattack/transformations/__init__.py b/textattack/transformations/__init__.py index 97619986..a17ebd26 100644 --- a/textattack/transformations/__init__.py +++ b/textattack/transformations/__init__.py @@ -5,6 +5,7 @@ A transformation is a method which perturbs a text input through the insertion, deletion and substiution of words, characters, and phrases. All transformations take a ``TokenizedText`` as input and return a list of ``TokenizedText`` that contains possible transformations. Every transformation is a subclass of the abstract ``Transformation`` class. """ + from .transformation import Transformation from .sentence_transformations import * diff --git a/textattack/transformations/sentence_transformations/back_transcription.py b/textattack/transformations/sentence_transformations/back_transcription.py index ec83c4db..81cc8aff 100644 --- a/textattack/transformations/sentence_transformations/back_transcription.py +++ b/textattack/transformations/sentence_transformations/back_transcription.py @@ -4,7 +4,6 @@ """ - from transformers import WhisperForConditionalGeneration, WhisperProcessor from textattack.shared import AttackedText diff --git a/textattack/transformations/sentence_transformations/back_translation.py b/textattack/transformations/sentence_transformations/back_translation.py index 5cd4e385..ec0b772f 100644 --- a/textattack/transformations/sentence_transformations/back_translation.py +++ b/textattack/transformations/sentence_transformations/back_translation.py @@ -4,7 +4,6 @@ """ - import random from transformers import MarianMTModel, MarianTokenizer diff --git a/textattack/transformations/sentence_transformations/sentence_transformation.py b/textattack/transformations/sentence_transformations/sentence_transformation.py index ea7baea1..cbe0d727 100644 --- a/textattack/transformations/sentence_transformations/sentence_transformation.py +++ b/textattack/transformations/sentence_transformations/sentence_transformation.py @@ -6,7 +6,6 @@ """ - from textattack.transformations import Transformation diff --git a/textattack/transformations/word_innerswap_random.py b/textattack/transformations/word_innerswap_random.py index 2d0693bb..1ef8103c 100644 --- a/textattack/transformations/word_innerswap_random.py +++ b/textattack/transformations/word_innerswap_random.py @@ -3,7 +3,6 @@ ========================================================== """ - import random from textattack.transformations import Transformation diff --git a/textattack/transformations/word_insertions/word_insertion.py b/textattack/transformations/word_insertions/word_insertion.py index def4809b..da567cfb 100644 --- a/textattack/transformations/word_insertions/word_insertion.py +++ b/textattack/transformations/word_insertions/word_insertion.py @@ -5,6 +5,7 @@ For example, if we insert "new" in position 3 in the text "I like the movie", we get "I like the new movie". Subclasses can implement the abstract ``WordInsertion`` class by overriding ``self._get_new_words``. """ + from textattack.transformations import Transformation diff --git a/textattack/transformations/word_insertions/word_insertion_masked_lm.py b/textattack/transformations/word_insertions/word_insertion_masked_lm.py index d768a588..8dd759b6 100644 --- a/textattack/transformations/word_insertions/word_insertion_masked_lm.py +++ b/textattack/transformations/word_insertions/word_insertion_masked_lm.py @@ -2,6 +2,7 @@ WordInsertionMaskedLM Class ------------------------------- """ + import re import torch diff --git a/textattack/transformations/word_merges/word_merge.py b/textattack/transformations/word_merges/word_merge.py index 6194970a..b1078ed7 100644 --- a/textattack/transformations/word_merges/word_merge.py +++ b/textattack/transformations/word_merges/word_merge.py @@ -5,6 +5,7 @@ For example, if we can merge the words "the" and "movie" in the text "I like the movie" and get following text: "I like film". When we choose to "merge" word at index ``i``, we merge it with the next word at ``i+1``. """ + from textattack.transformations import Transformation diff --git a/textattack/transformations/word_merges/word_merge_masked_lm.py b/textattack/transformations/word_merges/word_merge_masked_lm.py index b13c43df..afb95730 100644 --- a/textattack/transformations/word_merges/word_merge_masked_lm.py +++ b/textattack/transformations/word_merges/word_merge_masked_lm.py @@ -3,6 +3,7 @@ ------------------------------------------------ """ + import re import torch diff --git a/textattack/transformations/word_swaps/__init__.py b/textattack/transformations/word_swaps/__init__.py index 431e0e34..31163d3d 100644 --- a/textattack/transformations/word_swaps/__init__.py +++ b/textattack/transformations/word_swaps/__init__.py @@ -4,7 +4,6 @@ """ - from .word_swap import WordSwap # Black box transformations diff --git a/textattack/transformations/word_swaps/chn_transformations/chinese_homophone_character_swap.py b/textattack/transformations/word_swaps/chn_transformations/chinese_homophone_character_swap.py index 1f2a47a1..31901078 100644 --- a/textattack/transformations/word_swaps/chn_transformations/chinese_homophone_character_swap.py +++ b/textattack/transformations/word_swaps/chn_transformations/chinese_homophone_character_swap.py @@ -3,7 +3,6 @@ ------------------------------------- """ - import os import pandas as pd diff --git a/textattack/transformations/word_swaps/word_swap.py b/textattack/transformations/word_swaps/word_swap.py index c51e8056..69c11fab 100644 --- a/textattack/transformations/word_swaps/word_swap.py +++ b/textattack/transformations/word_swaps/word_swap.py @@ -4,6 +4,7 @@ Word swap transformations act by replacing some words in the input. Subclasses can implement the abstract ``WordSwap`` class by overriding ``self._get_replacement_words`` """ + import random import string diff --git a/textattack/transformations/word_swaps/word_swap_change_location.py b/textattack/transformations/word_swaps/word_swap_change_location.py index 916b97d3..0e2d0218 100644 --- a/textattack/transformations/word_swaps/word_swap_change_location.py +++ b/textattack/transformations/word_swaps/word_swap_change_location.py @@ -2,6 +2,7 @@ Word Swap by Changing Location ------------------------------- """ + from collections import defaultdict import more_itertools as mit diff --git a/textattack/transformations/word_swaps/word_swap_change_number.py b/textattack/transformations/word_swaps/word_swap_change_number.py index d30df1cf..9cb6b16a 100644 --- a/textattack/transformations/word_swaps/word_swap_change_number.py +++ b/textattack/transformations/word_swaps/word_swap_change_number.py @@ -3,6 +3,7 @@ ------------------------------- """ + import more_itertools as mit from num2words import num2words import numpy as np diff --git a/textattack/transformations/word_swaps/word_swap_embedding.py b/textattack/transformations/word_swaps/word_swap_embedding.py index 386cddc3..e1bcbadc 100644 --- a/textattack/transformations/word_swaps/word_swap_embedding.py +++ b/textattack/transformations/word_swaps/word_swap_embedding.py @@ -7,6 +7,7 @@ Paper title: Counter-fitting Word Vectors to Linguistic Constraints """ + from textattack.shared import AbstractWordEmbedding, WordEmbedding from .word_swap import WordSwap diff --git a/textattack/transformations/word_swaps/word_swap_gradient_based.py b/textattack/transformations/word_swaps/word_swap_gradient_based.py index 0d12fa18..ff9a6ef3 100644 --- a/textattack/transformations/word_swaps/word_swap_gradient_based.py +++ b/textattack/transformations/word_swaps/word_swap_gradient_based.py @@ -3,6 +3,7 @@ ------------------------------- """ + import torch import textattack diff --git a/textattack/transformations/word_swaps/word_swap_homoglyph_swap.py b/textattack/transformations/word_swaps/word_swap_homoglyph_swap.py index 34a64297..089580bd 100644 --- a/textattack/transformations/word_swaps/word_swap_homoglyph_swap.py +++ b/textattack/transformations/word_swaps/word_swap_homoglyph_swap.py @@ -2,6 +2,7 @@ Word Swap by Homoglyph ------------------------------- """ + import numpy as np # from textattack.shared import utils diff --git a/textattack/transformations/word_swaps/word_swap_hownet.py b/textattack/transformations/word_swaps/word_swap_hownet.py index 1738e60c..926f1e29 100644 --- a/textattack/transformations/word_swaps/word_swap_hownet.py +++ b/textattack/transformations/word_swaps/word_swap_hownet.py @@ -3,7 +3,6 @@ ------------------------------- """ - import pickle from textattack.shared import utils diff --git a/textattack/transformations/word_swaps/word_swap_inflections.py b/textattack/transformations/word_swaps/word_swap_inflections.py index da238036..992e5a2f 100644 --- a/textattack/transformations/word_swaps/word_swap_inflections.py +++ b/textattack/transformations/word_swaps/word_swap_inflections.py @@ -5,7 +5,6 @@ """ - import random import lemminflect diff --git a/textattack/transformations/word_swaps/word_swap_masked_lm.py b/textattack/transformations/word_swaps/word_swap_masked_lm.py index e031f0ea..99788b83 100644 --- a/textattack/transformations/word_swaps/word_swap_masked_lm.py +++ b/textattack/transformations/word_swaps/word_swap_masked_lm.py @@ -3,7 +3,6 @@ ------------------------------- """ - import itertools import re diff --git a/textattack/transformations/word_swaps/word_swap_random_character_insertion.py b/textattack/transformations/word_swaps/word_swap_random_character_insertion.py index 517e1bfd..31de91c4 100644 --- a/textattack/transformations/word_swaps/word_swap_random_character_insertion.py +++ b/textattack/transformations/word_swaps/word_swap_random_character_insertion.py @@ -3,6 +3,7 @@ ------------------------------------------------ """ + import numpy as np # from textattack.shared import utils diff --git a/textattack/transformations/word_swaps/word_swap_random_character_substitution.py b/textattack/transformations/word_swaps/word_swap_random_character_substitution.py index 23c8427c..e040d159 100644 --- a/textattack/transformations/word_swaps/word_swap_random_character_substitution.py +++ b/textattack/transformations/word_swaps/word_swap_random_character_substitution.py @@ -2,6 +2,7 @@ Word Swap by Random Character Substitution ------------------------------------------------ """ + import numpy as np # from textattack.shared import utils diff --git a/textattack/transformations/word_swaps/word_swap_wordnet.py b/textattack/transformations/word_swaps/word_swap_wordnet.py index 5dfa1c18..9f98a8d4 100644 --- a/textattack/transformations/word_swaps/word_swap_wordnet.py +++ b/textattack/transformations/word_swaps/word_swap_wordnet.py @@ -3,7 +3,6 @@ ------------------------------------------------ """ - import nltk from nltk.corpus import wordnet From 635f9e95a923b324f3ed212dc8645f823a9b7850 Mon Sep 17 00:00:00 2001 From: Yanjun Qi Date: Sun, 10 Mar 2024 18:53:26 -0400 Subject: [PATCH 11/11] Update update_test_outputs.py --- tests/test_command_line/update_test_outputs.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_command_line/update_test_outputs.py b/tests/test_command_line/update_test_outputs.py index 727aef1d..a96d3785 100644 --- a/tests/test_command_line/update_test_outputs.py +++ b/tests/test_command_line/update_test_outputs.py @@ -3,6 +3,8 @@ This is useful for large changes, but be wary: the outputs still may need to be manually edited to account for variance between runs. """ + + from helpers import run_command_and_get_result from test_attack import attack_test_params from test_augment import augment_test_params @@ -27,6 +29,8 @@ def update_test(command, outfile, add_magic_str=False): open(outfile, "w").write(stdout + "\n") + + def main(): #### `textattack attack` tests #### for _, command, outfile in attack_test_params: @@ -39,5 +43,7 @@ def main(): update_test(command, outfile) + + if __name__ == "__main__": main()