Skip to content

Commit cf17aa8

Browse files
committed
fixing typos
1 parent b8a9b22 commit cf17aa8

File tree

5 files changed

+24
-32
lines changed

5 files changed

+24
-32
lines changed

README.md

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -212,21 +212,22 @@ for t in range(500):
212212
w2.grad.data.zero_()
213213

214214
# Use autograd to compute the backward pass. This call will compute the
215-
# gradient of all loss with respect to all Variables with requires_grad=True.
215+
# gradient of loss with respect to all Variables with requires_grad=True.
216216
# After this call w1.data and w2.data will be Variables holding the gradient
217217
# of the loss with respect to w1 and w2 respectively.
218218
loss.backward()
219219

220-
# Update weights using gradient descent: w1.grad and w2.grad are Variables
221-
# and w1.grad.data and w2.grad.data are Tensors.
220+
# Update weights using gradient descent; w1.data and w2.data are Tensors,
221+
# w1.grad and w2.grad are Variables and w1.grad.data and w2.grad.data are
222+
# Tensors.
222223
w1.data -= learning_rate * w1.grad.data
223224
w2.data -= learning_rate * w2.grad.data
224225
```
225226

226227
## PyTorch: Defining new autograd functions
227228
Under the hood, each primitive autograd operator is really two functions that
228-
operate on Tensors. The *forward* function computes output Tensors from input
229-
Tensors. The *backward* function recieves the gradient of the output Tensors
229+
operate on Tensors. The **forward** function computes output Tensors from input
230+
Tensors. The **backward** function receives the gradient of the output Tensors
230231
with respect to some scalar value, and computes the gradient of the input Tensors
231232
with respect to that same scalar value.
232233

@@ -249,12 +250,11 @@ class MyReLU(torch.autograd.Function):
249250
torch.autograd.Function and implementing the forward and backward passes
250251
which operate on Tensors.
251252
"""
252-
253253
def forward(self, input):
254254
"""
255255
In the forward pass we receive a Tensor containing the input and return a
256-
Tensor containing the output. You can save cache arbitrary Tensors for use
257-
in the backward pass using the save_for_backward method.
256+
Tensor containing the output. You can cache arbitrary Tensors for use in the
257+
backward pass using the save_for_backward method.
258258
"""
259259
self.save_for_backward(input)
260260
return input.clamp(min=0)
@@ -279,14 +279,10 @@ dtype = torch.FloatTensor
279279
N, D_in, H, D_out = 64, 1000, 100, 10
280280

281281
# Create random Tensors to hold input and outputs, and wrap them in Variables.
282-
# Setting requires_grad=False indicates that we do not need to compute gradients
283-
# with respect to these Variables during the backward pass.
284282
x = Variable(torch.randn(N, D_in).type(dtype), requires_grad=False)
285283
y = Variable(torch.randn(N, D_out).type(dtype), requires_grad=False)
286284

287285
# Create random Tensors for weights, and wrap them in Variables.
288-
# Setting requires_grad=True indicates that we want to compute gradients with
289-
# respect to these Variables during the backward pass.
290286
w1 = Variable(torch.randn(D_in, H).type(dtype), requires_grad=True)
291287
w2 = Variable(torch.randn(H, D_out).type(dtype), requires_grad=True)
292288

@@ -423,7 +419,7 @@ In TensorFlow, packages like [Keras](https://github.com/fchollet/keras),
423419
and [TFLearn](http://tflearn.org/) provide higher-level abstractions over
424420
raw computational graphs that are useful for building neural networks.
425421

426-
In PyTorch, the `nn` package serves this same purpose. The nn package defines a set of
422+
In PyTorch, the `nn` package serves this same purpose. The `nn` package defines a set of
427423
**Modules**, which are roughly equivalent to neural network layers. A Module receives
428424
input Variables and computes output Variables, but may also hold internal state such as
429425
Variables containing learnable parameters. The `nn` package also defines a set of useful
@@ -522,9 +518,9 @@ model = torch.nn.Sequential(
522518
loss_fn = torch.nn.MSELoss(size_average=False)
523519

524520
# Use the optim package to define an Optimizer that will update the weights of
525-
# the model for us. Here we will use stochastic gradient descent (SGD), but the
526-
# optim package contains many other optimization algoriths. The first argument
527-
# to the Adam constructor tells the optimizer which Variables it should update.
521+
# the model for us. Here we will use Adam; the optim package contains many other
522+
# optimization algoriths. The first argument to the Adam constructor tells the
523+
# optimizer which Variables it should update.
528524
learning_rate = 1e-4
529525
optimizer = torch.optim.Adam(model.parameters(), lr=learning_rate)
530526
for t in range(500):

README_raw.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ network:
100100

101101
## PyTorch: Defining new autograd functions
102102
Under the hood, each primitive autograd operator is really two functions that
103-
operate on Tensors. The *forward* function computes output Tensors from input
104-
Tensors. The *backward* function recieves the gradient of the output Tensors
103+
operate on Tensors. The **forward** function computes output Tensors from input
104+
Tensors. The **backward** function receives the gradient of the output Tensors
105105
with respect to some scalar value, and computes the gradient of the input Tensors
106106
with respect to that same scalar value.
107107

@@ -166,7 +166,7 @@ In TensorFlow, packages like [Keras](https://github.com/fchollet/keras),
166166
and [TFLearn](http://tflearn.org/) provide higher-level abstractions over
167167
raw computational graphs that are useful for building neural networks.
168168

169-
In PyTorch, the `nn` package serves this same purpose. The nn package defines a set of
169+
In PyTorch, the `nn` package serves this same purpose. The `nn` package defines a set of
170170
**Modules**, which are roughly equivalent to neural network layers. A Module receives
171171
input Variables and computes output Variables, but may also hold internal state such as
172172
Variables containing learnable parameters. The `nn` package also defines a set of useful

autograd/two_layer_net_autograd.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@
5656
w2.grad.data.zero_()
5757

5858
# Use autograd to compute the backward pass. This call will compute the
59-
# gradient of all loss with respect to all Variables with requires_grad=True.
59+
# gradient of loss with respect to all Variables with requires_grad=True.
6060
# After this call w1.data and w2.data will be Variables holding the gradient
6161
# of the loss with respect to w1 and w2 respectively.
6262
loss.backward()
6363

64-
# Update weights using gradient descent: w1.grad and w2.grad are Variables
65-
# and w1.grad.data and w2.grad.data are Tensors.
64+
# Update weights using gradient descent; w1.data and w2.data are Tensors,
65+
# w1.grad and w2.grad are Variables and w1.grad.data and w2.grad.data are
66+
# Tensors.
6667
w1.data -= learning_rate * w1.grad.data
6768
w2.data -= learning_rate * w2.grad.data

autograd/two_layer_net_custom_function.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ class MyReLU(torch.autograd.Function):
1818
torch.autograd.Function and implementing the forward and backward passes
1919
which operate on Tensors.
2020
"""
21-
2221
def forward(self, input):
2322
"""
2423
In the forward pass we receive a Tensor containing the input and return a
25-
Tensor containing the output. You can save cache arbitrary Tensors for use
26-
in the backward pass using the save_for_backward method.
24+
Tensor containing the output. You can cache arbitrary Tensors for use in the
25+
backward pass using the save_for_backward method.
2726
"""
2827
self.save_for_backward(input)
2928
return input.clamp(min=0)
@@ -48,14 +47,10 @@ def backward(self, grad_output):
4847
N, D_in, H, D_out = 64, 1000, 100, 10
4948

5049
# Create random Tensors to hold input and outputs, and wrap them in Variables.
51-
# Setting requires_grad=False indicates that we do not need to compute gradients
52-
# with respect to these Variables during the backward pass.
5350
x = Variable(torch.randn(N, D_in).type(dtype), requires_grad=False)
5451
y = Variable(torch.randn(N, D_out).type(dtype), requires_grad=False)
5552

5653
# Create random Tensors for weights, and wrap them in Variables.
57-
# Setting requires_grad=True indicates that we want to compute gradients with
58-
# respect to these Variables during the backward pass.
5954
w1 = Variable(torch.randn(D_in, H).type(dtype), requires_grad=True)
6055
w2 = Variable(torch.randn(H, D_out).type(dtype), requires_grad=True)
6156

nn/two_layer_net_optim.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
loss_fn = torch.nn.MSELoss(size_average=False)
3131

3232
# Use the optim package to define an Optimizer that will update the weights of
33-
# the model for us. Here we will use stochastic gradient descent (SGD), but the
34-
# optim package contains many other optimization algoriths. The first argument
35-
# to the Adam constructor tells the optimizer which Variables it should update.
33+
# the model for us. Here we will use Adam; the optim package contains many other
34+
# optimization algoriths. The first argument to the Adam constructor tells the
35+
# optimizer which Variables it should update.
3636
learning_rate = 1e-4
3737
optimizer = torch.optim.Adam(model.parameters(), lr=learning_rate)
3838
for t in range(500):

0 commit comments

Comments
 (0)