title: Tensorflow labels for classification aren't loaded properly in the model
body: <p>I'm having issues with the categories in in my data, I can't set the Dense softmax layer to &quot;3&quot; instead of &quot;1&quot; for 3 categories.</p>
  <p>I assume my issue is with vectorize_text, but I am not completely sure. I can also assume that I don't set the label tensors correctly.</p>
  <pre><code># Start of data generation
  
  dummy_data = {'text': ['Love', 'Money', 'War'],
                'labels': [1,2,3]
                }
  dummy_data['text'] = dummy_data['text']*500
  dummy_data['labels'] = dummy_data['labels']*500
  
  df_train_bogus = pd.DataFrame(dummy_data)  
  
  
  def df_to_dataset(dataframe, shuffle=True, batch_size=32):
    ds = tf.data.Dataset.from_tensor_slices(dict(dataframe)).batch(batch_size)
    return ds
  
  batch_size = 32
  train_ds = df_to_dataset(df_train_bogus, batch_size=batch_size)
  val_ds = df_to_dataset(df_train_bogus, batch_size=batch_size)
  
  # Model constants (can be lower but that doesn't matter for this example)
  sequence_length = 128
  max_features = 20000  # vocab size
  embedding_dim = 128
  # End of data generation
  </code></pre>
  <pre><code>#  Start of vectorization
  vectorize_layer = TextVectorization(
      standardize = 'lower_and_strip_punctuation',
      max_tokens=max_features,
      output_mode=&quot;int&quot;,
      output_sequence_length=sequence_length,
  )
  
  def vectorize_text(text, labels):
    print(text)
    print(labels)
  
    text = tf.expand_dims(text, -1)
    return vectorize_layer(text), labels
  
  vectorize_layer.adapt(df_train_bogus['text'])
  
  train_ds_vectorized = train_ds.map(lambda x: (vectorize_text(x['text'], x['labels'])))
  val_ds_vectorized = val_ds.map(lambda x: (vectorize_text(x['text'], x['labels'])))
  
  &quot;&quot;&quot;
  Output:
  Tensor(&quot;args_1:0&quot;, shape=(None,), dtype=string)
  Tensor(&quot;args_0:0&quot;, shape=(None,), dtype=int64)
  Tensor(&quot;args_1:0&quot;, shape=(None,), dtype=string)
  Tensor(&quot;args_0:0&quot;, shape=(None,), dtype=int64)
  
  &quot;&quot;&quot;
  </code></pre>
  <pre><code>#  The model
  
  model = Sequential()
  model.add(Embedding(max_features, embedding_dim, input_length=sequence_length))
  model.add(LSTM(embedding_dim, input_shape=(None, sequence_length)))
  
  model.add(Dense(3, activation='softmax'))
  #  Fails with this error:
  #      ValueError: Shapes (None, 1) and (None, 3) are incompatible
  
  model.summary()
  
  model.compile(loss=&quot;categorical_crossentropy&quot;,
                optimizer=&quot;adam&quot;,
                metrics=[&quot;accuracy&quot;])  # model 4
  
  epochs = 10
  
  # Fit the model using the train and test datasets.
  history = model.fit(train_ds_vectorized, validation_data=val_ds_vectorized, epochs=epochs)
  </code></pre>