How Data Becomes Numbers
A model does arithmetic, so every input — text, images, categories — must first become a vector of numbers. Here is how that conversion works and why it matters.
On this page
A machine learning model does one kind of work: arithmetic on numbers. It multiplies, adds, and compares. It has no notion of “Tuesday” or “the word cat” or “a red pixel.” So before any learning happens, every input has to be turned into a list of numbers — a vector. This step is called feature engineering or encoding, and getting it wrong caps everything downstream.
The target: a vector of numbers
The model wants each example as a fixed-length row of numbers. A house might become [1450, 3, 2, 1998] — square footage, bedrooms, bathrooms, year built. Each position is a feature, and the whole list is a feature vector.
Fixed-length matters. Every house has to map to the same number of slots in the same order, so the model can learn “the number in slot 0 tends to raise the price.” If one house had four numbers and the next had six, the arithmetic would not line up.
Numbers that are already numbers are the easy case. The interesting problems are everything else: categories, text, images.
Encoding categories
Suppose a feature is color: red, green, or blue. The tempting move is red=1, green=2, blue=3. This is usually a mistake. It tells the model blue (3) is “more than” red (1) and that green sits exactly between them. That ordering is fiction, and the model will try to learn from it.
The fix is one-hot encoding: give each category its own slot, set to 1 if present and 0 otherwise. Red becomes [1, 0, 0], green [0, 1, 0], blue [0, 0, 1]. No false ordering, no false distances. The cost is width — a feature with a thousand categories becomes a thousand slots, mostly zeros.
When a category genuinely is ordered — small, medium, large — a single number that respects the order (1, 2, 3) is fine and far more compact. The rule is: encode the structure that really exists, and no more.
Encoding text
Text is the hard case, and how you handle it defines an era of the field.
The oldest approach counts words. Bag-of-words makes one slot per vocabulary word and fills each with how often that word appears. Simple, and it throws away all word order — “dog bites man” and “man bites dog” get identical vectors.
The modern approach is different in kind. Text is first split into tokens, and each token maps to a learned dense vector called an embedding — a few hundred numbers positioned so that similar meanings sit close together. Nobody hand-assigns those numbers; the model learns them so that “king” and “queen” land near each other. This is the bridge from this layer to how LLMs actually read text, and the deeper mechanics live in word2vec and embedding space geometry.
Encoding images
An image is already numeric if you look closely. A grayscale pixel is one number, its brightness from 0 to 255. A color pixel is three — red, green, blue intensities. A photo is just a grid of these, and flattening the grid into a long list gives you a vector.
A modest 200x200 color image is 200 x 200 x 3 = 120,000 numbers. That is large, and treating each pixel as an independent feature ignores the fact that neighboring pixels are related. Handling that spatial structure efficiently is a whole architectural topic, but the starting point is simply: pixels are numbers, an image is a grid of them.
Why scale matters: normalization
Return to the house: [1450, 3, 2, 1998]. Square footage runs into the thousands; bedrooms are single digits. To a model doing raw arithmetic, the big numbers shout and the small ones whisper — square footage dominates purely because of its scale, not its importance.
Normalization rescales every feature to a comparable range, often roughly -1 to 1 or a mean of 0. After normalizing, each feature starts on equal footing and the model decides what matters from the data, not from an accident of units. Skipping this step is one of the most common reasons a model trains slowly or badly, and it connects directly to why gradient descent struggles when features live on wildly different scales.
Garbage in, garbage out
The encoding is what the model sees. If your encoding hides the signal — false orderings, dropped word order, unscaled features — no amount of clever architecture recovers it. A great deal of real machine learning work is not model tuning but deciding how to turn messy reality into honest numbers.
What to remember
- Models do arithmetic, so every input becomes a fixed-length vector of numbers before any learning.
- Encode only the structure that exists: one-hot for unordered categories, a single ordered number for ordered ones.
- Text goes from word counts (bag-of-words) to learned dense embeddings; images are grids of pixel numbers.
- Normalize features to comparable scales, or large-valued features dominate for no good reason.
- The encoding caps the ceiling — bad features cannot be rescued by a better model.
Next: What Is a Neural Network? — how a machine turns those numbers into a prediction.