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.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

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

Version Location Description Submitted by Date submitted
PDF 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"

Jørgen Lang  Sep 22, 2025 
PDF 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}%')

Jørgen Lang  Oct 17, 2025 
PDF 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.

Jørgen Lang  Sep 22, 2025 
PDF 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"

Jørgen Lang  Sep 22, 2025 
PDF 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.

Jørgen Lang  Oct 13, 2025 
PDF 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.

Jørgen Lang  Oct 13, 2025 
PDF 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.

Jørgen Lang  Oct 14, 2025 
PDF 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.

Jørgen Lang  Oct 15, 2025 
PDF 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)

Jørgen Lang  Oct 15, 2025 
PDF 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?

Jørgen Lang  Oct 15, 2025 
PDF 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.

Jørgen Lang  Oct 15, 2025 
PDF 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() […]?

Jørgen Lang  Oct 15, 2025 
PDF 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"

Jørgen Lang  Oct 16, 2025 
PDF 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.

Jørgen Lang  Oct 16, 2025 
PDF 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.

Jørgen Lang  Oct 17, 2025 
PDF Page 55
1st heading

## Disclaimer: This is not meant as a serious suggestion. ###
Text: Building a CNN to Distinguish Between
Horses and Humans
Issue: Missed opportunity for a John Steinbeck reference
Suggested fix: Rename section to "Of Horses and Men"

Weekend is near… ;)

Jørgen Lang  Oct 17, 2025 
PDF Page 57
figure 3-8

Issue: directory names are different in naming and case from actual dir structure
Suggested fix: correct dir naming in figure according to actual dir structure

Jørgen Lang  Oct 17, 2025 
PDF 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.

Jørgen Lang  Oct 17, 2025 
PDF 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

Jørgen Lang  Oct 17, 2025 
PDF 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.

Jørgen Lang  Oct 17, 2025 
PDF 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…… ¯\_(ツ)_/¯

Jørgen Lang  Oct 17, 2025 
PDF 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()

Jørgen Lang  Oct 17, 2025 
PDF 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.

Jørgen Lang  Oct 20, 2025 
PDF 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.

Jørgen Lang  Oct 20, 2025 
PDF 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.

Jørgen Lang  Oct 20, 2025 
PDF Page 71
3rd para

Text: You’ll notice that we’re printing the output shape of the last layer, […]
Issue: Output referenced in text seems to be missing
Suggested fix: Include a screenshot showing the output.

Jørgen Lang  Oct 21, 2025 
PDF Page 73
code example, line1

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

Jørgen Lang  Oct 21, 2025 
PDF 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"

Jørgen Lang  Oct 21, 2025 
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.

Jørgen Lang  Oct 21, 2025 
PDF 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

Jørgen Lang  Oct 21, 2025 
PDF 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]

Jørgen Lang  Oct 21, 2025 
PDF 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

Jørgen Lang  Oct 21, 2025 
PDF 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?

Jørgen Lang  Oct 21, 2025 
PDF 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.

Jørgen Lang  Oct 22, 2025 
PDF 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

Jørgen Lang  Oct 22, 2025 
PDF 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?

Jørgen Lang  Oct 22, 2025 
PDF 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'

Jørgen Lang  Oct 22, 2025 
PDF 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

Jørgen Lang  Oct 22, 2025 
PDF 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")

Jørgen Lang  Oct 22, 2025 
PDF Page 92
2nd last para, 2nd sentence

Text: Based on the hardware you have available and the number of cores, the speed of your CPU, etc.,
Issue: context is Load (ETL), so supposedly this is rather GPU/TPU
Suggested fix: C → G

Jørgen Lang  Oct 23, 2025 
PDF 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

Jørgen Lang  Oct 23, 2025 
PDF 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

Jørgen Lang  Oct 24, 2025 
PDF 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.

Jørgen Lang  Oct 30, 2025 
PDF 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"

Jørgen Lang  Nov 02, 2025 
PDF 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"

Jørgen Lang  Nov 11, 2025 
PDF 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"

Jørgen Lang  Nov 11, 2025 
PDF 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"

Jørgen Lang  Nov 11, 2025 
PDF 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'

Jørgen Lang  Nov 12, 2025 
PDF 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>.

Jørgen Lang  Nov 16, 2025 
PDF 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

Jørgen Lang  Nov 18, 2025 
PDF 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?)

Jørgen Lang  Nov 18, 2025 
PDF Page 209 ff.
multiple

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

Jørgen Lang  Nov 24, 2025 
PDF 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

Jørgen Lang  Nov 27, 2025 
PDF Page 245
code example

Text: […] and adding another layer between the RNNs and the linears:
Issue: This "another" layer and the following Linears seem to be missing in the code.
Question: Did I get this right? I suspect a misunderstanding on my side.

Jørgen Lang  Nov 27, 2025 
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 
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 
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 
PDF 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

Jørgen Lang  Dec 02, 2025