试图通过文档和这里中的文档小插曲来为一些tweet创建单词嵌入:
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
,但我得到的错误是,尽管重新安装了text2vec包并对其进行了require
,但R还是找不到这个函数。
为了确保我的数据不是某种格式问题,我尝试使用movie_review
数据运行代码,并遇到了同样的问题。为了彻底起见,我还尝试指定grain_size
参数,但是得到了相同的错误。我检查了Git存储库上的问题,没有在这个站点上看到任何东西,也没有在互联网查询中看到任何东西。
还有其他人遇到这个问题或者是一个新的人的问题吗?
发布于 2017-04-11 21:36:37
只需为模型使用正确的构造函数:glove = GlobalVectors$new(word_vectors_size = 50, vocabulary = vocab, x_max = 10)
glove()
是从非常旧的包版本中产生的旧版本。
发布于 2020-06-29 07:29:02
显然,GlobalVectors
构造器又一次改变了,现在直接从中医那里获取词汇信息?
glove = GlobalVectors$new(rank = 50, x_max = 10)
wv_main = glove$fit_transform(tcm, n_iter = 10, convergence_tol = 0.01, n_threads = 8)
https://stackoverflow.com/questions/43343820
复制相似问题