对于一个项目,我使用R包wordVectors和函数 train_word2vec() see an example here
我的第一个问题: 此功能需要train_file,它是单个.txt文件(在您的计算机上)。目前,您必须将此文件存储在计算机的特定目录中。但是我的R环境中也有文件(在data.frame中,列为:text(df $ text))。
我想避免读取.txt文件,而是使用带有文本的R data.frame。有解决方法吗?
我的第二个问题: 相同的函数(train_word2vec)具有一个“输出”参数,称为“输出文件的路径”。再说一次,我不想在计算机上放任何东西,那么有没有一种解决方法可以在我的R环境(R脚本)中存储输出模型(比如说“ vec.bin”)?
代码:
library(devtools)
install_github("mukul13/rword2vec")
library(rword2vec)
model=word2vec(train_file = "text8",output_file = "vec.bin",binary=1)
# Instead of "text8" I want to insert a data.frame column (containing text).
# Instead of "vec.bin" I want to have something Like "foo <- vec.bin" in R. So that the output stays within R and not on my PC.
答案 0 :(得分:1)
rword2vec
是word2vec
的瘦包装,这是一个用C编写的程序,希望从训练文件中读取并写入输出文件。例如,请参见此处:https://github.com/mukul13/rword2vec/blob/master/R/word2vec.R#L28。相应的C函数在这里:https://github.com/mukul13/rword2vec/blob/master/src/word2vec.c#L638。无法在那里读取或写入data.frame
。
您是否尝试过使用text2vec作为替代方法?至少乍一看,它看起来更灵活。