Representation Learning

Stop hand-designing features and let the model learn useful descriptions of the data.

The Big Question

Throughout the Representation section, the same idea kept returning. Models became more powerful when we changed how the data was represented.

Decision trees represented data as a hierarchy of decisions. Random Forests and Gradient Boosting combined many tree representations. SVMs searched for a robust linear boundary. Kernel methods manually transformed data into richer feature spaces.

That raises a deeper question. If better representations lead to better models, why are humans designing the representations at all?

Can a machine learn its own representation?

This is not just another algorithm. It is the conceptual bridge from classical machine learning to modern deep learning.

Core Intuition

Imagine predicting whether Jessie orders a burger. The dataset contains hours since last meal, burger price, friends ordering burgers, and restaurant distance. These are raw features.

FeatureValuePossible concept
Hours since last meal8hunger
Burger price$16price sensitivity
Friends ordering burgers4social pressure
Restaurant distance12 minutesconvenience

Jessie is not really responding to the number 8. She is responding to hunger. She is not responding directly to the number 4. She is responding to social influence. The problem is that nobody measured those concepts.

Representation learning is the process of automatically discovering useful features from data. The model learns internal descriptions that make the prediction task easier.

A child learning to recognize dogs does something similar. At first, the child sees colors and pixels. Over time, useful concepts such as ears, tails, noses, and fur emerge because they help distinguish dogs from other things.

Interactive Demo

Learned representation lab
Raw feature spaceoverlapping
Learned representationsame classifier

Hidden activations

B1z = [0.50, 0.50]
B2z = [0.50, 0.50]
B3z = [0.50, 0.50]
B4z = [0.50, 0.50]

What changed?

The vertical classifier stays fixed. Training changes the internal coordinates so examples with similar outcomes move closer together.

Classifier accuracy
50%

The classifier is intentionally simple. The representation does the heavy lifting.

Class separation8%

This is the bridge to deep learning: hidden layers learn coordinates that make the task easier for the output layer.

Move the training slider. The classifier stays the same, but the internal representation becomes more organized. That is the point: the difficult part is often finding the right representation, not choosing a fancier classifier.

Mathematics

The General Idea

Suppose the original input is xx. Instead of predicting directly from xx, we first learn a transformation:

z=f(x)z=f(x)

The vector zz is the learned representation. The prediction is then made from zz rather than the raw input:

y^=g(z)\hat y=g(z)

Combining the two functions gives:

y^=g(f(x))\hat y=g(f(x))

The function ff learns useful features. The function gg uses those features to make predictions.

Worked Example

Suppose Jessie has raw input x=(8,16,4)x=(8,16,4), representing hours since eating, burger price, and friends ordering burgers. A learned representation might be:

z=(0.92,0.15,0.81)z=(0.92,0.15,0.81)

These numbers no longer correspond to obvious physical quantities. They are coordinates in a learned feature space. Two people with similar burger-buying behavior should produce similar representations, even if their raw inputs differ.

TypeExampleMeaning
Raw featureHours since last meal = 8A measured number in the dataset.
Human conceptHunger = highA meaningful idea the raw number only hints at.
Learned representationz_1 = 0.92A model-discovered coordinate that may or may not be human-readable.

Why It Works

The optimization objective has not changed. We still minimize prediction loss. The difference is that we now optimize both the representation and the predictor at the same time.

Previously, feature engineering fixed ff by hand and training learned only gg. Representation learning lets training adjust both ff and gg.

minf,giL(yi,g(f(xi)))\min_{f,g}\sum_i L(y_i,g(f(x_i)))

As training reduces the loss, the learned representation gradually becomes more useful for the task.

What Makes A Good Representation?

A good representation should:

Place similar examples close together

Examples with similar behavior should have nearby coordinates.

Separate different concepts

Useful differences should become easier for a simple predictor to detect.

Ignore irrelevant variation

Noise and nuisance details should matter less.

Preserve task-relevant information

The representation should keep what the prediction needs.

Notice that human interpretability is not required. Some of the best representations are difficult to name, but they are still useful.

Why It Changed Machine Learning

For decades, progress often depended on better feature engineering. Researchers designed image descriptors, speech features, text features, and domain-specific transformations by hand.

Modern deep learning shifted the focus. Instead of hand-designing representations, we build models that learn representations automatically. This is one reason deep learning became so effective for images, speech, and natural language.

Implementation

This sketch shows the shape of a one-hidden-layer network. Do not worry about backpropagation yet. The important idea is that the hidden layer is a learned representation.

import numpy as np

def relu(x):
    return np.maximum(0, x)

def sigmoid(x):
    return 1 / (1 + np.exp(-np.clip(x, -500, 500)))

class OneHiddenLayerNetwork:
    def __init__(self, input_dim, hidden_dim):
        self.W1 = 0.01 * np.random.randn(input_dim, hidden_dim)
        self.b1 = np.zeros(hidden_dim)
        self.W2 = 0.01 * np.random.randn(hidden_dim, 1)
        self.b2 = 0.0

    def forward(self, X):
        z = relu(X @ self.W1 + self.b1)      # learned representation
        y_hat = sigmoid(z @ self.W2 + self.b2)
        return z, y_hat

model = OneHiddenLayerNetwork(input_dim=3, hidden_dim=4)
z, predictions = model.forward(X)

print("hidden representation", z[:5])
print("predictions", predictions[:5])

During training, the hidden representations change. Examples that need similar predictions can move closer together in hidden space, even if their raw inputs look different.

Interview Discussion

What is representation learning?

It is the process of automatically learning useful features or internal descriptions of data from the training objective.

How is it different from feature engineering?

In feature engineering, humans design transformations. In representation learning, the model learns transformations while learning the task.

What is a learned representation?

It is a transformed version of the input, often a vector, that makes the prediction task easier.

Why are hidden layers considered learned representations?

A hidden layer transforms the input into new activations. Training adjusts those activations so they become useful for the output task.

Why was representation learning a turning point?

It reduced dependence on hand-crafted features and made it possible to learn useful abstractions from raw data at scale.

Active Recall

1. What is a representation?

2. Why are raw features often insufficient?

3. What is the difference between feature engineering and representation learning?

4. What does the function f(x) represent?

5. Why can learning the representation improve prediction without changing the classifier?

Common Mistakes

  • Thinking representation learning is a specific algorithm.
  • Assuming learned features must be human-interpretable.
  • Confusing the representation with the prediction.
  • Believing representation learning only exists in deep learning.

Connection To Embeddings

Kernel methods improved machine learning by manually designing richer feature spaces. Representation learning removes the manual design step. Instead of asking humans to invent useful transformations, the model discovers them automatically from data. The next question is how a machine can actually learn those representations. That leads to neural networks and hidden layers.