标签: stanford-nlp

在python中使用stanford tagger时出错

这是我的代码和错误消息:

>>> from nltk.tag.stanford import StanfordTagger
>>> st = StanfordTagger('bidirection-distsim-wsj-0-18.tagger')

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nltk/tag/stanford.py", line 42, in __init__
    verbose=verbose)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nltk/internals.py", line 597, in find_jar
    raise LookupError('\n\n%s\n%s\n%s' % (div, msg, div))
LookupError: 

===========================================================================
  NLTK was unable to find ! Set the CLASSPATH environment variable.

  For more information, on , see:
    <http://nlp.stanford.edu/software>
===========================================================================
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?我真的想在Python中使用stanford tagger谢谢!

python pos-tagger stanford-nlp

6
推荐指数
1
解决办法
3904
查看次数

如何使用stanford nlp删除停用词

我想使用stanford nlp解析文档并从中删除停用词,所以我的问题是如何使用stanford nlp删除停用词是否有任何api删除它,我找到StopWords类但我不知道如何使用这个,请建议我怎么弄这个?

谢谢

java parsing stop-words stanford-nlp

6
推荐指数
1
解决办法
6488
查看次数

如何在Stanford NER中使用IOB标签?

似乎有一些不同的设置:

iobtags
iobTags
entitySubclassification (IOB1 or IOB2?)
evaluateIOB
Run Code Online (Sandbox Code Playgroud)

我使用哪种设置,如何正确使用?

我试着像这样标记:

1997    B-DATE
volvo   B-BRAND
wia64t  B-MODEL
highway B-TYPE
tractor I-TYPE
Run Code Online (Sandbox Code Playgroud)

但是在训练输出上,似乎认为B-TYPE和I-TYPE是不同的类别.

我正在使用2013-11-12版本.

named-entity-recognition stanford-nlp

6
推荐指数
1
解决办法
6215
查看次数

使用NLP的实体识别和情感分析

所以,这个问题可能有点天真,但我想要问Stackoverflow友好的人不会受伤.

我现在的公司已经在NLP上使用第三方API了一段时间了.我们基本上对一个字符串进行URL编码并将其发送出去,然后他们为我们提取某些实体(我们有一个我们正在查找的实体列表)并返回一个实体:情感的json映射.我们最近决定将这个项目改为内部.

我过去两天一直在研究NLTK,Stanford NLP和lingpipe,并且无法弄清楚我是否正在重新发明这个项目的轮子.

我们已经拥有包含原始非结构化文本的大量表格,以及包含该文本中提取的实体及其情绪的另一个表格.实体是单个单词.例如:

非结构化文本:现在用于床.这不是最好的.

实体:床

情绪:消极

我认为这意味着我们拥有培训数据(非结构化文本)以及实体和情感.现在我如何在其中一个NLP框架上使用此培训数据并获得我们想要的内容?没有线索.我有点步骤,但不确定:

  1. Tokenize句子
  2. 标记单词
  3. 在句子中找到名词(POS标记)
  4. 找出那句话的情绪.

但是,对于我上面提到的情况,这应该是失败的,因为它用2个不同的句子谈论床?

所以问题 - 是否有人知道完成上述任务的最佳框架是什么,以及相同的任何教程(注意:我不是要求解决方案).如果您之前已经完成了这些工作,这个任务是否太大而无法承担?我查了一些商业API,但使用起来非常昂贵(我们是一个小小的创业公司).

谢谢stackoverflow!

nlp nltk stanford-nlp sentiment-analysis lingpipe

6
推荐指数
1
解决办法
1745
查看次数

使用NLTK简化法国POS标签集

如何简化斯坦福法国POS标签器返回的部分语音标签?将英文句子读入NLTK相当容易,找到每个单词的词性,然后使用map_tag()来简化标签集:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import os
from nltk.tag.stanford import POSTagger
from nltk.tokenize import word_tokenize
from nltk.tag import map_tag

#set java_home path from within script. Run os.getenv("JAVA_HOME") to test java_home
os.environ["JAVA_HOME"] = "C:\\Program Files\\Java\\jdk1.7.0_25\\bin"

english = u"the whole earth swarms with living beings, every plant, every grain and leaf, supports the life of thousands."

