{'fraction_non_alphanumeric': 0.039475159807110013, 'fraction_numerical': 0.01289671414152742, 'mean_word_length': 4.856392294220665, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 1, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
TransZero: Attribute-guided Transformer for Zero-Shot Learning

Zero-shot learning (ZSL) aims to recognize novel classes by transferring semantic knowledge from seen classes to unseen ones. Semantic knowledge is learned from attribute descriptions shared between different classes, which act as strong priors for localizing object attributes that represent discriminative region features, enabling significant visual-semantic interaction. Although some attention-based models have attempted to learn such region features in a single image, the transferability and discriminative attribute localization of visual features are typically neglected. In this paper, we propose an attribute-guided Transformer network, termed TransZero, to refine visual features and learn attribute localization for discriminative visual embedding representations in ZSL. Specifically, TransZero takes a feature augmentation encoder to alleviate the cross-dataset bias between ImageNet and ZSL benchmarks, and improves the transferability of visual features by reducing the entangled relative geometry relationships among region features. To learn locality-augmented visual features, TransZero employs a visual-semantic decoder to localize the image regions most relevant to each attribute in a given image, under the guidance of semantic attribute information. Then, the locality-augmented visual features and semantic vectors are used to conduct effective visual-semantic interaction in a visual-semantic embedding network. Extensive experiments show that TransZero achieves the new state of the art on three ZSL benchmarks. The codes are available at: \url{https://github.com/shiming-chen/TransZero}.


Introduction
Figure 1: Motivation illustration. (a) Existing attentionbased ZSL methods simply learn region embeddings (e.g., the whole bird body), neglecting the transferability and discriminative attribute localization (e.g., the distinctive bird body parts) of visual features; (b) Our TransZero reduces the entangled relationships among region features to improve their transferability and localizes the object attributes to represent discriminative region features, enabling significant visual-semantic interaction.
based on the semantic information (e.g., sentence embeddings (Reed et al. 2016), and attribute vectors (Lampert, Nickisch, and Harmeling 2014)), which are shared between the seen and unseen classes employed to support the knowledge transfer. According to their classification range, ZSL methods can be categorized into conventional ZSL (CZSL), which aims to predict unseen classes, and generalized ZSL (GZSL), which can predict both seen and unseen classes (Xian, Schiele, and Akata 2017).
To enable visual-semantic interactions, early ZSL methods attempt to build an embedding between seen classes and their class semantic vectors, and then classify unseen classes by nearest neighbor search in the embedding space. Since the embedding is only learned by seen class samples, these embedding-based methods usually overfit to seen classes under the GZSL setting (known as the bias problem). To tackle this problem, many generative ZSL methods have been proposed to generate samples of unseen classes by leveraging generative models (e.g., variational autoencoders (VAEs) (Arora et al. 2018;Schönfeld et al. 2019;Chen et al. 2021b), generative adversarial nets (GANs) (Xian et al. 2018(Xian et al. , 2019Chen et al. 2021a), and generative flows (Shen, Qin, and Huang 2020)) for data augmentation. Thus the ZSL task is converted into a supervised classification problem.
Although these methods have achieved progressive improvement, they rely on global visual features which are insufficient for representing the fine-grained information of classes (e.g., red-legged of Kittiwake), since the discriminative information is contained in a few regions corresponding to a few attributes. Thus, the visual feature representations are limited, resulting in poor visual-semantic interactions. More recently, some attention-based models Zhu et al. 2019;Xu et al. 2020;Yu et al. 2018;Liu et al. 2019) have attempted to learn more discriminative region features with the guidance of the semantic information, as shown in Fig. 1(a). However, these methods are limited in: i) They directly take the entangled region (grid) features for ZSL classification, which hinders the transferability of visual features from seen to unseen classes; ii) They simply learn region embeddings (e.g., the whole bird body), neglecting the importance of discriminative attribute localization (e.g., the distinctive bird body parts). Thus, properly improving the transferability and localizing the object attributes for enabling significant visual-semantic interaction in ZSL has become very necessary.
To tackle the above challenges, in this paper, we propose an attribute-guided Transformer, termed TransZero, which reduces the entangled relationships among region features to improve their transferability and localizes the object attributes to represent discriminative region features in ZSL, as shown in Fig. 1(b). Specifically, TransZero consists of an attributed-guided Transformer (AGT) that learns localityaugmented visual features and a visual-semantic embedding network (VSEN) that conducts visual-semantic interactions. In AGT, we first take a feature augmentation encoder to i) alleviate the cross-dataset bias between ImageNet and ZSL benchmarks, and ii) reduce the entangled relative geometry relationships between different regions for improving the transferability from seen to unseen classes. They are ignored by existing ZSL methods. To learn locality-augmented visual features, we employ a visual-semantic detector in AGT to localize the image regions most relevant to each attribute in a given image, under the guidance of semantic attribute information. Then, the locality-augmented visual features and semantic vectors are used to enable visual-semantic interaction in VSEN. Extensive experiments show that TransZero achieves the new state of the art on three ZSL benchmarks. The qualitative results also demonstrate that TransZero refines visual features and provides attribute-level localization.
The main contributions of this paper are summarized as follows: • We introduce a novel ZSL method, termed TransZero, which employs an attribute-guided Transformer to refine the visual features and learn the attribute localization for discriminative visual embedding representations. To the best of our knowledge, TransZero is the first work extending the Transformer to the ZSL task.
• We propose a feature augmentation encoder to i) alleviate the cross-dataset bias between ImageNet and ZSL benchmarks, and ii) reduce the entangled relative geometry relationships between different regions to improve the transferability from seen to unseen classes. They are ignored by existing ZSL methods. • Extensive experiments demonstrate that TransZero achieves the new state of the art on three ZSL benchmarks. We further qualitatively show that our TransZero refines the visual features and accurately localizes finegrained parts for discriminative feature representations.

