AAPL: Adding Attributes to Prompt Learning for Vision-Language Models
Gahyeon Kim Sohee Kim Seokju Lee



Symmetry Breaking and Spatiotemporal Pattern Formation in Photonic
Time Crystals
    Yiming Pan
    April 29, 2024
================================================================================

[1]These authors contributed equally.
[2]Corresponding author.


Recent advances in large pre-trained vision-language models have demonstrated remarkable performance on zero-shot downstream tasks. Building upon this, recent studies, such as CoOp and CoCoOp, have proposed the use of prompt learning, where context within a prompt is replaced with learnable vectors, leading to significant improvements over manually crafted prompts. However, the performance improvement for unseen classes is still marginal, and to tackle this problem, data augmentation has been frequently used in traditional zero-shot learning techniques. Through our experiments, we have identified important issues in CoOp and CoCoOp: the context learned through traditional image augmentation is biased toward seen classes, negatively impacting generalization to unseen classes. To address this problem, we propose adversarial token embedding to disentangle low-level visual augmentation features from high-level class information when inducing bias in learnable prompts. Through our novel mechanism called “Adding Attributes to Prompt Learning", , we guide the learnable context to effectively extract text features by focusing on high-level features for unseen classes. We have conducted experiments across 11 datasets, and overall,  shows favorable performances compared to the existing methods in few-shot learning, zero-shot learning, cross-dataset, and domain generalization tasks. The code is available at: https://github.com/Gahyeonkim09/AAPLhttps://github.com/Gahyeonkim09/AAPL
      


§ INTRODUCTION


Recent research has shown significant improvements not only in model generalization performance through the use of large-scale vision-language models (VLMs), but also in zero-shot image classification performance <cit.>. It has been demonstrated that utilizing VLMs such as contrastive language-image pretraining (CLIP) <cit.>, ALIGN <cit.>, Flamingo <cit.>, etc., is effective in extracting image and text information for training classification models. The strengths of these VLMs have proven to be effective in prompt learning and handling both visual and textual information efficiently <cit.>. 
CoOp <cit.> and CoCoOp <cit.> have effectively produced learnable context vectors for classification weights via a text encoder (, Transformer <cit.>) along with CLIP. Specifically, CoCoOp <cit.> has enabled the creation of class-specific classification weights by incorporating additional context information generated from images. In addition, visual prompt tuning (VPT) <cit.> demonstrated performance improvements in downstream tasks by introducing a small number of learnable parameters into the encoder layer of the Transformer along with image patches, without the need to replace or fine-tune the pre-trained transformer.



However, both CoOp <cit.> and VPT <cit.> have learnable parameters that are not manageable, especially in the case of CoCoOp <cit.>, where it is unknown how the learnable vector will be shifted by the conditional bias based on particular information taken from the image that is added to the learnable context vector. This lack of management over learnable parameters can lead to unintentional bias in few-shot classification tasks or domain generalization tasks <cit.>. To address this, we propose a new approach called , “Adding Attributes to Prompt Learning”, as illustrated in Fig. <ref>.
In this context, augmentation generates a learnable bias that can be decomposed, with the augmented image serving as the visual prompt. 
Subsequent learning with visual-text prompts involves the use of a learnable context vector, which plays an adversarial role and mitigates unintended overfitting in downstream tasks <cit.>. In summary, our contributions are as follows:
♢=4mm =0mm =0mm
  
  *  We propose using augmented images as a visual prompt and introduce the concept of “delta meta token,” which encapsulates attribute-specific information.
  
  *  Employing delta meta token, we conduct AdTriplet loss to make the conditional bias include the semantic feature of the class robustly, even in the presence of augmentation added to the learnable prompt through adversarial triplet loss.
  
  *  We demonstrate performance improvements in base-to-new generalization tasks, cross-dataset tasks, and domain generalization tasks.


 




§ RELATED WORKS


