Skip to content

Commit

Permalink
Improve docstring of History callback.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 363975387
  • Loading branch information
fchollet authored and tensorflower-gardener committed Mar 19, 2021
1 parent ca9dcdd commit 2321565
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions keras/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1086,22 +1086,33 @@ def _finalize_progbar(self, logs, counter):
class History(Callback):
"""Callback that records events into a `History` object.
This callback is automatically applied to
every Keras model. The `History` object
gets returned by the `fit` method of models.
This callback gets added by default to
every call of `model.fit()`. That's how Keras keeps track of model training
history. You should never have to add this callback manually.
The `History` callback instance that is automatically added to `fit()`
gets returned at the end of `fit()`.
This `History` instance contains a `.history` attribute, which is a dict
that stores the logs of the model, such as the loss values for each
training epoch.
Example:
>>> model = tf.keras.models.Sequential([tf.keras.layers.Dense(10)])
>>> model.compile(tf.keras.optimizers.SGD(), loss='mse')
>>> history = model.fit(np.arange(100).reshape(5, 20), np.zeros(5),
... epochs=10)
>>> model.compile(optimizer='sgd', loss='mse')
>>> history = model.fit(np.zeros((32, 5)), np.zeros((32, 10)),
... epochs=5)
>>> # Inspect training parameters
>>> print(history.params)
{'verbose': 1, 'epochs': 10, 'steps': 1}
>>> # check the keys of history object
{'verbose': 1, 'epochs': 5, 'steps': 1}
>>> # Inspect the keys of the `history` dict
>>> print(history.history.keys())
dict_keys(['loss'])
>>> print(history.history.keys())
dict_keys(['loss'])
>>> # This is the loss history over the 5 training epochs
>>> history.history['loss']
[0.0, 0.0, 0.0, 0.0, 0.0]
"""

def __init__(self):
Expand Down

0 comments on commit 2321565

Please sign in to comment.