from keras.models import Graph
from keras.layers.core import Dense
from keras.layers.recurrent import LSTM
model = Graph()
model.add_input(name='input', input_shape=(1, 30))
model.add_node(LSTM(100, return_sequences=False), name='forward', input='input')
model.add_node(LSTM(100, return_sequences=False, go_backwards=True), name='backward', input='input')
model.add_node(Dense(12, activation='sigmoid'), name='sigmoid', inputs=['forward','backward'])
model.add_output(name='output', input='sigmoid')
model.compile(optimizer='Adam', loss={'output': 'categorical_crossentropy'})
The code throws a series of errors like this:
<<!! BUG IN FGRAPH.REPLACE OR A LISTENER !!>> <type 'exceptions.TypeError'> ('The type of the replacement must be compatible with the type of the original Variable.', Subtensor{:int64:}.0, Subtensor{int64:int64:int64}.0, TensorType(float32, (True, False, False)), TensorType(float32, 3D), 'local_subtensor_merge') local_subtensor_merge
ERROR (theano.gof.opt): Optimization failure due to: local_subtensor_merge
ERROR (theano.gof.opt): node: Subtensor{:int64:}(Subtensor{::int64}.0, ScalarFromTensor.0)
ERROR (theano.gof.opt): TRACEBACK:
ERROR (theano.gof.opt): Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/theano/gof/opt.py", line 1807, in process_node
fgraph.replace_all_validate(repl_pairs, reason=lopt)
File "/usr/local/lib/python2.7/dist-packages/theano/gof/toolbox.py", line 309, in replace_all_validate
fgraph.replace(r, new_r, reason=reason, verbose=False)
File "/usr/local/lib/python2.7/dist-packages/theano/gof/fg.py", line 561, in replace
str(reason))
TypeError: ('The type of the replacement must be compatible with the type of the original Variable.', Subtensor{:int64:}.0, Subtensor{int64:int64:int64}.0, TensorType(float32, (True, False, False)), TensorType(float32, 3D), 'local_subtensor_merge')
removing go_backwards=True the model compiles.
any suggestion? how can i fix it? I need a working B-LSTM
downgrade to 0.8.0 theano maybe a quick solution... :)
@fio710 I had exactly the same error today with pretty much the same code. This happened after removing the embedding layer, which you did as well I think..
@ymcui And I have Theano 0.8.0 ... So downgrading is not a solution.
Theano 0.8.1 and 0.8.0 are basically the same thing, apart from a crash fix for MacOS X.
This message (while frightening) is just a warning, and does not prevent the model from being compiled.
Just to note that now the code in the description don't crash. So I think it can be closed. The problem in Theano have been fixed some times ago already.
Most helpful comment
Theano 0.8.1 and 0.8.0 are basically the same thing, apart from a crash fix for MacOS X.
This message (while frightening) is just a warning, and does not prevent the model from being compiled.