我用这个Keras word-level text generation example作为我自己工作的基础。
当我尝试训练数据时,我在第59行得到 MemoryError :
X = np.zeros((len(sentences), maxlen, len(words)), dtype=np.bool)
作为一个大矩阵用零初始化。 y:
会发生相同的零初始化y = np.zeros((len(sentences), len(words)), dtype=np.bool)
稍后矩阵将被填充(一个热编码):
for i, sentence in enumerate(sentences):
for t, word in enumerate(sentence.split()):
X[i, t, word_indices[word]] = 1
y[i, word_indices[next_words[i]]] = 1
如何使用稀疏矩阵来节省内存并使其可执行?
我看了scipy's sparse matrix,但看起来他们只支持2D矩阵 我也看了Tensorflow's sparse tensor,但我认为它们不支持零初始化以便稍后填充它们(就像我需要的那样)。