title: Adapt Text Classifier Neural Net To Accept Multiple Categories
body: <p>I'm trying to adjust the text classifier neural net in this Keras/Tensorflow tutorial to output multiple (more than 2 categories). I think I can change the output layer to use a 'softmax' activation but I'm not sure how to adjust the input layer.</p>
  
  <p>Tutorial Link:
  <a href="https://www.tensorflow.org/tutorials/keras/basic_text_classification" rel="nofollow noreferrer">https://www.tensorflow.org/tutorials/keras/basic_text_classification</a></p>
  
  <p>The tutorial is using movie review data and the only two categories are positive or negative so the model only uses an output layer with activation set to 'sigmoid'.</p>
  
  <p>I have 16 categories represented using one-hot encoding.</p>
  
  <p><strong>Tutorial Example:</strong></p>
  
  <pre><code>vocab_size = 10000
  model = keras.Sequential()
  model.add(keras.layers.Embedding(vocab_size, 16))
  model.add(keras.layers.GlobalAveragePooling1D())
  model.add(keras.layers.Dense(16, activation=tf.nn.relu))
  model.add(keras.layers.Dense(1, activation=tf.nn.sigmoid))
  </code></pre>
  
  <p><strong>My Attempt:</strong></p>
  
  <pre><code>model.add(keras.layers.Embedding(10000, 16))
  model.add(keras.layers.GlobalAveragePooling1D())
  model.add(keras.layers.Dense(16, activation=tf.nn.relu))
  model.add(keras.layers.Dense(16, activation='softmax'))
  
  
  model.compile(optimizer='adam',
                loss='binary_crossentropy',
                metrics=['acc'])
  
  history = model.fit(x_train[:5000],
                  y_train[:5000],
                  epochs=1,
                  batch_size=256,
                  validation_data=(x_train[5000:], y_train[5000:]),
                  verbose=1)
  </code></pre>
  
  <p><strong>Error:</strong>
  ValueError: A target array with shape (5000, 1) was passed for an output of shape (None, 16) while using as loss <code>binary_crossentropy</code>. This loss expects targets to have the same shape as the output.</p>
  
  <p><strong>Data Shapes:</strong></p>
  
  <pre><code>x_train[:5000] (5000, 2000)
  y_train[:5000] (5000,16)
  x_train[5000:] (1934, 2000)
  y_train[5000:] (1934,16)
  </code></pre>
  
  <p><strong>Model Summary:</strong>
  Model: "sequential_16"</p>
  
  <pre><code>Layer (type)                 Output Shape              Param #   
  embedding_15 (Embedding)     (None, None, 16)          160000    
  global_average_pooling1d_15  (None, 16)                0         
  dense_30 (Dense)             (None, 16)                272       
  dense_31 (Dense)             (None, 16)                272
  </code></pre>
  
  <p>Total params: 160,544</p>
  
  <p>Trainable params: 160,544</p>
  
  <p>Non-trainable params: 0</p>