Revamping Cross-Modal Recipe Retrieval With Hierarchical Transformers and Self-Supervised Learning

Amaia Salvador, Erhan Gundogdu, Loris Bazzani, Michael DonoserCVPR 2021

Introduction

Cross-modal recipe retrieval—the ability to find a recipe from a food photograph or vice versa—is a challenging task due to the structured and long-form nature of culinary data. Recipes typically consist of a title, a list of ingredients, and a sequence of preparation instructions. Previous state-of-the-art methods often relied on Recurrent Neural Networks (RNNs) like LSTMs, which struggle to capture long-range dependencies in complex instructions. Furthermore, many existing systems failed to utilize the vast amount of "unpaired" recipe data (recipes without images) available in large-scale datasets like Recipe1M.

This work introduces a revamped framework that replaces sequential models with Hierarchical Transformers and leverages self-supervised learning to exploit unpaired data, setting a new benchmark for the field.

Methodology

The proposed architecture consists of two primary innovations: the Hierarchical Recipe Transformer (HTR) and a self-supervised recipe loss ($\mathcal{L}_{rec}$).

Hierarchical Recipe Transformer (HTR)

Unlike standard Transformers that treat text as a flat sequence, the HTR processes recipes hierarchically. At the sentence level, a Transformer encodes individual components (e.g., a single ingredient line or one instruction step). These sentence-level embeddings are then passed to a document-level Transformer that aggregates them into a unified representation. This structure allows the model to better capture the semantic relationships between different parts of a recipe.

Self-Supervised Learning from Unpaired Data

A significant portion of the Recipe1M dataset (approximately 66%) lacks associated images. To utilize this data, the authors introduced a self-supervised triplet loss, $\mathcal{L}_{rec}$. This loss encourages the embeddings of a recipe's title, ingredients, and instructions to be close to one another in the joint embedding space. By aligning these internal components, the model learns a more robust "food language" representation even in the absence of visual cues.

The overall architecture of the proposed system, showing the hierarchical encoders and the joint training with paired and self-supervised losses.

Experiments and Results

The model was evaluated on the Recipe1M dataset, which contains approximately 1 million recipes. The primary metrics used were Median Rank (MedR) and Recall at K (R@K) on a test set of 10,000 samples.

Learning from the "Missing" Data

Incorporating the unpaired text-only recipes via self-supervision provided a significant boost. It's not just about more data; it's about learning the internal consistency of what makes a "recipe." This approach also grants the model a "hallucination" capability: because it learns to align the title, ingredients, and instructions, it becomes robust to missing information. If a user provides a recipe without a title at test time, the model can infer the missing semantic information from the ingredients and instructions to successfully retrieve the correct image.

Performance Gains and Ablation

Ablation studies confirmed that while ingredients are the most critical component for retrieval, the "Full Recipe" (Title + Ingredients + Instructions) consistently performs best. The transition from LSTMs to Hierarchical Transformers alone yielded a 4.6-point improvement in Recall@1. When combined with the self-supervised loss and a Vision Transformer (ViT) image backbone, the system achieved a new state-of-the-art Median Rank of 3.0 and a Recall@1 of 33.5% on the 10k test set. This represents a significant leap over previous complex adversarial and multi-stage training systems.

Qualitative Impact

The effectiveness of the proposed components is visible in the retrieval rankings. As shown in the qualitative analysis, the addition of the self-supervised loss ($\mathcal{L}_{rec}$) and the ViT backbone consistently improves the rank of the ground-truth recipe ($R$) for a given query image ($I$).

Qualitative results showing how the rank of the correct recipe improves as self-supervised loss and stronger visual backbones (ViT) are added.

Conclusion

By simplifying the retrieval pipeline and focusing on hierarchical modeling and self-supervision, this research demonstrates that Transformers are highly effective for structured document retrieval. The ability to learn from unpaired data not only improves performance but also makes the model more robust to missing information at inference time. Future work may extend this hierarchical approach to video-based retrieval and more granular image-to-ingredient alignment.

Summary updated

BibTeX
@inproceedings{salvador2021revamping,
  author = {Amaia Salvador and Erhan Gundogdu and Loris Bazzani and Michael Donoser},
  title = {{Revamping Cross-Modal Recipe Retrieval With Hierarchical Transformers and Self-Supervised Learning}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2021},
  doi = {10.1109/cvpr46437.2021.01522},
}
Figure