在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
相关产品推荐
相关产品推荐

