【发布时间】:2017-02-03 14:38:59
【问题描述】:
我使用 text2vec 从包含许多行业特定行话的专有文本数据语料库生成自定义词嵌入(因此,像谷歌提供的那些库存嵌入将不起作用)。类比效果很好,但我很难应用嵌入来评估新数据。我想使用我已经训练过的嵌入来理解新数据中的关系。我正在使用的方法(如下所述)看起来很复杂,而且速度很慢。有更好的方法吗?也许我只是错过了一些已经内置在包中的东西?
这是我的方法(鉴于我使用的是专有数据源,我可以生成最接近可重现代码的方法):
d = 包含新数据的列表。每个元素都是类字符
vecs = 从 text2vec 的 glove 实现中获得的词向量化
new_vecs <- sapply(d, function(y){
it <- itoken(word_tokenizer(y), progressbar=FALSE) # for each statement, create an iterator punctuation
voc <- create_vocabulary(it, stopwords= tm::stopwords()) # for each document, create a vocab
vecs[rownames(vecs) %in% voc$vocab$terms, , drop=FALSE] %>% # subset vecs for the words in the new document, then
colMeans # find the average vector for each document
}) %>% t # close y function and sapply, then transpose to return matrix w/ one row for each statement
对于我的用例,我需要将每个文档的结果分开,因此任何涉及将 d 的元素粘贴在一起的操作都行不通,但肯定有比我拼凑的更好的方法.我觉得我一定遗漏了一些相当明显的东西。
任何帮助将不胜感激。
【问题讨论】: