Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialization of self._predict_stochastic #1

Open
jjkernst opened this issue Jun 6, 2016 · 2 comments
Open

Initialization of self._predict_stochastic #1

jjkernst opened this issue Jun 6, 2016 · 2 comments

Comments

@jjkernst
Copy link

jjkernst commented Jun 6, 2016

Hi, I am attempting to run the Examples/sentiment_lstm_regression.py however I am running into some issues: it keeps failing on the initialization of the predict_stochastic function in the first callback of modeltest.

First the function fails on X = models.standardize_X(X), due to the below error. Is this function supposed to be standardize(X)? I can't find a standardize_X in the latest Keras pull (I am using 1.0.3)?
AttributeError: 'module' object has no attribute 'standardize_X'

The function then also fails on defining the K function because neither model.X_test nor model.y_train are defined. The example doesn't have a test set passed into the fit model, so I'm not sure which variable this would be referencing.
K.function([self.model.X_test], [self.model.y_train])
AttributeError: 'Sequential' object has no attribute 'X_test'

If I remove the Modeltest call backs, the training works fine.

Any help you could provide would be greatly appreciated. Thanks!

@jasonbunk
Copy link

I fixed these issues with the following changes:

  • In callbacks.py, insert this at line 6:
def standardize_X(X):
    if type(X) == list:
        return X
    else:
        return [X]

then replace "X = models.standardize_X(X)" with "X = standardize_X(X)"

  • In callbacks.py, replace the line
self._predict_stochastic = K.function([self.model.X_test], [self.model.y_train])

with the following (using the Theano backend of Keras):

self._predict_stochastic = K.function([self.model.inputs[0]],
                    [self.model.outputs[0]], givens={K.learning_phase(): np.uint8(1)})
  • I also had to insert this at line 51 of sentiment_lstm_regression.py:
X_train = np.asarray(X_train)
X_test  = np.asarray(X_test)
Y_train = np.asarray(Y_train)
Y_test  = np.asarray(Y_test)

jasonbunk added a commit to jasonbunk/BayesianRNN that referenced this issue Jul 15, 2016
@Chealkeo
Copy link

I fixed these issues with the following changes:

  • In callbacks.py, insert this at line 6:
def standardize_X(X):
    if type(X) == list:
        return X
    else:
        return [X]

then replace "X = models.standardize_X(X)" with "X = standardize_X(X)"

  • In callbacks.py, replace the line
self._predict_stochastic = K.function([self.model.X_test], [self.model.y_train])

with the following (using the Theano backend of Keras):

self._predict_stochastic = K.function([self.model.inputs[0]],
                    [self.model.outputs[0]], givens={K.learning_phase(): np.uint8(1)})
  • I also had to insert this at line 51 of sentiment_lstm_regression.py:
X_train = np.asarray(X_train)
X_test  = np.asarray(X_test)
Y_train = np.asarray(Y_train)
Y_test  = np.asarray(Y_test)

hi, thanks for your solution, furthermore, I want to clear which version of theano and keras used in above code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants