roo*_*m13 6 python recommendation-engine python-3.x cosine-similarity pytorch
我正在构建一个基于内容的简单推荐系统。为了以GPU加速的方式计算余弦相似度,我使用Pytorch
。
在从中创建tfidf词汇张量时csr_matrix
,它会提示以下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
Run Code Online (Sandbox Code Playgroud)
我尝试了一个小的测试(tfidf矩阵大小= 10,296)数据集,它可以工作。实际数据集中的tfidf矩阵大小为(27639,226957)
归档时间: |
|
查看次数: |
2623 次 |
最近记录: |