【发布时间】:2019-10-09 21:30:11
【问题描述】:
我正在构建一个简单的基于内容的推荐系统。为了以 GPU 加速的方式计算 余弦相似度,我使用了Pytorch。
在从 csr_matrix 创建 tfidf 词汇张量时,它会提示以下 RuntimeErrorr
RuntimeError: [enforce fail at CPUAllocator.cpp:56] posix_memalign(&data, gAlignment, nbytes) == 0. 12 vs 0
我是这样做的:
coo = tfidf_matrix.tocoo()
values = coo.data
indices = np.vstack( (coo.row, coo.col ))
i = torch.LongTensor(indices)
v = torch.FloatTensor(values)
tfidf_matrix_tensor = torch.sparse.FloatTensor(i, v, torch.Size(coo1.shape)).to_dense()
# Prompts the error
我尝试了一个小型测试(tfidf 矩阵大小 = 10,296)数据集,它可以工作。 真实数据集的 tfidf 矩阵大小为 (27639, 226957)
【问题讨论】:
-
这可能是 PyTorch 中的一个错误,最好通过在 github issues 上提问来解决。
标签: python python-3.x pytorch recommendation-engine cosine-similarity