【问题标题】:Stanford NLP Sentiment - how to check if a word is recognized, is in the vocabulary?Stanford NLP Sentiment - 如何检查一个单词是否被识别,是否在词汇表中?
【发布时间】:2014-11-27 14:37:00
【问题描述】:

如果一个单词被斯坦福 NLP Sentiment 识别,是否有一个函数返回 true,否则返回 false?

例如,如果我想找到句子的情绪: “因为BBB,我喜欢AAA。” 短语 (AAA) 和 (BBB) 都不会被识别,因此会得到相同的短语向量(这会影响结果)。 我想避免这种情况。

【问题讨论】:

    标签: dictionary stanford-nlp words vocabulary


    【解决方案1】:

    如果你有一个 SentimentModel 实例,你可以检查它的公共成员 wordVectors(不知道为什么这是公开的,但我想那是另一回事..)。

    SentimentModel model = SentimentModel.loadSerialized("edu/stanford/nlp/models/sentiment/sentiment.ser.gz");
    boolean knownWord = model.wordVectors.containsKey("foo");
    

    【讨论】:

    • 鉴于我有一个应该以某种方式包含它的 StanfordCoreNLP 对象,你知道我该从谁那里得到 SentimentModel 对象吗?
    • 据我在代码中看到的,无法直接从StanfordCoreNLP 访问模型实例(成员可见性问题)。但是您可以使用默认模型配置实例化您自己的 SentimentModel - 请参阅我更新的答案。
    • 非常感谢。也应该是: boolean knownWord = model.wordVectors.containsKey("foo");
    猜你喜欢
    • 1970-01-01
    • 2021-04-26
    • 2017-12-28
    • 2015-11-17
    • 2019-01-06
    • 1970-01-01
    • 2013-05-24
    • 1970-01-01
    • 2013-02-09
    相关资源
    最近更新 更多