liveBook · Manning

Torch.nn.Module

torch.nn.Module is PyTorch’s base class for neural-network components that encapsulate computation, parameters, and submodules.

How 5 Manning books explain it

Deep Learning with PyTorch, Second Edition

The PyTorch base class for defining neural-network models as Python modules with parameters, submodules, and a forward method.

How it is used
Organizes trainable layers and their computation into reusable components or complete PyTorch networks.
How deep it goes
Works through subclassing, calls, registration, and parameter collection; leaves backward computation to autograd rather than defining a backward method.
Examples
Uses a convolutional image classifier with an explicit reshape, plus parameter-count and named-parameter inspections.
What you can do after
Build it from scratch by subclassing nn.Module, defining forward, registering child layers, and supplying collected parameters to an optimizer.

Read how Deep Learning with PyTorch, Second Edition explains torch.nn.Module →

Deep Learning with Python, Third Edition

The base class for defining stateful PyTorch models with parameters and a forward method.

How it is used
Packages trainable state and forward computation into reusable PyTorch model objects for gradient-based training.
How deep it goes
Demonstrates subclass definition, Parameter tracking, invocation, optimizer integration, training steps, and gradient clearing.
Examples
Uses a linear classifier with weight and bias Parameters, mean squared error, SGD, and a compact training step.
What you can do after
Build it from scratch using torch.nn.Module, torch.nn.Parameter, and torch.optim.SGD.

Read how Deep Learning with Python, Third Edition explains torch.nn.Module →

Natural Language Processing in Action, Second Edition

A PyTorch module is a reusable neural-network component represented by the torch.nn.Module base class and its registered parameters and submodules.

How it is used
Defines a trainable PyTorch neuron for binary classification of names.
How deep it goes
Explains subclass construction and forward propagation, then demonstrates training without detailing Module internals.
Examples
Uses a LogisticRegressionNN module with 3,663 TF-IDF inputs and name predictions such as John, Ruby, and Sarah.
What you can do after
Build it from scratch by subclassing Module, defining forward propagation, and training the resulting model.

Read how Natural Language Processing in Action, Second Edition explains torch.nn.Module →

Math and Architectures of Deep Learning

The PyTorch base class that neural network models subclass to define learnable modules and a forward pass.

How it is used
Defines reusable neural-network models whose layers and forward computations participate in prediction and training.
How deep it goes
Descends through subclassing, initialization, Sequential chaining, forward execution, and optimizer integration, but not Module internals.
Examples
Uses a demand-prediction multilayer perceptron and a convolutional network with three Conv2d layers.
What you can do after
Build it from scratch by subclassing Module, composing layers, implementing forward(), and training through parameters and an optimizer.

Read how Math and Architectures of Deep Learning explains torch.nn.Module →

Deep Learning with R, Third Edition

torch.nn.Module is PyTorch's base class for building objects that represent neural-network modules and manage their parameters.

How it is used
Packages model state and forward computation for object-oriented PyTorch training.
How deep it goes
Defines subclass structure, invocation, optimizer integration, training steps, and gradient resetting, but not Module internals.
Examples
Demonstrates a linear classifier with weight and bias Parameters, matrix multiplication, loss backpropagation, SGD, and gradient clearing.
What you can do after
Build a trainable PyTorch model and operate its optimizer-driven training loop.

Read how Deep Learning with R, Third Edition explains torch.nn.Module →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.