title: How to return history of validation loss in Keras
body: <p>Using Anaconda Python 2.7 Windows 10.</p>
  
  <p>I am training a language model using the Keras exmaple:</p>
  
  <pre><code>print('Build model...')
  model = Sequential()
  model.add(GRU(512, return_sequences=True, input_shape=(maxlen, len(chars))))
  model.add(Dropout(0.2))
  model.add(GRU(512, return_sequences=False))
  model.add(Dropout(0.2))
  model.add(Dense(len(chars)))
  model.add(Activation('softmax'))
  
  model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
  
  def sample(a, temperature=1.0):
      # helper function to sample an index from a probability array
      a = np.log(a) / temperature
      a = np.exp(a) / np.sum(np.exp(a))
      return np.argmax(np.random.multinomial(1, a, 1))
  
  
  # train the model, output generated text after each iteration
  for iteration in range(1, 3):
      print()
      print('-' * 50)
      print('Iteration', iteration)
      model.fit(X, y, batch_size=128, nb_epoch=1)
      start_index = random.randint(0, len(text) - maxlen - 1)
  
      for diversity in [0.2, 0.5, 1.0, 1.2]:
          print()
          print('----- diversity:', diversity)
  
          generated = ''
          sentence = text[start_index: start_index + maxlen]
          generated += sentence
          print('----- Generating with seed: "' + sentence + '"')
          sys.stdout.write(generated)
  
          for i in range(400):
              x = np.zeros((1, maxlen, len(chars)))
              for t, char in enumerate(sentence):
                  x[0, t, char_indices[char]] = 1.
  
              preds = model.predict(x, verbose=0)[0]
              next_index = sample(preds, diversity)
              next_char = indices_char[next_index]
  
              generated += next_char
              sentence = sentence[1:] + next_char
  
              sys.stdout.write(next_char)
              sys.stdout.flush()
          print()
  </code></pre>
  
  <p>According to Keras documentation, the <code>model.fit</code> method returns a History callback, which has a history attribute containing the lists of successive losses and other metrics.</p>
  
  <pre><code>hist = model.fit(X, y, validation_split=0.2)
  print(hist.history)
  </code></pre>
  
  <p>After training my model, if I run <code>print(model.history)</code> I get the error:</p>
  
  <pre><code> AttributeError: 'Sequential' object has no attribute 'history'
  </code></pre>
  
  <p>How do I return my model history after training my model with the above code?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>The issue was that:</p>
  
  <p>The following had to first be defined:</p>
  
  <pre><code>from keras.callbacks import History 
  history = History()
  </code></pre>
  
  <p>The callbacks option had to be called</p>
  
  <pre><code>model.fit(X_train, Y_train, nb_epoch=5, batch_size=16, callbacks=[history])
  </code></pre>
  
  <p>But now if I print</p>
  
  <pre><code>print(history.History)
  </code></pre>
  
  <p>it returns</p>
  
  <pre><code>{}
  </code></pre>
  
  <p>even though I ran an iteration. </p>