From 423f54d2daa67c02196737f17fc4365df6de76a1 Mon Sep 17 00:00:00 2001 From: Caglar Date: Mon, 11 May 2015 10:21:32 -0400 Subject: [PATCH 1/2] fixed the random number generators. --- code/lstm.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/code/lstm.py b/code/lstm.py index 14f78a02..09eafe2a 100644 --- a/code/lstm.py +++ b/code/lstm.py @@ -17,6 +17,10 @@ datasets = {'imdb': (imdb.load_data, imdb.prepare_data)} +# Set the random number generators' seeds for consistency +SEED = 123 +random.seed(SEED) +numpy.random.seed(SEED) def numpy_floatX(data): return numpy.asarray(data, dtype=config.floatX) @@ -303,7 +307,7 @@ def rmsprop(lr, tparams, grads, x, mask, y, cost): def build_model(tparams, options): - trng = RandomStreams(1234) + trng = RandomStreams(SEED) # Used for dropout. use_noise = theano.shared(numpy_floatX(0.)) @@ -401,7 +405,7 @@ def train_lstm( noise_std=0., use_dropout=True, # if False slightly faster, but worst test error # This frequently need a bigger model. - reload_model="", # Path to a saved model we want to start from. + reload_model=None, # Path to a saved model we want to start from. test_size=-1, # If >0, we keep only this number of test example. ): From 29b167a328a8551f2f888813cd5da4e63d9d4390 Mon Sep 17 00:00:00 2001 From: Caglar Date: Mon, 11 May 2015 11:06:01 -0400 Subject: [PATCH 2/2] converted the code to use numpy random number generator. --- code/lstm.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/code/lstm.py b/code/lstm.py index 09eafe2a..4423840a 100644 --- a/code/lstm.py +++ b/code/lstm.py @@ -3,7 +3,6 @@ ''' from collections import OrderedDict import cPickle as pkl -import random import sys import time @@ -19,7 +18,6 @@ # Set the random number generators' seeds for consistency SEED = 123 -random.seed(SEED) numpy.random.seed(SEED) def numpy_floatX(data): @@ -34,7 +32,7 @@ def get_minibatches_idx(n, minibatch_size, shuffle=False): idx_list = numpy.arange(n, dtype="int32") if shuffle: - random.shuffle(idx_list) + numpy.random.shuffle(idx_list) minibatches = [] minibatch_start = 0 @@ -423,7 +421,7 @@ def train_lstm( # size example. So we must select a random selection of the # examples. idx = numpy.arange(len(test[0])) - random.shuffle(idx) + numpy.random.shuffle(idx) idx = idx[:test_size] test = ([test[0][n] for n in idx], [test[1][n] for n in idx]) @@ -472,6 +470,7 @@ def train_lstm( print "%d train examples" % len(train[0]) print "%d valid examples" % len(valid[0]) print "%d test examples" % len(test[0]) + history_errs = [] best_p = None bad_count = 0 @@ -589,7 +588,6 @@ def train_lstm( if __name__ == '__main__': # See function train for all possible parameter and there definition. train_lstm( - #reload_model="lstm_model.npz", max_epochs=100, test_size=500, )