pycorenlp:"CoreNLP请求超时.您的文档可能太长"

Fra*_*urt 6 python nlp timeout stanford-nlp

我正在尝试在长文本上运行pycorenlp并收到CoreNLP request timed out. Your document may be too long错误消息.怎么解决?有没有办法增加斯坦福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)
Run Code Online (Sandbox Code Playgroud)

Stanford Core NLP Server使用以下方式启动:

java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer 9000
Run Code Online (Sandbox Code Playgroud)

Fra*_*urt 9

您可以'timeout': '50000'properties字典中添加(单位为ms):

output = nlp.annotate(text, properties={
    'timeout': '50000',
    'annotators': 'tokenize,ssplit,pos,depparse,parse',
    'outputFormat': 'json'
})
Run Code Online (Sandbox Code Playgroud)

否则,您可以启动指定超时的Stanford Core NLP服务器:

java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 50000
Run Code Online (Sandbox Code Playgroud)

(文档没有提到timeout参数,也许他们忘了添加它,它至少存在于stanford-corenlp-full-2015-12-09,又名3.6.0.,这是最新的公开发布)

  • 是的,很不幸[我目前遇到的问题](http://stackoverflow.com/questions/39809061/edu-stanford-nlp-io-runtimeioexception-could-not-connect-to-server)可能有事要做出现超时问题或类似问题。 (2认同)