Skip to content

Image-language and multimodal models · Image-language and multimodal models · MM009 · Model

ALBEF

Aligns image and text embeddings before fusing them and uses a momentum teacher to provide soft training targets.

Explained here Component demo, not a trained model CodeSplash's run and the reference's record

In CodeSplash

Documented in the Academy only. There's no Set up button.

Availability
Explained here
Code example
Component demo, not a trained model
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Aligns image and text embeddings before fusing them and uses a momentum teacher to provide soft training targets. This reduces the burden of learning alignment entirely inside the multimodal fusion network and addresses some noisy-pair issues.

Question / objective

Can contrastive pre-alignment and momentum-generated targets improve grounded multimodal learning from noisy image-text pairs? The learning target replaces a null/alternative hypothesis formulation; benchmark evaluation is a separate statistical task.

Method type and supervision

Model/system family. Image-language or broader multimodal learning using the paired, generated or task-specific supervision described below. This is not a classical significance test.

Architecture / computational structure

Image and text encoders first produce aligned unimodal representations; a multimodal encoder fuses them through cross-attention. Momentum copies provide pseudo-target distributions for selected objectives.

Assumptions

Teacher predictions are not independent labels and can perpetuate errors. Paired captions still omit details; hard negatives may be valid alternative descriptions. The method does not require detector boxes, but it still learns from paired modalities.

Formula / computational definition

θm←mθm+(1−m)θ\theta_m\leftarrow m\theta_m+(1-m)\theta updates teacher weights; Ldistill=−∑jqj(m)log⁡pjL_{distill}=-\sum_j q_j^{(m)}\log p_j matches student predictions to stopped-gradient teacher targets q(m)q^{(m)}, alongside the specified alignment/masking losses. This captures the central mechanism; consult the primary source for all masks, stages, normalizations and loss terms.

Parameters and notation

Learned/estimated quantities: Student encoder/fusion/predictor weights are learned; teacher weights follow EMA state updates. Momentum, target mixing and task weights are hyperparameters rather than inferred truths. Hyperparameters and design choices: Momentum schedule, distillation mixing, contrastive temperature, negative selection and resolution affect stability and transfer.

Fitting, fine-tuning, and adaptation

Adapt task heads/fusion layers first. When extending pretraining, update the momentum teacher consistently with the student and monitor both soft-target quality and downstream grounding. LoRA requires corresponding handling of teacher/adapted parameters. Save the exact trainable-module selection, data split, loss, optimizer and processor configuration; distinguish parameter adaptation from inference-time prompt tuning.

How to use and calibrate

Choose a specific model/processor and task protocol, validate preprocessing on known examples, tune only on a held-out development set and freeze the final evaluation. Report retrieval, downstream reasoning and teacher/negative-mining ablations; check noise sensitivity and near-duplicate leakage.

Example application

Improve retrieval and question answering when web captions are useful but noisy.

Interpretation / pitfalls

Watch out

Reported capability is conditional on available visual evidence, data coverage and the chosen task. Report retrieval, downstream reasoning and teacher/negative-mining ablations; check noise sensitivity and near-duplicate leakage. A successful numeric component example is not evidence that a complete system achieves a published benchmark score.

Python and R code examples

Component: Mix hard paired labels with momentum-teacher soft targets. Dependencies: shared NumPy/base-R setup above. Python: executed successfully. R: unexecuted. Complete model training/inference: not run.

Full implementation routes: Python: use the authors’ alignment/fusion and momentum-distillation implementation; R: prototype target mixing and evaluate outputs, using reticulate for the full model.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — Mix hard paired labels with momentum-teacher soft targets.

Shared setup for this chapter
import numpy as np
def softmax(x):
    z = np.asarray(x, dtype=float)
    e = np.exp(z-z.max())
    return e/e.sum()
hard=np.array([1.,0.,0.]); teacher=np.array([.7,.2,.1])
mix=.4; target=(1-mix)*hard+mix*teacher
student=softmax(np.array([1.2,.1,-.2]))
print(target,"distilled CE",-np.sum(target*np.log(student)))
R

Component demo, not a trained model — Mix hard paired labels with momentum-teacher soft targets.

Shared setup for this chapter
softmax <- function(x) {
  e <- exp(x-max(x))
  e/sum(e)
}
hard <- c(1,0,0); teacher <- c(.7,.2,.1); mix <- .4
target <- (1-mix)*hard+mix*teacher
student <- softmax(c(1.2,.1,-.2))
print(target); print(-sum(target*log(student)))

Sources

From the CodeSplash reference, entry MM009.