我正在尝试运行 pycorenlp在长文本上得到一个 CoreNLP 请求超时。你的文档可能太长了
错误信息。如何解决?有没有办法增加Stanford CoreNLP超时了吗?
我不想将文本分割成更小的文本。
这是我使用的代码:
'''
From https://github.com/smilli/py-corenlp/blob/master/example.py
'''
from pycorenlp import StanfordCoreNLP
import pprint
if __name__ == '__main__':
nlp = StanfordCoreNLP('http://localhost:9000')
fp = open("long_text.txt")
text = fp.read()
output = nlp.annotate(text, properties={
'annotators': 'tokenize,ssplit,pos,depparse,parse',
'outputFormat': 'json'
})
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(output)
Stanford Core NLP Server 是使用以下工具启动的:
java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer 9000
最佳答案
可以在properties
字典中加入'timeout': '50000'
(单位为ms):
output = nlp.annotate(text, properties={
'timeout': '50000',
'annotators': 'tokenize,ssplit,pos,depparse,parse',
'outputFormat': 'json'
})
否则,您可以启动指定超时的 Stanford Core NLP 服务器:
java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 50000
(documentation 没有提到 timeout
参数,也许他们忘了添加它,它至少存在于 stanford-corenlp-full-2015-12-09, a.k.a. 3.6.0. 中,这是最新的公开版本)
关于python - pycorenlp : "CoreNLP request timed out. Your document may be too long",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36435207/