QData / TextAttack

TextAttack πŸ™ is a Python framework for adversarial attacks, data augmentation, and model training in NLP https://textattack.readthedocs.io/en/master/
https://textattack.readthedocs.io/en/master/
MIT License
2.97k stars 398 forks source link

ModuleNotFoundError: No module named 'tensorflow_text' on `textattack attack --help` #530

Closed alvarobartt closed 3 years ago

alvarobartt commented 3 years ago

Describe the bug

For the first time you install textattack with pip install textattack and you try to textattack attack --help it will start installing some NLTK dependencies, but at some point it will fail with the error code ModuleNotFoundError: No module named 'tensorflow_text'.

So that even though tensorflow_text is an optional requirement, it's mandatory so as to run textattack attack --help.

To Reproduce

Steps to reproduce the behavior:

  1. Install it using pip install textattack on an empty environment
  2. Run following command textattack attack --help
  3. See the error logs

Expected behavior

An ImportError shouldn't pop out while checking for the --help of a CLI command, and since this is the case, tensorflow_text could be included as a mandatory/default requirement, or just handle the ImportError so that the user knows what optional requirements need to be installed.

Screenshots or Traceback

textattack: Updating TextAttack package dependencies.
textattack: Downloading NLTK required packages.
[nltk_data] Downloading package averaged_perceptron_tagger to
[nltk_data]     C:\Users\XXX\AppData\Roaming\nltk_data...
[nltk_data]   Unzipping taggers\averaged_perceptron_tagger.zip.
[nltk_data] Downloading package stopwords to
[nltk_data]     C:\Users\XXX\AppData\Roaming\nltk_data...
[nltk_data]   Package stopwords is already up-to-date!
[nltk_data] Downloading package omw to
[nltk_data]     C:\Users\XXX\AppData\Roaming\nltk_data...
[nltk_data]   Unzipping corpora\omw.zip.
[nltk_data] Downloading package universal_tagset to
[nltk_data]     C:\Users\XXX\AppData\Roaming\nltk_data...
[nltk_data]   Unzipping taggers\universal_tagset.zip.
[nltk_data] Downloading package wordnet to
[nltk_data]     C:\Users\XXX\AppData\Roaming\nltk_data...
[nltk_data]   Package wordnet is already up-to-date!
[nltk_data] Downloading package punkt to
[nltk_data]     C:\Users\XXX\AppData\Roaming\nltk_data...
[nltk_data]   Package punkt is already up-to-date!
textattack: Downloading https://textattack.s3.amazonaws.com/word_embeddings/paragramcf.
100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 481M/481M [00:41<00:00, 11.6MB/s]
textattack: Unzipping file C:\Users\XXX\.cache\textattack\tmpuore8opz.zip to C:\Users\XXX/.cache/textattack\word_embeddings/paragramcf.
textattack: Successfully saved word_embeddings/paragramcf to cache.
Traceback (most recent call last):
  File "C:\Users\XXX\Miniconda3\envs\xxx\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\XXX\Miniconda3\envs\xxx\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\XXX\Miniconda3\envs\xxx\Scripts\textattack.exe\__main__.py", line 4, in <module>
  File "C:\Users\XXX\Miniconda3\envs\xxx\lib\site-packages\textattack\__init__.py", line 12, in <module>
    from .attack_args import AttackArgs, CommandLineAttackArgs
  File "C:\Users\XXX\Miniconda3\envs\xxx\lib\site-packages\textattack\attack_args.py", line 15, in <module>
    from .attack import Attack
  File "C:\Users\XXX\Miniconda3\envs\xxx\lib\site-packages\textattack\attack.py", line 19, in <module>
    from textattack.constraints import Constraint, PreTransformationConstraint
  File "C:\Users\XXX\Miniconda3\envs\xxx\lib\site-packages\textattack\constraints\__init__.py", line 25, in <module>
    from . import semantics
  File "C:\Users\XXX\Miniconda3\envs\xxx\lib\site-packages\textattack\constraints\semantics\__init__.py", line 7, in <module>
    from . import sentence_encoders
  File "C:\Users\XXX\Miniconda3\envs\xxx\lib\site-packages\textattack\constraints\semantics\sentence_encoders\__init__.py", line 12, in <module>
    from .universal_sentence_encoder import (
  File "C:\Users\XXX\Miniconda3\envs\xxx\lib\site-packages\textattack\constraints\semantics\sentence_encoders\universal_sentence_encoder\__init__.py", line 8, in <module> 
    from .multilingual_universal_sentence_encoder import (
  File "C:\Users\XXX\Miniconda3\envs\xxx\lib\site-packages\textattack\constraints\semantics\sentence_encoders\universal_sentence_encoder\multilingual_universal_sentence_encoder.py", line 5, in <module>
    import tensorflow_text  # noqa: F401
ModuleNotFoundError: No module named 'tensorflow_text'

System Information (please complete the following information):

qiyanjun commented 3 years ago

@alvarobartt please

pip install textattack[tensorflow,optional]

alvarobartt commented 3 years ago

Sure @qiyanjun, but shouldn't an ImportError be raised detailing how to install the missing dependencies? Also, I assume that the --help flag shouldn't require any dependency, so the try: ... except ImportError: ... block should be implemented as far as I'm concerned πŸ‘πŸ» Anyway great job with the package!

qiyanjun commented 3 years ago

I see. Great suggestion. Will add

Sent from my iPhone

On Sep 29, 2021, at 17:10, Álvaro Bartolomé @.***> wrote:

ο»Ώ Sure @qiyanjun, but shouldn't an ImportError be raised detailing how to install the missing dependencies? Also, I assume that the --help flag shouldn't require any dependency, so the try: ... except ImportError: ... block should be implemented as far as I'm concerned πŸ‘πŸ» Anyway great job with the package!

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

alvarobartt commented 3 years ago

I may create a fork and then a PR so as to address this, so I'll let you know! :+1:

qiyanjun commented 3 years ago

Thanks

Sent from my iPhone

On Sep 30, 2021, at 03:32, Álvaro Bartolomé @.***> wrote:

ο»Ώ I may create a fork and then a PR so as to address this, so I'll let you know! πŸ‘

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

qiyanjun commented 3 years ago

see PR #535

alvarobartt commented 3 years ago

Thanks @qiyanjun, that can do the work in the meantime to avoid issues with the installation πŸŽ‰