2

尝试通过文档中的 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.

*我确实尝试过使用,但我得到了错误,尽管重新安装了 text2vec 包并ing 它GloVe,但 R 找不到该函数。require

为了检查以确保我的数据不是某种格式问题,我尝试使用数据运行代码movie_review并遇到同样的问题。为了彻底起见,我还尝试指定grain_size参数,但得到相同的错误。我检查了 Git 存储库上的问题,在此站点或互联网查询中没有看到任何内容。

其他人遇到这个还是新人的问题?

4

2 回答 2

3

显然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)
于 2020-06-29T15:29:02.857 回答
1

只需为模型使用正确的构造函数:glove = GlobalVectors$new(word_vectors_size = 50, vocabulary = vocab, x_max = 10)

glove()是非常旧的软件包版本中的旧版本。

于 2017-04-12T05:36:37.333 回答