我尝试使用LSI来生成表示文档的向量。我正在使用Scipy库中的svd包。但是程序抛出了一个内存错误。我的矩阵的大小是100x13057。这对我的8G内存来说是不是太大了?
我在stackflow中搜索了这个问题。有人说我只需要在我的64位操作系统上安装64位Python。(现在,我在64位操作系统上有32位Python )。但是重新安装所有的库太简单了。另一种观点是转换稀疏矩阵。
那么,每个人都对这个问题有想法吗?谢谢!
raw_matrix = []
for text in forest_lsi:
raw_matrix.append( text.get_vector() )
from svd import compute_svd
print("The size of raw matrix: "+str(len(raw_matrix))+" * "+str(len(raw_matrix[0])))
matrix = compute_svd( raw_matrix )Concole中的消息如下所示:
The size of raw matrix: 100 * 13057
Original matrix:
[[1 1 2 ..., 0 0 0]
[0 3 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]
...,
[0 0 0 ..., 0 0 0]
[0 0 1 ..., 0 0 0]
[0 0 2 ..., 1 1 3]]
Traceback (most recent call last):
File "D:\workspace\PyQuEST\src\Practice\baseline_lsi.py", line 93, in <module>
matrix = compute_svd( raw_matrix )
File "D:\workspace\PyQuEST\src\Practice\svd.py", line 12, in compute_svd
U, s, V = linalg.svd( matrix )
File "D:\Program\Python26\lib\site-packages\scipy\linalg\decomp_svd.py", line 79, in svd
full_matrices=full_matrices, overwrite_a = overwrite_a)
MemoryError发布于 2011-12-28 05:04:50
如果您使用的是默认V,那么您的dtype=np.float矩阵将占用大约字节的内存。1.4。我的预感是,对于您的32位Python来说,这太大了。尝试使用32位浮点数,即dtype=np.float32,以将内存使用量减半,或者开始使用scipy.sparse (对于信息检索问题,几乎总是一个好主意)。
https://stackoverflow.com/questions/8649181
复制相似问题