Hyperparticle / udify

A single model that parses Universal Dependencies across 75 languages. Given a sentence, jointly predicts part-of-speech tags, morphology tags, lemmas, and dependency trees.
https://arxiv.org/abs/1904.02099
MIT License
219 stars 56 forks source link

Out-of-directory calls #17

Open AngelAquino opened 4 years ago

AngelAquino commented 4 years ago

Hello, and thanks for making this parser available!

I wrote a shell script which calls predict.py from an external directory, but I encounter the following error:

Traceback (most recent call last):
  File "../udify/predict.py", line 57, in <module>
    batch_size=args.batch_size)
  File "/media/sf_thesis/udify/udify/util.py", line 143, in predict_model_with_archive
    cuda_device=cuda_device)
  File "/usr/local/lib/python3.6/dist-packages/allennlp/models/archival.py", line 230, in load_archive
    cuda_device=cuda_device)
  File "/usr/local/lib/python3.6/dist-packages/allennlp/models/model.py", line 327, in load
    return cls.by_name(model_type)._load(config, serialization_dir, weights_file, cuda_device)
  File "/usr/local/lib/python3.6/dist-packages/allennlp/models/model.py", line 265, in _load
    model = Model.from_params(vocab=vocab, params=model_params)
  File "/usr/local/lib/python3.6/dist-packages/allennlp/common/from_params.py", line 365, in from_params
    return subclass.from_params(params=params, **extras)
  File "/usr/local/lib/python3.6/dist-packages/allennlp/common/from_params.py", line 386, in from_params
    kwargs = create_kwargs(cls, params, **extras)
  File "/usr/local/lib/python3.6/dist-packages/allennlp/common/from_params.py", line 133, in create_kwargs
    kwargs[name] = construct_arg(cls, name, annotation, param.default, params, **extras)
  File "/usr/local/lib/python3.6/dist-packages/allennlp/common/from_params.py", line 229, in construct_arg
    return annotation.from_params(params=subparams, **subextras)
  File "/usr/local/lib/python3.6/dist-packages/allennlp/common/from_params.py", line 365, in from_params
    return subclass.from_params(params=params, **extras)
  File "/media/sf_thesis/udify/udify/modules/text_field_embedder.py", line 163, in from_params
    for name, subparams in token_embedder_params.items()
  File "/media/sf_thesis/udify/udify/modules/text_field_embedder.py", line 163, in <dictcomp>
    for name, subparams in token_embedder_params.items()
  File "/usr/local/lib/python3.6/dist-packages/allennlp/common/from_params.py", line 365, in from_params
    return subclass.from_params(params=params, **extras)
  File "/usr/local/lib/python3.6/dist-packages/allennlp/common/from_params.py", line 388, in from_params
    return cls(**kwargs)  # type: ignore
  File "/media/sf_thesis/udify/udify/modules/bert_pretrained.py", line 589, in __init__
    model = BertModel(BertConfig.from_json_file(bert_config))
  File "/usr/local/lib/python3.6/dist-packages/pytorch_pretrained_bert/modeling.py", line 206, in from_json_file
    with open(json_file, "r", encoding='utf-8') as reader:
FileNotFoundError: [Errno 2] No such file or directory: 'config/archive/bert-base-multilingual-cased/bert_config.json'

The program works fine when called from within the udify directory itself, though. Would it be possible to modify the addresses in the source code to work for external calls as well? I'd be willing to help sift through the source files for this if needed.

Hyperparticle commented 4 years ago

The code assumes all paths point inside the repo for simplicity. One easy workaround is to create a symlink inside the repo that points to your desired directory/file. Otherwise, it should require some code changes to the scripts to get it working, probably not too difficult. I don't have time right now to look into this myself but I welcome pull requests.