3
3
'''
4
4
from collections import OrderedDict
5
5
import cPickle as pkl
6
- import random
7
6
import sys
8
7
import time
9
8
17
16
18
17
datasets = {'imdb' : (imdb .load_data , imdb .prepare_data )}
19
18
19
+ # Set the random number generators' seeds for consistency
20
+ SEED = 123
21
+ numpy .random .seed (SEED )
20
22
21
23
def numpy_floatX (data ):
22
24
return numpy .asarray (data , dtype = config .floatX )
@@ -30,7 +32,7 @@ def get_minibatches_idx(n, minibatch_size, shuffle=False):
30
32
idx_list = numpy .arange (n , dtype = "int32" )
31
33
32
34
if shuffle :
33
- random .shuffle (idx_list )
35
+ numpy . random .shuffle (idx_list )
34
36
35
37
minibatches = []
36
38
minibatch_start = 0
@@ -303,7 +305,7 @@ def rmsprop(lr, tparams, grads, x, mask, y, cost):
303
305
304
306
305
307
def build_model (tparams , options ):
306
- trng = RandomStreams (1234 )
308
+ trng = RandomStreams (SEED )
307
309
308
310
# Used for dropout.
309
311
use_noise = theano .shared (numpy_floatX (0. ))
@@ -401,7 +403,7 @@ def train_lstm(
401
403
noise_std = 0. ,
402
404
use_dropout = True , # if False slightly faster, but worst test error
403
405
# This frequently need a bigger model.
404
- reload_model = "" , # Path to a saved model we want to start from.
406
+ reload_model = None , # Path to a saved model we want to start from.
405
407
test_size = - 1 , # If >0, we keep only this number of test example.
406
408
):
407
409
@@ -419,7 +421,7 @@ def train_lstm(
419
421
# size example. So we must select a random selection of the
420
422
# examples.
421
423
idx = numpy .arange (len (test [0 ]))
422
- random .shuffle (idx )
424
+ numpy . random .shuffle (idx )
423
425
idx = idx [:test_size ]
424
426
test = ([test [0 ][n ] for n in idx ], [test [1 ][n ] for n in idx ])
425
427
@@ -468,6 +470,7 @@ def train_lstm(
468
470
print "%d train examples" % len (train [0 ])
469
471
print "%d valid examples" % len (valid [0 ])
470
472
print "%d test examples" % len (test [0 ])
473
+
471
474
history_errs = []
472
475
best_p = None
473
476
bad_count = 0
@@ -585,7 +588,6 @@ def train_lstm(
585
588
if __name__ == '__main__' :
586
589
# See function train for all possible parameter and there definition.
587
590
train_lstm (
588
- #reload_model="lstm_model.npz",
589
591
max_epochs = 100 ,
590
592
test_size = 500 ,
591
593
)
0 commit comments