A Shared Binary Code Over Frozen Image and Text Embeddings

Image-text models such as CLIP place a photo and its caption far apart in their shared embedding space, even when both describe the same thing. Images occupy one narrow cone on the unit sphere and captions occupy another. This "modality gap" is usually treated as a geometric defect that needs fixing, for example by subtracting the average offset between the two clouds. We propose a different reading, taken from an older model family. A Gaussian-Bernoulli restricted Boltzmann machine is an energy-based model in which binary hidden switches move the mean of a Gaussian over real-valued inputs. Such a model already has a natural place to store a modality offset: the visible bias, which is a per-modality constant mean, together with a per-dimension noise variance.

Concretely, we fit one such model jointly over frozen image embeddings and frozen text embeddings. One layer of binary hidden units is shared by both modalities, and each modality gets its own Gaussian visible group. The gap is then absorbed by the modality-specific biases and variances. Matching runs through the shared binary code. Neither cloud is translated or warped, so each modality keeps its internal neighbourhoods. The model is cheap: one matrix multiply per embedding, and an exact closed-form ranking score.

The model nests the two simplest competitors. Remove the hidden units and it reduces to per-modality centering and scaling, which is essentially the training-free standardization of I0T. Make the hidden units Gaussian instead of binary and it becomes a linear shared-factor model, close to probabilistic canonical correlation analysis. The proposal is therefore a falsifiable claim about one ingredient. A shared code made of binary switches turns the joint density into a mixture of exponentially many Gaussians. That mixture can represent one-caption-to-many-images correspondence, which neither a constant offset nor a linear factor model can. If binary units do not beat Gaussian ones, the idea fails and we will say so.

Core Claim

Let $v \in \mathbb{R}^d$ be a frozen image embedding, $t \in \mathbb{R}^d$ a frozen text embedding, and $h \in \{0,1\}^K$ the shared binary code. The energy is

$$E(v,t,h) = \sum_i \frac{(v_i - a_i)^2}{2\sigma_i^2} + \sum_i \frac{(t_i - b_i)^2}{2\rho_i^2} - \sum_j h_j\Big(c_j + \sum_i \frac{U_{ij} v_i}{\sigma_i^2} + \sum_i \frac{V_{ij} t_i}{\rho_i^2}\Big).$$

The terms are as follows. $a, b$ are the image and text visible biases, meaning each modality's own mean. $\sigma^2, \rho^2$ are the per-dimension image and text variances. $c$ holds the hidden biases. $U, V$ are the image-side and text-side weights.

Given $h$, each modality is Gaussian with mean $a + Uh$ (image) or $b + Vh$ (text). This is the conditional form described in Restricted Boltzmann Machines and Their Extensions for Face Modeling. Summing out $h$ gives a closed-form free energy:

$$F(v,t) = \sum_i \frac{(v_i - a_i)^2}{2\sigma_i^2} + \sum_i \frac{(t_i - b_i)^2}{2\rho_i^2} - \sum_j \log\big(1 + e^{\,c_j + U_j^\top (v/\sigma^2) + V_j^\top (t/\rho^2)}\big).$$

For a fixed image query, ranking captions by $-F(v,t)$ is exactly ranking by $p(t \mid v)$. No sampling or iterative denoising is required.

The modality gap lives in $a - b$. The per-dimension "peak activations" that I0T found are coordinates where one modality has an extreme mean and a small spread. Those land in $a$, $b$, $\sigma$ and $\rho$. They therefore stop dominating similarity, without anything being subtracted from the embeddings. We predict three things. First, cross-modal retrieval will beat both centroid standardization and a matched linear shared-factor model. Second, within-modality nearest-neighbour structure will be preserved exactly, since the embeddings are never moved. Third, binary units specifically will be what helps on queries with many valid matches.

How This Relates to Prior Work

Three groups of papers play different roles here.

The first group motivates the proposal by documenting the gap. Mind the Gap traces the gap to separate encoders that point their output cones in different directions from initialization, and to contrastive repulsion. It also shows that the size of the gap behaves like a tunable knob rather than pure error. Its Not a Modality Gap shows that a gap appears even between two identical image encoders, which points to poor spread over the sphere rather than modality per se. I0T pins the gap on a few dimensions with modality-specific peaks.

