斯坦福大学CoreNLP标记化.空白属性不适用于中文



我正在使用斯坦福CoreNLP进行pos标记和NER在预先标记的中文文本上,我阅读了官方文档 https://stanfordnlp.github.io/CoreNLP/tokenize.html,说tokenize.whitespace选项"如果设置为true,则仅在遇到空格时才分隔单词"。这正是我想要的。

但是我正在使用python,pycorenlp与CoreNLP服务器进行交互,并且对java一无所知。然后我读了 anwser 如何用斯坦福 CoreNLP 标记预标记文本?并认为也许唯一要做的就是在我的请求后属性字典中添加"tokenize.whitespace"="true"和另一个属性,但它根本不起作用。我像这样运行我的服务器:

java -Xmx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -serverProperties StanfordCoreNLP-chinese.properties -port 9000 -timeout 150000

在我的Jupyter笔记本中:

from pycorenlp import StanfordCoreNLP
nlp = StanfordCoreNLP('http://localhost:9000')
output = nlp.annotate('公司 作为 物联网 行业', properties={
'annotators': 'pos,ner',
'tokenize.whitespace': 'true', # first property
'ssplit.eolonly': 'true', # second property
'outputFormat': 'json'
})
for sentence in output['sentences']:
print(' '.join([token['word'] for token in sentence['tokens']]))

这给了:

公司 作为 物 联网 行业

CoreNLP 仍在标记令牌"物联网",就像我不添加这两个属性一样。然后我尝试创建一个.properties文件并在命令行上使用它,而不是StanfordCoreNLP-chinese.properties,但它也不起作用。在我的测试属性中:

tokenize.whitespace=true
ssplit.eolonly=true

然后我像这样运行服务器:

java -Xmx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -serverProperties 'test.properties' -port 9000 -timeout 150000

它仍然表现得好像我什么都没改变。有人知道我错过了什么吗?任何帮助都值得赞赏:)

最后我解决了自己的问题。

对中文文本使用 tokenize.whitespace=true 很棘手,似乎它永远不起作用;相反,添加

'tokenize.language': 'Whitespace'

添加到属性字典或等效项,添加

tokenize.language: Whitespace

到您的 .properties 文件以正确完成工作。

此属性写在同一页上 https://stanfordnlp.github.io/CoreNLP/tokenize.html#options,我以前没有注意到。为什么它出于同一目的存在两个属性,这有点令人困惑。

最新更新