allenai / allennlp

An open-source NLP research library, built on PyTorch.
http://www.allennlp.org
Apache License 2.0
11.76k stars 2.25k forks source link

Coref_Resolver (predictor) on AllenNLP not working locally on my MAC #4082

Closed bikegirl closed 4 years ago

bikegirl commented 4 years ago

Describe the bug I have an allennlp virt env and have allennlp installed successfully. I am able to use the dep parse predictor perfectly for analysis, but when I use the coref predictor via the same exact steps as the dep parse predictor, it doesn't not work.

To Reproduce Steps to reproduce the behavior

  1. Go to 'allennlp.org'
  2. Click on 'usage tab and use the demo code for coreference resolution'
  3. Locally you should have a virt env with allennlp installed successfully
  4. conda activate allennlp_virt_env with Python 3.6.10

Expected behavior This is an example of using the dependency parser from allennlp `(allennlp) rebeccaflores@Rebeccas-MBP envs % python Python 3.6.10 | packaged by conda-forge | (default, Apr 6 2020, 14:40:13) [GCC Clang 9.0.1 ] on darwin Type "help", "copyright", "credits" or "license" for more information.

import allennlp from allennlp.predictors.predictor import Predictor /Users/rebeccaflores/miniconda3/envs/allennlp/lib/python3.6/site-packages/sklearn/utils/linearassignment.py:22: FutureWarning: The linearassignment module is deprecated in 0.21 and will be removed from 0.23. Use scipy.optimize.linear_sum_assignment instead. FutureWarning) predictor = Predictor.from_path("https://s3-us-west-2.amazonaws.com/allennlp/models/biaffine-dependency-parser-ptb-2018.08.23.tar.gz") Did not use initialization regex that was passed: .bias_ih. Did not use initialization regex that was passed: .bias_hh. Did not use initialization regex that was passed: .weight_hh. Did not use initialization regex that was passed: .weight_ih. predictor.predict( ... sentence="If I bring 10 dollars tomorrow, can you buy me lunch?" ... ) Your label namespace was 'pos'. We recommend you use a namespace ending with 'labels' or 'tags', so we don't add UNK and PAD tokens by default to your vocabulary. See documentation for non_padded_namespaces parameter in Vocabulary. {'arc_loss': 0.00019108332344330847, 'tag_loss': 0.0031930117402225733, 'loss': 0.003384095150977373, 'words': ['If', 'I', 'bring', '10', 'dollars', 'tomorrow', ',', 'can', 'you', 'buy', 'me', 'lunch', '?'], 'pos': ['IN', 'PRP', 'VBP', 'CD', 'NNS', 'NN', ',', 'MD', 'PRP', 'VB', 'PRP', 'NN', '.'], 'predicted_dependencies': ['mark', 'nsubj', 'advcl', 'num', 'dobj', 'tmod', 'punct', 'aux', 'nsubj', 'root', 'iobj', 'dobj', 'punct'], 'predicted_heads': [3, 3, 10, 5, 3, 3, 10, 10, 10, 0, 10, 10, 10], 'hierplane_tree': {'text': 'If I bring 10 dollars tomorrow , can you buy me lunch ?', 'root': {'word': 'buy', 'nodeType': 'root', 'attributes': ['VB'], 'link': 'root', 'spans': [{'start': 41, 'end': 45}], 'children': [{'word': 'bring', 'nodeType': 'advcl', 'attributes': ['VBP'], 'link': 'advcl', 'spans': [{'start': 5, 'end': 11}], 'children': [{'word': 'If', 'nodeType': 'mark', 'attributes': ['IN'], 'link': 'mark', 'spans': [{'start': 0, 'end': 3}]}, {'word': 'I', 'nodeType': 'nsubj', 'attributes': ['PRP'], 'link': 'nsubj', 'spans': [{'start': 3, 'end': 5}]}, {'word': 'dollars', 'nodeType': 'dobj', 'attributes': ['NNS'], 'link': 'dobj', 'spans': [{'start': 14, 'end': 22}], 'children': [{'word': '10', 'nodeType': 'num', 'attributes': ['CD'], 'link': 'num', 'spans': [{'start': 11, 'end': 14}]}]}, {'word': 'tomorrow', 'nodeType': 'tmod', 'attributes': ['NN'], 'link': 'tmod', 'spans': [{'start': 22, 'end': 31}]}]}, {'word': ',', 'nodeType': 'punct', 'attributes': [','], 'link': 'punct', 'spans': [{'start': 31, 'end': 33}]}, {'word': 'can', 'nodeType': 'aux', 'attributes': ['MD'], 'link': 'aux', 'spans': [{'start': 33, 'end': 37}]}, {'word': 'you', 'nodeType': 'nsubj', 'attributes': ['PRP'], 'link': 'nsubj', 'spans': [{'start': 37, 'end': 41}]}, {'word': 'me', 'nodeType': 'iobj', 'attributes': ['PRP'], 'link': 'iobj', 'spans': [{'start': 45, 'end': 48}]}, {'word': 'lunch', 'nodeType': 'dobj', 'attributes': ['NN'], 'link': 'dobj', 'spans': [{'start': 48, 'end': 54}]}, {'word': '?', 'nodeType': 'punct', 'attributes': ['.'], 'link': 'punct', 'spans': [{'start': 54, 'end': 56}]}]}, 'nodeTypeToStyle': {'root': ['color5', 'strong'], 'dep': ['color5', 'strong'], 'nsubj': ['color1'], 'nsubjpass': ['color1'], 'csubj': ['color1'], 'csubjpass': ['color1'], 'pobj': ['color2'], 'dobj': ['color2'], 'iobj': ['color2'], 'mark': ['color2'], 'pcomp': ['color2'], 'xcomp': ['color2'], 'ccomp': ['color2'], 'acomp': ['color2'], 'aux': ['color3'], 'cop': ['color3'], 'det': ['color3'], 'conj': ['color3'], 'cc': ['color3'], 'prep': ['color3'], 'number': ['color3'], 'possesive': ['color3'], 'poss': ['color3'], 'discourse': ['color3'], 'expletive': ['color3'], 'prt': ['color3'], 'advcl': ['color3'], 'mod': ['color4'], 'amod': ['color4'], 'tmod': ['color4'], 'quantmod': ['color4'], 'npadvmod': ['color4'], 'infmod': ['color4'], 'advmod': ['color4'], 'appos': ['color4'], 'nn': ['color4'], 'neg': ['color0'], 'punct': ['color0']}, 'linkToPosition': {'nsubj': 'left', 'nsubjpass': 'left', 'csubj': 'left', 'csubjpass': 'left', 'pobj': 'right', 'dobj': 'right', 'iobj': 'right', 'pcomp': 'right', 'xcomp': 'right', 'ccomp': 'right', 'acomp': 'right'}}} data = predictor.predict("Hermione rode on the train with her friends Ron and Harry to learn at Hogwartz") print(type(data)) <class 'dict'> print(data.keys()) dict_keys(['arc_loss', 'tag_loss', 'loss', 'words', 'pos', 'predicted_dependencies', 'predicted_heads', 'hierplane_tree']) pos_tags = data['pos'] doc = data['words'] dep_parses = data['predicted_dependencies'] print(pos_tags) ['NNP', 'VBD', 'IN', 'DT', 'NN', 'IN', 'PRP$', 'NNS', 'NNP', 'CC', 'NNP', 'TO', 'VB', 'IN', 'NNP'] print(doc) ['Hermione', 'rode', 'on', 'the', 'train', 'with', 'her', 'friends', 'Ron', 'and', 'Harry', 'to', 'learn', 'at', 'Hogwartz'] print(dep_parses) ['nsubj', 'root', 'prep', 'det', 'pobj', 'prep', 'poss', 'pobj', 'nsubj', 'cc', 'conj', 'aux', 'xcomp', 'prep', 'pobj']`

