Allennlp: Could I have a sample script on how to use coreference-resolution?

Created on 17 Oct 2018  路  9Comments  路  Source: allenai/allennlp

The demo on of coref is great :
http://demo.allennlp.org/coreference-resolution

Could I have a python sample script on how to use coreference-resolution? I tried with the following but failed :

from allennlp.models.archival import load_archive
from allennlp.predictors import Predictor

archive = load_archive("./coref-model-2018.02.05.tar.gz")
predictor = Predictor.from_archive(archive, 'coreference-resolution')
predictor.predict_json({"document": "This is a sentence to be predicted!"})

Most helpful comment

Funny enough, it does appear as though the parameter sentence has been deprecated and replaced with document.

+ results = model.predict(document="Put your sentence here.")
- results = model.predict(sentence="Put your sentence here.")

:-D

All 9 comments

from allennlp import pretrained
model = pretrained.neural_coreference_resolution_lee_2017()

results = model.predict(sentence="Put your sentence here.")

This appears to be out of date. The module pretrained appears to no longer exist. Please advise.

@davidbernat it seems to still work for me

$ ipython
Python 3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 13:42:17)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.7.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from allennlp import pretrained

In [2]: model = pretrained.neural_coreference_resolution_lee_2017()
/Users/nfliu/miniconda3/envs/allennlp/lib/python3.6/site-packages/torch/nn/modules/rnn.py:54: UserWarning: dropout option adds dropout after all but last recurrent layer, so non-zero dropout expects num_layers greater than 1, but got dropout=0.2 and num_layers=1
  "num_layers={}".format(dropout, num_layers))
/Users/nfliu/git/allennlp/allennlp/data/token_indexers/token_characters_indexer.py:56: UserWarning: You are using the default value (0) of `min_padding_length`, which can cause some subtle bugs (more info see https://github.com/allenai/allennlp/issues/1954). Strongly recommend to set a value, usually the maximum size of the convolutional layer size when using CnnEncoder.
  UserWarning)

maybe you could raise a new issue with more details about your allennlp version, etc?

Thank you for the quickness.
I installed via pip: pip install allennlp which installs allennlp-0.6.0. This is in Python 3.6.

I can see that the module pretrained does exist in the GitHub repository. So, this may be a problem of pretrained not being installed via pip?

hmm, 0.6.0 is quite out of date. what happens if you do pip install allennlp==0.8.0?

Doesn't exist.

localhost:~ user$ pip install allennlp==0.8.0
Collecting allennlp==0.8.0
  ERROR: Could not find a version that satisfies the requirement allennlp==0.8.0 (from versions: 0.1a6, 0.2.0, 0.2.1, 0.2.2, 0.2.3, 0.3.0, 0.4.0, 0.4.1, 0.4.2, 0.4.3, 0.5.0, 0.5.1, 0.6.0)
ERROR: No matching distribution found for allennlp==0.8.0

recent versions of allennlp require at least python 3.6.1, ever since

https://github.com/allenai/allennlp/pull/1667

That is the problem. Thank you. I was unaware that pip filtered versions based on local Python version compatibility. Updated to Python 3.6.9 downloads allennlp-0.8.5 and I assume this will work as described above. Thank you again.

Funny enough, it does appear as though the parameter sentence has been deprecated and replaced with document.

+ results = model.predict(document="Put your sentence here.")
- results = model.predict(sentence="Put your sentence here.")

:-D

Was this page helpful?
0 / 5 - 0 ratings