Advancing Prompt Learning through an External Layer

Fangming Cui, Xun Yang, Chao Wu, Liang Xiao, Xinmei Tian · DOI

Abstract

Prompt learning represents a promising method for adapting pre-trained vision-language models (VLMs) to various downstream tasks by learning a set of text embeddings. One challenge inherent to these methods is the poor generalization performance due to the invalidity of the learned text embeddings for unseen tasks. A straightforward approach to bridge this gap is to freeze the text embeddings in prompts, which results in a lack of capacity to adapt VLMs for downstream tasks. To address this dilemma, we propose a paradigm called EnPrompt with a novel External Layer (EnLa). Specifically, we propose a textual external layer and learnable visual embeddings for adapting VLMs to downstream tasks. The learnable external layer is built upon valid embeddings of pre-trained CLIP. This design considers the balance of learning capabilities between the two branches. To align the textual and visual features, we propose a novel two-pronged approach: i) we introduce the optimal transport as the discrepancy metric to align the vision and text modalities, and ii) we introduce a novel strengthening feature to enhance the interaction between these two modalities. Four representative experiments (i.e., base-to-novel generalization, few-shot learning, cross-dataset generalization, domain shifts generalization) across 15 datasets demonstrate that our method outperforms the existing prompt learning method.

Introduction

Vision-Language Models (VLMs) like CLIP have demonstrated remarkable zero-shot capabilities. However, adapting these models to specific downstream tasks via "prompt learning" (e.g., CoOp) often leads to a generalization collapse. When models learn specific text prompts for a set of "base" classes, they frequently overfit, rendering the learned embeddings invalid for "novel" classes. This creates a dilemma: freezing embeddings preserves general knowledge but limits task adaptation, while making them learnable sacrifices generalization. EnPrompt aims to find the "Goldilocks zone"—retaining general knowledge while allowing for deep task-specific adaptation.

Methodology: The EnPrompt Paradigm

To resolve the generalization gap, we introduce EnPrompt, a framework centered on a novel External Layer (EnLa) and advanced modality alignment.

Architectural comparison of EnPrompt (Ours) against CoOp and MaPLe, highlighting the External Layer (EnLa), Optimal Transport alignment, and feature fusion mechanisms.

External Layer (EnLa)

Unlike traditional methods that modify text embeddings directly, EnPrompt freezes the original CLIP embeddings. It adds a learnable transformer-based External Layer (EnLa) on top. This allows the model to adapt the output of the text branch without corrupting the underlying linguistic knowledge, effectively acting as a "black box" that diversifies prompt templates and reduces sensitivity to manual prompt engineering.

Modality Alignment via Optimal Transport

Rather than relying solely on Cross-Entropy (CE) loss, EnPrompt utilizes Optimal Transport (OT) as a discrepancy metric. OT treats features as probability distributions, finding the most efficient way to align vision and text modalities. This approach is more robust to distribution shifts than standard point-to-point metrics, capturing subtle nuances that traditional Euclidean distance might miss.

Strengthening Feature Interaction

To ensure balanced learning between branches, a "V-L function" transfers features from the textual EnLa into the visual branch. These are fused with learnable visual embeddings and integrated into the image encoder via "deep prompting," ensuring neither modality dominates the adaptation process.

Experimental Results

We evaluated EnPrompt across 15 diverse datasets, covering generic objects (ImageNet), fine-grained classification (OxfordPets, Flowers102), and specialized tasks like satellite imagery (EuroSAT) and action recognition (UCF101).

Radar chart comparing EnPrompt (Ours) with CLIP, CoOp, CoCoOp, and MaPLe across various datasets, demonstrating superior performance across most benchmarks.

Base-to-Novel Generalization

EnPrompt achieved a Harmonic Mean (HM) of 80.64% across 11 datasets, significantly outperforming the previous state-of-the-art, MaPLe (78.55%), and CoOp (71.66%). Notably, it improved CLIP’s zero-shot accuracy on novel classes by 2.69%, whereas previous methods like CoOp actually decreased performance on unseen categories.

Domain Robustness and Few-Shot Learning

In domain shift scenarios (e.g., testing on sketches or adversarial images), EnPrompt maintained the highest average accuracy (60.77%), proving its resilience against distribution shifts. Furthermore, it showed significant gains in few-shot scenarios, particularly with as few as 2 training shots, indicating rapid and effective modality alignment.

Conclusion

EnPrompt successfully bridges the gap between task-specific adaptation and broad generalization in VLMs. By utilizing an external layer and optimal transport, it achieves state-of-the-art results across a wide array of benchmarks. Future work will explore extending this paradigm to more complex temporal tasks like video moment retrieval and investigating broader cross-domain scaling.

Summary updated

BibTeX
@inproceedings{cui2024advancing,
  author = {Fangming Cui and Xun Yang and Chao Wu and Liang Xiao and Xinmei Tian},
  title = {{Advancing Prompt Learning through an External Layer}},
  booktitle = {ACM Multimedia},
  year = {2024},
  doi = {10.1145/3664647.3680953},
}
Figure