title: Input 0 of layer gru is incompatible with the layer: expected ndim=3, found ndim=2
body: <p>I'm using TF 2.5 and I'm punctually following the tutorial on <a href="https://www.tensorflow.org/text/tutorials/text_generation" rel="nofollow noreferrer">https://www.tensorflow.org/text/tutorials/text_generation</a> just to get some confidence.</p>
  <p>But I don't understand why after building the model I get an inconsistency on the dimension; it expects a 3-dimensional layer and it receives only two.</p>
  <pre><code>ValueError: Input 0 of layer gru is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: (64, 100)
  </code></pre>
  <p>Meanwhile this problem is not found in the tutorial, even using their own dataset, and this leaves me puzzled.</p>
  <p>I then tried various combinations, even generating a dummy dimension in the dataset, but I don't get the desired result.</p>
  <p>I somehow understand that the problem should lies in the dataset conformation since:</p>
  <pre><code>&lt;PrefetchDataset shapes: ((64, 100), (64, 100)), types: (tf.int64, tf.int64)&gt;
  </code></pre>
  <p>I see I am missing a dimension. But how can I &quot;add&quot; a dimension to it, or viceversa exclude the model to expect 3 dimension (but, in that case, I am wondering what's the meaning of the whole model), it's not clear.</p>
  <p>I have read many similar cases (both with GRU and LSTM) and tried various options, but given my unfamiliarity, I feel I am at a standstill.</p>
  <p>I would be grateful if someone could give me a tip.</p>
  <p>Here is my code (that replicates the one on TensorFlow page linked above):</p>
  <p>(this is also my very first post on SO!)</p>
  <pre><code>BATCH_SIZE = 64
  BUFFER_SIZE = 10000
  
  dataset = (dataset
             .shuffle(BUFFER_SIZE)
             .batch(BATCH_SIZE, drop_remainder=True)
             .prefetch(tf.data.experimental.AUTOTUNE))
  
  vocab_size = len(vocab)
  embedding_dim = 256
  rnn_units = 1024
  
  
  class MyModel(tf.keras.Model):
      def __init__(self, vocab_size, embedding_dim, rnn_units):
          super().__init__(self)
          self.embedding = tf.keras.layers.GRU(rnn_units, return_sequences=True, return_state=True)
          self.dense = tf.keras.layers.Dense(vocab_size)
          
      def call(self, inputs, states=None, return_state=False, training=False):
          x = inputs
          x = self.embedding(x, training=training)
          if states is None:
              states = self.gru.get_initial_state(x)
          x = self.dense(x, training=training)
          
          if return_state:
              return x, states
          else:
              return x
  
  model = MyModel(vocab_size=len(ids_from_chars.get_vocabulary()), embedding_dim=embedding_dim, rnn_units=rnn_units)
  
  for input_example_batch, target_example_batch in dataset.take(1):
      example_batch_predictions = model(input_example_batch)
      print (example_batch_predictions.shape, &quot;# (batch_size, sequence_length, vocab_size)&quot;)
  </code></pre>