liveBook · Manning

Torch.nn.Module

As explained in Build AI Drug Discovery Pipelines

nn.Module is the PyTorch base class for defining neural-network components with registered parameters, submodules, and computation.

torch.nn.Module is PyTorch’s base class for neural-network components. A custom model subclasses it, defines its layers in __init__, and defines computation in forward. Assigning layers such as Linear modules to the class makes the network’s architecture and trainable parameters part of one reusable object. section 8.2.2

Build a custom module around three practical ideas:

  • Initialize the parent module with super().__init__() before defining the network’s layers. section 8.2.2
  • Declare layers such as nn.Linear(input_size, 512), matching each layer’s output size to the next layer’s input size. section 8.2.2
  • Implement forward to apply transformations in order, including nonlinear activation and dropout before returning the prediction. section 8.2.2

Kinase activity prediction

A molecule represented by a fingerprint vector can enter a module with three fully connected layers: 2048 input features become 512, then 256, then one output. ReLU supplies nonlinear transformations, while dropout with rate 0.2 is applied after the first two hidden layers.

How Build AI Drug Discovery Pipelines covers it

How deep it goes
Explains subclassing, initialization, layer dimensions, affine transformations, and forward computation, but not training-loop mechanics.
Examples
Uses KinaseBinderNN with fingerprint vectors and VAECYC with embeddings, bidirectional GRUs, latent projections, and autoregressive decoding.
What you can do after
Build it from scratch by subclassing nn.Module, declaring layers, and routing input tensors through a forward method.
How it connects
Connects neural-network modules with linear layers, activation functions, dropout, recurrent networks, and variational autoencoders.

Also explained in

Compare how 7 books explain torch.nn.Module →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build AI Drug Discovery Pipelines. The section links point to the parts of the book it draws on.