python - NLTK 包和其他依赖项出现错误

标签 python nlp stanford-nlp named-entity-recognition

我已经安装了NLTK包和其他依赖项,并设置环境变量如下:

STANFORD_MODELS=/mnt/d/stanford-ner/stanford-ner-2018-10-16/classifiers/english.all.3class.distsim.crf.ser.gz:/mnt/d/stanford-ner/stanford-ner-2018-10-16/classifiers/english.muc.7class.distsim.crf.ser.gz:/mnt/d/stanford-ner/stanford-ner-2018-10-16/classifiers/english.conll.4class.distsim.crf.ser.gz

CLASSPATH=/mnt/d/stanford-ner/stanford-ner-2018-10-16/stanford-ner.jar

当我尝试访问如下分类器时:

stanford_classifier = os.environ.get('STANFORD_MODELS').split(':')[0]

stanford_ner_path = os.environ.get('CLASSPATH').split(':')[0]

st = StanfordNERTagger(stanford_classifier, stanford_ner_path, encoding='utf-8')

我收到以下错误。但我不明白是什么导致了这个错误。

Error: Could not find or load main class edu.stanford.nlp.ie.crf.CRFClassifier
OSError: Java command failed : ['/mnt/c/Program Files (x86)/Common 
Files/Oracle/Java/javapath_target_1133041234/java.exe', '-mx1000m', '-cp', '/mnt/d/stanford-ner/stanford-ner-2018-10-16/stanford-ner.jar', 'edu.stanford.nlp.ie.crf.CRFClassifier', '-loadClassifier', '/mnt/d/stanford-ner/stanford-ner-2018-10-16/classifiers/english.all.3class.distsim.crf.ser.gz', '-textFile', '/tmp/tmpaiqclf_d', '-outputFormat', 'slashTags', '-tokenizerFactory', 'edu.stanford.nlp.process.WhitespaceTokenizer', '-tokenizerOptions', '"tokenizeNLs=false"', '-encoding', 'utf8']

最佳答案

我找到了这个问题的答案。我正在使用 NLTK == 3.4。从 NLTK ==3.3 及以上版本开始,斯坦福 NLP(POS、NER、tokenizer)不会作为 nltk.tag 的一部分加载,而是从 nltk.parse.corenlp.CoreNLPParser 加载。 stackoverflow 的答案可以在 stackoverflow.com/questions/13883277/stanford-parser-and-nltk/… 中找到,官方文档的 github 链接是 github.com/nltk/nltk/wiki/Stanford-CoreNLP-API-in-NLTK .

其他信息,如果您面临来自 NER 标记器或 coreNLP API 的任何其他解析器的超时问题,请增加超时限制,如 https://github.com/nltk/nltk/wiki/Stanford-CoreNLP-API-in-NLTK/_compare/3d64e56bede5e6d93502360f2fcd286b633cbdb9...f33be8b06094dae21f1437a6cb634f86ad7d83f7 中所述。作者:dimazest。

关于python - NLTK 包和其他依赖项出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55185021/

相关文章:

python - reshape Pandas DataFrame

java - 斯坦福解析器 - 训练输入规范

python - 如果使用 range() 的列表中的值为 257 或更大,则 "if i is not value"将被忽略

python - 如何在Python中运行TCL脚本?

python - Gunicorn Django 线程

java - 完全免费的 nlp 解析器?

对其自然语言描述的 SQL 查询

machine-learning - OneVsRestClassifier 的损失函数

python - 从数据中提取特定信息

java - NLTK -> 使用斯坦福依赖分析器 ->