AI State of the Art
Math/Information Theory/13 min
Section 336

Mutual Information and Its Applications in ML

Listen as a podcast β†’

Mutual information: how much two variables share

When you observe an image and predict its label, a fundamental question arises: how much information does the image contain about the label? And conversely, how much does the label tell us about the image? Mutual information answers this question precisely and symmetrically.

Definition

The formula

The mutual information between two random variables XX and YY is:

I(X;Y)=βˆ‘x,yP(x,y)log⁑P(x,y)P(x)P(y)I(X; Y) = \sum_{x, y} P(x, y) \log \frac{P(x, y)}{P(x) P(y)}

It's the KL divergence between the joint distribution P(x,y)P(x, y) and the product of marginals P(x)P(y)P(x) P(y):

I(X;Y)=DKL(P(X,Y)βˆ₯P(X)P(Y))I(X; Y) = D_{KL}(P(X, Y) \| P(X) P(Y))

If XX and YY are independent, P(x,y)=P(x)P(y)P(x, y) = P(x) P(y) and I(X;Y)=0I(X; Y) = 0. The more dependent the variables are, the higher the mutual information.

Equivalent formulas

Mutual information can be expressed in several ways, all instructive:

I(X;Y)=H(X)βˆ’H(X∣Y)I(X; Y) = H(X) - H(X|Y) I(X;Y)=H(Y)βˆ’H(Y∣X)I(X; Y) = H(Y) - H(Y|X) I(X;Y)=H(X)+H(Y)βˆ’H(X,Y)I(X; Y) = H(X) + H(Y) - H(X, Y)

The first one says: mutual information is the reduction in uncertainty about XX when you know YY. It's the initial uncertainty minus the residual uncertainty.

Venn diagram analogy

Think of a Venn diagram:

  • The left circle is H(X)H(X) (total uncertainty of XX)
  • The right circle is H(Y)H(Y) (total uncertainty of YY)
  • The intersection is I(X;Y)I(X; Y) (shared information)
  • The union is H(X,Y)H(X, Y) (joint entropy)
  • H(X∣Y)H(X|Y) is the part of H(X)H(X) outside the intersection
Two panels. On the left, a 2x2 table of the joint distribution between weather (Sunny, Rainy) and umbrella (No umbrella, Umbrella), with 0.45 on the diagonal and 0.05 off the diagonal. On the right, a two-circle Venn diagram: the blue circle is labelled H(X|Y) equals 0.469, the red circle H(Y|X) equals 0.469, the intersection I(X;Y) equals 0.531, with H(X) equals 1.000, H(Y) equals 1.000 and H(X,Y) equals 1.469.
The Venn diagram on a worked example. Weather and carrying an umbrella are strongly linked: the 0.45 entries on the diagonal of the table say the two almost always go together. On the right, each circle is worth 1 bit of uncertainty, but 0.531 bit is shared (the intersection) and only 0.469 bit of uncertainty is left specific to each variable once the other is known. The union of the two circles, 1.469, is indeed the joint entropy and not 2 bits.Source : Wayland Zhan, Information Theory Is All You Need (to Understand LLMs)

Key properties

Symmetry

I(X;Y)=I(Y;X)I(X; Y) = I(Y; X)

Unlike KL divergence, mutual information is symmetric. What XX tells about YY is exactly what YY tells about XX.

Non-negativity

I(X;Y)β‰₯0I(X; Y) \geq 0

with equality if and only if XX and YY are independent.

More general than correlation

Pearson correlation only captures linear dependencies. Mutual information captures any form of statistical dependence. Two variables can have zero correlation but high mutual information (for example, Y=X2Y = X^2 with XX symmetric around 0).

Bounds

0≀I(X;Y)≀min⁑(H(X),H(Y))0 \leq I(X; Y) \leq \min(H(X), H(Y))

The shared information cannot exceed the total information of each variable.

Feature selection

The principle

To choose the most informative features for predicting a target variable YY, you can rank features by decreasing mutual information:

score(Xj)=I(Xj;Y)\text{score}(X_j) = I(X_j; Y)

A feature with high mutual information with the target is potentially useful. A feature with I(Xj;Y)β‰ˆ0I(X_j; Y) \approx 0 is independent of the target and can be eliminated.

Advantages over correlation

  • Captures nonlinear relationships between features and target
  • Doesn't assume any particular distribution
  • Works for both discrete and continuous variables (with kernel or histogram estimation)

Limitations

  • Estimating mutual information in high dimensions is difficult
  • Doesn't account for redundancies between features: two highly correlated features can each have high II with the target, but adding both doesn't bring much

Contrastive learning and InfoNCE

The idea of contrastive learning

Contrastive learning learns representations by bringing together representations of "similar" examples (positives) and pushing apart those of "different" examples (negatives). But what's the connection with mutual information?

InfoNCE loss

The InfoNCE loss (Information Noise Contrastive Estimation), at the heart of SimCLR, CLIP, and many others, is a lower bound on mutual information:

LInfoNCE=βˆ’E[log⁑ef(x,y+)ef(x,y+)+βˆ‘j=1Kef(x,yjβˆ’)]\mathcal{L}_{\text{InfoNCE}} = -E\left[\log \frac{e^{f(x, y^+)}}{e^{f(x, y^+)} + \sum_{j=1}^{K} e^{f(x, y_j^-)}}\right]