Vision-language models    Vision-language models (VLMs) using image-text pairs have shown superior capabilities over image-only models, especially in zero-shot transfer tasks for various downstream classification tasks <cit.>. Prominent models such as CLIP <cit.> and ALIGN <cit.>, which have advanced through large-scale web data utilization, employ self-supervised learning for enhanced textual and visual alignment. In the embedding space, the contrastive loss draws matched image-text representation pairs closer, while it draws the representation of mismatched pairs farther away. Using this method, CLIP demonstrates exceptional zero-shot image recognition capabilities without the need for further fine-tuning. Our goal is to find efficient methods for applying pre-trained vision-language models to downstream applications, especially in prompt learning like CoOp <cit.> and CoCoOp <cit.>.


Prompt learning in vision-language models    The concept of prompt learning was initially proposed in the domain of natural language processing (NLP) <cit.>. 
Unlike manually designing prompts, prompt learning research focuses on automatically selecting prompts during the fine-tuning stage.
Recently, this concept has been extended to the field of computer vision <cit.>.
CoOp <cit.> introduced continuous prompt learning to the vision domain, applying pre-trained vision-language models to various tasks. Instead of using a manual prompt like “a photo of a", they transformed the context word into a learnable context vector to optimize continuous prompts.
However, CoOp has limitations in generalizability due to overfitting on few-shot datasets. To address this, CoCoOp <cit.> adds a conditional bias called meta token extracted from image features to the learnable prompt. 
It shifts the focus from static to dynamic prompts, enabling optimization based on the characteristics of each instance rather than a specific class, consequently enhancing CoOp's domain generalization performance.
However, meta token obtained from an image sample cannot be claimed to be completely robust against overfitting issues <cit.>, and it is not interpretable because it is extracted from the shallow network, called metanet, composed of Linear-ReLU-Linear layers. Therefore, we propose a new prompt learning method using image augmentation to leverage attribute-specific bias added to learnable prompts.


Zero-shot learning    
Few-shot learning is the process of training on a small number of labeled samples before classifying the new images. In contrast, zero-shot learning (ZSL) aims to distinguish unseen classes by training exclusively on seen classes <cit.>.
This is achieved by exclusively training on a set of base classes and utilizing side information, typically visual attributes like color, shape, and other features, shared with these unseen classes. This auxiliary information helps the machine understand language or concepts in a way humans do, enabling it to recognize unseen classes. 
The common methods <cit.> are learning the relation between a class embedding and the image feature, which represents this auxiliary information. 
However, these methods often exhibit a bias against unseen classes, known as “seen-class bias" <cit.>.
Other research efforts concentrate on enhancing visual-semantic embedding <cit.>, or developing better image feature extractors <cit.>.
However, these methods usually assume a fixed set of auxiliary information, consisting of attributes labeled by humans. This assumption poses challenges, as labeling attributes is expensive, requires expert annotators, and is difficult to scale on large datasets.
Diverging from existing ZSL methods, our work focuses on adapting large vision-language models and employs techniques based on prompting. 




§ METHODOLOGY







 §.§ Preliminaries

Prompt learning for CLIP    CLIP <cit.> employs an image encoder based on ResNet <cit.> or ViT <cit.> and a text encoder based on Transformer <cit.> to extract features from images and text, respectively. These features are trained with a contrastive loss in the embedding space, aiming to maximize cosine similarities between paired modality features. When an input image x is processed through the image encoder f(·), it generates an image feature f(x). Using a prompt template like “a photo of a {class}.", where the {class} token is substituted with the name of the i-th class, yields K text features with corresponding weight vectors {w_i}^K_i=1 for the given K class categories. The prediction probability for CoOp is as Eq. <ref>, where sim(·, ·) denotes cosine similarity and τ is a temperature parameter.
    
    p(y|x) = exp(sim(f(x), w_y)/τ)/∑_i=1^Kexp(sim(f(x), w_i)/τ)
    