The second group constrains the design. Mitigate the Gap reports that translating embeddings by the centroid difference distorts within-modality structure. That is why our model never moves the embeddings. Extending Multi-modal Contrastive Representations shows that a single shallow linear map cannot both close the gap and respect the base space. We read this as a limit on linear bridges, and it motivates the nonlinear binary code. The known instability of learning visible variances, raised in Loop based Continual Learning, constrains how we train.

The third group sits closest to the idea, and the contrast with each needs to be stated. Diffusion-Link also works on frozen embeddings with Gaussian machinery. However, it is asymmetric: it denoises audio embeddings into the text space, uses text as a fixed anchor, and needs iterative sampling. Our model is symmetric, moves neither modality, and scores in one pass. DITS argues that isotropic Gaussian noise harms ranking. Our model sidesteps that objection because the Gaussian noise is never sampled at test time. It only defines a likelihood whose free energy is computed exactly, and the variances are learned per dimension rather than fixed and isotropic.

The nearest classical relative is Multimodal DBN for Predicting High-Quality Answers in cQA portals. It joins a Gaussian input layer for continuous metadata with a Bernoulli text layer under a shared hidden layer, but uses this for classification on raw features. It never studies the geometry of a pretrained shared embedding space, and it never uses the model as a retrieval scorer. Restricted Boltzmann Machines With Gaussian Visible Units Guided by Pairwise Constraints pulls matched pairs together inside a single continuous domain. We instead obtain the pairing from the joint density across two domains.

Research Program

Data and encoders. We extract frozen embeddings from CLIP ViT-B/32 for MS COCO training pairs, and separately for CC3M, to test scale. We keep the unit-norm embeddings and rely on the fact that, in 512 dimensions, a diagonal Gaussian is a reasonable local approximation on the sphere. As a check, we report results with and without a fixed global whitening step fitted on training data.

Training. The model is trained by persistent contrastive divergence on paired $(v,t)$. To address the documented variance divergence, we parameterize log-variances, clip their range, and initialize $a, b, \sigma, \rho$ to the empirical per-modality moments. Under that initialization, the model with no hidden units is exactly I0T-style standardization, so training starts from the strongest training-free baseline. As a fallback if contrastive divergence remains unstable, we use denoising score matching on the free energy. Score matching is a natural fit because the visible units are Gaussian. The hidden size $K$ ranges from 256 to 4096.

Scoring. Image-to-text and text-to-image retrieval use $-F$. We also test a pointwise-mutual-information score, $-F(v,t) + F_v(v) + F_t(t)$, where $F_v$ and $F_t$ are the single-modality free energies. This removes each modality's prior and should reduce "hub" captions that match everything.

Analysis. We make three measurements. First, we measure how much of the raw centroid distance is accounted for by $a - b$, and whether I0T's peak dimensions coincide with the extreme entries of $a - b$ and the smallest variances. Second, we measure how many hidden units are active per pair, and whether images of the same caption activate overlapping but different subsets of units, which is the mixture behaviour we claim. Third, we measure within-modality nearest-neighbour overlap against raw CLIP. This should be 100% for our scorer and lower for embedding translation.

Baselines

The naive reference point is raw CLIP cosine similarity on the same frozen embeddings. I0T reports 69.60% image-to-text and 67.10% text-to-image retrieval accuracy for it on Flickr30k. On MS COCO, Its Not a Modality Gap reports a centroid distance of 0.66.

The strongest training-free competitor is I0T_post: per-modality mean subtraction followed by renormalization, computed from the same training embeddings we use. It is the most direct threat because our model with zero hidden units reduces to it. Its reported Flickr30k numbers are 73.30% image-to-text and 76.30% text-to-image. We rerun it in our own pipeline on the same CLIP checkpoint and the same metric, and treat our rerun as the reference. Beating it means a consistent gain in both directions on Flickr30k and MS COCO across three seeds. A one-direction gain does not count.