Related Work
Zero-Shot Learning. Early ZSL methods (Song et al. 2018;Li et al. 2018;Xian et al. 2018Xian et al. , 2019Yu et al. 2020;Min et al. 2020;Han et al. 2021;Chen et al. 2021a;Chou, Lin, and Liu 2021;Han et al. 2021) focus on learning a mapping between the visual and semantic domains to transfer semantic knowledge from seen to unseen classes. They typically extract global visual features from pre-trained or end-to-end trainable networks. Typically, end-to-end models achieve better performance than pre-trained ones because they fine-tune the visual features, thus alleviating the crossdataset bias between ImageNet and ZSL benchmarks (Chen et al. 2021a;Xian et al. 2019). However, these methods still usually yield relatively undesirable results, since they cannot efficiently capture the subtle differences between seen and unseen classes. More relevant to this work are the recent attention-based ZSL methods Zhu et al. 2019;Xu et al. 2020;Liu et al. 2021) that utilize attribute descriptions as guidance to discover the more discriminative region (or part) features. Unfortunately, They simply learn region embeddings (e.g., the whole bird body) neglecting the importance of discriminative attribute localization (e.g., the distinctive bird body parts). Furthermore, the end-to-end attention models are also time-consuming when it comes to fine-tuning the CNN backbone. In contrast, we propose an attribute-guided Transformer to learn the attribute localization for discriminative region feature representations under non end-to-end ZSL model.
Transformer Model. Transformer models (Vaswani et al. 2017) have recently demonstrated excellent performance on a broad range of language and computer vision tasks, e.g., machine translation (Ott et al. 2018), image recognition (Dosovitskiy et al. 2021), video understanding (Gabeur et al. 2020), visual question answering ), etc. The success of Transformers can be mainly attributed to selfsupervision and self-attention (Khan et al. 2021). The selfsupervision allows complex models to be trained without the high cost of manual annotation, which in turn enables generalizable representations that encode useful relationships between the entities presented in a given dataset to be learned. The self-attention layers take the broad context of a given sequence into account by learning the relationships between the elements in the token set (e.g., words in language or patches in an image). Some methods (Gabeur et al. 2020;Cornia et al. 2020;Huang et al. 2019;Pan et al. 2020) have also shown that the transformer architecture can better capture the relationship between visual features and process sequences in parallel during training. Motivated by these, we design an attribute-guided Transformer that reduces the re- AGT includes a feature augmentation encoder that alleviates the cross-dataset bias between ImageNet and ZSL benchmarks and reduces the entangled geometry relationships between different regions for improving the transferability from seen to unseen classes, and a visual-semantic decoder that learns locality-augmented visual features based on the semantic attribute information. VSEN is used to enable significant visual-semantic interaction.
lationships among different regions to improve the transferability of visual features and learns the attribute localization for representing discriminative region features.