System (please complete the following information):

Additional context This is my stack trace for the error: `>>> coref_resolver = Predictor.from_path("https://storage.googleapis.com/allennlp-public-models/coref-spanbert-large-2020.02.27.tar.gz") Traceback (most recent call last): File "", line 1, in File "/Users/rebeccaflores/miniconda3/envs/allennlp/lib/python3.6/site-packages/allennlp/predictors/predictor.py", line 105, in from_path return Predictor.from_archive(load_archive(archive_path), predictor_name) File "/Users/rebeccaflores/miniconda3/envs/allennlp/lib/python3.6/site-packages/allennlp/models/archival.py", line 153, in load_archive cuda_device=cuda_device) File "/Users/rebeccaflores/miniconda3/envs/allennlp/lib/python3.6/site-packages/allennlp/models/model.py", line 321, in load return cls.by_name(model_type)._load(config, serialization_dir, weights_file, cuda_device) File "/Users/rebeccaflores/miniconda3/envs/allennlp/lib/python3.6/site-packages/allennlp/models/model.py", line 268, in _load model = Model.from_params(vocab=vocab, params=model_params) File "/Users/rebeccaflores/miniconda3/envs/allennlp/lib/python3.6/site-packages/allennlp/common/from_params.py", line 274, in from_params return subclass.from_params(params=params, extras) File "/Users/rebeccaflores/miniconda3/envs/allennlp/lib/python3.6/site-packages/allennlp/common/from_params.py", line 285, in from_params kwargs = create_kwargs(cls, params, extras) File "/Users/rebeccaflores/miniconda3/envs/allennlp/lib/python3.6/site-packages/allennlp/common/from_params.py", line 147, in create_kwargs kwargs[name] = annotation.from_params(params=subparams, subextras) File "/Users/rebeccaflores/miniconda3/envs/allennlp/lib/python3.6/site-packages/allennlp/common/from_params.py", line 274, in from_params return subclass.from_params(params=params, extras) File "/Users/rebeccaflores/miniconda3/envs/allennlp/lib/python3.6/site-packages/allennlp/modules/text_field_embedders/basic_text_field_embedder.py", line 117, in from_params for name, subparams in token_embedder_params.items() File "/Users/rebeccaflores/miniconda3/envs/allennlp/lib/python3.6/site-packages/allennlp/modules/text_field_embedders/basic_text_field_embedder.py", line 117, in for name, subparams in token_embedder_params.items() File "/Users/rebeccaflores/miniconda3/envs/allennlp/lib/python3.6/site-packages/allennlp/common/from_params.py", line 260, in from_params default_to_first_choice=default_to_first_choice) File "/Users/rebeccaflores/miniconda3/envs/allennlp/lib/python3.6/site-packages/allennlp/common/params.py", line 259, in pop_choice raise ConfigurationError(message) allennlp.common.checks.ConfigurationError: "pretrained_transformer_mismatched not in acceptable choices for model.text_field_embedder.token_embedders.tokens.type: ['embedding', 'character_encoding', 'elmo_token_embedder', 'openai_transformer_embedder']"

`

