 TypeError: Expected int32, got 1e-07 of type 'float' instead.
Can you help me out
 Epoch 1/60
Traceback (most recent call last):
  File "MDLSTM7_CRF.py", line 422, in <module>
    model_build(input_file)
  File "MDLSTM7_CRF.py", line 311, in model_build
    history = model.fit([X_word_train, X_char_train, pos_tag_train, max_len_array], y_train, batch_size=5, epochs=60, validation_split=0.2, verbose=1)
  File "C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\keras\engine\training.py", line 66, in _method_wrapper
    return method(self, *args, **kwargs)
  File "C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\keras\engine\training.py", line 848, in fit
    tmp_logs = train_function(iterator)
  File "C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\eager\def_function.py", line 580, in __call__
    result = self._call(*args, **kwds)
  File "C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\eager\def_function.py", line 627, in _call
    self._initialize(args, kwds, add_initializers_to=initializers)
  File "C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\eager\def_function.py", line 506, in _initialize
    *args, **kwds))
  File "C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\eager\function.py", line 2446, in _get_concrete_function_internal_garbage_collected
    graph_function, _, _ = self._maybe_define_function(args, kwargs)
  File "C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\eager\function.py", line 2777, in _maybe_define_function
    graph_function = self._create_graph_function(args, kwargs)
  File "C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\eager\function.py", line 2667, in _create_graph_function
    capture_by_value=self._capture_by_value),
  File "C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\framework\func_graph.py", line 981, in func_graph_from_py_func
    func_outputs = python_func(*func_args, **func_kwargs)
  File "C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\eager\def_function.py", line 441, in wrapped_fn
    return weak_wrapped_fn().__wrapped__(*args, **kwds)
  File "C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\framework\func_graph.py", line 968, in wrapper
    raise e.ag_error_metadata.to_exception(e)
TypeError: in user code:

    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\keras\engine\training.py:571 train_function  *
        outputs = self.distribute_strategy.run(
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:951 run  **
        return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:2290 call_for_each_replica
        return self._call_for_each_replica(fn, args, kwargs)
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:2649 _call_for_each_replica
        return fn(*args, **kwargs)
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\keras\engine\training.py:533 train_step  **
        y, y_pred, sample_weight, regularization_losses=self.losses)
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\keras\engine\compile_utils.py:205 __call__
        loss_value = loss_obj(y_t, y_p, sample_weight=sw)
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\keras\losses.py:143 __call__
        losses = self.call(y_true, y_pred)
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\keras\losses.py:246 call
        return self.fn(y_true, y_pred, **self._fn_kwargs)
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\keras\losses.py:1558 sparse_categorical_crossentropy
        y_true, y_pred, from_logits=from_logits, axis=axis)
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\keras\backend.py:4620 sparse_categorical_crossentropy
        epsilon_ = _constant_to_tensor(epsilon(), output.dtype.base_dtype)
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\keras\backend.py:709 _constant_to_tensor
        return constant_op.constant(x, dtype=dtype)
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\framework\constant_op.py:262 constant
        allow_broadcast=True)
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\framework\constant_op.py:300 _constant_impl
        allow_broadcast=allow_broadcast))
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\framework\tensor_util.py:451 make_tensor_proto
        _AssertCompatible(values, dtype)
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\framework\tensor_util.py:331 _AssertCompatible
        (dtype.name, repr(mismatch), type(mismatch).__name__))

    TypeError: Expected int32, got 1e-07 of type 'float' instead. @kusumlata123,
Looks like the provided code is not the complete code. Can you please, share colab link or complete code with supporting files to reproduce the issue in our environment. It helps us in localizing the issue faster.

Also the Tensorflow v2.2 is a pretty old version. Could you please test the code in the latest TensorFlow v2.15 or v2.16 where most of the bugs are resolved in the updated versions.
Thank you! As my code supported this one , i have run this code in 2021 and now
again want to run for research purpose


On Mon, Jun 3, 2024 at 12:47 PM tilakrayal ***@***.***> wrote:

> @kusumlata123 <https://github.com/kusumlata123>,
> Looks like the provided code is not the complete code. Can you please,
> share colab link or complete code with supporting files to reproduce the
> issue in our environment. It helps us in localizing the issue faster.
>
> Also the Tensorflow v2.2 is a pretty old version. Could you please test
> the code in the latest TensorFlow v2.15 or v2.16 where most of the bugs are
> resolved in the updated versions.
> Thank you!
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/tensorflow/tensorflow/issues/68959#issuecomment-2144449490>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AJKEARCIVD6RAYB7FXIK3NLZFQKABAVCNFSM6AAAAABITECF4SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNBUGQ2DSNBZGA>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
  from tensorflow.keras.preprocessing.sequence import pad_sequences
ModuleNotFoundError: No module named 'tensorflow.keras'

 if i have upgraded version from 2.2.0 to 2.11.0 with  keras 2.11.0 @kusumlata123,
