Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Unable to interact with md_gender Multi Task Classifier #3655

Closed
lnisenbaum-tdab opened this issue May 17, 2021 · 4 comments
Closed

Unable to interact with md_gender Multi Task Classifier #3655

lnisenbaum-tdab opened this issue May 17, 2021 · 4 comments

Comments

@lnisenbaum-tdab
Copy link

Bug description
I am not able to interact with md_gender Multi Task Classsifier model from the zoo. I tried two different approaches:

Approach 1) Google Colab Notebook

Model downloaded as expected but the following error message appears: No module named 'parlai_internal'

Reproduction steps
Enter steps to reproduce the behavior.

# Import the Interactive script
from parlai.scripts.interactive import Interactive

# call it with particular args
Interactive.main(
    # the model_file is a filename path pointing to a particular model dump.
    # Model files that begin with "zoo:" are special files distributed by the ParlAI team.
    # They'll be automatically downloaded when you ask to use them.
    model_file='zoo:md_gender/model'
)

Expected behavior
I was expecting to be able to interact with Multi Task Classifier similarly to what is shown in Google Colab Parlai Tutorial for the tutorial_transformer_generator

Logs
Please paste the command line output:

15:04:53 | building data: /usr/local/lib/python3.7/dist-packages/data/models/md_gender/md_gender_classifier.tgz
15:04:53 | Downloading http://parl.ai/downloads/_models/md_gender/md_gender_classifier.tgz to /usr/local/lib/python3.7/dist-packages/data/models/md_gender/md_gender_classifier.tgz
Downloading md_gender_classifier.tgz: 100%|██████████| 2.29G/2.29G [01:37<00:00, 23.6MB/s]
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-12-f7aa5f599605> in <module>()
      7     # Model files that begin with "zoo:" are special files distributed by the ParlAI team.
      8     # They'll be automatically downloaded when you ask to use them.
----> 9     model_file='zoo:md_gender/model'
     10 )

22 frames
/usr/local/lib/python3.7/dist-packages/parlai/core/script.py in main(cls, *args, **kwargs)
    106             return cls._run_args(args)
    107         elif kwargs:
--> 108             return cls._run_kwargs(kwargs)
    109         else:
    110             return cls._run_args(None)

/usr/local/lib/python3.7/dist-packages/parlai/core/script.py in _run_kwargs(cls, kwargs)
     71         """
     72         parser = cls.setup_args()
---> 73         opt = parser.parse_kwargs(**kwargs)
     74         return cls._run_from_parser_and_opt(opt, parser)
     75 

/usr/local/lib/python3.7/dist-packages/parlai/core/params.py in parse_kwargs(self, **kwargs)
   1265         self.error = _captured_error
   1266         try:
-> 1267             string_args = self._kwargs_to_str_args(**kwargs)
   1268             return self.parse_args(args=string_args)
   1269         finally:

/usr/local/lib/python3.7/dist-packages/parlai/core/params.py in _kwargs_to_str_args(self, **kwargs)
   1217         # become aware of any extra args that might be specified if the user
   1218         # provides something like model="transformer/generator".
-> 1219         self.add_extra_args(string_args)
   1220 
   1221         # do it again, this time knowing about ALL args.

/usr/local/lib/python3.7/dist-packages/parlai/core/params.py in add_extra_args(self, args)
    936         model = get_model_name(parsed)
    937         if model is not None:
--> 938             self.add_model_subargs(model, partial)
    939 
    940         # add world args, if we know a priori which world is being used

/usr/local/lib/python3.7/dist-packages/parlai/core/params.py in add_model_subargs(self, model, partial)
    810         Add arguments specific to a particular model.
    811         """
--> 812         agent = load_agent_module(model)
    813         try:
    814             if hasattr(agent, 'add_cmdline_args'):

/usr/local/lib/python3.7/dist-packages/parlai/core/loader.py in load_agent_module(agent_path)
    186             module_name = "%s.agents.%s.%s" % (repo, agent_path, agent_path)
    187 
--> 188     my_module = importlib.import_module(module_name)
    189     model_class = getattr(my_module, class_name)
    190 

/usr/lib/python3.7/importlib/__init__.py in import_module(name, package)
    125                 break
    126             level += 1
--> 127     return _bootstrap._gcd_import(name[level:], package, level)
    128 
    129 