Proposed Method
We first introduce some notations and the problem definition. Assume that we have D s = {(x s i , y s i )} as training data with C s seen classes, where x s i ∈ X denotes the image i, and y s i ∈ Y s is the corresponding class label. Another set of unseen classes C u has unlabeled samples i ∈ X are the unseen class images, and y u i ∈ Y u are the corresponding labels. A set of class semantic vectors of the class c ∈ C s ∪ C u = C with A attributes z c = [z c 1 , . . . , z c A ] = φ(y) helps knowledge transfer from seen to unseen classes. Note that we also use the semantic attribute vectors of each attribute {v a } A a=1 learned by a language model (i.e., GloVe (Pennington, Socher, and Manning 2014)) according to each word in attribute names. ZSL aims to predict the class labels y u ∈ Y u and y ∈ Y = Y s ∪ Y u in the CZSL and GZSL settings, respectively, where Y s ∩Y u = ∅.
In this paper, we propose an attribute-guided Transformer network (termed TransZero) to refine the visual features and localize the object attributes for representing the discriminative region features under a non end-to-end model. This enables significant visual-semantic interaction in ZSL. As illustrated in Fig. 2, our TransZero includes an attributeguided Transformer (AGT) and visual-semantic embedding network (VSEN). AGT refines the visual feature using a feature augmentation encoder, and learns locality-augmented visual features using a visual-semantic decoder. VSEN enables visual-semantic interaction for ZSL classification.

Attribute-Guided Transformer
Feature Augmentation Encoder. Since there is a crossdataset bias between ImageNet and ZSL benchmarks (Chen et al. 2021a), we introduce a feature augmentation encoder to refine the visual features of ZSL benchmarks. Additionally, previous ZSL methods typically flatten the grid features (extracted from a CNN backbone) into a feature vector, which is further used for generative models or embedding learning. However, such a feature vector implicitly entangles the feature representations among various regions in an image, which hinders their transferability from one domain to other domains (e.g., from seen to unseen classes) (Xu et al. 2020;Atzmon et al. 2020;Chen et al. 2021c). As such, we propose a feature-augmented scaled dot-product attention to further enhance the encoder layer by reducing the relative geometry relationships among the grid features.
To learn relative geometry features (Herdade et al. 2019;Zhang et al. 2021), we first calculate the relative center coordinates (v cen i , t cen i ) based on the pair of 2D relative positions of the i-th grid v min where ) are the relative position coordinates of the top left corner and bottom right corner of the grid i, respectively.
Then, we construct region geometry features G ij between grid i and grid j: where where r ij is the relative geometry relationship between grids i and j, F C is a fully connected layer followed by a ReLU activation, and w T g is a set of learnable weight parameters.
Finally, we substract the region geometry features from the visual features in the feature-augmented scaled dotproduct attention to provide a more accurate attention map, formally defined as: where Q, K, V are the query, key and value matrices, W e q , W e k , W e v are the learnable matrices of weights, d e is a scaling factor, and Z aug is the augmented features. U ∈ R HW ×C are the packed visual features, which are learned from the flattened features embedded by a fully connected layer followed by a ReLU and a Dropout layer.
Visual-Semantic Decoder. Following the standard Transformer (Vaswani et al. 2017), our visual-semantic decoder takes a multi-head self-attention layer and feed-forward network (FFN) to build the decoder layer. The decoding process continuously incorporates visual information under the guidance of semantic attribute features v A . Thus, our visualsemantic decoder can effectively localize the image regions most relevant to each attribute in a given image. The multihead self-attention layer uses the outputs of the encoder U as keys (K d t ) and values (V d t ) and a set of learnable semantic embeddings v A as queries (Q d t ). It is defined as: where W d qt , W d kt , W d vt are the learnable weights, d d is a scaling factor, and is a concatenation operation. Then, an FFN with two linear transformations followed a ReLU activation in between is applied to the attended featuresF : where W 1 , W 2 , b 1 and b 2 are the weights and biases of the linear layers respectively, and F are the locality-augmented visual features.

Visual-Semantic Embedding Network
After generating locality-augmented visual features, we further map them into the semantic embedding space. To encourage the mapping to be more accurate, we take the semantic attribute vectors {v a } A a=1 as support, based on a mapping function (M). Specifically, M matches the locality-augmented visual features F with the semantic attribute information v A : where W is an embedding matrix that embeds F into the semantic attribute space. In essence, ψ(x i )[a] is an attribute score that represents the confidence of having the a-th attribute in the image x i . Given a set of semantic attribute vectors {v a } A a=1 , TransZero attains a mapped semantic embedding ψ(x i ).

