I searched for the backpropagation code in keras github but I couldn't find it. Searched model.fit() Please help. Thank you


1 Answer 1


In Keras, the backpropagation algorithm is not explicitly written as a separate function or method. Instead, it's implemented as part of the training process when we use model.fit(). The backpropagation algorithm is handled by TensorFlow's automatic differentiation and optimization features. When using Keras, we typically define our model architecture, compile the model with a chosen optimizer and loss function, and then train the model using model.fit(). The optimizer and loss function are the key components that enable the backpropagation process.

let's say if we are using the popular Adam optimizer, Keras relies on TensorFlow's tf.keras.optimizers.Adam implementation. The backpropagation process is handled by the optimizer when it updates the model weights based on the gradients of the loss function with respect to the weights.

  • $\begingroup$ Decent information. Even better would be to show the auto-diff code for one of the examples you cite. $\endgroup$ Apr 15, 2023 at 16:49
  • $\begingroup$ Do you mean I should demonstrate the backpropagation process? $\endgroup$ Apr 15, 2023 at 18:18
  • $\begingroup$ I'm suggesting to answer the question by showing the where the auto-diff source is $\endgroup$ Apr 16, 2023 at 4:41
  • $\begingroup$ @Rohit Singh Ok backprop is handled by the keras.optimizers.Optimizer , but that will have the backdrop code (even though not as a separate method) right, I'm asking for that. $\endgroup$
    – vivian.ai
    Apr 19, 2023 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.