I guess your code was written which was compatible with the tensorflow v2.2. There are more number of apis which were deprecated in the older versions and couldn't be used in the latest versions. 

Eg:from tensorflow.keras.preprocessing.sequence import pad_sequences---tf.keras.preprocessing.sequence was deprecated
![image](https://github.com/tensorflow/tensorflow/assets/81610181/c1d66f54-2afd-4a3a-be83-d6558b7badde)

https://www.tensorflow.org/api_docs/python/tf/keras/preprocessing/sequence

https://stackoverflow.com/questions/72326025/cannot-import-name-pad-sequences-from-keras-preprocessing-sequence

Please try to convert the complete code and try to execute the code. Thank you!
### Issue type

Bug

### Have you reproduced the bug with TensorFlow Nightly?

Yes

### Source

source

### TensorFlow version

tf 2.2.0, tf-gpu-2.2.0

### Custom code

Yes

### OS platform and distribution

window

### Mobile device

Laptop

### Python version

3.7.6

### Bazel version

_No response_

### GCC/compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

model_build(input_file)
  File "MDLSTM7_CRF.py", line 307, in model_build
    verbose=int(1)
  File "C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\keras\engine\training.py", line 66, in _method_wrapper
    return method(self, *args, **kwargs)
  File "C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\keras\engine\training.py", line 848, in fit
    tmp_logs = train_function(iterator)
  File "C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\eager\def_function.py", line 580, in __call__
    result = self._call(*args, **kwds)
  File "C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\eager\def_function.py", line 627, in _call
    self._initialize(args, kwds, add_initializers_to=initializers)
  File "C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\eager\def_function.py", line 506, in _initialize
    *args, **kwds))
  File "C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\eager\function.py", line 2446, in _get_concrete_function_internal_garbage_collected
    graph_function, _, _ = self._maybe_define_function(args, kwargs)
  File "C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\eager\function.py", line 2777, in _maybe_define_function
    graph_function = self._create_graph_function(args, kwargs)
  File "C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\eager\function.py", line 2667, in _create_graph_function
    capture_by_value=self._capture_by_value),
  File "C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\framework\func_graph.py", line 981, in func_graph_from_py_func
    func_outputs = python_func(*func_args, **func_kwargs)
  File "C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\eager\def_function.py", line 441, in wrapped_fn
    return weak_wrapped_fn().__wrapped__(*args, **kwds)
  File "C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\framework\func_graph.py", line 968, in wrapper
    raise e.ag_error_metadata.to_exception(e)
TypeError: in user code:

    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\keras\engine\training.py:571 train_function  *
        outputs = self.distribute_strategy.run(
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:951 run  **
        return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:2290 call_for_each_replica
        return self._call_for_each_replica(fn, args, kwargs)
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:2649 _call_for_each_replica
        return fn(*args, **kwargs)
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\keras\engine\training.py:533 train_step  **
        y, y_pred, sample_weight, regularization_losses=self.losses)
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\keras\engine\compile_utils.py:205 __call__
        loss_value = loss_obj(y_t, y_p, sample_weight=sw)
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\keras\losses.py:143 __call__
        losses = self.call(y_true, y_pred)
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\keras\losses.py:246 call
        return self.fn(y_true, y_pred, **self._fn_kwargs)
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\keras\losses.py:1558 sparse_categorical_crossentropy
        y_true, y_pred, from_logits=from_logits, axis=axis)
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\keras\backend.py:4620 sparse_categorical_crossentropy
        epsilon_ = _constant_to_tensor(epsilon(), output.dtype.base_dtype)
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\keras\backend.py:709 _constant_to_tensor
        return constant_op.constant(x, dtype=dtype)
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\framework\constant_op.py:262 constant
        allow_broadcast=True)
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\framework\constant_op.py:300 _constant_impl
        allow_broadcast=allow_broadcast))
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\framework\tensor_util.py:451 make_tensor_proto
        _AssertCompatible(values, dtype)
    C:\Users\saivi\anaconda3\envs\mention\lib\site-packages\tensorflow\python\framework\tensor_util.py:331 _AssertCompatible
        (dtype.name, repr(mismatch), type(mismatch).__name__))

    TypeError: Expected int32, got 1e-07 of type 'float' instead.

### Standalone code to reproduce the issue

```shell
X_word_train = np.array(X_word_train, dtype=np.int32)
    X_char_train = np.array(X_char_train, dtype=np.int32).reshape((len(X_char_train), max_len, max_len_char))
    pos_tag_train = np.array(pos_tag_train, dtype=np.int32)
    y_train = np.array(y_train, dtype=np.int32).reshape(len(y_train), max_len, 1)

    # Use np.full to create an array of integers
    max_len_array = np.full(len(X_word_train), max_len, dtype=np.int32)
 
    history = model.fit(
        [X_word_train, X_char_train, pos_tag_train, max_len_array],
        y_train,
        batch_size=5,
        epochs=60,
        shuffle=False,
        validation_split=0.2,
        verbose=1
    )
```


### Relevant log output

```shell
model should be train
```
