Python 使用空格的句子情感得分
我有一系列超过10万个句子,我想对它们的情绪进行排名 我对NLP的世界还很陌生,但我就是这样开始的(改编自) MyMotionalWordList是我手工创建的大约200个单词的列表 我的问题是: (1-a)计算情感词语的数量似乎不是最好的方法。有人有没有更好的方法 (1-b)如果这种方法足够好,有没有关于如何从wordnet中提取情感词语的建议 (2) 升级的最好方法是什么?我正在考虑将所有句子添加到pandas数据框中,然后将match函数应用到每个句子中Python 使用空格的句子情感得分,python,nlp,spacy,sentiment-analysis,wordnet,Python,Nlp,Spacy,Sentiment Analysis,Wordnet,我有一系列超过10万个句子,我想对它们的情绪进行排名 我对NLP的世界还很陌生,但我就是这样开始的(改编自) MyMotionalWordList是我手工创建的大约200个单词的列表 我的问题是: (1-a)计算情感词语的数量似乎不是最好的方法。有人有没有更好的方法 (1-b)如果这种方法足够好,有没有关于如何从wordnet中提取情感词语的建议 (2) 升级的最好方法是什么?我正在考虑将所有句子添加到pandas数据框中,然后将match函数应用到每个句子中 提前谢谢 主要有两种方法: 你已
提前谢谢 主要有两种方法:
- 你已经开始了,这是一个情感词汇的列表,并计算它们出现的频率 举例说明你认为情感句子和什么是无感情的句子到机器学习模型,并让它解决这个问题。
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)