The fit method trains a compiled neural network by repeatedly processing mini-batches, calculating loss, and updating weights. Supply inputs and targets, choose the number of epochs and batch size, then inspect the returned training history. section 3.6.6 section 3.7
history <- model |> fit( inputs, #1 targets, #2 epochs = 5, #3 batch_size = 128 #4 )
A minimal R/Keras call passes training data, repeats training for five epochs, and uses batches of 128 examples for each update. section 3.6.6
Use the main arguments and outputs to control and inspect training:
- Pass inputs and targets as R or NumPy arrays, or use a TensorFlow Dataset. section 3.6.6
- Set epochs to control how many times the training loop iterates over the data. section 3.6.6
- Set batch_size to control how many examples contribute to each weight-update gradient. section 3.6.6
- Read the returned history object for per-epoch loss and metric values, or convert it to a data frame. section 3.6.6
- Monitor loss and metrics on validation data to assess performance on inputs excluded from training. section 3.7
Customizing the training step
When the default supervised-learning workflow is too restrictive, override Model's train_step() and continue calling fit(). A custom step can run the forward pass, compute loss, obtain gradients, update trainable weights, update metrics, and return logged values. This preserves conveniences such as callbacks, performance optimizations, and distributed-training support while changing the learning algorithm. section 7.4 section 7.4.4

