pip install allennlp
pip install allennlp-models
from allennlp.predictors.predictor import Predictor
# path can be url or local path (pre-downloaded file)
predictor = Predictor.from_path("https://storage.googleapis.com/allennlp-public-models/coref-spanbert-large-2021.03.10.tar.gz")
text = "Eva and Martha didn't want their friend Jenny to feel lonely so they invited her to the party."
prediction = predictor.predict(document=text) # get prediction
print(prediction['clusters']) # list of clusters (the indices of spaCy tokens)
# Result: [[[0, 2], [6, 6], [13, 13]], [[6, 8], [15, 15]]]
print(predictor.coref_resolved(text)) # resolved text
# Result: "Eva and Martha didn't want Eva and Martha's friend Jenny to feel lonely so Eva and Martha invited their friend Jenny to the party."
其他相关问题:
(1)allennlp + wordnet + zipfile.BadZipFile error
(2)离线安装nltk_data
spacy安装和使用问题(tokenizer)
pip install spacy
import spacy
nlp = spacy.load('en_core_web_sm') # load the model
text = "Eva and Martha didn't want their friend Jenny to feel lonely so they invited her to the party."
doc = nlp(text) # get the spaCy Doc (composed of Tokens)
print(list(doc)) # tokens
加载en_core_web_sm模型可能会出现SSL error的问题,可以到官方release下载和当前spacy版本对应的模型,然后利用pip进行安装:
pip show spacy # show the version of spacy
pip install en_core_web_sm-x.x.x.tar.gz # install the model without proxy - method 1
python -m spacy download en_core_web_sm # install the model with proxy - method 2
其他相关问题:
(1)解决neuralcoref和spacy版本兼容性问题