/usr/lib/python3.7/importlib/_bootstrap.py in _gcd_import(name, package, level)

/usr/lib/python3.7/importlib/_bootstrap.py in _find_and_load(name, import_)

/usr/lib/python3.7/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

/usr/lib/python3.7/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

/usr/lib/python3.7/importlib/_bootstrap.py in _gcd_import(name, package, level)

/usr/lib/python3.7/importlib/_bootstrap.py in _find_and_load(name, import_)

/usr/lib/python3.7/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

/usr/lib/python3.7/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

/usr/lib/python3.7/importlib/_bootstrap.py in _gcd_import(name, package, level)

/usr/lib/python3.7/importlib/_bootstrap.py in _find_and_load(name, import_)

/usr/lib/python3.7/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

/usr/lib/python3.7/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

/usr/lib/python3.7/importlib/_bootstrap.py in _gcd_import(name, package, level)

/usr/lib/python3.7/importlib/_bootstrap.py in _find_and_load(name, import_)

/usr/lib/python3.7/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

ModuleNotFoundError: No module named 'parlai_internal'

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

Approach 2) Run locally by previously defining an environment

I also tried running the model locally on my machine on a previously defined conda environment

Reproduction steps
Enter steps to reproduce the behavior.

  1. Clonned parlai GH repo

  2. Created a conda environment and executed pip install parlai

  3. Made sure that every requirement listed in requirements.txt was present

  4. Tried interacting with the model in the command line:
    parlai interactive -t md_gender -m projects.md_gender.bert_ranker_classifier.agents:BertRankerClassifierAgent -mf zoo:md_gender/model -ecands inline -cands inline --interactive_mode False --data-parallel False

  5. At this point I had an error message stating that spacy and en_core_web_sm-2.2.0 packages were missing
    I then Installed spacy and also the package en_core_web_sm-2.2.0 running
    pip3 install https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.2.0/en_core_web_sm-2.2.0.tar.gz

  6. Tried interacting with the model one more time but another error messsage popped up

Expected behavior
I was expecting to be able to interact with Multi Task Classifier similarly to what is shown in Google Colab Parlai Tutorial for the tutorial_transformer_generator

Logs
Please paste the command line output:

/Users/laureanonisenbaum/opt/anaconda3/envs/parlai/lib/python3.7/site-packages/spacy/util.py:717: UserWarning: [W094] Model 'en_core_web_sm' (2.2.0) specifies an under-constrained spaCy version requirement: >=2.2.0. This can lead to compatibility problems with older versions, or as new spaCy versions are released, because the model may say it's compatible when it's not. Consider changing the "spacy_version" in your meta.json to a version range, with a lower and upper pin. For example: >=3.0.6,<3.1.0
  warnings.warn(warn_msg)
