# 跨模态对比学习

跨模态对比学习是一种机器学习技术，它训练两个编码器——每个模态一个——将匹配对（例如一张图像及其说明文字）映射到一个共享的嵌入空间中，使它们在空间中彼此靠近，而不匹配的对则被推开。由此得到的对齐空间支持跨模态检索、零样本分类和嵌入算术运算。<sup>[1](https://arxiv.org/pdf/2103.0020)</sup> 当CLIP在4亿对网络收集的图像-文本对上训练，并证明所学到的空间无需任务特定标签即可迁移到未见任务时，这项技术在大规模上变得实用。<sup>[1](https://arxiv.org/pdf/2103.0020)</sup>

| 关键事实 | 数值 |
|---|---|
| 核心目标 | 在一批N对样本中，对余弦相似度施加对称InfoNCE式交叉熵<sup>[1](https://arxiv.org/pdf/2103.0020)</sup> |
| 典型数据规模 | 4亿对（CLIP），超过10亿对含噪替代文本对（ALIGN），290亿对已见样本对（Meta CLIP 2）<sup>[1](https://arxiv.org/pdf/2103.0020)</sup><sup> • </sup><sup>[2](https://proceedings.mlr.press/v139/jia21b/jia21b.pdf)</sup><sup> • </sup><sup>[3](https://github.com/facebookresearch/MetaCLIP/)</sup> |
| 典型批大小 | 32,768（CLIP）；16,384（ALIGN）；SigLIP最优为32k<sup>[1](https://arxiv.org/pdf/2103.0020)</sup><sup> • </sup><sup>[2](https://proceedings.mlr.press/v139/jia21b/jia21b.pdf)</sup><sup> • </sup><sup>[4](https://openaccess.thecvf.com/content/ICCV2023/papers/Zhai_Sigmoid_Loss_for_Language_Image_Pre-Training_ICCV_2023_paper.pdf)</sup> |
| 温度 | 可学习，CLIP中初始化为0.07；ALIGN中收敛于约1/64；实践中通常设为接近0.01<sup>[1](https://arxiv.org/pdf/2103.0020)</sup><sup> • </sup><sup>[2](https://proceedings.mlr.press/v139/jia21b/jia21b.pdf)</sup><sup> • </sup><sup>[5](https://proceedings.iclr.cc/paper_files/paper/2024/file/f41b6e5af73421e46ceed9cb036e72e7-Paper-Conference.pdf)</sup> |
| 标志性零样本结果 | 76.4% ImageNet top-1（ALIGN），未使用任何ImageNet训练样本<sup>[2](https://proceedings.mlr.press/v139/jia21b/jia21b.pdf)</sup> |
| 主要失效模式 | 模态鸿沟、假阴性、批大小依赖、数据集偏差<sup>[6](https://proceedings.neurips.cc/paper_files/paper/2022/file/702f4db7543a7432431df588d57bc7c9-Paper-Conference.pdf)</sup><sup> • </sup><sup>[7](https://aclanthology.org/2022.emnlp-main.256.pdf)</sup> |

## 工作原理

该方法采用双编码器架构：图像编码器和文本编码器产生的嵌入经过L2归一化，相似度为余弦相似度除以温度\( \tau \)——一个通常小于1的正数，它将余弦范围扩展到[−1, 1]之外。<sup>[8](https://papers.neurips.cc/paper_files/paper/2022/file/072fd0525592b43da661e254bbaadc27-Paper-Conference.pdf)</sup> 给定一批N对样本，模型必须识别\( N \times N \)种可能配对中哪些实际发生了：N个真实对为正样本，\( N^{2} - N \)个其他组合为负样本，并对从图像到文本和从文本到图像两个方向的相似度分数施加对称交叉熵损失。<sup>[1](https://arxiv.org/pdf/2103.0020)</sup>

该目标源自奥尔德、李和维尼亚尔斯于2018年提出的InfoNCE损失，其最小化导致编码器最大程度地保留真实对之间的互信息。<sup>[9](https://doi.org/10.48550/arxiv.1807.03748)</sup><sup> • </sup><sup>[10](https://proceedings.mlr.press/v182/zhang22a/zhang22a.pdf)</sup> 在CLIP的伪代码中，未归一化预测分数是归一化嵌入的点积乘以\( e^{t} \)，总损失是行方向与列方向交叉熵的平均值。<sup>[1](https://arxiv.org/pdf/2103.0020)</sup> 温度控制softmax将正样本与负样本分离的锐度：CLIP式目标的理论表明，当数据不完全可分时，\( \tau = O(\gamma / \log(B/\epsilon)) \)，其中\( \gamma \)是分离间隔，B是批大小；实践中\( \tau \)常设为接近0.01。<sup>[5](https://proceedings.iclr.cc/paper_files/paper/2024/file/f41b6e5af73421e46ceed9cb036e72e7-Paper-Conference.pdf)</sup> 在线性设定下，该损失族上的每一步梯度更新可解释为对对比交叉[协方差矩阵](https://www.edgepedia.org/zh/covariance-matrix)执行SVD，这解释了目标如何学习对齐两个模态的特征。<sup>[11](https://ar5iv.labs.arxiv.org/html/2302.06232)</sup>

## 实施方法

训练按照可识别的顺序进行。首先，收集配对数据：CLIP从[英语维基百科](https://www.edgepedia.org/zh/english-wikipedia)中提取的高频视觉概念允许列表中整理了4亿对图像-文本对，而ALIGN使用了自然分布下的原始替代文本对，未进行昂贵的过滤。<sup>[1](https://arxiv.org/pdf/2103.0020)</sup><sup> • </sup><sup>[2](https://proceedings.mlr.press/v139/jia21b/jia21b.pdf)</sup> 数据整理本身就是一个可设计的步骤：Meta CLIP的整理算法通过采样阈值平衡头部和尾部概念，将阈值从OpenAI CLIP的20k对提高到Meta CLIP的170k对，同时保留6%来自尾部概念的匹配。<sup>[12](https://papers.neurips.cc/paper_files/paper/2025/file/449fb670956a93b3d4d95167f72093e1-Paper-Conference.pdf)</sup>

其次，选择编码器和投影头。CLIP的文本编码器是一个63M参数的12层512宽[Transformer](https://www.edgepedia.org/zh/transformer)，具有49,152个词元的字节对编码词汇表和最大序列长度76；CLIP移除了单模态对比学习中使用的非线性投影头，仅保留线性投影，并使用随机方形裁剪作为唯一的增强方式。<sup>[1](https://arxiv.org/pdf/2103.0020)</sup> ALIGN从头训练了EfficientNet-L2和BERT-Large。<sup>[2](https://proceedings.mlr.press/v139/jia21b/jia21b.pdf)</sup> 第三，使用非常大的批进行训练，使批本身提供负样本：CLIP使用32,768，ALIGN使用16,384，跨1024个TPUv3核心。<sup>[1](https://arxiv.org/pdf/2103.0020)</sup><sup> • </sup><sup>[2](https://proceedings.mlr.press/v139/jia21b/jia21b.pdf)</sup> 最后，用零样本探针进行评估：类名由文本编码器嵌入，图像-文本余弦相似度经\( \tau \)缩放和softmax归一化，这等价于一个多项式逻辑回归分类器，其输入和权重经L2归一化，无偏置，并带温度缩放。<sup>[1](https://arxiv.org/pdf/2103.0020)</sup>

## 起源

批构造和目标改编自[深度度量学习](https://www.edgepedia.org/zh/deep-metric-learning)，并以InfoNCE的形式在对比表征学习中得到推广；InfoNCE由奥尔德、李和维尼亚尔斯于2018年在arXiv上提出。<sup>[9](https://doi.org/10.48550/arxiv.1807.03748)</sup> 单模态对应物SimCLR及其NT-Xent损失由陈及其同事于2020年在arXiv上提出。<sup>[13](https://doi.org/10.48550/arxiv.2002.05709)</sup> 首个大规模图像-文本应用是ConVIRT，由张及其同事于2020年在arXiv上报告，它通过双向对比目标从自然发生的图像-报告对中学习医学视觉表征。<sup>[10](https://proceedings.mlr.press/v182/zhang22a/zhang22a.pdf)</sup> CLIP由拉德福德及其同事于2021年在arXiv上报告，是ConVIRT的简化版本，从头在4亿对网络数据上训练；ALIGN由贾及其同事于2021年在arXiv上报告，将相同配方扩展到含噪替代文本数据。<sup>[1](https://arxiv.org/pdf/2103.0020)</sup><sup> • </sup><sup>[2](https://proceedings.mlr.press/v139/jia21b/jia21b.pdf)</sup> ConVIRT的作者指出，他们2020年的发布直接启发了CLIP和ALIGN。<sup>[10](https://proceedings.mlr.press/v182/zhang22a/zhang22a.pdf)</sup>

## 变体

**损失变体。** SigLIP由翟、穆斯塔法、科列斯尼科夫和拜尔于2023年报告，用成对sigmoid损失替代softmax，将每个图像-文本对视为独立的二分类问题，匹配对标签\( z_{ij} = 1 \)，否则为−1，温度初始化为10且可学习，偏置初始化为−10；由于没有操作跨越整个批，分布式训练更简单，批大小与任务定义解耦。<sup>[4](https://openaccess.thecvf.com/content/ICCV2023/papers/Zhai_Sigmoid_Loss_for_Language_Image_Pre-Training_ICCV_2023_paper.pdf)</sup> UniCLIP使用带每域温度和偏移的MP-NCE多正样本损失，将域间（图像-文本）和域内（图像-图像）对比损失合并到一个嵌入空间。<sup>[8](https://papers.neurips.cc/paper_files/paper/2022/file/072fd0525592b43da661e254bbaadc27-Paper-Conference.pdf)</sup> CyCLIP由戈尔及其同事于2022年报告，添加循环一致性正则化以减少跨模态和模态内结构之间的不一致。<sup>[14](https://doi.org/10.48550/arxiv.2205.14459)</sup> SigLIP 2（2025）扩展了sigmoid损失配方，加入基于描述的预训练、自蒸馏、掩码预测和在线数据整理，在零样本分类、检索和迁移到视觉-语言模型方面在所有规模上均优于SigLIP。<sup>[15](https://arxiv.org/pdf/2502.14786)</sup>

**模态与领域变体。** [ImageBind](https://www.edgepedia.org/zh/imagebind)由吉尔达尔及其同事于2023年报告，仅使用图像配对数据学习跨六种模态（图像、文本、音频、深度、热成像和IMU）的联合嵌入，用对称InfoNCE损失将每个模态对齐到图像嵌入。<sup>[16](https://doi.org/10.48550/arxiv.2305.05665)</sup> CrossCLR由佐尔法加里及其同事于2021年报告，将跨模态对比学习应用于多模态视频表征。<sup>[17](https://doi.org/10.48550/arxiv.2109.14910)</sup> MedCLIP解耦图像和文本以形成更多训练对，并用基于UMLS医学知识的语义匹配损失替代InfoNCE以消除假阴性。<sup>[7](https://aclanthology.org/2022.emnlp-main.256.pdf)</sup> AlignCLIP（2025）在视觉和文本编码器之间共享参数，并添加模态内分离损失以缩小模态鸿沟。<sup>[18](https://proceedings.iclr.cc/paper_files/paper/2025/file/cc1de06a58ba1db43538a37e076e466d-Paper-Conference.pdf)</sup> Meta CLIP由徐及其同事于2023年报告，为CLIP式训练贡献了一种可扩展的数据整理算法。<sup>[19](https://doi.org/10.48550/arxiv.2309.16671)</sup> Meta CLIP 2（2025）是首个在全球网络规模图像-文本对上从头训练CLIP的配方，使用语言识别和跨300多种语言的语言特定整理；其ViT-H/14在零样本ImageNet上超越仅英语版本，并在CVQA、Babel-ImageNet和XM3600图像到文本检索上创下多语言最优结果。<sup>[12](https://papers.neurips.cc/paper_files/paper/2025/file/449fb670956a93b3d4d95167f72093e1-Paper-Conference.pdf)</sup><sup> • </sup><sup>[3](https://github.com/facebookresearch/MetaCLIP/)</sup>

## 应用

**零样本分类与检索。** 零样本CLIP在30多个数据集上进行了基准测试，发现与先前任务特定的监督模型具有竞争力，在ImageNet上匹配原始ResNet-50而无需使用其128万个标注样本；零样本CLIP模型也比同等精度的监督ImageNet模型更鲁棒。<sup>[1](https://arxiv.org/pdf/2103.0020)</sup> ALIGN达到76.4%零样本ImageNet top-1，在零样本检索中，在Flickr30K和MSCOCO上比CLIP提升超过7%。<sup>[2](https://proceedings.mlr.press/v139/jia21b/jia21b.pdf)</sup><sup> • </sup><sup>[20](https://research.google/blog/align-scaling-up-visual-and-vision-language-representation-learning-with-noisy-text-supervision/)</sup> ALIGN嵌入还支持组合查询：将查询图像的嵌入与文本字符串的嵌入相加可检索相关图像，属性可通过嵌入空间中的减法移除。<sup>[20](https://research.google/blog/align-scaling-up-visual-and-vision-language-representation-learning-with-noisy-text-supervision/)</sup>

**音频、医学影像与视觉-语言模型。** ImageBind的涌现零样本音频分类在ESC、Clotho和[AudioCaps](https://www.edgepedia.org/zh/audiocaps)上匹配或超越使用直接音频-文本监督训练的专家模型。<sup>[16](https://doi.org/10.48550/arxiv.2305.05665)</sup> 在医学影像中，ConVIRT预训练仅需ImageNet初始化对应模型10%的标注数据即可在四个分类任务上达到相当或更好的性能，MedCLIP仅使用20K预训练样本即优于ConVIRT和GLoRIA。<sup>[10](https://proceedings.mlr.press/v182/zhang22a/zhang22a.pdf)</sup><sup> • </sup><sup>[7](https://aclanthology.org/2022.emnlp-main.256.pdf)</sup> SigLIP 2编码器作为视觉-语言模型的特征提取器，已与Gemma 2 2B LLM结合用于描述生成、OCR、视觉问答和检测数据。<sup>[15](https://arxiv.org/pdf/2502.14786)</sup>

## 局限与替代方案

**模态鸿沟。** CLIP的图像和文本嵌入占据嵌入空间中两个完全分离的区域，这一模式在跨越文本、自然图像、视频、医学图像和氨基酸序列的模型中均有发现，甚至随机权重下也存在。在CLIP学到的温度\( \tau = 1/100 \)下，单位球面上测得的鸿沟\( \lVert \text{gap} \rVert = 0.82 \)恰好位于对比损失的全局最小值处，因此优化本身保留了鸿沟；鸿沟随温度升高单调减小，而不匹配（含噪）的配对数据是低温下重要的形成因素。改变鸿沟距离显著影响下游零样本分类性能和公平性。<sup>[6](https://proceedings.neurips.cc/paper_files/paper/2022/file/702f4db7543a7432431df588d57bc7c9-Paper-Conference.pdf)</sup> AlignCLIP将配对图像-文本嵌入之间的平均角度从约70度降至47度，并将跨模态对齐分数从0.38–0.47提升至0.62–0.67。<sup>[18](https://proceedings.iclr.cc/paper_files/paper/2025/file/cc1de06a58ba1db43538a37e076e466d-Paper-Conference.pdf)</sup>

**假阴性与批大小。** [批内负样本](https://www.edgepedia.org/zh/in-batch-negatives)可能是错误的：来自不同患者的图像和报告可能具有相同语义却被视为负样本，这促使了MedCLIP的语义匹配损失。<sup>[7](https://aclanthology.org/2022.emnlp-main.256.pdf)</sup> 批大小直接影响性能：SigLIP在批大小32k时表现最佳，而softmax CLIP损失需要98k且仍未超越它；CLIP式目标的理论分析偏好更大的批，因为它们减小误差界的常数。<sup>[4](https://openaccess.thecvf.com/content/ICCV2023/papers/Zhai_Sigmoid_Loss_for_Language_Image_Pre-Training_ICCV_2023_paper.pdf)</sup><sup> • </sup><sup>[5](https://proceedings.iclr.cc/paper_files/paper/2024/file/f41b6e5af73421e46ceed9cb036e72e7-Paper-Conference.pdf)</sup>

**与其他目标的比较。** 将预测性词袋目标替换为对比目标，在零样本迁移到ImageNet上带来了4倍效率提升；模态鸿沟文献引用CLIP表明，对比学习在多模态模型预训练中比生成式方法高效12倍。<sup>[1](https://arxiv.org/pdf/2103.0020)</sup><sup> • </sup><sup>[6](https://proceedings.neurips.cc/paper_files/paper/2022/file/702f4db7543a7432431df588d57bc7c9-Paper-Conference.pdf)</sup> 理论还表明对比损失至关重要：仅在平方损失非对比目标上训练会导致大误差，甚至在零样本数据集上随机猜测；而[多模态对比学习](https://www.edgepedia.org/zh/multimodal-contrastive-learning)可以超越逐模态应用的单模态对比学习，即使配对错误也是如此。<sup>[5](https://proceedings.iclr.cc/paper_files/paper/2024/file/f41b6e5af73421e46ceed9cb036e72e7-Paper-Conference.pdf)</sup><sup> • </sup><sup>[11](https://ar5iv.labs.arxiv.org/html/2302.06232)</sup>

## References

1. [Learning Transferable Visual Models From Natural Language Supervision (CLIP)](https://arxiv.org/pdf/2103.0020)
2. [Scaling Up Visual and Vision-Language Representation Learning With Noisy Text Supervision (ALIGN)](https://proceedings.mlr.press/v139/jia21b/jia21b.pdf)
3. [facebookresearch/MetaCLIP (GitHub repository and model release)](https://github.com/facebookresearch/MetaCLIP/)
4. [Sigmoid Loss for Language Image Pre-Training (SigLIP)](https://openaccess.thecvf.com/content/ICCV2023/papers/Zhai_Sigmoid_Loss_for_Language_Image_Pre-Training_ICCV_2023_paper.pdf)
5. [Understanding Transferable Representation Learning and Zero-Shot Transfer in CLIP](https://proceedings.iclr.cc/paper_files/paper/2024/file/f41b6e5af73421e46ceed9cb036e72e7-Paper-Conference.pdf)
6. [Mind the Gap: Understanding the Modality Gap in Multi-modal Contrastive Representation Learning](https://proceedings.neurips.cc/paper_files/paper/2022/file/702f4db7543a7432431df588d57bc7c9-Paper-Conference.pdf)
7. [MedCLIP: Contrastive Learning from Unpaired Medical Images and Text](https://aclanthology.org/2022.emnlp-main.256.pdf)
8. [UniCLIP: Unified Framework for Contrastive Language–Image Pre-training](https://papers.neurips.cc/paper_files/paper/2022/file/072fd0525592b43da661e254bbaadc27-Paper-Conference.pdf)
9. [Oord, Aaron van den, Li, Yazhe, Vinyals, Oriol (2018). Representation Learning with Contrastive Predictive Coding. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1807.03748)
10. [Contrastive Learning of Medical Visual Representations from Paired Images and Text (ConVIRT)](https://proceedings.mlr.press/v182/zhang22a/zhang22a.pdf)
11. [Understanding Multimodal Contrastive Learning and Incorporating Unpaired Data](https://ar5iv.labs.arxiv.org/html/2302.06232)
12. [Meta CLIP 2: A Worldwide Scaling Recipe](https://papers.neurips.cc/paper_files/paper/2025/file/449fb670956a93b3d4d95167f72093e1-Paper-Conference.pdf)
13. [Chen, Ting and colleagues (2020). A Simple Framework for Contrastive Learning of Visual Representations. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2002.05709)
14. [Goel, Shashank and colleagues (2022). CyCLIP: Cyclic Contrastive Language-Image Pretraining. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2205.14459)
15. [SigLIP 2: Multilingual Vision-Language Encoders with Improved Semantic Understanding, Localization, and Dense Features](https://arxiv.org/pdf/2502.14786)
16. [Girdhar, Rohit and colleagues (2023). ImageBind: One Embedding Space To Bind Them All. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2305.05665)
17. [Zolfaghari, Mohammadreza and colleagues (2021). CrossCLR: Cross-modal Contrastive Learning For Multi-modal Video Representations. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2109.14910)
18. [AlignCLIP: Mitigating the Modality Gap via Improved Cross-Modal Alignment (ICLR 2025)](https://proceedings.iclr.cc/paper_files/paper/2025/file/cc1de06a58ba1db43538a37e076e466d-Paper-Conference.pdf)
19. [Xu, Hu and colleagues (2023). Demystifying CLIP Data. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2309.16671)
20. [ALIGN: Scaling Up Visual and Vision-Language Representation Learning With Noisy Text Supervision (Google AI blog)](https://research.google/blog/align-scaling-up-visual-and-vision-language-representation-learning-with-noisy-text-supervision/)

---
*Initially written Sep 29, 2026 · Edited: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › 机器学习与神经计算 › 机器学习方法 › 监督、无监督与半监督学习

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/cross-modal-contrastive-learning

English original: https://www.edgepedia.org/cross-modal-contrastive-learning
