【发布时间】:2020-08-01 10:55:54
【问题描述】:
我有一系列 100.000 多个句子,我想对它们的情感程度进行排名。
我对 NLP 世界很陌生,但这就是我设法开始的方式(改编自 spacy 101)
import spacy
from spacy.matcher import Matcher
matcher = Matcher(nlp.vocab)
def set_sentiment(matcher, doc, i, matches):
doc.sentiment += 0.1
myemotionalwordlist = ['you','superb','great','free']
sentence0 = 'You are a superb great free person'
sentence1 = 'You are a great person'
sentence2 = 'Rocks are made o minerals'
sentences = [sentence0,sentence1,sentence2]
pattern2 = [[{"ORTH": emotionalword, "OP": "+"}] for emotionalword in myemotionalwordlist]
matcher.add("Emotional", set_sentiment, *pattern2) # Match one or more emotional word
for sentence in sentences:
doc = nlp(sentence)
matches = matcher(doc)
for match_id, start, end in matches:
string_id = nlp.vocab.strings[match_id]
span = doc[start:end]
print("Sentiment", doc.sentiment)
myemotionalwordlist 是我手动构建的大约 200 个单词的列表。
我的问题是:
(1-a) 计算情绪词的数量似乎不是最好的方法。有人有更好的方法建议吗?
(1-b) 如果这种方法足够好,关于如何从 wordnet 中提取情感词有什么建议吗?
(2) 升级此问题的最佳方法是什么?我正在考虑将所有句子添加到熊猫数据框中,然后将匹配函数应用于每个句子
提前致谢!
【问题讨论】:
标签: python nlp spacy sentiment-analysis wordnet