schmmd commented 4 years ago

Not all the usage information works in v0.9.0. We have a release candidate out (allennlp-v1.0.0.rc1) that should be able to run this model. I'm going to update the demo on Monday.

bikegirl commented 4 years ago

Do I need to update allennlp somehow locally on my virtenv or should I remove the virtenv and just create a new one with the newly update allennlp release candidate?

schmmd commented 4 years ago

@bikegirl you can probably re-use your existing environment but I typically just create a new one to be safe. We have the release candidate out now and the demo has updated usage information.

bikegirl commented 4 years ago

Okay awesome, I will test this out and update.

bikegirl commented 4 years ago

I tried to install the new release, but it didn't work. I removed my conda virtenv and start anew. These were my steps: conda create --name allenlp python=3.6.10 conda activate allennlp conda install allennlp==1.0.0rc1 allennlp-models==1.0.0rc1

I get this error: image

schmmd commented 4 years ago

Try pip install allennlp==1.0.0rc1 instead. I recommend following the instructions in our README.md.

bikegirl commented 4 years ago

The simple pip install allennlp==1.0.0rc1 does not work either for me. My terminal reports a "successful" installation of allennlp when I run that command (mainly b/c I've already installed it successfully supposedly), but when I type conda list to confirm the package was installed in my environment or I try to import allennlp, it says there is no such module.

See photos attached.

I can try the readme again, but the read me has same instructions.

githubissue1 githubissue2
bikegirl commented 4 years ago

I wanted to make a comment above, where it says "requirement already satisfied" and it shows it's installed at this path: /Users/rebeccaflores/miniconda3/lib/python3.7/site-packages I have no idea why it was installed in this path if I pip installed while I was in my virtual environment. I would have expected something along the lines of: /Users/rebeccaflores/miniconda3/envs/allennlp/lib/python3.7/site-packages so I have no idea what's going on. I don't know if I should uninstall if from my base so that I can have it only in my allennlp environments or just leave it as is and not mess with it.

Anyhow, from my base path I am able to use all the tools I want locally at least.

schmmd commented 4 years ago

I'm sorry, but I also have no idea by this point... I'm able to use it in my environment but clearly it's not working in yours.

bikegirl commented 4 years ago

Haha who knows. I really need the tools right now, so since it's working fine on my base I'm not going to mess with it lol. Later this summer I am going to try and delete it from the base and see if I can get it installed and working just in the allennlp virtenv. Thanks for all your help!

github-actions[bot] commented 4 years ago

@schmmd this is just a friendly ping to make sure you haven't forgotten about this issue 😜

github-actions[bot] commented 4 years ago

@schmmd this is just a friendly ping to make sure you haven't forgotten about this issue 😜

schmmd commented 4 years ago

Closing, as a long time has passed and I wasn't able to reproduce the original issue. @bikegirl I hope you figured something out to get the information back in April! Please open a new issue if there's anything outstanding.