【问题标题】:Apart from Keras and Spacy, can I use Stanford Core NLP for Deep Learning?除了 Keras 和 Spacy,我可以使用 Stanford Core NLP 进行深度学习吗?
【发布时间】:2019-07-10 08:23:05
【问题描述】:

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

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

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

【问题讨论】:

    标签: deep-learning nlp stanford-nlp lstm


    【解决方案1】:

    我之前也因为同样的原因使用过RNN,我就是这样做的:

    准备工作

    1. 下载 coreNLP 包。您可以通过here 进行操作。
    2. 通过运行pip install pycorenlp 安装pycorenlp wrapper
    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"]
    

    【讨论】:

    • CoreNLP (server) 计算的情感,是基于RNN的吗?
    • 我相信是这样,请参阅我们传递给nlp.annotate 方法的properties 字典。在properties 中,我们传递了'annotators': 'sentiment',这是实现Socher 的RNN 的SentimentAnnotator 类。请参阅文档here
    • 是的,这就是 RNN 的实现。该文档提供了一种使用此命令“java -mx8g edu.stanford.nlp.sentiment.SentimentTraining -numHid 25 -trainPath train.txt -devPath dev.txt -train -model model.ser.gz”来训练模型的方法。有没有办法可以使用我的 twitter 数据集来训练这个模型?
    • -trainPath设置为训练目录。它将从该目录加载所有文件并对其进行训练。开发数据使用devPath
    • 什么是开发数据?也感谢您回答我上面的所有问题。还在学习!
    猜你喜欢
    • 1970-01-01
    • 2018-10-25
    • 1970-01-01
    • 2017-01-08
    • 1970-01-01
    • 2021-04-13
    • 2023-04-10
    • 1970-01-01
    • 2020-12-01
    相关资源
    最近更新 更多