GeezerVison is showing github.com — converted the code to use numpy random number generator. · mpage/DeepLearningTutorials@29b167a
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: code/lstm.py +3-5Lines changed: 3 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
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 |
|
|
19 | 18 |
|
20 | 19 | # Set the random number generators' seeds for consistency |
21 | 20 | SEED = 123 |
22 | | -random.seed(SEED) |
23 | 21 | numpy.random.seed(SEED) |
24 | 22 |
|
25 | 23 | def numpy_floatX(data): |
@@ -34,7 +32,7 @@ def get_minibatches_idx(n, minibatch_size, shuffle=False): |
34 | 32 | idx_list = numpy.arange(n, dtype="int32") |
35 | 33 |
|
36 | 34 | if shuffle: |
37 | | - random.shuffle(idx_list) |
| 35 | + numpy.random.shuffle(idx_list) |
38 | 36 |
|
39 | 37 | minibatches = [] |
40 | 38 | minibatch_start = 0 |
@@ -423,7 +421,7 @@ def train_lstm( |
423 | 421 | # size example. So we must select a random selection of the |
424 | 422 | # examples. |
425 | 423 | idx = numpy.arange(len(test[0])) |
426 | | - random.shuffle(idx) |
| 424 | + numpy.random.shuffle(idx) |
427 | 425 | idx = idx[:test_size] |
428 | 426 | test = ([test[0][n] for n in idx], [test[1][n] for n in idx]) |
429 | 427 |
|
@@ -472,6 +470,7 @@ def train_lstm( |
472 | 470 | print "%d train examples" % len(train[0]) |
473 | 471 | print "%d valid examples" % len(valid[0]) |
474 | 472 | print "%d test examples" % len(test[0]) |
| 473 | + |
475 | 474 | history_errs = [] |
476 | 475 | best_p = None |
477 | 476 | bad_count = 0 |
@@ -589,7 +588,6 @@ def train_lstm( |
589 | 588 | if __name__ == '__main__': |
590 | 589 | # See function train for all possible parameter and there definition. |
591 | 590 | train_lstm( |
592 | | - #reload_model="lstm_model.npz", |
593 | 591 | max_epochs=100, |
594 | 592 | test_size=500, |
595 | 593 | ) |