Conditional context optimization in prompt learning      CoOp <cit.> introduces context tokens as trainable vectors, M learnable context, {v_1, v_2,..., v_M}, departing from a fixed template like “a photo of a". The i-th class prompt, t_i = {v_1, v_2,..., v_M, c_i}, includes these vectors and word embeddings of the class name, c_i. Text features are generated from t_i by CLIP text encoder g(·), which remained frozen throughout training. 
CoCoOp <cit.> proposes instance-conditional context to prioritize individual input instances, reducing the overfitting of CoOp. This is done by using a metanet, denoted as h_θ(·) parameterized by θ, to generate a conditional token for each input. 
Where π = h_θ(f(x)) and m ∈{1, 2,..., M}, each context token is obtained by v_m(x) = v_m + π. The prompt of the i-th class is conditioned on the input image feature, , t_i(x) = {v_1(x), v_2(x),..., v_M(x), c_i}. Jointly updating context vectors {v_m(x)}^M_m=1 and metanet during training ensures generalizability. The prediction probability for CoCoOp is as follows:
    
    p(y|x) = exp(sim(f(x), g(t_y(x)))/τ)/∑_i=1^K exp(sim(f(x), g(t_i(x)))/τ).






 §.§ Delta Meta Token

Effect of augmentation in CoCoOp    To investigate the effect of augmentation in prompt learning, we conducted a comparative experiment by adapting augmentation into CoCoOp <cit.>. 
We added conditional bias from augmented images to the learnable prompt while maintaining other settings consistent with CoCoOp. 
As detailed in Table <ref>, incorporating augmentation leads to a decrease in base-to-new generalization accuracy compared to the original CoCoOp since the metanet fails to extract the semantic features from the augmented images; thus extracting arbitrary noise rather than attribute-specific semantics. 
Additionally, as shown in Fig. <ref>, it does not show a big difference in class clustering, indicating that the meta token fails to capture the crucial semantic features for the classification. Consequently, this suggests that merely using augmentation in prompt learning might not enhance robustness or performance. It potentially leads to detrimental effects due to the metanet's inability to identify meaningful semantic features from the augmented images, focusing on instance-specific features rather than class semantics. To achieve optimal results, augmentation needs to be applied more carefully, ensuring that the conditional biases appropriately capture the semantic information of the class. 

                           




             

Delta meta token: detach attribute feature    CoCoOp <cit.> improves the generalization performance of CoOp <cit.> by introducing metanet, which outputs meta token from image samples, then adds it to the learnable prompt. It focuses on learning about individual instance information rather than class information.  However, it's still unclear what information the meta token contains, as the metanet is a black box, and its shallow architecture leads to uncertain feature extraction. As shown in Fig. <ref>, it fails to demonstrate clear clustering by neither augmentation type nor class. It shows that the meta token does not effectively capture the semantic information of the class or the attribute of the input image sample. To address this issue and make it possible to add desired information to the learnable prompt, we propose the concept of a delta meta token, the attribute-specific bias. The overview of  is shown in Fig. <ref>.

To make a delta meta token, two images of each of the two different classes are required, , class 1 and class 2, as shown in Fig. <ref>. 
Two different augmentation types are randomly selected from 14 augmentations proposed in SimCLR <cit.> for each pair of input images without any duplication, which is denoted as Aug_A(·) and Aug_B(·). 
Inspired by TextManiA <cit.>, which demonstrated the extraction of attribute information from text using Word Vector Analogy <cit.>, we generate delta meta token by subtracting image features in the same class with different augmentation. Delta meta token represents a difference vector from image features that contain augmentation information. They are generated at each iteration. The delta meta token from an image x of class 1 and Aug_A(·) can be written as follows:


    Δπ^1A = h_θ(f(Aug_A(x_1))) - h_θ(f(x_1)) .


As TextManiA has shown, utilizing attributes containing semantic details derived from class information demonstrates its effectiveness in classification tasks. 
In other words, while the meta token includes both class and attribute information, the delta meta token preserves more specific image feature information associated with augmentation.
Adding decomposed auxiliary features to the learnable prompts, the delta meta token can learn attribute information. We enable the learnable prompt to incorporate semantic features more abundantly, thus making the augmentation more effective. 
Similar to adversarial prompt learning for natural language processing <cit.>, our method involves the adversarial interaction between class and attribute information, where the metanet learns to extract attribute-related information from augmented image features. 
The more the learnable prompt learns the semantic feature information of the class, the better the classification performance.







