title: Keras 2 input model, incompatible Shapes
body: <p>I'm trying to build a two input model with keras, with each input being a string.</p>
  <p>Here's the code for the model</p>
  <pre><code>    vectorize_layer1 = TextVectorization(split=&quot;character&quot;, output_sequence_length=512,
                                           max_tokens=MAX_STRING_SIZE)
      vectorize_layer1.adapt(list(vocab))
  
      # define two sets of inputs
      inputA = Input(shape=(1,), dtype=tf.string)
      inputB = Input(shape=(1,), dtype=tf.string)
  
      # the first branch operates on the first input
      x = vectorize_layer1(inputA)
      x = Embedding(len(vectorize_layer1.get_vocabulary()), MAX_STRING_SIZE)(x)
      x = Bidirectional(LSTM(MAX_STRING_SIZE, return_sequences=True, dropout=.2))(x)
      x = LSTM(MAX_STRING_SIZE, activation=&quot;tanh&quot;, return_sequences=False, dropout=.2)(x)
      x = Model(inputs=inputA, outputs=x)
  
      # the second branch opreates on the second input
      y = vectorize_layer1(inputB)
      y = Embedding(len(vectorize_layer1.get_vocabulary()), MAX_STRING_SIZE)(y)
      y = Bidirectional(LSTM(MAX_STRING_SIZE, return_sequences=True, dropout=.2))(y)
      y = LSTM(MAX_STRING_SIZE, activation=&quot;tanh&quot;, return_sequences=False, dropout=.2)(y)
      y = Model(inputs=inputB, outputs=y)
  
      # combine the output of the two branches
      combined = concatenate([x.output, y.output])
      # apply a FC layer and then a prediction on the categories
      z = Dense(2, activation=&quot;relu&quot;)(combined)
      z = Dense(len(LABELS), activation=&quot;softmax&quot;)(z)
  
      # our model will accept the inputs of the two branches an
      model = Model(inputs=[x.input, y.input], outputs=z)
      print(model.predict((np.array([&quot;i love python&quot;]), np.array([&quot;test&quot;]))))
      #That prediction works fine! 
  
      model.summary()
      plot_model(model, to_file=&quot;model.png&quot;, show_shapes=True, show_layer_names=True)
      model.compile(optimizer='Adam',
                    loss=CategoricalCrossentropy(from_logits=False),
                    metrics=[&quot;categorical_accuracy&quot;])
  
      stopper = EarlyStopping(monitor='val_categorical_accuracy', patience=10)
      checkpointer = ModelCheckpoint(&quot;model-best.tf&quot;, save_best_only=True)
  
  
      model.fit(
          training,
          callbacks=[stopper, checkpointer],
          steps_per_epoch=2048,
          validation_data=validation,
          batch_size=8,
          epochs=epochs
      )
      model.save(output, save_format='tf')
  </code></pre>
  <p>I'm getting the Shapes are incompatible error though:</p>
  <pre><code> line 5119, in categorical_crossentropy
          target.shape.assert_is_compatible_with(output.shape)
  
      ValueError: Shapes (None, 1) and (None, 20) are incompatible
  </code></pre>
  <p>Here is an example of the training/validation data:</p>
  <pre><code>((array(['foo'], dtype='&lt;U6'), array(['bar'], dtype='&lt;U26')), array([0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]))
  </code></pre>
  <p>Any ideas what is going wrong? The data looks ok to me, the categories are 1-hot encoded.</p>
  <p><a href="https://i.stack.imgur.com/Uuouf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Uuouf.png" alt="Model diagram" /></a></p>
  <p>Here is the stack trace:</p>
  <pre><code>ValueError: in user code:
  
      File &quot;/Users/**/code/venv/lib/python3.10/site-packages/keras/engine/training.py&quot;, line 1051, in train_function  *
          return step_function(self, iterator)
      File &quot;/Users/**/code/venv/lib/python3.10/site-packages/keras/engine/training.py&quot;, line 1040, in step_function  **
          outputs = model.distribute_strategy.run(run_step, args=(data,))
      File &quot;/Users/**/code/venv/lib/python3.10/site-packages/keras/engine/training.py&quot;, line 1030, in run_step  **
          outputs = model.train_step(data)
      File &quot;/Users/**/code/venv/lib/python3.10/site-packages/keras/engine/training.py&quot;, line 890, in train_step
          loss = self.compute_loss(x, y, y_pred, sample_weight)
      File &quot;/Users/**/code/venv/lib/python3.10/site-packages/keras/engine/training.py&quot;, line 948, in compute_loss
          return self.compiled_loss(
      File &quot;/Users/**/code/venv/lib/python3.10/site-packages/keras/engine/compile_utils.py&quot;, line 201, in __call__
          loss_value = loss_obj(y_t, y_p, sample_weight=sw)
      File &quot;/Users/**/code/venv/lib/python3.10/site-packages/keras/losses.py&quot;, line 139, in __call__
          losses = call_fn(y_true, y_pred)
      File &quot;/Users/**/code/venv/lib/python3.10/site-packages/keras/losses.py&quot;, line 243, in call  **
          return ag_fn(y_true, y_pred, **self._fn_kwargs)
      File &quot;/Users/**/code/venv/lib/python3.10/site-packages/keras/losses.py&quot;, line 1787, in categorical_crossentropy
          return backend.categorical_crossentropy(
      File &quot;/Users/**/code/venv/lib/python3.10/site-packages/keras/backend.py&quot;, line 5119, in categorical_crossentropy
          target.shape.assert_is_compatible_with(output.shape)
  
      ValueError: Shapes (None, 1) and (None, 20) are incompatible
  </code></pre>