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:

MessageClaimPrizeLabel
Claim your prize. Claim it at the meeting.21Spam
The project meeting is tomorrow.00Non-spam
Prize!01Spam

We can now combine the first message’s counts into a vector (2,1)(2,1), 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 xx-axis marking the claim count and the vertical yy-axis marking the prize count. The message sits at the point (2,1)(2,1): 2 along the claim axis and 1 along the prize axis.

The message as a point at (2, 1)The horizontal x-axis counts claim and the vertical y-axis counts prize. The message “Claim your prize. Claim it at the meeting.” has coordinates (2, 1) in this two-word vocabulary. Dashed guides connect the point to 2 on the x-axis and 1 on the y-axis.0112233claimprize(2, 1)

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:

MessageClaimPrizeMeetingLabel
Claim your prize. Claim it at the meeting.211Spam
The project meeting is tomorrow.001Non-spam
Prize!010Spam

In the first message, meeting appears once, so the vector becomes (2,1,1)(2,1,1). All three coordinates are nonzero. Other messages still record zero for absent words. The coordinate order is claim, prize, then meeting.

Message vector: geometry on the claim, prize, meeting axesThe orange input vector x = (2, 1, 1) is shown on the claim, prize, meeting axes. Drag or use arrow keys to rotate. Shift-drag or Shift-arrow keys to pan. Scroll or use plus and minus to zoom. Press 0 to reset the view.claimprizemeetingx

Input x = (2, 1, 1)

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:

MessageWord-count vector
Prize!(0,1,0)(0,1,0)
Claim your prize. Claim it at the meeting.(2,1,1)(2,1,1)
The project meeting is tomorrow.(0,0,1)(0,0,1)
Claim your prize at the meeting.(1,1,1)(1,1,1)

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:

c=w1x1+w2x2+w3x3=∑j=13wjxj.c=w_1x_1+w_2x_2+w_3x_3=\sum_{j=1}^{3}w_jx_j.

Here xjx_j is the value of input feature jj, and wjw_j is its corresponding weight. The inputs form the vector xx, and the stored weights form the neuron’s incoming weight vector ww. We can also name a coordinate by its feature: xclaimx_{\mathrm{claim}} denotes the claim count in the input vector xx.

The full neuron calculation then adds a bias β\beta to this score and applies an activation function ϕ\phi, which can introduce nonlinearity. This produces the neuron’s output hh:

h=ϕ(c+β).h=\phi(c+\beta).

To make the demonstration simpler, we will use zero bias and an identity activation function, so the output is the weighted sum itself:

h=c.h=c.

The diagram below shows this calculation for our message vector (2,1,1)(2,1,1): each count is multiplied by its corresponding weight, and the three contributions are added to produce the score cc.

Three input counts, three weights, one neuronThe word counts are claim 2, prize 1, and meeting 1. Each count is multiplied by its corresponding weight, w1 through w3. The neuron adds the results to produce the scalar c. With zero bias, c equals 2 times w1 plus w2 plus w3. Numerical weights have not yet been chosen.Input countsWeightsclaim2× w₁prize1× w₂meeting1× w₃One neuronΣAddScorecc = 2w₁ + 1w₂ + 1w₃

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 w=(1,0,0)w=(1,0,0). When the neuron processes our input, it computes the weighted sum:

c=1×2+0×1+0×1=2.c=1\times2+0\times1+0\times1=2.

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 1.51.5 and prize a weight of 11, while keeping meeting at 00:

wpromo=(1.5,1,0).w_{\mathrm{promo}}=(1.5,1,0).

When the neuron computes the weighted sum for the same message using these new weights, we get:

cpromo=1.5×2+1×1+0×1=4.c_{\mathrm{promo}}=1.5\times2+1\times1+0\times1=4.

With these weights, each occurrence of claim contributes 1.51.5 to the score, each prize contributes 11, 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, w=(0,1,−1)w=(0,1,-1) computes the prize count minus the meeting count: each occurrence of meeting lowers the score by 11. 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 (2,1,1)(2,1,1) 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:

