我正在努力理解Coreference NLP斯坦福工具。,这是我的代码,它正在运行
import os
os.environ["CORENLP_HOME"] = "/home/daniel/StanfordCoreNLP/stanford-corenlp-4.0.0"
from stanza.server import CoreNLPClient
text = 'When he came from Brazil, Daniel was fortified with letters from Conan but otherwise did not know a soul except Herbert. Yet this giant man from the Northeast, who had never worn an overcoat or experienced a change of seasons, did not seem surprised by his past.'
with CoreNLPClient(annotators=['tokenize','ssplit','pos','lemma','ner', 'parse', 'depparse','coref'],
properties={'annotators': 'coref', 'coref.algorithm' : 'neural'},timeout=30000, memory='16G') as client:
ann = client.annotate(text)
chains = ann.corefChain
chain_dict=dict()
for index_chain,chain in enumerate(chains):
chain_dict[index_chain]={}
chain_dict[index_chain]['ref']=''
chain_dict[index_chain]['mentions']=[{'mentionID':mention.mentionID,
'mentionType':mention.mentionType,
'number':mention.number,
'gender':mention.gender,
'animacy':mention.animacy,
'beginIndex':mention.beginIndex,
'endIndex':mention.endIndex,
'headIndex':mention.headIndex,
'sentenceIndex':mention.sentenceIndex,
'position':mention.position,
'ref':'',
} for mention in chain.mention ]
for k,v in chain_dict.items():
print('key',k)
mentions=v['mentions']
for mention in mentions:
words_list = ann.sentence[mention['sentenceIndex']].token[mention['beginIndex']:mention['endIndex']]
mention['ref']=' '.join(t.word for t in words_list)
print(mention['ref'])我尝试了三种算法:
他是个来自东北的巨人,从来没有穿过大衣,也没有经历过季节的变化,但以理他的。
这个来自东北的巨人,从来没有穿过大衣,也没有经历过季节的变化,他的
问题:
import nltk.parse.stanford import StanfordDependencyParser进行依赖解析时,它比这个StanfordNLP库要快得多。有没有任何方法加速这个CoreNLPClient的Python?统计算法的结果似乎更好。我预计最好的结果将来自于神经算法。你同意我的观点吗?在统计算法中有4种有效的提及,而当我使用神经算法时只有2种。
我是不是遗漏了什么?
发布于 2020-08-14 15:53:06
但我不能给你任何关于3和4的线索。
https://stackoverflow.com/questions/62735456
复制相似问题