代码之家  ›  专栏  ›  技术社区  ›  R overflow

在R中输入和输出,避免使用函数(train_word2vec()-WordVectors)进行写入和读取

  •  0
  • R overflow  · 技术社区  · 6 年前

    对于一个项目,我使用R包wordVectors和函数 see an example here

    我的第一个问题: 此函数需要一个train_文件,它是一个.txt文件(在您的计算机上)。现在,您必须将此文件存储在计算机的特定目录中。但是我的R环境中也有这个文件(在data.frame中,在名为:text(df$text)的列中)。

    我想避免读取.txt文件,而是对文本使用R data.frame。有解决办法吗?

    我的第二个问题:

    代码:

    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.  
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Ralf Stubner    6 年前

    rword2vec 是一个很薄的包装 word2vec 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