【问题标题】:NLTK can't find the Stanford POS tagger model fileNLTK 找不到 Stanford POS tagger 模型文件
【发布时间】:2016-08-29 15:33:41
【问题描述】:

我正在尝试使用来自 NLTK 的 StanfordPOSTagger。我下载了 Stanford POS full tagger。我已经设置了

CLASSPATH=/home/waheeb/Stanford_Tools/stanford-postagger-full-2015-12-09  /stanford-postagger.jar
STANFORD_MODELS=home/waheeb/Stanford_Tools/stanford-postagger-full-2015-12-09/models

当我在 python 中输入以下内容时:

>>> from nltk.tag import StanfordPOSTagger
>>> st = StanfordPOSTagger('english-bidirectional-distsim.tagger')

我收到以下错误:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/waheeb/anaconda2/lib/python2.7/site-packages/nltk/tag /stanford.py", line 136, in __init__
super(StanfordPOSTagger, self).__init__(*args, **kwargs)
File "/home/waheeb/anaconda2/lib/python2.7/site-packages/nltk/tag/stanford.py", line 56, in __init__
env_vars=('STANFORD_MODELS',), verbose=verbose)
File "/home/waheeb/anaconda2/lib/python2.7/site-packages /nltk/internals.py", line 573, in find_file
file_names, url, verbose))
File "/home/waheeb/anaconda2/lib/python2.7/site-packages/nltk/internals.py", line 567, in find_file_iter
raise LookupError('\n\n%s\n%s\n%s' % (div, msg, div))

查找错误:

=========================================================================
NLTK was unable to find the english-bidirectional-distsim.tagger file!
Use software specific configuration paramaters or set the TANFORD_MODELS  environment variable.
==========================================================================

为什么会这样??

【问题讨论】:

标签: python nlp nltk stanford-nlp pos-tagger


【解决方案1】:

在调用 Python 脚本之前,您忘记在命令行中使用 export。 IE。

alvas@ubi:~$ export STANFORDTOOLSDIR=$HOME
alvas@ubi:~$ export CLASSPATH=$STANFORDTOOLSDIR/stanford-postagger-full-2015-12-09/stanford-postagger.jar
alvas@ubi:~$ export STANFORD_MODELS=$STANFORDTOOLSDIR/stanford-postagger-full-2015-12-09/models
alvas@ubi:~$ python

更多详情见https://gist.github.com/alvations/e1df0ba227e542955a8a


类似的问题包括:

【讨论】:

  • @alvas....我已经导出了它们。我忘了在问题中提到这一点。但错误仍然存​​在。
  • 您是否认真按照gist.github.com/alvations/e1df0ba227e542955a8a上的说明进行操作?
  • 完美...谢谢。如果您还注意到我忘记在 STANFORD_MODELS=/ 中的 home 之前添加“/”
猜你喜欢
  • 2017-11-05
  • 1970-01-01
  • 2015-01-26
  • 1970-01-01
  • 2015-06-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-27
相关资源
最近更新 更多