path_to_english_model = "C:\\Text\\Professional\\Digital Humanities\\Packages and Tools\\Stanford Packages\\stanford-postagger-full-2014-08-27\\stanford-postagger-full-2014-08-27\\models\\english-bidirectional-distsim.tagger"
path_to_jar = "C:\\Text\\Professional\\Digital Humanities\\Packages and Tools\\Stanford Packages\\stanford-postagger-full-2014-08-27\\stanford-postagger-full-2014-08-27\\stanford-postagger.jar"

#define english and french taggers
english_tagger = POSTagger(path_to_english_model, path_to_jar, encoding="utf-8") …
Run Code Online (Sandbox Code Playgroud)

python syntax nlp nltk stanford-nlp

6
推荐指数
1
解决办法
2832
查看次数

如何培养一个以pos-tag序列为特征的朴素贝叶斯分类器?

我有两类句子.每个都有相当明显的pos标签序列.如何训练以POS-Tag序列为特征的Naive-Bayes分类器?Stanford CoreNLP/NLTK(Java或Python)是否提供了使用pos-tag作为特征构建分类器的任何方法?我知道在python中NaiveBayesClassifier允许构建一个NB分类器,但它使用contains-a-wordas作为功能,但它可以扩展为使用pos-tag-sequence作为功能吗?

machine-learning nltk stanford-nlp text-classification naivebayes

6
推荐指数
1
解决办法
2100
查看次数

使用Stanford NLP进行文本标记化:过滤不需要的单词和字符

Stanford NLP在分类工具中用于字符串标记化.我想唯一有意义的话,但我得到的非字标记(如---,>,.等),而不是重要的话像am,is,to(停用词).有人知道解决这个问题的方法吗?

java machine-learning tokenize stanford-nlp

6
推荐指数
2
解决办法
6240
查看次数

使用Stanford CoreNLP(3.5.2)进行并发处理

我在同时注释多个句子时面临并发问题.我不清楚我是做错了还是CoreNLP中有错误.

我的目标是使用并行运行的多个线程使用管道"tokenize,ssplit,pos,lemma,ner,parse,dcoref"来注释句子.每个线程分配自己的StanfordCoreNLP实例,然后将其用于注释.

问题是在某些时候抛出异常:

java.util.ConcurrentModificationException
	at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
	at java.util.ArrayList$Itr.next(ArrayList.java:851)
	at java.util.Collections$UnmodifiableCollection$1.next(Collections.java:1042)
	at edu.stanford.nlp.trees.GrammaticalStructure.analyzeNode(GrammaticalStructure.java:463)
	at edu.stanford.nlp.trees.GrammaticalStructure.analyzeNode(GrammaticalStructure.java:488)
	at edu.stanford.nlp.trees.GrammaticalStructure.analyzeNode(GrammaticalStructure.java:488)
	at edu.stanford.nlp.trees.GrammaticalStructure.analyzeNode(GrammaticalStructure.java:488)
	at edu.stanford.nlp.trees.GrammaticalStructure.analyzeNode(GrammaticalStructure.java:488)
	at edu.stanford.nlp.trees.GrammaticalStructure.analyzeNode(GrammaticalStructure.java:488)
	at edu.stanford.nlp.trees.GrammaticalStructure.analyzeNode(GrammaticalStructure.java:488)
	at edu.stanford.nlp.trees.GrammaticalStructure.analyzeNode(GrammaticalStructure.java:488)
	at edu.stanford.nlp.trees.GrammaticalStructure.analyzeNode(GrammaticalStructure.java:488)
	at edu.stanford.nlp.trees.GrammaticalStructure.analyzeNode(GrammaticalStructure.java:488)
	at edu.stanford.nlp.trees.GrammaticalStructure.analyzeNode(GrammaticalStructure.java:488)
	at edu.stanford.nlp.trees.GrammaticalStructure.<init>(GrammaticalStructure.java:201)
	at edu.stanford.nlp.trees.EnglishGrammaticalStructure.<init>(EnglishGrammaticalStructure.java:89)
	at edu.stanford.nlp.semgraph.SemanticGraphFactory.makeFromTree(SemanticGraphFactory.java:139)
	at edu.stanford.nlp.pipeline.DeterministicCorefAnnotator.annotate(DeterministicCorefAnnotator.java:89)
	at edu.stanford.nlp.pipeline.AnnotationPipeline.annotate(AnnotationPipeline.java:68)
	at edu.stanford.nlp.pipeline.StanfordCoreNLP.annotate(StanfordCoreNLP.java:412)
