尝试使用documentation和here中的text2vec小插图来为某些推文创建单词嵌入:
head(twtdf$Tweet.content)
[1] "$NFLX $GS $INTC $YHOO $LVS\n$MSFT $HOG $QCOM $LUV $UAL\n$MLNX $UA $BIIB $GOOGL $GM $V\n$SKX $GE $CAT $MCD $AAL $SBUX"
[2] "Good news frequent fliers. @AmericanAir says lower fares will be here for awhile"
[3] "Wall St. closing out the week with more earnings. What to watch:\n▶︎ $MCD\n▶︎ $AAL\n▶︎ $CAT\n"
[4] "Barrons loves $AAL at low multiple bc it's \"insanely profitable\". Someone tell them how cycles+ multiples work."
[5] "These airlines are now offering in-flight Wi-Fi $DAL $AAL"
几乎遵循指南:
library(text2vec)
require(text2vec)
twtdf <- read.csv("tweets.csv",header=T, stringsAsFactors = F)
twtdf$ID <- seq.int(nrow(twtdf))
tokens = twtdf$Tweet.content %>% tolower %>% word_tokenizer
length(tokens)
it = itoken(tokens)
# create vocabulary
v = create_vocabulary(it) %>%
prune_vocabulary(term_count_min = 5)
# create co-occurrence vectorizer
vectorizer = vocab_vectorizer(v, grow_dtm = F, skip_grams_window = 5L)
#dtm <- create_dtm(it, vectorizer, grow_dtm = R)
it = itoken(tokens)
tcm = create_tcm(it, vectorizer)
glove_model = glove(tcm, word_vectors_size = 50, vocabulary = v, x_max = 10, learning_rate = .2)
fit(tcm, glove_model, n_iter = 15)
#when this was executed, R couldn't find the function
#fit <- GloVe(tcm = tcm, word_vectors_size = 50, x_max = 10, learning_rate = 0.2, num_iters = 15)
但是,每当我执行glove_model
时,都会收到以下错误:
Error in .subset2(public_bind_env, "initialize")(...) :
unused argument (grain_size = 100000)
In addition: Warning message:
'glove' is deprecated.
Use 'GloVe' instead.
*我确实尝试使用GloVe
代替,但我收到了R无法重新找到text2vec软件包并require
找不到该函数的错误。
要检查以确保我的数据没有某种格式问题,我尝试使用movie_review
数据运行代码并遇到同样的问题。为了彻底,我还尝试指定grain_size
参数,但得到相同的错误。我检查了Git存储库上的问题,并没有在此网站或互联网查询中看到任何内容或任何内容。
其他人遇到这个问题还是新人问题?
答案 0 :(得分:1)
只需对模型使用正确的构造函数:glove = GlobalVectors$new(word_vectors_size = 50, vocabulary = vocab, x_max = 10)
glove()
是旧版程序包中的旧版本。
答案 1 :(得分:0)
显然GlobalVectors
构造函数又被更改了,现在直接从TCM获取词汇信息了吗?
glove = GlobalVectors$new(rank = 50, x_max = 10)
wv_main = glove$fit_transform(tcm, n_iter = 10, convergence_tol = 0.01, n_threads = 8)