Generally, for any machine learning/deep learning system, we compute a loss, $$L = l(x, \theta, y)$$ which is a function of the input feature vector $$x$$ (after activation), model parameters $$\theta$$ (which actually is encoded in $$x$$ since $$x$$ is the final feature vector), and $$y$$, the label. Now, to learn, we compute $$\frac{\partial L}{\partial \theta}$$ and update the parameters, $$\theta$$ using this.

However, pytorch (and other libraries) also provide a way to hook the gradients of the feature vectors as well, (torch.tensor.register_hook()). Let us say I hook this to $$x$$. What exactly is this gradient? I believe that this is $$\frac{\partial L}{\partial x}$$. And if so, what is the use of this gradient? What information can this gradient give us? Have there been any works on exploring this gradient and its uses? Any references would be appreciated. Thanks!

• just a quick comment, not all ML algorithms are based on a gradient computation (decision trees for instance) Mar 4 at 5:27
• I think the gradient with respect to the raw data doesn't really tell you anything because the raw data cannot be changed. It only tells you that for the current iteration, to obtain the optimal mapping to the output, the input should have differed by this much. This can be seen by following the chain rule for standard neural networks for back propagation, you will encounter the derivative for dL/dz where z is the intermediate results. This will have the exact same interpretation as with dL/dx, just with the intermediate result z rather than the input x. Mar 4 at 20:43
• @timmy1691 yeah that was my interpretation, but I still wonder why this feature exists and if there is any use to it, thanks Mar 4 at 22:55
• @OlorinIstari this is because with respect to the chain rule, you need it to complete the chain rule, other than this, I don't think there is any use, if you consider using gradient descent for logistic regression or linear regression, that derivative is never calculated. It exists and can be calculated but is never calculated solely for the training of the model. Mar 5 at 10:08