liveBook · Manning

PyTorch

As explained in Math and Architectures of Deep Learning

An open-source machine learning library used here to provide the chapter's executable code examples and automatic gradient computation.

PyTorch is an open-source machine learning library that turns mathematical ideas into executable Python programs. It supports tensor manipulation, linear algebra, probability distributions, neural networks, optimization, and convolution, with examples commonly run in Jupyter Notebook. section 2.2 section 5.0

Typical uses include:

  • Representing vectors, matrices, tensors, and data batches for machine-learning computations. section 2.2
  • Computing eigenvalues, eigenvectors, singular-value decompositions, PCA, and latent semantic analysis. section 2.15.1 section 4.5.7 section 4.6.3
  • Building datasets, neural-network models, loss functions, optimizers, and training loops. section 9.2.3
  • Applying fixed or learned one-dimensional and two-dimensional convolution kernels. section 10.1.4 section 10.3.3

Training a classifier

A custom Dataset exposes height, weight, and class-label records; DataLoader creates shuffled minibatches; a two-layer model produces raw scores; CrossEntropyLoss, backpropagation, and SGD update its parameters. section 9.2.3

Listing 14.1 PyTorch- PCA revisited
import torch

X = get_data()                                      #1

X_mean = X.mean(axis=0)                             #2

X = X - X_mean                                      #3

U, S, Vh = torch.linalg.svd(X, full_matrices=False) #4

V = Vh.T                                            #5

V_trimmed =  V[:, 0: 2]                             #6

X_proj = torch.matmul(X, V_trimmed)                 #7

X_proj = torch.cat([X_proj,                         #8
              torch.zeros((X_proj.shape[0], 1))], axis=1)

X_recon = torch.matmul(X_proj, Vh)                  #9

X_recon = X_recon + X_mean                          #10

PCA dimensionality reduction centers data, computes an SVD, projects onto two components, and approximately reconstructs the original points. section 14.4.1

How Math and Architectures of Deep Learning covers it

How deep it goes
Demonstrates practical APIs and tensor shapes through worked code, while stopping short of library internals and learned-kernel theory.
Examples
Demonstrates matrix diagonalization, PCA and LSA, classifier training, custom convolution kernels, and dimensionality reduction.
What it assumes
Assumes Python basics while introducing the relevant mathematics before showing executable implementations.
What you can do after
Apply via PyTorch to implement mathematical transformations, construct training pipelines, optimize models, and compute projections or convolutions.
How it connects
Connects tensors with linear algebra, PCA, SVD, probability distributions, neural networks, SGD, and convolution.

Also explained in

Compare how 11 books explain PyTorch →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Math and Architectures of Deep Learning. The section links point to the parts of the book it draws on.