Model Optimization
To achieve effective optimization, we employ the attribute regression loss, attribute-based cross-entropy loss and selfcalibration loss to train TransZero.
Attribute Regression Loss. To encourage VSEN to accurately map visual features into their corresponding semantic embeddings, we introduce an attribute regression loss to constrain TransZero. Here, we regard visual-semantic mapping as a regression problem and minimize the mean square error between the ground truth attribute z c and the embedded attribute score ψ(x s i ) of a sample x s i : Attribute-Based Cross-Entropy Loss. Since the associated image embedding is projected near its class semantic vector z c when an attribute is visually present in an image, we take the attribute-based cross-entropy loss L ACE to optimize the parameters of the TransZero model, i.e., the dot product between the visual embedding and each class semantic vector is calculated to produce class logits. This encourages the image to have the highest compatibility score with its corresponding class semantic vector. Given a batch of n b training images {x s i } n b i=1 with their corresponding class semantic vectors z c , L ACE is defined as: . (15) Self-Calibration Loss. Since L AR and L ACE optimize the model on seen classes, TransZero inevitably overfits to these classes, as also observed in Huynh and Elhamifar 2020a;Xu et al. 2020). To tackle this challenge, we further introduce a self-calibration loss L SC to explicitly shift some of the prediction probabilities from seen to unseen classes. L SC is thus formulated as: where I [c∈C u ] is an indicator function (i.e., it is 1 when c ∈ C u , otherwise -1). Intuitively, L ACE encourages nonzero probabilities to be assigned to the unseen classes during training, which allows TransZero to produce a (large) nonzero probability for the true unseen class when given test samples from unseen classes. Finally, we formulate the overall loss function of Tran-sZero: where λ AR and λ SC are the weights to controle their corresponding loss terms. Table 1: Results (%) of the state-of-the-art CZSL and GZSL modes on CUB, SUN and AWA2, including end-to-end and non end-to-end methods (generative and non-generative methods). The best and second-best results are marked in Red and Blue, respectively. The Symbol "-" indicates no results. The Symbol "*" denotes attention-based methods.

Zero-Shot Prediction
After training TransZero, we first obtain the embedding features of a test instance x i in the semantic space i.e., ψ(x i ). Then, we take an explicit calibration to predict the test label of x i , which is formulated as: Here, C u /C corresponds to the CZSL/GZSL setting respectively.
Evaluation Protocols Following (Xian, Schiele, and Akata 2017), we measure the top-1 accuracy both in the CZSL and GZSL settings. In the CZSL setting, we simply predict the unseen classes to compute the accuracy of test samples, i.e., acc. In the GZSL setting, we compute the accuracy of the test samples from both the seen classes (denoted as S) and unseen classes (denoted as U ). Meanwhile, their harmonic mean (defined as H = (2 × S × U )/(S + U )) is also employed for evaluation in the GZSL setting.

Implementation Details
We use the training splits proposed in (Xian et al. 2018). We take a ResNet101 pre-trained on ImageNet as the CNN backbone for extracting the feature map without fine-tuning. We use the SGD optimizer with hyperparameters (momentum = 0.9, weight decay = 0.0001) to optimize our model. The learning rate and batch size are set to 0.0001 and 50, respectively. We empirically set λ SC to 0.3 and λ AR to 0.005 for all datasets. The encoder and decoder layers are set to 1 with one attention head.

Comparison with State of the Art
Conventional Zero-Shot Learning. Here, we first compare our TransZero with the state-of-the-art methods in the CZSL setting. As shown in Table 1, our TransZero achieves the best accuracies of 76.8% and 65.6% on CUB and SUN, respectively. This shows that TransZero effectively learns the attribute-augmented region feature representations for distinguishing various fine-grained classes. As for the coarse-grained dataset (i.e., AWA2), TransZero still obtains competitive performance, with a top-1 accuracy of 70.1%. Compared with other attention-based methods (e.g., SGMA , AREN , APN (Xu et al. 2020)), TransZero obtains significant gains of over 4.8% and 4.0% on CUB and SUN, respectively. This demonstrates that the attribute localization representations learned by our TransZero are more discriminative than the region embeddings learned by the existing attention-based methods on fine-grained datasets.  Generalized Zero-Shot Learning. Table 1 shows the results of different methods in the GZSL setting. The results show that the unseen accuracy (U ) of all methods is usually lower than the seen accuracy (S) on the CUB and AWA2 datasets, i.e., U < S. Meanwhile, U > S on the SUN dataset since the number of seen classes is much larger than the number of unseen classes.
We can see that most state-of-the-art methods achieve good results on seen classes but fail on unseen classes, while our method generalizes better to unseen classes with high unseen and seen accuracies. For example, TransZero achieves the best performance with harmonic mean of 68.8% and 70.2% on CUB and AWA2, respectively. We argue that the benefits of TransZero come from the fact that i) the feature augmentation encoder in AGT improves the discriminability and transferability of visual features, and ii) the self-calibration mechanism alleviates the bias problem. Finally, our TransZero also outperforms the attentionbased methods by harmonic mean improvements of at least 1.6%, 3.2% and 3.1% on CUB, SUN and AWA2, respectively. This demonstrates the superiority and great potential of our attribute-guided Transformer for the ZSL task.

