Skip to content

Commit

Permalink
This fixes issue yaringal#1 by updating Example to latest Keras API (…
Browse files Browse the repository at this point in the history
…tested with Theano backend)
  • Loading branch information
jasonbunk committed Jul 15, 2016
1 parent 316e28d commit ef5ac9b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Example/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
from keras import backend as K
from keras import models

def standardize_X(X):
if type(X) == list:
return X
else:
return [X]

class ModelTest(Callback):
''' Test model at the end of every X epochs.
Expand Down Expand Up @@ -61,9 +67,10 @@ def predict_stochastic(self, X, batch_size=128, verbose=0):
- [Dropout: A simple way to prevent neural networks from overfitting](http://jmlr.org/papers/v15/srivastava14a.html)
- [Dropout as a Bayesian Approximation: Representing Model Uncertainty in Deep Learning](http://arxiv.org/abs/1506.02142)
'''
X = models.standardize_X(X)
X = standardize_X(X)
if self._predict_stochastic is None: # we only get self.model after init
self._predict_stochastic = K.function([self.model.X_test], [self.model.y_train])
self._predict_stochastic = K.function([self.model.inputs[0]], [self.model.outputs[0]],
givens={K.learning_phase(): np.uint8(1)})
return self.model._predict_loop(self._predict_stochastic, X, batch_size, verbose)[0]


Expand Down
5 changes: 5 additions & 0 deletions Example/sentiment_lstm_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
X_train, X_test, Y_train, Y_test = dataset.X_train, dataset.X_test, dataset.Y_train, dataset.Y_test
mean_y_train, std_y_train = dataset.mean_y_train, dataset.std_y_train

X_train = np.asarray(X_train)
X_test = np.asarray(X_test)
Y_train = np.asarray(Y_train)
Y_test = np.asarray(Y_test)

# Set seed:
np.random.seed(global_seed)

Expand Down

0 comments on commit ef5ac9b

Please sign in to comment.