diff --git a/beginner_source/examples_autograd/polynomial_autograd.py b/beginner_source/examples_autograd/polynomial_autograd.py index d33ca8bcb90..b8353fc598e 100755 --- a/beginner_source/examples_autograd/polynomial_autograd.py +++ b/beginner_source/examples_autograd/polynomial_autograd.py @@ -2,8 +2,8 @@ PyTorch: Tensors and autograd ------------------------------- -A third order polynomial, trained to predict :math:`y=\sin(x)` from :math:`-\pi` -to :math:`\pi` by minimizing squared Euclidean distance. +A third order polynomial, trained to predict :math:`y=e^x` from :math:`-1` +to :math:`1` by minimizing squared Euclidean distance. This implementation computes the forward pass using operations on PyTorch Tensors, and uses PyTorch autograd to compute gradients. @@ -14,7 +14,6 @@ holding the gradient of ``x`` with respect to some scalar value. """ import torch -import math # We want to be able to train our model on an `accelerator `__ # such as CUDA, MPS, MTIA, or XPU. If the current accelerator is available, we will use it. Otherwise, we use the CPU. @@ -39,7 +38,6 @@ c = torch.randn((), dtype=dtype, requires_grad=True) d = torch.randn((), dtype=dtype, requires_grad=True) -initial_loss = 1. learning_rate = 1e-5 for t in range(5000): # Forward pass: compute predicted y using operations on Tensors. @@ -50,7 +48,7 @@ # loss.item() gets the scalar value held in the loss. loss = (y_pred - y).pow(2).sum() - # Calculare initial loss, so we can report loss relative to it + # Calculate initial loss, so we can report loss relative to it if t==0: initial_loss=loss.item()