title: ValueError while performing 'binary-crossentropy' ==> array shapes not matching
body: <p>I was using tensorflow + keras while trying to implement a "Text classification" model to classify different types of movie reviews. I am running into a error which tells that the shapes aren't equal. </p>
  
  <p>Because I am not sure where the error might be hidden, I can't produce a reprex example as i am not certain how to isolate the problem. It may be worth your time if the line with variable(x_val) is there as there may be a problem with the partitioning.</p>
  
  <blockquote>
    <p>note this is not the final code. as I had already encountered an error at this point, i stopped writing it.</p>
  </blockquote>
  
  <pre class="lang-py prettyprint-override"><code>from __future__ import absolute_import, division, print_function
  import numpy as np
  import tensorflow as tf
  from tensorflow import keras
  
  imdb = keras.datasets.imdb
  (train_data, train_labels), (test_data, test_labels) = imdb.load_data(num_words=10000)
  
  #print ("The length if training data: "len(train_data[0]), "And labels: "len(test_data[0]))
  
  word_index = imdb.get_word_index()
  word_index = {k: (v+3) for k,v in word_index.items()}
  word_index["&lt;PAD&gt;"] = 0
  word_index["&lt;START&gt;"] = 1
  word_index["&lt;UNKNOWN&gt;"] = 2
  word_index["&lt;END&gt;"] = 3
  
  reverse_word_index = dict([(value, key) for (key, value) in word_index.items() ])
  def decode_review(text):
      return (' '.join([reverse_word_index.get(i , "?") for i in text ]))
  
  print (decode_review(train_data[0]))
  
  train_data = keras.preprocessing.sequence.pad_sequences(train_data, 
                                                 value=word_index["&lt;PAD&gt;"],
                                                 padding="post",
                                                 maxlen=256)
  
  
  test_data = keras.preprocessing.sequence.pad_sequences(test_data, 
                                                 value=word_index["&lt;PAD&gt;"],
                                                 padding="post",
                                                 maxlen=256)
  
  #print ('train length :' ,len(train_data[0]), 'test length: ', len(train_data[1]))
  
  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(16, activation=tf.nn.sigmoid))
  
  print ("the model summary is :======&gt;&gt;" , model.summary())
  
  model.compile(optimizer="adam" , loss="binary_crossentropy", metrics=["acc"])
  
  x_val = train_data[:10000]
  
  partial_x_train = train_data[10000:]
  
  y_val = train_labels[:10000]
  
  partial_y_train = train_labels[10000:]
  
  history = model.fit(partial_x_train , partial_y_train , epochs=40 , batch_size=512, 
                      validation_data=(x_val, y_val), verbose=1)
  </code></pre>
  
  <p><strong>This is the error message I was getting:-----</strong>
  Model: "sequential_1"</p>
  
  <pre><code>_________________________________________________________________
  Layer (type)                 Output Shape              Param #   
  =================================================================
  embedding_1 (Embedding)      (None, None, 16)          160000    
  _________________________________________________________________
  global_average_pooling1d_1 ( (None, 16)                0         
  _________________________________________________________________
  dense_2 (Dense)              (None, 16)                272       
  _________________________________________________________________
  dense_3 (Dense)              (None, 16)                272       
  =================================================================
  Total params: 160,544
  Trainable params: 160,544
  Non-trainable params: 0
  _________________________________________________________________
  the model summary is :======&gt;&gt; None
  WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/nn_impl.py:180: add_dispatch_support.&lt;locals&gt;.wrapper (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.
  Instructions for updating:
  Use tf.where in 2.0, which has the same broadcast rule as np.where
  ---------------------------------------------------------------------------
  ValueError                                Traceback (most recent call last)
  &lt;ipython-input-18-02082e1f39d4&gt; in &lt;module&gt;()
       57 
       58 history = model.fit(partial_x_train , partial_y_train , epochs=40 , batch_size=512, 
  ---&gt; 59                     validation_data=(x_val, y_val), verbose=1)
  
  ValueError: A target array with shape (15000, 1) was passed for an output of shape (None, 16) while using as loss `binary_crossentropy`. This loss expects targets to have the same shape as the output.
  </code></pre>