I've wrapped some code that can run out of memory with a try/except block. However, though a MemoryError is generated, it is not caught.
I have the following code:
while True:
try:
self.create_indexed_vocab( vocab )
self.reset_weights()
break;
except MemoryError:
# Stuff to reduce size of vocabulary
self.vocab, self.index2word = None, None
self.syn0, self.syn1 = None, None
self.min_count += 1
logger.info( ...format string here... )
I get the following Traceback:
File "./make_model_tagged_wmt11.py", line 39, in <module>
model.build_vocab(sentences)
File "/root/CustomCompiledSoftware/gensim/gensim/models/word2vec.py", line 236, in build_vocab
self.reset_weights()
File "/root/CustomCompiledSoftware/gensim/gensim/models/word2vec.py", line 347, in reset_weights
self.syn0 += (random.rand(len(self.vocab), self.layer1_size) - 0.5) / self.layer1_size
File "mtrand.pyx", line 1044, in mtrand.RandomState.rand (numpy/random/mtrand/mtrand.c:6523)
File "mtrand.pyx", line 760, in mtrand.RandomState.random_sample (numpy/random/mtrand/mtrand.c:5713)
File "mtrand.pyx", line 137, in mtrand.cont0_array (numpy/random/mtrand/mtrand.c:1300)
MemoryError
I'm running Python 2.7.3 under Ubuntu 12.04
The reset_weights line self.syn0 is exactly the line I am expecting to raise the exception (it allocates a big array). The puzzling thing is that I can't catch the memory error and do things that will make the array size smaller.
Are there special circumstances that result in the MemoryError being unable to be caught?
vocabin your call tocreate_indexed_vocabsupposed to beself.vocab? And, to @DannyElly's point, perhaps there's a call toreset_weightshidden in a the call to create_indexed_vocab? That likely wouldn't matter here, since it's reporting a MemoryError...self.reset_weights()) and see only the before print. this is the best that I can help. I know I'm suggesting trivial and stupid pointers but we are all humans and sometimes we are missing obvious things. good luck to u!