Created
April 24, 2024 04:10
-
-
Save mahimairaja/02a12c60136c72dcdd790ac72dc6fe2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
x = torch.ones(3) # Input Tensor | |
y = torch.zeros(2) # Expected Output Tensor | |
w = torch.randn(3, 2, requires_grad=True) # Weight matrix | |
b = torch.randn(2 , requires_grad=True) # Bias | |
z = torch.matmul(x, w) + b # Calculated output | |
loss = torch.nn.functional.binary_cross_entropy_with_logits(z, y) | |
loss.backward() # Computes the gradient of loss w.r.t w and b | |
print(w.grad) | |
print(b.grad) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment