Errata

AI and ML for Coders in PyTorch

Errata for AI and ML for Coders in PyTorch

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

Color key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted By Date submitted Date corrected
Page Chapter 1
Multiple instances

While reading, I noticed a couple of minor inconsistencies that I thought might be helpful to point out for future editions or errata listings.

# Framework Reference Mismatch

In the section that reads:

"ML is a technique that enables us to do this, but to get started, we’ll need a framework—that’s where TensorFlow enters the picture. In the next section, we’ll take a look at what TensorFlow is and how to install it."

The following section actually discusses PyTorch, not TensorFlow, which may be confusing to readers expecting a TensorFlow introduction.

# Installation Instructions Reference

Similarly, in another section:

"With Python, there are many ways to install frameworks, but the default one supported by the TensorFlow team is pip. So, in your Python environment, installing PyTorch is as easy as using this:"

The transition from a TensorFlow-specific statement to PyTorch installation instructions may benefit from clarification or rephrasing to avoid ambiguity.

These are minor issues, but I thought they might be worth noting to maintain the excellent clarity and consistency throughout the book.

Thank you again for your work—it's been a valuable resource.

Note from the Author or Editor:
Please change the references to 'TensorFlow' to read 'PyTorch' instead

Stevin Wilson  Jul 29, 2025  Jan 23, 2026
Page Page 6 and 7
Page 6 4th Paragraph, Page 7 1st paragraph

The aforementioned paragraphs mention the use of the framework 'Tensorflow', however it should be 'Pytorch'

Note from the Author or Editor:
Thank you! The original edition of the book was for TensorFlow, and when revising for PyTorch we missed a couple of non-technical references. We'll ensure this is updated for future versions.

Zoheb Khan  Aug 06, 2025  Jan 23, 2026
Page page 9, subsection heading
bottom heading

Text: Installing Porch in Python
Issue: Possible typo, probably intended as "Torch"
Suggested fix: Change to "Installing Torch in Python"

Note from the Author or Editor:
Doing 'PyTorch', where somehow the yT was missing :)

Jørgen Lang  Sep 22, 2025  Jan 23, 2026
Page p62
continuation of code, line 5 (on p62)

Text: print(f'Test Set Accuracy: {100 * correct / total}%')
Issue: Previous prose, comment and code indicate evaluation of training data, *not* test data.
Suggested fix: change text to: print(f'Training Set Accuracy: {100 * correct / total}%')

Note from the Author or Editor:
Fixed

Jørgen Lang  Oct 17, 2025  Jan 23, 2026
Page 8
2nd para

Text: wrapped in the torchvision.models library.
Issue: missing formatting for "torchvision.models"
Suggested fix: Format as fixed-width ("code" in Atlas) analoguous to "torch.distributed" 2 paragraphs above.

Note from the Author or Editor:
Fixed

Jørgen Lang  Sep 22, 2025  Jan 23, 2026
Page 9
3rd last para

Text: With Python, there are many ways to install frameworks, but the default one supported by the TensorFlow team is pip.
Issue: needs PT instead of TF
Suggested fix: replace "TensorFlow" with "PyTorch"

Note from the Author or Editor:
Fixed

Jørgen Lang  Sep 22, 2025  Jan 23, 2026
Page 17
last para

Text: "You’ll see the word tensor a lot in ML; it gives the TensorFlow framework its name.
Issue: TF is superseeded by PyTorch in the book.
Suggested fix: Rephrase slghtly: "You’ll see the word tensor a lot in ML; it also gives the TensorFlow framework its name. OR just remove the TF part.

Note from the Author or Editor:
I said 'it even gives the TensorFlow framework its name' :)

Jørgen Lang  Oct 13, 2025  Jan 23, 2026
Page 18ff
multiple

In multiple instances the variable "y" is written in uppercase (as a capital "Y"), while in the remainder of the chapter it is consistently in lowercase.

I might be missing something here, but I suppose this has simply been overlooked in the copy editing process.

Note from the Author or Editor:
I think I got them all, changed to lowercase

Jørgen Lang  Oct 13, 2025  Jan 23, 2026
Page 28
4th para, 1st sentence

Text: If you remember, in Chapter 1 we had a Sequential model to specify that we had
many layers.
Issue: Misleading as we only had one layer.
Suggested fix: Rephrase as: If you remember, in Chapter 1 we had a Sequential model to specify how many layers we wanted to use.

Note from the Author or Editor:
Changed to:

If you remember, in #ch01_introduction_to_pytorch_1748548870019566 we used a Sequential model , whose name suggested we could use many layers in Sequence. In that case, we had only one layer, but now we’re using it to define multiple layers.

Jørgen Lang  Oct 14, 2025  Jan 23, 2026
Page 35
3rd para, 1st sentence

Text: We’ll also use the term epoch for a training cycle with all of the data
Issue: The term "epoch" is being used multiple times before its definition here.
Suggested fix: Move the definition to page 19 where it's first mentioned.

Note from the Author or Editor:
I'll keep it here, but also add a definition to p19

Jørgen Lang  Oct 15, 2025  Jan 23, 2026
Page 35
5th para (just above "Training the Neural Network"), 1st sentence

Text: This will simply call the train function we specified five times […]
Issue: missing format for "train"
Suggested fix: format "train" as "literal" (ID and others) or "code" (Atlas)

Note from the Author or Editor:
I made it 'code'

Jørgen Lang  Oct 15, 2025  Jan 23, 2026
Page 37
3rd code snippet

Text:
for batch, (X, y) in enumerate(dataloader):
# Compute prediction and loss
pred = model(X)
loss = loss_fn(pred, y)
accuracy = get_accuracy(pred, y)
# Backpropagation

Question:
Is the "# Backpropagation" comment really needed here?

Note from the Author or Editor:
No! :) -- Deleted

Jørgen Lang  Oct 15, 2025  Jan 23, 2026
Page 38
Code below "Exploring the Model Output"

Text:
" import matplotlib.pyplot as plt"
Issue:
First character of import statement is whitespace. Copy/paste from PDF will lead to indentation error.
Suggested fix: Remove whitespace and be happy ever after.

Note from the Author or Editor:
Fixed

Jørgen Lang  Oct 15, 2025  Jan 23, 2026
Page 39
2nd para, 2nd sentence

Text: The Softmax function gets the log() of the value, where log(1) is zero and
the log of any value less than one is a negative value.
Issue: The code example does not use Softmax() but argmax(1).
Question: Did you mean:
The argmax function gets the log() […]?

Note from the Author or Editor:
Should be argmax -- fixed

Jørgen Lang  Oct 15, 2025  Jan 23, 2026
Page 51
5th para

Text: Finally, these 128 are fed into the final layer (self.fc1) with 10 outputs—that represent the 10 classes.
Issue: Final layer in code is "self.fc2"
Suggested fix: Change "self.fc1" to "self.fc2"

Note from the Author or Editor:
Fixed

Jørgen Lang  Oct 16, 2025  Jan 23, 2026
Page 51
4th para, last sentence

Text: The output is 128, which is the same number of neurons we used in Chapter 2 for the deep neural network (DNN).
Issue: The term DNN is mentioned here for the first time. DNNs are introduced in ch10.
Suggested fix: Give a brief explanation here and point to chapter 10 for details.

Note from the Author or Editor:
Blurb added

Jørgen Lang  Oct 16, 2025  Jan 23, 2026
Page 54
various, 3 times

Text: "dense layers"
Issue: very likely a tensor flow relict, as in PyTorch the term is "fully connected (fc)" as introduced in chapter 1
Suggested fix: Change wording "dense layer" → "fully connected layer". Maybe add a note explaining they are almost synonymous.

Note from the Author or Editor:
Avoided 'Dense' and used 'fully connected' and 'Linear' as appropriate

Jørgen Lang  Oct 17, 2025  Jan 23, 2026
Page 58
2nd para, last sentence

Text: […] and the directory for validation is validation_dir, as specified earlier.
Issue: validation_dir has not yet been specified. Instead, on page 56 reader is referred to a later section.
Suggested fix: Not sure here. Maybe at least add code to specify validation_dir, so there is no broken context.

Note from the Author or Editor:
Added the code earlier, so we can see the validation_dir being created

Jørgen Lang  Oct 17, 2025  Jan 23, 2026
Page 59
3rd para

Text: The theory is that these will be activated feature maps […]
Issue: term "feature map" has not yet been introduced
Suggested fix: give a brief explanation or use an already introduced synonym

Note from the Author or Editor:
Blurb added

Jørgen Lang  Oct 17, 2025  Jan 23, 2026
Page 60
last para, 3rd sentence

Text: In the preceding code snippet, you’ve already downloaded the training and vali‐
dation datasets, […]
Issue 1: The preceeding code snippet shows the training of the CNN.
Issue 2: The validation dataset was not downloaded yet. Instead the reader was referred to this section.
Suggested fix: Add the missing code snippet or extend the code at the bottom of page 56.

Note from the Author or Editor:
The note had confusion text about validation and testing, so I just deleted it so the text will dlow better. FOr the code for downloading validation, it's in the notebook, so I noted that just below Figure 3-8

Jørgen Lang  Oct 17, 2025  Jan 23, 2026
Page 61
2nd para, last sentence

Text: Here, you’ll download some additional images for testing the model.
Issue: This contradicts the text on the previous page: ' In the preceding code snippet, you’ve already downloaded the training and validation datasets'.
Suggested fix: Not sure, what's best here. Maybe it's just a big misunderstanding on my side…… ¯\_(ツ)_/¯

Note from the Author or Editor:
You're right -- it's not very clearly worded. Better just to remove that sentence. Done :)

Jørgen Lang  Oct 17, 2025  Jan 23, 2026
Page 62
code, top

Text (2x):
images, labels = images.to(device),
labels.to(device).float()
Issue: causes an indentation error, probably done in typesetting for legibility
Suggested fix:
images = images.to(device)
labels = labels.to(device).float()

Note from the Author or Editor:
Fixed

Jørgen Lang  Oct 17, 2025  Jan 23, 2026
Page 63
3rd para, 2nd sentence

Text: I’ve provided a “Horses or Humans” notebook on GitHub that you can open directly in Colab.
Issue: "Colab" link points to TensorFlow-version of code
Suggested fix: Provide link to PyTorch version.

Note from the Author or Editor:
Fixed

Jørgen Lang  Oct 20, 2025  Jan 23, 2026
Page 65
2nd code snippet + text above

Text: If it’s greater than 0.5, we’re looking at a human
Code: class_name = "Human" if prediction.item() == 1 else "Horse"
Issue: code tests for equality, i.e. only "Human" if value exactly == 1.
Suggested fix: class_name = "Human" if prediction.item() >= 0.5 else "Horse"
unless output from prediction_item() is already normalized to 0 || 1.

Note from the Author or Editor:
Fixed

Jørgen Lang  Oct 20, 2025  Jan 23, 2026
Page 67
before last para

Text: missing?
Issue: Expected short explanation of transforms for validation data (2nd part of code)
Suggested fix: remove # Transforms for the validation data part or add short description of what it does.

Note from the Author or Editor:
Added blurb before code

Jørgen Lang  Oct 20, 2025  Jan 23, 2026
Page 73
code example, line1

Text: [5x whitespace]def load_image(image_path, transform):
Issue: Indentation error
Suggested fix: remove indentation on line1

Note from the Author or Editor:
fixed

Jørgen Lang  Oct 21, 2025  Jan 23, 2026
Page 74
2nd last para, 2nd sentence

Text: If you wanted to train a dataset to recognize […]
Issue: Possible confusion of terms
Suggested fix: replace "dataset" with, e.g., "model"

Note from the Author or Editor:
Fixed to 'model'

Jørgen Lang  Oct 21, 2025  Jan 23, 2026
PDF
Page 74
2nd last para, last sentence

Text: […] there’s a simple dataset you can use for this.
Issue:
- Link leads to datasets collection on laurencemoroney.com/datasets.html.
- Link on website does not work.
- Error message:
<Error>
<Code>NoSuchBucket</Code>
<Message>The specified bucket does not exist.</Message>
</Error>
Suggested fix: Reassign.

Note from the Author or Editor:
Link has been fixed

Jørgen Lang  Oct 21, 2025  Jan 23, 2026
Page 76
1st code snippet, line 6

Text: nn.Linear(1024, 3) # Final layer for binary classification
Issue: Comment references binary classification
Suggested fix: # Final layer for ternary classification
or similar

Note from the Author or Editor:
Removed 'binary'

Jørgen Lang  Oct 21, 2025  Jan 23, 2026
Page 77
3rd para

Text: If you explore this a little deeper, you can see that the file named scissors4.png had an output of –2.5582, –1.7362, 3.8465]
Issue: Missing opening square bracket
Suggested fix: –2.5582, –1.7362, 3.8465] → [–2.5582, –1.7362, 3.8465]

Note from the Author or Editor:
Fixed

Jørgen Lang  Oct 21, 2025  Jan 23, 2026
Page 79
figure

Text: A neural network with dropouts
Issue: figure does not show dropouts, instead all neurons and layers are fully connected as in previous figure - just with thicker lines
Suggested fix: replace with correct figure

Note from the Author or Editor:
This is an error, the diagram I provided wasn't redrawn correctly. Highlighting with the team

Jørgen Lang  Oct 21, 2025  Jan 23, 2026
Page 80
last para, 1st sentence

Text: Before we explore further scenarios, in Chapter 4, you’ll get an introduction to
PyTorch data, which is […]
Question: Did you mean "PyTorch data sets" as mentioned in the last sentence of the same paragraph?

Note from the Author or Editor:
rewrote to: "you’ll get an introduction to how to handle data in PyTorch. You'll explore the APIs that make it much easier for you to get access to data for training and testing your networks" -- which I think is clearer

Jørgen Lang  Oct 21, 2025  Jan 23, 2026
Page 84
2nd code example

Text: # Create the FashionMNIST dataset
Question: "Shouldn't this be # Create the FashionMNIST training dataset" in this context? Might be a misunderstanding on my side, of course.

Note from the Author or Editor:
You are correct, I edited to say 'training dataset'

Jørgen Lang  Oct 22, 2025  Jan 23, 2026
Page 86
4th para, 1st sentence

Text: While FakeData only gives image types, you could relatively easily create your own CustomData (as we looked at earlier) […]
Issue: earlier class was called "CustomDataset"
Suggested fix: change CustomData → CustomDataset

Note from the Author or Editor:
Changed to 'your own custom data (as a CustomDataSet like we saw earlier) to provide...'

Jørgen Lang  Oct 22, 2025  Jan 23, 2026
Page 86
last para

Text: Thankfully, when using datasets, you can generally do this with an easy and intuitive API.
Issue: ambiguous use of "datasets"
Question: Did you mean the general term or do you refer to the plural of the "Dataset" (imported from torch.utils.data) class here?

Note from the Author or Editor:
Changed to 'the datasets namespace' to match the code where we do datasets.FashionMNIST etc.

Jørgen Lang  Oct 22, 2025  Jan 23, 2026
Page 88
1st para, 1st sentence

Text: One more thing to consider when using custom splits is that the name random doesn’t mean […]
Issue: name is 'random_split'
Suggested fix: replace 'random' → 'random_split'

Note from the Author or Editor:
Fixed

Jørgen Lang  Oct 22, 2025  Jan 23, 2026
Page 88
5th para, 2nd sentence

Text: For example, batching, image augmentation, mapping to feature columns, and other such logic […]
Issue: only mention of term 'feature columns' in the book
Suggested fix: rephrase for consistency with existing material

Note from the Author or Editor:
Changed to 'features' to be more generic

Jørgen Lang  Oct 22, 2025  Jan 23, 2026
Page 90
1st para, 2nd sentence

Text: Whenever you’re dealing with training or inference and you want the data or model to be on the accelerator, you’ll see something like .to(“cuda”) […]
Issue: use of typographical/smart quotes in code.
Suggested fix: replace .to(“cuda”) → .to("cuda")

Note from the Author or Editor:
Fixed

Jørgen Lang  Oct 22, 2025  Jan 23, 2026
Page 93
last para, 1st sentence

Text: This chapter covered the data ecosystem in PyTorch and introduced you to the dataset and DataLoader classes.
Issue: dataset class name should be uppercase
Suggested fix: dataset → Dataset

Note from the Author or Editor:
Fixed

Jørgen Lang  Oct 23, 2025  Jan 23, 2026
Page 100
2nd para, 1st sentence

Text: Then, you’ll be given the sequences representing the three sentences.
Issue: only two sentences
Suggested fix: replace three → two

Note from the Author or Editor:
Fixed

Jørgen Lang  Oct 24, 2025  Jan 23, 2026
Page 120
1st para, last sentence

Text: […] so add 24 to get to 24, 24.
Issue: This looks like an array or a vector with missing brackets ([24, 24]).
Suggested fix: replace 24, 24 → 2,424 as shown in sample output above.

Note from the Author or Editor:
Fixed

Jørgen Lang  Oct 30, 2025  Jan 23, 2026
Page 139
2nd last para

Text: It was a very short sentence, so it’s padded up to 85 characters with a lot of zeros!
Issue: The array contains tokens.
Suggested fix: replace "characters" → "tokens"

Note from the Author or Editor:
Fixed

Jørgen Lang  Nov 02, 2025  Jan 23, 2026
Page 154
1st para

Text: You can then set the loss function and classifier to this. (Note that the LR is 0.001, or 1e–3.):
Issue: Text refers to optimizer, not classifier
Suggested fix: replace "classifier" → "optimizer"

Note from the Author or Editor:
Fixed

Jørgen Lang  Nov 11, 2025  Jan 23, 2026
Page 155
last para, last sentence

Text: […] while the loss for the test set diverged after 15
epochs, the validation loss turned to increase […]
Issue: Text mentions test set while chart is labelled as "Training and Validation Loss".
Suggested fix: replace "test set" → "training set"

Note from the Author or Editor:
Fixed

Jørgen Lang  Nov 11, 2025  Jan 23, 2026
Page 155 + 156
figure 7-9 + figure 7-10

Text:
Figure 7-9. Accuracy for LSTM over 30 epochs
Figure 7-10. Loss with LSTM over 30 epochs
Issue: training ran für 300 epochs
Suggested fix: replace "30" → "300"

Note from the Author or Editor:
Fixed

Jørgen Lang  Nov 11, 2025  Jan 23, 2026
Page 168
last para

Text: This model shows a total of 406.817 parameters of which only 6,817 are trainable, so training will be fast!
Issue: period instead of decimal comma
Suggested fix: replace '406.817' → '406,817'

Note from the Author or Editor:
Fixed

Jørgen Lang  Nov 12, 2025  Jan 23, 2026
Page 175
last para

Text: You’ll want to create a single string with all the text and set that to be your data. Use \n for the line breaks. Then, this corpus can be easily loaded and tokenized. First, the tokenize function will split the text into individual words, and then the create_word_dictionary will create a dictionary with an index for each individual word in the text:
Issue: Missing formatting for "\n" and "tokenize".
Suggested fix: <code>\n</code>, <code>tokenize</code>.

Note from the Author or Editor:
Thanks, fixed!

Jørgen Lang  Nov 16, 2025  Jan 23, 2026
Page 187
1st code snippet

Will mark the prepending protocol in URL with [protocol] so error submission does not throw a tantrum. ¯\_(ツ)_/¯

Text: !wget --no-check-certificate \ […]
[protocol]storage.googleapis.com/learning-datasets/ \
irish-lyrics-eof.txt-O /tmp/irish-lyrics-eof.txt
Issue:
1. \ - line break within string
2. missing whitespace before -O switch
Suggested fix:
!wget --no-check-certificate \
"[protocol]storage.googleapis.com/learning-datasets/"\
"irish-lyrics-eof.txt" -O /tmp/irish-lyrics-eof.txt

Note from the Author or Editor:
Added the space before -O, that's a typo.

Not sure about the need for [protocol] -- don't want the user to type that.

Jørgen Lang  Nov 18, 2025  Jan 23, 2026
Page 190
figure caption

Text: Adding a second LSTM layer
Issue: Text refers to VLR
Suggested fix: Accuracy and loss with variable learning rate.
(copypasta?)

Note from the Author or Editor:
Sorry, a little onclear on this -- the text says 'you can set it as a variable rate, which we do here...' -- and then it shows the result. Isn't this as intended?

Jørgen Lang  Nov 18, 2025  Jan 23, 2026
Page 209 ff.
multiple

Text: […] # features and targets […]
Issue: These were called "features and labels" before
Suggested fix: Unify to use "features and labels".

Note from the Author or Editor:
A little more nuanced than that -- when it's a sequence, I like to think of the label as the value that you are targeting, hence the interchangeable language. I edited the prose at the top to use 'target label' to clarify this, so when in code you only see 'target' it makes sense.

Jørgen Lang  Nov 24, 2025  Jan 23, 2026
Page 243-244
last sentence (contd. on p. 244)

Text: As discussed in earlier chapters, with dropout, neighboring neurons are randomly dropped out (ignored) during training to avoid a familiarity bias.
Issue: Bias was introduced as "proximity bias" in ch. 3
Suggested fix: familiarity bias → proximity bias

Note from the Author or Editor:
Fixed

Jørgen Lang  Nov 27, 2025  Jan 23, 2026
PDF
Page 260
1st + 2nd code snippet

Text: python3 -m venv chapter12env
Issue: Example is from ch 13
Suggested fix: change chapter12env → chapter13env

Jørgen Lang  Dec 01, 2025  Jan 23, 2026
PDF
Page 260
6th para, 1st sentence

Text: Then, you’ll be ready to install PyTorch.
Issue: We install TorchServe, not PyTorch
Suggested fix: Then, you’ll be ready to install TorchServe.

Jørgen Lang  Dec 01, 2025  Jan 23, 2026
PDF
Page 264
1st para 1st sentence

Text: Before running it, make sure you have a model-store (or similar) directory that you will store the archived model in.
Issue: At the beginning of the chapter this directory was created under the name "model_store".
Suggested Change model-store → model_store

Jørgen Lang  Dec 01, 2025  Jan 23, 2026
Page 266
1st code example, line 3 + line 6

Text:
line 3: --model-store model-store
line 6: --models simple_linear=model_store/simple_linear.mar
Issue: inconsistent paths: model-store vs model_store
Suggested fix: harmonize path/dir name to model store througout chapter

Note from the Author or Editor:
Fixed
THe directory is now model_store
The parameter name is model-store, so we specify model-store is model_store!

Jørgen Lang  Dec 02, 2025  Jan 23, 2026
PDF
Page 341
1st para, last sentence

Text: On macOS, the shared RAM with the M-Series chips works well, while running on an M1 Mac with 16 Gb, the Gemma 2B is fast and smooth with Ollama.
Issue: "Gb" (Gigabit) vs "GB" (Gigabyte)
Suggested fix: replace Gb → GB

Jørgen Lang  Dec 13, 2025  Jan 23, 2026
Page 348
2nd last para

Text: Next, we can wrap all this code in a function called analyze, with this signature:
Issue: According to following code examples, function is called 'analyze_file'
Suggested fix: replace: function called analyze → function called analyze_file

Note from the Author or Editor:
Fixed

Jørgen Lang  Dec 14, 2025  Jan 23, 2026
Page 352
1st para, 2nd sentence

Text:If the process completes successfully, the JobId is updated […]
Issue: variable name in code is jobId (lowercase 'j')
Suggested fix: replace JobId → jobId in prose

Note from the Author or Editor:
Fixed

Jørgen Lang  Dec 14, 2025  Jan 23, 2026