Does the delta meta token have exact augmentation information?    In Fig. <ref>, we used t-SNE to compare the validation results of metanet of both CoCoOp <cit.> and . It shows that CoCoOp fails to distinguish between augmentations compared to . As comparing Fig. <ref> (c) and (d), while meta token cannot perfectly discriminate 14 augmentations, delta meta token shows almost perfect distinction, except for a few augmentations, , vertical flip and rotations. This clustering result shows that the delta meta token extracts more specific information about augmentation than the meta token. As demonstrated in TextManiA <cit.>, for the textual case, subtraction between features can retain specific features. In the case of the image, we show that delta meta token is more effective in making it contain the exact augmentation information. To the best of our knowledge, we are the first to employ feature decomposition through subtraction using visual features for prompt learning. It is noteworthy that, while the meta token still retains information about the class, the delta meta token accurately distinguishes between the semantic feature and the attribute feature.



 §.§ Adversarial Triplet Loss

Using triplet loss <cit.>, we can eliminate the remaining class-specific information in the delta meta token while enhancing information related to augmentations. Training is conducted with 4 delta meta tokens, , Δπ^1A, Δπ^1B, Δπ^2A, and Δπ^2B, in the embedding space, aiming to increase the distance between vectors of the same class while minimizing it for the same augmentation. 
For instance, considering anchor as Δπ^1A, its positive pair is Δπ^2A, which has a different class but the same augmentation. In contrast, Δπ^1B is considered a negative pair because it has the same class but a different augmentation.
The distance between the anchor and the negative pair should be greater than the distance between the anchor and the positive pair. The Euclidean distance is denoted as ·_2, and the margin of the triplet loss is denoted as m in Eq. <ref>.


    L_triplet(x, x^+, x^- ;Δπ^1A, Δπ^2A,Δπ^1B) 
    
      = max (0, x - x^+_2 - x - x^-_2 + m ) 
    
      = max (0, Δπ^1A - Δπ^2A_2 - Δπ^1A - Δπ^1B_2 + m )


Thus, we introduce the Adtriplet loss, which adversarially trains the model to prioritize the alignment of augmentation information over class information. This loss is updated alongside the classification loss, specifically the cross-entropy loss.
The AdTriplet loss is used as constraints-4, as illustrated in Fig. <ref>, to make the connection between the class information domain and augmentation attribute domain more balanced <cit.>.


    L_AdTriplet = L_triplet^1(Δπ^1A, Δπ^2A,Δπ^1B) 
    + L_triplet^2(Δπ^2B, Δπ^1B, Δπ^2A)
 

Cross-entropy loss is computed following the same method as CoCoOp <cit.>. 
To ensure fairness between the training and test phases, only one input image label is used for cross-entropy loss calculation.
The final training loss function is as follows: 

    L_total = α * L_AdTriplet + β * L_CE,
 
where α and β are hyper-parameters for scaling. 
In Sec. <ref>, we provide detailed information on parameter tuning.








§ EXPERIMENTS






 §.§ Experimental Settings

Datasets  We use 11 classification datasets based on CLIP <cit.>, CoOp <cit.>, and CoCoOp <cit.> for base-to-new generalization and cross-dataset transfer: ImageNet <cit.> and Caltech101 <cit.> for generic object classification, OxfordPets <cit.>, StanfordCars <cit.>, Flowers102 <cit.>, Food101 <cit.> and FGVCAircraft <cit.> for fine-grained image recognition, EuroSAT <cit.> for satellite image classification, UCF101 <cit.> for action classification, DTD <cit.> for texture classification, and SUN397 <cit.> for scene recognition. 
For domain generalization experiments, we use ImageNet <cit.> as the source dataset and 4 other ImageNet-based datasets, , ImageNetV2 <cit.>, ImageNetSketch <cit.>, ImageNet-A <cit.>, and ImageNet-R <cit.>, as the target datasets, which each contain a different kind of domain shift. 

Baselines  We compare  with 3 baseline methods: the zero-shot CLIP <cit.>, CoOp <cit.>, and CoCoOp <cit.>. 
CLIP uses the hand-crafted template “a photo of a {class}" to generate the prompts for knowledge transfer.
CoOp learns a static prompt that replaces the hand-crafted prompts with the learnable vectors.
CoCoOp generates dynamic prompts by adding the image-conditional prompts to the learnable prompts in CoOp.

