You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在R中使用word2vec加载GoogleNews预训练模型报错求助

解决R中加载GoogleNews word2vec模型提示文件为空的问题

核心解决方案:指定文件类型为二进制

你的代码未明确指定文件是二进制格式,read.word2vec默认按文本格式读取,无法识别二进制的GoogleNews模型文件,因此报错。修改代码如下:

library(word2vec)
# 添加type = "bin"参数指定二进制格式
google_emb <- read.word2vec(
  file = "C:\\Users\\my_name\\Documents\\Model\\GoogleNews-vectors-negative300.bin",
  type = "bin",
  normalize = TRUE
)

其他辅助排查点(若上述方案无效)

  • 使用file.path构建路径,避免手动转义错误:
    model_path <- file.path("C:", "Users", "my_name", "Documents", "Model", "GoogleNews-vectors-negative300.bin")
    google_emb <- read.word2vec(file = model_path, type = "bin", normalize = TRUE)
    
  • 确认R的内存分配足够:3.4GB的模型需要足够内存支持,可通过memory.limit()查看当前内存限制,若不足可通过memory.limit(size = 8192)调整(单位为MB)。

内容的提问来源于stack exchange,提问作者Sheesh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 06:52:24