Skip to content

Commit

Permalink
Merge pull request #780 from marcorosa/deps
Browse files Browse the repository at this point in the history
Polish dependencies and support python3.11
  • Loading branch information
qiyanjun authored Mar 10, 2024
2 parents c1a92b9 + 635f9e9 commit fce1f09
Show file tree
Hide file tree
Showing 107 changed files with 119 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
python-version: [3.9]

steps:
- uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ checkpoints/
*.csv
!tests/sample_outputs/csv_attack_log.csv
tests/test_command_line/attack_log.txt
textattack/=22.3.0
6 changes: 1 addition & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@
]

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"] = [
"sentence_transformers==2.2.0",
"stanza",
"visdom",
"wandb",
"gensim==4.1.2",
"gensim",
]

# For developers, install development tools along with all optional dependencies.
Expand Down Expand Up @@ -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(),
)
6 changes: 6 additions & 0 deletions tests/test_command_line/update_test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -39,5 +43,7 @@ def main():
update_test(command, outfile)




if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions textattack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions textattack/attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions textattack/attack_recipes/bae_garg_2019.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
============================================
"""

from textattack.constraints.grammaticality import PartOfSpeech
from textattack.constraints.pre_transformation import (
RepeatModification,
Expand Down
1 change: 1 addition & 0 deletions textattack/attack_recipes/bert_attack_li_2020.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
1 change: 1 addition & 0 deletions textattack/attack_recipes/checklist_ribeiro_2020.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions textattack/attack_recipes/hotflip_ebrahimi_2017.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions textattack/attack_recipes/iga_wang_2019.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions textattack/attack_recipes/input_reduction_feng_2018.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
(Pathologies of Neural Models Make Interpretations Difficult)
"""

from textattack import Attack
from textattack.constraints.pre_transformation import (
RepeatModification,
Expand Down
1 change: 1 addition & 0 deletions textattack/attack_recipes/kuleshov_2017.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions textattack/attack_recipes/morpheus_tan_2020.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

from textattack import Attack
from textattack.constraints.pre_transformation import (
RepeatModification,
Expand Down
1 change: 1 addition & 0 deletions textattack/attack_recipes/pruthi_2019.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
=================================================================
"""

from textattack import Attack
from textattack.constraints.overlap import MaxWordsPerturbed
from textattack.constraints.pre_transformation import (
Expand Down
1 change: 1 addition & 0 deletions textattack/attack_recipes/pso_zang_2020.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
(Word-level Textual Adversarial Attacking as Combinatorial Optimization)
"""

from textattack import Attack
from textattack.constraints.pre_transformation import (
InputColumnModification,
Expand Down
1 change: 1 addition & 0 deletions textattack/attack_recipes/pwws_ren_2019.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions textattack/attack_recipes/seq2sick_cheng_2018_blackbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
1 change: 0 additions & 1 deletion textattack/attack_results/successful_attack_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""


from .attack_result import AttackResult


Expand Down
1 change: 0 additions & 1 deletion textattack/augment_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
===================
"""


from dataclasses import dataclass

AUGMENTATION_RECIPE_NAMES = {
Expand Down
1 change: 0 additions & 1 deletion textattack/augmentation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions textattack/augmentation/augmenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Augmenter Class
===================
"""

import random

import tqdm
Expand Down
1 change: 1 addition & 0 deletions textattack/augmentation/recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
1 change: 0 additions & 1 deletion textattack/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"""


from abc import ABC, abstractmethod
from .textattack_command import TextAttackCommand
from . import textattack_cli
1 change: 0 additions & 1 deletion textattack/commands/eval_model_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"""


from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser
from dataclasses import dataclass

Expand Down
1 change: 0 additions & 1 deletion textattack/commands/textattack_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"""


# !/usr/bin/env python
import argparse

Expand Down
1 change: 0 additions & 1 deletion textattack/commands/train_model_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"""


from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser

from textattack import CommandLineTrainingArgs, Trainer
Expand Down
1 change: 1 addition & 0 deletions textattack/constraints/grammaticality/cola.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
--------------------------
"""

import lru
import nltk
from transformers import AutoModelForSequenceClassification, AutoTokenizer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""


from .language_model_constraint import LanguageModelConstraint

from .google_language_model import Google1BillionWordsLanguageModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""


from .google_language_model import (
GoogleLanguageModel as Google1BillionWordsLanguageModel,
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
All rights reserved.
"""


import os

import lru
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
--------------------------------------
"""

from collections import defaultdict

import numpy as np
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Author: Moustafa Alzantot ([email protected])
All rights reserved.
"""

import sys

from textattack.shared.utils import LazyLoader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""


import os

import torch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
--------------------------
"""

from .learning_to_write import LearningToWriteLanguageModel
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
"""


import torch
from torch import nn
from torch.autograd import Variable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""


from torch import nn as nn
from torch.autograd import Variable

Expand Down
1 change: 1 addition & 0 deletions textattack/constraints/grammaticality/language_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
LanguageTool Grammar Checker
------------------------------
"""

import language_tool_python

from textattack.constraints import Constraint
Expand Down
1 change: 1 addition & 0 deletions textattack/constraints/grammaticality/part_of_speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Part of Speech Constraint
--------------------------
"""

import flair
from flair.data import Sentence
from flair.models import SequenceTagger
Expand Down
1 change: 0 additions & 1 deletion textattack/constraints/overlap/meteor_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""


import nltk

from textattack.constraints import Constraint
Expand Down
1 change: 1 addition & 0 deletions textattack/constraints/pre_transformation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
-----------------------------
"""

import math

from textattack.constraints import PreTransformationConstraint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
-----------------------------
"""

from textattack.constraints import PreTransformationConstraint


Expand Down
Loading

0 comments on commit fce1f09

Please sign in to comment.