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

Can not run example with pre-built models #113

Open
nkrot opened this issue Aug 27, 2019 · 1 comment
Open

Can not run example with pre-built models #113

nkrot opened this issue Aug 27, 2019 · 1 comment

Comments

@nkrot
Copy link

nkrot commented Aug 27, 2019

System information

  • Ubuntu 18.0.4 (LTS)
  • Python 3.6.8
  • anago==1.0.8
  • Keras==2.2.5
  • Keras-Applications==1.0.8
  • Keras-Preprocessing==1.1.0
  • tensorflow==1.14.0
  • tensorflow-estimator==1.14.0

Problem

I try to run pretrained models as shown in README, namely:

url = 'https://s3-ap-northeast-1.amazonaws.com/dev.tech-sketch.jp/chakki/public/conll2003_en.zip'
weights, params, preprocessor = anago.utils.download(url)
model = anago.Sequence.load(weights, params, preprocessor)
text = 'President Obama is speaking at the White House .'
res = model.analyze(text)

and receive the following error (future warnings have been silenced):

Using TensorFlow backend.
/tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/sklearn/externals/joblib/__init__.py:15: DeprecationWarning: sklearn.externals.joblib is deprecated in 0.21 and will be removed in 0.23. Please import this functionality directly from joblib, which can be installed with: pip install joblib. If this warning is raised when loading pickled models, you may need to re-serialize those models with scikit-learn 0.21+.
  warnings.warn(msg, category=DeprecationWarning)
WARNING: Logging before flag parsing goes to stderr.
W0827 17:33:44.624381 140560557238080 deprecation_wrapper.py:119] From /tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:541: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.

W0827 17:33:44.635842 140560557238080 deprecation_wrapper.py:119] From /tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:66: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.

W0827 17:33:44.646406 140560557238080 deprecation_wrapper.py:119] From /tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:4432: The name tf.random_uniform is deprecated. Please use tf.random.uniform instead.

W0827 17:33:44.847993 140560557238080 deprecation.py:323] From /tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:3239: add_dispatch_support.<locals>.wrapper (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.where in 2.0, which has the same broadcast rule as np.where
W0827 17:33:45.003281 140560557238080 deprecation_wrapper.py:119] From /tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:148: The name tf.placeholder_with_default is deprecated. Please use tf.compat.v1.placeholder_with_default instead.

W0827 17:33:45.008451 140560557238080 deprecation.py:506] From /tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:3733: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version.
Instructions for updating:
Please use `rate` instead of `keep_prob`. Rate should be set to `rate = 1 - keep_prob`.
Traceback (most recent call last):
  File "/tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 471, in _apply_op_helper
    as_ref=input_arg.is_ref)
  File "/tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1293, in internal_convert_n_to_tensor
    ctx=ctx))
  File "/tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1224, in internal_convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File "/tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1018, in _TensorTensorConversionFunction
    (dtype.name, t.dtype.name, str(t)))
ValueError: Tensor conversion requested dtype bool for Tensor with dtype float32: 'Tensor("crf_1/zeros_like_4:0", shape=(?, ?), dtype=float32)'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./test_02.py", line 21, in <module>
    model = anago.Sequence.load(weights, params, preprocessor)
  File "/tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/anago/wrapper.py", line 140, in load
    self.model = load_model(weights, params)
  File "/tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/anago/models.py", line 22, in load_model
    model = model_from_json(f.read(), custom_objects={'CRF': CRF})
  File "/tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/keras/engine/saving.py", line 627, in model_from_json
    return deserialize(config, custom_objects=custom_objects)
  File "/tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/keras/layers/__init__.py", line 168, in deserialize
    printable_module_name='layer')
  File "/tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/keras/utils/generic_utils.py", line 147, in deserialize_keras_object
    list(custom_objects.items())))
  File "/tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/keras/engine/network.py", line 1062, in from_config
    process_node(layer, node_data)
  File "/tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/keras/engine/network.py", line 1012, in process_node
    layer(unpack_singleton(input_tensors), **kwargs)
  File "/tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/keras/engine/base_layer.py", line 451, in __call__
    output = self.call(inputs, **kwargs)
  File "/tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/anago/layers.py", line 215, in call
    test_output = self.viterbi_decoding(X, mask)
  File "/tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/anago/layers.py", line 484, in viterbi_decoding
    argmin_tables = self.recursion(input_energy, mask, return_logZ=False)
  File "/tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/anago/layers.py", line 445, in recursion
    mask2 = K.cast(K.concatenate([mask, K.zeros_like(mask[:, :1])], axis=1), K.floatx())
  File "/tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 2176, in concatenate
    return tf.concat([to_dense(x) for x in tensors], axis)
  File "/tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/tensorflow/python/util/dispatch.py", line 180, in wrapper
    return target(*args, **kwargs)
  File "/tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py", line 1299, in concat
    return gen_array_ops.concat_v2(values=values, axis=axis, name=name)
  File "/tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/tensorflow/python/ops/gen_array_ops.py", line 1256, in concat_v2
    "ConcatV2", values=values, axis=axis, name=name)
  File "/tmp/test-anago/venv-1.0.8/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 499, in _apply_op_helper
    raise TypeError("%s that don't all match." % prefix)
TypeError: Tensors in list passed to 'values' of 'ConcatV2' Op have types [bool, float32] that don't all match.

Could you help me understand what i am doing wrong?

Thanks in advance,
Nikolai

@nkrot
Copy link
Author

nkrot commented Aug 31, 2019

Hi. I think I have found the cause. The same cause is also preventing the training on a fresh model.

So... the reason that pip install anago (that installs anago==1.0.8) installs too new libraries of Keras and tensorflow. In fact, I ended up with:

Keras==2.2.5
tensorflow==1.14.0

Which is expected given that the file setup.py (https://github.com/Hironsan/anago/blob/master/setup.py) specifies versions of these libraries in a broad, in fact open-ended, fashion:

    'Keras>=2.2.0', 'h5py>=2.7.1', 'scikit-learn>=0.19.1',
    'numpy>=1.14.3', 'tensorflow>=1.8.0', 'requests>=2.18.4',
    'seqeval>=0.0.3'

Assuming that anago was tested with at least the lowest versions, I downgraded Keras, tensorflow and seqeval libraries.

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

1 participant