【问题标题】:Twitter sentiment analysis using Word2Vec使用 Word2Vec 进行 Twitter 情绪分析
【发布时间】: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")

【问题讨论】:

标签: python r twitter


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-20
    • 1970-01-01
    • 2015-09-23
    • 2012-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多