liveBook · Manning

Hidden layer

As explained in Graph Neural Networks in Action

An intermediate layer of a neural network whose activations are not directly exposed as the model's inputs or outputs.

A hidden layer transforms a network’s input into an intermediate representation before the final output. That representation can be useful in its own right: when a network learns to predict which nodes appear together on graph walks, its hidden layer can provide node embeddings. section 2.4.3 section 2.4.4

What the hidden layer does depends on the task:

  • In node2vec, a shallow network predicts visited nodes from a starting node; the trained hidden layer becomes a node embedding. section 2.4.3
  • In a multilayer perceptron, hidden layers transform an input vector toward a prediction. Their outputs can also serve another task or model; for node embeddings, the last hidden layer is typically used. section 2.4.4
  • In a recurrent neural network, a hidden layer is updated at each timestep using the new input and previous hidden state, allowing sequential data to influence later outputs. section 6.5.1

A hidden layer in PyTorch

A basic recurrent model can define an nn.RNN with a chosen hidden size, initialize its hidden state with zeros, and pass selected RNN outputs through nn.Linear to produce predictions. This is a single-layer starting point; RNNs can also be stacked or replaced with LSTM or GRU layers. section 6.5.1

Figure 6.17 Structure for an RNN. Temporal updates as a single self-loop denoted by Whh (left). An unfolded model in time showing the model updates (right). Here, we change our input, output, and hidden layers (x, y, h) to be temporal variables (xt, yt, ht). At our initial step, t, we update our current hidden layer with input data from xt and the weights from our previous hidden layer ht–1 and then use this to output yt. The weights from ht are then passed to ht+1 along with the new input at xt+1 to infer yt+1.
figure

The unfolded RNN diagram makes the hidden layer’s update across timesteps visible. section 6.5.1

How Graph Neural Networks in Action covers it

How deep it goes
Explains intermediate representations and RNN updates with a PyTorch example, but defers backpropagation-through-time computational details to deep-learning packages.
Examples
Illustrates hidden representations with graph-walk node prediction, image classification, and a single-layer PyTorch RNN.
What it assumes
Assumes some deep-learning familiarity while briefly introducing tensor-to-output layers and multilayer perceptrons.
What you can do after
Apply it via PyTorch’s nn.RNN by initializing a hidden state and mapping RNN outputs through nn.Linear.
How it connects
Connects hidden layers to node2vec, node embeddings, multilayer perceptrons, graph neural networks, and recurrent neural networks.

Also explained in

Compare how 8 books explain hidden layer →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Graph Neural Networks in Action. The section links point to the parts of the book it draws on.