首页 > 解决方案 > 除了 Keras 和 Spacy,我可以使用 Stanford Core NLP 进行深度学习吗?

问题描述

我正在尝试使用深度学习 (RNN) 对 Twitter 数据进行情感分析。我知道还有其他各种深度学习库,例如 TF、keras、gensim 等,但我想知道是否可以使用 CoreNLP 库执行深度学习。

https://github.com/charlescc9/deep-learning-sentiment-analysis

上面这个人尝试比较深度学习的 gensim、tensorflow 和 core nlp。但是几乎没有任何文档,我无法理解如何运行文件(或)所需的依赖项。请帮帮我。

标签: deep-learningnlpstanford-nlplstm

解决方案


我之前出于同样的原因使用过 RNN,这就是我所做的:

准备

  1. 下载 coreNLP 包。你可以从这里开始
  2. 通过运行安装pycorenlp 包装器pip install pycorenlp
  3. Java>=1.8如果没有安装,请安装。

用法

现在,让我们看看如何使用它:

  1. 将下载的 zip 文件解压到项目目录中
  2. 打开终端并运行以下命令: java -mx5g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -timeout 10000
  3. 现在,服务器localhost:9000默认运行。现在,您可以编写程序了。

这是一个简单的例子:

>>> from pycorenlp import StanfordCoreNLP
>>>
>>> sentence = "NLP is great"
>>> nlp = StanfordCoreNLP('http://localhost:9000')
>>> res = nlp.annotate(sentence, properties={ 'annotators': 'sentiment',
...                                           'outputFormat': 'json',
...                                           'timeout': 10000,})
>>> #you can get the class by:
>>> klass = res["sentences"][0]["sentimentValue"]

推荐阅读