ValueError: Input 1 of layer "model" is incompatible with the layer: expected shape=(None, 15), found shape=(1, 14)
@emailbsuv  Could you please have a look at this [link](https://www.tensorflow.org/guide/keras/customizing_what_happens_in_fit) to know more about the customizing model fit() and let me know if it helps?
Thank you! > @emailbsuv Could you please have a look at this [link](https://www.tensorflow.org/guide/keras/customizing_what_happens_in_fit) to know more about the customizing model fit() and let me know if it helps? Thank you!

Could you take a look at this [link](https://t.me/s/DeepLearningMonitor/14) to learn more about your link's help for setting up a fit() model and let me know if it helps?
Thank you!
 @SuryanarayanaY I was able to replicate this issue on colab, please find the [gist](https://colab.research.google.com/gist/sushreebarsa/60d9129070c91869ae3b6c912156dc69/61453.ipynb) here?
Thank you! I was able to solve this issue by changing 
`#target_sequences = np.expand_dims(output_sequences[:, 1:], -1)` to 
`target_sequences = np.expand_dims(output_sequences, -1)`
and 
`model.fit([input_sequences, output_sequences[:, :-1]], target_sequences,  epochs=50, batch_size=1)` to `model.fit([input_sequences, output_sequences], target_sequences, epochs=50, batch_size=1)`
You can find the code [here](https://colab.research.google.com/drive/19AVYr_1T77yH8rM6648k0QaOqt52gxM7?usp=sharing)
 Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/61453">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/61453">No</a>
 > I was able to solve this issue by changing `#target_sequences = np.expand_dims(output_sequences[:, 1:], -1)` to `target_sequences = np.expand_dims(output_sequences, -1)` and `model.fit([input_sequences, output_sequences[:, :-1]], target_sequences, epochs=50, batch_size=1)` to `model.fit([input_sequences, output_sequences], target_sequences, epochs=50, batch_size=1)` You can find the code [here](https://colab.research.google.com/drive/19AVYr_1T77yH8rM6648k0QaOqt52gxM7?usp=sharing)

There are several possible reasons why a model may return incomplete responses:

1. Insufficient dataset size for training. A small data set means that the model cannot learn all linguistic patterns. More dialogue examples need to be added.
2. Too small latent space (dimension of phrase presentation vectors). Because of this, the model cannot capture all the information from the input phrase. Try increasing latent_dim.
3. Premature termination of training. We need to increase the number of epochs so that the model learns better.
4. Model architecture problem. Perhaps more complex or deep models are needed (for example, add another LSTM layer).
5. Text preprocessing errors or incorrect generation of target sequences. We need to check these parts of the code.
6. Instability in the learning process. It will help to use dropout, batch normalization and other regularization methods. Hi @emailbsuv ,

The error is due to shape mismatch of input-2(encoder output) and target_sequence wrt model architecture. Both should have same shape as per model architecture. Changing the shapes will cause the error as model architecture shape is already defined for Input layer.

There are 2 possible solutions. 

1.Mention the shape of Input layer as `(None,)`
2.Or Maintain the same shape as mentioned in Input layer while designing model architecture.

I have attached both possible fix in the [gist](https://colab.sandbox.google.com/gist/SuryanarayanaY/9d3d4943d195b8e0c250164ff158540c/61453_r1.ipynb) you may choose any one that suits your requirement.

Thanks!




 This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/61453">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/61453">No</a>

### Issue type

Bug

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

Yes

### Source

source

### TensorFlow version

tf 2.13.0

### Custom code

Yes

### OS platform and distribution

windows 11

### Mobile device

_No response_

### Python version

3.11.4

### Bazel version

_No response_

### GCC/compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

Python TF script do not run, because errors

### Standalone code to reproduce the issue

```shell
import numpy as np
import tensorflow as tf
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Input, LSTM, Dense
import os

# Set the TensorFlow logging level to ERROR
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

# Training data
input_data = [
    "Привет, как тебя зовут?",
    "Какие у тебя интересы?",
    "Как прошел твой день?",
    "Ты любишь путешествовать?",
    "Что ты думаешь о знакомствах через интернет?"
]

output_data = [
    "Привет! Меня зовут ЧатБот. А тебя?",
    "Мои интересы - это общение с людьми!",
    "Мой день прошел хорошо, спасибо.",
    "Я бот, поэтому путешествовать не могу, но обожаю общение с людьми!",
    "Я думаю, что знакомства через интернет - это отличный способ найти новых друзей и партнеров."
]

input_tokens = tf.keras.preprocessing.text.Tokenizer(filters='')
output_tokens = tf.keras.preprocessing.text.Tokenizer(filters='')
input_tokens.fit_on_texts(input_data)
output_tokens.fit_on_texts(output_data)

input_sequences = input_tokens.texts_to_sequences(input_data)
output_sequences = output_tokens.texts_to_sequences(output_data)

# Pad sequences to the maximum length
max_seq_length = max(len(seq) for seq in input_sequences + output_sequences)
input_sequences = tf.keras.preprocessing.sequence.pad_sequences(input_sequences, padding='post', maxlen=max_seq_length)
output_sequences = tf.keras.preprocessing.sequence.pad_sequences(output_sequences, padding='post', maxlen=max_seq_length)

# Seq2Seq Model
latent_dim = 64

# Encoder
encoder_inputs = Input(shape=(max_seq_length,))
encoder_embedding = tf.keras.layers.Embedding(len(input_tokens.word_index) + 1, latent_dim)(encoder_inputs)
encoder_outputs, state_h, state_c = LSTM(latent_dim, return_state=True)(encoder_embedding)
encoder_states = [state_h, state_c]

# Decoder
decoder_inputs = Input(shape=(max_seq_length,))
decoder_embedding = tf.keras.layers.Embedding(len(output_tokens.word_index) + 1, latent_dim)(decoder_inputs)
decoder_lstm = LSTM(latent_dim, return_sequences=True, return_state=True)
decoder_outputs, _, _ = decoder_lstm(decoder_embedding, initial_state=encoder_states)
decoder_dense = Dense(len(output_tokens.word_index) + 1, activation='softmax')
decoder_outputs = decoder_dense(decoder_outputs)

# Model
model = Model([encoder_inputs, decoder_inputs], decoder_outputs)
model.compile(optimizer='rmsprop', loss='sparse_categorical_crossentropy')

# Prepare target sequences
target_sequences = output_sequences[:, 1:]

# Training
model.fit([input_sequences, output_sequences[:, :-1]], target_sequences,  epochs=50, batch_size=1)





# Save the model
model.save("chatbot_model.keras")

# Example of using the trained model
def predict_response(input_text):
    input_seq = input_tokens.texts_to_sequences([input_text])
    input_seq = tf.keras.preprocessing.sequence.pad_sequences(input_seq, padding='post', maxlen=max_seq_length)
    output_seq = model.predict([input_seq, np.zeros((len(input_seq), max_seq_length))])
    output_seq = np.argmax(output_seq, axis=-1)
    output_text = ' '.join([output_tokens.index_word[i] for i in output_seq[0] if i != 0])
    return output_text

# Example of using the model to generate responses
user_input = "Как прошел твой день?"
response = predict_response(user_input)
print(response)
```


### Relevant log output

```shell
C:\git\mt_server\markettrader.mooo.com>python chat.py
TensorFlow version: 2.13.0
Epoch 1/50
Traceback (most recent call last):
  File "C:\git\mt_server\markettrader.mooo.com\chat.py", line 65, in <module>
    model.fit([input_sequences, output_sequences[:, :-1]],  epochs=50, batch_size=1)
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\src\utils\traceback_utils.py", line 70, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "C:\Users\User\AppData\Local\Temp\__autograph_generated_filer5ymro82.py", line 15, in tf__train_function
    retval_ = ag__.converted_call(ag__.ld(step_function), (ag__.ld(self), ag__.ld(iterator)), None, fscope)
    ^^^^^
ValueError: in user code:

    File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\src\engine\training.py", line 1338, in train_function  *
        return step_function(self, iterator)
    File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\src\engine\training.py", line 1322, in step_function  **
        outputs = model.distribute_strategy.run(run_step, args=(data,))
    File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\src\engine\training.py", line 1303, in run_step  **
        outputs = model.train_step(data)
    File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\src\engine\training.py", line 1080, in train_step
        y_pred = self(x, training=True)
    File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\src\utils\traceback_utils.py", line 70, in error_handler
        raise e.with_traceback(filtered_tb) from None
    File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\src\engine\input_spec.py", line 298, in assert_input_compatibility
        raise ValueError(

    ValueError: Input 1 of layer "model" is incompatible with the layer: expected shape=(None, 15), found shape=(1, 14)
```