c=∑j=13wjxj=w⊤x.c=\sum_{j=1}^{3}w_jx_j=w^\top x.

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 xx and ww as column vectors with three rows and one column, and use w⊤w^\top to represent the weights as a one-row, three-column matrix so that multiplying it by the input column xx produces one score.

For nonzero vectors, we can also express this same dot product geometrically, using the vectors’ lengths and the angle between them:

h=c=w⊤x=∥w∥ ∥x∥cos⁡θ,h=c=w^\top x=\lVert w\rVert\,\lVert x\rVert\cos\theta,

where θ\theta 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 ∥w∥∥x∥\lVert w\rVert\lVert x\rVert, which sets the scale, and cos⁡θ\cos\theta, which captures the vectors’ alignment. For example, doubling the weights to (3,2,0)(3,2,0) 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 (1.5,1,0)(1.5,1,0) is shown in blue and the message vector (2,1,1)(2,1,1) in orange. The angle between them describes their alignment; their dot product combines that alignment with both vectors’ lengths to produce the score 44 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.

Promotion reader: geometry on the claim, prize, meeting axesReader (1.5, 1, 0), shown input (2, 1, 1). Their angle in three dimensions is 25.066 degrees. The shaded claim–prize plane shows meeting = 0. Dot product 4. All three word coordinates are shown. Drag or use arrow keys to rotate. Shift-drag or Shift-arrow keys to pan. Scroll or use plus and minus to zoom. Press 0 to reset the view.claimprizemeetingwx

Reader w = (1.5, 1, 0)

Input x = (2, 1, 1)

3D angle θ25.1°
Dot-product score

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 cc to denote a neuron’s weighted-sum score and add a subscript to identify the detector. So, for the promotional detector, the formula is:

cpromo=1.5xclaim+xprizec_{\mathrm{promo}}=1.5x_{\mathrm{claim}}+x_{\mathrm{prize}}

Each additional occurrence of claim raises the score by 1.51.5, and each additional prize raises it by 11. 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 22 and setting the claim and prize weights to 00:

wroutine=(0,0,2),croutine=2xmeetingw_{\mathrm{routine}}=(0,0,2), \qquad c_{\mathrm{routine}}=2x_{\mathrm{meeting}}

Let’s apply these weights to our starting message and to the project-meeting message:

Messagewmeeting×xmeetingw_{\mathrm{meeting}}\times x_{\mathrm{meeting}}Score
Claim your prize. Claim it at the meeting.2×12\times12
The project meeting is tomorrow.2×12\times12

We now have two neurons receiving the same three-coordinate input xx. Each produces one scalar response, and these responses together form the layer’s output vector h=(cpromo,croutine)h=(c_{\mathrm{promo}},c_{\mathrm{routine}}):

