liveBook · Manning

Activation

As explained in Human-in-the-Loop Machine Learning: Active learning and annotation for human-centered AI

A neural network activation is the output value of a unit or layer during a forward computation.

An activation is the output value of a neural network unit or layer during a forward computation. A layer’s activations form a vector of values that can be inspected alongside the model’s predictions. section 4.1.2 section 4.1.3

For diversity sampling, low activation can flag an item that the model has little information about and may be an outlier. This is a model-based criterion: an unusual vector could instead have unusually high values, but the sampling approach focuses on low activation. section 4.1.2 section 4.2

Figure 4.2 Two neural architectures and how you can interpret them for outlier detection. In the top example, you can use the model scores (known as z or logits), which retain their absolute values before they are normalized via softmax. In the bottom example, you have lost the absolute values in the final layer because of the softmax function, so you can use the activation in the second-to-last layer to determine whether an item is an outlier.

The choice of layer matters: logits retain absolute scores before softmax, while a second-to-last layer can provide activations when the final layer has already normalized them. section 4.1.2

A second-to-last layer is most useful for this purpose in deeper networks when it resembles the final layer and has fewer neurons. More neurons can introduce random variability that is harder to overcome statistically. section 4.1.2

Listing 4.1 Allowing our model to return hidden layers in addition to softmax values
    def forward(self, feature_vec, return_all_layers=False):
        # Define how data is passed through the model and what is returned
 
        hidden1 = self.linear1(feature_vec).clamp(min=0) # ReLU
        output = self.linear2(hidden1)
        log_softmax = F.log_softmax(output, dim=1)      #1
 
        if return_all_layers:
            return [hidden1, output, log_softmax]       #2
        else:
            return log_softmax

A PyTorch forward function can expose hidden activations and output logits through an explicit return_all_layers parameter, while retaining the usual log-softmax return by default. section 4.1.3

Absolute activation values can be difficult to compare: neuron distributions vary, some neurons may model noise, and different parts of a network may use different activation functions. Ranking items by each neuron’s activation avoids having to determine every neuron’s distribution and helps identify the least-activated items. section 4.2

Ranking one neuron’s activations

For ten items with activations ordered from 2.43 down to −0.42, the item at −0.36 is near the low end of the ranking. It is a candidate for model-based outlier sampling, even without assuming a normal distribution. section 4.2

How Human-in-the-Loop Machine Learning: Active learning and annotation for human-centered AI covers it

How deep it goes
Explains layer selection, activation extraction, and rank-based comparison, including limitations of absolute values.
Examples
Illustrates ranked neuron values for ten items and a forward function that returns hidden activations and logits.
What you can do after
Apply it via PyTorch to expose layer outputs and rank low-activation candidates for outlier sampling.
How it connects
Connects activations to logits, softmax, outlier detection, and diversity sampling.

Also explained in

Compare how 4 books explain activation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Human-in-the-Loop Machine Learning: Active learning and annotation for human-centered AI. The section links point to the parts of the book it draws on.