标签: stanford-nlp

Stanford CoreNLP Annotators线程安全吗?

斯坦福CoreNLP的网站

http://nlp.stanford.edu/software/corenlp.shtml

列出了几十个像魅力一样工作的注释器.我想使用Annotators的实例来处理多个线程的常见任务(词形还原,标记,解析).例如,将大量(GB文本)的处理拆分为线程或提供Web服务.

过去有一些讨论引用了LocalThreads,根据我的理解,它使用每个线程的一个Annotator实例(从而避免了线程安全方面的问题).这是一个选项,但这样所有模型文件和资源也必须加载n次.

Annotators(或其中一些)是否可以使用线程安全?我在讨论,文档或常见问题中找不到任何结论性/官方性的内容.

java multithreading thread-safety stanford-nlp

7
推荐指数
1
解决办法
1737
查看次数

在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
查看次数

使用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
查看次数

如何安装和调用Stanford NERTagger?

我想在python环境中使用NLTK接口来获取Stanford NER , nltk.tag.stanford.NERTagger.

from nltk.tag.stanford import NERTagger
st = NERTagger('/usr/share/stanford-ner/classifiers/all.3class.distsim.crf.ser.gz',
               '/usr/share/stanford-ner/stanford-ner.jar') 
st.tag('Rami Eid is studying at Stony Brook University in NY'.split()) 
Run Code Online (Sandbox Code Playgroud)

我应该得到输出:

[('Rami', 'PERSON'), ('Eid', 'PERSON'), ('is', 'O'), ('studying', 'O'),
('at', 'O'), ('Stony', 'ORGANIZATION'), ('Brook', 'ORGANIZATION'),
('University', 'ORGANIZATION'), ('in', 'O'), ('NY', 'LOCATION')]
Run Code Online (Sandbox Code Playgroud)

我已根据NLTK网站中描述的程序安装了NLTK.但是,我根本找不到/ usr/share/stanford-ner.我在哪里以及如何找到整个包并将其安装在我的目录中.

python nlp nltk stanford-nlp

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

使用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 NER tagger NLTK(python)与JAVA的差异

我使用python和java来运行斯坦福NER标记器,但我看到结果的差异.

例如,当我输入句子"参与使用ERwin作为主要软件的数据建模的所有方面.",

JAVA结果:

"ERwin": "PERSON"
Run Code Online (Sandbox Code Playgroud)

Python结果:

In [6]: NERTagger.tag("Involved in all aspects of data modeling using ERwin as the primary software for this.".split())
Out [6]:[(u'Involved', u'O'),
 (u'in', u'O'),
 (u'all', u'O'),
 (u'aspects', u'O'),
 (u'of', u'O'),
 (u'data', u'O'),
 (u'modeling', u'O'),
 (u'using', u'O'),
 (u'ERwin', u'O'),
 (u'as', u'O'),
 (u'the', u'O'),
 (u'primary', u'O'),
 (u'software', u'O'),
 (u'for', u'O'),
 (u'this.', u'O')]
Run Code Online (Sandbox Code Playgroud)

Python nltk包装器无法将"ERwin"作为PERSON捕获.

这里有趣的是Python和Java使用2015-04-20发布的相同训练数据(english.all.3class.caseless.distsim.crf.ser.gz).

我的最终目标是让python以与Java相同的方式工作.

我在nltk.tag中查看StanfordNERTagger,看看有什么我可以修改的.下面是包装代码:

class StanfordNERTagger(StanfordTagger):
"""
A class for Named-Entity Tagging with Stanford Tagger. The input is the paths to:

- a model trained …
Run Code Online (Sandbox Code Playgroud)

python nlp named-entity-recognition nltk stanford-nlp

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

如何在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
查看次数

如何使用 NLP 库从句子中提取谓词和主语?

我想从一个句子中找到谓词和主语Natural Language Processing Libraries。这种技术在世界上NLP是否有任何名称或有什么方法可以做到这一点?

例子:他喜欢孩子。结果:(他,喜欢孩子)

nlp nltk stanford-nlp opennlp

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