cd /news/machine-learning/what-a-neural-network-actually-compu… · home topics machine-learning article
[ARTICLE · art-87973] src=dev.to ↗ pub= topic=machine-learning verified=true sentiment=· neutral

What a Neural Network Actually Computes: From Token IDs to Matrix Multiplication

A developer explains that neural networks process text by converting words into token IDs, which are then transformed through matrix multiplication and non-linear activation functions. The post details how layers stack to build representations, why GPUs accelerate deep learning, and how training adjusts weight matrices via gradient descent.

read4 min views1 publishedAug 5, 2026

NLP models cannot process words directly, which is why tokenization[1] exists. Tokenization ends with a list of integers — token IDs like [30642, 1634, 318, ...]

. That list is what actually gets fed into a model. This article answers why NLP models cannot process raw text directly.

The answer is simple: NLP models consist of neural networks that perform matrix multiplication, which needs a list of numbers, not characters.

A neural network is built from layers, and each layer does one core operation: take a vector of numbers in, multiply it by a matrix of learned weights, add a bias, and produce a new vector of numbers out.

Example

A layer takes in a 3-number input vector.

Input vector: [1.0, 0.5, 2.0]

Weight matrix (2 rows, 3 columns — these numbers are what the network learns during training, starting from random values)

import numpy as np

weight_matrix = np.array([
    [0.1, 0.2, 0.3],
    [0.4, 0.5, 0.6]
])

input_vector = np.array([1.0, 0.5, 2.0])

output = weight_matrix @ input_vector    # @ is matrix multiplication in NumPy
print(output)

Output:

[0.8 1.85]

This is the step applied after multiplication. A small non-linear function like ReLU, which is the rule "turn any negative number into zero," applied to the output. Without a non-linear step, stacking layers is mathematically pointless: a layer that doubles its input, followed by a layer that triples its input, is exactly equivalent to one layer that multiplies by 6 — no matter how many purely linear layers you chain, they always collapse into one. A non-linear function like ReLU breaks that collapse, which is why it's included after every layer.

A real network isn't one layer — it's many, stacked one after another. Layer 1's output vector becomes layer 2's input vector, and so on, each with its own learned weight matrix and activation function. Deep learning refers to networks with many such layers stacked in sequence. Each layer transforms the vector a little further, building progressively more useful representations of the original input as it passes through.

The RNN's hidden state vector — "combine the current word with a running summary of everything seen so far" — is exactly this same operation. At every timestep, the RNN takes the current word's vector and the previous hidden state vector, multiplies each by its own learned weight matrix, adds the results together, and passes the combined output through an activation function to produce the new hidden state. At every timestep, the same weight matrix is applied to the previous hidden state.

Because the hidden state is a fixed-size vector, and every timestep applies the same fixed-size weight matrices to it, there is only so much a fixed-size matrix multiplication can preserve as more and more information gets folded in step after step. The compression problem is a direct consequence of forcing arbitrarily long input through the same fixed-size matrix operation over and over, resulting in information dilution.

You could describe a layer's computation as many individual multiply-and-add operations done sequentially. Writing it as one matrix multiplied by one vector instead, lets an entire layer's output be computed as a single operation — and this is exactly why GPUs matter for deep learning. GPUs are hardware built specifically to perform huge numbers of these multiplications and additions simultaneously, in parallel, rather than sequentially. This is also part of why transformers[2] could train at a scale that the RNN's sequential computation never could.

The numbers inside each weight matrix (for e.g. 0.1

, 0.2

, 0.3

) aren't set by a person — they start as random values and get adjusted repeatedly during training, based on how far the network's output was from what it should have been (gradient descent[3]). "Training a neural network" means finding the specific numbers in every weight matrix, across every layer, that make the chain of matrix multiplications produce useful output.

A neural network, essentially, is: token IDs get converted into meaningful vectors, those vectors get passed through a series of layers, each of which is a matrix multiplication followed by a small non-linear step, and the specific numbers inside those matrices are learned from data rather than hand-coded.

The RNN's hidden state update is one particular arrangement of this operation, while the transformer's self-attention is another. A transformer reuses the same weight matrices across every token position within a layer — same underlying idea as the RNN — but it applies them all at once instead of sequentially. Across layers (depth), transformers use different weights per layer, unlike the RNN's single reused set.

Token IDs are arbitrary integers assigned to tokens — they carry no meaning on their own. The next article covers how meaning gets assigned to a token ID.

[1]: For details on tokenization, refer to How Text Becomes Numbers: Tokenization Explained from First Principles

[2]: For details on RNN and transformers, refer to Rules to Learning: Why NLP Needed Transformers

[3]: Gradient descent is the process a network uses to gradually improve its weight matrix numbers in the direction that reduces error.

── more in #machine-learning 4 stories · sorted by recency
── more on @numpy 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/what-a-neural-networ…] indexed:0 read:4min 2026-08-05 ·