Feature detectors: how neurons read and write
Neural networks learn to recognize patterns and use them to make predictions. How those patterns are represented inside a network remains an open research question. Distill’s work on understanding neural networks proposes that features are the fundamental units of neural networks. This makes it interesting to explore how a neural network can implement a feature detection mechanism.
To understand this mechanism, we will begin with a single neuron. Its incoming weights determine which parts of the input to emphasize, suppress, or ignore, allowing it to act as a feature detector that responds to a particular pattern. Our exploration will be based on a small spam classifier, where a neuron’s response to a combination of promotional words helps the output neuron decide whether the message is spam.
Then we will bring several of these feature detectors together in a layer, each using different weights to respond to a different pattern in the same input. In our spam classifier, one neuron responds to promotional words while another responds to words common in routine messages. Their responses give the next layer several signals to combine, allowing the prediction to depend on multiple patterns rather than a single detector.
We choose the detector roles and weights by hand to make the calculations easy to follow and each neuron’s contribution easy to inspect. In a trained network, those roles emerge as learning adjusts the weights, and individual neurons can develop overlapping responses that do not fit such clear categories. Our example gives us a simple setting in which to understand the mechanism before examining what training produces.
Dimensions count coordinates
Let’s first look at how a message becomes a point in a feature space. We will choose a few words and count how many times each appears in the message, then use those counts to calculate a spam or non-spam prediction. We choose the vocabulary and weights by hand so that each calculation can be followed. A training demonstration later uses the same encoding with learned weights.
First, we need to define our vocabulary: the words we will track, arranged in a fixed order. Every message will use the same list: one count per vocabulary word, with zero for an absent word. Words outside the vocabulary are ignored. To see how this works, we will start with just two words: claim and prize.
The table shows a small illustrative dataset, with each message’s label and its counts for our two vocabulary words. We treat uppercase and lowercase letters alike and ignore punctuation:
| Message | Claim | Prize | Label |
|---|---|---|---|
| Claim your prize. Claim it at the meeting. | 2 | 1 | Spam |
| The project meeting is tomorrow. | 0 | 0 | Non-spam |
| Prize! | 0 | 1 | Spam |
We can now combine the first message’s counts into a vector , where the first entry is the claim count and the second is the prize count. These two numbers are the vector’s components, also called its coordinates. The number of coordinates defines the vector’s dimensionality, so our vector is two-dimensional. This is word-count encoding, a bag-of-words representation: it records how often words occur but discards their order in the message.
In the broad sense of a numerical vector representation, we can think of this as a manually designed embedding of the message. We chose what each coordinate means; its value comes from counting words. The term “embedding” often refers to a representation learned during training, so we will refer to our fixed input representation as word-count encoding.
You may have seen a vector like this defined in PyTorch:
import torch
x = torch.tensor([2, 1])Its shape is (2,): one array axis containing two entries. PyTorch calls this a one-dimensional tensor, because x.ndim counts array axes. In our geometric description, it represents a two-dimensional vector, because it has two coordinates.
This two-dimensional vector can be plotted on a plane with the horizontal -axis marking the claim count and the vertical -axis marking the prize count. The message sits at the point : 2 along the claim axis and 1 along the prize axis.
If we want to start tracking another word, such as meeting, we add its count as a third coordinate, giving our vector another dimension. Here is the extended table:
| Message | Claim | Prize | Meeting | Label |
|---|---|---|---|---|
| Claim your prize. Claim it at the meeting. | 2 | 1 | 1 | Spam |
| The project meeting is tomorrow. | 0 | 0 | 1 | Non-spam |
| Prize! | 0 | 1 | 0 | Spam |
In the first message, meeting appears once, so the vector becomes . All three coordinates are nonzero. Other messages still record zero for absent words. The coordinate order is claim, prize, then meeting.
Each word count is an input feature and occupies one coordinate, corresponding to an axis in feature space. Moving along the axis for the claim count changes that count while leaving the others fixed. These counts are discrete: a word can appear once or twice, but not 1.5 times.
Here, the input features have clear meanings because we chose the encoding: one coordinate per word in our vocabulary. We will also choose the detector weights by hand so we can follow how they combine these counts. However, in many text models, a tokenizer instead converts each message into a sequence of token IDs, representing words or parts of words. The model maps these IDs to learned embeddings. Training adjusts the embeddings and the network’s weights so it can learn useful patterns without us assigning particular word groups to individual neurons.
We assign an axis to each input feature. Since the count of each word we track is one feature, the vocabulary size determines the input vector’s dimensionality. With a vocabulary of 100 words, every message gets 100 coordinates, whether it contains 3 words or 300. A message can be any length: additional words may change the counts, but they do not add coordinates. We cannot draw all 100 axes together, but we can still store the values and calculate with them.
Our complete vocabulary is ['claim', 'prize', 'meeting']. Every message gets three coordinates, including zeros for absent words:
| Message | Word-count vector |
|---|---|
| Prize! | |
| Claim your prize. Claim it at the meeting. | |
| The project meeting is tomorrow. | |
| Claim your prize at the meeting. |
A vector with mostly zero entries is called sparse. “Prize!” has two zero entries out of three. With a larger vocabulary, a short message might use only a small fraction of the available words; the rest would still receive zero counts.
One neuron combines three inputs into one score
We now encode a message as three features: the counts of claim, prize, and meeting. Now let’s see how a neuron can use these features to detect a pattern. The neuron stores one weight for each input coordinate, determining how much that input contributes to the result. It then multiplies each input coordinate by its corresponding weight and adds the contributions to produce a single response score. Training adjusts these weights to change how the neuron responds to its inputs.
This calculation is a weighted sum:
Here is the value of input feature , and is its corresponding weight. The inputs form the vector , and the stored weights form the neuron’s incoming weight vector . We can also name a coordinate by its feature: denotes the claim count in the input vector .
The full neuron calculation then adds a bias to this score and applies an activation function , which can introduce nonlinearity. This produces the neuron’s output :
To make the demonstration simpler, we will use zero bias and an identity activation function, so the output is the weighted sum itself:
The diagram below shows this calculation for our message vector : each count is multiplied by its corresponding weight, and the three contributions are added to produce the score .
Notice what this mechanism allows the neuron to do: by setting some weights to zero, it can ignore those input coordinates and respond only to the others. A count multiplied by zero contributes nothing to the sum; a negative weight makes a positive count lower the score.
For example, to make the neuron respond only to the claim count, give claim a weight of 1 and every other word a weight of 0. Its stored weight vector is therefore . When the neuron processes our input, it computes the weighted sum:
Our input vector now has three nonzero entries, while the chosen weight vector has two zeros. A zero means different things in these two kinds of vectors: a zero input count means the word is absent, while a zero weight means the neuron ignores that word, even when it is present. Vectors with many zero entries are called sparse; our chosen weight vector has two zeros out of three entries.
So far, our neuron has used only one input feature: the claim count. But it can also combine several features by giving them nonzero weights. For example, we can create a promotional reader that responds to claim and prize while ignoring meeting. Let’s give claim a weight of and prize a weight of , while keeping meeting at :
When the neuron computes the weighted sum for the same message using these new weights, we get:
With these weights, each occurrence of claim contributes to the score, each prize contributes , and meeting contributes nothing.
This detector responds to claim and prize regardless of their meaning in context: “prize” could also appear in a legitimate announcement. For a trained neuron, we must examine its responses to many inputs before assigning it a label such as “promotion detector.”
It’s also possible to make a feature suppress the neuron’s response by giving it a negative weight. For example, computes the prize count minus the meeting count: each occurrence of meeting lowers the score by . Equal counts cancel, so a zero score does not necessarily mean that the input is zero.
The weights define a reading direction
Let’s now introduce a little linear algebra and see how the input and weight vectors relate geometrically. We already plotted the vector for one of our example messages in a three-dimensional space with claim, prize, and meeting axes. We can now plot the neuron’s weight vector in that same space and compare their directions.
The weight vector defines the neuron’s reading direction: its relative weights determine which combination of input coordinates it measures. The dot product measures how much of the input lies along this direction, scaled by the weight vector’s length. We can calculate it using the vectors’ coordinates:
As you can see, it’s the same arithmetic as the weighted sum we saw earlier. Scalar algebra expresses it as a weighted sum, while linear algebra expresses it as a dot product between vectors. In the formula above, we write and as column vectors with three rows and one column, and use to represent the weights as a one-row, three-column matrix so that multiplying it by the input column produces one score.
For nonzero vectors, we can also express this same dot product geometrically, using the vectors’ lengths and the angle between them:
where is the angle between the input and the reading direction. With both lengths fixed, an input pointing closer to the reading direction produces a larger score. An input perpendicular to it produces zero.
The formula above has two parts: the length product , which sets the scale, and , which captures the vectors’ alignment. For example, doubling the weights to preserves the reading direction but doubles every score. The dot product therefore reflects both the vectors’ alignment and their lengths.
The widget below shows how the message vector aligns with the neuron’s reading direction. The promotional reader’s weight vector is shown in blue and the message vector in orange. The angle between them describes their alignment; their dot product combines that alignment with both vectors’ lengths to produce the score we calculated above. All three input coordinates are visible, so the plot shows the full input and reading direction.
Drag the plot to inspect the two arrows from different viewpoints; rotating the view does not change their alignment or score. The shaded claim–prize plane shows where the meeting count is zero. The arc marks the angle between the arrows; its 3D measurement appears alongside the dot-product calculation.
Reader w = (1.5, 1, 0)
Input x = (2, 1, 1)
wᵀx =1.5 × 2+ 1 × 1+ 0 × 1= 4
Since the reader’s meeting weight is zero, adding meeting counts moves the input perpendicular to the reading direction and leaves its score unchanged, regardless of how many times meeting occurs.
From feature detectors to a layer
By giving claim and prize nonzero weights and meeting a zero weight, we made the neuron respond to a combination of claim and prize counts while ignoring meeting. This is how our neuron acts as a feature detector: its score measures a particular combination of input features. We use to denote a neuron’s weighted-sum score and add a subscript to identify the detector. So, for the promotional detector, the formula is:
Each additional occurrence of claim raises the score by , and each additional prize raises it by . Adding meeting leaves the score unchanged because its weight is zero.
A message can contain many different patterns, and different neurons can respond to different combinations of its features. To detect another pattern, we can introduce a second neuron that receives the same three word counts. Let’s use the word “meeting” for a routine-message pattern, giving it a weight of and setting the claim and prize weights to :
Let’s apply these weights to our starting message and to the project-meeting message:
| Message | Score | |
|---|---|---|
| Claim your prize. Claim it at the meeting. | 2 | |
| The project meeting is tomorrow. | 2 |
We now have two neurons receiving the same three-coordinate input . Each produces one scalar response, and these responses together form the layer’s output vector :
| Message | Promotional response | Routine response | Layer output |
|---|---|---|---|
| Claim your prize. Claim it at the meeting. | 4 | 2 | |
| The project meeting is tomorrow. | 0 | 2 | |
| Prize! | 1 | 0 | |
| Claim your prize at the meeting. | 2.5 | 2 |
The diagram below shows how both neurons receive the same three word counts and use their own weights to produce the two coordinates of .
We can describe the layer shown above in matrix form by collecting the neurons’ weight vectors into one weight matrix . The first row contains the promotional neuron’s weights, and the second contains the routine neuron’s weights:
Each row corresponds to one neuron, and each column corresponds to one input feature: claim, prize, or meeting. This makes a matrix, mapping the three input counts to two neuron responses. From a linear algebra perspective, we can describe the matrix in terms of its row and column spaces. For our , the row space is the plane spanned by the promotional reader and the routine reader in the claim–prize–meeting input space. Its column space is the full promotional–routine response plane: all output pairs that the matrix can produce when input coordinates may take arbitrary real values.
Each row computes one detector’s response by taking the dot product of its weights with the input. This is the row view of matrix multiplication: one dot product per output coordinate. For our starting message, , this gives
The result is the layer’s activation vector, with one coordinate per neuron’s output after its activation function. The matrix–vector multiplication above is the same calculation shown in the diagram. Because we don’t use biases or nonlinear activation functions in this example, the weighted sums pass through unchanged, so is both the pre-activation vector and the activation vector.
When a neuron has a large positive activation, we informally say it is firing strongly. We call an activation large relative to that neuron’s usual responses across inputs; other neurons may operate on different scales. The underlying dot-product score depends on the input and weight vectors’ lengths and their alignment. Bias and the activation function can then modify this score to produce the neuron’s output.
Our two neurons illustrate specialization: one responds to promotional words and the other to routine-message words. Both receive the same input vector but store their own weights. We deliberately set a weight to zero for each input feature we want a neuron to ignore. In trained networks, these weights are usually nonzero, so neurons typically combine many of the same input features, giving each a different influence through their learned weights.
One output neuron combines the responses into a prediction
Our first layer produces the activation vector , containing the promotional response and routine response . To use these detected patterns to decide whether the message is spam or non-spam, we’ll add a classification neuron that takes these responses as inputs and combines them into a single score. It uses the same weighted-sum mechanism, but now combines detected patterns rather than individual word counts.
Because we have only two classes—spam and non-spam—this is a binary classification problem. We can use a single classification score and choose the class from its sign: positive means spam, negative means non-spam, and zero marks the decision boundary, where our manual rule gives neither class a preference.
We want a stronger promotional response to move the prediction toward spam and a stronger routine response to move it toward non-spam. To achieve this, we’ll set the classification neuron’s weights to for the promotional response and for the routine response, keeping its bias at zero. The classification score is described by the formula , where denotes the classification score.
Use the controls below to change the promotional and routine responses and see how their weighted contributions move the classification score along the number line.
We chose the classification neuron’s weights, and , to make the calculation easy to follow. They are not necessarily optimal for real messages; training can learn these weights along with the feature detectors’ incoming weights.
Just as we collected the feature detectors’ weights into matrix , we can collect the classification neuron’s weights into matrix . This weight matrix has one row and two columns. We write the hidden layer’s output as a column vector, with the promotional response followed by the routine response , so that multiplying by gives the classification score :
Whether chosen by hand or learned through training, these weights produce a classification score that can be negative or greater than . A probability, however, must lie between and . To express the result as a probability, we could apply the sigmoid function to the completed score:
A positive score gives a probability above ; a negative score gives one below . Thresholding that probability at is equivalent to checking the score’s sign. This conversion does not change the decision, and hand-chosen weights do not guarantee calibrated probabilities.
Sigmoid converts one score into one probability; here, the probability of non-spam is . If the output layer instead produced several scores, one for each mutually exclusive class, we would use softmax to convert them together into class probabilities that sum to .
With the classification neuron in place, we now have a complete network. The diagram below shows three input units, one for each word count; two hidden neurons, which detect promotional and routine-message patterns; and one output neuron, which combines their responses into a classification score.
We can now follow a message through the whole network: from three word counts to two detector responses, which are then combined into one classification score.
The widget below lets you explore the network’s two computations. shows how the two readers act on the 3D word-count vector to produce the response vector . shows how those responses contribute to the final classification score on a number line. Switching views keeps the same message.
The , , and sliders let you adjust the word counts and see how those changes affect the input vector, detector responses, and final score. For example, increasing meeting from 1 to 2 while leaving claim at 2 and prize at 1 raises the routine response from 2 to 4 while the promotional response stays at 4. The two hidden responses become equal at , so the output layer’s score falls from 2 to 0. Increasing meeting further makes the routine response larger than the promotional response, producing a negative score and a non-spam prediction.
Input x = (2, 1, 1)
Green w₁ = (1.5, 1, 0) · Angle to x: 25.1°
Purple w₂ = (0, 0, 2) · Angle to x: 65.9°
w₁ᵀx =1.5 × 2+ 1 × 1+ 0 × 1= 4
w₂ᵀx =0 × 2+ 0 × 1+ 2 × 1= 2
Output h = (4, 2)
The two views show how the network turns word counts into detector responses and then into a decision. The prediction depends on the balance between the two responses: gives spam, gives non-spam, and equality marks the boundary. Both detector responses are nonnegative, but their outgoing weights give them opposite effects on the final score. The sliders change these responses while the weights remain fixed. A detector’s role therefore depends on both what it reads and how its response contributes to the next layer.
The widget also shows why angle alone does not determine a detector’s response. With prize and meeting both at 1, increasing claim from 2 to 3 changes the input’s angle to both readers. The green reader’s score rises from 4 to 5.5 because its claim weight is 1.5. The purple reader’s score stays at 2 because its claim weight is zero: the input moves farther along the claim axis, but its component along the meeting axis stays unchanged. Although the input becomes less aligned with the purple reader, it also gets longer, leaving their dot product unchanged.
From activations to vector contributions
So far, we have followed how neurons read their inputs: our feature detectors read the word counts, and our classification neuron reads the detectors’ responses. Taking dot products with the matrix’s rows gives us the row view we used earlier. Expressing the same multiplication as a linear combination of the matrix’s columns gives us the column view. Through this view, we can follow each detector’s response forward and see what it contributes to the classification neuron.
For this, we turn to the columns of the next layer’s weight matrix—the classifier’s matrix . Each column is scaled by the activation value of its corresponding detector neuron, producing that detector’s contribution to the classifier. In mechanistic interpretability, the corresponding column in the next layer’s weight matrix defines the neuron’s writing direction. This column represents a direction in the output space, while the neuron’s activation determines how strongly it writes along that direction. This is exactly the column view of matrix multiplication: each activation scales a column, and the resulting contributions add to form the weighted sum .
Let’s make this writing view concrete by expanding the classifier’s calculation one detector at a time. Its weight matrix has two columns, one for each detector. We’ll first use symbolic weights and to show how the contributions combine, then substitute their numerical values. Let denote the promotional detector’s outgoing weight and the routine detector’s outgoing weight. We name the columns and so we can follow each detector’s contribution separately: scales the first column, and scales the second.
The promotional activation multiplies the first column, containing ; the routine activation multiplies the second column, containing . Their contributions add in the single output coordinate:
In our classifier, and . Each column has just one entry because there is only one receiving neuron. For our starting message, the promotional detector produces , and the routine detector produces . Their contributions are
For each detector, is the computed activation, is the stored column of outgoing weights, and is the contribution to the next layer. Both activations are positive, but their outgoing weights give their contributions opposite signs: the promotional detector adds to the classification score, while the routine detector subtracts . With one receiving neuron, these contributions lie on a single number line. Adding them gives
This connects reading and writing as two views of the same matrix multiplication:
- Reading is the row view: take dot products. Each receiving neuron reads the activation vector by taking its dot product with that neuron’s row of . Each dot product produces one coordinate of , as in the row calculation we used earlier.
- Writing is the column view: scale and add vectors. Each sending detector’s activation scales its column of . The resulting contribution vectors add together to produce .
In our classifier, the receiving neuron reads using the row , while the two sending detectors contribute through the columns and . Both views compute the same matrix–vector product: the row view follows the receiving neurons, and the column view follows the sending neurons’ contributions.
To see how this works when the next layer has more than one neuron, suppose our two detectors connect to two receiving neurons. Each detector has a separate outgoing weight for each receiver, so its contribution is a vector with two coordinates. In this extension, the weight matrix has two rows and two columns:
Each row belongs to one receiving neuron. Column contains the first detector’s weights to both receivers, and ; column contains the second detector’s weights, and . The activation scales every entry of , while scales every entry of :
Now follow just the first detector, keeping its activation for our starting message. With and , its contribution is
The first entry adds to the first receiving neuron’s weighted sum; the second subtracts from the second neuron’s weighted sum. These are contributions, not the receiving neurons’ final outputs: each neuron also receives contributions from other detectors, adds its bias, and applies its activation function.
The first detector still outputs just one number, . Its outgoing weights distribute that response across the next layer. More generally, column has one entry per receiving neuron, and scaling it by activation produces a contribution vector with the same number of coordinates.
The outgoing weights fix the relative effects on the two receiving neurons: add one unit to the first and subtract two from the second. Changing the activation scales both effects together. We can draw these effects on a plane, with one axis for each receiving neuron’s weighted sum. The contribution points in the same direction as , but its arrow is four times as long.
The diagram below shows the outgoing weight vector in blue, defining the detector’s writing direction, and its scaled contribution in dashed orange. Each axis represents one receiving neuron’s weighted sum.
The column, the activation, and the next layer each play a distinct role:
- The column defines the writing direction. The nonzero vector specifies the relative effects of one detector on the receiving neurons.
- The activation scales the contribution. With fixed, the contribution has magnitude .
- The next layer sums the contributions. It combines all the vectors , adds its bias, and applies its activation function.
A positive activation preserves the column’s direction, zero contributes nothing, and a negative activation, if the activation function allows it, reverses the direction. In our example, makes the contribution four times as long as , with the same direction.
This is why we describe neurons as reading from one space and writing into another. The diagram below follows each detector from its reading weights in , through its activation, to its writing weights in .
For the whole layer, the contributions add together with the next layer’s bias:
Here is the next layer’s bias vector and is its pre-activation vector; its activation function is applied afterward. The same activation is therefore both a detector’s response to its input and the scaling coefficient for its contribution to the next layer.
The row and column views are two ways of interpreting the same matrix multiplication. But a neuron’s own reading and writing directions usually come from different matrices: its incoming weights determine what it responds to, while its outgoing weights determine what it contributes to the next layer. In our example, each detector reads through a row of and writes through a column of . The rows of describe how the receiving neurons read those detectors’ responses.
Why two linear layers still give one linear transformation
In our original classifier, we explored reading and writing without introducing any nonlinearity between the layers: each hidden neuron passes its weighted sum directly to the output neuron. This made the mechanism easy to follow, but it also limits what the network can express. To model relationships beyond a single weighted sum of the original inputs, we need a nonlinear activation between the layers. Without one, adding linear layers still gives a single linear transformation.
To see why, recall that with our identity hidden activations and zero biases, the hidden activation vector is and the classification score is . Substituting the first expression into the second gives
The column view explains why this works. Each column of describes how one word count contributes to the hidden activation vector. Multiplying by transforms each of those columns into its contribution to the final score:
| Input coordinate | Column of | After applying |
|---|---|---|
| claim | ||
| prize | ||
| meeting |
These transformed columns form the product :
Because is linear, combining the columns of and then transforming the result gives the same answer as transforming each column first and then combining them. The word counts supply the same scaling coefficients in either calculation. The product therefore takes the original input directly to the score.
So the same score can be calculated directly from the word counts:
One output neuron with those three incoming weights would produce exactly the same score for every input. Our hidden layer gives us an interpretable intermediate representation, but stacking linear layers does not expand the kinds of input-to-score functions we can represent. Applying sigmoid afterward gives the same probability in either arrangement.
To make the hidden layer express a nonlinear relationship, we can apply a nonlinear activation to its weighted sums before the output layer combines them. We will use ReLU: it lets a detector contribute only when its weighted sum crosses a threshold set by its bias. A bias alone would only shift a linear transformation; the nonlinear activation is what generally prevents the two layers from collapsing into one fixed affine transformation.
Adding nonlinearity with ReLU
We can now add the nonlinear step our original classifier was missing. Each hidden neuron still reads the input with a dot product, but we add a bias and apply ReLU before passing its response to the output layer. The bias sets the threshold; ReLU makes responses below that threshold zero. These three steps produce the dot-product score , the score after adding bias , and the activation passed to the next layer:
ReLU passes positive pre-activations through and replaces negative ones with zero. Add bias to the promotional reader:
Our original message has raw score , so its pre-activation and activation are . A message containing claim once and none of the other selected words has raw score , pre-activation , and activation . This reader now contributes only when its weighted count exceeds . Repetition alone can cross that threshold; both promotional words need not appear.
This changes how additional evidence affects the response. Increasing the raw score from to leaves the activation at , while increasing it from to raises the activation from to . The same increase has a different effect depending on whether the detector is above its threshold. One fixed weighted sum cannot reproduce both behaviors across inputs.
Keeping the routine bias at zero and the outgoing weights unchanged, the original message now gives and , predicting non-spam. We changed the model by adding the promotional bias and ReLU. The earlier widgets continue to show the original manual model.
The activation acts on the total after the bias. It does not filter terms inside the dot product separately: with zero bias, contributions and give , whereas clipping each contribution first would give . Cancellation happens before the activation sees the score.
A detector’s own response can be negative if its activation function permits it. For example, weights applied to our original input give raw score . A bias can also turn a positive raw score into a negative pre-activation. Identity activation preserves that negative value, ReLU replaces it with zero, and activations such as tanh can produce negative outputs.
A nonnegative activation can still lower the next neuron’s score through a negative outgoing weight. Our routine detector does this with , even when it uses ReLU. Conversely, a negative activation paired with a positive outgoing weight also lowers the receiving neuron’s weighted sum: the contribution’s sign depends on both factors in .
With bias and nonlinear activation included, the whole network now computes
Here acts on each hidden pre-activation, and is the output neuron’s scalar bias. Incoming rows still read the input, hidden neurons still supply scalar coordinates, and those scalars still multiply outgoing columns. Bias and activation change how we obtain the scalars. Unlike the identity-activation case, a network with ReLU generally cannot be replaced by one fixed matrix across all inputs.
Training the classifier on real messages
To compare our manual detectors with learned ones, we trained the same network on real messages from the SMS Spam Collection. Each message supplies three word counts—claim, prize, and meeting—and a spam/non-spam label. Training started from random weights and adjusted the weights and biases to improve predictions, without assigning detector roles. You can run the experiment yourself .
We used 4,128 messages for training and reserved 1,031 for testing. This deliberately limited vocabulary misses most spam messages, but it lets us inspect exactly what each neuron learns.
The table compares our manual detectors with the learned neurons. We paired them after training by examining:
- Which words increase or suppress their responses.
- Whether those responses raise or lower the spam score.
The manual values are from our ReLU example, with promotional bias and routine bias . The learned values are rounded to four decimal places.
| Parameter | Manual promotional | Learned neuron 0 | Manual routine | Learned neuron 1 |
|---|---|---|---|---|
| Incoming weight for claim | +1.5 | +2.5743 | 0 | −1.2761 |
| Incoming weight for prize | +1 | +2.5039 | 0 | −1.3264 |
| Incoming weight for meeting | 0 | −0.1353 | +2 | +2.6763 |
| Hidden bias | −3 | −0.0160 | 0 | +1.2650 |
| Outgoing weight into the spam score | +1 | +3.0799 | −1 | −1.5553 |
The output bias changed from our manual to a learned .
Neuron 0 resembles our promotional reader: claim and prize have positive incoming weights, and the positive outgoing weight turns its response into evidence for spam. Training gave the two words nearly equal weights, where we gave claim more weight. It also learned a small negative meeting weight and a bias close to zero, so a single claim or prize activates it; our manual bias of required a stronger input.
Neuron 1 resembles our routine reader, but has a broader role. Meeting increases its response, and its negative outgoing weight lowers the spam score. Unlike our manual reader, it also uses negative claim and prize weights to suppress that response. Its positive bias makes it active even when none of the tracked words appear, supplying default non-spam evidence.
Training learned similar detector roles using different parameter values. Our manual weights were chosen to explain the mechanism; they were not target values for training. The comparison therefore focuses on what the neurons respond to and how their responses affect the prediction.
Disable a neuron and measure its effect
To test each neuron’s role, we set its activation to zero on every held-out input, keeping the other activation, weights, and biases fixed. This removes exactly its contribution; we do not retrain the model.
| Model intervention | Class predictions changed | Spam detected out of 128 | Cross-entropy loss |
|---|---|---|---|
| Original model | — | 25 | 0.3213 |
| Disable neuron 0 | 25 | 0 | 0.3400 |
| Disable neuron 1 | 0 | 25 | 0.6215 |
Removing neuron 0 eliminates every successful spam detection. Removing neuron 1 changes no predicted classes, because the remaining output bias still gives zero-count inputs a negative score. But their predicted spam probability rises from 10.76% to 46.30%, and the loss increases substantially. A neuron can affect the probability estimates even when it changes no thresholded predictions.
Does training always find those roles?
We repeated training with 11 random initializations, keeping the data split, minibatch order, and training settings fixed. All runs made the same held-out class predictions, but their internal mechanisms differed. In one run, a neuron was inactive on every test input. In another, both outgoing weights were negative: a positive output bias supplied the spam score, and neuron activations reduced it.
The read–activate–write calculation holds in every run, but a positive-writing promotional detector is only one possible learned implementation. Class predictions alone do not tell us which implementation a network uses.
The narrow encoding also limits what this experiment establishes. All 103 missed spam messages share the zero vector with 893 non-spam messages. The simple rule “claim or prize occurs” matches every held-out class prediction, so this experiment does not show that nonlinear depth is necessary for these decisions.
Our hand-chosen detectors resemble behavior that training can learn from real messages. In the saved run, neuron 0 learned to respond to claim and prize and increase the spam score, without us assigning it that role. Disabling it removed all 25 successful spam detections. Neuron 1 learned to lower the score, with meeting strengthening its response, although its bias also made it active when no tracked words appeared.
The resemblance is useful, but the learned roles are less tidy than our manual ones: both neurons use all three inputs, and other random initializations found different ways to make the same predictions. Our example illustrates how learned weights can detect useful patterns and turn those responses into predictions. This small experiment does not establish that larger networks give each human concept its own neuron.
Another reading direction: recommending movies
The dot product is a central matching mechanism in many machine-learning models. In our feature detectors, it scores how an input matches a neuron’s reading vector, taking both alignment and magnitude into account. The same operation can match a movie’s attributes to a user’s tastes, as illustrated in MLVU’s lecture on embedding models.
Imagine running a movie rental business and wanting to recommend movies your users will enjoy. We could start with two manually chosen features, romance and action, in that order. Each movie gets an attribute vector , and each user gets a preference vector . For the movie, positive coordinates mean more of an attribute than a chosen reference level, and negative coordinates mean less. For the user, positive coordinates mean a preference for more of that attribute, and negative coordinates mean a preference for less.
The two inputs to our scoring calculation might be , a user who likes romance and prefers less action, and , a movie with both attributes above their reference levels. Recall how our spam detector combined the message’s word-count vector with its weight vector . Here, plays the role of the message input , while plays the role of the detector’s weights . Their dot product again produces a single number as its output, now the compatibility score :
For this user, the preference vector acts as a detector for a particular combination: more romance and less action. Its weights encode that pattern—romance raises the response, while action lowers it. The resulting score measures how strongly the movie matches this weighted preference.
The romance match contributes , while the action mismatch contributes . Matching signs raise the score; opposite signs lower it. Two negative values also contribute positively: a user who prefers little romance matches a movie with little romance. Magnitudes determine how much each term matters, so a user coordinate near zero gives that attribute little influence. When scoring movies for the same user, their preference vector acts like a neuron’s incoming weight vector: it determines which movie attributes raise or lower the score, and by how much. A different user supplies a different reading direction. This is the same weighted-sum step we used in our feature detectors.
Learning features without designing them
We followed a message from word counts to detector responses and then to a spam prediction. Each neuron’s incoming weights determine what it reads; its bias and activation function determine the response it produces. That response scales its outgoing weights, contributing to the next layer. Our manual weights made each part of this calculation easy to inspect.
The training experiment showed how similar detector behavior can emerge from examples. We supplied messages and spam labels, but never assigned the neurons their detector roles. Gradients guided updates to the weights and biases through the prediction loss. One neuron learned to respond to claim and prize and raise the spam score; another learned to lower it, with meeting strengthening that response. We interpreted those roles afterward by examining weights, responses, and the effects of disabling neurons.
Movie recommendation provided an additional example of learning useful features. Manually assigning romance and action values to every user and movie would be costly. In the movie example, the model’s designers can instead give each user and movie a learned embedding: a vector whose coordinates are adjustable model parameters. Our message vectors also represent objects numerically, but their input coordinates are word counts computed by a fixed rule. The recommender learns its vectors from observed ratings, using shared patterns across users to estimate preferences for movies they have not rated. This extends the spam example: both the reading vector and the representation it reads can be learned, although their coordinates need not acquire identifiable meanings such as romance or action.
Our spam experiment also showed the limits of assigning meanings to learned parameters. Other initializations produced the same class predictions through different internal mechanisms, so prediction accuracy alone does not reveal what each neuron detects or how it contributes to the decision. Our promotional reader demonstrated how a reading direction can combine several input coordinates: it responds to both claim and prize. Broader work on learned representations explores features distributed across several neurons and individual neurons responding to several distinct features, called polysemanticity. Our small experiment did not test those phenomena. The reading-and-writing calculation gives us a starting point for investigating them: what produces a response, where it contributes, and how that contribution affects the model’s behavior.