I am trying to follow this tutorial to learn a bit about deep learning with keras, however I keep getting MemoryError. Can you please point out what is causing it and how to take care of it?
Here is the code:
import numpy as np
from keras import models, regularizers, layers
from keras.datasets import imdb
(train_data, train_labels), (test_data, test_labels) = imdb.load_data(num_words=10000)
def vectorize_sequences(sequences, dimension=10000):
results = np.zeros((len(sequences), dimension))
for i, sequence in enumerate(sequences):
results[i, sequence] = 1.
return results
x_train = vectorize_sequences(train_data)
Here is the traceback (line number doesn't match the line number from the code mentioned above)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/home/uttam/pycharm-2018.2.4/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "/home/uttam/pycharm-2018.2.4/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/home/uttam/PycharmProjects/IMDB/imdb.py", line 33, in <module>
x_train = vectorize_sequences(train_data)
File "/home/uttam/PycharmProjects/IMDB/imdb.py", line 27, in vectorize_sequences
results = np.zeros((len(sequences), dimension))
MemoryError
x_train = vectorize_sequences(train_data)
is irrelevant to the problem (it is never executed) - I am removing it, and keep it in mind for the future... – Emma