Training details  Our implementation is based on CoCoOp <cit.>. We employ the pre-trained ViT-B/16 model from CLIP <cit.> as the backbone. We fix the context length to 4 and initialize the context vectors randomly. The presented results are the mean values obtained from experiments conducted with three random seeds. We follow the training epochs, batch sizes, and schedules as prescribed by CoCoOp. In the context of few-shot learning, we confine evaluation to the maximum shot, , 16 shots, considered by CoOp. For evaluation, we use the model from the last epoch. The parameter size of  is the same as CoCoOp, and the hyper-parameter m in Eq. <ref> is set to 0.2.






 §.§ Generalization from Base-to-New Classes

We divided the classes equally into two groups, one for the base classes and another for the new classes, , unseen classes, just like in CoCoOp <cit.>. Learning-based models are trained solely on base classes. In few-shot learning, the model is evaluated with the base classes, whereas in zero-shot learning, it is evaluated with the new classes to test the model's generalizability.
In this task, we set hyper-parameters α and β to 0.2 and 1. Table <ref> presents the performance results of  compared to the baseline.
 outperformed in 7 out of 11 datasets, with the harmonic mean of total dataset accuracy exceeding that of CoCoOp. However, performance on the DTD <cit.> was significantly lower. The geometrical augmentations, especially flips and rotations, appear to have minimal effect on , as they do not significantly alter the appearance of the original images in the context of texture. This demonstrates that the effectiveness of  varies across different datasets. 




 §.§ Cross-Dataset Transfer

To assess the robustness and adaptability of , we tested its generalization ability across datasets by training it on all 1000 ImageNet classes and then applying it on the other 10 datasets, as shown in Table <ref>. 
We assume that the model can learn semantic information about image features by learning precise attributes. 
To evaluate this, we increased the model's focus on learning augmentation information by setting both hyper-parameters, α and β, to 1 in this experiment and afterward.  achieves higher generalization in 3 datasets: OxfordPets <cit.>, FGVCAircraft <cit.>, and UCF101 <cit.>, compared to CoCoOp <cit.>. However, the performance on DTD <cit.> and EuroSAT <cit.> was noticeably poorer than other datasets. This suggests that these datasets are vulnerable to 's augmentation-based prompt learning. 
These datasets are not object-centric but rather possess global features, , long-distance satellite images and texture images. Extracting specific attributes from these datasets is challenging due to their unique characteristics. 






 §.§ Domain Generalization

For domain generalization, we trained our model on the whole ImageNet dataset, same as in Sec. <ref>, and evaluated it on 4 datasets that represent a domain shift from ImageNet (, ImageNetV2 <cit.>, ImageNetSketch <cit.>, ImageNet-A <cit.>, and ImageNet-R <cit.>). The comparison of these tests is presented in Table <ref>. We achieved better performance on all datasets except for ImageNet-A. This demonstrates that attribute-specific bias effectively deals with domain shift. 







 §.§ Augmentation Profiling

Why should the delta meta token learn about attributes rather than class information?    
To assess the effectiveness of learning attributes, we compared the silhouette scores <cit.> based on augmentation types. 
The silhouette score evaluates how well data points are clustered, considering both cohesion (proximity within the same cluster) and separation (distance from the nearest neighboring cluster).
The silhouette score S(i) for data point i, is calculated as follows: S(i) = b(i)-a(i)/max{a(i), b(i)}, where a(i) is the average distance of i to all other data points in the same cluster, and b(i) is the average distance of i to the data points in the nearest cluster that i does not belong to.
A higher silhouette score indicates better clustering. In other words, datasets that effectively learn information about augmentations from the Adtriplet loss have higher silhouette scores. 
As shown in Fig. <ref>, the zero-shot classification performance of  generally improves. However, there is a sharp decrease in performance for DTD <cit.>  and EuroSAT <cit.>. 
This suggests that datasets that cannot effectively extract augmentation information do not perform well. 
Training precise attributes to delta meta token is crucial for zero-shot classification, and it's evident that determining what information to add to the learnable prompt is highly important for datasets sensitive to .


 

