BioSentVec 嵌入未在 Linux 服务器上加载

问题描述

trial.py 中的 Python 代码

import sent2vec

model_path = 'BioSentVec/BioSentVec_PubMed_MIMICIII-bigram_d700.bin'

model = sent2vec.Sent2vecModel()

try:

    model.load_model(model_path)
except Exception as e:
    print(e)

在命令行运行:

$ python3 trial.py

输出

terminate called after throwing an instance of 'std::bad_alloc'   
what():  std::bad_alloc 
Aborted (core dumped)

BioSentVec 嵌入是 22GB,我有 46GB 可用。基于fasttext的模型。运行 Ubuntu 20.04 LTS。使用 conda 环境 - 在安装一些旧版本的依赖项时遇到问题。 任何帮助嵌入将句子转换为向量的帮助将不胜感激, 谢谢大家。

解决方法

这看起来像是一个错误,可能是由于可寻址内存不足造成的。

请注意,一个 22GB 的磁盘文件可能需要比 22GB 多得多的可用内存来加载 - 因此尝试使用具有更多 RAM 的机器可能会解决问题。

您还应该仔细检查您在本地拥有的模型文件是否没有以任何方式被截断或损坏。有时,这些问题稍后会显示为神秘的加载错误。

(似乎项目 providing that file 没有提供确切的预期大小。所以我使用命令 curl -I "https://ftp.ncbi.nlm.nih.gov/pub/lu/Suppl/BioSentVec/BioSentVec_PubMed_MIMICIII-bigram_d700.bin" 查询网络服务器,它报告:

HTTP/1.1 200 OK
Date: Sat,26 Jun 2021 18:02:19 GMT
Server: Apache
Last-Modified: Sun,21 Oct 2018 15:34:20 GMT
ETag: "53ba885aa-578beded2028f"
Accept-Ranges: bytes
Content-Length: 22475736490
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET,POST,PUT,OPTIONS
Access-Control-Allow-Headers: RANGE,Cache-control,If-None-Match,Content-Type
Access-Control-Expose-Headers: Content-Length,Content-Range,Content-Type
Content-Type: application/octet-stream

因此,鉴于 Content-Length 标头,您应该仔细检查您的本地副本是否正好是 22,475,736,490 字节长。

另一种选择可能是尝试将其再次下载到不同的地方——不同的路径,或另一台具有无可挑剔的互联网连接的机器——只是为了检查两个下载的大小和校验和是否相同。)