ZHANGYUXUAN-zR commited on
Commit
ffc3028
·
verified ·
1 Parent(s): 32c11f0

Add files using upload-large-folder tool

Browse files
parse/dev/SwIp410B6aQ/SwIp410B6aQ.md ADDED
The diff for this file is too large to render. See raw diff
 
parse/dev/UDqHhbqYJV/UDqHhbqYJV.md ADDED
The diff for this file is too large to render. See raw diff
 
parse/dev/UDqHhbqYJV/UDqHhbqYJV_content_list.json ADDED
The diff for this file is too large to render. See raw diff
 
parse/dev/UDqHhbqYJV/UDqHhbqYJV_middle.json ADDED
The diff for this file is too large to render. See raw diff
 
parse/dev/UDqHhbqYJV/UDqHhbqYJV_model.json ADDED
The diff for this file is too large to render. See raw diff
 
parse/dev/bMYU8_qD8PW/bMYU8_qD8PW.md ADDED
@@ -0,0 +1,287 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # A Unified Model for Multi-class Anomaly Detection
2
+
3
+ Zhiyuan $\mathbf { V o u } ^ { 1 * }$ Lei $\mathbf { C u i ^ { 2 * } }$ Yujun Shen3 Kai Yang4 Xin Lu4 Yu Zheng1 Xinyi Le1†
4
+
5
+ 1Shanghai Jiao Tong University 2Tsinghua University 3CUHK 4SenseTime zhiyuanyou@foxmail.com, cuil19@mails.tsinghua.edu.cn, shenyujun0302@gmail.com {yangkai, luxin}@sensetime.com, yuzheng@sjtu.edu.cn, lexinyi@sjtu.edu.cn
6
+
7
+ # Abstract
8
+
9
+ Despite the rapid advance of unsupervised anomaly detection, existing methods require to train separate models for different objects. In this work, we present $U n i A D$ that accomplishes anomaly detection for multiple classes with a unified framework. Under such a challenging setting, popular reconstruction networks may fall into an “identical shortcut”, where both normal and anomalous samples can be well recovered, and hence fail to spot outliers. To tackle this obstacle, we make three improvements. First, we revisit the formulations of fully-connected layer, convolutional layer, as well as attention layer, and confirm the important role of query embedding (i.e., within attention layer) in preventing the network from learning the shortcut. We therefore come up with a layer-wise query decoder to help model the multi-class distribution. Second, we employ a neighbor masked attention module to further avoid the information leak from the input feature to the reconstructed output feature. Third, we propose a feature jittering strategy that urges the model to recover the correct message even with noisy inputs. We evaluate our algorithm on MVTec-AD and CIFAR-10 datasets, where we surpass the state-of-the-art alternatives by a sufficiently large margin. For example, when learning a unified model for 15 categories in MVTec-AD, we surpass the second competitor on the tasks of both anomaly detection (from $8 8 . 1 \%$ to $9 6 . 5 \%$ ) and anomaly localization (from $8 9 . 5 \%$ to $9 6 . 8 \%$ ). Code is available at https:// github.com/zhiyuanyou/UniAD.
10
+
11
+ # 1 Introduction
12
+
13
+ Anomaly detection has found an increasingly wide utilization in manufacturing defect detection [4], medical image analysis [17], and video surveillance [46]. Considering the highly diverse anomaly types, a common solution is to model the distribution of normal samples and then identify anomalous ones via finding outliers. It is therefore crucial to learn a compact boundary for normal data, as shown in Fig. 1a. For this purpose, existing methods [6, 11, 25, 27, 48, 49, 52] propose to train separate models for different classes of objects, like in Fig. 1c. However, such a one-class-one-model scheme could be memory-consuming especially along with the number of classes increasing, and also uncongenial to the scenarios where the normal samples manifest themselves in a large intra-class diversity (i.e., one object consists of various types).
14
+
15
+ In this work, we target a more practical task, which is to detect anomalies from different object classes with a unified framework. The task setting is illustrated in Fig. 1d, where the training data covers normal samples from a range of categories, and the learned model is asked to accomplish anomaly detection for all these categories without any fine-tuning. It is noteworthy that the categorical information (i.e., class label) is inaccessible at both the training and the inference stages, considerably easing the difficulty of data preparation. Nonetheless, solving such a task is fairly challenging. Recall that the rationale behind unsupervised anomaly detection is to model the distribution of normal data and find a compact decision boundary as in Fig. 1a. When it comes to the multi-class case, we expect the model to capture the distribution of all classes simultaneously such that they can share the same boundary as in Fig. 1b. But if we focus on a particular category, say the green one in Fig. 1b, all the samples from other categories should be considered as anomalies no matter whether they are normal (i.e., blue circles) or anomalous (i.e., blue triangles) themselves. From this perspective, how to accurately model the multi-class distribution becomes vital.
16
+
17
+ ![](images/b6232b853896a035f8a396234cfe67be2075d265ba691a7c3cd42f00cbab0b69.jpg)
18
+ Figure 1: Task setting of unified anomaly detection. (a) Existing methods learn separate decision boundaries for different object classes, while (b) our approach models the multi-class data distribution such that one boundary is enough to spot outliers regarding all categories. As a result, we escape from the conventional one-class-one-model paradigm in (c), and manage to accomplish anomaly detection for various classes with a unified framework in (d).
19
+
20
+ A widely used approach to learning the normal data distribution draws support from image (or feature) reconstruction [2, 5, 26, 39, 51], which assumes that a well-trained model always produces normal samples regardless of the defects within the inputs. In this way, there will be large reconstruction errors for anomalous samples, making them distinguishable from the normal ones. However, we find that popular reconstruction networks suggest unsatisfying performance on the challenging task studied in this work. They typically fall into an “identity shortcut”, which appears as returning a direct copy of the input disregarding its content.1 As a result, even anomalous samples can be well recovered with the learned model and hence become hard to detect. Moreover, under the unified case, where the distribution of normal data is more complex, the “identical shortcut” problem is magnified. Intuitively, to learn a unified model that can reconstruct all kinds of objects, it requires the model to work extremely hard to learn the joint distribution. From this perspective, learning an “identical shortcut” appears as a far easier solution.
21
+
22
+ To address this issue, we carefully tailor a feature reconstruction framework that prevents the model from learning the shortcut. First, we revisit the formulations of fully-connected layer, convolutional layer, as well as attention layer used in neural networks, and observe that both fully-connected layer and convolutional layer face the risk of learning a trivial solution. This drawback is further amplified under the multi-class setting in that the normal data distribution becomes far more complex. Instead, the attention layer is sheltered from such a risk, benefiting from a learnable query embedding (see Sec. 3.1). Accordingly, we propose a layer-wise query decoder to intensify the use of query embedding. Second, we argue that the full attention (i.e., every feature point relates to each other) also contributes to the shortcut issue, because it offers the chance of directly copying the input to the output. To avoid the information leak, we employ a neighbor masked attention module, where a feature point relates to neither itself nor its neighbors. Third, inspired by Bengio et al. [3], we propose a feature jittering strategy, which requires the model to recover the source message even with noisy inputs. All these designs help the model escape from the “identity shortcut”, as shown in Fig. 2b. Extensive experiments on MVTec-AD [4] and CIFAR-10 [23] demonstrate the sufficient superiority of our approach, which we call $U n i A D$ , over existing alternatives under the unified task setting. For instance, when learning a single model for 15 categories in MVTec-AD, we achieve state-of-the-art performance on the tasks of both anomaly detection and anomaly localization, boosting the AUROC from $8 8 . 1 \%$ to $9 6 . 5 \%$ and from $8 9 . 5 \%$ to $9 6 . 8 \%$ , respectively.
23
+
24
+ # 2 Related work
25
+
26
+ Anomaly detection. 1) Classical approaches extend classical machine learning methods for one-class classification, such as one-class support vector machine (OC-SVM) [38] and support vector data description (SVDD) [35, 41]. Patch-level embedding [48], geometric transformation [18], and elastic weight consolidation [33] are incorporated for improvement. 2) Pseudo-anomaly converts anomaly detection to supervised learning, including classification [25, 32, 45], image denoising [52], and hypersphere segmentation [27]. However, these methods partly rely on how well proxy anomalies match real anomalies that are not known [13]. 3) Modeling then comparison assumes that the pre-trained network is capable of extracting discriminative features for anomaly detection [11, 34]. PaDiM [11] and MDND [34] extract pre-trained features to model normal distribution, then utilize a distance metric to measure the anomalies. Nevertheless, these methods need to memorize and model all normal features, thus are computationally expensive. 4) Knowledge distillation proposes that the student distilled by a teacher on normal samples could only extract normal features [6, 13, 37, 44, 45]. Recent works mainly focus on model ensemble [6], feature pyramid [37, 44], and reverse distillation [13].
27
+
28
+ Reconstruction-based anomaly detection. These methods rely on the hypothesis that reconstruction models trained on normal samples only succeed in normal regions, but fail in anomalous regions [5, 8, 26, 36, 49]. Early attempts include Auto-Encoder (AE) [5, 9], Variational Auto-Encoder (VAE) [22, 26], and Generative Adversarial Net (GAN) [2, 30, 36, 51]. However, these methods face the problem that the model could learn tricks that the anomalies are also restored well. Accordingly, researchers adopt different strategies to tackle this issue, such as adding instructional information (i.e., structural [53] or semantic [39, 46]), memory mechanism [19, 20, 29], iteration mechanism [12], image masking strategy [47], and pseudo-anomaly [9, 32]. Recently, DRAEM [52] first recovers the pseudo-anomaly disturbed normal images for representation, then utilizes a discriminative net to distinguish the anomalies, achieving excellent performance. However, DRAEM [52] ceases to be effective under the unified case. Moreover, there is still an important aspect that has not been well studied, i.e., what architecture is the best reconstruction model? In this paper, we first compare and analyze three popular architectures including MLP, CNN, and transformer. Then, accordingly, we base on the transformer and further design three improvements, which compose our UniAD.
29
+
30
+ Transformer in anomaly detection. Transformer [42] with attention mechanism, first proposed in natural language processing, has been successfully used in computer vision [7, 16]. Some attempts try to utilize transformer for anomaly detection. InTra [31] adopts transformer to recover the image by recovering all masked patches one by one. VT-ADL [28] and AnoVit [50] both apply transformer encoder to reconstruct images. However, these methods directly utilize vanilla transformer, and do not figure out why transformer brings improvement. In contrast, we confirm the efficacy of the query embedding to prevent the shortcut, and accordingly design a layer-wise query decoder. Also, to avoid the information leak of the full attention, we employ a neighbor masked attention module.
31
+
32
+ # 3 Method
33
+
34
+ # 3.1 Revisiting feature reconstruction for anomaly detection
35
+
36
+ In Fig. 2, following the feature reconstruction paradigm [39, 49], we build an MLP, a CNN, and a transformer (with query embedding) to reconstruct the features extracted by a pre-trained backbone. The reconstruction errors represent the anomaly possibility. The architectures of the three networks are given in Appendix. The metric is evaluated every 10 epochs. Note that the periodic evaluation is impractical since anomalies are not available during training. As shown in Fig. 2a, after a period of training, the performances of the three networks decrease severely with the losses going extremely small. We attribute this to the problem of “identical shortcut”, where both normal and anomalous regions can be well recovered, thus failing to spot anomalies. This speculation is verified by the visualization results in Fig. 2b (more results in Appendix). However, compared with MLP and CNN, the transformer suffers from a much smaller performance drop, indicating a slighter shortcut problem. This encourages us to analyze as follows.
37
+
38
+ We denote the features in a normal image as $\pmb { x } ^ { + } \in \mathbb { R } ^ { K \times C }$ , where $K$ is the feature number, $C$ is the channel dimension. The batch dimension is omitted for simplicity. Similarly, the features in an anomalous image are denoted as $\pmb { x } ^ { - } \in \mathbb { R } ^ { K \times C }$ . The reconstruction loss is chosen as the MSE loss.
39
+
40
+ ![](images/f359d145336a151f892f300a30f2f84bdfa6df11e6012b50907c0ea33940f5a3.jpg)
41
+ Figure 2: Comparison among MLP, CNN, transformer, and our UniAD on MVTec-AD [4]. (a) Training loss (blue) as well as the testing AUROC on anomaly detection (green) and localization (red). During the training of MLP, CNN, and transformer, the reconstruction error keeps going smaller on normal samples, but the performance on anomalies suffers from a severe drop after reaching the peak. This is caused by the model learning an “identical shortcut”, which tends to directly copy the input as the output regardless of whether it is normal or anomalous. (b) Visual explanation of the shortcut issue, where the anomalous samples can be well recovered and hence become hard to detect from normal ones. In contrast, UniAD overcomes such a problem and manages to reconstruct anomalies as normal samples. It is noteworthy that all models are learned for feature reconstruction and a separate decoder is employed to render images from features. This decoder is only used for visualization.
42
+
43
+ We provide a rough analysis using a simple 1-layer network as the reconstruction net, which is trained with ${ \pmb x } ^ { + }$ and tested to detect anomalous regions in ${ \pmb x } ^ { - }$ .
44
+
45
+ Fully-connected layer in MLP. Denote the weights and bias in this layer as $\pmb { w } \in \mathbb { R } ^ { C \times C } , \pmb { b } \in \mathbb { R } ^ { C }$ respectively, this layer can be represented as,
46
+
47
+ $$
48
+ \pmb { y } = \pmb { x } ^ { + } \pmb { w } + \pmb { b } \in \mathbb { R } ^ { K \times C } .
49
+ $$
50
+
51
+ With the MSE loss pushing $\textbf { { y } }$ to ${ \pmb x } ^ { + }$ , the model may take shortcut to regress $w \to I$ (identity matrix), $\mathbf b \to \mathbf 0$ . Ultimately, this model could also reconstruct ${ \pmb x } ^ { - }$ well, failing in anomaly detection.
52
+
53
+ Convolutional layer in CNN. A convolutional layer with $1 \times 1$ kernel is equivalent to a fullyconnected layer. Besides, An $n \times n$ $( n > 1 )$ ) kernel has more parameters and larger capacity, and can complete whatever $1 \times 1$ kernel can. Thus, this layer also has the chance to learn a shortcut.
54
+
55
+ Transformer with query embedding. In such a model, there is an attention layer with a learnable query embedding, $\mathbf { \bar { q } } \in \mathbb { R } ^ { \mathbf { \bar { K } } \times C }$ . When using this layer as the reconstruction model, it is denoted as,
56
+
57
+ $$
58
+ { \pmb y } = \mathrm { s o f t m a x } ( { \pmb q } ( { \pmb x } ^ { + } ) ^ { T } / \sqrt { C } ) { \pmb x } ^ { + } \in \mathbb { R } ^ { K \times C } .
59
+ $$
60
+
61
+ To push $\textbf { { y } }$ to ${ \pmb x } ^ { + }$ , the attention map, softmax $( \pmb q ( \pmb x ^ { + } ) ^ { T } / \sqrt { C } )$ , should approximate $\pmb { I }$ (identity matrix), so $\pmb q$ must be highly related to ${ \pmb x } ^ { + }$ . Considering that $\pmb q$ in the trained model is relevant to normal samples, the model could not reconstruct ${ \pmb x } ^ { - }$ well. The ablation study in Sec. 4.6 shows that without the query embedding, the performance of transformer drops dramatically by $1 8 . 1 \%$ and $1 3 . 4 \%$ in anomaly detection and localization, respectively. Thus the query embedding is of vital significance to model the normal distribution.
62
+
63
+ However, transformer still suffers from the shortcut problem, which inspires our three improvements. 1) According to that the query embedding can prevent reconstructing anomalies, we design a Layerwise Query Decoder (LQD) by adding the query embedding in each decoder layer rather than only the first layer in vanilla transformer. 2) We suspect that the full attention increases the possibility of the shortcut. Since one token could see itself and its neighbor regions, it is easy to reconstruct by simply copying. Thus we mask the neighbor tokens when calculating the attention map, called Neighbor Masked Attention (NMA). 3) We employ a Feature Jittering (FJ) strategy to disturb the input features, leading the model to learn normal distribution from denoising. Benefiting from these designs, our UniAD achieves satisfying performance, as illustrated in Fig. 2.
64
+
65
+ Relation between the “identical shortcut” problem and the unified case. In Fig. 2a, we aim to visualize the “identical shortcut” problem, where the loss becomes smaller yet the performance drops.
66
+
67
+ ![](images/855a91070ef894d03f297ec342fc74d6da14d6c832d1b9fae74b2b5c5c132187.jpg)
68
+ Figure 3: Framework of UniAD, consisting of a Neighbor Masked Encoder (NME) and a Layer-wise Query Decoder (LQD). Each layer in LQD employs a learnable query embedding to help model the complex training data distribution. The full attention in transformer is replaced by neighbor masked attention to avoid the information leak from the input to the output. The feature jittering strategy encourages the model to recover the correct message with noisy inputs. All the three improvements assist the model against learning the “identical shortcut” (see Sec. 3.1 and Fig. 2 for details).
69
+
70
+ ![](images/9f58a091d2fbbebc9f5f5e64eaa929c479d4670d2e4b40ad48e306edf6bab81f.jpg)
71
+ Figure 4: Comparison between the unified case and the separate case on the training curves of MLP. In the separate case, the curves are obtained by averaging all categories. Compared with the separate case, the unified case has a smaller reconstruction error but much worse performance, indicating a severer “identical shortcut” problem.
72
+
73
+ ![](images/35911b53aeeb2ecbe0d34d45c19e02807f12435599942b5c722a940a406f0045.jpg)
74
+ Figure 5: Illustration of neighbor masked attention, where a feature point relates to neither itself nor its neighbors.
75
+
76
+ We conduct the same experiment under the separate case on MLP. As shown in Fig. 4, the accuracy (green for detection and red for localization) keeps growing up along with the loss (blue) getting smaller. This helps reveal the relation between the “identical shortcut” problem and the unified case, which is that the unified case is more challenging and hence magnifies the “identical shortcut” problem. Therefore, since our approach is specially designed to solve the “identical shortcut” problem, our method can be effective in the unified case.
77
+
78
+ # 3.2 Improving feature reconstruction for unified anomaly detection
79
+
80
+ Overview. As shown in Fig. 3, our UniAD is composed of a Neighbor Masked Encoder (NME) and a Layer-wise Query Decoder (LQD). Firstly, the feature tokens extracted by a fixed pre-trained backbone are further integrated by NME to derive the encoder embeddings. Then, in each layer of LQD, a learnable query embedding is successively fused with the encoder embeddings and the outputs of the previous layer (self-fusion for the first layer). The feature fusion is completed by the Neighbor Masked Attention (NMA). The final outputs of LQD are viewed as the reconstructed features. Also, we propose a Feature Jittering (FJ) strategy to add perturbations to the input features, leading the model to learn normal distribution from the denoising task. Finally, the results of anomaly localization and detection are obtained through the reconstruction differences.
81
+
82
+ Neighbor masked attention. We suspect that the full attention in vanilla transformer [42] contributes to the “identical shortcut”. In full attention, one token is permitted to see itself, so it will be easy to reconstruct by simply copying. Moreover, considering that the feature tokens are extracted by a CNN backbone, the neighbor tokens must share lots of similarities. Therefore, we propose to mask the neighbor tokens when calculating the attention map, called Neighbor Masked Attention (NMA). Note that the neighbor region is defined in the 2D space, as shown in Fig. 5.
83
+
84
+ Neighbor masked encoder. The encoder follows the standard architecture in vanilla transformer. Each layer consists of an attention module and a Feed-Forward Network (FFN). However, the full attention is replaced by our proposed NMA to prevent the information leak.
85
+
86
+ Layer-wise query decoder. It is analyzed in Sec. 3.1 that the query embedding could help prevent reconstructing anomalies well. However, there is only one query embedding in the vanilla transformer. Therefore, we design a Layer-wise Query Decoder (LQD) to intensify the use of query embedding, as shown in Fig. 3. Specifically, in each layer of LQD, a learnable query embedding is first fused with the encoder embeddings, then integrated with the outputs of the previous layer (self-integration for the first layer). The feature fusion is implemented by NMA. Following the vanilla transformer, a 2-layer FFN is applied to handle these fused tokens, and the residual connection is utilized to facilitate the training. The final outputs of LQD serve as the reconstructed features.
87
+
88
+ Feature jittering. Inspired by Denoising Auto-Encoder (DAE) [3, 43], we add perturbations to feature tokens, guiding the model to learn knowledge of normal samples by the denoising task. Specifically, for a feature token, $\pmb { f } _ { t o k } \in \mathbb { R } ^ { C }$ , we sample the disturbance $D$ from a Gaussian distribution,
89
+
90
+ $$
91
+ D \sim N ( \mu = 0 , \sigma ^ { 2 } = ( \alpha \frac { | | \mathbf { f } _ { t o k } | | _ { 2 } } { C } ) ^ { 2 } ) ,
92
+ $$
93
+
94
+ where $\alpha$ is the jittering scale to control the noisy degree. Also, the sampled disturbance is added to $f _ { t o k }$ with a fixed jittering probability, $p$ .
95
+
96
+ # 3.3 Implementation details
97
+
98
+ Feature extraction. We adopt a fixed EfficientNet-b4 [40] pre-trained on ImageNet [14] as the feature extractor. The features from stage-1 to stage-4 are selected. Here the stage means the combination of blocks that have the same size of feature maps. Then these features are resized to the same size, and concatenated along channel dimension to form a feature map, $\mathbf { \Delta } f _ { o r g } \in \mathbb { R } ^ { C _ { o r g } \times H \times W }$ .
99
+
100
+ Feature reconstruction. The feature map, $f _ { o r g }$ , is first tokenized to $H \times W$ feature tokens, followed by a linear projection to reduce $C _ { o r g }$ to a smaller channel, $C$ . Then these tokens are processed by NME and LQD. The learnable position embeddings [15, 16] are added in attention modules to inform the spatial information. Afterward, another linear projection is used to recover the channel from $C$ to $C _ { o r g }$ . After reshape, the reconstructed feature map, $\mathbf { \bar { f } } _ { r e c } \in \mathbb { R } ^ { C _ { o r g } \times H \times W }$ , is finally obtained.
101
+
102
+ Objective function. Our model is trained with the MSE loss as,
103
+
104
+ $$
105
+ \mathcal { L } = \frac { 1 } { H \times W } | | \mathbf { f } _ { o r g } - \mathbf { f } _ { r e c } | | _ { 2 } ^ { 2 } .
106
+ $$
107
+
108
+ Inference for anomaly localization. The result of anomaly localization is an anomaly score map, which assigns an anomaly score for each pixel. Specifically, the anomaly score map, $s$ , is calculated as the L2 norm of the reconstruction differences as,
109
+
110
+ $$
111
+ \pmb { s } = | | \pmb { f } _ { o r g } - \pmb { f } _ { r e c } | | _ { 2 } \in \mathbb { R } ^ { H \times W } .
112
+ $$
113
+
114
+ Then $\pmb { s }$ is up-sampled to the image size with bi-linear interpolation to obtain the localization results.
115
+
116
+ Inference for anomaly detection. Anomaly detection aims to detect whether an image contains anomalous regions. We transform the anomaly score map, $\pmb { s }$ , to the anomaly score of the image by taking the maximum value of the averagely pooled $\pmb { s }$ .
117
+
118
+ # 4 Experiment
119
+
120
+ # 4.1 Datasets and metrics
121
+
122
+ MVTec-AD [4] is a comprehensive, multi-object, multi-defect industrial anomaly detection dataset with 15 classes. For each anomalous sample in the test set, the ground-truth includes both image label and anomaly segmentation. In the existing literature, only the separate case is researched. In this paper, we introduce the unified case, where only one model is used to handle all categories.
123
+
124
+ Table 1: Anomaly detection results with AUROC metric on MVTec-AD [4]. All methods are evaluated under the unified / separate case. In the unified case, the learned model is applied to detect anomalies for all categories without fine-tuning.
125
+
126
+ <table><tr><td colspan="2">Category</td><td>US [6]</td><td>PSVDD[48] PaDiM[11] CutPaste [25] MKD [37] DRAEM [52]]</td><td></td><td></td><td></td><td></td><td>Ours</td></tr><tr><td rowspan="10">Object</td><td>Bottle Cable</td><td>184.0/ 99.0</td><td>85.5/98.6</td><td>97.9 / 99.9</td><td>67.9/98.2</td><td>98.7/99.4</td><td>97.5/99.2</td><td>99.7 ± 0.04 /100</td></tr><tr><td></td><td>60.0 / 86.2</td><td>64.4 /90.3</td><td>70.9 / 92.7</td><td>69.2 / 81.2</td><td>78.2 / 89.2</td><td>57.8 /91.8</td><td>95.2 ± 0.84 / 97.6</td></tr><tr><td>Capsule</td><td>57.6/ 86.1</td><td>61.3 / 76.7</td><td>73.4 / 91.3</td><td>63.0 / 98.2</td><td>68.3 / 80.5</td><td>65.3 / 98.5</td><td>86.9 ± 0.73 / 85.3</td></tr><tr><td>Hazelnut</td><td>95.8/ 93.1</td><td>83.9 / 92.0</td><td>85.5/92.0</td><td>80.9/ 98.3</td><td>97.1/98.4</td><td>93.7/100</td><td>99.8 ± 0.10 / 99.9</td></tr><tr><td>Metal Nut</td><td>62.7/ 82.0</td><td>80.9 /94.0</td><td>88.0 / 98.7</td><td>60.0 / 99.9</td><td>64.9 / 73.6</td><td>72.8 /98.7</td><td>99.2 ± 0.09 / 99.0</td></tr><tr><td>Pill</td><td>56.1 / 87.9</td><td>89.4 / 86.1</td><td>68.8 / 93.3</td><td>71.4 / 94.9</td><td>79.7 / 82.7</td><td>82.2 /98.9</td><td>93.7 ± 0.65 / 88.3</td></tr><tr><td>Screw</td><td>66.9 / 54.9</td><td>80.9 / 81.3</td><td>56.9 / 85.8</td><td>85.2/88.7</td><td>75.6 /83.3</td><td>92.0 / 93.9</td><td>87.5 ± 0.57 / 91.9</td></tr><tr><td>Toothbrush</td><td>57.8 / 95.3</td><td>99.4 /100</td><td>95.3 / 96.1</td><td>63.9 / 99.4</td><td>75.3 / 92.2</td><td>90.6 /100</td><td>94.2 ± 0.20 /95.0</td></tr><tr><td>Transistor</td><td>61.0 / 81.8</td><td>77.5 / 91.5</td><td>86.6 /97.4</td><td>57.9 / 96.1</td><td>73.4 /85.6</td><td>74.8 /93.1</td><td>99.8 ± 0.09 /100</td></tr><tr><td>Zipper</td><td>78.6 /91.9</td><td>77.8 / 97.9</td><td>79.7 / 90.3</td><td>93.5 / 99.9</td><td>87.4 / 93.2</td><td>98.8 / 100</td><td>95.8 ± 0.51/ 96.7</td></tr><tr><td rowspan="5">Texture</td><td>Carpet</td><td>86.6 / 91.6</td><td>63.3 / 92.9</td><td>93.8/ 99.8</td><td>93.6 /93.9</td><td>69.8 / 79.3</td><td>98.0 /97.0</td><td>99.8 ± 0.02 / 99.9</td></tr><tr><td>Grid</td><td>69.2/ 81.0</td><td>66.0 /94.6</td><td>73.9 / 96.7</td><td>93.2/100</td><td>83.8 /78.0</td><td>99.3 / 99.9</td><td>98.2±0.26/98.5</td></tr><tr><td>Leather</td><td>97.2 / 88.2</td><td>60.8 / 90.9</td><td>99.9 /100</td><td>93.4/100</td><td>93.6 / 95.1</td><td>98.7 /100</td><td>100 ± 0.00 /100</td></tr><tr><td>Tile</td><td>93.7 / 99.1</td><td>88.3 /97.8</td><td>93.3 /98.1</td><td>88.6 /94.6</td><td>89.5 /91.6</td><td>99.8 / 99.6</td><td>99.3 ± 0.14 / 99.0</td></tr><tr><td>Wood</td><td>90.6 / 97.7</td><td>72.1/ 96.5</td><td>98.4 /99.2</td><td>80.4 / 99.1</td><td>93.4 / 94.3</td><td>99.8 / 99.1</td><td>98.6 ± 0.08 / 97.9</td></tr><tr><td colspan="2">Mean</td><td>74.5 / 87.7</td><td>76.8 /92.1</td><td>84.2 /95.5</td><td>77.5 / 96.1</td><td>81.9 / 87.8</td><td>88.1/98.0</td><td>96.5±0.08/96.6</td></tr></table>
127
+
128
+ CIFAR-10 [23] is a classical image classification dataset with 10 categories. Existing methods [6, 24, 37] evaluate CIFAR-10 mainly in the one-versus-many setting, where one class is viewed as normal samples, and others serve as anomalies. Semantic AD [1, 10] proposes a many-versus-one setting, treating one class as anomalous and the remaining classes as normal. Different from both, we propose a unified case (many-versus-many setting), which is detailed in Sec. 4.4.
129
+
130
+ Metrics. Following prior works [4, 6, 52], the Area Under the Receiver Operating Curve (AUROC) is used as the evaluation metric for anomaly detection.
131
+
132
+ # 4.2 Anomaly detection on MVTec-AD
133
+
134
+ Setup. Anomaly detection aims to detect whether an image contains anomalous regions. The anomaly detection performance is evaluated on MVTec-AD [4]. The image size is selected as $2 2 4 \times 2 2 4$ , and the size for resizing feature maps is set as $1 4 \times 1 4$ . The feature maps from stage-1 to stage-4 of EfficientNet-b4 [40] are resized and concatenated together to form a 272-channel feature map. The reduced channel dimension is set as 256. AdamW optimizer [21] with weight decay $1 \times 1 0 ^ { - 4 }$ is used. Our model is trained for 1000 epochs on 8 GPUs (NVIDIA Tesla V100 16GB) with batch size 64. The learning rate is $1 \times 1 0 ^ { - 4 }$ initially, and dropped by 0.1 after 800 epochs. The layer numbers of the encoder and decoder are both 4. The neighbor size, jittering scale, and jittering probability are set as $7 \times 7$ , 20, and 1, respectively. The evaluation is run with 5 random seeds. In both the separate case and the unified case, the reconstruction models are trained from the scratch.
135
+
136
+ Baselines. Our approach is compared with baselines including: US [6], PSVDD [48], PaDiM [11], CutPaste [25], MKD [37], and DRAEM [52]. Under the separate case, the baselines’ metric is reported in their papers except the metric of US borrowed from [52]. Under the unified case, US, PSVDD, PaDiM, CutPaste, MKD, and DRAEM are run with the publicly available implementations.
137
+
138
+ Quantitative results of anomaly detection on MVTec-AD [4] are shown in Tab. 1. Though all baselines achieve excellent performances under the separate case, their performances drop dramatically under the unified case. The previous SOTA, DRAEM, a reconstruction-based method trained by pseudo-anomaly, suffers from a drop of near $10 \%$ . For another strong baseline, CutPaste, a pseudo-anomaly approach, the drop is as large as $1 8 . 6 \%$ . However, our UniAD has almost no performance drop from the separate case $( 9 6 . 6 \% )$ to the unified case $( 9 6 . 5 \% )$ . Moreover, we beat the best competitor, DRAEM, by a dramatically large margin $( 8 . 4 \% )$ , demonstrating our superiority.
139
+
140
+ Table 2: Anomaly localization results with AUROC metric on MVTec-AD [4]. All methods are evaluated under the unified / separate case. In the unified case, the learned model is applied to detect anomalies for all categories without fine-tuning.
141
+
142
+ <table><tr><td colspan="2">Category Bottle</td><td>US [6]</td><td></td><td></td><td></td><td></td><td>PSVDD [48] PaDiM[11] FCDD [27] MKD [37] DRAEM[52]</td><td>Ours</td></tr><tr><td rowspan="6">Object</td><td rowspan="10">Cable Capsule Hazelnut Metal Nut Pill</td><td>67.9 /97.8 78.3 /91.9</td><td>86.7 /98.1 62.2 /96.8</td><td>96.1/ 98.2 81.0 /96.7</td><td>56.0 /97</td><td>91.8 / 96.3</td><td>87.6 / 99.1</td><td>[98.1 ± 0.04 / 98.1</td></tr><tr><td></td><td></td><td></td><td>64.1/90</td><td>89.3 /82.4</td><td>71.3 /94.7</td><td>97.3 ± 0.10 / 96.8</td></tr><tr><td>85.5 /96.8</td><td>83.1/95.8</td><td>96.9 /98.6</td><td>67.6 /93</td><td>88.3 / 95.9</td><td>50.5 / 94.3</td><td>98.5 ± 0.01 / 97.9</td></tr><tr><td>93.7 /98.2</td><td>97.4 /97.5</td><td>96.3 / 98.1</td><td>79.3 /95</td><td>91.2 /94.6</td><td>96.9 /99.7</td><td>98.1 ± 0.10 / 98.8</td></tr><tr><td>76.6/97.2</td><td>96.0 / 98.0</td><td>84.8 /97.3</td><td>57.5 /94</td><td>64.2 /86.4</td><td>62.2 /99.5</td><td>94.8 ± 0.09 / 95.7</td></tr><tr><td>80.3/96.5</td><td>96.5 / 95.1</td><td>87.7 /95.7</td><td>65.9 /81</td><td>69.7 / 89.6</td><td>94.4 /97.6</td><td>95.0 ± 0.16 / 95.1</td></tr><tr><td>Screw 90.8/97.4</td><td>74.3 /95.7</td><td>94.1/ 98.4</td><td>67.2/86</td><td>92.1/96.0</td><td>95.5 /97.6</td><td>98.3 ± 0.08 / 97.4</td></tr><tr><td>Toothbrush 86.9 / 97.9</td><td>98.0 /98.1</td><td>95.6 /98.8</td><td>60.8 /94</td><td>88.9 /96.1</td><td>97.7/98.1</td><td>98.4 ± 0.03 / 97.8</td></tr><tr><td>Transistor 68.3/ 73.7</td><td>78.5/97.0</td><td>92.3/97.6</td><td>54.2/88</td><td>71.7 /76.5</td><td>64.5 /90.9</td><td>97.9 ± 0.19 / 98.7</td></tr><tr><td>Zipper 84.2/95.6</td><td>95.1 /95.1</td><td>94.8 / 98.4</td><td>63.0 /92</td><td>86.1/93.9</td><td>98.3 / 98.8</td><td>96.8 ± 0.24 / 96.0</td></tr><tr><td rowspan="4">Texture</td><td>Carpet Grid</td><td>88.7 /93.5 78.6 / 92.6</td><td>97.6 / 99.0</td><td>68.6/96</td><td>95.5 / 95.6</td><td>98.6 / 95.5</td><td>98.5±0.01/98.0</td></tr><tr><td>Leather</td><td>64.5 /89.9</td><td>70.8/96.2 71.0 / 97.1</td><td>65.8 /91</td><td>82.3 /91.8</td><td>98.7 / 99.7</td><td>96.5 ± 0.04 / 94.6</td></tr><tr><td>Tile</td><td>95.4 /97.8 93.5 / 97.4</td><td>84.8 /99.0</td><td>66.3 /98</td><td>96.7 /98.1</td><td>97.3 /98.6</td><td>98.8 ± 0.03 / 98.3</td></tr><tr><td>Wood</td><td>82.7 /92.5 92.1 / 91.4</td><td>80.5 /94.1</td><td>59.3 /91</td><td>85.3 /82.8</td><td>98.0 / 99.2</td><td>91.8 ± 0.10 / 91.8</td></tr><tr><td colspan="2">Mean</td><td>83.3 / 92.1 81.8 /93.9</td><td>80.7 /90.8 85.6/95.7</td><td>89.1 /94.1 89.5 / 97.4</td><td>53.3 /88 63.3/92</td><td>80.5 /84.8 84.9 /90.7</td><td>96.0 / 96.4 87.2 / 97.3</td><td>93.2 ± 0.08 / 93.4 [96.8 ± 0.02 / 96.6</td></tr><tr><td colspan="8">Normal Anomaly Recon GT Pred Normal Anomaly Recon 9 (b)</td><td>GT Pred</td></tr><tr><td colspan="2">(a)</td><td colspan="6">800</td><td></td></tr><tr><td colspan="2">(c)</td><td colspan="6"></td></tr></table>
143
+
144
+ # 4.3 Anomaly localization on MVTec-AD
145
+
146
+ Setup and baselines. Anomaly localization aims to localize anomalous regions in an anomalous image. MVTec-AD [4] is chosen as the benchmark dataset. The setup is the same as that in Sec. 4.2. Besides the competitors in Sec. 4.2, FCDD [27] is included, whose metric under the separate case is reported in its paper. Under the unified case, we run FCDD with the implementation: FCDD.
147
+
148
+ Quantitative results of anomaly localization on MVTec-AD [4] are reported in Tab. 2. Similar to Sec. 4.2, switching from the separate case to the unified case, the performance of all competitors drops significantly. For example, the performance of US, an important distillation-based baseline, decreases by $1 2 . 1 \%$ . FCDD, a pseudo-anomaly approach, suffers from a dramatic drop of $2 8 . 7 \%$ , reflecting the pseudo-anomaly is not suitable for the unified case. However, our UniAD even gains a slight improvement from the separate case $( 9 6 . 6 \% )$ to the unified case $( 9 6 . 8 \% )$ , proving the suitability of our UniAD for the unified case. Moreover, we significantly surpass the strongest baseline, PaDiM, by $7 . 3 \%$ . This significant improvement reflects the effectiveness of our model.
149
+
150
+ Qualitative results for anomaly localization on MVTec-AD [4] are illustrated in Fig. 6. For both global (Fig. 6a) and local (Fig. 6b) structural anomalies, both scattered texture perturbations (Fig. 6c) and multiple texture scratches (Fig. 6d), our method could successfully reconstruct anomalies to their corresponding normal samples, then accurately localize anomalous regions through reconstruction differences. More qualitative results are given in Appendix.
151
+
152
+ # 4.4 Anomaly detection on CIFAR-10
153
+
154
+ Setup. To further verify the effectiveness of our UniAD, we extend CIFAR-10 [23] to the unified case, which consists of four combinations. For each combination, five categories together serve as normal samples, while other categories are viewed as anomalies. The class indices of the four combinations are $\lbrace 0 1 2 3 4 \rbrace$ , $\{ 5 6 7 8 9 \}$ , $\{ 0 2 4 6 8 \}$ , $\lbrace 1 3 5 7 9 \rbrace$ . Here, $\lbrace 0 1 2 3 4 \rbrace$ means the normal samples include images from class $0 , 1 , 2 , 3 , 4$ , and similar for others. Note that the class index is obtained by sorting the class names of 10 classes. The setup of the model is detailed in Appendix.
155
+
156
+ Table 3: Anomaly detection results with AUROC metric on CIFAR-10 [23] under the unified case. Here, $\lbrace 0 1 2 3 4 \rbrace$ means samples from class $0 , 1 , 2 , 3 , 4$ are borrowed as the normal ones.
157
+
158
+ <table><tr><td>Normal Indices</td><td>US [6]</td><td>FCDD [27]</td><td>FCDD+OE [27]</td><td>PANDA [33]</td><td>MKD [37]</td><td>Ours</td></tr><tr><td>{01234}</td><td>51.3</td><td>55.0</td><td>71.8</td><td>66.6</td><td>64.2</td><td>84.4 ± 0.02</td></tr><tr><td>{56789}</td><td>51.3</td><td>50.3</td><td>73.7</td><td>73.2</td><td>69.3</td><td>80.9 ± 0.02</td></tr><tr><td>{02468}</td><td>63.9</td><td>59.2</td><td>85.3</td><td>77.1</td><td>76.4</td><td>93.0 ± 0.03</td></tr><tr><td>{13579}</td><td>56.8</td><td>58.5</td><td>85.0</td><td>72.9</td><td>78.7</td><td>90.6 ± 0.09</td></tr><tr><td>Mean</td><td>55.9</td><td>55.8</td><td>78.9</td><td>72.4</td><td>72.1</td><td>87.2 ± 0.03</td></tr></table>
159
+
160
+ Table 4: Performance comparison and architecture comparison between UniAD and transformerbased competitors on MVTec-AD [4]. All methods are evaluated under the unified / separate case.
161
+
162
+ <table><tr><td>Method</td><td>Det.</td><td>Loc.</td><td>1 query</td><td>Layer-wise query</td></tr><tr><td>InTra [31]</td><td>65.3/95.0</td><td>70.6 /96.6</td><td>X</td><td>X</td></tr><tr><td>VT-ADL [28]</td><td>55.4/ 78.7</td><td>64.4/ 82.0</td><td>X</td><td>×</td></tr><tr><td>AnoVit [50]</td><td>69.6/78</td><td>68.4/ 83</td><td>X</td><td>×</td></tr><tr><td>Ours (baseline)</td><td>87.6 / 94.7</td><td>92.8 / 95.8</td><td>√</td><td></td></tr><tr><td>Ours</td><td>96.5 / 96.6</td><td>96.8 / 96.6</td><td>×</td><td>X</td></tr></table>
163
+
164
+ Baselines. US [6], FCDD [27], $\mathrm { F C D D + O E }$ [27], PANDA [33], and MKD [37] serve as competitors.
165
+ US, FCDD, FCDD+OE, PANDA, and MKD are run with the publicly available implementations.
166
+
167
+ Quantitative results of anomaly detection on CIFAR-10 [23] are shown in Tab. 3. When five classes together serve as normal samples, two recent baselines, US and FCDD, almost lose their ability to detect anomalies. When utilizing 10000 images sampled from CIFAR-100 [23] as auxiliary Outlier Exposure (OE), $\mathrm { F C D D + O E }$ improves the performance by a large margin. We still stably outperform FCDD $\mathsf { \Pi } + \mathsf { O E }$ by $8 . 3 \%$ without the help of OE, indicating the efficacy of our UniAD.
168
+
169
+ # 4.5 Comparison with transformer-based competitors
170
+
171
+ As described in Sec. 2, some attempts [31, 28, 50] also try to utilize transformer for anomaly detection. Here we compare our UniAD with existing transformer-based competitors on MVTec-AD [4]. Recall that, we choose transformer as the reconstruction model considering its great potential in preventing the model from learning the “identical shortcut” (refer to Sec. 3.1). Concretely, we find that the learnable query embedding is essential for avoiding such a shortcut but is seldom explored in existing transformer-based approaches. As shown in Tab. 4, after introducing even only one query embedding, our baseline already outperforms existing alternatives by a sufficiently large margin in the unified setting. Our proposed three components further improve our strong baseline. Recall that all three components are proposed to avoid the model from directly outputting the inputs.
172
+
173
+ # 4.6 Ablation studies
174
+
175
+ To verify the effectiveness of the proposed modules and the selection of hyperparameters, we implement extensive ablation studies on MVTec-AD [4] under the unified case.
176
+
177
+ Layer-wise query. Tab. 5a verifies our assertion that the query embedding is of vital significance. 1) Without query embedding, meaning the encoder embeddings are directly input to the decoder, the performance is the worst. 2) Adding only one query embedding to the first decoder layer (i.e., vanilla transformer [42]) promotes the performance dramatically by $1 8 . 1 \%$ and $1 3 . 4 \%$ in anomaly detection and localization, respectively. 3) With layer-wise query embedding in each decoder layer, image-level and pixel-level AUROC is further improved by $7 . 4 \%$ and $3 . 7 \%$ , respectively.
178
+
179
+ Layer number. We conduct experiments to investigate the influence of layer number, as shown in Tab. 5b. 1) No matter with which combination, our model outperforms vanilla transformer by a large margin, reflecting the effectiveness of our design. 2) The best performance is achieved with a moderate layer number: $4 { \mathrm { E n c } } + 4 { \mathrm { D e c } }$ . A larger layer number like 6Enc+6Dec does not bring further promotion, which may be because more layers are harder to train.
180
+
181
+ Table 5: Ablation studies with AUROC metric on MVTec-AD [4]. Default settings are in blue. (a) Layer-wise query, NMA, & FJ (b) Layer Number of Encoder & Decoder
182
+
183
+ <table><tr><td>w/o q.</td><td>1q</td><td>Layer-wise q.</td><td>NMA</td><td>FJ</td><td>Det.</td><td>Loc.</td><td colspan="2"></td><td>Vanilla [42]</td><td colspan="2">Loc.</td><td>Ours</td></tr><tr><td>√</td><td>-</td><td></td><td>=</td><td></td><td>69.5</td><td>79.4</td><td colspan="2">#Enc,#Dec</td><td colspan="2">Det.</td><td>Det.</td><td>Loc.</td></tr><tr><td></td><td>【</td><td></td><td></td><td></td><td>87.6</td><td>92.8</td><td colspan="2">4,0</td><td>69.8</td><td>79.2</td><td>94.9</td><td>96.0</td></tr><tr><td>=</td><td></td><td>√</td><td>=</td><td></td><td>95.0</td><td>96.5</td><td colspan="2">0,4</td><td>80.5</td><td>88.3</td><td>96.1</td><td>96.3</td></tr><tr><td></td><td></td><td>1</td><td>【</td><td></td><td>96.1</td><td>96.3</td><td colspan="2">2,2</td><td>84.7</td><td>90.6</td><td>95.1</td><td>96.0</td></tr><tr><td></td><td></td><td></td><td></td><td>!</td><td>95.0</td><td>95.8</td><td colspan="2">4,4</td><td>87.6</td><td>92.8</td><td>96.5</td><td>96.8</td></tr><tr><td>=</td><td>-</td><td>√</td><td>√</td><td>【</td><td>96.5</td><td>96.8</td><td colspan="2">6,6</td><td>86.1</td><td>91.9</td><td>96.5</td><td>96.7</td></tr><tr><td colspan="2">(c) Neighbor Size in NMA</td><td></td><td colspan="3">(d) Where to Add NMA</td><td colspan="3">(e) Jitter Scale α in FJ</td><td colspan="3">(f) Jitter Prob.</td><td>p inFJ</td></tr><tr><td>Size</td><td>Det.</td><td>Loc.</td><td>Place</td><td>Det.</td><td>Loc.</td><td>a</td><td>Det.</td><td>Loc.</td><td></td><td>p</td><td>Det.</td><td>Loc.</td></tr><tr><td>1×1</td><td>94.6</td><td>96.3</td><td>Enc</td><td>95.8</td><td>96.3</td><td></td><td>5 96.1</td><td>96.7</td><td></td><td>0.25</td><td>95.6</td><td>96.5</td></tr><tr><td>5×5</td><td>96.4</td><td>96.8</td><td>Enc+Dec1</td><td>96.4</td><td>96.8</td><td></td><td>10 96.4</td><td>96.7</td><td></td><td>0.50</td><td>95.8</td><td>96.7</td></tr><tr><td>7x7</td><td>96.5</td><td>96.8</td><td>Enc+Dec2</td><td>96.5</td><td>96.7</td><td></td><td>20 96.5</td><td>96.8</td><td></td><td>0.75</td><td>96.3</td><td>96.7</td></tr><tr><td>9×9</td><td>96.3</td><td>96.7</td><td>All </td><td>96.5</td><td>96.8</td><td></td><td>30 95.7</td><td>96.6</td><td></td><td>1</td><td>96.5</td><td>96.8</td></tr></table>
184
+
185
+ Neighbor masked attention. 1) The effectiveness of NMA is proven in Tab. 5a. Under the case of one query embedding, adding NMA brings promotion by $8 . 5 \%$ for detection and $3 . 5 \%$ for localization. 2) The neighbor size of NMA is selected in Tab. 5c. $1 \times 1$ neighbor size is the worst, because $1 \times 1$ is too small to prevent the information leak, thus the recovery could be completed by copying neighbor regions. A larger neighbor size $( \geq 5 { \times } 5 )$ is obviously much better, and the best one is selected as $7 \times 7$ . 3) We also study the place to add NMA in Tab. 5d. Only adding NMA in the encoder (Enc) is not enough. The performance could be stably improved when further adding NMA in the first or second attention in the decoder $\mathbf { E n c + D e c l }$ , $_ \mathrm { E n c + D e c } 2$ ) or both (All). This reflects that the full attention of the decoder also contributes to the information leak.
186
+
187
+ Feature jittering. 1) Tab. 5a confirms the efficacy of FJ. With one query embedding as the baseline, introducing FJ could bring an increase of $7 . 4 \%$ for detection and $3 . 0 \%$ for localization, respectively. 2) According to Tab. 5e, the jittering scale, $\alpha$ , is chosen as 20. A larger $\alpha$ (i.e., 30) disturbs the feature too much, degrading the results. 3) In Tab. 5f, the jittering probability, $p$ , is studied. In essence, the task would be a denoising task with feature jittering, and be a reconstruction task without feature jittering. The results show that the full denoising task (i.e., $p = 1$ ) is the best.
188
+
189
+ # 5 Conclusion
190
+
191
+ In this work, we propose UniAD that unifies anomaly detection regarding multiple classes. For such a challenging task, we assist the model against learning an “identical shortcut” with three improvements. First, we confirm the effectiveness of the learnable query embedding and carefully tailor a layer-wise query decoder to help model the complex distribution of multi-class data. Second, we come up with a neighbor masked attention module to avoid the information leak from the input to the output. Third, we propose feature jittering that helps the model less sensitive to the input perturbations. Under the unified task setting, our method achieves state-of-the-art performance on MVTec-AD and CIFAR-10 datasets, significantly outperforming existing alternatives.
192
+
193
+ Discussion. In this work, different kinds of objects are handled without being distinguished. We have not used the category labels that may help the model better fit multi-class data. How to incorporate the unified model with category labels should be further studied. In practical uses, normal samples are not as consistent as those in MVTec-AD, often manifest themselves in some diversity. Our UniAD could handle all 15 categories in MVTec-AD, hence would be more suitable for real scenes. However, anomaly detection may be used for video surveillance, which may infringe personal privacy.
194
+
195
+ # Acknowledgments and Disclosure of Funding
196
+
197
+ Acknowledgement. This work is sponsored by the National Key Research and Development Program of China (2021YFB1716000) and National Natural Science Foundation of China (62176152).
198
+
199
+ References
200
+ [1] F. Ahmed and A. Courville. Detecting semantic anomalies. In Assoc. Adv. Artif. Intell., 2020.
201
+ [2] S. Akcay, A. Atapour-Abarghouei, and T. P. Breckon. GANomaly: Semi-supervised anomaly detection via adversarial training. In Asian Conf. Comput. Vis., 2018.
202
+ [3] Y. Bengio, L. Yao, G. Alain, and P. Vincent. Generalized denoising auto-encoders as generative models. In Adv. Neural Inform. Process. Syst., 2013.
203
+ [4] P. Bergmann, M. Fauser, D. Sattlegger, and C. Steger. MVTec AD–A comprehensive real-world dataset for unsupervised anomaly detection. In IEEE Conf. Comput. Vis. Pattern Recog., 2019.
204
+ [5] P. Bergmann, S. Löwe, M. Fauser, D. Sattlegger, and C. Steger. Improving unsupervised defect segmentation by applying structural similarity to autoencoders. In International Joint Conference on Computer Vision, Imaging and Computer Graphics Theory and Applications (VISIGRAPP), 2019.
205
+ [6] P. Bergmann, M. Fauser, D. Sattlegger, and C. Steger. Uninformed students: Student-teacher anomaly detection with discriminative latent embeddings. In IEEE Conf. Comput. Vis. Pattern Recog., 2020.
206
+ [7] N. Carion, F. Massa, G. Synnaeve, N. Usunier, A. Kirillov, and S. Zagoruyko. End-to-end object detection with transformers. In Eur. Conf. Comput. Vis., 2020.
207
+ [8] L. Chen, Z. You, N. Zhang, J. Xi, and X. Le. UTRAD: Anomaly detection and localization with Utransformer. Neural Networks, 2022.
208
+ [9] A.-S. Collin and C. De Vleeschouwer. Improved anomaly detection by training an autoencoder with skip connections on images corrupted with stain-shaped noise. In Int. Conf. Pattern Recog., 2021.
209
+ [10] L. Deecke, L. Ruff, R. A. Vandermeulen, and H. Bilen. Transfer-based semantic anomaly detection. In Int. Conf. Mach. Learn., 2021.
210
+ [11] T. Defard, A. Setkov, A. Loesch, and R. Audigier. PaDim: A patch distribution modeling framework for anomaly detection and localization. In Int. Conf. Pattern Recog., 2021.
211
+ [12] D. Dehaene, O. Frigo, S. Combrexelle, and P. Eline. Iterative energy-based projection on a normal data manifold for anomaly localization. In Int. Conf. Learn. Represent., 2019.
212
+ [13] H. Deng and X. Li. Anomaly detection via reverse distillation from one-class embedding. In IEEE Conf. Comput. Vis. Pattern Recog., 2022.
213
+ [14] J. Deng, W. Dong, R. Socher, L.-J. Li, K. Li, and L. Fei-Fei. ImageNet: A large-scale hierarchical image database. In IEEE Conf. Comput. Vis. Pattern Recog., 2009.
214
+ [15] J. Devlin, M.-W. Chang, K. Lee, and K. Toutanova. Bert: Pre-training of deep bidirectional transformers for language understanding. arXiv preprint arXiv:1810.04805, 2018.
215
+ [16] A. Dosovitskiy, L. Beyer, A. Kolesnikov, D. Weissenborn, X. Zhai, T. Unterthiner, M. Dehghani, M. Minderer, G. Heigold, S. Gelly, et al. An image is worth 16x16 words: Transformers for image recognition at scale. In Int. Conf. Learn. Represent., 2021.
216
+ [17] T. Fernando, H. Gammulle, S. Denman, S. Sridharan, and C. Fookes. Deep learning for medical anomaly detection–a survey. ACM Computing Surveys (CSUR), 2021.
217
+ [18] I. Golan and R. El-Yaniv. Deep anomaly detection using geometric transformations. In Adv. Neural Inform. Process. Syst., 2018.
218
+ [19] D. Gong, L. Liu, V. Le, B. Saha, M. R. Mansour, S. Venkatesh, and A. v. d. Hengel. Memorizing normality to detect anomaly: Memory-augmented deep autoencoder for unsupervised anomaly detection. In Int. Conf. Comput. Vis., 2019.
219
+ [20] J. Hou, Y. Zhang, Q. Zhong, D. Xie, S. Pu, and H. Zhou. Divide-and-assemble: Learning block-wise memory for unsupervised anomaly detection. In Int. Conf. Comput. Vis., 2021.
220
+ [21] L. Ilya and H. Frank. Decoupled weight decay regularization. In Int. Conf. Learn. Represent., 2019.
221
+ [22] D. P. Kingma and M. Welling. Auto-encoding variational bayes. arXiv preprint arXiv:1312.6114, 2013.
222
+ [23] A. Krizhevsky. Learning multiple layers of features from tiny images. Master’s thesis, University of Tront, 2009.
223
+ [24] G. Kwon, M. Prabhushankar, D. Temel, and G. AlRegib. Backpropagated gradient representations for anomaly detection. In Eur. Conf. Comput. Vis., 2020.
224
+ [25] C.-L. Li, K. Sohn, J. Yoon, and T. Pfister. CutPaste: Self-supervised learning for anomaly detection and localization. In IEEE Conf. Comput. Vis. Pattern Recog., 2021.
225
+ [26] W. Liu, R. Li, M. Zheng, S. Karanam, Z. Wu, B. Bhanu, R. J. Radke, and O. Camps. Towards visually explaining variational autoencoders. In IEEE Conf. Comput. Vis. Pattern Recog., 2020.
226
+ [27] P. Liznerski, L. Ruff, R. A. Vandermeulen, B. J. Franks, M. Kloft, and K.-R. Müller. Explainable deep one-class classification. In Int. Conf. Learn. Represent., 2021.
227
+ [28] P. Mishra, R. Verk, D. Fornasier, C. Piciarelli, and G. L. Foresti. VT-ADL: A vision transformer network for image anomaly detection and localization. In International Symposium on Industrial Electronics, 2021.
228
+ [29] H. Park, J. Noh, and B. Ham. Learning memory-guided normality for anomaly detection. In IEEE Conf. Comput. Vis. Pattern Recog., 2020.
229
+ [30] P. Perera, R. Nallapati, and B. Xiang. OCGAN: One-class novelty detection using GANs with constrained latent representations. In IEEE Conf. Comput. Vis. Pattern Recog., 2019.
230
+ [31] J. Pirnay and K. Chai. Inpainting transformer for anomaly detection. arXiv preprint arXiv:2104.13897, 2021.
231
+ [32] M. Pourreza, B. Mohammadi, M. Khaki, S. Bouindour, H. Snoussi, and M. Sabokrou. G2D: generate to detect anomaly. In IEEE Winter Conf. Appl. Comput. Vis., 2021.
232
+ [33] T. Reiss, N. Cohen, L. Bergman, and Y. Hoshen. Panda: Adapting pretrained features for anomaly detection and segmentation. In IEEE Conf. Comput. Vis. Pattern Recog., 2021.
233
+ [34] O. Rippel, P. Mertens, and D. Merhof. Modeling the distribution of normal data in pretrained deep features for anomaly detection. In Int. Conf. Pattern Recog., 2021.
234
+ [35] L. Ruff, R. Vandermeulen, N. Goernitz, L. Deecke, S. A. Siddiqui, A. Binder, E. Müller, and M. Kloft. Deep one-class classification. In Int. Conf. Mach. Learn., 2018.
235
+ [36] M. Sabokrou, M. Khalooei, M. Fathy, and E. Adeli. Adversarially learned one-class classifier for novelty detection. In IEEE Conf. Comput. Vis. Pattern Recog., 2018.
236
+ [37] M. Salehi, N. Sadjadi, S. Baselizadeh, M. H. Rohban, and H. R. Rabiee. Multiresolution knowledge distillation for anomaly detection. In IEEE Conf. Comput. Vis. Pattern Recog., 2021.
237
+ [38] B. Schölkopf, J. C. Platt, J. Shawe-Taylor, A. J. Smola, and R. C. Williamson. Estimating the support of a high-dimensional distribution. Neural Computation, 2001.
238
+ [39] Y. Shi, J. Yang, and Z. Qi. Unsupervised anomaly segmentation via deep feature reconstruction. Neurocomputing, 2021.
239
+ [40] M. Tan and Q. Le. EfficientNet: Rethinking model scaling for convolutional neural networks. In Int. Conf. Mach. Learn., 2019.
240
+ [41] D. M. Tax and R. P. Duin. Support vector data description. Machine Learning, 2004.
241
+ [42] A. Vaswani, N. Shazeer, N. Parmar, J. Uszkoreit, L. Jones, A. N. Gomez, Ł. Kaiser, and I. Polosukhin. Attention is all you need. In Adv. Neural Inform. Process. Syst., 2017.
242
+ [43] P. Vincent, H. Larochelle, Y. Bengio, and P.-A. Manzagol. Extracting and composing robust features with denoising autoencoders. In Int. Conf. Mach. Learn., 2008.
243
+ [44] G. Wang, S. Han, E. Ding, and D. Huang. Student-teacher feature pyramid matching for anomaly detection. Brit. Mach. Vis. Conf., 2021.
244
+ [45] S. Wang, L. Wu, L. Cui, and Y. Shen. Glancing at the patch: Anomaly localization with global and local feature comparison. In IEEE Conf. Comput. Vis. Pattern Recog., 2021.
245
+ [46] Y. Xia, Y. Zhang, F. Liu, W. Shen, and A. L. Yuille. Synthesize then compare: Detecting failures and anomalies for semantic segmentation. In Eur. Conf. Comput. Vis., 2020.
246
+ [47] X. Yan, H. Zhang, X. Xu, X. Hu, and P.-A. Heng. Learning semantic context from normal samples for unsupervised anomaly detection. In Assoc. Adv. Artif. Intell., 2021.
247
+ [48] J. Yi and S. Yoon. Patch SVDD: Patch-level SVDD for anomaly detection and segmentation. In Asian Conf. Comput. Vis., 2020.
248
+ [49] Z. You, K. Yang, W. Luo, L. Cui, Y. Zheng, and X. Le. ADTR: Anomaly detection transformer with feature reconstruction. arXiv preprint arXiv:2209.01816, 2022.
249
+ [50] L. Yunseung and K. Pilsung. AnoViT: Unsupervised anomaly detection and localization with vision transformer-based encoder-decoder. arXiv preprint arXiv:2203.10808, 2022.
250
+ [51] M. Z. Zaheer, J.-h. Lee, M. Astrid, and S.-I. Lee. Old is gold: Redefining the adversarially learned one-class classifier training paradigm. In IEEE Conf. Comput. Vis. Pattern Recog., 2020.
251
+ [52] V. Zavrtanik, M. Kristan, and D. Skocaj. DRAEM-A discriminatively trained reconstruction embedding ˇ for surface anomaly detection. In Int. Conf. Comput. Vis., 2021.
252
+ [53] K. Zhou, Y. Xiao, J. Yang, J. Cheng, W. Liu, W. Luo, Z. Gu, J. Liu, and S. Gao. Encoding structure-texture relation with P-Net for anomaly detection in retinal images. In Eur. Conf. Comput. Vis., 2020.
253
+
254
+ # Checklist
255
+
256
+ 1. For all authors...
257
+
258
+ (a) Do the main claims made in the abstract and introduction accurately reflect the paper’s contributions and scope? [Yes]
259
+ (b) Did you describe the limitations of your work? [Yes] See Discussion in Sec. 5.
260
+ (c) Did you discuss any potential negative societal impacts of your work? [Yes] See Discussion in Sec. 5.
261
+ (d) Have you read the ethics review guidelines and ensured that your paper conforms to them? [Yes]
262
+
263
+ 2. If you are including theoretical results...
264
+
265
+ (a) Did you state the full set of assumptions of all theoretical results? [N/A] (b) Did you include complete proofs of all theoretical results? [N/A]
266
+
267
+ 3. If you ran experiments...
268
+
269
+ (a) Did you include the code, data, and instructions needed to reproduce the main experimental results (either in the supplemental material or as a URL)? [Yes] See Sec. 4 and Appendix. Also, we have released the code.
270
+ (b) Did you specify all the training details (e.g., data splits, hyperparameters, how they were chosen)? [Yes] See Sec. 4.1 & Sec. 4.4 for data splits, and Sec. 4.6 for the choice of hyperparameters.
271
+ (c) Did you report error bars (e.g., with respect to the random seed after running experiments multiple times)? [Yes] See Tab. 1, Tab. 2, and Tab. 3.
272
+ (d) Did you include the total amount of compute and the type of resources used (e.g., type of GPUs, internal cluster, or cloud provider)? [Yes] See Setup in Sec. 4.2.
273
+
274
+ 4. If you are using existing assets (e.g., code, data, models) or curating/releasing new assets...
275
+
276
+ (a) If your work uses existing assets, did you cite the creators? [Yes] See Sec. 4.1 and Baselines in Sec. 4.
277
+ (b) Did you mention the license of the assets? [N/A]
278
+ (c) Did you include any new assets either in the supplemental material or as a URL? [N/A]
279
+ (d) Did you discuss whether and how consent was obtained from people whose data you’re using/curating? [N/A]
280
+ (e) Did you discuss whether the data you are using/curating contains personally identifiable information or offensive content? [N/A]
281
+
282
+ 5. If you used crowdsourcing or conducted research with human subjects...
283
+
284
+ (a) Did you include the full text of instructions given to participants and screenshots, if applicable? [N/A]
285
+
286
+ (b) Did you describe any potential participant risks, with links to Institutional Review Board (IRB) approvals, if applicable? [N/A]
287
+ (c) Did you include the estimated hourly wage paid to participants and the total amount spent on participant compensation? [N/A]
parse/dev/bMYU8_qD8PW/bMYU8_qD8PW_content_list.json ADDED
@@ -0,0 +1,1230 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "type": "text",
4
+ "text": "A Unified Model for Multi-class Anomaly Detection ",
5
+ "text_level": 1,
6
+ "bbox": [
7
+ 186,
8
+ 122,
9
+ 810,
10
+ 147
11
+ ],
12
+ "page_idx": 0
13
+ },
14
+ {
15
+ "type": "text",
16
+ "text": "Zhiyuan $\\mathbf { V o u } ^ { 1 * }$ Lei $\\mathbf { C u i ^ { 2 * } }$ Yujun Shen3 Kai Yang4 Xin Lu4 Yu Zheng1 Xinyi Le1† ",
17
+ "bbox": [
18
+ 202,
19
+ 199,
20
+ 795,
21
+ 215
22
+ ],
23
+ "page_idx": 0
24
+ },
25
+ {
26
+ "type": "text",
27
+ "text": "1Shanghai Jiao Tong University 2Tsinghua University 3CUHK 4SenseTime zhiyuanyou@foxmail.com, cuil19@mails.tsinghua.edu.cn, shenyujun0302@gmail.com {yangkai, luxin}@sensetime.com, yuzheng@sjtu.edu.cn, lexinyi@sjtu.edu.cn ",
28
+ "bbox": [
29
+ 202,
30
+ 219,
31
+ 795,
32
+ 270
33
+ ],
34
+ "page_idx": 0
35
+ },
36
+ {
37
+ "type": "text",
38
+ "text": "Abstract ",
39
+ "text_level": 1,
40
+ "bbox": [
41
+ 462,
42
+ 305,
43
+ 535,
44
+ 321
45
+ ],
46
+ "page_idx": 0
47
+ },
48
+ {
49
+ "type": "text",
50
+ "text": "Despite the rapid advance of unsupervised anomaly detection, existing methods require to train separate models for different objects. In this work, we present $U n i A D$ that accomplishes anomaly detection for multiple classes with a unified framework. Under such a challenging setting, popular reconstruction networks may fall into an “identical shortcut”, where both normal and anomalous samples can be well recovered, and hence fail to spot outliers. To tackle this obstacle, we make three improvements. First, we revisit the formulations of fully-connected layer, convolutional layer, as well as attention layer, and confirm the important role of query embedding (i.e., within attention layer) in preventing the network from learning the shortcut. We therefore come up with a layer-wise query decoder to help model the multi-class distribution. Second, we employ a neighbor masked attention module to further avoid the information leak from the input feature to the reconstructed output feature. Third, we propose a feature jittering strategy that urges the model to recover the correct message even with noisy inputs. We evaluate our algorithm on MVTec-AD and CIFAR-10 datasets, where we surpass the state-of-the-art alternatives by a sufficiently large margin. For example, when learning a unified model for 15 categories in MVTec-AD, we surpass the second competitor on the tasks of both anomaly detection (from $8 8 . 1 \\%$ to $9 6 . 5 \\%$ ) and anomaly localization (from $8 9 . 5 \\%$ to $9 6 . 8 \\%$ ). Code is available at https:// github.com/zhiyuanyou/UniAD. ",
51
+ "bbox": [
52
+ 233,
53
+ 337,
54
+ 766,
55
+ 613
56
+ ],
57
+ "page_idx": 0
58
+ },
59
+ {
60
+ "type": "text",
61
+ "text": "1 Introduction ",
62
+ "text_level": 1,
63
+ "bbox": [
64
+ 174,
65
+ 640,
66
+ 310,
67
+ 657
68
+ ],
69
+ "page_idx": 0
70
+ },
71
+ {
72
+ "type": "text",
73
+ "text": "Anomaly detection has found an increasingly wide utilization in manufacturing defect detection [4], medical image analysis [17], and video surveillance [46]. Considering the highly diverse anomaly types, a common solution is to model the distribution of normal samples and then identify anomalous ones via finding outliers. It is therefore crucial to learn a compact boundary for normal data, as shown in Fig. 1a. For this purpose, existing methods [6, 11, 25, 27, 48, 49, 52] propose to train separate models for different classes of objects, like in Fig. 1c. However, such a one-class-one-model scheme could be memory-consuming especially along with the number of classes increasing, and also uncongenial to the scenarios where the normal samples manifest themselves in a large intra-class diversity (i.e., one object consists of various types). ",
74
+ "bbox": [
75
+ 174,
76
+ 672,
77
+ 825,
78
+ 797
79
+ ],
80
+ "page_idx": 0
81
+ },
82
+ {
83
+ "type": "text",
84
+ "text": "In this work, we target a more practical task, which is to detect anomalies from different object classes with a unified framework. The task setting is illustrated in Fig. 1d, where the training data covers normal samples from a range of categories, and the learned model is asked to accomplish anomaly detection for all these categories without any fine-tuning. It is noteworthy that the categorical information (i.e., class label) is inaccessible at both the training and the inference stages, considerably easing the difficulty of data preparation. Nonetheless, solving such a task is fairly challenging. Recall that the rationale behind unsupervised anomaly detection is to model the distribution of normal data and find a compact decision boundary as in Fig. 1a. When it comes to the multi-class case, we expect the model to capture the distribution of all classes simultaneously such that they can share the same boundary as in Fig. 1b. But if we focus on a particular category, say the green one in Fig. 1b, all the samples from other categories should be considered as anomalies no matter whether they are normal (i.e., blue circles) or anomalous (i.e., blue triangles) themselves. From this perspective, how to accurately model the multi-class distribution becomes vital. ",
85
+ "bbox": [
86
+ 174,
87
+ 804,
88
+ 823,
89
+ 873
90
+ ],
91
+ "page_idx": 0
92
+ },
93
+ {
94
+ "type": "image",
95
+ "img_path": "images/b6232b853896a035f8a396234cfe67be2075d265ba691a7c3cd42f00cbab0b69.jpg",
96
+ "image_caption": [
97
+ "Figure 1: Task setting of unified anomaly detection. (a) Existing methods learn separate decision boundaries for different object classes, while (b) our approach models the multi-class data distribution such that one boundary is enough to spot outliers regarding all categories. As a result, we escape from the conventional one-class-one-model paradigm in (c), and manage to accomplish anomaly detection for various classes with a unified framework in (d). "
98
+ ],
99
+ "image_footnote": [],
100
+ "bbox": [
101
+ 184,
102
+ 89,
103
+ 818,
104
+ 236
105
+ ],
106
+ "page_idx": 1
107
+ },
108
+ {
109
+ "type": "text",
110
+ "text": "",
111
+ "bbox": [
112
+ 174,
113
+ 340,
114
+ 825,
115
+ 452
116
+ ],
117
+ "page_idx": 1
118
+ },
119
+ {
120
+ "type": "text",
121
+ "text": "A widely used approach to learning the normal data distribution draws support from image (or feature) reconstruction [2, 5, 26, 39, 51], which assumes that a well-trained model always produces normal samples regardless of the defects within the inputs. In this way, there will be large reconstruction errors for anomalous samples, making them distinguishable from the normal ones. However, we find that popular reconstruction networks suggest unsatisfying performance on the challenging task studied in this work. They typically fall into an “identity shortcut”, which appears as returning a direct copy of the input disregarding its content.1 As a result, even anomalous samples can be well recovered with the learned model and hence become hard to detect. Moreover, under the unified case, where the distribution of normal data is more complex, the “identical shortcut” problem is magnified. Intuitively, to learn a unified model that can reconstruct all kinds of objects, it requires the model to work extremely hard to learn the joint distribution. From this perspective, learning an “identical shortcut” appears as a far easier solution. ",
122
+ "bbox": [
123
+ 174,
124
+ 458,
125
+ 825,
126
+ 623
127
+ ],
128
+ "page_idx": 1
129
+ },
130
+ {
131
+ "type": "text",
132
+ "text": "To address this issue, we carefully tailor a feature reconstruction framework that prevents the model from learning the shortcut. First, we revisit the formulations of fully-connected layer, convolutional layer, as well as attention layer used in neural networks, and observe that both fully-connected layer and convolutional layer face the risk of learning a trivial solution. This drawback is further amplified under the multi-class setting in that the normal data distribution becomes far more complex. Instead, the attention layer is sheltered from such a risk, benefiting from a learnable query embedding (see Sec. 3.1). Accordingly, we propose a layer-wise query decoder to intensify the use of query embedding. Second, we argue that the full attention (i.e., every feature point relates to each other) also contributes to the shortcut issue, because it offers the chance of directly copying the input to the output. To avoid the information leak, we employ a neighbor masked attention module, where a feature point relates to neither itself nor its neighbors. Third, inspired by Bengio et al. [3], we propose a feature jittering strategy, which requires the model to recover the source message even with noisy inputs. All these designs help the model escape from the “identity shortcut”, as shown in Fig. 2b. Extensive experiments on MVTec-AD [4] and CIFAR-10 [23] demonstrate the sufficient superiority of our approach, which we call $U n i A D$ , over existing alternatives under the unified task setting. For instance, when learning a single model for 15 categories in MVTec-AD, we achieve state-of-the-art performance on the tasks of both anomaly detection and anomaly localization, boosting the AUROC from $8 8 . 1 \\%$ to $9 6 . 5 \\%$ and from $8 9 . 5 \\%$ to $9 6 . 8 \\%$ , respectively. ",
133
+ "bbox": [
134
+ 174,
135
+ 631,
136
+ 825,
137
+ 878
138
+ ],
139
+ "page_idx": 1
140
+ },
141
+ {
142
+ "type": "text",
143
+ "text": "2 Related work ",
144
+ "text_level": 1,
145
+ "bbox": [
146
+ 174,
147
+ 89,
148
+ 316,
149
+ 106
150
+ ],
151
+ "page_idx": 2
152
+ },
153
+ {
154
+ "type": "text",
155
+ "text": "Anomaly detection. 1) Classical approaches extend classical machine learning methods for one-class classification, such as one-class support vector machine (OC-SVM) [38] and support vector data description (SVDD) [35, 41]. Patch-level embedding [48], geometric transformation [18], and elastic weight consolidation [33] are incorporated for improvement. 2) Pseudo-anomaly converts anomaly detection to supervised learning, including classification [25, 32, 45], image denoising [52], and hypersphere segmentation [27]. However, these methods partly rely on how well proxy anomalies match real anomalies that are not known [13]. 3) Modeling then comparison assumes that the pre-trained network is capable of extracting discriminative features for anomaly detection [11, 34]. PaDiM [11] and MDND [34] extract pre-trained features to model normal distribution, then utilize a distance metric to measure the anomalies. Nevertheless, these methods need to memorize and model all normal features, thus are computationally expensive. 4) Knowledge distillation proposes that the student distilled by a teacher on normal samples could only extract normal features [6, 13, 37, 44, 45]. Recent works mainly focus on model ensemble [6], feature pyramid [37, 44], and reverse distillation [13]. ",
156
+ "bbox": [
157
+ 174,
158
+ 125,
159
+ 825,
160
+ 304
161
+ ],
162
+ "page_idx": 2
163
+ },
164
+ {
165
+ "type": "text",
166
+ "text": "Reconstruction-based anomaly detection. These methods rely on the hypothesis that reconstruction models trained on normal samples only succeed in normal regions, but fail in anomalous regions [5, 8, 26, 36, 49]. Early attempts include Auto-Encoder (AE) [5, 9], Variational Auto-Encoder (VAE) [22, 26], and Generative Adversarial Net (GAN) [2, 30, 36, 51]. However, these methods face the problem that the model could learn tricks that the anomalies are also restored well. Accordingly, researchers adopt different strategies to tackle this issue, such as adding instructional information (i.e., structural [53] or semantic [39, 46]), memory mechanism [19, 20, 29], iteration mechanism [12], image masking strategy [47], and pseudo-anomaly [9, 32]. Recently, DRAEM [52] first recovers the pseudo-anomaly disturbed normal images for representation, then utilizes a discriminative net to distinguish the anomalies, achieving excellent performance. However, DRAEM [52] ceases to be effective under the unified case. Moreover, there is still an important aspect that has not been well studied, i.e., what architecture is the best reconstruction model? In this paper, we first compare and analyze three popular architectures including MLP, CNN, and transformer. Then, accordingly, we base on the transformer and further design three improvements, which compose our UniAD. ",
167
+ "bbox": [
168
+ 173,
169
+ 310,
170
+ 825,
171
+ 503
172
+ ],
173
+ "page_idx": 2
174
+ },
175
+ {
176
+ "type": "text",
177
+ "text": "Transformer in anomaly detection. Transformer [42] with attention mechanism, first proposed in natural language processing, has been successfully used in computer vision [7, 16]. Some attempts try to utilize transformer for anomaly detection. InTra [31] adopts transformer to recover the image by recovering all masked patches one by one. VT-ADL [28] and AnoVit [50] both apply transformer encoder to reconstruct images. However, these methods directly utilize vanilla transformer, and do not figure out why transformer brings improvement. In contrast, we confirm the efficacy of the query embedding to prevent the shortcut, and accordingly design a layer-wise query decoder. Also, to avoid the information leak of the full attention, we employ a neighbor masked attention module. ",
178
+ "bbox": [
179
+ 174,
180
+ 511,
181
+ 825,
182
+ 621
183
+ ],
184
+ "page_idx": 2
185
+ },
186
+ {
187
+ "type": "text",
188
+ "text": "3 Method ",
189
+ "text_level": 1,
190
+ "bbox": [
191
+ 174,
192
+ 647,
193
+ 269,
194
+ 664
195
+ ],
196
+ "page_idx": 2
197
+ },
198
+ {
199
+ "type": "text",
200
+ "text": "3.1 Revisiting feature reconstruction for anomaly detection ",
201
+ "text_level": 1,
202
+ "bbox": [
203
+ 174,
204
+ 683,
205
+ 596,
206
+ 696
207
+ ],
208
+ "page_idx": 2
209
+ },
210
+ {
211
+ "type": "text",
212
+ "text": "In Fig. 2, following the feature reconstruction paradigm [39, 49], we build an MLP, a CNN, and a transformer (with query embedding) to reconstruct the features extracted by a pre-trained backbone. The reconstruction errors represent the anomaly possibility. The architectures of the three networks are given in Appendix. The metric is evaluated every 10 epochs. Note that the periodic evaluation is impractical since anomalies are not available during training. As shown in Fig. 2a, after a period of training, the performances of the three networks decrease severely with the losses going extremely small. We attribute this to the problem of “identical shortcut”, where both normal and anomalous regions can be well recovered, thus failing to spot anomalies. This speculation is verified by the visualization results in Fig. 2b (more results in Appendix). However, compared with MLP and CNN, the transformer suffers from a much smaller performance drop, indicating a slighter shortcut problem. This encourages us to analyze as follows. ",
213
+ "bbox": [
214
+ 174,
215
+ 710,
216
+ 825,
217
+ 863
218
+ ],
219
+ "page_idx": 2
220
+ },
221
+ {
222
+ "type": "text",
223
+ "text": "We denote the features in a normal image as $\\pmb { x } ^ { + } \\in \\mathbb { R } ^ { K \\times C }$ , where $K$ is the feature number, $C$ is the channel dimension. The batch dimension is omitted for simplicity. Similarly, the features in an anomalous image are denoted as $\\pmb { x } ^ { - } \\in \\mathbb { R } ^ { K \\times C }$ . The reconstruction loss is chosen as the MSE loss. ",
224
+ "bbox": [
225
+ 176,
226
+ 868,
227
+ 825,
228
+ 911
229
+ ],
230
+ "page_idx": 2
231
+ },
232
+ {
233
+ "type": "image",
234
+ "img_path": "images/f359d145336a151f892f300a30f2f84bdfa6df11e6012b50907c0ea33940f5a3.jpg",
235
+ "image_caption": [
236
+ "Figure 2: Comparison among MLP, CNN, transformer, and our UniAD on MVTec-AD [4]. (a) Training loss (blue) as well as the testing AUROC on anomaly detection (green) and localization (red). During the training of MLP, CNN, and transformer, the reconstruction error keeps going smaller on normal samples, but the performance on anomalies suffers from a severe drop after reaching the peak. This is caused by the model learning an “identical shortcut”, which tends to directly copy the input as the output regardless of whether it is normal or anomalous. (b) Visual explanation of the shortcut issue, where the anomalous samples can be well recovered and hence become hard to detect from normal ones. In contrast, UniAD overcomes such a problem and manages to reconstruct anomalies as normal samples. It is noteworthy that all models are learned for feature reconstruction and a separate decoder is employed to render images from features. This decoder is only used for visualization. "
237
+ ],
238
+ "image_footnote": [],
239
+ "bbox": [
240
+ 178,
241
+ 88,
242
+ 825,
243
+ 257
244
+ ],
245
+ "page_idx": 3
246
+ },
247
+ {
248
+ "type": "text",
249
+ "text": "We provide a rough analysis using a simple 1-layer network as the reconstruction net, which is trained with ${ \\pmb x } ^ { + }$ and tested to detect anomalous regions in ${ \\pmb x } ^ { - }$ . ",
250
+ "bbox": [
251
+ 174,
252
+ 425,
253
+ 821,
254
+ 454
255
+ ],
256
+ "page_idx": 3
257
+ },
258
+ {
259
+ "type": "text",
260
+ "text": "Fully-connected layer in MLP. Denote the weights and bias in this layer as $\\pmb { w } \\in \\mathbb { R } ^ { C \\times C } , \\pmb { b } \\in \\mathbb { R } ^ { C }$ respectively, this layer can be represented as, ",
261
+ "bbox": [
262
+ 173,
263
+ 459,
264
+ 823,
265
+ 488
266
+ ],
267
+ "page_idx": 3
268
+ },
269
+ {
270
+ "type": "equation",
271
+ "img_path": "images/9a83e024f138e6b5d1902e578570e59d0cb19b675af2a1c68605fca9c6993735.jpg",
272
+ "text": "$$\n\\pmb { y } = \\pmb { x } ^ { + } \\pmb { w } + \\pmb { b } \\in \\mathbb { R } ^ { K \\times C } .\n$$",
273
+ "text_format": "latex",
274
+ "bbox": [
275
+ 413,
276
+ 493,
277
+ 584,
278
+ 512
279
+ ],
280
+ "page_idx": 3
281
+ },
282
+ {
283
+ "type": "text",
284
+ "text": "With the MSE loss pushing $\\textbf { { y } }$ to ${ \\pmb x } ^ { + }$ , the model may take shortcut to regress $w \\to I$ (identity matrix), $\\mathbf b \\to \\mathbf 0$ . Ultimately, this model could also reconstruct ${ \\pmb x } ^ { - }$ well, failing in anomaly detection. ",
285
+ "bbox": [
286
+ 169,
287
+ 518,
288
+ 826,
289
+ 546
290
+ ],
291
+ "page_idx": 3
292
+ },
293
+ {
294
+ "type": "text",
295
+ "text": "Convolutional layer in CNN. A convolutional layer with $1 \\times 1$ kernel is equivalent to a fullyconnected layer. Besides, An $n \\times n$ $( n > 1 )$ ) kernel has more parameters and larger capacity, and can complete whatever $1 \\times 1$ kernel can. Thus, this layer also has the chance to learn a shortcut. ",
296
+ "bbox": [
297
+ 174,
298
+ 553,
299
+ 823,
300
+ 594
301
+ ],
302
+ "page_idx": 3
303
+ },
304
+ {
305
+ "type": "text",
306
+ "text": "Transformer with query embedding. In such a model, there is an attention layer with a learnable query embedding, $\\mathbf { \\bar { q } } \\in \\mathbb { R } ^ { \\mathbf { \\bar { K } } \\times C }$ . When using this layer as the reconstruction model, it is denoted as, ",
307
+ "bbox": [
308
+ 171,
309
+ 601,
310
+ 821,
311
+ 628
312
+ ],
313
+ "page_idx": 3
314
+ },
315
+ {
316
+ "type": "equation",
317
+ "img_path": "images/ec37e94f64b16f1724c852eabd61def70c938cb33b7749d8c98609e5beaf4dcd.jpg",
318
+ "text": "$$\n{ \\pmb y } = \\mathrm { s o f t m a x } ( { \\pmb q } ( { \\pmb x } ^ { + } ) ^ { T } / \\sqrt { C } ) { \\pmb x } ^ { + } \\in \\mathbb { R } ^ { K \\times C } .\n$$",
319
+ "text_format": "latex",
320
+ "bbox": [
321
+ 354,
322
+ 635,
323
+ 642,
324
+ 655
325
+ ],
326
+ "page_idx": 3
327
+ },
328
+ {
329
+ "type": "text",
330
+ "text": "To push $\\textbf { { y } }$ to ${ \\pmb x } ^ { + }$ , the attention map, softmax $( \\pmb q ( \\pmb x ^ { + } ) ^ { T } / \\sqrt { C } )$ , should approximate $\\pmb { I }$ (identity matrix), so $\\pmb q$ must be highly related to ${ \\pmb x } ^ { + }$ . Considering that $\\pmb q$ in the trained model is relevant to normal samples, the model could not reconstruct ${ \\pmb x } ^ { - }$ well. The ablation study in Sec. 4.6 shows that without the query embedding, the performance of transformer drops dramatically by $1 8 . 1 \\%$ and $1 3 . 4 \\%$ in anomaly detection and localization, respectively. Thus the query embedding is of vital significance to model the normal distribution. ",
331
+ "bbox": [
332
+ 174,
333
+ 661,
334
+ 825,
335
+ 746
336
+ ],
337
+ "page_idx": 3
338
+ },
339
+ {
340
+ "type": "text",
341
+ "text": "However, transformer still suffers from the shortcut problem, which inspires our three improvements. 1) According to that the query embedding can prevent reconstructing anomalies, we design a Layerwise Query Decoder (LQD) by adding the query embedding in each decoder layer rather than only the first layer in vanilla transformer. 2) We suspect that the full attention increases the possibility of the shortcut. Since one token could see itself and its neighbor regions, it is easy to reconstruct by simply copying. Thus we mask the neighbor tokens when calculating the attention map, called Neighbor Masked Attention (NMA). 3) We employ a Feature Jittering (FJ) strategy to disturb the input features, leading the model to learn normal distribution from denoising. Benefiting from these designs, our UniAD achieves satisfying performance, as illustrated in Fig. 2. ",
342
+ "bbox": [
343
+ 173,
344
+ 751,
345
+ 825,
346
+ 877
347
+ ],
348
+ "page_idx": 3
349
+ },
350
+ {
351
+ "type": "text",
352
+ "text": "Relation between the “identical shortcut” problem and the unified case. In Fig. 2a, we aim to visualize the “identical shortcut” problem, where the loss becomes smaller yet the performance drops. ",
353
+ "bbox": [
354
+ 173,
355
+ 883,
356
+ 821,
357
+ 911
358
+ ],
359
+ "page_idx": 3
360
+ },
361
+ {
362
+ "type": "image",
363
+ "img_path": "images/855a91070ef894d03f297ec342fc74d6da14d6c832d1b9fae74b2b5c5c132187.jpg",
364
+ "image_caption": [
365
+ "Figure 3: Framework of UniAD, consisting of a Neighbor Masked Encoder (NME) and a Layer-wise Query Decoder (LQD). Each layer in LQD employs a learnable query embedding to help model the complex training data distribution. The full attention in transformer is replaced by neighbor masked attention to avoid the information leak from the input to the output. The feature jittering strategy encourages the model to recover the correct message with noisy inputs. All the three improvements assist the model against learning the “identical shortcut” (see Sec. 3.1 and Fig. 2 for details). "
366
+ ],
367
+ "image_footnote": [],
368
+ "bbox": [
369
+ 184,
370
+ 88,
371
+ 813,
372
+ 324
373
+ ],
374
+ "page_idx": 4
375
+ },
376
+ {
377
+ "type": "image",
378
+ "img_path": "images/9f58a091d2fbbebc9f5f5e64eaa929c479d4670d2e4b40ad48e306edf6bab81f.jpg",
379
+ "image_caption": [
380
+ "Figure 4: Comparison between the unified case and the separate case on the training curves of MLP. In the separate case, the curves are obtained by averaging all categories. Compared with the separate case, the unified case has a smaller reconstruction error but much worse performance, indicating a severer “identical shortcut” problem. "
381
+ ],
382
+ "image_footnote": [],
383
+ "bbox": [
384
+ 178,
385
+ 433,
386
+ 496,
387
+ 537
388
+ ],
389
+ "page_idx": 4
390
+ },
391
+ {
392
+ "type": "image",
393
+ "img_path": "images/35911b53aeeb2ecbe0d34d45c19e02807f12435599942b5c722a940a406f0045.jpg",
394
+ "image_caption": [
395
+ "Figure 5: Illustration of neighbor masked attention, where a feature point relates to neither itself nor its neighbors. "
396
+ ],
397
+ "image_footnote": [],
398
+ "bbox": [
399
+ 521,
400
+ 439,
401
+ 812,
402
+ 592
403
+ ],
404
+ "page_idx": 4
405
+ },
406
+ {
407
+ "type": "text",
408
+ "text": "We conduct the same experiment under the separate case on MLP. As shown in Fig. 4, the accuracy (green for detection and red for localization) keeps growing up along with the loss (blue) getting smaller. This helps reveal the relation between the “identical shortcut” problem and the unified case, which is that the unified case is more challenging and hence magnifies the “identical shortcut” problem. Therefore, since our approach is specially designed to solve the “identical shortcut” problem, our method can be effective in the unified case. ",
409
+ "bbox": [
410
+ 173,
411
+ 661,
412
+ 826,
413
+ 744
414
+ ],
415
+ "page_idx": 4
416
+ },
417
+ {
418
+ "type": "text",
419
+ "text": "3.2 Improving feature reconstruction for unified anomaly detection ",
420
+ "text_level": 1,
421
+ "bbox": [
422
+ 176,
423
+ 761,
424
+ 651,
425
+ 776
426
+ ],
427
+ "page_idx": 4
428
+ },
429
+ {
430
+ "type": "text",
431
+ "text": "Overview. As shown in Fig. 3, our UniAD is composed of a Neighbor Masked Encoder (NME) and a Layer-wise Query Decoder (LQD). Firstly, the feature tokens extracted by a fixed pre-trained backbone are further integrated by NME to derive the encoder embeddings. Then, in each layer of LQD, a learnable query embedding is successively fused with the encoder embeddings and the outputs of the previous layer (self-fusion for the first layer). The feature fusion is completed by the Neighbor Masked Attention (NMA). The final outputs of LQD are viewed as the reconstructed features. Also, we propose a Feature Jittering (FJ) strategy to add perturbations to the input features, leading the model to learn normal distribution from the denoising task. Finally, the results of anomaly localization and detection are obtained through the reconstruction differences. ",
432
+ "bbox": [
433
+ 174,
434
+ 786,
435
+ 825,
436
+ 911
437
+ ],
438
+ "page_idx": 4
439
+ },
440
+ {
441
+ "type": "text",
442
+ "text": "Neighbor masked attention. We suspect that the full attention in vanilla transformer [42] contributes to the “identical shortcut”. In full attention, one token is permitted to see itself, so it will be easy to reconstruct by simply copying. Moreover, considering that the feature tokens are extracted by a CNN backbone, the neighbor tokens must share lots of similarities. Therefore, we propose to mask the neighbor tokens when calculating the attention map, called Neighbor Masked Attention (NMA). Note that the neighbor region is defined in the 2D space, as shown in Fig. 5. ",
443
+ "bbox": [
444
+ 173,
445
+ 90,
446
+ 825,
447
+ 175
448
+ ],
449
+ "page_idx": 5
450
+ },
451
+ {
452
+ "type": "text",
453
+ "text": "Neighbor masked encoder. The encoder follows the standard architecture in vanilla transformer. Each layer consists of an attention module and a Feed-Forward Network (FFN). However, the full attention is replaced by our proposed NMA to prevent the information leak. ",
454
+ "bbox": [
455
+ 174,
456
+ 180,
457
+ 825,
458
+ 223
459
+ ],
460
+ "page_idx": 5
461
+ },
462
+ {
463
+ "type": "text",
464
+ "text": "Layer-wise query decoder. It is analyzed in Sec. 3.1 that the query embedding could help prevent reconstructing anomalies well. However, there is only one query embedding in the vanilla transformer. Therefore, we design a Layer-wise Query Decoder (LQD) to intensify the use of query embedding, as shown in Fig. 3. Specifically, in each layer of LQD, a learnable query embedding is first fused with the encoder embeddings, then integrated with the outputs of the previous layer (self-integration for the first layer). The feature fusion is implemented by NMA. Following the vanilla transformer, a 2-layer FFN is applied to handle these fused tokens, and the residual connection is utilized to facilitate the training. The final outputs of LQD serve as the reconstructed features. ",
465
+ "bbox": [
466
+ 173,
467
+ 228,
468
+ 825,
469
+ 340
470
+ ],
471
+ "page_idx": 5
472
+ },
473
+ {
474
+ "type": "text",
475
+ "text": "Feature jittering. Inspired by Denoising Auto-Encoder (DAE) [3, 43], we add perturbations to feature tokens, guiding the model to learn knowledge of normal samples by the denoising task. Specifically, for a feature token, $\\pmb { f } _ { t o k } \\in \\mathbb { R } ^ { C }$ , we sample the disturbance $D$ from a Gaussian distribution, ",
476
+ "bbox": [
477
+ 173,
478
+ 345,
479
+ 826,
480
+ 388
481
+ ],
482
+ "page_idx": 5
483
+ },
484
+ {
485
+ "type": "equation",
486
+ "img_path": "images/ab18dc28ce0e6034ae5f7097dc445de3de46bbb01533b7649347e28172f864c4.jpg",
487
+ "text": "$$\nD \\sim N ( \\mu = 0 , \\sigma ^ { 2 } = ( \\alpha \\frac { | | \\mathbf { f } _ { t o k } | | _ { 2 } } { C } ) ^ { 2 } ) ,\n$$",
488
+ "text_format": "latex",
489
+ "bbox": [
490
+ 375,
491
+ 390,
492
+ 620,
493
+ 421
494
+ ],
495
+ "page_idx": 5
496
+ },
497
+ {
498
+ "type": "text",
499
+ "text": "where $\\alpha$ is the jittering scale to control the noisy degree. Also, the sampled disturbance is added to $f _ { t o k }$ with a fixed jittering probability, $p$ . ",
500
+ "bbox": [
501
+ 173,
502
+ 421,
503
+ 828,
504
+ 450
505
+ ],
506
+ "page_idx": 5
507
+ },
508
+ {
509
+ "type": "text",
510
+ "text": "3.3 Implementation details ",
511
+ "text_level": 1,
512
+ "bbox": [
513
+ 174,
514
+ 465,
515
+ 374,
516
+ 479
517
+ ],
518
+ "page_idx": 5
519
+ },
520
+ {
521
+ "type": "text",
522
+ "text": "Feature extraction. We adopt a fixed EfficientNet-b4 [40] pre-trained on ImageNet [14] as the feature extractor. The features from stage-1 to stage-4 are selected. Here the stage means the combination of blocks that have the same size of feature maps. Then these features are resized to the same size, and concatenated along channel dimension to form a feature map, $\\mathbf { \\Delta } f _ { o r g } \\in \\mathbb { R } ^ { C _ { o r g } \\times H \\times W }$ . ",
523
+ "bbox": [
524
+ 173,
525
+ 489,
526
+ 825,
527
+ 547
528
+ ],
529
+ "page_idx": 5
530
+ },
531
+ {
532
+ "type": "text",
533
+ "text": "Feature reconstruction. The feature map, $f _ { o r g }$ , is first tokenized to $H \\times W$ feature tokens, followed by a linear projection to reduce $C _ { o r g }$ to a smaller channel, $C$ . Then these tokens are processed by NME and LQD. The learnable position embeddings [15, 16] are added in attention modules to inform the spatial information. Afterward, another linear projection is used to recover the channel from $C$ to $C _ { o r g }$ . After reshape, the reconstructed feature map, $\\mathbf { \\bar { f } } _ { r e c } \\in \\mathbb { R } ^ { C _ { o r g } \\times H \\times W }$ , is finally obtained. ",
534
+ "bbox": [
535
+ 173,
536
+ 551,
537
+ 825,
538
+ 623
539
+ ],
540
+ "page_idx": 5
541
+ },
542
+ {
543
+ "type": "text",
544
+ "text": "Objective function. Our model is trained with the MSE loss as, ",
545
+ "bbox": [
546
+ 174,
547
+ 627,
548
+ 596,
549
+ 643
550
+ ],
551
+ "page_idx": 5
552
+ },
553
+ {
554
+ "type": "equation",
555
+ "img_path": "images/4c51c7f7526d492ff1ffc18011ba70355e26a89adf4f08eb54b4d123238ade2e.jpg",
556
+ "text": "$$\n\\mathcal { L } = \\frac { 1 } { H \\times W } | | \\mathbf { f } _ { o r g } - \\mathbf { f } _ { r e c } | | _ { 2 } ^ { 2 } .\n$$",
557
+ "text_format": "latex",
558
+ "bbox": [
559
+ 398,
560
+ 645,
561
+ 599,
562
+ 676
563
+ ],
564
+ "page_idx": 5
565
+ },
566
+ {
567
+ "type": "text",
568
+ "text": "Inference for anomaly localization. The result of anomaly localization is an anomaly score map, which assigns an anomaly score for each pixel. Specifically, the anomaly score map, $s$ , is calculated as the L2 norm of the reconstruction differences as, ",
569
+ "bbox": [
570
+ 174,
571
+ 683,
572
+ 825,
573
+ 724
574
+ ],
575
+ "page_idx": 5
576
+ },
577
+ {
578
+ "type": "equation",
579
+ "img_path": "images/dacf2fb9ce853151683c3794593f80aabbc6bd77e7e50e6673fa0e06f13c60ea.jpg",
580
+ "text": "$$\n\\pmb { s } = | | \\pmb { f } _ { o r g } - \\pmb { f } _ { r e c } | | _ { 2 } \\in \\mathbb { R } ^ { H \\times W } .\n$$",
581
+ "text_format": "latex",
582
+ "bbox": [
583
+ 393,
584
+ 726,
585
+ 604,
586
+ 744
587
+ ],
588
+ "page_idx": 5
589
+ },
590
+ {
591
+ "type": "text",
592
+ "text": "Then $\\pmb { s }$ is up-sampled to the image size with bi-linear interpolation to obtain the localization results. ",
593
+ "bbox": [
594
+ 176,
595
+ 746,
596
+ 823,
597
+ 761
598
+ ],
599
+ "page_idx": 5
600
+ },
601
+ {
602
+ "type": "text",
603
+ "text": "Inference for anomaly detection. Anomaly detection aims to detect whether an image contains anomalous regions. We transform the anomaly score map, $\\pmb { s }$ , to the anomaly score of the image by taking the maximum value of the averagely pooled $\\pmb { s }$ . ",
604
+ "bbox": [
605
+ 173,
606
+ 766,
607
+ 825,
608
+ 809
609
+ ],
610
+ "page_idx": 5
611
+ },
612
+ {
613
+ "type": "text",
614
+ "text": "4 Experiment ",
615
+ "text_level": 1,
616
+ "bbox": [
617
+ 174,
618
+ 827,
619
+ 305,
620
+ 844
621
+ ],
622
+ "page_idx": 5
623
+ },
624
+ {
625
+ "type": "text",
626
+ "text": "4.1 Datasets and metrics ",
627
+ "text_level": 1,
628
+ "bbox": [
629
+ 174,
630
+ 857,
631
+ 357,
632
+ 872
633
+ ],
634
+ "page_idx": 5
635
+ },
636
+ {
637
+ "type": "text",
638
+ "text": "MVTec-AD [4] is a comprehensive, multi-object, multi-defect industrial anomaly detection dataset with 15 classes. For each anomalous sample in the test set, the ground-truth includes both image label and anomaly segmentation. In the existing literature, only the separate case is researched. In this paper, we introduce the unified case, where only one model is used to handle all categories. ",
639
+ "bbox": [
640
+ 173,
641
+ 882,
642
+ 821,
643
+ 911
644
+ ],
645
+ "page_idx": 5
646
+ },
647
+ {
648
+ "type": "table",
649
+ "img_path": "images/282eee1f90c5d1eec7ff62e44f03d3b4ecbc0631d8d11714511e170c618dff44.jpg",
650
+ "table_caption": [
651
+ "Table 1: Anomaly detection results with AUROC metric on MVTec-AD [4]. All methods are evaluated under the unified / separate case. In the unified case, the learned model is applied to detect anomalies for all categories without fine-tuning. "
652
+ ],
653
+ "table_footnote": [],
654
+ "table_body": "<table><tr><td colspan=\"2\">Category</td><td>US [6]</td><td>PSVDD[48] PaDiM[11] CutPaste [25] MKD [37] DRAEM [52]]</td><td></td><td></td><td></td><td></td><td>Ours</td></tr><tr><td rowspan=\"10\">Object</td><td>Bottle Cable</td><td>184.0/ 99.0</td><td>85.5/98.6</td><td>97.9 / 99.9</td><td>67.9/98.2</td><td>98.7/99.4</td><td>97.5/99.2</td><td>99.7 ± 0.04 /100</td></tr><tr><td></td><td>60.0 / 86.2</td><td>64.4 /90.3</td><td>70.9 / 92.7</td><td>69.2 / 81.2</td><td>78.2 / 89.2</td><td>57.8 /91.8</td><td>95.2 ± 0.84 / 97.6</td></tr><tr><td>Capsule</td><td>57.6/ 86.1</td><td>61.3 / 76.7</td><td>73.4 / 91.3</td><td>63.0 / 98.2</td><td>68.3 / 80.5</td><td>65.3 / 98.5</td><td>86.9 ± 0.73 / 85.3</td></tr><tr><td>Hazelnut</td><td>95.8/ 93.1</td><td>83.9 / 92.0</td><td>85.5/92.0</td><td>80.9/ 98.3</td><td>97.1/98.4</td><td>93.7/100</td><td>99.8 ± 0.10 / 99.9</td></tr><tr><td>Metal Nut</td><td>62.7/ 82.0</td><td>80.9 /94.0</td><td>88.0 / 98.7</td><td>60.0 / 99.9</td><td>64.9 / 73.6</td><td>72.8 /98.7</td><td>99.2 ± 0.09 / 99.0</td></tr><tr><td>Pill</td><td>56.1 / 87.9</td><td>89.4 / 86.1</td><td>68.8 / 93.3</td><td>71.4 / 94.9</td><td>79.7 / 82.7</td><td>82.2 /98.9</td><td>93.7 ± 0.65 / 88.3</td></tr><tr><td>Screw</td><td>66.9 / 54.9</td><td>80.9 / 81.3</td><td>56.9 / 85.8</td><td>85.2/88.7</td><td>75.6 /83.3</td><td>92.0 / 93.9</td><td>87.5 ± 0.57 / 91.9</td></tr><tr><td>Toothbrush</td><td>57.8 / 95.3</td><td>99.4 /100</td><td>95.3 / 96.1</td><td>63.9 / 99.4</td><td>75.3 / 92.2</td><td>90.6 /100</td><td>94.2 ± 0.20 /95.0</td></tr><tr><td>Transistor</td><td>61.0 / 81.8</td><td>77.5 / 91.5</td><td>86.6 /97.4</td><td>57.9 / 96.1</td><td>73.4 /85.6</td><td>74.8 /93.1</td><td>99.8 ± 0.09 /100</td></tr><tr><td>Zipper</td><td>78.6 /91.9</td><td>77.8 / 97.9</td><td>79.7 / 90.3</td><td>93.5 / 99.9</td><td>87.4 / 93.2</td><td>98.8 / 100</td><td>95.8 ± 0.51/ 96.7</td></tr><tr><td rowspan=\"5\">Texture</td><td>Carpet</td><td>86.6 / 91.6</td><td>63.3 / 92.9</td><td>93.8/ 99.8</td><td>93.6 /93.9</td><td>69.8 / 79.3</td><td>98.0 /97.0</td><td>99.8 ± 0.02 / 99.9</td></tr><tr><td>Grid</td><td>69.2/ 81.0</td><td>66.0 /94.6</td><td>73.9 / 96.7</td><td>93.2/100</td><td>83.8 /78.0</td><td>99.3 / 99.9</td><td>98.2±0.26/98.5</td></tr><tr><td>Leather</td><td>97.2 / 88.2</td><td>60.8 / 90.9</td><td>99.9 /100</td><td>93.4/100</td><td>93.6 / 95.1</td><td>98.7 /100</td><td>100 ± 0.00 /100</td></tr><tr><td>Tile</td><td>93.7 / 99.1</td><td>88.3 /97.8</td><td>93.3 /98.1</td><td>88.6 /94.6</td><td>89.5 /91.6</td><td>99.8 / 99.6</td><td>99.3 ± 0.14 / 99.0</td></tr><tr><td>Wood</td><td>90.6 / 97.7</td><td>72.1/ 96.5</td><td>98.4 /99.2</td><td>80.4 / 99.1</td><td>93.4 / 94.3</td><td>99.8 / 99.1</td><td>98.6 ± 0.08 / 97.9</td></tr><tr><td colspan=\"2\">Mean</td><td>74.5 / 87.7</td><td>76.8 /92.1</td><td>84.2 /95.5</td><td>77.5 / 96.1</td><td>81.9 / 87.8</td><td>88.1/98.0</td><td>96.5±0.08/96.6</td></tr></table>",
655
+ "bbox": [
656
+ 173,
657
+ 141,
658
+ 831,
659
+ 386
660
+ ],
661
+ "page_idx": 6
662
+ },
663
+ {
664
+ "type": "text",
665
+ "text": "",
666
+ "bbox": [
667
+ 174,
668
+ 407,
669
+ 823,
670
+ 435
671
+ ],
672
+ "page_idx": 6
673
+ },
674
+ {
675
+ "type": "text",
676
+ "text": "CIFAR-10 [23] is a classical image classification dataset with 10 categories. Existing methods [6, 24, 37] evaluate CIFAR-10 mainly in the one-versus-many setting, where one class is viewed as normal samples, and others serve as anomalies. Semantic AD [1, 10] proposes a many-versus-one setting, treating one class as anomalous and the remaining classes as normal. Different from both, we propose a unified case (many-versus-many setting), which is detailed in Sec. 4.4. ",
677
+ "bbox": [
678
+ 174,
679
+ 440,
680
+ 825,
681
+ 511
682
+ ],
683
+ "page_idx": 6
684
+ },
685
+ {
686
+ "type": "text",
687
+ "text": "Metrics. Following prior works [4, 6, 52], the Area Under the Receiver Operating Curve (AUROC) is used as the evaluation metric for anomaly detection. ",
688
+ "bbox": [
689
+ 173,
690
+ 517,
691
+ 823,
692
+ 545
693
+ ],
694
+ "page_idx": 6
695
+ },
696
+ {
697
+ "type": "text",
698
+ "text": "4.2 Anomaly detection on MVTec-AD ",
699
+ "text_level": 1,
700
+ "bbox": [
701
+ 176,
702
+ 575,
703
+ 447,
704
+ 590
705
+ ],
706
+ "page_idx": 6
707
+ },
708
+ {
709
+ "type": "text",
710
+ "text": "Setup. Anomaly detection aims to detect whether an image contains anomalous regions. The anomaly detection performance is evaluated on MVTec-AD [4]. The image size is selected as $2 2 4 \\times 2 2 4$ , and the size for resizing feature maps is set as $1 4 \\times 1 4$ . The feature maps from stage-1 to stage-4 of EfficientNet-b4 [40] are resized and concatenated together to form a 272-channel feature map. The reduced channel dimension is set as 256. AdamW optimizer [21] with weight decay $1 \\times 1 0 ^ { - 4 }$ is used. Our model is trained for 1000 epochs on 8 GPUs (NVIDIA Tesla V100 16GB) with batch size 64. The learning rate is $1 \\times 1 0 ^ { - 4 }$ initially, and dropped by 0.1 after 800 epochs. The layer numbers of the encoder and decoder are both 4. The neighbor size, jittering scale, and jittering probability are set as $7 \\times 7$ , 20, and 1, respectively. The evaluation is run with 5 random seeds. In both the separate case and the unified case, the reconstruction models are trained from the scratch. ",
711
+ "bbox": [
712
+ 173,
713
+ 607,
714
+ 825,
715
+ 746
716
+ ],
717
+ "page_idx": 6
718
+ },
719
+ {
720
+ "type": "text",
721
+ "text": "Baselines. Our approach is compared with baselines including: US [6], PSVDD [48], PaDiM [11], CutPaste [25], MKD [37], and DRAEM [52]. Under the separate case, the baselines’ metric is reported in their papers except the metric of US borrowed from [52]. Under the unified case, US, PSVDD, PaDiM, CutPaste, MKD, and DRAEM are run with the publicly available implementations. ",
722
+ "bbox": [
723
+ 174,
724
+ 752,
725
+ 825,
726
+ 808
727
+ ],
728
+ "page_idx": 6
729
+ },
730
+ {
731
+ "type": "text",
732
+ "text": "Quantitative results of anomaly detection on MVTec-AD [4] are shown in Tab. 1. Though all baselines achieve excellent performances under the separate case, their performances drop dramatically under the unified case. The previous SOTA, DRAEM, a reconstruction-based method trained by pseudo-anomaly, suffers from a drop of near $10 \\%$ . For another strong baseline, CutPaste, a pseudo-anomaly approach, the drop is as large as $1 8 . 6 \\%$ . However, our UniAD has almost no performance drop from the separate case $( 9 6 . 6 \\% )$ to the unified case $( 9 6 . 5 \\% )$ . Moreover, we beat the best competitor, DRAEM, by a dramatically large margin $( 8 . 4 \\% )$ , demonstrating our superiority. ",
733
+ "bbox": [
734
+ 174,
735
+ 814,
736
+ 825,
737
+ 911
738
+ ],
739
+ "page_idx": 6
740
+ },
741
+ {
742
+ "type": "table",
743
+ "img_path": "images/8adb5255348e6f7fc2153419990626c60c63990c89bdb23884879dbd2156a053.jpg",
744
+ "table_caption": [
745
+ "Table 2: Anomaly localization results with AUROC metric on MVTec-AD [4]. All methods are evaluated under the unified / separate case. In the unified case, the learned model is applied to detect anomalies for all categories without fine-tuning. "
746
+ ],
747
+ "table_footnote": [],
748
+ "table_body": "<table><tr><td colspan=\"2\">Category Bottle</td><td>US [6]</td><td></td><td></td><td></td><td></td><td>PSVDD [48] PaDiM[11] FCDD [27] MKD [37] DRAEM[52]</td><td>Ours</td></tr><tr><td rowspan=\"6\">Object</td><td rowspan=\"10\">Cable Capsule Hazelnut Metal Nut Pill</td><td>67.9 /97.8 78.3 /91.9</td><td>86.7 /98.1 62.2 /96.8</td><td>96.1/ 98.2 81.0 /96.7</td><td>56.0 /97</td><td>91.8 / 96.3</td><td>87.6 / 99.1</td><td>[98.1 ± 0.04 / 98.1</td></tr><tr><td></td><td></td><td></td><td>64.1/90</td><td>89.3 /82.4</td><td>71.3 /94.7</td><td>97.3 ± 0.10 / 96.8</td></tr><tr><td>85.5 /96.8</td><td>83.1/95.8</td><td>96.9 /98.6</td><td>67.6 /93</td><td>88.3 / 95.9</td><td>50.5 / 94.3</td><td>98.5 ± 0.01 / 97.9</td></tr><tr><td>93.7 /98.2</td><td>97.4 /97.5</td><td>96.3 / 98.1</td><td>79.3 /95</td><td>91.2 /94.6</td><td>96.9 /99.7</td><td>98.1 ± 0.10 / 98.8</td></tr><tr><td>76.6/97.2</td><td>96.0 / 98.0</td><td>84.8 /97.3</td><td>57.5 /94</td><td>64.2 /86.4</td><td>62.2 /99.5</td><td>94.8 ± 0.09 / 95.7</td></tr><tr><td>80.3/96.5</td><td>96.5 / 95.1</td><td>87.7 /95.7</td><td>65.9 /81</td><td>69.7 / 89.6</td><td>94.4 /97.6</td><td>95.0 ± 0.16 / 95.1</td></tr><tr><td>Screw 90.8/97.4</td><td>74.3 /95.7</td><td>94.1/ 98.4</td><td>67.2/86</td><td>92.1/96.0</td><td>95.5 /97.6</td><td>98.3 ± 0.08 / 97.4</td></tr><tr><td>Toothbrush 86.9 / 97.9</td><td>98.0 /98.1</td><td>95.6 /98.8</td><td>60.8 /94</td><td>88.9 /96.1</td><td>97.7/98.1</td><td>98.4 ± 0.03 / 97.8</td></tr><tr><td>Transistor 68.3/ 73.7</td><td>78.5/97.0</td><td>92.3/97.6</td><td>54.2/88</td><td>71.7 /76.5</td><td>64.5 /90.9</td><td>97.9 ± 0.19 / 98.7</td></tr><tr><td>Zipper 84.2/95.6</td><td>95.1 /95.1</td><td>94.8 / 98.4</td><td>63.0 /92</td><td>86.1/93.9</td><td>98.3 / 98.8</td><td>96.8 ± 0.24 / 96.0</td></tr><tr><td rowspan=\"4\">Texture</td><td>Carpet Grid</td><td>88.7 /93.5 78.6 / 92.6</td><td>97.6 / 99.0</td><td>68.6/96</td><td>95.5 / 95.6</td><td>98.6 / 95.5</td><td>98.5±0.01/98.0</td></tr><tr><td>Leather</td><td>64.5 /89.9</td><td>70.8/96.2 71.0 / 97.1</td><td>65.8 /91</td><td>82.3 /91.8</td><td>98.7 / 99.7</td><td>96.5 ± 0.04 / 94.6</td></tr><tr><td>Tile</td><td>95.4 /97.8 93.5 / 97.4</td><td>84.8 /99.0</td><td>66.3 /98</td><td>96.7 /98.1</td><td>97.3 /98.6</td><td>98.8 ± 0.03 / 98.3</td></tr><tr><td>Wood</td><td>82.7 /92.5 92.1 / 91.4</td><td>80.5 /94.1</td><td>59.3 /91</td><td>85.3 /82.8</td><td>98.0 / 99.2</td><td>91.8 ± 0.10 / 91.8</td></tr><tr><td colspan=\"2\">Mean</td><td>83.3 / 92.1 81.8 /93.9</td><td>80.7 /90.8 85.6/95.7</td><td>89.1 /94.1 89.5 / 97.4</td><td>53.3 /88 63.3/92</td><td>80.5 /84.8 84.9 /90.7</td><td>96.0 / 96.4 87.2 / 97.3</td><td>93.2 ± 0.08 / 93.4 [96.8 ± 0.02 / 96.6</td></tr><tr><td colspan=\"8\">Normal Anomaly Recon GT Pred Normal Anomaly Recon 9 (b)</td><td>GT Pred</td></tr><tr><td colspan=\"2\">(a)</td><td colspan=\"6\">800</td><td></td></tr><tr><td colspan=\"2\">(c)</td><td colspan=\"6\"></td></tr></table>",
749
+ "bbox": [
750
+ 173,
751
+ 142,
752
+ 826,
753
+ 500
754
+ ],
755
+ "page_idx": 7
756
+ },
757
+ {
758
+ "type": "text",
759
+ "text": "4.3 Anomaly localization on MVTec-AD ",
760
+ "text_level": 1,
761
+ "bbox": [
762
+ 176,
763
+ 553,
764
+ 465,
765
+ 568
766
+ ],
767
+ "page_idx": 7
768
+ },
769
+ {
770
+ "type": "text",
771
+ "text": "Setup and baselines. Anomaly localization aims to localize anomalous regions in an anomalous image. MVTec-AD [4] is chosen as the benchmark dataset. The setup is the same as that in Sec. 4.2. Besides the competitors in Sec. 4.2, FCDD [27] is included, whose metric under the separate case is reported in its paper. Under the unified case, we run FCDD with the implementation: FCDD. ",
772
+ "bbox": [
773
+ 174,
774
+ 578,
775
+ 825,
776
+ 633
777
+ ],
778
+ "page_idx": 7
779
+ },
780
+ {
781
+ "type": "text",
782
+ "text": "Quantitative results of anomaly localization on MVTec-AD [4] are reported in Tab. 2. Similar to Sec. 4.2, switching from the separate case to the unified case, the performance of all competitors drops significantly. For example, the performance of US, an important distillation-based baseline, decreases by $1 2 . 1 \\%$ . FCDD, a pseudo-anomaly approach, suffers from a dramatic drop of $2 8 . 7 \\%$ , reflecting the pseudo-anomaly is not suitable for the unified case. However, our UniAD even gains a slight improvement from the separate case $( 9 6 . 6 \\% )$ to the unified case $( 9 6 . 8 \\% )$ , proving the suitability of our UniAD for the unified case. Moreover, we significantly surpass the strongest baseline, PaDiM, by $7 . 3 \\%$ . This significant improvement reflects the effectiveness of our model. ",
783
+ "bbox": [
784
+ 174,
785
+ 640,
786
+ 825,
787
+ 751
788
+ ],
789
+ "page_idx": 7
790
+ },
791
+ {
792
+ "type": "text",
793
+ "text": "Qualitative results for anomaly localization on MVTec-AD [4] are illustrated in Fig. 6. For both global (Fig. 6a) and local (Fig. 6b) structural anomalies, both scattered texture perturbations (Fig. 6c) and multiple texture scratches (Fig. 6d), our method could successfully reconstruct anomalies to their corresponding normal samples, then accurately localize anomalous regions through reconstruction differences. More qualitative results are given in Appendix. ",
794
+ "bbox": [
795
+ 174,
796
+ 757,
797
+ 825,
798
+ 828
799
+ ],
800
+ "page_idx": 7
801
+ },
802
+ {
803
+ "type": "text",
804
+ "text": "4.4 Anomaly detection on CIFAR-10 ",
805
+ "text_level": 1,
806
+ "bbox": [
807
+ 176,
808
+ 843,
809
+ 441,
810
+ 858
811
+ ],
812
+ "page_idx": 7
813
+ },
814
+ {
815
+ "type": "text",
816
+ "text": "Setup. To further verify the effectiveness of our UniAD, we extend CIFAR-10 [23] to the unified case, which consists of four combinations. For each combination, five categories together serve as normal samples, while other categories are viewed as anomalies. The class indices of the four combinations are $\\lbrace 0 1 2 3 4 \\rbrace$ , $\\{ 5 6 7 8 9 \\}$ , $\\{ 0 2 4 6 8 \\}$ , $\\lbrace 1 3 5 7 9 \\rbrace$ . Here, $\\lbrace 0 1 2 3 4 \\rbrace$ means the normal samples include images from class $0 , 1 , 2 , 3 , 4$ , and similar for others. Note that the class index is obtained by sorting the class names of 10 classes. The setup of the model is detailed in Appendix. ",
817
+ "bbox": [
818
+ 174,
819
+ 869,
820
+ 825,
821
+ 911
822
+ ],
823
+ "page_idx": 7
824
+ },
825
+ {
826
+ "type": "table",
827
+ "img_path": "images/a87cf437af883ed380b23589e661234a69dd41ef032747df3e0fe2b27bd6b10a.jpg",
828
+ "table_caption": [
829
+ "Table 3: Anomaly detection results with AUROC metric on CIFAR-10 [23] under the unified case. Here, $\\lbrace 0 1 2 3 4 \\rbrace$ means samples from class $0 , 1 , 2 , 3 , 4$ are borrowed as the normal ones. "
830
+ ],
831
+ "table_footnote": [],
832
+ "table_body": "<table><tr><td>Normal Indices</td><td>US [6]</td><td>FCDD [27]</td><td>FCDD+OE [27]</td><td>PANDA [33]</td><td>MKD [37]</td><td>Ours</td></tr><tr><td>{01234}</td><td>51.3</td><td>55.0</td><td>71.8</td><td>66.6</td><td>64.2</td><td>84.4 ± 0.02</td></tr><tr><td>{56789}</td><td>51.3</td><td>50.3</td><td>73.7</td><td>73.2</td><td>69.3</td><td>80.9 ± 0.02</td></tr><tr><td>{02468}</td><td>63.9</td><td>59.2</td><td>85.3</td><td>77.1</td><td>76.4</td><td>93.0 ± 0.03</td></tr><tr><td>{13579}</td><td>56.8</td><td>58.5</td><td>85.0</td><td>72.9</td><td>78.7</td><td>90.6 ± 0.09</td></tr><tr><td>Mean</td><td>55.9</td><td>55.8</td><td>78.9</td><td>72.4</td><td>72.1</td><td>87.2 ± 0.03</td></tr></table>",
833
+ "bbox": [
834
+ 176,
835
+ 127,
836
+ 821,
837
+ 226
838
+ ],
839
+ "page_idx": 8
840
+ },
841
+ {
842
+ "type": "table",
843
+ "img_path": "images/c29015b65dc59b3aae9574a5308081b062cb45e6b8a37a81351334a6d41fdbed.jpg",
844
+ "table_caption": [
845
+ "Table 4: Performance comparison and architecture comparison between UniAD and transformerbased competitors on MVTec-AD [4]. All methods are evaluated under the unified / separate case. "
846
+ ],
847
+ "table_footnote": [],
848
+ "table_body": "<table><tr><td>Method</td><td>Det.</td><td>Loc.</td><td>1 query</td><td>Layer-wise query</td></tr><tr><td>InTra [31]</td><td>65.3/95.0</td><td>70.6 /96.6</td><td>X</td><td>X</td></tr><tr><td>VT-ADL [28]</td><td>55.4/ 78.7</td><td>64.4/ 82.0</td><td>X</td><td>×</td></tr><tr><td>AnoVit [50]</td><td>69.6/78</td><td>68.4/ 83</td><td>X</td><td>×</td></tr><tr><td>Ours (baseline)</td><td>87.6 / 94.7</td><td>92.8 / 95.8</td><td>√</td><td></td></tr><tr><td>Ours</td><td>96.5 / 96.6</td><td>96.8 / 96.6</td><td>×</td><td>X</td></tr></table>",
849
+ "bbox": [
850
+ 189,
851
+ 262,
852
+ 810,
853
+ 361
854
+ ],
855
+ "page_idx": 8
856
+ },
857
+ {
858
+ "type": "text",
859
+ "text": "",
860
+ "bbox": [
861
+ 176,
862
+ 377,
863
+ 821,
864
+ 419
865
+ ],
866
+ "page_idx": 8
867
+ },
868
+ {
869
+ "type": "text",
870
+ "text": "Baselines. US [6], FCDD [27], $\\mathrm { F C D D + O E }$ [27], PANDA [33], and MKD [37] serve as competitors. \nUS, FCDD, FCDD+OE, PANDA, and MKD are run with the publicly available implementations. ",
871
+ "bbox": [
872
+ 174,
873
+ 425,
874
+ 823,
875
+ 454
876
+ ],
877
+ "page_idx": 8
878
+ },
879
+ {
880
+ "type": "text",
881
+ "text": "Quantitative results of anomaly detection on CIFAR-10 [23] are shown in Tab. 3. When five classes together serve as normal samples, two recent baselines, US and FCDD, almost lose their ability to detect anomalies. When utilizing 10000 images sampled from CIFAR-100 [23] as auxiliary Outlier Exposure (OE), $\\mathrm { F C D D + O E }$ improves the performance by a large margin. We still stably outperform FCDD $\\mathsf { \\Pi } + \\mathsf { O E }$ by $8 . 3 \\%$ without the help of OE, indicating the efficacy of our UniAD. ",
882
+ "bbox": [
883
+ 174,
884
+ 459,
885
+ 825,
886
+ 530
887
+ ],
888
+ "page_idx": 8
889
+ },
890
+ {
891
+ "type": "text",
892
+ "text": "4.5 Comparison with transformer-based competitors ",
893
+ "text_level": 1,
894
+ "bbox": [
895
+ 174,
896
+ 549,
897
+ 553,
898
+ 563
899
+ ],
900
+ "page_idx": 8
901
+ },
902
+ {
903
+ "type": "text",
904
+ "text": "As described in Sec. 2, some attempts [31, 28, 50] also try to utilize transformer for anomaly detection. Here we compare our UniAD with existing transformer-based competitors on MVTec-AD [4]. Recall that, we choose transformer as the reconstruction model considering its great potential in preventing the model from learning the “identical shortcut” (refer to Sec. 3.1). Concretely, we find that the learnable query embedding is essential for avoiding such a shortcut but is seldom explored in existing transformer-based approaches. As shown in Tab. 4, after introducing even only one query embedding, our baseline already outperforms existing alternatives by a sufficiently large margin in the unified setting. Our proposed three components further improve our strong baseline. Recall that all three components are proposed to avoid the model from directly outputting the inputs. ",
905
+ "bbox": [
906
+ 174,
907
+ 574,
908
+ 825,
909
+ 699
910
+ ],
911
+ "page_idx": 8
912
+ },
913
+ {
914
+ "type": "text",
915
+ "text": "4.6 Ablation studies ",
916
+ "text_level": 1,
917
+ "bbox": [
918
+ 174,
919
+ 719,
920
+ 325,
921
+ 733
922
+ ],
923
+ "page_idx": 8
924
+ },
925
+ {
926
+ "type": "text",
927
+ "text": "To verify the effectiveness of the proposed modules and the selection of hyperparameters, we implement extensive ablation studies on MVTec-AD [4] under the unified case. ",
928
+ "bbox": [
929
+ 174,
930
+ 746,
931
+ 821,
932
+ 773
933
+ ],
934
+ "page_idx": 8
935
+ },
936
+ {
937
+ "type": "text",
938
+ "text": "Layer-wise query. Tab. 5a verifies our assertion that the query embedding is of vital significance. 1) Without query embedding, meaning the encoder embeddings are directly input to the decoder, the performance is the worst. 2) Adding only one query embedding to the first decoder layer (i.e., vanilla transformer [42]) promotes the performance dramatically by $1 8 . 1 \\%$ and $1 3 . 4 \\%$ in anomaly detection and localization, respectively. 3) With layer-wise query embedding in each decoder layer, image-level and pixel-level AUROC is further improved by $7 . 4 \\%$ and $3 . 7 \\%$ , respectively. ",
939
+ "bbox": [
940
+ 174,
941
+ 779,
942
+ 825,
943
+ 863
944
+ ],
945
+ "page_idx": 8
946
+ },
947
+ {
948
+ "type": "text",
949
+ "text": "Layer number. We conduct experiments to investigate the influence of layer number, as shown in Tab. 5b. 1) No matter with which combination, our model outperforms vanilla transformer by a large margin, reflecting the effectiveness of our design. 2) The best performance is achieved with a moderate layer number: $4 { \\mathrm { E n c } } + 4 { \\mathrm { D e c } }$ . A larger layer number like 6Enc+6Dec does not bring further promotion, which may be because more layers are harder to train. ",
950
+ "bbox": [
951
+ 176,
952
+ 869,
953
+ 823,
954
+ 911
955
+ ],
956
+ "page_idx": 8
957
+ },
958
+ {
959
+ "type": "table",
960
+ "img_path": "images/f69f201920fd8e9fb2aa8ea9ad167890595e23ce52f7b2387f7275199070ddc6.jpg",
961
+ "table_caption": [
962
+ "Table 5: Ablation studies with AUROC metric on MVTec-AD [4]. Default settings are in blue. (a) Layer-wise query, NMA, & FJ (b) Layer Number of Encoder & Decoder "
963
+ ],
964
+ "table_footnote": [],
965
+ "table_body": "<table><tr><td>w/o q.</td><td>1q</td><td>Layer-wise q.</td><td>NMA</td><td>FJ</td><td>Det.</td><td>Loc.</td><td colspan=\"2\"></td><td>Vanilla [42]</td><td colspan=\"2\">Loc.</td><td>Ours</td></tr><tr><td>√</td><td>-</td><td></td><td>=</td><td></td><td>69.5</td><td>79.4</td><td colspan=\"2\">#Enc,#Dec</td><td colspan=\"2\">Det.</td><td>Det.</td><td>Loc.</td></tr><tr><td></td><td>【</td><td></td><td></td><td></td><td>87.6</td><td>92.8</td><td colspan=\"2\">4,0</td><td>69.8</td><td>79.2</td><td>94.9</td><td>96.0</td></tr><tr><td>=</td><td></td><td>√</td><td>=</td><td></td><td>95.0</td><td>96.5</td><td colspan=\"2\">0,4</td><td>80.5</td><td>88.3</td><td>96.1</td><td>96.3</td></tr><tr><td></td><td></td><td>1</td><td>【</td><td></td><td>96.1</td><td>96.3</td><td colspan=\"2\">2,2</td><td>84.7</td><td>90.6</td><td>95.1</td><td>96.0</td></tr><tr><td></td><td></td><td></td><td></td><td>!</td><td>95.0</td><td>95.8</td><td colspan=\"2\">4,4</td><td>87.6</td><td>92.8</td><td>96.5</td><td>96.8</td></tr><tr><td>=</td><td>-</td><td>√</td><td>√</td><td>【</td><td>96.5</td><td>96.8</td><td colspan=\"2\">6,6</td><td>86.1</td><td>91.9</td><td>96.5</td><td>96.7</td></tr><tr><td colspan=\"2\">(c) Neighbor Size in NMA</td><td></td><td colspan=\"3\">(d) Where to Add NMA</td><td colspan=\"3\">(e) Jitter Scale α in FJ</td><td colspan=\"3\">(f) Jitter Prob.</td><td>p inFJ</td></tr><tr><td>Size</td><td>Det.</td><td>Loc.</td><td>Place</td><td>Det.</td><td>Loc.</td><td>a</td><td>Det.</td><td>Loc.</td><td></td><td>p</td><td>Det.</td><td>Loc.</td></tr><tr><td>1×1</td><td>94.6</td><td>96.3</td><td>Enc</td><td>95.8</td><td>96.3</td><td></td><td>5 96.1</td><td>96.7</td><td></td><td>0.25</td><td>95.6</td><td>96.5</td></tr><tr><td>5×5</td><td>96.4</td><td>96.8</td><td>Enc+Dec1</td><td>96.4</td><td>96.8</td><td></td><td>10 96.4</td><td>96.7</td><td></td><td>0.50</td><td>95.8</td><td>96.7</td></tr><tr><td>7x7</td><td>96.5</td><td>96.8</td><td>Enc+Dec2</td><td>96.5</td><td>96.7</td><td></td><td>20 96.5</td><td>96.8</td><td></td><td>0.75</td><td>96.3</td><td>96.7</td></tr><tr><td>9×9</td><td>96.3</td><td>96.7</td><td>All </td><td>96.5</td><td>96.8</td><td></td><td>30 95.7</td><td>96.6</td><td></td><td>1</td><td>96.5</td><td>96.8</td></tr></table>",
966
+ "bbox": [
967
+ 181,
968
+ 122,
969
+ 821,
970
+ 324
971
+ ],
972
+ "page_idx": 9
973
+ },
974
+ {
975
+ "type": "text",
976
+ "text": "",
977
+ "bbox": [
978
+ 173,
979
+ 330,
980
+ 821,
981
+ 358
982
+ ],
983
+ "page_idx": 9
984
+ },
985
+ {
986
+ "type": "text",
987
+ "text": "Neighbor masked attention. 1) The effectiveness of NMA is proven in Tab. 5a. Under the case of one query embedding, adding NMA brings promotion by $8 . 5 \\%$ for detection and $3 . 5 \\%$ for localization. 2) The neighbor size of NMA is selected in Tab. 5c. $1 \\times 1$ neighbor size is the worst, because $1 \\times 1$ is too small to prevent the information leak, thus the recovery could be completed by copying neighbor regions. A larger neighbor size $( \\geq 5 { \\times } 5 )$ is obviously much better, and the best one is selected as $7 \\times 7$ . 3) We also study the place to add NMA in Tab. 5d. Only adding NMA in the encoder (Enc) is not enough. The performance could be stably improved when further adding NMA in the first or second attention in the decoder $\\mathbf { E n c + D e c l }$ , $_ \\mathrm { E n c + D e c } 2$ ) or both (All). This reflects that the full attention of the decoder also contributes to the information leak. ",
988
+ "bbox": [
989
+ 173,
990
+ 364,
991
+ 826,
992
+ 489
993
+ ],
994
+ "page_idx": 9
995
+ },
996
+ {
997
+ "type": "text",
998
+ "text": "Feature jittering. 1) Tab. 5a confirms the efficacy of FJ. With one query embedding as the baseline, introducing FJ could bring an increase of $7 . 4 \\%$ for detection and $3 . 0 \\%$ for localization, respectively. 2) According to Tab. 5e, the jittering scale, $\\alpha$ , is chosen as 20. A larger $\\alpha$ (i.e., 30) disturbs the feature too much, degrading the results. 3) In Tab. 5f, the jittering probability, $p$ , is studied. In essence, the task would be a denoising task with feature jittering, and be a reconstruction task without feature jittering. The results show that the full denoising task (i.e., $p = 1$ ) is the best. ",
999
+ "bbox": [
1000
+ 174,
1001
+ 496,
1002
+ 825,
1003
+ 579
1004
+ ],
1005
+ "page_idx": 9
1006
+ },
1007
+ {
1008
+ "type": "text",
1009
+ "text": "5 Conclusion ",
1010
+ "text_level": 1,
1011
+ "bbox": [
1012
+ 174,
1013
+ 598,
1014
+ 299,
1015
+ 614
1016
+ ],
1017
+ "page_idx": 9
1018
+ },
1019
+ {
1020
+ "type": "text",
1021
+ "text": "In this work, we propose UniAD that unifies anomaly detection regarding multiple classes. For such a challenging task, we assist the model against learning an “identical shortcut” with three improvements. First, we confirm the effectiveness of the learnable query embedding and carefully tailor a layer-wise query decoder to help model the complex distribution of multi-class data. Second, we come up with a neighbor masked attention module to avoid the information leak from the input to the output. Third, we propose feature jittering that helps the model less sensitive to the input perturbations. Under the unified task setting, our method achieves state-of-the-art performance on MVTec-AD and CIFAR-10 datasets, significantly outperforming existing alternatives. ",
1022
+ "bbox": [
1023
+ 174,
1024
+ 628,
1025
+ 825,
1026
+ 739
1027
+ ],
1028
+ "page_idx": 9
1029
+ },
1030
+ {
1031
+ "type": "text",
1032
+ "text": "Discussion. In this work, different kinds of objects are handled without being distinguished. We have not used the category labels that may help the model better fit multi-class data. How to incorporate the unified model with category labels should be further studied. In practical uses, normal samples are not as consistent as those in MVTec-AD, often manifest themselves in some diversity. Our UniAD could handle all 15 categories in MVTec-AD, hence would be more suitable for real scenes. However, anomaly detection may be used for video surveillance, which may infringe personal privacy. ",
1033
+ "bbox": [
1034
+ 174,
1035
+ 746,
1036
+ 825,
1037
+ 829
1038
+ ],
1039
+ "page_idx": 9
1040
+ },
1041
+ {
1042
+ "type": "text",
1043
+ "text": "Acknowledgments and Disclosure of Funding ",
1044
+ "text_level": 1,
1045
+ "bbox": [
1046
+ 174,
1047
+ 848,
1048
+ 555,
1049
+ 866
1050
+ ],
1051
+ "page_idx": 9
1052
+ },
1053
+ {
1054
+ "type": "text",
1055
+ "text": "Acknowledgement. This work is sponsored by the National Key Research and Development Program of China (2021YFB1716000) and National Natural Science Foundation of China (62176152). ",
1056
+ "bbox": [
1057
+ 174,
1058
+ 883,
1059
+ 823,
1060
+ 911
1061
+ ],
1062
+ "page_idx": 9
1063
+ },
1064
+ {
1065
+ "type": "text",
1066
+ "text": "References \n[1] F. Ahmed and A. Courville. Detecting semantic anomalies. In Assoc. Adv. Artif. Intell., 2020. \n[2] S. Akcay, A. Atapour-Abarghouei, and T. P. Breckon. GANomaly: Semi-supervised anomaly detection via adversarial training. In Asian Conf. Comput. Vis., 2018. \n[3] Y. Bengio, L. Yao, G. Alain, and P. Vincent. Generalized denoising auto-encoders as generative models. In Adv. Neural Inform. Process. Syst., 2013. \n[4] P. Bergmann, M. Fauser, D. Sattlegger, and C. Steger. MVTec AD–A comprehensive real-world dataset for unsupervised anomaly detection. In IEEE Conf. Comput. Vis. Pattern Recog., 2019. \n[5] P. Bergmann, S. Löwe, M. Fauser, D. Sattlegger, and C. Steger. Improving unsupervised defect segmentation by applying structural similarity to autoencoders. In International Joint Conference on Computer Vision, Imaging and Computer Graphics Theory and Applications (VISIGRAPP), 2019. \n[6] P. Bergmann, M. Fauser, D. Sattlegger, and C. Steger. Uninformed students: Student-teacher anomaly detection with discriminative latent embeddings. In IEEE Conf. Comput. Vis. Pattern Recog., 2020. \n[7] N. Carion, F. Massa, G. Synnaeve, N. Usunier, A. Kirillov, and S. Zagoruyko. End-to-end object detection with transformers. In Eur. Conf. Comput. Vis., 2020. \n[8] L. Chen, Z. You, N. Zhang, J. Xi, and X. Le. UTRAD: Anomaly detection and localization with Utransformer. Neural Networks, 2022. \n[9] A.-S. Collin and C. De Vleeschouwer. Improved anomaly detection by training an autoencoder with skip connections on images corrupted with stain-shaped noise. In Int. Conf. Pattern Recog., 2021. \n[10] L. Deecke, L. Ruff, R. A. Vandermeulen, and H. Bilen. Transfer-based semantic anomaly detection. In Int. Conf. Mach. Learn., 2021. \n[11] T. Defard, A. Setkov, A. Loesch, and R. Audigier. PaDim: A patch distribution modeling framework for anomaly detection and localization. In Int. Conf. Pattern Recog., 2021. \n[12] D. Dehaene, O. Frigo, S. Combrexelle, and P. Eline. Iterative energy-based projection on a normal data manifold for anomaly localization. In Int. Conf. Learn. Represent., 2019. \n[13] H. Deng and X. Li. Anomaly detection via reverse distillation from one-class embedding. In IEEE Conf. Comput. Vis. Pattern Recog., 2022. \n[14] J. Deng, W. Dong, R. Socher, L.-J. Li, K. Li, and L. Fei-Fei. ImageNet: A large-scale hierarchical image database. In IEEE Conf. Comput. Vis. Pattern Recog., 2009. \n[15] J. Devlin, M.-W. Chang, K. Lee, and K. Toutanova. Bert: Pre-training of deep bidirectional transformers for language understanding. arXiv preprint arXiv:1810.04805, 2018. \n[16] A. Dosovitskiy, L. Beyer, A. Kolesnikov, D. Weissenborn, X. Zhai, T. Unterthiner, M. Dehghani, M. Minderer, G. Heigold, S. Gelly, et al. An image is worth 16x16 words: Transformers for image recognition at scale. In Int. Conf. Learn. Represent., 2021. \n[17] T. Fernando, H. Gammulle, S. Denman, S. Sridharan, and C. Fookes. Deep learning for medical anomaly detection–a survey. ACM Computing Surveys (CSUR), 2021. \n[18] I. Golan and R. El-Yaniv. Deep anomaly detection using geometric transformations. In Adv. Neural Inform. Process. Syst., 2018. \n[19] D. Gong, L. Liu, V. Le, B. Saha, M. R. Mansour, S. Venkatesh, and A. v. d. Hengel. Memorizing normality to detect anomaly: Memory-augmented deep autoencoder for unsupervised anomaly detection. In Int. Conf. Comput. Vis., 2019. \n[20] J. Hou, Y. Zhang, Q. Zhong, D. Xie, S. Pu, and H. Zhou. Divide-and-assemble: Learning block-wise memory for unsupervised anomaly detection. In Int. Conf. Comput. Vis., 2021. \n[21] L. Ilya and H. Frank. Decoupled weight decay regularization. In Int. Conf. Learn. Represent., 2019. \n[22] D. P. Kingma and M. Welling. Auto-encoding variational bayes. arXiv preprint arXiv:1312.6114, 2013. \n[23] A. Krizhevsky. Learning multiple layers of features from tiny images. Master’s thesis, University of Tront, 2009. \n[24] G. Kwon, M. Prabhushankar, D. Temel, and G. AlRegib. Backpropagated gradient representations for anomaly detection. In Eur. Conf. Comput. Vis., 2020. \n[25] C.-L. Li, K. Sohn, J. Yoon, and T. Pfister. CutPaste: Self-supervised learning for anomaly detection and localization. In IEEE Conf. Comput. Vis. Pattern Recog., 2021. \n[26] W. Liu, R. Li, M. Zheng, S. Karanam, Z. Wu, B. Bhanu, R. J. Radke, and O. Camps. Towards visually explaining variational autoencoders. In IEEE Conf. Comput. Vis. Pattern Recog., 2020. \n[27] P. Liznerski, L. Ruff, R. A. Vandermeulen, B. J. Franks, M. Kloft, and K.-R. Müller. Explainable deep one-class classification. In Int. Conf. Learn. Represent., 2021. \n[28] P. Mishra, R. Verk, D. Fornasier, C. Piciarelli, and G. L. Foresti. VT-ADL: A vision transformer network for image anomaly detection and localization. In International Symposium on Industrial Electronics, 2021. \n[29] H. Park, J. Noh, and B. Ham. Learning memory-guided normality for anomaly detection. In IEEE Conf. Comput. Vis. Pattern Recog., 2020. \n[30] P. Perera, R. Nallapati, and B. Xiang. OCGAN: One-class novelty detection using GANs with constrained latent representations. In IEEE Conf. Comput. Vis. Pattern Recog., 2019. \n[31] J. Pirnay and K. Chai. Inpainting transformer for anomaly detection. arXiv preprint arXiv:2104.13897, 2021. \n[32] M. Pourreza, B. Mohammadi, M. Khaki, S. Bouindour, H. Snoussi, and M. Sabokrou. G2D: generate to detect anomaly. In IEEE Winter Conf. Appl. Comput. Vis., 2021. \n[33] T. Reiss, N. Cohen, L. Bergman, and Y. Hoshen. Panda: Adapting pretrained features for anomaly detection and segmentation. In IEEE Conf. Comput. Vis. Pattern Recog., 2021. \n[34] O. Rippel, P. Mertens, and D. Merhof. Modeling the distribution of normal data in pretrained deep features for anomaly detection. In Int. Conf. Pattern Recog., 2021. \n[35] L. Ruff, R. Vandermeulen, N. Goernitz, L. Deecke, S. A. Siddiqui, A. Binder, E. Müller, and M. Kloft. Deep one-class classification. In Int. Conf. Mach. Learn., 2018. \n[36] M. Sabokrou, M. Khalooei, M. Fathy, and E. Adeli. Adversarially learned one-class classifier for novelty detection. In IEEE Conf. Comput. Vis. Pattern Recog., 2018. \n[37] M. Salehi, N. Sadjadi, S. Baselizadeh, M. H. Rohban, and H. R. Rabiee. Multiresolution knowledge distillation for anomaly detection. In IEEE Conf. Comput. Vis. Pattern Recog., 2021. \n[38] B. Schölkopf, J. C. Platt, J. Shawe-Taylor, A. J. Smola, and R. C. Williamson. Estimating the support of a high-dimensional distribution. Neural Computation, 2001. \n[39] Y. Shi, J. Yang, and Z. Qi. Unsupervised anomaly segmentation via deep feature reconstruction. Neurocomputing, 2021. \n[40] M. Tan and Q. Le. EfficientNet: Rethinking model scaling for convolutional neural networks. In Int. Conf. Mach. Learn., 2019. \n[41] D. M. Tax and R. P. Duin. Support vector data description. Machine Learning, 2004. \n[42] A. Vaswani, N. Shazeer, N. Parmar, J. Uszkoreit, L. Jones, A. N. Gomez, Ł. Kaiser, and I. Polosukhin. Attention is all you need. In Adv. Neural Inform. Process. Syst., 2017. \n[43] P. Vincent, H. Larochelle, Y. Bengio, and P.-A. Manzagol. Extracting and composing robust features with denoising autoencoders. In Int. Conf. Mach. Learn., 2008. \n[44] G. Wang, S. Han, E. Ding, and D. Huang. Student-teacher feature pyramid matching for anomaly detection. Brit. Mach. Vis. Conf., 2021. \n[45] S. Wang, L. Wu, L. Cui, and Y. Shen. Glancing at the patch: Anomaly localization with global and local feature comparison. In IEEE Conf. Comput. Vis. Pattern Recog., 2021. \n[46] Y. Xia, Y. Zhang, F. Liu, W. Shen, and A. L. Yuille. Synthesize then compare: Detecting failures and anomalies for semantic segmentation. In Eur. Conf. Comput. Vis., 2020. \n[47] X. Yan, H. Zhang, X. Xu, X. Hu, and P.-A. Heng. Learning semantic context from normal samples for unsupervised anomaly detection. In Assoc. Adv. Artif. Intell., 2021. \n[48] J. Yi and S. Yoon. Patch SVDD: Patch-level SVDD for anomaly detection and segmentation. In Asian Conf. Comput. Vis., 2020. \n[49] Z. You, K. Yang, W. Luo, L. Cui, Y. Zheng, and X. Le. ADTR: Anomaly detection transformer with feature reconstruction. arXiv preprint arXiv:2209.01816, 2022. \n[50] L. Yunseung and K. Pilsung. AnoViT: Unsupervised anomaly detection and localization with vision transformer-based encoder-decoder. arXiv preprint arXiv:2203.10808, 2022. \n[51] M. Z. Zaheer, J.-h. Lee, M. Astrid, and S.-I. Lee. Old is gold: Redefining the adversarially learned one-class classifier training paradigm. In IEEE Conf. Comput. Vis. Pattern Recog., 2020. \n[52] V. Zavrtanik, M. Kristan, and D. Skocaj. DRAEM-A discriminatively trained reconstruction embedding ˇ for surface anomaly detection. In Int. Conf. Comput. Vis., 2021. \n[53] K. Zhou, Y. Xiao, J. Yang, J. Cheng, W. Liu, W. Luo, Z. Gu, J. Liu, and S. Gao. Encoding structure-texture relation with P-Net for anomaly detection in retinal images. In Eur. Conf. Comput. Vis., 2020. ",
1067
+ "bbox": [
1068
+ 171,
1069
+ 88,
1070
+ 828,
1071
+ 917
1072
+ ],
1073
+ "page_idx": 10
1074
+ },
1075
+ {
1076
+ "type": "text",
1077
+ "text": "",
1078
+ "bbox": [
1079
+ 171,
1080
+ 83,
1081
+ 830,
1082
+ 916
1083
+ ],
1084
+ "page_idx": 11
1085
+ },
1086
+ {
1087
+ "type": "text",
1088
+ "text": "",
1089
+ "bbox": [
1090
+ 171,
1091
+ 92,
1092
+ 826,
1093
+ 299
1094
+ ],
1095
+ "page_idx": 12
1096
+ },
1097
+ {
1098
+ "type": "text",
1099
+ "text": "Checklist ",
1100
+ "text_level": 1,
1101
+ "bbox": [
1102
+ 174,
1103
+ 324,
1104
+ 254,
1105
+ 340
1106
+ ],
1107
+ "page_idx": 12
1108
+ },
1109
+ {
1110
+ "type": "text",
1111
+ "text": "1. For all authors... ",
1112
+ "bbox": [
1113
+ 214,
1114
+ 352,
1115
+ 339,
1116
+ 366
1117
+ ],
1118
+ "page_idx": 12
1119
+ },
1120
+ {
1121
+ "type": "text",
1122
+ "text": "(a) Do the main claims made in the abstract and introduction accurately reflect the paper’s contributions and scope? [Yes] \n(b) Did you describe the limitations of your work? [Yes] See Discussion in Sec. 5. \n(c) Did you discuss any potential negative societal impacts of your work? [Yes] See Discussion in Sec. 5. \n(d) Have you read the ethics review guidelines and ensured that your paper conforms to them? [Yes] ",
1123
+ "bbox": [
1124
+ 238,
1125
+ 371,
1126
+ 825,
1127
+ 476
1128
+ ],
1129
+ "page_idx": 12
1130
+ },
1131
+ {
1132
+ "type": "text",
1133
+ "text": "2. If you are including theoretical results... ",
1134
+ "bbox": [
1135
+ 214,
1136
+ 479,
1137
+ 493,
1138
+ 494
1139
+ ],
1140
+ "page_idx": 12
1141
+ },
1142
+ {
1143
+ "type": "text",
1144
+ "text": "(a) Did you state the full set of assumptions of all theoretical results? [N/A] (b) Did you include complete proofs of all theoretical results? [N/A] ",
1145
+ "bbox": [
1146
+ 236,
1147
+ 500,
1148
+ 738,
1149
+ 530
1150
+ ],
1151
+ "page_idx": 12
1152
+ },
1153
+ {
1154
+ "type": "text",
1155
+ "text": "3. If you ran experiments... ",
1156
+ "bbox": [
1157
+ 212,
1158
+ 535,
1159
+ 393,
1160
+ 549
1161
+ ],
1162
+ "page_idx": 12
1163
+ },
1164
+ {
1165
+ "type": "text",
1166
+ "text": "(a) Did you include the code, data, and instructions needed to reproduce the main experimental results (either in the supplemental material or as a URL)? [Yes] See Sec. 4 and Appendix. Also, we have released the code. \n(b) Did you specify all the training details (e.g., data splits, hyperparameters, how they were chosen)? [Yes] See Sec. 4.1 & Sec. 4.4 for data splits, and Sec. 4.6 for the choice of hyperparameters. \n(c) Did you report error bars (e.g., with respect to the random seed after running experiments multiple times)? [Yes] See Tab. 1, Tab. 2, and Tab. 3. \n(d) Did you include the total amount of compute and the type of resources used (e.g., type of GPUs, internal cluster, or cloud provider)? [Yes] See Setup in Sec. 4.2. ",
1167
+ "bbox": [
1168
+ 238,
1169
+ 554,
1170
+ 825,
1171
+ 700
1172
+ ],
1173
+ "page_idx": 12
1174
+ },
1175
+ {
1176
+ "type": "text",
1177
+ "text": "4. If you are using existing assets (e.g., code, data, models) or curating/releasing new assets... ",
1178
+ "bbox": [
1179
+ 214,
1180
+ 705,
1181
+ 823,
1182
+ 719
1183
+ ],
1184
+ "page_idx": 12
1185
+ },
1186
+ {
1187
+ "type": "text",
1188
+ "text": "(a) If your work uses existing assets, did you cite the creators? [Yes] See Sec. 4.1 and Baselines in Sec. 4. \n(b) Did you mention the license of the assets? [N/A] \n(c) Did you include any new assets either in the supplemental material or as a URL? [N/A] \n(d) Did you discuss whether and how consent was obtained from people whose data you’re using/curating? [N/A] \n(e) Did you discuss whether the data you are using/curating contains personally identifiable information or offensive content? [N/A] ",
1189
+ "bbox": [
1190
+ 238,
1191
+ 723,
1192
+ 825,
1193
+ 859
1194
+ ],
1195
+ "page_idx": 12
1196
+ },
1197
+ {
1198
+ "type": "text",
1199
+ "text": "5. If you used crowdsourcing or conducted research with human subjects... ",
1200
+ "bbox": [
1201
+ 215,
1202
+ 864,
1203
+ 707,
1204
+ 878
1205
+ ],
1206
+ "page_idx": 12
1207
+ },
1208
+ {
1209
+ "type": "text",
1210
+ "text": "(a) Did you include the full text of instructions given to participants and screenshots, if applicable? [N/A] ",
1211
+ "bbox": [
1212
+ 233,
1213
+ 883,
1214
+ 826,
1215
+ 912
1216
+ ],
1217
+ "page_idx": 12
1218
+ },
1219
+ {
1220
+ "type": "text",
1221
+ "text": "(b) Did you describe any potential participant risks, with links to Institutional Review Board (IRB) approvals, if applicable? [N/A] \n(c) Did you include the estimated hourly wage paid to participants and the total amount spent on participant compensation? [N/A] ",
1222
+ "bbox": [
1223
+ 238,
1224
+ 90,
1225
+ 826,
1226
+ 150
1227
+ ],
1228
+ "page_idx": 13
1229
+ }
1230
+ ]
parse/dev/bMYU8_qD8PW/bMYU8_qD8PW_middle.json ADDED
The diff for this file is too large to render. See raw diff
 
parse/dev/bMYU8_qD8PW/bMYU8_qD8PW_model.json ADDED
The diff for this file is too large to render. See raw diff
 
parse/dev/cpDhcsEDC2/cpDhcsEDC2.md ADDED
@@ -0,0 +1,395 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FILIP: FINE-GRAINED INTERACTIVE LANGUAGEIMAGE PRE-TRAINING
2
+
3
+ Lewei Yao $^ { 1 , 2 \ast }$ Runhui Huang3∗ Lu $\mathbf { H o u } ^ { 1 * }$ Guansong ${ { \bf L } } { \bf u } ^ { 1 }$ Minzhe Niu1 Hang $\mathbf { X } \mathbf { u } ^ { \mathrm { { 1 \dag } } }$ Xiaodan Liang 3† Zhenguo Li1 Xin Jiang1 Chunjing $\mathbf { X } \mathbf { u } ^ { 1 }$ 1Huawei Noah’s Ark Lab, 2Hong Kong University of Science and Technology 3Sun Yat-sen University
4
+
5
+ # ABSTRACT
6
+
7
+ Unsupervised large-scale vision-language pre-training has shown promising advances on various downstream tasks. Existing methods often model the crossmodal interaction either via the similarity of the global feature of each modality which misses sufficient information, or finer-grained interactions using cross/selfattention upon visual and textual tokens. However, cross/self-attention suffers from inferior efficiency in both training and inference. In this paper, we introduce a large-scale Fine-grained Interactive Language-Image Pre-training (FILIP) to achieve finer-level alignment through a cross-modal late interaction mechanism, which uses a token-wise maximum similarity between visual and textual tokens to guide the contrastive objective. FILIP successfully leverages the finergrained expressiveness between image patches and textual words by modifying only contrastive loss, while simultaneously gaining the ability to pre-compute image and text representations offline at inference, keeping both large-scale training and inference efficient. Furthermore, we construct a new large-scale image-text pair dataset called FILIP300M for pre-training. Experiments show that FILIP achieves state-of-the-art performance on multiple downstream vision-language tasks including zero-shot image classification and image-text retrieval. The visualization on word-patch alignment further shows that FILIP can learn meaningful fine-grained features with promising localization ability.
8
+
9
+ # 1 INTRODUCTION
10
+
11
+ Large-scale Vision-Language Pre-training (VLP) models like CLIP (Radford et al., 2021) and ALIGN (Jia et al., 2021) have recently demonstrated success across various downstream tasks. They learn visual and textual representations from millions of image-text pairs collected from the Internet and show superior zero-shot ability and robustness. The core technique of these models lies in the global contrastive alignment of the images and texts through a dual-stream model. Such architecture is inference-efficient for downstream tasks like retrieval because the encoders for the two modalities can be decoupled and the image or text representations can be pre-computed offline. However, CLIP and ALIGN model the cross-modal interaction via solely the similarity of the global feature of each modality, lacking the ability of capturing finer-level information like the relationship between visual objects and textual words. In this paper, we develop a simple yet efficient cross-modal finer-grained interaction mechanism for large-scale VLP.
12
+
13
+ To achieve finer-grained cross-modal interaction, previous methods mainly exploited two kinds of methods. (1) One line of work (Chen et al., 2020; Li et al., 2020b; Dong et al., 2021; Li et al., 2021b; Zhang et al., 2021; Zhan et al., 2021) uses a pre-trained object detector to extract region-of-interest (ROI) features from images, and then fuses it with the paired text through a VLP model. This design complicates the pre-training due to pre-computing and storing a large number of ROI features. In addition, the zero-shot ability of these approaches is usually limited by the predefined number of classes and their performance is also restricted by the quality of the detector. (2) Another line of work (Li et al., 2021a; Kim et al., 2021) enforces the token-wise or patch-wise representations from both modalities into the same space and models these finer-grained interactions via cross-attention (Li et al., 2021a) or self-attention (Kim et al., 2021). However, these methods are usually less efficient in terms of both training and inference. In particular, during training, cross-attention in (Li et al., 2021a) requires to be performed in an encoder-decoder structure, while the complexity of the self-attention (Kim et al., 2021) grows quadratically with the length of the prolonged concatenated sequences of both modalities. During inference, the data from both modalities are intertwined to compute the cross-attention or self-attention, and can not be pre-computed offline as dual-stream models like CLIP and ALIGN. This can be less efficient for downstream tasks like image/text retrieval and image classification.
14
+
15
+ In this paper, we propose a large-scale Fine-grained Interactive Language-Image Pre-training framework named FILIP to address these limitations. Inspired by Khattab & Zaharia (2020), we model the fine-grained semantic alignment through a novel cross-modal late interaction mechanism in the contrastive loss, instead of using cross or self-attention. Specifically, our fine-grained contrastive learning uses a token-wise maximum similarity between visual and textual tokens to guide the contrastive objective. In this way, FILIP successfully leverages the finer-grained expressiveness among image patches and textual words while simultaneously gaining the ability to pre-compute image and text representations offline. Unlike Khattab & Zaharia (2020), we discard the padded tokens and use average instead summation of token-wise maximum similarities when computing the image-text alignment, which enhances the cross-modal representation learning and stabilizes training. Furthermore, we construct a large-scale pre-training dataset named FILIP300M from the Internet. Data cleaning and image-text data augmentation are also explored and proved useful in this work.
16
+
17
+ Extensive experiments show that by effectively learning fine-grained representations, FILIP achieves state-of-the-art performance on multiple downstream tasks, including zero-shot image classification and image-text retrieval. For example, FILIP reaches $7 7 . 1 \%$ top-1 accuracy for zero-shot ImageNet classification, surpassing CLIP with less training data. Visualizations on word-patch alignment further show that FILIP learns meaningful finer-grained features with promising localization ability.
18
+
19
+ # 2 RELATED WORK
20
+
21
+ Vision-Language Pre-training Models. The pre-train-and-fine-tune scheme has achieved great success in the domains of natural language processing (Devlin et al., 2019; Brown et al., 2020) and computer vision (Dosovitskiy et al., 2020). It is then naturally extended to a joint cross-modal domain of Vision-and-Language Pre-training (VLP). The pre-training datasets of recent VLP models include publically available datasets like YFCC100M (Thomee et al., 2016) and CC12M (Changpinyo et al., 2021), as well as larger-scale datasets with more than 100M samples in CLIP (Radford et al., 2021) and ALIGN (Jia et al., 2021), which are shown to be even more powerful. The pretraining tasks of VLP models can be categorized into two categories: image-text contrastive learning task and Language Modeling (LM) based tasks: (i) CLIP (Radford et al., 2021), ALIGN (Jia et al., 2021) and UNIMO (Li et al., 2021b) make use of cross-modal contrastive learning which aligns the textual and visual information into a unified semantic space; (ii) VisualBERT (Li et al., 2019), UNITER (Chen et al., 2020), M6 (Lin et al., 2021), and DALL-E (Ramesh et al., 2021) employ LM-like objectives, including both masked LM (e.g., Masked Language/Region Modeling), and autoregressive LM (e.g., image captioning, text-grounded image generation). On the other hand, some methods rely on a pre-trained object detection model such as Faster-RCNN (Ren et al., 2015) to extract image regional features offline, which requires extra labeled bounding-box data and makes the approach less scalable. Recent efforts such as SOHO (Huang et al., 2021) and SimVLM (Wang et al., 2021) try to eliminate this burden via visual dictionary or PrefixLM (Raffel et al., 2020). In this paper, we directly learn fine-grained vision-language representations in an end-to-end and simpler manner while maintaining the benefit of inference efficiency.
22
+
23
+ Multi-Modality Interaction Mechanism. The core of vision-language pre-training models lies in modeling the interaction between the two modalities. There are mainly two types of cross-modal interaction architectures: Single-stream models like VisualBERT (Li et al., 2019) and ViLT (Kim et al., 2021) directly concatenate the patch-wise or regional visual features and textual embeddings and feed them to the transformer-based model. Dual-stream models such as ViLBERT (Lu et al., 2019) and CLIP (Radford et al., 2021) have separate encoders for different modalities. This allows flexible use of different models for different modalities, and efficient inference for downstream tasks like image-text retrieval, through the ability of decoupling the encoders and pre-compute image/text features offline. SCAN (Lee et al., 2018) considers latent alignments between image regions and words. However, it is based on Triplet loss with a bottom-Up attention via a Faster-RCNN to extract object features while we try to directly learn to localize fine-grained object from patches. In this paper, while following the dual-stream approach for its flexible and efficient inference, we further propose a new multi-modal interaction mechanism to capture the fine-grained representations.
24
+
25
+ ![](images/373e2fb4c6fe425ddf3adfaab03f61e1fbd3367bd06b47ed9be8c6e5665c5685.jpg)
26
+ Figure 1: Overall architecture of FILIP, a dual-stream model with Transformer-based image and text encoders. On top of the image and text encoders, the representations of textual tokens and visual tokens are linearly projected to the multi-modal joint space. A novel fine-grained contrastive learning equipped with cross-modal late interaction is proposed, which uses a token-wise maximum similarity between visual and textual tokens.
27
+
28
+ # 3 METHOD
29
+
30
+ In this paper, we propose a new cross-modal pre-training model that excels in fine-grained interaction between image encoder and text encoder for mining more detailed semantic alignment, named as FILIP, as shown in Figure 1. Particularly, FILIP is a dual-stream model with Transformer-based image and text encoders. For the visual modality, the image encoder is a Vision Transformer (Dosovitskiy et al., 2020) which takes the concatenation of an extra [CLS] token embedding and linearly projected image patches as input. For the textual modality, following Radford et al. (2021), we use the lower-cased byte pair encoding (BPE) (Sennrich et al., 2016b) with a vocabulary size of 49,408 to tokenize the text. Each text sequence starts with [BOS] token and ends with [EOS] token. After the word embedding layer, the token embeddings are fed into a modified decoder-only Transformer model as in (Radford et al., 2019). On top of the image and text encoders, the representations of textual tokens and visual tokens are linearly projected to the multi-modal common space, and are separately L2-normalized. Different from existing dual-stream models (e.g., CLIP and ALIGN) which models cross-modal interaction via only the global features of the entire image and text sequence, we introduce a novel fine-grained contrastive learning objective equipped with cross-modal late interaction which takes into account the fine-grained interaction between image patches and textual tokens, detailed in Section 3.1.
31
+
32
+ # 3.1 FINE-GRAINED CONTRASTIVE LEARNING
33
+
34
+ Contrastive representation learning has recently been found to learn better representations than its predictive counterpart in both visual (Tian et al., 2020) and vision-language cross-modal pre-training (Radford et al., 2021). Under a general formulation of cross-modal contrastive learning (Radford et al., 2021), we want to learn encoders $f _ { \theta }$ for image data $\mathcal { T }$ and $g _ { \phi }$ for text data $\tau$ such that, given an image $\pmb { x } ^ { I } \in \mathcal { I }$ , and a text $\pmb { x } ^ { T } \in \mathcal { T }$ , the encoded representations $f _ { \theta } ( \pmb { x } ^ { I } )$ and $g _ { \phi } ( \pmb { x } ^ { T } )$ are close if they are relateimage-text pairs t if not, und, For image a distance metric. in image-text pair i, g batch, we sample is its positive, whi $b$ $\{ \pmb { x } _ { k } ^ { I } , \pmb { x } _ { k } ^ { T } \} _ { k = 1 } ^ { b ^ { \ast } }$ $\boldsymbol { x } _ { k } ^ { I }$ $\{ x _ { k } ^ { I } , \pmb { x } _ { k } ^ { T } \}$ $\pmb { x } _ { k } ^ { T }$
35
+
36
+ the other texts will be used as in-batch negatives. The image-to-text contrastive loss $\mathcal { L } _ { k } ^ { I }$ for $\pmb { x } _ { k } ^ { I }$ can then be formulated as
37
+
38
+ $$
39
+ \mathcal { L } _ { k } ^ { I } ( \boldsymbol { x } _ { k } ^ { I } , \{ \boldsymbol { x } _ { j } ^ { T } \} _ { j = 1 } ^ { b } ) = - \frac { 1 } { b } \log \frac { e x p ( s _ { k , k } ^ { I } ) } { \sum _ { j } e x p ( s _ { k , j } ^ { I } ) } ,
40
+ $$
41
+
42
+ where $s _ { k , j } ^ { I }$ denotes the similarity of the $k$ -th image to the $j$ -th text. Similarly, the text-to-image contrastive loss for $\pmb { x } _ { k } ^ { T }$ is
43
+
44
+ $$
45
+ \mathcal { L } _ { k } ^ { T } ( \boldsymbol { x } _ { k } ^ { T } , \{ \boldsymbol { x } _ { j } ^ { I } \} _ { j = 1 } ^ { b } ) = - \frac { 1 } { b } \log \frac { e x p ( s _ { k , k } ^ { T } ) } { \sum _ { j } e x p ( s _ { j , k } ^ { T } ) } .
46
+ $$
47
+
48
+ The total loss of this mini-batch can be represented by
49
+
50
+ $$
51
+ \mathcal { L } = \frac { 1 } { 2 } \sum _ { k = 1 } ^ { b } ( \mathcal { L } _ { k } ^ { I } + \mathcal { L } _ { k } ^ { T } ) .
52
+ $$
53
+
54
+ # 3.1.1 CROSS-MODAL LATE INTERACTION
55
+
56
+ From the contrastive loss (1), the cross-modal interaction is reflected in how we compute the similarities $s _ { i , j } ^ { I }$ and $s _ { i , j } ^ { T }$ for the $i$ -th image and $j$ -th text. Previous methods like CLIP (Radford et al., 2021) and ALIGN (Jia et al., 2021) simply encode each image or text separately to a global feature i.e., $f _ { \theta } ( \pmb { x } _ { i } ^ { I } ) \in \mathbb { R } ^ { d }$ and $g _ { \phi } ( \pmb { x } _ { j } ^ { T } ) \in \mathbb { R } ^ { d }$ , and compute these two similarities as
57
+
58
+ $$
59
+ s _ { i , j } ^ { I } = s _ { i , j } ^ { T } = f _ { \theta } ( \pmb { x } _ { i } ^ { I } ) ^ { \top } g _ { \phi } ( \pmb { x } _ { j } ^ { T } ) ,
60
+ $$
61
+
62
+ neglecting finer-grained interactions (e.g., word-patch alignment) between the two modalities. To alleviate this problem, while simultaneously maintain the training and inference efficiency of dualstream models, we apply a cross-modal late interaction inspired by Khattab & Zaharia (2020) to model the token-wise cross-modal interaction.
63
+
64
+ Specifically, denote $n _ { 1 }$ and $n _ { 2 }$ as the number of (non-padded) tokens of the $i$ -th image and $j$ -th text, respectively, and the corresponding encoded features are $f _ { \theta } ( \pmb { x } _ { i } ^ { I } ) \in \mathbb { R } ^ { n _ { 1 } \times d }$ and $g _ { \phi } ( \pmb { x } _ { j } ^ { T } ) \in \mathbb { R } ^ { n _ { 2 } \times d }$ . For the $k$ -th visual token, we compute its similarities with all textual tokens of $\pmb { x } _ { j } ^ { T }$ , and use the largest one
65
+
66
+ $$
67
+ \operatorname* { m a x } _ { 0 \leq r < n _ { 2 } } [ f _ { \theta } ( \pmb { x } _ { i } ^ { I } ) ] _ { k } ^ { \top } [ g _ { \phi } ( \pmb { x } _ { j } ^ { T } ) ] _ { r }
68
+ $$
69
+
70
+ as its token-wise maximum similarity with $\pmb { x } _ { j } ^ { T }$ . We then use the average token-wise maximum similarity of all non-padded tokens in the image (resp. text) as the similarity of an image to a text (resp. a text to an image). The similarity of the $i$ -th image to the $j$ -th text can thus be formulated as:
71
+
72
+ $$
73
+ s _ { i , j } ^ { I } ( \pmb { x } _ { i } ^ { I } , \pmb { x } _ { j } ^ { T } ) = \frac { 1 } { n _ { 1 } } \sum _ { k = 1 } ^ { n _ { 1 } } [ f _ { \theta } ( \pmb { x } _ { i } ^ { I } ) ] _ { k } ^ { \top } [ g _ { \phi } ( \pmb { x } _ { j } ^ { T } ) ] _ { m _ { k } ^ { I } } ,
74
+ $$
75
+
76
+ where $m _ { k } ^ { I } = \arg \operatorname* { m a x } _ { 0 \leq r < n _ { 2 } } [ f _ { \theta } ( \pmb { x } _ { i } ^ { I } ) ] _ { k } ^ { \top } [ g _ { \phi } ( \pmb { x } _ { j } ^ { T } ) ] _ { r }$ . Similarly, the similarity of the $j$ -th text to the $i$ -th image is
77
+
78
+ $$
79
+ s _ { i , j } ^ { T } ( \pmb { x } _ { i } ^ { I } , \pmb { x } _ { j } ^ { T } ) = \frac { 1 } { n _ { 2 } } \sum _ { k = 1 } ^ { n _ { 2 } } [ f _ { \theta } ( \pmb { x } _ { i } ^ { I } ) ] _ { m _ { k } ^ { T } } ^ { \top } [ g _ { \phi } ( \pmb { x } _ { j } ^ { T } ) ] _ { k } ,
80
+ $$
81
+
82
+ where $m _ { k } ^ { T } = \arg \operatorname* { m a x } _ { 0 \leq r < n _ { 1 } } [ f _ { \theta } ( \pmb { x } _ { i } ^ { I } ) ] _ { r } ^ { \top } [ g _ { \phi } ( \pmb { x } _ { j } ^ { T } ) ] _ { k }$ . Note that $s _ { i , j } ^ { I } ( \pmb { x } _ { i } ^ { I } , \pmb { x } _ { j } ^ { T } )$ in Equation (4) does not necessarily equal $s _ { i , j } ^ { T } ( \pmb { x } _ { i } ^ { I } , \pmb { x } _ { j } ^ { T } )$ in Equation (5).
83
+
84
+ Remark 1 Intuitively, the token-wise maximum similarity in Equation (3) means that for each image patch, we find its most similar textual token. Similarly, for each textual token, we also find its closest image patch. By applying this to the similarity calculation in (4) and (5) for contrastive loss (1), the dual-stream model learns fine-grained alignment between image patches and textual tokens.
85
+
86
+ The original late interaction mechanism in (Khattab & Zaharia, 2020) computes the relevance score of a document to a query padded with mask tokens, as a sum of token-wise maximum similarities, and is optimized via a pairwise softmax cross-entropy loss. Though inspired from Khattab & Zaharia (2020), our proposed cross-modal late interaction differs in several aspects. Firstly, we exclude the padded textual tokens when computing the similarity, as they harm the performance. We speculate that this is because these padded tokens also learn textual representations and will mislead the model to align image patches to these meaningless padded tokens rather than meaningful non-padded words. Secondly, when computing similarities (4) and (5), we use the average of the token-wise maximum similarities instead of summation in (Khattab & Zaharia, 2020). This is because the number of non-padded tokens varies from text to text, and this summation over all non-padded tokens can have quite different magnitudes, leading to less stabilized training and worse final performance. These two modifications are crucial to not only the downstream tasks’ performance, but also the quality of the word-patch alignment. A more detailed discussion can be found in Appendix A.7. Thirdly, we optimize the late interaction mechanism via a contrastive loss (1) which is found powerful vision-language pre-training (Radford et al., 2021) instead of the original pairwise loss in (Khattab & Zaharia, 2020).
87
+
88
+ Training Efficiency. Though the cross-modal late interaction is able to capture finer-grained features compared with the original loss, it relies on the token-wise representations of both modalities, and can be inefficient in terms of communication, memory and computation, especially when the batch size is large. To alleviate this problem, we utilize several methods. Firstly, we reduce the embedding size to 256. Besides, we reduce the precision of the last-layer features of both modalities from fp32 to fp16 before node communication in a distributed learning setting, and perform the multiplication in Equations (4) and (5) under the reduced precision. In addition, since the complexity of similarity calculation scales with the sequence length of textual tokens and image patches, for each image (resp. text), we select the $2 5 \%$ tokens with the highest token-wise maximum similarity score (Equation (3)) among all texts (resp. images) in the same local worker before node communication, based on the intuition that each sample can be represented by a few of the most representative tokens. Effects of these modifications are studied in Section 4.4.
89
+
90
+ # 3.1.2 PROMPT ENSEMBLE AND TEMPLATES
91
+
92
+ Due to the problem of polysemy and inconsistency with the pre-training process, following Radford et al. (2021), we also use prompt templates to augment the original label for some downstream tasks. For visualizations, for simplicity, we use only one prompt template across the paper, i.e. “a photo of a $\{ { \mathrm { l a b e l } } \}$ .” as Radford et al. (2021). For other experiments, we report results using prompt ensemble following Radford et al. (2021). When multiple prompts are allowed, the token-wise representations of different prompt templates for the same class label are different, and can not be summed together to form a mean textual representation as in (Radford et al., 2021). Thus, instead of ensembling different prompt templates by their mean textual representation, we ensemble them by their mean token-wise similarity. Specifically, suppose there are $C$ prompt templates, each label is augmented to $C$ different texts $\dot { { \pmb x } } _ { 1 } ^ { T } , \dot { { \pmb x } } _ { 2 } ^ { T } , \cdots , \dot { { \pmb x } } _ { C } ^ { T }$ . The similarity between an image $\boldsymbol { x } ^ { I }$ and this label is computed as $\begin{array} { r } { \frac { 1 } { C } \sum _ { c = 1 } ^ { C } s _ { \cdot , \cdot } ^ { I } ( \pmb { x } ^ { I } , \pmb { x } _ { c } ^ { T } ) } \end{array}$ , where $s _ { \cdot , \cdot } ^ { I }$ · is defined in Equation (4).
93
+
94
+ We use a unified rule-based method inspired by Radford et al. (2018) to construct prompt templates for image classification tasks. Specifically, each template consists of four components:
95
+
96
+ [prefix] $\{ { \mathrm { l a b e l } } \}$ , [category description]. [suffix].
97
+
98
+ Here, the “[prefix]” is an in-context description like “a photo of a” similar as Radford et al. (2021); “label” is a class label of the dataset; “[category description]” describes the category which is found helpful for some fine-grained image classification datasets (Radford et al., 2021), e.g., “ a type of pet” for dataset Oxford-IIIT Pets. An interesting finding is that, adding a suffix that includes the reference word “it” (e.g., “I like it.”) at the end of the prompt empirically improves the zero-shot classification performance of the proposed model. We speculate this is because the reference word “it” strengthens the fine-grained cross-modal alignment, as it can also be aligned to image patches of the target object. Detailed prompt templates for different datasets can be found in Appendix A.5.
99
+
100
+ # 3.2 IMAGE AND TEXT AUGMENTATION
101
+
102
+ To obtain better generalization and data-efficiency of the model, we perform data augmentation on both images and texts during the pre-training phase to construct more image-text pairs. We apply AutoAugment (Krizhevsky et al., 2012; Sato et al., 2015; Cubuk et al., 2019; Hoffer et al., 2020) for image augmentation, following the SOTA vision recognition methods (Touvron et al., 2021; Xie et al., 2020b). To ensure the augmented texts are semantically similar as the original one, for text augmentation, we rewrite the original text using back-translation (Xie et al., 2020a; Sennrich et al., 2016a). Specifically, the texts are first translated to the target language and then translated back to the source language. We choose German and Russian as the target language and get extra two texts for each image-text pair. When constructing a batch of image-text pairs during the pre-training, the text of each image-text pair is randomly sampled from the three candidate texts, i.e., the original text and two back-translated texts.
103
+
104
+ Table 1: Top-1 accuracy $\% )$ of zero-shot image classification on 12 datasets. Our FILIP can boost $3 \sim 5 \%$ accuracy on average.
105
+
106
+ <table><tr><td></td><td>CITAII</td><td>CEIRIIIO</td><td>[rreeaer</td><td>srrprits</td><td>TirreeiiG</td><td>[orPooI</td><td>163305</td><td></td><td>VTerirt</td><td>sTodpptit</td><td>BroAI</td><td>1aeeger</td><td>Jee</td></tr><tr><td>CLIP-ViT-B/32 FILIPbase-ViT-B/32</td><td>91.3 86.9</td><td>65.1 65.5</td><td>87.9 91.9</td><td>59.4 55.4</td><td>66.7 85.3</td><td>84.4 82.8</td><td>63.2 69.1</td><td>44.5 49.3</td><td>21.2 57.2</td><td>87.0 88.1</td><td>49.4 49.9</td><td>63.2 68.8</td><td>65.3 70.9+5.6</td></tr><tr><td>CLIP-ViT-L/14</td><td>96.2</td><td>77.9</td><td>92.6</td><td>77.3</td><td>78.7</td><td>92.9</td><td>67.7</td><td>55.3</td><td>36.1</td><td>93.5</td><td>59.9</td><td>75.3</td><td>75.3</td></tr><tr><td>FILIPlarge- ViT-L/14</td><td>95.7</td><td>75.3</td><td>93.0</td><td>70.8</td><td>90.1</td><td>92.2</td><td>73.1</td><td>60.7</td><td>60.2</td><td>92</td><td>59.2</td><td>77.1</td><td>78.3+3.0</td></tr></table>
107
+
108
+ # 3.3 PRE-TRAINING DATASET
109
+
110
+ A sufficiently large image-text dataset is a prerequisite for vision-language pre-training. Recent CLIP (Radford et al., 2021) and ALIGN (Jia et al., 2021) construct datasets with 400M and 1800M image-text pairs, respectively. In this work, we also collect a large-scale dataset called FILIP300M from the Internet, which consists of 300M image-text pairs and covers board vision and language concepts. For image-based filtering, we remove the images whose shorter dimension is smaller than 200 pixels and the aspect ratio is larger than 3. For text-based filtering, we keep only English texts, and exclude the meaningless ones, e.g., img 0.jpg. We also discard image-text pairs whose texts are repeated for over 10 times. Besides, we also use 3 public datasets, including Conceptual Captions 3M (CC3M) (Sharma et al., 2018), Conceptual 12M (CC12M) (Changpinyo et al., 2021) and Yahoo Flickr Creative Commons 100M (YFCC100M) (Thomee et al., 2016). We apply the same filtering rules on YFCC100M. Finally, we use about 340M image-text pairs for pre-training. Despite using a smaller training dataset than CLIP and ALIGN, our models still outperform them in most down-steam tasks (see Section 4).
111
+
112
+ # 4 EXPERIMENTS
113
+
114
+ # 4.1 EXPERIMENTAL SETUP
115
+
116
+ Model Architectures. We train two models from scratch, i.e., ${ \mathrm { F I L I P } } _ { \mathrm { b a s e } }$ and $\mathrm { F I L I P _ { l a r g e } }$ . The model architectures follow CLIP (Radford et al., 2021), i.e., the image encoder is ViT-B/32 for ${ \mathrm { F I L I P } } _ { \mathrm { b a s e } }$ and ViT-L/14 for $\mathrm { F I L I P _ { l a r g e } }$ . More details can be found in Appendix A.3.
117
+
118
+ Pre-training Details. To save memory and scale up the batch size, automatic mixed-precision (Micikevicius et al., 2018) and gradient checkpoint (Griewank & Walther, 2000; Chen et al., 2016) are used The input images are resized to $2 2 4 \times 2 2 4$ resolution during pre-training and the maximum length of the text is limited to 77 tokens following Radford et al. (2021). The training is mainly conducted on Nvidia V100 GPUs and Ascend Cards. ${ \mathrm { F I L I P } } _ { \mathrm { b a s e } }$ is trained on 128 cards about 9 days and $\mathrm { F I L I P _ { l a r g e } }$ takes about 24 days to train on 192 cards. Unless otherwise specified, we use $\mathrm { F I L I P _ { l a r g e } }$ to compare with other methods and ${ \mathrm { F I L I P } } _ { \mathrm { b a s e } }$ for ablation. We train both models using the LAMB optimizer (You et al., 2020) and cosine learning rate schedule (Loshchilov & Hutter, 2016) with a linear warmup. Weight decay regularization is applied to all parameters except bias, layer normalization, token embedding, positional embedding and temperature in contrastive loss. Detailed values of hyperparameters for different datasets and models can be found in Appendix A.3.
119
+
120
+ # 4.2 IMAGE CLASSIFICATION
121
+
122
+ In this section, we compare our FILIP with CLIP (Radford et al., 2021) on 12 downstream image classification datasets.
123
+
124
+ Table 2: Results of zero-shot image-text retrieval on Flickr30K and MSCOCO datasets. The last two rows (marked with \*) report the zero-shot results on Flickr30K dataset of model fine-tuned on MSCOCO dataset, following the setting of ALBEF (Li et al., 2021a).
125
+
126
+ <table><tr><td></td><td colspan="6">Flickr30K</td><td colspan="6">MSCOCO</td></tr><tr><td></td><td colspan="3">image-to-text</td><td colspan="3">text-to-image</td><td colspan="3">image-to-text</td><td colspan="3">text-to-image</td></tr><tr><td></td><td></td><td>R@1 R@5 R@10</td><td></td><td></td><td></td><td></td><td>R@1 R@5 R@10 R@1 R@5 R@10 R@1 R@5 R@10</td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>Unicoder-VL</td><td>64.3</td><td>85.8</td><td>92.3</td><td>48.4</td><td>76.0</td><td>85.2</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>ImageBERT</td><td>70.7</td><td>90.2</td><td>94.0</td><td>54.3</td><td>79.6</td><td>87.5</td><td>44.0</td><td>71.2</td><td>80.4</td><td>32.3</td><td>59.0</td><td>70.2</td></tr><tr><td>UNITER</td><td>83.6</td><td>95.7</td><td>97.7</td><td>68.7</td><td>89.2</td><td>93.9</td><td>1</td><td></td><td></td><td>一</td><td></td><td></td></tr><tr><td>CLIP</td><td>88.0</td><td>98.7</td><td>99.4</td><td>68.7</td><td>90.6</td><td>95.2</td><td>58.4</td><td>81.5</td><td>88.1</td><td>37.8</td><td>62.4</td><td>72.2</td></tr><tr><td>ALIGN</td><td>88.6</td><td>98.7</td><td>99.7</td><td>75.7</td><td>93.8</td><td>96.8</td><td>58.6</td><td>83.0</td><td>89.7</td><td>45.6</td><td>69.8</td><td>78.6</td></tr><tr><td>FILIP</td><td>89.8</td><td>99.2</td><td>99.8</td><td>75.0</td><td>93.4</td><td>96.3</td><td>61.3</td><td>84.3</td><td>90.4</td><td>45.9</td><td>70.6</td><td>79.3</td></tr><tr><td>ALBEF*</td><td>94.1</td><td>99.5</td><td>99.7</td><td>82.8</td><td>96.3</td><td>98.1</td><td>一</td><td></td><td>1</td><td>一</td><td>1</td><td>1</td></tr><tr><td>FILIP*</td><td>95.4</td><td>99.8</td><td>100.0</td><td>84.7</td><td>97.0</td><td>98.7</td><td></td><td></td><td></td><td></td><td></td><td></td></tr></table>
127
+
128
+ Zero-shot Classification. As in Section 3.1.2, we apply a set of prompts (Appendix A.5) for each dataset and ensemble them to get the final results. Table 1 shows the results on 12 datasets. Despite using less training data (340M vs. 400M), both ${ \mathrm { F I L I P } } _ { \mathrm { b a s e } }$ and $\mathrm { F I L I P _ { l a r g e } }$ considerably outperform their CLIP counterparts in terms of average top-1 accuracy over 12 datasets, i.e., achieving absolute improvements of $5 . 6 \%$ and $3 . 0 \%$ , respectively. In particular, our FILIP surpasses CLIP on ImageNet, the largest dataset among 12 datasets. FILIP also achieves substantial performance gains on some domain-specific datasets like Aircrafts. We speculate this is because, unlike CLIP which aggregates the information of the whole image into the [CLS] token, our proposed FILIP focuses more on the target object by directly aligning the image patches of the target object with the textual tokens corresponding to the class label (visualizations of word-patch alignment are in Section 4.5).
129
+
130
+ Linear Probe. Table 14 in Appendix A.6 shows the linear probe results, and FILIP again outperforms CLIP by $1 . 2 { \sim } 1 . 8 \%$ points on average. More details can be found in Appendix A.6.
131
+
132
+ # 4.3 IMAGE-TEXT RETRIEVAL
133
+
134
+ Image-text retrieval consists of two sub-tasks: image-to-text retrieval and text-to-image retrieval. We evaluate our FILIP model on two retrieval benchmark datasets: Flickr30K (Plummer et al., 2015) and MSCOCO (Lin et al., 2014), under both zero-shot and fine-tuned settings. More details of experimental setting can be found in Appendix A.3.
135
+
136
+ Tables 2 and 3 show the results of zero-shot and fine-tuned image-text retrieval, respectively. We compare our FILIP model against methods with complex attention layers including Unicoder-VL (Li et al., 2020a), ImageBERT (Qi et al., 2020), UNITER (Chen et al., 2020), VILLA (Gan et al., 2020), ERNIE-ViL (Yu et al., 2021), Oscar (Li et al., 2020b), VinVL (Zhang et al., 2021), ALBEF (Li et al., 2021a), and methods trained on larger-scale image-text datasets including CLIP (Radford et al., 2021) and ALIGN (Jia et al., 2021). As we can see, FILIP achieves state-of-the-art performances under all metrics on both Flickr30K and MSCOCO datasets, except for zero-shot text-to-image retrieval on Flickr30K, where FILIP achieves competitive performance with SOTA. For zero-shot image-to-text retrieval on MSCOCO dataset, the absolute $\mathbb { R } \ @ 1$ of our proposed FILIP is $2 . 7 \%$ higher than ALIGN, which is trained on a much larger dataset.
137
+
138
+ # 4.4 ABLATION STUDY
139
+
140
+ Effectiveness of Each Component. We study the effectiveness of each component in FILIP, i.e., image/text augmentations and cross-modal late interaction. Experiments are conducted on ${ \mathrm { F I L I P } } _ { \mathrm { b a s e } }$ , with a filtered subset of YFCC100M as the training dataset (as described in Section 3.3), on both zero-shot retrieval and classification tasks. We measure models’ performance on MSCOCO zeroshot image-text retrieval and ImageNet zero-shot classification, which are two effective indicators for the quality of the learned vision-language representations.
141
+
142
+ Table 4 reports the results. As can be seen, all three components are beneficial for both tasks. Despite the simple design, cross-modal late interaction brings significant performance improvements over the baseline (the vanilla CLIP ViT-B/32), with an absolute $\mathbf { R } \ @ 1$ gain of $5 . 5 \%$ (resp. $3 . 8 \%$ ) for image-to-text (resp. text-to-image) retrieval on MSCOCO and an absolute top-1 accuracy gain of $3 . 9 \%$ for zero-shot classification on ImageNet. Further improvements are observed when all components are combined together.
143
+
144
+ Table 3: Results of fine-tuned image-text retrieval on Flickr30K and MSCOCO datasets.
145
+
146
+ <table><tr><td></td><td colspan="6">Flickr30K</td><td colspan="6">MSCOCO</td></tr><tr><td></td><td></td><td>image-to-text</td><td></td><td></td><td>text-to-image</td><td></td><td></td><td>image-to-text</td><td></td><td></td><td>text-to-image</td><td></td></tr><tr><td></td><td>R@1</td><td>R@5</td><td>R@10</td><td>R@1</td><td>R@5</td><td>R@10</td><td>R@1</td><td>R@5</td><td>R@10</td><td>R@1</td><td>R@5</td><td>R@10</td></tr><tr><td>Unicoder-VL</td><td>86.2</td><td>96.3</td><td>99.0</td><td>71.5</td><td>90.9</td><td>94.9</td><td>62.3</td><td>87.1</td><td>92.8</td><td>48.4</td><td>76.7</td><td>85.9</td></tr><tr><td>ImageBERT</td><td>87.0</td><td>97.6</td><td>99.2</td><td>73.1</td><td>92.6</td><td>96.0</td><td>66.4</td><td>89.8</td><td>94.4</td><td>50.5</td><td>78.7</td><td>87.1</td></tr><tr><td>UNITER</td><td>87.3</td><td>98.0</td><td>99.2</td><td>75.6</td><td>94.1</td><td>96.8</td><td>65.7</td><td>88.6</td><td>93.8</td><td>52.9</td><td>79.9</td><td>88.0</td></tr><tr><td>VILLA</td><td>87.9</td><td>97.5</td><td>98.8</td><td>76.3</td><td>94.2</td><td>96.8</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>ERNIE-ViL</td><td>88.1</td><td>98.0</td><td>99.2</td><td>76.7</td><td>93.6</td><td>96.4</td><td></td><td></td><td></td><td></td><td></td><td>一</td></tr><tr><td>Oscar</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>73.5</td><td>92.2</td><td>96.0</td><td>57.5</td><td>82.8</td><td>89.8</td></tr><tr><td>VinVL</td><td>1</td><td></td><td>一</td><td>一</td><td>一</td><td>1</td><td>75.4</td><td>92.9</td><td>96.2</td><td>58.8</td><td>83.5</td><td>90.3</td></tr><tr><td>ALIGN</td><td>95.3</td><td>99.8</td><td>100.0</td><td>84.9</td><td>97.4</td><td>98.6</td><td>77.0</td><td>93.5</td><td>96.9</td><td>59.9</td><td>83.3</td><td>89.8</td></tr><tr><td>ALBEF</td><td>95.9</td><td>99.8</td><td>100.0</td><td>85.6</td><td>97.5</td><td>98.9</td><td>77.6</td><td>94.3</td><td>97.2</td><td>60.7</td><td>84.3</td><td>90.5</td></tr><tr><td>Our FILIP</td><td>96.6</td><td>100.0</td><td>100.0</td><td>87.1</td><td>97.7</td><td>99.1</td><td>78.9</td><td>94.4</td><td>97.4</td><td>61.2</td><td>84.3</td><td>90.6</td></tr></table>
147
+
148
+ Table 4: Ablation study of different components on pre-training subset of YFCC100M. I2T and T2I are abbreviations for image-to-text and text-to-image retrieval, respectively. “ZS” means zero-shot performance. Underlined numbers have the highest improvements for the corresponding metrics.
149
+
150
+ <table><tr><td rowspan="2">Model</td><td colspan="4">MSCOCO</td><td rowspan="2">ImageNet ZS Top1</td></tr><tr><td>I2TR@1</td><td>I2T R@5</td><td>T2I R@1</td><td>T2IR@5</td></tr><tr><td>Baseline (ViT-B/32)</td><td>25.0</td><td>49.5</td><td>14.7</td><td>34.7</td><td>30.4</td></tr><tr><td>w/ image augmentation</td><td>26.1</td><td>51.8</td><td>16.5</td><td>37.5</td><td>32.5</td></tr><tr><td>w/back translation</td><td>29.2</td><td>55.0</td><td>17.9</td><td>39.8</td><td>33.9</td></tr><tr><td>w/ cross-modal late interaction</td><td>30.5</td><td>55.3</td><td>18.5</td><td>40.0</td><td>34.3</td></tr><tr><td>Our FILIPbase</td><td>33.4</td><td>60.1</td><td>23.0</td><td>46.2</td><td>37.8</td></tr></table>
151
+
152
+ Table 5: Efficiency study of the cross-modal late interaction. “orig” and “late” stand for the contrastive loss based on the original cosine similarity in CLIP and our proposed cross-modal late interaction, respectively. “ZS” means zero-shot performance. We report results for ViT-B/32 trained on filtered YFCC100M with 8 V100 GPUs, with a batch size of 512 per GPU. Training time and memory consumption are tested using the same gradient checkpoint configuration. \* denotes our final setting used in other experiments.
153
+
154
+ <table><tr><td>Loss</td><td>Embed dim</td><td>Embed precision</td><td>Token %</td><td>Training time (sec/iter)</td><td>Memory (MB)</td><td>ImageNet ZS Top1</td></tr><tr><td>orig (baseline)</td><td>512</td><td>fp32</td><td>1</td><td>1.31</td><td>14300</td><td>30.4</td></tr><tr><td>late</td><td>512</td><td>fp32</td><td>100%</td><td>2.85</td><td>26000</td><td>34.6</td></tr><tr><td>late</td><td>512</td><td>fp16</td><td>100%</td><td>2.67</td><td>23468</td><td>34.5</td></tr><tr><td>late</td><td>256</td><td>fp16</td><td>100%</td><td>2.31</td><td>22382</td><td>35.2</td></tr><tr><td>late</td><td>256</td><td>fp16</td><td>50%</td><td>1.61</td><td>16336</td><td>34.5</td></tr><tr><td>late*</td><td>256</td><td>fp16</td><td>25%</td><td>1.39</td><td>16100</td><td>34.3</td></tr></table>
155
+
156
+ Efficiency Study of Cross-modal Late Interaction. Since the late interaction mechanism in Section 3.1.1 requires to calculate the similarity between all visual and textual tokens, its efficiency can be a problem when employed in large-scale distributed training. As described in Section 3.1.1, we make several attempts to address the issue. Table 5 shows the efficiency improvement on zero-shot classification on ImageNet when these attempts are applied. As can be seen, these attempts improve the efficiency of late interaction without accuracy drop. Combining all three attempts achieves only slightly slower training and larger memory consumption than the original loss in CLIP.
157
+
158
+ # 4.5 VISUALIZATION OF FINE-GRAINED ALIGNMENT
159
+
160
+ In this section, we visualize FILIP’s capability of capturing fine-grained cross-modal correspondence using the method of word-patch alignment. To make a fair comparison, we use our FILIPbase trained on YFCC100M and CLIP’s ViT-B/32, which are of the same size, for visualization. Each image is patchified to $7 \times 7$ image patches. More visualization results can be found in Appendix A.4.
161
+
162
+ ![](images/ac03918fdbcf8c481cbca69053abf9c08404a9d6a22fe1e112eaf3f50e56731c.jpg)
163
+ Figure 2: Visualizations of word-patch alignment for 4 classes of the ImageNet dataset and “a photo of a $\{ { \mathrm { l a b e l } } \}$ .” is the prompt. Numbers in the parentheses after the class label indicate the location indices of the class label in the tokenized textual sequence. The correct predictions are highlighted by opaque patches with the class label indices in red.
164
+
165
+ Visualization Method. The word-patch alignment is performed based on the token-wise similarity between the image patches and textual tokens. Specifically, for the $k$ -th image patch, the location index of textual token with the largest similarity with it $\overset { \cdot } { m } _ { k } ^ { I }$ in Equation (4)) is considered as its predicted label, and is placed at the center of it. Take class “balloon” as an example. There are 8 tokens in the tokenized textual sequence “[BOS] a photo of a balloon. [EOS]”, and the location index of the class label “balloon” is $\mathbf { \Delta } ^ { 6 6 } 5 ^ { , 9 }$ . Note that one class label may be tokenized to more than one token. Location indices of textual tokens corresponding to the class label are highlighted in red, while the others are marked in white. A desired model that learns fine-grained representations would predict image patches of the target object to red indices.
166
+
167
+ Observations. Figure 2 shows the word-patch alignment results for FILIP and CLIP on 4 classes from the ImageNet dataset. As can be seen, FILIP exhibits the finer-grained understanding of an image in the following aspects. (i) A single object: From the visualization of class “small white butterfly”, the image patches covering the object are all classified correctly; (ii) Same object in different shapes: From the visualizations of class “balloon” and “lifeboat”, image patches corresponding to all target objects with different shapes and locations are correctly classified; (iii) Key Components of an object: For class “electric locomotive”, there are two key components crucial to correctly classifying the image, i.e., “electric” and “locomotive”, whose corresponding textual token indices are $\mathbf { \bar { \Psi } } ^ { 6 6 } 5 ^ { \mathrm { , } }$ and $\because 6 ^ { , }$ , respectively. As can be seen, image patches matching these two key components are respectively correctly classified. On the other hand, CLIP can not correctly align image patches with corresponding textual tokens. Compared with Kim et al. (2021) which uses an extra optimal transport to align the textual word and image patch distributions, the word-patch alignment can be simply automatically learned by our method.
168
+
169
+ # 5 CONCLUSION AND FUTURE WORK
170
+
171
+ This paper introduces FILIP, a simple yet generic framework towards fine-grained vision-language pre-training. By using a token-wise maximum similarity, our method learns fine-grained representation for patches in the images and words in the sentences. While it achieves competitive results against several large-scale multi-modal pre-training on various downstream tasks, both its architecture and training procedure can still be optimized to improve its performance. In the future, a more advanced image encoder as well as a well-designed interaction layer can be used to boost the performance. Furthermore, we can further add more masked language/image loss to support more generation tasks. To this end, we hope to extend FILIP as a generic and unified interface for solving a large variety of vision-language tasks.
172
+
173
+ # REFERENCES
174
+
175
+ Tom B Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah, Jared Kaplan, Prafulla Dhariwal, Arvind Neelakantan, Pranav Shyam, Girish Sastry, Amanda Askell, et al. Language models are few-shot learners. In Advances in neural information processing systems, 2020.
176
+
177
+ Soravit Changpinyo, Piyush Sharma, Nan Ding, and Radu Soricut. Conceptual 12M: Pushing webscale image-text pre-training to recognize long-tail visual concepts. In IEEE/CVF Conference on Computer Vision and Pattern Recognition, 2021.
178
+
179
+ Tianqi Chen, Bing Xu, Chiyuan Zhang, and Carlos Guestrin. Training deep nets with sublinear memory cost. preprint arXiv:1604.06174, 2016.
180
+
181
+ Yen-Chun Chen, Linjie Li, Licheng Yu, Ahmed El Kholy, Faisal Ahmed, Zhe Gan, Yu Cheng, and Jingjing Liu. Uniter: Universal image-text representation learning. In European conference on computer vision, pp. 104–120. Springer, 2020.
182
+
183
+ Ekin D Cubuk, Barret Zoph, Dandelion Mane, Vijay Vasudevan, and Quoc V Le. Autoaugment: Learning augmentation strategies from data. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 113–123, 2019.
184
+
185
+ Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. Bert: Pre-training of deep bidirectional transformers for language understanding. In Annual Conference of the North American Chapter of the Association for Computational Linguistics, 2019.
186
+
187
+ Ming Ding, Zhuoyi Yang, Wenyi Hong, Wendi Zheng, Chang Zhou, Da Yin, Junyang Lin, Xu Zou, Zhou Shao, Hongxia Yang, et al. Cogview: Mastering text-to-image generation via transformers. arXiv preprint arXiv:2105.13290, 2021.
188
+
189
+ Carl Doersch, Abhinav Gupta, and Alexei A Efros. Unsupervised visual representation learning by context prediction. In Proceedings of the IEEE international conference on computer vision, pp. 1422–1430, 2015.
190
+
191
+ Xiao Dong, Xunlin Zhan, Yangxin Wu, Yunchao Wei, Xiaoyong Wei, Minlong Lu, and Xiaodan Liang. M5product: A multi-modal pretraining benchmark for e-commercial product downstream tasks. Preprint arXiv:2109.04275, 2021.
192
+
193
+ Alexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn, Xiaohua Zhai, Thomas Unterthiner, Mostafa Dehghani, Matthias Minderer, Georg Heigold, Sylvain Gelly, et al. An image is worth 16x16 words: Transformers for image recognition at scale. In International Conference on Learning Representations, 2020.
194
+
195
+ Zhe Gan, Yen-Chun Chen, Linjie Li, Chen Zhu, Yu Cheng, and Jingjing Liu. Large-scale adversarial training for vision-and-language representation learning. arXiv preprint arXiv:2006.06195, 2020.
196
+
197
+ Andreas Griewank and Andrea Walther. Algorithm 799: revolve: an implementation of checkpointing for the reverse or adjoint mode of computational differentiation. ACM Transactions on Mathematical Software (TOMS), 26(1):19–45, 2000.
198
+
199
+ Elad Hoffer, Tal Ben-Nun, Itay Hubara, Niv Giladi, Torsten Hoefler, and Daniel Soudry. Augment your batch: Improving generalization through instance repetition. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 8129–8138, 2020.
200
+
201
+ Zhicheng Huang, Zhaoyang Zeng, Yupan Huang, Bei Liu, Dongmei Fu, and Jianlong Fu. Seeing out of the box: End-to-end pre-training for vision-language representation learning. In IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 12976–12985, 2021.
202
+
203
+ Sergey Ioffe and Christian Szegedy. Batch normalization: Accelerating deep network training by reducing internal covariate shift. In International conference on machine learning, pp. 448–456. PMLR, 2015.
204
+
205
+ Chao Jia, Yinfei Yang, Ye Xia, Yi-Ting Chen, Zarana Parekh, Hieu Pham, Quoc V Le, Yunhsuan Sung, Zhen Li, and Tom Duerig. Scaling up visual and vision-language representation learning with noisy text supervision. In International Conference on Machine Learning, 2021.
206
+
207
+ Omar Khattab and Matei Zaharia. Colbert: Efficient and effective passage search via contextualized late interaction over bert. In International ACM SIGIR Conference on Research and Development in Information Retrieval, pp. 39–48, 2020.
208
+
209
+ Wonjae Kim, Bokyung Son, and Ildoo Kim. Vilt: Vision-and-language transformer without convolution or region supervision. In International Conference on Machine Learning, 2021.
210
+
211
+ Alex Krizhevsky, Ilya Sutskever, and Geoffrey E Hinton. Imagenet classification with deep convolutional neural networks. In Advances in neural information processing systems, volume 25, pp. 1097–1105, 2012.
212
+
213
+ Kuang-Huei Lee, Xi Chen, Gang Hua, Houdong Hu, and Xiaodong He. Stacked cross attention for image-text matching. In Proceedings of the European Conference on Computer Vision (ECCV), pp. 201–216, 2018.
214
+
215
+ Gen Li, Nan Duan, Yuejian Fang, Ming Gong, and Daxin Jiang. Unicoder-vl: A universal encoder for vision and language by cross-modal pre-training. In Proceedings of the AAAI Conference on Artificial Intelligence, volume 34, pp. 11336–11344, 2020a.
216
+
217
+ Junnan Li, Ramprasaath R. Selvaraju, Akhilesh Deepak Gotmare, Shafiq Joty, and Steven Xiong, Caiming andHoi. Align before fuse: Vision and language representation learning with momentum distillation. Technical Report arXiv:2107.07651, 2021a.
218
+
219
+ Liunian Harold Li, Mark Yatskar, Da Yin, Cho-Jui Hsieh, and Kai-Wei Chang. Visualbert: A simple and performant baseline for vision and language. Preprint arXiv:1908.03557, 2019.
220
+
221
+ Wei Li, Can Gao, Guocheng Niu, Xinyan Xiao, Hao Liu, Jiachen Liu, Hua Wu, and Haifeng Wang. Unimo: Towards unified-modal understanding and generation via cross-modal contrastive learning. In Annual Meeting of the Association for Computational Linguistics, 2021b.
222
+
223
+ Xiujun Li, Xi Yin, Chunyuan Li, Pengchuan Zhang, Xiaowei Hu, Lei Zhang, Lijuan Wang, Houdong Hu, Li Dong, Furu Wei, et al. Oscar: Object-semantics aligned pre-training for vision-language tasks. In European Conference on Computer Vision, pp. 121–137. Springer, 2020b.
224
+
225
+ Junyang Lin, Rui Men, An Yang, Chang Zhou, Ming Ding, Yichang Zhang, Peng Wang, Ang Wang, Le Jiang, Xianyan Jia, et al. M6: A chinese multimodal pretrainer. Preprint arXiv:2103.00823, 2021.
226
+
227
+ Tsung-Yi Lin, Michael Maire, Serge Belongie, James Hays, Pietro Perona, Deva Ramanan, Piotr Dollar, and C Lawrence Zitnick. Microsoft coco: Common objects in context. In ´ European conference on computer vision, pp. 740–755. Springer, 2014.
228
+
229
+ I. Loshchilov and F. Hutter. Sgdr: Stochastic gradient descent with warm restarts. ICLR 2017 (5th International Conference on Learning Representations), 2016.
230
+
231
+ Jiasen Lu, Dhruv Batra, Devi Parikh, and Stefan Lee. Vilbert: pretraining task-agnostic visiolinguistic representations for vision-and-language tasks. In International Conference on Neural Information Processing Systems, pp. 13–23, 2019.
232
+
233
+ Paulius Micikevicius, Sharan Narang, Jonah Alben, Gregory Diamos, Erich Elsen, David Garcia, Boris Ginsburg, Michael Houston, Oleksii Kuchaiev, Ganesh Venkatesh, et al. Mixed precision training. In International Conference on Learning Representations, 2018.
234
+
235
+ Fabian Pedregosa, Gael Varoquaux, Alexandre Gramfort, Vincent Michel, Bertrand Thirion, Olivier ¨ Grisel, Mathieu Blondel, Peter Prettenhofer, Ron Weiss, Vincent Dubourg, et al. Scikit-learn: Machine learning in python. the Journal of machine Learning research, 12:2825–2830, 2011.
236
+
237
+ Bryan A Plummer, Liwei Wang, Chris M Cervantes, Juan C Caicedo, Julia Hockenmaier, and Svetlana Lazebnik. Flickr30k entities: Collecting region-to-phrase correspondences for richer imageto-sentence models. In IEEE international conference on computer vision, pp. 2641–2649, 2015.
238
+
239
+ Di Qi, Lin Su, Jia Song, Edward Cui, Taroon Bharti, and Arun Sacheti. Imagebert: Cross-modal pre-training with large-scale weak-supervised image-text data. arXiv preprint arXiv:2001.07966, 2020.
240
+
241
+ Alec Radford, Karthik Narasimhan, Tim Salimans, and Ilya Sutskever. Improving language understanding by generative pre-training. 2018.
242
+
243
+ Alec Radford, Jeffrey Wu, Rewon Child, David Luan, Dario Amodei, Ilya Sutskever, et al. Language models are unsupervised multitask learners. OpenAI blog, 1(8):9, 2019.
244
+
245
+ Alec Radford, Jong Wook Kim, Chris Hallacy, Aditya Ramesh, Gabriel Goh, Sandhini Agarwal, Girish Sastry, Amanda Askell, Pamela Mishkin, Jack Clark, et al. Learning transferable visual models from natural language supervision. Preprint arXiv:2103.00020, 2021.
246
+
247
+ Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, and Peter J Liu. Exploring the limits of transfer learning with a unified text-to-text transformer. Journal of Machine Learning Research, 21:1–67, 2020.
248
+
249
+ Aditya Ramesh, Mikhail Pavlov, Gabriel Goh, Scott Gray, Chelsea Voss, Alec Radford, Mark Chen, and Ilya Sutskever. Zero-shot text-to-image generation. Preprint arXiv:2102.12092, 2021.
250
+
251
+ Shaoqing Ren, Kaiming He, Ross Girshick, and Jian Sun. Faster r-cnn: Towards real-time object detection with region proposal networks. Advances in neural information processing systems, 28: 91–99, 2015.
252
+
253
+ Ikuro Sato, Hiroki Nishimura, and Kensuke Yokoi. Apac: Augmented pattern classification with neural networks. Technical Report arXiv:1505.03229, 2015.
254
+
255
+ Ramprasaath R Selvaraju, Michael Cogswell, Abhishek Das, Ramakrishna Vedantam, Devi Parikh, and Dhruv Batra. Grad-cam: Visual explanations from deep networks via gradient-based localization. In IEEE international conference on computer vision, pp. 618–626, 2017.
256
+
257
+ Rico Sennrich, Barry Haddow, and Alexandra Birch. Improving neural machine translation models with monolingual data. In Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pp. 86–96, 2016a.
258
+
259
+ Rico Sennrich, Barry Haddow, and Alexandra Birch. Neural machine translation of rare words with subword units. In Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pp. 1715–1725, 2016b.
260
+
261
+ Piyush Sharma, Nan Ding, Sebastian Goodman, and Radu Soricut. Conceptual captions: A cleaned, hypernymed, image alt-text dataset for automatic image captioning. In Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pp. 2556–2565, 2018.
262
+
263
+ Bart Thomee, David A Shamma, Gerald Friedland, Benjamin Elizalde, Karl Ni, Douglas Poland, Damian Borth, and Li-Jia Li. Yfcc100m: The new data in multimedia research. Communications of the ACM, 59(2):64–73, 2016.
264
+
265
+ Yonglong Tian, Dilip Krishnan, and Phillip Isola. Contrastive multiview coding. In Computer Vision–ECCV 2020: 16th European Conference, pp. 776–794. Springer, 2020.
266
+
267
+ Hugo Touvron, Matthieu Cord, Matthijs Douze, Francisco Massa, Alexandre Sablayrolles, and Herve J ´ egou. Training data-efficient image transformers & distillation through attention. In ´ International Conference on Machine Learning, pp. 10347–10357. PMLR, 2021.
268
+
269
+ Zirui Wang, Jiahui Yu, Adams Wei Yu, Zihang Dai, Yulia Tsvetkov, and Yuan Cao. Simvlm: Simple visual language model pretraining with weak supervision. Preprint arXiv:2108.10904, 2021.
270
+
271
+ Qizhe Xie, Zihang Dai, Eduard Hovy, Thang Luong, and Quoc Le. Unsupervised data augmentation for consistency training. In Advances in Neural Information Processing Systems, volume 33, 2020a.
272
+
273
+ Qizhe Xie, Minh-Thang Luong, Eduard Hovy, and Quoc V Le. Self-training with noisy student improves imagenet classification. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 10687–10698, 2020b.
274
+
275
+ Yang You, Jing Li, Sashank Reddi, Jonathan Hseu, Sanjiv Kumar, Srinadh Bhojanapalli, Xiaodan Song, James Demmel, Kurt Keutzer, and Cho-Jui Hsieh. Large batch optimization for deep learning: Training bert in 76 minutes. In International Conference on Learning Representations, 2020.
276
+
277
+ Fei Yu, Jiji Tang, Weichong Yin, Yu Sun, Hao Tian, Hua Wu, and Haifeng Wang. Ernie-vil: Knowledge enhanced vision-language representations through scene graphs. In Proceedings of the AAAI Conference on Artificial Intelligence, volume 35, pp. 3208–3216, 2021.
278
+
279
+ Xunlin Zhan, Yangxin Wu, Xiao Dong, Yunchao Wei, Minlong Lu, Yichi Zhang, Hang Xu, and Xiaodan Liang. Product1m: Towards weakly supervised instance-level product retrieval via crossmodal pretraining. In International Conference on Computer Vision, 2021.
280
+
281
+ Pengchuan Zhang, Xiujun Li, Xiaowei Hu, Jianwei Yang, Lei Zhang, Lijuan Wang, Yejin Choi, and Jianfeng Gao. Vinvl: Revisiting visual representations in vision-language models. In IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 5579–5588, 2021.
282
+
283
+ # A APPENDIX
284
+
285
+ # A.1 ETHICAL ISSUES IN DATA COLLECTION
286
+
287
+ When collecting the large-scale image-text pairs from the Internet, we perform person-name substitutions as in Changpinyo et al. (2021), in order to protect the privacy of the individuals appearing in the text. Specifically, we replace each person name appeared in the text with a special $< p e r s o n >$ token. Besides, we also disgard image-text pairs whose text contains sensitive words.
288
+
289
+ # A.2 DATASETS SUMMARY
290
+
291
+ Table 6 shows the number of image-text pairs of each datasets used in different pre-training methods.
292
+
293
+ Table 6: Number of image-text pairs used in the pre-training of FILIP, CLIP and ALIGN.
294
+
295
+ <table><tr><td rowspan="2"></td><td colspan="4">FILIP</td><td rowspan="2">CLIP (Radford et al. 2021)</td><td rowspan="2">ALIGN (Jia et al., 2021)</td></tr><tr><td>CC3M</td><td>CC12M</td><td>YFCC100M</td><td>FILIP300M</td></tr><tr><td>#</td><td>3M</td><td>10M</td><td>26M</td><td>300M</td><td>400M</td><td>1800M</td></tr></table>
296
+
297
+ # A.3 DETAILED EXPERIMENTAL SETTINGS
298
+
299
+ Table 7: The architecture parameters for FILIP models.
300
+
301
+ <table><tr><td rowspan="2">Model</td><td rowspan="2">Embedding dimension</td><td rowspan="2">Input resolution</td><td colspan="3">Image Encoder</td><td colspan="3">Text Encoder</td></tr><tr><td>#layers</td><td>width</td><td>#heads</td><td>#layers</td><td>width</td><td>#heads</td></tr><tr><td>FILIPbase</td><td>256</td><td>224× 224</td><td>12</td><td>768</td><td>12</td><td>12</td><td>512</td><td>8</td></tr><tr><td>FILIPlarge</td><td>256</td><td>224× 224</td><td>24</td><td>1024</td><td>16</td><td>12</td><td>768</td><td>12</td></tr></table>
302
+
303
+ Model Architectures. We follow the same architecture design as CLIP, for both ${ \mathrm { F I L I P } } _ { \mathrm { b a s e } }$ and $\mathrm { F I L I P _ { l a r g e } }$ , except that we reduce the embedding dimension from 512/768 to 256 for the efficiency of loss computation. Table 7 describes the details of architectures.
304
+
305
+ Details for Pre-training and Hyperparameters. For the implementation of the contrastive loss, following CLIP (Radford et al., 2021) and ALIGN (Jia et al., 2021), we also set the temperature in the softmax function to be a learnable parameter and initialize it as 0.07. For the pre-training, we use the LAMB optimizer implemented by the cybertronai’s open-source repository (https: //github.com/cybertronai/pytorch-lamb). For the learning rate scheduler, we first assign a base learning rate and then linearly warm it up to the peak learning rate according to the effective total batch size by a square root strategy, $p e a k \_ l r = b a s e \_ l r \times \sqrt { \frac { t o t a l \_ b s } { 5 1 2 } }$ . We note that a large weight decay is crucial to stabilize training and improve generalization. Specifically, we found that the training stability is a challenging issue when applying mix-precision training to large-scale models, i.e., the training is extremely unstable and the NaN loss easily happens. Recent works
306
+
307
+ Table 8: Common hyperparameters used for FILIP pre-training.
308
+
309
+ <table><tr><td>Hyperparameter</td><td>Value</td></tr><tr><td>Vocabulary size Initial temperature</td><td>49408</td></tr><tr><td>LAMB β1</td><td>0.07 0.9</td></tr><tr><td>LAMB β2</td><td>0.999</td></tr><tr><td>LAMB e</td><td>10-4</td></tr><tr><td>Warm-up iters</td><td>3000</td></tr><tr><td>Training epochs</td><td>30</td></tr></table>
310
+
311
+ Table 9: Model- and dataset-specific hyperparameters used for FILIP pre-training. Numbers in batch size represent the total batch size across all workers and are calculated as: batch size per GPU $\times$ #GPUs. FILIP340M is the combination of FILIP300M, YFCC100M, CC12M and CC3M.
312
+
313
+ <table><tr><td>Model</td><td>Dataset</td><td>Batch size</td><td>Base LR</td><td>Weight decay</td></tr><tr><td>FILIPbase</td><td>YFCC100M</td><td>1024×8</td><td>6×10-3</td><td>3e-2</td></tr><tr><td>FILIPbase</td><td>FILIP340M</td><td>320 ×128</td><td>2×10-3</td><td>3e-3</td></tr><tr><td>FILIPlarge</td><td>FILIP340M</td><td>160×192</td><td>1.5 ×10-3</td><td>3e-3</td></tr></table>
314
+
315
+ DALL-E (Ramesh et al., 2021) and Cogview (Ding et al., 2021) also notice this issue and provide their solutions. However, we found that simply increasing the weight decay and applying the trick of removing the weight decay of specific parameters as described in Section 4.1 work for our case. The base learning rate and weight decay are selected manually via observing the performance at the early training stage. Table 8 summarizes the common hyperparameters and Table 9 shows the model- and dataset-specific hyperparameters for FILIP pre-training.
316
+
317
+ Details for Image-text Retrieval. Following previous works (Jia et al., 2021; Li et al., 2021a), for Flickr30K, we test on the 1K test set with or without fine-tuning on the 30K training set, while for MSCOCO, we test on the 5K test set with or without fine-tuning on the 113K training set. We use the similarity between image and text for ranking and use the contrastive loss for fine-tuning. Since there are multiple texts for each image in these two datasets, we change the ground-truth label of contrastive loss to consider multiple positives, by assigning a probability of 1/#positive to each positive following ALBEF (Li et al., 2021a). Besides, we also use prompts during evaluation for both datasets, see Appendix A.5 for details. Table 10 shows the hyperparameters for image-text retrieval fine-tuning.
318
+
319
+ Table 10: Hyperparameters used for image-text retrieval fine-tuning.
320
+
321
+ <table><tr><td>Hyperparameter</td><td>Value</td></tr><tr><td>Image size</td><td>392 × 392</td></tr><tr><td>Training epochs</td><td>3 LAMB</td></tr><tr><td>Optimizer Batch size</td><td>5120</td></tr><tr><td>Base LR</td><td>2×10-4</td></tr><tr><td></td><td></td></tr><tr><td>Weight decay</td><td>3×10-4</td></tr></table>
322
+
323
+ # A.4 MORE VISUALIZATIONS OF WORD-PATCH ALIGNMENT AND GRAD-CAM HEATMAPS
324
+
325
+ In Figure 3, we visualize the cross-modal alignment of the proposed method for more images, in terms of both word-patch alignment as described in Section 4.5 and Grad-CAM heatmaps (Selvaraju et al., 2017). We compute the Grad-CAM heatmaps based on the average self-attention maps over the image patches classified to targeted textual tokens (i.e., the textual token(s) corresponding to the class label in the ImageNet dataset) in the last layer of the image encoder. We average the heatmaps over all attention heads. As can be seen, our proposed model learns meaningful alignment between image patches and textual tokens.
326
+
327
+ # A.5 PROMPT TEMPLATES FOR DOWNSTREAM TASKS
328
+
329
+ Image Classification. Table 11 shows the prompt templates for different image classification datasets in the form of “ [prefix] $\{ { \mathrm { l a b e l } } \}$ , [category description]. [suffix]. ” in Equation (6). There are three components to be determined in the template, i.e., the prefix, the category description and the suffix. For each component, we select several well-performed ones for each dataset. Then we use the full combinations of all three components as the set of prompt templates for ensemble. For instance, we use 5 prefixes, no category descriptions, and 6 suffixes for dataset ImageNet. Then the total number of prompt templates for this dataset is: $5 \times 1 \times 6 = 3 0$ .
330
+
331
+ ![](images/20fbe4e2808cbe21836a966ce2b5bca908857a06e2de03675b55cc628fd8d423.jpg)
332
+ Figure 3: More visualizations on different classes of ImageNet dataset. Numbers in the parentheses after the class label indicate the location indices of class label in the tokenized textual sequence.
333
+
334
+ Table 11: Prompt templates used for 12 downstream image classification tasks.
335
+
336
+ <table><tr><td rowspan=1 colspan=1>Dataset</td><td rowspan=1 colspan=1>Prefix</td><td rowspan=1 colspan=1>Categorydescription</td><td rowspan=1 colspan=1>Suffix</td></tr><tr><td rowspan=1 colspan=1>CIFAR10</td><td rowspan=1 colspan=1>“a photo of a&quot;,“a jpeg photo ofa”,&quot;a painting ofa”,&quot;itap of a”,“graffiti of a”,“a cartoon”,“adoodle”</td><td rowspan=1 colspan=1>None</td><td rowspan=1 colspan=1>None,“It&#x27;s common in daily life”,“It&#x27;s cute&quot;,“It&#x27;s ugly”,“It&#x27;s weird”,&quot;Hope you like it”</td></tr><tr><td rowspan=1 colspan=1>CIFAR100</td><td rowspan=1 colspan=1>“a jpeg photo of a”,“a painting of a”,“a good photo of a”,&quot;abad photo of a”,“a photo of a”,“itap of a”,“a rendering of a”</td><td rowspan=1 colspan=1>None</td><td rowspan=1 colspan=1>None,“It&#x27;s common in dailylife&quot;,“It&#x27;sbeautiful&quot;,“It&#x27;sugly”,&quot;I like it”,“T take it to-day”</td></tr><tr><td rowspan=1 colspan=1>Caltech101</td><td rowspan=1 colspan=1>“a photo of a”,“a cropped photo of a”,“a good photo ofa&quot;,&quot;a bad photo of a”</td><td rowspan=1 colspan=1>None</td><td rowspan=1 colspan=1>None,“I like it”,“I hate it&quot;,&quot;It&#x27;s ugly”,&quot;It&#x27;s cute&quot;</td></tr><tr><td rowspan=1 colspan=1>Stanford-Car</td><td rowspan=1 colspan=1>“a photo of a”,“a close-upphoto of a&quot;,“a good photo ofa”,“a bad photo of a”</td><td rowspan=1 colspan=1>“a type of car”,“a type of auto-mobile”</td><td rowspan=1 colspan=1>“I like it”,“It belongs to myfriend’,“It&#x27;s brand new”,“It’&#x27;s popular recently”,“It&#x27;s impor-tant to me”,“I take it today”</td></tr><tr><td rowspan=1 colspan=1>Flowers102</td><td rowspan=1 colspan=1>“a photo of a (many)”,“a ren-dering of a (many)”, “itap of a(many)”</td><td rowspan=1 colspan=1>“a type offlower&quot;,&quot;a typeof bloom”</td><td rowspan=1 colspan=1>“It&#x27;s beautiful”,“It&#x27;s from mybest friend”,“It gives out a sweet perfume/fragrance</td></tr><tr><td rowspan=1 colspan=1>ImageNet</td><td rowspan=1 colspan=1>“a photo of a&quot;,&quot;a good photo ofa”,&quot;a bad photo of a”,“a close-up photo of a”,“itap of a”</td><td rowspan=1 colspan=1>None</td><td rowspan=1 colspan=1>“I like it”,“It&#x27;s common indaily life&quot;,“It&#x27;s not common in daily life”,“It&#x27;s ugly”,“It&#x27;scute&quot;,&quot;It&#x27;s beautiful&quot;</td></tr><tr><td rowspan=1 colspan=1>Food101</td><td rowspan=1 colspan=1>“a photo of my”,“a close-up photo of my”,“itap of my”</td><td rowspan=1 colspan=1>“atypeoffood”,“a typeof nourish-ment”</td><td rowspan=1 colspan=1>“I made it today”,“I like it”,“I hate it”,&quot;It&#x27;s delicious&quot;,&quot;It&#x27;swith nice flavour”,“It&#x27;s withterrible flavour&quot;,“It&#x27;s popularrecently”</td></tr><tr><td rowspan=1 colspan=1>SUN397</td><td rowspan=1 colspan=1>“a photo of a”,“a good photo ofa&quot;,“a bad photo of a”,“a bright photo of a&quot;,a dark photo of a”,“a black and white photo of a&quot;,“a nice scene of a”,“a terriblescene of a”</td><td rowspan=1 colspan=1>None</td><td rowspan=1 colspan=1>None,“I like it”,“I hate it”,“It&#x27;s beautiful”,“It&#x27;s commonin daily life&quot;,&quot;It&#x27;s important tome”</td></tr><tr><td rowspan=1 colspan=1>DTD</td><td rowspan=1 colspan=1>“itap of a”,“a close-up photo ofa”</td><td rowspan=1 colspan=1>“texture”,“surface&quot;,“material”</td><td rowspan=1 colspan=1>None,“It&#x27;s out of style”,“It&#x27;s popular in old days”,“It&#x27;sugly”,&quot;It&#x27;s beautiful”</td></tr><tr><td rowspan=1 colspan=1>Aircrafts</td><td rowspan=1 colspan=1>“a photo of the”,“a close-up photo of the&quot;,&quot;a good photo ofthe”,&quot;a pixelated photo of the”</td><td rowspan=1 colspan=1>“a typeof plane”,“a typeof aircraft”,“atype of airliner”</td><td rowspan=1 colspan=1>None,&quot;I like it”,“It&#x27;s important to me”,“I take it today”,“Hopeyou like it”</td></tr><tr><td rowspan=1 colspan=1>Oxford Pet</td><td rowspan=1 colspan=1>“a photo of my”,“a low reso-lution photo of my”,“a goodphoto of my”</td><td rowspan=1 colspan=1>“a type of pet”,“a type of dogor cat”</td><td rowspan=1 colspan=1>None,“It&#x27;s cute”,“It&#x27;s impor-tant to me”,“I like it”,“It’sbeautiful&quot;</td></tr><tr><td rowspan=1 colspan=1>EuroSAT</td><td rowspan=1 colspan=1>“a photo of a”,“apainting of a”,&quot;a cropped photo of a”,&quot;a good photo of a”,“a blurry photo ofa”</td><td rowspan=1 colspan=1>None,“an ex-ample of aerialor satellite im-ages”</td><td rowspan=1 colspan=1>None,“I like it”,“It&#x27;s takenfrom an aircraft or some flying object”,&quot;It&#x27;s collected by imag-ing satellites”</td></tr></table>
337
+
338
+ Table 12: Prompt templates used for zero-shot image-text retrieval on Flickr30K and MSCOCO datasets.
339
+
340
+ <table><tr><td rowspan=1 colspan=1>Dataset</td><td rowspan=1 colspan=1>Task</td><td rowspan=1 colspan=1>Prefix</td><td rowspan=1 colspan=1>Suffix</td></tr><tr><td rowspan=1 colspan=1>Flickr30K</td><td rowspan=1 colspan=1>image-to-text retrievaltext-to-image retrieval</td><td rowspan=1 colspan=1>“a good photo of the”“a good photo of”</td><td rowspan=1 colspan=1>“I hate it.”None</td></tr><tr><td rowspan=1 colspan=1>MSCOCO</td><td rowspan=1 colspan=1>image-to-text retrievaltext-to-image retrieval</td><td rowspan=1 colspan=1>“a good photo of”None</td><td rowspan=1 colspan=1>“It is ugly.”None</td></tr></table>
341
+
342
+ Image-text Retrieval. Following CLIP (Radford et al., 2021), we use prompt in zero-shot imagetext retrieval for both Flickr30K and MSCOCO datasets. The prompt is selected by the same rule as described in Section 3.1.2, except that we do not use “[category description]” here. Table 12 shows the prompt templates for zero-shot image-text retrieval on Flickr30K and MSCOCO datasets.
343
+
344
+ # A.6 LINEAR PROBE ON IMAGE CLASSIFICATION
345
+
346
+ In this section, we evaluate FILIP on the linear probe for image classification. Following common linear probe setting, we freeze the whole backbone network and only finetune the last linear classifier. Since we remove the “[CLS]” token in our vision encoder, we apply a mean pooling over all the other visual tokens to aggregate them into a global image representation which is then fed into the linear classifier.
347
+
348
+ Setting. Following CLIP, we train the logistic regression classifier using scikit-learn’s L-BFGS implementation (Pedregosa et al., 2011), with maximum 1,000 iterations on those 11 datasets except ImageNet. For ImageNet, we use a pytorch-based codebase to accelerate the training with GPU. Following Doersch et al. (2015), we adopt a Batch Normalization (Ioffe & Szegedy, 2015) layer before the linear classifier which is beneficial to stabilize the mixed-precision training. Random resized crop and horizontal flipping are used to augment training data. We use the cosine learning rate scheduler with a linear warmup of 10 epochs. More hyperparameters used in linear probe on ImageNet are shown in Table 13.
349
+
350
+ Table 13: Hyperparameters used for linear probe image classification on ImageNet.
351
+
352
+ <table><tr><td>Hyperparameter</td><td>Value</td></tr><tr><td>Image size</td><td>224 × 224</td></tr><tr><td>Training epochs</td><td>90</td></tr><tr><td>Optimizer</td><td>SGD</td></tr><tr><td>Batch size</td><td>4096</td></tr><tr><td>Base LR</td><td>0.1</td></tr><tr><td>Weight decay</td><td>0</td></tr></table>
353
+
354
+ Results. Table 14 compares the linear probe performance of our proposed FILIP with CLIP over 12 datasets. Our ${ \mathrm { F I L I P } } _ { \mathrm { b a s e } }$ (resp. ${ \mathrm { F I L I P } } _ { \mathrm { l a r g e } }$ ) achieves $8 5 . 5 \%$ (resp. $9 1 . 0 \% )$ average Top-1 accuracy over 12 downstream tasks, which provides noticeable improvements, i.e., $1 . 8 \%$ (resp. $1 . 2 \%$ ) higher, compared to its CLIP’s counterpart. This implies that our FILIP learns more powerful vision features which may potentially facilitate border downstream vision tasks.
355
+
356
+ # A.7 COMPARISON WITH KHATTAB & ZAHARIA (2020)
357
+
358
+ As is stated in Section 3.1, compared to Khattab & Zaharia (2020), besides being the first to apply the late interaction to contrastive learning for vision-language pre-training, we make two other modifications, i.e., removing padded tokens and using average over non-padded tokens instead of summation. In the following, we show that these two modifications are crucial to the performance, and the quality of finer-granular word-patch alignment.
359
+
360
+ For comparison, we replace the proposed cross-modal late interaction in FILIPbase with the original late interaction in Khattab & Zaharia (2020). Following the setting in Section 4.4, we pre-train on
361
+
362
+ Table 14: Top-1 accuracy $( \% )$ of linear probe on image classification on 12 datasets. Our FILIP outperforms CLIP by $1 . 2 { \sim } 1 . 8 \%$ points on average.
363
+
364
+ <table><tr><td></td><td>CIRIIIO</td><td>CEIRIIIO</td><td>srrprrrets [Erleaer</td><td>TiroTenIG</td><td></td><td>[o1poo</td><td>L6610S</td><td></td><td>Viririt</td><td>siorprttrt</td><td>JoIA aneee</td><td>Aaee</td></tr><tr><td>CLIP-ViT-B/32 FILIPbase</td><td>95.1 95.3</td><td>80.5 80.3</td><td>93.0 95.0</td><td>81.8 78.6</td><td>96.6 98.7</td><td>88.8 86.2</td><td>76.6 77.9</td><td>76.5 78.1</td><td>52.0 76.6</td><td>90.0 88.0</td><td>97.0 76.1 95.9 75.8</td><td>83.7 85.5+1.8</td></tr><tr><td>CLIP-ViT-L/14 FILIPlarge</td><td>98.0 97.9</td><td>87.5 87.0</td><td>96.5 97.2</td><td>90.9 89.0</td><td>99.2 99.6</td><td>95.2 94.6</td><td>81.8 82.1 83.2</td><td>69.4 83.9 84.8</td><td>95.1 93.5</td><td>98.2 97.3</td><td>83.9 84.5</td><td>89.8 91.0+1.2</td></tr></table>
365
+
366
+ the filtered YFCC100M with mixed-precision using 8 V100 GPUs. The batch size per GPU is 512 and the dimension of the token feature is 256. We report results with the top $2 5 \%$ tokens (selected using the method in Section 3.1) during training. Note that the original late interaction in Khattab & Zaharia (2020) is sensitive to the temperature in the softmax function, and we report the best result among several initialization values of the temperature.
367
+
368
+ Effect to Performance. Table 15 shows the comparison on zero-shot ImageNet classification. When these two modifications are removed, the zero-shot Top-1 accuracy of ImageNet drops from 34.3 to 32.7.
369
+
370
+ Table 15: Comparison of Top-1 Accuracy $\%$ between the proposed cross-modal late interaction loss and Khattab & Zaharia (2020) on zero-shot ImageNet classification.
371
+
372
+ <table><tr><td>ours</td><td>late interaction in Khattab &amp; Zaharia (2020)</td></tr><tr><td>34.3</td><td>32.7</td></tr></table>
373
+
374
+ Effect to the Word-patch Alignment In Figure 4, we compare the word-patch alignment using the models trained with the proposed cross-modal late interaction and the late interaction in Khattab & Zaharia (2020). According to the visualizations, using the original late interaction in Khattab & Zaharia (2020) leads to less accurate word-patch alignment. Specifically, the object patches are often aligned to the padded tokens instead of class names. We speculate this is because the padded tokens learn similar representations as existing key textual tokens, similar to the finding in Section 3.2 of Khattab & Zaharia (2020) that padding with masked tokens (which is called “query augmentation” in Khattab & Zaharia (2020)) tend to “re-weigh existing terms based on their importance for matching the query”.
375
+
376
+ # A.8 ABLATION ON THE FULL PRE-TRAINING DATASET
377
+
378
+ In Table 16, we compare the proposed cross-modal late interaction loss with the original CLIP loss (Radford et al., 2019) on the full pre-training dataset introduced in Section 3.3. In Table 16, CLIP denotes the results reported by CLIP paper, ${ \mathrm { C L I P } } _ { \mathrm { r e p } }$ is our reproduced CLIP version with the original contrastive loss using exactly the same architecture on the same pre-training dataset as $\mathrm { F I L I P _ { b a s e } }$ . As can be seen, the $\mathrm { F I L I P _ { b a s e } }$ has 6.7 points higher average accuracy than the ${ \mathrm { C L I P } } _ { \mathrm { r e p } }$ over 12 datasets. This further verifies that the performance gain of FILIP comes from the proposed cross-modal late interaction, rather than the data or architecture.
379
+
380
+ # A.9 INFERENCE TIME OF IMAGE-TEXT RETRIEVAL
381
+
382
+ Setting. In this section, we test the inference time of both image retrieval and text retrieval on the test set of Flickr30K and MSCOCO. We compare our proposed model $\mathrm { F I L I P _ { l a r g e } }$ against SCAN (Lee et al., 2018) and CLIP (ViT-L/14) (Radford et al., 2021) . We test the inference time of CLIP and SCAN using their released code. For image retrieval, we precompute the image features and report the inference time for one text query, which contains (i) the time to extract the feature of one text query, and (ii) the time of similarity calculation with all images and ranking. Similarly, for text retrieval, we precompute the text features and report the inference time for one image query, which contains (i) the time to extract the feature of one image query, and (ii) the time of similarity calculation with all texts and ranking. The test set of Flickr30k contains 1000 images and 5000 texts, while the test set of COCO contains 5000 images and 25000 texts. The time is averaged over 1000 runs.
383
+
384
+ ![](images/a5708b0450ce3bc341085d20067e241dfa3db9047c48f75fee7bd4b01f5c1f76.jpg)
385
+ Figure 4: Comparison of word-patch alignment between the proposed cross-modal late interaction and that in ColBERT (Khattab & Zaharia, 2020). “a photo of a $\{ { \mathrm { l a b e l } } \}$ .” is the prompt. Numbers in the parentheses after the class label indicate the location indices of the class label in the tokenized textual sequence. The correct predictions to the class labels are highlighted by opaque patches with the class label indices in red. Incorrect predictions to the padded tokens are highlighted by opaque patches with the padded token indices in blue.
386
+
387
+ Table 16: Top-1 accuracy $\textcircled{9}$ on image classification on 12 datasets. ${ \mathrm { C L I P } } _ { \mathrm { r e p } }$ is our reproduced CLIP trained with the same training data and evaluated with the same prompts as our FILIP. With the same backbone architecture, our FILIP significantly improves the zero-shot Top-1 average accuracy over 12 datasets.
388
+
389
+ <table><tr><td></td><td>CIIIII</td><td>CEIRII</td><td>GErreaaer</td><td>srrprrtts</td><td>Tirsoii</td><td>TO1poo0</td><td>163305</td><td></td><td>Sirit</td><td>sodpptrr JHtoII</td><td>1ne</td><td>eee</td></tr><tr><td>CLIP</td><td>91.3</td><td>65.1</td><td>87.9</td><td>59.4</td><td>66.7</td><td>84.4</td><td>63.2</td><td>44.5</td><td>21.2</td><td>87</td><td>49.4 63.2</td><td>65.3</td></tr><tr><td>CLIPrep</td><td>82.0</td><td>57.5</td><td>89.9</td><td>45.1</td><td>80.7</td><td>75.1</td><td>63.6 46.7</td><td>33.7</td><td>82.7</td><td>49.0</td><td>64.2</td><td>64.2</td></tr><tr><td>FILIPbase</td><td>86.9</td><td>65.5</td><td>91.9</td><td>55.4</td><td>85.3</td><td>82.8 69.1</td><td>49.3</td><td>57.2</td><td>88.1</td><td>49.9</td><td>68.8</td><td>70.9</td></tr></table>
390
+
391
+ Table 17: Comparison on performance and inference time of image-text retrieval on Flickr30K and MSCOCO datasets.
392
+
393
+ <table><tr><td></td><td colspan="10">Flickr30K</td><td colspan="6">Inference time</td></tr><tr><td></td><td>image-&gt;text</td><td colspan="3"></td><td colspan="3"></td><td colspan="5">MSCOCO</td><td colspan="3">Flickr30K</td><td colspan="2">MSCOCO</td></tr><tr><td>R@1</td><td></td><td>R@5</td><td>R@10</td><td>R@1</td><td>text-&gt;image R@5</td><td>R@10</td><td>R@1</td><td>image-&gt;text R@5</td><td>R@10</td><td>R@1</td><td>text-&gt;image R@5</td><td>R@10</td><td>i-to-t</td><td>t-to-i</td><td>i-to-t</td><td>t-to-i</td></tr><tr><td>SCAN</td><td>67.4</td><td>90.3</td><td>95.8</td><td>48.6</td><td>77.7</td><td>85.2</td><td>50.4</td><td>82.2</td><td>90.0</td><td>38.6</td><td>69.3</td><td>80.4</td><td></td><td></td><td></td><td>21.3s</td><td>26ms</td></tr><tr><td>CLIP</td><td>88.0</td><td>98.7</td><td>99.4</td><td>68.7</td><td>90.6</td><td>95.2</td><td></td><td>58.4 81.5</td><td>88.1</td><td>37.8</td><td>62.4</td><td></td><td>72.2</td><td>4.47s 23ms</td><td>7ms 8ms</td><td>24ms</td><td>9ms</td></tr><tr><td>FILIP</td><td>96.6</td><td>100.0</td><td>100.0</td><td>87.1</td><td>97.7</td><td>99.1</td><td>78.9</td><td>94.4</td><td>97.4</td><td>61.2</td><td>84.3</td><td>90.6</td><td></td><td>24ms</td><td>8ms</td><td>26ms</td><td>9ms</td></tr></table>
394
+
395
+ Results. The inference time of retrieval is shown in Table 17. Benefitting from the efficiency optimizations (i.e., FP16 quantization and reduced feature dimension) in Section 3.1, the inference time of FILIP is close to CLIP. In image retrieval, SCAN is slightly faster than FILIP on Flickr30K with 1000 images, because SCAN uses a lightweight GRU as the text encoder. However, SCAN is much slower than FILIP (i.e., about $1 7 \mathrm { m s }$ slower per query) on MSCOCO with more (i.e., 5000) images because of the slower computation involved in the two-stage stacked cross-attention when computing the similarity. For text retrieval, SCAN is much slower than FILIP and its own image retrieval, mainly due to three reasons: (i) the image encoder is a Faster RCNN which is more expensive than the lightweight GRU text encoder; (ii) the text candidates are 5 times more than the image candidates in image retrieval; and (ii) the similarity computation of SCAN relies on the cross-attention computation, which is not straightforward to be paralleled, even in their official code; while our FILIP’s similarity computation is simply a matrix multiplication and is readily optimized on most modern hardwares.
parse/dev/cpDhcsEDC2/cpDhcsEDC2_content_list.json ADDED
The diff for this file is too large to render. See raw diff
 
parse/dev/cpDhcsEDC2/cpDhcsEDC2_middle.json ADDED
The diff for this file is too large to render. See raw diff
 
parse/dev/h0OYV0We3oh/h0OYV0We3oh.md ADDED
The diff for this file is too large to render. See raw diff
 
parse/dev/h0OYV0We3oh/h0OYV0We3oh_content_list.json ADDED
The diff for this file is too large to render. See raw diff
 
parse/dev/h0OYV0We3oh/h0OYV0We3oh_model.json ADDED
The diff for this file is too large to render. See raw diff
 
parse/dev/k9bx1EfHI_-/k9bx1EfHI_-_middle.json ADDED
The diff for this file is too large to render. See raw diff
 
parse/dev/k9bx1EfHI_-/k9bx1EfHI_-_model.json ADDED
The diff for this file is too large to render. See raw diff
 
parse/dev/uLYc4L3C81A/uLYc4L3C81A.md ADDED
@@ -0,0 +1,418 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Confident Adaptive Language Modeling
2
+
3
+ Tal Schuster1,⇤ Adam Fisch2,⇤ Jai Gupta1
4
+
5
+ Mostafa Dehghani1 Dara Bahri1 Vinh Q. Tran1 Yi Tay1 Donald Metzler1
6
+
7
+ 1Google Research 2CSAIL, MIT
8
+
9
+ # Abstract
10
+
11
+ Recent advances in Transformer-based large language models (LLMs) have led to significant performance improvements across many tasks. These gains come with a drastic increase in the models’ size, potentially leading to slow and costly use at inference time. In practice, however, the series of generations made by LLMs is composed of varying levels of difficulty. While certain predictions truly benefit from the models’ full capacity, other continuations are more trivial and can be solved with reduced compute. In this work, we introduce Confident Adaptive Language Modeling (CALM), a framework for dynamically allocating different amounts of compute per input and generation timestep. Early exit decoding involves several challenges that we address here, such as: (1) what confidence measure to use; (2) connecting sequence-level constraints to local per-token exit decisions; and (3) attending back to missing hidden representations due to early exits in previous tokens. Through theoretical analysis and empirical experiments on three diverse text generation tasks, we demonstrate the efficacy of our framework in reducing compute—speedup of up to $\times 3 .$ —while provably maintaining high performance.
12
+
13
+ # 1 Introduction
14
+
15
+ Recent advances in Large Language Models (LLMs) have led to breakthroughs in language understanding and language generation across almost every widely-used Natural Language Processing (NLP) task considered in the field today [5; 15; 17; 20; 51; 52; 53; 75; 89; 73]. Autoregressive language modeling provides a flexible framework for solving complex tasks with a unified natural language input and output format, while also relaxing the need for large-scale task-specific data collection and training [67; 15; 17; 58; 80]. The large size of LLMs, however, results in massive computational load that might be limiting for certain real-world applications (e.g., machine translation) [9; 30; 42; 49; 59; 63; 71]. This is especially pronounced in the autoregressive decoding process where the full stack of Transformer layers is repeatedly computed for each output token [37; 40; 86].
16
+
17
+ While large models do better in general, the same amount of computation may not be required for every input to achieve similar performance (e.g., depending on if the input is easy or hard) [66]. Early exiting is a promising approach to decreasing the computational cost of multilayered architectures such as those used in Transformer-based LLMs, where the number of layers used by the model is dynamically decided on an input-by-input basis [18; 23; 57; 60; 70]. In this setting, an LLM can choose to generate a new token based off the representation at an intermediate layer instead of using the full model, and save computation as a result. A natural question that arises, however, is when is it a good decision to exit early, as opposed to wait? Naively choosing when to exit can be suboptimal in terms of saving computation time, and also result in unpredictable degradations to model performance, especially when predictions depend on each other, as in autoregressive language generation.
18
+
19
+ ![](images/6403c6cf0f82b2a39928dda68d9bb61b123b168bef6e6e383a2672124b140f74.jpg)
20
+ Figure 1: Illustration of CALM generation (see Figure 4 for the full example) with local per-token early exiting decisions that provably satisfy global user-defined constraints on the full sequence.
21
+
22
+ In this work, we analyze the early exiting paradigm for LLMs, and present a principled method for increasing model efficiency while remaining confident in the quality of the resulting predictions. Specifically, we develop a method for calibrating local, per-token, exit decisions such that global, sequence-level constraints—as determined by lexical or semantic sequence-level metrics like ROUGE or BLEURT score—are provably maintained with arbitrarily high probability (e.g., $9 5 \%$ ). This process, which we call Confident Adaptive Language Modeling (CALM), is illustrated in Figure 1.
23
+
24
+ Our approach leverages recent techniques in distribution-free risk control in order to create confident generations with strong statistical guarantees [2; 3; 10]. Concretely, suppose we have been given a calibration set $S _ { \mathrm { c a l } } : = \{ P _ { i } \} _ { i = 1 } ^ { n } \in \mathcal { P } ^ { n }$ of independent and identically distributed (i.i.d.) prompts to our LLM (e.g., paragraphs to be summarized, sentences to be translated, or questions to be answered via language modeling). Let $P _ { \mathrm { t e s t } }$ be a new i.i.d. test prompt to our LLM, where $Y _ { \mathrm { e a r l y } } : =$ $\mathbf { L L M } _ { \mathrm { e a r l y } } ( P _ { \mathrm { t e s t } } )$ and $Y _ { \mathrm { f u l l } } : = \mathrm { L L M } _ { \mathrm { f u l l } } ( P _ { \mathrm { t e s t } } )$ are the adaptive and standard outputs of our LLM, respectively. In order to be satisfied with $Y _ { \mathrm { e a r l y } }$ , we might require it to be textually consistent with $Y _ { \mathrm { f u l l } }$ . Given any bounded text dissimilarity function $\mathcal { D }$ , we aim to calibrate the early-exiting LLM such that its predictions agree to a tolerance $\delta$ with the full model in expectation with high probability,
25
+
26
+ $$
27
+ \begin{array} { r } { \mathbb { P } \Big ( \mathbb { E } \big [ \mathcal { D } ( Y _ { \mathrm { e a r l y } } , Y _ { \mathrm { f u l l } } ) \big ] \leq \delta \mid \mathcal { S } _ { \mathrm { c a l } } \Big ) \geq 1 - \epsilon , } \end{array}
28
+ $$
29
+
30
+ where the randomness is over draws of $ { S _ { \mathrm { c a l } } }$ , and $\epsilon \in ( 0 , 1 )$ . Eq. (1) has the significant advantage of being achievable using only unlabeled calibration data $ { S _ { \mathrm { c a l } } }$ (a quality that is critical for fewshot tasks, for example). Enforcing textual consistency with the original $Y _ { \mathrm { f u l l } }$ , however, may be unnecessarily strict for certain tasks, especially where multiple generations may be acceptable. As an alternative, given a calibration set of prompts paired with a set of (potentially multiple) target references, $\bar { S _ { \mathrm { c a l } } } : = \{ ( P _ { i } , Z _ { i } ) \} _ { i = 1 } ^ { n } \in ( \mathcal { P } \times 2 ^ { \mathcal { V } } ) ^ { \bar { n } }$ , and any bounded risk function $\mathcal { R }$ , we also consider an objective that enforces risk consistency by limiting the relative increase in risk of the predictions $Y _ { \mathrm { e a r l y } }$ compared to $Y _ { \mathrm { f u l l } }$ , with respect to the set of test-time references $Z _ { \mathrm { t e s t } }$ , i.e.,
31
+
32
+ $$
33
+ \mathbb { P } \Big ( \mathbb { E } \big [ \mathcal { R } ( Y _ { \mathrm { e a r l y } } , Z _ { \mathrm { t e s t } } ) - \mathcal { R } ( Y _ { \mathrm { f u l l } } , Z _ { \mathrm { t e s t } } ) \big ] \leq \delta \big | \ S _ { \mathrm { c a l } } \Big ) \geq 1 - \epsilon .
34
+ $$
35
+
36
+ Within the constraints of either Eq. (1) or Eq. (2), the goal of our work is to find the most computationally efficient $Y _ { \mathrm { e a r l y } }$ , i.e., generations that exit as early as possible while still maintaining our desired performance guarantees. In order to achieve this, it is necessary to develop a reliable signal for how likely local, per-token early-exit decisions are to disrupt the global properties of the complete sequence. Here, we first analyze how errors are propagated in Transformer-based LLMs, and then present an effective and efficient scoring mechanism for assigning “consistent early-exit” confidence scores after each layer used during the generation of a new token. The decision to exit or not is based on these scores, and is carefully calibrated using $ { S _ { \mathrm { c a l } } }$ such that our performance bounds are provably satisfied.
37
+
38
+ Finally, we empirically validate our method on multiple, diverse NLP generation tasks, including text summarization, machine translation, and question answering. Our experiments demonstrate the potential of CALM in reducing the average complexity of the model and accelerating inference by about $\times 3$ while reliably controlling for high performance.
39
+
40
+ Contributions. In summary, our main contributions are as follows:
41
+
42
+ • A framework (CALM) for reliably accelerating Transformer-based LLM generations. • A systematic analysis of the token-wise early exit mechanism that motivates a simple-but-effective class of confidence measures and threshold functions that are used as part of the CALM framework. • An empirical demonstration of CALM’s efficiency gains on three diverse generation datasets.
43
+
44
+ # 2 Related Work
45
+
46
+ Improving inference-time efficiency of LLMs has been an ongoing effort of the research community over the past several years [49; 72; 85], leveraging techniques such as knowledge distillation [6; 32; 36; 69; 69; 78; 56], floating point quantization [71; 65], layer pruning [24], vector dropping [38], and others [41]. Another line of work involves conditional computation to train larger models that only use a sparser subset of the full network during inference, for example by routing over mixture-ofexperts [9; 22; 39; 91], recurring modules [18; 29; 35], or accessing external memory [82]. These models, however, still use the same amount of compute for all input examples.
47
+
48
+ Here, we focus on adaptive compute, a specific kind of conditional compute that aims to dynamically allocate different computational power per example, with the goal of reducing the overall complexity while maintaining high performance. This approach, often referred to as early-exiting [16; 25; 47; 74; 79; 87], is complementary to many of the solutions above and can potentially be combined with them. Multiple early-exit techniques for encoder-only Transformers (e.g., BERT [20]) have been recently proposed [8; 34; 43; 44; 45; 60; 68; 83; 90; 92]. Most of these methods rely on intrinsic confidence measures (e.g., based on the softmax distribution), while others try to predict the routing in advance [46; 70], or train a small early-exit classifier [57; 84], as we also examine here. These measures can be calibrated to reliably guarantee consistency of the early prediction with the full model [57]. However, the techniques used for encoder-only classifiers are unsuitable for global consistency constraints with a sequence of dependent predictions, which are inherent in the decoding process of autoregressive language models, which we address here.
49
+
50
+ Our work is also motivated by recent findings on the existence of saturation events in LMs, where the top-ranked prediction is unchanged after some layer and is propagated upward. Geva et al. [28] examined interactions of the hidden-state with feed-forward layers to predict these events. However, they only consider local single predictions and do not address the challenges involved with sequence generation. Our early-exit LM architecture most closely relates to Elbayad et al. [23], who found a tokenlevel early-exit classifier to provide the best efficiency-performance tradeoffs on machine translation. Here, we introduce a theoretically-grounded calibration method for provably controlling the quality of the full sequence. By doing so, we provide reliable efficiency gains—deriving local early exiting decisions from the global desirable constraints. Moreover, we introduce several model improvements and empirical analyses, including (1) analyzing the primary sources of performance degradation, leading us to propose a decaying threshold function for better tradeoff control without inflating the search space; (2) improving the early-exit classifier training; and (3) experimenting with two new tasks.
51
+
52
+ Our calibration procedure for connecting global constraints to local decisions, relates to recent research around distribution-free uncertainty quantification [1; 62; 77]. Several methods were developed in recent studies to expand and adjust the theoretical framework for obtaining practical efficiency gains on target applications [4; 7; 21; 26; 27; 48; 88]. Here, we frame our consistency requirements around the Learn then Test (LTT) framework [3], and leverage the approximately monotonic behavior of our confidence measures and the nested structure of our problem, that by definition guarantees consistency with large enough threshold, to form tight and effective bounds.
53
+
54
+ # 3 Early Exiting for Adaptive Language Modeling
55
+
56
+ In the following, we describe and analyze the early-exiting Transformer LM. We begin with a brief recap of the Transformer architecture (§3.1) and early exiting (§3.2) for convenience, following previous work [23; 70; 76]. We then investigate the effects of early exiting on model performance, and identify primary sources of performance degradation and how to alleviate them (§3.3)—which guide our architecture and training design (§3.4) and proposed per-token confidence measures (§3.5).
57
+
58
+ # 3.1 The Transformer architecture
59
+
60
+ We use the Transformer sequence-to-sequence model, based on the T5x implementation [55]. Here, we only review simplified details of the Transformer architecture relevant to early-exiting, and refer the reader to Vaswani et al. [76] for full details. At a high level, both encoder and decoder networks contain $L$ stacked layers, where each layer is composed of a multi-head self-attention sub-layer, followed by a feedforward sub-layer, each with residual connections and layer normalization. The decoder network has an additional multi-head attention sub-layer that attends to the encoder states.
61
+
62
+ Consider a prompt $\boldsymbol { x } = ( x _ { 1 } , \dots , x _ { p } )$ , processed by the encoder to yield encoder states $( e _ { 1 } , \ldots , e _ { p } )$ , and the current, partially generated response $( y _ { 1 } , \dots , y _ { t } )$ . When generating the next token $y _ { t + 1 }$ , the decoder computes a decoder state $d _ { t } ^ { i }$ for layer $i$ out of $L$ as:
63
+
64
+ $$
65
+ \begin{array} { r } { h _ { t } ^ { i } : = \mathrm { A t t e n t i o n } ( d _ { t } ^ { i - 1 } , d _ { 1 : t - 1 } ^ { i - 1 } ) ; \quad a _ { t } ^ { i } : = \mathrm { A t t e n t i o n } ( h _ { t } ^ { i } , e _ { 1 : p } ) ; \quad d _ { t } ^ { i } : = \mathrm { F e e d F o r w a r d } ( a _ { t } ^ { i } ) . } \end{array}
66
+ $$
67
+
68
+ Internal to each of the attention mechanisms, written as $\mathrm { A t t e n t i o n } ( x , z _ { 1 : m } )$ for some input $x$ and sequence of $m$ states $z _ { 1 : m }$ , $x$ is first projected to a query vector $q : = \mathbf { W } _ { Q } x \in \mathbb { R } ^ { \dim _ { k } }$ , while $z$ is projected to a matrix of key-value vectors, $\mathbf { K } : = \mathbf { W } _ { K } z _ { 1 : m } \in \mathbb { R } ^ { m \times \mathrm { d i m } _ { k } }$ and $\mathbf { V } : = \mathbf { W } _ { V } z _ { 1 : m } \in$ $\mathbf { \mathbb { R } } ^ { m \times \dim _ { v } }$ . The output $o$ is then computed as o := softmax $\left( q \mathbf { K } ^ { \top } / \sqrt { \mathrm { d i m } _ { k } } \right) \mathbf { V }$ .
69
+
70
+ Multi-head and normalization components are omitted for brevity. Each layer uses different projections $\mathbf { W } _ { Q } ^ { i } , \mathbf { W } _ { K } ^ { i }$ , and $\mathbf { W } _ { V } ^ { i }$ (which are also unique for computing $h _ { t } ^ { i }$ versus $\dot { a } _ { t } ^ { i \cdot }$ ).
71
+
72
+ Finally, after layer $L$ , a distribution over vocabulary tokens $y _ { t + 1 } \in \mathcal { D }$ is computed via a softmaxnormalized linear classifier $\mathbf { W } _ { L }$ , where $p ( y _ { t + 1 } \mid d _ { t } ^ { L } ) = \mathrm { s o f t m a x } ( \mathbf { W } _ { L } d _ { t } ^ { L } )$ .
73
+
74
+ # 3.2 Decoding with early exiting
75
+
76
+ Instead of always making a prediction based on the representation at the final layer, $d _ { t } ^ { L }$ , the key idea in early-exiting is to choose $y _ { t + 1 }$ more quickly, if confident, by computing $p ( y _ { t + 1 } \mid d _ { t } ^ { i } ) =$ softmax $( \dot { W _ { i } } \dot { d _ { t } ^ { i } } )$ for some intermediate layer $i < L$ . Concretely, let $\bar { c } _ { t } ^ { i } \in [ \bar { 0 } , 1 ]$ denote some local confidence score for layer $i$ while processing token $t$ , where higher values indicate a higher propensity to exit early (we will propose effective instantiations of $c _ { t } ^ { i }$ in $\ S 3 . 5 )$ . Let $\lambda _ { t } ^ { i } \in [ 0 , 1 ]$ denote some local early-exiting threshold, where the model exits early if $c _ { t } ^ { i } \geq \lambda _ { t } ^ { i }$ , or otherwise proceeds to compute the next representation, $d _ { t } ^ { i + 1 }$ . The (greedily chosen) prediction $y _ { t + 1 }$ can then be written as:
77
+
78
+ $$
79
+ y _ { t + 1 } : = \left\{ \begin{array} { l l } { \arg \operatorname* { m a x } p ( y _ { t + 1 } \mid d _ { t } ^ { 1 } ) \quad } & { \mathrm { i f } c _ { t } ^ { 1 } \geq \lambda _ { t } ^ { 1 } , } \\ { \arg \operatorname* { m a x } p ( y _ { t + 1 } \mid d _ { t } ^ { 2 } ) \quad } & { \mathrm { i f } c _ { t } ^ { 2 } \geq \lambda _ { t } ^ { 2 } , } \\ { \quad } & { \ \vdots } \\ { \arg \operatorname* { m a x } p ( y _ { t + 1 } \mid d _ { t } ^ { L } ) \quad } & { \mathrm { o t h e r w i s e } . } \end{array} \right.
80
+ $$
81
+
82
+ Note that due to the self-attention mechanism of the Transformer, computing the input hidden state $h _ { t } ^ { i }$ for layer $i$ depends on $d _ { 1 : t - 1 } ^ { i - 1 }$ , i.e., the output hidden states of the previous layer for all the tokens that have been generated so far.2 Therefore, if the model has early exited at some layer $j < i - 1$ for a token $s < t$ , then $d _ { s } ^ { i - 1 }$ is not available. As an approximation, we set $d _ { s } ^ { k } = d _ { s } ^ { j }$ for all layers $k > j$ following Elbayad et al. [23], with the understanding that this will introduce some error. In the next section, in addition to other factors, we will analyze the impact of this copied state on performance.
83
+
84
+ # 3.3 The effects of early exiting on error propagation
85
+
86
+ We perform several controlled experiments to investigate the behavior and the potential of earlyexiting during decoding. We use an 8-layer T5 encoder-decoder and the CNN/DM dataset for these experiments. See $\ S 5$ for more details on this model and data.
87
+
88
+ # 3.3.1 State propagation
89
+
90
+ First, we control for the correctness of the predicted tokens to examine the effect of state copying (§3.2), and also measure an approximate upper bound for compute reduction. We use an oracle confidence measure that exits at the earliest layer that agrees with the top prediction (i.e., replacing the conditions in Eq. 4 with arg max $p ( y _ { t + 1 } \mid \bar { d } _ { t } ^ { i } ) = \arg \operatorname* { m a x } p ( y _ { t + 1 } \mid { \dot { d } } _ { t } ^ { \hat { L } } ) )$ . Hence, the only factor that can cause divergence in the generation is the state copying mechanism for skipped layers. The results of this experiment are highly encouraging. This oracle achieves an ROUGE-L score of 38.24, compared to 38.32 with the full model, while only using an average of 1.53 layers per token. We also try an oracle that always uses $d _ { 1 : t - 1 } ^ { 1 }$ and it reaches 38.31 ROUGE-L. These results indicate that (1) the model is robust to state copying from lower layers, and (2) there is remarkable potential for saving compute—by up to $\times 5 . 2$ —while preserving performance, given a good confidence measure.
91
+
92
+ We also experiment with copying the projected states $\mathbf { K } ^ { j } , \mathbf { V } ^ { j }$ to skipped layers $k > j$ . This version of the oracle results in a significant drop in performance to 23.02 ROUGE-L. Overall, we conjecture that the self-attention at layer $i$ for token $t$ can safely use hidden-states $d _ { s } ^ { j }$ for $j < i - 1$ as key-values of tokens $s < t$ , as long as the projections $\mathbf { W } _ { K / V } ^ { i }$ of layer $i$ are used. Notably, this projection can now be computed concurrently for all skipped layers as they all use the same $d$ from the exited layer.
93
+
94
+ ![](images/c9293fe540f82f85222a9ced360ae50fb5c8012dd05f8b51c72a691482b5286a.jpg)
95
+ Figure 2: Earlier noise in the decoding process has greater effect on the overall output (a), though in practice the affect of early exits is minor due to high performance of early layers. A decaying confidence threshold (b) allows finer control over the performance-efficiency tradeoff (c).
96
+
97
+ # 3.3.2 Sensitivity to local errors
98
+
99
+ Next, we examine the impact of local token modifications—which might occur due to early exits—on the whole generated sequence. We experiment with two kinds of perturbations: sampling-based, where we select the 10th-ranked token according to layer $L$ ; and layer-based, where we select the the first layer’s prediction at timestep $t$ . All other tokens are predicted greedily by layer $L$ . As shown in Figure 2a, earlier perturbations result in lower sequence-level scores as there are more tokens that might suffer from the divergence. The degradation, though, is much smaller with layer- compared to sampling-based perturbations since, in practice, the early exit predictions are mostly accurate.
100
+
101
+ Decaying threshold. Following the above observation, we introduce a decaying early-exiting threshold that is more permissive towards exiting as the decoding process continues. Motivated by the logarithmic behavior in Figure 2a, we use an exponential function with a user-defined temperature $\tau$ :
102
+
103
+ $$
104
+ \lambda ^ { \prime } ( \lambda , t ) : = \mathrm { c l i p } _ { [ 0 , 1 ] } \left( \frac { 9 } { 1 0 } \lambda + \frac { 1 } { 1 0 } e ^ { - \tau \cdot t / N } \right) ,
105
+ $$
106
+
107
+ where $N$ is the maximum output length. Figure 2b illustrates this function. Essentially, this function presents an effective compromise between simply using the same threshold for all tokens, and searching over a huge space of per-position different thresholds. Practically, it supports finer and better control over the performance-efficiency tradeoff compared to a single threshold. Figure $2 \mathrm { c }$ presents the outcomes of a search over $\lambda$ with steps of 0.01 and softmax-based confidence $( \ S 3 . 5 )$ . With the single threshold variant $( \tau = 0$ ), attempting to improve the efficiency will lead to a drastic drop of more than 10 points in the textual similarity against the full model’s prediction. In contrast, the decaying thresholds reveal several intermediate points with desirable tradeoffs to consider.
108
+
109
+ # 3.4 Training early exit classifiers for local consistency
110
+
111
+ While our goal is to preserve the quality of the complete output sequence, we note that this doesn’t necessarily demand local token-level consistency. Consider the target sequence “the concert was wonderful and long.” An output that switches the order of adjectives to “the concert was long and wonderful” would be called consistent by most semantic measures (and obtain 100 token- $F _ { 1 }$ score). Yet, the sentences diverge at the first adjective long which is semantically different from wonderful.
112
+
113
+ Training for global consistency, however, could be challenging [81] as it depends on possibly noisy signals that might affect the learning, and also breaks the efficient teacher-forcing training strategy of LMs that relies on local-decisions. On the other hand, perfect local consistency implies global consistency. Therefore, we opt to train for local consistency, which requires minimal changes to the training procedure, and relax the local requirement to a global one during inference.
114
+
115
+ Specifically, similar to Elbayad et al. [23], we average losses for each layer to obtain the objective
116
+
117
+ $$
118
+ \mathcal { L } = \sum _ { i = 1 } ^ { L } \omega _ { i } \mathcal { L } _ { i } , \quad \mathrm { w h e r e } \quad \sum _ { i = 1 } ^ { L } \omega _ { i } = 1 .
119
+ $$
120
+
121
+ $\mathcal { L }$ is the negative log-likelihood loss. We set $\begin{array} { r } { \omega _ { i } = i / \sum _ { j = 1 } ^ { L } j } \end{array}$ to favor higher layers, and find this objective to mostly preserve the full model’s performance compared to regular training. We note that there is some misalignment between this training and inference behavior due to the hidden states of skipped layers. However, as discussed in $\ S 3 . 3 . 1$ , the performance is not affected if the hidden-state is copied.
122
+
123
+ # 3.5 Local confidence measures
124
+
125
+ We experiment with three confidence measures for Eq. (4) that differ in their parameter and compute operation efficiencies. Our experiments (§6) will also show that they differ in their predictive power.
126
+
127
+ Softmax response. We take the difference between the top two values of Softmax $( \mathbf { W _ { i } } d _ { t } ^ { i } )$ . With a large output vocabulary, this results in many floating point operations (FLOPs)—though, the next layer $i + 1$ can start its computation in parallel, avoiding additional runtime.
128
+
129
+ Hidden-state saturation. As a simple parameter-free and fast to compute alternative, we take the cosine similarity $\mathrm { s i m } ( d _ { t } ^ { i } , d _ { t } ^ { i - 1 } )$ for $i > 1$ . By definition, the first possible exit is at the second layer (unless $\lambda = 0$ ). This measure tries to identify early saturation events of the hidden-state [28].
130
+
131
+ Early exit classifier. We train a dedicated linear classifier $\mathcal { M }$ to predict the likelihood of exiting with local consistency given the current hidden-state: $c _ { t } ^ { i } = \mathcal { M } ( \bar { d } _ { t } ^ { i } )$ . This measure is very fast to compute at inference, and adds only $| d | + 1$ new parameters. To avoid any impact on the core model’s performance, we train it as a second step where we freeze all parameters other than $\mathcal { M }$ . We simply use a per-layer independent cross-entropy loss against a consistency oracle $\mathbb { 1 } [ \operatorname { a r g m a x } ( p ( y _ { t + 1 } | d _ { t } ^ { i } ) \bar { = }$ ar $\mathrm { g } \operatorname* { m a x } ( p ( y _ { t + 1 } | d _ { t } ^ { L } ) ]$ , and average across the $L - 1$ layers. We also experimented with the geometriclike training of Elbayad et al. [23], but find it to be less effective here (see App. D). The two objectives are closely related, but the geometric one ignores any signal from the states post the first oracle exit.
132
+
133
+ # 4 Calibrating Local Early Exits from Global Constraints
134
+
135
+ We now describe our calibration procedure for finding a shared exit threshold $\lambda \in [ 0 , 1 ]$ that can be used directly in Eq. (4), or via Eq. (5), such that we provably satisfy our desired global constraints over the fully generated sequences. At a high level, our approach uses the following basic recipe:
136
+
137
+ 1. We specify a grid of possible values of $\boldsymbol { \Lambda } = \left( \lambda _ { 1 } , \ldots , \lambda _ { k } \right)$ that may result in acceptable generations;
138
+ 2. We choose the lowest valid $\lambda \in \Lambda$ that we can identify with rigorous statistical testing tools.
139
+
140
+ Let $P _ { \mathrm { t e s t } }$ be an i.i.d. prompt given to the LLM at test time, and let $Y _ { \mathrm { f u l l } } : = \mathrm { L L M } _ { \mathrm { f u l l } } ( P _ { \mathrm { t e s t } } ) \in \mathcal { V }$ and $Y _ { \mathrm { e a r l y } } : = \mathrm { L L M } _ { \mathrm { e a r l y } } ( P _ { \mathrm { t e s t } } , \lambda ) \in \mathcal { Y }$ denote the full and adaptive responses, respectively. Optionally, let $\dot { Z } _ { \mathrm { t e s t } }$ be a set of gold references for our task, if assumed. Our goal, as introduced in $\ S 1$ , is to find a valid $\lambda$ using $ { S _ { \mathrm { c a l } } }$ such that we satisfy either of two types of global “consistency” constraints:
141
+
142
+ Definition 1 (Textual consistency). An adaptive LLM is textually consistent if given any bounded text dissimilarity function, $\mathcal { D } \colon \mathcal { V } \times \mathcal { V } \to \mathbb { R }$ , and tolerance $\delta \in \mathbb { R }$ , $\mathbb { E } \big [ { \cal D } ( Y _ { \mathrm { e a r l y } } , \tilde { Y _ { \mathrm { f u l l } } } ) \big ] \leq \dot { \delta }$ .
143
+
144
+ Definition 2 (Risk consistency). An adaptive LLM is risk consistent if given any bounded risk function, $\mathcal { R } : \mathcal { V } \times 2 ^ { \mathcal { V } } \to \mathbb { R } ,$ , and tolerance $\delta \in \mathbb { R } ,$ $\mathbb { E } [ \mathcal { R } ( Y _ { \mathrm { e a r l y } } , Z _ { \mathrm { t e s t } } ) ] \le \mathbb { E } [ \mathcal { R } ( Y _ { \mathrm { f u l l } } , Z _ { \mathrm { t e s t } } ) ] + \delta$ .
145
+
146
+ Without loss of generality, we will assume that $\mathcal { D }$ and $\mathcal { R }$ are always normalized to the unit interval $[ 0 , 1 ]$ , and therefore will only be considering tolerances $\delta \in ( 0 , 1 )$ . At a glance, to find a $\lambda$ that produces a consistent $\mathbf { L L M } _ { \mathrm { e a r l y } }$ , we cast our problem as a multiple hypothesis testing problem over a large array of $k$ candidate classifier exit thresholds, $\boldsymbol { \Lambda } = \left( \lambda _ { 1 } , \ldots , \lambda _ { k } \right)$ , and apply the Learn then Test (LTT) framework of Angelopoulos et al. [3] to identify a subset of statistically valid, constraint-satisfying thresholds $\Lambda _ { \mathrm { v a l i d } } \subset \Lambda$ . Our final $\lambda$ is then chosen as $\lambda : = \operatorname* { m i n } ( \Lambda _ { \mathrm { v a l i d } } \cup \dot { \{ 1 \} } )$ .
147
+
148
+ # 4.1 The Learn then Test calibration framework
149
+
150
+ Choosing a value of $\lambda$ that rigorously satisfies our consistency objectives is challenging, as the performance impact of increasing or decreasing $\lambda$ is not necessarily monotonic. Naively setting $\lambda$ , for example, based simply on average calibration set performance, can lead to statistically invalid results in our finite-sample, distribution-free setting. The LTT framework proposed by Angelopoulos et al. [3] solves this problem by reframing hyper-parameter selection as a multiple testing problem.
151
+
152
+ Let $\boldsymbol { \Lambda } = \left( \lambda _ { 1 } , \ldots , \lambda _ { k } \right)$ be a finite grid of hyper-parameter values that may, or may not, obtain valid consistency. For example, when searching for a value of $\lambda \in [ 0 , 1 ]$ , we might consider the evenly spaced set $\begin{array} { r } { \dot { \Lambda } = \{ \frac { i } { k + 1 } : \stackrel { \cdot } { i } = 1 , \dots , k \} } \end{array}$ . LTT then identifies a subset of values, $\Lambda _ { \mathrm { v a l i d } } \subset \Lambda$ , where
153
+
154
+ $$
155
+ \mathbb { P } \Big ( \exists \lambda \in \Lambda _ { \mathrm { v a l i d } } \colon \mathbf { L L M _ { \mathrm { e a r l y } } } ( P _ { \mathrm { t e s t } } , \lambda ) \mathrm { ~ a n d ~ } \mathbf { L L M _ { \mathrm { f u l l } } } ( P _ { \mathrm { t e s t } } ) \mathrm { ~ a r e ~ } \mathbf { n o t } \mathrm { ~ c o n s i s t e n t } \Big ) \le \epsilon .
156
+ $$
157
+
158
+ Here, we are using consistency to refer to either textual consistency or risk consistency. Eq. (7) can be satisfied by applying standard multiple hypothesis testing techniques as long as super-uniform p-values, $p _ { j }$ , are supplied for each value $\lambda _ { j } \in \Lambda$ that support the null hypothesis
159
+
160
+ $$
161
+ H _ { j } \colon \mathbf { L } \mathbf { L } \mathbf { M } _ { \mathrm { e a r l y } } ( P _ { \mathrm { t e s t } } , \lambda _ { j } ) \ \mathrm { a n d } \ \mathbf { L } \mathbf { L } \mathbf { M } _ { \mathrm { f u l l } } ( P _ { \mathrm { t e s t } } ) \ \mathrm { a r e } \ \mathbf { n o t } \ \mathrm { c o n s i s t e n t } .
162
+ $$
163
+
164
+ $\lambda _ { j }$ is placed in $\Lambda _ { \mathrm { v a l i d } }$ if $H _ { j }$ is rejected, and discarded otherwise. This yields a consistent $\mathbf { L L M } _ { \mathrm { e a r l y } }$ . Proposition 1 (LTT for CALM). Suppose $p _ { j }$ is super-uniform for all $j$ under $H _ { j }$ for some specified tolerance $\delta \in ( 0 , 1 )$ . Let $\mathcal { A }$ be any family-wise error rate (FWER) controlling procedure at a level $\epsilon \in ( 0 , 1 )$ , where $\mathcal { A } ( p _ { 1 } , \ldots , p _ { k } )$ selects $H _ { j }$ to reject. Choosing $\lambda : = \operatorname* { m i n } ( \Lambda _ { \mathrm { v a l i d } } \cup \{ 1 \} )$ then yields a consistent $L L M _ { \mathrm { e a r l y } }$ with probability at least $1 - \epsilon$ .
165
+
166
+ Note that a FWER-controlling procedure at a level $\epsilon$ is an algorithm that decides to accept or reject hypotheses $\{ H _ { i } \} _ { i = 1 } ^ { k }$ , while ensuring that the probability of falsely rejecting any $H _ { j }$ is less than $\epsilon$ . The proof of Proposition 1, given in Appendix A.1, follows directly from Theorem 1 of Angelopoulos et al. [3], and the fact that $\mathbf { L L M _ { \mathrm { e a r l y } } } ( P _ { \mathrm { t e s t } } ^ { - } , 1 ) = \mathbf { L L M _ { \mathrm { f u l l } } } ( P _ { \mathrm { t e s t } } )$ by construction per Eq. (4), so that we can always use $\lambda = 1$ as a valid fallback if we fail to identify non-empty $\Lambda _ { \mathrm { v a l i d } }$ . In the next sections, we describe how we calculate valid $\mathsf { p }$ -values using $ { S _ { \mathrm { c a l } } }$ , and our choice of FWER-controlling procedure.
167
+
168
+ # 4.2 Defining p-values for consistent early-exiting
169
+
170
+ LTT relies on valid $\mathfrak { p }$ -values $p _ { j }$ , where $p _ { j }$ is a random variable satisfying $\mathbb { P } ( p _ { j } \leq u ) \leq u$ under $H _ { j }$ for all $u \in [ 0 , 1 ]$ . For our purposes, we can obtain valid $\mathsf { p }$ -values from the empirical consistency of $\mathrm { L L M } _ { \mathrm { e a r l y } } ( P _ { i } , \lambda )$ measured over the random calibration sample, $ { S _ { \mathrm { c a l } } }$ . Since we have assumed w.l.o.g. that either of our bounded consistency functions $\mathcal { D }$ and $\mathcal { R }$ from Defs. 1 and 2 have been normalized to lie in $[ 0 , 1 ]$ , we can, for example, obtain a valid $\mathfrak { p }$ -value by simply inverting Hoeffding’s inequality:3
171
+
172
+ $$
173
+ p _ { j } ^ { \mathrm { H o e f f d i n g } } : = e ^ { - 2 n ( \operatorname* { m a x } ( 0 , \delta - \widehat { E } ( \lambda _ { j } ) ) ) ^ { 2 } } ,
174
+ $$
175
+
176
+ where $\begin{array} { r } { \widehat { E } ( \lambda _ { j } ) : = \frac { 1 } { n } \sum _ { i = 1 } ^ { n } L _ { i } ( \lambda _ { j } ) } \end{array}$ is the empirical average of random variable $L _ { i } ( \lambda _ { j } ) \in [ 0 , 1 ]$ , with
177
+
178
+ $$
179
+ \mathsf { \Pi } _ { \mathsf { L } _ { i } } ( \lambda _ { j } ) : = \mathcal { D } ( \mathrm { L L M } _ { \mathrm { e a r l y } } ( P _ { i } , \lambda _ { j } ) , \mathrm { L L M } _ { \mathrm { f u l l } } ( P _ { i } ) ) \quad \mathrm { o r }
180
+ $$
181
+
182
+ $$
183
+ L _ { i } ( \lambda _ { j } ) : = \operatorname* { m a x } \left( 0 , \mathcal { R } ( \operatorname { L L M } _ { \mathrm { e a r l y } } ( P _ { i } , \lambda _ { j } ) , Z _ { i } ) - \mathcal { R } ( \operatorname { L L M } _ { \mathrm { f u l l } } ( P _ { i } ) , Z _ { i } ) \right) ,
184
+ $$
185
+
186
+ for textual consistency versus risk consistency, respectively. Note that, as a technicality of enforcing the r.v. $L _ { i } ( \lambda _ { j } )$ to be within $[ 0 , 1 ]$ , Eq. (11) computes a conservative estimate of the difference in the empirical risk that doesn’t reward instances in which the risk of the early-exit model is lower.
187
+
188
+ # 4.3 Efficient fixed sequence testing
189
+
190
+ The more values of $\lambda$ we test, the higher the chance that we might accidentally choose a $\lambda$ that does not in fact result in consistent generations, despite whatever misleading performance we might have measured by chance on $ { S _ { \mathrm { c a l } } }$ . As part of LTT, we must select a multiple testing procedure that corrects for this (i.e., that controls the FWER at level $\epsilon$ ). Though the precise dependence between the early-exit LLM’s performance and $\lambda$ is unknown, in practice we find that it tends to be fairly smooth and roughly monotonic. That is, nearby thresholds $\bar { \lambda } \approx \lambda ^ { \prime }$ tend to perform similarly, whereas $\lambda > \lambda ^ { \prime }$ tends to result in relatively more consistent performance. Taking advantage of this structure, we choose to employ fixed sequence testing (FST) as our FWER-controlling procedure [3; 11].
191
+
192
+ Here we define a sequence of descending thresholds $\lambda _ { 1 } > \lambda _ { 2 } > . . . \lambda _ { k }$ with a relatively coarse step size (e.g., increments of 0.05). For each $\lambda _ { j }$ in order, we compute $p _ { j }$ , and reject $H _ { j }$ if $p _ { j } \leq \epsilon$ . The first time we fail to reject $H _ { j }$ , we immediately terminate our search, and return $\lambda _ { j - 1 }$ to use as our calibrated threshold (or 1, if we fail to reject $H _ { 1 }$ ). An Algorithm of the full procedure is provided in Appendix E.
193
+
194
+ ![](images/0c105aa367418bb431e00db485785f8d1b130393e688a242b52e2fc317d8243b.jpg)
195
+ Figure 3: Validation empirical performance-efficiency tradeoffs for different confidence measures, compared to static baselines and a local oracle measure with state propagation for skipped layers.
196
+
197
+ # 5 Experimental Setting
198
+
199
+ We empirically evaluate our methods on three popular text generation tasks that vary in their target generation length and extractive degrees against the input. CNN/DM [31] is a collection of news articles to be summarized in few sentences. WMT15 EN-FR [13] contains English sentences (one per example) to be machine translated to French. Open-book SQUAD 1.1 [54] is a QA dataset with Wikipedia paragraphs paired with questions, where the target answer is a text span from the input. Length statistics of the validation sets are summarized in Table 1.
200
+
201
+ Table 1: Average number of tokens in reference targets of evaluation datasets (5/95th percentiles in parenthesis).
202
+
203
+ <table><tr><td>Dataset</td><td>Output length</td></tr><tr><td>CNN/DM</td><td>82 (42 - 141)</td></tr><tr><td>WMTEN-FR</td><td>39 (10 -82)</td></tr><tr><td>SQUAD</td><td>5 (1-13)</td></tr></table>
204
+
205
+ Model. We implement CALM on top of the T5 encoder-decoder model that showed good performance on the tasks above [53], using the T5X framework [55]. We use the 8 layers T5 1.1 model that doesn’t share input and output embeddings. We share all output embeddings for the softmax predictions, and the early-exit classifier across all decoder layers. Based on validation results, we set the temperature of our decaying threshold to $\tau = 4$ for the softmax and classifier measures of CNN/DM and WMT. In other settings, we use $\tau = 0$ . See App. C for more details, and App. B.3 for a 12 layers T5 model.
206
+
207
+ Evaluation metrics. We use the standard metrics for each task: ROUGE-L for CNN/DM, BLEU [50] for WMT, and Token-F1 [54] for SQUAD. We rely on the same metrics for computing the risk and textual distance, other than BLEU which is a corpus-level metric that doesn’t directly enable expectation control. Instead, we use the BLEURT learned metric [61]. For a given metric $m ( y _ { \mathrm { e a r l y } } , y _ { \mathrm { f u l l ~ o r } } z _ { \mathrm { t e s t } } ) \in [ 0 , 1 ]$ , we use $1 - m$ for distance or risk computation, respectively.
208
+
209
+ Our main efficiency metric is the average number of decoder layers used per output token, as it directly measures complexity reduction without conflating with implementation or infrastructure specific details [19]. For reference, we also report the average decoder FLOPs reduction per token [23]. Also, we compute an estimated speedup of the whole encoder-decoder model for generating the full sequence, based on TPUv3 benchmarking with 200 examples in Colab (see App. C for details).
210
+
211
+ Calibration experiments. For each task, we use the validation and test sets to evaluate our calibration method (§4) (for SQUAD we only use the validation set as the test answers are hidden). We run 50 random trials per target tolerance $\delta$ and consistency objective (textual or risk), where we partition the data to $80 \%$ calibration $( S _ { \mathrm { c a l } } )$ and $20 \%$ test $( P _ { \mathrm { t e s t } } )$ . We set $\epsilon = 0 . 0 5$ for all experiments.
212
+
213
+ Baselines. We emphasize that the CALM framework is general for any autoregressive multi-layered LM with any confidence measure, allowing controlled consistency by Eq. (1) or Eq. (2). To empirically evaluate the efficiency gains enabled by our proposed confidence measures, we compare with static baselines that use the same number of layers for all tokens. We also compare our early-exit classifier training with the geometric method of [23] in Appendix D. Also, we compute an oracle local measure (§3.3.1) as an upper-bound estimate of the performance-efficiency tradeoff.
214
+
215
+ # 6 Experimental Results
216
+
217
+ We first report the empirical performance-efficiency tradeoff achieved with each confidence measure.
218
+ For each task and measure, we evaluate the full range of $\lambda$ on the validation set, with steps of 0.05.
219
+
220
+ Table 2: Test efficiency gains per choice of $\delta$ , consistency objective, and confidence measure. $\epsilon$ is set to 0.05. For plots of the full range of $\delta$ with standard deviation, see Appendix B.
221
+
222
+ <table><tr><td rowspan="2">8</td><td rowspan="2">Measure</td><td rowspan="2"></td><td colspan="3">CNN/DM</td><td colspan="3">WMT</td><td colspan="3">SQUAD</td></tr><tr><td>layers</td><td>FLOPs r.</td><td>speedup</td><td>layers</td><td>FLOPs r.</td><td>speedup</td><td>layers</td><td>FLOPs r.</td><td>speedup</td></tr><tr><td rowspan="6">sisuos[enxəL 5</td><td rowspan="6">1</td><td>softmax state</td><td>5.73 8.00</td><td>×0.44 ×1.00</td><td>×1.41 ×1.00</td><td>3.35</td><td>×0.66</td><td>×2.01</td><td>1.65</td><td>×3.15</td><td>×1.63</td></tr><tr><td></td><td></td><td></td><td></td><td>7.68</td><td>×1.01</td><td>×1.00</td><td>2.00</td><td>×3.65</td><td>×1.68</td></tr><tr><td>classifier</td><td>7.16</td><td>×1.03</td><td>×1.42</td><td>5.50</td><td>×1.06</td><td>×2.05</td><td>2.59</td><td>×2.37</td><td>×1.10</td></tr><tr><td>softmax</td><td>2.62</td><td>×0.49</td><td>×2.57</td><td>1.76</td><td>×0.91</td><td>×2.83</td><td>1.03</td><td>×5.68</td><td>×1.88</td></tr><tr><td>state</td><td>7.97</td><td>×1.00</td><td>×1.01</td><td>2.84</td><td>×1.93</td><td>×1.55</td><td>2.00</td><td>×3.65</td><td>×1.68</td></tr><tr><td>classifier</td><td>4.51</td><td>×1.15</td><td>×2.04</td><td>2.97</td><td>×1.22</td><td>×2.00</td><td>1.37</td><td>×5.09</td><td>×1.11</td></tr><tr><td rowspan="6">Prrsrorssrr 00</td><td rowspan="6">0</td><td>softmax</td><td>3.75</td><td>×0.47</td><td>×1.96</td><td>3.19</td><td>×0.67</td><td>×2.10</td><td>1.65</td><td>×3.15</td><td>×1.63</td></tr><tr><td>state</td><td>7.97</td><td>×1.00</td><td>×1.01</td><td>7.68</td><td>×1.01</td><td>×1.00</td><td>3.13</td><td>×2.11</td><td>×1.68</td></tr><tr><td>classifier</td><td>6.49</td><td>×1.06</td><td>×1.71</td><td>5.05</td><td>×1.08</td><td>×1.97</td><td>3.36</td><td>×1.55</td><td>×1.11</td></tr><tr><td>softmax</td><td>1.73</td><td>×0.50</td><td>×3.53</td><td>1.96</td><td>×0.85</td><td>×2.73</td><td>1.65</td><td>×3.15</td><td>×1.63</td></tr><tr><td>state</td><td>5.22</td><td>×1.11</td><td>×1.64</td><td>2.72</td><td>×2.01</td><td>×1.58</td><td>2.00</td><td>×3.65</td><td>×1.68</td></tr><tr><td>classifier</td><td>2.30</td><td>×1.25</td><td>×2.09</td><td>3.08</td><td>×1.21</td><td>×1.98</td><td>2.59</td><td>×2.37</td><td>×1.10</td></tr></table>
223
+
224
+ The results, presented in Figure 3, show the power of the softmax response measure, allowing only minor performance loss while reducing more than half of the layers in all three tasks. The early-exit classifier, that is more FLOP-efficient, is also effective, mostly when targeting high performance (right hand side of plots). The simple and parameter-free state saturation measure is competitive, but often falls bellow the static baseline, despite enabling per-token exit decisions.
225
+
226
+ The dynamic oracle obtains compelling efficiency gains, using only 1.5, 1.3, and 1.2 layers on average for summarization, WMT, and QA, respectively, without losing any performance. This illustrates the full potential of CALM and leaves further room for improvements with better confidence measures. It also shows the effectiveness of inference-time state propagation for skipped layers (§3.3.1).
227
+
228
+ # 6.1 Calibrated performance with guaranteed textual or risk consistency
229
+
230
+ Next, we examine the outcomes of the calibration process. Since the obtained risk is guaranteed to be valid (i.e., $\leq \delta$ at least $9 5 \%$ of the time), we focus here on efficiency gains per chosen $\delta$ . We refer the reader to Appendix B for empirical validation and for additional results and qualitative examples.
231
+
232
+ Table 2 presents the efficiency gains per choice of $\delta$ for each consistency objective and confidence measure. We examine larger $\delta$ values for textual consistency as this is generally a stricter requirement since the full model’s error is not considered.
233
+
234
+ Across all, the softmax confidence measure leads to the greatest decrease in number of decoder layers required. Accordingly, softmax mostly enables the highest speedup gains of up to about three times faster than running through all the model’s layers. The very lightweight early-exit classifier sometimes provides better gains than softmax, even if more decoding layers are used. Since the speedup is computed over the full generated output, we see more gains on the longer outputs of summarization and translation where the decoding takes most of the time, compared to the short QA outputs where the whole decoding time is not much longer than the encoding time.
235
+
236
+ These encouraging efficiency gains are enabled even with the rigorous performance guarantees that are sometimes conservative (e.g., Eq. (11)). We note that relaxing these constraints, or tightening the confidence intervals (e.g., with larger calibration sets), can further improve the empirical gains.
237
+
238
+ The softmax operation over the full output vocabulary is FLOPs heavy (though, this compute can potentially be paralleled), sometime leading to increased total FLOPs, even with fewer used layers. The state-based and early-exit classifier measures require minimal FLOPs and provide a good alternative with compelling efficiency gains, if total (parallelizable, or not) FLOPs is of concern.
239
+
240
+ # 6.2 Example output: effectively distributing the model’s capacity across timesteps
241
+
242
+ Figure 4 presents two CALM summary generations for an article from the CNN/DM dataset, compared to the output of the full model (See Figure B.5 in the Appendix for examples from the other tasks) . Y (2) y uses a lower confidence threshold for early exiting compared to Y (1)early . The colors, depicting the number of decoder layers used per output token, illustrate how CALM obtains the
243
+
244
+ <table><tr><td>test</td><td colspan="5">SouthAfrica-bGntotiatig84tiilackCapscdfrstCufiiElit&#x27;sutiatei Eliot,6,adotpadinteaialcketfor14montsenedinisindicaiofrteacigrandplaedunderdon McCullum.New Zealand play the winner of the semi-final between Australia or India.</td></tr><tr><td>Yfull:</td><td colspan="5">GrantElititZaadrougoteordCupfal.6yedaiSouthAutaturaldKltwil surely never playanotherinningslike his 84.New Zealandwilltake oneither Australiaor India in the finalon Sunday.</td></tr><tr><td>Y): early</td><td colspan="5">_Grant_Eliott_hit_a_six_to_put_New_Zealand_through__to__the_World_Cup_final_._Elliott tt_was__born_in_South__Africa_but_ a_naturalised_Kiwi_ The_36-year-old_will_surely_never__play_another_innings_like_his_unbeaten_84_ New_Zealand_will_now__take_on_either_Australia_or__India_in_the_final_on_Sunday_.&lt;EOS&gt;</td></tr><tr><td>Y(2) early ‘</td><td colspan="5">Grant_Ellott_hit_84_in_the_Black_Caps_chase__New_Zealand_reached_the_World_Cup_final._lliott tt_was__born__in_So uthAfrica_butanaturalised_KiwiEliowillsurelynevepayanotheinninglikehisunbeate84&gt;</td></tr><tr><td rowspan="2">y(1) Yearly</td><td colspan="5">D(Yearly,Yfull)</td><td rowspan="2"></td></tr><tr><td colspan="2">0.02</td><td>Rearty-Rfull</td><td>Average layers</td><td>Speedup</td></tr><tr><td colspan="2">Y(2) early</td><td>0.01 -0.3</td><td>2.1 1.9</td><td>X 2.9 X3.6</td><td>Exit layer-colormapping:12345678 D and R are computed with ROUGE-L</td><td></td></tr></table>
245
+
246
+ Figure 4: CALM accelerates the generation by early exiting when possible, and selectively using the full decoder’s capacity only forsoftmax-based confidence measure. $Y _ { \mathrm { e a r l y } } ^ { ( 1 ) }$ Y (2) kenand onstrated here on a CNN/DM example withuse different confidence thresholds for early exiting. Bellow the text, we report the measured textual and risk consistency of each of the two outputs, along with efficiency gains. The colors represent the number of decoding layers used for each token—light green shades indicate less than half of the total layers.
247
+
248
+ efficiency gains. Only a few selected tokens use the full capacity of the model (colored in red), while for most tokens the model exits after one or few decoding layers (colored in green).
249
+
250
+ The example in Figure 4 also demonstrates one difference between the two types of consistency constraints, given a reference output $Z _ { \mathrm { t e s t } }$ . Textual consistency $D ( Y _ { \mathrm { e a r l y } } , Y _ { \mathrm { f u l l } } )$ generally (though, not always) degrades (i.e., increases) when decreasing the confidence threshold as the outputs tend to more significantly diverge from $Y _ { \mathrm { f u l l } }$ . The trend of risk consistency, however, depends also on the reference output $Z _ { \mathrm { t e s t } }$ . If $Y _ { \mathrm { f u l l } } \approx Z _ { \mathrm { t e s t } }$ then the two constraints are nearly the same. In this example, they are sufficiently different that Y (2)early obtained better (lower) risk even though the textual distance from $Y _ { \mathrm { f u l l } }$ is higher. On the one hand, given the availability of reference outputs for calibration, this suggests that for an imperfect model, risk consistency could lead to more aggressive early-exiting while maintaining the quality of generations. On the other hand, since the Relu in Eq. (11) doesn’t reward negative risk differences, the benefits might not fully materialize. Overall, the two constraints provide different alternatives for the user to choose from depending on the availability of reference outputs, the performance of the full model, and the exact desired performance guarantees.
251
+
252
+ # 7 Conclusion
253
+
254
+ We present confident adaptive language modeling (CALM) for dynamically allocating different amounts of compute per generated token, following explicitly defined tolerance levels on the full generation output. This paper covers both modeling solutions and analyses towards this goal, as well as a theoretically-grounded framework for provably controlling the quality of the full output to meet the user-specified tolerance levels. We investigate the effects of local early exiting during decoding on the final output, leading us to propose a decaying function over the initial threshold that enables finer control over the performance-efficiency tradeoffs without inflating the search space. We also study different solutions for addressing missing computations of early-exited tokens that are dependent upon for future tokens. Overall, our complete adaptive compute framework for LMs requires minimal modifications to the underlying model and enables efficiency gains while satisfying rigorous quality guarantees for the output. Also, our oracle experiments and runtime analysis demonstrates the full potential of this framework and leave room for future research to further improve the efficiency in a controllable way.
255
+
256
+ # Acknowledgements
257
+
258
+ We thank Ionel Gog for significantly improving the implementation after submission. We also thank Anselm Levskaya, Hyung Won Chung, Seungyeon Kim, Tao Wang, Paul Barham, and Michael Isard for great discussions and code suggestions. We thank Orhan Firat, Carlos Riquelme, Aditya Menon, Zhifeng Chen, Sanjiv Kumar, and Jeff Dean for helpful discussions and feedback on the project.
259
+
260
+ # References
261
+
262
+ [1] Anastasios N. Angelopoulos and Stephen Bates. A gentle introduction to conformal prediction and distribution-free uncertainty quantification. 2021. doi: 10.48550/ARXIV.2107.07511. URL https://arxiv.org/abs/2107.07511. [2] Anastasios Nikolas Angelopoulos and Stephen Bates. A gentle introduction to conformal prediction and distribution-free uncertainty quantification, 2021. URL https://arxiv. org/abs/2107.07511.
263
+ [3] Anastasios Nikolas Angelopoulos, Stephen Bates, Emmanuel J. Candès, Michael I. Jordan, and Lihua Lei. Learn then test: Calibrating predictive algorithms to achieve risk control. ArXiv preprint: 2110.01052, 2021.
264
+ [4] Anastasios Nikolas Angelopoulos, Amit Kohli, Stephen Bates, Michael I. Jordan, Jitendra Malik, Thayer Alshaabi, Srigokul Upadhyayula, and Yaniv Romano. Image-to-image regression with distribution-free uncertainty quantification and applications in imaging. ArXiv, abs/2202.05265, 2022.
265
+ [5] Vamsi Aribandi, Yi Tay, Tal Schuster, Jinfeng Rao, Huaixiu Steven Zheng, Sanket Vaibhav Mehta, Honglei Zhuang, Vinh Q. Tran, Dara Bahri, Jianmo Ni, Jai Gupta, Kai Hui, Sebastian Ruder, and Donald Metzler. Ext5: Towards extreme multi-task scaling for transfer learning. In International Conference on Learning Representations, 2022. URL https://openreview. net/forum?id $\equiv$ Vzh1BFUCiIX.
266
+ [6] Haoli Bai, Wei Zhang, Lu Hou, Lifeng Shang, Jing Jin, Xin Jiang, Qun Liu, Michael Lyu, and Irwin King. Binarybert: Pushing the limit of bert quantization. arXiv preprint arXiv:2012.15701, 2020.
267
+ [7] Yu Bai, Song Mei, Haiquan Wang, Yingbo Zhou, and Caiming Xiong. Efficient and differentiable conformal prediction with general function classes. ArXiv, abs/2202.11091, 2022. [8] Aaron Baier-Reinio and Hans De Sterck. N-ode transformer: A depth-adaptive variant of the transformer using neural ordinary differential equations. ArXiv, abs/2010.11358, 2020. [9] Ankur Bapna, Naveen Arivazhagan, and Orhan Firat. Controlling computation versus quality for neural sequence models. 2020. doi: 10.48550/ARXIV.2002.07106. URL https://arxiv. org/abs/2002.07106.
268
+ [10] Stephen Bates, Anastasios Nikolas Angelopoulos, Lihua Lei, Jitendra Malik, and Michael I. Jordan. Distribution free, risk controlling prediction sets. ArXiv preprint: 2101.02703, 2020.
269
+ [11] Peter Bauer. Multiple testing in clinical trials. Statistics in medicine, 10 6:871–89; discussion 889–90, 1991.
270
+ [12] Vidmantas Bentkus. On hoeffding’s inequalities. Annals of Probability, 32:1650–1673, 2004.
271
+ [13] Ondˇrej Bojar, Rajen Chatterjee, Christian Federmann, Barry Haddow, Matthias Huck, Chris Hokamp, Philipp Koehn, Varvara Logacheva, Christof Monz, Matteo Negri, Matt Post, Carolina Scarton, Lucia Specia, and Marco Turchi. Findings of the 2015 workshop on statistical machine translation. In Proceedings of the Tenth Workshop on Statistical Machine Translation, pages 1–46, Lisbon, Portugal, September 2015. Association for Computational Linguistics. doi: 10.18653/v1/W15-3001. URL https://aclanthology.org/W15-3001.
272
+ [14] James Bradbury, Roy Frostig, Peter Hawkins, Matthew James Johnson, Chris Leary, Dougal Maclaurin, George Necula, Adam Paszke, Jake VanderPlas, Skye Wanderman-Milne, and Qiao Zhang. JAX: composable transformations of Python+NumPy programs, 2018. URL http://github.com/google/jax.
273
+ [15] Tom Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah, Jared D Kaplan, Prafulla Dhariwal, Arvind Neelakantan, Pranav Shyam, Girish Sastry, Amanda Askell, Sandhini Agarwal, Ariel Herbert-Voss, Gretchen Krueger, Tom Henighan, Rewon Child, Aditya Ramesh,
274
+
275
+ Daniel Ziegler, Jeffrey Wu, Clemens Winter, Chris Hesse, Mark Chen, Eric Sigler, Mateusz Litwin, Scott Gray, Benjamin Chess, Jack Clark, Christopher Berner, Sam McCandlish, Alec Radford, Ilya Sutskever, and Dario Amodei. Language models are few-shot learners. In H. Larochelle, M. Ranzato, R. Hadsell, M.F. Balcan, and H. Lin, editors, Advances in Neural Information Processing Systems, volume 33, pages 1877–1901. Curran Associates, Inc., 2020. URL https://proceedings.neurips.cc/paper/2020/ file/1457c0d6bfcb4967418bfb8ac142f64a-Paper.pdf.
276
+
277
+ [16] Berkant Barla Cambazoglu, Hugo Zaragoza, Olivier Chapelle, Jiang Chen, Ciya Liao, Zhaohui Zheng, and Jon Degenhardt. Early exit optimizations for additive machine learned ranking systems. In WSDM ’10, 2010.
278
+
279
+ [17] Aakanksha Chowdhery, Sharan Narang, Jacob Devlin, Maarten Bosma, Gaurav Mishra, Adam Roberts, Paul Barham, Hyung Won Chung, Charles Sutton, Sebastian Gehrmann, Parker Schuh, Kensen Shi, Sasha Tsvyashchenko, Joshua Maynez, Abhishek Rao, Parker Barnes, Yi Tay, Noam Shazeer, Vinodkumar Prabhakaran, Emily Reif, Nan Du, Ben Hutchinson, Reiner Pope, James Bradbury, Jacob Austin, Michael Isard, Guy Gur-Ari, Pengcheng Yin, Toju Duke, Anselm Levskaya, Sanjay Ghemawat, Sunipa Dev, Henryk Michalewski, Xavier Garcia, Vedant Misra, Kevin Robinson, Liam Fedus, Denny Zhou, Daphne Ippolito, David Luan, Hyeontaek Lim, Barret Zoph, Alexander Spiridonov, Ryan Sepassi, David Dohan, Shivani Agrawal, Mark Omernick, Andrew M. Dai, Thanumalayan Sankaranarayana Pillai, Marie Pellat, Aitor Lewkowycz, Erica Moreira, Rewon Child, Oleksandr Polozov, Katherine Lee, Zongwei Zhou, Xuezhi Wang, Brennan Saeta, Mark Diaz, Orhan Firat, Michele Catasta, Jason Wei, Kathy Meier-Hellstern, Douglas Eck, Jeff Dean, Slav Petrov, and Noah Fiedel. Palm: Scaling language modeling with pathways. 2022.
280
+
281
+ [18] Mostafa Dehghani, Stephan Gouws, Oriol Vinyals, Jakob Uszkoreit, and Lukasz Kaiser. Universal transformers. In International Conference on Learning Representations (ICLR), 2019.
282
+
283
+ [19] Mostafa Dehghani, Yi Tay, Anurag Arnab, Lucas Beyer, and Ashish Vaswani. The efficiency misnomer. In International Conference on Learning Representations, 2022. URL https: //openreview.net/forum?id $=$ iulEMLYh1uR.
284
+
285
+ [20] Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. BERT: Pre-training of deep bidirectional transformers for language understanding. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers), pages 4171–4186, Minneapolis, Minnesota, June 2019. Association for Computational Linguistics. doi: 10.18653/v1/N19-1423. URL https://aclanthology.org/N19-1423.
286
+
287
+ [21] Neil Dey, Jing Ding, Jack G. Ferrell, Carolina Kapper, Maxwell Lovig, Emiliano Planchon, and Jonathan P Williams. Conformal prediction for text infilling and part-of-speech prediction. ArXiv, abs/2111.02592, 2021.
288
+
289
+ [22] Nan Du, Yanping Huang, Andrew M. Dai, Simon Tong, Dmitry Lepikhin, Yuanzhong Xu, Maxim Krikun, Yanqi Zhou, Adams Wei Yu, Orhan Firat, Barret Zoph, Liam Fedus, Maarten Bosma, Zongwei Zhou, Tao Wang, Yu Emma Wang, Kellie Webster, Marie Pellat, Kevin Robinson, Kathy Meier-Hellstern, Toju Duke, Lucas Dixon, Kun Zhang, Quoc V Le, Yonghui Wu, Zhifeng Chen, and Claire Cui. Glam: Efficient scaling of language models with mixtureof-experts. 2021.
290
+
291
+ [23] Maha Elbayad, Jiatao Gu, Edouard Grave, and Michael Auli. Depth-adaptive transformer. In International Conference on Learning Representations, 2020. URL https://openreview. net/forum?id $\equiv$ SJg7KhVKPH.
292
+
293
+ [24] Angela Fan, Edouard Grave, and Armand Joulin. Reducing transformer depth on demand with structured dropout. arXiv preprint arXiv:1909.11556, 2019.
294
+
295
+ [25] Michael Figurnov, Artem Sobolev, and Dmitry P. Vetrov. Probabilistic adaptive computation time. ArXiv, abs/1712.00386, 2017.
296
+
297
+ [26] Adam Fisch, Tal Schuster, Tommi Jaakkola, and Regina Barzilay. Efficient conformal prediction via cascaded inference with expanded admission. In International Conference on Learning Representations (ICLR), 2021.
298
+
299
+ [27] Adam Fisch, Tal Schuster, T. Jaakkola, and Regina Barzilay. Conformal prediction sets with limited false positives. ArXiv, abs/2202.07650, 2022.
300
+
301
+ [28] Mor Geva, Avi Caciularu, Kevin Ro Wang, and Yoav Goldberg. Transformer feed-forward layers build predictions by promoting concepts in the vocabulary space. 2022.
302
+
303
+ [29] Alex Graves. Adaptive computation time for recurrent neural networks. 2016.
304
+
305
+ [30] Caglar Gulcehre, Orhan Firat, Kelvin Xu, Kyunghyun Cho, and Yoshua Bengio. On integrating a language model into neural machine translation. Computer Speech & Language, 45:137– 148, 2017. ISSN 0885-2308. doi: https://doi.org/10.1016/j.csl.2017.01.014. URL https: //www.sciencedirect.com/science/article/pii/S0885230816301395.
306
+
307
+ [31] Karl Moritz Hermann, Tomas Kocisky, Edward Grefenstette, Lasse Espeholt, Will Kay, Mustafa Suleyman, and Phil Blunsom. Teaching machines to read and comprehend. In C. Cortes, N. Lawrence, D. Lee, M. Sugiyama, and R. Garnett, editors, Advances in Neural Information Processing Systems, volume 28. Curran Associates, Inc., 2015. URL https://proceedings.neurips.cc/paper/2015/file/ afdec7005cc9f14302cd0474fd0f3c96-Paper.pdf.
308
+
309
+ [32] Geoffrey E. Hinton, Oriol Vinyals, and Jeffrey Dean. Distilling the knowledge in a neural network. ArXiv, abs/1503.02531, 2015.
310
+
311
+ [33] Wassily Hoeffding. Probability inequalities for sums of bounded random variables. Journal of the American Statistical Association, 58:13–30, 1963.
312
+
313
+ [34] Lu Hou, Zhiqi Huang, Lifeng Shang, Xin Jiang, Xiao Chen, and Qun Liu. Dynabert: Dynamic bert with adaptive width and depth. Advances in Neural Information Processing Systems, 33: 9782–9793, 2020.
314
+
315
+ [35] Yacine Jernite, Edouard Grave, Armand Joulin, and Tomas Mikolov. Variable computation in recurrent neural networks. arXiv preprint arXiv:1611.06188, 2016.
316
+
317
+ [36] Xiaoqi Jiao, Yichun Yin, Lifeng Shang, Xin Jiang, Xiao Chen, Linlin Li, Fang Wang, and Qun Liu. Tinybert: Distilling bert for natural language understanding. arXiv preprint arXiv:1909.10351, 2019.
318
+
319
+ [37] Jungo Kasai, Nikolaos Pappas, Hao Peng, James Cross, and Noah Smith. Deep encoder, shallow decoder: Reevaluating non-autoregressive machine translation. In International Conference on Learning Representations, 2021. URL https://openreview.net/forum? id $\equiv$ KpfasTaLUpq.
320
+
321
+ [38] Gyuwan Kim and Kyunghyun Cho. Length-adaptive transformer: Train once with length drop, use anytime with search. In Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing (Volume 1: Long Papers), pages 6501–6511, Online, August 2021. Association for Computational Linguistics. doi: 10.18653/v1/2021.acl-long.508. URL https://aclanthology.org/2021.acl-long.508.
322
+
323
+ [39] Sneha Kudugunta, Yanping Huang, Ankur Bapna, Maxim Krikun, Dmitry Lepikhin, MinhThang Luong, and Orhan Firat. Beyond distillation: Task-level mixture-of-experts for efficient inference. In Findings of the Association for Computational Linguistics: EMNLP 2021, pages 3577–3599, Punta Cana, Dominican Republic, November 2021. Association for Computational Linguistics. doi: 10.18653/v1/2021.findings-emnlp.304. URL https://aclanthology. org/2021.findings-emnlp.304.
324
+
325
+ [40] Imad Lakim, Ebtesam Almazrouei, Ibrahim Abualhaol, Merouane Debbah, and Julien Launay. A holistic assessment of the carbon footprint of noor, a very large Arabic language model. In Proceedings of BigScience Episode #5 – Workshop on Challenges & Perspectives in Creating Large Language Models, pages 84–94, virtual+Dublin, May 2022. Association for Computational Linguistics. URL https://aclanthology.org/2022.bigscience-1.8.
326
+
327
+ [41] Tao Lei. When attention meets fast recurrence: Training language models with reduced compute. In Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing, pages 7633–7648, Online and Punta Cana, Dominican Republic, November 2021. Association for Computational Linguistics. doi: 10.18653/v1/2021.emnlp-main.602. URL https://aclanthology.org/2021.emnlp-main.602.
328
+
329
+ [42] Dmitry Lepikhin, HyoukJoong Lee, Yuanzhong Xu, Dehao Chen, Orhan Firat, Yanping Huang, Maxim Krikun, Noam Shazeer, and Zhifeng Chen. {GS}hard: Scaling giant models with conditional computation and automatic sharding. In International Conference on Learning Representations, 2021. URL https://openreview.net/forum?id $\underline { { \underline { { \mathbf { \Pi } } } } } =$ qrwe7XHTmYb.
330
+
331
+ [43] Lei Li, Yankai Lin, Deli Chen, Shuhuai Ren, Peng Li, Jie Zhou, and Xu Sun. Cascadebert: Accelerating inference of pre-trained language models via calibrated complete models cascade. arXiv preprint arXiv:2012.14682, 2020.
332
+
333
+ [44] Weijie Liu, Peng Zhou, Zhe Zhao, Zhiruo Wang, Haotang Deng, and Qi Ju. Fastbert: a self-distilling bert with adaptive inference time. arXiv preprint arXiv:2004.02178, 2020.
334
+
335
+ [45] Xiangyang Liu, Tianxiang Sun, Junliang He, Lingling Wu, Xinyu Zhang, Hao Jiang, Zhao Cao, Xuanjing Huang, and Xipeng Qiu. Towards efficient nlp: A standard evaluation and a strong baseline. arXiv preprint arXiv:2110.07038, 2021.
336
+
337
+ [46] Yijin Liu, Fandong Meng, Jie Zhou, Yufeng Chen, and Jinan Xu. Faster depth-adaptive transformers. In AAAI, 2021.
338
+
339
+ [47] Zhuang Liu, Zhiqiu Xu, Hung-Ju Wang, Trevor Darrell, and Evan Shelhamer. Anytime dense prediction with confidence adaptivity. In International Conference on Learning Representations, 2022. URL https://openreview.net/forum?id $\equiv$ kNKFOXleuC.
340
+
341
+ [48] Charles Lu and Jayasheree Kalpathy-Cramer. Distribution-free federated learning with conformal predictions. ArXiv, abs/2110.07661, 2021.
342
+
343
+ [49] Nafise Sadat Moosavi, Angela Fan, Vered Shwartz, Goran Glavaš, Shafiq Joty, Alex Wang, and Thomas Wolf, editors. Proceedings of SustaiNLP: Workshop on Simple and Efficient Natural Language Processing, Online, November 2020. Association for Computational Linguistics. URL https://aclanthology.org/2020.sustainlp-1.0.
344
+
345
+ [50] Kishore Papineni, Salim Roukos, Todd Ward, and Wei-Jing Zhu. Bleu: a method for automatic evaluation of machine translation. In Proceedings of the 40th Annual Meeting of the Association for Computational Linguistics, pages 311–318, Philadelphia, Pennsylvania, USA, July 2002. Association for Computational Linguistics. doi: 10.3115/1073083.1073135. URL https: //aclanthology.org/P02-1040.
346
+
347
+ [51] Matthew E. Peters, Mark Neumann, Mohit Iyyer, Matt Gardner, Christopher Clark, Kenton Lee, and Luke Zettlemoyer. Deep contextualized word representations. In Proceedings of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long Papers), pages 2227–2237, New Orleans, Louisiana, June 2018. Association for Computational Linguistics. doi: 10.18653/v1/N18-1202. URL https://aclanthology.org/N18-1202.
348
+
349
+ [52] Alec Radford, Jeff Wu, Rewon Child, David Luan, Dario Amodei, and Ilya Sutskever. Language models are unsupervised multitask learners. 2019.
350
+
351
+ [53] Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, and Peter J. Liu. Exploring the limits of transfer learning with a unified text-to-text transformer. 2019.
352
+
353
+ [54] Pranav Rajpurkar, Jian Zhang, Konstantin Lopyrev, and Percy Liang. SQuAD: $^ { 1 0 0 , 0 0 0 + }$ questions for machine comprehension of text. In Proceedings of the 2016 Conference on Empirical Methods in Natural Language Processing, pages 2383–2392, Austin, Texas, November 2016. Association for Computational Linguistics. doi: 10.18653/v1/D16-1264. URL https://aclanthology.org/D16-1264.
354
+
355
+ [55] Adam Roberts, Hyung Won Chung, Anselm Levskaya, Gaurav Mishra, James Bradbury, Daniel Andor, Sharan Narang, Brian Lester, Colin Gaffney, Afroz Mohiuddin, Curtis Hawthorne, Aitor Lewkowycz, Alex Salcianu, Marc van Zee, Jacob Austin, Sebastian Goodman, Livio Baldini Soares, Haitang Hu, Sasha Tsvyashchenko, Aakanksha Chowdhery, Jasmijn Bastings, Jannis Bulian, Xavier Garcia, Jianmo Ni, Andrew Chen, Kathleen Kenealy, Jonathan H. Clark, Stephan Lee, Dan Garrette, James Lee-Thorp, Colin Raffel, Noam Shazeer, Marvin Ritter, Maarten Bosma, Alexandre Passos, Jeremy Maitin-Shepard, Noah Fiedel, Mark Omernick, Brennan Saeta, Ryan Sepassi, Alexander Spiridonov, Joshua Newlan, and Andrea Gesmundo. Scaling up models and data with $\pm 5 \mathrm { x }$ and seqio. arXiv preprint arXiv:2203.17189, 2022. URL https://arxiv.org/abs/2203.17189.
356
+
357
+ [56] Victor Sanh, Lysandre Debut, Julien Chaumond, and Thomas Wolf. Distilbert, a distilled version of bert: smaller, faster, cheaper and lighter. arXiv preprint arXiv:1910.01108, 2019.
358
+
359
+ [57] Tal Schuster, Adam Fisch, Tommi Jaakkola, and Regina Barzilay. Consistent accelerated inference via confident adaptive transformers. In Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing, pages 4962–4979, Online and Punta Cana, Dominican Republic, November 2021. Association for Computational Linguistics. doi: 10.18653/v1/2021. emnlp-main.406. URL https://aclanthology.org/2021.emnlp-main.406.
360
+
361
+ [58] Tal Schuster, Ashwin Kalyan, Alex Polozov, and Adam Tauman Kalai. Programming puzzles. In Thirty-fifth Conference on Neural Information Processing Systems Datasets and Benchmarks Track (Round 1), 2021. URL https://openreview.net/forum?id $\underline { { \underline { { \mathbf { \Pi } } } } } =$ fe_hCc4RBrg.
362
+
363
+ [59] Roy Schwartz, Jesse Dodge, Noah A. Smith, and Oren Etzioni. Green ai. Communications of the ACM, 63(12):54–63, Nov 2020. ISSN 1557-7317. doi: 10.1145/3381831. URL http://dx.doi.org/10.1145/3381831.
364
+
365
+ [60] Roy Schwartz, Gabriel Stanovsky, Swabha Swayamdipta, Jesse Dodge, and Noah A. Smith. The right tool for the job: Matching model and instance complexities. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics, pages 6640–6651, Online, July 2020. Association for Computational Linguistics. doi: 10.18653/v1/2020.acl-main.593. URL https://aclanthology.org/2020.acl-main.593.
366
+
367
+ [61] Thibault Sellam, Dipanjan Das, and Ankur Parikh. BLEURT: Learning robust metrics for text generation. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics, pages 7881–7892, Online, July 2020. Association for Computational Linguistics. doi: 10.18653/v1/2020.acl-main.704. URL https://aclanthology.org/2020. acl-main.704.
368
+
369
+ [62] Glenn Shafer and Vladimir Vovk. A tutorial on conformal prediction. Journal of Machine Learning Research (JMLR), 9:371–421, June 2008.
370
+
371
+ [63] Or Sharir, Barak Peleg, and Yoav Shoham. The cost of training nlp models: A concise overview. arXiv preprint: arXiv 2006.06138, 2020.
372
+
373
+ [64] Noam Shazeer and Mitchell Stern. Adafactor: Adaptive learning rates with sublinear memory cost. 2018. doi: 10.48550/ARXIV.1804.04235. URL https://arxiv.org/abs/1804. 04235.
374
+
375
+ [65] Sheng Shen, Zhen Dong, Jiayu Ye, Linjian Ma, Zhewei Yao, Amir Gholami, Michael W Mahoney, and Kurt Keutzer. Q-bert: Hessian based ultra low precision quantization of bert. In Proceedings of the AAAI Conference on Artificial Intelligence, volume 34, pages 8815–8821, 2020.
376
+
377
+ [66] Antoine Simoulin and Benoit Crabbé. How many layers and why? An analysis of the model depth in transformers. In Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing: Student Research Workshop, pages 221–228, Online, August 2021. Association for Computational Linguistics. doi: 10.18653/v1/2021.acl-srw.23. URL https://aclanthology.org/2021.acl-srw.23.
378
+
379
+ [67] Aarohi Srivastava, Abhinav Rastogi, Abhishek Rao, Abu Awal Md Shoeb, Abubakar Abid, Adam Fisch, Adam R. Brown, Adam Santoro, Aditya Gupta, and Garriga-Alonso et al. Beyond the imitation game: Quantifying and extrapolating the capabilities of language models. 2022. doi: 10.48550/ARXIV.2206.04615. URL https://arxiv.org/abs/2206.04615.
380
+
381
+ [68] Asa Cooper Stickland and Iain Murray. Bert and pals: Projected attention layers for efficient adaptation in multi-task learning. In International Conference on Machine Learning, pages 5986–5995. PMLR, 2019.
382
+
383
+ [69] Siqi Sun, Yu Cheng, Zhe Gan, and Jingjing Liu. Patient knowledge distillation for bert model compression. arXiv preprint arXiv:1908.09355, 2019.
384
+
385
+ [70] Tianxiang Sun, Xiangyang Liu, Wei Zhu, Zhichao Geng, Lingling Wu, Yilong He, Yuan Ni, Guotong Xie, Xuanjing Huang, and Xipeng Qiu. A simple hash-based early exiting approach for language understanding and generation. In Findings of the Association for Computational Linguistics: ACL 2022, pages 2409–2421, Dublin, Ireland, May 2022. Association for Computational Linguistics. URL https://aclanthology.org/2022.findings-acl.189.
386
+
387
+ [71] Zhiqing Sun, Hongkun Yu, Xiaodan Song, Renjie Liu, Yiming Yang, and Denny Zhou. Mobilebert: a compact task-agnostic bert for resource-limited devices. arXiv preprint arXiv:2004.02984, 2020.
388
+
389
+ [72] Yi Tay, Mostafa Dehghani, Dara Bahri, and Donald Metzler. Efficient transformers: A survey. ACM Computing Surveys (CSUR), 2022.
390
+
391
+ [73] Yi Tay, Mostafa Dehghani, Vinh Q Tran, Xavier Garcia, Dara Bahri, Tal Schuster, Huaixiu Steven Zheng, Neil Houlsby, and Donald Metzler. Unifying language learning paradigms. arXiv preprint arXiv:2205.05131, 2022.
392
+
393
+ [74] Surat Teerapittayanon, Bradley McDanel, and H. T. Kung. Branchynet: Fast inference via early exiting from deep neural networks. 2016 23rd International Conference on Pattern Recognition (ICPR), pages 2464–2469, 2016.
394
+
395
+ [75] Romal Thoppilan, Daniel De Freitas, Jamie Hall, Noam M. Shazeer, Apoorv Kulshreshtha, Heng-Tze Cheng, Alicia Jin, Taylor Bos, Leslie Baker, Yu Du, Yaguang Li, Hongrae Lee, Huaixiu Zheng, Amin Ghafouri, Marcelo Menegali, Yanping Huang, Maxim Krikun, Dmitry Lepikhin, James Qin, Dehao Chen, Yuanzhong Xu, Zhifeng Chen, Adam Roberts, Maarten Bosma, Yanqi Zhou, Chung-Ching Chang, I. A. Krivokon, Willard James Rusch, Marc Pickett, Kathleen S. Meier-Hellstern, Meredith Ringel Morris, Tulsee Doshi, Renelito Delos Santos, Toju Duke, Johnny Hartz Søraker, Ben Zevenbergen, Vinodkumar Prabhakaran, Mark Diaz, Ben Hutchinson, Kristen Olson, Alejandra Molina, Erin Hoffman-John, Josh Lee, Lora Aroyo, Ravindran Rajakumar, Alena Butryna, Matthew Lamm, V. O. Kuzmina, Joseph Fenton, Aaron Cohen, Rachel Bernstein, Ray Kurzweil, Blaise Aguera-Arcas, Claire Cui, Marian Croak, Ed Chi, and Quoc Le. Lamda: Language models for dialog applications. ArXiv, abs/2201.08239, 2022.
396
+
397
+ [76] Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Łukasz Kaiser, and Illia Polosukhin. Attention is all you need. In Advances in Neural Information Processing Systems (NeurIPS), 2017.
398
+
399
+ [77] Vladimir Vovk, Alex Gammerman, and Glenn Shafer. Algorithmic Learning in a Random World. Springer-Verlag, Berlin, Heidelberg, 2005.
400
+
401
+ [78] Wenhui Wang, Furu Wei, Li Dong, Hangbo Bao, Nan Yang, and Ming Zhou. Minilm: Deep self-attention distillation for task-agnostic compression of pre-trained transformers. Advances in Neural Information Processing Systems, 33:5776–5788, 2020.
402
+
403
+ [79] Xin Wang, Fisher Yu, Zi-Yi Dou, and Joseph Gonzalez. Skipnet: Learning dynamic routing in convolutional networks. ArXiv, abs/1711.09485, 2018.
404
+
405
+ [80] Jason Wei, Xuezhi Wang, Dale Schuurmans, Maarten Bosma, Ed Chi, Quoc Le, and Denny Zhou. Chain of thought prompting elicits reasoning in large language models. 2022.
406
+
407
+ [81] John Wieting, Taylor Berg-Kirkpatrick, Kevin Gimpel, and Graham Neubig. Beyond BLEU:training neural machine translation with semantic similarity. In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics, pages 4344–4355, Florence, Italy, July 2019. Association for Computational Linguistics. doi: 10.18653/v1/P19-1427. URL https://aclanthology.org/P19-1427.
408
+ [82] Yuhuai Wu, Markus Norman Rabe, DeLesley Hutchins, and Christian Szegedy. Memorizing transformers. In International Conference on Learning Representations, 2022. URL https: //openreview.net/forum?id $= ^ { \prime }$ TrjbxzRcnf-.
409
+ [83] Ji Xin, Raphael Tang, Jaejun Lee, Yaoliang Yu, and Jimmy Lin. Deebert: Dynamic early exiting for accelerating bert inference. arXiv preprint arXiv:2004.12993, 2020.
410
+ [84] Ji Xin, Raphael Tang, Yaoliang Yu, and Jimmy Lin. BERxiT: Early exiting for BERT with better fine-tuning and extension to regression. In Proceedings of the 16th Conference of the European Chapter of the Association for Computational Linguistics: Main Volume, pages 91–104, Online, April 2021. Association for Computational Linguistics. doi: 10.18653/v1/2021.eacl-main.8. URL https://aclanthology.org/2021.eacl-main.8.
411
+ [85] Jingjing Xu, Wangchunshu Zhou, Zhiyi Fu, Hao Zhou, and Lei Li. A survey on green deep learning. ArXiv, abs/2111.05193, 2021.
412
+ [86] Linting Xue, Aditya Barua, Noah Constant, Rami Al-Rfou, Sharan Narang, Mihir Kale, Adam Roberts, and Colin Raffel. Byt5: Towards a token-free future with pre-trained byte-to-byte models. 2021. doi: 10.48550/ARXIV.2105.13626. URL https://arxiv.org/abs/ 2105.13626.
413
+ [87] Hongxu Yin, Arash Vahdat, José Manuel Álvarez, Arun Mallya, Jan Kautz, and Pavlo Molchanov. Adavit: Adaptive tokens for efficient vision transformer. ArXiv, abs/2112.07658, 2021.
414
+ [88] Margaux Zaffran, Aymeric Dieuleveut, Olivier F’eron, Yannig Goude, and Julie Josse. Adaptive conformal predictions for time series. ArXiv, abs/2202.07282, 2022.
415
+ [89] Susan Zhang, Stephen Roller, Naman Goyal, Mikel Artetxe, Moya Chen, Shuohui Chen, Christopher Dewan, Mona Diab, Xian Li, Xi Victoria Lin, Todor Mihaylov, Myle Ott, Sam Shleifer, Kurt Shuster, Daniel Simig, Punit Singh Koura, Anjali Sridhar, Tianlu Wang, and Luke Zettlemoyer. Opt: Open pre-trained transformer language models. 2022.
416
+ [90] Wangchunshu Zhou, Canwen Xu, Tao Ge, Julian McAuley, Ke Xu, and Furu Wei. Bert loses patience: Fast and robust inference with early exit. Advances in Neural Information Processing Systems, 33:18330–18341, 2020.
417
+ [91] Yanqi Zhou, Tao Lei, Hanxiao Liu, Nan Du, Yanping Huang, Vincent Zhao, Andrew Dai, Zhifeng Chen, Quoc Le, and James Laudon. Mixture-of-experts with expert choice routing. 2022. doi: 10.48550/ARXIV.2202.09368. URL https://arxiv.org/abs/2202.09368.
418
+ [92] Wei Zhu. Leebert: Learned early exit for bert with cross-level optimization. In Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing (Volume 1: Long Papers), pages 2968–2980, 2021.
parse/dev/uLYc4L3C81A/uLYc4L3C81A_content_list.json ADDED
The diff for this file is too large to render. See raw diff
 
parse/dev/uLYc4L3C81A/uLYc4L3C81A_middle.json ADDED
The diff for this file is too large to render. See raw diff