【发布时间】:2019-03-02 18:25:49
【问题描述】:
我尝试运行语言建模程序。当我使用文档中包含 15000 句的数据序列时,程序运行正常。但是,当我尝试用更大的数据(大 10 倍)更改数据时,遇到如下错误:
Traceback (most recent call last):
File "<ipython-input-2-aa5ef9098286>", line 1, in <module>
runfile('C:/Users/cerdas/Documents/Bil/Lat/lstm-plato-lm/platolm.py', wdir='C:/Users/cerdas/Documents/Bil/Lat/lstm-plato-lm')
File "C:\Users\cerdas\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
execfile(filename, namespace)
File "C:\Users\cerdas\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/cerdas/Documents/Bil/Lat/lstm-plato-lm/platolm.py", line 35, in <module>
y = to_categorical(y, num_classes=vocab_size)
File "C:\Users\cerdas\Anaconda3\lib\site-packages\keras\utils\np_utils.py", line 30, in to_categorical
categorical = np.zeros((n, num_classes), dtype=np.float32)
MemoryError
这是可疑的错误代码行:
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
还有np.utils
categorical = np.zeros((n, num_classes), dtype=np.float64)
我试图搜索类似问题的解决方案,我发现我必须将categorical_crossentropy 更改为sparse_categorical_crossentropy。我已经这样做了,但是使用相同的回溯仍然是错误的。
谢谢
【问题讨论】:
标签: python numpy memory keras cross-entropy