Ablation Study
To provide the further insight into TransZero, we conduct ablation studies to evaluate the effects of the feature augmentation encoder (denoted as FAE), feature augmentation in FAE (denoted as FA), visual-semantic decoder (denoted as DEC), self-calibration loss (i.e., L SC ) and attribute regression loss (i.e., L AR ). Our results are shown in Table 2. TransZero performs significantly worse than its full model when no feature augmentation encoder is used, i.e., the acc/harmonic mean drops by 9.5%/12.0% on CUB and 4.4%/8.7% on SUN. If we incorporate the encoder of the standard Transformer without feature augmentation, TransZero again achieves poor results compared to its full model, i.e., the acc/harmonic mean drops by 2.8%/2.3% and 1.8%/2.3% on CUB and SUN, respectively. When TransZero without visual-semantic decoder, its performances decreases dramatically on all datasets. Moreover, the self-calibration mechanism can effectively alleviate the bias problem, resulting in improvements in the harmonic mean of 10.7% and 3.4% on CUB and SUN, respectively. The attribute regression constraint further improves the performance of TransZero by directing VSEN to conduct effective visual-semantic mapping.

Qualitative Results
Visualization of Attention Maps. To intuitively show the effectiveness of our TransZero at learning localityaugmented visual features, we visualize the attention maps learned by the existing attention-based methods (e.g., AREN (Xie et al. 2019)) and TransZero. As shown in Fig. 3, AREN simply learns region embeddings for visual representations, e.g., the whole bird body, neglecting the fine-grained semantic attribute information. In contrast, our Transzero learns discriminative attribute localization for visual features by assigning high positive scores to key attributes (e.g., the 'bill shape all purpose' of the Acadian Flycatcher in Fig. 3). Thus, TransZero achieves significant performance both in seen and unseen classes. t-SNE Visualizations. As shown in Fig. 4, we present the t-SNE visualization (Maaten and Hinton 2008) of visual features for (a) seen classes and (b) unseen classes on CUB, learned by the CNN backbone, TransZero encoder w/o FA, TransZero encoder, and TransZero decoder. When we incorporate the standard encoder into our TransZero, the visual features learned by the encoder are significantly improved compared to the original visual features extracted from the CNN Backbone (e.g., ResNet101). When we use the feature augmentation encoder to refine the original visual features, the quality of the unseen features is further enhanced. These results demonstrate that the encoder of TransZero effectively alleviates the cross-dataset bias problem and reduces the entangled relative geometry relationships among different regions, improving the transferability. Moreover, the visualsemantic decoder learns locality-augmented visual features for improving visual feature representations.

Hyperparameter Analysis
Effects of Loss Weight. λ AR is employed to weigh the importance of the attribute regression loss, which directs  the VSEN to conduct effective visual-semantic interaction. We try a wide range of λ AR evaluated on CUB and SUN, i.e., λ AR = {0.001, 0.005, 0.01, 0.05, 0.1, 0.5}. Results are shown in Fig. 5. When λ AR is set to a large value, all evaluation protocols tend to drop. This is because the loss value of the attribute regression loss is too large, and thus the contributions of other losses are mitigated. When λ AR is set to 0.005, our TransZero achieves the best performance.
Effects of Loss Weight. λ SC adjusts the weight of the self-calibration loss, which effectively alleviates the bias problem. As shown in Fig. 6, the accuracy on seen classes increases and the accuracy on unseen classes decreases when we increase λ SC . Meanwhile, TransZero is insensitive to the self-calibration loss in the CZSL setting. We investigate a wide range of λ SC on CUB and SUN to find an appropriate setting for λ SC . Based on the results, we set λ SC to 0.3 for all datasets.

Conclusion
In this paper, we propose a novel attribute-guided Transformer network for ZSL (termed TransZero). First, our Tran- sZero employs a feature augmentation encoder to improve the discriminability and transferability of visual features by alleviating the cross-dataset problem and reducing the entangled region feature relationships. Meanwhile, a visualsemantic decoder is introduced to learn the attribute localization for locality-augmented visual feature representations. Secondly, a visual-semantic embedding network is used to enable effective visual-semantic interaction between the learned locality-augmented visual features and class semantic vectors. Extensive experiments on three popular benchmark datasets demonstrate the superiority of our approach. We believe that our work also facilitates the development of other visual-and-language learning systems, e.g., natural language for visual reasoning.