目前我正在使用文本挖掘,其中包括使用开源工具 R 进行情感识别和分配相应的业务类别。我发现这两个文档在一定程度上帮助了我:
我的方法是标记文本,然后查找情绪和业务类别。为此,我需要用于情感挖掘的正面和负面库以及包含单词和类别的类别文件。我能够得到正面和负面的词,但无法获得分类库。
- 我在哪里可以获得分类库?
- 上述方法是否合适?有一个更好的方法吗?
目前我正在使用文本挖掘,其中包括使用开源工具 R 进行情感识别和分配相应的业务类别。我发现这两个文档在一定程度上帮助了我:
我的方法是标记文本,然后查找情绪和业务类别。为此,我需要用于情感挖掘的正面和负面库以及包含单词和类别的类别文件。我能够得到正面和负面的词,但无法获得分类库。
Jeffrey Breen 提到的一种解决方案是使用Lu and Hiu 的 lexicon。他还在 Twitter 上提供了一个很酷的情感挖掘教程。
几种选择
1)监督学习:理想情况下,您希望在数据中包含文本和标签,其中标签是指您感兴趣的类别。为此,您需要手动标记数据。然后,您可以训练统计/机器学习算法,以便对您标记的类别进行分类。为此,R 中的一个简单方法是使用text2vec
andglmnet
包。
2)无监督学习:如果您不愿意标记数据,则可以使用统计模型来查找主题,这称为潜在狄利克雷分配。它也受 支持text2vec
,还有其他软件包,例如topicmodels
.
3)迁移学习:最后,另一种选择是迁移学习。这个想法是您从另一个问题中获取标记数据,训练分类器并使用模型对数据进行预测。问题是查找同一域的数据...
4)使用字典(hack):以下是我写的原始答案,它使用正负单词“字典”的查找表。我现在要说这个选项是最后一个资源,它有点像黑客,因为它太宽泛了。我认为现在有一些包可以实现这一点。
编辑
下面是我之前的回答。
我使用Jeffrey 的函数通过“查找”方法计算分数。
我制作了阿根廷政客的腐败指数。所以说他们腐败的人越多,得分就越高。
对于我拥有的数据,因为推文是西班牙语,我只是写了一个更符合问题需求的小字典。我想这取决于您要分析的内容。
除了这种方法,还有更复杂的方法。我认为有一个关于 NLP 的 coursera 课程。
这是另一个资源: https ://sites.google.com/site/miningtwitter/basics/text-mining 它说由于 twitter API 的变化而被弃用,但是 twitteR 包的作者将该包适应了新的 API。所以你需要首先安装更新的包,也许是它的源版本。这是作者的网页。_http://geoffjentry.hexdump.org/ 需要后者以便在拨打超过 100 条推文时不会得到重复的推文。
杰弗里的功能:
score.sentiment = function(sentences, pos.words, neg.words, .progress='none')
{
require(plyr)
require(stringr)
# we got a vector of sentences. plyr will handle a list
# or a vector as an "l" for us
# we want a simple array ("a") of scores back, so we use
# "l" + "a" + "ply" = "laply":
scores = laply(sentences, function(sentence, pos.words, neg.words) {
# clean up sentences with R's regex-driven global substitute, gsub():
sentence = gsub('[[:punct:]]', '', sentence)
sentence = gsub('[[:cntrl:]]', '', sentence)
sentence = gsub('\\d+', '', sentence)
# and convert to lower case:
sentence = tolower(sentence)
# split into words. str_split is in the stringr package
word.list = str_split(sentence, '\\s+')
# sometimes a list() is one level of hierarchy too much
words = unlist(word.list)
# compare our words to the dictionaries of positive & negative terms
pos.matches = match(words, pos.words)
neg.matches = match(words, neg.words)
# match() returns the position of the matched term or NA
# we just want a TRUE/FALSE:
pos.matches = !is.na(pos.matches)
neg.matches = !is.na(neg.matches)
# and conveniently enough, TRUE/FALSE will be treated as 1/0 by sum():
score = sum(pos.matches) - sum(neg.matches)
return(score)
}, pos.words, neg.words, .progress=.progress )
scores.df = data.frame(score=scores, text=sentences)
return(scores.df)
}