Allennlp 安装和使用问题
allennlp使用
Allen:coreference resolution 共指demo网站
建立有效的共指消解模型 #该项目基于huggingface和allennlp进行了改进,有开源代码。
AllenNLP是由艾伦人工智能研究所开发的用于构建用于自然语言处理的深度学习模型的开源库。它建立在PyTorch之上,旨在为希望轻松构建高质量深度NLP模型的研究人员,工程师,学生等提供支持。它为现代NLP中的通用组件和模型提供了高级抽象和API。它还提供了可扩展的框架,可以轻松地运行和管理NLP实验。
AllenNLP是一个基于PyTorch的NLP研究库,可为开发者提供语言任务中的各种业内最佳训练模型。官网提供了一个很好的入门教程AllenNLP Guide,能够让初学者在30分钟内就了解AllenNLP的使用方法。
https://www.jiqizhixin.com/articles/2019-08-13-3 四种常见NLP框架使用总结(里面有关于allennlp的部分)
AllenNLP 安装和使用
AllenNLP 的python调用方法,github
1、安装指令
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
# Result: {'top_spans': [[0, 0], [0, 2], [2, 2], [6, 6], [6, 8], [13, 13], [15, 15], [17, 18]], 'antecedent_indices': [[0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]], 'predicted_antecedents': [-1, -1, -1, 1, -1, 1, 4, -1], 'document': ['Eva', 'and', 'Martha', 'did', "n't", 'want', 'their', 'friend', 'Jenny', 'to', 'feel', 'lonely', 'so', 'they', 'invited', 'her', 'to', 'the', 'party', '.'], 'clusters': [[[0, 2], [6, 6], [13, 13]], [[6, 8], [15, 15]]]}
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."
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
stanford CoreNLP
CoreNLP Demo
CoreNLP Overview
stanfordNLP Corenlp github
python中stanfordCorenlp使用教程
CoreNLP 客户端调用api
NeuralCoref Demo:Coreference Resolution in spaCy with Neural Networks
在评价测试集中,一篇论文中用到的方法,但是还没有测试过
Lexical Chains meet Word Embeddings in Document-level Statistical
github地址