aneesh-joshi / LSTM_POS_Tagger

A simple POS Tagger made using a Bidirectional LSTM using keras trained on the Brown Corpus
34 stars 19 forks source link

ValueError: Layer model expects 1 input(s), but it received 2 input tensors. Inputs received: [<tf.Tensor 'IteratorGetNext:0' shape=(None, None) dtype=int32>, <tf.Tensor 'IteratorGetNext:1' shape=(None, None, None) dtype=float32>] #19

Open bounmed opened 3 years ago

bounmed commented 3 years ago

I get this error when I run python3 make_model.py to generate the model

Keras version: 2.4.3 Tensorflow version : 2.4.1


TOTAL TAGS 472
TOTAL WORDS 49645
We have 36697 TRAINING samples
We have 9175 VALIDATION samples
We have 11469 TEST samples
Total 400000 word vectors.
Embedding matrix shape (49646, 100)
X_train shape (36697, 100)
2021-03-07 14:24:21.306751: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set
2021-03-07 14:24:21.306950: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
model fitting - Bidirectional LSTM
Model: "model"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
input_1 (InputLayer)         [(None, 100)]             0         
_________________________________________________________________
embedding (Embedding)        (None, 100, 100)          4964600   
_________________________________________________________________
bidirectional (Bidirectional (None, 100, 128)          84480     
_________________________________________________________________
time_distributed (TimeDistri (None, 100, 473)          61017     
=================================================================
Total params: 5,110,097
Trainable params: 5,110,097
Non-trainable params: 0
_________________________________________________________________
/Users/mohamed/Library/Python/3.8/lib/python/site-packages/tensorflow/python/keras/engine/training.py:1844: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
  warnings.warn('`Model.fit_generator` is deprecated and '
2021-03-07 14:24:21.687944: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:116] None of the MLIR optimization passes are enabled (registered 2)
Epoch 1/2
Traceback (most recent call last):
  File "make_model.py", line 114, in <module>
    model.fit_generator(train_generator,
  File "/Users/mohamed/Library/Python/3.8/lib/python/site-packages/tensorflow/python/keras/engine/training.py", line 1847, in fit_generator
    return self.fit(
  File "/Users/mohamed/Library/Python/3.8/lib/python/site-packages/tensorflow/python/keras/engine/training.py", line 1100, in fit
    tmp_logs = self.train_function(iterator)
  File "/Users/mohamed/Library/Python/3.8/lib/python/site-packages/tensorflow/python/eager/def_function.py", line 828, in __call__
    result = self._call(*args, **kwds)
  File "/Users/mohamed/Library/Python/3.8/lib/python/site-packages/tensorflow/python/eager/def_function.py", line 871, in _call
    self._initialize(args, kwds, add_initializers_to=initializers)
  File "/Users/mohamed/Library/Python/3.8/lib/python/site-packages/tensorflow/python/eager/def_function.py", line 725, in _initialize
    self._stateful_fn._get_concrete_function_internal_garbage_collected(  # pylint: disable=protected-access
  File "/Users/mohamed/Library/Python/3.8/lib/python/site-packages/tensorflow/python/eager/function.py", line 2969, in _get_concrete_function_internal_garbage_collected
    graph_function, _ = self._maybe_define_function(args, kwargs)
  File "/Users/mohamed/Library/Python/3.8/lib/python/site-packages/tensorflow/python/eager/function.py", line 3361, in _maybe_define_function
    graph_function = self._create_graph_function(args, kwargs)
  File "/Users/mohamed/Library/Python/3.8/lib/python/site-packages/tensorflow/python/eager/function.py", line 3196, in _create_graph_function
    func_graph_module.func_graph_from_py_func(
  File "/Users/mohamed/Library/Python/3.8/lib/python/site-packages/tensorflow/python/framework/func_graph.py", line 990, in func_graph_from_py_func
    func_outputs = python_func(*func_args, **func_kwargs)
  File "/Users/mohamed/Library/Python/3.8/lib/python/site-packages/tensorflow/python/eager/def_function.py", line 634, in wrapped_fn
    out = weak_wrapped_fn().__wrapped__(*args, **kwds)
  File "/Users/mohamed/Library/Python/3.8/lib/python/site-packages/tensorflow/python/framework/func_graph.py", line 977, in wrapper
    raise e.ag_error_metadata.to_exception(e)
ValueError: in user code:

    /Users/mohamed/Library/Python/3.8/lib/python/site-packages/tensorflow/python/keras/engine/training.py:805 train_function  *
        return step_function(self, iterator)
    /Users/mohamed/Library/Python/3.8/lib/python/site-packages/tensorflow/python/keras/engine/training.py:795 step_function  **
        outputs = model.distribute_strategy.run(run_step, args=(data,))
    /Users/mohamed/Library/Python/3.8/lib/python/site-packages/tensorflow/python/distribute/distribute_lib.py:1259 run
        return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
    /Users/mohamed/Library/Python/3.8/lib/python/site-packages/tensorflow/python/distribute/distribute_lib.py:2730 call_for_each_replica
        return self._call_for_each_replica(fn, args, kwargs)
    /Users/mohamed/Library/Python/3.8/lib/python/site-packages/tensorflow/python/distribute/distribute_lib.py:3417 _call_for_each_replica
        return fn(*args, **kwargs)
    /Users/mohamed/Library/Python/3.8/lib/python/site-packages/tensorflow/python/keras/engine/training.py:788 run_step  **
        outputs = model.train_step(data)
    /Users/mohamed/Library/Python/3.8/lib/python/site-packages/tensorflow/python/keras/engine/training.py:754 train_step
        y_pred = self(x, training=True)
    /Users/mohamed/Library/Python/3.8/lib/python/site-packages/tensorflow/python/keras/engine/base_layer.py:998 __call__
        input_spec.assert_input_compatibility(self.input_spec, inputs, self.name)
    /Users/mohamed/Library/Python/3.8/lib/python/site-packages/tensorflow/python/keras/engine/input_spec.py:204 assert_input_compatibility
        raise ValueError('Layer ' + layer_name + ' expects ' +

    ValueError: Layer model expects 1 input(s), but it received 2 input tensors. Inputs received: [<tf.Tensor 'IteratorGetNext:0' shape=(None, None) dtype=int32>, <tf.Tensor 'IteratorGetNext:1' shape=(None, None, None) dtype=float32>]
dutkaD commented 3 years ago

Hey,

I haven't worked on it for a while. Regarding this I found this issue on StackOverflow.

https://stackoverflow.com/questions/61586981/valueerror-layer-sequential-20-expects-1-inputs-but-it-received-2-input-tensor

Seems like you need to replace a list with a tuple as your input.

They say there that that has changed with a newer version of Tensorflow, if it's TensorFlow 2.3.0 and upper? the list wouldn't work.