Run Code Online (Sandbox Code Playgroud)

我附上了一个应用程序的示例代码,该代码在我的Core i3 370M笔记本电脑(Win 7 64位,Java 1.8.0.45 64位)上大约20秒内重现问题.此应用程序读取识别文本蕴涵(RTE)语料库的XML文件,然后使用标准Java并发类同时解析所有句子.需要将本地RTE XML文件的路径作为命令行参数提供.在我的测试中,我使用了公开的XML文件:http: //www.nist.gov/tac/data/RTE/RTE3-DEV-FINAL.tar.gz

package semante.parser.stanford.server;

import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import …
Run Code Online (Sandbox Code Playgroud)

concurrency multithreading stanford-nlp

6
推荐指数
1
解决办法
3346
查看次数

加快CoreNLP情绪分析

谁能想到加快我的CoreNLP情绪分析的方法(下图)?

我在服务器启动时初始化CoreNLP管道:

// Initialize the CoreNLP text processing pipeline
public static Properties props = new Properties();
public static StanfordCoreNLP pipeline;

// Set text processing pipeline's annotators
props.setProperty("annotators", "tokenize, ssplit, pos, parse, sentiment");
// Use Shift-Reduce Constituency Parsing (O(n),
// http://nlp.stanford.edu/software/srparser.shtml) vs CoreNLP's default
// Probabilistic Context-Free Grammar Parsing (O(n^3))
props.setProperty("parse.model", "edu/stanford/nlp/models/srparser/englishSR.ser.gz");
pipeline = new StanfordCoreNLP(props);
Run Code Online (Sandbox Code Playgroud)

然后我从我的控制器调用管道:

String text = 'A sample string.'
Annotation annotation = pipeline.process(text);
List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
for (CoreMap sentence : sentences) {
    Tree tree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class); …
Run Code Online (Sandbox Code Playgroud)

java optimization performance stanford-nlp sentiment-analysis

6
推荐指数
1
解决办法
526
查看次数

如何在Windows上设置Stanford CoreNLP服务器以返回文本情绪

我试图在Windows上使用Stanford CoreNLP设置本地服务器,以计算超过1M文章和视频文本的情绪分数.我不懂Java,所以我需要一些帮助.

我成功安装了Stanford CoreNLP 3.6.0,我运行的服务器运行:

java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer
Run Code Online (Sandbox Code Playgroud)

从我的其他计算机运行此http帖子工作,我收到预期的响应(xxx.xxx.xxx.xxx是服务器的IP地址):

wget --post-data 'the quick brown fox jumped over the lazy dog' 'xxx.xxx.xxx.xxx:9000/?properties={"tokenize.whitespace": "true", "annotators": "tokenize,ssplit,pos,lemma,parse", "outputFormat": "json"}' -O -
Run Code Online (Sandbox Code Playgroud)

但是,回复并不包含情绪.显而易见的解决方案是添加注释器:

wget --post-data 'the quick brown fox jumped over the lazy dog' 'xxx.xxx.xxx.xxx:9000/?properties={"tokenize.whitespace": "true", "annotators": "tokenize,ssplit,pos,lemma,parse,sentiment", "outputFormat": "json"}' -O -
Run Code Online (Sandbox Code Playgroud)

但是,在服务器端,我收到此错误:

java.lang.IllegalArgumentException: Unknown annotator: sentiment
at edu.stanford.nlp.pipeline.StanfordCoreNLP.ensurePrerequisiteAnnotators(StanfordCoreNLP.java:281)
at edu.stanford.nlp.pipeline.StanfordCoreNLPServer$CoreNLPHandler.getProperties(StanfordCoreNLPServer.java:476)
at edu.stanford.nlp.pipeline.StanfordCoreNLP$CoreNLPHandler.handle(StanfordCoreNLPServer.java:350)
at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
at sun.net.httpserver.AuthFilter.doFilter(Unknown Source)
at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(Unknown Source)
at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
at sun.net.httpserver.ServerImpl$Exchange.run(Unknown Source)
at …
Run Code Online (Sandbox Code Playgroud)

java stanford-nlp sentiment-analysis server

6
推荐指数
1
解决办法
2877
查看次数