MessagePromotional responseRoutine responseLayer output hh
Claim your prize. Claim it at the meeting.42(4,2)(4,2)
The project meeting is tomorrow.02(0,2)(0,2)
Prize!10(1,0)(1,0)
Claim your prize at the meeting.2.52(2.5,2)(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 hh.

“Claim your prize. Claim it at the meeting.”

Three vocabulary coordinates become two neuron responsesFor “Claim your prize. Claim it at the meeting.”, the three input counts are 2, 1, 1. Both neurons receive all three counts. The promotional neuron uses weights 1.5 and 1 for claim and prize, producing 4. The routine neuron reads meeting with weight 2, producing 2. Dashed connections have zero weight. The three-dimensional input becomes the two-dimensional activation vector (4, 2).claim2prize1meeting11.514Promotional22Routine

We can describe the layer shown above in matrix form by collecting the neurons’ weight vectors into one weight matrix WW. The first row contains the promotional neuron’s weights, and the second contains the routine neuron’s weights:

W=[1.510002]W=\begin{bmatrix} 1.5&1&0\\ 0&0&2 \end{bmatrix}

Each row corresponds to one neuron, and each column corresponds to one input feature: claim, prize, or meeting. This makes WW a 2×32\times3 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 WW, the row space is the plane spanned by the promotional reader (1.5,1,0)(1.5,1,0) and the routine reader (0,0,2)(0,0,2) in the claim–prize–meeting input space. Its column space is the full promotional–routine response plane: all output pairs h=Wxh=Wx 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, x=(2,1,1)⊤x=(2,1,1)^\top, this gives

h=Wx=[wpromo⊤xwroutine⊤x]=[1.5(2)+1(1)+0(1)2(1)]=[42]h=Wx =\begin{bmatrix}w_{\mathrm{promo}}^\top x\\w_{\mathrm{routine}}^\top x\end{bmatrix} =\begin{bmatrix} 1.5(2)+1(1)+0(1)\\ 2(1) \end{bmatrix} =\begin{bmatrix}4\\2\end{bmatrix}

The result hh 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 hh 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 hh, containing the promotional response h1h_1 and routine response h2h_2. 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 +1+1 for the promotional response and −1-1 for the routine response, keeping its bias at zero. The classification score is described by the formula s=(+1)h1+(−1)h2=h1−h2s=(+1)h_1+(-1)h_2=h_1-h_2, where ss 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.

× (−1)Contribution: −2
× (+1)Contribution: 4
s = (+1) × 4 + (−1) × 2 = 2Spam

We chose the classification neuron’s weights, +1+1 and −1-1, 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 WW, we can collect the classification neuron’s weights into matrix VV. This weight matrix has one row and two columns. We write the hidden layer’s output hh as a column vector, with the promotional response h1h_1 followed by the routine response h2h_2, so that multiplying VV by hh gives the classification score ss:

V=[1−1],h=[h1h2],s=Vh.V=\begin{bmatrix}1&-1\end{bmatrix}, \qquad h=\begin{bmatrix}h_1\\h_2\end{bmatrix}, \qquad s=Vh.

Whether chosen by hand or learned through training, these weights produce a classification score that can be negative or greater than 11. A probability, however, must lie between 00 and 11. To express the result as a probability, we could apply the sigmoid function to the completed score:

P(spam∣x)=σ(s)=11+e−s.P(\mathrm{spam}\mid x)=\sigma(s)=\frac{1}{1+e^{-s}}.

A positive score gives a probability above 0.50.5; a negative score gives one below 0.50.5. Thresholding that probability at 0.50.5 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 1−P(spam∣x)1-P(\mathrm{spam}\mid x). 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 11.

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.

“Claim your prize. Claim it at the meeting.”

Three input units, two hidden neurons, and one output neuronFor “Claim your prize. Claim it at the meeting.”, the three input counts are 2, 1, 1. Both neurons receive all three counts. The promotional neuron uses weights 1.5 and 1 for claim and prize, producing 4. The routine neuron reads meeting with weight 2, producing 2. Dashed connections have zero weight. The three-dimensional input becomes the two-dimensional activation vector (4, 2). The output neuron combines these responses with weights +1 and −1 to give a score of 2: Spam.Input xHidden layer hOutput s+1−1claim2prize1meeting11.514Promotional22Routine2Spams = (+1) × 4 + (−1) × 2 = 2

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. Feature detectors shows how the two readers act on the 3D word-count vector xx to produce the response vector hh. Classifier shows how those responses contribute to the final classification score on a number line. Switching views keeps the same message.

The claim, prize, and meeting 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 h=(4,4)h=(4,4), 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 word counts (2, 1, 1) in three dimensionsThe blue vector is the input. Green w₁ = (1.5, 1, 0) is the promotional reader; purple w₂ = (0, 0, 2) is the routine reader. Reader arrows show directions with display lengths adjusted for visibility. Angles are calculated in 3D, not measured on the screen. Drag or use arrow keys to rotate. Shift-drag or Shift-arrow keys to pan. Scroll or use plus and minus to zoom. Press 0 to reset the view.claimprizemeetingw₁w₂x0

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: h1>h2h_1>h_2 gives spam, h1<h2h_1<h_2 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 VV. 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 VhVh.

Let’s make this writing view concrete by expanding the classifier’s calculation one detector at a time. Its weight matrix VV has two columns, one for each detector. We’ll first use symbolic weights aa and bb to show how the contributions combine, then substitute their numerical values. Let aa denote the promotional detector’s outgoing weight and bb the routine detector’s outgoing weight. We name the columns v1v_1 and v2v_2 so we can follow each detector’s contribution separately: h1h_1 scales the first column, and h2h_2 scales the second.

V=[ab],v1=[a],v2=[b].V=\begin{bmatrix}a&b\end{bmatrix}, \qquad v_1=\begin{bmatrix}a\end{bmatrix}, \qquad v_2=\begin{bmatrix}b\end{bmatrix}.

The promotional activation h1h_1 multiplies the first column, containing aa; the routine activation h2h_2 multiplies the second column, containing bb. Their contributions add in the single output coordinate:

Vh=h1v1+h2v2=h1[a]+h2[b]=[h1a+h2b].Vh=h_1v_1+h_2v_2 =h_1\begin{bmatrix}a\end{bmatrix} +h_2\begin{bmatrix}b\end{bmatrix} =\begin{bmatrix}h_1a+h_2b\end{bmatrix}.

In our classifier, a=1a=1 and b=−1b=-1. Each column has just one entry because there is only one receiving neuron. For our starting message, the promotional detector produces h1=4h_1=4, and the routine detector produces h2=2h_2=2. Their contributions are

h1v1=4[1]=[4],h2v2=2[−1]=[−2].h_1v_1=4\begin{bmatrix}1\end{bmatrix}=\begin{bmatrix}4\end{bmatrix}, \qquad h_2v_2=2\begin{bmatrix}-1\end{bmatrix}=\begin{bmatrix}-2\end{bmatrix}.

For each detector, hih_i is the computed activation, viv_i is the stored column of outgoing weights, and hivih_iv_i is the contribution to the next layer. Both activations are positive, but their outgoing weights give their contributions opposite signs: the promotional detector adds 44 to the classification score, while the routine detector subtracts 22. With one receiving neuron, these contributions lie on a single number line. Adding them gives

Vh=h1v1+h2v2=[4]+[−2]=[2].Vh=h_1v_1+h_2v_2 =\begin{bmatrix}4\end{bmatrix}+\begin{bmatrix}-2\end{bmatrix} =\begin{bmatrix}2\end{bmatrix}.

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 hh by taking its dot product with that neuron’s row of VV. Each dot product produces one coordinate of VhVh, as in the row calculation we used earlier.
  • Writing is the column view: scale and add vectors. Each sending detector’s activation hih_i scales its column viv_i of VV. The resulting contribution vectors add together to produce VhVh.

In our classifier, the receiving neuron reads hh using the row [1,−1][1,-1], while the two sending detectors contribute through the columns [1][1] and [−1][-1]. 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 VV has two rows and two columns:

V=[abcd],v1=[ac],v2=[bd].V=\begin{bmatrix}a&b\\c&d\end{bmatrix}, \qquad v_1=\begin{bmatrix}a\\c\end{bmatrix}, \qquad v_2=\begin{bmatrix}b\\d\end{bmatrix}.

Each row belongs to one receiving neuron. Column v1v_1 contains the first detector’s weights to both receivers, aa and cc; column v2v_2 contains the second detector’s weights, bb and dd. The activation h1h_1 scales every entry of v1v_1, while h2h_2 scales every entry of v2v_2:

Vh=h1v1+h2v2=h1[ac]+h2[bd]=[h1a+h2bh1c+h2d].Vh=h_1v_1+h_2v_2 =h_1\begin{bmatrix}a\\c\end{bmatrix} +h_2\begin{bmatrix}b\\d\end{bmatrix} =\begin{bmatrix}h_1a+h_2b\\h_1c+h_2d\end{bmatrix}.

Now follow just the first detector, keeping its activation h1=4h_1=4 for our starting message. With a=1a=1 and c=−2c=-2, its contribution is

h1v1=4[1−2]=[4−8].h_1 v_1=4\begin{bmatrix}1\\-2\end{bmatrix} =\begin{bmatrix}4\\-8\end{bmatrix}.

The first entry adds 44 to the first receiving neuron’s weighted sum; the second subtracts 88 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, h1=4h_1=4. Its outgoing weights distribute that response across the next layer. More generally, column viv_i has one entry per receiving neuron, and scaling it by activation hih_i produces a contribution vector with the same number of coordinates.

The outgoing weights (1,−2)(1,-2) 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 (4,−8)(4,-8) points in the same direction as (1,−2)(1,-2), 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.

A larger activation scales the same writing directionThe horizontal axis is the contribution to the first receiving neuron's weighted sum; the vertical axis is the contribution to the second's. Both axes use the same scale. The solid blue outgoing weight vector v₁ = (1, −2) defines the detector's writing direction. A dashed orange arrow follows the same direction to (4, −8), showing the scaled contribution h₁v₁ when activation h₁ equals 4. The arrows overlap: the orange arrow is four times as long. These are one detector's contributions, not the receiving layer's final outputs.012345-2-4-6-8Contribution to first receiverContribution to second receiverv₁ = (1, −2)h₁v₁ = (4, −8)Outgoing vectorDefines writing directionScaled contributionwhen h₁ = 4Same direction,four times the length

The column, the activation, and the next layer each play a distinct role:

  • The column defines the writing direction. The nonzero vector viv_i specifies the relative effects of one detector on the receiving neurons.
  • The activation scales the contribution. With viv_i fixed, the contribution hivih_i v_i has magnitude ∣hi∣∥vi∥|h_i|\lVert v_i\rVert.
  • The next layer sums the contributions. It combines all the vectors hivih_i v_i, 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, h1=4h_1=4 makes the contribution four times as long as v1v_1, 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 WW, through its activation, to its writing weights in VV.

Detectors read through rows of W and write through columns of VFrom left to right: input vector x with coordinates x₁, x₂, x₃; incoming matrix W with rows (w₁₁, w₁₂, w₁₃) and (w₂₁, w₂₂, w₂₃); detector activations h₁ and h₂; and outgoing matrix V with columns v₁ = (v₁₁, v₂₁) and v₂ = (v₁₂, v₂₂), defining the detectors’ writing directions. Blue follows the first detector from its incoming row to its outgoing column; purple follows the second. This uses zero bias and identity activation. Both matrices remain fixed during the forward pass.Input spaceInput coordinates xReading weights WOne row per detectorDetectorsScalar activations hWriting weights VNext layer’s matrixx₁x₂x₃w₁₁w₁₂w₁₃dot productw₂₁w₂₂w₂₃dot productRows define what detectors readh₁h₂scales v₁scales v₂v₁v₁₁v₂₁v₂v₁₂v₂₂Columns define writing directionsRead: h = WxWrite: Vh = h₁v₁ + h₂v₂

For the whole layer, the contributions add together with the next layer’s bias:

znext=Vh+βnext=∑ihivi+βnextz_{\mathrm{next}}=Vh+\beta_{\mathrm{next}}=\sum_i h_i v_i+\beta_{\mathrm{next}}

Here βnext\beta_{\mathrm{next}} is the next layer’s bias vector and znextz_{\mathrm{next}} is its pre-activation vector; its activation function is applied afterward. The same activation hih_i 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 WW and writes through a column of VV. The rows of VV 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 h=Wxh=Wx and the classification score is s=Vhs=Vh. Substituting the first expression into the second gives

s=V(Wx)=(VW)x.s=V(Wx)=(VW)x.

The column view explains why this works. Each column of WW describes how one word count contributes to the hidden activation vector. Multiplying by VV transforms each of those columns into its contribution to the final score:

Input coordinateColumn of WWAfter applying V=[1,−1]V=[1,-1]
claim(1.5,0)(1.5,0)1.51.5
prize(1,0)(1,0)11
meeting(0,2)(0,2)−2-2

These transformed columns form the product VWVW:

VW=[1−1][1.510002]=[1.51−2].VW= \begin{bmatrix}1&-1\end{bmatrix} \begin{bmatrix} 1.5&1&0\\ 0&0&2 \end{bmatrix} =\begin{bmatrix}1.5&1&-2\end{bmatrix}.

Because VV is linear, combining the columns of WW 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 VWVW therefore takes the original input directly to the score.

So the same score can be calculated directly from the word counts:

s=1.5xclaim+xprize−2xmeeting.s=1.5x_{\mathrm{claim}}+x_{\mathrm{prize}}-2x_{\mathrm{meeting}}.

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 cic_i, the score sis_i after adding bias βi\beta_i, and the activation hih_i passed to the next layer:

ci=wi⊤x,si=ci+βi,hi=ReLU⁡(si)=max⁡(0,si).c_i=w_i^\top x,\qquad s_i=c_i+\beta_i,\qquad h_i=\operatorname{ReLU}(s_i)=\max(0,s_i).

ReLU passes positive pre-activations through and replaces negative ones with zero. Add bias −3-3 to the promotional reader:

h1=max⁡(0,1.5xclaim+xprize−3).h_1=\max(0,1.5x_{\mathrm{claim}}+x_{\mathrm{prize}}-3).

Our original message has raw score 44, so its pre-activation and activation are 11. A message containing claim once and none of the other selected words has raw score 1.51.5, pre-activation −1.5-1.5, and activation 00. This reader now contributes only when its weighted count exceeds 33. 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 11 to 22 leaves the activation at 00, while increasing it from 44 to 55 raises the activation from 11 to 22. 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 h=(1,2)h=(1,2) and s=−1s=-1, 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 44 and −3-3 give ReLU⁡(4−3)=1\operatorname{ReLU}(4-3)=1, whereas clipping each contribution first would give 44. 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 w=(−2,1,0)w=(-2,1,0) applied to our original input x=(2,1,1)x=(2,1,1) give raw score (−2)×2+1×1=−3(-2)\times2+1\times1=-3. 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 v2=−1v_2=-1, 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 hivih_i v_i.

With bias and nonlinear activation included, the whole network now computes

h=ϕ(Wx+β),s=Vh+b=∑ihivi+b.h=\phi(Wx+\beta),\qquad s=Vh+b=\sum_i h_i v_i+b.

Here ϕ\phi acts on each hidden pre-activation, and bb 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 Open in molab.

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 −3-3 and routine bias 00. The learned values are rounded to four decimal places.

ParameterManual promotionalLearned neuron 0Manual routineLearned neuron 1
Incoming weight for claim+1.5+2.57430−1.2761
Incoming weight for prize+1+2.50390−1.3264
Incoming weight for meeting0−0.1353+2+2.6763
Hidden bias−3−0.01600+1.2650
Outgoing weight into the spam score+1+3.0799−1−1.5553

The output bias changed from our manual 00 to a learned −0.1484-0.1484.

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 −3-3 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 hivih_i v_i contribution; we do not retrain the model.

Model interventionClass predictions changedSpam detected out of 128Cross-entropy loss
Original model—250.3213
Disable neuron 02500.3400
Disable neuron 10250.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 mm, and each user gets a preference vector uu. 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 u=(2,−1)u=(2,-1), a user who likes romance and prefers less action, and m=(3,1)m=(3,1), a movie with both attributes above their reference levels. Recall how our spam detector combined the message’s word-count vector x=(2,1,1)x=(2,1,1) with its weight vector w=(1.5,1,0)w=(1.5,1,0). Here, mm plays the role of the message input xx, while uu plays the role of the detector’s weights ww. Their dot product again produces a single number as its output, now the compatibility score ss:

s=u⊤m=2×3+(−1)×1=5.s=u^\top m=2\times3+(-1)\times1=5.

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 66, while the action mismatch contributes −1-1. 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 uu 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.

Image viewer

Pinch or use + / − to zoom. Drag or use arrow keys to move. Esc to close.