python - pycorenlp : "CoreNLP request timed out. Your document may be too long"

标签 python timeout nlp stanford-nlp

我正在尝试运行 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/

相关文章:

python - python 中的分箱数据(散点图​​)?

python - 如何使用 python selenium 将文本添加到页面?

java - Hibernate 4.0 的事务锁定问题

machine-learning - 如何训练 NER 识别单词不是实体?

c# - 文本哈希技巧在 Python 和 C# 中产生不同的结果

python charmap 编解码器无法将位置 Y 字符映射中的字节 X 解码为 <undefined>

python - 如何在 Python 中对号码列表进行排序?

python - 没有名为 'virtualenvwrapper' 的模块

python - 如何使用 python-mechanize 设置超时?

php - 当 curl 尝试解析主机时,如何更改 php curl 超时 (curl err_no 6)