liveBook · Manning

Torch.nn.Module

As explained in 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.

torch.nn.Module is the base class for defining reusable PyTorch neural-network components. A subclass configures layers in __init__ and defines forward() to describe how inputs propagate through them. section 5.2.5

Single-neuron name classifier

A LogisticRegressionNN module combines torch.nn.Linear with sigmoid activation to classify names from 3,663 TF-IDF features. Training connects the model to BCELoss, SGD, gradients, and parameter updates.

How Natural Language Processing in Action, Second Edition covers it

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 it assumes
Assumes TF-IDF features and binary classification while demonstrating the module structure from the model definition onward.
What you can do after
Build it from scratch by subclassing Module, defining forward propagation, and training the resulting model.
How it connects
Connects neural-network modules to Linear layers, sigmoid activation, binary cross-entropy, SGD, and backpropagation.

Also explained in

Compare how 5 books explain torch.nn.Module →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.