Which dataset is vulnerable for ?    
To assess the impact of various datasets on the evaluation of learning attribute features, we applied 's proposed AdTriplet loss and the traditional triplet loss method. 
Unlike the AdTriplet loss, the traditional triplet loss trains the delta meta token to cluster classes rather than augmentation types. 
As shown in Table <ref>, when utilizing Adtriplet loss across 6 datasets, performance improvement was observed compared to using triplet loss. Particularly, FGVCAircraft <cit.> exhibited approximately a 7% higher performance improvement with the triplet loss. Utilizing the traditional triplet loss method means that the delta meta token is trained to bring the same class together regardless of augmentation type. Consequently, datasets that showed improved performance on AdTriplet loss have a higher dependency on class information. 
Triplet loss-trained delta meta token extracts class-related information, causing meta token to contribute noisy features rather than class semantic features when added to prompts. In contrast, AdTriplet loss-trained tokens focus on extracting the class semantic features. Datasets with AdTriplet loss perform well because they rely more on the class information. This highlights the advantage of  based on the dataset's characteristics. 





Which augmentation is effective to prompt learning?
    The t-SNE visualization of the delta meta token for 14 augmentations is shown, along with their silhouette scores, in Fig. <ref> (a). It turned out that it is difficult to distinguish rotations from flips and between color jitters, while other augmentations are obvious. All datasets exhibit difficulty in distinguishing these augmentations.
Following selective augmentation training, when trained only on augmentations whose results are good (shown in Fig. <ref> (b)), clustering is greatly enhanced, and silhouette scores are also raised. Also, the average performance for base-to-new generalization improved, as seen in Table <ref>. But when training solely with the opposite, , bad augs (Fig. <ref> (c)), there is neither significant improvement in silhouette scores nor in the average base-to-new generalization results. 
The ambiguity of augmentations between flips and rotations and between color jitters limits the learning capacity of the metanet. 







 with weighted random sampling    
Fig. <ref> shows a consistent correlation between lower silhouette scores and worse zero-shot classification performance compared to CoCoOp <cit.> across several datasets. Insufficient knowledge of semantic features makes classifying unseen classes more difficult. To address this, an active approach <cit.> was utilized for datasets DTD <cit.>, EuroSAT <cit.>, StanfordCars <cit.>, and SUN397 <cit.>, which have insufficient learning of augmentation type information. 
For training, silhouette scores were used as thresholds for random sampling weights. As shown in Table <ref>, this improved the performance of base-to-new generalization across all 4 datasets. 
Notably, EuroSAT showed a significant 10% improvement, emphasizing the effectiveness of dynamically selecting and emphasizing weaker augmentation types during each epoch. 
It demonstrates that attribute-specific feature decomposition for challenging augmentations enables more robust learning of semantic features.





§ CONCLUSION


Our novel approach efficiently extracts specific semantic features and delta meta tokens by subtracting the augmented image feature from the original image feature. Leveraging AdTriplet loss adversarially enhances classification loss, enabling precise discernment of attribute features through augmentations—a foundational aspect of our approach. By decomposing attribute and semantic features more accurately, we introduce attribute-specific bias into the prompt. Furthermore, our study underscores the indispensability of  in prompt learning with augmentation for zero-shot classification tasks. In summary, our emphasis on attribute decomposition in prompt learning is underscored through augmentation profiling and analysis of dataset correlations, augmentations, and  performance.



Acknowledgments    
Thanks to Prof. George Kamenos for his invaluable assistance in reviewing and editing this paper.
This work was partly supported by Innovative Human Resource Development for Local Intellectualization program through the Institute of Information & Communications Technology Planning & Evaluation(IITP) grant funded by the Korea government(MSIT) (IITP-2024-00156287, 40%). 
This research was supported by the Korea Institute for Advancement of Technology (KIAT) grant funded by the Ministry of Trade, Industry, and Energy (MOTIE), Korea, (P0025331, 30%). 
This work was supported by the National Research Foundation of Korea(NRF) grant funded by the Korea government(MSIT) (No. RS-2023-00252616, 30%). 






    ieeenat_fullname
    


