Skip to content

Commit 2dddbd9

Browse files
fzalkowholly1238
andauthored
Minor fixes in tutorial on basics (file names, spaces, links) (pytorch#1638)
* tensorqs_tutorial -> tensors_tutorial * autogradqs_tutorial -> autograds_tutorial * spaces * fix link to torch.Tensor.scatter_ documentation * undo file renaming * autogradqs_tutorial.py in readme Co-authored-by: Holly Sweeney <[email protected]>
1 parent c2c30b4 commit 2dddbd9

10 files changed

+140
-151
lines changed

beginner_source/basics/README.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Learn the Basics
99
Quickstart
1010
https://pytorch.org/tutorials/beginner/basics/quickstart_tutorial.html
1111

12-
3. tensors_tutorial.py
12+
3. tensorqs_tutorial.py
1313
Tensors
1414
https://pytorch.org/tutorials/beginner/basics/tensor_tutorial.html
1515

@@ -25,7 +25,7 @@ Learn the Basics
2525
Building the Neural Network
2626
https://pytorch.org/tutorials/beginner/basics/buildmodel_tutorial.html
2727

28-
7. autograd_tutorial.py
28+
7. autogradqs_tutorial.py
2929
Automatic Differentiation with torch.autograd_tutorial
3030
https://pytorch.org/tutorials/beginner/basics/autograd_tutorial.html
3131

@@ -36,4 +36,3 @@ Learn the Basics
3636
9. saveloadrun_tutorial.py
3737
Save and Load the Model
3838
https://pytorch.org/tutorials/beginner/basics/saveloadrun_tutorial.html
39-

beginner_source/basics/autogradqs_tutorial.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
`Learn the Basics <intro.html>`_ ||
3-
`Quickstart <quickstart_tutorial.html>`_ ||
4-
`Tensors <tensorqs_tutorial.html>`_ ||
3+
`Quickstart <quickstart_tutorial.html>`_ ||
4+
`Tensors <tensorqs_tutorial.html>`_ ||
55
`Datasets & DataLoaders <data_tutorial.html>`_ ||
66
`Transforms <transforms_tutorial.html>`_ ||
77
`Build Model <buildmodel_tutorial.html>`_ ||
@@ -64,7 +64,7 @@
6464
# documentation <https://pytorch.org/docs/stable/autograd.html#function>`__.
6565
#
6666

67-
print('Gradient function for z =',z.grad_fn)
67+
print('Gradient function for z =', z.grad_fn)
6868
print('Gradient function for loss =', loss.grad_fn)
6969

7070
######################################################################
@@ -240,4 +240,3 @@
240240
# Further Reading
241241
# ~~~~~~~~~~~~~~~~~
242242
# - `Autograd Mechanics <https://pytorch.org/docs/stable/notes/autograd.html>`_
243-

beginner_source/basics/buildmodel_tutorial.py

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
`Learn the Basics <intro.html>`_ ||
3-
`Quickstart <quickstart_tutorial.html>`_ ||
3+
`Quickstart <quickstart_tutorial.html>`_ ||
44
`Tensors <tensorqs_tutorial.html>`_ ||
55
`Datasets & DataLoaders <data_tutorial.html>`_ ||
66
`Transforms <transforms_tutorial.html>`_ ||
@@ -12,9 +12,9 @@
1212
Build the Neural Network
1313
===================
1414
15-
Neural networks comprise of layers/modules that perform operations on data.
16-
The `torch.nn <https://pytorch.org/docs/stable/nn.html>`_ namespace provides all the building blocks you need to
17-
build your own neural network. Every module in PyTorch subclasses the `nn.Module <https://pytorch.org/docs/stable/generated/torch.nn.Module.html>`_.
15+
Neural networks comprise of layers/modules that perform operations on data.
16+
The `torch.nn <https://pytorch.org/docs/stable/nn.html>`_ namespace provides all the building blocks you need to
17+
build your own neural network. Every module in PyTorch subclasses the `nn.Module <https://pytorch.org/docs/stable/generated/torch.nn.Module.html>`_.
1818
A neural network is a module itself that consists of other modules (layers). This nested structure allows for
1919
building and managing complex architectures easily.
2020
@@ -32,20 +32,20 @@
3232
#############################################
3333
# Get Device for Training
3434
# -----------------------
35-
# We want to be able to train our model on a hardware accelerator like the GPU,
36-
# if it is available. Let's check to see if
37-
# `torch.cuda <https://pytorch.org/docs/stable/notes/cuda.html>`_ is available, else we
38-
# continue to use the CPU.
35+
# We want to be able to train our model on a hardware accelerator like the GPU,
36+
# if it is available. Let's check to see if
37+
# `torch.cuda <https://pytorch.org/docs/stable/notes/cuda.html>`_ is available, else we
38+
# continue to use the CPU.
3939

4040
device = 'cuda' if torch.cuda.is_available() else 'cpu'
4141
print('Using {} device'.format(device))
4242

4343
##############################################
4444
# Define the Class
4545
# -------------------------
46-
# We define our neural network by subclassing ``nn.Module``, and
46+
# We define our neural network by subclassing ``nn.Module``, and
4747
# initialize the neural network layers in ``__init__``. Every ``nn.Module`` subclass implements
48-
# the operations on input data in the ``forward`` method.
48+
# the operations on input data in the ``forward`` method.
4949

5050
class NeuralNetwork(nn.Module):
5151
def __init__(self):
@@ -66,7 +66,7 @@ def forward(self, x):
6666
return logits
6767

6868
##############################################
69-
# We create an instance of ``NeuralNetwork``, and move it to the ``device``, and print
69+
# We create an instance of ``NeuralNetwork``, and move it to the ``device``, and print
7070
# its structure.
7171

7272
model = NeuralNetwork().to(device)
@@ -75,14 +75,14 @@ def forward(self, x):
7575

7676
##############################################
7777
# To use the model, we pass it the input data. This executes the model's ``forward``,
78-
# along with some `background operations <https://github.com/pytorch/pytorch/blob/270111b7b611d174967ed204776985cefca9c144/torch/nn/modules/module.py#L866>`_.
78+
# along with some `background operations <https://github.com/pytorch/pytorch/blob/270111b7b611d174967ed204776985cefca9c144/torch/nn/modules/module.py#L866>`_.
7979
# Do not call ``model.forward()`` directly!
80-
#
80+
#
8181
# Calling the model on the input returns a 10-dimensional tensor with raw predicted values for each class.
8282
# We get the prediction probabilities by passing it through an instance of the ``nn.Softmax`` module.
8383

8484
X = torch.rand(1, 28, 28, device=device)
85-
logits = model(X)
85+
logits = model(X)
8686
pred_probab = nn.Softmax(dim=1)(logits)
8787
y_pred = pred_probab.argmax(1)
8888
print(f"Predicted class: {y_pred}")
@@ -97,26 +97,26 @@ def forward(self, x):
9797
# Model Layers
9898
# -------------------------
9999
#
100-
# Let's break down the layers in the FashionMNIST model. To illustrate it, we
101-
# will take a sample minibatch of 3 images of size 28x28 and see what happens to it as
102-
# we pass it through the network.
100+
# Let's break down the layers in the FashionMNIST model. To illustrate it, we
101+
# will take a sample minibatch of 3 images of size 28x28 and see what happens to it as
102+
# we pass it through the network.
103103

104104
input_image = torch.rand(3,28,28)
105105
print(input_image.size())
106106

107107
##################################################
108108
# nn.Flatten
109109
# ^^^^^^^^^^^^^^^^^^^^^^
110-
# We initialize the `nn.Flatten <https://pytorch.org/docs/stable/generated/torch.nn.Flatten.html>`_
110+
# We initialize the `nn.Flatten <https://pytorch.org/docs/stable/generated/torch.nn.Flatten.html>`_
111111
# layer to convert each 2D 28x28 image into a contiguous array of 784 pixel values (
112112
# the minibatch dimension (at dim=0) is maintained).
113-
113+
114114
flatten = nn.Flatten()
115115
flat_image = flatten(input_image)
116116
print(flat_image.size())
117117

118118
##############################################
119-
# nn.Linear
119+
# nn.Linear
120120
# ^^^^^^^^^^^^^^^^^^^^^^
121121
# The `linear layer <https://pytorch.org/docs/stable/generated/torch.nn.Linear.html>`_
122122
# is a module that applies a linear transformation on the input using its stored weights and biases.
@@ -145,7 +145,7 @@ def forward(self, x):
145145
#################################################
146146
# nn.Sequential
147147
# ^^^^^^^^^^^^^^^^^^^^^^
148-
# `nn.Sequential <https://pytorch.org/docs/stable/generated/torch.nn.Sequential.html>`_ is an ordered
148+
# `nn.Sequential <https://pytorch.org/docs/stable/generated/torch.nn.Sequential.html>`_ is an ordered
149149
# container of modules. The data is passed through all the modules in the same order as defined. You can use
150150
# sequential containers to put together a quick network like ``seq_modules``.
151151

@@ -162,9 +162,9 @@ def forward(self, x):
162162
# nn.Softmax
163163
# ^^^^^^^^^^^^^^^^^^^^^^
164164
# The last linear layer of the neural network returns `logits` - raw values in [-\infty, \infty] - which are passed to the
165-
# `nn.Softmax <https://pytorch.org/docs/stable/generated/torch.nn.Softmax.html>`_ module. The logits are scaled to values
166-
# [0, 1] representing the model's predicted probabilities for each class. ``dim`` parameter indicates the dimension along
167-
# which the values must sum to 1.
165+
# `nn.Softmax <https://pytorch.org/docs/stable/generated/torch.nn.Softmax.html>`_ module. The logits are scaled to values
166+
# [0, 1] representing the model's predicted probabilities for each class. ``dim`` parameter indicates the dimension along
167+
# which the values must sum to 1.
168168

169169
softmax = nn.Softmax(dim=1)
170170
pred_probab = softmax(logits)
@@ -173,12 +173,12 @@ def forward(self, x):
173173
#################################################
174174
# Model Parameters
175175
# -------------------------
176-
# Many layers inside a neural network are *parameterized*, i.e. have associated weights
177-
# and biases that are optimized during training. Subclassing ``nn.Module`` automatically
178-
# tracks all fields defined inside your model object, and makes all parameters
179-
# accessible using your model's ``parameters()`` or ``named_parameters()`` methods.
180-
#
181-
# In this example, we iterate over each parameter, and print its size and a preview of its values.
176+
# Many layers inside a neural network are *parameterized*, i.e. have associated weights
177+
# and biases that are optimized during training. Subclassing ``nn.Module`` automatically
178+
# tracks all fields defined inside your model object, and makes all parameters
179+
# accessible using your model's ``parameters()`` or ``named_parameters()`` methods.
180+
#
181+
# In this example, we iterate over each parameter, and print its size and a preview of its values.
182182
#
183183

184184

@@ -195,6 +195,3 @@ def forward(self, x):
195195
# Further Reading
196196
# --------------
197197
# - `torch.nn API <https://pytorch.org/docs/stable/nn.html>`_
198-
199-
200-

beginner_source/basics/data_tutorial.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
`Learn the Basics <intro.html>`_ ||
3-
`Quickstart <quickstart_tutorial.html>`_ ||
3+
`Quickstart <quickstart_tutorial.html>`_ ||
44
`Tensors <tensorqs_tutorial.html>`_ ||
55
**Datasets & DataLoaders** ||
66
`Transforms <transforms_tutorial.html>`_ ||
@@ -22,7 +22,7 @@
2222
# ``Dataset`` stores the samples and their corresponding labels, and ``DataLoader`` wraps an iterable around
2323
# the ``Dataset`` to enable easy access to the samples.
2424
#
25-
# PyTorch domain libraries provide a number of pre-loaded datasets (such as FashionMNIST) that
25+
# PyTorch domain libraries provide a number of pre-loaded datasets (such as FashionMNIST) that
2626
# subclass ``torch.utils.data.Dataset`` and implement functions specific to the particular data.
2727
# They can be used to prototype and benchmark your model. You can find them
2828
# here: `Image Datasets <https://pytorch.org/vision/stable/datasets.html>`_,
@@ -71,7 +71,7 @@
7171
# Iterating and Visualizing the Dataset
7272
# -----------------
7373
#
74-
# We can index ``Datasets`` manually like a list: ``training_data[index]``.
74+
# We can index ``Datasets`` manually like a list: ``training_data[index]``.
7575
# We use ``matplotlib`` to visualize some samples in our training data.
7676

7777
labels_map = {
@@ -111,9 +111,9 @@
111111
# Creating a Custom Dataset for your files
112112
# ---------------------------------------------------
113113
#
114-
# A custom Dataset class must implement three functions: `__init__`, `__len__`, and `__getitem__`.
115-
# Take a look at this implementation; the FashionMNIST images are stored
116-
# in a directory ``img_dir``, and their labels are stored separately in a CSV file ``annotations_file``.
114+
# A custom Dataset class must implement three functions: `__init__`, `__len__`, and `__getitem__`.
115+
# Take a look at this implementation; the FashionMNIST images are stored
116+
# in a directory ``img_dir``, and their labels are stored separately in a CSV file ``annotations_file``.
117117
#
118118
# In the next sections, we'll break down what's happening in each of these functions.
119119

@@ -148,8 +148,8 @@ def __getitem__(self, idx):
148148
# ^^^^^^^^^^^^^^^^^^^^
149149
#
150150
# The __init__ function is run once when instantiating the Dataset object. We initialize
151-
# the directory containing the images, the annotations file, and both transforms (covered
152-
# in more detail in the next section).
151+
# the directory containing the images, the annotations file, and both transforms (covered
152+
# in more detail in the next section).
153153
#
154154
# The labels.csv file looks like: ::
155155
#
@@ -183,9 +183,9 @@ def __len__(self):
183183
# __getitem__
184184
# ^^^^^^^^^^^^^^^^^^^^
185185
#
186-
# The __getitem__ function loads and returns a sample from the dataset at the given index ``idx``.
187-
# Based on the index, it identifies the image's location on disk, converts that to a tensor using ``read_image``, retrieves the
188-
# corresponding label from the csv data in ``self.img_labels``, calls the transform functions on them (if applicable), and returns the
186+
# The __getitem__ function loads and returns a sample from the dataset at the given index ``idx``.
187+
# Based on the index, it identifies the image's location on disk, converts that to a tensor using ``read_image``, retrieves the
188+
# corresponding label from the csv data in ``self.img_labels``, calls the transform functions on them (if applicable), and returns the
189189
# tensor image and corresponding label in a tuple.
190190

191191
def __getitem__(self, idx):
@@ -207,7 +207,7 @@ def __getitem__(self, idx):
207207
#################################################################
208208
# Preparing your data for training with DataLoaders
209209
# -------------------------------------------------
210-
# The ``Dataset`` retrieves our dataset's features and labels one sample at a time. While training a model, we typically want to
210+
# The ``Dataset`` retrieves our dataset's features and labels one sample at a time. While training a model, we typically want to
211211
# pass samples in "minibatches", reshuffle the data at every epoch to reduce model overfitting, and use Python's ``multiprocessing`` to
212212
# speed up data retrieval.
213213
#
@@ -224,7 +224,7 @@ def __getitem__(self, idx):
224224
#
225225
# We have loaded that dataset into the ``DataLoader`` and can iterate through the dataset as needed.
226226
# Each iteration below returns a batch of ``train_features`` and ``train_labels`` (containing ``batch_size=64`` features and labels respectively).
227-
# Because we specified ``shuffle=True``, after we iterate over all batches the data is shuffled (for finer-grained control over
227+
# Because we specified ``shuffle=True``, after we iterate over all batches the data is shuffled (for finer-grained control over
228228
# the data loading order, take a look at `Samplers <https://pytorch.org/docs/stable/data.html#data-loading-order-and-sampler>`_).
229229

230230
# Display image and label.
@@ -245,5 +245,3 @@ def __getitem__(self, idx):
245245
# Further Reading
246246
# --------------
247247
# - `torch.utils.data API <https://pytorch.org/docs/stable/data.html>`_
248-
249-

beginner_source/basics/intro.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
**Learn the Basics** ||
3-
`Quickstart <quickstart_tutorial.html>`_ ||
4-
`Tensors <tensorqs_tutorial.html>`_ ||
3+
`Quickstart <quickstart_tutorial.html>`_ ||
4+
`Tensors <tensorqs_tutorial.html>`_ ||
55
`Datasets & DataLoaders <data_tutorial.html>`_ ||
66
`Transforms <transforms_tutorial.html>`_ ||
77
`Build Model <buildmodel_tutorial.html>`_ ||
@@ -12,20 +12,20 @@
1212
Learn the Basics
1313
===================
1414
15-
Authors:
15+
Authors:
1616
`Suraj Subramanian <https://github.com/suraj813>`_,
17-
`Seth Juarez <https://github.com/sethjuarez/>`_,
18-
`Cassie Breviu <https://github.com/cassieview/>`_,
19-
`Dmitry Soshnikov <https://soshnikov.com/>`_,
20-
`Ari Bornstein <https://github.com/aribornstein/>`_
17+
`Seth Juarez <https://github.com/sethjuarez/>`_,
18+
`Cassie Breviu <https://github.com/cassieview/>`_,
19+
`Dmitry Soshnikov <https://soshnikov.com/>`_,
20+
`Ari Bornstein <https://github.com/aribornstein/>`_
2121
22-
Most machine learning workflows involve working with data, creating models, optimizing model
23-
parameters, and saving the trained models. This tutorial introduces you to a complete ML workflow
22+
Most machine learning workflows involve working with data, creating models, optimizing model
23+
parameters, and saving the trained models. This tutorial introduces you to a complete ML workflow
2424
implemented in PyTorch, with links to learn more about each of these concepts.
2525
26-
We'll use the FashionMNIST dataset to train a neural network that predicts if an input image belongs
27-
to one of the following classes: T-shirt/top, Trouser, Pullover, Dress, Coat, Sandal, Shirt, Sneaker,
28-
Bag, or Ankle boot.
26+
We'll use the FashionMNIST dataset to train a neural network that predicts if an input image belongs
27+
to one of the following classes: T-shirt/top, Trouser, Pullover, Dress, Coat, Sandal, Shirt, Sneaker,
28+
Bag, or Ankle boot.
2929
3030
`This tutorial assumes a basic familiarity with Python and Deep Learning concepts.`
3131
@@ -34,12 +34,12 @@
3434
------------------
3535
You can run this tutorial in a couple of ways:
3636
37-
- **In the cloud**: This is the easiest way to get started! Each section has a "Run in Microsoft Learn" link at the top, which opens an integrated notebook in Microsoft Learn with the code in a fully-hosted environment.
37+
- **In the cloud**: This is the easiest way to get started! Each section has a "Run in Microsoft Learn" link at the top, which opens an integrated notebook in Microsoft Learn with the code in a fully-hosted environment.
3838
- **Locally**: This option requires you to setup PyTorch and TorchVision first on your local machine (`installation instructions <https://pytorch.org/get-started/locally/>`_). Download the notebook or copy the code into your favorite IDE.
3939
4040
4141
How to Use this Guide
42-
-----------------
42+
-----------------
4343
If you're familiar with other deep learning frameworks, check out the `0. Quickstart <quickstart_tutorial.html>`_ first
4444
to quickly familiarize yourself with PyTorch's API.
4545
@@ -51,4 +51,4 @@
5151
.. toctree::
5252
:hidden:
5353
54-
"""
54+
"""

0 commit comments

Comments
 (0)