如何使用Stanford NLP Tagger和NLTK提高速度 [英] How to improve speed with Stanford NLP Tagger and NLTK

查看:134
本文介绍了如何使用Stanford NLP Tagger和NLTK提高速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以以更高性能的方式使用Standford Tagger?

Is there any way to use the Standford Tagger in a more performant fashion?

每次调用NLTK的包装器都会为每个分析的字符串启动一个新的Java实例,这非常慢,尤其是在使用较大的外语模型时……

Each call to NLTK's wrapper starts a new java instance per analyzed string which is very very slow especially when a larger foreign language model is used...

http://www.nltk.org/api/nltk.tag .html#module-nltk.tag.stanford

推荐答案

找到了解决方案.可以在servlet模式下运行POS Tagger,然后通过HTTP连接到它.完美.

Found the solution. It is possible to run the POS Tagger in servlet mode and then connect to it via HTTP. Perfect.

http://nlp.stanford.edu/software/pos-tagger-faq.shtml #d

示例

在后台启动服务器

nohup java -mx1000m -cp /var/stanford-postagger-full-2014-01-04/stanford-postagger.jar edu.stanford.nlp.tagger.maxent.MaxentTaggerServer -model /var/stanford-postagger-full-2014-01-04/models/german-dewac.tagger -port 2020 >& /dev/null &

调整防火墙以限制仅从本地主机对端口2020的访问

iptables -A INPUT -p tcp -s localhost --dport 2020 -j ACCEPT
iptables -A INPUT -p tcp --dport 2020 -j DROP

使用wget测试

wget http://localhost:2020/?die welt ist schön

关闭服务器

pkill -f stanford

恢复iptable设置

iptables -D INPUT -p tcp -s localhost --dport 2020 -j ACCEPT
iptables -D INPUT -p tcp --dport 2020 -j DROP

这篇关于如何使用Stanford NLP Tagger和NLTK提高速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