where ff is a similarity function between representations, y+y^+ is the positive example, and yjβˆ’y_j^- are the KK negative examples.

It can be shown that:

I(X;Y)β‰₯log⁑(K+1)βˆ’LInfoNCEI(X; Y) \geq \log(K + 1) - \mathcal{L}_{\text{InfoNCE}}

Minimizing the InfoNCE loss maximizes a lower bound on the mutual information between the representations of the two views. That's why contrastive learning is sometimes called "mutual information maximization."

CLIP: a flagship example

CLIP learns image-text representations by maximizing mutual information between image and text embeddings that correspond to each other. The image of a cat and the sentence "a photo of a cat" share information about the visual content. CLIP captures this shared information in a common embedding space.

The Information Bottleneck

The theoretical framework

The Information Bottleneck theory, proposed by Naftali Tishby in 1999, offers an original perspective on why deep neural networks work. The idea is that a good representation ZZ of an input XX for predicting an output YY must:

  1. Maximize I(Z;Y)I(Z; Y): the representation should contain the maximum relevant information for prediction
  2. Minimize I(Z;X)I(Z; X): the representation should forget the irrelevant details of the input

min⁑Z[βˆ’I(Z;Y)+Ξ²β‹…I(Z;X)]\min_{Z} \left[-I(Z; Y) + \beta \cdot I(Z; X)\right]

The parameter Ξ²\beta controls the tradeoff between compression and prediction.

Interpretation for deep networks

Each layer of a deep network can be seen as a transformation that compresses input information while preserving useful information for the output. The early layers extract many features (high I(Z;X)I(Z; X)), and subsequent layers compress toward the essentials (low I(Z;X)I(Z; X), high I(Z;Y)I(Z; Y)).

The fitting phase and the compression phase

Experimental work has observed two phases during training:

  1. Fitting phase: the network learns to encode relevant information, I(Z;Y)I(Z; Y) increases rapidly
  2. Compression phase: the network forgets irrelevant details, I(Z;X)I(Z; X) decreases while I(Z;Y)I(Z; Y) remains stable

This interpretation remains debated in the scientific community, but it offers an intuitive framework for thinking about what deep networks do.

Six plots for networks with one through six hidden layers. Each has I(X;T) on the horizontal axis and I(T;Y) on the vertical axis, with one trajectory per layer coloured from black (start of training) to yellow (10 to the power 4 epochs). Every trajectory first rises almost vertically, then moves to the left while staying near the top.
The two phases can be read straight off the shape of the trajectories. The horizontal axis is how much information the layer keeps about the input, the vertical axis how much it keeps about the output. The initial vertical climb is the fitting phase: the layer learns to predict. The long turn to the left that follows is the compression phase: the layer forgets the input without losing anything about the output. The deeper the network (bottom right), the more each layer runs this path from its own position.Source : Shwartz-Ziv and Tishby, Opening the Black Box of Deep Neural Networks via Information, via Lilian Weng (Lil Log)

Estimating mutual information

The practical challenge

Computing exact mutual information requires knowing the joint distribution P(X,Y)P(X, Y), which is rarely the case in practice. We need estimators.

Classic estimators

  • Histogram: discretize the variables and count. Simple but imprecise in high dimensions.
  • KNN (k-Nearest Neighbors): the Kraskov-Stogbauer-Grassberger estimator uses distances to neighbors to estimate densities. More robust than histograms.

Neural estimators

MINE (Mutual Information Neural Estimation) uses a neural network to estimate a lower bound on mutual information:

I(X;Y)β‰₯EP(X,Y)[TΞΈ(x,y)]βˆ’log⁑EP(X)P(Y)[eTΞΈ(x,y)]I(X; Y) \geq E_{P(X,Y)}[T_\theta(x, y)] - \log E_{P(X)P(Y)}[e^{T_\theta(x, y)}]

where TΞΈT_\theta is a neural network. This allows estimating mutual information between network layers, learned representations, or any pair of variables.

Mutual information in modern architectures

Attention and mutual information

The attention mechanism can be interpreted as a relevance computation: which input tokens are most informative for predicting an output token? It's an implicit form of mutual information maximization between the query and the keys.

Data augmentation

Data augmentations in contrastive learning (cropping, rotation, color changes) are chosen to preserve semantic information (I(Z;Y)I(Z; Y) stays high) while modifying surface details (I(Z;X)I(Z; X) is reduced). It's the Information Bottleneck put into practice.

Regularization and information forgetting

Dropout, weight decay, and data augmentation can all be seen as mechanisms that reduce I(Z;X)I(Z; X) (the information the representation keeps about the input), forcing the network to retain only information useful for the task.

Key takeaways

  • Mutual information I(X;Y)I(X; Y) measures any form of statistical dependence between two variables
  • I(X;Y)=H(X)βˆ’H(X∣Y)I(X; Y) = H(X) - H(X|Y): it's the reduction in uncertainty brought by knowledge of the other variable
  • It's more general than correlation because it captures nonlinear dependencies
  • InfoNCE in contrastive learning maximizes a lower bound on mutual information
  • The Information Bottleneck proposes that a good network compresses the input while preserving relevant information for the output
  • Estimating mutual information in high dimensions is a practical challenge, solved by neural estimators like MINE

Where this is used. The InfoNCE objective described here is what trains text embedding models.