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

Errors occurs when run RunModel.py #10

Closed
yingdongucas opened this issue Jan 20, 2018 · 3 comments
Closed

Errors occurs when run RunModel.py #10

yingdongucas opened this issue Jan 20, 2018 · 3 comments

Comments

@yingdongucas
Copy link

I have installed dependencies in the requirements.txt, but error occurs when using the command "python RunModel.py models/EN_NER.h5 input.txt".

When using tensorflow as backend, the error is as follows:
Traceback (most recent call last):
File "RunModel.py", line 22, in
lstmModel.loadModel(modelPath)
File "/home/pinkee/Desktop/vulnerability/emnlp2017-bilstm-cnn-crf/neuralnets/BiLSTM.py", line 574, in loadModel
model = keras.models.load_model(modelPath, custom_objects=create_custom_objects())
File "/home/pinkee/anaconda2/lib/python2.7/site-packages/keras/models.py", line 176, in load_model
model.model._make_train_function()
File "/home/pinkee/anaconda2/lib/python2.7/site-packages/keras/engine/training.py", line 760, in _make_train_function
self.total_loss)
File "/home/pinkee/anaconda2/lib/python2.7/site-packages/keras/optimizers.py", line 562, in get_updates
grads = self.get_gradients(loss, params)
File "/home/pinkee/anaconda2/lib/python2.7/site-packages/keras/optimizers.py", line 85, in get_gradients
grads = [clip_norm(g, self.clipnorm, norm) for g in grads]
File "/home/pinkee/anaconda2/lib/python2.7/site-packages/keras/optimizers.py", line 14, in clip_norm
g = K.switch(n >= c, g * c / n, g)
TypeError: unsupported operand type(s) for *: 'IndexedSlices' and 'int'

When using theano as backend, the error is as follows:
Traceback (most recent call last):
File "RunModel.py", line 34, in
lstmModel.loadModel(modelPath)
File "/home/pinkee/Desktop/vulnerability/emnlp2017-bilstm-cnn-crf/neuralnets/BiLSTM.py", line 574, in loadModel
model = keras.models.load_model(modelPath, custom_objects=create_custom_objects())
File "/home/pinkee/anaconda2/lib/python2.7/site-packages/keras/models.py", line 142, in load_model
model = model_from_config(model_config, custom_objects=custom_objects)
File "/home/pinkee/anaconda2/lib/python2.7/site-packages/keras/models.py", line 193, in model_from_config
return layer_from_config(config, custom_objects=custom_objects)
File "/home/pinkee/anaconda2/lib/python2.7/site-packages/keras/utils/layer_utils.py", line 42, in layer_from_config
return layer_class.from_config(config['config'])
File "/home/pinkee/anaconda2/lib/python2.7/site-packages/keras/models.py", line 1091, in from_config
model.add(layer)
File "/home/pinkee/anaconda2/lib/python2.7/site-packages/keras/models.py", line 332, in add
output_tensor = layer(self.outputs[0])
File "/home/pinkee/anaconda2/lib/python2.7/site-packages/keras/engine/topology.py", line 572, in call
self.add_inbound_node(inbound_layers, node_indices, tensor_indices)
File "/home/pinkee/anaconda2/lib/python2.7/site-packages/keras/engine/topology.py", line 635, in add_inbound_node
Node.create_node(self, inbound_layers, node_indices, tensor_indices)
File "/home/pinkee/anaconda2/lib/python2.7/site-packages/keras/engine/topology.py", line 166, in create_node
output_tensors = to_list(outbound_layer.call(input_tensors[0], mask=input_masks[0]))
File "/home/pinkee/Desktop/vulnerability/emnlp2017-bilstm-cnn-crf/neuralnets/keraslayers/ChainCRF.py", line 360, in call
y_pred = viterbi_decode(x, self.U, self.b_start, self.b_end, mask)
File "/home/pinkee/Desktop/vulnerability/emnlp2017-bilstm-cnn-crf/neuralnets/keraslayers/ChainCRF.py", line 163, in viterbi_decode
y = _backward(gamma, mask)
File "/home/pinkee/Desktop/vulnerability/emnlp2017-bilstm-cnn-crf/neuralnets/keraslayers/ChainCRF.py", line 220, in _backward
go_backwards=True)
File "/home/pinkee/anaconda2/lib/python2.7/site-packages/keras/backend/theano_backend.py", line 1136, in rnn
go_backwards=go_backwards)
File "/home/pinkee/anaconda2/lib/python2.7/site-packages/theano/scan_module/scan.py", line 773, in scan
condition, outputs, updates = scan_utils.get_updates_and_outputs(fn(*args))
File "/home/pinkee/anaconda2/lib/python2.7/site-packages/keras/backend/theano_backend.py", line 1124, in _step
output, new_states = step_function(input, states)
File "/home/pinkee/Desktop/vulnerability/emnlp2017-bilstm-cnn-crf/neuralnets/keraslayers/ChainCRF.py", line 213, in _backward_step
y_t = batch_gather(gamma_t, y_tm1)
File "/home/pinkee/Desktop/vulnerability/emnlp2017-bilstm-cnn-crf/neuralnets/keraslayers/ChainCRF.py", line 39, in batch_gather
indices = tf.pack([tf.range(batch_size), indices], axis=1)
File "/home/pinkee/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/math_ops.py", line 1086, in range
limit = ops.convert_to_tensor(limit, dtype=dtype, name="limit")
File "/home/pinkee/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 669, in convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "/home/pinkee/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/constant_op.py", line 176, in _constant_tensor_conversion_function
return constant(v, dtype=dtype, name=name)
File "/home/pinkee/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/constant_op.py", line 165, in constant
tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape))
File "/home/pinkee/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/tensor_util.py", line 441, in make_tensor_proto
tensor_proto.string_val.extend([compat.as_bytes(x) for x in proto_values])
File "/home/pinkee/anaconda2/lib/python2.7/site-packages/tensorflow/python/util/compat.py", line 65, in as_bytes
(bytes_or_text,))
TypeError: Expected binary or unicode string, got Subtensor{int64}.0

How to solve the errors? Thank you!

@nreimers
Copy link
Member

Hi,
Tensorflow sadly doesn't work with the character-based word embeddings (which are used for the pre-trained model).

Theano should work, but I think with the most recent version of theano there might be a problem? Which version of theano do you have? I developed the code for theano==0.9.0

Further I can recommend to try the docker version of this script:
https://github.com/UKPLab/emnlp2017-bilstm-cnn-crf/tree/master/docker

This will install all needed dependencies and you can run the code within the docker container. Issues with different versions of the deep learning frameworks will always be an issue, as these frameworks develop so rapidly. So often after 1/2 - 1 year, old code is no longer running. Here is docker a great solution to ensure that code is also runnable after a longer period of time, as you can exactly control your environment.

@yingdongucas
Copy link
Author

@nreimers Thank you very much for your solution, it perfectly works. I am using theano 0.9.0 now.

@nreimers
Copy link
Member

Great to hear, that it works now.

Sadly it is quite hard to keep code up-to-date with the most recent versions of the different deep learning frameworks, so sadly I don't know why it breaks with the latest version of theano.

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

2 participants