The key-ingredient ablation replaces the binary hidden layer with Gaussian hidden units of the same size and trains it on the same data, with the same optimizer budget and hyperparameter search. That model is a linear shared-factor model in the spirit of probabilistic canonical correlation analysis. It isolates whether the binary mixture matters. We additionally report a variant with variances fixed to 1, which isolates the per-dimension variance as the mechanism that absorbs peak activations.

The trained-adapter competitor is a two-layer MLP adapter on each modality. It has the same parameter count as $U, V$, is trained with symmetric InfoNCE (the standard contrastive loss) on the same pairs, and gets the same tuning budget. We also include the uniformity-plus-alignment fine-tuning of Its Not a Modality Gap, applied as an adapter on frozen features so that compute is matched. That paper reports Caltech101 zero-shot accuracy rising from 0.42 to 0.49 with its method.

For the audio extension, the reference is Diffusion-Link. On AudioCaps it reports a matched-pair cosine similarity of 0.688 and a supervised CIDEr (a captioning-quality score) of 82.5. No reported retrieval-recall result was found on Lacuna for Diffusion-Link on AudioCaps, so we run it ourselves on frozen CLAP embeddings for that comparison.

Why not just…?

Why not just subtract the modality means, as I0T does? This is the most serious threat, and the design deliberately contains it as the zero-hidden-unit special case. If adding hidden units does not improve on it, the binary code is not doing anything and the proposal fails. The reason to expect more is that centering removes a constant offset but leaves correspondence to raw cosine. It cannot express that a caption like "a dog on a beach" is compatible with several distinct image clusters. We will check where gains appear by splitting test queries by the number of distinct visual clusters among their ground-truth matches. If the gains are uniform, the mixture story is wrong.

Why not just fit linear probabilistic canonical correlation analysis or a linear shared Gaussian factor model? A linear factor model also explains the offset through means and shares a latent across modalities. Extending Multi-modal Contrastive Representations gives evidence that shallow linear maps face a tradeoff between closing the gap and preserving structure, but that evidence concerns projections, not joint densities. The Gaussian-hidden ablation settles this directly under matched training budgets. A tie means we report that the binary code is unnecessary.

Why not just train a small contrastive adapter? An InfoNCE adapter is discriminative and will likely be strong on in-distribution retrieval. Contrastive training is also what Mind the Gap identifies as producing the gap in the first place. An adapter also moves the embeddings, which Mitigate the Gap links to damaged within-modality structure. We expect the adapter to roughly tie on COCO retrieval and lose on two fronts: within-modality nearest-neighbour preservation, and transfer from COCO-trained parameters to Flickr30k and CIFAR-10 zero-shot. If it wins on transfer too, the generative route offers only interpretability, and we will state that.

Proposed Experiments

The decisive experiment trains every model on COCO-train embeddings and evaluates Flickr30k retrieval in both directions with the same CLIP checkpoint. For zero-shot classification, class prompts serve as text: we report CIFAR-10, where Mind the Gap reports 0.9013 for CLIP and 0.9081 after gap tuning, and Caltech101, with reported CLIP accuracy of 0.42. Alongside these we report centroid distance after mapping both modalities to their hidden posteriors, and within-modality neighbour overlap.

Three outcomes would support the claim. The binary model must beat our rerun of I0T_post in both retrieval directions on Flickr30k. It must beat the Gaussian-hidden ablation by more than seed variance. And the gain must concentrate on queries with many visually distinct matches.

A second experiment addresses the open question of whether the gap should be removed. We repeat the FairFace denigration analysis from Mind the Gap, whose reported rate for "White" subjects is 15.7% at gap 0.82 and 13.7% at gap 0.97. We score with $-F$, which ignores the raw gap, and with the pointwise-mutual-information variant. If routing matching through the shared code raises offensive misclassifications, that is evidence that the raw gap was doing protective work rather than being pure error, and we will report it.

A third experiment replaces CLIP with CLAP on AudioCaps to test whether the mechanism is modality-agnostic. It compares against Diffusion-Link on matched-pair similarity and on retrieval recall that we compute ourselves for both methods.