Multimodal BERT-based Classification

Machine Learning
Introduced by
Kiela, D. et al.; Lu, J. et al.
Year
2019
Type
Multimodal transformer classifier
Family
Deep learning / NLP / CV

What does it do?

Multimodal BERT-based classification extends the BERT transformer to classify data that combines text with another modality, most commonly an image.

Each modality is encoded separately, the representations are fused, and a single classification head predicts the label. Models such as MMBT (Kiela et al., 2019) and ViLBERT (Lu et al., 2019) brought this design to prominence around 2019.

The intuition behind the method

BERT encodes language by using context across a full sentence. Many tasks, however, depend on both what a post says and what it shows: a hateful meme, a product listing, or a social media post often cannot be labeled from text or image alone. Multimodal BERT models handle this by encoding each modality with its own encoder and merging the resulting vectors before classification. The fusion step is where the model has to reconcile the two channels, which is both the source of its usefulness and the part most sensitive to design choices.

History

The multimodal extension of BERT became prominent in 2019 with ViLBERT (Lu et al., 2019), which pretrained separate vision and language streams that exchange information through cross-modal attention, and with MMBT (Kiela et al., 2019), which applied a simpler supervised fusion of image features into the BERT token sequence. Both works built on the BERT transformer encoder. Together they established the two main routes to multimodal transformers: joint pretraining and supervised fusion for a downstream task.

When to use it

Choose multimodal BERT-based classification when the label depends on both text and at least one other modality, such as an image, audio, or structured metadata, and when a reasonable amount of labeled paired examples is available; the amount needed depends on the task and the encoders used. Typical fits include meme classification, product categorization, and moderation of posts that combine a caption with an image. Do not use it when the data has only one modality, because the extra encoders add cost without a second signal. It is also a poor choice when labeled pairs are very scarce or when interpretability and lightweight inference are strict requirements; a unimodal model or a simple fusion baseline is then easier to justify.

Limitations and considerations

  • Requires labeled examples in which both modalities are present; records with a missing modality have to be handled separately.
  • Compute cost is higher than unimodal BERT fine-tuning, because two encoders run for every example at both training and inference time.
  • The fusion design (projection, concatenation, or cross-attention) adds choices that the labeled data must support; a complex fusion layer can overfit a small dataset.
  • Because the modalities are merged into one vector before classification, a prediction cannot be cleanly split into text and image contributions; attribution needs ablation or dedicated explanation tools.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Starts from pretrained BERT and image encoder weights, so a labeled task dataset can be used for fine-tuning rather than full multimodal pretraining.
  • The fused representation lets the classifier use cues that only appear in combination, such as a caption whose meaning depends on the accompanying image.
  • Fusion can be varied within one framework, from simple concatenation to cross-attention, so the design can be matched to how strongly the modalities interact.
  • Publicly available pretrained encoders for text and images lower the cost of building a working baseline.

Applications

  • Hate speech and harmful content detection in image-text memes.
  • E-commerce product classification using title text and product images together.
  • Medical report classification combining clinical notes with radiology scans.
  • Social media post sentiment analysis incorporating both caption and attached image.
  • Visual question answering framed as classification over a fixed answer set.
  • Document classification for scanned forms that include both printed text and layout.

How it works

How it works

1

The input text is tokenized and passed through a pretrained BERT encoder. The embedding of the [CLS] token, which summarizes the sequence, is taken as the text representation. During fine-tuning the BERT weights are updated together with the classification layers, so the text encoder adapts to the downstream labels.

2

The non-text input, typically an image, is passed through a separate encoder that produces a feature vector or a sequence of region features. Its output lives in a different feature space from the BERT representation, so the fusion step typically requires a projection or adapter layer to map both into a compatible form. For audio or tabular data, a domain-appropriate encoder takes the place of the image encoder.

3

The text and non-text representations are combined into a single fused vector, h_fused, which is the input to the classification head. Concatenation is the usual baseline: the non-text vector, after the projection or adapter layer, is joined end to end with the text vector. Cross-attention, in which tokens from one modality attend to the other, is a more complex alternative: it can capture interactions between the modalities but adds parameters and compute. Because the fusion choice affects results, it should be compared on held-out data rather than assumed.

4

The fused vector h_fused is passed through a linear layer and a softmax, which gives class probabilities. The model is fine-tuned end to end with cross-entropy loss on labeled multimodal examples.

Formula
\hat{y} = \text{softmax}(W \cdot \mathbf{h}_{\text{fused}} + b)

Common pitfalls

  • Choosing cross-attention fusion without first measuring a simple concatenation baseline on the same held-out split.
  • Ignoring modality imbalance: if one encoder's features dominate the fused vector or the training loss, the other modality contributes little, which unimodal ablations will reveal.
  • Fine-tuning all BERT layers on a small dataset can overfit. Freezing early layers or using a lower learning rate for them is one mitigation to evaluate on validation data.
  • Reporting only accuracy on imbalanced classes; report macro F1 alongside accuracy and inspect the confusion matrix.
  • Concatenating raw BERT and image vectors without a projection or adapter layer that maps them to a shared size and scale, which can leave the classifier input dominated by whichever vector has larger magnitude.

Frequently asked questions

Do I need to pretrain from scratch on multimodal data?

No. The usual approach is to start from publicly available pretrained BERT and image encoder weights and fine-tune the full model, or parts of it, on a labeled multimodal dataset. Joint pretraining on large paired corpora requires substantial compute and data.

Which fusion strategy should I choose?

Start with a simple baseline: concatenate the [CLS] vector with the pooled image features and feed the result to the classification head. Call this concatenation fusion. Cross-attention or co-attention fusion can improve results when the modalities interact closely, but it adds parameters and compute. Adopt it only if the baseline leaves a clear gap on a held-out split.

How much labeled paired data do I need?

The amount depends on the task, the label set, and the encoders used, so no fixed threshold applies. Small labeled sets increase the risk of overfitting, so evaluate on held-out data. If performance is poor on a small set, consider freezing the BERT encoder and training only the classification head as a linear probe, or applying data augmentation where it is appropriate.

Can I use modalities other than images?

Yes. The general pattern of encoding each modality separately, fusing, and classifying applies to audio (with a spectrogram or audio encoder), tabular features (with a small MLP), or video (with a frame-level or temporal encoder). The text stream still uses BERT.

How do I explain which modality drove a prediction?

Gradient-based saliency maps, attention weight visualization, or SHAP values computed separately for text tokens and image patches can give coarse attribution. For rigorous modality attribution, compare unimodal ablations (text-only vs. image-only predictions) to the multimodal output.

Related methods

Sources

  1. Kiela, D., Bhooshan, S., Firooz, H., Perez, E., & Testuggine, D. (2019). Supervised multimodal bitransformers for classifying images and text. arXiv preprint arXiv:1909.02950.

    Open publication reference
  2. Lu, J., Batra, D., Parikh, D., & Lee, S. (2019). ViLBERT: Pretraining task-agnostic visiolinguistic representations for vision-and-language tasks. Advances in Neural Information Processing Systems, 32.

    Open publication reference