title: Using fit_generator in Keras Model
body: <p>I'm trying to train a neural network using Keras and Tensorflow backend. My <code>X</code> is text descriptions which I have processed and transformed into sequences. Now, my <code>y</code> is a sparse matrix since it's a multi-label classification and I have many output classes.</p>
  
  <pre><code>&gt;&gt;&gt; y
  &lt;30405x3387 sparse matrix of type '&lt;type 'numpy.int64'&gt;'
      with 54971 stored elements in Compressed Sparse Row format&gt;
  </code></pre>
  
  <p>To train the model, I tried defining a batch generator:</p>
  
  <pre><code>def batch_generator(x, y, batch_size=32):
      n_batches_per_epoch = x.shape[0]//batch_size
      for i in range(n_batches_per_epoch):
          index_batch = range(x.shape[0])[batch_size*i:batch_size*(i+1)]       
          x_batch = x[index_batch,:]
          y_batch = y[index_batch,:].todense()
          yield x_batch, np.array(y_batch)
  </code></pre>
  
  <p>I've divided my data as:</p>
  
  <pre><code>x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=42)
  </code></pre>
  
  <p>I define my model as:</p>
  
  <pre><code>model = Sequential()
  # Create architecture, add some layers.
  model.add(Dense(num_classes))
  model.add(Activation('sigmoid'))
  model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
  </code></pre>
  
  <p>And I'm training my model as:</p>
  
  <pre><code>model.fit_generator(generator=batch_generator(x_train, y_train), steps_per_epoch=(x_train[0]/32), epochs=200, callbacks=the_callbacks)
  </code></pre>
  
  <p>But my model starts with around 55% accuracy and it quickly (in 2 or 3 steps) becomes 99.95%, which makes no sense at all. Am I doing something wrong?</p>