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.
The unfolded RNN diagram makes the hidden layer’s update across timesteps visible. section 6.5.1







