使用 Word2Vec 进行 Twitter 情绪分析

Posted

技术标签:

【中文标题】使用 Word2Vec 进行 Twitter 情绪分析【英文标题】:Twitter sentiment analysis using Word2Vec 【发布时间】:2022-01-10 06:21:40 【问题描述】:

到目前为止,我已经在 R 代码中完成了以下操作。我正在执行 Twitter 情绪分析(正面/负面),我需要使用分类模型,例如:逻辑回归、SVM 等。截至目前,我已经删除了空格、网址、表情符号等。创建一个新列“整洁的推文”和对其进行标记。然后我在条形图上绘制最常见的单词。现在,我想实现 Word2Vec 技术来标记推文并在我的模型中使用它(在 R 中)。但我不知道该怎么做。有人可以帮我吗? csv文件链接:https://drive.google.com/file/d/1ARqEt75G1UcUpfdBtae1yEvurydeE2vr/view?usp=sharing

谢谢!

library(xgboost)
library(readr)
library(stringr)
library(caret)
library(car)
library(tidytext)
library(stringr)
library(tidyr)
library(dplyr)

set.seed(123)
twitter_train<-read.csv("/Users/R/Final Training Data Set-twitter.csv")
text<-twitter_train$tweet
text <- tolower(text)
# Remove mentions, urls, emojis, numbers, punctuations, etc.
text <- gsub("@\\w+", "", text)
text <- gsub("https?://.+", "", text)
text <- gsub("\\d+\\w*\\d*", "", text)
text <- gsub("#\\w+", "", text)
text <- gsub("[^\x01-\x7F]", "", text)
text <- gsub("[[:punct:]]", " ", text)
# Remove spaces and newlines
text <- gsub("\n", " ", text)
text <- gsub("^\\s+", "", text)
text <- gsub("\\s+$", "", text)
text <- gsub("[ |\t]+", " ", text)
#Create new column to store cleaned tweets
twitter_train["fix_text"] <- text
head(twitter_train$fix_text, 10)

# Convert to tidy format
tidy_text <- twitter_train %>%
  select(id,label,fix_text) %>%
  #Tokenize the word from the tweets
  unnest_tokens(input = fix_text, output = word) %>%
  # Remove stop words
  anti_join(stop_words, by="word")

#Plotting most common words in corpus
tidy_text %>% # gives you a bar chart of the most frequent words found in the tweets
  count(word, sort = TRUE) %>%
  top_n(30) %>%
  mutate(word = reorder(word, n)) %>%
  ggplot(aes(x = word, y = n)) +
  geom_col() +
  xlab(NULL) +
  coord_flip() +
  labs(y = "Count",
       x = "Unique words",
       title = "Most frequent words found in the dataset",
       subtitle = "Stop words removed from the list")

【问题讨论】:

请修剪您的代码,以便更容易找到您的问题。请按照以下指南创建minimal reproducible example。 【参考方案1】:

使用 R 包 word2vec 嵌入您的单词,并通过 word2vec::doc2vec http://www.bnosac.be/index.php/blog/100-word2vec-in-r 将这些嵌入聚合到推文级别

或使用 R 包 doc2vec 直接使用段落 2vec 模型 DM/DBOW 嵌入您的文本,并将推文嵌入提供给您的 SVM http://www.bnosac.be/index.php/blog/103-doc2vec-in-r

【讨论】:

以上是关于使用 Word2Vec 进行 Twitter 情绪分析的主要内容,如果未能解决你的问题,请参考以下文章

使用朴素贝叶斯分类的 Twitter 情绪分析仅返回“中性”标签

为 Twitter 情绪分析项目寻找 C# 中的开源朴素贝叶斯分类器 [关闭]

Python——用户评论情绪分析

《面向微博的社会情绪词典构建及情绪分析方法研究》学习笔记

算法集锦(17)|自然语言处理| 比特币市场情绪分析算法

使用文本挖掘技术分析Twitter用户对电影Rangoon的评价