Traceback (most recent call last):
  File "/Users/laureanonisenbaum/opt/anaconda3/envs/parlai/bin/parlai", line 8, in <module>
    sys.exit(main())
  File "/Users/laureanonisenbaum/opt/anaconda3/envs/parlai/lib/python3.7/site-packages/parlai/__main__.py", line 14, in main
    superscript_main()
  File "/Users/laureanonisenbaum/opt/anaconda3/envs/parlai/lib/python3.7/site-packages/parlai/core/script.py", line 297, in superscript_main
    opt = parser.parse_args(args)
  File "/Users/laureanonisenbaum/opt/anaconda3/envs/parlai/lib/python3.7/site-packages/parlai/core/params.py", line 1153, in parse_args
    self.add_extra_args(args)
  File "/Users/laureanonisenbaum/opt/anaconda3/envs/parlai/lib/python3.7/site-packages/parlai/core/script.py", line 156, in add_extra_args
    sa.choices[args[0]].add_extra_args(args)
  File "/Users/laureanonisenbaum/opt/anaconda3/envs/parlai/lib/python3.7/site-packages/parlai/core/params.py", line 930, in add_extra_args
    self.add_task_args(task, partial)
  File "/Users/laureanonisenbaum/opt/anaconda3/envs/parlai/lib/python3.7/site-packages/parlai/core/params.py", line 839, in add_task_args
    agent = load_teacher_module(t)
  File "/Users/laureanonisenbaum/opt/anaconda3/envs/parlai/lib/python3.7/site-packages/parlai/core/loader.py", line 281, in load_teacher_module
    task_module = load_task_module(taskname)
  File "/Users/laureanonisenbaum/opt/anaconda3/envs/parlai/lib/python3.7/site-packages/parlai/core/loader.py", line 247, in load_task_module
    task_module = importlib.import_module(module_name)
  File "/Users/laureanonisenbaum/opt/anaconda3/envs/parlai/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/laureanonisenbaum/opt/anaconda3/envs/parlai/lib/python3.7/site-packages/parlai/tasks/md_gender/agents.py", line 18, in <module>
    from .wikipedia import WikipediaTeacher  # noqa: F401
  File "/Users/laureanonisenbaum/opt/anaconda3/envs/parlai/lib/python3.7/site-packages/parlai/tasks/md_gender/wikipedia.py", line 25, in <module>
    NLP = spacy.load('en_core_web_sm')
  File "/Users/laureanonisenbaum/opt/anaconda3/envs/parlai/lib/python3.7/site-packages/spacy/__init__.py", line 51, in load
    name, vocab=vocab, disable=disable, exclude=exclude, config=config
  File "/Users/laureanonisenbaum/opt/anaconda3/envs/parlai/lib/python3.7/site-packages/spacy/util.py", line 324, in load_model
    return load_model_from_package(name, **kwargs)
  File "/Users/laureanonisenbaum/opt/anaconda3/envs/parlai/lib/python3.7/site-packages/spacy/util.py", line 357, in load_model_from_package
    return cls.load(vocab=vocab, disable=disable, exclude=exclude, config=config)
  File "/Users/laureanonisenbaum/opt/anaconda3/envs/parlai/lib/python3.7/site-packages/en_core_web_sm/__init__.py", line 12, in load
    return load_model_from_init_py(__file__, **overrides)
  File "/Users/laureanonisenbaum/opt/anaconda3/envs/parlai/lib/python3.7/site-packages/spacy/util.py", line 522, in load_model_from_init_py
    config=config,
  File "/Users/laureanonisenbaum/opt/anaconda3/envs/parlai/lib/python3.7/site-packages/spacy/util.py", line 390, in load_model_from_path
    config = load_config(config_path, overrides=dict_to_dot(config))
  File "/Users/laureanonisenbaum/opt/anaconda3/envs/parlai/lib/python3.7/site-packages/spacy/util.py", line 547, in load_config
    raise IOError(Errors.E053.format(path=config_path, name="config.cfg"))
OSError: [E053] Could not read config.cfg from /Users/laureanonisenbaum/opt/anaconda3/envs/parlai/lib/python3.7/site-packages/en_core_web_sm/en_core_web_sm-2.2.0/config.cfg

Additional context
None

@stephenroller
Copy link
Contributor

cc @emilydinan

@ivanscattergood
Copy link

ivanscattergood commented May 25, 2021

To run the md_gender model so that it returns the stats about the self, partner and gender neutral you must set the interactive_mode='false', this will force it to use the worlds.py file and display sorted scores.

I have attached a text file, that if converted to a python file you can call this code interactively:
md_gender.txt

And you will get the following output:
Md_gender

@emilydinan
Copy link
Contributor

Hi @lnisenbaum-tdab, just as @ivanscattergood suggest, you will have to set a couple of additional parameters with your call to the interactive script. See the README here to find the command:

parlai interactive -t md_gender -m projects.md_gender.bert_ranker_classifier.agents:BertRankerClassifierAgent -mf zoo:md_gender/model -ecands inline -cands inline --interactive_mode False --data-parallel False

You will have to specify the model path (projects.md_gender.bert_ranker_classifier.agents:BertRankerClassifierAgent) as well as the cands/ecands/interactive_mode/data_parallel parameters.

Feel free to re-open if you still have issues with this.

@lnisenbaum-tdab
Copy link
Author

Yes, thanks! We got to interact with it by adding those parameters.

Also, we set up a Python 3.8.5 environment and run:

python setup.py develop

Then installed some missing dependencies:

pip install spacy>3.0.6

python -m spacy download en_core_web_sm

pip install pytorch-pretrained-bert

I will try to test it on a batch of samples now but in terms of setup we are good to close this

Cheers!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants