title: keras sparse_categorical_crossentropy loss function output shape didn't match
body: <p>I have a dataset which has 3570 labels. When I use the <code>sparse_categorical_crossentropy</code> as the loss function, the output shape didn't match.</p>
  
  <pre><code>model = Sequential()
  model.add(Dense(1024, input_dim=79, activation='relu'))
  model.add(Dense(2048, activation='relu'))
  model.add(Dense(3570, activation='sigmoid'))
  
  model.compile(loss='sparse_categorical_crossentropy',
                optimizer='rmsprop',
                metrics=['accuracy'])
  model.fit(x_train, y_train,
            epochs=10,
            batch_size=1,
            validation_data=(x_valid, y_valid))
  </code></pre>
  
  <p>and the output is 
  <code>ValueError: Error when checking model target: expected dense_42 to have shape (None, 1) but got array with shape (1055, 3570)</code> </p>
  
  <p>Then I fount this <a href="https://github.com/fchollet/keras/issues/2444" rel="nofollow noreferrer">issue#2444</a> and used <code>np.expand_dims(y, -1)</code> to change the code. But there was still have error. </p>
  
  <pre><code>model = Sequential()
  model.add(Dense(1024, input_dim=79, activation='relu'))
  model.add(Dense(2048, activation='relu'))
  model.add(Dense(3570, activation='sigmoid'))
  
  model.compile(loss='sparse_categorical_crossentropy',
                optimizer='rmsprop',
                metrics=['accuracy'])
  model.fit(x_train, np.expand_dims(y_train, -1),
            epochs=10,
            batch_size=1,
            validation_data=(x_valid, np.expand_dims(y_valid, -1)))
  </code></pre>
  
  <p>the error
  <code>ValueError: Error when checking model target: expected dense_45 to have 2 dimensions, but got array with shape (1055, 3570, 1)</code></p>
  
  <p>How should I change the code?</p>