diff --git a/.github/workflows/check-formatting.yml b/.github/workflows/check-formatting.yml index 73dcfd77a..3151fa514 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 diff --git a/.gitignore b/.gitignore index 880868351..8c0f14f07 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 4dd1ad244..59db81e30 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,11 +17,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 - +click==8.0.2 diff --git a/setup.py b/setup.py index 6053e30bd..effda6cc0 100644 --- a/setup.py +++ b/setup.py @@ -27,11 +27,11 @@ ] extras["tensorflow"] = [ - "tensorflow==2.9.1", + "tensorflow>=2.9.1", "tensorflow_hub", - "tensorflow_text>=2", + "tensorflow_text>=2.9.0", "tensorboardX", - "tensorflow-estimator==2.9.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. @@ -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(), ) diff --git a/tests/test_command_line/update_test_outputs.py b/tests/test_command_line/update_test_outputs.py index 727aef1db..a96d37854 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() diff --git a/textattack/__init__.py b/textattack/__init__.py index 306294062..28c5c8561 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 47537d1b0..7e05f93ec 100644 --- a/textattack/attack.py +++ b/textattack/attack.py @@ -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_recipes/bae_garg_2019.py b/textattack/attack_recipes/bae_garg_2019.py index 76ed108c6..f670d8f6e 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 1801a6dc6..360b88639 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 3fb7a0e35..6491e046e 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 fa4ba9445..18724907d 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 cb7dce22d..a925d987b 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 85be1c2ef..226edf993 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 8d2b7bf93..70ab58534 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 74b61f04d..e8f57d2de 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 fb3804a9e..213506eb3 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 0812c892b..4147b3b8c 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 bf544c302..cd75c6901 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 86b79aa23..a0122aa6b 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 2d1e489ef..3ece9ceef 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 c7ce2e78c..ef4bc4d40 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 c59a11410..25b321690 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 1b8200e2d..39b8269e5 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 4c0f87f74..9f9e8bb5c 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 b4446d344..b741e3c5a 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 7957fbfee..c4dbb6b34 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 219d6500c..02ad8c5ba 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 b069c94b2..36aa1bea2 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 190bad25c..0a4f1a056 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 diff --git a/textattack/constraints/grammaticality/language_models/__init__.py b/textattack/constraints/grammaticality/language_models/__init__.py index ce726fc67..ddc20b98a 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 803d21258..26045b751 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 005dda55e..e23fcc612 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 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 8e042ea52..fc79cc9c1 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 b4b15e0fa..382a5977d 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 7a8e862be..a7f8922db 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 16aa770dc..a16e57b4f 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 610754f59..7de7ee58b 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 d43370eb5..f486aadc0 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 0781b49fb..50abcf0b3 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 f531f33c7..1cf2a404f 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 diff --git a/textattack/constraints/overlap/meteor_score.py b/textattack/constraints/overlap/meteor_score.py index 7a4eb9f16..fecb62562 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 9cfdd8cff..89261f35f 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 0eba7b501..67a1e5a76 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 b0c796fc2..520130e12 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 716554eb4..5f0d30d58 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 d60166b4e..5a2862edf 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 ecfaa05f8..e42282486 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 927d277d0..b068960bc 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/universal_sentence_encoder/__init__.py b/textattack/constraints/semantics/sentence_encoders/universal_sentence_encoder/__init__.py index 2e3b5f10b..4967402ca 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 9e36c2694..2093b0a78 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 31891ecd2..26b922dcc 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 77fb10b11..3c08ccef9 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 354225d8c..5c7074969 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 40769ae77..686a7a6a6 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 25336521f..3b1ad3acd 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 5540488d8..c9577b2b6 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 5d51bdf05..712ed7030 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 diff --git a/textattack/goal_functions/text/non_overlapping_output.py b/textattack/goal_functions/text/non_overlapping_output.py index e2cb49820..347f163f7 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 diff --git a/textattack/loggers/logger.py b/textattack/loggers/logger.py index 7e979b2bf..2c85cd125 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 80ab1b90a..ccd3d10b7 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 7b9990421..92c47a38a 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 6104de1b3..38c11b293 100644 --- a/textattack/metrics/attack_metrics/words_perturbed.py +++ b/textattack/metrics/attack_metrics/words_perturbed.py @@ -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 73c133cff..a0086d439 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 c267e7b19..a3e96e24d 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 74adc8b2d..04a90ae11 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 8e2f32a0c..1183b1a64 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 e6df4df79..b044f580d 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 445872a66..347e7e964 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 d015f9dd7..d7f57f9a2 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 5c5cba329..4d483606b 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 6deb616fa..004bed24a 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 054f8e336..094b4d8f0 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 728e02ac7..9c9d80742 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 25d0a2b57..8ef13ac27 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 660a1e1d1..b5e262916 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 49b9c8552..208911a8f 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 b5d97cf1c..c857f20cd 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 f59570ed0..54c4a40ff 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 b731c9edb..fdc48aa07 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 76b5981bc..390262810 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 2855c219b..2adaf6b26 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 f0e91d9ff..1f78a5da4 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 37594f57e..59db4f362 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/transformations/__init__.py b/textattack/transformations/__init__.py index 97619986f..a17ebd26e 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 ec83c4db4..81cc8aff9 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 5cd4e3856..ec0b772f4 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 ea7baea17..cbe0d727a 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 2d0693bb3..1ef8103c4 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 def4809bf..da567cfbc 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 d768a588f..8dd759b61 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 6194970ab..b1078ed78 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 b13c43dfb..afb957303 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 431e0e345..31163d3d2 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 1f2a47a14..319010780 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/chn_transformations/chinese_word_swap_masked.py b/textattack/transformations/word_swaps/chn_transformations/chinese_word_swap_masked.py index a0b33096c..ce217d508 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): diff --git a/textattack/transformations/word_swaps/word_swap.py b/textattack/transformations/word_swaps/word_swap.py index c51e8056f..69c11fab6 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 916b97d39..0e2d0218b 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 d30df1cfe..9cb6b16ad 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 386cddc3f..e1bcbadc0 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 0d12fa187..ff9a6ef3e 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 34a642977..089580bde 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 1738e60c5..926f1e296 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 da238036d..992e5a2f0 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 e031f0ea7..99788b832 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 517e1bfd3..31de91c4f 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 23c8427c8..e040d159b 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 5dfa1c182..9f98a8d44 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