ageron / handson-ml2

A series of Jupyter notebooks that walk you through the fundamentals of Machine Learning and Deep Learning in Python using Scikit-Learn, Keras and TensorFlow 2.
Apache License 2.0
28k stars 12.8k forks source link

Chapter 16 - Issue with Encoder-Decoder Network for Neural Machine Translation #187

Open STRZGR opened 4 years ago

STRZGR commented 4 years ago

Hi,

Really enjoying the book, but I'm encountering a problem when trying to implement the "Encoder-Decoder Network for Neural Machine Translation" in chapter 16.

I'm getting the error below on both my local machine and in the Google Colab notebook:


TypeError Traceback (most recent call last)

in () 21 final_outputs, final_state, final_sequence_lengths = decoder( 22 decoder_embeddings, initial_state=encoder_state, ---> 23 sequence_length=sequence_lengths) 24 Y_proba = tf.nn.softmax(final_outputs.rnn_output) 25 /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/base_layer.py in __call__(self, *args, **kwargs) 920 not base_layer_utils.is_in_eager_or_tf_function()): 921 with auto_control_deps.AutomaticControlDependencies() as acd: --> 922 outputs = call_fn(cast_inputs, *args, **kwargs) 923 # Wrap Tensors in `outputs` in `tf.identity` to avoid 924 # circular dependencies. /usr/local/lib/python3.6/dist-packages/tensorflow/python/autograph/impl/api.py in wrapper(*args, **kwargs) 263 except Exception as e: # pylint:disable=broad-except 264 if hasattr(e, 'ag_error_metadata'): --> 265 raise e.ag_error_metadata.to_exception(e) 266 else: 267 raise TypeError: in user code: /usr/local/lib/python3.6/dist-packages/tensorflow_addons/seq2seq/decoder.py:163 call * self, /usr/local/lib/python3.6/dist-packages/typeguard/__init__.py:261 wrapper * check_argument_types(memo) /usr/local/lib/python3.6/dist-packages/typeguard/__init__.py:668 check_argument_types * check_type(description, value, expected_type, memo) /usr/local/lib/python3.6/dist-packages/typeguard/__init__.py:566 check_type * checker_func(argname, value, expected_type, memo) /usr/local/lib/python3.6/dist-packages/typeguard/__init__.py:409 check_union * raise TypeError('type of {} must be one of ({}); got {} instead'. TypeError: type of argument "training" must be one of (bool, NoneType); got tensorflow.python.framework.ops.Tensor instead
sowmya-debug commented 4 years ago

I think this problem has cropped up recently. I am facing the same problem. Of course, I need to understand what's going on inside these lines.

khushgrover commented 4 years ago

I got the code working by replacing keras with tf.keras everywhere in this particular cell in the colab notebook.

decoder

rickiepark commented 4 years ago

Hi, I think It's a somewhat bug in TensorFlow addons v0.10.0. It works fine at TF 2.2 & TFA 0.9.1.

Thanks. :)

IvanKuchin commented 4 years ago

Hi,

Answered it here. https://stackoverflow.com/questions/62564245/error-when-building-basicdecoder-tensorflow-addons/62805064#62805064