Datasets:
Tasks:
Question Answering
Modalities:
Image
Formats:
imagefolder
Languages:
English
Size:
100K - 1M
ArXiv:
License:
Add files using upload-large-folder tool
Browse filesFiles changed (50)
- md/train/--rcOeCKRh/--rcOeCKRh.mdAdded+236
- md/train/5GihaaZKL4/5GihaaZKL4.mdAdded+394
- md/train/9Y7_c5ZAd5i/9Y7_c5ZAd5i.mdAdded
- md/train/9c-IsSptbmA/9c-IsSptbmA.mdAdded+257
- md/train/B1eB5xSFvr/B1eB5xSFvr.mdAdded+432
- md/train/B1gJ1L2aW/B1gJ1L2aW.mdAdded+289
- md/train/B1lda1HtvB/B1lda1HtvB.mdAdded+600
- md/train/BJe932EYwS/BJe932EYwS.mdAdded+342
- md/train/Bk7wvW-C-/Bk7wvW-C-.mdAdded+261
- md/train/Bki4EfWCb/Bki4EfWCb.mdAdded+366
- md/train/BylVcTNtDS/BylVcTNtDS.mdAdded+251
- md/train/BysZhEqee/BysZhEqee.mdAdded+277
- md/train/CR1XOQ0UTh-/CR1XOQ0UTh-.mdAdded
- md/train/DPHsCQ8OpA/DPHsCQ8OpA.mdAdded+335
- md/train/H1egcgHtvB/H1egcgHtvB.mdAdded+260
- md/train/H1lGHsA9KX/H1lGHsA9KX.mdAdded+321
- md/train/HJxYwiC5tm/HJxYwiC5tm.mdAdded+242
- md/train/HkgB2TNYPS/HkgB2TNYPS.mdAdded+499
- md/train/HkgaETNtDB/HkgaETNtDB.mdAdded+391
- md/train/HkgrZ0EYwB/HkgrZ0EYwB.mdAdded
- md/train/HkuGJ3kCb/HkuGJ3kCb.mdAdded
- md/train/I3HOxaZIJ0J/I3HOxaZIJ0J.mdAdded
- md/train/L7Irrt5sMQa/L7Irrt5sMQa.mdAdded
- md/train/Ov_sMNau-PF/Ov_sMNau-PF.mdAdded
- md/train/PKubaeJkw3/PKubaeJkw3.mdAdded
- md/train/S1efxTVYDr/S1efxTVYDr.mdAdded
- md/train/SPrVNsXnGd/SPrVNsXnGd.mdAdded
- md/train/Syl7OsRqY7/Syl7OsRqY7.mdAdded
- md/train/Syx72jC9tm/Syx72jC9tm.mdAdded
- md/train/Ysuv-WOFeKR/Ysuv-WOFeKR.mdAdded
- md/train/ZsGg52s-cQZ/ZsGg52s-cQZ.mdAdded
- md/train/aDjoksTpXOP/aDjoksTpXOP.mdAdded
- md/train/aFvG-DNPNB9/aFvG-DNPNB9.mdAdded
- md/train/fATZNtA1-V0/fATZNtA1-V0.mdAdded
- md/train/fmgYOUahK9/fmgYOUahK9.mdAdded
- md/train/iKQAk8a2kM0/iKQAk8a2kM0.mdAdded
- md/train/lxHgXYN4bwl/lxHgXYN4bwl.mdAdded
- md/train/nYz2_BbZnYk/nYz2_BbZnYk.mdAdded
- md/train/r1gRTCVFvB/r1gRTCVFvB.mdAdded
- md/train/r1kNDlbCb/r1kNDlbCb.mdAdded
- md/train/rG2ponW2Si/rG2ponW2Si.mdAdded
- md/train/rJYFzMZC-/rJYFzMZC-.mdAdded
- md/train/rJlUhhVYvS/rJlUhhVYvS.mdAdded
- md/train/rk6cfpRjZ/rk6cfpRjZ.mdAdded
- md/train/rk6qdGgCZ/rk6qdGgCZ.mdAdded
- md/train/ryGDEjCcK7/ryGDEjCcK7.mdAdded
- md/train/rylSzl-R-/rylSzl-R-.mdAdded
- md/train/tPCrkaLa9Y5ld/tPCrkaLa9Y5ld.mdAdded
- md/train/x2TMPhseWAW/x2TMPhseWAW.mdAdded
- md/train/xpFFI_NtgpW/xpFFI_NtgpW.mdAdded
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236# CROSS-SUPERVISED OBJECT DETECTION
Anonymous authors Paper under double-blind review
# ABSTRACT
After learning a new object category from image-level annotations (with no object bounding boxes), humans are remarkably good at precisely localizing those objects. However, building good object localizers (i.e., detectors) currently requires expensive instance-level annotations. While some work has been done on learning detectors from weakly labeled samples (with only class labels), these detectors do poorly at localization. In this work, we show how to build better object detectors from weakly labeled images of new categories by leveraging knowledge learned from fully labeled base categories. We call this learning paradigm cross-supervised object detection. While earlier works investigated this paradigm, they did not apply it to realistic complex images (e.g., COCO), and their performance was poor. We propose a unified framework that combines a detection head trained from instance-level annotations and a recognition head learned from image-level annotations, together with a spatial correlation module that bridges the gap between detection and recognition. These contributions enable us to better detect novel objects with image-level annotations in complex multi-object scenes such as the COCO dataset.
# 1 INTRODUCTION
Deep architectures have achieved great success in many computer vision tasks including object recognition and the closely related problem of object detection. Modern detectors, such as the Faster RCNN (Ren et al., 2015), YOLO (Redmon et al., 2016), and RetinaNet (Lin et al., 2017), use the same network backbone as popular recognition models. However, even with the same backbone architectures, detection and recognition models require different types of supervision. A good detector relies heavily on precise bounding boxes and labels for each instance (we shall refer to these as instance-level annotations), whereas a recognition model needs only image-level labels. Needless to say, it is more time consuming and expensive to obtain high quality bounding box annotations than class labels. As a result, current detectors are limited to a small set of categories relative to their object recognition counterparts. To address this limitation, it is natural to ask, “Is it possible to learn detectors with only class labels?” This problem is commonly referred to as weakly supervised object detection (WSOD).
Early WSOD work (Hoffman et al., 2014) showed fair performance by directly applying recognition networks to object detection. More recently, researchers have used multiple instance learning methods (Dietterich et al., 1997) to recast WSOD as a multi-label classification problem (Bilen & Vedaldi, 2016). However, these weakly supervised detectors perform poorly at localization. Most WSOD experiments have been conducted on the ILSVRC (Russakovsky et al., 2015) data set, in which images have only a single object, or on the PASCAL VOC (Everingham et al., 2010) data set, which has only 20 categories. The simplicity of these data sets limits the number and types of distractors in an image, making localization substantially easier. Learning from only class labels, it is challenging to detect objects at different scales in an image that contains many distractors. In particular, as shown in our experiments, weakly supervised object detectors do not work well in complex multi-object scenes, such as the COCO dataset (Lin et al., 2014).
To address this challenge, we focus on a form of learning in which the localization of classes with only object labels (weakly labeled classes) can benefit from other classes that have ground truth bounding boxes (fully labeled classes). We refer to this interesting learning paradigm as crosssupervised object detection (CSOD). While several works (Hoffman et al., 2014; Tang et al., 2016;
Yang et al., 2019a; Redmon & Farhadi, 2017) have explored this problem before, they still have the same limitation as the WSOD work we mentioned above. Those cross-supervised object detectors work under simplified scenarios (e.g., ILSVRC data set) where images contain single objects and are object-centered. They struggle to learn under more complex and realistic scenarios, where there are multiple objects from potentially very different classes, and objects could be small and appear anywhere in the images. In this work, we show that by doing multi-task learning on both weaklysupervised base classes and fully-supervised novel classes, our model is able to learn a good detector under the CSOD setting.
More formally, we define CSOD as follows. At training time, we are given 1) images contain objects from both base and novel classes, 2) both class labels and ground truth bounding boxes for base objects, and 3) only class labels for novel objects. Our goal is to detect novel objects. In CSOD, base classes and novel classes are disjoint. Thus, it can be seen as performing fullysupervised detection on the base classes and weakly supervised detection on the novel classes. It has similarities to both transfer learning and semi-supervised learning, since it transfer knowledge from base class to novel class and have more information about some instances than other instances. However, CSOD represents a distinct and novel paradigm for learning.
The current weakly-supervised method has several drawbacks to learn from a multi objects image. As shown in Fig. 1, a weakly supervised object detector tends to detect only the most discriminating part of novel objects instead of the whole object. Notice how only the head of the person, and not the whole body, is detected. Another issue is that the localizer for one object (e.g., the horse) may be confused by the occurrence of another object, such as the person on the horse. This example illustrates the gap between detection and recognition: without ground truth bounding boxes, the detector acts like a standard recognition model – focusing on discriminating rather than detecting.
In this paper, we explore two major mechanisms for improving on this. Our first mechanism is unifying detection and recognition. Using the same network backbone architecture, recognition and detection can be seen as image-level classification and region-level classification respectively, suggesting a strong relation between them. In particular, it suggests a shared training framework in which the same backbone is used with different heads for detection and recognition. Thus, we combine a detection head learned from ground truth bounding boxes, and a recognition head learned in a weakly supervised fashion from class labels. Unlike a traditional recognition head, our recognition head produces a class score for multiple proposals and is capable of detecting objects. The second mechanism is learning a spatial correlation module to reduce the gap between detection and recognition. It takes several high-confidence bounding boxes produced by the recognition head as input, and learns to regress ground truth bounding boxes. By combining these mechanisms together, our model outperforms all previous models when all novel objects are weakly labeled.
In summary, our contributions are three-fold. First, we define a new task—cross-supervised object detection, which enables us to leverage knowledge from fully labeled base categories to help learn a robust detector from novel object class labels only. Second, we propose a unified framework in which two heads are learned from class labels and detection labels respectively, along with a spatial correlation module bridging the gap between recognition and detection. Third, we significantly outperform existing methods (Zhang et al. (2018a); Tang et al. (2017; 2018)) on PASCAL VOC and COCO, suggesting that CSOD could be a promising approach for expanding object detection to a much larger number of categories.
# 2 RELATED WORK
Weakly supervised object detection. WSOD (Kosugi et al. (2019); Zeng et al. (2019); Yang et al. (2019b); Wan et al. (2019); Arun et al. (2019); Wan et al. (2018); Zhang et al. (2018b); Ren et al. (2020); Zhang et al. (2018c); Li et al. (2019); Gao et al. (2019b); Kosugi et al. (2019)) attempts to learn a detector with only image category labels. Most of these methods adopt the idea of Multiple Instance Learning (Dietterich et al. (1997)) to recast WSOD as a multi-label classification task. Bilen & Vedaldi (2016) propose an end-to-end network by modifying a classifier to operate at the level of image regions, serving as a region selector and a classifier simultaneously. Tang et al. (2017) and Tang et al. (2018) find that several iterations of online refinement based on the outputs of previous iterations boosts performance. Wei et al. (2018) and Diba et al. (2017) use semantic segmentation based on class activation maps (Zhou et al. (2016)) to help generate tight bounding boxes. However,
 Figure 1: A comparison between weakly supervised object detector and our detector. Weakly supervised object detector only detects the most discriminating part of an object, e.g., focus on head of a person when detecting a person; or being distracted by co-occurring instances, e.g., distracted by the person on the horse when detecting a horse. Our detector can address these issues.
WSOD methods tend to focus on the most discriminating part of an object and are prone to distractions from co-occurring objects. Detecting a part of the object or distractors represents convergence to a local optimum. Thus, their performance depends heavily on initialization. In comparison, our proposed cross-supervised object detector alleviates the issue of getting trapped in a local optimum by leveraging knowledge learned from fully labeled base categories.
Cross-supervised object detection. There are several previous works using both image-level and instance-level annotations. Kuen et al. (2019) learned a parameter transferring function between a classifier and a detector, enabling an image-based classification network to be adapted to a regionbased classification network. Hoffman et al. (2014) and Tang et al. (2016) propose methods of adaptation for knowledge transfer from classification features to detection features. Uijlings et al. (2018) use a proposal generator trained on base classes to transfer knowledge by leveraging a MIL framework, organized in a semantic hierarchy. Hoffman et al. (2015) design a three-step framework to learn a feature representation from weakly supervised classes and strongly supervised classes jointly. However, these methods can only perform object localization in single object scenes such as ILSVRC, whereas our method can perform object detection in complex multi-object scenes as well, e.g. COCO. Also, it is worth noting that we are doing multi-task learning, which means that we jointly learn from base and novel classes. In comparison, some works (Uijlings et al., 2018) are doing transfer learning. They first learn a model on base classes and then transfer and fine-tune the model on novel classes. Gao et al. (2019a) use a few instance-level labels and a large scale of image-level labels for each category in a training-mining framework, which is referred to as semisupervised detection. Zhang et al. (2018a) propose a framework named MSD that learn objectness on base categories and use it to reject distractors when learning novel objects. In comparison, our spatial correlation module not only learns objectness, but also refines coarse bounding boxes. Further, our model learns from both base and novel classes instead of only novel classes.
# 3 CROSS-SUPERVISED OBJECT DETECTION
CSOD requires us to learn from instance-level annotations (detection labels) and image-level annotations (recognition labels). In this section, we explain the unification of detection and recognition and introduce our framework. In the next section, we describe our novel spatial correlation module.
# 3.1 UNIFYING DETECTION AND RECOGNITION
How to learn a detector from both instance-level and image-level annotations? Since detection and recognition can be seen as region-level and image-level classification respectively, a natural choice is to design a unified framework that combines a detection head and a recognition head that can learn from image-level and instance-level annotations respectively. Here we exploit several baselines to unify the detection and recognition head. (1) Finetune. We first learn through the detection head on base classes with fully labeled samples. Then, we finetune our model using the recognition head on novel classes with only class labels. (2) Two Head. We simultaneously learn the detection and recognition head on base and novel classes, respectively. The weights of the backbones are updated using the loss backpropagated from both heads jointly. (3) Two head +. Instead of learning only on novel classes, we learn the recognition head from class labels of both base and novel classes whereas the recognition head remain the same. (4) Two Branch. Instead of having two shared fully-connected layers after RoI pooling layer (see Fig. 2), we make these two fully-connected layers seperated, allowing the detection and recognition head to have separate unshared pair of fully-connected layers each. Everything else is the same as the Two Head baseline. Experiments are conducted to compare these baselines in $\ S \ S . 1$ and $\ S \ S . 2$ . Our proposed model is based on Two Head. We will discuss the details in $\ S 3 . 2$ .
 Figure 2: Our Detection-Recognition Network (DRN) without the spatial correlation module. In this illustration, Person belongs to novel classes and Boat belongs to base classes. The recognition head learns from the class label Person and outputs the top-scoring bounding box to help the detection head learn to detect the person. The spatial correlation module, discussed in $\ S 4$ , can be added to further refine the top-scoring bounding boxes.
The connection between the recognition and detection head. The baselines mentioned above only use the recognition head to detect novel objects, ignoring the fact that a detection head can play the same role even better. A majority of WSOD methods (Tang et al. (2017); Wan et al. (2019); Wei et al. (2018)) find that re-train a new detector taking the top-scoring bounding boxes from a weakly supervised object detector as ground truth marginally improve the performance. Even with coarse and noisy pseudo bounding boxes, a standard object detector produces better detection results than a weakly supervised object detector. Keeping this hypothesis in mind, we introduce a guidance from the recognition head to the detection head. For each of the novel categories existing in a training sample, the recognition head outputs the top-scoring bounding box, which are then used by the detection head as supervision in that sample.
# 3.2 DETECTION-RECOGNITION NETWORK
The structure of our Detection-Recognition Network (DRN) is shown in Fig. 2. Given an image, we first generate 2000 object proposals by Selective Search (Uijlings et al. (2013)) or RPN (Ren et al. (2015)) trained on base classes. The image and proposals are fed into several convolutional (conv) layers followed by a region-of-interest (RoI) pooling layer (Girshick (2015)) to output fixed-size feature maps. Then, these feature maps are fed into two fully connected (fc) layers to produce a collection of proposal features, which are further branched into the recognition and detection head.
Recognition Head. We followed previous WSOD methods to design our recognition head. Since OICR (Tang et al. (2017)) is simple, neat, and commonly being used, we make our recognition head the same as OICR, but with fewer refinement branches to reduce the computation cost. However, our recognition head can be replaced by any WSOD structure as shown in $\ S 5 . 3$ .
Within the recognition head as shown in Fig. 2, the proposal features are branched into three streams producing three matrices $\mathbf { x } ^ { c } , \mathbf { x } ^ { d } , \mathbf { x } ^ { e } \in \mathbb { R } ^ { C \times | R | }$ , where $C$ is the number of novel classes and $| R |$ is the number of proposals. Then the two matrices $\mathbf { x } ^ { c }$ and $\mathbf { x } ^ { d }$ are passed through a softmax function
 Figure 3: Our spatial correlation module (SCM). Our SCM learns to capture spatial correlation among high-confidence bounding boxes, generating a class-agnostic heatmap for the whole image. A heatmap detector is then trained to learn ground truth bounding boxes.
over classes and proposals respectively: $\sigma ( \mathbf { x } ^ { c } )$ and $\sigma ( \mathbf { x } ^ { d } )$ . A proposal score $\mathbf { x } _ { c r } ^ { R }$ , indicating the score of $c ^ { t h }$ novel class for $r ^ { t h }$ proposal, corresponds to the respective element of the matrix $\bar { \mathbf { x } } ^ { R } =$ $\sigma ( \mathbf { x } ^ { c } ) \odot \sigma ( \mathbf { x } ^ { d } )$ , where $\odot$ refers to an element-wise product. Finally, we obtain the image score of $c ^ { t h }$ class $\phi _ { c }$ by summing over all proposals: $\begin{array} { r } { \phi _ { c } = \sum _ { r = 1 } ^ { | R | } x _ { c r } ^ { R } } \end{array}$ . Then we culate a standard multi-class cross-entropy loss as shown in the first term of Eq.1. Another matrix $\mathbf { x } ^ { e }$ function over classes, the result of which is expresses as a weighted multi-class cross entropy loss as shown in the second term of Eq.1. We set the pseudo label for each proposal $r$ based on its IoU (or overlap) with the top-scoring proposal of $c ^ { t h }$ class, $y _ { c r } = 1$ if $\mathrm { I o U } > 0 . 5$ and $y _ { c r } = 0$ otherwise. The weight $w _ { r }$ for each proposal $r$ is its IoU with the top-scoring proposal. The total loss for the recognition head is
$$L _ { r e c } = [ - \sum _ { c = 1 } ^ { C } y _ { c } l o g \phi _ { c } + ( 1 - y _ { c } ) l o g ( 1 - \phi _ { c } ) ] + [ - \frac { 1 } { | { \cal R } | } \sum _ { r = 1 } ^ { | { \cal R } | } \sum _ { c = 1 } ^ { C + 1 } w _ { r } y _ { c r } l o g x _ { c r } ^ { e } ]$$
Supervision from our recognition head. We use the matrix $x ^ { e }$ to propose pseudos bounding boxes to guide the detection head. Specifically, we select one top-scoring proposal for each object category that appears in the image as a pseudo bounding box, as done in OICR. We introduce the spatial correlation module in $\ S 4$ , to further refine this pseudo ground truth.
Detection Head. Now that we have pseudo bounding boxes for novel objects and ground truth bounding boxes for base objects, we train our detection head like a standard detector. For simplicity and efficiency, our detection head use the same structure of Faster R-CNN (Ren et al. (2015)). At inference time, the detection head produces detection results for both base categories and novel categories.
# 4 LEARNING TO MODEL SPATIAL CORRELATION
Our intuition is that there exists spatial correlation among high-confidence bounding boxes, and such spatial correlation can be captured to predict ground truth bounding boxes. By representing the spatial correlation in a class-agnostic heatmap, we can easily learn a mapping from recognitionbased bounding boxes to ground truth bounding boxes for base categories, and then transfer this mapping to novel categories.
Thus, we propose a spatial correlation module (SCM). SCM is used as a guidance refinement technique, taking sets of high-confidence bounding boxes from the recognition head, and correspondingly returning pseudo ground truth bounding boxes to the detection head. These pseudo ground truth boxes act as supervision while training on novel categories. The framework of SCM is showed in Fig. 3. Within this module, we first generate a class agnostic heatmap based on the high-confidence bounding boxes predicted by our recognition head, and then we perform detection on top of the heatmap.
Heatmap synthesis. We want to capture the information about how the high-confidence bounding boxes interact amongst themselves. Here, we introduce a simple way of achieving this using a class-agnostic heatmap. For each category existing in the image $y _ { c } = 1 , c \in C$ , we first threshold and select high-confidence bounding boxes of class $c$ . Then we synthesize a corresponding classagnostic heatmap, which is essentially a two-channel feature map of the same size as the original image. The value at each pixel is the sum and the maximum of confidence over all selected bounding boxes covering that pixel.
Table 1: Object Detection performance (mAP $\%$ ) on PASCAL VOC 2007 test set. ∗ indicates using the structure of OICR in the recognition head. ”MSD-Ens” is the ensemble of AlexNet and VGG16. ”MSD-Ens+FRCN” indicates using an ensemble model to predict pseudo ground truths and then learn a Fast-RCNN (Girshick (2015)) using VGG-16.
<table><tr><td rowspan="2">Method</td><td rowspan="2">Base mean</td><td colspan="9">Novel</td><td rowspan="2"></td></tr><tr><td>table</td><td>dog</td><td>horse</td><td>mbike</td><td>person</td><td>plant sheep</td><td></td><td>sofa</td><td>train tv</td></tr><tr><td>OICR</td><td>42.1</td><td>33.4</td><td>29.3</td><td>56.3</td><td>64.6</td><td>8.0</td><td>23.5</td><td>47.2</td><td>47.2</td><td>48.3 61.7</td><td>mean 42.0</td></tr><tr><td>PCL</td><td>49.2</td><td>51.5</td><td>37.3</td><td>63.3</td><td>63.9</td><td>15.8 23.6</td><td>48.8</td><td>55.3</td><td>61.2</td><td>62.1</td><td>48.3</td></tr><tr><td>MSD-VGG16</td><td>50.6</td><td>14.3</td><td>69.3</td><td>65.4 69.6</td><td>2.4</td><td>20.5</td><td>54.6</td><td>34.3</td><td>58.3</td><td>54.6</td><td>44.3</td></tr><tr><td>MSD-Ens</td><td>53.4</td><td>18.3</td><td>70.6</td><td>66.7 69.8</td><td></td><td>3.7 24.7</td><td>55.0</td><td>37.4</td><td>58.3</td><td>57.3</td><td>46.1</td></tr><tr><td>MSD-Ens+FRCN</td><td>53.9</td><td>15.3</td><td>72.0</td><td>74.4</td><td>65.2</td><td>15.4</td><td>25.1 53.6</td><td>54.4</td><td>45.6</td><td>61.4</td><td>48.2</td></tr><tr><td>Weight Transfer</td><td>68.4</td><td>10.4</td><td>61.0</td><td>58.0</td><td>65.1</td><td>19.8</td><td>19.5</td><td>58.0</td><td>50.8 58.6</td><td>52.7</td><td>45.4</td></tr><tr><td>Finetune*</td><td>71.8</td><td>17.8</td><td>22.9</td><td>15.2</td><td>71.2</td><td>10.2</td><td>15.1</td><td>61.7 36.6</td><td>21.9</td><td>61.3</td><td>33.4</td></tr><tr><td>Two Head*</td><td>72.9</td><td>60.6</td><td>33.2</td><td>47.7</td><td>70.2</td><td>3.9</td><td>25.5</td><td>52.6</td><td>58.4 54.7</td><td>64.4</td><td>47.1</td></tr><tr><td>Two Head+*</td><td>72.4</td><td>44.5</td><td>29.5</td><td>52.4</td><td>68.4</td><td>5.1</td><td>22.6 53.0</td><td>55.5</td><td>58.6</td><td>64.8</td><td> 45.4</td></tr><tr><td>Two Branch*</td><td>72.7</td><td>57.3</td><td>30.2</td><td>44.2 68.1</td><td>3.0</td><td>21.4</td><td>52.2</td><td>53.5</td><td>51.2</td><td>59.7</td><td>44.1</td></tr><tr><td>Ours w/o SCM</td><td>71.6</td><td>62.3</td><td>41.9</td><td>38.2</td><td>73.0</td><td>11.3</td><td>26.0</td><td>60.6</td><td>63.8</td><td>70.5 65.3</td><td>51.3</td></tr><tr><td>Ours</td><td>72.9</td><td>61.0</td><td>57.1</td><td>63.5</td><td>72.0</td><td>19.5</td><td>24.2</td><td>60.9</td><td>58.6</td><td>68.5 65.5</td><td>55.1+3.8</td></tr><tr><td>Ours* w/o SCM</td><td>72.7</td><td>66.8</td><td>50.4</td><td>57.0 71.5</td><td></td><td>12.1 27.6</td><td>57.1</td><td>62.7</td><td>54.2</td><td>64.2</td><td>52.4</td></tr><tr><td>Ours*</td><td>72.7</td><td>60.9</td><td>59.4</td><td>70.5</td><td>71.0</td><td>17.5</td><td>24.1</td><td>62.0</td><td>60.5 62.4</td><td>69.1</td><td>55.7+8.3</td></tr></table>
Heatmap detection. We consider each class-agnostic heatmap as a two-channel image, and perform detection on it. Specifically, we learn a class-agnostic detector on base classes, that we further use to produce pseudo ground truth bounding boxes for novel objects.
For this task, we use a lightweight one-stage detector, consisting of only five convolutional layers. We follow the same network architecture and loss as FCOS (Tian et al. (2019)), replacing the backbone and feature pyramid network with five max pooling layers. In our experiments, we also compare this tiny detector to a baseline: using three fully-connected layers to regress the groundtruth location taking the coordinates of high-confidence bounding boxes as input.
Loss of DRN. After introducing our SCM, we can formulate the full loss function for DRN. We use $L _ { r e c }$ , $L _ { d e t }$ , and $L _ { s c m }$ to indicate the losses from our recognition head, detection head, and spatial correlation module respectively. $\lambda _ { r e c } , \lambda _ { d e t }$ , and $\lambda _ { s c m }$ are the regularization hyperparameters used to balance the three separate loss functions. We train our DRN using the following loss:
$$L = \lambda _ { r e c } L _ { r e c } + \lambda _ { d e t } L _ { d e t } + \lambda _ { s c m } L _ { s c m }$$
# 5 EXPERIMENTS
# 5.1 PASCAL VOC
Setup. PASCAL VOC 2007 and 2012 datasets contain 9, 962 and 22, 531 images respectively for 20 object classes. They are divided into train, val, and test sets. Here we follow previous work (Tang et al. (2017)) to choose the trainval set (5, 011 images from 2007 and 11, 540 images from 2012). We divide the first 10 classes into base classes and the other 10 classes into novel classes. To evaluate our methods, we calculate mean of Average Precision (mAP) based on the PASCAL criteria, i.e., $\mathrm { I O U } { > } 0 . 5$ between predicted boxes and ground truths.
Implementation details. All our baselines, competitors and our framework are based on VGG16 (Simonyan & Zisserman (2015)) followed most of weakly supervised object detection methods. We set $\lambda _ { r e c } = 1$ , $\lambda _ { d e t } = 1 0$ , and $\lambda _ { s c m } = 1 0$ . We train the whole framework for 20 epochs using SGD with a momentum of 0.9, a weight decay of 0.0005 and a learning rate of 0.001, which is reduced by a factor of 10 at $1 4 ^ { t h }$ epoch. For a stable learning process, we don’t provide supervision from recognition head to detection head in the first 9 epochs.
Table 2: The results on COCO. We compare our method with several strong baselines in $\ S \ 3 . 1$ and competitors. Our method significantly outperforms these approaches, showing that our crosssupervised object detector is capable of detecting novel objects in complex multi-object scenes.
<table><tr><td rowspan="2">method</td><td colspan="6">non-voc -→ voc: test on B = {voc}</td><td colspan="6"> sixty→ twenty: test on B= {twenty}</td></tr><tr><td>AP</td><td>AP50</td><td>AP75</td><td>APs APM</td><td></td><td>APL</td><td>AP</td><td>AP50</td><td>AP75 APsAPm APL</td><td></td><td></td><td></td></tr><tr><td>Rec. Head</td><td>4.0</td><td>15.4</td><td>0.9</td><td>1.2</td><td>5.7</td><td>5.8</td><td>4.7</td><td>16.4</td><td>1.3</td><td>1.7</td><td>8.0</td><td>6.9</td></tr><tr><td>OICR</td><td>4.2</td><td>15.7</td><td>1.0</td><td>1.3</td><td>5.5</td><td>5.9</td><td>4.5</td><td>16.6</td><td>1.4</td><td>2.0</td><td>8.2</td><td>7.1</td></tr><tr><td>PCL</td><td>9.2</td><td>19.6</td><td>-</td><td>-</td><td>1</td><td>-</td><td>9.2</td><td>19.6</td><td>-</td><td>-</td><td>1</td><td>-</td></tr><tr><td>Weight T.</td><td>9.3</td><td>26.4</td><td>5.7</td><td>5.8</td><td>11.7</td><td>12.4</td><td>8.7</td><td>25.5</td><td>5.5</td><td>5.4</td><td>11.5</td><td>11.7</td></tr><tr><td>Finetune</td><td>2.3</td><td>7.4</td><td>0.3</td><td>0.7</td><td>3.1</td><td>3.3</td><td>2.4</td><td>7.7</td><td>0.2</td><td>0.5</td><td>2.8</td><td>3.0</td></tr><tr><td>Two Head</td><td>11.0</td><td>30.2</td><td>6.1</td><td>6.2</td><td>15.4</td><td>15.4</td><td>11.3</td><td>29.5</td><td>5.8</td><td>6.3</td><td>14.8</td><td>15.0</td></tr><tr><td>Two Head+</td><td>9.1</td><td>26.7</td><td>5.4</td><td>5.5</td><td>12.1</td><td>12.3</td><td>9.0</td><td>27.1</td><td>5.4</td><td>5.7</td><td>11.7</td><td>11.6</td></tr><tr><td>Two Branch</td><td>9.4</td><td>26.6</td><td>5.6</td><td>5.7</td><td>12.3</td><td>12.4</td><td>8.5</td><td>24.4</td><td>4.5</td><td>4.3</td><td>11.9</td><td>11.9</td></tr><tr><td>Ours w/o SCM</td><td>12.5</td><td>33.6</td><td>6.6</td><td>7.3</td><td>19.2</td><td>16.4</td><td>12.6</td><td>32.3</td><td>7.8</td><td>7.0</td><td>19.4</td><td>17.4</td></tr><tr><td> Ours</td><td>13.9+1.4</td><td> 36.2+2.6</td><td>7.7</td><td>6.9</td><td>18.8</td><td>19.9</td><td>14.0+1.4</td><td> 34.5+2.2</td><td>8.9</td><td>7.1</td><td>19.2</td><td>20.6</td></tr></table>
Baselines and competitors. We compare against several baselines as mentioned in $\ S \ 3 . 1$ , two WSOD methods: OICR (Tang et al. (2017)) and PCL (Tang et al. (2018)), and two cross-supervised object detector: MSD (Zhang et al. (2018a)), weight transfer (Kuen et al. (2019)).
Results. As shown in Table 1, our method outperforms all other approaches by a large margin (over $7 \%$ relative increase in mAP on novel classes). The results are consistent with our discussion in $\ S \ 3 . 1$ . We note that (1) sharing backbone for the recognition and detection head learns a more discriminative embedding for novel objects. In Table 1, Two Head∗ boosts the performance by 5 points as compared to only using the recognition head (OICR). (2) A supervision from recognition head to detection head exploits the full potential of a detection model. By adding the supervision (Ours∗ w/o SCM ), the result is improved by 5 points as compared to Two Head. (3) Our spatial correlation module successfully captures the spatial correlation between high-confidence proposals. It further boosts the performance by 3 points.
<table><tr><td>method</td><td>non-voc-→voc AP50 on B</td><td>sixty-→twenty AP50 on B</td></tr><tr><td>2 layer Fc layer 3 layer</td><td>31.0 30.8</td><td>28.7 28.3</td></tr><tr><td>4 layer</td><td>30.5</td><td>28.5</td></tr><tr><td>R-50-FPN</td><td>36.4</td><td>34.8</td></tr><tr><td>FCOS 4 conv</td><td>35.8</td><td>33.8</td></tr><tr><td>5 conv</td><td>36.2</td><td>34.5</td></tr><tr><td>w/o SCM</td><td>33.6</td><td>32.3</td></tr></table>
(a) Ablation on Heatmap synthesis. The result suggests using two-channel heatmap consists of maximum confidence and sum of confidence over proposals covering that position.
(b) Ablation on the structure of SCM. FCOS with 5 conv layers has nearly the best performance and very few parameters compared to a ResNet-50 backbone.
Table 3: Ablation study of our method.
<table><tr><td></td><td>non-voc-→voc AP50 on B</td><td>sixty→twenty AP50 on B</td></tr><tr><td>method max</td><td>35.5</td><td>33.8</td></tr><tr><td>sum</td><td>36.0</td><td>34.0</td></tr><tr><td>num</td><td>31.5</td><td>29.5</td></tr><tr><td>max+sum</td><td>36.2</td><td>34.5</td></tr><tr><td>max+num</td><td>35.7</td><td>34.1</td></tr><tr><td>sum+num</td><td>35.9</td><td>34.2</td></tr><tr><td>max+sum+num</td><td>36.1</td><td>34.2</td></tr></table>
<table><tr><td>method</td><td>non-voc-→voc AP50 on B</td><td>sixty-→twenty AP50 on B</td></tr><tr><td>WSDDN</td><td>35.7</td><td>33.8</td></tr><tr><td>OICR</td><td>36.6</td><td>34.7</td></tr><tr><td>Ours</td><td>36.4</td><td>34.5</td></tr></table>
<table><tr><td colspan="2"></td><td colspan="2">base-novel AP50 on A AP5o on B</td></tr><tr><td rowspan="2">dataset PASCAL VOC</td><td>method</td><td></td><td rowspan="2">46.1</td></tr><tr><td>RPN</td><td>76.2</td></tr><tr><td rowspan="2">non-voc->voc</td><td>SS</td><td>72.7</td><td>55.7</td></tr><tr><td>RPN SS</td><td>46.3 42.5</td><td>36.2 34.5</td></tr></table>
(c) Ablation on the structure of the recognition head. OICR has more refinement branches so it behaves a little better than our recognition head but takes double the computation time.
(d) Ablation on the proposal generator. On PASCAL VOC, there are not enough categories to learn a good RPN. So, we use selective search and RPN to generate proposals for PASCAL VOC and COCO respectively.
 Figure 4: Detection results on novel objects. The results are from our proposed model but with different heads. The first row shows the results of the recognition head. The second row lists the results from SCM. The third row displays the results from the detection head.
# 5.2 COCO
Setup. We train on the COCO train2017 split and test on val2017 split. We simulate the crosssupervised object detection scenario on COCO by splitting the 80 classes into base and novel classes. We use a 20/60 split same as Hu et al. (2018), dividing the COCO categories into all the 20 classes contained in PASCAL VOC and the 60 that are not. We refer to these as the ‘voc’ and ‘non-voc’ category sets. ‘voc non-voc’ indicates that we take ‘voc’ as our base classes and ‘non-voc’ as our novel classes. Similarly, we split the first 20 classes into ‘twenty’ and the last 60 classes into ’sixty’.
Implementation details. The implementation details are the same as $\ S 5 . 1$ by default. We train the whole framework for 13 epochs. There is no supervision from recognition head to detection head in the first 5 epochs. The learning rate is reduced by a factor of 10 at $\bar { 8 } ^ { t h }$ , and $1 2 ^ { t h }$ epochs.
Baselines and competitors. Most baselines and competitors are the same as $\ S \ S . 1$ . ’Rec. Head’ represents only using our recognition head structure as a weakly supervised object detector.
Results. The results on COCO still support our discussion in $\ S 5 . 1$ . Even in complex multi objects scenes, our DRN outperforms all baselines and competitors by a large margin.
# 5.3 ABLATION EXPERIMENTS
Heatmap synthesis. In Table 3a, we compare the different methods to synthesize the heatmaps in the spatial correlation module. For each position in the heatmap, we consider three kinds of values: the maximum of confidence, the sum of confidence, and the number of proposals covering the position. This result informs us to use max and sum to create a two-channel heatmap.
Structure of SCM. In Table 3b, we compare different implementations of SCM. We compare the FCOS (Tian et al. (2019)) with 5 convolutional layers and the standard FCOS with a ResNet-50 (He et al. (2016)) backbone. We also compare to the regression baseline mentioned in $\ S 4$ . Considering the computation cost, we choose FCOS with 5 convolutional layer as our heatmap detector.
Structure of the Recognition head. In Table 3c, we compare different structures for the recognition head. WSDDN (Bilen & Vedaldi (2016)) and OICR are compared to our structure. The results support that our model can benefit from a stronger recognition head.
Different proposal generation methods. Table 3d shows the ablation of different ways to generate proposals. In PASCAL VOC with only 10 base classes, RPN performs worse than selective search. In COCO with 60 base classes, RPN performs better than selective search.
Visualization. Fig. 4 shows detection results on novel objects. Images in the first row, the second row, and the third row are detected by our model from the recognition head, the SCM, and the detection head respectively. The images in the first row tend to focus on the discriminating parts of the objects, e.g. the first and the second images contain only a part of the person. It also tends to detect co-occurring objects, e.g. the fourth image not only detects horse but also a large part of the person. Our SCM alleviates these problems. It tends to focus on the whole object, e.g. the first and the third samples detect the whole person instead of only the head. Also, it can correct unsatisfactory bounding boxes distracted by co-occurring objects, e.g. SCM correctly localizes the horse instead of localizing both the person and the horse in the fourth example. Obviously, bounding boxes in the third row are the best, indicating the efficacy of our framework.
# 6 CONCLUSION
In this paper, we have focused on cross-supervised object detection in realistic settings with complex imagery. We explore two major ways to build a good cross-supervised object detector: sharing network backbone between a recognition head and a detection head, and learning a spatial correlation module to bridge the gap between recognition and detection. Significant improvement on PASCAL VOC and COCO suggests a novel and promising approach for expanding object detection to a much larger number of categories.
# REFERENCES
Aditya Arun, C.V. Jawahar, and M. Pawan Kumar. Dissimilarity coefficient based weakly supervised object detection. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2019.
Hakan Bilen and Andrea Vedaldi. Weakly supervised deep detection networks. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2016.
Ali Diba, Vivek Sharma, Ali Pazandeh, Hamed Pirsiavash, and Luc Van Gool. Weakly supervised cascaded convolutional networks. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2017.
Thomas G Dietterich, Richard H Lathrop, and Tomas Lozano-P ´ erez. Solving the multiple instance ´ problem with axis-parallel rectangles. Artificial intelligence, 1997.
Mark Everingham, Luc Van Gool, Christopher KI Williams, John Winn, and Andrew Zisserman. The pascal visual object classes (voc) challenge. International journal of computer vision (IJCV), 2010.
Jiyang Gao, Jiang Wang, Shengyang Dai, Li-Jia Li, and Ram Nevatia. Note-rcnn: Noise tolerant ensemble rcnn for semi-supervised object detection. In Proceedings of the IEEE International Conference on Computer Vision (ICCV), 2019a.
Yan Gao, Boxiao Liu, Nan Guo, Xiaochun Ye, Fang Wan, Haihang You, and Dongrui Fan. Cmidn: Coupled multiple instance detection network with segmentation guidance for weakly supervised object detection. In Proceedings of the IEEE International Conference on Computer Vision (ICCV), 2019b.
Ross Girshick. Fast r-cnn. In Proceedings of the IEEE International Conference on Computer Vision (ICCV), 2015.
Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Deep residual learning for image recognition. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2016.
Judy Hoffman, Sergio Guadarrama, Eric S Tzeng, Ronghang Hu, Jeff Donahue, Ross Girshick, Trevor Darrell, and Kate Saenko. Lsda: Large scale detection through adaptation. In Advances in Neural Information Processing Systems (NeurIPS), 2014.
Judy Hoffman, Deepak Pathak, Trevor Darrell, and Kate Saenko. Detector discovery in the wild: Joint multiple instance and representation learning. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2015.
Ronghang Hu, Piotr Dollar, Kaiming He, Trevor Darrell, and Ross Girshick. Learning to segment ´ every thing. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2018.
Satoshi Kosugi, Toshihiko Yamasaki, and Kiyoharu Aizawa. Object-aware instance labeling for weakly supervised object detection. In Proceedings of the IEEE International Conference on Computer Vision (ICCV), 2019.
Jason Kuen, Federico Perazzi, Zhe Lin, Jianming Zhang, and Yap-Peng Tan. Scaling object detection by transferring classification weights. In Proceedings of the IEEE International Conference on Computer Vision (ICCV), 2019.
Xiaoyan Li, Meina Kan, Shiguang Shan, and Xilin Chen. Weakly supervised object detection with segmentation collaboration. In Proceedings of the IEEE International Conference on Computer Vision (ICCV), 2019.
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 ´ Proceedings of the European Conference on Computer Vision (ECCV), 2014.
Tsung-Yi Lin, Priya Goyal, Ross Girshick, Kaiming He, and Piotr Dollar. Focal loss for dense object ´ detection. In Proceedings of the IEEE International Conference on Computer Vision (ICCV), 2017.
Joseph Redmon and Ali Farhadi. Yolo9000: better, faster, stronger. In Proceedings of the IEEE International Conference on Computer Vision (CVPR), 2017.
Joseph Redmon, Santosh Divvala, Ross Girshick, and Ali Farhadi. You only look once: Unified, real-time object detection. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2016.
Shaoqing Ren, Kaiming He, Ross Girshick, and Jian Sun. Faster r-cnn: Towards real-time object detection with region proposal networks. In Advances in Neural Information Processing Systems (NeurIPS), 2015.
Zhongzheng Ren, Zhiding Yu, Xiaodong Yang, Ming-Yu Liu, Yong Jae Lee, Alexander G Schwing, and Jan Kautz. Instance-aware, context-focused, and memory-efficient weakly supervised object detection. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2020.
Olga Russakovsky, Jia Deng, Hao Su, Jonathan Krause, Sanjeev Satheesh, Sean Ma, Zhiheng Huang, Andrej Karpathy, Aditya Khosla, Michael Bernstein, Alexander C. Berg, and Li Fei-Fei. ImageNet Large Scale Visual Recognition Challenge. International Journal of Computer Vision (IJCV), 2015.
Karen Simonyan and Andrew Zisserman. Very deep convolutional networks for large-scale image recognition. In Proceedings of the International Conference on Learning Representations (ICLR), 2015.
Peng Tang, Xinggang Wang, Xiang Bai, and Wenyu Liu. Multiple instance detection network with online instance classifier refinement. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2017.
Peng Tang, Xinggang Wang, Song Bai, Wei Shen, Xiang Bai, Wenyu Liu, and Alan Yuille. Pcl: Proposal cluster learning for weakly supervised object detection. IEEE transactions on pattern analysis and machine intelligence, 2018.
Yuxing Tang, Josiah Wang, Boyang Gao, Emmanuel Dellandrea, Robert Gaizauskas, and Liming ´ Chen. Large scale semi-supervised object detection using visual and semantic knowledge transfer. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2016.
Zhi Tian, Chunhua Shen, Hao Chen, and Tong He. Fcos: Fully convolutional one-stage object detection. In Proceedings of the IEEE International Conference on Computer Vision (ICCV), 2019.
Jasper Uijlings, Stefan Popov, and Vittorio Ferrari. Revisiting knowledge transfer for training object class detectors. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2018.
Jasper RR Uijlings, Koen EA Van De Sande, Theo Gevers, and Arnold WM Smeulders. Selective search for object recognition. International journal of computer vision (IJCV), 2013.
Fang Wan, Pengxu Wei, Jianbin Jiao, Zhenjun Han, and Qixiang Ye. Min-entropy latent model for weakly supervised object detection. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2018.
Fang Wan, Chang Liu, Wei Ke, Xiangyang Ji, Jianbin Jiao, and Qixiang Ye. C-mil: Continuation multiple instance learning for weakly supervised object detection. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2019.
Yunchao Wei, Zhiqiang Shen, Bowen Cheng, Honghui Shi, Jinjun Xiong, Jiashi Feng, and Thomas Huang. Ts2c: Tight box mining with surrounding segmentation context for weakly supervised object detection. In Proceedings of the European Conference on Computer Vision (ECCV), 2018.
Hao Yang, Hao Wu, and Hao Chen. Detecting 11k classes: Large scale object detection without fine-grained bounding boxes. In Proceedings of the IEEE International Conference on Computer Vision (CVPR), 2019a.
Ke Yang, Dongsheng Li, and Yong Dou. Towards precise end-to-end weakly supervised object detection network. In Proceedings of the IEEE International Conference on Computer Vision (ICCV), 2019b.
Zhaoyang Zeng, Bei Liu, Jianlong Fu, Hongyang Chao, and Lei Zhang. Wsod2: Learning bottomup and top-down objectness distillation for weakly-supervised object detection. In Proceedings of the IEEE International Conference on Computer Vision (ICCV), 2019.
Junge Zhang, Kaiqi Huang, Jianguo Zhang, et al. Mixed supervised object detection with robust objectness transfer. IEEE transactions on pattern analysis and machine intelligence, 2018a.
Xiaopeng Zhang, Jiashi Feng, Hongkai Xiong, and Qi Tian. Zigzag learning for weakly supervised object detection. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2018b.
Yongqiang Zhang, Yancheng Bai, Mingli Ding, Yongqiang Li, and Bernard Ghanem. W2f: A weakly-supervised to fully-supervised framework for object detection. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2018c.
Bolei Zhou, Aditya Khosla, Agata Lapedriza, Aude Oliva, and Antonio Torralba. Learning deep features for discriminative localization. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2016.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394# Pairwise Adjusted Mutual Information
Anonymous Author(s) Affiliation Address email
# Abstract
1 A well-known metric for quantifying the similarity between two clusterings is 2 the adjusted mutual information. Compared to mutual information, a corrective 3 term based on random permutations of the labels is introduced, preventing two 4 clusterings being similar by chance. Unfortunately, this adjustment makes the 5 metric computationally expensive. In this paper, we propose a novel adjustment 6 based on pairwise label permutations instead of full label permutations. Specifically, 7 we consider permutations where only two samples, selected uniformly at random, 8 exchange their labels. We show that the corresponding adjusted metric, which 9 can be expressed explicitly, behaves similarly to the standard adjusted mutual 10 information for assessing the quality of a clustering, while having a much lower 11 time complexity. Both metrics are compared in terms of quality and performance 12 on experiments based on synthetic and real data.
# 13 1 Introduction
14 A well-known metric for quantifying the similarity between two clusterings of the same data is 15 the adjusted mutual information [Nguyen et al., 2009; Vinh et al., 2010]. Compared to mutual 16 information, this metric is adjusted against chance, meaning that the similarity cannot be due to 17 randomness but only to the structure of the dataset, appearing in both clusterings. This is the reason 18 why this metric is widely used in unsupervised learning, see [Zhang et al., 2013; Thirion et al., 2014; 19 Taha and Hanbury, 2015; Yang et al., 2016; Wang et al., 2017] for various applications. 20 The standard way of adjusting mutual information against chance is through random label permuta 21 tions of one of the clusterings [Vinh et al., 2010]. Unfortunately, this adjustment makes the metric 22 computationally expensive. Specifically, the time complexity of the metric is in $O ( \operatorname* { m a x } ( k , l ) n )$ , 23 where $k , l$ are the numbers of clusters in each clustering and $n$ is the number of samples [Romano et 24 al., 2014]. As a comparison, the time complexity of mutual information is equal to $O ( k l )$ given the 25 contingency matrix of the clusterings, i.e., the matrix counting the number of samples in each pair of 26 clusters, one per clustering. The additional computational effort required by adjustment is significant 27 as the number of samples $n$ is typically much larger than the numbers of clusters $k , l$ . 28 In this paper, we propose a novel adjustment based on pairwise permutations. That is, we consider 29 permutations where only two samples, selected uniformly at random, exchange their labels. We 30 show that the corresponding adjusted metric, we refer to as pairwise adjusted mutual information, 31 is as efficient as adjusted mutual information for assessing the quality of a clustering, with a much 32 lower time complexity. In particular, the time complexity is the same as that of mutual information. 33 The gain in complexity is significant, as the computation time is now independent of the number of 34 samples $n$ , given the contingency matrix. 35 The rest of the paper is organized as follows. We first provide the definition and key properties of 36 adjusted mutual information in the general setting of information theory. We then introduce mutual 37 information with pairwise adjustement and explain why the exact same properties are satisfied by 38 this new notion of adjusted mutual information. The application of both notions of adjustment to 39 clustering, including the explicit expressions of the corresponding metrics, is presented in section 4. 40 Experiments on both synthetic and real data are presented in section 5. Section 6 concludes the paper.
# 41 2 Adjusted mutual information
42 Let $P$ be the uniform probability measure on $\Omega = \{ 1 , \dots , n \}$ , for some positive integer $n$ . Let $X , Y$ 43 be random variables on the probability space $( \Omega , P )$ . Without any loss of generality, we assume that 44 $X$ and $Y$ are mapping from $\Omega$ to sets consisting of consecutive integers, starting from 1. Denoting by 45 $H$ the entropy, the mutual information between $X$ and $Y$ is defined by [Cover and Thomas, 1991]:
$$I ( X , Y ) = H ( X ) + H ( Y ) - H ( X , Y ) .$$
This is the information shared by $X$ and $Y$ , which is equal to 0 if $X$ and $Y$ are independent. A distance between $X$ and $Y$ can then be defined by:
$$d ( X , Y ) = H ( X , Y ) - I ( X , Y ) = H ( X | Y ) + H ( Y | X ) .$$
46 This distance, known as the variation of information, is a metric in the quotient space of random 47 variables under the equivalence relation $X \sim Y$ if and only if there is some bijection $\varphi$ such that 48 $X = \varphi ( Y )$ [Meila, 2003]. ˘ 49 Adjusted mutual information. The adjusted mutual information between $X$ and $Y$ , corresponding 50 to the mutual information between $X$ and $Y$ adjusted against chance, is defined by:
$$\Delta I ( X , Y ) = I ( X , Y ) - \operatorname { E } ( I ( X , Y _ { \sigma } ) ) ,$$
51 where $Y _ { \sigma }$ is the random variable $Y \circ \sigma$ , for any permutation $\sigma$ of $\{ 1 , \ldots , n \}$ , and the expectation is 52 taken over all permutations $\sigma$ , chosen uniformly at random. 53 Remark 1 (Normalization). It is frequent to also normalize adjusted mutual information, so as to 54 get a score between $\boldsymbol { \theta }$ and 1 [Vinh et al., 2010; Romano et al., 2014]. In this paper, we only focus on 55 the adjustment step. Note that normalization can be equally applied to both considered notions of 56 adjustment and thus be studied separately.
57 We have the equivalent definition:
$$\begin{array} { l } { \displaystyle \Delta I ( X , Y ) = \mathrm { E } ( H ( X , Y _ { \sigma } ) ) - H ( X , Y ) , } \\ { \displaystyle = \frac { 1 } { 2 } ( \mathrm { E } ( d ( X , Y _ { \sigma } ) ) - d ( X , Y ) ) . } \end{array}$$
58 This equivalence follows from Proposition 1 and the fact that the definition is symmetric in $X$ and $Y$ 59 All proofs are available in the supplementary material.
60 Proposition 1. We have for any random variables $X$ and $Y$ :
$$\begin{array} { r l } & { H ( X ) = \operatorname { E } ( H ( X _ { \sigma } ) ) , } \\ & { \operatorname { E } ( H ( X , Y _ { \sigma } ) ) = \operatorname { E } ( H ( X _ { \sigma } , Y ) ) , } \\ & { \operatorname { E } ( I ( X , Y _ { \sigma } ) ) = \operatorname { E } ( I ( X _ { \sigma } , Y ) ) . } \end{array}$$
61 In view of (3), we expect $\Delta I ( X , Y )$ to be positive if $X$ and $Y$ share information, as $X$ is expected to 62 be closer to $Y$ (for the distance $d$ ) than to $Y _ { \sigma }$ , a randomized version of $Y$ . There are specific cases 63 where $\Delta I ( X , Y ) = 0$ , as stated in Proposition 2; these cases will be interpreted in terms of clustering 64 in section 4. 65 Proposition 2. We have $\Delta I ( X , Y ) = 0$ whenever $Y$ (or $X$ , by symmetry) is constant or equal to 66 some permutation of $\{ 1 , \ldots , n \}$ .
Adjusted entropy. Observing that $H ( X ) = I ( X , X )$ , we define similarly the adjusted entropy of $X$ by:
$$\Delta H ( X ) = \Delta I ( X , X ) = H ( X ) - \operatorname { E } ( I ( X , X _ { \sigma } ) ) .$$
67 By (1), we get:
$$\Delta H ( X ) = \operatorname { E } ( H ( X , X _ { \sigma } ) ) - H ( X ) = { \frac { 1 } { 2 } } \operatorname { E } ( d ( X , X _ { \sigma } ) ) .$$
68 Since $d$ is a metric, this shows that the adjusted entropy of $X$ is non-negative.
69 Proposition 3. We have $\Delta H ( X ) = 0$ if and only if X is constant or equal to some permutation of 70 $\{ 1 , \ldots , n \}$ . 71 Proposition 3 characterizes random variables with zero adjusted entropy. Again, this result will be 2 interpreted in terms of clustering in section 4.
# 73 3 Pairwise adjustment
74 In this section, we introduce pairwise adjusted mutual information. The definition is the same as 75 adjusted mutual information, except that the permutation $\sigma$ is now restricted to the set of pairwise 76 permutations. Specifically, we consider permutations $\sigma$ for which there exists $i , j \in \{ 1 , \ldots , n \}$ 77 such that $\sigma ( i ) \stackrel { \textstyle - } { = } j$ and $\overset { \cdot } { \boldsymbol { \sigma } ( j ) } = i$ , whereas $\sigma ( t ) = t$ for all $t \neq i , j$ . We consider the set of such 78 permutations $\sigma$ where the samples $i , j$ are drawn uniformly at random in the set $\{ 1 , \ldots , n \}$ . We 79 denote by $\sigma _ { \mathrm { p } }$ such a random permutation. Observe that $\sigma _ { \mathrm { p } }$ is the identity with probability $1 / n$ (the 80 probability that $i = j$ ).
Pairwise adjusted mutual information. We define the pairwise adjusted mutual information as:
$$\Delta _ { \mathrm { p } } I ( X , Y ) = I ( X , Y ) - \mathrm { E } ( I ( X , Y _ { \sigma _ { \mathrm { p } } } ) ) .$$
81 This is exactly the same definition as the adjusted mutual information, except for the considered 82 permutations $\sigma _ { \mathrm { p } }$ . It can be readily verified that the same properties apply, with the exact same proofs, 83 a key property being that the random permutations $\sigma _ { \mathrm { p } }$ and $\sigma _ { \mathrm { p } } ^ { \mathrm { ~ - 1 ~ } }$ have the same distributions. In 84 particular, we have the analogue of (3):
$$\begin{array} { l } { { \Delta _ { \mathrm { p } } I ( X , Y ) = \mathrm { E } ( H ( X , Y _ { \sigma _ { \mathrm { p } } } ) ) - H ( X , Y ) , } } \\ { { \ ~ = { \frac { 1 } { 2 } } ( \mathrm { E } ( d ( X , Y _ { \sigma _ { \mathrm { p } } } ) ) - d ( X , Y ) ) . } } \end{array}$$
85 Moreover, $\Delta _ { \mathrm { p } } I ( X , Y ) = 0$ whenever $X$ or $Y$ is constant or equal to some permutation of $\{ 1 , \ldots , n \}$
Pairwise adjusted entropy. We also define the pairwise adjusted entropy as:
$$\Delta _ { \mathrm { p } } H ( X ) = \Delta _ { \mathrm { p } } I ( X , X ) = H ( X ) - \mathrm { E } ( I ( X , X _ { \sigma _ { \mathrm { p } } } ) ) .$$
86 We have $\Delta _ { \mathrm { p } } H ( X ) \geq 0$ , with equality if and only if $X$ is constant or equal to some permutation of 87 $\{ 1 , \ldots , n \}$ .
# 88 4 Application to clustering
89 Let $A = \{ A _ { 1 } , \ldots , A _ { k } \}$ and $B = \{ B _ { 1 } , \ldots , B _ { l } \}$ be two partitions of some finite set $\{ 1 , \ldots , n \}$ into $k$ 90 and $l$ clusters, respectively. Let $\Omega = \{ 1 , \dots , n \}$ and $\mathrm { P }$ be the uniform probability measure over $\Omega$ . 91 Consider the random variables $X$ and $Y$ defined on $( \Omega , \mathrm { P } )$ by $X ^ { - 1 } ( i ) \doteq A _ { i }$ for all $i = 1 , \ldots , k$ and 92 $Y ^ { - 1 } ( j ) = B _ { j }$ for all $j = 1 , \dots , l .$ . Note that $X ( \omega )$ and $Y ( \omega )$ can be interpreted as the labels $i$ and $j$ 93 of sample $\omega$ in clusterings $A$ and $B$ , for each $\omega \in \{ 1 , \ldots , n \}$ . 94 We denote by $a _ { i } ~ = ~ \left| A _ { i } \right|$ the size of cluster $A _ { i }$ , by $b _ { j } ~ = ~ | B _ { j } |$ the size of cluster $B _ { j }$ , and by 95 $n _ { i j } = | A _ { i } \cap B _ { j } |$ the number of samples both in cluster $A _ { i }$ and cluster $B _ { j }$ , for all $i = 1 , \ldots , k$ and 96 $j = 1 , \dots , l$ . The matrix $( n _ { i j } ) _ { 1 \leq i \leq k , 1 \leq j \leq l }$ is known as the contingency matrix. Note that $a _ { i }$ and $b _ { j }$ 97 are the sums of row $i$ and column $j$ of the contingency matrix, respectively. 98 Adjusted mutual information. A well-known metric for assessing the similarity $s ( A , B )$ between 99 clusterings $A$ and $B$ is the adjusted mutual information 1 $\Delta I ( X , { \bar { Y } } )$ between the corresponding 100 random variables $X$ and $Y$ . In words, this is the common information shared by clusterings $A$ and $B$ 101 not due to randomness. 102 By Proposition 2, we have $s ( A , B ) = 0$ whenever clustering $A$ (or $B$ , by symmetry) is trivial, that is, 103 it consists of a single cluster or of $n$ clusters (one per sample). This is a key property, showing the 104 interest of the adjustment.
105 It is known that [Vinh et al., 2010]:
$$\begin{array} { l } { { \displaystyle s ( A , B ) = - \sum _ { i = 1 } ^ { k } \sum _ { j = 1 } ^ { l } \frac { n _ { i j } } { n } \log \frac { n _ { i j } } { n } } } \\ { { \displaystyle + \sum _ { i = 1 } ^ { k } \sum _ { j = 1 } ^ { l } \sum _ { c = ( a _ { i } + b _ { j } - n ) ^ { + } } ^ { \operatorname* { m i n } ( a _ { i } , b _ { j } ) } \frac { a _ { i } ! b _ { j } ! ( n - a _ { i } ) ! ( n - b _ { j } ) ! } { n ! c ! ( a _ { i } - c ) ! ( b _ { j } - c ) ! ( n - a _ { i } - b _ { j } + c ) ! } \frac { c } { n } \log \frac { c } { n } } , } \end{array}$$
with the notation 106 $( \cdot ) ^ { + } = \operatorname* { m a x } ( \cdot , 0 )$ . The time complexity of this formula, which is dominated by the 107 second term, is in $O ( \operatorname* { m a x } ( k , l ) n )$ [Romano et al., 2014]. In particular, it is linear in the number of 108 samples $n$ .
109 Interestingly, we can similarly assess the quantity of information $q ( A )$ contained in clustering 110 $A$ through the adjusted entropy $\Delta H ( X )$ of the corresponding random variable $X$ . This is the 111 information contained in $A$ not due to randomness. We have $q ( A ) \geq 0$ and, by Proposition 3, 112 $q ( A ) = 0$ if and only if clustering $A$ is trivial, that is, it consists of a single cluster or of $n$ clusters 113 (one per sample).
114 Since $q ( A ) = s ( A , A )$ , it follows from (6) that:
$$\mathfrak { r } ( A ) = - \sum _ { i = 1 } ^ { k } \frac { a _ { i } } { n } \log \frac { a _ { i } } { n } + \sum _ { i , j = 1 } ^ { K } \sum _ { c = ( a _ { i } + a _ { j } - n ) ^ { + } } ^ { \operatorname* { m i n } ( a _ { i } , a _ { j } ) } + \frac { a _ { i } ! a _ { j } ! ( n - a _ { i } ) ! ( n - a _ { j } ) ! } { n ! c ! ( a _ { i } - c ) ! ( a _ { j } - c ) ! ( n - a _ { i } - a _ { j } + k ) ! } \frac { c } { n } \log \frac { c } { n } .$$
115 The time complexity of this formula, also dominated by the second term, is in $O ( k n )$ . Again, this 116 complexity is linear in the number of samples $n$ . 117 Pairwise adjusted mutual information. The main contribution of the paper is the following new 118 measure of similarity $s _ { \mathrm { p } } ( A , B )$ between clusterings $A$ and $B$ , based on the pairwise adjusted mutual 119 information $\Delta _ { \mathrm { p } } I ( X , Y )$ between the corresponding random variables $X$ and $Y$ . We have an explicit 120 expression for this similarity:
121 Theorem 1. We have for any clusterings $A , B$
$$\begin{array} { c } { { s _ { \mathrm { p } } ( A , B ) = 2 \displaystyle \sum _ { i = 1 } ^ { k } \displaystyle \sum _ { j = 1 } ^ { l } \displaystyle \frac { n _ { i j } ( n - a _ { i } - b _ { j } + n _ { i j } ) } { n ^ { 2 } } \left( \displaystyle \frac { n _ { i j } } { n } \log \displaystyle \frac { n _ { i j } } { n } - \displaystyle \frac { n _ { i j } - 1 } { n } \log \displaystyle \frac { n _ { i j } - 1 } { n } \right) } } \\ { { + 2 \displaystyle \sum _ { i = 1 } ^ { k } \displaystyle \sum _ { j = 1 } ^ { l } \displaystyle \frac { ( a _ { i } - n _ { i j } ) ( b _ { j } - n _ { i j } ) } { n ^ { 2 } } \left( \displaystyle \frac { n _ { i j } } { n } \log \displaystyle \frac { n _ { i j } } { n } - \displaystyle \frac { n _ { i j } + 1 } { n } \log \displaystyle \frac { n _ { i j } + 1 } { n } \right) . } } \end{array}$$
122 The time complexity of this formula is in $O ( k l )$ , like mutual information. It is independent of the 123 number of samples $n$ , given the contingency matrix. Corollary 1 shows that the time complexity 124 reduces to $O ( m )$ , where $m$ is the number of non-zero entries of the contingency matrix, provided the 125 latter is stored in sparse format.
126 Corollary 1. We have for any clusterings $A , B$ :
$${ \begin{array} { l } { { \displaystyle { \boldsymbol { s } } _ { \mathrm { p } } ( A , B ) = 2 \sum _ { i , j : n _ { i j } > 0 } { \frac { n _ { i j } ( n - a _ { i } - b _ { j } + n _ { i j } ) } { n ^ { 2 } } } \left( { \frac { n _ { i j } } { n } } \log { \frac { n _ { i j } } { n } } - { \frac { n _ { i j } - 1 } { n } } \log { \frac { n _ { i j } - 1 } { n } } \right) } } \\ { \displaystyle \qquad + 2 \sum _ { i , j : n _ { i j } > 0 } { \frac { ( a _ { i } - n _ { i j } ) ( b _ { j } - n _ { i j } ) } { n ^ { 2 } } } \left( { \frac { n _ { i j } } { n } } \log { \frac { n _ { i j } } { n } } - { \frac { n _ { i j } + 1 } { n } } \log { \frac { n _ { i j } + 1 } { n } } + { \frac { 1 } { n } } \log { \frac { 1 } { n } } \right) } \\ { \displaystyle \qquad - 2 \left( n ^ { 2 } - \sum _ { i = 1 } ^ { k } a _ { i } ^ { 2 } - \sum _ { j = 1 } ^ { l } b _ { i } ^ { 2 } + \sum _ { i , j : n _ { i j } > 0 } n _ { i j } ^ { 2 } \right) { \frac { 1 } { n } } \log { \frac { 1 } { n } } . } \end{array} }$$
127 Similarly, we can define the quantity of information $q _ { \mathrm { p } } ( A )$ in clustering $A$ through the pairwise 128 adjusted entropy $\Delta _ { \mathrm { p } } H ( X )$ of the corresponding random variable $X$ . Again, $q _ { \mathrm { p } } ( A ) \geq 0$ , with 129 $q _ { \mathrm { p } } \overset { \cdot } { (} A ) = 0$ if and only if clustering $A$ is trivial.
$$q _ { \mathrm { p } } ( A ) = 2 \sum _ { i = 1 } ^ { k } { \frac { a _ { i } ( n - a _ { i } ) } { n ^ { 2 } } } \left( { \frac { a _ { i } } { n } } \log { \frac { a _ { i } } { n } } - { \frac { a _ { i } - 1 } { n } } \log { \frac { a _ { i } - 1 } { n } } - { \frac { 1 } { n } } \log { \frac { 1 } { n } } \right) .$$
131 Note that the time complexity of this formula in $O ( k )$ . It only depends on the number of clusters $k$ , 132 and not on the number of samples $n$ .
# 133 5 Experiments
134 In this section, we compare both notions of adjusted mutual information through experiments 135 involving synthetic and real data. The experiments are run on a computer equipped with an AMD 136 Ryzen Threadripper 1950X 16-Core Processor and 32 GB of RAM, with a a Debian $1 0 0 \mathrm { S }$ . All codes 137 and datasets used in the experiments are available in the supplementary material. 138 Synthetic data. We start with the simple case of $n = 1 0 0$ samples with clusters of even sizes, 139 consisting of consecutive samples. Specifically, we consider the set of clusterings $A ^ { ( s ) }$ , consisting of 140 clusters of size $s$ (except possibly the last one), for $s = 1 , 2 , \ldots , 1 0 0$ . In particular, both $A ^ { ( 1 ) }$ and 141 $A ^ { ( 1 0 0 ) }$ are trivial clusterings while $A ^ { ( 5 ) }$ consists of 20 clusters of size 5. 142 Figure 1 gives the similarity between clusterings $A ^ { ( 1 0 ) }$ and $A ^ { ( s ) }$ with respect to $s$ in terms of adjusted 143 mutual information, for both notions of adjustment, i.e., $s ( A ^ { ( 1 0 ) } , A ^ { ( s ) } )$ and $s _ { \mathrm { p } } ( A ^ { ( 1 0 ) } , A ^ { ( s ) } )$ . We 144 observe very close behaviors, suggesting that both notions of adjustment tend to capture the same 145 patterns in the clusterings. Note that the maximum similarity is attained for $s = 1 0$ in both cases, as 146 expected. The similarity is equal to 0 for $s \in \{ 1 , 1 0 0 \}$ for both cases, in agreement with Proposition 147 2. We also observe local peaks at $s = 2 0 , 3 0 , \ldots , 9 0$ , which can be interpreted by the fact that 148 clustering $A ^ { ( 1 0 ) }$ is a refinement of clustering $A ^ { ( s ) }$ for these values of $s$ ; similarly, the local peak at 149 $s = 5$ may be interpreted by the fact that clustering $A ^ { ( 5 ) }$ is a refinement of clustering $A ^ { ( 1 \bar { 0 } ) }$ . The Spearman correlation between both metrics over all values of $s$ is equal to 0.99. 151 We now consider random clusterings. Specifically, we assign $n$ samples to $k$ clusters independently 152 at random, according to some probability distribution $p = ( p _ { 1 } , \dotsc , p _ { k } )$ , which is itself drawn at 153 random2. Consider three such random clusterings $A , B$ , $C$ (with the same parameters $n$ and $k$ , but 154 different probability distributions $p$ ). We would like to know whether $A$ is “closer" to $B$ or to $C$ . In 155 particular, we are interested in testing whether both notions of adjusted mutual information give the 156 same ordering in the sense that:
 Figure 1: Comparison of metrics on synthetic data $\mathit { n } = 1 0 0 $ ).
$$( s ( A , B ) - s ( A , C ) ) ( s _ { \mathrm { p } } ( A , B ) - s _ { \mathrm { p } } ( A , C ) ) \geq 0 .$$
157 We compute the average precision score (fraction of triplets $A , B , C$ for which (7) is true) over 1 000 158 independent samples of $A , B , C$ , for different values of $n$ and $k$ . We repeat the experiment 100 times 159 to get the mean and standard deviation. The results are given in Table 1. We observe a very high 160 precision score, always higher than $9 3 \%$ , showing that both notions of adjusted mutual information 161 tend to give the same ordering of these random clusterings. 162 For the performance gain, we compare the computation times of both versions of adjusted mutual 163 information for the similarity between clusterings $A$ and $B$ , where $A$ consists of $k = 1 0$ clusters 164 of same size and $B$ is a random clustering, drawn as in the previous experiment. Both versions of 165 adjusted mutual information are coded in Python, with the standard version imported from scikit-learn. 166 Figure 2 shows the computation time when the number of samples $n$ grows from $1 0 ^ { 2 }$ to $1 0 ^ { 7 }$ . The 167 performance gain brought by pairwise adjustement is significant. In particular, the computation time 168 becomes independent of the number of samples.
<table><tr><td>n</td><td>k</td><td>Precision score</td></tr><tr><td>100 100</td><td>2 5</td><td>0.972 ± 0.004 0.952 ± 0.007</td></tr><tr><td>100</td><td>10</td><td>0.943 ± 0.006</td></tr><tr><td>100</td><td>20</td><td>0.955 ± 0.008</td></tr><tr><td>500</td><td>20</td><td>0.936 ± 0.007</td></tr><tr><td>1000 1000</td><td>20 50</td><td>0.933 ± 0.006</td></tr></table>
 Table 1: Precision score (mean $\pm$ standard deviation) Figure 2: Computation time with respect to $n$ (mean $\pm$ standard deviation).
Real data. We first consider the 79 datasets of the benchmark suite [Gagolewski,169 $2 0 2 0 ] ^ { 3 }$ . We apply 170 to each dataset each of the following clustering algorithms:
• $k$ -means • Affinity propagation • Mean shift • Spectral clustering • Ward • Agglomerative clustering • DBSCAN • OPTICS • Birch • Gaussian Mixture
181 We use the scikit-learn4 implementation of these algorithms, with the corresponding default param 182 eters5. We get 10 clusterings per dataset. The quality of each clustering is assessed through the 183 similarity with the available ground-truth labels, using adjusted mutual information with either full 184 adjustment or pairwise adjustment. We then compute the Spearman correlation of the corresponding 185 similarities, a value of 1 meaning the exact same ordering of the 10 clusterings with full adjustment 186 and pairwise adjustment. The results are shown in Figure 3, together with the speed-up in computation 187 time due to pairwise adjustment. In both cases, the 79 datasets are ordered by the number of samples, 188 ranging from 105 to 105 600 [Gagolewski, 2020]. 189 We first observe that the correlation is very high, suggesting again that both notions of adjusted mutual 190 information tend to provide the same results. For 65 datasets among 79, the Spearman correlation is 191 higher than $9 5 \%$ . As for the computation time, we observe a significant performance gain, by one 192 order of magnitude for the largest datasets. 193 We have conducted the same experiments with OpenML [Vanschoren et al., 2013]6. We selected all 194 datasets with at least 1,000 but no more than 50,000 samples, at most 100 features (all numerical), no 195 missing data and ground-truth labels forming clusters of at least 5 samples on average. The results 196 are shown in Figure for the resulting 34 datasets. Again, the datasets are ordered by the number of 197 samples, here ranging from 1,188 to 45,918. The conclusions are similar. In particular, the Spearman 198 correlation is higher than $9 5 \%$ for 30 datasets among 34, and the performance gain exceeds 25 for the 199 largest datasets.
 Figure 3: Comparison of metrics on the Gagolewski benchmark.
 Figure 4: Comparison of metrics on OpenML datasets.
We have proposed another way of adjusting mutual information against chance, through pairwise label permutations. The novel metric, whose explicit expression is given in Theorem 1, has a much lower complexity than the usual adjusted mutual information. Interestingly, both metrics can also be used to assess the quantity of information contained in a clustering, which the common property of being equal to 0 if and only if the clustering is trivial, as stated in Proposition 3; again, the pairwise adjusted entropy, given in Corollary 2, has a much lower complexity. Experiments on synthetic and real data show that pairwise adjusted mutual information tends to provide the same results as the usual adjusted mutual information for comparing clusterings, while involving much less computations.
For future work, we plan to extend this idea to other similarity metrics. While the practical interest is less obvious for the Adjusted Rand Index [Hubert and Arabie, 1985], due to the fact that the time complexity of this metric is already independent of the number of samples, it would be worth considering other versions of information theoretic measures, as those studied in [Romano et al., 2016].
# References
Thomas M Cover and Joy A Thomas. Elements of Information Theory. Wiley, 1991.
Marek Gagolewski. Benchmark suite for clustering algorithms – version 1, 2020.
Lawrence Hubert and Phipps Arabie. Comparing partitions. Journal of classification, 2(1):193–218, 1985.
Marina Meila. Comparing clusterings by the variation of information. In ˘ Learning theory and kernel machines, pages 173–187. Springer, 2003.
Xuan Vinh Nguyen, Julien Epps, and James Bailey. Information theoretic measures for clusterings comparison: is a correction for chance necessary? In ICML, 2009.
Simone Romano, James Bailey, Vinh Nguyen, and Karin Verspoor. Standardized mutual information for clustering comparisons: one step further in adjustment for chance. In International Conference on Machine Learning, pages 1143–1151, 2014.
Simone Romano, Nguyen Xuan Vinh, James Bailey, and Karin Verspoor. Adjusting for chance clustering comparison measures. The Journal of Machine Learning Research, 17(1):4635–4666, 2016.
Abdel Aziz Taha and Allan Hanbury. Metrics for evaluating 3d medical image segmentation: analysis, selection, and tool. BMC medical imaging, 15(1):29, 2015.
Bertrand Thirion, Gaël Varoquaux, Elvis Dohmatob, and Jean-Baptiste Poline. Which fmri clustering gives good brain parcellations? Frontiers in neuroscience, 8:167, 2014.
Joaquin Vanschoren, Jan N. van Rijn, Bernd Bischl, and Luis Torgo. Openml: Networked science in machine learning. SIGKDD Explorations, 15(2):49–60, 2013.
Nguyen Xuan Vinh, Julien Epps, and James Bailey. Information theoretic measures for clusterings comparison: Variants, properties, normalization and correction for chance. The Journal of Machine Learning Research, 11:2837–2854, 2010.
Bo Wang, Junjie Zhu, Emma Pierson, Daniele Ramazzotti, and Serafim Batzoglou. Visualization and analysis of single-cell rna-seq data by kernel-based similarity learning. Nature methods, 14(4):414–416, 2017.
Zhao Yang, René Algesheimer, and Claudio J Tessone. A comparative analysis of community detection algorithms on artificial networks. Scientific reports, 6:30750, 2016.
Jiajie Zhang, Paschalia Kapli, Pavlos Pavlidis, and Alexandros Stamatakis. A general species delimitation method with applications to phylogenetic placements. Bioinformatics, 29(22):2869– 2876, 2013.
1. For all authors...
(a) Do the main claims made in the abstract and introduction accurately reflect the paper’s contributions and scope? [Yes] A variant of adjusted mutual information. (b) Did you describe the limitations of your work? [Yes] Pairwise adjustement only applied to mutual information in the present work, see Section 6. (c) Did you discuss any potential negative societal impacts of your work? [N/A] (d) Have you read the ethics review guidelines and ensured that your paper conforms to them? [Yes]
2. If you are including theoretical results...
(a) Did you state the full set of assumptions of all theoretical results? [Yes] No specific assumption is required. Theorem 1, Corollary 2 and 3 give explicit expressions using notations defined at the beginning of Section 4. (b) Did you include complete proofs of all theoretical results? [Yes] See the supplementary material.
3. If you ran experiments...
(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 the Jupyter notebooks in the supplementary material. (b) Did you specify all the training details (e.g., data splits, hyperparameters, how they were chosen)? [N/A] This is a metric for unsupervised learning. No data split required, no hyperparameter. (c) Did you report error bars (e.g., with respect to the random seed after running experiments multiple times)? [Yes] See Table 1 and Figure 2 (not applicable to other experiments). (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 the running times provided in the Figures; the resources used are detailed at the beginning of section 5.
4. If you are using existing assets (e.g., code, data, models) or curating/releasing new assets...
(a) If your work uses existing assets, did you cite the creators? [Yes] See the references for the datasets. (b) Did you mention the license of the assets? [N/A] (c) Did you include any new assets either in the supplemental material or as a URL? [N/A] (d) Did you discuss whether and how consent was obtained from people whose data you’re using/curating? [N/A] (e) Did you discuss whether the data you are using/curating contains personally identifiable information or offensive content? [N/A]
5. If you used crowdsourcing or conducted research with human subjects...
(a) Did you include the full text of instructions given to participants and screenshots, if applicable? [N/A] (b) Did you describe any potential participant risks, with links to Institutional Review Board (IRB) approvals, if applicable? [N/A] (c) Did you include the estimated hourly wage paid to participants and the total amount spent on participant compensation? [N/A]123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257# Be Confident! Towards Trustworthy Graph Neural Networks via Confidence Calibration
Xiao Wang, Hongrui Liu, Chuan Shi∗, Cheng Yang
School of Computer Science (National Pilot Software Engineering School) Beijing University of Posts and Telecommunications Beijing, China {xiaowang, liuhongrui, shichuan, yangcheng}@bupt.edu.cn
# Abstract
Despite Graph Neural Networks (GNNs) have achieved remarkable accuracy, whether the results are trustworthy is still unexplored. Previous studies suggest that many modern neural networks are over-confident on the predictions, however, surprisingly, we discover that GNNs are primarily in the opposite direction, i.e., GNNs are under-confident. Therefore, the confidence calibration for GNNs is highly desired. In this paper, we propose a novel trustworthy GNN model by designing a topology-aware post-hoc calibration function. Specifically, we first verify that the confidence distribution in a graph has homophily property, and this finding inspires us to design a calibration GNN model (CaGCN) to learn the calibration function. CaGCN is able to obtain a unique transformation from logits of GNNs to the calibrated confidence for each node, meanwhile, such transformation is able to preserve the order between classes, satisfying the accuracypreserving property. Moreover, we apply the calibration GNN to self-training framework, showing that more trustworthy pseudo labels can be obtained with the calibrated confidence and further improve the performance. Extensive experiments demonstrate the effectiveness of our proposed model in terms of both calibration and accuracy.
# 1 Introduction
Graphs are ubiquitous in the real world, including social networks, e-commerce networks, traffic networks, and so on. Recently, Graph Neural Networks (GNNs), which are able to effectively learn the node representations based on the message-passing manner, have attracted considerable attention in dealing with graph data [16, 33, 39, 44, 15, 2, 34]. To date, GNNs have been applied to various applications and achieved remarkable accuracy, e.g., node classification [16, 33], link prediction [41] and graph classification [9].
However, it is well established that a model with good accuracy is not the only goal, but a trustworthy model is highly desired in many applications, especially in safety-critical fields [1]. Usually, a trustworthy model implies that it should know when it is likely to be incorrect, in other words, the probability, i.e., the confidence, associated with the predicted class label should reflect its ground truth correctness likelihood [12]. For example, in the scene of autonomous driving, the system will adopt the prediction given by the model only when the model has high confidence for its prediction. Otherwise, the decision-making power will be returned to the driver or the system adopts other safer strategies. Recently, the confidence calibration has attracted considerable attention in deep learning [12, 40, 19], which reveals that many modern neural network models are over-confident on the predictions, i.e., the prediction accuracy is lower than its confidence. However, it has not been studied in GNNs on the semi-supervised scenario, which gives rise to one fundamental question: will the current GNNs follow the same over-confident property as other neural networks? A well-informed answer can help us better understand GNNs and enable GNNs to be applied to various areas in a more reliable manner.
As the first contribution of this study, we present experiments assessing the relationship between the confidence and the accuracy of Graph Convolutional Networks (GCNs) [16] and Graph Attention Networks (GAT) [33] in the node classification task (more details can be seen in Section 2), respectively. Surprisingly, we discover that existing GNNs are far distant from being well-calibrated, and more importantly, GNNs tend to be under-confident in their predictions, which is very different from other modern deep learning models that are often over-confident [12, 19]. GNNs being under-confident means that many predictions are distributed in the low-confidence range, and therefore, fewer predictions are available for safety-critical applications. Once the weakness is identified, another natural question is: how can we calibrate the confidence on predictions given by GNNs so as to make them more trustworthy?
Essentially, the confidence calibration is to calibrate the outputs (also known logits) of original models (e.g., GNNs), therefore, a straightforward manner is to employ temperature scaling (TS) [12], OP-families [25] to learn calibration function using a held-out dataset in a post-hoc way. However, when being applied to graphs, they all ignore the effect of topology, which will inevitably make mistakes during calibration. For example, considering that the logits of two nodes $a$ and $^ b$ are the same, but node $a$ is similar to its neighbors while node $b$ is not. Apparently, the predictions of GCNs for $a$ should be more confident than $^ b$ , while the traditional calibration methods, e.g., TS, will learn the same confidence for $a$ and $^ b$ , because it does not consider the effect of topology.
Moreover, most of them explore calibration functions only in the linear space [12, 18] while it is well known that non-linear space contains more complex function transformation which is able to calibrate networks with complicated landscapes well. Even if some works have explored the non-linear space such as Matrix Scaling [12], they generally degrade the classification accuracy of the original classifier, while a good accuracy is still a basic requirement by many applications.
In this paper, we introduce a topology-aware post-hoc calibration method for GNNs. Specifically, for the logits given by the original classification GNNs, we employ another calibration GCN (CaGCN) to propagate confidence, naturally enabling that the confidence of topologically adjacent nodes becomes similar. CaGCN learns a unique temperature $t$ for each node for temperature scaling, thus preserving the accuracy of the original classification GCN. In addition, based on our finding that large numbers of high-accuracy predictions are distributed in the low-confidence range, we design a calibrated self-training model CaGCN-st in which the confidence is firstly calibrated then used to generate pseudo labels with high confidence. The contributions of this paper are three-fold:
• We study the trustworthy problem of GNNs, and discover one unique characteristic of GNNs, i.e., the predictions made by GNNs are usually under-confident. • We propose a novel trustworthy GNN model based on the confidence calibration. Our proposed calibration function has three features: topology-aware, non-linear, and accuracy-preserving. We further design a calibrated self-training GNN model, which can effectively utilize the predictions with high confidence. • Extensive experiments demonstrate the effectiveness of our proposed models in terms of both calibration and accuracy.
# 2 Notation and Preliminary Study
In this paper, we focus on the calibration of semi-supervised node classification in an undirected attributed graph $G = \left( V , E \right)$ with the adjacent matrix $\mathbf { A } \in \mathbb { R } ^ { N \times N }$ and the node feature matrix $\mathbf { X } =$ $[ \mathbf { x } _ { 1 } , \ldots , \mathbf { x } _ { N } ] ^ { \mathsf { T } }$ . $V$ is a set of nodes and $E \subseteq V \times V$ is a set of edges between nodes. $N = | V |$ is the number of nodes. Here we give the definition of perfect calibration of GNNs as follows:
Definition 1. Given random variables A, $\mathbf { X }$ , $\mathbf { Y } \subseteq \{ 1 , \ldots , K \}$ and a GNN model $f _ { \theta }$ where $\theta$ is the learnable parameters, for node i with label $y _ { i } \in \mathbf { Y }$ , $\mathbf { z } _ { i } = f _ { \theta } ( \mathbf { x } _ { i } , \mathbf { A } ) = [ z _ { i , 1 } , \ldots , z _ { i , K } ] ^ { \mathsf { T } }$ is the output of GNNs (i.e., the prediction probability), and $\hat { y } _ { i } = \mathrm { a r g } \operatorname* { m a x } _ { k } z _ { i , k }$ and $\hat { p } _ { i } = \operatorname* { m a x } _ { k } z _ { i , k }$ are the prediction and the confidence respectively. Then we define $f _ { \theta }$ to be perfectly calibrated as:
$$\mathbb { P } ( \hat { y } _ { i } = y _ { i } | \hat { p } _ { i } = p ) = p , \forall p \in [ 0 , 1 ] .$$
 Figure 1: Reliability diagrams for GCN (top) and GAT (bottom) without confidence calibration. The diagram is expected to plot an identity function of accuracy with respect to confidence. Any deviation from a perfectly diagonal (i.e., the difference between blue and red histogram) represents the miscalibration.
 Figure 2: Confidence distribution before calibration.
According to Definition 1, GNN is perfectly calibrated only when the confidence $\hat { p } _ { i }$ is exactly equal to the true probability of getting a correct prediction for every node.
Next, we take two representative GNNs (GCN [16] and GAT [33]) as examples to analyze whether they are perfectly calibrated. Specifically, we apply GCN and GAT to four widely used datasets Cora [29], Citeseer [29], Pubmed [29], CoraFull [3], and examine whether their results satisfy Definition 1. To provide more results, we select three label rates for training set (i.e., 20, 40, 60 labeled nodes per class). All the experimental settings follow [16, 33]. Since the true probability $p$ cannot be exactly known, we take an approximate way to evaluate the calibration as in [12]. In particular, we first partition the [0,1] range of confidence into 20 equal bins and then we group the nodes into corresponding bins according to their confidence. After that we calculate the average accuracy of each bin. We expect the average accuracy is equal to the average confidence of each bin, which means the model is approximately perfectly calibrated. For example, if the average confidence of nodes in the bin [0.95, 1.0] is 0.96, and then the classification accuracy in this bin should be $96 \%$ .
We illustrate the results of label rate being 20 in Fig. 1 using Reliability Diagrams [23] here, where the $\mathbf { X }$ -axis is the confidence in 20 bins of equal size and y-axis is the average accuracy in each bin. The blue represents the classification accuracy of GCN and GAT while the red is our expectation. More results of label rate being 40, 60 and other GNN models can be seen in Fig. 8, Fig. 9, Fig. 12, Fig. 13 and Fig. 14 in the appendix. We can see that in all the datasets, the average accuracy of most bins is higher than the average confidence. In other words, these GNNs actually achieve remarkable performance, but they all output low confidence, i.e., the GNNs are usually under-confident. Please note that this phenomenon of GNNs is very different from other modern neural networks, which are generally known to be over-confident [12, 19]. Moreover, as shown in Fig. 2, we also visualize the confidence distribution of test nodes, where the $\mathbf { X }$ -axis is the confidence and y-axis is the density [28]. The histogram height multiplied by the width is equal to the frequency. The blue represents the confidence distribution of correct predictions while the yellow represents that of incorrect predictions. More results of label rate being 40 and 60 can be seen in Fig. 10 and Fig. 11 in the appendix. We can see that a large quantity of correct predictions are distributed in the low confidence range. The results above indicate that the current GNNs are far from perfect calibration, leading to unreliable confidence.
# 3 Confidence Calibration on GCNs
In this section, we propose our method to calibrate current GNNs. Given $\mathbf { A }$ and $\mathbf { X }$ , for a $l$ -layer GCN [16], the output of the GCN before the softmax layer can be obtained by:
$$\begin{array} { r } { \mathbf { V } = \mathbf { A } \sigma ( \cdots \mathbf { A } \sigma ( \mathbf { A X W } ^ { ( 1 ) } ) \mathbf { W } ^ { ( 2 ) } \cdots ) \mathbf { W } ^ { ( l ) } = [ \mathbf { v } _ { 1 } , \cdots , \mathbf { v } _ { N } ] ^ { \mathsf { T } } , } \end{array}$$
where $\mathbf { W } ^ { ( l ) }$ is the weight matrix of $l$ -th layer in GCN and $\sigma ( \cdot )$ is the activation function. For each node $i \in \{ 1 , \cdots , N \}$ , our goal is to learn a calibration function which is fed with $\mathbf { v } _ { i }$ (often known as the logit of node $i$ ) and outputs a calibrated confidence using a held-out dataset in a post-hoc way. The calibration function should satisfy three points below: (1) taking the network topology into account (2) non-linear (3) preserving the classification accuracy of the GCNs.
# 3.1 CaGCN: GCNs as Calibration Function
 Figure 3: The illustration of the confidence propagation. Different colors indicate different classes.
Table 1: Summary of total variation of confidence before and after calibration (Bold: best). Uncal. is short for uncalibrated and TS is short for temperature scaling.
<table><tr><td rowspan="2">Dataset</td><td colspan="3">GCN</td></tr><tr><td>Uncal.</td><td>TS</td><td>Ours</td></tr><tr><td>Cora</td><td>240.267</td><td>172.346</td><td>164.651</td></tr><tr><td>Citeseer</td><td>128.145</td><td>112.212</td><td>108.684</td></tr><tr><td>Pubmed</td><td>1299.33</td><td>1266.68</td><td>1113.41</td></tr><tr><td>CoraFull</td><td>6014.32</td><td>4698.20</td><td>4500.30</td></tr></table>
We assume that the ground-truth confidence distribution in a graph has homophily property, i.e., the confidence of neighboured nodes given by well-calibrated models should be similar, and thus we conduct an experiment to verify this. We employ the classic temperature scaling method [12] as our calibration function and use the total variation [27] of confidence as our evaluation, which sums the difference of confidence between all the neighboured nodes. We compare the total variation of confidence before and after confidence calibration, where the results are shown in Table 1. We can find that the total variation of confidence does decrease after temperature scaling, which verifies our assumption. This inspires us that if a GCN model is well-calibrated, then the confidence between neighbors should be more similar than before.
To this end, we find that GCN itself can play the role of calibration function that meets above requirement since GCN is able to propagate node features along the network topology and smooth similar information between neighboured nodes. Therefore, we can employ another $l .$ -layer GCN (CaGCN) as our calibration function to propagate the confidence along the network topology. Specifically, given the output $\mathbf { V }$ of the classification GCN, the logit $\mathbf { v } _ { i } ^ { \prime }$ and confidence $\hat { p } _ { i }$ for node $i$ after calibration can be obtained by:
$$\begin{array} { r l } & { { \mathbf { V } } ^ { \prime } = { \mathbf { A } } \sigma ( \cdots { \mathbf { A } } \sigma ( { \mathbf { A } } { \mathbf { V } } { \mathbf { W } } ^ { ( 1 ) } ) { \mathbf { W } } ^ { ( 2 ) } \cdots ) { \mathbf { W } } ^ { ( l ) } = [ { \mathbf { v } } ^ { \prime } _ { 1 } , \cdots , { \mathbf { v } } ^ { \prime } _ { N } ] ^ { \mathsf { T } } , } \\ & { { \mathbf { z } } _ { i } = [ \sigma _ { S M } ( \nu ^ { \prime } _ { i , 1 } ) , \cdots , \sigma _ { S M } ( \nu ^ { \prime } _ { i , K } ) ] ^ { \mathsf { T } } , \hat { p } _ { i } = \operatorname* { m a x } z _ { i , k } , } \end{array}$$
where $\begin{array} { r } { \sigma _ { S M } ( \nu ^ { \prime } _ { i , \cdot } ) = \frac { \exp ( \nu ^ { \prime } _ { i , \cdot } ) } { \sum _ { j = 1 } ^ { K } \exp ( \nu ^ { \prime } _ { i , j } ) } } \end{array}$ is the softmax operation. Then the total variation of confidence will surely become lower and the original classification GCN will be calibrated. Please note that although temperature scaling can be directly applied here, compared with GCN, it does not take the network topology into account, which may cause mistakes mentioned in Section 1. Moreover, temperature scaling only employs a linear transformation, and GCN is able to learn a non-linear calibration function.
For a comprehensive understanding of confidence propagation, we make a detailed and visible illustration here. As shown in Fig. 3, the logits of two nodes $a$ and $^ b$ are the same, but node $a$ is similar to its neighbors while node $b$ is not. Apparently, the predictions of GCNs for $a$ should be more confident than $b$ . Suppose that $a$ , $b$ and their neighbours are under-confident based on the observation above. If we continue to propagate their logits along the topology using another GCN, the logits of $a$ and its neighbors will tend to be the same. Therefore, if one or more of these nodes are calibrated during the calibration process, all of them will be calibrated as well. The confidence is propagated in this way. On the other hand, looking at another node $b$ , it is as difficult even for manual classification as it is for GCNs. Consequently, the confidence of $b$ should stay still even be lower. However, it will become higher because of the influence from $a$ if we use the traditional calibration method without considering the network topology. Instead, when the network topology is taken into account, the logit of $^ b$ will be averaged by its neighboured and each dimension tends to $1 / K$ . It will be correctly calibrated when other nodes in the same situation are well-calibrated.
# 3.2 The Accuracy-Preserving Property
Until now, we have proposed a non-linear calibration model CaGCN which can take the network topology into account, but the accuracy-preserving property cannot be satisfied. To address this problem, we firstly study the general accuracy-preserving calibration function.
Proposition 1. Let $h : \mathbb { R } ^ { K } \to \mathbb { R } ^ { K }$ be a calibration function, $s : \mathbb { R } \to \mathbb { R }$ be a 1-D function and $\mathbf { v } _ { i } = [ \nu _ { i , 1 } , \cdots , \nu _ { i , K } ] ^ { \mathsf { T } }$ be the logit of node i. The calibration function $h$ preserves the classification accuracy of the original model if s is a strictly isotonic function and $h$ satisfies:
$$\begin{array} { r } { h ( \mathbf { v } _ { i } ) = [ s ( \nu _ { i , 1 } ) , \dots , s ( \nu _ { i , K } ) ] ^ { \mathsf { T } } , \forall i \in \{ 1 , \cdots , N \} . } \end{array}$$
Proof We set $\nu _ { i , 1 } < \nu _ { i , 2 } < \cdots < \nu _ { i , K }$ without loss of generality. Since $[ s ( \nu _ { i , 1 } ) , \ldots , s ( \nu _ { i , K } ) ] ^ { \mathsf { T } }$ shares the same order with $\mathbf { v } _ { i }$ as a result of the strictly isotonicity of $s$ , the order between classes of the logit $\mathbf { v } _ { i }$ is unchanged, hence the accuracy of the prediction is preserved.
Temperature scaling [12] is the simplest accuracy-preserving calibration method using a scalar parameter $t$ called temperature for all classes. Given the logit $\mathbf { v } _ { i }$ of node $i .$ , the confidence of the prediction is $\hat { p } _ { i } = \operatorname* { m a x } _ { k } \sigma _ { S M } ( \nu _ { i , k } / t ) ( t > 0 )$ . In temperature scaling, $h ( { \bf v } _ { i } ) = [ \nu _ { i , 1 } / t , \cdot \cdot \cdot , \nu _ { i , K } / t ] ^ { \top }$ is the calibration function and $s ( x ) = x / t$ is the strictly isotonic function.
However, we can find that temperature scaling (TS) [40] only performs the same linear transformation for all the nodes using the same $t$ . As mentioned in Eq. 3, we propose to use CaGCN as our calibration function, while CaGCN is generally not isotonic, i.e., the order between classes of $\mathbf { v } _ { i }$ and $\mathbf { v } _ { i } ^ { \prime }$ is not the same, implying that after calibration by CaGCN, the accuracy of original GCN cannot be preserved. Instead, here we propose an improved CaGCN. Given the output $\mathbf { V }$ of the classification GCN, we firstly use a $l$ -layer GCN to learn a unique temperature $t _ { i }$ for each node $i .$ , then get a calibrated logit $\mathbf { v } _ { i } ^ { \prime }$ by transforming its original logit $\mathbf { v } _ { i }$ using $t _ { i }$ in a temperature-scaling way, and finally obtain calibrated confidence $\hat { p } _ { i }$ as follows:
$$\begin{array} { r } { \mathbf { t } = \sigma ^ { + } ( \mathbf { A } \sigma ( \cdot \cdot \cdot \mathbf { A } \sigma ( \mathbf { A } \mathbf { V } \mathbf { W } ^ { ( 1 ) } ) \mathbf { W } ^ { ( 2 ) } \cdot \cdot \cdot ) \mathbf { W } ^ { ( l ) } ) = [ t _ { 1 } , \cdots , t _ { N } ] ^ { \top } ( t _ { i } > 0 , \forall i \in \{ 1 , \cdots , N \} ) , } \\ { \mathbf { v } _ { i } ^ { r } = h ( \mathbf { v } _ { i } , t _ { i } ) = [ \nu _ { i , 1 } / t _ { i } , \cdots , \nu _ { i , K } / t _ { i } ] ^ { \top } , \mathbf { z } _ { i } = [ \sigma _ { S M } ( \nu _ { i , 1 } ^ { \prime } ) , \cdots , \sigma _ { S M } ( \nu _ { i , K } ^ { \prime } ) ] ^ { \top } , \hat { p } _ { i } = \operatorname* { m a x } _ { { \boldsymbol { k } } } z _ { i , { \boldsymbol { k } } } , } \end{array}$$
where $t _ { i } \in \mathbb { R }$ is a scalar greater than zero and $\sigma ^ { + } ( \mathbf { x } ) = l o g ( 1 + e x p ( \mathbf { x } ) )$ is an element-wise softplus activation [8]. The model proposed in Eq. 5 does not change the order between classes of $\mathbf { v } _ { i }$ and $\mathbf { v } _ { i } ^ { \prime }$ , implying that the accuracy of original GCN is preserved. Compared Eq. 5 with Eq. 3, we can find that Eq. 5 makes the same transformation on all the dimensions of $\mathbf { v } _ { i }$ , which will limit the learnable calibration function space. However, we will prove that actually Eq. 5 is the same with the model proposed in Eq. 3 on confidence calibration using the Proposition 2. Considering that for any logit $\mathbf { v } _ { i }$ , our expectation is in fact that the calibration model can output any confidence $\hat { p } _ { i } \in \big ( \frac { 1 } { K } , 1 \big )$ . Please note that $\hat { p } _ { i } \geq \frac { 1 } { K }$ , or the prediction will be changed. Since Eq. 3 has no limitation on the learnt calibration model, its output $\hat { p } _ { i }$ can take any value from $\frac { 1 } { K }$ to 1. Therefore, if we can prove the output $\hat { p } _ { i }$ in Eq. 5 can also traverse the interval $\textstyle { \big ( } { \frac { 1 } { K } } , 1 { \big ) }$ for any $\mathbf { v } _ { i }$ , the equality between Eq. 3 and Eq.5 can be proved.
Proposition 2. Given the original logit $\mathbf { v } _ { i } = [ \nu _ { i , 1 } , \cdots , \nu _ { i , K } ] ^ { \mathsf { T } }$ of node $i ,$ assume $\nu _ { i , j }$ not approaching infinity for each $j \in \{ 1 , \cdots , K \}$ . The calibrated confidence $\hat { p } _ { i }$ in Eq. $5$ can traverse the interval $\textstyle { \big ( } { \frac { 1 } { K } } , 1 { \big ) }$ for node i.
Proof We set $\nu _ { i , 1 } > \nu _ { i , 2 } > \cdots > \nu _ { i , K }$ without loss of generality. For any $\mathbf { v } _ { i } \in \mathbb { R } ^ { K }$ , with the assumption of $\mathbf { v } _ { i }$ not approaching infinity, we have that
$$\operatorname* { l i m } _ { t \to 0 } \hat { p } _ { i } = \operatorname* { l i m } _ { t \to 0 } \frac { e x p ( \nu _ { i , 1 } / t _ { i } ) } { \sum _ { j = 1 } ^ { K } e x p ( \nu _ { i , j } / t _ { i } ) } = \operatorname* { l i m } _ { t \to 0 } \frac { e x p ( ( \nu _ { i , 1 } - \nu _ { i , 2 } ) / t _ { i } ) } { e x p ( ( \nu _ { i , 1 } - \nu _ { i , 2 } ) / t _ { i } ) + \sum _ { j = 2 } ^ { K } e x p ( ( \nu _ { i , j } - \nu _ { i , 2 } ) / t _ { i } ) } = 1$$
and
$$\operatorname* { l i m } _ { t \to + \infty } \hat { p } _ { i } = \operatorname* { l i m } _ { t \to + \infty } \frac { e x p ( \nu _ { i , 1 } / t _ { i } ) } { \sum _ { j = 1 } ^ { K } e x p ( \nu _ { i , j } / t _ { i } ) } = \frac { 1 } { K } .$$
Obviously, both $\sigma _ { S M } ( \nu _ { i , k } )$ and $\mathbf { v } _ { i } / t _ { i }$ are continuous, thus $\sigma _ { S M } ( \nu _ { i , k } / t _ { i } )$ is continuous. Therefore, $\begin{array} { r } { \hat { p } _ { i } = \operatorname* { m a x } _ { k } z _ { i , k } = \operatorname* { m a x } _ { k } \sigma _ { S M } ( \nu _ { i , k } / t _ { i } ) } \end{array}$ can traverse the interval $( 1 / K , 1 )$ .
The assumption about $\mathbf { v } _ { i }$ is easy to be satisfied since the L2-norm in GCN drives the weight matrix $\mathbf { W }$ approaching zero matrix and each element in node feature matrix $\mathbf { X }$ is not infinity. Therefore, based on Eq. 2, each element $\nu _ { i , j }$ in $\mathbf { V }$ cannot approach infinity. From Proposition 2 we know that for any $\mathbf { v } _ { i }$ , there exactly exists such a unique temperature $t _ { i }$ that $\hat { p } _ { i }$ can take any value from $1 / K$ to 1. In other words, the model can be perfectly calibrated.
# 3.3 Optimization Objective
Since NLL loss [10] can be decomposed into calibration loss and refinement loss [21], minimizing NLL loss benefits for confidence calibration. Therefore, we employ the NLL loss as our objective function with an additional regularization term. We use the prediction probability $\mathbf { z } _ { i } \in \mathbb { R } ^ { K }$ in Eq. 5 to calculate the NLL loss. Denote the $K$ -class one-hot label for node $i$ as $\mathbf y _ { i } = [ y _ { i , 1 } , \cdots , y _ { i , K } ] ^ { \intercal }$ and suppose the size of the validation set is $| D _ { \nu a l } |$ . Then the NLL loss over all validation nodes is represented as ${ \mathcal { L } } _ { n l l }$ where:
$$\mathcal { L } _ { n l l } = - \sum _ { i = 1 } ^ { | D _ { \nu a l } | } \sum _ { k = 1 } ^ { K } y _ { i , k } l o g ( z _ { i , k } ) .$$
Due to the under-confidence of GCNs, our goal is to increase the confidence of correct predictions while decreasing that of incorrect predictions. Considering that for incorrect predictions, the NLL loss cannot directly reduce their confidence, therefore, we design a regularization term for NLL loss as follows:
$$\mathcal { L } _ { c a l } = \frac { 1 } { n } ( \sum _ { i = 1 } ^ { | c o r | } 1 - z _ { i , m } ^ { ( c o r ) } + z _ { i , s } ^ { ( c o r ) } + \sum _ { i = 1 } ^ { | i n c | } z _ { i , m } ^ { ( i n c ) } - z _ { i , s } ^ { ( i n c ) } ) ,$$
where $\left| c o r \right|$ and $| i n c |$ are the number of nodes correctly and incorrectly predicted and $z _ { i , m }$ and $z _ { i , s }$ are the max and submax prediction probability. Intuitively, the confidence of incorrect predictions is decreased by reducing the gap between the max and the submax value of $\mathbf { z } _ { i }$ and vice versa. Combining ${ \mathcal { L } } _ { n l l }$ and $\mathcal { L } _ { c a l }$ , we have the following overall objective function:
$$\begin{array} { r } { \mathcal { L } = \mathcal { L } _ { n l l } + \lambda \mathcal { L } _ { c a l } , } \end{array}$$
where $\lambda$ is the parameter of the regularization term. With the guide of labeled data, we can optimize CaGCN via back propagation and learn the calibrated confidence. The overall framework of CaGCN is shown in Fig. 4.
# 4 Self-training with Confidence Calibration
Here we propose a practical application of confidence calibration to improve the performance of self-training in GCNs. Self-training is to predict the labels for unlabeled data, and then add them to the training set, so as to achieve better performance. When applying self-training to GCN, we firstly obtain the predictions $\hat { y } _ { i }$ and the confidence $\hat { p } _ { i }$ given by GCN and then add the most confident nodes to the training set with pseudo labels $\hat { y } _ { i }$ based on $\hat { p } _ { i }$ . We continue to train until convergence. However, existing self-training methods perform not as expected with higher label rates [30]. Considering the under-confidence of existing GCNs, motivated by [26], we argue that the under-performance of existing self-training methods originals from large numbers of high-accuracy predictions distributing in low-confidence intervals as shown in Fig. 2, causing that they cannot be added to the training set.
 Figure 4: The overall framework of CaGCN. Solid lines represent that we can backpropagate gradient here while dashed lines represent we cannot. We firstly train a classification GCN using the training set to obtain the logit $\mathbf { V }$ of all the nodes. Then we feed $\mathbf { V }$ to $\mathrm { C a G C N }$ to get the temperature t and transform $\mathbf { V }$ using t into $\mathbf { V } ^ { \prime }$ . Finally, the loss can be obtained using $\mathbf { V } ^ { \prime }$ after softmax according to Eq. 10 and CaGCN can be optimized with the guide of the validation set.
Table 2: ECE $\mathbf { \Gamma } ( \mathbf { M } { = } 2 0 )$ ) on different models and citation networks of various label rate (L/C) with and without calibration. Uncal. represents the uncalibrated model, (-) denotes this method cannot converge to a meaningful result and bold denotes the best result, the subscript of each result refers to the standard deviation $( \times 1 0 ^ { - 3 } )$ while the superscript refers to the results of paired t-test ( \* for 0.05 level and $^ { * * }$ for 0.01 level).
<table><tr><td rowspan="2">Dataset</td><td rowspan="2">L/C</td><td colspan="4">GCN</td><td colspan="4">GAT</td></tr><tr><td>Uncal.</td><td>TS</td><td>MS</td><td>CaGCN</td><td>Uncal.</td><td>TS</td><td>MS</td><td>CaGCN</td></tr><tr><td rowspan="3">Cora</td><td>20</td><td>0.13476.3</td><td>0.04885.5</td><td>0.04145.7</td><td>0.04016.7</td><td>0.15588.9</td><td>0.07179.8</td><td>0.05449.4</td><td>0.0450</td></tr><tr><td>40</td><td>0.11344.7</td><td>0.04177.2</td><td>0.03724.6</td><td>0.04075.4</td><td>0.13405.4</td><td>0.04857.7</td><td>0.04916.0</td><td>0.0365</td></tr><tr><td>60</td><td>0.09374.9</td><td>0.0355.4</td><td>0.03646.1</td><td>0.03764.4</td><td>0.12013.3</td><td>0.03936.1</td><td>0.04115.3</td><td>0.031332</td></tr><tr><td rowspan="3">Citeseer</td><td>20</td><td>0.12487.1</td><td>0.06418.7</td><td>0.06443.7</td><td>0.05957.2</td><td>0.15345.0</td><td>0.09168.7</td><td>0.06339.8</td><td>0.05726.8</td></tr><tr><td>40</td><td>0.09577.7</td><td>0.06014.2</td><td>0.05385.7</td><td>0.05455.5</td><td>0.12528.7</td><td>0.07973.1</td><td>0.05905.4</td><td>0.05325.4</td></tr><tr><td>60</td><td>0.08066.4</td><td>0.05595.0</td><td>0.05216.4</td><td>0.05463.4</td><td>0.10905.9</td><td>0.06487.1</td><td>0.05199.1</td><td>0.05257.6</td></tr><tr><td rowspan="3">Pubmed</td><td>20</td><td>0.05867.7</td><td>0.05413.8</td><td>0.04764.2</td><td>0.0405.0</td><td>0.08353.1</td><td>0.06564.6</td><td>0.05013.7</td><td>0.0356</td></tr><tr><td>40</td><td>0.04445.5</td><td>0.04466.3</td><td>0.04366.3</td><td>0.0402.0</td><td>0.08694.6</td><td>0.06586.5</td><td>0.05396.0</td><td>0.0308</td></tr><tr><td>60</td><td>0.04459.7</td><td>0.03676.0</td><td>0.03186.4</td><td>0.03114.8</td><td>0.09934.1</td><td>0.06696.3</td><td>0.04835.7</td><td>0.03082</td></tr><tr><td rowspan="3">CoraFull</td><td>20</td><td>0.19866.1</td><td>0.10136.1</td><td>=</td><td>0.0776</td><td>0.21193.6</td><td>0.11015.1</td><td>=</td><td>0.07880</td></tr><tr><td>40</td><td>0.23215.4</td><td>0.11176.5</td><td></td><td>0.0701</td><td>0.24384.2</td><td>0.11338.3</td><td></td><td>0.07388</td></tr><tr><td>60</td><td>0.23374.0</td><td>0.09813.8</td><td></td><td>0.0768</td><td>0.24971.8</td><td>0.11335.2</td><td></td><td>0.0849</td></tr></table>
Consequently, we design a self-training model CaGCN-st where confidence is firstly calibrated then employed to generate pseudo labels for unlabeled nodes. Specifically, given an unlabeled dataset $D _ { U }$ and a labeled dataset $D _ { L }$ which has been divided into three parts $D _ { t r a i n }$ , $D _ { \nu a l }$ and $D _ { t e s t }$ , we firstly train a classification GCN using $D _ { t r a i n }$ to get the logit of each node. Then all the logits will be fed into a CaGCN to train and we get a calibrated confidence for each node. It should be noted that instead of $D _ { \nu a l }$ , we still employ $D _ { t r a i n }$ to train our CaGCN. After that, the most confident predictions of $D _ { U }$ will be adopted as the pseudo labels according to a threshold $\tau$ and added to the label set. The $D _ { t r a i n }$ is enlarged in this way. The process above will be repeated $s$ stages until convergence. Please note that our classification GCN and CaGCN are re-initialized in each stage.
# 5 Experiments
In this section, we evaluate the performance of CaGCN on confidence calibration and CaGCN-st on self-training respectively. We choose the commonly used citation networks Cora [29], Citeseer [29], Pubmed [29] and CoraFull [3] for evaluation, and more detailed descriptions are in Appendix B.
Table 3: Node classification accuracy and the standard deviation on GCN and its self-training variants.
<table><tr><td rowspan="2">Dataset</td><td rowspan="2">L/C</td><td colspan="7">Methods</td></tr><tr><td>Orig.</td><td>St.</td><td>Ct.</td><td>Union</td><td>Inter.</td><td>TS-st</td><td>CaGCN-st</td></tr><tr><td rowspan="3">Cora</td><td>20</td><td>81.630.24</td><td>82.270.33</td><td>81.510.30</td><td>81.850.68</td><td>81.410.28</td><td>82.680.20</td><td>83.110.52</td></tr><tr><td>40</td><td>83.990.26</td><td>83.590.34</td><td>83.660.25</td><td>83.330.41</td><td>83.380.33</td><td>84.440.35</td><td>84.370.38</td></tr><tr><td>60</td><td>84.440.29</td><td>84.980.32</td><td>84.630.31</td><td>85.030.30</td><td>84.880.18</td><td>85.600.24</td><td>85.790.27</td></tr><tr><td rowspan="3">Citeseer</td><td>20</td><td>71.640.32</td><td>73.240.44</td><td>74.220.29</td><td>74.600.38</td><td>72.250.45</td><td>74.200.24</td><td>74.90040</td></tr><tr><td>40</td><td>72.250.32</td><td>74.700.33</td><td>72.120.39</td><td>74.790.36</td><td>73.660.32</td><td>75.620.19</td><td>75.480.50</td></tr><tr><td>60</td><td>73.200.35</td><td>75.080.29</td><td>73.210.36</td><td>75.530.30</td><td>75.230.23</td><td>75.870.24</td><td>76.430.20</td></tr><tr><td rowspan="3">Pubmed</td><td>20</td><td>79.570.33</td><td>80.320.18</td><td>79.670.32</td><td>81.120.29</td><td>79.590.29</td><td>80.950.18</td><td>81.16.36</td></tr><tr><td>40</td><td>80.650.39</td><td>82.200.32</td><td>81.620.40</td><td>81.840.23</td><td>80.460.55</td><td>82.280.39</td><td>83.0821</td></tr><tr><td>60</td><td>83.380.34</td><td>83.350.28</td><td>83.400.36</td><td>83.320.35</td><td>83.310.17</td><td>83.260.39</td><td>84.47023</td></tr><tr><td rowspan="3">CoraFull</td><td>20</td><td>60.450.43</td><td>60.870.28</td><td>60.120.45</td><td>60.520.35</td><td>61.010.53</td><td>61.730.41</td><td>62.190.49</td></tr><tr><td>40</td><td>65.770.37</td><td>65.830.45</td><td>64.220.35</td><td>64.330.42</td><td>65.840.37</td><td>66.110.60</td><td>66.300.31</td></tr><tr><td>60</td><td>66.520.25</td><td>66.620.30</td><td>66.640.29</td><td>66.780.29</td><td>66.820.32</td><td>66.950.45</td><td>67.600.40</td></tr></table>
# 5.1 Confidence Calibration Evaluation
Baselines. Since our CaGCN is a general calibration model for GNNs, here we choose GCN [16] and GAT [33] as our classification models. For comparison, we choose the classic post-hoc calibration methods temperature scaling (TS) [12] and matrix scaling with off-diagonal regularization (MS) [18] as our baselines.
Experimental settings. For the base model GCN and GAT, i.e., the uncalibrated model, we follow parameters suggested by [16] and [33] and further carefully tune them to get optimal performance. For the post-hoc calibration technique, we follow the official implementation [12, 18]. For our CaGCN, we train a two-layer GCN with the hidden layer dimension to be 16. We set $\lambda = 0 . 5$ for all datasets, weight decay to be 5e-3 for Cora, Citeseer, Pubmed and 0.03 for CoraFull. Other parameters of CaGCN follows [16]. We evaluate the performance of confidence calibration by ECE [22], NLL [10] and Brier Score (BS) [4], which we expect are smaller, and we set the bin number $M = 2 0$ for ECE (more details can be seen in Appendix A). For all methods, we randomly run 10 times and report the average results. More detailed experimental settings can be seen in Appendix B.
Results. Table 2 reports calibration results evaluated by ECE (more results on NLL and Brier Score are in Appendix C.1). We have the following observations: (1) Compared with uncalibrated models and other baselines, CaGCN is statistically significantly better at the $^ { * } 0 . 0 5$ level and $\ast \ast _ { } 0 . 0 1$ level. (2) The ECE values on uncalibrated models are generally the highest, implying that GCN and GAT are poorly calibrated. (3) MS behaves badly on datasets with many classes, e.g., CoraFull. This is because the number of parameters for matrix scaling scales quadratically with the number of classes while the size of the validation set keeps unchanged. Therefore, it will over-fit to the small validation set when dataset has a great number of classes. However, CaGCN does not have this problem.
Additional analysis. In Section 2 we visualize the under-confidence problem of existing GNNs using reliability diagrams. Here we utilize the same visualization method to make a comparison before and after confidence calibration. As shown in Fig. 8, Fig. 9, Fig. 10 and Fig. 11 in the appendix, we can find that the confidence is well-calibrated after calibration.
# 5.2 Classification Evaluation of Self-Training
Baselines. Since self-training can be applied to any models, here we choose GCN and GAT as our base models, i.e., the original models (Orig.) without self-training, and we choose self-training (St.), co-training (Ct.), Union, Intersection (Inter.) methods proposed in [20] for comparison, which are commonly used as the baselines in self-training. Furthermore, we employ TS as the confidence calibration function in CaGCN-st as another baseline and we denote it by TS-st.
Experimental settings. We set the learning rate $l r = 0 . 0 0 1$ for CaGCN-st and train our CaGCN-st 200 epochs for Cora, 150 epochs for Citeseer, 100 epochs for Pubmed and 500 epochs for CoraFull. We set the threshold $\tau \in \{ 0 . 8 , 0 . 8 5 , 0 . 9 , 0 . 9 5 , 0 . 9 9 \}$ and the maximum number of stage $s = 1 0$ . As for baselines, all the parameters follow [20] and we further carefully tune them to get optimal performance. For all methods, we randomly run 10 times and report the average results.
Results. Table 3 summarizes the node classification accuracy on GCN and its self-training variants. More results on GAT can be seen in Appendix C.2. We have the following observation: (1) CaGCN-st consistently outperforms all the baselines on all the datasets and label rates at the $^ { * } 0 . 0 5$ level. (2) Compared with the base model, self-training methods generally achieve better results, which proves their effectiveness. (3) Self-training methods with confidence calibration (i.e., TS-st and CaGCN-st) have better performance, which implies that confidence calibration scales more correct predictions to the high confidence range while keeps incorrect predictions basically unchanged, which we believe is beneficial for self-training.
Ablation study. CaGCN-st generates pseudo labels based on the calibrated confidence. Here we study the effectiveness of the confidence calibration function CaGCN in CaGCNst. We propose a variant GCN-st of CaGCNst, where CaGCN is removed from CaGCN-st while other parts are kept unchanged. All the experimental settings of GCN-st are the same as CaGCN-st. We report the results in Table 4, and we can observe that CaGCN-st consistently outperforms GCN-st on all the datasets, implying that self-training with calibrated confidence can generate more correct pseudo labels.
Additional analysis. We also investigate the changing trends of accuracy with respect to the threshold $\tau$ in CaGCN-st in Appendix C.2 and study why GCNs are poorly calibrated in Appendix D.
Table 4: Abaltion study on self-training
<table><tr><td rowspan="2">Dataset L/C</td><td rowspan="2"></td><td>GCN</td><td></td><td>GAT</td></tr><tr><td>GCN-st CaGCN-st</td><td></td><td>GCN-st CaGCN-st</td></tr><tr><td rowspan="3">Cora</td><td>20</td><td>82.28</td><td>83.11</td><td>84.08 84.08</td></tr><tr><td>40</td><td>84.10</td><td>84.37 85.50</td><td>85.63</td></tr><tr><td>60</td><td>85.16 85.79</td><td>85.57</td><td>86.26</td></tr><tr><td rowspan="3">Citeseer</td><td>20</td><td>74.13</td><td>74.90</td><td>73.73 74.34</td></tr><tr><td>40</td><td>75.28</td><td>75.48</td><td>75.07 75.62</td></tr><tr><td>60</td><td>75.85 76.43</td><td>75.13</td><td>76.08</td></tr><tr><td rowspan="3">Pubmed</td><td>20</td><td>81.01</td><td>81.16</td><td>80.34 81.17</td></tr><tr><td>40</td><td>82.90</td><td>83.08</td><td>82.75 83.47</td></tr><tr><td>60</td><td>83.44 84.47</td><td>83.46</td><td>83.95</td></tr><tr><td rowspan="3">CoraFull</td><td>20</td><td>61.32</td><td>62.19 62.09</td><td>65.46</td></tr><tr><td>40</td><td>65.96</td><td>66.30</td><td>65.92 66.86</td></tr><tr><td>60</td><td>66.43 67.60</td><td>66.54</td><td>67.45</td></tr></table>
# 6 Related Work
Graph Neural Networks. Modern GCNs mimics CNNs to learn the local and global structural patterns of graphs through designed convolution and readout functions. [5] generalizes CNNs to graph signal based on the spectrum of graph Laplacian. ChebNet [7] uses Chebyshev polynomials to approximate the $K$ -order localized graph filters and GCN [16] further employs the 1-order simplification of the Chebyshev filter. GAT [33] utilizes attention mechanisms to adaptively learn aggregation weights. GraphSAGE [13] uses various ways of pooling for aggregation. [20] introduces self-training to GCNs and [30] proposes a multi-stage self-supervised (M3S) self-training algorithm of GCNs. Both [20] and [30] focus on the few-shot learning and neither has ever explored self-training with higher label rates in GCNs. More works on GNNs can be found in surveys [36, 43], however, to the best of our knowledge, current GNNs have not considered the confidence calibration.
Confidence Calibration. Confidence calibration has been studied for a long time in CV and NLP [12, 23, 25, 14, 19, 37, 40, 42]. [12] discovers modern neural networks are poorly calibrated and study factors influencing calibration. Platt scaling [24] is a simple post-hoc calibration method for binary models, which transforms the logit using scalar parameters. Temperature scaling is the simplest multi-class extension of Platt scaling and matrix and vector scaling are another two extensions of platt scaling. [40] proposes Mix-n-Match calibration strategies which mix parameter methods with non-parameter methods. [25] explores the non-linear space for post-hoc calibration function using a neural network. Moreover, [32] points out GNNs can be miscalibrated in the supervised scenario and mainly focus on miscalibration originated from the imbalanced class distribution. However, none of them have considered the confidence calibration in GNNs on the common semi-supervised scenario.
# 7 Conclusion
Current efforts on advancing GNNs mostly focus on classification accuracy. However, when deploying GNNs to real-world applications, especially safety-critical fields, whether the results of GNNs are trustworthy is another important factor that cannot be neglected. In this paper, we study the confidence calibration problem in GNNs and discover existing GNNs are under-confident on their predictions. To solve this problem, we propose a novel trustworthy GNN model CaGCN which respects the homophily property of confidence in GNNs and preserves the classification accuracy. Moreover, we propose a novel self-training method CaGCN-st where confidence is first calibrated by CaGCN and then used to generate pseudo labels. Extensive experiments demonstrate the effectiveness of our proposed model in terms of both calibration and accuracy.
An interesting direction for future work is to extend CaGCN to other graph tasks, but more studies need to be conducted. We take the link prediction as an example, where we can regard the link prediction as a binary classification problem and the output as the confidence. Considering that the ground-truth confidence distribution for nodes should have the homophily property as is shown in Section 3.1, edges are likely to have the same property as well. As a result, we can employ CaGCN to propagate the confidence between edges by regarding the edges as the nodes. However, more exploration still needs to be conducted for the homophily property of edges.
Broader impact. Current efforts on advancing GNNs mostly focus on classification accuracy. However, when deploying GNNs to real-world applications, especially safety-critical fields, whether the results of GNNs are trustworthy is another important factor. The demands for a trustworthy model are universal and extensive such as in the field of disease prediction [31], traffic states prediction [6] and object detection [11] for autonomous driving, where estimating the true probability of getting a correct prediction is necessary. We take the disease prediction [31] as an example, where GNNs are utilized to encode the information of different symptoms, users and diseases. In this scenario, accurately and comprehensively predicting diseases at an early stage will help patients receive prevention treatments in a timely manner. Otherwise, the misdiagnosis and missed diagnosis will endanger the health of patients. Therefore, a trustworthy model is urgently needed. Our CaGCN can make a trustworthy prediction based on its confidence, and as a result, decrease the risk of misdiagnosis and missed diagnosis. We hope our work can provide insights for future improvements in tackling the trustworthiness problem in other saftey-critical fields.
Limitations. One potential issue of this work is that it provides a limited explanation to the underconfidence problem. We advocate peer researchers to look into this, making GNNs more reliable in different domains. Other than that, since this work is mostly on the discovery of the confidence calibration problem in GNNs and the theoretical aspect of improving calibration, we do not foresee any direct negative impacts on the society.
# Acknowledgments and Disclosure of Funding
This work is supported in part by the National Natural Science Foundation of China (No. 62172052, No. U20B2045, U1936104, 61772082, 61702296, 62002029).
# References
[1] Dario Amodei, Chris Olah, Jacob Steinhardt, Paul Christiano, John Schulman, and Dan Mané. Concrete problems in ai safety. arXiv preprint arXiv:1606.06565, 2016. [2] Deyu Bo, Xiao Wang, Chuan Shi, and Huawei Shen. Beyond low-frequency information in graph convolutional networks. arXiv preprint arXiv:2101.00797, 2021. [3] Aleksandar Bojchevski and Stephan Günnemann. Deep gaussian embedding of graphs: Unsupervised inductive learning via ranking. arXiv preprint arXiv:1707.03815, 2017. [4] Glenn W Brier. Verification of forecasts expressed in terms of probability. Monthly weather review, 78(1):1–3, 1950. [5] Joan Bruna, Wojciech Zaremba, Arthur Szlam, and Yann LeCun. Spectral networks and locally connected networks on graphs. arXiv preprint arXiv:1312.6203, 2013. [6] Zhiyong Cui, Kristian Henrickson, Ruimin Ke, and Yinhai Wang. Traffic graph convolutional recurrent neural network: A deep learning framework for network-scale traffic learning and forecasting. IEEE Transactions on Intelligent Transportation Systems, 21(11):4883–4894, 2019. [7] Michaël Defferrard, Xavier Bresson, and Pierre Vandergheynst. Convolutional neural networks on graphs with fast localized spectral filtering. arXiv preprint arXiv:1606.09375, 2016. [8] Charles Dugas, Yoshua Bengio, François Bélisle, Claude Nadeau, and René Garcia. Incorporating second-order functional knowledge for better option pricing. Advances in neural information processing systems, pages 472–478, 2001. [9] Federico Errica, Marco Podda, Davide Bacciu, and Alessio Micheli. A fair comparison of graph neural networks for graph classification. arXiv preprint arXiv:1912.09893, 2019. [10] Jerome Friedman, Trevor Hastie, Robert Tibshirani, et al. The elements of statistical learning, volume 1. Springer series in statistics New York, 2001. [11] Jiayuan Gu, Han Hu, Liwei Wang, Yichen Wei, and Jifeng Dai. Learning region features for object detection. In Proceedings of the european conference on computer vision (ECCV), pages 381–395, 2018. [12] Chuan Guo, Geoff Pleiss, Yu Sun, and Kilian Q Weinberger. On calibration of modern neural networks. In International Conference on Machine Learning, pages 1321–1330. PMLR, 2017. [13] William L Hamilton, Rex Ying, and Jure Leskovec. Inductive representation learning on large graphs. arXiv preprint arXiv:1706.02216, 2017. [14] Zongbo Han, Changqing Zhang, Huazhu Fu, and Joey Tianyi Zhou. Trusted multi-view classification. In 9th International Conference on Learning Representations, ICLR 2021. [15] Weihua Hu, Matthias Fey, Marinka Zitnik, Yuxiao Dong, Hongyu Ren, Bowen Liu, Michele Catasta, and Jure Leskovec. Open graph benchmark: Datasets for machine learning on graphs. arXiv preprint arXiv:2005.00687, 2020. [16] Thomas N Kipf and Max Welling. Semi-supervised classification with graph convolutional networks. arXiv preprint arXiv:1609.02907, 2016. [17] Johannes Klicpera, Aleksandar Bojchevski, and Stephan Günnemann. Predict then propagate: Graph neural networks meet personalized pagerank. In 7th International Conference on Learning Representations, ICLR 2019. [18] Meelis Kull, Miquel Perello-Nieto, Markus Kängsepp, Hao Song, Peter Flach, et al. Beyond temperature scaling: Obtaining well-calibrated multiclass probabilities with dirichlet calibration. arXiv preprint arXiv:1910.12656, 2019. [19] Aviral Kumar, Sunita Sarawagi, and Ujjwal Jain. Trainable calibration measures for neural networks from kernel mean embeddings. In International Conference on Machine Learning, pages 2805–2814. PMLR, 2018. [20] Qimai Li, Zhichao Han, and Xiao-Ming Wu. Deeper insights into graph convolutional networks for semi-supervised learning. In Proceedings of the AAAI Conference on Artificial Intelligence, volume 32, 2018. [21] Allan H Murphy. A new vector partition of the probability score. Journal of Applied Meteorology and Climatology, 12(4):595–600, 1973. [22] Mahdi Pakdaman Naeini, Gregory Cooper, and Milos Hauskrecht. Obtaining well calibrated probabilities using bayesian binning. In Proceedings of the AAAI Conference on Artificial Intelligence, volume 29, 2015. [23] Alexandru Niculescu-Mizil and Rich Caruana. Predicting good probabilities with supervised learning. In Proceedings of the 22nd international conference on Machine learning, pages 625–632, 2005. [24] John Platt et al. Probabilistic outputs for support vector machines and comparisons to regularized likelihood methods. Advances in large margin classifiers, 10(3):61–74, 1999. [25] Amir Rahimi, Amirreza Shaban, Ching-An Cheng, Richard Hartley, and Byron Boots. Intra order-preserving functions for calibration of multi-class neural networks. Advances in Neural Information Processing Systems, 33, 2020. [26] Mamshad Nayeem Rizve, Kevin Duarte, Yogesh S Rawat, and Mubarak Shah. In defense of pseudo-labeling: An uncertainty-aware pseudo-label selection framework for semi-supervised learning. arXiv preprint arXiv:2101.06329, 2021. [27] Stanisław Saks. Theory of the integral. 1937. [28] David W Scott. Multivariate density estimation: theory, practice, and visualization. John Wiley & Sons, 2015. [29] Prithviraj Sen, Galileo Namata, Mustafa Bilgic, Lise Getoor, Brian Galligher, and Tina EliassiRad. Collective classification in network data. AI magazine, 29(3):93–93, 2008. [30] Ke Sun, Zhouchen Lin, and Zhanxing Zhu. Multi-stage self-supervised learning for graph convolutional networks on graphs with few labeled nodes. In Proceedings of the AAAI Conference on Artificial Intelligence, volume 34, pages 5892–5899, 2020. [31] Zhenchao Sun, Hongzhi Yin, Hongxu Chen, Tong Chen, Lizhen Cui, and Fan Yang. Disease prediction via graph neural networks. IEEE Journal of Biomedical and Health Informatics, 25 (3):818–826, 2020. [32] Leonardo Teixeira, Brian Jalaian, and Bruno Ribeiro. Are graph neural networks miscalibrated? arXiv preprint arXiv:1905.02296, 2019. [33] Petar Velickovi ˇ c, Guillem Cucurull, Arantxa Casanova, Adriana Romero, Pietro Lio, and Yoshua ´ Bengio. Graph attention networks. arXiv preprint arXiv:1710.10903, 2017. [34] Xiao Wang, Meiqi Zhu, Deyu Bo, Peng Cui, Chuan Shi, and Jian Pei. Am-gcn: Adaptive multichannel graph convolutional networks. In Proceedings of the 26th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining, pages 1243–1253, 2020. [35] Felix Wu, Amauri Souza, Tianyi Zhang, Christopher Fifty, Tao Yu, and Kilian Weinberger. Simplifying graph convolutional networks. In International conference on machine learning, pages 6861–6871. PMLR, 2019. [36] Zonghan Wu, Shirui Pan, Fengwen Chen, Guodong Long, Chengqi Zhang, and S Yu Philip. A comprehensive survey on graph neural networks. IEEE transactions on neural networks and learning systems, 2020. [37] Chen Xing, Sercan Arik, Zizhao Zhang, and Tomas Pfister. Distance-based learning from errors for confidence calibration. arXiv preprint arXiv:1912.01730, 2019. [38] Keyulu Xu, Weihua Hu, Jure Leskovec, and Stefanie Jegelka. How powerful are graph neural networks? In 7th International Conference on Learning Representations, ICLR 2019. [39] Jiaxuan You, Zhitao Ying, and Jure Leskovec. Design space for graph neural networks. Advances in Neural Information Processing Systems, 33, 2020. [40] Jize Zhang, Bhavya Kailkhura, and T Yong-Jin Han. Mix-n-match: Ensemble and compositional methods for uncertainty calibration in deep learning. In International Conference on Machine Learning, pages 11117–11128. PMLR, 2020. [41] Muhan Zhang and Yixin Chen. Link prediction based on graph neural networks. arXiv preprint arXiv:1802.09691, 2018. [42] Xujiang Zhao, Feng Chen, Shu Hu, and Jin-Hee Cho. Uncertainty aware semi-supervised learning on graph data. arXiv preprint arXiv:2010.12783, 2020. [43] Jie Zhou, Ganqu Cui, Shengding Hu, Zhengyan Zhang, Cheng Yang, Zhiyuan Liu, Lifeng Wang, Changcheng Li, and Maosong Sun. Graph neural networks: A review of methods and applications. AI Open, 1:57–81, 2020. [44] Jiong Zhu, Yujun Yan, Lingxiao Zhao, Mark Heimann, Leman Akoglu, and Danai Koutra. Beyond homophily in graph neural networks: Current limitations and effective designs. Advances in Neural Information Processing Systems, 33, 2020.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432# DIFFTAICHI: DIFFERENTIABLE PROGRAMMING FORPHYSICAL SIMULATION
Yuanming $\mathbf { H } \mathbf { u } ^ { \dag }$ , Luke Anderson†, Tzu-Mao $\mathbf { L i } ^ { * }$ , Qi $\mathbf { S u n } ^ { \ddagger }$ , Nathan $\mathbf { C a r r } ^ { \dagger }$ , Jonathan Ragan-Kelley∗, Frédo Durand† †MIT CSAIL {yuanming,lukea,fredo}@mit.edu ‡Adobe Research {qisu,ncarr}@adobe.com ∗UC Berkeley {tzumao,jrk}@berkeley.edu
# ABSTRACT
We present DiffTaichi, a new differentiable programming language tailored for building high-performance differentiable physical simulators. Based on an imperative programming language, DiffTaichi generates gradients of simulation steps using source code transformations that preserve arithmetic intensity and parallelism. A light-weight tape is used to record the whole simulation program structure and replay the gradient kernels in a reversed order, for end-to-end backpropagation. We demonstrate the performance and productivity of our language in gradient-based learning and optimization tasks on 10 different physical simulators. For example, a differentiable elastic object simulator written in our language is $4 . 2 \times$ shorter than the hand-engineered CUDA version yet runs as fast, and is $1 8 8 \times$ faster than the TensorFlow implementation. Using our differentiable programs, neural network controllers are typically optimized within only tens of iterations.
 Figure 1: Left: Our language allows us to seamlessly integrate a neural network (NN) controller and a physical simulation module, and update the weights of the controller or the initial state parameterization (blue). Our simulations typically have $5 1 2 \sim 2 0 4 8$ time steps, and each time step has up to one thousand parallel operations. Right: 10 differentiable simulators built with DiffTaichi.
Differentiable physical simulators are effective components in machine learning systems. For example, de Avila Belbute-Peres et al. (2018a) and Hu et al. (2019b) have shown that controller optimization with differentiable simulators converges one to four orders of magnitude faster than model-free reinforcement learning algorithms. The presence of differentiable physical simulators in the inner loop of these applications makes their performance vitally important. Unfortunately, using existing tools it is difficult to implement these simulators with high performance.
We present DiffTaichi, a new differentiable programming language for high performance physical simulations on both CPU and GPU. It is based on the Taichi programming language (Hu et al.,
2019a). The DiffTaichi automatic differentiation system is designed to suit key language features required by physical simulation, yet often missing in existing differentiable programming tools, as detailed below:
Megakernels Our language uses a “megakernel” approach, allowing the programmer to naturally fuse multiple stages of computation into a single kernel, which is later differentiated using source code transformations and just-in-time compilation. Compared to the linear algebra operators in TensorFlow (Abadi et al., 2016) and PyTorch (Paszke et al., 2017), DiffTaichi kernels have higher arithmetic intensity and are therefore more efficient for physical simulation tasks.
Imperative Parallel Programming In contrast to functional array programming languages that are popular in modern deep learning (Bergstra et al., 2010; Abadi et al., 2016; Li et al., 2018b), most traditional physical simulation programs are written in imperative languages such as Fortran and $\mathrm { C } { + } { + }$ . DiffTaichi likewise adopts an imperative approach. The language provides parallel loops and control flows (such as “if” statements), which are widely used constructs in physical simulations: they simplify common tasks such as handling collisions, evaluating boundary conditions, and building iterative solvers. Using an imperative style makes it easier to port existing physical simulation code to DiffTaichi.
Flexible Indexing Existing parallel differentiable programming systems provide element-wise operations on arrays of the same shape, e.g. c[i, j] $=$ a[i, j] + b[i, j]. However, many physical simulation operations, such as numerical stencils and particle-grid interactions are not elementwise. Common simulation patterns such as y[p[i] $\star \ 2$ , $\mathbf { j } ] \ = \ \times [ \mathbf { q } [ \mathbf { j } + \mathbf { j } ] ]$ can only be expressed with unintuitive scatter/gather operations in these existing systems, which are not only inefficient but also hard to develop and maintain. On the other hand, in DiffTaichi, the programmer directly manipulates array elements via arbitrary indexing, thus allowing partial updates of global arrays and making these common simulation patterns naturally expressible. The explicit indexing syntax also makes it easy for the compiler to perform access optimizations (Hu et al., 2019a).
The three requirements motivated us to design a tailored two-scale automatic differentiation system, which makes DiffTaichi especially suitable for developing complex and high-performance differentiable physical simulators, possibly with neural network controllers (Fig. 1, left). Using our language, we are able to quickly implement and automatically differentiate 10 physical simulators1, covering rigid bodies, deformable objects, and fluids (Fig. 1, right). A comprehensive comparison between DiffTaichiand other differentiable programming tools is in Appendix A.
# 2 BACKGROUND: THE TAICHI PROGRAMMING LANGUAGE
DiffTaichi is based on the Taichi programming language (Hu et al., 2019a). Taichi is an imperative programming language embedded in $\mathrm { C } { + } { + } 1 4$ . It delivers both high performance and high productivity on modern hardware. The key design that distinguishes Taichi from other imperative programming languages such as $\mathrm { C + + / C U D A }$ is the decoupling of computation from data structures. This allows programmers to easily switch between different data layouts and access data structures with indices (i.e. $\times [ \mathfrak { i } , \ \mathfrak { j } , \ \mathsf { k } ] ,$ , as if they are normal dense arrays, regardless of the underlying layout. The Taichi compiler then takes both the data structure and algorithm information to apply performance optimizations. Taichi provides “parallel-for" loops as a first-class construct. These designs make Taichi especially suitable for writing high-performance physical simulators. For more details, readers are referred to Hu et al. (2019a).
The DiffTaichi language frontend is embedded in Python, and a Python AST transformer compiles DiffTaichi code to Taichi intermediate representation (IR). Unlike Python, the DiffTaichi language is compiled, statically-typed, parallel, and differentiable. We extend the Taichi compiler to further compile and automatically differentiate the generated Taichi IR into forward and backward executables.
We demonstrate the language using a mass-spring simulator, with three springs and three mass points, as shown right. In this section we introduce the forward simulator using the DiffTaichi frontend of Taichi, which is an easier-to-use wrapper of the Taichi $\mathrm { C } { + } { + } 1 4$ frontend.
Allocating Global Variables Firstly we allocate a set of global tensors to store the simulation state. These tensors include a scalar loss of type float32, 2D tensors $\times , ~ \lor$ , force of size steps $\times { \mathsf n _ { - } }$ springs and type float $3 2 \times 2$ , and 1D arrays of size n_spring for spring properties: spring_anchor_a (int32), spring_anchor_b (int32), spring_length (float32).
Defining Kernels A mass-spring system is modeled by Hooke’s law $\textbf { F } = \ k ( \| \mathbf { x } _ { a } - \mathbf { x } _ { b } \| _ { 2 } \ - $ $l _ { 0 } ) \frac { \mathbf { x } _ { a } - \mathbf { x } _ { b } } { \lVert \mathbf { x } _ { a } - \mathbf { x } _ { b } \rVert _ { 2 } }$ where $k$ is the spring stiffness, $\mathbf { F }$ is spring force, $\mathbf { x } _ { a }$ and $\mathbf { x } _ { b }$ are the positions of two mass points, and $l _ { 0 }$ is the rest length. The following kernel loops over all the springs and scatters forces to mass points:
@ti.kernel def apply_spring_force(t: ti.i32): # Kernels can have parameters. Here t is a parameter with type int32. for i in range(n_springs): # A parallel for, preferably on GPU a, $\textrm { b } =$ spring_anchor_a[i], spring_anchor_b[i] $\times \_ a$ , ${ \bf \sf x _ { - } b } ~ = ~ { \bf \sf x _ { \bar { \tau } } t } ~ - ~ { \bf \epsilon } _ { 1 }$ , a], $\times \left[ { \ t { \mathrm { ~ \ - ~ } } 1 } \right.$ , b] dist $= \mathbf { \nabla } \times \_ \mathsf { a } - \mathbf { \nabla } \times \_ \mathsf { b }$ length $=$ dist.norm() + 1e-4 $\begin{array} { r l } { \mathsf { F } } & { { } = } \end{array}$ (length - spring_length[i]) $\star$ spring_stiffness $\star$ dist / length # Apply spring impulses to mass points. force[t, a] $+ = - \mathsf { F } \sharp \mathsf { \Gamma } ^ { \prime \prime } { + } = { \mathrm { \Omega } } ^ { \prime \prime }$ is atomic by default force[t, b] $\mathrm { \Sigma } + + + \mathrm { \Sigma } \mathsf { F }$
For each particle $i$ , we use semi-implicit Euler time integration with damping: $\begin{array} { r } { { \pmb v } _ { t , i } = e ^ { - \Delta t \alpha } { \pmb v } _ { t - 1 , i } + } \end{array}$ $\begin{array} { r } { \frac { \Delta t } { m _ { i } } { \bf F } _ { t , i } , { \bf x } _ { t , i } = { \bf x } _ { t - 1 , i } + \Delta t { \bf v } _ { t , i } } \end{array}$ , where $\pmb { v } _ { t , i } , \mathbf { x } _ { t , i } , m _ { i }$ are the velocity, position and mass of particle $i$ at time step $t$ , respectively. $\alpha$ is a damping factor. The kernel is as follows:
@ti.kernel def time_integrate(t: ti.i32): for i in range(n_objects): $\qquad \mathsf { s } \quad \mathsf { = }$ math.exp(-dt $\star$ damping) $\#$ Compile-time evaluation since dt and damping are constants $\mathsf { v } [ \mathsf { t } , \mathsf { ~ \mathsf { ~ \mathsf { \Sigma } ~ } } _ { } { \mathsf { \Sigma } } ] = \mathsf { s } \star \mathsf { v } [ \mathsf { t } - \mathsf { ~ \mathsf { \Sigma } ~ } _ { } { \mathsf { \Sigma } } _ { } { \mathsf { \Sigma } } \mathsf { i } ] + \mathsf { d } \mathsf { t } \star \mathsf { \Sigma } _ { } { \mathsf { \Sigma } } _ { } { \mathsf { \Sigma } } _ { } { \mathsf { \Sigma } } _ { } { \mathsf { \Sigma } } _ { } { \mathsf { \Sigma } } _ { } { \mathsf { \Sigma } } _ { } { \mathsf { \Sigma } } _ { } { \mathsf { \Sigma } } _ { }$ force[t, i] / mass $\#$ mass $= ~ 1$ in this example x[t, $\dot { \bf ~ l } ] ~ = ~ { \bf \nabla } \times [ \dot { \bf t } ~ - ~ { \bf 1 }$ , i] $^ +$ dt $\star$ v[t, i]
Assembling the Forward Simulator With these components, we define the forward time integration:
def forward(): for t in range(1, steps): apply_spring_force(t) time_integrate(t)
# 3 AUTOMATICALLY DIFFERENTIATING PHYSICAL SIMULATORS IN TAICHI
The main goal of DiffTaichi’s automatic differentiation (AD) system is to generate gradient simulators automatically with minimal code changes to the traditional forward simulators.
Design Decision Source Code Transformation (SCT) (Griewank & Walther, 2008) and Tracing (Wengert, 1964) are common choices when designing AD systems. In our setting, using SCT to differentiate a whole simulator with thousands of time steps, results in high performance yet poor flexibility and long compilation time. On the other hand, naively adopting tracing provides flexibility yet poor performance, since the “megakernel" structure is not preserved during backpropagation. To get both performance and flexibility, we developed a two-scale automatic differentiation system (Figure 2): we use SCT for differentiating within kernels, and use a light-weight tape that only stores function pointers and arguments for end-to-end simulation differentiation. The global tensors are natural checkpoints for gradient evaluation.
 Figure 2: Left: The DiffTaichi system. We reuse some infrastructure (white boxes) from Taichi, while the blue boxes are our extensions for differentiable programming. Right: The tape records kernel launches and replays the gradient kernels in reverse order during backpropagation.
Assumption Unlike functional programming languages where immutable output buffers are generated, imperative programming allows programmers to freely modify global tensors. To make automatic differentiation well-defined under this setting, we make the following assumption on imperative kernels:
# Global Data Access Rules:
1) If a global tensor element is written more than once, then starting from the second write, the write must come in the form of an atomic add (“accumulation”). 2) No read accesses happen to a global tensor element, until its accumulation is done.
In forward simulators, programmers may make subtle changes to satisfy the rules. For instance, in the mass-spring simulation example, we record the whole history of $\times$ and $\vee$ , instead of keeping only the latest values. The memory consumption issues caused by this can be alleviated via checkpointing, as discussed later in Appendix D.
With these assumptions, kernels will not overwrite the outputs of each other, and the goal of AD is clear: given a primal kernel $f$ that takes as input $X _ { 1 } , X _ { 2 } , \ldots , X _ { n }$ and outputs (or accumulates to) $Y _ { 1 } , Y _ { 2 } , \dots , Y _ { m }$ , the generated gradient (adjoint) kernel $f ^ { * }$ should take as input $X _ { 1 } , X _ { 2 } , \ldots , X _ { n }$ and $Y _ { 1 } ^ { * }$ $^ { \prime * } _ { 1 } , Y _ { 2 } ^ { * } , \ldots , Y _ { m } ^ { * }$ and accumulate gradient contributions to $X _ { 1 } ^ { * } , X _ { 2 } ^ { * } , \ldots , X _ { m } ^ { * }$ , where each $X _ { i } ^ { * }$ is an adjoint of $X _ { i }$ , i.e. $\partial ( \mathrm { I o s s } ) / \partial X _ { i }$ .
Storage Control of Adjoint Tensors Users can specify the storage of adjoint tensors using the Taichi data structure description language (Hu et al., 2019a), as if they are primal tensors. We also provide ti.root.lazy_grad() to automatically place the adjoint tensors following the layout of their primals.
# 3.1 LOCAL AD: DIFFERENTIATING TAICHI KERNELS USING SOURCE CODE TRANSFORMS
A typical Taichi kernel consists of multiple levels of for loops and a body block. To make later AD easier, we introduce two basic code transforms to simplify the loop body, as detailed below.
 Figure 3: Simple IR preprocessing before running the AD source code transform (left to right). Demonstrated in ${ \mathsf { C } } { + } { + }$ . The actual Taichi IR is often more complex. Containing loops are ignored.
Flatten Branching In physical simulation branches are common, e.g., when implementing boundary conditions and collisions. To simplify the reverse-mode AD pass, we first replace “if” statements with ternary operators select(cond, value_if_true, value_if_false), whose gradients are clearly defined (Fig. 3, middle). This is a common transformation in program vectorization (e.g. Karrenberg & Hack (2011); Pharr & Mark (2012)).
Eliminate Mutable Local Variables After removing branching, we end up with straight-line loop bodies. To further simplify the IR and make the procedure truly single-assignment, we apply a series of local variable store forwarding transforms, until the mutable local variables can be fully eliminated (Fig. 3, right).
After these two custom IR simplification transforms, DiffTaichi only has to differentiate the straightline code without mutable variables, which it achieves with reverse-mode AD, using a standard source code transformation (Griewank & Walther, 2008). More details on this transform are in Appendix B.
Loops Most loops in physical simulation are parallel loops, and during AD we preserve the parallel loop structures. For loops that are not explicitly marked as parallel, we reverse the loop order during AD transforms. We do not support loops that carry a mutating local variable since that would require a complex and costly run-time stack to maintain the history of local variables. Instead, users are instructed to employ global variables that satisfy the global data access rules.
Parallelism and Thread Safety For forward simulation, we inherit the “parallel-for" construct from Taichi to map each loop iteration onto CPU/GPU threads. Programmers use atomic operations for thread safety. Our system can automatically differentiate these atomic operations. Gradient contributions in backward kernels are accumulated to the adjoint tensors via atomic adds.
# 3.2 GLOBAL AD: END-TO-END BACKPROPAGATION USING A LIGHT-WEIGHT TAPE
We construct a tape (Fig. 2, right) of the kernel execution so that gradient kernels can be replayed in a reversed order. The tape is very light-weight: since the intermediate results are stored in global tensors, during forward simulation the tape only records kernel names and the (scalar) input parameters, unlike other differentiable functional array systems where all the intermediate buffers have to be recorded by the tape. Whenever a DiffTaichi kernel is launched, we append the kernel function pointer and parameters to the tape. When evaluating gradients, we traverse the reversed tape, and invoke the gradient kernels with the recorded parameters. Note that DiffTaichi AD is evaluating gradients with respect to input global tensors instead of the input parameters.
Learning/Optimization with Gradients Now we revisit the mass-spring example and make it differentiable for optimization. Suppose the goal is to optimize the rest lengths of the springs so that the triangle area formed by the three springs becomes 0.2 at the end of the simulation. We first define the loss function:

Goal: Adjust the spring rest lengths,so that thisarea=0.2 after 1024 time steps (initialarea $\mathbf { \tau } = \mathbf { 0 . 0 0 5 }$ )
The programmer uses ti.Tape to memorize forward kernel launches. It automatically replays the gradients of these kernels in reverse for backpropagation. Initially the springs have lengths [0.1, 0.1, 0.14], and after optimization the rest lengths are [0.600, 0.600, 0.529]. This means the springs will expand the triangle according to Hooke’s law and form a larger triangle: [Reproduce: mass_spring_simple.py]

Complex Kernels Sometimes the user may want to override the gradients provided by the compiler. For example, when differentiating a 3D singular value decomposition done with an iterative solver, it is better to use a manually engineered SVD derivative subroutine for better stability. We provide two more decorators ti.complex_kernel and ti.complex_kernel_grad to overwrite the default automatic differentiation, as detailed in Appendix C. Apart from custom gradients, complex kernels can also be used to implement checkpointing, as detailed in Appendix D.
# 4 EVALUATION
We evaluate DiffTaichi on 10 different physical simulators covering large-scale continuum and small-scale rigid body simulations. All results can be reproduced with the provided script. The dynamic/optimization processes are visualized in the supplemental video. In this section we focus our discussions on three simulators. More details on the simulators are in Appendix E.
# 4.1 DIFFERENTIABLE CONTINUUM MECHANICS FOR ELASTIC OBJECTS [diffmpm]
First, we build a differentiable continuum simulation for soft robotics applications. The physical system is governed by momentum and mass conservation, i.e. $\begin{array} { r } { \rho \frac { D \mathbf { v } } { D t } = \nabla \cdot \boldsymbol { \sigma } + \rho \mathbf { g } } \end{array}$ , $\begin{array} { r } { \frac { D \rho } { D t } + \rho \nabla \cdot \mathbf { v } = } \end{array}$ 0. We follow ChainQueen’s implementation (Hu et al., 2019b) and use the moving least squares material point method (Hu et al., 2018) to simulate the system. We were able to easily translate the original CUDA simulator into DiffTaichi syntax. Using this simulator and an open-loop controller, we can easily train a soft robot to move forward (Fig. 1, diffmpm).
Performance and Productivity Compared with manual gradient implementations in (Hu et al., 2019b), getting gradients in DiffTaichi is effortless. As a result, the DiffTaichi implementation is $4 . 2 \times$ shorter in terms of lines of code, and runs almost as fast; compared with TensorFlow, DiffTaichi code is $1 . 7 \times$ shorter and $1 8 8 \times$ faster (Table 1). The Tensorflow implementation is verbose due to the heavy use of tf.gather_nd/scatter_nd and array transposing and broadcasting.
Table 1: diffmpm performance comparison on an NVIDIA GTX 1080 Ti GPU. We benchmark in 2D using 6.4K particles. For the lines of code, we only include the essential implementation, excluding boilerplate code. [Reproduce: python3 diffmpm_benchmark.py]
<table><tr><td>Approach</td><td>Forward Time</td><td>Backward Time</td><td>Total Time</td><td># Lines of Code</td></tr><tr><td>TensorFlow</td><td>13.20 ms</td><td>35.70 ms</td><td>48.90 ms (188.×)</td><td>190</td></tr><tr><td>CUDA</td><td>0.10 ms</td><td>0.14 ms</td><td>0.24 ms (0.92×)</td><td>460</td></tr><tr><td>DiffTaichi</td><td>0.11 ms</td><td>0.15 ms</td><td>0.26 ms (1.00×)</td><td>110</td></tr></table>
# 4.2 DIFFERENTIABLE INCOMPRESSIBLE FLUID SIMULATOR [smoke]
We implemented a smoke simulator (Fig. 1, smoke) with semi-Lagrangian advection (Stam, 1999) and implicit pressure projection, following the example in Autograd (Maclaurin et al., 2015). Using gradient descent optimization on the initial velocity field, we are able to find a velocity field that changes the pattern of the fluid to a target image (Fig. 7a in Appendix). We compare the performance of our system against PyTorch, Autograd, and JAX in Table 2. Note that as an example from the
Table 2: smoke benchmark against Autograd, PyTorch, and JAX. We used a $1 1 0 ~ \times ~ 1 1 0$ grid and 100 time steps, each with 6 Jacobi pressure projections. [Reproduce: python3 smoke_[autograd/pytorch/jax/taichi_cpu/taichi_gpu].py]. Note that the Autograd program uses float64 precision, which approximately doubles the run time.
<table><tr><td>Approach</td><td>Forward Time</td><td>Backward Time</td><td>Total Time</td><td>#Essential LoC</td></tr><tr><td>PyTorch (CPU, f32)</td><td>405 ms</td><td>328 ms</td><td>733 ms (13.8×)</td><td>74</td></tr><tr><td>PyTorch (GPU, f32)</td><td>254 ms</td><td>457 ms</td><td>711 ms (13.4×)</td><td>74</td></tr><tr><td>Autograd (CPU, f64)</td><td>307 ms</td><td>1197 ms</td><td>1504 ms (28.4×)</td><td>51</td></tr><tr><td>JAX (GPU, f32)</td><td>24 ms</td><td>75 ms</td><td>99 ms (1.9×)</td><td>90</td></tr><tr><td>DiffTaichi (CPU, f32)</td><td>66 ms</td><td>132 ms</td><td>198 ms (3.7x)</td><td>75</td></tr><tr><td>DiffTaichi (GPU, f32)</td><td>24 ms</td><td>29 ms</td><td>53 ms (1.0×)</td><td>75</td></tr></table>
Autograd library, this grid-based simulator is intentionally simplified to suit traditional array-based programs. For example, a periodic boundary condition is used so that Autograd can represent it using numpy.roll, without any branching. Still, Taichi delivers higher performance than these arraybased systems. The whole program takes 10 seconds to run in DiffTaichi on a GPU, and 2 seconds are spent on JIT. JAX JIT compilation takes 2 minutes.
# 4.3 DIFFERENTIABLE RIGID BODY SIMULATORS [rigid_body]
We built an impulse-based (Catto, 2009) differentiable rigid body simulator (Fig. 1, rigid_body) for optimizing robot controllers. This simulator supports rigid body collision and friction, spring forces, joints, and actuation. The simulation is end-to-end differentiable except for a countable number of discontinuities. Interestingly, although the forward simulator works well, naively differentiating it with DiffTaichi leads to completely misleading gradients, due to the rigid body collisions. We discuss the cause and solution of this issue below.
Improving collision gradients Consider the rigid ball example in Fig. 4 (left), where a rigid ball collides with a friction-less ground. Gravity is ignored, and due to conservation of kinetic energy the ball keeps a constant speed even after this elastic collision.
In the forward simulation, using a small $\Delta t$ often leads to a reasonable result, as done in many physics simulators. Lowering the initial ball height will increase the final ball height, since there is less distance to travel before the ball hits the ground and more after (see the loss curves in Fig.4, middle right). However, using a naive time integrator, no matter how small $\Delta t$ is, the evaluated gradient of final height w.r.t. initial height will be 1 instead of $- 1$ . This counter-intuitive behavior is due to the fact that time discretization itself is not differentiated by the compiler. Fig. 4 explains this effect in greater detail.
 Figure 4: How gradients can go wrong with naive time integrators. For clarity we use a large $\Delta t$ here. Left: Since collision detection only happens at multiples of $\Delta t$ ( $2 \Delta t$ in this case), lowering the initial position of the ball (light blue) leads to a lowered final position. Middle Left: By improving the time integrator to support continuous time of impact (TOI), collisions can be detected at any time, e.g. $1 . 9 \Delta t$ (light red). Now the blue ball ends up higher than the green one. Middle Right: Although the two time integration techniques lead to almost identical forward results (in practice $\Delta t$ is small), the naive time integrator gives an incorrect gradient of 1, but adding TOI yields the correct gradient. Please see our supplemental video for a better demonstration. [Reproduce: python3 rigid_body_toi.py] Right: When zooming in, the loss of the naive integrator is decreasing, and the saw-tooth pattern explains the positive gradients. [Reproduce: python3 rigid_body_toi.py zoom]
 Figure 5: Adding TOI greatly improves gradient and optimization quality. Each experiment is repeated five times. [Reproduce: python3 [mass_spring/rigid_body.py] [1/2] plot && python3 plot_losses.py]
We propose a simple solution of adding continuous collision resolution (see, for example, Redon et al. (2002)), which considers precise time of impact (TOI), to the forward program (Fig. 4, middle left). Although it barely improves the forward simulation (Fig. 4, middle right), the gradient will be corrected effectively (Fig. 4, right). The details of continuous collision detection are in Appendix F. In real-world simulators, we find the TOI technique leads to significant improvement in gradient quality in controller optimization tasks (Fig. 5). Having TOI or not barely affects forward simulation: in the supplemental video, we show that a robot controller optimized in a simulator with TOI, actually works well in a simulator without TOI.
The takeaway is, differentiating physical simulators does not always yield useful gradients of the physical system being simulated, even if the simulator does forward simulation well. In Appendix G, we discuss some additional gradient issues we have encountered.
# 5 RELATED WORK
Differentiable programming The recent rise of deep learning has motivated the development of differentiable programming libraries for deep NNs, most notably auto-differentiation frameworks such as Theano (Bergstra et al., 2010), TensorFlow (Abadi et al., 2016) and PyTorch (Paszke et al., 2017). However, physical simulation requires complex and customizable operations due to the intrinsic computational irregularity. Using the aforementioned frameworks, programmers have to compose these coarse-grained basic operations into desired complex operations. Doing so often leads to unsatisfactory performance.
Earlier work on automatic differentiation focuses on transforming existing scalar code to obtain derivatives (e.g. Utke et al. (2008), Hascoet & Pascual (2013), Pearlmutter & Siskind (2008)). A recent trend has emerged for modern programming languages to support differentiable function transformations through annotation (e.g. Innes et al. (2019), Wei et al. (2019)). These frameworks enable differentiating general programming languages, yet they provide limited parallelism.
Differentiable array programming languages such as Halide (Ragan-Kelley et al., 2013; Li et al., 2018b), Autograd (Maclaurin et al., 2015), JAX (Bradbury et al., 2018), and Enoki (Jakob, 2019) operate on arrays instead of scalars to utilize parallelism. Instead of operating on arrays that are immutable, DiffTaichi uses an imperative style with flexible indexing to make porting existing physical simulation algorithms easier.
Differentiable Physical Simulators Building differentiable simulators for robotics and machine learning has recently increased in popularity. Without differentiable programming, Battaglia et al. (2016), Chang et al. (2016) and Mrowca et al. (2018) used NNs to approximate the physical process and used the NN gradients as the approximate simulation gradients. Degrave et al. (2016) and de Avila Belbute-Peres et al. (2018b) used Theano and PyTorch respectively to build differentiable rigid body simulators. Schenck & Fox (2018) differentiates position-based fluid using custom CUDA kernels. Popovic et al. ´ (2000) used a differentiable rigid body simulator for manipulating physically based animations. The ChainQueen differentiable elastic object simulator (Hu et al., 2019b) implements forward and gradient versions of continuum mechanics in hand-written CUDA kernels, leading to performance that is two orders of magnitude higher than a pure TensorFlow implementation. Liang et al. (2019) built a differentiable cloth simulator for material estimation and motion control. The deep learning community also often incorporates differentiable rendering operations (OpenDR (Loper & Black, 2014), N3MR (Kato et al., 2018), redner (Li et al., 2018a), Mitsuba 2 (Nimier-David et al., 2019)) to learn from 3D scenes.
# 6 CONCLUSION
We have presented DiffTaichi, a new differentiable programming language designed specifically for building high-performance differentiable physical simulators. Motivated by the need for supporting megakernels, imperative programming, and flexible indexing, we developed a tailored two-scale automatic differentiation system. We used DiffTaichi to build 10 simulators and integrated them into deep neural networks, which proved the performance and productivity of DiffTaichi over existing systems. We hope our programming language can greatly lower the barrier of future research on differentiable physical simulation in the machine learning and robotics communities.
# BIBLIOGRAPHY
Martín Abadi, Paul Barham, Jianmin Chen, Zhifeng Chen, Andy Davis, Jeffrey Dean, Matthieu Devin, Sanjay Ghemawat, Geoffrey Irving, Michael Isard, et al. Tensorflow: A system for largescale machine learning. In 12th USENIX Symposium on Operating Systems Design and Implementation (OSDI 16), pp. 265–283, 2016.
Peter W. Battaglia, Razvan Pascanu, Matthew Lai, Danilo Rezende, and Koray Kavukcuoglu. Interaction networks for learning about objects, relations and physics. 2016.
James Bergstra, Olivier Breuleux, Frédéric Bastien, Pascal Lamblin, Razvan Pascanu, Guillaume Desjardins, Joseph Turian, David Warde-Farley, and Yoshua Bengio. Theano: A cpu and gpu math compiler in python. In Proc. 9th Python in Science Conf, volume 1, pp. 3–10, 2010.
James Bradbury, Roy Frostig, Peter Hawkins, Matthew James Johnson, Chris Leary, Dougal Maclaurin, and Skye Wanderman-Milne. JAX: composable transformations of Python+NumPy programs, 2018. URL http://github.com/google/jax.
Erin Catto. Modeling and solving constraints. In Game Developers Conference, pp. 16, 2009.
Michael B Chang, Tomer Ullman, Antonio Torralba, and Joshua B Tenenbaum. A compositional object-based approach to learning physical dynamics. ICLR, 2016.
Filipe de Avila Belbute-Peres, Kevin Smith, Kelsey Allen, Josh Tenenbaum, and J Zico Kolter. End-to-end differentiable physics for learning and control. In Advances in Neural Information Processing Systems, pp. 7178–7189, 2018a.
Filipe de Avila Belbute-Peres, Kevin A Smith, Kelsey Allen, Joshua B Tenenbaum, and J Zico Kolter. End-to-end differentiable physics for learning and control. In Neural Information Processing Systems, 2018b.
Jonas Degrave, Michiel Hermans, Joni Dambre, et al. A differentiable physics engine for deep learning in robotics. arXiv preprint arXiv:1611.01652, 2016.
Ronald M Errico. What is an adjoint model? Bulletin of the American Meteorological Society, 78 (11):2577–2592, 1997.
Richard Gordon, Robert Bender, and Gabor T Herman. Algebraic reconstruction techniques (art) for three-dimensional electron microscopy and x-ray photography. Journal of theoretical Biology, 29(3):471–481, 1970.
Andreas Griewank and Andrea Walther. Evaluating derivatives: principles and techniques of algorithmic differentiation, volume 105. Siam, 2008.
Laurent Hascoet and Valérie Pascual. The Tapenade automatic differentiation tool: Principles, model, and specification. 39(3):20:1–20:43, 2013.
Yuanming Hu, Yu Fang, Ziheng Ge, Ziyin Qu, Yixin Zhu, Andre Pradhana, and Chenfanfu Jiang. A moving least squares material point method with displacement discontinuity and two-way rigid body coupling. 37(4):150, 2018.
Yuanming Hu, Tzu-Mao Li, Luke Anderson, Jonathan Ragan-Kelley, and Frédo Durand. Taichi: A language for high-performance computation on spatially sparse data structures. In SIGGRAPH Asia 2019 Technical Papers, pp. 201. ACM, 2019a.
Yuanming Hu, Jiancheng Liu, Andrew Spielberg, Joshua B Tenenbaum, William T Freeman, Jiajun Wu, Daniela Rus, and Wojciech Matusik. Chainqueen: A real-time differentiable physical simulator for soft robotics. Proceedings of IEEE International Conference on Robotics and Automation (ICRA), 2019b.
Mike Innes, Alan Edelman, Keno Fischer, Chris Rackauckus, Elliot Saba, Viral B Shah, and Will Tebbutt. Zygote: A differentiable programming system to bridge machine learning and scientific computing. arXiv preprint arXiv:1907.07587, 2019.
Wenzel Jakob. Enoki: structured vectorization and differentiation on modern processor architectures, 2019. https://github.com/mitsuba-renderer/enoki.
Chenfanfu Jiang. The material point method for the physics-based simulation of solids and fluids. University of California, Los Angeles, 2015.
Ralf Karrenberg and Sebastian Hack. Whole-function vectorization. In Code Generation and Optimization, pp. 141–150, 2011.
Hiroharu Kato, Yoshitaka Ushiku, and Tatsuya Harada. Neural 3d mesh renderer. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pp. 3907–3916, 2018.
Stig Larsson and Vidar Thomée. Partial differential equations with numerical methods, volume 45. Springer Science & Business Media, 2008.
Tzu-Mao Li, Miika Aittala, Frédo Durand, and Jaakko Lehtinen. Differentiable monte carlo ray tracing through edge sampling. In SIGGRAPH Asia 2018 Technical Papers, pp. 222. ACM, 2018a.
Tzu-Mao Li, Michaël Gharbi, Andrew Adams, Frédo Durand, and Jonathan Ragan-Kelley. Differentiable programming for image processing and deep learning in Halide. ACM Transactions on Graphics (TOG), 37(4):139, 2018b.
Junbang Liang, Ming C Lin, and Vladlen Koltun. Differentiable cloth simulation for inverse problems. Advances in Neural Information Processing Systems, 2019.
Matthew M Loper and Michael J Black. Opendr: An approximate differentiable renderer. In European Conference on Computer Vision, pp. 154–169. Springer, 2014.
Dougal Maclaurin, David Duvenaud, and Ryan P Adams. Autograd: Effortless gradients in numpy. In ICML 2015 AutoML Workshop, volume 238, 2015.
Aleka McAdams, Andrew Selle, Rasmus Tamstorf, Joseph Teran, and Eftychios Sifakis. Computing the singular value decomposition of 3x3 matrices with minimal branching and elementary floating point operations. Technical report, University of Wisconsin-Madison Department of Computer Sciences, 2011.
Damian Mrowca, Chengxu Zhuang, Elias Wang, Nick Haber, Li Fei-Fei, Joshua B Tenenbaum, and Daniel LK Yamins. Flexible neural representation for physics prediction. 1806.08047, 2018.
Merlin Nimier-David, Delio Vicini, Tizian Zeltner, and Wenzel Jakob. Mitsuba 2: A retargetable forward and inverse renderer. Transactions on Graphics (Proceedings of SIGGRAPH Asia), 38 (6), November 2019. doi: 10.1145/3355089.3356498.
Adam Paszke, Sam Gross, Soumith Chintala, Gregory Chanan, Edward Yang, Zachary DeVito, Zeming Lin, Alban Desmaison, Luca Antiga, and Adam Lerer. Automatic differentiation in pytorch. 2017.
Barak A. Pearlmutter and Jeffrey Mark Siskind. Reverse-mode AD in a functional framework: Lambda the ultimate backpropagator. ACM Transactions on Programming Languages and Systems, 30(2):7:1–7:36, 2008.
Matt Pharr and William R Mark. ispc: A spmd compiler for high-performance cpu programming. In Innovative Parallel Computing, pp. 1–13, 2012.
Jovan Popovic, Steven M Seitz, Michael Erdmann, Zoran Popovi ´ c, and Andrew Witkin. Interactive ´ manipulation of rigid body simulations. In Proceedings of the 27th annual conference on Computer graphics and interactive techniques, pp. 209–217. ACM Press/Addison-Wesley Publishing Co., 2000.
Jonathan Ragan-Kelley, Connelly Barnes, Andrew Adams, Sylvain Paris, Frédo Durand, and Saman Amarasinghe. Halide: A language and compiler for optimizing parallelism, locality, and recomputation in image processing pipelines. SIGPLAN Not., 48(6):519–530, jun 2013.
Stéphane Redon, Abderrahmane Kheddar, and Sabine Coquillart. Fast continuous collision detection between rigid bodies. In Computer graphics forum, volume 21, pp. 279–287. Wiley Online Library, 2002.
Connor Schenck and Dieter Fox. Spnets: Differentiable fluid dynamics for deep neural networks. arXiv preprint arXiv:1806.06094, 2018.
Jos Stam. Stable fluids. In Siggraph, volume 99, pp. 121–128, 1999.
Andre Pradhana Tampubolon, Theodore Gast, Gergely Klár, Chuyuan Fu, Joseph Teran, Chenfanfu Jiang, and Ken Museth. Multi-species simulation of porous sand and water mixtures. ACM Transactions on Graphics (TOG), 36(4):105, 2017.
Jean Utke, Uwe Naumann, Mike Fagan, Nathan Tallent, Michelle Strout, Patrick Heimbach, Chris Hill, and Carl Wunsch. Openad/f: A modular open-source tool for automatic differentiation of fortran codes. 34(4):18, 2008.
Jui-Hsien Wang, Ante Qu, Timothy R Langlois, and Doug L James. Toward wave-based sound synthesis for computer animation. ACM Trans. Graph., 37(4):109–1, 2018.
Richard Wei, Marc Rasi Dan Zheng, and Bart Chrzaszcz. Differentiable programming mega-proposal. https://github.com/apple/swift/blob/master/docs/ DifferentiableProgramming.md, 2019. Accessed: 2019-09-25.
R. E. Wengert. A simple automatic derivative evaluation program. Communications of the ACM, 7 (8):463–464, aug 1964.
# A COMPARISON WITH EXISTING SYSTEMS
Workload differences between deep learning and differentiable physical simulation Existing differentiable programming tools for deep learning are typically centered around large data blobs. For example, in AlexNet, the second convolution layer has size $2 7 \times 2 7 \times 1 2 8 \times 1 2 8$ . These tools usually provide users with both low-level operations such as tensor add and mul, and high-level operations such as convolution. The bottleneck of typical deep-learning-based computer vision tasks are convolutions, so the provided high-level operations, with very high arithmetic intensity2, can fully exploit hardware capability. However, the provided operations are “atoms” of these differentiable programming tools, and cannot be further customized. Users often have to use low-level operations to compose their desired high-level operations. This introduces a lot of temporary buffers, and potentially excessive GPU kernel launches. As shown in Hu et al. (2019b), a pure TensorFlow implementation of a complex physical simulator is $1 3 2 \times$ slower than a CUDA implementation, due to excessive GPU kernel launches and the lack of producer-consumer locality3.
The table below compares DiffTaichi with existing tools for build differentiable physical simulators.
Table 3: Comparisons between DiffTaichi and other differentiable programming tools. Note that this table only discusses features related to differentiable physical simulation, and the other tools may not have been designed for this purpose. For example, PyTorch and TensorFlow are designed for classical deep learning tasks and have proven successful in their target domains. Also note that the XLA backend of TensorFlow and JIT feature of PyTorch allow them to fuse operators to some extent, but for simulation we want complete operator fusion within megakernels. “Swift” AD (Wei et al., 2019) is partially implemented as of November 2019. “Julia” refers to Innes et al. (2019).
<table><tr><td>Feature</td><td>DiffTaichi</td><td>PyTorch</td><td>TensorFlow</td><td>Enoki</td><td>JAX</td><td>Halide</td><td>Julia</td><td>Swift</td></tr><tr><td>GPUMegakernels</td><td><</td><td>A</td><td>△</td><td><</td><td></td><td></td><td></td><td></td></tr><tr><td>Imperative Scheme</td><td></td><td></td><td></td><td>【</td><td></td><td></td><td></td><td>【</td></tr><tr><td>Parallelism</td><td></td><td></td><td></td><td></td><td>?</td><td></td><td></td><td></td></tr><tr><td>Flexible Indexing</td><td></td><td></td><td></td><td></td><td></td><td>【</td><td>【</td><td></td></tr></table>
# B DIFFERENTATING STRAIGHT-LINE TAICHI KERNELS USING SOURCE CODE TRANSFORM
Primal and adjoint kernels Recall that in DiffTaichi, (primal) kernels are operators that take as input multiple tensors (e.g., $X , Y )$ and output another set of tensors. Mathematically, kernel $f$ has the form
$$f ( X _ { 0 } , X _ { 1 } , . . , X _ { n } ) = Y _ { 0 } , Y _ { 1 } , . . . , Y _ { m } .$$
Kernels usually execute uniform operations on these tensors. When it comes to differentiable programming, a loss function is defined on the final output tensors. The gradients of the loss function “ $L ^ { \prime \prime }$ with respect to each tensor are stored in adjoint tensors and computed via adjoint kernels.
The adjoint tensor of (primal) tensor $X _ { i j k }$ is denoted as $X _ { i j k } ^ { * }$ . Its entries are defined by $X _ { i j k } ^ { * } =$ $\partial L / \partial X _ { i j k }$ . At a high level, our automatic differentiation (AD) system transforms a primal kernel into its adjoint form. Mathematically,
Reverse-Mode Automatic Differentiation
$$( \mathbf { a d j o i n t } ) f ^ { * } ( X _ { 0 } , X _ { 1 } , . . , X _ { n } , Y _ { 0 } ^ { * } , Y _ { 1 } ^ { * } , . . . , Y _ { m } ^ { * } ) = X _ { 0 } ^ { * } , X _ { 1 } ^ { * } , . . , X _ { n } ^ { * } .$$
Differentiating within kernels: The “make_adjoint” pass (reverse-mode AD) After the preprocessing passes, which flatten branching and eliminate mutable local variables, the “make_adjoint” pass transforms a forward evaluation (primal) kernel into its gradient accumulation (“adjoint”) kernel. It takes straight-line code directly and operates on the hierarchical intermediate representation (IR) of Taichi4 . Multiple outer for loops are allowed for the primal kernel. The Taichi compiler will distribute these parallel iterations onto CPU/GPU threads.
During the “make_adjoint” pass, for each SSA instruction, a local adjoint variable will be allocated for gradient contribution accumulation. The compiler will traverse the statements in reverse order, and accumulate the gradients to the corresponding adjoint local variable.
For example, a 1D array operation $y _ { i } = \sin x _ { i } ^ { 2 }$ has its IR representation as follows:
<table><tr><td>for i ∈ range(0, 16, step 1) do</td></tr><tr><td>%1=load x[i]</td></tr><tr><td>%2 = mul %1, %1</td></tr><tr><td>%3= sin(%2)</td></tr><tr><td>store y[i] = %3</td></tr><tr><td>end for</td></tr></table>
The above primal kernel will be transformed into the following adjoint kernel:
<table><tr><td>for i in range(0,16, step 1) do</td></tr><tr><td>/ adjoint variables</td></tr><tr><td>%1adj = alloca 0.0</td></tr><tr><td>%2adj = alloca 0.0</td></tr><tr><td>%3adj = alloca 0.0</td></tr><tr><td>// original forward computation</td></tr><tr><td>%1=load x[] %2 = mul %1, %1</td></tr><tr><td>%3= sin(%2)</td></tr><tr><td>/ reverse accumulation</td></tr><tr><td>%4 = load y_adj[i]</td></tr><tr><td>%3adj += %4</td></tr><tr><td>%5 = cos(%2)</td></tr><tr><td>%2adj += %3adj * %5</td></tr><tr><td>%1adj += 2 * %1 * %2adj</td></tr><tr><td>atomic add x_adj[i],%1adj end for</td></tr></table>
Note that for clarity the transformed code is not strictly SSA here. The actual IR has more instructions. A following simplification pass will simplify redundant instructions generated by the AD pass.
# C COMPLEX KERNELS
Here we demonstrated how to use complex kernels to override the automatic differentiation system. We use singular value decomposition (SVD) of $3 \times 3$ matrices $\mathbf { M } = \mathbf { U } \pmb { \Sigma } \mathbf { V } ^ { * }$ ) as an example. Fast SVD solvers used in physical simulation are often iterative, yet directly evaluate the gradient of this iterative process is likely numerically unstable. Suppose we use McAdams et al. (2011) as the forward SVD solver, and use the method in Jiang (2015) (Section 2.1.1.2) to evalute the gradients, the complex kernels are used as follows:
# Do Singular Value Decomposition (SVD) on n matrices @ti.kernel def iterative_svd(num_iterations: ti.f32): for i in range(n): input $=$ matrix_M[i] for iter in range(num_iterations): ... iteratively solve SVD using McAdams et al. 2011 matrix_U[i] $=$ ... matrix_Sigma[i] $=$ matrix_V[i] $=$ ... @ti.kernel def svd_gradient(): for i in range(n): ... Implement, for example, section 2.1.1.2 of Jiang (2015) . # A complex kernel that is registered as the svd_forward complex kernel @ti.complex_kernel_grad(svd_forward) def svd_backward(num_iterations): # differentiave SVD svd_gradient()
# D CHECKPOINTING
In this section we demonstrate how to use checkpointing via complex kernels. The goal of checkpointing is to use recomputation to save memory space. We demonstrate this using the diffmpm example, whose simulation cycle consists of particle to grid transform (p2g), grid boundary conditions (grid_op), and grid to particle transform $( \mathtt { g } 2 \mathsf { p } )$ . We assume the simulation has $O ( n )$ time steps.
# D.1 RECOMPUTATION WITHIN TIME STEPS
A naive implementation without checkpointing allocates $O ( n )$ copied of the simulation grid, which can cost a lot of memory space. Actually, if we recompute the grid states during the backward simulation time step by redoing ${ \mathsf { p } } 2 { \mathsf { g } }$ and grid_op, we can reused the grid states and allocate only one copy. This checkpointing optimization is demonstrated in the code below:
<table><tr><td>@ti.complex_kernel</td></tr><tr><td>def advance(s):</td></tr><tr><td>clear_grid()</td></tr><tr><td>compute_actuation(s)</td></tr><tr><td>p2g(s)</td></tr><tr><td>grid_op()</td></tr><tr><td>g2p(s)</td></tr><tr><td>@ti.complex_kernel_grad(advance)</td></tr><tr><td>def advance_grad(s):</td></tr><tr><td>clear_grid() p2g(s)</td></tr><tr><td>grid_op() # recompute the grid</td></tr><tr><td></td></tr><tr><td>g2p.grad(s)</td></tr><tr><td>grid_op.grad()</td></tr><tr><td>p2g.grad(s) compute_actuation.grad(s)</td></tr></table>
# D.2 SEGMENT-WISE RECOMPUTATION
Given a simulation with $O ( n )$ time steps, if all simulation steps are recorded, the space consumption is $O ( n )$ . This linear space consumption is sometimes too large for high-resolution simulations with long time horizon. Fortunately, we can reduce the space consumption using a segment-wise checkpointing trick: We split the simulation into segments of $S$ steps, and in forward simulation store only the first simulation state in each segment. During backpropagation when we need the remaining simulation states in a segment, we recompute them based on the first state in that segment.
Note that if the segment size is $O ( S )$ , then we only need to store $O ( n / S )$ simulation steps for checkpoints and $\bar { O ( S ) }$ reusable simulation steps for backpropagation within segments. The total√ space consumption is √ $O ( S + n / S )$ . Setting ${ \cal S } \doteq { \cal O } ( \sqrt { n } )$ reduces memory consumption from $O ( n )$ to $O ( { \sqrt { n } } )$ . The time complexity remains $O ( n )$ .
# E DETAILS ON 10 DIFFERENTIABLE SIMULATORS
E.1 DIFFERENTIABLE CONTINUUM MECHANICS FOR ELASTIC OBJECTS [diffmpm]
 Figure 6: Controller optimization with our differentiable continuum simulators. Left: the 2D robot with four muscles. Middle: A 3D robot with 16 muscles and 30K particles crawling on the ground. [Reproduce: python3 [diffmpm/diffmpm3d].py] Right: We couple the robot (30K particles) and the liquid simulator (13K particles), and optimize its open-loop controller in this difficult situation.[Reproduce: python3 liquid.py]
# E.2 DIFFERENTIABLE LIQUID SIMULATOR [liquid]
We follow the weakly compressible fluid model in Tampubolon et al. (2017) and implemented a 3D differentiable liquid simulator within the [diffmpm3d] framework. Our liquid simulation can be two-way coupled with elastic object simulation (Figure 6, right).
# E.3 DIFFERENTIABLE INCOMPRESSIBLE FLUID SIMULATOR [smoke]
 Figure 7: (a): (Left to right) with an optimized initial smoke velocity field, the fluid changes its pattern to a “Taichi" symbol. [Reproduce: python3 smoke_taichi.py] (b): Unoptimized (top three) and optimized (bottom three) waves at time step 3, 189, and 255. [Reproduce: python3 wave.py]
Backpropagating Through Pressure Projection We followed the baseline implementation in Autograd, and used 10 Jacobi iterations for pressure projection. Technically, 10 Jacobi iterations are not sufficient to make the velocity field fully divergence-free. However, in this example, it does a decent job, and we are able to successfully backpropagate through the unrolled 10 Jacobi iterations.
In larger-scale simulations, 10 Jacobi iterations are likely not sufficient. Assuming the Poisson solve is done by an iterative solver (e.g. multigrid preconditioned conjugate gradients, MGPCG) with 5 multigrid levels and 50 conjugate gradient iterations, then automatic differentiation will likely not be able to provide gradients with sufficient numerical accuracy across this long iterative process. The accuracy is likely worse when conjugate gradients present, as they are known to numerically drift as the number of iterations increases. In this case, the user can still use DiffTaichi to implement the forward MGPCG solver, while implementing the backward part of the Poisson solve manually, likely using adjoint methods (Errico, 1997). DiffTaichi provides “complex kernels” to override the built-in AD system, as shown in Appendix C.
E.4 DIFFERENTIABLE HEIGHT FIELD SHALLOW WATER SIMULATOR [wave]
We adopt the wave equation in Wang et al. (2018) to model shallow water height field evolution:
$$\ddot { u } = c ^ { 2 } \nabla ^ { 2 } u + c \alpha \nabla ^ { 2 } \dot { u } ,$$
where $u$ is the height of shallow water, $c$ is the “speed of sound” and $\alpha$ is a damping coefficient. We use the $\dot { u }$ and $\ddot { u }$ notations for the first and second order partial derivatives of $u$ w.r.t time $t$ respectively.
Wang et al. (2018) used the finite different time-domain (FDTD) method (Larsson & Thomée, 2008) to discretize Eqn. 1, yielding an update scheme:
where
$$\begin{array} { r l } & { \mathrm { \quad } _ { t , i , j } = 2 u _ { t - 1 , i , j } + ( c ^ { 2 } \dot { \Delta t ^ { 2 } } + c \alpha \Delta t ) ( \nabla ^ { 2 } u ) _ { t - 1 , i , j } - p _ { t - 2 , i , j } - c \alpha \Delta t ( \nabla ^ { 2 } u ) _ { t - 2 , i , j } , } \\ & { \mathrm { \quad } ( \nabla ^ { 2 } u ) _ { t , i , j } = \frac { - 4 u _ { t , i , j } + u _ { t , i , j + 1 } + u _ { t , i , j - 1 } + u _ { t , i + 1 , j } + u _ { t , i - 1 , j } } { { \Delta x ^ { 2 } } } . } \end{array}$$
We implemented this wave simulator in DiffTaichi to simulate shallow water. We used a grid of resolution $1 2 8 \times 1 2 8$ and 256 time steps. The loss function is defined as
$$L = \sum _ { i , j } \Delta x ^ { 2 } ( u _ { T , i , j } - \hat { u } _ { i , j } ) ^ { 2 }$$
where $T$ is the final time step, and $\hat { u }$ is the target height field. 200 gradient descent iterations are then used to optimize the initial height field. We set $\hat { u }$ to be the pattern “Taichi", and Fig. 7b shows the unoptimized and optimized wave evolution.
We set the “Taichi" symbol as the target pattern. Fig. 7b shows the unoptimized and optimized final wave patterns. More details on discretization is in Appendix E.
# E.5 DIFFERENTIABLE MASS-SPRING SYSTEM [mass_spring]
We extend the mass-spring system in the main text with ground collision and a NN controller. The time-of-impact fix is implemented for improved gradients. The optimization goal is to maximize the distance moved forward with 2048 time steps. We designed three mass-spring robots as shown in Fig. 8 (left).
# E.6 DIFFERENTIABLE BILLIARD SIMULATOR [billiards]
A differentiable rigid body simulator is built for optimizing a billiards strategy (Fig. 8, middle). We used forward Euler for the billiard ball motion and conservation of momentum and kinetic energy for collision resolution.
 Figure 8: Left: Three mass-spring robots. The red and blue springs are actuated. A two layer NN is used as controller. [Reproduce: python3 mass_spring.py [1/2/3] train]. Middle: Optimizing billiards. The optimizer adjusts the initial position and velocity of the white ball, so that the blue ball will reach the target destination (black dot). [Reproduce: python3 billiards.py] Right: Optimizing a robot walking. The rigid robot is controlled with a NN controller and learned to walk in 20 gradient descent iterations. [Reproduce: python3 rigid_body.py]
E.7 DIFFERENTIABLE RIGID BODY SIMULATOR [rigid_body]
Are rigid body collisions differentiable? It is worth noting that discontinuities can happen in rigid body collisions, and at a countable number of discontinuities the objective function is nondifferentiable. However, apart from these discontinuities, the process is still differentiable almost everywhere. The situation of rigid body collision is somewhat similar to the “ReLU” activation function in neural networks: at point $x = 0$ , ReLU is not differentiable (although continuous), yet it is still widely adopted. The rigid body simulation cases are more complex than ReLU, as we have not only non-differentiable points, but also discontinuous points. Based on our experiments, in these impulse-based rigid body simulators, we still find the gradients useful for optimization despite the discontinuities, especially with our time-of-impact fix.
# E.8 DIFFERENTIABLE WATER RENDERER [water_renderer]
We implemented differentiable renderers to visualize the refracting water surfaces from wave. We use finite differences to reconstruct the water surface models based on the input height field and refract camera rays to sample the images, using bilinear interpolation for meaningful gradients. To show our system works well with other differentiable programming systems, we use an adversarial optimization goal: fool VGG-16 into thinking that the refracted squirrel image is a goldfish (Fig. 9).
 Figure 9: This three-stage program (simulation, rendering, recognition) is end-to-end differentiable. Our optimized initial water height field evolves to form a refraction pattern that perturbs the image into one that fools VGG16 $( 9 9 . 9 1 \%$ goldfish). [Reproduce: python3 water_renderer.py]
E.9 DIFFERENTIABLE VOLUME RENDERER [volume_renderer]
We implemented a basic volume renderer that simply uses ray marching (we ignore light, scattering, etc.) to integrate a density field over each camera ray. In this task, we render a number of target images from different viewpoints, with the camera rotated around the given volume. The goal is then to optimize for the density field of the volume that would produce these target images: we render candidate images from the same viewpoints and compute an L2 loss between them and the target images, before performing gradient descent on the density field (Fig. 10). Essentially, this demonstrates how to use gradients to reconstruct 3D objects out of $\mathrm { X }$ -ray photos in a brute-force manner. Other approaches to this task include algebraic reconstruction techniques (ART) (Gordon et al., 1970).
 Figure 10: Volume rendering of bunny shaped density field. Left: 3 (of the 7) target images. Right: optimized images of the middle bunny after iteration 2, 50, 100. [Reproduce: python3 volume_renderer.py]
E.10 DIFFERENTIABLE ELECTRIC FIELD SIMULATOR [electric]
Recall Coulomb’s law: $\mathbf { F } = k { \frac { q _ { 1 } q _ { 2 } } { r ^ { 2 } } } { \hat { \mathbf { r } } }$ . In the right figure, there are eight electrodes carrying static charge. The red ball also carries static charge. The controller, which is a two-layer neural network, tries to manipulate the electrodes so that the red ball follows the path of the blue ball. The bigger the electrode, the more positive charge it carries.
# F FIXING GRADIENTS WITH TIME OF IMPACT AND CONTINUOUS COLLISION DETECTION
Here is a naive time integrator in the mass-spring system example:
@ti.kernel def advance(t: ti.i32): for $\dot { 7 }$ in range(n_objects): s $=$ math.exp(-dt $\star$ damping) new $\underline { { \boldsymbol { \mathsf { U } } } } \mathrm { ~ \boldsymbol { \mathsf { U } } ~ } = \mathrm { ~ \boldsymbol { \mathsf { S } } ~ } \star$ v[t - 1, i] $^ +$ dt $\star$ gravity $\star$ ti.Vector([0.0, 1.0]) ol $\mathsf { I } \_ { \mathsf { X } } \ = \ \mathsf { x } [ \mathsf { t } \ \textrm { - } \ \mathsf { 1 }$ , i] depth $=$ old_x[1] - ground_height if depth $< ~ \Theta$ and new_ $\iota [ 1 ] ~ < ~ \mathfrak { O }$ : # assuming a sticky ground (infinite coefficient of friction) new_v[0] $= \cdot$ 0 new_v[1] $=$ 0 # Without considering time of impact, we assume the whole dt uses new_v new_x $=$ old_x + dt \* new_v v[t, i] $=$ new_v x[t, i] $=$ new_x
Implementing TOI in this system is relative straightforward:
@ti.kernel def advance_toi(t: ti.i32): for i in range(n_objects): $\qquad \mathsf { s } \quad \mathsf { = }$ math.exp(-dt $\star$ damping) old_v = s \* v[t - 1, i] $^ +$ dt $\star$ gravity $\star$ ti.Vector([0.0, 1.0]) old_x $=$ x[t - 1, i] new_x $=$ old_x $^ +$ dt $\star$ old_v toi $\mathbf { \xi } = \mathbf { \xi } \odot . \Theta$ new_v $=$ old_v if new $\_ x [ 1 ] \ <$ ground_height and old_v[1] < -1e-4: # The 1e-4 safe guard is important for numerical stability toi $=$ -(old_x[1] - ground_height) / old_v[1] # Compute the time of impact new_ $. { } v = { }$ ti.Vector([0.0, 0.0]) # Note that with time of impact, dt is divided into two parts, # the first part using old_v, and second part using new_v new $\underline { { \boldsymbol { \mathsf { X } } } } \ = \ \mathsf { o l d } _ { - } \mathsf { { X } } \ +$ toi $\star$ old_v $^ +$ (dt - toi) $\star$ new_v v[t, i] $=$ new_v x[t, i] $=$ new_x In rigid body simulation, the implementation follows the same idea yet is slightly more complex. Please refer to rigid_body.py for more details.
# G ADDITIONAL TIPS ON GRADIENT BEHAVIORS
Initialization matters: flat lands and local minima in physical processes A trivial example of objective flat land is in billiards. Without proper initialization, gradient descent will make no progress since gradients are zero (Fig. 11). Also note the local minimum near $\left( - 5 , 0 . 0 3 \right)$ .
 Figure 11: Left: Scanning initial velocity in the billiard example. Middle: Most initial angles yield a flat objective (final distance between the blue ball and black destination) of 0.065, since the white ball does not collide with any other balls and imposes no effect on the pink ball via the chain reaction. Right: A zoomed-in view of the middle figure. The complex collisions lead to a lot of local minimums. [Reproduce: python3 billiards.py 1.0/0.23]
In mass_spring and rigid_body, once the robot falls down, gradient descent will quickly become trapped. A robot on the ground will make no further progress, no matter how it changes its controller. This leads to a more non-trivial local minimum and zero gradient case.
Ideal physical models are only “ideal”: discontinuities and singularities Real-world macroscopic physical processes are usually continuous. However, building upon ideal physical models, even in the forward physical simulation results can contain discontinuities. For example, in a rigid body model with friction, changing the initial rotation of the box can lead to different corners hitting the ground first, and result in a discontinuity (Fig. 12). In electric and mass_spring, due to the $\textstyle { \frac { 1 ^ { - } } { r ^ { 2 } } }$ and $\textstyle { \frac { 1 } { r } }$ terms, when $r 0$ , gradients can be very inaccurate due to numerical precision issues. Note that $\dot { d } ( 1 / r ) / d r = - 1 / r ^ { 2 }$ , and the gradient is more numerically problematic than the primal for a small $r$ . Safeguarding $r$ is critically important for gradient stability.
 Figure 12: Friction in rigid body with collision is a common source of discontinuity. In this scene a rigid body hits the ground. Slightly rotating the rigid body changes which corner (A/B) hits the ground first, and different normal/friction impulses will be applied to the rigid body. This leads to a discontinuity in its final position $\mathrm { l o s s } \mathrm { = }$ final y coordinate). [Reproduce: python3 rigid_body_discontinuity.py] Please see our supplemental video for more details.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289# CHARACTERIZING ADVERSARIAL SUBSPACES USING LOCAL INTRINSIC DIMENSIONALITY
Xingjun $\mathbf { M } \mathbf { a } ^ { 1 }$ , $\mathbf { B o L i } ^ { 2 }$ , Yisen Wang3, Sarah M. Erfani1, Sudanthi Wijewickrema1 Grant Schoenebeck4, Dawn $\mathbf { S o n g ^ { \bar { 2 } } }$ , Michael E. Houle5, James Bailey1 1The University of Melbourne, Parkville, Australia 2University of California, Berkeley, USA 3Tsinghua University, Beijing, China 4University of Michigan, Ann Arbor, USA 5National Institute of Informatics, Tokyo, Japan
# ABSTRACT
Deep Neural Networks (DNNs) have recently been shown to be vulnerable against adversarial examples, which are carefully crafted instances that can mislead DNNs to make errors during prediction. To better understand such attacks, a characterization is needed of the properties of regions (the so-called ‘adversarial subspaces’) in which adversarial examples lie. We tackle this challenge by characterizing the dimensional properties of adversarial regions, via the use of Local Intrinsic Dimensionality (LID). LID assesses the space-filling capability of the region surrounding a reference example, based on the distance distribution of the example to its neighbors. We first provide explanations about how adversarial perturbation can affect the LID characteristic of adversarial regions, and then show empirically that LID characteristics can facilitate the distinction of adversarial examples generated using state-of-the-art attacks. As a proof-of-concept, we show that a potential application of LID is to distinguish adversarial examples, and the preliminary results show that it can outperform several state-of-the-art detection measures by large margins for five attack strategies considered in this paper across three benchmark datasets . Our analysis of the LID characteristic for adversarial regions not only motivates new directions of effective adversarial defense, but also opens up more challenges for developing new attacks to better understand the vulnerabilities of DNNs.
# 1 INTRODUCTION
Deep Neural Networks (DNNs) are highly expressive models that have achieved state-of-the-art performance on a wide range of complex problems, such as speech recognition (Hinton et al., 2012) and image classification (Krizhevsky et al., 2012). However, recent studies have found that DNNs can be compromised by adversarial examples (Szegedy et al., 2013; Goodfellow et al., 2014; Nguyen et al., 2015). These intentionally-perturbed inputs can induce the network to make incorrect predictions at test time with high confidence, even when the examples are generated using different networks (Liu et al., 2016; Carlini & Wagner, 2017b; Papernot et al., 2016b). The amount of perturbation required is often small, and (in the case of images) imperceptible to human observers. This undesirable property of deep networks has become a major security concern in real-world applications of DNNs, such as self-driving cars and identity recognition (Evtimov et al., 2017; Sharif et al., 2016). In this paper, we aim to further understand adversarial attacks by characterizing the regions within which adversarial examples reside.
Each adversarial example can be regarded as being surrounded by a connected region of the domain (the ‘adversarial region’ or ‘adversarial subspace’) within which all points subvert the classifier in a similar way. Adversarial regions can be defined not only in the input space, but also with respect to the activation space of different DNN layers (Szegedy et al., 2013). Developing an understanding of the properties of adversarial regions is a key requirement for adversarial defense. Under the assumption that data can be modeled in terms of collections of manifolds, several works have attempted to characterize the properties of adversarial subspaces, but no definitive method yet exists which can reliably discriminate adversarial regions from those in which normal data can be found. Szegedy et al. (2013) argued that adversarial subspaces are low probability regions (not naturally occurring) that are densely scattered in the high dimensional representation space of DNNs. However, a linear formulation argues that adversarial subspaces span a contiguous multidimensional space, rather than being scattered randomly in small pockets (Goodfellow et al., 2014; Warde-Farley et al., 2016). Tanay & Griffin (2016) further emphasize that adversarial subspaces lie close to (but not on) the data submanifold. Similarly, it has also been found that the boundaries of adversarial subspaces are close to legitimate data points in adversarial directions, and that the higher the number of orthogonal adversarial directions of these subspaces, the more transferable they are to other models (Tramer\` et al., 2017). To summarize, with respect to the manifold model of data, the known properties of adversarial subspaces are: (1) they are of low probability, (2) they span a contiguous multidimensional space, (3) they lie off (but are close to) the data submanifold, and (4) they have class distributions that differ from that of their closest data submanifold.
 Figure 1: This example shows how density measures can fail to characterize the spatial properties of adversarial regions. The Gaussian kernel with bandwidth 0.2 is used for KD.
Among adversarial defense/detection techniques, Kernel Density (KD) estimation has been proposed as a measure to identify adversarial subspaces (Feinman et al., 2017). Carlini & Wagner (2017a) demonstrated the usefulness of KD-based detection, taking advantage of the low probability density generally associated with adversarial subspaces. However, in this paper we will show that kernel density is not effective for the detection of some forms of attack. In addition to kernel density, there are other density-based measures, such as the number of nearest neighbors within a fixed distance, and the mean distance to the $k$ nearest neighbors ( $k$ -mean distance). Again, these measures have limitations for the characterization of local adversarial regions. For example, in Figure 1 the three density measures fail to differentiate an adversarial example (red star) from a normal example (black cross), as the two examples are locally surrounded by the same number of neighbors (50), and have the same $k$ -mean distance $\mathrm { \ K M = } 0 . 1 9$ ) and kernel density $( \mathrm { K D = } 0 . 9 2$ ).
As an alternative to density measures, Figure 1 leads us to consider expansion-based measures of intrinsic dimensionality as a potentially effective method of characterizing adversarial examples. Expansion models of dimensionality assess the local dimensional structure of the data — such models have been successfully employed in a wide range of applications, such as manifold learning, dimension reduction, similarity search and anomaly detection (Amsaleg et al., 2015; Houle, 2017a). Although earlier expansion models characterize intrinsic dimensionality as a property of data sets, the Local Intrinsic Dimensionality (LID) fully generalizes this concept to the local distance distribution from a reference point to its neighbors (Houle, 2017a;b) — the dimensionality of the local data submanifold in the vicinity of the reference point is revealed by the growth characteristics of the cumulative distribution function. In this paper, we use LID to characterize the intrinsic dimensionality of adversarial regions, and attempt to test how well the estimates of LID can be used to distinguish adversarial examples. Note that the main goal of LID is to characterize properties of adversarial examples, instead of being applied as a pure defense method, which requires stronger assumptions on the current threat model. In Figure 1, the estimated LID of the adversarial example $( \mathrm { L I D } \approx 4 . 3 6 )$ is much higher than that of the referenced normal data sample $( \mathrm { L I D } \approx 1 . 5 3 ) $ , illustrating that the estimated LID can efficiently capture the intrinsic dimensional properties of adversarial regions. In this paper, we aim to study the LID properties of adversarial examples generated using state-of-the-art attack methods. In particular, our contributions are:
• We propose LID for the characterization of adversarial regions of deep networks. We discuss how adversarial perturbation can affect the LID characteristics of an adversarial region, and empirically show that the characteristics of test examples can be estimated effectively using a minibatch of training data. • Our study reveals that the estimated LID of adversarial examples considered in this paper1 is significantly higher than that of normal data examples, and that this difference becomes more pronounced in deeper layers of DNNs. We empirically demonstrate that the LID characteristics of adversarial examples generated using five state-of-the-art attack methods can be easily discriminated from those of normal examples, and provide a baseline classifier with features based on LID estimates that generally outperforms several existing detection measures on five attacks across three benchmark datasets. Though the adversarial examples considered here are not guaranteed to be the strongest with careful parameter tuning, these preliminary results firmly demonstrate the usefulness of LID measurement. • We show that the adversarial regions generated by different attacks share similar dimensional properties, in that LID characteristics of a simple attack can potentially be used to detect other more complex attacks. We also show that a naive LID-based detector is robust to the normal low confidence Optimization-based attack of (Carlini & Wagner, 2017a).
# 2 RELATED WORK
In this section, we briefly review the state of the art in both adversarial attack and adversarial defense.
Adversarial Attack: A wide range of approaches have been proposed for the crafting of adversarial examples to compromise the performance of DNNs; here, we mention a selection of such works. The Fast Gradient Method (FGM) (Goodfellow et al., 2014) directly perturbs normal input by a small amount along the gradient direction. The Basic Iterative Method (BIM) is an iterative version of FGM (Kurakin et al., 2016). One variant of BIM stops immediately once misclassification has been achieved with respect to the training set (BIM-a), and another iterates a fixed number of steps (BIM-b). For image sets, the Jacobian-based Saliency Map Attack (JSMA) iteratively selects the two most effective pixels to perturb based on the adversarial saliency map, repeating the process until misclassification is achieved (Papernot et al., 2016c). The Optimization-based attack (Opt), arguably the most effective to date, addresses the problem via an optimization framework (Liu et al., 2016; Carlini & Wagner, 2017b).
Adversarial Defense: A number of defense techniques have been introduced, including adversarial training (Goodfellow et al., 2014), distillation (Papernot et al., 2016d), gradient masking (Gu & Rigazio, 2014), and feature squeezing (Xu et al., 2017). However, these defenses can generally be evaded by Opt attacks, either wholly or partially (Carlini & Wagner, 2017a; He et al., 2017; Li & Vorobeychik, 2014; 2015). Given the inherent challenges for adversarial defense, recent works have instead focused on detecting adversarial examples. These works attempt to discriminate adversarial examples (positive class) from both normal and noisy examples (negative class), based on features extracted from different layers of a DNN. Detection subnetworks based on activations (Metzen et al., 2017), a cascade detector based on the PCA projection of activations (Li & Li, 2016), an augmented neural network detector based on statistical measures, a learning framework that covers unexplored space in vulnerable models (Rouhani et al., 2017; 2018), a logistic regression detector based on KD, and Bayesian Uncertainty (BU) features (Grosse et al., 2017) are a few such works. However, a recent study by Carlini & Wagner (2017a) has shown that these detection methods can be vulnerable to attack as well.
# 3 LOCAL INTRINSIC DIMENSIONALITY
In the theory of intrinsic dimensionality, classical expansion models (such as the expansion dimension and generalized expansion dimension (Karger & Ruhl, 2002; Houle et al., 2012)) measure the rate of growth in the number of data objects encountered as the distance from the reference sample increases. As an intuitive example, in Euclidean space, the volume of an $m$ -dimensional ball grows proportionally to $r ^ { m }$ , when its size is scaled by a factor of $r$ . From this rate of volume growth with distance, the expansion dimension $m$ can be deduced as:
$${ \frac { V _ { 2 } } { V _ { 1 } } } = \left( { \frac { r _ { 2 } } { r _ { 1 } } } \right) ^ { m } \Rightarrow m = { \frac { \ln ( V _ { 2 } / V _ { 1 } ) } { \ln ( r _ { 2 } / r _ { 1 } ) } } .$$
By treating probability mass as a proxy for volume, classical expansion models provide a local view of the dimensional structure of the data, as their estimation is restricted to a neighborhood around the sample of interest. Transferring the concept of expansion dimension to the statistical setting of continuous distance distributions leads to the formal definition of LID (Houle, 2017a).
Definition 1 (Local Intrinsic Dimensionality).
Given a data sample $x \in X$ , let $R > 0$ be a random variable denoting the distance from x to other data samples. If the cumulative distribution function $F ( r )$ of $R$ is positive and continuously differentiable at distance $r > 0$ , the LID of $x$ at distance $r$ is given by:
$$\mathbf { L I D } _ { F } ( r ) \triangleq \operatorname* { l i m } _ { \epsilon 0 } \frac { \ln \big ( F ( ( 1 + \epsilon ) \cdot r ) / F ( r ) \big ) } { \ln ( 1 + \epsilon ) } = \frac { r \cdot F ^ { \prime } ( r ) } { F ( r ) } ,$$
whenever the limit exists.
$F ( r )$ is analogous to the volume $V$ in Equation (1); however, we note that the underlying distance measure need not be Euclidean. The last equality of Equation (2) follows by applying L’Hopital’s ˆ rule to the limits (Houle, 2017a). The local intrinsic dimension at $x$ is in turn defined as the limit, when the radius $r$ tends to zero:
$$\mathrm { L I D } _ { F } = \operatorname * { l i m } _ { r \to 0 } \mathrm { L I D } _ { F } ( r ) .$$
$\mathrm { L I D } _ { F }$ describes the relative rate at which its cumulative distance function $F ( r )$ increases as the distance $r$ increases from 0, and can be estimated using the distances of $x$ to its $k$ nearest neighbors within the sample (Amsaleg et al., 2015).
In the ideal case where the data in the vicinity of $x$ is distributed uniformly within a submanifold, $\mathrm { L I D } _ { F }$ equals the dimension of the submanifold; however, in general these distributions are not ideal, the manifold model of data does not perfectly apply, and $\mathrm { L I D } _ { F }$ is not an integer. Nevertheless, the local intrinsic dimensionality does give a rough indication of the dimension of the submanifold containing $x$ that would best fit the data distribution in the vicinity of $x$ . We refer readers to Houle (2017a;b) for more details concerning the LID model.
Estimation of LID: According to the branch of statistics known as extreme value theory, the smallest $k$ nearest neighbor distances could be regarded as extreme events associated with the lower tail of the underlying distance distribution. Under very reasonable assumptions, the tails of continuous probability distributions converge to the Generalized Pareto Distribution (GPD), a form of powerlaw distribution (Coles et al., 2001). From this, Amsaleg et al. (2015) developed several estimators of LID to heuristically approximate the true underlying distance distribution by a transformed GPD; among these, the Maximum Likelihood Estimator (MLE) exhibited a useful trade-off between statistical efficiency and complexity. Given a reference sample $x \sim \mathcal { P }$ , where $\mathcal { P }$ represents the data distribution, the MLE estimator of the LID at $x$ is defined as follows:
$$\widehat { \mathrm { L I D } } ( x ) = - \Bigg ( \frac { 1 } { k } \sum _ { i = 1 } ^ { k } \log \frac { r _ { i } ( x ) } { r _ { k } ( x ) } \Bigg ) ^ { - 1 } .$$
Here, $r _ { i } ( x )$ denotes the distance between $x$ and its $i$ -th nearest neighbor within a sample of points drawn from $\mathcal { P }$ , where $r _ { k } ( x )$ is the maximum of the neighbor distances. In practice, the sample set is drawn uniformly from the available training data (omitting $x$ itself), which itself is presumed to have been randomly drawn from $\mathcal { P }$ . We emphasize that the LID defined in Equation (3) is a theoretical quantity, and that $\widehat { \mathrm { L I D } }$ as defined in Equation (4) is its estimate. In the remainder of this paper, we will refer to Equation (4) to calculate LID estimates.
# 4 CHARACTERIZING ADVERSARIAL REGIONS
Our aim is to gain a better understanding of adversarial regions, and thereby derive potential defenses and provide new directions for more efficient attacks. We begin by providing some motivation with respect to the manifold model of data as to how adversarial perturbation might affect the LID characteristic of adversarial regions. We then show how a detector can potentially be designed using LID estimates to discriminate between adversarial and normal examples.
LID of Adversarial Subspaces: Consider a sample $x \in X$ lying within a data submanifold $S$ , where $X$ is a randomly sampled dataset from $\mathcal { P }$ consisting only of normal (unperturbed) examples. Adversarial perturbation of $x$ typically results in a new sample $x ^ { \prime }$ whose coordinates differ from those of $x$ by very small amounts. Assuming that $x ^ { \prime }$ is indeed a successful adversarial perturbation of $x$ , the theoretical LID value associated with $x$ is simply the dimension of $S$ , whereas the theoretical LID value associated with $x ^ { \prime }$ is the dimension of the adversarial subspace within which it resides. Recent work in Amsaleg et al. (2017) shows that the magnitude of the perturbation required to make changes in the expected nearest neighbor ranking tends to zero as the LID and the data sample size tend to infinity.
Since perturbation schemes generally allow the modification of all data coordinates, they exploit the full degrees of freedom afforded by the representational dimension of the data domain. As pointed out by (Goodfellow et al., 2014; Warde-Farley et al., 2016; Tanay & Griffin, 2016), $x ^ { \prime }$ is very likely to lie outside $S$ (but very close to $S$ — in a high-dimensional contiguous space). In applications involving high-dimensional data, the representational dimension is typically far larger than the intrinsic dimension of any given data submanifold, which implies that the theoretical LID of $x ^ { \prime }$ is far greater than that of $x$ .
In practice, however, the values of LID must be estimated from local data samples. This is typically done by applying an appropriate estimator (such as the MLE estimator shown in Equation (4)) to a $k$ -nearest neighborhood of the test samples, for some appropriate fixed choice of $k$ . Typically, $k$ is chosen large enough for the estimation to stabilize, but not so large that the sample is no longer local to the test sample. If the dimension of $S$ is reasonably low, one can expect the estimation of the LID of $x$ to be reasonably accurate.
For the adversarial subspace, the samples appearing in the neighborhood of $x ^ { \prime }$ can be expected to be drawn from more than one manifold. The proximity of $x ^ { \prime }$ to $S$ means that the neighborhood is likely to contain neighbors lying in $S$ ; however, if the neighborhood were composed mostly of samples drawn from $S$ , $x ^ { \prime }$ would not likely be an adversarial example. Thus, the neighbors of $x ^ { \prime }$ taken together are likely to span a subspace of intrinsic dimensionality much higher than any of these submanifolds considered individually, and the LID estimate computed for $x ^ { \prime }$ can be expected to reveal this.
Efficiency through Minibatch Sampling: Computing neighborhoods with respect to the entirety of the dataset $X$ can be prohibitively expensive, particularly when the (global) intrinsic dimensionality of $X$ is too high to support efficient indexing. For this reason, when $X$ is large, the computational cost can be reduced by estimating the LID of an adversarial example $x ^ { \prime }$ from its $k$ -nearest neighbor set within a randomly-selected sample (minibatch) of the dataset $X$ . Since the LID estimation model regards the distances from $x ^ { \prime }$ to the members of $X$ as determined by independently-drawn samples from a distribution $\mathcal { P }$ , the estimator can also be applied to the distances induced by any random minibatch, as it too would be drawn independently from the same distribution $\mathcal { P }$ .
Provided that the minibatch is chosen sufficiently large so as to ensure that the $k$ -nearest neighbor sets remain in the vicinity of $x ^ { \prime }$ , estimates of LID computed for $x ^ { \prime }$ within the minibatch would resemble those computed within the full dataset $X$ . Conversely, as the size of the minibatch is reduced, the variance of the estimates would increase. However, if the gap between the true LID values of $x$ and $x ^ { \prime }$ is sufficiently large, even an extremely small minibatch size and / or small neighborhood size could conceivably produce estimates whose difference is sufficient to reveal the adversarial nature of $x ^ { \prime }$ . As we shall show in Section 5.2, discrimination between adversarial and non-adversarial examples turns out to be possible even for minibatch sizes as small as 100, and for neighborhood sizes as small as 20.
Using LID to Characterize Adversarial Examples: We next describe how LID estimates can serve as features to train a detector to distinguish adversarial examples. Note that here we only aim to train a baseline classifier to demonstrate how well LID can characterize adversarial examples. Robust detection taking different attack variations into account, such as attack confidence, will be left as future work. Our methodology requires that training sets be comprised of three types of examples: adversarial, normal and noisy. This replicates the methodology used in (Feinman et al., 2017; Carlini & Wagner, 2017a), where the rationale for including noisy examples is that DNNs are required to be robust to random input noise (Fawzi et al., 2016) and noisy inputs should not be identified as adversarial attacks. A classifier can be trained by using the training data to construct features for each sample, based on its LID within a minibatch of samples across different layers, where the class label is assigned positive for adversarial examples and assigned negative for normal and noisy examples.
Algorithm 1 describes how the LID features can be extracted for training an LID-based classifier. Given an initial training dataset and a DNN pre-trained on the initial training dataset, the algorithm outputs a classifier trained using LID features. As in previous studies (Carlini & Wagner, 2017a; Feinman et al., 2017), we assume that the initial training dataset is free of adversarial examples — that is, all examples in the dataset are considered ‘normal’ to begin with. The extraction of LID features first begins with the generation of adversarial and noisy counterparts to normal examples (step 3 and 4) in each minibatch. One minibatch of normal examples $( B _ { n o r m } )$ is used for generating 2 counterpart minibatches of examples: one adversarial $( B _ { a d v } )$ and one noisy $( B _ { n o i s y } )$ . The adversarial examples are generated using an adversarial attack on normal examples (step 3), while noisy examples are generated by adding random noise to normal examples, subject to the constraint that the magnitude of perturbation undergone by a noisy example is the same as the magnitude of perturbation undergone by its counterpart adversarial example (step 4). One minibatch of normal examples is converted to an equal number of adversarial examples after step 3, and an equal number of noisy examples after step 4.
The LID associated with each example (either normal, adversarial or noisy) is estimated from its $k$ nearest neighbors in the normal minibatch (steps 12-14), using Equation (4). For any new unknown test example, a minibatch consisting only of normal training examples is used to estimate LID. For each example and each transformation layer in the DNN, an LID estimate is calculated. The distance function needed for this estimate uses the activation values of the neurons in the given layer as inputs (step 7). As will be discussed in Section 5.2, we use all transformation layers, including conv2d, max-pooling, dropout, ReLU and softmax, since we expect adversarial regions to exist in each layer of the DNN representation space. The LID estimates associated with the example are then used as feature values (one feature for each transformation layer). Finally, a classifier (such as logistic regression) is trained using the LID features. Test examples can then be classified by the LID-based classifier to either the positive (adversarial) or negative (non-adversarial) class by means of its LID-based feature values.
# 5 EVALUATING LID-BASED CHARACTERIZATION OF ADVERSARIAL EXAMPLES
In this section, we evaluate the discrimination power of LID-based characterization against five adversarial attack strategies — FGM, BIM-a, BIM-b, JSMA, and Opt, as introduced in Section 2. These attack strategies were selected for our experiments due to their reported effectiveness and their diversity. For each of the 5 forms of attack, the LID detector is compared with the state-of-the-art detection measures KD and BU as discussed in Section 2, with respect to three benchmark image datasets: MNIST (LeCun et al., 1990), CIFAR-10 (Krizhevsky & Hinton, 2009) and SVHN (Netzer et al., 2011). Each of these three datasets is associated with a designated training set and test set. Before reporting and discussing the results, we first describe the experimental setup.
# Algorithm 1 Training phase for LID-based adversarial classifier
#
$X$ : a dataset of normal examples $H ( x )$ : a pre-trained DNN with $L$ transformation layers $k$ : the number of nearest neighbors for LID estimation
# Output:
Detector(LID) . a detector 1: $\mathrm { L I D } _ { n e g } { = } [ ]$ , $\mathrm { L I D } _ { p o s } { = } [ ]$ 2: for $B _ { n o r m }$ in $X$ do $\textsf { \textsf { D } } B _ { n o r m }$ : a minibatch of normal examples 3: $B _ { a d v } : =$ adversarial attack $B _ { n o r m }$ . $B _ { a d v }$ : a minibatch of adversarial examples 4: $B _ { n o i s y }$ : $: =$ add random noise to $B _ { n o r m }$ . $B _ { n o i s y }$ : a minibatch of noisy examples 5: N = |Bnorm| $\triangleright$ number of examples in $B _ { n o r m }$ 6: LIDnorm, LIDnoisy, $\mathrm { L I D } _ { n o i s y } = \mathrm { z e r o s } [ N , L ]$ 7: for $i$ in $[ 1 , L ]$ do 8: Anorm = Hi(Bnorm) $\triangleright i$ -th layer activations of $B _ { n o r m }$ 9: Aadv = Hi(Badv) $\triangleright i$ -th layer activations of $B _ { a d v }$ 10: $A _ { n o i s y } = H ^ { i } ( B _ { n o i s y } )$ ${ \triangleright } i$ -th layer activations of $B _ { n o i s y }$ 11: for $j$ in $[ 1 , N ]$ do 12: $\begin{array} { r } { \dot { \mathrm { L I D } _ { n o r m } } \dot { [ j , i ] } = - \Big ( \frac { 1 } { k } \sum _ { i = 1 } ^ { k } \log { \frac { r _ { i } ( A _ { n o r m } [ j ] , A _ { n o r m } ) } { r _ { k } ( A _ { n o r m } [ j ] , A _ { n o r m } ) } } \Big ) ^ { - 1 } } \end{array}$ 13: $\begin{array} { r } { \mathbf { L I D } _ { a d v } [ j , i ] = - \Big ( \frac { 1 } { k } \sum _ { i = 1 } ^ { k } \log \frac { r _ { i } ( A _ { a d v } [ j ] , A _ { n o r m } ) } { r _ { k } ( A _ { a d v } [ j ] , A _ { n o r m } ) } \Big ) ^ { - \frac { 1 } { \gamma _ { k } } } } \end{array}$ 1 14: LIDnoisy[j, i] = − 1k Pki=1 log ri(Anoisy[j],Anorm)rk(Anoisy[j],Anorm) 15: $\triangleright r _ { i } ( A [ j ] , A _ { n o r m } )$ : the $L _ { 2 }$ distance of $A _ { - } [ j ]$ to its $i$ -th nearest neighbor in $A _ { n o r m }$ 16: end for 17: end for 18: ${ \mathrm { L I D } } _ { n e g }$ .append $( \mathrm { L I D } _ { n o r m } )$ , ${ \mathrm { L I D } } _ { n e g }$ .append $( \mathrm { L I D } _ { n o i s y } )$ 19: $\mathrm { L I D } _ { p o s }$ .append $\mathrm { L I D } _ { a d v , }$ ) 20: end for 21: Detector $\left( \mathrm { L I D } \right) =$ train a classifier on $( \mathrm { L I D } _ { n e g } , \mathrm { L I D } _ { p o s } )$
# 5.1 EXPERIMENTAL SETUP
Training and Testing: For each of the three image datasets, a DNN classifier was independently pretrained on its designated training set (the pre-train set), and its designated test set was used for testing (the pre-test set). Any pre-test images not correctly classified were discarded, and the remaining images were subdivided into train $( 8 0 \% )$ and test $( 2 0 \% )$ sets for subsequent processing. Both of these sets were randomly partitioned into minibatches of size 100, for later use in the computation of LID characteristics.
The LID-, KD- and BU-based detectors were trained separately on the train set using the scheme in Algorithm 1, with the calculation of LID estimates replaced by KD and BU calculation for their respective detectors. All three detectors were then evaluated against equal numbers of normal, noisy and adversarial images crafted from members of the test set, as described in Steps 2-4 of Algorithm 1. The LID, KD and BU characteristics of those test images were then generated as shown in Steps 1- 19 of Algorithm 1. It should be noted that no images of the test set were examined during any of the training processes, so as to avoid cross contamination. The adversarial examples for both training and testing were generated by applying one of the five selected attacks. Following the procedure outlined in Feinman et al. (2017), the noisy examples for the JSMA attack were crafted by changing the values of a randomly-selected set of pixels to either their minimum or maximum (determined randomly), where the number of pixels to be adjusted was chosen to be equal to the number of pixels perturbed in the generation of adversarial examples. For the other attack strategies, $L _ { 2 }$ Gaussian noise was added to the pixel values instead of setting them to their minimum or maximum. As suggested by Feinman et al. (2017); Carlini & Wagner (2017a), we used the logistic regression classifier as detector, and report its AUC score as the metric for performance.
Deep Neural Networks for Pretraining: The pretrained DNN used for MNIST was a 5-layer ConvNet with max-pooling and dropout. It achieved $9 9 . 2 9 \%$ classification accuracy on (normal)
pre-test images. For CIFAR-10, a 12-layer ConvNet with max-pooling and dropout was used. This model reported an accuracy of $8 4 . 5 6 \%$ on (normal) pre-test images. For SVHN, we trained a 6-layer ConvNet with max-pooling and dropout. It achieved $9 2 . 1 8 \%$ accuracy on (normal) pre-test images. We deliberately did not tune the DNNs, as their performance was close to the state-of-the-art and could thus be considered sufficient for use in an adversarial study (Feinman et al., 2017).
Parameter Tuning: We tuned the bandwidth $( \sigma )$ parameter for KD, and the number of nearest neighbors $( k )$ for LID, using nested cross validation within the training set (train). Using the AUC values of detection performance, the bandwidth was tuned using a grid search over the range [0, 10) in log-space, and neighborhood size was tuned using a grid search over the range [10, 100) with respect to a minibatch of size 100. For a given dataset, the parameter setting selected was the one with highest AUC averaged across all attacks. The optimal bandwidths chosen for MNIST, CIFAR10 and SVHN were 3.79, 0.26, and 1.0, respectively, while the value of $k$ for LID estimation was set to 20 for MNIST and CIFAR-10, and 30 for SVHN. For BU, we chose the number of prediction runs to be $T = 5 0$ in all experiments. We did not tune this parameter, as it is not considered to be sensitive for choices of $T$ greater than 20 (Carlini & Wagner, 2017a).
Our implementation is based on the detection framework of Feinman et al. (2017). For FGM, JSMA, BIM-a, and BIM-b attack strategies, we used the cleverhans library (Papernot et al., 2016a), and for the Opt attack strategy, we used the author’s implementation (Carlini & Wagner, 2017b). We scaled all image feature values to the interval [0, 1]. Our code is available for download at https: //github.com/xingjunm/lid_adversarial_subspace_detection.
# 5.2 LID CHARACTERISTICS OF ADVERSARIAL EXAMPLES
We provide empirical results showing the LID characteristics of adversarial examples generated by Opt, the most effective of the known attack strategies. The left subfigure in Figure 2 shows the LID scores (at the softmax layer) of 100 randomly selected normal, noisy and adversarial (Opt) examples from the CIFAR-10 dataset. We observe that at this layer, the LID scores of adversarial examples are significantly higher than those of normal or noisy examples. This supports our expectation that adversarial regions have higher intrinsic dimensionality than normal data regions (as discussed in Section 4). It also suggests that the transition from normal example to adversarial example may follow directions in which the complexity of the local data submanifold significantly increases, leading to an increase in estimated LID values.
In the right subfigure of Figure 2, we further show that the LID scores of adversarial examples are more easily discriminated from those of other examples at deeper layers of the network. The 12-layer ConvNet used for CIFAR-10 consists of 26 transformation layers: the input layer $( L _ { 0 } )$ , conv2d/max-pooling $( L _ { 1 - 1 7 } )$ , dense/dropout $( L _ { 1 8 - 2 4 } )$ and the final softmax layer $\left( L _ { 2 5 } \right)$ . The estimated LID characteristics of adversarial examples become distinguishable (detection $\mathrm { A U C } > 0 . 5 )$ at the dense layers $( L _ { 1 8 - 2 4 } )$ , and significantly different at the softmax layer $\left( L _ { 2 5 } \right)$ . This suggests that the fully-connected and softmax transformations may be more sensitive to adversarial perturbations than convolutional transformations. Plots of LID scores for the MNIST and SVHN datasets can be found in Appendix A.2.
With regard to the stability of performance based on parameter variation ( $k$ for LID, or bandwidth for KD), we can see from Figure 3 that LID is more stable than KD, exhibiting less variation in AUC as the parameter varies. From this figure, we also see that KD requires significantly different optimal settings for different types of data. For simpler datasets such as MNIST and SVHN, KD requires quite high bandwidth choices for best performance.
# 5.3 ANALYSIS OF LID PROPERTIES
LID Outperforms KD and BU: We compare the performance of LID-based detection with that of detectors trained with features of KD and BU individually, as well as a detector trained with a combination of KD and BU features (denoted as $\mathsf { \nabla \mathsf { K D + B U } } ^ { \mathsf { 5 } }$ ). As shown in Table 1, LID outperforms the KD and BU measures (both individually and combined) by large margins on all attack strategies tested, across all datasets tested. For the most effective attack strategy known to date, the Opt attack, the LID-based detector achieved AUC scores of $9 9 . 2 4 \%$ , $9 8 . 9 4 \mathrm { \bar { / } } _ { 0 }$ and $9 7 . 6 0 \%$ on MNIST, CIFAR-10 and SVHN respectively, compared to AUC scores of $9 5 . 3 5 \%$ , $9 3 . 7 7 \%$ and $9 0 . 6 6 \%$ for the detector based on KD and BU. This strong performance suggests that LID is a highly promising characteristic for the discrimination of adversarial examples and regions. We also note that KD was not effective for the FGM, JSMA and BIM-a attack strategies, whereas the BU measure failed to detect most FGM and BIM- $\mathbf { \sigma } . \mathbf { b }$ attacks on the MNIST dataset.
 Figure 2: The left-hand figure shows the LID scores (at the softmax layer) of 100 normal (blue), noisy (green), and Opt attack (red $\mathbf { X }$ -cross) examples from the CIFAR-10 dataset. The scores have been scaled to the interval [0,1] using min-max normalization. The blue and green lines appear superimposed due to similarities in the LID scores for normal and noisy examples. The right-hand figure shows the detection performance (AUC) based on LID scores computed at different layers. $L _ { i }$ denotes the $i$ -th transformation layer.
 Figure 3: Top row: tuning bandwidth $\sigma$ for KD using a grid search over the range [0, 10) in logspace, separately for each dataset. Bottom row: tuning $k$ for LID using a grid search over the range [10, 100) for minibatch size 100, separately for each dataset. The vertical dashed lines denote the selected parameter choice.
Generalizability Analysis: It is natural to consider the question of whether samples of one attack strategy may be detected by a model that has been trained on samples of a different attack strategy. We conduct a preliminary investigation of this issue by studying the generalizability of KD, BU and LID for detecting previously unseen attack strategies on the CIFAR-10 dataset. The KD, BU and LID detectors are trained on samples of the simplest attack strategy, FGM, and then tested on samples of the more complex attacks BIM-a, BIM-b, JSMA and Opt. The training and test datasets are generated in the same way as in our previous experiments with only the FGM attack applied on the train set while the other attacks applied separately on the test set. The test attack data is standardized by scaling so as to fit the training data. The results are shown in Table 2, from which we see that the LID detector trained on FGM can accurately detect the much more complex attacks of the other strategies. The KD and BU characteristics can also achieve good performance on this transfer learning task, but are less consistent than our proposed LID characteristic. The results appear to indicate that the adversarial regions generated by different attack strategies possess similar dimensional properties.
Table 1: A comparison of the discrimination power (AUC score $( \% )$ of a logistic regression classifier) among LID, KD, BU, and $\mathrm { K D + B U }$ . The AUC score is computed for each attack strategy on each dataset, and the best results are highlighted in bold.
<table><tr><td>Dataset</td><td>Feature</td><td>FGM</td><td>BIM-a</td><td>BIM-b</td><td>JSMA</td><td>Opt</td></tr><tr><td rowspan="3">MNIST</td><td rowspan="3">KD BU KD+BU</td><td>78.12</td><td>98.14</td><td>98.61</td><td>68.77</td><td>95.15</td></tr><tr><td>32.37</td><td>91.55</td><td>25.46</td><td>88.74</td><td>71.30</td></tr><tr><td>82.43</td><td>99.20</td><td>98.81</td><td>90.12</td><td>95.35</td></tr><tr><td rowspan="4">CIFAR-10</td><td>LID KD</td><td>96.89 64.92</td><td>99.60 68.38</td><td>99.83 98.70</td><td>92.24 85.77</td><td>99.24 91.35</td></tr><tr><td>BU</td><td>70.53</td><td>81.60</td><td>97.32</td><td>87.36</td><td>91.39</td></tr><tr><td>KD+BU</td><td>70.40</td><td>81.33</td><td>98.90</td><td>88.91</td><td>93.77</td></tr><tr><td>LID</td><td>82.38</td><td>82.51</td><td>99.78</td><td>95.87</td><td>98.94</td></tr><tr><td rowspan="4">SVHN</td><td>KD</td><td>70.39</td><td>77.18</td><td>99.57</td><td>86.46</td><td>87.41</td></tr><tr><td>BU</td><td>86.78</td><td>84.07</td><td>86.93</td><td>91.33</td><td>87.13</td></tr><tr><td>KD+BU</td><td>86.86</td><td>83.63</td><td>99.52</td><td>93.19</td><td>90.66</td></tr><tr><td>LID</td><td>97.61</td><td>87.55</td><td>99.72</td><td>95.07</td><td>97.60</td></tr></table>
It is worth mentioning that the BU detector trained on the FGM attack generalizes poorly to detect BIM-b adversarial examples $( \mathrm { A U C } { = } 2 . 6 5 \%$ ). This may due to the fact that BIM-b performs a fixed number of perturbations (50 in our setting) that likely extend well beyond the classification boundary. Such perturbed adversarial examples tend to possess Bayesian model uncertainties even lower than normal examples under dropout randomization, as dropping out a certain proportion of their representations $5 0 \%$ in our setting) would not lead to high prediction variance. This is consistent with the results reported in Feinman et al. (2017): only $4 \%$ of BIM-b adversarial examples, in contrast to at least $7 4 . 7 \%$ of adversarial examples of other attack strategies, exhibit higher Bayesian uncertainties than normal examples. It is particularly interesting to see that detectors trained on the FGM attack strategy can sometimes achieve better performance when used to identify the other attacks. An extensive study of detection generalizability across all attack strategies is an interesting topic for future work.
Table 2: This table of AUC scores $( \% )$ shows the generalizability of detectors trained on the FGM attack strategy (row) to other forms of attack (column), with respect to the CIFAR-10 dataset. The best results are indicated in bold font.
<table><tr><td>Train</td><td>Test</td><td>FGM</td><td>BIM-a</td><td>BIM-b</td><td>JSMA</td><td>Opt</td></tr><tr><td rowspan="3">FGM</td><td>KD</td><td>64.92</td><td>69.15</td><td>89.71</td><td>85.72</td><td>91.22</td></tr><tr><td>BU</td><td>70.53</td><td>81.67</td><td>2.65</td><td>86.79</td><td>91.27</td></tr><tr><td>LID</td><td>82.38</td><td>82.30</td><td>91.61</td><td>89.93</td><td>93.32</td></tr></table>
Effect of Larger Minibatch Sizes in LID Estimation: In the estimation of LID values, a default minibatch size of 100 was used, with a view to ensuring efficiency. Even though experimental analysis has shown that the MLE estimator of LID is not stable on such small samples (Amsaleg et al., 2015), this is more than adequately compensated for by the learning process in LID-based detection, as evidenced by the superior performance shown in Table 1. However, it is an interesting question as to whether the use of larger minibatch sizes could further improve the performance (as measured by AUC) without incurring unreasonably high computational cost. Figure 5 in Appendix A.3 illustrates the effect of using a minibatch size of 1000 for different choices of $k$ . It does indicate that increasing the batch size can improve the detection performance even further. A comprehensive investigation of the tradeoffs among minibatch size, LID estimation accuracy, and detection performance is an interesting direction for future work.
Table 3: The failure rate $( \% )$ of an adaptive attack targeting the LID-based detector.
<table><tr><td></td><td>MNIST</td><td>CIFAR-10</td><td>SVHN</td></tr><tr><td>Scenario 1 (LID at all layers): Attack Failure Rate</td><td>100</td><td>100</td><td>100</td></tr><tr><td>Scenario 2 (LID at one layer): Attack Failure Rate</td><td>100</td><td>95.7</td><td>97.2</td></tr></table>
Adaptive Attack Against LID Measurement: To further evaluate the robustness of our LIDbased detector, we applied an adaptive Opt attack in a white-box setting. Similar to the strategy used in Carlini & Wagner (2017a) to attack the KD-based detector, we used an $\mathrm { O p t } L _ { 2 }$ attack with a modified adversarial objective:
$$\mathrm { m i n i m i z e } \ \| x - x _ { a d v } \| _ { 2 } ^ { 2 } + \alpha \cdot \left( \ell ( x _ { a d v } ) + \ell ( \mathrm { L I D } ( x _ { a d v } ) ) \right)$$
where $\alpha$ is a constant balancing between the amount of perturbation and the adversarial strength, and the LID scores are computed at the pre-softmax layer.
We test two different scenarios for detection. In the first scenario, we use LID features as described in Algorithm 1. In the second scenario, we use LID scores only at the pre-softmax layer. Since the Opt attack uses only the pre-softmax activation output to guide the perturbation, the latter scenario allows a fair comparison to be made (Carlini & Wagner, 2017b;a). The optimal constant $\alpha$ is determined via an internal binary search for $\alpha \in [ 1 0 ^ { - 3 } , 1 0 ^ { 6 } ]$ . The rationale for the minimization of the LID characteristic in Equation (5) is that adversarial examples have higher LID characteristics than normal examples, as we have demonstrated in Section 5.2.
We applied the adaptive attack on 1000 normal images randomly chosen from the detection test set (test). The deep networks used were the same ConvNet configurations as used in our previous experiments. To evaluate attack performance, instead of AUC as measured in the previous sections, we report accuracy as suggested by Carlini & Wagner (2017a). We see from Table 3 that the adaptive attack in Scenario 2 fails to find any valid adversarial example $1 0 0 \%$ , $9 5 . 7 \%$ and $9 7 . 2 \%$ of the time on MNIST, CIFAR-10 and SVHN respectively. In addition, when trained on all transformation layers (Scenario 1), the LID-based detector still correctly detected the attacks $1 0 0 \%$ of the time. Based on these results, we can conclude that integrating LID into the adversarial objective (increasing the complexity of the attack) does not make detection more difficult for our method. This is in contrast to the work of Carlini & Wagner (2017a), who showed that incorporating kernel density into the objective function makes detection substantially more difficult for the KD method.
# 6 DISCUSSION AND CONCLUSION
In this paper, we have addressed the challenge of understanding the properties of adversarial regions, particularly with a view to detecting adversarial examples. We characterized the dimensional properties of adversarial regions via the use of Local Intrinsic Dimensionality (LID), and showed how these could be used as features in an adversarial example detection process. Our empirical results suggest that LID is a highly promising measure for the characterization of adversarial examples, one that can be used to deliver state-of-the-art discrimination performance. From a theoretical perspective, we have provided an initial intuition as to how LID is an effective method for characterizing adversarial attack, one which complements the recent theoretical analysis showing how increases in LID effectively diminish the amount of perturbation required to move a normal example into an adversarial region (with respect to 1-NN classification) (Amsaleg et al., 2017). Further investigation in this direction may lead to new techniques for both adversarial attack and defense.
In the learning process, the activation values at each layer of the LID-based detector can be regarded as a transformation of the input to a space in which the LID values have themselves been transformed. A full understanding of LID characteristics should take into account the effect of DNN transformations on these characteristics. This is a challenging question, since it requires a better understanding of the DNN learning processes themselves. One possible avenue for future research may be to model the dimensional characteristics of the DNN itself, and to empirically verify how they influence the robustness of DNNs to adversarial attacks.
Another open issue for future research is the empirical investigation of the effect of LID estimation quality on the performance of adversarial detection. As evidenced by the improvement in performance observed when increasing the minibatch size from 100 to 1000 (Figure 5 in Appendix A.3), it stands to reason that improvements in estimator quality or sampling strategies could both be beneficial in practice.
# ACKNOWLEDGMENTS
James Bailey is in part supported by the Australian Research Council via grant number DP170102472. Michael E. Houle is in part supported by JSPS Kakenhi Kiban (B) Research Grant 15H02753. Bo Li and Dawn Song are partially supported by Berkeley Deep Drive, the Center for Long-Term Cybersecurity, and FORCES (Foundations Of Resilient CybEr-Physical Systems), which receives support from the National Science Foundation (NSF award numbers CNS-1238959, CNS-1238962, CNS-1239054, CNS-1239166).
# REFERENCES
Laurent Amsaleg, Oussama Chelly, Teddy Furon, Stephane Girard, Michael E. Houle, Ken-ichi ´ Kawarabayashi, and Michael Nett. Estimating local intrinsic dimensionality. In SIGKDD, pp. 29–38. ACM, 2015.
Laurent Amsaleg, James Bailey, Dominique Barbe, Sarah Erfani, Michael E. Houle, Vinh Nguyen, and Milos Radovanovic. The vulnerability of learning to adversarial perturbation increases withˇ intrinsic dimensionality. In WIFS, 2017.
Nicholas Carlini and David Wagner. Adversarial examples are not easily detected: Bypassing ten detection methods. arXiv preprint arXiv:1705.07263, 2017a.
Nicholas Carlini and David Wagner. Towards evaluating the robustness of neural networks. In S&P, pp. 39–57, 2017b.
Stuart Coles, Joanna Bawa, Lesley Trenner, and Pat Dorazio. An introduction to statistical modeling of extreme values, volume 208. Springer, 2001.
Ivan Evtimov, Kevin Eykholt, Earlence Fernandes, Tadayoshi Kohno, Bo Li, Atul Prakash, Amir Rahmati, and Dawn Song. Robust physical-world attacks on machine learning models. arXiv preprint arXiv:1707.08945, 2017.
Alhussein Fawzi, Seyed-Mohsen Moosavi-Dezfooli, and Pascal Frossard. Robustness of classifiers: from adversarial to random noise. In NIPS, pp. 1632–1640, 2016.
Reuben Feinman, Ryan R. Curtin, Saurabh Shintre, and Andrew B Gardner. Detecting adversarial samples from artifacts. arXiv preprint arXiv:1703.00410, 2017.
Ian J. Goodfellow, Jonathon Shlens, and Christian Szegedy. Explaining and harnessing adversarial examples. arXiv preprint arXiv:1412.6572, 2014.
Kathrin Grosse, Praveen Manoharan, Nicolas Papernot, Michael Backes, and Patrick McDaniel. On the (statistical) detection of adversarial examples. arXiv preprint arXiv:1702.06280, 2017.
Shixiang Gu and Luca Rigazio. Towards deep neural network architectures robust to adversarial examples. arXiv preprint arXiv:1412.5068, 2014.
Warren He, James Wei, Xinyun Chen, Nicholas Carlini, and Dawn Song. Adversarial example defenses: Ensembles of weak defenses are not strong. arXiv preprint arXiv:1706.04701, 2017.
Geoffrey Hinton, Li Deng, Dong Yu, George E. Dahl, Abdel-rahman Mohamed, Navdeep Jaitly, Andrew Senior, Vincent Vanhoucke, Patrick Nguyen, Tara N. Sainath, and Brian Kingsbury. Deep neural networks for acoustic modeling in speech recognition: The shared views of four research groups. Signal Processing Magazine, 29(6):82–97, 2012.
Michael E. Houle. Local intrinsic dimensionality I: an extreme-value-theoretic foundation for similarity applications. In SISAP, pp. 64–79, 2017a.
Michael E. Houle. Local intrinsic dimensionality II: multivariate analysis and distributional support. In SISAP, pp. 80–95, 2017b.
Michael E. Houle, Hisashi Kashima, and Michael Nett. Generalized expansion dimension. In ICDMW, pp. 587–594, 2012.
David R. Karger and Matthias Ruhl. Finding nearest neighbors in growth-restricted metrics. In STOC, pp. 741–750. ACM, 2002.
Alex Krizhevsky and Geoffrey Hinton. Learning multiple layers of features from tiny images. 2009.
Alex Krizhevsky, Ilya Sutskever, and Geoffrey E. Hinton. Imagenet classification with deep convolutional neural networks. In NIPS, pp. 1097–1105, 2012.
Alexey Kurakin, Ian Goodfellow, and Samy Bengio. Adversarial examples in the physical world. arXiv preprint arXiv:1607.02533, 2016.
Yann LeCun, Bernhard E Boser, John S Denker, Donnie Henderson, Richard E Howard, Wayne E Hubbard, and Lawrence D Jackel. Handwritten digit recognition with a back-propagation network. In Advances in neural information processing systems, pp. 396–404, 1990.
Bo Li and Yevgeniy Vorobeychik. Feature cross-substitution in adversarial classification. In Advances in neural information processing systems, pp. 2087–2095, 2014.
Bo Li and Yevgeniy Vorobeychik. Scalable optimization of randomized operational decisions in adversarial classification settings. In Artificial Intelligence and Statistics, pp. 599–607, 2015.
Xin Li and Fuxin Li. Adversarial examples detection in deep networks with convolutional filter statistics. arXiv preprint arXiv:1612.07767, 2016.
Yanpei Liu, Xinyun Chen, Chang Liu, and Dawn Song. Delving into transferable adversarial examples and black-box attacks. arXiv preprint arXiv:1611.02770, 2016.
Jan Hendrik Metzen, Tim Genewein, Volker Fischer, and Bastian Bischoff. On detecting adversarial perturbations. arXiv preprint arXiv:1702.04267, 2017.
Yuval Netzer, Tao Wang, Adam Coates, Alessandro Bissacco, Bo Wu, and Andrew Y Ng. Reading digits in natural images with unsupervised feature learning. In NIPS workshop on deep learning and unsupervised feature learning, volume 2011, pp. 5, 2011.
Anh Nguyen, Jason Yosinski, and Jeff Clune. Deep neural networks are easily fooled: High confidence predictions for unrecognizable images. In CVPR, pp. 427–436, 2015.
Nicolas Papernot, Ian Goodfellow, Ryan Sheatsley, Reuben Feinman, and Patrick McDaniel. cleverhans v1. 0.0: an adversarial machine learning library. arXiv preprint arXiv:1610.00768, 2016a.
Nicolas Papernot, Patrick McDaniel, and Ian Goodfellow. Transferability in machine learning: from phenomena to black-box attacks using adversarial samples. arXiv preprint arXiv:1605.07277, 2016b.
Nicolas Papernot, Patrick McDaniel, Somesh Jha, Matt Fredrikson, Z. Berkay Celik, and Ananthram Swami. The limitations of deep learning in adversarial settings. In EuroS&P, pp. 372–387, 2016c.
Nicolas Papernot, Patrick McDaniel, Xi Wu, Somesh Jha, and Ananthram Swami. Distillation as a defense to adversarial perturbations against deep neural networks. In S&P, pp. 582–597, 2016d.
Bita Darvish Rouhani, Mohammad Samragh, Tara Javidi, and Farinaz Koushanfar. Curtail: Characterizing and thwarting adversarial deep learning. arXiv preprint arXiv:1709.02538, 2017.
Bita Darvish Rouhani, Mohammad Samragh, Tara Javidi, and Farinaz Koushanfar. Towards safe deep learning: Unsupervised defense against generic adversarial attacks, 2018.
Mahmood Sharif, Sruti Bhagavatula, Lujo Bauer, and Michael K Reiter. Accessorize to a crime: Real and stealthy attacks on state-of-the-art face recognition. In Proceedings of the 2016 ACM SIGSAC Conference on Computer and Communications Security, pp. 1528–1540, 2016.
Christian Szegedy, Wojciech Zaremba, Ilya Sutskever, Joan Bruna, Dumitru Erhan, Ian Goodfellow, and Rob Fergus. Intriguing properties of neural networks. arXiv preprint arXiv:1312.6199, 2013.
Thomas Tanay and Lewis Griffin. A boundary tilting persepective on the phenomenon of adversarial examples. arXiv preprint arXiv:1608.07690, 2016.
Florian Tramer, Nicolas Papernot, Ian Goodfellow, Dan Boneh, and Patrick McDaniel. The space \` of transferable adversarial examples. arXiv preprint arXiv:1704.03453, 2017.
David Warde-Farley, Ian Goodfellow, T. Hazan, G. Papandreou, and D. Tarlow. Adversarial perturbations of deep neural networks. Perturbations, Optimization, and Statistics, pp. 1–32, 2016.
Weilin Xu, David Evans, and Yanjun Qi. Feature squeezing: Detecting adversarial examples in deep neural networks. arXiv preprint arXiv:1704.01155, 2017.
# A APPENDIX
# A.1 STATISTICS OF ADVERSARIAL ATTACK STRATEGIES
Table 4: The $L _ { 2 }$ mean perturbation and model accuracy $( \% )$ on adversarial examples.
<table><tr><td rowspan="2"></td><td colspan="2">MNIST</td><td colspan="2">CIFAR</td><td colspan="2">SVHN</td></tr><tr><td>L2</td><td>Acc.</td><td>L2</td><td>Acc.</td><td>L2</td><td>Acc.</td></tr><tr><td>FGM</td><td>6.26</td><td>11.09</td><td>2.74</td><td>3.15</td><td>7.09</td><td>6.17</td></tr><tr><td>BIM-a</td><td>2.30</td><td>10.43</td><td>0.48</td><td>0.00</td><td>0.83</td><td>0.13</td></tr><tr><td>BIM-b</td><td>5.42</td><td>10.42</td><td>3.39</td><td>0.00</td><td>5.53</td><td>0.13</td></tr><tr><td>JSMA</td><td>5.40</td><td>10.00</td><td>3.64</td><td>0.04</td><td>3.09</td><td>0.16</td></tr><tr><td>Opt</td><td>4.21</td><td>3.92</td><td>0.37</td><td>0.01</td><td>0.59</td><td>0.26</td></tr></table>
# A.2 LID CHARACTERISTICS OF ADVERSARIAL EXAMPLES
Figure 4 illustrates LID characteristics of the most effective attack strategy known to date, Opt, on the MNIST and SVHN datasets. On both datasets, the LID scores of adversarial examples are significantly higher than those of normal or noisy examples. In the right-hand plot, the LID scores of normal examples and its noisy counterparts appear superimposed due to their similarities.
 Figure 4: The plots show the normalized LID scores of 100 randomly selected normal (blue), noisy (green) and Opt attack (red $\mathbf { X }$ -cross) examples. The noisy and adversarial examples were generated from the normal examples. The left-hand plot shows the scores (at the pre-softmax layer) of MNIST examples, while the right-hand plot shows LID scores (at the softmax layer) of SVHN examples. Normal and noisy example curves appear superimposed in the right-hand figure due to the similarity of their values.
Figure 5 shows the discrimination power (detection AUC) of LID characteristics estimated using two different minibatch sizes: the default setting of 100, and a larger size of 1000. The horizontal axis represents different choices of the neighborhood size $k$ , from $\bar { 1 } 0 \%$ to $9 0 \%$ percent to the batch size. We note that the peak AUC is higher for the larger minibatch size.
 Figure 5: The detection AUC score of LID estimated using different neighborhood sizes $k$ with a larger minibatch size of 1000. The results are shown for the detection of Opt attacks on the MNIST, CIFAR-10 and SVHN datasets.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600# FEATURE SELECTION USING STOCHASTIC GATES
Anonymous authors Paper under double-blind review
# ABSTRACT
Feature selection problems have been extensively studied in the setting of linear estimation, for instance LASSO, but less emphasis has been placed on feature selection for non-linear functions. In this study, we propose a method for feature selection in non-linear function estimation problems. The new procedure is based on directly penalizing the $\ell _ { 0 }$ norm of features, or the count of the number of selected features. Our $\ell _ { 0 }$ based regularization relies on a continuous relaxation of the Bernoulli distribution, which allows our model to learn the parameters of the approximate Bernoulli distributions via gradient descent. The proposed framework simultaneously learns a non-linear regression or classification function while selecting a small subset of features. We provide an information-theoretic justification for incorporating Bernoulli distribution into our approach. Furthermore, we evaluate our method using synthetic and real-life data and demonstrate that our approach outperforms other embedded methods in terms of predictive performance and feature selection.
# 1 INTRODUCTION
Feature selection is a fundamental task in machine learning and statistics. Feature selection leads to a number of potential benefits: reducing experimental costs Min et al. (2014), enhancing interpretability (Ribeiro et al., 2016), computational speed up and even improving model generalization on unseen data (Chandrashekar & Sahin, 2014). In biomedicine, scientists collect multitude datasets comprising of many biomarkers (e.g., genes or proteins) that require development of effective diagnostics or prognostics models. For instance, in Genome wide association studies (GWAS), feature selection can help identify such models and lead to improved risk assessment and reduced cost.
Feature selection methods may be classified into three major categories: filter methods, wrapper methods, and embedded methods. Filter methods attempt to remove irrelevant features prior to learning a model. These methods filter features using a per-feature relevance score that is created based on some statistical measure (Battiti, 1994; Peng et al., 2005; Estévez et al., 2009; Song et al., 2007; 2012; Chen et al., 2017). Wrapper methods (Kohavi & John, 1997b; Stein et al., 2005; Zhu et al., 2007; Reunanen, 2003; Allen, 2013) use the outcome of a classifier to determine the relevance of each feature, which requires recomputing the classifier for each subset of features. This becomes computationally expensive for neural network based wrapper methods (Verikas & Bacauskiene, 2002; Kabir et al., 2010; Roy et al., 2015).
Embedded methods aim to remove this burden by learning the model while simultaneously selecting the subset of relevant features. The Least Absolute Shrinkage and Selection Operator (LASSO) (Tibshirani, 1996) is a well-known embedded method, whose objective is to minimize the loss while enforcing an $\ell _ { 1 }$ constraint on the weights of the features. Although LASSO is scalable and widely used (Hans, 2009; Li et al., 2011; 2006), it is restricted to the domain of linear functions. To allow the model to capture nonlinear interaction, it is appealing to consider the non-convex extension of the LASSO formulation using neural networks.
We develop a fully embedded feature selection method for nonlinear models. To the best of our knowledge it is the first $\ell _ { 0 }$ embedded feature selection method. Our method improves upon the LASSO formulation in two aspects: a) it captures nonlinear interactions between the features via neural network modeling and b) it employs an $\ell _ { 0 }$ -like regularization using gates whose weights are parametrized by a smooth variant of a Bernoulli distribution. Altogether these twofold improvements are formulated as a fully differentiable neural network. Specifically, our contributions are as follows:
1. By utilizing a recent development of continuous and differentiable approximation to discrete distributions (Maddison et al., 2016), (Jang et al., 2017), (Louizos et al., 2017), we introduce a solution to the long standing problem of feature selection with an $\ell _ { 0 }$ regularization. 2. We present a novel simple relaxation of Bernoulli distribution to sparsify the input layer (the feature space) which we call stochastic gate (STG) and show its advantage over the distribution presented by (Louizos et al., 2017) both in performance and convergence time. 3. By applying these two relaxations to an input layer of a neural network, we perform embedded feature selection in classification, regression or survival analysis tasks and demonstrate its capabilities on artificial and real data sets. 4. We justify our probabilistic approach by analyzing the constrained Mutual Information maximization objective of feature selection. We demonstrate the applicability of our method using numerous examples (see Section 6 and Appendix).
Notation: We refer to vectors as bold lowercase $_ { \textbf { \em x } }$ and random vectors as bold uppercase letters $\boldsymbol { X }$ . Scalars are non-bold case $y$ , while random variables are capital case $Y$ . A set is represented by script fonts $\mathcal { X } , \mathcal { Y } , \mathcal { S }$ . For example the $n ^ { t h }$ vector-valued observation is denoted as ${ \mathbf { \mathcal { x } } } _ { n }$ whereas $X _ { d }$ represents the $d ^ { t h }$ feature of the vector-valued random variable $\boldsymbol { X }$ . Let $[ n ] = 1 , 2 , \ldots , n$ . For a set $\bar { \mathcal { S } } \bar { \subset } [ D ]$ let the vector $\pmb { s } \in \{ 0 , 1 \} ^ { D }$ be the characteristic function for the set. That is $s _ { i } = 1$ if $i \in S$ and 0 otherwise. For two vectors $_ { \textbf { \em x } }$ and $_ { z }$ we denote $\pmb { x } \odot z$ to be the element-wise product between $_ { \textbf { \em x } }$ and $_ z$ . Thus, if we let $\pmb { s } \in \{ 0 , 1 \} ^ { D }$ be the characteristic vector of $s$ , then we may define $\mathbf { \Delta } \mathbf { x } _ { S } = \mathbf { \Delta } \mathbf { x } \odot \mathbf { \Delta } \mathbf { s }$ The $\ell _ { 1 }$ norm of a vector is denoted as $\begin{array} { r } { \| \pmb { x } \| _ { 1 } = \sum _ { i = 1 } ^ { D } | x _ { i } | } \end{array}$ . Finally, the $\ell _ { 0 }$ norm of a vector is denoted as $\| \pmb { x } \| _ { 0 }$ and counts the total number of non-zero entries in the vector $_ { \textbf { \em x } }$ .
# 2 PROBLEM SETUP AND BACKGROUND
Let $\boldsymbol { \mathcal { X } } ~ \in ~ \mathbb { R } ^ { D }$ be the input domain with corresponding response domain $\mathcal { V }$ . Given realizations from some unknown data distribution $P _ { X , Y }$ , the goal of embedded feature selection methods is to simultaneously find a subset of indices $\mathcal { S } \subset \{ 1 , . . . D \}$ and construct a model that predicts $Y$ based on the selected features $X _ { \mathcal { S } }$ .
# 2.1 RISK MINIMIZATION OBJECTIVE
We assume that we are given a family of functions $\mathcal { F }$ such that any function $f _ { \pmb { \theta } } \in \mathcal { F }$ is indexed by a set of parameters $\pmb \theta$ . Given some loss $L$ , a selection of features $s \subset [ D ]$ , and a choice of parameters $\pmb \theta$ , we denote the risk of our model as
$$R ( \pmb \theta , \pmb s ) = \mathbb { E } _ { X , Y } L ( f _ { \boldsymbol \theta } ( \pmb X \odot \pmb s ) , Y ) ,$$
where we recall that $\pmb { s } = \{ 0 , 1 \} ^ { D }$ is a vector of indicator variables for the set $s$ and $\odot$ denotes the point-wise product. Thus, the goal of the feature selection problem is to find the parameters $\pmb \theta$ and $\pmb { s }$ that minimize $R ( \pmb \theta , s )$ such that $\| s \| _ { 0 }$ is small compared to $D$ .
# 2.2 FEATURE SELECTION FOR LINEAR MODELS
Before proceeding with our proposed method, we review the feature selection problem in the linear regression setting with the least squares loss. Thus, we restrict $\mathcal { F }$ to be the space of linear functions and the loss function to be the quadratic loss.
Given observations $\{ x _ { n } , y _ { n } \} _ { n = 1 } ^ { N }$ we may consider the constrained empirical risk minimization problem
$$\operatorname* { m i n } _ { \pmb { \theta } } \frac { 1 } { N } \sum _ { n = 1 } ^ { N } L ( \pmb { \theta } ^ { T } \pmb { x } _ { n } , y _ { n } ) \quad \mathrm { s . t . } \ \| \pmb { \theta } \| _ { 0 } \leq k .$$
Since the above problem is intractable, a number of authors replace the $\ell _ { 0 }$ constraint with a surrogate function $\Omega ( \pmb \theta ) : \dot { \mathbb { R } } ^ { D } \mathbb { R } _ { + }$ designed to penalize the number of selected features in $\pmb \theta$ . A natural choice for $\Omega$ is the $\ell _ { 1 }$ norm, which yields a convex problem and more precisely the LASSO optimization problem. The $\ell _ { 1 }$ is known to be the closest convex relaxation to the $\ell _ { 0 }$ . In fact, in certain settings the
LASSO optimization and the $\ell _ { 0 }$ based objective have the same solution. While the original LASSO problem focuses on the constrained optimization problem, the regularized least squares problem, which is often used in practice, yields the following minimization objective:
$$\operatorname* { m i n } _ { \pmb { \theta } } \frac { 1 } { N } \sum _ { n = 1 } ^ { N } ( \pmb { \theta } ^ { T } \pmb { x } _ { n } - \pmb { y } _ { n } ) ^ { 2 } + \lambda \| \pmb { \theta } \| _ { 1 } .$$
The hyperparameter $\lambda$ trades off the amount of regularization versus the fit of the objective1. The $\ell _ { 1 }$ regularized method is very effective for feature selection and prediction; however, it achieves this through shrinkage of the coefficients. As a result, (Fan & Li, 2001) have considered non-convex choices for $\Omega$ that perform well both theoretically and empirically for prediction and feature selection.
Our goal is to apply such regularization techniques to perform feature selection while learning a non-linear function. Kernel methods have been considered (Yamada et al., 2014), but scale quadratically in the number of observations. To alleviate this burden, (Gregorová et al., 2018) use random Fourier features to approximate the kernel. (Li et al., 2016) and (Scardapane et al., 2017) take an alternative approach by modeling $f _ { \theta }$ using a neural network with $\ell _ { 1 }$ regularization on the input weights. However, in practice, introducing an $\ell _ { 1 }$ penalty into gradient descent does not provide sufficient sparsification. Below, we discuss our method that works to directly use an $\ell _ { 0 }$ penalty.
# 3 PROPOSED METHOD
We take a probabilistic approach to approximate the $\ell _ { 0 }$ norm, which can extend to non-linear models while remaining computationally efficient. To motivate such probabilistic approach, we provide theoretical support (see Section 4) based on a Mutual Information perspective of the feature selection problem.
To view the $\ell _ { 0 }$ regularized version of the risk (Eq. 1) from a probabilistic perspective, one can introduce a Bernoulli random vector $\tilde { S }$ whose entries are independent and the $d ^ { t h }$ entry satisfies $\pi _ { d } = \mathbb { P } ( \tilde { S } _ { d } = 1 )$ for $d \in [ D ]$ . If we denote the empirical expectation over our observations as $\hat { \mathbb { E } } _ { X , Y }$ , then, the empirical regularized risk (Eq. 1) becomes
$$\operatorname* { m i n } _ { \theta , \pi } \hat { R } ( \theta , \pi ) = \operatorname* { m i n } _ { \theta , \pi } \hat { \mathbb { E } } _ { X , Y } \mathbb { E } _ { \tilde { S } } \left[ L ( f _ { \theta } ( X \odot \tilde { S } ) , Y ) + \lambda | | \tilde { S } | | _ { 0 } \right] ,$$
where we have $\mathbb { E } _ { \tilde { S } } | | \tilde { S } | | _ { 0 } = \sum _ { d = 1 } ^ { D } \pi _ { d }$ and we constrain $\pi _ { d } \in \{ 0 , 1 \}$ . Clearly, this formulation is equivalent to Eq. 1, with a regularized penalty on cardinality rather than an explicit constraint. We may then relax the discrete constraint on $\pi _ { d }$ to be $\pi _ { d } \in [ 0 , 1 ]$ .
Now, our goal is to find the model parameters $\pmb { \theta } ^ { * }$ and Bernoulli parameters $\pi ^ { * }$ that minimize the empirical risk $\hat { R } ( \pmb \theta , \pmb \pi )$ via gradient descent. However, an optimization of a loss function which includes discrete random variables suffers from high variance (see F in the Appendix for more details). Therefore, inspired by a recently developed continuous approximation for discrete random variables, suggested by (Jang et al., 2017; Maddison et al., 2016), we develop and use a novel and simple continuous distribution that is fully differentiable and suited for the task of feature selection.
# 3.1 CONTINUOUS RELAXATION
Our continuous relaxation for the Bernoulli variables ${ \cal \tilde { S } } _ { d }$ for $d \in \ [ D ]$ is termed stochastic gate (STG). The STG relies on the reparametrization trick, which is widely used for reducing the variance of gradient estimators (Miller et al., 2017; Figurnov et al., 2018). To construct a continuous approximation to Bernoulli random variable via the reparametrization trick, we define $z _ { d } = g ( \mu _ { d } + \epsilon _ { d } ) = \operatorname* { m a x } ( 0 , \operatorname* { m i n } ( 1 , \epsilon _ { d } + \mu _ { d } + 0 . 5 ) )$ where $\epsilon _ { d }$ is drawn from a Gaussian distribution $\mathcal { N } ( 0 , \sigma _ { d } )$ , where $\sigma _ { d }$ is fixed throughout training. This approximation can be viewed as a clipped, mean-shifted, Gaussian random vector. Furthermore, the gradient of the objective with respect to $\mu _ { d }$ can be computed via the chain rule.
We can now rewrite the objective in Eq. 4 as
$$\operatorname* { m i n } _ { \theta , \mu } \hat { R } ( \theta , \mu ) = \operatorname* { m i n } _ { \theta , \mu } \mathbb { E } _ { X , Y } \mathbb { E } _ { Z } \left[ L ( f _ { \theta } ( X \odot Z ) , Y ) + \lambda | | Z | | _ { 0 } \right] ,$$
where $z$ is a random vector with $D$ independent variables $z _ { d }$ for $[ D ]$ . To optimize the empirical surrogate of the objective (Eq. 5), we first differentiate it with respect to $\pmb { \mu }$ . Then, Monte Carlo sampling leads us to the following gradient estimator
$$\frac { \partial } { \partial \mu _ { d } } \hat { R } ( \pmb \theta , \mu ) = \frac { 1 } { K } \sum _ { k = 1 } ^ { K } \bigg [ L ^ { \prime } ( z ^ { k } ) \frac { \partial z _ { d } ^ { k } } { \partial \mu _ { d } } \bigg ] + \frac { \lambda } { K } \frac { \partial } { \partial \mu _ { d } } \sum _ { k = 1 } ^ { K } \mathrm { P r } \{ z _ { d } ^ { k } > 0 \} ,$$
where $K$ is the number of Monte Carlo samples. Thus, we can update the parameters $\mu _ { d }$ for $[ D ]$ via gradient descent. We note that if we replace $\frac { \partial { z } _ { d } ^ { k } } { \partial { \mu } _ { d } }$ with 1, the above gradient estimator for $L ^ { \prime }$ is reduced to the Straight-Through estimator (Bengio et al., 2013).
Under the continuous relaxation, the expected regularization term in the objective $\hat { R } ( \pmb \theta , \pmb \mu )$ is simply the sum of the probability that the gates $\{ z _ { d } \} _ { d = 1 } ^ { D }$ are active, which is equal to $\begin{array} { r } { \sum _ { d = 1 } ^ { D } \Phi \left( \frac { \mu _ { d } + \frac { 1 } { 2 } } { \sigma _ { d } } \right) } \end{array}$ where $\Phi$ is the standard Gaussian CDF. To conclude, we can now optimize the objective in Eq. 5 using gradient descent over the model parameters $\pmb \theta$ and the parameters $\pmb { \mu }$ representing the Gaussian’s mean (instead of the Bernoulli parameters $\pi$ ).
After training, to remove the stochasticity from the learned gates, we set $\hat { z } _ { d } = \operatorname* { m a x } _ { \mathbf { \alpha } } ( 0 , \operatorname* { m i n } ( 1 , \mu _ { d } +$ 0.5)), which informs what features are selected. Note that when $\left| \mu _ { d } \right|$ is less than $\begin{array} { l } { { \frac { 1 } { 2 } } } \end{array}$ , $\hat { z } _ { d }$ returns the value between $( 0 , 1 )$ . In such a case, we can treat the value of $\hat { z } _ { d }$ as feature importance or employ an additional thresholding (i.e. 1 if $\hat { z } _ { d } > 0 . 5$ and 0 otherwise) depending on application-specific needs. In the Appendix, we provide the pseudo-code of our algorithm as well as the discussion of the choice of $\sigma _ { d }$ .
# 4 CONNECTION TO MUTUAL INFORMATION
In this section we show an equivalence between the Bernoulli formulation of the feature selection problem and the $\ell _ { 0 }$ regularized approach.
# 4.1 MUTUAL INFORMATION BASED OBJECTIVE
From an information theoretic perspective, the goal of feature selection is to find a subset of features $s$ that has the highest Mutual Information (MI) with the target variable $Y$ . Recall that the MI between two random variables can be defined as $I ( X ; Y ) = H ( Y ) - H ( Y | X )$ where $H ( Y ) , H ( Y | X )$ are the entropy of $p _ { Y } ( Y )$ and the conditional entropy of $p _ { Y | \mathbf { X } } ( Y | X )$ , respectively (Cover & Thomas, 2006). Then we can formulate the task as selecting $s$ such that the mutual information between $X _ { \mathcal { S } }$ and $Y$ are maximized:
$$\operatorname* { m a x } _ { s } I ( X _ { s } , Y ) \quad { \mathrm { s . t . ~ } } | S | = k ,$$
where $k$ is the hypothesised number of relevant features.
# 4.2 INTRODUCING RANDOMNESS
We first demonstrate that under mild assumptions we can replace the deterministic search over the set $s$ (or corresponding indicator vector $\pmb { s }$ ), by a search over the parameters of the distributions that model $\pmb { s }$ . Our proposition is based on the following two assumptions:
Assumption 1: There exists a subset of indices ${ \boldsymbol { S } } ^ { * }$ with cardinality equal to $k$ such that for any $i \in S ^ { * }$ we have $I ( X _ { i } ; Y | { \cal { X } } _ { \backslash \{ i \} } ) > 0$ . Assumption 2: $I ( X _ { \cal S ^ { * c } } ; Y | X _ { \cal S ^ { * } } ) = 0$ .
Discussion of assumptions: Assumption 1 that including an element from $S ^ { * }$ improves prediction accuracy. This assumption is equivalent to stating that feature $i$ is strongly relevant (Kohavi & John, 1997a; Brown et al., 2012). Assumption 2 simply states that $S ^ { * }$ is a superset of the Markov Blanket of the variable $Y$ (Brown et al., 2012). The assumptions are quite benign. For instance they are satisfied if $\boldsymbol { X }$ is drawn from a Gaussian with a non-degenerate covariance matrix and $Y = f ( X _ { \mathcal { S } ^ { * } } ) + w$ where $w$ is noise independent of $\boldsymbol { X }$ and $f$ is not degenerate. With these assumptions in hand, we may present our result.
Proposition 1. Suppose that the above assumptions hold for the model. Then, solving the optimization in Eq. 6 is equivalent to solving the optimization
$$\operatorname* { m a x } _ { \mathbf { 0 } \leq \pi \leq 1 } I ( X \odot \tilde { S } ; Y ) \quad s . t . \quad \sum _ { i } \mathbb { E } [ \tilde { S } _ { i } ] \leq k ,$$
where the coordinates $\tilde { S } _ { i }$ are drawn independently at random according to a Bernoulli distribution with parameter $\pi _ { i }$ .
Due to length constraints, we leave the proof of this proposition and how it bridges the MI maximization (Eq. 6) and risk minimization (Eq. 2) to the Appendix (see Section C and D).
# 5 RELATED WORK
The two most related works to this study are (Louizos et al., 2017) and (Chen et al., 2018). In (Louizos et al., 2017), they introduce the Hard-Concrete (HC) distribution as a continuous surrogate for Bernoulli distributions in the context of model compression. The HC distribution is induced by applying a hard sigmoid $z = \operatorname* { m i n } ( 1 , \operatorname* { m a x } ( 0 , \bar { s } ) )$ to $\bar { s }$ , where we construct $\bar { s }$ by applying Sigmoid function to the logistic distribution as follows:
$$u \sim U ( 0 , 1 ) , L = \log ( u ) - \log ( 1 - u ) , s = \frac { 1 } { 1 + \exp ( \frac { - ( \log \alpha + L ) } { \beta } ) } , \bar { s } = s ( \zeta - \tau ) + \tau$$
The interval $( \tau , \zeta )$ , with $\tau < 0$ and $\zeta > 1$ , allows the distribution to have more probability mass on the edge of the support. The authors demonstrate how incorporating the HC in deep neural networks leads to fast convergence and improved generalization due to the sparsification effect. In this study, we introduce this type of sparsification for the long standing problem of feature selection with $\ell _ { 0 }$ regularization.We demonstrate that a simple relaxation of Bernoulli distributions is sufficient and works better than the HC distribution for feature selection. We find empirically that the HC yields high variance gradient estimates compared to the STG. This high-variance does not affect model sparsification as the sparsity pattern does not matter. Contrarily, for feature selection it is crucial as practitioners require a stable procedure. Furthermore, higher variance gradients will result in a slower convergence of the model (this has been demonstrated empirically in the supp. material). In (Chen et al., 2018), the Gumbel-softmax trick is used to develop a framework for interpreting pre-trained models. Their method is focused on finding a subset of features given a particular instance, and therefore is not appropriate for general feature selection.
Some studies tackle embedded feature selection problems by extending LASSO and group LASSO to neural network models. The authors (Li et al., 2016; Scardapane et al., 2017) and (Feng & Simon, 2017) have a similar goal as ours in performing feature selection, but instead rely on the $\ell _ { 1 }$ relaxation to the $\ell _ { 0 }$ . Our approach, which utilizes stochastic gates coupled with the $\ell _ { 0 }$ norm achieves substantially better empirical performance compared against other $\ell _ { 1 }$ based baselines. This point is demonstrated in the next section.
# 6 EXPERIMENTS
Here we provide empirical evaluation of our method in a wide range of settings. We begin with simple linear regression evaluating the capabilities of our approach to select a sparse set of relevant features (section 6.1). We then evaluate our method in nonlinear regression tasks (section 6.2). Next, we demonstrate the applicability of the method in a highly nonlinear classification task (section 6.3. Finally, we present two potential applications (section 7).
We implement our method using both the STG and HC distributions and compare their applicability for feature selection. The hyperparamters of all the methods are optimized using validation sets via Optuna (Takuya Akiba & Koyama, 2019). In the Appendix, we provide all details of the Optuna based parameter tuning procedure. Additional experiments also appear in the Appendix, including high dimensional datasets and an extensive comparisons between the STG and HC (Louizos et al., 2017) distributions.
# 6.1 SUPPORT RECOVERY IN LINEAR REGRESSION
In the setting of noisy linear regression, (Wainwright, 2009) have analyzed the probability of LASSO to correctly identify a sparse subset of active variables. The problem is know as support recovery and is formulated as follows; let $\beta ^ { * } \in \mathbb { R } ^ { D }$ be a fixed sparse vector, such that $\beta _ { i } ^ { * } \in \{ - \overline { { 0 . 5 } } , 0 . 5 \}$ (with equal probability) if $i \in S$ , and $\beta _ { i } ^ { * } = 0$ otherwise. Suppose the cardinality of the support $| S | = k$ is known. Given a matrix of measurements $\pmb { X } \in \mathbb { R } ^ { N \times D }$ with values drawn independently from $N ( 0 , 1 )$ , the response $\textbf { { y } }$ is defined as
$$\pmb { y } = \pmb { X } \beta ^ { * } + \pmb { w } ,$$
where the values of the noise $\pmb { w } _ { i } , i = 1 , . . . , N$ are drawn independently from $N ( 0 , 0 . 5 )$
Here, we reproduce this setting to evaluate the probability of the proposed approach to perfectly recover the support of $\beta ^ { * }$ . As suggested by (Wainwright, 2009), we use a sparsity that scales with $D$ such that $k = \lceil 0 . 4 D ^ { 0 . 7 5 } \rceil$ . For each number of samples $N$ in the range [10, 500], we run 200 simulations and count the portion of correctly recovered supports. We repeat this process for 2 different values of $D$ and compare our performance to LASSO. For LASSO, the regularization parameter was set to its optimal value $\begin{array} { r } { \alpha _ { N } = \sqrt { \frac { 2 \sigma ^ { 2 } \log ( D - k ) \log ( k ) } { N } } } \end{array}$ (Wainwright, 2009). For STG and HC we set $\lambda _ { N } = C \alpha _ { N }$ , such that $C$ is a constant, which is selected using a grid search in the range [0.1,10]. As evident from Fig. 1, even when restricting to linear functions our method has a clear advantage over LASSO. This implies that the $\ell _ { 0 }$ based penalty, although is non convex in nature, allows perfect recovery of the support using less samples. Furthermore, the proposed STG requires even less samples than the HC distribution and suffers from a smaller variance.
 Figure 1: Probability of successfully recovering the support of a sparse signal $\boldsymbol { \beta } ^ { * } \in \mathbb { R } ^ { D }$ vs. the number of observations $N$ . Comparison between the proposed method, HC and LASSO under a linear additive noise model $\pmb { y } = \pmb { X } \beta ^ { * } + \pmb { w }$ using (a) $D = 6 4$ and (b) $D = 1 2 8$ . Central lines are the means while shaded are represent the standard deviation.
# 6.2 NONLINEAR REGRESSION USING SYNTHETIC AND REAL DATASETS
In this section, we evaluate our method for regression tasks against two other embedded feature selection methods: LASSO and Sparse Random Fourier Features (Gregorová et al., 2018). Following the same format as (Gregorová et al., 2018), the following functions are used to generate synthetic data: (SE1: 100/5) $y = \sin { ( x _ { 1 } + x _ { 3 } ) ^ { 2 } } \sin { ( x _ { 7 } x _ { 8 } x _ { 9 } ) } + \mathcal { N } ( 0 , 0 . 1 )$ . (SE2: 18/5) $\begin{array} { r } { y = \log ( ( \sum _ { s = 1 1 } ^ { \mathbf { \bar { 1 } } 5 } x _ { s } ) ^ { 2 } ) + } \end{array}$ $\mathcal { N } ( 0 , 0 . 1 )$ . (SE3: 1000/10) $y = 1 0 ( z _ { 1 } ^ { 2 } + z _ { 3 } ^ { 2 } ) e ^ { - 2 ( z _ { 1 } ^ { 2 } + z _ { 3 } ^ { 2 } ) } + \mathcal { N } ( 0 , 0 . 0 1 )$ , where each $x _ { i }$ is drawn from the standard Gaussian $\mathcal { N } ( 0 , 1 )$ . For (SE3), the five consecutive coordinates are generated by ${ x _ { 5 } } _ { ( j - 1 ) + i } = { z _ { j } } + \mathrm { { N } } ( 0 , 0 . 1 )$ , where $z _ { j } \sim \mathcal { N } ( 0 , 1 )$ for $i = 1 , . . . , 5$ and $j = 1 , . . . , 2 0 0$ . The numbers next to the experiment code indicate total dimensions/relevant dimensions in the feature space. We also evaluate our method using three real datasets: (RCP: 21/-), of computer systems activity, (REL 17/-) of F16 elevators and (RAI 39/-) of F16 ailernos all taken from the LIACC repository 2. For each dataset, we generate 30 different replications and randomly split the data into train, validation, and test set (see Appendix for more details). The root mean squared error on the test set averaged over 30 random replicated datasets are reported in Table 1. Our method outperforms all alternative methods for most cases. Note that (SE1) is generated using a sine function, which is in favor of the random Fourier feature based method (SRFF).
Table 1: Regression performance comparison in terms of root mean squared error. The mean and standard deviation are computed across 30 resamples. $N$ is 1000 for SE1,2,3 and 6000 for RCP. The values for LASSO and SRFF are borrowed from (Gregorová et al., 2018). DNN represents a deep neural network without feature selection.
<table><tr><td>EXP</td><td>LASSO</td><td>RF</td><td>SG-L1-NN</td><td>SRFF</td><td>DNN</td><td>HC</td><td>STG</td></tr><tr><td>SE1</td><td>0.29 (0.01)</td><td>0.30 (0.01)</td><td>0.29 (0.01)</td><td>0.27 (0.01)</td><td>0.29 (0.01)</td><td>0.29 (0.01)</td><td>0.29 (0.01)</td></tr><tr><td>SE2</td><td>2.22 (0.10)</td><td>2.34 (0.17)</td><td>2.35 (0.18)</td><td>1.60 (0.10)</td><td>2.05 (0.11)</td><td>1.19 (0.31)</td><td>0.87 (0.15)</td></tr><tr><td>SE3</td><td>0.68 (0.002)</td><td>0.50(0.01)</td><td>0.68 (0.01)</td><td>0.48 (0.03)</td><td>0.73 (0.02)</td><td>0.33 (0.05)</td><td>0.14 (0.10)</td></tr><tr><td>RCP</td><td>9.69 (0.71)</td><td>3.52 (0.12)</td><td>9.64 (0.65)</td><td>2.52 (0.18)</td><td>2.89 (0.25)</td><td>2.74 (0.75)</td><td>2.44 (0.08)</td></tr><tr><td>REL</td><td>0.47 (0.01)</td><td>0.58 (0.01)</td><td>0.44 (0.01)</td><td>0.31 (0.03)</td><td>0.61 (0.01)</td><td>0.33 (0.04)</td><td>0.27 (0.002)</td></tr><tr><td>RAI</td><td>0.43 (0.02)</td><td>0.48 (0.003)</td><td>0.47(0.002)</td><td>0.41(0.02)</td><td>0.44 (0.01)</td><td>0.41 (0.01)</td><td>0.39 (0.01)</td></tr></table>
6.3 NOISY BINARY XOR CLASSIFICATION
In the following evaluation, we consider the problem of learning a binary XOR function for classification task. The first two coordinates $x _ { 1 } , x _ { 2 }$ are drawn from a binary "fair" Bernoulli distribution. The response variable is set as an XOR of the first coordinates, such that $y = x _ { 1 } \oplus x _ { 2 }$ . The coordinates $x _ { i } , i = 3 , . . . , D$ are nuisance features, also drawn from a binary "fair" Bernoulli distribution. The number of points we generate is $N = 1 , 5 0 0$ , of which $7 0 \%$ are reserved for test and $1 0 \%$ of the remaining training set was reserved for validation. We compare the proposed method to four embedded feature selection methods (LASSO (Tibshirani, 1996), C-support vectors (SVC) (Chang & Lin, 2011), deep feature selection (DFS) (Li et al., 2016), sparse group regularized NN (SG-L1-NN) (Scardapane et al., 2017)). To provide more benchmarks, we also compare our embedded method against three wrapper methods (Extremely Randomized Trees (Tree) (Rastogi & Shim, 2000), Random Forests (RF) (Strobl et al., 2008)) and Extreme Gradient Boosting (XGBOOST) (Chen & Guestrin, 2016).
To evaluate the feature selection performance, we calculate the Informative Features Weight Ratio (IFWR). IFWR is defined as the sum of weights $W _ { d }$ over the informative features divided by the sum over all weights. In the case of binary weights the IFWR is in fact a recall measure for the relevant features (See the Appendix for more details.)
The experiment is repeated 20 times for different values of $D$ , and the average test classification accuracy and standard deviation are presented in Fig. 2(a), followed by the IFWR in Fig. 2(b). The number of selected features affects the accuracy. Therefore, to treat all the methods in a fair manner, we tune the hyperparameter that controls the sparsity level using Optuna (Takuya Akiba & Koyama, 2019) which optimizes the overall accuracy across different $D \mathrm { s }$ . For instance, the wrapper methods (Tree, RF and XGBOOST) has a threshold value to retain features. We retrain them using only such features whose weight is higher than the threshold. In terms of feature ranking (see Fig. 2(c), only the tree based methods and the proposed (STG and HC based) provide the optimal median rank (which is 1.5) for the two relevant features. Nonetheless, the ranking provided by STG is the most stable comparing to all the alternative methods.
 Figure 2: (a) Classification accuracy (mean and standard deviation) vs. the number of irrelevant noisy dimension $( D )$ for the XOR problem. (b) The Informative Features Weight Ratio (IFWR), central lines are the means while shaded are represent the standard deviation. IFWR is the sum of weights $W _ { d }$ over the informative features divided by the sum over all weights. (c) Box plots for the median rank of the two informative features. Black line and dashed red represent the median and mean of each method. Optimal median rank in this experiment is 1.5.
# 7 APPLICATION
# 7.1 PURIFIED POPULATIONS OF PERIPHERAL BLOOD MONOCYTES (PBMCS)
In (Zheng et al., 2017), the authors have subjected more than 90, 000 purified cell populations of peripheral blood monocytes (PBMCs) to Single-cell RNA sequencing (scRNA-seq) analysis. Here we use this data and focus on classifying two subpopulations of T-cells, namely Naive and regulatory T-cells. We use the proposed method to select a subset of genes for which the network discriminates between Naive and regulatory T-cells. We first filter out the genes that are lowly expressed in the cells, which leaves us with $D = 2 5 3 8$ genes (features). The total number of cells in these two classes is $N = 2 0 7 4 2$ , of which we only use $1 \bar { 0 } \%$ of the data for training. We apply the proposed method for different values of $\lambda$ and report the number of selected features and classification accuracy on the test set. Here we compare our performance (STG and HC) to RF and LASSO. A least squares polynomial fit plot of the accuracy vs. number of selected features is presented in Fig. 3. The accuracy obtained by a NN without feature selection is $9 1 . 0 9 \%$ , which is comparable to what we achieve with a small fraction of the features. We have also evaluated the performance of the Hard-Concrete applied to all layers (HC-Full), following the procedure in (Louizos et al., 2017). Empirically we observed that using this type of regularization across all layers provides inferior capabilities in terms of feature selection. Moreover, when the HC-Full converges to a larger subset of features $( d > 5 0$ ), it does not generalize at all and the test accuracy is around 0.5.
Table 2: Performance comparison of survival analysis on METABRIC. We run the same experiment 5 times with different train/test split and report the mean and the standard deviation on the test set. In (Katzman et al., 2018), it is reported that DeepSurv outperforms other existing survival analysis methods such as Random Survival Forest (RSF) (Ishwaran et al., 2008) and the original Cox Propotional Hazard Model.
<table><tr><td></td><td>DEEPSURV</td><td>RSF</td><td>CoX-LASSO</td><td>Cox-HC</td><td>CoX-STG</td></tr><tr><td>C-INDEX</td><td>0.612 (0.009)</td><td>0.626 (0.006)</td><td>0.580 (0.003)</td><td>0.636 (0.007)</td><td>0.633 (0.005)</td></tr><tr><td># FEATURES</td><td>221 (ALL)</td><td>221 (ALL)</td><td>44(0)</td><td>8 (0.89)</td><td>2(0)</td></tr></table>
 Figure 3: Classification of T-cells sub-populations. Accuracy vs. number of features selected by each method. Comparison of the proposed method (STG and HC) to Random Forests (RF) and LASSO.
7.2 COX PROPORTIONAL HAZARD MODELS FOR SURVIVAL ANALYSIS
We incorporate our STG into DeepSurv (Katzman et al., 2018) to examine how this procedure improves survival analysis. The input to this analysis are gene expression profiles (Curtis et al., 2012) along with additional commonly used clinical variables, the goal is to predict survival time. In this setting, identifying a small subset of predictive covariates is important as it may lead to cheaper and more stable medical assays. See the Appendix for additional description of the data and the experimental setup.
We compared our method (Cox-STG and COX-HC) against three other methods: Cox model with $\ell _ { 1 }$ regularization (Cox-LASSO), Random Survival Forest (RSF) (Ishwaran et al., 2008) and the original DeepSurv. We evaluate the predictive ability of the learned models based on the concordance index (CI), a standard performance metric for model assessment in survival analysis, which measures the agreement between the rankings of the predicted and observed survival times. The performance in terms of the CI is reported in Table 2. We see that Cox-HC and Cox-STG outperform the alternative methods, indicating that our method shrinks the feature size while learning a predictive model.
# 8 CONCLUSION
In this paper, we propose a novel embedded feature selection method for neural networks and linear models based on stochastic gates. It has an advantage over previous $\ell _ { 1 }$ based regularization methods in terms of achieving a high level of sparsity while learning effective non linear models. We justify our probabilistic feature selection framework from the information theoretic perspective. In experiments, we demonstrate that our method consistently outperforms existing embedded feature selection methods in both synthetic and real datasets.
# REFERENCES
Genevera I Allen. Automatic feature selection via weighted kernels and regularization. Journal of Computational and Graphical Statistics, 22(2):284–299, 2013.
Roberto Battiti. Using mutual information for selecting features in supervised neural net learning. IEEE Transactions on neural networks, 5(4):537–550, 1994.
Yoshua Bengio, Nicholas Léonard, and Aaron C. Courville. Estimating or propagating gradients through stochastic neurons for conditional computation. CoRR, abs/1308.3432, 2013.
Gavin Brown, Adam Pocock, Ming-Jie Zhao, and Mikel Luján. Conditional likelihood maximisation: a unifying framework for information theoretic feature selection. Journal of machine learning research, 13(Jan):27–66, 2012.
Sohail Chand. On tuning parameter selection of lasso-type methods-a monte carlo study. In Proceedings of 2012 9th International Bhurban Conference on Applied Sciences & Technology (IBCAST), pp. 120–129. IEEE, 2012.
Girish Chandrashekar and Ferat Sahin. A survey on feature selection methods. Computers & Electrical Engineering, 40(1):16–28, 2014.
Chih-Chung Chang and Chih-Jen Lin. Libsvm: A library for support vector machines. ACM transactions on intelligent systems and technology (TIST), 2(3):27, 2011.
Jianbo Chen, Mitchell Stern, Martin J Wainwright, and Michael I Jordan. Kernel feature selection via conditional covariance minimization. In Advances in Neural Information Processing Systems, pp. 6946–6955, 2017.
Jianbo Chen, Le Song, Martin J Wainwright, and Michael I Jordan. Learning to explain: An information-theoretic perspective on model interpretation. arXiv preprint arXiv:1802.07814, 2018.
Tianqi Chen and Carlos Guestrin. Xgboost: A scalable tree boosting system. In Proceedings of the 22nd acm sigkdd international conference on knowledge discovery and data mining, pp. 785–794. ACM, 2016.
Tom Coen, Wouter Saeys, Herman Ramon, and Josse De Baerdemaeker. Optimizing the tuning parameters of least squares support vector machines regression for nir spectra. Journal of Chemometrics: A Journal of the Chemometrics Society, 20(5):184–192, 2006.
Thomas M. Cover and Joy A. Thomas. Elements of Information Theory (Wiley Series in Telecommunications and Signal Processing). Wiley-Interscience, New York, NY, USA, 2006. ISBN 0471241954.
Christina Curtis, Sohrab P Shah, Suet-Feung Chin, Gulisa Turashvili, Oscar M Rueda, Mark J Dunning, Doug Speed, Andy G Lynch, Shamith Samarajiwa, Yinyin Yuan, et al. The genomic and transcriptomic architecture of 2,000 breast tumours reveals novel subgroups. Nature, 486(7403): 346, 2012.
Pablo A Estévez, Michel Tesmer, Claudio A Perez, and Jacek M Zurada. Normalized mutual information feature selection. IEEE Transactions on Neural Networks, 20(2):189–201, 2009.
Jianqing Fan and Runze Li. Variable selection via nonconcave penalized likelihood and its oracle properties. Journal of the American statistical Association, 96(456):1348–1360, 2001.
Yingying Fan and Cheng Yong Tang. Tuning parameter selection in high dimensional penalized likelihood. Journal of the Royal Statistical Society: Series B (Statistical Methodology), 75(3): 531–552, 2013.
J. Feng and N. Simon. Sparse-Input Neural Networks for High-dimensional Nonparametric Regression and Classification. ArXiv e-prints, November 2017.
Mikhail Figurnov, Shakir Mohamed, and Andriy Mnih. Implicit reparameterization gradients. In Advances in Neural Information Processing Systems, pp. 441–452, 2018.
Magda Gregorová, Jason Ramapuram, Alexandros Kalousis, and Stéphane Marchand-Maillet. Largescale nonlinear variable selection via kernel random features. arXiv preprint arXiv:1804.07169, 2018.
Chris Hans. Bayesian lasso regression. Biometrika, 96(4):835–845, 2009.
Hemant Ishwaran and Udaya B. Kogalur. Random survival forests for r, 2007.
Hemant Ishwaran, Udaya B. Kogalur, Eugene H. Blackstone, and Michael S. Lauer. Random survival forests. Annals of Applied Statistics, 2(3):841–860, 9 2008. ISSN 1932-6157. doi: 10.1214/08-AOAS169.
Eric Jang, Shixiang Gu, and Ben Poole. Categorical reparameterization with gumbel-softmax. 2017. URL https://arxiv.org/abs/1611.01144.
Md Monirul Kabir, Md Monirul Islam, and Kazuyuki Murase. A new wrapper feature selection approach using neural network. Neurocomputing, 73(16-18):3273–3283, 2010.
Jared L. Katzman, Uri Shaham, Alexander Cloninger, Jonathan Bates, Tingting Jiang, and Yuval Kluger. Deepsurv: personalized treatment recommender system using a cox proportional hazards deep neural network. BMC Medical Research Methodology, 18, 2018.
Ron Kohavi and George H John. Wrappers for feature subset selection. Artificial intelligence, 97 (1-2):273–324, 1997a.
Ron Kohavi and George H John. Wrappers for feature subset selection. Artificial intelligence, 97 (1-2):273–324, 1997b.
Yann LeCun, Léon Bottou, Yoshua Bengio, and Patrick Haffner. Gradient-based learning applied to document recognition. Proceedings of the IEEE, 86(11):2278–2324, 1998.
Johannes Lederer and Christian Müller. Don’t fall for tuning parameters: tuning-free variable selection in high dimensions with the trex. In Twenty-Ninth AAAI Conference on Artificial Intelligence, 2015.
Fan Li, Yiming Yang, and Eric P Xing. From lasso regression to feature vector machine. In Advances in Neural Information Processing Systems, pp. 779–786, 2006.
Wei Li, Jianxing Feng, and Tao Jiang. Isolasso: a lasso regression approach to rna-seq based transcriptome assembly. In International Conference on Research in Computational Molecular Biology, pp. 168–188. Springer, 2011.
Yifeng Li, Chih-Yu Chen, and Wyeth W Wasserman. Deep feature selection: theory and application to identify enhancers and promoters. Journal of Computational Biology, 23(5):322–336, 2016.
Christos Louizos, Max Welling, and Diederik P. Kingma. Learning sparse neural networks through l0 regularization. CoRR, abs/1712.01312, 2017.
Chris J. Maddison, Andriy Mnih, and Yee Whye Teh. The concrete distribution: A continuous relaxation of discrete random variables. CoRR, abs/1611.00712, 2016. URL http://arxiv. org/abs/1611.00712.
Andrew Miller, Nick Foti, Alexander D’Amour, and Ryan P Adams. Reducing reparameterization gradient variance. In Advances in Neural Information Processing Systems, pp. 3708–3718, 2017.
Fan Min, Qinghua Hu, and William Zhu. Feature selection with test cost constraint. International Journal of Approximate Reasoning, 55(1):167–179, 2014.
Hanchuan Peng, Fuhui Long, and Chris Ding. Feature selection based on mutual information criteria of max-dependency, max-relevance, and min-redundancy. IEEE Transactions on pattern analysis and machine intelligence, 27(8):1226–1238, 2005.
Rajeev Rastogi and Kyuseok Shim. Public: A decision tree classifier that integrates building and pruning. Data Mining and Knowledge Discovery, 4(4):315–344, 2000.
Juha Reunanen. Overfitting in making comparisons between variable selection methods. Journal of Machine Learning Research, 3(Mar):1371–1382, 2003.
Marco Tulio Ribeiro, Sameer Singh, and Carlos Guestrin. "why should i trust you?": Explaining the predictions of any classifier. In Proceedings of the 22Nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, KDD ’16, pp. 1135–1144, New York, NY, USA, 2016. ACM. ISBN 978-1-4503-4232-2. doi: 10.1145/2939672.2939778. URL http://doi.acm. org/10.1145/2939672.2939778.
Debaditya Roy, K Sri Rama Murty, and C Krishna Mohan. Feature selection using deep neural networks. In Neural Networks (IJCNN), 2015 International Joint Conference on, pp. 1–6. IEEE, 2015.
Simone Scardapane, Danilo Comminiello, Amir Hussain, and Aurelio Uncini. Group sparse regularization for deep neural networks. Neurocomput., 241(C):81–89, June 2017. ISSN 0925- 2312. doi: 10.1016/j.neucom.2017.02.029. URL https://doi.org/10.1016/j.neucom. 2017.02.029.
Le Song, Alex Smola, Arthur Gretton, Karsten M Borgwardt, and Justin Bedo. Supervised feature selection via dependence estimation. In Proceedings of the 24th international conference on Machine learning, pp. 823–830. ACM, 2007.
Le Song, Alex Smola, Arthur Gretton, Justin Bedo, and Karsten Borgwardt. Feature selection via dependence maximization. Journal of Machine Learning Research, 13(May):1393–1434, 2012.
Gary Stein, Bing Chen, Annie S Wu, and Kien A Hua. Decision tree classifier for network intrusion detection with ga-based feature selection. In Proceedings of the 43rd annual Southeast regional conference-Volume 2, pp. 136–141. ACM, 2005.
Carolin Strobl, Anne-Laure Boulesteix, Thomas Kneib, Thomas Augustin, and Achim Zeileis. Conditional variable importance for random forests. BMC bioinformatics, 9(1):307, 2008.
Toshihiko Yanase Takeru Ohta Takuya Akiba, Shotaro Sano and Masanori Koyama. Optuna: A next-generation hyperparameter optimization framework. KDD, 2019.
Robert Tibshirani. Regression shrinkage and selection via the lasso. Journal of the Royal Statistical Society. Series B (Methodological), pp. 267–288, 1996.
Antanas Verikas and Marija Bacauskiene. Feature selection with neural networks. Pattern Recognition Letters, 23(11):1323–1335, 2002.
Martin J. Wainwright. Sharp thresholds for high-dimensional and noisy sparsity recovery using $\ell _ { 1 }$ -constrained quadratic programming (lasso). IEEE Transactions on Information Theory, 55 (5):2183–2202, May 2009. ISSN 0018-9448. doi: 10.1109/tit.2009.2016018. URL http: //dx.doi.org/10.1109/tit.2009.2016018.
Ronald J. Williams. Simple statistical gradient-following algorithms for connectionist reinforcement learning. Machine Learning, 8:229–256, 1992.
Makoto Yamada, Wittawat Jitkrittum, Leonid Sigal, Eric P Xing, and Masashi Sugiyama. Highdimensional feature selection by feature-wise kernelized lasso. Neural computation, 26(1):185–207, 2014.
Grace XY Zheng, Jessica M Terry, Phillip Belgrader, Paul Ryvkin, Zachary W Bent, Ryan Wilson, Solongo B Ziraldo, Tobias D Wheeler, Geoff P McDermott, Junjie Zhu, et al. Massively parallel digital transcriptional profiling of single cells. Nature communications, 8:14049, 2017.
Zexuan Zhu, Yew-Soon Ong, and Manoranjan Dash. Wrapper–filter feature selection algorithm using a memetic framework. IEEE Transactions on Systems, Man, and Cybernetics, Part B (Cybernetics), 37(1):70–76, 2007.
A APPENDIX B ALGORITHM
Here we present the pseudo code of our method, presented in Algorithm 1. The loss $L$ is typically negative-log likelihood for classification and squared loss for regression. $N$ is the sample size, $D$ is the number of features, $K$ is the number of Monte Carlo samples.
Input: $\pmb { X } \in \mathbb { R } ^ { N \times D }$ , target variables $\boldsymbol { y } \in \mathbb { R } ^ { N }$ , regularization parameter $\lambda$ , number of epochs $M$ , learning rate $\gamma$ ,
Output: Trained model $f _ { \pmb { \theta } }$ and parameter $\boldsymbol { \mu } \in \mathbb { R } ^ { D }$
. 1: Initialize the model parameter $\pmb { \theta }$ . Set $\pmb { \mu } = 0$ . 2: for $i = 1 , . . . , M$ do 3: for $n = 1 , . . . , N$ do 4: for $d = 1 , . . . , D$ do 5: for $k = 1 , . . . , K$ do 6: Sample (k)d ∼ $\epsilon _ { d } ^ { ( k ) } \sim N ( 0 , \sigma _ { d } )$ 7: Compute the gate z(kd $z _ { d } ^ { ( k ) } = \operatorname* { m a x } ( 0 , \operatorname* { m i n } ( 1 , \mu _ { d } + \epsilon _ { d } ^ { ( k ) } + 0 . 5 ) )$ 8: end for 9: $\begin{array} { r } { z _ { d } = \frac { 1 } { K } \sum _ { k = 1 } ^ { K } z _ { d } ^ { ( k ) } } \end{array}$ 10: end for 11: Set $\boldsymbol { z } = [ z _ { 1 } , . . . , z _ { D } ] ^ { T }$ 12: 13: end forCompute the loss $\begin{array} { r } { \hat { L } = \frac { 1 } { N } \sum _ { n = 1 } ^ { N } L ( f _ { \theta } ( \pmb { x } _ { n } \odot \pmb { z } ) , y _ { n } ) } \end{array}$ 14: N Compute the regularization term $\begin{array} { r } { R = \lambda \sum _ { d = 1 } ^ { D } \Phi ( \frac { \mu _ { d } + 0 . 5 } { \sigma _ { d } } ) } \end{array}$ 15: Update $\pmb { \theta } : = \pmb { \theta } - \gamma \nabla _ { \pmb { \theta } } \hat { L }$ and $\pmb { \mu } : = \pmb { \mu } - \gamma \nabla \pmb { \mu } ( \hat { L } + R )$ 16: end for
17:
Algorithm 1: STG: Feature selection using stochastic gates
We empirically observe that setting the number of Monte Carlo samples $K = 1$ and the standard deviation of the Gaussian distribution $\sigma _ { d } = 0 . 5$ for $d = 1 , . . . , D$ suffices for feature selection in our experiments. See Section E in the Appendix for more details about the specific choice of $\sigma _ { d }$ . After training, the set of indices for selected features is: $\{ d : \operatorname* { m i n } ( 1 , \operatorname* { m a x } ( 0 , \mu _ { d } + 0 . 5 ) ) > 0 \}$ .
# C PROOF OF PROPOSITION 1
We now provide a proof for Proposition 1, showing the equivalence between the stochastic optimization (Eq.7) and the deterministic one (Eq. 6). Let $\tilde { \cal S }$ be a subset such that $S ^ { * } \setminus \tilde { S } \ne \emptyset$ . That is there exists some element in $S ^ { * }$ that is not in $\tilde { \cal S }$ . For any such set $\tilde { \cal S }$ we have that $I ( X _ { \tilde { S } } ; Y ) < I ( X ; Y )$ . Indeed, if we let $i \in { \cal S } ^ { * } \cap \tilde { \cal S } ^ { c }$ then we have
$$\begin{array} { r l } { I ( \boldsymbol { X } _ { \tilde { \mathcal { S } } } ; Y ) } & { \leq I ( \boldsymbol { X } _ { \backslash \{ i \} } ; Y ) } \\ & { = I ( \boldsymbol { X } ; Y ) - I ( \boldsymbol { X } _ { i } ; Y | \boldsymbol { X } _ { \backslash \{ i \} } ) } \\ & { < I ( \boldsymbol { X } ; Y ) , } \end{array}$$
where the final inequality follows by Assumption 1. Assumption 2 also yields that for any set $\tilde { \cal S }$ such that $S ^ { * } \subset \tilde { S }$ , we have $I ( { \pmb X } _ { \tilde { S } } ; Y ) = I ( { \pmb X } ; Y )$ . Now, when we consider the Bernoulli optimization problem we have
$$\operatorname* { m a x } _ { \pi } I ( X \odot S ; Y ) \quad \mathrm { s . t . } \quad \sum _ { l } \pi _ { l } \leq k \mathrm { a n d } 0 \leq \pi _ { l } \leq 1 .$$
The mutual information can be expanded as
$$I ( X \odot S ; Y ) = \sum _ { s } I ( X \odot s ; Y ) p _ { \pi } ( S = s ) ,$$
where we have used the fact that $_ { s }$ is independent of everything else. Recall that in optimization (Eq. 7) the coordinates of $\pmb { S }$ are sampled at random. Therefore, the distribution that is being optimized over $p _ { \pi }$ is a product distribution. Our goal is to understand the form of this distribution. To that end, we will consider a problem dropping the independence constraint. If we can show that the distribution found by solving this new optimization problem with less constraints is still a product distribution, then we obtain a solution to the original optimization (Eq. 6).
Now, from above we know that the optimal value of the optimization is $I ( X \odot { \tilde { S } } ; Y )$ for any set $S ^ { * } \subset \tilde { S }$ . Hence, any unconstrained distribution should place all of its mass on such subsets in order to maximize the mutual information. As a result $\begin{array} { r } { \sum _ { l \in S ^ { * } } p ( S _ { l } = 1 ) = k } \end{array}$ . However, there is an optimization constraint that $\mathbb { E } [ \sum _ { l } S _ { l } ] \le k$ . Therefore, $\mathbb { E } [ S _ { l } ] = 0$ for any $l \notin S ^ { * }$ . Hence, the optimal solution is to select the distribution so that all of the mass is placed on the subset $S ^ { * }$ and no mass elsewhere. As this is also a product distribution, this complete the proof of the claim.
# D BRIDGING THE TWO PERSPECTIVES
To motivate the introduction of randomness into the risk, we have looked at the feature selection problem from a MI perspective. Based on the MI objective, we have observed that introducing randomness into the constrained maximization procedure, does not change the objective (Proposition 1). Here we provide a relation between the MI objective (Eq. 6) to the empirical risk (Eq. 1), which supports our proposed procedure.
We first note that the MI maximization over the set $s$ can be reformulated as the minimization of the conditional entropy $H ( Y | \boldsymbol { X } _ { \mathcal { S } } )$ since $H ( Y )$ does not depend on $s$ :
$$\displaystyle { \operatorname* { m a x } _ { \mathcal { S } } I ( \mathbf { \boldsymbol { X } } _ { \mathcal { S } } ; Y ) = \operatorname* { m a x } _ { \mathcal { S } } H ( Y ) - H ( Y | \mathbf { \boldsymbol { X } } _ { \mathcal { S } } ) \iff \operatorname* { m i n } _ { \mathcal { S } } H ( Y | \mathbf { \boldsymbol { X } } _ { \mathcal { S } } ) } .$$
Recall that $X _ { \mathcal { S } } = X \odot \tilde { S }$ . By Proposition 1, we can rewrite the deterministic search over the set $s$ by a search over the Bernoulli parameters $\pi$ :
$$\begin{array} { r l } { \displaystyle \operatorname* { m i n } _ { \pi } H ( \boldsymbol { Y } | \boldsymbol { X } \odot \tilde { \boldsymbol { S } } ) = \operatorname* { m i n } _ { \pi } \mathbb { E } _ { \boldsymbol { X } , \boldsymbol { Y } , \tilde { \boldsymbol { S } } } - \log P _ { \pmb { \theta } ^ { * } } ( \boldsymbol { Y } | \boldsymbol { X } \odot \tilde { \boldsymbol { S } } ) } & { } \\ { = \displaystyle \operatorname* { m i n } _ { \pmb { \theta } } \operatorname* { m i n } _ { \pi } \mathbb { E } _ { \boldsymbol { X } , \boldsymbol { Y } , \tilde { \boldsymbol { S } } } - \log P _ { \pmb { \theta } } ( \boldsymbol { Y } | \boldsymbol { X } \odot \tilde { \boldsymbol { S } } ) , } \end{array}$$
where the expectation is over $X , Y \sim P _ { \pmb { \theta } _ { * } }$ , which is the true data distribution, and $\tilde { S } \sim B e r n ( \tilde { S } | \pi )$ . Put our model distribution as $P _ { \theta }$ , then we can rewrite the right hand side as:
$$\begin{array} { r l } & { \mathbb { E } _ { X , Y , \tilde { S } } \log P _ { \theta ^ { * } } \big ( Y | X \odot \tilde { S } \big ) = \mathbb { E } _ { X , Y , \tilde { S } } \Bigg [ \log P _ { \theta ^ { * } } \big ( Y | X \odot \tilde { S } \big ) \frac { P _ { \theta } \big ( Y | X \odot \tilde { S } \big ) } { P _ { \theta } \big ( Y | X \odot \tilde { S } \big ) } \Bigg ] } \\ & { \qquad = \mathbb { E } _ { X , Y , \tilde { S } } \log \frac { P _ { \theta ^ { * } } \big ( Y | X \odot \tilde { S } \big ) } { P _ { \theta } \big ( Y | X \odot \tilde { S } \big ) } + \mathbb { E } _ { X , Y , \tilde { S } } \log P _ { \theta } \big ( Y | X \odot \tilde { S } \big ) . } \end{array}$$
Since $\mathrm { K L } ( P _ { \theta ^ { * } } ( Y | X \odot \tilde { S } ) | | P _ { \theta } ( Y | X \odot \tilde { S } ) )$ is non-negative, $\mathbb { E } _ { \tilde { S } } \mathbf { K } \mathbf { L } ( P _ { \theta * } ( Y | \boldsymbol { X } \odot \tilde { \pmb { S } } ) | | P _ { \theta } ( Y | \boldsymbol { X } \odot \tilde { \pmb { S } } ) )$ is also non-negative because it is a weighted sum of non-negative terms. Noting that
$$\mathbb { E } _ { \tilde { S } } \mathrm { K L } \big ( P _ { \theta * } ( Y | X \odot \tilde { S } ) | | P _ { \theta } ( Y | X \odot \tilde { S } ) \big ) = \mathbb { E } _ { X , Y , \tilde { S } } \log \frac { P _ { \theta * } ( Y | X \odot \tilde { S } ) } { P _ { \theta } ( Y | X \odot \tilde { S } ) }$$
we can conclude that
$$\mathbb { E } _ { X , Y , \tilde { S } } - \log P _ { \theta ^ { * } } ( Y | X \odot \tilde { S } ) \leq \mathbb { E } _ { X , Y , \tilde { S } } - \log P _ { \theta } ( Y | X \odot \tilde { S } ) .$$
If we consider the negative log likelihood of the target given the observations (i.e. $- \log P _ { \theta } ( Y | X \odot \tilde { \pmb { S } } ) )$ as a loss function $L$ (which encodes the classification or regression function $f _ { \pmb { \theta } } ,$ ), then we see that minimizing the risk approximately maximizes the MI objective in Eq. 6.
# E DETAILS OF REGULARIZATION TERM
Here we provide the detail description of the regularization term. For the vector of stochastic gates $z \in \mathbb { R } ^ { D }$ , the regularization term is expressed as follows:
$$\begin{array} { l } { \displaystyle \mathbb { E } _ { Z } \| Z \| _ { 0 } = \displaystyle \sum _ { d = 1 } ^ { D } \mathbb { P } [ z _ { d } > 0 ] = \displaystyle \sum _ { d = 1 } ^ { D } \mathbb { P } [ \mu _ { d } + \sigma _ { d } \epsilon _ { d } > - \frac { 1 } { 2 } ] } \\ { = \displaystyle \sum _ { d = 1 } ^ { D } \{ 1 - \mathbb { P } [ \mu _ { d } + \sigma _ { d } \epsilon _ { d } \leq - \frac { 1 } { 2 } ] \} } \\ { = \displaystyle \sum _ { d = 1 } ^ { D } \{ 1 - \Phi ( - \frac { 1 } { \sigma _ { d } } ) \} } \\ { = \displaystyle \sum _ { d = 1 } ^ { D } \Phi ( \frac { \mu _ { d } + \frac { 1 } { 2 } } { \sigma _ { d } } ) . } \end{array}$$
The derivative of the regularization term with respect to the distribution parameter $\mu _ { d }$ is simply the Gaussian PDF:
$$\frac { \partial } { \partial \mu _ { d } } \mathbb { E } _ { Z } \left\| Z \right\| _ { 0 } = \frac { \partial } { \partial \mu _ { d } } \Phi ( \frac { \mu _ { d } + \frac { 1 } { 2 } } { \sigma _ { d } } ) = \frac { 1 } { \sqrt { 2 \pi \sigma _ { d } ^ { 2 } } } e ^ { - \frac { ( \mu _ { d } + \frac { 1 } { 2 } ) ^ { 2 } } { 2 \sigma _ { d } ^ { 2 } } } .$$
The effect of $\sigma$ can be understood by looking at the value of $\frac { \partial } { \partial \mu _ { d } } \mathbb { E } _ { Z } | | Z | | _ { 0 }$ . In the first iteration during the training, $\mu _ { d }$ is 0. Therefore, during the initial phase of training, it is close to $\frac { \lambda } { \sqrt { 2 \pi \sigma _ { d } ^ { 2 } } } e ^ { - \frac { 1 } { 8 \sigma _ { d } ^ { 2 } } }$ . In order to remove irrelevant features, this term has to be greater than the derivative of the loss with respect to $\mu _ { d }$ because otherwise $\mu _ { d }$ is updated in the incorrect direction. To encourage such behavior, we set $\sigma = 0 . 5$ , which is around the maximum of the gradient during the initial phase as shown in Fig. 4. Although the point that attains the maximum moves as $\mu$ changes, we empirically observe that setting $\sigma = 0 . 5$ performs well in our experiments when the regularization parameter $\lambda$ is appropriately tuned (see Section I).
 Figure 4: The plot of ∂∂µ EZ||Z||0|µ=0 = √ 12πσ2 e for $\sigma = [ 0 . 0 0 1 , 2 ]$
# F ISSUES IN GRADIENT ESTIMATION OF DISCRETE RANDOM VARIABLES
In Section 3.1, we have introduced Bernoulli random $\widetilde { s } _ { d } , d = 1 , . . . , D$ variables with corresponding parameters $\pi _ { d }$ into the risk objective (Eq. 4). Taking the expectation over the $\ell _ { 0 }$ norm of $\tilde { s }$ boils down to the sum of the Bernoulli parameters $\pi _ { d }$ . However, the optimization of the resulting objective suffers from high variance due to the discrete nature of $\tilde { S }$ . Here, we attempt to convey this problem by analyzing the risk term in the objective in Eq. 4. Using the Bernoulli paramterization the empirical risk $\hat { R } ( \pmb \theta , \pmb \pi )$ is expressed as
$$\sum _ { \mathscr { Z } : \{ 0 , 1 \} ^ { D } } \left[ \sum _ { n = 1 } ^ { N } [ L ( f _ { \theta } ( \mathscr { z } \odot \mathscr { x } _ { n } ) , \pmb { y } _ { n } ] \prod _ { d = 1 } ^ { D } \pi _ { d } ^ { \mathscr { z } _ { d } } ( 1 - \pi _ { d } ) ^ { 1 - \mathscr { z } _ { d } } \right] .$$
In practice, as the outer sum involves enumerating $2 ^ { D }$ possibilities of the indicator variables, one can replace the outer sum with Monte Carlo samples from the product of Bernoulli distributions $B ( z | \pi )$ . However, a Monte Carlo estimate of $\frac { \partial } { \partial \pi _ { d } } \hat { R } ( \pmb \theta , \pmb \pi )$ suffers from high variance. To see this, consider the following exact gradient of the empirical risk with respect to $\pi _ { d }$ , which is
$$\sum _ { z : \{ 0 , 1 \} ^ { D } , z _ { d } = 1 } \left[ L ( z ) p _ { z _ { i } \neq d } \right] - \sum _ { z : \{ 0 , 1 \} ^ { D } , z _ { d } = 0 } \left[ L ( z ) p _ { z _ { i } \neq d } \right] ,$$
where $p ( z _ { i \neq d } ) = \prod _ { i \neq d } ^ { D } \pi _ { i } ^ { z _ { i } } ( 1 - \pi _ { i } ) ^ { 1 - z _ { i } }$ , by absorbing the model $f _ { \theta } ( \cdot )$ and the data into $L ( \cdot )$ . Due to the discrete nature of $_ z$ , we see that even the sign of the gradient estimate becomes inaccurate if we can only access a small number of Monte Carlo samples. While a score-function estimator such as REINFORCE (Williams, 1992) can be used, it is known that the reparametrization trick reduces the variance more in practice.
# G COMPARISON TO HARD-CONCRETE DISTRIBUTION
To evaluate the strength of the proposed continuous relaxation of the Bernoulli distribution, described in Subsection 3.1, we compare it with the Hard-Concrete distribution (Louizos et al., 2017), another continuous surrogate for Bernoulli distributions, which was originally developed for neural network model compression. The details of the Hard-Concrete distribution is described below.
# G.1 HARD-CONCRETE DISTRIBUTION
The authors in (Louizos et al., 2017) introduce a modification of Binary Concrete, whose sampling procedure is as follows:
$$\begin{array} { r } { u \sim U ( 0 , 1 ) , L = \log ( U ) - \log ( 1 - U ) } \\ { s = \frac { 1 } { 1 + \exp ( \frac { - ( \log { \alpha } + L ) } { \beta } ) } } \\ { \bar { s } = s ( \zeta - \tau ) + \tau } \\ { z = \operatorname* { m i n } ( 1 , \operatorname* { m a x } ( 0 , \bar { s } ) ) } \end{array}$$
where $( \tau , \zeta )$ is an interval, with $\tau < 0$ and $\zeta > 1$ . This induces a new distribution, whose support is $[ 0 , 1 ]$ instead of $( 0 , 1 )$ . With $0 < \beta < 1$ , the probability density concentrates its mass near the end points, since values larger than $\frac { 1 - \tau } { \zeta - \tau }$ are rounded to one, whereas values smaller than $\frac { - \tau } { \zeta - \tau }$ are rounded to zero.
The CDF of $s$ is
$$Q _ { s } ( s | \beta , \log \alpha ) = \mathrm { { S i g m o i d } } ( ( \log s - \log ( 1 - s ) ) \beta - \log \alpha )$$
and so the CDF of $\bar { s }$ is
$$Q _ { \bar { s } } ( \bar { s } | \phi ) = \mathrm { S i g m o i d } ( ( \log ( \frac { \bar { s } - \tau } { \zeta - \tau } ) - \log ( 1 - \frac { \bar { s } - \tau } { \zeta - \tau } ) ) \beta - \log \alpha$$
where $\phi = ( \beta , \log \alpha , \zeta , \tau )$
Now, the probability of being the gate $z _ { i }$ being active is $1 - Q _ { \bar { s } } ( 0 | \phi )$ and can be written as
$$1 - Q _ { \bar { s } } ( 0 | \phi ) = \mathrm { S i g m o i d } ( \log \alpha - \beta \log \frac { - \tau } { \zeta } )$$
# G.2 THE EFFECT OF THE HEAVY TAIL DISTRIBUTION
The main difference between our proposed distribution (STG) and the Hard-Concrete (Louizos et al., 2017) distribution is that the latter is based on the logistic distribution, which has a heavier tail than the Gaussian distribution we have employed. As shown in Fig 5, the heavy-tailness results in instability during training. Furthermore, our method converges much faster and more reliably than the feature selection method using the Hard-Concrete distribution on a the two-moons, XOR and MADELON datasets (see Subsection J.1 and J.2). A similar phenomenon is also demonstrated in the MNIST experiment (see Subsection J.3).
 Figure 5: Comparison between STG and Hard-Concrete on the Two-Moon dataset (a), XOR (b) and MADELON (c). The shaded area represents the standard deviation, calculated by running the same experiment 10 times with different random initializations.
# H NON-CONVEX DETERMINISTIC REGULARIZATION
Our proposed objective for feature selection (summarized in Eq. 5) consists of three major differences compared to the LASSO formulation.
• Non-linearity, which is obtained by learning parameters of a multi-layer network with non linear activation’s. • Feature gates, these are a specific form on non convex regularization. • Stochasticity, which is achieved by injecting noise via the reparametrization trick.
In section 6.1, we have demonstrated that even in the linear regime the proposed formulation outperforms the LASSO in the task of identifying active features (see Fig. 1(a)).
The stochastic property of the gates proposed in this paper is justified using a MI prospective (see Section 4). Nonetheless, in this section we evaluate whether the practical performance gain of our method stems from the non-convex regularization or from it’s combination with the injected noise.
We define a deterministic gate using $\tilde { z } _ { d } = g ( \mu _ { d } ) = \operatorname* { m a x } ( 0 , \operatorname* { m i n } ( 1 , \mu _ { d } + 0 . 5 ) )$ , where $\mu _ { d }$ is a parameter learned for each feature $d = 1 , . . . , D$ . In the linear regression setting we can define the non-convex deterministic (NCD) as
$$\operatorname* { m i n } _ { \theta , \mu } \frac { 1 } { N } \sum _ { n = 1 } ^ { N } ( \theta ^ { T } x _ { n } \odot \tilde { z } - y _ { n } ) ^ { 2 } + \lambda \sum _ { d = 1 } ^ { D } \Phi \left( \frac { \mu _ { d } + 0 . 5 } { 0 . 5 } \right) ,$$
where $\Phi$ is the standard Gaussian CDF. Combined with $\tilde { z } _ { d }$ this non-convex regularized objective is deterministic and differentiable, and its solution can be approximated via gradient decent. We evaluate the applicability of such alternative objective for the task of feature selection in linear regression. The experimental setting follows the description in Section 6.1 using $D = 6 4$ .
In Fig. 6(b), we compare the values of the deteministic gates (DNC) and stochastic gates (STG) using $N = 6 0$ . As depicted from this figure, the STG correctly identifies the active features (first 10) and sparsifies the non-active features. The deterministic version DNC does induce partial sparsity, but fails to remove some of the irrelevant features. Furthemore, it does not push the gates values of active features up to 1. Clearly, in the deterministic setting, shrinking the value of $\mu _ { d }$ while compensating with a large coefficient in $\pmb \theta$ is preferable for the objective in Eq. 12.
To evaluate the probability of support recovery using DNC, we apply additional thresholding to the gates. Specifically, we use a threshold of 0.5 to define if a feature is active or not. A comparison with STG, HC and LASSO in this setting appears in Fig. 6(a). The DNC is superior to LASSO, but inferior to the HC and STG. Which means that there is a true advantage of stochacity in our formulation.
One aspect that is crucially difference between the STG and DNC is what we call “second chance”. For the deterministic formulation, if a feature is zeroed out in an early training phase, the gradient of the feature vanishes for further training and it will never be pulled back. For the STG, even if the feature has been pulled to zero, the gate may still be pushed back up to one at a later training phase. This is due to the injected noise which allows to reevaluate the gradient of each gate. In Fig. 6(c), we demonstrate this “second chance” effect using $N = 6 0$ samples and presenting the gate’s values (throughout training) for an active feature.
To conclude, this form of deterministic gates (Eq. 12) is not suitable for an embedded feature selection method. Using thresholding seems somewhat effective; however such thresholding was not required for the STG in any of our experiments. While the shrinkage phenomenon might be avoided using further regularization on $\pmb \theta$ this is out of the scope of the current study.
 Figure 6: Support recovery in the linear regression (see Section 6.1), the dimension $D = 6 4$ . (a) Phase transition comparison between the STG, HC, LASSO and the deterministic non convex (DNC). (b) An example of the output gates, STG $( z _ { d } )$ and DNC $( \tilde { z } _ { d } )$ for $N = 6 0$ . Each marker represents the gate value of the corresponding feature, of which the first 10 features are active. The deterministic gates are not pushed towards 1. (c) Demonstration of the “second chance” inherit to the STG. In the deterministic setting if a feature is eliminated its gradient vanishes for the rest of the training. The STG reevaluates this features and “recovers” after 4000 epochs.
# I TUNING THE REGULARIZATION PARAMETER $\lambda$
There have been several studies (Lederer & Müller, 2015; Coen et al., 2006) on the problem of tuning regularization parameter in regression and classification. Perhaps the most related regularized objective is the LASSO formulation. Studies such as (Chand, 2012; Fan & Tang, 2013) develop methods for tuning the regularization parameter in LASSO. In Eq. 5 as in the LASSO formulation, increasing the value of $\lambda$ effectively forces a sparser solution with less features. For simplicity, we focus on one popular way for tuning $\lambda$ in the LASSO. The idea is to minimize the generalization error using a cross validation procedure over a range of $\lambda$ values.
In this section, we demonstrate that this procedure is also applicable for the proposed approach. We apply the STG to the RAI dataset and evaluate the MSE using a 5-folds cross validation procedure. We compute the MSE on the validation data using 100 values of $\lambda$ logarithmically scaled in $[ 1 0 ^ { - 3 } , 1 0 ^ { 1 } ]$ As demonstrated in Fig. 7, using a cross validation procedure for tuning $\lambda$ provides a clear optimal value for this example.
 Figure 7: Demonstrating a cross validation procedure on the RAI dataset (see section I for details). We perform 5-folds cross validation and evaluate the MSE on the test test. The optimal $\lambda = 0 . 1 3 5$ which seems stable in this example based on the low standard deviation.
# J ADDITIONAL EXPERIMENTS
# J.1 MADELON DATASET
The MADELON dataset, first suggested for the NIPS 2003 feature selection problem, is a multivariate highly nonlinear binary classification problem. The MADELON dataset is generated using 32 groups of data points placed on a 5 dimensional hyper-cube and randomly labeling them by one of the two class labels. The first 5 informative features are then used to create 15 additional coordinates that are formed based on a random linear transformation of the first 5. A Gaussian noise $N ( 0 , 1 )$ is added to each feature. Next, additional 480 nuisance coordinates are added in the same manner. These features have no effect on the class label. Finally, $1 \%$ of the labels are flipped. To be consistent with the XOR and two moons experiments, we use 1, 500 points from this dataset, and evaluate our proposed method in terms of its predictive power and ability to detect the informative features. We vary the regularizaton parameter $\lambda$ in the range [0.01, 10] and evaluate the classification accuracy using 5 folds cross validation. In this example, we restrict our comparison to Random Forest and LASSO. We focus on Random Forest as it was the strongest competitor to our method in all of our experiments, while LASSO is evaluated because it is a widely used embedded feature selection method.
As evident from Fig. 8(a), our method achieves the highest accuracy while using less features. Moreover, as depicted from this figure, peak performence occurs when selecting 5 features, thus, our method provides a clear indication to the true number of informative features. Both LASSO and RF on the other hand, do not provide a clear indication of the true number of relevant features. In Fig. 8(b), we evaluate the effect of $\lambda$ on the number and quality of selected features. As shown in this plot, there is a wide range of $\lambda$ ’s such that our method only selects relevant features. Finally, as evident from the plato on the right hand side of the red plot, there is a range of $\lambda$ ’s such that exactly 5 features are selected.
 Figure 8: (a) Classification accuracy on the MADELON data sets. We evaluate performance using 5-fold cross validation for different number of selected features. In this dataset, only the first 20 coordinates are informative. In that regime the proposed method outperforms RF and LASSO. (b) An empirical evaluation of the effect the regularization parameter $\lambda$ . The IFWR and the number of selected features are presented on both sides of the $y$ -axis of this plot. For both plots, the mean is presented as a solid/dashed line, while the standard deviation is marked as a shaded color around the mean. (c) Box plots for the median rank of the 5 original informative features. Black line and dashed red represent the median and mean of each method. Optimal median rank in this experiment is 3.
# J.2 TWO MOONS CLASSIFICATION WITH NUISANCE FEATURES
In this experiment, we construct a dataset based on "two moons" shape classes, concatenated with noisy features. The first two coordinates $x _ { 1 } , x _ { 2 }$ are generated by adding a Gaussian noise with zero mean and the variance of $\sigma _ { r } ^ { 2 } = 0 . 1$ onto two nested half circles, as presented in Fig. 9(a). Nuisance features $x _ { i } , i = 3 , . . . , D$ , are drawn from a Gaussian distribution with zero mean and variance of $\sigma _ { n } ^ { 2 } = 1$ . We reserve the $7 0 \%$ as a test set, and use $1 0 \%$ of the remaining training set as a validation set. We follow the same hyperparameter tuning procedure as in the XOR experiment. The classification accuracy is in Fig. 9(b). Based on the classification accuracies, it is evident that for a small number of nuisance dimensions all methods correctly identify the most relevant features. The proposed method (STG) and Random Forest (RF) are the only methods that achieve near perfect classification accuracy for a wide range of nuisance dimensions. The other NN based method (DFS) seem to converge to sub-optimal solutions. We note that the median rank for all the methods is 1.5.
 Figure 9: (a) Realizations from the "Two moons" shaped binary classification class. $X _ { 1 }$ and $X _ { 2 }$ are the relevant features, $X _ { i } , i = 3 , . . . , D$ are noisy features drawn from a Gaussian with zero mean and variance of 1. (b) Classification accuracy (mean and standard deviation based on 20 runs) vs. the number of irrelevant noisy dimension.
# J.3 SPARSE HANDWRITTEN DIGITS CLASSIFICATION
In the following toy example, we attempt to distinguish between images of handwritten digits of 3’s and 8’s using samples from MNIST (LeCun et al., 1998). The orientation and location of the digits is more or less the same throughout this dataset, therefore for these two classes (3’s and 8’s), we expect that some of the left side features (pixels) would be sufficient for the separation. The experiment is performed as followed. We reserve $9 0 \%$ of the data as the test set, and train on the remaining $1 0 \%$ . We then apply STG and evaluate the classification accuracy and the number of selected features. We use the architecture [200, 50, 10] with tanh activations. The experiment was repeated 10 times, the extracted features and accuracies were consistent over 20 trials. We noticed a relatively small number of selected features, which are positioned southwest and close to the center of the images, achieve very high classification accuracy. An example of 9 randomly selected samples overlaid with the weights of the selected features is presented in Fig. 10(a). Furthermore, we also evaluate the effect of $\lambda$ on the the number of selected features and accuracy of the method. We apply our method (STG) and its variant using the Hard-Concrete distribution to a randomly sampled training set of size $N = 1 5 0 0$ and vary $\lambda$ in the range of [0.001, 0.01]. In Fig. 10(b) we present the accuracy and sparsity level vs. the $\lambda$ parameter. This experiment demonstrates the improved performance of the proposed distribution compared to the Hard-Concrete (HC (Louizos et al., 2017)), which was designed for neural net model compression. Not only that the overall accuracy is superior, but also it seems that the transition as a function of $\lambda$ is smoother, which suggests that the method is less sensitive to the choice of $\lambda$ .
# J.4 GISETTE DATASET
The Gisette is a handwritten dataset also appears in the NIPS 2003 feature selection challenge. The data consists of 13, 500 handwritten digits of $\ ' 4 '$ and ’9’. The original digits have $2 8 \times 2 8$ pixels, which were modified for the feature selection challenge. Specifically, a random subset of the features are embedded in a 2500 dimensional space and additional 2500 irrelevant probes are added. The train, validation and test dimensions are $6 0 0 0 / 1 0 0 0 / 7 5 0 0$ respectively. We apply the proposed STG based feature selection method and compare its performance to Random Forests (RF) and Extremely Randomized Trees (Tree). As evident from Fig. 11, we obtain a high accuracy even for a dramatic reduction in the feature size. LASSO is not presented in this experiment as its performance is dramatically inferior to the alternatives (accuracy $< 0 . 6$ ).
 Figure 10: (a) Nine samples from MNIST (white) overlaid with the subset of 13 features (black) selected by STG. Based on only these features, the binary classification accuracy reaches $9 2 . 2 \%$ . For these nine randomly selected samples, all the 8’s have values within the support of the selected features, whereas for the 3’s there is no intersection. (b) The comparison of accuracy and sparsity level performance for $\lambda$ in the range of $[ 1 0 ^ { - 3 } , 1 0 ^ { - 2 } ]$ between using our proposed method (STG) and its variant using the Hard-Concrete (HC) distribution.
 Figure 11: Classification of the binary noisy digits from the Gisette dataset. The total number of feature is 5000 of which 2500 are irrelevant probes. Here we compare the performance of the proposed approach to RF and Tree based classifier. The lines represent a least squares polynomial fit plot of the accuracy vs. number of selected features.
# J.5 REUTERS CORPUS VOLUME I
The Reuters Corpus Volume I (RCV1) consists of 800, 000 newswire stories manually labeled by 103 categories. This is a multilable regime, i.e. each story is assigned to multiple categories. Here we focus on a binary subset of this corpus, with 23, 203 stories. The total number of feature is 47, 236 and the train, validation and test portions are $1 0 \%$ , $8 . 5 \%$ , and $8 1 . 5 \%$ respectively. We evaluate the performance of our method using a 5-fold cross validation. A comparison the LASSO and RF appears in Fig. 12. This example demonstrates that our method is also effective in an extremely high dimensional regime of non linear function estimation.
# J.6 DETAILS OF COX PROPORTIONAL HAZARD MODEL
Survival times are assumed to follow a distribution, which is characterized by the survival function $S ( t ) = P ( T > t )$ . A hazard function, which measures the instantaneous rate of death, is defined by $\begin{array} { r } { h ( t ) = \operatorname* { l i m } _ { \Delta t 0 } \frac { P ( t < T \leq t + \Delta t | T > t ) } { \Delta t } = \frac { p ( t ) } { S ( t ) } } \end{array}$ . We can relate the two functions in the following way: S(t) = e− R t0 h(t)dt.
Proportional hazard models assume a multiplicative effect of the covariates $x$ on the hazard function such that
$$h ( t | \boldsymbol { x } ) = h _ { 0 } ( t ) e ^ { \theta ^ { T } \boldsymbol { x } } ,$$
 Figure 12: Classification of the version of the RCV1 textual dataset. The total number of feature is 47, 236. Here we compare the performance of the proposed approach to RF and LASSO. The lines represent a least squares polynomial fit plot of the accuracy vs. number of selected features.
where $h _ { 0 } ( t )$ is a baseline hazard function, which is often the exponential or Weibull distribution, and $\pmb \theta$ is the parameter of interests.
One of the difficulties in estimating $\pmb { \theta }$ in survival analysis is that a large portion of the available data is censored. However, in order to obtain estimates, Cox observed that it is sufficient to maximize the partial-likelihood, which is defined as follows: $\begin{array} { r } { L ( \pmb \theta ) = \prod _ { T _ { i } \mathrm { u n c e n s o r e d } } \frac { e ^ { \pmb \theta ^ { T } \pmb x _ { i } } } { \sum _ { T _ { j } \geq T _ { i } } e ^ { \pmb \theta ^ { T } \pmb x _ { j } } } . } \end{array}$
In (Katzman et al., 2018), the authors propose DeepSurv, which uses a deep neural network model to replace the linear relations between the covariate $_ { \textbf { \em x } }$ and $\pmb { \theta }$ , demonstrating improvements of survival time prediction over existing models such as CPH and the random survival forest (Ishwaran $\&$ Kogalur, 2007), (Ishwaran et al., 2008).
The Molecular Taxonomy of Breast Cancer International Consortium (METABRIC) dataset consists of gene expression data and clinical features for 1, 980 patients, and $5 7 . 7 2 \%$ have an observed death due to breast cancer with a median survival time of 116 months.
The METABRIC dataset involves 24,368 features (genes). Most genes are irrelevant for outcome prediction. To demonstrate the advantage of STG in the context of survival analysis, we selected 16 well-known genes relevant for survival (out of the 24,368 genes) that correspond to the Oncotype DX test, a gene panel used for treatment decision making. We also include five additional clinical features (hormone treatment indicator, radiotherapy indicator, chemotherapy indicator, ER-positive indicator, and age at diagnosis). We then added 200 additional irrelevant gene variables that we selected randomly from the remaining list of genes.
After we omit the null values, the number of samples is 1969. We reserve the $2 0 \%$ for test, and use the $2 0 \%$ of the remaining training set as validation. (That is, Train: 1260, Valid: 315, Test: 394 samples.)
Experimental Detail For DeepSurv, we manually select the architecture using the validation set so that we obtain a similar performance reported in (Katzman et al., 2018). The learning rate decay is set to 1. The learning rate and the regularization parameter are optimized via Optuna using the validation set, where the search range is set $L R : [ 1 e - 3 , 1 ]$ and $\lambda : [ 1 e - 3 , 1 ]$ . The hyperparameters used in the experiment are the following: architecture :[60, 20, 3], activation: selu (as suggested by (Katzman et al., 2018)), learning rate : 0.152, learning rate decay: 1.0, $\sigma : 0 . 5$ , $\lambda : 0 . 0 2 3$ , training epoch: 2000. Note that to see the effect of feature selection, we used the hyperparameters optimized for DeepSurv to test our method (STG-DeepSurv).
# J.7 ADDITIONAL EXPERIMENTAL DETAILS
Here we provide a full description of the procedures we have performed in the experimental parts of the paper.
For synthetic datasets are first split into train, validation and test. Validation is always $1 0 \%$ of the train, while the exact ratios between train and test is detailed for each experiment separately. All the neural network weights are initialized by drawing from $\mathcal { N } ( 0 , 0 . 1 )$ and bias terms are set to 0. All the batch sizes are equal to the number of training samples. In table 3, we detail the search range of hyperparamters as well as the exact values used in our experiments. We set n-trials $= 1 0 0 0$ for Optuna, which is a define-by-run based hyperparameter optimization software equipped with efficient search and pruning strategies. We use SGD for all the experiments, except for the Cox model where we use Adam. All the experiments are conducted using Intel(R) Xeon(R) CPU E5-2620 v3 $( \underline { { { \omega } } } 2 . 4 \mathrm { G h z }$ $_ { \mathbf { X } 2 }$ (12 cores total).
Table 3: List of the search range for the hyperparameters used in our expirements for XOR and Two-Moon
<table><tr><td>Param</td><td>Search range</td></tr><tr><td># dense layers #hidden units activation LR n-epoch (DFS, SG-L1-NN) α (SG-L1-NN) 入 (SG-L1-NN) 入 (STG,DFS) 入 (LASSO) n-est (RF, XGBoost, Tree) n-boost-round (XGBoost) Thresh (RF,XGBoost, Tree) max-depth (XGBoost) c (SVC)</td><td>[1,3] [10,500] [tanh, relu, sigmoid] [le-4, 1e-1] [50,20000] [1e-3,1] [1e-7, 1] [1e-3, 1] [0.01, 1] [5,100] [1,100] [0.01,0.5] [0.01,0.5] [1e-7, 1]</td></tr></table>
For the Phase Transition experiment, we use 0.1 as a learning rate. For all the experiments when we use Tree and RF, we use the default value for max-depth, so that nodes are expanded based on the purity. For the XOR problem, the exact architectures used for the NN based methods are: (STG/HC): [476, 490, 14] with Tanh, (DFS): [100, 10] with Tanh, (SG-L1-NN): [100, 10, 5] with Tanh. For the two moons we use (STG): [490, 406, 18] with Tanh, (DFS): [158, 27, 224] with Tanh, (SG-L1-NN): [88, 28, 27] with Tanh. For the XOR problem, we attempted to use Optuna to optimize parameters of DFS and SG-L1-NN, but we ended up using the architecture suggested by the authors (Li et al., 2016; Scardapane et al., 2017) as they outperform the values suggested by Optuna. The number of epochs used for the XOR problem is $2 0 K$ , 14K, 800 for STG/HC, DFS and SG-L1-NN respectively. Regularization parameters are $0 . 1 7 , 3 . 3 e \mathrm { ~ - ~ } 5$ and $3 e - 5$ respectively. The number of epochs used for the two-moons problem is $2 0 K$ , 1570, 708 for STG/HC, DFS and SG-L1-NN respectively. Regularization parameters are $0 . 4 8 , 9 e \mathrm { ~ - ~ } 3$ and $1 e - 3$ respectively. We note that the regularization parameters and learning procedure is different in nature, as we use an $\ell _ { 0 }$ type penalty. For the PBMC experiment, the architecture was hand-tuned using the validation set and set as [200, 100, 50, 10] with Tanh. Learning rate was 0.2 and the number of epochs 4000. The hyperparameter $\lambda$ varies in the range [0.001, 0.11] to achieve different levels of sparsity. For MADELON, we use the architecture optimized for the binary XOR classification. The number of epochs used is $2 0 K$ , the learning rate is 0.06 and $\lambda$ varies in the range [0.01, 10]. For regression, the learning rate and the $\lambda$ are optimized via Optuna using the search range $L R : [ 1 e - 4 , 1 ]$ and $\lambda : [ 1 e - 4 , 1 0 ]$ based on validation. The parameters used are the following: (SE1) architecture [600, 200, 100, 50, 1] with ReLu activations, num epochs: 5, $\lambda : 5$ , $L R : 0 . 0 0 0 1$ (SE2) architecture [600, 300, 150, 60, 20] with ReLu activations, num epochs $= 2 0 0 0$ , $\lambda : 5$ , $L R : 0 . 0 0 1$ (SE3) architecture [600, 300, 150, 60, 20] with ReLu activations, num epochs : 1000, $\lambda : 1$ , $L R : 0 . 0 0 5$ . (RCP) architecture [1000, 300, 150, 60, 20] with ReLu activation, num-epochs: 2000, $\lambda : 5 . 0$ , $L R : 0 . 0 0 1$ . (REL) architecture [26,91,63] with ReLu activation, num-epochs: 1600, $\lambda : 0 . 0 3 1$ , $L R : 0 . 0 0 7$ . (RAI) architecture [10,177] with ReLu activation, num-epochs: 1800, $\lambda : 0 . 0 1 9$ , $L R : 0 . 0 0 2$ . Architectures for SE1-SE3 and RCP where tuned manually.
The ratio of train/test/valid split is 1:1:1 for synthetic data. For the real data (RCP and REL), the train size is 6000, the test and valid size is 1000 samples. For RAI the train size is 5000, the test and valid size is 1000 samples.
In order to define the IFWR, for STG, the $d ^ { t h }$ feature weight is set to $\operatorname* { m a x } ( 0 , \operatorname* { m i n } ( 1 , \mu _ { d } + 0 . 5 ) )$ . For other neural net based methods, it is given by $\textstyle \sum _ { j } W _ { d j }$ , where $W$ is the weight matrix of the first layer. For other methods we just used the feature relevance returned by the trained model. Finally, the LASSO’s IFWR in the XOR experiment was omitted from the manuscript as it suffered from high variance.
Regarding the comparison performed in the two-moons and XOR problem, we believe that adding IFWR along with classification accuracy versus number of feature selected provides a complementary perspective in demonstrating the efficacy of feature selection techniques. We emphasize that our goal is not to just rank features but select features by assigning the weight of 0 to irrelevant features while simultaneously obtaining good predictive accuracy.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342# PNAT: NON-AUTOREGRESSIVE TRANSFORMER BY POSITION LEARNING
Anonymous authors Paper under double-blind review
# ABSTRACT
Non-autoregressive models are promising on various text generation tasks. Previous work hardly considers to explicitly model the positions of generated words. However, the position modeling is an essential problem in non-autoregressive text generation. In this study, we propose PNAT, which incorporates positions as a latent variable into the text generative process. Experimental results show that PNAT achieves top results on machine translation and paraphrase generation tasks, outperforming several strong baselines.
# 1 INTRODUCTION
Transformer (Vaswani et al., 2017) has been widely used in many text generation tasks, which is first proposed in neural machine translation, achieving great success for its promising performance. Nevertheless, the auto-regressive property of Transformer has been a bottleneck. Specifically, the decoder of Transformer generates words sequentially, and the latter words are conditioned on previous ones in a sentence. Such bottleneck prevents the decoder from higher efficiency in parallel computation, and imposes strong constrains in text generation, with which the generation order has to be left to right (or right to left) (Shaw et al., 2018; Vaswani et al., 2017).
Recently, many researches (Gu et al., 2018; Lee et al., 2018; Wang et al., 2019; Wei et al., 2019) are devoted to break the auto-regressive bottleneck by introducing non-autoregressive Transformer (NAT) for neural machine translation, where the decoder generates all words simultaneously instead of sequentially. Intuitively, NAT abandons feeding previous predicted words into decoder state at the next time step, but directly copy encoded representation at source side to the decoder inputs (Gu et al., 2018). However, without the auto-regressive constrain, the search space of the output sentence becomes larger (Wei et al., 2019), which brings the performance gap (Lee et al., 2018) between NAT and auto-regressive Transformer (AT). Related works propose to include some inductive priors or learning techniques to boost the performance of NAT. But most of previous work hardly consider explicitly modeling the position of output words during text generation.
We argue that position prediction is an essential problem of NAT. Current NAT approaches do not explicitly model the position of output words, and may ignore the reordering issue in generating output sentences. Compared to machine translation, the reorder problem is much more severe in tasks such as table-to-text (Liu et al., 2018) and dialog generations (Shen et al., 2017). Additionally, it is straightforward to explicitly model word positions in output sentences, as position embeddings are used in Transformer, which is natively non-autoregressive, to include the order information. Intuitively, if output positions are explicitly modeled, the predicted position combined with Transformer to realize non-autoregressive generation would become more natural.
In this paper, we propose non-autoregressive transformer by position learning (PNAT). PNAT is simple yet effective, which explicitly models positions of output words as latent variables in the text generation. Specifically, we introduce a heuristic search process to guide the position learning, and max sampling is adopted to inference the latent model. The proposed PNAT is motivated by learning syntax position (also called syntax distance). Shen et al. (2018) show that syntax position of words in a sentence could be predicted by neural networks in a non-autoregressive fashion, which even obtains top parsing accuracy among strong parser baselines. Given the observations above, we try to directly predict the positions of output words to build a NAT model for text generation.
Our proposed PNAT takes following advantages:
• We propose PNAT, which first includes positions of output words as latent variables for text generation. Experiments show that PNAT achieves very top results in non-autoregressive NMT, outperforming many strong baselines. PNAT also obtains better results than AT in paraphrase generation task. Further analysis shows that PNAT has great potentials. With the increase of position prediction accuracy, performances of PNAT could increase significantly. The observations may shed light on the future direction of NAT. Thanks to the explicitly modeling of position, we could control the generation by facilitating the position latent variable, which may enable interesting applications such as controlling one special word left to another one. We leave this as future work.
# 2 BACKGROUND
# 2.1 AUTOREGRESSIVE DECODING
A target sequence $Y { = } y _ { 1 : M }$ is decomposed into a series of conditional probabilities autoregressively, each of which is parameterized using neural networks. This approach has become a de facto standard in language modeling(Sundermeyer et al., 2012), and has been also applied to conditional sequence modeling $p ( Y | X )$ by introducing an additional conditional variable $X { = } x _ { 1 : N }$ :
$$p ( \boldsymbol { Y } | \boldsymbol { X } ) = \prod _ { t = 1 } ^ { M } p ( y _ { t } | y _ { < t } , \boldsymbol { X } ; \theta )$$
With different choices of neural network architectures such as recurrent neural networks (RNNs) (Bahdanau et al., 2014; Cho et al., 2014), convolutional neural networks (CNNs) (Krizhevsky et al., 2012; Gehring et al., 2017), as well as self-attention based transformer (Vaswani et al., 2017), the autoregressive decoding has achieved great success in tasks such as machine translation (Bahdanau et al., 2014), paraphrase generation (Gupta et al., 2018), speech recognition (Graves et al., 2013), etc.
# 2.2 NON-AUTOREGRESSIVE DECODING
Autoregressive model suffers from the issue of slow decoding in inference, because tokens are generated sequentially and each of them depends on previous ones. As a solution to this issue, Gu et al. (2018) proposed Non-Autoregressive Transformer (denoted as NAT) for machine translation, breaking the dependency among the target tokens through time by decoding all the tokens simultaneously. Put simply, NAT (Gu et al., 2018) factorizes the conditional distribution over a target sequence into a series of conditionally independent distributions with respect to time:
$$p ( { \cal Y } | { \cal X } ) = p _ { L } ( { \cal M } | { \cal X } : \theta ) \cdot \prod _ { t = 1 } ^ { M } p ( y _ { t } | { \cal X } )$$
which allows trivially finding the most likely target sequence by arg $\operatorname* { m a x } _ { Y }$ $p ( Y | X )$ for each timestep $t$ , effectively bypassing computational overhead and sub-optimality in decoding from an autoregressive model.
Although non-autoregressive models achieves $1 5 \times$ speedup in machine translation compared with autoregressive models, it comes at the expense of potential performance degradation (Gu et al., 2018). The degradation results from the removal of conditional dependencies within the decoding sentence $y _ { t }$ depend on $y _ { < t , }$ ). Without such dependencies, the decoder is hard to leverage the inherent sentence structure in prediction.
# 2.3 LATENT VARIABLES FOR NON-AUTOREGRESSIVE DECODING
A non-autoregressive model could be incorporated with conditional dependency as latent variable to alleviate the degradation resulted from the absence of dependency:
$$P ( Y | X ) = \int _ { z } P ( z | X ) \prod _ { t = 1 } ^ { M } P ( y _ { t } | z , X ) d z$$
For example, NAT-FT (Gu et al., 2018) models the inherent sentence structure with a latent fertility variable, which represents how many target tokens that a source token would translate to. Lee et al. (2018) introduces $L$ intermediate predictions $Y ^ { 1 : L }$ as random variables , and to refine the predictions from $Y ^ { 1 }$ to $Y ^ { L }$ in a iterative manner.
# 3 PNAT: POSITION-BASED NON-AUTOREGRESSIVE TRANSFORMER
We propose position-based non-autoregressive transformer (PNAT), an extension to transformer incorporated with non auto-regressive decoding and position learning.
# 3.1 MODELING POSITION WITH LATENT VARIABLES
Languages are usually inconsistent with each other in word order. Thus reordering is usually required when translating a sentence from a language to another. In NAT family, words representations or encoder states at source side are copied to the target side to feed into decoder as its input. Previously, Gu et al. (2018) utilizes positional attention which incorporates positional encoding into decoder attention to perform local reordering. But such implicitly reordering mechanism by position attention may cause a repeated generation problem, because position learning module is not optimized directly, and is likely to be misguided by target supervision.
To tackle with this problem, we propose to explicitly model the position as a latent variable. We rewrite the target sequence $Y$ with its corresponding position latent variable $z = z _ { 1 : M }$ as a set $Y _ { z } =$ $y _ { z _ { 1 } : z _ { M } }$ . The conditional probability $P ( { Y \vert { X } } )$ is factorized with respect to the position latent variable:
$$P ( Y | X ) = \sum _ { z \in \pi ( M ) } P ( z | X ) \cdot P ( Y | z , X )$$
where $\pi ( M )$ is a set consisting of permutations with $M$ elements. At decoding time, the factorization allows us to decode sentences in parallel by pre-predicting the corresponding position variables $z$ .
# 3.2 MODEL ARCHITECTURE
 attention over the output of the encoder stack. Similar to the encoder, we employ residual connectionsaround each of the sub-layers, followed by layer normalization. We also modify the self-attention around each of the sub-layers, followed by layer normalization. We also modify the self-attentionFigure 1: Illustration of the proposed model, where the black solid arrows represent differentiable sub-layer in the decoder stack to prevent positions from attending to subsequent positions. Tmasking, combined with fact that the output embeddings are offset by one position, ensures thatsub-layer in the decoder stack to prevent positions frommasking, combined with fact that the output embeddings aconnections and the dashed arrows are non-differentiable operations.
As shown in Figure 1, PNAT is composed of four modules: an encoder stack, a bridge block, a 3.2 Attention 3.2 Attentionposition predictor as well as a decoder stack. Before detailing each component of PNAT model, we overview the architecture for a brief understanding.
Like most sequence-to-sequence models, PNAT first encodes a source sequence $X { = } x _ { 1 : N }$ into its contextual word representations $\scriptstyle { E = e _ { 1 : N } }$ with the encoder stack. With generated contextual word representation $E$ at source side, the bridge block is leveraged to computed the target length $M$ as well as the corresponding features $D { = } d _ { 1 : { M } }$ , which is fed into the decoder as its input. It is worth noting that the decoder inputs $D$ is computed without reordering. Thus the position predictor is introduced to deal with this issue by predicting a permutation $z { = } z _ { 1 : { M } }$ over $D$ . Finally, PNAT generates the target sequence from the decoder input $D$ and its permutation $_ z$ .
Encoder and Decoder Given a source sentence $X$ with length $N$ , PNAT encoder produces its contextual word representations $E$ . The contextual word representations $E$ are further used in computing target length $M$ and decoder initial states $D$ , and are also used as memory of attention at decoder side.
Generally, PNAT decoder can be considered as a transformer with a broader vision, because it leverages future word information that is blind to the autoregressive transformer. Intuitively, we use relative position encoding in self-attention(Shaw et al., 2018), rather than absolute one that is more likely to cause position errors. Following Shaw et al. (2018) with a clipping distance $d$ (usually $d \geq 2 \AA$ ) set for relative positions, we preserve $d = 4$ relations.
Bridge The bridge module predicts the target length $M$ , and initializes the decoder inputs $D$ from the source representations $E$ . The target length $M$ could be estimated from the source encoder representation:
$$M = N + \arg \operatorname* { m a x } \phi ( E )$$
where $\phi ( \cdot )$ produces a categorical distribution ranged in $[ - B , B ]$ $B = 2 0$ ). It is notable that we use the predicted length at inference stage, although during training, we simply use the length of each reference target sequence. Then, we adopt the method proposed by Li et al. (2019) to compute $D$ . Given the source representation $E$ and the estimated target length $M$ , we linearly combine the embeddings of the neighboring source tokens to generate $D$ as follows:
$$d _ { j } = \sum _ { i } w _ { j i } \cdot e _ { i }$$
$$w _ { j i } = \mathrm { s o f t m a x } ( - | j - i | / \tau )$$
where $w _ { j i }$ is a normalized weight that reflects the contribution of $e _ { i }$ to $d _ { j }$ , and $\tau$ is a hyperparameter indicating the sharpness of the weight distribution.
Position Predictor For the proposed PNAT, we model position permutations with a position predictor. As shown in Figure 1, the position predictor takes the decoder inputs $D$ and the source representation $E$ to predict a permutation $_ z$ . The position predictor has a sub-encoder which stacks multiple layers of encoder units to predict its predicted input $R { = } r _ { 1 : { M } }$ .
With the predicted inputs $R$ , we conduct an autoregressive position predictor, denoted as AR-Predictor. The AR-Predictor searches a permutation $_ { z }$ with:
$$P ( \boldsymbol { z } | D , E ) = \prod _ { t = 1 } ^ { M } p _ { ( } z _ { t } | \boldsymbol { z } _ { < t } , D , E ; \boldsymbol { \theta } )$$
where $\theta$ is the parameter of AR-Predictor, which includes a RNN-based model incorporated with a pointer network (Vinyals et al., 2015).
To purse the efficiency of decoding, we also explore a non-autoregressive version for the position predictor, denoted as NAR-Predictor, to model the position permutation probabilities with:
$$P ( z | D , E ) = \prod _ { t = 1 } ^ { M } p ( z _ { t } | D , E ; \theta )$$
To obtain the permutation $_ { z }$ , AR-Predictor performs greedy search whereas NAR-Predictor performs direct arg max. We chose the AR-Predictor as our mainly position module in PNAT, and we also analyze the effectiveness of position modeling in Sec. 4.4.
# 3.3 TRAINING
Training requires maximizing the marginalized likelihood in Eqn. 4. However, this is intractable since we need to enumerate all the $M !$ permutations of tokens. We therefore optimize this objective by Monte Carlo sampling method with a heuristic search algorithm.
Heuristic Search for Positions Intuitively, each target token should have a corresponding decoder input, and meanwhile each decoder input should be assigned to a target token. Based on this idea, we design a heuristic search algorithm to allocate positions. Given the decoder inputs and its target tokens, we first estimate the similarity between each pair of the decoder input $d _ { i }$ and the target token embedding $y _ { j }$ , which is also the weights of the target word classifier:
$$\mathrm { s i m } _ { i , j } = \mathrm { c o s i n e } \left( d _ { i } , y _ { j } \right)$$
Based on the cosine similarity matrix, HSP is designed to find a perfect matching between decoder inputs and target tokens:
$$\mathrm { H S P } ( z ) = \underset { z } { \arg \operatorname* { m a x } } \sum _ { i = 0 } ^ { M } ( \ s i \mathrm { m } _ { i , z _ { i } } )$$
Here we apply a greedy algorithm to select the pair with the highest similarity score iteratively until a permutation $z _ { \mathrm { r e f } }$ is generated. More details are provided in Appendix A.
The intuition behind is that, if the decoder input $d _ { i }$ is already the most similar one to a target word, it would be easier to keep and even reinforce this association in learning the model. We also analyze the effectiveness of the HSP in the Sec. 4.4.
Objective Function With the heuristically discovered positions as reference positions $z _ { \mathrm { r e f } }$ , the position predictor could be trained with a position loss:
$$\mathcal { L } _ { \mathrm { p } } = - \log P ( z _ { \mathrm { r e f } } | D , E )$$
Grounding on the referenced positions, the generative process of target sequences is optimized by:
$$\mathcal { L } _ { \mathrm { g } } = - \sum _ { t = 1 } ^ { M } \log P ( Y | z _ { \mathrm { r e f } } ; X )$$
Finally, combining two loss functions mentioned above, a full-fledged loss is derived as
$${ \mathcal { L } } = { \mathcal { L } } _ { \mathrm { g } } + \alpha { \mathcal { L } } _ { \mathrm { p } }$$
The length predictor is a classifier that follows the previous settings. We also follow the previous practice (Gu et al., 2018; Wei et al., 2019) and perform an extra training process for the length predictor after the model trained and do not tune the parameter of the encoder.
# 3.4 INFERENCE
We follow the common choice of approximating decoding algorithms (Gu et al., 2018; Lee et al., 2018) to reduce the search space of latent variable model.
Argmax Decoding Following Gu et al. (2018), one simple and effective method is to select the best sequence by choosing the highest-probability latent sequence $z$ :
$$\begin{array} { c } { { z ^ { * } = \arg \operatorname* { m a x } _ { z } P ( z | D , E ) } } \\ { { } } \\ { { Y ^ { * } = \arg \operatorname* { m a x } _ { y } P ( Y | z ^ { * } , X ) } } \end{array}$$
where identifying $Y ^ { * }$ only requires independently maximizing the local probability for each output position.
Length Parallel Decoding We also consider the common practice of noisy parallel decoding (Gu et al., 2018), which generates a number of decoding candidates in parallel and selects the best via re-scoring using a pre-trained autoregressive model. For PNAT, we first predict the target length as $\hat { M }$ , then generate output sequence with argmax decoding for each target length candidate $M \in$ $[ \hat { M } - \Delta M , \hat { M } + \Delta M ]$ ( $M = 4$ in our experiments), which was called length parallel decoding (LPD). Then we use the pre-trained autoregressive model to rank these sequences and identify the best overall output as the final output.
# 4 EXPERIMENTS
We test PNAT on several benchmark sequence generation tasks. We first describe the experimental setting and implementation details and then present the main results, followed by some deep studies.
# 4.1 EXPERIMENTAL SETTING
To show the generation ability of PNAT, we conduct experiments on the popular machine translation and paraphrase generation tasks. These sequence generation task evaluation models from different perspectives. Translation tasks test the ability of semantic transforming across bilingual corpus. While paraphrase task focuses on substitution between the same languages while keeping the semantics.
Machine Translation We valid the effectiveness of PNAT on the most widely used benchmarks for machine translation — WMT14 EN-DE(4.5M pairs) and IWSLT16 DE-EN(196K pairs). The dataset is processed with Moses script (Koehn et al., 2007), and the words are segmented into subword units using byte-pair encoding (Sennrich et al., 2016, BPE). For both WMT datasets, the source and target languages share the same set of subword embeddings while for IWSLT we use separate embeddings.
Paraphrase Generation We conduct experiments following previous work (Miao et al., 2019) for paraphrase generation. We make use of the established Quora dataset 1 to evaluate on the paraphrase generation task. We consider the supervised paraphrase generation and split the Quora dataset in the standard setting. We sample $1 0 0 \mathrm { k }$ pairs sentence as training data, and holds out 3k, 30k for validation and testing, respectively.
# 4.2 IMPLEMENTATION DETAILS
Module Setting For machine translation, we follow the settings from Gu et al. (2018). In the case of IWSLT task, we use a small setting $( d _ { \mathrm { m o d e l } } = 2 7 8$ , $d _ { \mathrm { h i d d e n } } = 5 0 7$ , $p _ { \mathrm { d r o p o u t } } = 0 . 1$ , $n _ { \mathrm { l a y e r } } = 5$ and nhead $= 2$ ) suggested by Gu et al. (2018) for Transformer and NAT models. For WMT task, we use the base setting of the Vaswani et al. (2017) $\dot { d } _ { \mathrm { m o d e l } } = 5 1 2$ , $d _ { \mathrm { h i d d e n } } = 5 1 2$ , $p _ { \mathrm { d r o p o u t } } = 0 . 1$ , $n _ { \mathrm { l a y e r } } = 6 $ ).
For paraphrase generation, we follow the settings from Miao et al. (2019), and set the 300-dimensional GRU with 2 layer for Seq-to-Seq (GRU). We empirically select a Transformer and NAT models with hyperparameters $\dot { d } _ { \mathrm { m o d e l } } = 4 0 0$ , $d _ { \mathrm { h i d d e n } } = 8 0 0$ , $p _ { \mathrm { d r o p o u t } } = 0 . 1$ , $n _ { \mathrm { l a y e r } } = 3$ and $n _ { \mathrm { h e a d } } = 4$ ).
Optimization We optimize the parameter with the Adam optimizer (Kingma & Ba, 2014). The hyperparameter $\alpha$ used in Eqn. 14 was be set to 1.0 for WMT, 0.3 for IWSLT and Quora. We also use inverse square root learning rate scheduling (Vaswani et al., 2017) for the WMT, and using linear annealing (from $3 e - 4$ to $1 e - 5$ , suggested by Lee et al. (2018)) for the IWSLT and Quora. Each mini-batch consists of approximately 2K tokens for IWSLT and Quora, 32K tokens for WMT.
Knowledge Distillation Sequence-level knowledge distillation is applied to alleviate multimodality problem while training, using Transformer as a teacher (Hinton et al., 2015). Previous studies on non-autoregressive generation (Gu et al., 2018; Lee et al., 2018; Wei et al., 2019) have used translations produced by a pre-trained Transformer model as the training data, which significantly improves the performance. We follow this setting in translation tasks.
Table 1: Performance on the newstest-2014 for WMT14 EN-DE and test2013 for IWSLT EN-DE. ‘-’ denotes same numbers as above. ‘\*’ indicates our implementation. The decoding speed is measured sentence-by-sentence and the speedup is computed by comparing with Transformer.
<table><tr><td>Model</td><td>WMT14 EN-DE DE-EN</td><td>IWSLT16 DE-EN</td><td></td><td>Speedup</td></tr><tr><td colspan="3">Autoregressive Methods</td><td></td><td></td></tr><tr><td>Transformer-base (Vaswani et al., 2017) *Transformer(Beam=4)</td><td>27.30 27.40</td><td>1 31.33</td><td>34.81</td><td>1.0×</td></tr><tr><td colspan="3">Non-Autoregressive Methods</td><td></td><td></td></tr><tr><td>Flowseq (Ma et al., 2019)</td><td>18.55</td><td>23.36</td><td></td><td></td></tr><tr><td>*NAT-base</td><td>/</td><td>11.02</td><td></td><td>/</td></tr><tr><td>*PNAT</td><td>19.73 NAT w/ Knowledge Distillation</td><td>24.04</td><td></td><td>/</td></tr><tr><td>NAT-FT (Gu et al., 2018) LT (Kaiser et al., 2018) IR-NAT (Lee et al., 2018)</td><td>17.69 19.80 13.91</td><td>21.47 /</td><td>/ / 27.68</td><td>15.6× 5.8×</td></tr><tr><td>ENAT (Guo et al., 2019) NAT-REG (Wang et al., 2019) imitate-NAT (Wei et al.,2019) Flowseq (Ma et al.,2019)</td><td>20.65 20.65 22.44</td><td>16.77 23.02 24.77 25.67</td><td>/ / 1</td><td>9.0× 24.3× 1 18.6×</td></tr><tr><td>*NAT-base</td><td>21.45 1 23.05</td><td>26.16 16.69</td><td>一</td><td>1.1× 13.5x</td></tr><tr><td colspan="3">*PNAT 27.18 NATw/Reranking orIterative Refinments</td><td>31.23</td><td>7.3×</td></tr><tr><td>NAT-FT (rescoring 10 candidates) LT (rescoring 10 candidates) IR-NAT (refinement 10)</td><td>18.66 22.50</td><td>22.42 /</td><td>/ 一</td><td>7.7× /</td></tr><tr><td>ENAT (rescoring 9 candidates)</td><td>21.61 24.28</td><td>25.48 26.10</td><td>32.31 /</td><td>1.3× 12.4×</td></tr><tr><td>NAT-REG (rescoring 9 candidates) imitate-NAT (rescoring 9 candidates)</td><td>24.61 24.15</td><td>28.90 27.28</td><td>/ /</td><td>1 9.7×</td></tr><tr><td>Flowseq (rescoring 30 candidates) *PNAT (LPD n=9,△M=4)</td><td>23.48 24.48</td><td>28.40 29.16</td><td>/ 32.60</td><td>/ 3.7x</td></tr></table>
# 4.3 MAIN RESULTS
Machine Translation We compare the PNAT with strong NAT baselines, including the NAT with fertility (Gu et al., 2018, NAT-FT), the NAT with iterative refinement (Lee et al., 2018, IR-NAT), the NAT with regularization (Wang et al., 2019, NAT-REG), the NAT with enhanced decoder input (Guo et al., 2019, ENAT), the NAT with learning from auto-regressive model (Wei et al., 2019, imitateNAT), the NAT build on latent variables (Kaiser et al., 2018, LT), and the flow-based NAT model (Ma et al., 2019, Flowseq).
The results are shown in Table 1. We basically compare the proposed PNAT against the autoregressive counterpart both in terms of generation quality, which is measured with BLEU (Papineni et al., 2002) and inference speedup. For all our tasks, we obtain the performance of competitors by either directly using the performance figures reported in the previous works if they are available or producing them by using the open source implementation of baseline algorithms on our datasets.2 Clearly, PNAT achieves a comparable or better result to previous NAT models on both WMT and IWSLT tasks.
We list the result of the NAT models trained without using knowledge distillation in the second block of the Table 1. The PNAT achieves significant improvements (more than 13.0 BLEU points) over the naive baselines, which indicate that position learning greatly contributes to improve the model capability of NAT model. The PNAT also achieves a better result than the Flowseq around 1.0 BLEU, which demonstrates the effectiveness of PNAT in modeling dependencies between the target outputs.
As shown in the third block of the Table 1, without using reranking techniques, the PNAT outperforms all the competitors with a large margin, achieves a balance between performance and efficiency. In particular, the previous state-of-the-art(WMT14 DE-EN) Flowseq achieves good performance with the slow speed $( 1 . 1 \times )$ , while PNAT goes beyond Flowseq in both respects.
Our best results are obtained with length parallel decoding which employ autoregressive model to rerank the multiple generation candidates of different target length. Specifically, on the large scale WMT14 DE-EN task, PNAT $( + \mathrm { L P D } )$ surpass the NAT-REG by 0.76 BLEU score. Without reranking, the gap has increased to 2.4 BLEU score (27.18 v.s. 24.77). The experiments shows the power of explicitly position modeling which reduces the gap between non-autoregressive and the autoregressive models.
Paraphrase Generation Given a sentence, paraphrase generation aims to synthesize another sentence that is different from the given one, but conveys the same meaning. Comparing with translation task, paraphrase generation prefers a more similar order between source and target sentence, which possibly learn a trivial position model. PNAT can potentially yield better results with the position model to infer the relatively ordered alignment relationship.
Table 2: Results on validation set and test set of Quora.
<table><tr><td>Model Valid</td><td>Paraphrase(BLEU) Test</td></tr><tr><td>Seq-to-seq(GRU) Transformer</td><td>24.68 24.75 25.46</td></tr><tr><td>NAT-base</td><td>25.88 19.80</td></tr><tr><td>PNAT 29.30</td><td>20.34 29.00</td></tr></table>
The results of the paraphrase generation are shown in Table 2. In consist with our intuition, PNAT achieves the best result on this task and even surpass Transformer around 3.5 BLEU. The NAT model is not powerful enough to capture the latent position relationship. The comparison between NAT-base and PNAT shows that explicit position modeling in PNAT plays a crucial role in generating sentences.
# 4.4 ANALYSIS
Effectiveness of Heuristic Searched Position First, we analyze whether the position derived from the heuristic search is suitable for use as supervision to the position predictor. We evaluate the effectiveness of the searched position by training a PNAT as before and testing with the heuristic searched position instead of the predicted position. As shown in the second block of the Table 3, it is easier noticed that as PNAT w/ HSP achieves a significant improvement over the NAT-base and the Transformer, which demonstrates that the heuristic search for the position is effective.
<table><tr><td>Model</td><td colspan="2">Position Accuracy(%) permutation-acc relative-acc(r=4)</td><td>WMT14DE-EN BLEU</td><td>Speed Up</td></tr><tr><td>Transformer(beam=4)</td><td>/</td><td>1</td><td>30.68</td><td>1.0×</td></tr><tr><td>NAT-base</td><td>/</td><td>/</td><td>16.71</td><td>13.5×</td></tr><tr><td>PNATw/HSP</td><td>100.00</td><td>100.00</td><td>46.03</td><td>12.5×</td></tr><tr><td>PNATw/AR-Predictor</td><td>25.30</td><td>59.27</td><td>27.11</td><td>7.3×</td></tr><tr><td>PNAT w/NAR-Predictor</td><td>23.11</td><td>55.57</td><td>20.81</td><td>11.7×</td></tr></table>
Table 3: Results on validation set of WMT14 DE-EN with different position strategy. “HSP” means the reference position sequence derived from the heuristic position searching.
Effectiveness and Efficiency of Position Modeling We are also analysis the accuracy of our position modeling and its influence on the quality of generation on the WMT14 DE-EN task. For evaluating the position accuracy, we adopt the heuristic searched position as the position reference (denoted as “HSP”), which is the training target of the position predictor. PNAT requires the position information at two places. The first is the mutual relative relationship between the states that will be used during decoding. And the second is to reorder the decoded output after decoding. We then propose the corresponding metrics for evaluation, which is the relative position accuracy (with relation threshold $r = 4$ ) and the permutation accuracy.
As shown in Table 3, better position accuracy always yields better generation performance. The non-autoregressive position model is less effective than the current autoregressive position model, both in the accuracy of the permutation and the relative position. Even though the current PNAT with a simple AR-Predictor has surpassed the previous NAT model, the position accuracy is still less desirable (say, less than $30 \%$ ) and has a great exploration space. We provide a few examples in Appendix B. There is also a trade-off between the effectiveness and efficiency, the choice of the non-autoregressive means the efficiency and the choice of autoregressive means the effectiveness.
Repeated Generation Analysis Previous NAT often suffers from the repeated generation problem due to the lack of sequential position information. NAT is less effective to distinguish adjacent decoder hidden states, which is copied from the adjacent source representation. To further study this problem, we proposed to evaluate the gains of simply remove the repeated tokens. As shown in Table 4, we perform the repeated generation analysis on the paraphrase generation tasks. Removing repeated tokens has little impact for PNAT model, with only 0.05 BLEU differences. However for the NAT-base model, the gap comes with almost 1 BLEU (0.89). The results clearly demonstrate that the explicitly position model essentially learns the sequential information for sequence generation.
Table 4: Results on test set of Quora.
<table><tr><td rowspan="2">Model</td><td colspan="2">Paraphrase(Test-BLEU)</td><td></td></tr><tr><td>w/ remove repeats</td><td>w/o remove repeats</td><td>△BLEU</td></tr><tr><td>NAT-base</td><td>20.34</td><td>19.45</td><td>0.89</td></tr><tr><td>PNAT</td><td>29.00</td><td>28.95</td><td>0.05</td></tr></table>
Convergence Efficiency We also perform the training efficiency analysis in IWSLT16 DE-EN Translation task. The learning curves are shown in 2. The curve of the PNAT is on the top-left corner. Remarkably, PNAT has the best convergence speed compared with the NAT competitors and even a strong autoregressive model. The results are in line with our intuition, that the position learning brings meaningful information of position relationship and benefits the generation of the target sentence.
 Figure 2: The learning curves from training of models on evaluation set of IWSLT-16 DE-EN. Mini-batch size is 2048 tokens.
# 5 RELATED WORK
Gu et al. (2018) first develops a non-autoregressive Transformer for neural machine translation (NMT) tasks, which produces the outputs in parallel and the inference speed is thus significantly boosted.
Due to the removal of the dependencies between the target outputs, it comes at the cost that the translation quality is largely sacrificed. A line of work has been proposed to mitigate such performance degradation. Some previous work is focused on enhancing the decoder inputs by replacing the target words as inputs, such as Guo et al. (2019) and Lee et al. (2018). Lee et al. (2018) proposed a method of iterative refinement based on the latent variable model and denoising autoencoder. Guo et al. (2019) enhances decoder input by introducing the phrase table in statistical machine translation and embedding transformation. Another part of previous work focuses on improving the supervision of NAT’s decoder states, including imitation learning from autoregressive models (Wei et al., 2019) or regularizing the decoder state with backward reconstruction error (Wang et al., 2019). There is also a line studies build upon latent variables, such as Kaiser et al. (2018) and Roy et al. (2018) utilize discrete latent variables for making decoding more parallelizable. Moreover, Shao et al. (2019) also proposed a method to retrieve the target sequential information for NAT models. Unlike previous work, we explicitly model the position, which has shown its importance to the autoregressive model and can well model the dependence between states. To the best of our knowledge, PNAT is the first work to explicitly model position information for non-autoregressive text generation.
# 6 CONCLUSION
We proposed PNAT, a non-autoregressive transformer by explicitly modeled positions, which bridge the performance gap between the non-autoregressive decoding and autoregressive decoding. Specifically, we model the position as latent variables, and training with heuristic searched positions with MC algorithms. As a result, PNAT leads to significant improvement and move more close to the performance gap between the NAT and AT on machine translation tasks. Besides, the experimental results of the paraphrase generation task show that the performance of the PNAT can exceed that of the autoregressive model, and at the same time, it also has a large improvement space. According to our further analysis on effectiveness of position modeling, in future work, we can still enhance the performance of the NAT model by strengthening position learning.
# REFERENCES
Dzmitry Bahdanau, Kyunghyun Cho, and Yoshua Bengio. Neural machine translation by jointly learning to align and translate. arXiv preprint arXiv:1409.0473, 2014.
Kyunghyun Cho, Bart van Merrienboer, Caglar Gulcehre, Dzmitry Bahdanau, Fethi Bougares, Holger Schwenk, and Yoshua Bengio. Learning phrase representations using rnn encoder–decoder for statistical machine translation. In EMNLP, pp. 1724–1734, 2014.
Jonas Gehring, Michael Auli, David Grangier, Denis Yarats, and Yann N Dauphin. Convolutional sequence to sequence learning. In ICML, pp. 1243–1252, 2017.
Alex Graves, Abdel-rahman Mohamed, and Geoffrey Hinton. Speech recognition with deep recurrent neural networks. In 2013 IEEE international conference on acoustics, speech and signal processing, pp. 6645–6649. IEEE, 2013.
Jiatao Gu, James Bradbury, Caiming Xiong, Victor O.K. Li, and Richard Socher. Non-autoregressive neural machine translation. In ICLR, 2018.
Junliang Guo, Xu Tan, Di He, Tao Qin, Linli Xu, and Tie-Yan Liu. Non-autoregressive neural machine translation with enhanced decoder input. In AAAI, volume 33, pp. 3723–3730, 2019.
Ankush Gupta, Arvind Agarwal, Prawaan Singh, and Piyush Rai. A deep generative framework for paraphrase generation. In Thirty-Second AAAI Conference on Artificial Intelligence, 2018.
Geoffrey Hinton, Oriol Vinyals, and Jeff Dean. Distilling the knowledge in a neural network. arXiv preprint arXiv:1503.02531, 2015.
Lukasz Kaiser, Samy Bengio, Aurko Roy, Ashish Vaswani, Niki Parmar, Jakob Uszkoreit, and Noam Shazeer. Fast decoding in sequence models using discrete latent variables. In ICML, pp. 2395–2404, 2018.
Diederik P Kingma and Jimmy Ba. Adam: A method for stochastic optimization. arXiv preprint arXiv:1412.6980, 2014.
Philipp Koehn, Hieu Hoang, Alexandra Birch, Chris Callison-Burch, Marcello Federico, Nicola Bertoldi, Brooke Cowan, Wade Shen, Christine Moran, Richard Zens, Chris Dyer, Ondˇrej Bojar, Alexandra Constantin, and Evan Herbst. Moses: Open source toolkit for statistical machine translation. In ACL, pp. 177–180, 2007.
Alex Krizhevsky, Ilya Sutskever, and Geoffrey E Hinton. Imagenet classification with deep convolutional neural networks. In NIPS, pp. 1097–1105, 2012.
Jason Lee, Elman Mansimov, and Kyunghyun Cho. Deterministic non-autoregressive neural sequence modeling by iterative refinement. In EMNLP, pp. 1173–1182, 2018.
Zhuohan Li, Di He, Fei Tian, Tao Qin, Liwei Wang, and Tie-Yan Liu. Hint-based training for non-autoregressive translation. In NeuralIPS (to appear), 2019.
Tianyu Liu, Kexiang Wang, Lei Sha, Baobao Chang, and Zhifang Sui. Table-to-text generation by structure-aware seq2seq learning. In Thirty-Second AAAI Conference on Artificial Intelligence, 2018.
Xuezhe Ma, Chunting Zhou, Xian Li, Graham Neubig, and Eduard Hovy. FlowSeq: Nonautoregressive conditional sequence generation with generative flow. In EMNLP-IJCNLP, pp. 4273–4283, Hong Kong, China, November 2019. doi: 10.18653/v1/D19-1437. URL https://www.aclweb.org/anthology/D19-1437.
Ning Miao, Hao Zhou, Lili Mou, Rui Yan, and Lei Li. CGMH: Constrained sentence generation by Metropolis-Hastings sampling. In AAAI, 2019.
Kishore Papineni, Salim Roukos, Todd Ward, and Wei-Jing Zhu. BLEU: A method for automatic evaluation of machine translation. In ACL, pp. 311–318, 2002.
Aurko Roy, Ashish Vaswani, Niki Parmar, and Arvind Neelakantan. Towards a better understanding of vector quantized autoencoders. 2018.
Rico Sennrich, Barry Haddow, and Alexandra Birch. Neural machine translation of rare words with subword units. In ACL, pp. 1715–1725, 2016.
Chenze Shao, Yang Feng, Jinchao Zhang, Fandong Meng, Xilin Chen, and Jie Zhou. Retrieving sequential information for non-autoregressive neural machine translation. In ACL, 2019.
Peter Shaw, Jakob Uszkoreit, and Ashish Vaswani. Self-attention with relative position representations. In NAACL-HLT, pp. 464–468, 2018.
Xiaoyu Shen, Hui Su, Yanran Li, Wenjie Li, Shuzi Niu, Yang Zhao, Akiko Aizawa, and Guoping Long. A conditional variational framework for dialog generation. In Proceedings of the 55th Annual Meeting of the Association for Computational Linguistics (Volume 2: Short Papers), pp. 504–509, 2017.
Yikang Shen, Zhouhan Lin, Athul Paul Jacob, Alessandro Sordoni, Aaron Courville, and Yoshua Bengio. Straight to the tree: Constituency parsing with neural syntactic distance. In ACL, pp. 1171–1180, 2018.
Martin Sundermeyer, Ralf Schluter, and Hermann Ney. Lstm neural networks for language modeling. ¨ In Thirteenth annual conference of the international speech communication association, 2012.
Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Łukasz Kaiser, and Illia Polosukhin. Attention is all you need. In NIPS, pp. 5998–6008, 2017.
Oriol Vinyals, Meire Fortunato, and Navdeep Jaitly. Pointer networks. In NIPS, pp. 2692–2700, 2015.
Yiren Wang, Fei Tian, Di He, Tao Qin, ChengXiang Zhai, and Tie-Yan Liu. Non-autoregressive machine translation with auxiliary regularization. In AAAI, 2019.
Bingzhen Wei, Mingxuan Wang, Hao Zhou, Junyang Lin, and Xu Sun. Imitation learning for non-autoregressive neural machine translation. In ACL, 2019.
# A HEURISTIC SEARCH FOR POSITIONS
# Algorithm 1 Heuristic Search for Positions
Input: The candidates set of decoder inputs: $D = \{ d _ { 1 } , \cdots , d _ { M } \}$ and target embeddings: $Y =$ $\{ y _ { 1 } , \cdots , y _ { M } \}$ ; Output: The position of the decoder inputs $\hat { z }$ . 1: initial $A { \stackrel { \cdot } { = } } \{ \} , { \hat { D } } = D , { \hat { Y } } = Y$ ; 2: compute the similarity matrix $\mathrm { S i m } _ { D , Y }$ : the $\mathrm { S i m } [ i , j ]$ in the matrix is the the similarity between the $d _ { i }$ and $y _ { j }$ computing with $\mathrm { s i m } _ { i , j } =$ cosine $( d _ { i } , y _ { j } )$ ; 3: repeat 4: extract the similarity matrix $\mathrm { S i m } _ { \hat { D } , \hat { Y } }$ from the $\mathrm { S i m } _ { D , Y }$ ; 5: select: (i, j) = arg max(i,j) SimD,ˆ Yˆ 6: update: $A A \cup \{ ( i , j ) \}$ , $\hat { D } \hat { D } \setminus \{ d _ { i } \} , \hat { Y } \hat { Y } \setminus \{ y _ { j } \} ;$ 7: until $\hat { D } = \left\{ \begin{array} { r l r } \end{array} \right\}$ and $\hat { Y } = \{ \}$ 8: for each pair $( i , j )$ in $A$ do set $\hat { z } _ { i } = j$ 9: end for; 10: return $\hat { z }$
As shown in Algorithm 1, we perform a greedy algorithm to select the pair with the highest similarity score iteratively until the permutation $\hat { z }$ is generated.
The complexity of this algorithm is $o ( M ^ { 3 } )$ ( $M$ is the length of output sentence). Specifically, the complexity to select the maximum from the similarity matrix is $o ( \dot { M } ^ { 2 } )$ for each loop. We need $M$ loops of greedy search to allocate positions for all decoder inputs.
# B CASE STUDY OF PREDICTED POSITIONS
We also provide a few examples in Table 5. For each source sentence, we first analyze the generation quality of the PNAT with a heuristic searched position. Besides, we also show the translation with the predicted position. We have the following observations: First, the output generated by the PNAT using the heuristic searched position always keeps the high consistency with the reference, shows the effectiveness of the heuristic searched position. Second, better position accuracy always yields better generation performance (Case 1,2 against Case 3). Third, as we can see in case 4, though the permutation accuracy is lower, it still generates a good result, the reason why we chose to use the relative self-attention instead of absolute self-attention.
Table 5: Examples of translation outputs from PNAT with different setting on WMT14 DE-EN. It is should be noted that the length is different between the position sequence and the output sequence because we keep the origin position output and combine the BPE sequence to word sequence.
<table><tr><td>Source</td><td>bei dem deutschen Gesetz geht es um die Zuweisung bei der Geburt.</td></tr><tr><td>Reference Heuristic Searched Position(HSP) PNATw/HSP</td><td>German law is about assigning it at birth . 3,6, 1, 2, 10, 0, 5,4, 7, 8, 9 German law is about assigning them at birth .</td></tr><tr><td>PredictedPosition PNAT w/Predicted Postion</td><td>3, 6,1, 2, 10, 0, 5, 4, 7, 8, 9 German law is about assigning them at birth .</td></tr><tr><td>Source</td><td>weiB er über das Telefon @-@ Hacking Bescheid ?</td></tr><tr><td>Reference Heuristic Searched Position(HSP) PNATw/HSP</td><td>does he know about phone hacking ? 2, 1, 3,4, 8,5,6, 0, 7,9 does he know the telephone hacking ?</td></tr><tr><td>PredictedPosition PNAT w/Predicted Postion</td><td>1, 0, 3,4, 8,5, 6,2, 7, 9 he know about the telephone hacking ?</td></tr><tr><td>Source</td><td>was CCAAbedeutet,mochte eineBesucherin wissen.</td></tr><tr><td>Reference Heuristic Searched Position(HSP)</td><td>one visitor wants to know what CCAA means . 5,6, 7,8,9,3,2, 0,1, 11,4, 10</td></tr><tr><td>PNATw/HSP Predicted Position</td><td>a visitor wants to know what CCAA means . 5,0, 1, 2,3, 7,4, 8, 9,11,6, 10</td></tr><tr><td>PNAT w/Predicted Postion Source</td><td>CCAA means wants to know to a visitor . eines von 2O Kindern in den Vereinigten</td></tr><tr><td></td><td>Staaten hat inzwischen eine Lebensmittelal-</td></tr><tr><td>Reference</td><td>lergie . one in 20 children in the United States now</td></tr><tr><td>Heuristic Searched Position(HSP)</td><td>have food allergies . 14,1,2, 3,4,5,6,7,9,8,0,10,11, 12,13</td></tr><tr><td>PNAT w/HSP Predicted Position</td><td>one of 2O children in theUnited Statesnowhas food allergy . 14, 0, 1, 2, 3,4,5, 6, 8,7, 9, 10, 11, 12, 13</td></tr></table>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261# EXPLORING ASYMMETRIC ENCODER-DECODER STRUCTURE FOR CONTEXT-BASED SENTENCE REPRESENTATION LEARNING
Anonymous authors Paper under double-blind review
# ABSTRACT
Context information plays an important role in human language understanding, and it is also useful for machines to learn vector representations of language. In this paper, we explore an asymmetric encoder-decoder structure for unsupervised context-based sentence representation learning. As a result, we build an encoderdecoder architecture with an RNN encoder and a CNN decoder, and we show that neither an autoregressive decoder nor an RNN decoder is required. We further combine a suite of effective designs to significantly improve model efficiency while also achieving better performance. Our model is trained on two different large unlabeled corpora, and in both cases transferability is evaluated on a set of downstream language understanding tasks. We empirically show that our model is simple and fast while producing rich sentence representations that excel in downstream tasks.
# 1 INTRODUCTION
Learning distributed representations of sentences is an important and hard topic in both the deep learning and natural language processing communities, since it requires machines to encode a sentence with rich language content into a fixed-dimension vector filled with continuous values. We are interested in learning to build a distributed sentence encoder in an unsupervised fashion by exploiting the structure and relationship in a large unlabeled corpus. Since humans interpret sentences by composing from the meanings of the words, we decompose the task of learning a sentence encoder into two essential components: learning distributed word representations, and learning how to compose a sentence representation from the representations of words in the given sentence.
Numerous studies in human language processing have claimed that the context in which words and sentences are understood plays an important role in human language understanding (Altmann & Mirkovic, 2009; Binder & Desai, 2011). The idea of learning from the context information (Turney & Pantel, 2010) was recently successfully applied to vector representation learning for words in Mikolov et al. (2013); Pennington et al. (2014).
Collobert et al. (2011) proposed a unified framework for learning language representation from the unlabeled data, and it is able to generalize to various NLP tasks. Inspired by the prior work on incorporating context information into representation learning, Kiros et al. (2015) proposed the Skipthought model, which is an encoder-decoder model for unsupervised sentence representation learning. The paper exploits the semantic similarity within a tuple of adjacent sentences as supervision, and successfully built a generic, distributed sentence encoder. Rather than applying the conventional autoencoder model, the skip-thought model tries to reconstruct the surrounding 2 sentences instead of the input sentence. The learned sentence representation encoder outperforms previous unsupervised pretrained models on the evaluation tasks with no finetuning, and the results are comparable to the models which were trained directly on the datasets in a supervised fashion.
The usage of 2 independent decoders in Skip-thought model matches our intuition that, given the current sentence, inferring the previous sentence and inferring the next one should be different. Recently, Tang et al. (2017) proposed the Skip-thought Neighbor model, which only decodes the next sentence, and the performance on the downstream tasks is similar to that of their implementation of the Skip-thought model.
 Figure 1: Our proposed model is composed of an RNN encoder, and a CNN decoder. During training, a batch of sentences are sent to the model, and the RNN encoder computes a vector representation for each of sentences; then the CNN decoder needs to reconstruct the paired target sequence, which contains 30 contiguous words right after the input sentence, given the vector representation. 300 is the dimension of word vectors. $D$ is the dimension of sentence representation, and it varies along with the change of the RNN encoder size. (Better view in color.)
In this paper, we follow the idea in the Skip-thought Neighbor model, which exploits the subsequent context information for learning representation, and aim to bring asymmetry into structure design as well. Our proposed model has an asymmetric encoder-decoder structure, which keeps an RNN as the encoder and has a CNN as the decoder, and will be referred to as an “RNN-CNN” model. The key components of our model design can be summarized as:
1. a bidirectional RNN encodes the input sentence, and a CNN decodes all words in the paired target sequence at once, which speeds up the training process; 2. the supervision for training comes from inferring the next contiguous words given the current sentence, which helps the model to learn from the context in an unsupervised fashion; 3. the mean+max pooling captures complex interactions among words, which augments the transferability of the proposed model; 4. tying word embeddings in the encoder with the word prediction layer in the decoder constrains the input and output space to be the same, which also reduces number of parameters and regularizes the model.
We demonstrate the transferability of our model by evaluation on various downstream tasks, and the performance shows that our model improves both results and training efficiency.
# 2 RNN-CNN MODEL
Our model is highly asymmetric in terms of both training pairs and model structure. Specifically, our model has an RNN as the encoder, and a CNN as the decoder. During training, the encoder takes the $i$ - th sentence $s _ { i }$ as input, and then generates a fixed-dimension vector $\mathbf { z } _ { i }$ as the sentence representation; the decoder is applied to reconstruct the next sentence or the subsequent few contiguous words $t _ { i }$ . The difference of the generated sequence and the target sequence is measured by cross-entropy loss. An illustration is in Figure 1. (For simplicity, we omit the subscript $i$ in the section.)
Encoder: The encoder is a bi-directional Gated Recurrent Unit (GRU) (Chung et al., 2014). We experimented with both Long-short Term Memory (LSTM, Hochreiter & Schmidhuber (1997)) and GRU. Since LSTM didn’t give us significant performance boost, and generally GRU runs faster than LSTM, in our experiments, we stick to using GRU in the encoder. Suppose that a sentence $s$ contains $M$ words, which are $\boldsymbol { w } ^ { 1 } , \boldsymbol { w } ^ { 2 } , . . . , \boldsymbol { w } ^ { M }$ , and they are transformed by an embedding matrix $\mathbf { E }$ to word vectors. The bi-directional GRU will take one word vector at a time, and run in both forward and backward direction; both sets of hidden states are concatenated to form the hidden state matrix $\mathbf { H } = [ \mathbf { h } ^ { 1 } , \mathbf { h } ^ { 2 } , . . . , \mathbf { h } ^ { M } ] \in \mathbb { R } ^ { D \times M }$ , where $d$ is the dimension of the representations $\mathbf { h } ^ { m } = \left[ \overleftarrow { \mathbf { h } ^ { m } } ; \overrightarrow { \mathbf { h } ^ { m } } \right]$ $( \forall m \in \{ 1 , 2 , . . . , M \} )$ .
Representation: We aim to provide a model with faster training speed with better transferability than existing algorithms, thus we choose to apply a parameter-free composition function, which is a concatenation of the outputs from a global mean pooling over time and a global max pooling over time, on the computed sequence of hidden states. The composition function can be represented as
$$\mathbf { z } = \left[ \frac { 1 } { M } \sum _ { m = 1 } ^ { M } \mathbf { h } ^ { m } ; \operatorname* { m a x } \mathbf { H } _ { \mathrm { 1 } \cdot } ; \operatorname* { m a x } \mathbf { H } _ { \mathrm { 2 } \cdot } ; . . . ; \operatorname* { m a x } \mathbf { H } _ { d } \right] ,$$
where max $\mathbf { H } _ { d }$ · is the max operation on the $d$ -th row of the matrix $\mathbf { H }$ , which outputs a scalar. Thus the representation $\mathbf { z }$ has a dimension of $2 d$ .
Decoder: The decoder is a 3-layer CNN to reconstruct the paired target sequence $t$ , which needs to expand $\mathbf { z }$ from length 1 to the length of $t$ . Intuitively, the decoder could be a stack of deconvolution layers. For fast training speed, we optimized the architecture to make it plausible to use fullyconnected layers and convolution layers in the decoder, since generally, convolution layers run faster than deconvolution layers in modern deep learning frameworks.
Suppose that the target sequence $t$ has $N$ words, the first layer of deconvolution will expand $\mathbf { z }$ , which could be considered as a sequence with length 1, into a feature map with length $N$ . It can be easily implemented as a concatenation of outputs from $N$ linear transformations in parallel. Then the second and third layer are 1D-convolution layers with kernel size 3 and 1, respectively. The output feature map $\mathbf { V } = [ \bar { \mathbf { v } } ^ { 1 } , \mathbf { v } ^ { 2 } , . . . , \mathbf { v } ^ { N } ]$ , where $\mathbf { v } \in \mathbb { R } ^ { e }$ , and $e$ is dimension of the word vectors.
Note that our decoder is not an autoregressive model, and it brings us high training efficiency. We will discuss the reason of choosing this decoder which we call a predict-all-words CNN decoder.
Objective: A softmax layer is applied after the decoder to produce a probability distribution over words at each position, softmax $\left( \mathbf { E v } ^ { n } \right)$ , and the training objective is to minimize the sum of the negative log-likelihood over all positions in the target sequence $t$ :
$$\mathcal { L } = - \sum _ { n = 1 } ^ { N } \log P ( w ^ { n } | \mathbf { z } ) .$$
The loss function $\mathcal { L }$ is summed over all sentences in the training corpus.
# 3 ARCHITECTURE DESIGN
We follow the idea of an encoder-decoder model with using the context information for learning sentence representations in an unsupervised fashion. Since the decoder won’t be used after training, and the quality of the generated sequences is not our main focus, it is important to study the design of the decoder. Generally, a fast training algorithm is preferred, thus proposing a new decoder with high training efficiency and also strong transferability is crucial for an encoder-decoder model.
# 3.1 CNN AS THE DECODER
Our design of the decoder is basically a 3-layer ConvNet, and it predicts all words in the next sequence all at once. In contrast, existing work, such as Skip-thought Kiros et al. (2015), and CNN-LSTM Gan et al. (2017),use autoregressive RNNs as the decoders.
An autoregressive model is good at generating sequences with high quality, such as language and speech. However, an autoregressive decoder seems to be unnecessary in an encoder-decoder model for learning sentence representations, since it won’t be used after training, and it runs quite slow during training. Therefore, we conducted experiments to test the necessity of using an autoregressive decoder in learning sentence representations, and we had 2 findings.
Finding I: It is not necessary to input the correct words into an autoregressive decoder in terms of learning good sentence representations.
<table><tr><td>Decoder</td><td>SICK-r</td><td>SICK-E</td><td>STS14</td><td>MSRP (Acc/F1)</td><td>SST</td><td>TREC</td></tr><tr><td colspan="7">auto-regressive RNN as decoder</td></tr><tr><td>Baseline</td><td>0.8530</td><td>82.6</td><td>0.51/0.50</td><td>74.1/81.7</td><td>82.5</td><td>88.2</td></tr><tr><td>Always Sampling</td><td>0.8576</td><td>83.2</td><td>0.55/0.53</td><td>74.7 /81.3</td><td>80.6</td><td>87.0</td></tr><tr><td>Uniform Sampling</td><td>0.8559</td><td>82.9</td><td>0.54/0.53</td><td>74.0 / 81.8</td><td>81.0</td><td>87.4</td></tr><tr><td colspan="7">auto-regressive CNN as decoder</td></tr><tr><td>Baseline</td><td>0.8510</td><td>82.8</td><td>0.49/0.48</td><td>74.7/82.8</td><td>81.4</td><td>82.6</td></tr><tr><td>Always Sampling</td><td>0.8535</td><td>83.3</td><td>0.53/0.52</td><td>75.0/81.7</td><td>81.4</td><td>87.6</td></tr><tr><td>Uniform Sampling</td><td>0.8568</td><td>83.4</td><td>0.56/0.54</td><td>74.7 /81.4</td><td>83.0</td><td>88.4</td></tr><tr><td colspan="7">predict-all-words RNN as decoder</td></tr><tr><td>RNN</td><td>0.8508</td><td>82.8</td><td>0.58/0.55</td><td>74.2/82.8</td><td>81.6</td><td>88.8</td></tr><tr><td colspan="7">predict-all-words CNN as decoder</td></tr><tr><td>CNN</td><td>0.8530</td><td>82.6</td><td>0.58/0.56</td><td>75.6/82.9</td><td>82.8</td><td>89.2</td></tr><tr><td>CNN-Max</td><td>0.8465</td><td>82.6</td><td>0.50/0.47</td><td>73.3 / 81.5</td><td>79.1</td><td>82.2</td></tr><tr><td colspan="7">Double-sized RNN Encoder</td></tr><tr><td>CNN</td><td>0.8631</td><td>83.9</td><td>0.58/0.55</td><td>74.7 /83.1</td><td>83.4</td><td>90.2</td></tr><tr><td>CNN-Max</td><td>0.8485</td><td>83.2</td><td>0.47/0.44</td><td>72.9 / 80.8</td><td>82.2</td><td>86.6</td></tr></table>
Table 1: The models here all have a bi-directional GRU as the encoder (dimensionality 300 in each direction). The default way of producing the representation is a concatenation of outputs from a global mean-pooling and a global max-pooling, while “·-Max” refers to the model with only global maxpooling. Bold numbers are the best results among all presented models. We found that 1) inputting correct words to an autoregressive decoder is not necessary; 2) predict-all-words decoders work roughly the same as autoregressive decoders; 3) mean+max pooling provides stronger transferability than the max-pooling alone does. The table supports our choice of the predict-all-words CNN decoder and the way of producing vector representations from the bi-directional RNN encoder.
The experimental design was inspired by Bengio et al. (2015). The model we designed for the experiment has a bi-directional GRU as the encoder, and an autoregressive decoder, including both RNN and CNN. We started by analyzing the effect of different sampling strategies of the input words on learning an auto-regressive decoder.
We compared 3 autoregressive decoding settings: 1) using ground-truth words (Baseline), 2) using previously predicted words (Always Sampling), and 3) using uniformly sampled words from the dictionary (Uniform Sampling). The 3 decoding settings were named by Bengio et al. (2015). The results are presented in the Table 1.
Generally, the three different decoding settings didn’t make much of a difference in terms of the performance on selected downstream tasks, with RNN or CNN as the decoder. The results tell us that, in terms of learning good sentence representations, the autoregressive decoder doesn’t require the correct ground-truth words as the inputs.
# Finding II: The model with an autoregressive decoder works roughly the same as the model with a predict-all-words decoder.
With Finding I, we noticed that the correct ground-truth input words to the autoregressive decoder is not necessary in terms of learning sentence representations. Therefore, it makes sense to test whether we need an autoregressive model at all.
In our model, the CNN decoder predicts all words at once during training, which is different from autoregressive decoders, and we call it a predict-all-words CNN decoder. We want to compare the performance of the predict-all-words decoders and that of the autoregressive decoders separate from the RNN/CNN distinction, thus we designed a predict-all-words CNN decoder and RNN decoder.
The predict-all-words CNN decoder is described in Section 2, which is a stack of 3 convolutional layers, and all words are predicted once at the output of the decoder. The predict-all-words RNN decoder is built based on our CNN decoder. To keep the number of parameters roughly the same, we replaced the last 2 convolutional layers with a bidirectional GRU.
The results are also presented in the Table 1. The performance of the predict-all-words RNN decoder does not significantly differ from that of any one of the autoregressive RNN decoders, and the same observation was observed in CNN decoders.
These two findings actually support our choice of using a predict-all-words CNN as the decoder, and it brings the model higher training efficiency and strong transferability.
# 3.2 MEAN $^ +$ MAX POOLING
Since the encoder is a bi-directional RNN in our model, we have multiple ways to select/compute on the generated hidden states to produce a sentence representation. In Skip-thought (Kiros et al., 2015) and SDAE (Hill et al., 2016), only the hidden state at the last time step produced by the RNN encoder is regarded as the vector representation for a given sentence, which may not be the most expressive vector for representing the input sentence.
We followed the idea proposed in Chen et al. (2016). They built a model for supervised SNLI task (Bowman et al., 2015) that concatenates the outputs from a global mean pooling and a global max pooling to serve as a sentence representation, and showed a performance boost on the SNLI dataset. Also, Conneau et al. (2017) found that the model with global max pooling function has stronger transferability than the model with a global mean pooling function after supervised training on SNLI.
In our proposed RNN-CNN model, we empirically show that the mean $+$ max pooling provides stronger transferability than the max pooling does, and the results are presented in Table 1. The concatenation of a mean-pooling and a max pooling function is actually a parameter-free composition function, and the computation load is negligible compared to heavy matrix multiplications. Also, the non-linearity of the max pooling function augments the mean pooling function for building a representation that captures a more complex composition of the syntactic information.
# 3.3 TYING WORD EMBEDDINGS AND WORD PREDICTION LAYER
We choose to share the parameters in the word embedding layer in RNN encoder and the word prediction layer in CNN decoder. The tying was proposed in both Press & Wolf (2017) and Inan et al. (2016), and it generally helps to learn a better language model. In our model, the tying also drastically reduces the number of parameters, which could prevent overfitting.
Furthermore, we initialize the word embeddings with pretrained word vectors, such as word2vec (Mikolov et al., 2013) and GloVe (Pennington et al., 2014), since it has been shown that these pretrained word vectors can serve as good initialization for deep learning models, and more likely lead to better results than random samples from a uniform distribution.
# 3.4 STUDY OF THE HYPERPARAMETERS IN OUR MODEL DESIGN
We studied hyperparameters in our model design based on 3 out of 10 downstream tasks, including SICK-r, SICK-E (Marelli et al., 2014), and STS14 (Agirre et al., 2014). The first model we created, which is reported in Section 2, is a decent design, and the following variations didn’t give us much performance change except small improvements with increasing the dimensionality of the encoder. However, we think it is worth mentioning the effect of hyperparameters in our model design. We present the Table in the supplementary material and we summarize it as follows:
1. Decoding the next sentence worked similarly as decoding the subsequent contiguous words. 2. Decoding subsequent 30 words, which was adopted from the Skip-thought training code 1, gave us a reasonable good performance. More words for decoding didn’t give us a significant performance gain, while it took longer to train. 3. Adding more layers into the decoder and enlarging the dimension of the convolutional layers indeed sightly improved the performance on the 3 downstream tasks, but as training efficiency is one of our main concerns, we decided it wasn’t worth sacrificing training efficiency for the minor performance improvement.
4. Increasing the dimensionality of the RNN encoder improved the model performance, and the additional training time brought by it was less than that by adding more layers and enlarging the dimension of the convolutional layers in the CNN decoder. We reported results from both smallest and largest models in Table 2.
# 4 EXPERIMENT SETTINGS
The large corpus we used for unsupervised training is the BookCorpus dataset Zhu et al. (2015), which contains 74 million sentences from 7000 books in total. For stable training, we use ADAM (Kingma & Ba, 2014) algorithm for optimization, and gradient clipping (Pascanu et al., 2013) when the norm of gradient exceeds a certain value. Since we didn’t find any significant difference between word2vec and GloVe as initialization in terms of the performance, we stick to using the word vectors from word2vec to initialize the word embedding layer in our models.
The vocabulary for unsupervised training contains the top $2 0 \mathrm { k }$ most frequent words in BookCorpus. In order to generalize the model trained with a relatively small, fixed vocabulary to the much larger set of all possible English words, Kiros et al. (2015) proposed a word expansion method that learns a linear projection from the pretrained word embeddings word2vec to the learned RNN word embeddings. Thus, the model benefits from the generalization ability of the pretrained word embeddings.
The downstream tasks for evaluation include semantic relatedness (SICK) (Marelli et al., 2014), paraphrase detection (MSRP) (Dolan et al., 2004), question-type classification (TREC) (Li & Roth, 2002), and 5 benchmark sentiment and subjective datasets, which includes movie review sentiment (MR, SST) (Pang & Lee, 2005; Socher et al., 2013), customer product reviews (CR) (Hu & Liu, 2004), subjectivity/objectivity classification (SUBJ) (Pang & Lee, 2004), opinion polarity (MPQA) (Wiebe et al., 2005), and semantic textual similarity (STS14) (Agirre et al., 2014). After unsupervised training on the BookCorpus dataset, we fix the parameters in the encoder, and apply it as a sentence representation extractor on the 10 tasks.
In order to compare the effect of different corpora, we also trained 2 models on Amazon Book Review dataset (without ratings) which is the largest subset of the Amazon Review dataset (McAuley et al., 2015) with 142 million sentences after tokenization, about twice as large as BookCorpus.
Both training and evaluation of our models were conducted in PyTorch 2, and we used SentEval 3 provided by Conneau et al. (2017) to evaluate the transferability of models with different settings. All the models were trained for the same number of iterations with the same batch size, and the performance was measured at the end of training for each of the models.
# 5 RELATED WORK AND COMPARISON
Table 2 presented the results on 10 evaluation tasks of our proposed RNN-CNN models, and related work. “small RNN-CNN” refers to the model with the dimension of representation as 1200, and “large RNN-CNN” refers to that as 4800. The results of our model on SNLI can be found in Table 3.
Our work was inspired by analyzing the Skip-thought model (Kiros et al., 2015). Skip-thought model successfully applied this form of learning from the context information into unsupervised representation learning for sentences, in which the model learns to encode the current sentence and decode the surrounding 2 sentences, and then, Ba et al. (2016) augmented the LSTM with proposed layer-normalization (Skip-thought+LN), which improved the skip-thought model generally on all downstream tasks. Instead of applying RNNs in the model, Hill et al. (2016) proposed the FastSent model which only learns source and target word embeddings, and it is a generalization of CBOW (Mikolov et al., 2013) to sentence-level learning, and the composition function over word embeddings is a summation operation. Later on, Gan et al. (2017) applied a CNN as the encoder, which is called the CNN-LSTM model. The proposed composition model follows the idea of encoding the current sentence and predicting itself and the next sentence; the proposed hierarchical model leverages the context information from both sentence-level and paragraph-level, while learning to encode the current sentence and predict the next one, the model has another RNN to process the sentence representation one at a time at paragraph-level.
<table><tr><td>Model</td><td>Hrs</td><td>SICK-r</td><td>SICK-E</td><td>STS14</td><td>MSRP</td><td></td><td>TREC MR</td><td>CR</td><td></td><td>SUBJ MPQA SST</td><td></td></tr><tr><td colspan="10">Unsupervised training with unordered sentences</td><td></td><td></td><td></td></tr><tr><td>Unigram-TFIDF</td><td>-</td><td>-</td><td>-</td><td></td><td>73.6/81.7</td><td>85.0</td><td>73.7</td><td>79.2</td><td>90.3</td><td>82.4</td><td>-</td></tr><tr><td>ParagraphVec</td><td>4</td><td>-</td><td>-</td><td>0.42/0.43</td><td>72.9/81.1</td><td>59.4</td><td>60.2</td><td>66.9</td><td>76.3</td><td>70.7</td><td>-</td></tr><tr><td>word2vec BOW</td><td>2</td><td>0.8030</td><td>78.7</td><td>0.65/0.64</td><td>72.5/81.4</td><td>83.6</td><td>77.7</td><td>79.8</td><td>90.9</td><td>88.3</td><td>79.7</td></tr><tr><td>fastText BOW</td><td>-</td><td>0.8000</td><td>77.9</td><td>0.63/0.62</td><td>72.4/81.2</td><td>81.8</td><td>76.5</td><td>78.9</td><td>91.6</td><td>87.4</td><td>78.8</td></tr><tr><td>GloVe BOW</td><td>-</td><td>0.8000</td><td>78.6</td><td>0.54/0.56</td><td>72.1/80.9</td><td>83.6</td><td>78.7</td><td>78.5</td><td>91.6</td><td>87.6</td><td>79.8</td></tr><tr><td>SDAE</td><td>72</td><td>-</td><td>-</td><td>0.37/0.38</td><td>73.7/80.7</td><td>78.4</td><td>74.6</td><td>78.0</td><td>90.8</td><td>86.9</td><td>-</td></tr><tr><td colspan="10">Unsupervised trainingwith ordered sentences-BookCorpus</td></tr><tr><td>DiscSent:</td><td>8</td><td>-</td><td>-</td><td>-</td><td>75.0/-</td><td>87.2</td><td>-</td><td>-</td><td>93.0</td><td>-</td><td>■</td></tr><tr><td>FastSent</td><td>2</td><td>-</td><td>-</td><td>0.63/0.64</td><td>72.2/80.3</td><td>76.8</td><td>70.8</td><td>78.4</td><td>88.7</td><td>80.6</td><td>■</td></tr><tr><td>FastSent+AE</td><td>2</td><td>-</td><td>-</td><td>0.62/0.62</td><td>71.2/79.1</td><td>80.4</td><td>71.8</td><td>76.5</td><td>88.8</td><td>81.5</td><td>-</td></tr><tr><td>Skip-thought</td><td>336</td><td>0.8580</td><td>82.3</td><td>0.29/0.35</td><td>73.0/82.0</td><td>92.2</td><td>76.5</td><td>80.1</td><td>93.6</td><td>87.1</td><td>82.0</td></tr><tr><td>Skip-thought+LN</td><td>720</td><td>0.8580</td><td>79.5</td><td>0.44/0.45</td><td>■</td><td>88.4</td><td>79.4</td><td>83.1</td><td>93.7</td><td>89.3</td><td>82.9</td></tr><tr><td>combine CNN-LSTM</td><td>-</td><td>0.8618</td><td>:</td><td>1</td><td>76.5/83.8</td><td>92.6</td><td>77.8</td><td>82.1</td><td>93.6</td><td>89.4</td><td>1</td></tr><tr><td>small RNN-CNN+</td><td>20</td><td>0.8530</td><td>82.6</td><td>0.58/0.56</td><td>75.6/82.9</td><td>89.2</td><td>77.6</td><td>80.3</td><td>92.3</td><td>87.8</td><td>82.8</td></tr><tr><td>large RNN-CNN+</td><td>34</td><td>0.8698</td><td>85.2</td><td>0.59/0.57</td><td>75.1/83.2</td><td>92.2</td><td>79.7</td><td>81.9</td><td>94.0</td><td>88.7</td><td>84.1</td></tr><tr><td colspan="10">Unsupervised training with ordered sentences-Amazon Book Review</td><td></td></tr><tr><td>small RNN-CNN+</td><td>21</td><td>0.8476</td><td>82.7</td><td>0.53/0.53</td><td>73.8/81.5</td><td>84.8</td><td>83.3</td><td>83.0</td><td>94.7</td><td>88.2</td><td>87.8</td></tr><tr><td>large RNN-CNN+</td><td>33</td><td>0.8616</td><td>84.3</td><td>0.51/0.51</td><td>75.7/82.8</td><td>90.8</td><td>85.3</td><td>86.8</td><td>95.3</td><td>89.0</td><td>88.3</td></tr><tr><td colspan="10">Unsupervised training with ordered sentences-Amazon Review</td></tr><tr><td>BYTE m-LSTM</td><td>720</td><td>0.7920</td><td>-</td><td></td><td>75.0/82.8</td><td>■</td><td>86.9</td><td>91.4</td><td>94.6</td><td>88.5</td><td>■</td></tr><tr><td colspan="10">Supervisedtraining-Transfer learning</td><td></td></tr><tr><td>NMTEn-to-Fr</td><td>72</td><td>-</td><td>=</td><td>0.43/0.42</td><td>-</td><td>82.8</td><td>64.7</td><td>70.1</td><td>84.9</td><td>81.5</td><td>■</td></tr><tr><td>CaptionRep BOW</td><td>24</td><td></td><td></td><td>0.46/0.42</td><td>-</td><td>72.2</td><td>61.9</td><td>69.3</td><td>77.4</td><td>70.8</td><td>=</td></tr><tr><td>DictRep BOW</td><td>24</td><td></td><td>=</td><td>0.67/0.70</td><td>68.4/76.8</td><td>81.0</td><td>76.7</td><td>78.7</td><td>90.7</td><td>87.2</td><td>-</td></tr><tr><td>BiLSTM-Max(SNLI)</td><td><24</td><td>0.8850</td><td>84.6</td><td>0.68/0.65</td><td>75.1/82.3</td><td>88.7</td><td>79.9</td><td>84.6</td><td>92.1</td><td>89.8</td><td>83.3</td></tr><tr><td>BiLSTM-Max(AlINLI)</td><td><24</td><td>0.8840</td><td>86.3</td><td>0.70/0.67</td><td>76.2/83.1</td><td>88.2</td><td>81.1</td><td>86.3</td><td>92.4</td><td>90.2</td><td>84.6</td></tr><tr><td colspan="10">Supervised task-dependent training-No transfer learning</td></tr><tr><td>NB-SVM</td><td>-</td><td></td><td></td><td></td><td></td><td>-</td><td>79.4</td><td>81.8</td><td>93.2</td><td>86.3</td><td>83.1</td></tr><tr><td>AdaSent</td><td>-</td><td>=</td><td></td><td></td><td></td><td>92.4</td><td>83.1</td><td>86.3</td><td>95.5</td><td>93.3</td><td>-</td></tr><tr><td>Tree-LSTM</td><td>、</td><td>0.8680</td><td></td><td></td><td>-</td><td>-</td><td>-</td><td>■</td><td>-</td><td>-</td><td>■</td></tr><tr><td>TF-KLD</td><td>-</td><td>-</td><td></td><td></td><td>80.4/85.9</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td></tr></table>
Table 2: Related Work and Comparison. As presented in the table, our designed asymmetric RNN-CNN model has strong transferability, and is overall better than existing unsupervised models in terms of fast training speed and good performance on evaluation tasks. The table presents the model comparison. “†”s refer to our models, and “small/large” refers to the dimension of representation as 1200/4800. “‡” indicates that DiscSent model was trained with additional data from Wikipedia and the Gutenberg project. Bold numbers are the best ones among the models with same training and transferring setting, and underlined numbers are best results among all unsupervised representation learning models. For STS14, the performance measures are Pearson’s and Spearman’s score. For MSRP, the performance measures are accuracy and F1 score.
Our model falls in the same category as it is an encoder-decoder model. However, we aim to propose an efficient and effective model. Instead of decoding the surrounding 2 sentences as in Skip-thought, FastSent and the compositional CNN-LSTM, our model only decodes the subsequent sequence with a fixed length. Compared with hierarchical CNN-LSTM, our model showed that, with a proper model design, this next-words context information is sufficient in learning sentence representations. Particularly, our proposed small RNN-CNN model runs roughly 3 times faster than our implemented Skip-thought model on the same GPU machine during training.
Another unsupervised approach is to learn a discriminative model by distinguishing whether a target sentence is in the context of the source sentence, and also the discourse information. DiscSent (Jernite et al., 2017) proposed to learn a classifier on top of the representations, which judges 1) whether the two sentences are adjacent to each other, 2) whether the two sentences are in the correct order, and 3) whether the second sentence starts with a conjunction phrase. DisSent (Nie et al., 2017) pointed out that human annotated explicit discourse relations is also good for learning sentence representations. It is a very promising research direction since the proposed models are generally computational efficient and have clear intuition. However, the performance on the downstream tasks is still worse than encoder-decoder models.
Proposed by Radford et al. (2017), BYTE m-LSTM model uses a multiplicative LSTM unit (Krause et al., 2016) to learn a language model on Amazon Review data McAuley et al. (2015). The model works reasonably well on the downstream tasks, since the RNNs are able to produce a distributed representation for the given left-context information, such as a sentence or a document. In our experiment, we also trained our RNN-CNN model on the Amazon Book review, which is the largest subset of the Amazon review dataset, and indeed, we had a performance gain on all single-sentence classification tasks. The performance gain in our experiment and also in BYTE m-LSTM was brought by the matching between the corpus domain and the domain of downstream tasks, and it raises 2 questions 1) which corpus is good for learning sentence representations, and 2) whether the downstream tasks are comprehensive to cover sufficient aspects of a sentence.
Previously mentioned models are learned from ordered sentences, but unordered sentences can also be used for learning representations of sentences. ParagraphVec (Le & Mikolov, 2014) learns a fixed-dimension vector for each sentence by predicting the words within the given sentence. However, after training, the representation for a new sentence is hard to derive, since it requires optimizing the sentence representation towards an objective. SDAE (Hill et al., 2016) learns the sentence representations with a denoising auto-encoder model. The noise was added in the encoder by replacing words with a fixed token, and swapping two words, both with a specific probability. Our proposed RNN-CNN model trains faster than SDAE does, since the CNN decoder runs faster than the RNN decoder in SDAE, and since we utilized the sentence-level continuity as a supervision which SDAE doesn’t, our model largely performs better than SDAE.
Table 3: We implemented the same classifier as mentioned in Vendrov et al. (2015) on top of the features computed by our model. Our proposed RNN-CNN model gets similar result on SNLI as Skip-thought, but with much less training time.
<table><tr><td rowspan=1 colspan=1>Model</td><td rowspan=1 colspan=1>SNLI (Acc %)</td></tr><tr><td rowspan=1 colspan=2>Unsupervised TransferLearning</td></tr><tr><td rowspan=1 colspan=1>Skip-thought (Vendrov et al.)largeRNN-CNN BookCorpuslarge RNN-CNN Amazon</td><td rowspan=1 colspan=1>81.581.781.5</td></tr><tr><td rowspan=1 colspan=2>SupervisedTraining</td></tr><tr><td rowspan=1 colspan=1>ESIM (Chen et al.)DIIN (Gong et al.)</td><td rowspan=1 colspan=1>86.788.9</td></tr></table>
Supervised transfer learning is also promising when we are able to get large enough labeled data. Conneau et al. (2017) applied a bi-directional LSTM as the sentence encoder with multiple fully-connected layers to deal with both SNLI (Bowman et al., 2015), and MultiNLI (Williams et al., 2017). The trained model demonstrates a very impressive transferability on all downstream tasks, including both supervised and unsupervised. The direct and discriminative training signal pushes the RNN encoder to focus on the semantics of a given sentence, which learns to a boost in performance, and beats all other methods. Our RNN-CNN model trained on Amazon Book Review data has better results on supervised classification tasks than BiLSTM-Max does, while the per
formance of ours on semantic relatedness tasks is inferior to BiLSTM-Max. We argue that labeling a large amount of training data is time-consuming and costly; unsupervised learning could potentially provide a great initial point for human labeling making it less costly and more efficient.
# 6 CONCLUSION
Inspired by learning to exploit the contextual information present in adjacent sentences, we proposed an asymmetric encoder-decoder model with a suite of techniques for improving context-based unsupervised sentence representation learning. Since we believe that a simple model will be faster in training and easier to analyze, we opt to use simple techniques in our proposed model, including 1) an RNN as the encoder, and a predict-all-words CNN as the decoder, 2) learning by inferring next contiguous words, 3) mean+max pooling, and 4) tying word vectors with word prediction. With thorough discussion and extensive evaluation, we justify our decision making for each component in our RNN-CNN model. In terms of the performance and the efficiency of training, we justify that our model is a fast and simple algorithm for learning generic sentence representations from unlabeled corpora. Further research will focus on how to maximize the utility of the context information, and how to design simple architectures to best make use of it.
# REFERENCES
Eneko Agirre, Carmen Banea, Claire Cardie, Daniel M. Cer, Mona T. Diab, Aitor Gonzalez-Agirre, Weiwei Guo, Rada Mihalcea, German Rigau, and Janyce Wiebe. Semeval-2014 task 10: Multilingual semantic textual similarity. In SemEval@COLING, 2014.
Gerry Altmann and Jelena Mirkovic. Incrementality and prediction in human sentence processing. Cognitive science, 33 4:583–609, 2009.
Jimmy Ba, Ryan Kiros, and Geoffrey E. Hinton. Layer normalization. CoRR, abs/1607.06450, 2016.
Samy Bengio, Oriol Vinyals, Navdeep Jaitly, and Noam Shazeer. Scheduled sampling for sequence prediction with recurrent neural networks. In NIPS, 2015.
Jeffrey R Binder and Rutvik H Desai. The neurobiology of semantic memory. Trends in cognitive sciences, 15 11:527–36, 2011.
Samuel R. Bowman, Gabor Angeli, Christopher Potts, and Christopher D. Manning. A large annotated corpus for learning natural language inference. In EMNLP, 2015.
Qian Chen, Xiaodan Zhu, Zhenhua Ling, Si Wei, and Hui Jiang. Enhancing and combining sequential and tree lstm for natural language inference. arXiv preprint arXiv:1609.06038, 2016.
Junyoung Chung, Caglar Gulcehre, KyungHyun Cho, and Yoshua Bengio. Empirical evaluation of gated recurrent neural networks on sequence modeling. arXiv preprint arXiv:1412.3555, 2014.
Ronan Collobert, Jason Weston, Léon Bottou, Michael Karlen, Koray Kavukcuoglu, and Pavel P. Kuksa. Natural language processing (almost) from scratch. Journal of Machine Learning Research, 12:2493–2537, 2011.
Alexis Conneau, Douwe Kiela, Holger Schwenk, Loïc Barrault, and Antoine Bordes. Supervised learning of universal sentence representations from natural language inference data. In EMNLP, 2017.
William B. Dolan, Chris Quirk, and Chris Brockett. Unsupervised construction of large paraphrase corpora: Exploiting massively parallel news sources. In COLING, 2004.
Zhe Gan, Yunchen Pu, Ricardo Henao, Chunyuan Li, Xiaodong He, and Lawrence Carin. Learning generic sentence representations using convolutional neural networks. In EMNLP, 2017.
Yichen Gong, Heng Luo, and Jian Zhang. Natural language inference over interaction space. CoRR, abs/1709.04348, 2017.
Felix Hill, Kyunghyun Cho, and Anna Korhonen. Learning distributed representations of sentences from unlabelled data. In HLT-NAACL, 2016.
Sepp Hochreiter and Juergen Schmidhuber. Long short-term memory. Neural Computation, 9: 1735–1780, 1997.
Minqing Hu and Bing Liu. Mining and summarizing customer reviews. In KDD, 2004.
Hakan Inan, Khashayar Khosravi, and Richard Socher. Tying word vectors and word classifiers: A loss framework for language modeling. CoRR, abs/1611.01462, 2016.
Yacine Jernite, Samuel R. Bowman, and David Sontag. Discourse-based objectives for fast unsupervised sentence representation learning. CoRR, abs/1705.00557, 2017.
Diederik Kingma and Jimmy Ba. Adam: A method for stochastic optimization. arXiv preprint arXiv:1412.6980, 2014.
Jamie Ryan Kiros, Yukun Zhu, Ruslan Salakhutdinov, Richard S. Zemel, Raquel Urtasun, Antonio Torralba, and Sanja Fidler. Skip-thought vectors. In NIPS, 2015.
Ben Krause, Liang Lu, Iain Murray, and Steve Renals. Multiplicative lstm for sequence modelling. CoRR, abs/1609.07959, 2016.
Quoc V. Le and Tomas Mikolov. Distributed representations of sentences and documents. In ICML, 2014.
Xin Li and Dan Roth. Learning question classifiers. In COLING, 2002.
Marco Marelli, Stefano Menini, Marco Baroni, Luisa Bentivogli, Raffaella Bernardi, and Roberto Zamparelli. A sick cure for the evaluation of compositional distributional semantic models. In LREC, 2014.
Julian J. McAuley, Christopher Targett, Qinfeng Shi, and Anton van den Hengel. Image-based recommendations on styles and substitutes. In SIGIR, 2015.
Tomas Mikolov, Ilya Sutskever, Kai Chen, Gregory S. Corrado, and Jeffrey Dean. Distributed representations of words and phrases and their compositionality. In NIPS, 2013.
Allen Nie, Erin D. Bennett, and Noah D. Goodman. Dissent: Sentence representation learning from explicit discourse relations. CoRR, abs/1710.04334, 2017.
Bo Pang and Lillian Lee. A sentimental education: Sentiment analysis using subjectivity summarization based on minimum cuts. In ACL, 2004.
Bo Pang and Lillian Lee. Seeing stars: Exploiting class relationships for sentiment categorization with respect to rating scales. In ACL, 2005.
Razvan Pascanu, Tomas Mikolov, and Yoshua Bengio. On the difficulty of training recurrent neural networks. In ICML, 2013.
Jeffrey Pennington, Richard Socher, and Christopher D. Manning. Glove: Global vectors for word representation. In EMNLP, 2014.
Ofir Press and Lior Wolf. Using the output embedding to improve language models. In EACL, 2017.
Alec Radford, Rafal Józefowicz, and Ilya Sutskever. Learning to generate reviews and discovering sentiment. CoRR, abs/1704.01444, 2017.
Richard Socher, Alex Perelygin, Jean Wu, Jason Chuang, Christopher D. Manning, Andrew Ng, and Christopher Potts. Recursive deep models for semantic compositionality over a sentiment treebank. 2013.
Shuai Tang, Hailin Jin, Chen Fang, Zhaowen Wang, and Virginia R. de Sa. Rethinking skip-thought: A neighborhood based approach. In RepL4NLP, ACL Workshop, 2017.
Peter D. Turney and Patrick Pantel. From frequency to meaning: Vector space models of semantics. J. Artif. Intell. Res., 37:141–188, 2010.
Ivan Vendrov, Jamie Ryan Kiros, Sanja Fidler, and Raquel Urtasun. Order-embeddings of images and language. CoRR, abs/1511.06361, 2015.
Janyce Wiebe, Theresa Wilson, and Claire Cardie. Annotating expressions of opinions and emotions in language. Language Resources and Evaluation, 39:165–210, 2005.
Adina Williams, Nikita Nangia, and Samuel R. Bowman. A broad-coverage challenge corpus for sentence understanding through inference. CoRR, abs/1704.05426, 2017.
Yukun Zhu, Ryan Kiros, Richard S. Zemel, Ruslan Salakhutdinov, Raquel Urtasun, Antonio Torralba, and Sanja Fidler. Aligning books and movies: Towards story-like visual explanations by watching movies and reading books. ICCV, pp. 19–27, 2015.
# SUPPLEMENTARY
# Anonymous authors
Paper under double-blind review
<table><tr><td>Encoder</td><td colspan="2">Decoder</td><td>Hrs</td><td>SICK-r SICK-E</td><td>STS14</td><td>MSRP (Acc/F1)</td><td>SST</td><td>TREC</td></tr><tr><td>type dim type</td><td colspan="8">dim Dimension of Sentence Representation: 1200</td></tr><tr><td rowspan="5">RNN 2x300</td><td>CNN</td><td>600-1200-300</td><td>20</td><td>0.8530 82.6</td><td>0.58/0.56</td><td>75.6/82.9</td><td>82.8</td><td>89.2</td></tr><tr><td>CNNt</td><td>600-1200-300</td><td>21</td><td>0.8515 82.7</td><td>0.58/0.56</td><td>75.3/82.5</td><td>82.9</td><td>85.2</td></tr><tr><td>CNN(10)</td><td>600-1200-300</td><td>11</td><td>0.8474 82.9</td><td>0.57/0.55</td><td>74.2/81.6</td><td>82.8</td><td>88.0</td></tr><tr><td>CNN(50)</td><td>600-1200-300</td><td>27</td><td>0.8533 82.5</td><td>0.57/0.55</td><td>74.7/82.2</td><td>81.5</td><td>86.2</td></tr><tr><td>RNN</td><td>600</td><td>26</td><td>0.8530 82.6</td><td>0.51/0.50</td><td>74.1/81.7</td><td></td><td></td></tr><tr><td>RNN2x300 CNN4x300S</td><td>CNN</td><td>600-1200-300</td><td>8</td><td>0.8117 80.5</td><td>0.44/0.42</td><td>72.7/80.7</td><td>81.0 78.4</td><td>89.0 85.0</td></tr><tr><td rowspan="2">RNN 2x300</td><td>CNN</td><td>600-1200-2400-300</td><td>28</td><td>0.8570</td><td></td><td>74.3/81.5</td><td></td><td>88.2</td></tr><tr><td>CNN</td><td>1200-2400-300</td><td>27</td><td>84.0 0.8541 83.0</td><td>0.58/0.56 0.59/0.57</td><td>74.3/82.2</td><td>82.8 82.9</td><td>89.0</td></tr><tr><td colspan="9">Dimension of Sentence Representation: 2400</td></tr><tr><td>RNN2x600</td><td>CNN</td><td>600-1200-300</td><td>25</td><td>0.8631 83.9</td><td></td><td>0.58/0.55</td><td>74.7/83.1</td><td>83.4 90.2</td></tr><tr><td>RNN2x600</td><td>RNN</td><td>600</td><td>32</td><td>0.8647</td><td>84.2</td><td>0.52/0.51</td><td>74.0/81.2 84.2</td><td>87.6</td></tr><tr><td>CNN3x800‡</td><td>RNN</td><td>600</td><td>8</td><td>0.8132</td><td></td><td>71.9/81.9</td><td>-</td><td>86.6</td></tr><tr><td colspan="9">Dimension of Sentence Representation: 4800</td></tr><tr><td>RNN2x1200</td><td>CNN</td><td>600-1200-300</td><td>34 0.8698</td><td>85.2</td><td>0.59/0.57</td><td>75.1/83.2</td><td>84.1</td><td>92.2</td></tr><tr><td colspan="2">Skip-thought (Kiros et al.,2015)</td><td>336</td><td>0.8584</td><td>82.3</td><td>0.29/0.35</td><td>73.0/82.0</td><td>82.0</td><td>92.2</td></tr><tr><td colspan="2">Skip-thought+LN (Ba et al., 2016)</td><td></td><td>720 0.8580</td><td>79.5</td><td>0.44/0.45</td><td>-</td><td>82.9</td><td>88.4</td></tr></table>
Table 1: Architecture Comparison. As shown in the table, our designed asymmetric RNN-CNN model (row 1,9, and 12) works better than other asymmetric models (CNN-LSTM, row 11), and models with symmetric structure (RNN-RNN, row 5 and 10). In addition, with larger encoder size, our model demonstrates stronger transferability. The default setting for our CNN decoder is that it learns to reconstruct 30 words right next to every input sentence. “CNN(10)” represents a CNN decoder with the length of outputs as 10, and “CNN(50)” represents it with the length of outputs as 50. “†” indicates that the CNN decoder learns to reconstruct next sentence. $^ { 6 6 } \ddag ^ { 5 }$ indicates the results reported in Gan et al. as future predictor. The CNN encoder in our experiment, noted as “ $\cdot \ S ^ { \ , }$ , was based on AdaSent in Zhao et al. and Conneau et al.. Bold numbers are best results among models at same dimension, and underlined numbers are best results among all models. For STS14, the performance measures are Pearson’s and Spearman’s score. For MSRP, the performance measures are accuracy and F1 score.
# REFERENCES
Jimmy Ba, Ryan Kiros, and Geoffrey E. Hinton. Layer normalization. CoRR, abs/1607.06450, 2016.
Alexis Conneau, Douwe Kiela, Holger Schwenk, Loïc Barrault, and Antoine Bordes. Supervised learning of universal sentence representations from natural language inference data. In EMNLP, 2017.
Zhe Gan, Yunchen Pu, Ricardo Henao, Chunyuan Li, Xiaodong He, and Lawrence Carin. Learning generic sentence representations using convolutional neural networks. In EMNLP, 2017.
Jamie Ryan Kiros, Yukun Zhu, Ruslan Salakhutdinov, Richard S. Zemel, Raquel Urtasun, Antonio Torralba, and Sanja Fidler. Skip-thought vectors. In NIPS, 2015.
Han Zhao, Zhengdong Lu, and Pascal Poupart. Self-adaptive hierarchical sentence model. In IJCAI, 2015.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366# INFERENCE SUBOPTIMALITY IN VARIATIONAL AUTOENCODERS
Anonymous authors Paper under double-blind review
# ABSTRACT
Amortized inference has led to efficient approximate inference for large datasets. The quality of posterior inference is largely determined by two factors: a) the ability of the variational distribution to model the true posterior and b) the capacity of the recognition network to generalize inference over all datapoints. We analyze approximate inference in variational autoencoders in terms of these factors. We find that suboptimal inference is often due to amortizing inference rather than the limited complexity of the approximating distribution. We show that this is due partly to the generator learning to accommodate the choice of approximation. Furthermore, we show that the parameters used to increase the expressiveness of the approximation play a role in generalizing inference rather than simply improving the complexity of the approximation.
# 1 INTRODUCTION
There has been significant work on improving inference in variational autoencoders (VAEs) (Kingma & Welling, 2014; Rezende et al., 2014) through the development of expressive approximate posteriors (Rezende & Mohamed, 2015; Kingma et al., 2016; Ranganath et al., 2016; Tomczak & Welling, 2016; 2017). These works have shown that with more expressive approximate posteriors, the model learns a better distribution over the data.
In this paper, we analyze inference suboptimality in VAEs: the mismatch between the true and approximate posterior. In other words, we are interested in understanding what factors cause the gap between the marginal log-likelihood and the evidence lower bound (ELBO). We refer to this as the inference gap. Moreover, we break down the inference gap into two components: the approximation gap and the amortization gap. The approximation gap comes from the inability of the approximate distribution family to exactly match the true posterior. The amortization gap refers to the difference caused by amortizing the variational parameters over the entire training set, instead of optimizing for each datapoint independently. We refer the reader to Table 1 for detailed definitions and Figure 1 for a simple illustration of the gaps. In Figure 1, ${ \mathcal { L } } [ q ]$ refers to the ELBO using an amortized distribution $q$ , whereas $q ^ { * }$ is the optimal $q$ within its variational family.
Our experiments investigate how the choice of encoder, posterior approximation, decoder, and model optimization affect the approximation and amortization gaps. We train VAE models in a number of settings on the MNIST, Fashion-MNIST (Xiao et al., 2017), and CIFAR10 datasets.
Our contributions are: a) we investigate inference suboptimality in terms of the approximation and amortization gaps, providing insight to guide future improvements in VAE inference, b) we quantitatively demonstrate that the learned true posterior accommodates the choice of approximation, and c) we demonstrate that using parameterized functions to improve the expressiveness of the approximation plays a large role in reducing error caused by amortization.
 Figure 1: Gaps in Inference
<table><tr><td>Term</td><td>Definition</td><td>VAE Formulation</td></tr><tr><td>Inference</td><td>logp(x)-L[q]</td><td>KL(q(z|x)llp(z|x))</td></tr><tr><td>Approximation</td><td>logp(x)-L[q*]</td><td>KL(q*(z|x)lp(z|x))</td></tr><tr><td>Amortization</td><td>C-C[a]</td><td>KL(q(z|x)llp(z|x))-KL(q*(z|x)llp(z|x))</td></tr></table>
Table 1: Summary of Gap Terms. The middle column refers to the general case where our variational objective is a lower bound on the marginal log-likelihood (not necessarily the ELBO). The right most column demonstrates the specific case in VAEs. $q ^ { * } ( z | x )$ refers to the optimal approximation within a family $\mathcal { Q }$ , i.e. $\begin{array} { r } { q ^ { * } ( z | x ) = \mathrm { \bar { a r g m i n } } _ { q \in \mathcal { Q } } \mathrm { K L } \left( q ( z | \bar { x } ) | | \dot { p ( z | x ) } \right) } \end{array}$ .
# 2 BACKGROUND
# 2.1 INFERENCE IN VARIATIONAL AUTOENCODERS
Let $x$ be the observed variable, $z$ the latent variable, and $p ( x , z )$ be their joint distribution. Given a dataset $X = \{ x _ { 1 } , x _ { 2 } , . . . , x _ { N } \}$ , we would like to maximize the marginal log-likelihood:
$$\log p ( X ) = \sum _ { i = 1 } ^ { N } \log p ( x _ { i } ) = \sum _ { i = 1 } ^ { N } \log \int p ( x _ { i } , z _ { i } ) d z _ { i } .$$
In practice, the marginal log-likelihood is computationally intractable due to the integration over the latent variable $z$ . Instead, VAEs optimize the ELBO of the marginal log-likelihood (Kingma & Welling, 2014; Rezende et al., 2014):
$$\begin{array} { r l } & { \log p ( x ) = \mathbb { E } _ { z \sim q ( z \mid x ) } \left[ \log \left( \displaystyle \frac { p ( x , z ) } { q ( z \mid x ) } \right) \right] + { \mathrm { K L } } \left( q ( z \mid x ) | | p ( z | x ) \right) } \\ & { \phantom { \exp x } \geq \mathbb { E } _ { z \sim q ( z \mid x ) } \left[ \log \left( \displaystyle \frac { p ( x , z ) } { q ( z \mid x ) } \right) \right] = \mathcal { L } _ { \mathrm { V A E } } [ q ] . } \end{array}$$
From the above we can see that the lower bound is tight if $q ( z | x ) = p ( z | x )$ . The choice of $q ( z | x )$ is often a factorized Gaussian distribution for its simplicity and efficiency. VAEs perform amortized inference by utilizing a recognition network (encoder), resulting in efficient approximate inference for large datasets. The overall model is trained by stochastically optimizing the ELBO using the reparametrization trick (Kingma & Welling, 2014).
# 2.2 EXPRESSIVE APPROXIMATE POSTERIORS
There are a number of strategies for increasing the expressiveness of approximate posteriors, going beyond the original factorized-Gaussian. We briefly summarize normalizing flows and auxiliary variables.
# 2.2.1 NORMALIZING FLOWS
Normalizing flow (Rezende & Mohamed, 2015) is a change of variables procedure for constructing complex distributions by transforming probability densities through a series of invertible mappings. Specifically, if we transform a random variable $z _ { \mathrm { 0 } }$ with distribution $q _ { 0 } ( z )$ , the resulting random variable $z _ { T } = T ( z _ { 0 } )$ has a distribution:
$$q _ { T } ( z _ { T } ) = q _ { 0 } ( z _ { 0 } ) \left| \mathrm { d e t } \frac { \partial z _ { T } } { \partial z _ { 0 } } \right| ^ { - 1 }$$
By successively applying these transformations, we can build arbitrarily complex distributions. Stacking these transformations remains tractable due to the determinant being decomposable: $\operatorname* { d e t } ( A { \bar { B } } ) = \operatorname* { d e t } ( A ) \operatorname* { d e t } ( B )$ . An important property of these transformations is that we can take expectations with respect to the transformed density $q _ { T } ( z _ { T } )$ without explicitly knowing its formula known as the law of the unconscious statistician (LOTUS):
$$\mathbb { E } _ { q _ { T } } [ h ( z _ { T } ) ] = \mathbb { E } _ { q _ { 0 } } [ h ( f _ { T } ( f _ { T - 1 } ( \dots f _ { 1 } ( z _ { 0 } ) ) ) ) ]$$
Using the change of variable and LOTUS, the lower bound can be written as:
$$\log p ( x ) \geq \mathbb { E } _ { z _ { 0 } \sim q _ { 0 } ( z | x ) } \left[ \log \left( \frac { p ( x , z _ { T } ) } { q _ { 0 } ( z _ { 0 } | x ) \prod _ { t = 1 } ^ { T } \left| \operatorname* { d e t } \frac { \partial z _ { t } } { \partial z _ { t - 1 } } \right| ^ { - 1 } } \right) \right] .$$
The main constraint on these transformations is that the determinant of their Jacobian needs to be easily computable.
# 2.2.2 AUXILIARY VARIABLES
Deep generative models can be extended with auxiliary variables which leave the generative model unchanged but make the variational distribution more expressive. Just as hierarchical Bayesian models induce dependencies between data, hierarchical variational models can induce dependencies between latent variables. The addition of the auxiliary variable changes the lower bound to:
$$\begin{array} { r l } & { \log p ( x ) \geq \mathbb { E } _ { z , v \sim q ( z , v \mid x ) } \left[ \log \left( \displaystyle \frac { p ( x , z ) r ( v \mid x , z ) } { q ( z , v \mid x ) } \right) \right] } \\ & { \qquad = \mathbb { E } _ { q ( z \mid x ) } \left[ \log \left( \displaystyle \frac { p ( x , z ) } { q ( z \mid x ) } \right) - { \mathrm { K L } \Big ( q ( v \mid z , x ) \| r ( v \mid x , z ) \Big ) } \right] } \end{array}$$
where $r ( v | x , z )$ is called the reverse model. From Eqn. 8, we see that this bound is looser than the regular ELBO, however the extra flexibility provided by the auxiliary variable can result in a higher lower bound. This idea has been employed in works such as auxiliary deep generative models (ADGM, Maaløe et al. (2016)), hierarchical variational models (HVM, Ranganath et al. (2016)) and Hamiltonian variational inference (HVI, Salimans et al. (2015)).
# 2.3 MARGINAL LOG-LIKELIHOOD ESTIMATION
We use two bounds to estimate the marginal log-likelihood of a model: IWAE (Burda et al., 2016) and AIS (Neal, 2001). Here we describe the IWAE bound. See Section 6.5 in the appendix for a description of AIS.
The IWAE bound is a tighter lower bound than the VAE bound. More specifically, if we take multiple samples from the $q$ distribution, we can compute a tighter lower bound on the marginal log-likelihood:
$$\log p ( x ) \geq \mathbb { E } _ { z _ { 1 } . . . z _ { k } \sim q ( z | x ) } \left[ \log \left( \frac { 1 } { k } \sum _ { i = 1 } ^ { k } \frac { p ( x , z _ { i } ) } { q ( z _ { i } | x ) } \right) \right] = \mathcal { L } _ { \mathrm { I W A E } } [ q ] .$$
As the number of importance samples approaches infinity, the bound approaches the marginal loglikelihood. This importance weighted bound was introduced along with the Importance Weighted Autoencoder (Burda et al., 2016), thus we refer to it as the IWAE bound. It is often used as an evaluation metric for generative models (Burda et al., 2016; Kingma et al., 2016). As shown by Bachman & Precup (2015) and Cremer et al. (2017), the IWAE bound can be seen as using the VAE bound but with an importance weighted $q$ distribution.
# 3 METHODS
# 3.1 APPROXIMATION AND AMORTIZATION GAPS
The inference gap $\mathcal { G }$ is the difference between the marginal log-likelihood $\log p ( x )$ and a lower bound ${ \mathcal { L } } [ q ]$ . Given the distribution in the family that maximizes the bound, $q ^ { * } ( z | x ) \ =$ arg $\operatorname* { m a x } _ { q \in \mathcal { Q } } \mathcal { L } [ q ]$ , the inference gap decomposes as the sum of approximation and amortization gaps:
$$\mathcal { G } = \log p ( x ) - \mathcal { L } [ q ] = \underbrace { \log p ( x ) - \mathcal { L } [ q ^ { * } ] } _ { \mathrm { A p p r o x i m a t i o n } } + \underbrace { \mathcal { L } [ q ^ { * } ] - \mathcal { L } [ q ] } _ { \mathrm { A m o r t i z a t i o n } } .$$
For VAEs, we can translate the gaps to KL divergences by rearranging (2):
$$\mathcal { G } _ { \mathrm { V A E } } = \mathrm { K L } \big ( q ^ { * } ( z | x ) | | p ( z | x ) \big ) + \mathrm { K L } \big ( q ( z | x ) | | p ( z | x ) \big ) - \mathrm { K L } \big ( q ^ { * } ( z | x ) | | p ( z | x ) \big ) .$$
# 3.2 FLEXIBLE APPROXIMATE POSTERIOR
Our experimentation compares two families of approximate posteriors: the fully-factorized Gaussian (FFG) and a flexible flow (Flow). Our choice of flow is a combination of the Real NVP (Dinh et al., 2017) and auxiliary variables (Ranganath et al., 2016; Maaløe et al., 2016). Our model also resembles leap-frog dynamics applied in Hamiltonian Monte Carlo (HMC, Neal et al. (2011)).
Let $z \in \mathbb { R } ^ { n }$ be the variable of interest and $v \in \mathbb { R } ^ { n }$ the auxiliary variable. Each flow step involves:
$$\begin{array} { l } { { v ^ { \prime } = v \circ \sigma _ { 1 } ( z ) + \mu _ { 1 } ( z ) } } \\ { { z ^ { \prime } = z \circ \sigma _ { 2 } ( v ^ { \prime } ) + \mu _ { 2 } ( v ^ { \prime } ) } } \end{array}$$
where $\sigma _ { 1 } , \sigma _ { 2 } , \mu _ { 1 } , \mu _ { 2 } : \mathbb { R } ^ { n } \to \mathbb { R } ^ { n }$ are differentiable mappings parameterized by neural nets and $\circ$ takes the Hadamard or element-wise product. The determinant of the combined transformation’s Jacobian, $| \mathrm { d e t } ( D f ) |$ , can be easily evaluated. See section 6.2 in the Appendix for a detailed derivation.
Thus, we can jointly train the generative and flow-based inference model by optimizing the bound:
$$\log p ( x ) \geq \mathbb { E } _ { z , v \sim q ( z , v \mid x ) } \left[ \log \left( { \frac { p ( x , z ^ { \prime } ) r ( v ^ { \prime } | x , z ^ { \prime } ) } { q ( z , v | x ) \left| \operatorname* { d e t } ( D f ) \right| ^ { - 1 } } } \right) \right] = \mathcal { L } _ { \mathrm { f l o w } } [ q ] .$$
Additionally, multiple such type of transformations can be stacked to improve expressiveness. We refer readers to section 6.1.2 in the Appendix for details of our flow configuration adopted in the experimentation.
# 3.3 EVALUATION BOUNDS
We use several bounds to compute the inference gaps. To estimate the marginal log-likelihood, $\log { \hat { p } } ( x )$ , we take the maximum of our tightest lower bounds, specifically the maximum between the IWAE and AIS bounds. To compute the AIS bound, we use 100 chains, each with 500 intermediate distributions, where each transition consists of one HMC trajectory with 10 leapfrog steps. The initial distribution for AIS is the prior, so that it is encoder-independent.
For our experiments, we test two different variational distributions: the fully-factorized Gaussian $q _ { F F G }$ and the flexible approximation $q F l o w$ as described in section 3.2. When computing ${ \mathcal { L } } _ { \mathrm { V A E } } [ q ]$ and $\mathcal { L } _ { \mathrm { I W A E } } [ q ]$ , we use 5000 samples. To compute $\mathcal { L } _ { \mathrm { V A E } } [ q ^ { * } ]$ , we optimize the parameters of the variational distribution for every datapoint. See Section 6.4 for details of the local optimization and stopping criteria.
# 4 RELATED WORK
Much of the earlier work on variational inference focused on optimizing the variational parameters locally for each datapoint, e.g. the original Stochastic Variational Inference scheme (SVI, Hoffman et al. (2013)) specifies the variational parameters to be optimized locally in the inner loop. Salakhutdinov & Larochelle (2010) perform such local optimization when learning deep Boltzmann machines. More recent work has applied this idea to improve approximate inference in directed Belief networks (Hjelm et al., 2015).
Most relevant to our work is the recent work of Krishnan et al. (2017). They explicitly remark on two sources of error in variational learning with inference networks, and propose to optimize approximate inference locally from an initialization output by the inference network. They show improved training on high-dimensional, sparse data with the hybrid method, claiming that local optimization reduces the negative effects of random initialization in the inference network early on in training. Yet, their work only dwells on reducing the amortization gap and does analyze the error arising from the use of limited approximating distributions.
 Figure 2: True Posterior and Approximate Distributions of a VAE with 2D latent space. Columns: 4 different datapoints. FFG: Fully-factorized Gaussian. Flow: Using a flexible approximate distribution. Amortized: Using amortized parameters. Optimal: Parameters optimized for individual datapoints. The green distributions are the true posterior distributions, highlighting the mismatch with the approximation.
Even though it is clear that failed inference would lead to a failed generative model, little quantitative assessment has been done showing the effect of the approximate posterior on the true posterior. Burda et al. (2016) visually demonstrate that when trained with an importance-weighted approximate posterior, the resulting true posterior is more complex than those trained with fully-factorized Gaussian approximations. We extend this observation quantitatively in the setting of flow-based approximate inference.
# 5 EXPERIMENTAL RESULTS
# 5.1 INTUITION THROUGH VISUALIZATION
To begin, we would like to gain some insight into the properties of inference in VAEs by visualizing different distributions in the latent space. To this end, we trained a VAE with a two-dimensional latent space on MNIST. We show contour plots of various distributions in the latent space in Fig. 2. The first row contains contour plots of the true posteriors $p ( z | x )$ for four different training datapoints (columns). We have selected these four examples to highlight different inference phenomena. The amortized FFG row refers to the output of the recognition net, in this case, a fully-factorized Gaussian (FFG) approximation. Optimal FFG is the FFG that best fits the posterior of the datapoint. Optimal Flow is the optimal fit of a flexible distribution to the same posterior, where the flexible distribution we use is described in Section 3.2.
Posterior A is an example of a distribution where FFG can fit well. Posterior B is an example of dependence between dimensions, demonstrating the limitation of having a factorized approximation. Posterior C highlights a shortcoming of performing amortization with a limited-capacity recognition network, where the amortized FFG shares little support with the true posterior. Posterior $\mathbf { D }$ is a bimodal distribution which demonstrates the ability of the flexible approximation to fit to complex distributions, in contrast to the simple FFG approximation. These observations raise the following question: in more typical VAEs, is the amortization of inference the leading cause of the distribution mismatch, or is it the choice of approximation?
<table><tr><td rowspan="2"></td><td colspan="2">MNIST</td><td colspan="2">Fashion-MNIST</td><td colspan="2">CIFAR-10</td></tr><tr><td>qFFG</td><td>qFlow</td><td>qFFG</td><td>qFlow</td><td>qFFG</td><td>qFlow</td></tr><tr><td>log p(x)</td><td>-89.80</td><td>-88.94</td><td>-97.47</td><td>-97.41</td><td>-14913.15</td><td>-14914.45</td></tr><tr><td>LVAE[qFlow]</td><td>-90.80</td><td>-90.38</td><td>-98.92</td><td>-99.10</td><td>-14914.22</td><td>-14915.57</td></tr><tr><td>LVAE[qFFG]</td><td>-91.23</td><td>-113.54</td><td>-100.53</td><td>-132.46</td><td>-14915.40</td><td>-14919.08</td></tr><tr><td>LVAE[q]</td><td>-92.57</td><td>-91.79</td><td>-104.75</td><td>-103.76</td><td>-14976.57</td><td>-14975.12</td></tr><tr><td>Approximation</td><td>1.43</td><td>1.44</td><td>3.06</td><td>1.69</td><td>2.25</td><td>1.12</td></tr><tr><td>Amortization</td><td>1.34</td><td>1.41</td><td>4.22</td><td>4.66</td><td>61.17</td><td>59.55</td></tr><tr><td>Inference</td><td>2.77</td><td>2.85</td><td>7.28</td><td>6.35</td><td>63.42</td><td>60.67</td></tr></table>
Table 2: Inference Gaps. The columns $q _ { F F G }$ and $q _ { F l o w }$ refer to the variational distribution used for training the model. All numbers are in nats.
# 5.2 AMORTIZATION VS APPROXIMATION GAP
Here we will compare the influence that the approximation and amortization errors have on the total inference gap. Table 2 are results from training on MNIST, Fashion-MNIST and CIFAR-10. For each dataset, we trained two different approximate posterior distributions: a fully-factorized Gaussian, $q _ { F F G }$ , and a flexible distribution, $q _ { F l o w }$ . Due to the computational cost of optimizing the local parameters for each datapoint, our evaluation is performed on a subset of 1000 datapoints for MNIST and Fashion-MNIST and a subset of 100 datapoints for CIFAR-10.
For MNIST, we see that the amortization and approximation gaps each account for nearly half of the inference gap. On Fashion-MNIST, which is a more difficult dataset to model, the amortization gap becomes larger than the approximation gap. Similarly for CIFAR-10, we see that the amortization gap is much more significant than the approximation gap. Thus, for the three datasets and model architectures that we tested, the amortization gap seems to be the prominent cause of inference suboptimality, especially when the difficulty of the dataset increases. This analysis indicates that improvements in inference will likely be a result of reducing amortization error, rather than approximation errors.
With these results in mind, would simply increasing the capacity of the encoder improve the amortization gap? We examined this by training the MNIST and Fashion-MNIST models from above but with larger encoders. See Section 6.1.2 for implementation details. Table 3 are the results of this experiment. Comparing to Table 2, we see that for both datasets and both variational distributions, the inference gap decreases and the decrease is mainly due to a reduction in the amortization gap.
<table><tr><td rowspan="7">logp(x) LVAE[qFlow] LVAEqFFG]</td><td colspan="2">MNIST</td><td colspan="2">Fashion-MNIST</td></tr><tr><td>qFFG</td><td>qFlow</td><td>qFFG</td><td>qFlow</td></tr><tr><td>-89.61</td><td>-88.99</td><td>-95.99</td><td>-96.18</td></tr><tr><td>-90.65</td><td>-90.44</td><td>-97.40</td><td>-97.91</td></tr><tr><td>-91.07</td><td>-108.71</td><td>-99.64</td><td>-129.7</td></tr><tr><td>-92.18</td><td>-91.19</td><td>-102.73</td><td>-101.67</td></tr><tr><td>LVAE[q] Approximation 1.46</td><td>1.45</td><td>3.65</td><td>1.73</td></tr><tr><td>Amortization</td><td>1.11</td><td>0.75</td><td>3.09</td><td>3.76</td></tr><tr><td>Inference</td><td>2.56</td><td>2.20</td><td>6.74</td><td>5.49</td></tr></table>
Table 3: Larger Encoder. The columns $q _ { F F G }$ and $q F l o w$ refer to the variational distribution used for training the model. All numbers are in nats.
# 5.2.1 INFLUENCE OF FLOWS ON AMORTIZATION GAP
The common reasoning for increasing the expressiveness of the approximate posterior is to minimize the difference between the true and approximate, i.e. reduce the approximation gap. However, given that the expressive approximation is often accompanied by many additional parameters, we would like to know if it has an influence on the amortization error.
To investigate this, we trained a VAE in the same manner as Section 5.2. After training, we kept the generator fixed and trained new encoders to fit to the fixed posterior. Specifically, we trained a small encoder with a factorized Gaussian $q$ distribution to obtain a large amortization gap. We then trained a small encoder with a flow distribution. See Section 6.2 for the details of the experiment. The results are shown in Table 4. As expected, we observe that the small encoder has a very large amortization gap. However, when we use $q _ { F l o w }$ as the approximate distribution, we see the approximation gap decrease, but more importantly, there is a significant decrease in the amortization gap. This indicates that the parameters used for increasing the complexity of the approximation also play a large role in diminishing the amortization error.
Table 4: Influence of Flows on the Amortization Gap. The parameters used to increase the flexibility of the approximate distribution also reduce the amortization gap. See Section 5.2.1 for details of the experiment.
<table><tr><td>Variational Family</td><td>qFFG</td><td>qFlow</td></tr><tr><td>logp(x) LVAE[q*]</td><td>-84.70 -86.61</td><td>-84.70 -85.48</td></tr><tr><td>LVAE[q] Approximation</td><td>-129.83 1.91</td><td>-98.58 0.78</td></tr><tr><td>Amortization</td><td>43.22</td><td>13.10</td></tr><tr><td>Inference</td><td>45.13</td><td>13.88</td></tr></table>
These results are expected given that the parameterization of the Flow distribution can be interpreted as an instance of the RevNet (Gomez et al., 2017) which has demonstrated that Real-NVP like transformations (Dinh et al., 2017) can model complex functions similar to typical MLPs. Thus the flow transformations we employ should also be expected to increase the expressiveness while also increasing the capacity of the encoder. The implication of this observation is that models which improve the flexibility of their variational approximation, and attribute their improved results to the increased expressiveness, may have actually been due to the reduction in amortization error.
# 5.3 INFLUENCE OF APPROXIMATE POSTERIOR ON TRUE POSTERIOR
We have seen that increasing the expressiveness of the approximation improves the marginal likelihood of the trained model, but to what amount does it alter the true posterior? Will a factorized Gaussian approximation cause the true posterior to be more like a factorized Gaussian or is the true posterior mostly fixed? Just as it is hard to evaluate a generative model by visually inspecting samples from the model, its hard to say how Gaussian the true posterior is by visual inspection. We can quantitatively determine how close the posterior is to a fully factorized Gaussian (FFG) distribution by comparing the marginal log-likelihood estimate, $\log { \dot { \hat { p } } } ( x )$ , and the Optimal FFG bound, $\mathcal { L } _ { \mathrm { V A E } } [ q _ { F F G } ^ { * } ]$ . In other words, we are estimating the KL divergence between the optimal Gaussian and the true posterior, $\mathrm { K L } \left( q ^ { * } ( z | x ) | | p ( z | x ) \right)$ .
In Table 2 on MNIST, the Optimal Flow improves upon the Optimal FFG for the FFG trained model by 0.4 nats. In contrast, on the Flow trained model, the difference increases to 12.5 nats. This suggests that the true posterior of a FFG-trained model is closer to FFG than the true posterior of the Flow-trained model. The same observation can be made on the Fashion-MNIST dataset. This implies that the decoder can learn to have a true posterior that fits better to the approximation. Although the generative model can learn to have a posterior that fits to the approximation, it seems that not having this constraint, ie. using a flexible approximate, results in better generative models.
We can use these observations to help justify our approximation and amortization gap results of Section 5.2. Those results showed that the amortization error is often the main cause of inference suboptimality. One reason for this is that the generator accommodates to the choice of approximation, as shown above, thus reducing the approximation error.
Given that we have seen that the generator could accommodate to the choice of approximation, our next question is whether a generator with more capacity can accommodate more. To this end, we trained VAEs with decoders of different sizes and measured the approximation gaps. Specifically, we trained decoders with 0, 2, and 4 hidden layers on MNIST. See Table 5 for the results. We see that as the capacity of the decoder increases, the approximation gap decreases. This result implies that the more flexible the generator, the less flexible the approximate distribution needs to be.
Table 5: Increased decoder capacity reduces approximation gap. All numbers are in nats.
<table><tr><td>Generator HiddenLayers</td><td>0</td><td>2</td><td>4</td></tr><tr><td>logp(x)</td><td>-100.52</td><td>-86.61</td><td>-83.82</td></tr><tr><td>LVAE[qFFG]</td><td>-104.42</td><td>-84.78</td><td>-82.19</td></tr><tr><td>Approximation Gap</td><td>3.90</td><td>1.83</td><td>1.63</td></tr></table>
# 5.3.1 ANNEALING THE ENTROPY
Typical warm-up (Bowman et al., 2015; Sønderby et al., 2016) refers to annealing $\mathrm { K L } \left( q ( \boldsymbol { z } | \boldsymbol { x } ) | | p ( \boldsymbol { z } ) \right)$ during training. This can also be interpreted as performing maximum likelihood estimation (MLE) early on during training. This optimization technique is known to help prevent the latent variable from degrading to the prior (Burda et al., 2016; Sønderby et al., 2016). We employ a similar annealing scheme during training. Rather than annealing the KL divergence, we anneal the entropy of the approximate distribution $q$ :
$$\begin{array} { r } { \mathbb { E } _ { z \sim q ( z | x ) } \left[ \log p ( x , z ) - \lambda \log q ( z | x ) \right] , } \end{array}$$
where $\lambda$ is annealed from 0 to 1 over training. This can be interpreted as maximum a posteriori (MAP) in the initial phase. Due to its similarity, we will also refer to this technique as warm-up.
We find that warm-up techniques, such as annealing the entropy, are important for allowing the true posterior to be more complex. Table 6 are results from a model trained without the entropy annealing schedule. Comparing these results to Table 2, we observe that the difference between $\mathcal { L } _ { \mathrm { V A E } } [ q _ { F F G } ^ { * } ]$ and $\mathcal { L } _ { \mathrm { V A E } } [ q _ { F l o w } ^ { * } ]$ is significantly smaller without entropy annealing. This indicates that the true posterior is more Gaussian when entropy annealing is not used. This suggests that, in addition to preventing the latent variable from degrading to the prior, entropy annealing allows the true posterior to better utilize the flexibility of the expressive approximation, resulting in a better trained model.
<table><tr><td rowspan="7">log p(x) LVAE[qFlow LVAE[qFFG]</td><td colspan="2">MNIST</td><td colspan="2">Fashion-MNIST</td></tr><tr><td>qFFG</td><td>qFlow</td><td>qFFG</td><td>qFlow</td></tr><tr><td>-89.82</td><td>-89.52</td><td>-102.56</td><td>-102.88</td></tr><tr><td>-90.96</td><td>-90.45</td><td>-103.73</td><td>-104.02</td></tr><tr><td>-90.84</td><td>-92.25</td><td>-103.85</td><td>-105.80</td></tr><tr><td>-92.33</td><td>-91.75</td><td>-106.90</td><td>-107.01</td></tr><tr><td>LvAE[q] Approximation 1.02</td><td>0.93</td><td>1.29</td><td>1.14</td></tr><tr><td>Amortization</td><td>1.49</td><td>1.30</td><td>3.05</td><td>2.29</td></tr><tr><td>Inference</td><td>2.51</td><td>2.23</td><td>4.34</td><td>4.13</td></tr></table>
Table 6: Models trained without entropy annealing. The columns $q _ { F F G }$ and $q _ { F l o w }$ refer to the variational distribution used for training the model. All numbers are in nats.
# 6 CONCLUSION
In this paper, we investigated how encoder capacity, approximation choice, decoder capacity, and model optimization influence inference suboptimality in terms of the approximation and amortization gaps. We found that the amortization gap is often the leading source of inference suboptimality and that the generator reduces the approximation gap by learning a true posterior that fits to the choice of approximate distribution. We showed that the parameters used to increase the expressiveness of the approximation play a role in generalizing inference rather than simply improving the complexity of the approximation. We confirmed that increasing the capacity of the encoder reduces the amortization error. We also showed that optimization techniques, such as entropy annealing, help the generative model to better utilize the flexibility of the expressive variational distribution. Computing these gaps can be useful for guiding improvements to inference in VAEs. Future work includes evaluating other types of expressive approximations and more complex likelihood functions.
REFERENCES P. Bachman and D. Precup. Training Deep Generative Models: Variations on a Theme. NIPS Approximate Inference Workshop, 2015. S. R. Bowman, L. Vilnis, O. Vinyals, A. M. Dai, R. Jozefowicz, and S. Bengio. Generating Sentences from a Continuous Space. ArXiv e-prints, November 2015. Y. Burda, R. Grosse, and R. Salakhutdinov. Importance weighted autoencoders. In ICLR, 2016. Djork-Arne Clevert, Thomas Unterthiner, and Sepp Hochreiter. Fast and accurate deep network ´ learning by exponential linear units (elus). arXiv preprint arXiv:1511.07289, 2015. C. Cremer, Q. Morris, and D. Duvenaud. Reinterpreting Importance-Weighted Autoencoders. ICLR Workshop, 2017. L. Dinh, J. Sohl-Dickstein, and S. Bengio. Density estimation using Real NVP. ICLR, 2017. Xavier Glorot and Yoshua Bengio. Understanding the difficulty of training deep feedforward neural networks. In Proceedings of the Thirteenth International Conference on Artificial Intelligence and Statistics, pp. 249–256, 2010. Aidan N Gomez, Mengye Ren, Raquel Urtasun, and Roger B Grosse. The reversible residual network: Backpropagation without storing activations. In Advances in Neural Information Processing Systems, pp. 2211–2221, 2017. R. Grosse, Z. Ghahramani, and R. P Adams. Sandwiching the marginal likelihood using bidirectional monte carlo. arXiv preprint arXiv:1511.02543, 2015. R Devon Hjelm, Kyunghyun Cho, Junyoung Chung, Russ Salakhutdinov, Vince Calhoun, and Nebojsa Jojic. Iterative refinement of approximate posterior for training directed belief networks. arXiv preprint arXiv:1511.06382, 2015. Matthew D Hoffman, David M Blei, Chong Wang, and John Paisley. Stochastic variational inference. The Journal of Machine Learning Research, 14(1):1303–1347, 2013. C. Jarzynski. Nonequilibrium equality for free energy differences. Physical Review Letters, 78(14): 2690, 1997. Diederik Kingma and Jimmy Ba. Adam: A method for stochastic optimization. arXiv preprint arXiv:1412.6980, 2014. D.P. Kingma and M. Welling. Auto-Encoding Variational Bayes. In ICLR, 2014. D.P. Kingma, T. Salimans, R. Jozefowicz, X. Chen, I. Sutskever, and M. Welling. Improving Variational Inference with Inverse Autoregressive Flow. NIPS, 2016. R. G. Krishnan, D. Liang, and M. Hoffman. On the challenges of learning with inference networks on sparse, high-dimensional data. ArXiv e-prints, October 2017. Hugo Larochelle and Yoshua Bengio. Classification using discriminative restricted boltzmann machines. In Proceedings of the 25th international conference on Machine learning, pp. 536–543. ACM, 2008. L. Maaløe, CK. Sønderby, SK. Sønderby, and O. Winther. Auxiliary Deep Generative Models. ICML, 2016. Radford M Neal et al. Mcmc using hamiltonian dynamics. Handbook of Markov Chain Monte Carlo, 2(11), 2011. R.M. Neal. Annealed importance sampling. Statistics and Computing, 2001. R. Ranganath, D. Tran, and D. M. Blei. Hierarchical Variational Models. ICML, 2016. D.J. Rezende and S Mohamed. Variational Inference with Normalizing Flows. In ICML, 2015.
D.J. Rezende, S. Mohamed, and D. Wierstra. Stochastic Backpropagation and Approximate Inference in Deep Generative Models. ICML, 2014.
R. Salakhutdinov and I. Murray. On the quantitative analysis of deep belief networks. In Proceedings of the 25th international conference on Machine learning, pp. 872–879. ACM, 2008.
Ruslan Salakhutdinov and Hugo Larochelle. Efficient learning of deep boltzmann machines. In Proceedings of the Thirteenth International Conference on Artificial Intelligence and Statistics, pp. 693–700, 2010.
T. Salimans, D.P. Kingma, and M. Welling. Markov chain monte carlo and variational inference: Bridging the gap. In ICML, 2015.
Casper Kaae Sønderby, Tapani Raiko, Lars Maaløe, Søren Kaae Sønderby, and Ole Winther. Ladder variational autoencoders. In Advances in Neural Information Processing Systems, pp. 3738–3746, 2016.
J. M. Tomczak and M. Welling. Improving Variational Auto-Encoders using Householder Flow. ArXiv e-prints, November 2016.
J. M. Tomczak and M. Welling. Improving Variational Auto-Encoders using convex combination linear Inverse Autoregressive Flow. ArXiv e-prints, June 2017.
Y. Wu, Y. Burda, R. Salakhutdinov, and R. Grosse. On the Quantitative Analysis of Decoder-Based Generative Models. ICLR, 2017.
Han Xiao, Kashif Rasul, and Roland Vollgraf. Fashion-mnist: a novel image dataset for benchmarking machine learning algorithms. github.com/zalandoresearch/fashion-mnist, 2017.
# APPENDIX
# 6.1 MODEL ARCHITECTURES AND TRAINING HYPERPARAMETERS
# 6.1.1 2D VISUALIZATION
The VAE model of Fig. 2 uses a decoder $p ( x | z )$ with architecture: $2 - 1 0 0 - 7 8 4$ , and an encoder $q ( z | x )$ with architecture: $7 8 4 - 1 0 0 - 4$ . We use tanh activations and a batch size of 50. The model is trained for 3000 epochs with a learning rate of $1 0 ^ { - 4 }$ using the ADAM optimizer (Kingma & Ba, 2014).
# 6.1.2 MNIST & FASHION-MNIST
Both MNIST and Fashion-MNIST consist of a training and test set with 60k and 10k datapoints respectively, where each datapoint is a $2 8 \mathbf { x } 2 8$ grey-scale image. We rescale the original images so that pixel values are within the range [0, 1]. For MNIST, We use the statically binarized version described by Larochelle & Bengio (2008). We also binarize Fashion-MINST statically. For both datasets, we adopt the Bernoulli likelihood for the generator.
The VAE models for MNIST and Fashion-MNIST experiments have the same architecture given in table 7. The flow configuration is given in table 8.
Table 7: Neural net architecture for MNIST/Fashion-MNIST experiments.
<table><tr><td>Inference Network</td><td>Generator</td></tr><tr><td>Input ∈R784</td><td>Input ∈R50</td></tr><tr><td>FC.200-ELU-FC.200-ELU-FC.50+50</td><td>FC.200-ELU-FC.200-ELU-FC.784-Sigmoid</td></tr></table>
In the large encoder setting, we change the number of hidden units for the inference network to be 500, instead of 200. The warm-up models are trained with a linear schedule over the first 400 epochs according to Section 5.3.1.
The activation function is chosen to be the exponential linear unit (ELU, Clevert et al. (2015)), as we observe improved performance compared to tanh. We follow the same learning rate schedule and train for the same amount of epochs as described by Burda et al. (2016). All models are trained with the a batch-size of 100 with ADAM.
# 6.1.3 CIFAR-10
CIFAR-10 consists of a training and test dataset with $5 0 \mathrm { k }$ and $1 0 \mathrm { k }$ datapoints respectively, where each datapoint is a $3 2 \times 3 2$ color image. We rescale individual pixel values to be in the range [0, 1]. We follow the discretized logistic likelihood model adopted by Kingma et al. (2016), where each input channel has its own scale learned by an MLP. For the latent variable, we use a 32-dimensional factorized Gaussian for $q ( z | x )$ following Kingma et al. (2016). For all neural networks, ELU is chosen to be the activation function. The specific network architecture is shown in Table 9.
We adopt a gradually decreasing learning rate with an initialize value of $1 0 ^ { - 3 }$ . Warm-up is applied with a linear schedule over the first 20 epochs. All models are trained with a batch-size of 100 with ADAM. Early-stopping is applied based on the performance on the held-out set.
For the model with expressive inference, we use four flow steps as opposed to only two in MNIST/Fashion-MNIST experiments.
# 6.2 INFLUENCE OF FLOWS ON AMORTIZATION GAP EXPERIMENT
The aim of this experiment is to show that the parameters used for increasing the expressiveness of the approximation also contribute to reducing the amortization error. To show this, we train a VAE on MNIST, discard the encoder, then retrain two encoders on the fixed decoder: one with a factorized Gaussian distribution and the other with a parameterized ’flow’ distribution. We use fixed decoder so that the true posterior is constant for both encoders. See 5.2.1 for the results and below for the architecture details.
The architecture of the decoder is: $D _ { Z } - 2 0 0 - 2 0 0 - D _ { X }$ . The architecture of the encoder used to train the decoder is $D _ { X } - 2 0 0 - 2 0 0 - 2 D _ { Z }$ . The approximate distribution $q ( z | x )$ is a factorized Gaussian.
Next, we describe the encoders which were trained on the fixed trained decoder. In order to highlight a large amortization gap, we employed a very small encoder architecture: $D _ { X } - 2 D _ { Z }$ . This encoder has no hidden layers, which greatly impoverishes its ability and results in a large amortization gap.
We compare two approximate distributions $q ( z | x )$ . Firstly, we experiment with the typical fully factorized Gaussian (FFG). The second is what we call a flow distribution. Specifically, we use the transformations of Dinh et al. (2017). We also include an auxiliary variable so we don’t need to select how to divide the latent space for the transformations. The approximate distribution over the latent $z$ and auxiliary variable $v$ factorizes as: $q ( z , v | x ) = q ( z | x ) \bar { q } ( v )$ . The $q ( v )$ distribution is simply a ${ \bf N } ( 0 , 1 )$ distribution. Since we’re using a auxiliary variable, we also require the $r ( v | z )$ distribution which we parameterize as $r ( v | z )$ : $[ D z ] - 5 0 - 5 0 - 2 D z$ . The flow transformation is the same as in Section 3.2, which we apply twice.
<table><tr><td>q(uolz0)</td><td>r(Ur|zT)</td></tr><tr><td>Input ∈R50</td><td>Input ∈ R50</td></tr><tr><td>FC.100-ELU-FC.100-ELU-FC.50+50</td><td>FC.100-ELU-FC.100-ELU-FC.50+50</td></tr></table>
<table><tr><td colspan="2">q(Ut+1, Zt+1lUt, zt)</td></tr><tr><td>01(),02()</td><td>μ1(.),μ2(.)</td></tr><tr><td>Input ∈ R50</td><td>Input ∈ R50</td></tr><tr><td>FC.100-ELU-FC.100-ELU-FC.50</td><td>FC.100-ELU-FC.100-ELU-FC.50</td></tr></table>
Table 8: Flow setting for MNIST/Fashion-MNIST experiments. $q ( v _ { T } , z _ { T } | v _ { 0 } , z _ { 0 } )$ consists of two normalizing flows given in the second tabular.
<table><tr><td>Inference Network</td><td>Generator</td></tr><tr><td>Input 32 × 32 color image</td><td>Input ∈ R32</td></tr><tr><td>4 × 4 conv. 64 channels.stride 2.BN 4 × 4 conv.128 channels.stride 2.BN</td><td>FC.256×2×2ELU;FC.64-ELU-FC.32-ELU-FC.3 4 × 4 deconv. 128 channels. stride 2. BN</td></tr><tr><td>4 × 4 conv. 256 channels. stride 2.BN</td><td>4 × 4 deconv.64 channels.stride 2.BN</td></tr><tr><td>FC.32 + 32.output layer for mean and log-variance</td><td>4 × 4 deconv.3 channels.stride 2. Sigmoid</td></tr></table>
Table 9: Network architecture for CIFAR-10 experiments. For the generator, one of the MLPs immediately after the input layer of the generator outputs channel-wise scales for the discretized logistic likelihood model. BN stands for batch-normalization.
# 6.3 COMPUTATION OF THE DETERMINANT FOR FLOW
The overall mapping $f$ that performs $( z , v ) \mapsto ( z ^ { \prime } , v ^ { \prime } )$ is the composition of two sheer mappings $f _ { 1 }$ and $f _ { 2 }$ that respectively perform $( z , v ) \mapsto ( z , v ^ { \prime } )$ and $( z , v ^ { \prime } ) \mapsto ( z ^ { \prime } , v ^ { \prime } )$ . Since the Jacobian of either one of the sheer mappings is diagonal, the determinant of the composed transformation’s Jacobian $D f$ can be easily computed:
$$\operatorname * { d e t } ( D f ) = \operatorname * { d e t } ( D f _ { 1 } ) \mathrm { d e t } ( D f _ { 2 } ) = \Bigl ( \prod _ { i = 1 } ^ { n } \sigma _ { 1 } ( z ) _ { i } \Bigr ) \Bigl ( \prod _ { j = 1 } ^ { n } \sigma _ { 2 } ( v ^ { \prime } ) _ { j } \Bigr ) .$$
# 6.4 LOCAL OPTIMIZATION OF APPROXIMATE DISTRIBUTION
For the local FFG optimization, we initialize the mean and variance as the prior, i.e. $\mathcal { N } ( 0 , I )$ . We optimize the mean and variance using the Adam optimizer with a learning rate of $1 0 ^ { - 3 }$ . To determine convergence, after every 100 optimization steps, we compute the average of the previous 100 ELBO values and compare it to the best achieved average. If it does not improve for 10 consecutive iterations then the optimization is terminated. For the Flow model, the same process is used to optimize all of its parameters. All neural nets for the flow were initialized with a variant of the Xavier initilization (Glorot & Bengio, 2010). We use 100 Monte Carlo samples to compute the ELBO to reduce variance.
# 6.5 ANNEALED IMPORTANCE SAMPLING
Annealed importance sampling (AIS, Neal (2001); Jarzynski (1997)) is a means of computing a lower bound to the marginal log-likelihood. Similarly to the importance weighted bound, AIS must sample a proposal distribution $\bar { f } _ { 1 } ( z )$ and compute the density of these samples, however, AIS then transforms the samples through a sequence of reversible transitions $\mathcal { T } _ { t } ( z ^ { \prime } | z )$ . The transitions anneal the proposal distribution to the desired distribution $f _ { T } ( z )$ .
Specifically, AIS samples an initial state $z _ { 1 } \sim f _ { 1 } ( z )$ and sets an initial weight $w _ { 1 } = 1$ . For the following annealing steps, $z _ { t }$ is sampled from $\mathcal { T } _ { t } { \left( z ^ { \prime } \right| } z )$ and the weight is updated according to:
$$w _ { t } = w _ { t - 1 } \frac { f _ { t } ( z _ { t - 1 } ) } { f _ { t - 1 } ( z _ { t - 1 } ) } .$$
This procedure produces weight $w _ { T }$ such that $\mathbb { E } \left[ w _ { T } \right] = \mathcal { Z } _ { T } / \mathcal { Z } _ { 1 }$ , where $Z _ { T }$ and $Z _ { 1 }$ are the normalizing constants of $f _ { T } ( z )$ and $f _ { 1 } ( z )$ respectively. This pertains to estimating the marginal likelihood when the target distribution is $p ( x , z )$ when we integrate with respect to $z$ .
Typically, the intermediate distributions are simply defined to be geometric averages: $f _ { t } ( z ) ~ =$ $\dot { f _ { 1 } } \dot { ( z ) } ^ { 1 - \dot { \beta _ { t } } } f _ { T } ( z ) ^ { \beta _ { t } }$ , where $\beta _ { t }$ is monotonically increasing with $\beta _ { 1 } = 0$ and $\beta _ { T } = 1$ . When $f _ { 1 } ( z ) =$ $p ( z )$ and $f _ { T } ( z ) = p ( x , z )$ , the intermediate distributions are: $f _ { i } ( x ) = p ( z ) p ( x | z ) ^ { \beta _ { i } }$ .
Model evaluation with AIS appears early on in the setting of deep belief networks (Salakhutdinov & Murray, 2008). AIS for decoder-based models was also used by $\mathrm { { W u } }$ et al. (2017). They validated the accuracy of the approach with Bidirectional Monte Carlo (BDMC, Grosse et al. (2015)) and demonstrated the advantage of using AIS over the IWAE bound for evaluation when the inference network overfits to the training data.
# 6.6 THE INFERENCE GAP
How well is inference done in VAEs during training? Are we close to doing the optimal or is there much room for improvement? To answer this question, we quantitatively measure the inference gap: the gap between the true marginal log-likelihood and the lower bound. This amounts to measuring how well inference is being done during training. Since we cannot compute the exact marginal log-likelihood, we estimate it using the maximum of any of its lower bounds, described in 3.3.
Fig. 3a shows training curves for a FFG and Flow inference network as measured by the VAE, IWAE, and AIS bounds on the training and test set. The inference gap on the training set with the FFG model is 3.01 nats, whereas the Flow model is 2.71 nats. Accordingly, Fig. 3a shows that the training IWAE bound is slightly tighter for the Flow model compared to the FFG. Due to this lower inference gap during training, the Flow model achieves a higher AIS bound on the test set than the FFG model.
To demonstrate that a very small inference gap can be achieved, even with a limited approximation such as a factorized Gaussian, we train the model on a small dataset. In this experiment, our training set consists of 1000 datapoints randomly chosen from the original MNIST training set. The training curves on this small datatset are show in Fig. 3b. Even with a factorized Gaussian distribution, the inference gap is very small: the AIS and IWAE bounds are overlapping and the VAE is just slightly below. Yet, the model is overfitting as seen by the decreasing test set bounds.
 Figure 3: Training curves for a FFG and a Flow inference model on MNIST. AIS provides the tightest lower bound and is independent of encoder overfitting. There is little difference between FFG and Flow models trained on the 1000 datapoints since inference is nearly equivalent.
# 6.6.1 ENCODER AND DECODER OVERFITTING
We will begin by explaining how we separate encoder from decoder overfitting. Decoder overfitting is the same as in the regular supervised learning scenario, where we compare the train and test error. To measure decoder overfitting independently from encoder overfitting, we use the AIS bound since it is encoder-independent. Thus we can observe decoder overfitting through the AIS test training curve. In contrast, the encoder can only overfit in the sense that the recognition network becomes unsuitable for computing the marginal likelihood on the test set. Thus, encoder overfitting is computed by: $\mathcal { L } _ { \mathrm { A I S } } \ - \mathcal { L } _ { \mathrm { I W } }$ on the test set.
For the small dataset of Fig. 3b, it clear that there is significant encoder and decoder overfitting. A model trained in this setting would benefit from regularization. For Fig. 3a, the model is not overfit and would benefit from more training. However, there is some encoder overfitting due to the gap between the AIS and IWAE bounds on the test set. Comparing the FFG and Flow models, it appears that the Flow does not have a large effect on encoder or decoder overfitting.
# 6.7 GAUSSIAN LATENTS WITH FULL COVARIANCE
The flexiblity of the Gaussian family with arbitrary covariance lies between that of FFG and Flow. With covariance, the Gaussian distribution can model interactions between different latent dimensions. Yet, compared to Flow, its expressiveness is limited due to its inability to model higher order interactions and its unimodal nature.
To apply the reparameterization trick, we perform the Cholesky decomposition on the covariance matrix: $\overrightharpoon { \Sigma } = L \overrightharpoon { L } ^ { \top }$ , where $L$ is lower triangular. A sample from $\mathcal { N } ( \boldsymbol { \mu } , \boldsymbol { \Sigma } )$ could be obtained by first sampling from a unit Gaussian $\epsilon \sim \mathcal { N } ( 0 , \bar { I } )$ , then computing $z = \mu + L \epsilon$ .
To analyze the capability of the Gaussian family, we train several VAEs on MNIST and FashionMNIST with the approximate posterior $q ( z | x )$ being a Gaussian with full covariance. To inspect how well inference is done, we perform the local optimizations described in Section 5.2 with FFG and Flow.
Table 10: Gaussian latents trained with full covariance.
<table><tr><td></td><td>MNIST</td><td>Fashion-MNIST</td></tr><tr><td>logp(x)</td><td>-89.28</td><td>-96.46</td></tr><tr><td>LVAElqFlow]</td><td>-90.69</td><td>-98.19</td></tr><tr><td>LvAE[FFG]</td><td>-101.84</td><td>-107.89</td></tr><tr><td>LvAE[q]</td><td>-92.05</td><td>-102.93</td></tr></table>
We can see from table 10 that local optimization with FFG on a model trained with full covariance inference produces a bad lower bound. This resonates with the argument that the approximation has a significant influence on the true posterior as described in section 5.3.
Comparing to numbers in table 2, we can see that the full-covariance VAE trained on MNIST is nearly on par with that trained with Flow (-89.28 vs -88.94). For Fashion-MNIST, the fullcovariance VAE even performs better by a large margin in terms of the estimated log-likelihood (-96.46 vs -97.41).123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251# A TARGET-AGNOSTIC ATTACK ON DEEP MODELS: EXPLOITING SECURITY VULNERABILITIES OF TRANSFER LEARNING
Shahbaz Rezaei & Xin Liu Department of Computer Science University of California Davis, CA 95616, USA {srezaei,xinliu}@ucdavis.edu
# ABSTRACT
Due to insufficient training data and the high computational cost to train a deep neural network from scratch, transfer learning has been extensively used in many deep-neural-network-based applications. A commonly used transfer learning approach involves taking a part of a pre-trained model, adding a few layers at the end, and re-training the new layers with a small dataset. This approach, while efficient and widely used, imposes a security vulnerability because the pre-trained model used in transfer learning is usually publicly available, including to potential attackers. In this paper, we show that without any additional knowledge other than the pre-trained model, an attacker can launch an effective and efficient brute force attack that can craft instances of input to trigger each target class with high confidence. We assume that the attacker has no access to any target-specific information, including samples from target classes, re-trained model, and probabilities assigned by Softmax to each class, and thus making the attack target-agnostic. These assumptions render all previous attack models inapplicable, to the best of our knowledge. To evaluate the proposed attack, we perform a set of experiments on face recognition and speech recognition tasks and show the effectiveness of the attack. Our work reveals a fundamental security weakness of the Softmax layer when used in transfer learning settings.
# 1 INTRODUCTION
Deep learning has been widely used in various applications, such as image classification Parkhi et al. (2015), image segmentation Chen et al. (2016), speech recognition Ji et al. (2018), machine translation Wu et al. (2016), network traffic classification Rezaei & Liu (2019b), etc. Because training a deep model is expensive, time-consuming, and data intensive, it is often undesirable or impractical to train a model from scratch in many applications. In such cases, transfer learning is often adopted to overcome these hurdles.
A typical approach for transfer learning is to transfer a part of the network that has already been trained on a similar task, add one or more layers at the end, and then re-train the model. Since a large part of the model has already been trained on a similar task, the weights are usually kept frozen and only the new layers are trained on the new task. Hence, the number of training parameters is considerably smaller than it is when training the entire model, which allows us to train the model quickly with a small dataset. Transfer learning has been widely used in practice Rezaei & Liu (2019c), including applications such as face recognition Parkhi et al. (2015), text-to-speech synthesis Jia et al. (2018), encrypted traffic classification Rezaei & Liu (2019a), and skin cancer detection Esteva et al. (2017).
One security vulnerability of transfer learning is that pre-trained models, also refereed to as teacher models, are often publicly available. For example, Google Cloud ML tutorial suggests using Google’s Inception V3 model as a pre-trained model and Microsoft Cognitive Toolkit (CNTK) suggests using ResNet18 as a pre-trained model for tasks such as flower classification Wang et al.
 Figure 1: Example of activation vector and how the Softmax layer responses. The image on the left shows the activation vector of a natural face in the training set. The Softmax layer performs Softmax operation over the linear combination of such activation vectors and assigns high confidence to the corresponding class. The target-agnostic image (the image on the right) is crafted such that it activates one neuron in activation vector with extremely large value and all others are almost zero. Such activation vector also fools the softmax layer to produce output with high confidence. Due to the lack of space, we only show the first 400 neurons of the activation vector.
(2018). This means that the part of the model transferred from the pre-trained model is known to potential attackers.
In this paper, we show that an attacker can launch a target-agnostic attack and fool the network when only the pre-trained model is available to the attacker. In our attack, the attacker only knows the pretrained (teacher) model used to re-train the target (student) model. The attacker does not know the class labels, samples from any target class, the entire re-trained model, or probabilities the model assigns to each class, making it target-agnostic. To the best of our knowledge, these assumptions are more general than those used in any previously proposed attack models, which renders the old models ineffective.
The target-agnostic attack can be adopted in scenarios where fingerprint, face, or voice is used for authentication/verification. In such cases, the attacker usually lacks access to fingerprint or voice samples, which could be used to bypass authentication/verification. Our attack aims to craft an input that triggers any target class with high confidence. The attacker can also continue the crafting process to trigger all target classes. Such adversarial examples can be used to easily bypass authentication/verification systems without having a true sample of the target class. Our work develops a highly effective target-agnostic attack, exploiting the intrinsic characteristic of Softmax in transfer learning settings. Our experiments on face recognition and speech recognition demonstrate the effectiveness of our attack.
In a typical transfer learning procedure, all neural network layers up to the penultimate layer are transferred to a new model and then a Softmax layer is added and re-trained on a new task. We call the scores at the penultimate layer activation vector and the part of the model that produces the activation vector feature extractor. Hence, the Softmax layer basically computes the softmax operation over the linear combination of activation vector. The left side of Figure 1 presents a natural input and a typical activation vector. Due to the use of linear combination of elements of activation vectors in Softmax layer, not only such patterns can trigger the corresponding classes, but also a large number of other unrelated patterns can also trigger Softmax layer in the same way. In this paper, we show that if we craft an image that produces an activation vector such that one neuron is large and others are almost zero (the right side of Figure 1), it triggers the class for which the weight associated to that neuron is higher in the linear combination. In other words, instead of finding all features that should be activated by feature extractor, we assign very large value to only one neuron to compensate for other neurons that we do not activate.
In summary, the contributions of this paper are as follows:
1. Present a target-agnostic attack in transfer learning settings. We show that if the pre-trained model used during transfer learning is available, an attacker can craft a set of universal adversarial images that can effectively fool any model re-trained on the pre-trained model. Our attack does not need any training sample from the target model or the target model itself for crafting images. Such a target-agnostic attack has two consequences: I) the crafting time is irrelevant because adversarial images are crafted only once and then they can be used on any model that used the pre-trained model during the transfer learning stage (that is why the attack is called target-agnostic), and II) it does not need to query the target model to craft images. Hence, an attack can craft a set of adversarial images on VGG face model, as an example, and then uses them effectively on any re-trained model based on VGG face.
2. Design a simple approach to exploit the vulnerabilities of Softmax layer. We show that both threshold-based approach, where the model only accept the classification result if the confidence is high, and reject-class-based approach, where the model is trained with an extra class, called reject/null class, to reject adversarial images are prone to our attack.
3. Evaluation of our attack on face recognition and speech recognition tasks. We study the effectiveness of our model in different scenarios and settings.
# 2 RELATED WORK
In general, there are two types of attacks on deep neural networks in literature: I) evasion and 2) data poisoning. In the evasion attack, an attacker aims to craft or modify an input to fool the neural network or force the model to predict a specific target class Elsayed et al. (2018). Various methods have been developed to generate adversarial examples by iteratively modifying pixels in an image using gradient of the loss function with respect to the input to finally fool the network Szegedy et al. (2013); Carlini & Wagner (2017a;b). These attacks usually assume that the gradient of the loss function is available to the attacker. In cases where the gradient is not available, it has been shown than one can still generate adversarial examples if the top 3 (or any other number of) predicted class labels are available Sharif et al. (2016). Interestingly, it has been shown that the adversarial examples are often universal, that is, an adversarial example generated for a model can often fool other models as well Carlini & Wagner (2017a). This allows an attacker to craft adversarial examples from a model she trained and use it on the target model provided that the training set is available.
The second type of attacks on deep neural networks is called data poisoning Shafahi et al. (2018). In the data poisoning attack, an attacker modifies the training dataset to create a backdoor that can be used later to trigger specific neurons which cause mis-classification. In some papers, a specific pattern is generated and added to the training set to fool the network to associate the pattern with a specific target class Sharif et al. (2016); Chen et al. (2017b); Liao et al. (2018); Liu et al. (2017). For instance, these patterns can be an eyeglass in a face recognition task Sharif et al. (2016), randomly chosen patterns Chen et al. (2017b), some specific watermarks or logos Liu et al. (2017), specific patterns to fool malware classifiers Munoz-Gonz ˜ alez et al. (2017), etc. In some extreme cases, it ´ has been shown that by only modifying a single bit to have a maximum or minimum possible value, one can create a backdoor Alberti et al. (2018). This happens due to the operation of max pooling layer commonly used in convolutional neural networks. After the training phase, the backdoor can be used to fool the network to predict the class label associated with these patterns at inference time.
There are a few studies specifically focused on attacks in transfer learning scenarios Ji et al. (2018); Wang et al. (2018). In Wang et al. (2018), the pre-trained model and an instance of target image are assumed to be available. Assuming that the attacker knows that the first $k$ layers of the pretrained model copied to the new model, the attacker perturb the source image such that the internal representation (activation vector) of the source image becomes similar to the internal representation of the target image at layer $k$ , using pre-trained model. In Ji et al. (2018), first, a set of semantic neighbors are generated for a given source and target input which are used to find the salient features of the source and target class. Then, similar to Wang et al. (2018), the pre-trained feature extractor is used to perturb the source image along the salient features such that their internal representation becomes close. However, these attacks do not work when no instances of the target class is available.
In this paper, we propose a target-agnostic attack on transfer learning. We assume that only the pretrained model (e.g., VGG face or ResNet18) is available to the attacker. We assume the re-training data and the re-trained model is unknown and not even a single target class sample is available. Our attack model is more general than the previous studies, and thus renders previous attacks on transfer learning infeasible. Note that black-box attacks Sharif et al. (2016); Papernot et al. (2017), where an attacker only have access to the model output, can theoretically be applied in our transfer learning settings. However, a successful black-box attack often needs hundreds to millions of queries to the target model whereas the high effectiveness of our attack means it only needs a few query to the target model to generate adversarial input.
 Figure 2: Transfer learning on VGG Face
# 3 SYSTEM MODEL
In this paper, we assume that the transferred model trained on a source task is publicly available. This is a reasonable assumption, which in fact is widely used in practice. For instance, Liu et al. (2017) used the VGG face model Parkhi et al. (2015) trained to recognize 2622 identities to recognize 5 new faces. The model is shown in Fig. 2. While our attack targets any transfer-learning-based deep models, we use face recognition based on VGG face as an example for explanation. Fig. 2 shows the typical transfer learning approach for face recognition Parkhi et al. (2015).
In transfer learning, the layers whose weights are transferred to the new model are called feature extractor that outputs semantic (internal) representation of an input. The last few layers that are re-trained on the new task are called classifier. In typical transfer learning attack scenarios, the transferred model is publicly available, but the re-trained model is not known to an attacker. In other words, the attacker only knows the feature extractor but not the classifier. The previous work on transfer learning Wang et al. (2018); Ji et al. (2018) assumes that at least one sample image from each target class is available because they aim to generate images that produce similar activation vector as the target samples produce. These approaches do not work without samples from the target class.
In this paper, we assume that the attacker does not have access to any samples of the new target classes. Our motivation of the attack is to craft images for models used in systems, such as authentication/verification system, for which there is no target sample available, otherwise the attacker could have just used those samples. In such cases, attackers do not have access to samples of the target classes and, consequently, the previous attacks do not work.
# 4 ATTACK DESIGN
Design Principle. To launch an attack with these restrictive assumptions, we need to approach the problem differently. Our attack exploits the key vulnerabilities of the Softmax layer which assigns high confidence labels to vast area of input space that are not necessarily close to the training manifold Gunther et al. (2017). Softmax layer basically performs Softmax operation on the linear combination of activation vector. The activation vector of a real image often shows certain pattern with several triggered neurons, as in Figure 1 (on the left). However, the linear combination of the Softmax layer can also be triggered if only a single neuron in the activation vector has a large value. In other words, each neuron of the activation vector has a direct and linear relation with one or few target classes with different weights. Hence, the attacker can trigger these neurons one by one to see which one is highly associated with each target class.
The main attack idea is to activate the $i ^ { t h }$ neuron at the output of the feature extractor $( n - 1 ^ { t h }$ layer), denoted by $x _ { i } ^ { n - 1 }$ , with a high value and keep the other neurons at the same layer zero, similar to the Figure 1 (on the right). After the feature extractor, the model has only a FC layer and a Softmax that outputs the probability of each class. Because of the linear combination used before Softmax operation, if there exists a neuron at layer $n ^ { t h }$ that associated a large weight to $x _ { i } ^ { n - 1 }$ , it will become large. Hence, the softmax will assign a high confidence to that class. In order to find an adversary image, we can iteratively try to trigger each neuron at the $( n - 1 ) ^ { t h }$ layer to find an adversary image.
Next, we further explain the attack intuition in more detail using a simple example. Let’s assume that the output of feature extractor is layer $( n - 1 ) ^ { t h }$ and we only have two target classes. Let’s keep all neurons at layer $( n - 1 ) ^ { t h }$ zero except the $i ^ { t h }$ neuron, denoted by $x _ { i } ^ { n - 1 }$ . Then, for the last layer, $n ^ { t h }$ , we have $x _ { 1 } ^ { n } = W _ { 1 , i } ^ { n } x _ { i } ^ { n - 1 }$ and $x _ { 2 } ^ { n } = W _ { 2 , i } ^ { n } x _ { i } ^ { n - 1 }$ , and other terms are zero. We omit $b$ for simplicity. Now, if $W _ { 1 , i } ^ { n } > W _ { 2 , i } ^ { n }$ , increasing $x _ { i } ^ { n - 1 }$ increases the difference between $x _ { 1 } ^ { n }$ and $x _ { 2 } ^ { n }$ . Although the difference increases linearly with $x _ { i } ^ { n - 1 }$ , the Softmax operation makes the difference exponential. In other words, by increasing $x _ { i } ^ { n - 1 }$ , one can arbitrarily increase the confidence of the target class whose ${ { W } _ { i } ^ { n } }$ is higher, i.e., class 1 in this example. That is the motivation of the proposed brute force attack.
Algorithm 1 The target-agnostic brute force attack
<table><tr><td></td><td>Input: M (number of neurons at the output of feature extractor),Iimg (initial input), K (number of</td></tr><tr><td>procedure ATTACK(Iimg,F,T)</td><td>iteration), F (known feature extractor),α (step constant),T (the target model on attack):</td></tr><tr><td>1: 2:</td><td>fori from 1 to M do</td></tr><tr><td></td><td>Y=0m</td></tr><tr><td>3: 4:</td><td></td></tr><tr><td>5:</td><td>Y[𝑖] = 1000; >Any sufficiently large number</td></tr><tr><td>6:</td><td>X=Iimg for j from 1 to K do</td></tr><tr><td>7:</td><td>L = γ(F(X)[i])-Y[i])²+ β(∑t≠i relu(F(X)[l]-Y[[])²)</td></tr><tr><td>8:</td><td>8=</td></tr><tr><td>9:</td><td>X=X-αδ</td></tr><tr><td>10:</td><td>if T(X) bypasses the authentication then return X</td></tr><tr><td>return </td><td></td></tr></table>
Algorithm Design. The brute force algorithm is shown in Algorithm 1. We first iterate through all neurons at the output of the feature extractor and set the target, $Y$ , such that at each iteration only one neuron is triggered. We set all elements of $Y$ to zero except for the $i ^ { t h }$ one which can be set to any sufficiently large number, e.g., 1000, in Algorithm 1. Note that $Y$ is a target of the feature extractor, not that of the entire re-trained model. In the case of the VGG face, there are 4096 neurons at this layer. So, we only try 4096 times at maximum. In fact, we will show in the next section that we only need to try a few times to trigger any class and we need way fewer than 4096 attempts to trigger all target classes at least once.
Inside the second loop, we use the derivative of the loss with respect to an input and change the input gradually to decrease the loss. Note that in the loop we only use the pre-trained model and the re-trained target model is not needed. We find that typical MSE loss between Y and feature extractor is very inefficient. For the target activation vector where $i ^ { t h }$ neuron is large and all other neurons are close to zero, the modified loss is defined as follows:
$$L = \gamma ( F ( x ) [ i ] ) - Y [ i ] ) ^ { 2 } + \beta ( \sum _ { l \neq i } r e l u ( F ( x ) [ l ] - Y [ l ] ) ^ { 2 } ) ,$$
where $F ( X )$ is the output of feature extractor (i.e. activation vector) and $Y$ is the target activation vector. It is similar to the regular MSE loss with two minor changes: I) Because the importance of $i ^ { t h }$ neuron is greater than all other 4095 neurons to our attack, we use $\gamma$ and $\beta$ to control the influence of each part on the loss function. II) Because of the existence of relu function after each fully connected layer to provide non-linearity, any value on the $( - \infty , 0 ]$ range becomes 0. Hence, instead of crafting an image that has large value in $i ^ { t h }$ neuron and zero value in all other neurons, we aim to craft an image that has large value in $i ^ { t h }$ neuron and any non-positive value in all other neurons. Not only the original MSE might not converge to an adversary example, our revised loss function defined in (1) is much more efficient since the loss function only focuses on neurons that have positive value at each step and ignores the ones that are already negative. This goal is acheived by adding the relu function in the loss function.
Implication. We call this type of attack target-agnostic because it does not exploit any information from target’s classes, model, or samples. In fact, if the same pre-trained model is used to re-train two different target tasks (models), $A$ and $B$ , the proposed target-agnostic attack crafts similar adversarial inputs for both $A$ and $B$ since it only uses the pre-trained model to craft inputs. The implication is that the attacker can craft a set of adversarial inputs with the source model using the proposed attack and use it effectively to attack all re-trained models that use the same pre-trained model. This means that the attack crafting time is not important and one can create a database of likely-to-trigger inputs for each popular pre-trained model, such as the VGG face or ResNet18. Given the simplicity, remarkable effectiveness, and target-agnostic feature of the proposed algorithm, it poses a huge security threat to transfer learning.
# 5 EVALUATION
In this section, we evaluate the effectiveness of our approach using two test cases: Face recognition and speech recognition (Appendix A.2). We use Keras with Tensorflow backend and a server with Intel Xeon W-2155 and Nvidia Titan Xp GPU using Ubuntu $1 6 . 0 4 ^ { 1 }$ . We use two metrics to evaluate the proposed attack model: 1) Number of attempts to break all classes (NABAC): Assuming that the number of target classes are known, this metric shows how many adversarial input instances are queried, on average, to trigger all target classes at least once with above $9 9 \%$ confidence. 2) Effectiveness $( X \% )$ : This metric shows the ratio of crafted inputs that trigger any target classes with $X \%$ confidence over the total number of crafted inputs. We use $9 5 \%$ and $9 9 \%$ confidence for effectiveness in this paper.
# 5.1 CASE STUDY: FACE RECOGNITION
In this case study, we use the VGG face model Parkhi et al. (2015) as a pre-trained model. We remove the last FC layer and the softmax (SM) layer to make a feature extractor. Then, we pair it with a new FC and SM layer, and re-train the model (while fixing feature extractor) with labeled faces of vision lab at UMass LWF (2016). During re-training, we train the model with Adam optimizer and cross entropy loss function. We set $K = 5 0 0 0 0$ , $\alpha = 0 . 1$ , $\beta = 0 . 0 1$ , and $\gamma = 1$ . In some experiments, we add more FC layers before the SM layer, as explained later.
Number of Target Classes. Table 1 shows the impact of number of target classes on the attack performance. We use 20 classes with the highest number of samples from UMass dataset LWF (2016). The largest class is George W Bush with 530 samples and the smallest one is Alejandro Toledo with 39 samples. A blank image is used as an intial image. For 5, 10, and 15 classes, we randomly choose a set from 20 classes and re-train and attack the model 50 times and average the results. For 20 classes, we only re-train and attack once. That is the reason we do not show the standard deviation in the table. Table 2 shows the result when we use five images from each class for test set and all other images for training set. Hence, the re-training dataset is imbalanced. To balance the dataset, we undersample all classes to have an equal training size, shown in Table 1.
As it is shown, the effectiveness of the attack on an imbalanced model is higher. However, the NABAC is slightly worse. We find out that on average the weights of SM layer for the class with larger training samples are slightly higher than the other classes. Hence, it is easier to trigger that class with the proposed method which increases the effectiveness. However, it is much harder to trigger the smallest class which makes the NABAC larger. The impact of imbalance re-training dataset is studied in more detail in Appendix A.1, where we show that the probability of triggering a target class directly associated with the number of training samples of that class during re-training. Moreover, the effectiveness and the NABAC improves when the number of target classes decreases, as expected. Note that in all scenarios, the effectiveness is greater than $7 5 \%$ . It means that the first crafted image has more than $7 5 \%$ chance of bypassing the authentication system (or any other application). It basically means that the traditional approach of limiting the number of queries to prevent brute-force-based attack does not work here.
Number of Layers to Re-train. In previous experiments, we assume that the weights of the feature extractor transferred from the pre-trained model are fixed during re-training and only the last FC layer is changed. One can tune more layers during re-training. Fig. 3(a) shows the impact of tuning more layers on the effectiveness and accuracy. Note that we assume that attacker does not know anything about the target model. Hence, in this experiment, the attacker still uses the pre-trained feature extractor up until the last FC layer. That means the pre-trained feature extractor that the attacker uses is slightly different from the re-trained model. In Fig. 3(a), X axis represents the layer from which we start tuning up to the last FC layer. Due to the small re-training dataset, as the number of tuning layers increases the accuracy drops. However, by tuning more layers, the pre-trained model that the attacker has access to becomes more different from the re-trained model. That is why the effectiveness of the attack decreases. Similarly, NABAC increases, as shown in Fig. 3(b). Despite the difference between the re-trained model and the model the attacker has access to, the attack is still effective, which means that the pre-trained model cannot be changed dramatically during re-training process and re-training more layers is not an effective defense strategy.
Table 1: Attack performance on balanced re-training dataset. Acc, NABAC, and $E f f$ stands for accuracy, number of attempts to break all classes, and effectiveness, respectively.
<table><tr><td rowspan="2">Target classes</td><td colspan="4">Balanced dataset</td></tr><tr><td>Acc</td><td>NABAC</td><td>Eff(95%)</td><td>Eff(99%)</td></tr><tr><td>5</td><td>99.12% ± .27</td><td>48.25 ± 42.5</td><td>91.68% ± 5.69</td><td>87.82% ± 6.98</td></tr><tr><td>10</td><td>98.43% ± .23</td><td>149.97± 132.15</td><td>88.87% ± 2.46</td><td>83.07% ± 3.31</td></tr><tr><td>15</td><td>97.16% ± 1.64</td><td>323.36± 253.56</td><td>87.79% ± 2.42</td><td>82.05% ± 2.74</td></tr><tr><td>20</td><td>96.87%</td><td>413</td><td>87.17%</td><td>79.16%</td></tr></table>
Table 2: Attack performance on imbalanced re-training dataset. Acc, NABAC, and $E f f$ stands for accuracy, number of attempts to break all classes, and effectiveness, respectively.
<table><tr><td rowspan="2">Target classes</td><td colspan="4">Imbalanced dataset</td></tr><tr><td>Acc</td><td>NABAC</td><td>Eff(95%)</td><td>Eff(99%)</td></tr><tr><td>5</td><td>99.21% ± .29</td><td>63.29 ± 80.30</td><td>93.52% ± 5.07</td><td>90.23% ± 5.71</td></tr><tr><td>10</td><td>98.47% ± .81</td><td>264.80 士 111.09</td><td>91.14% ± 3.65</td><td>86.28%± 5.40</td></tr><tr><td>15</td><td>98.01% ± 1.39</td><td>451.45 ± 244.31</td><td>90.41% ± 1.89</td><td>85.31% ± 2.48</td></tr><tr><td>20</td><td>97.07%</td><td>2836</td><td>88.72%</td><td>82.93%</td></tr></table>
Number of New Layers in the Re-trained Model. Next, we measure how adding and training more layers (pair of $\mathrm { F C } + \mathrm { R e l u } )$ ) after feature extractor can affect the proposed attack effectiveness. In this experiment, we use 5 balanced target classes. As shown in Table 3, adding more layers decreases the accuracy of the re-trained model because the re-training dataset is small and not enough to train more layers from scratch. The effectiveness of the attack decreases sightly as more new layers are tuned. When adding more new layers, not all target classes are affected equally and some classes may become harder to trigger. That is why NABAC increases. The goal of our attack is to have an activation vector with only one large value. However, each extra layer, added after feature extractor, smooths out the single large value and distributes it to more neurons in activation vector. That is the reason the attack becomes less effective when more new layers are added.
 Figure 3: Effect of number of re-training layers
Table 3: Effect of number of new layers in the re-trained model
<table><tr><td># of new layers</td><td>Accuracy</td><td>NABAC</td><td>Effectiveness(95%)</td><td>Effectiveness(99%)</td></tr><tr><td>1</td><td>99.12% ± .27</td><td>48.25 ± 42.5</td><td>91.68% ± 5.69</td><td>87.82% ± 6.98</td></tr><tr><td>2</td><td>98.24% ± 2.10</td><td>51.87 ± 39.94</td><td>91.57% ± 4.87</td><td>86.45% ± 5.35</td></tr><tr><td>3</td><td>95.46% ± 4.2</td><td>257.26 ± 387.16</td><td>89.45% ± 8.20</td><td>85.67% ± 8.88</td></tr></table>
 Figure 4: Number of reject training samples vs effectiveness/accuracy
Attack Effectiveness on A Classifier with Reject Class. It has been shown that relying on a threshold to reject or accept the classification result is not accurate because for the vast space of unknown inputs Softmax provides high confidence scores Nguyen et al. (2015). Hence, we add an extra class to the softmax layer, similar to Hosseini et al. (2017), called reject/unknown class. During re-training, we choose random sample images from entire UMass dataset, except the classes that we choose for target faces, and label them as reject class. We vary the number of training samples for reject class to see its effect on accuracy and effectiveness. Figure 4 illustrates the trade-off between the accuracy of the re-trained model and the effectiveness of our attack. The lowest effectiveness, for which the accuracy is $8 7 . 7 2 \%$ , is $4 1 . 4 0 \%$ which is still high. Hence, the classifier with a reject class option is still prone to our target-agnostic attack.
Attack Comparison with black-box attack and baseline attack. We compare our attack with a black-box attack and a baseline. For the baseline attack, we choose random face images from UMass dataset that have not been used for training. Interestingly, for the threshold-based model, there is a $1 2 . 6 0 \%$ chance that a random face image triggers an output class with high probability, as shown in Table 4. A model with a reject class can effectively prevent baseline attack since none of the random images fool the model. Moreover, we use Zoo black-box attack Chen et al. (2017a) as comparison. The default configuration of untargeted Zoo attack yields a very low effectiveness of $1 8 . 2 0 \%$ . After hyper-parameter tuning and setting the confidence of the crafted images in the algorithm to $0 . 9 9 \%$ , Zoo achieves its highest effectiveness of $7 6 . 1 2 \%$ . The effectiveness of all attacks are higher against the threshold-based model than the model with a reject class. Our attack needs only one query to the re-trained (student) model because it crafts the images using the publicly available pre-trained (teacher) model. Any black-box attack, such as Zoo, that depends only on the student models needs a significant number of queries which is easy to defend by limiting the number of queries.
# 6 DISCUSSION
In this paper, we show that the public information from transfer learning settings can be exploited to fool Softmax-based classifier. The main vulnerabilities of the Softmax layer comes from the fact that it assigns a high confidence output to inputs that are far away from the training input distribution. This drawback has been shown in studies that investigate open-set problem Bendale & Boult (2016); Gunther et al. (2017). In other words, Softmax-based models are vulnerable to inputs with different distribution than their training set. To mitigate the problem and defeat our attack, we use a recent novel classifier for the open-set problem, called extreme value machine (EVM) Rudd et al. (2017), that aims to fit a distribution to the activation vector (Figure 1) rather than a linear combination based on Softmax operation. We follow the experimental setting similar to Gunther et al. (2017). The accuracy of the EVM-based model is $9 5 . 6 0 \%$ , which is lower than the softmax-based model in our experiments, and the model successfully defeat all our crafted images. The main reason that EVM can be used as a defense mechanism is that the activation vector of our crafted images are far from the activation vector of any image in the training set. However, EVM has its own vulnerability: we find out that by feeding images of random faces (UMass dataset in our study), there is a $7 . 3 8 \%$ chance that the EVM-base model classifies the input as one of the target classes. Hence, more robust model is needed to defend our attack and also work well in open-set scenarios.
Table 4: Attack Comparison. NQT, NQS, and $E f$ stands for number of query to the teacher model, number of query to the student model, and effectiveness, respectively.
<table><tr><td rowspan="2">Attack type</td><td colspan="3">Threshold-based model</td><td colspan="2">With reject class</td></tr><tr><td>NQT</td><td>NQS</td><td>Ef(99%)</td><td>NQT NQS</td><td>Ef</td></tr><tr><td>Our attack</td><td>50,000</td><td>1</td><td>87.82%</td><td>50,000 1</td><td>78.24%</td></tr><tr><td>Zoo (black-box)</td><td>-</td><td>1,036,800</td><td>76.12%</td><td>二 816,800</td><td>81.01%</td></tr><tr><td>Baseline (random)</td><td>=</td><td>1</td><td>12.60%</td><td>- 1</td><td>00.00%</td></tr></table>
Another approach to defend the vulnerability of the Softmax layer is to check all elements of activation vector and avoid classification of suspicious inputs. In other words, if an activation element is significantly larger than what it should normally be, we can label the input image as malicious. In our experiment, we find that the average value of the largest neurons in activation vector is around 23.86 for normal face images and the largest value we observed is 47.22. So, if we define a threshold for the maximum value in activation vector to be around 50, it is possible to detect crafted images with our attack. In our attack scenario, we craft inputs with the maximum value in activation vector of 1000, which is easily detectable, if checked. We perform an experiment to see if our attack work when this value is much smaller and in a normal range. By crafting images with max value in activation vector of 50, instead of 1000, the effectiveness of our attack is dramatically reduced $( 0 . 0 0 0 7 \% )$ . However, this threshold may lead to a large false positive in inference time. With the max value of 100 and 200, the effectiveness is $0 . 0 5 8 \%$ and $0 . 2 \hat { 7 } \%$ , respectively. Hence, if the threshold value for anomaly detection is chosen meticulously, it can serve as a defense mechanism for our attack with the cost of increasing false positive (labeling some natural face images as malicious).
# 7 CONCLUSION
In this paper, we develop an efficient brute force attack on transfer learning for deep neural networks - the attack exploits a fundamental vulnerability of the Softmax layer that can be easily exploited when transfer learning is used. We assume that the attacker only knows the transferred model and its weights, and does not have access to the re-trained model, the re-trained dataset, and the re-trained model’s output. Our evaluations based on face recognition and speech recognition show that with a handful of attempts, the attacker can craft adversarial samples that can trigger all classes despite the fact that the attacker does not know the re-trained model and model’s target classes. The targetagnostic feature of the attack allows the attacker to use the same set of crafted images for different re-trained models and achieve high effectiveness when the models use the same pre-trained model. The proposed target-agnostic attack reveals a fundamental challenge of Softmax layer in transfer learning settings: because the Softmax layer assign high confidence output to vast space of unseen inputs, a simple brute-force attack can operate surprisingly effective. To defeat the target-agnostic attack, the model should consider the distribution of the activation vector, like EVM method, not the linear combination alone, like Softmax layer. Nevertheless, there is a fundamental trade-off between accuracy and robustness and it should be tuned based on the sensitivity of the application.
# ACKNOWLEDGMENTS
This work was supported by the National Science Foundation (NSF) under Grant CNS-1547461, Grant CNS-1718901, and Grant IIS-1838207.
# REFERENCES
Labeled faces in the wild, 2016. URL http://vis-www.cs.umass.edu/lfw/. [Online; accessed 24-Mar-2019].
Speech commands, 2017. URL https://www.tensorflow.org/tutorials/ sequences/audio_recognition. [Online; accessed 24-Mar-2019].
Pannous speech recognition, 2017. URL https://github.com/pannous/ tensorflow-speech-recognition. [Online; accessed 24-Mar-2019].
Michele Alberti, Vinaychandran Pondenkandath, Marcel Wursch, Manuel Bouillon, Mathias Seuret, Rolf Ingold, and Marcus Liwicki. Are you tampering with my data? In Proceedings of the European Conference on Computer Vision (ECCV), pp. 0–0, 2018.
Abhijit Bendale and Terrance E Boult. Towards open set deep networks. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 1563–1572, 2016.
Nicholas Carlini and David Wagner. Adversarial examples are not easily detected: Bypassing ten detection methods. In Proceedings of the 10th ACM Workshop on Artificial Intelligence and Security, pp. 3–14. ACM, 2017a.
Nicholas Carlini and David Wagner. Towards evaluating the robustness of neural networks. In 2017 IEEE Symposium on Security and Privacy (SP), pp. 39–57. IEEE, 2017b.
Liang-Chieh Chen, Yi Yang, Jiang Wang, Wei Xu, and Alan L Yuille. Attention to scale: Scaleaware semantic image segmentation. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 3640–3649, 2016.
Pin-Yu Chen, Huan Zhang, Yash Sharma, Jinfeng Yi, and Cho-Jui Hsieh. Zoo: Zeroth order optimization based black-box attacks to deep neural networks without training substitute models. In Proceedings of the 10th ACM Workshop on Artificial Intelligence and Security, pp. 15–26. ACM, 2017a.
Xinyun Chen, Chang Liu, Bo Li, Kimberly Lu, and Dawn Song. Targeted backdoor attacks on deep learning systems using data poisoning. arXiv preprint arXiv:1712.05526, 2017b.
Gamaleldin F Elsayed, Shreya Shankar, Brian Cheung, Nicolas Papernot, Alex Kurakin, Ian Goodfellow, and Jascha Sohl-Dickstein. Adversarial examples that fool both human and computer vision. arXiv preprint arXiv:1802.08195, 2018.
Andre Esteva, Brett Kuprel, Roberto A Novoa, Justin Ko, Susan M Swetter, Helen M Blau, and Sebastian Thrun. Dermatologist-level classification of skin cancer with deep neural networks. Nature, 542(7639):115, 2017.
Manuel Gunther, Steve Cruz, Ethan M Rudd, and Terrance E Boult. Toward open-set face recognition. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition Workshops, pp. 71–80, 2017.
Hossein Hosseini, Yize Chen, Sreeram Kannan, Baosen Zhang, and Radha Poovendran. Blocking transferability of adversarial examples in black-box learning systems. arXiv preprint arXiv:1703.04318, 2017.
Yujie Ji, Xinyang Zhang, Shouling Ji, Xiapu Luo, and Ting Wang. Model-reuse attacks on deep learning systems. In Proceedings of the 2018 ACM SIGSAC Conference on Computer and Communications Security, pp. 349–363. ACM, 2018.
Ye Jia, Yu Zhang, Ron Weiss, Quan Wang, Jonathan Shen, Fei Ren, Patrick Nguyen, Ruoming Pang, Ignacio Lopez Moreno, Yonghui Wu, et al. Transfer learning from speaker verification to multispeaker text-to-speech synthesis. In Advances in Neural Information Processing Systems, pp. 4485–4495, 2018.
Cong Liao, Haoti Zhong, Anna Squicciarini, Sencun Zhu, and David Miller. Backdoor embedding in convolutional neural network models via invisible perturbation. arXiv preprint arXiv:1808.10307, 2018.
Yingqi Liu, Shiqing Ma, Yousra Aafer, Wen-Chuan Lee, Juan Zhai, Weihang Wang, and Xiangyu Zhang. Trojaning attack on neural networks. Proc. NDSS, 2017.
Luis Munoz-Gonz ˜ alez, Battista Biggio, Ambra Demontis, Andrea Paudice, Vasin Wongrassamee, ´ Emil C Lupu, and Fabio Roli. Towards poisoning of deep learning algorithms with back-gradient optimization. In Proceedings of the 10th ACM Workshop on Artificial Intelligence and Security, pp. 27–38. ACM, 2017.
Anh Nguyen, Jason Yosinski, and Jeff Clune. Deep neural networks are easily fooled: High confidence predictions for unrecognizable images. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 427–436, 2015.
Nicolas Papernot, Patrick McDaniel, Ian Goodfellow, Somesh Jha, Z Berkay Celik, and Ananthram Swami. Practical black-box attacks against machine learning. In Proceedings of the 2017 ACM on Asia conference on computer and communications security, pp. 506–519. ACM, 2017.
Omkar M Parkhi, Andrea Vedaldi, Andrew Zisserman, et al. Deep face recognition. In BMVC, volume 1, pp. 6, 2015.
Shahbaz Rezaei and Xin Liu. How to achieve high classification accuracy with just a few labels: A semi-supervised approach using sampled packets. In Advances in Data Mining - Applications and Theoretical Aspects, 19th Industrial Conference, {ICDM} 2019, New York, USA, July 17 - July 21, pp. 28–42, 2019a.
Shahbaz Rezaei and Xin Liu. Deep learning for encrypted traffic classification: An overview. IEEE communications magazine, 57(5):76–81, 2019b.
Shahbaz Rezaei and Xin Liu. Security of deep learning methodologies: Challenges and opportunities. arXiv preprint arXiv:1912.03735, 2019c.
Ethan M Rudd, Lalit P Jain, Walter J Scheirer, and Terrance E Boult. The extreme value machine. IEEE transactions on pattern analysis and machine intelligence, 40(3):762–768, 2017.
Ali Shafahi, W Ronny Huang, Mahyar Najibi, Octavian Suciu, Christoph Studer, Tudor Dumitras, and Tom Goldstein. Poison frogs! targeted clean-label poisoning attacks on neural networks. arXiv preprint arXiv:1804.00792, 2018.
Mahmood Sharif, Sruti Bhagavatula, Lujo Bauer, and Michael K Reiter. Accessorize to a crime: Real and stealthy attacks on state-of-the-art face recognition. In Proceedings of the 2016 ACM SIGSAC Conference on Computer and Communications Security, pp. 1528–1540. ACM, 2016.
Christian Szegedy, Wojciech Zaremba, Ilya Sutskever, Joan Bruna, Dumitru Erhan, Ian Goodfellow, and Rob Fergus. Intriguing properties of neural networks. arXiv preprint arXiv:1312.6199, 2013.
Bolun Wang, Yuanshun Yao, Bimal Viswanath, Haitao Zheng, and Ben Y Zhao. With great training comes great vulnerability: practical attacks against transfer learning. In 27th {USENIX} Security Symposium ({USENIX} Security 18), pp. 1281–1297, 2018.
Yonghui Wu, Mike Schuster, Zhifeng Chen, Quoc V Le, Mohammad Norouzi, Wolfgang Macherey, Maxim Krikun, Yuan Cao, Qin Gao, Klaus Macherey, et al. Google’s neural machine translation system: Bridging the gap between human and machine translation. arXiv preprint arXiv:1609.08144, 2016.
# A APPENDIX
# A.1 CASE STUDY: FACE RECOGNITION
Choice of Initial Image. To generate adversarial images using Algorithm 1, we need to start with an initial image. To find out whether the initial image we start with has any impact on the brute force attack, we conduct 3 different experiments. We use random input, blank image (with all pixel set to one), and random images of celebrities. The results are shown in Fig. 5. First column shows crafted images starting from the random input. Second column illustrates crafted images from blank image.
 Figure 5: First column shows crafted images starting from the random input. Second column illustrates crafted images from blank image. Third and fourth columns show the initial images and the crafted images from the initial image, respectively. The fifth column illustrates a sample image from each class that is used for re-training.
 Figure 6: Target class distribution
Third and fourth columns show the initial images and the crafted images from the initial image, respectively. The fifth column illustrates a sample image from each class that is used for re-training. In our experiment, the choice of initial image has negligible impact on effectiveness of our attack.
Table 5 shows the result of using different initial images on the attack performance. We only re-train a model once with 5 randomly chosen faces and we achieve $9 9 . 3 8 \%$ accuracy. Then, we launch the attack on the same model 3 times, each with a different initial image. Although using a face image marginally improves the attack performance, the impact is negligible and the other initial input cases are still considerably effective.
Table 5: Impact of initial input on the attack
<table><tr><td>Initial input</td><td>NABAC</td><td>Effectiveness(95%)</td><td>Effectiveness(99%)</td></tr><tr><td>Blank</td><td>18</td><td>98.37%</td><td>98.37%</td></tr><tr><td>Random</td><td>19</td><td>98.37%</td><td>97.22%</td></tr><tr><td>A face image</td><td>18</td><td>99.83%</td><td>99.19%</td></tr></table>
Distribution of Target Classes. Fig. 6(a) illustrates a typical distribution of target classes triggered by crafted images of the proposed method. It is clear that the distribution is far from Uniform. It basically means that more neurons in layer $n - 1$ are associated with class 1 and, hence, during brute force attack, more crafted images will trigger that class.
To measure the impact of re-training set on the distribution of target classes, we use Jensen-Shannon distance (JSD). Jensen-Shannon divergence measures the similarity between two distributions as follows:
$$J S D ( P | | Q ) = \frac { 1 } { 2 } D ( P | | M ) + \frac { 1 } { 2 } D ( Q | | M )$$
where D(.) is Kullback-Leibler divergence and $M = { \textstyle \frac { 1 } { 2 } } ( P + Q )$ . Square root of JSD is a metric that we use to compare the similarity between the distribution of data samples in re-training dataset versus the distribution of triggered classes with adversarial inputs of our method.
We find that distribution of training samples during re-training can affect the target class distribution. Fig. 6(b) shows the JS distance of training set distribution and Uniform distribution versus JS distance of target class distribution and Uniform distribution. For each data point, we pick 5 random persons from UMass dataset and then re-train the VGG face model with. The line in Fig. 6(b) represents the linear regression of all data point. The figure shows that when the training set of re-training phase becomes more non-Uniform, the target class distribution becomes even more non-Uniform.
# A.2 CASE STUDY: SPEECH RECOGNITION
In Ji et al. (2018), a speech recognition model for digits were re-trained to detect speech commands. Following the same experiment, a model first pre-trained on the Pannous Speech dataset dig (2017) containing utterance of ten digits. Then, we randomly pick 5 classes from speech command dataset com (2017) to re-train the model. $8 0 \%$ of the dataset is used for fine-tuning and $2 0 \%$ for inference. Due to the lack of space and similarity of the results with previous case study, we omit most experiments with similar results. We use a 2D CNN model with 3 building block, each of which contains convolutional layers, Relu activation, and pooling layer, followed by $2 \mathrm { F C }$ layers and softmax layer at the end. The input is the Mel-Frequency Cepstral Coefficients (MFCC) of the wave files. Similar to the previous case study, we replace the SM layer and re-train the model by only tuning the last FC and SM layer.
Table 6: Effect of number of target classes on the proposed attack
<table><tr><td>#of target classes</td><td>Accuracy</td><td>NABAC</td><td>Effectiveness(95%)</td><td>Effectiveness(99%)</td></tr><tr><td>5</td><td>97.38%</td><td>37</td><td>100.00%</td><td>98.21%</td></tr><tr><td>10</td><td>93.30%</td><td>114</td><td>95.80%</td><td>93.75%</td></tr><tr><td>15</td><td>85.72%</td><td>812</td><td>92.22%</td><td>84.17%</td></tr></table>
Table 7: Effect of re-training set size
<table><tr><td>#of samples per class</td><td>Accuracy</td><td>NABAC</td><td>Effectiveness(95%)</td><td>Effectiveness(99%)</td></tr><tr><td>50</td><td>77.56%</td><td>13</td><td>97.48%</td><td>95.00%</td></tr><tr><td>100</td><td>82.46%</td><td>17</td><td>97.21%</td><td>95.23%</td></tr><tr><td>200</td><td>85.51%</td><td>21</td><td>98.25%</td><td>96.82%</td></tr><tr><td>1000</td><td>89.89%</td><td>17</td><td>98.60%</td><td>97.64%</td></tr><tr><td>2000</td><td>92.04%</td><td>17</td><td>98.60%</td><td>97.81%</td></tr></table>
Number of Target Classes. Table 6 shows the impact of number of target classes on the accuracy of the model and attack performance. Similar to the face recognition experiment, we start with a blank input (a 2D MFCC with 0 for all elements) and we use 70 and 0.1 for $k$ and $\alpha$ , respectively. As expected, the accuracy drops when the number of target classes increases. Since ten classes representing digits exist in both the pre-training dataset (Pannous dig (2017)) and the re-training dataset (speech command com (2017)), these classes are much easier for the target model to re-train with high accuracy in comparison with other classes, such as stop or left command. Hence, the re-trained model has more neuron connections to help classify digit classes which makes it harder for both the model to classify the other classes and the proposed attack to craft adversarial input for the non-digit classes. That is why we observe more dramatic decrease in accuracy and attack performance when the number of target classes increases.
Re-training Sample Size. Unlike face recognition case study in which most re-training classes have fewer than 100 samples, speech command dataset com (2017) contains more than 2000 samples for each class. Hence, we conduct an experiment to study the effect of re-training sample size on model and attack performance. We choose six classes (commands) that the pre-trained model did not trained on, i.e., left, right, down, up, go, and stop speech commands. Table 7 shows the impact of re-training set size on the model and attack performance. As expected, increasing the re-training set size improves the accuracy of the model. However, the accuracy of the re-trained model and the re-training set size have a negligible effect on the performance of proposed attack. By comparing Table 6 and Table 7, we realize that the attack performance is directly affected by the number of target classes, but it is not significantly affected by the accuracy of the re-trained model.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277# MARGINAL DEEP ARCHITECTURES: DEEP LEARNING FOR SMALL AND MIDDLE SCALE APPLICATIONS
Yuchen Zheng, Guoqiang Zhong & Junyu Dong
Department of Computer Science and Technology Ocean University of China ouczyc@outlook.com,{gqzhong, dongjunyu}@ouc.edu.cn
# ABSTRACT
In recent years, many deep architectures have been proposed in different fields. However, to obtain good results, most of the previous deep models need a large number of training data. In this paper, for small and middle scale applications, we propose a novel deep learning framework based on stacked feature learning models. Particularly, we stack marginal Fisher analysis (MFA) layer by layer for the initialization of the deep architecture and call it “Marginal Deep Architectures” (MDA). In the implementation of MDA, the weight matrices of MFA are first learned layer by layer, and then we exploit some deep learning techniques, such as back propagation, dropout and denoising to fine tune the network. To evaluate the effectiveness of MDA, we have compared it with some feature learning methods and deep learning models on 7 small and middle scale real-world applications, including handwritten digits recognition, speech recognition, historical document understanding, image classification, action recognition and so on. Extensive experiments demonstrate that MDA performs not only better than shallow feature learning models, but also state-of-the-art deep learning models in these applications.
# 1 INTRODUCTION
Deep learning methods have achieved desirable performance in many domains, such as image classification and detection, document analysis and recognition, natural language processing, video analysis (Krizhevsky et al., 2012; Chan et al., 2014; Ciresan et al., 2010; Collobert & Weston, 2008; Le et al., 2011). Deep learning methods learn the data representation by using multiple processing layers, which discover the intricate structure of high dimensional data with multiple levels of abstraction (LeCun et al., 2015). For example, for face recognition, the learned features of first layer may be the edges, directions and some local information. The second layer typically detects some object parts which are combination of edges and directions. The higher layers may further abstract the face image by combining the features of previous layers (outline of the eyes, nose, lips). This procedure is very similar with human visual and perceptual system.
In recently years, many deep learning methods have been proposed (l. Boureau & others, 2008; Lee et al., 2009b;a; Hinton & Salakhutdinov, 2006). However, most models meet some difficult problems to solve, such as some parameters need to be randomly initialized, like the weight matrix of two successive layers in deep belief networks (DBNs) and the convolution kernel in convolutional neural networks (CNNs). In addition, traditional deep learning methods need a large scale training data to train the complex networks. It causes many problems in the training process. If we don’t initialize the parameters properly, the optimization procedure might need a long training time and fall into local minima. Alternatively, many feature learning models have been proposed to learn the intrinsic structures of high-dimensional data and avoid the curse of dimensionality. In particular, most of them can be trained with small and middle scale of data and their learning algorithms are generally based on closed-form solution or convex optimization. For instance, marginal Fisher analysis (MFA) (Yan et al., 2007; Zhong et al., 2013) is one of the feature learning models that is a supervised method based on the graph embedding framework. It utilizes an intrinsic graph to characterize the intraclass compactness, and another penalty graph to characterize the interclass separability. Its optimal solution can be learned by generalized eigenvalue decomposition. However, on the one hand, shallow feature learning models cannot work well on the data with highly nonlinear structure; on the other hand, few efforts are made to combine shallow feature learning models for the design of deep architectures.
In order to simultaneously solve the existing problems in deep learning methods and combine the advantages of feature learning models, we proposed a novel deep learning method based on stacked feature learning models. Particularly, we stack marginal Fisher analysis (MFA) layer by layer for the initialization of the deep architecture and call it “Marginal Deep Architectures” (MDA). Firstly, the input data are mapped to higher dimensional space by using random weight matrix. Then we use MFA to learn the lower dimensional representation layer by layer. In the implementation of this architecture, we add some tricks in the training process, such as back propagation, dropout and denoising to fine tune the network. Finally, the softmax layer is connected to the last feature layer. We have compared our MDA with some feature learning methods and deep learning models on different domains of datasets (including handwritten digits recognition, speech recognition, historical document understanding, image classification, action recognition and so on). Extensive experiments demonstrate that MDA performs not only better than shallow feature learning models, but also state-of-the-art deep learning models in small and middle scale applications.
The contributions of this work are highlighted as follows.
1. We propose a novel structure to build a deep architecture. The first hidden layer has twice or quadruple neurons as the input layer. Then we can use some feature learning models layer by layer to learn the compact representations of data. Finally, we set the last layer as a softmax classifier.
2. Traditional deep learning models in general need a large scale training data. Compared with traditional deep learning models, MDA can work better than traditional deep learning models in small and middle scale applications because the initialization of the weight matrices using MFA is much better than that using random initialization.
3. Our MDA can work well in different domains of datasets, such as handwritten digits, spoken letters and natural images. Extensive experiments demonstrate that MDA is a general model to handel small and middle scale data. On the other hand, for large scale datasets, like CIFAR-10, MDA works comparatively with other deep learning methods.
The rest of this paper is organized as follows: In Section 2, we give a brief overview of related work. In Section 3, we present the marginal Fisher analysis (MFA) and the proposed marginal deep architectures (MDA) in detail. The experimental settings and results are reported in Section 4, while Section 5 concludes this paper with remarks and future work.
# 2 RELATED WORK
With the development of deep learning methods, many deep networks have been proposed in recent years (Donahue et al., 2013; Krizhevsky et al., 2012; Long et al., 2015; Zhou et al., 2014). These deep learning models show their powerful performance in various fields, such as image classification and analysis, document analysis and recognition, natural language processing et al. In the area of image analysis, Hinton et al. proposed a large, deep convolutional neural network (Alex net) to classify the 1.2 million high-resolution images in the ImageNet. It uses efficient GPU to speed their method. The results show that a large, deep convolutional neural network is capable of achieving recordbreaking results on a highly challenging dataset using purely supervised learning (Krizhevsky et al., 2012). In order to popularize the deep convolutional neural network, Donahue ea al. proposed DeCAF (Deep Convolutional Activation Feature) which is trained in a fully supervised fashion on a large, fixed set of object recognition tasks (Donahue et al., 2013). DeCAF provides a uniform framework for researchers who can improve and change this framework on some specific tasks. However, its performance at scene recognition has not attained the same level of success. In order to handle this problem, Zhou et al. introduce a new scene-centric database called Places with over 7 million labeled pictures of scenes. Then, they learn the deep features for scene recognition tasks by using the same architecture as ImageNet, and establish new state-of-the-art results on several scenecentric datasets (Zhou et al., 2014). However, these methods based on convolutional operation need very large scale training samples and a long training time. They can not work well on small and middle scale applications.
In other domains, deep learning methods also achieve good performance. Hinton et al. represent the shared views of four research groups that have had recent successes in using DNNs for automatic speech recognition (ASR). The DNNs that contain many layers of nonlinear hidden units and a very large output layer can outperform Gaussian mixture models (GMMs) at acoustic modeling for speech recognition on a variety of data sets (Hinton et al., 2012a). In the area of genetics, Xiong et al. use “deep learning” computer algorithms to derive a computational model that takes as input DNA sequences and applies general rules to predict splicing in human tissues (Xiong et al., 2015). It reveals the genetic origins of disease and how strongly genetic variants affect RNA splicing. In the area of natural language understanding, deep learning models have delivered strong results on topic classification, sentiment analysis et al. Sutskever et al. proposed a general approach, the Long Short-Term Memory (LSTM) architecture which can solve the general sequence to sequence problems better than before (Sutskever et al., 2014). In addition, Hinton et al. proposed autoencoder (AE) networks that is an effective way to learn the low-dimensional codes of high-dimensional data. Based on autoencoder, there are also have many excellent works to handle various tasks. Vincent et al. proposed a denoising autoencoder (DAE) which maked the learned representations robust to partial corruption of the input data (Vincent et al., 2008). The denoising autoencoder which initialize the deep architectures layer by layer is very similar with human visual system. Hinton et al. introduced random ‘dropout’ to prevent the overfitting which improve many benchmark tasks and obtain new records for speech and object recognition (Hinton et al., 2012b). Then, Vincent et al. proposed stacked denoising autoencoders (SDAE) which based on stacking layers of stacked denoising autoencoders (Vincent et al., 2010). It is very useful to learn the higher level representations and work well on natural images and handwritten digits. However, for the same reason, they also need a large scale training set and a long training time. They have no advantages to handle the small and middle scale applications.
Moreover, in the field of feature learning models, dimensionality reduction plays a crucial role to handle the problems for compressing, visualizing high-dimensional data and avoiding the “curse of dimensionality” (van der Maaten et al., 2009; van der Maaten, 2007). Traditional dimensionality reduction mainly can be classified into three types: linear or nonlinear, like principal components analysis (PCA) (Jolliffe, 2002) and linearity preserving projection (LPP) (Niyogi, 2004) are linear methods, stochastic neighbor embedding (SNE) (Hinton & Roweis, 2002) is a nonlinear method; supervised or unsupervised, such as marginal Fisher analysis (MFA) (Yan et al., 2007; Zhong et al., 2013) and linear discriminant analysis (LDA) (Fisher, 1936) are supervised methods, PCA is an unsupervised method; local or global, like MFA and SNE are local methods, PCA is a global method. Many feature learning models based on geometry theory provide different solutions to the problem of dimensionality reduction. Yan et al. proposed a general formulation about graph embedding framework can exploit new dimensionality reduction algorithms (Yan et al., 2007). If only directly use some feature learning models to extract the good representation from original data, it often eventually couldn’t get a good outcome. Considering this situation, we try to choose some excellent feature learning models and combine them with some deep learning algorithms. MFA is one special formulation of the graph embedding models based on this framework. It utilizes an intrinsic graph to characterize the intraclass compactness, and another penalty graph to characterize the interclass separability. Our motivation is to combine the advantage of MFA and deep architectures and propose a new initialization method for deep learning algorithms.
There are also have some excellent works about feature learning models combined the deep architectures (Yuan et al.; George et al., 2014; Ngiam et al., 2011). Yuan et al. proposed an improved multilayer learning model to solve the scene recognition task (Yuan et al.). This model overcome the limitation of shallow, one-layer representations for scene recognition. Trigeorgis et al proposed deep Semi-NMF, that is able to learn such hidden representations from different, unknown attributes of a given dataset (George et al., 2014). Ngiam proposed a deep architectures to learn features over multiple modalities (Ngiam et al., 2011). They showed that multi-modality feature learning is better than one modality and achieved good performance on video and audio datasets. However, in general, we can only obtain data from one modality. In this work, we combine the advantages of MFA and deep architectures, which based on stacked feature learning models (Zheng et al., 2014; 2015), then we use some deep learning tricks, like back propagation, denoising and dropout to fine tuning the network. The advantage of this deep architecture is that we can learn the desirable weight matrix even if the training data is not large enough. And compared with traditional deep learning models and shallow feature learning models, our MDA achieved state-of-the-art results in most cases.
 Figure 1: The brief representation for MDA. $\mathbf { W } _ { r _ { 1 } }$ represents the first layer random weight matrix, ${ \bf W } _ { M F A _ { 2 } }$ and ${ \bf W } _ { M F A _ { 3 } }$ represent the weight matrixes learned by MFA. The dotted red lines represent the dropout operation, the dotted red circle is the ‘dropout’ node, and the cross nodes are corrupted. The denoising and dropout operation are completely random. For simplicity, we have omitted bias terms.
# 3 MARGINAL DEEP ARCHITECTURES (MDA)
In this section, we firstly introduce a novel framework of deep architectures, then we introduce marginal Fisher analysis (MFA) and the proposed marginal deep architectures (MDA) in detail. In addition, we also present some deep learning tricks that we used in the MDA model, including back propagation, denoising and dropout.
# 3.1 A NOVEL FRAMEWORK OF DEEP ARCHITECTURES
The feature learning problem is generally formulated as follow. Given $n$ data, $\{ \mathbf { x } _ { 1 } ^ { T } , \hdots , \mathbf { x } _ { n } ^ { T } \} \in \Re ^ { D }$ , where $D$ is the dimensionality of the data space, we seeks the compact representations of these data, i.e., $\{ \mathbf { y } _ { 1 } ^ { T } , \ldots , \mathbf { y } _ { n } ^ { T } \} \in \Re ^ { d }$ , where $d$ is the dimensionality of the low dimensional embeddings.
In order to improve the accuracy of shallow feature learning models, we use stacked feature learning models to construct the deep architectures (Zheng et al., 2014; 2015), which is a general framework for different applications. In this case, the mapping of data from the original $D$ -dimensional space to the resulted $d$ -dimensional space can be described as
$$D \Longrightarrow D _ { 1 } \Longrightarrow \cdots \Longrightarrow D _ { i } \Longrightarrow \cdots \Longrightarrow D _ { p - 1 } \Longrightarrow d ,$$
where $D _ { 1 }$ is the first higher dimensional space, the number of the node is twice or quadruple as the input layer. $D _ { i }$ represents the dimensionality of the $i$ -th intermediate representation space, and $p$ is the total steps of mappings. Here, we can use different feature learning models for the learning of each layer. As the feature learning models are optimized layer by layer, we can obtain the mapping functions between successive layers. The first hidden layer is random by $\mathbf { W } _ { r 1 }$ , and the representation is,
$$\mathbf { a } ^ { 1 } = g ( \mathbf { W } _ { r _ { 1 } } ^ { T } \mathbf { x } + \mathbf { b } )$$
where, $g ( . )$ is a non-linear activation or transfer function. Then, we can use some feature learning models to initialize the next layers. The representations of next hidden layers are,
$$\mathbf { a } ^ { k } = g ( \mathbf { W } _ { F _ { k - 1 } } ^ { T } \mathbf { a } ^ { k - 1 } + \mathbf { b } )$$
where, $\mathbf { W } _ { F _ { k - 1 } }$ is the weight matrix of the $k - 1$ th layer learned from feature learning models.
# 3.2 MARGINAL FISHER ANALYSIS (MFA)
Based on our novel framework of deep architecture, we introduce Marginal Fisher Analysis (MFA) to build MDA. Here, many traditional feature learning models, such as linear discriminant analysis (LDA), can be used as building blocks of MDA. Take LDA as an example. It assumes that the data of each class follow a Gaussian distribution. However, this assumption is not often satisfied in the real world. Without this assumption, LDA can not work well to separate the data with nonlinear structure. Alternatively, MFA can solve this problem effectively. Hence, considering the learning capability, we choose MFA as the build blocks of MDA in our work. MFA used the graph embedding framework to set up an intrinsic graph that characterizes the intraclass compactness and another penalty graph which characterizes the interclass separability. The marginal Fisher criterion is defined as
$$\mathbf { W } ^ { * } = \operatorname * { a r g m i n } _ { \mathbf { W } } \frac { \operatorname { t r } ( \mathbf { W } ^ { T } \mathbf { X } ( \mathbf { D } - \mathbf { A } ) \mathbf { X } ^ { T } \mathbf { W } ) } { \operatorname { t r } ( \mathbf { W } ^ { T } \mathbf { X } ( \mathbf { D } ^ { p } - \mathbf { A } ^ { p } ) \mathbf { X } ^ { T } \mathbf { W } ) }$$
where $\mathbf { D }$ and $\mathbf { D } ^ { p }$ are diagonal matrices with elements $\begin{array} { r } { \mathbf { D } _ { i i } = \sum _ { j } \mathbf { A } _ { i j } } \end{array}$ , and $\begin{array} { r } { \mathbf { D } _ { i j } ^ { p } = \sum _ { j } \mathbf { A } _ { i j } ^ { p } } \end{array}$ , respectively. Then we can learn the projection matrix to multiply PCA’s projection and marginal Fisher projection,
$$\mathbf { W } _ { M F A } = \mathbf { W } _ { P C A } \mathbf { W } ^ { * }$$
# 3.3 MARGINAL DEEP ARCHITECTURES (MDA)
In order to combine the advantages of MFA and proposed deep architectures, we propose the marginal deep architectures (or MDA). The MDA inherited from the proposed novel framework of deep architectures is shown in Fig. 1. As an input vector $\mathbf { x } \in [ 0 , 1 \bar { ] } ^ { d }$ , we first map it to higher dimensional space by a random weight matrix $\mathbf { W } _ { r 1 }$ . The representation of first hidden layer is computed as
$$\mathbf { a } ^ { 1 } = s ( \mathbf { W } _ { r _ { 1 } } ^ { T } \mathbf { x } + \mathbf { b } )$$
where, $s ( . )$ is the sigmoid function $\begin{array} { r } { s ( x ) = \frac { 1 } { 1 + e ^ { - x } } } \end{array}$ , $\mathbf { b }$ is the bias terms, $\mathbf { a } ^ { 1 }$ is the output of first layer. From second layer to $( n - 1 )$ -th layer, we use the weight matrices learned from MFA to map layer by layer.
$$\mathbf { a } ^ { k } = s ( \mathbf { W } _ { M F A _ { k - 1 } } ^ { T } \mathbf { a } ^ { k - 1 } + \mathbf { b } )$$
The last layer is a softmax regression layer and the number of neuron is the number of category. The cost function is defined as,
$$J ( \mathbf { w } ) = - \frac { 1 } { N } ( \sum _ { i = 1 } ^ { N } \sum _ { j = 1 } ^ { K } \mathbf { I } ( y _ { i } = j ) \log \frac { \exp ( \mathbf { w } _ { j } ^ { T } \mathbf { a } _ { i } ^ { n - 1 } ) } { \sum _ { l = 1 } ^ { K } \exp ( \mathbf { w } _ { l } ^ { T } \mathbf { a } _ { i } ^ { n - 1 } ) } )$$
where, $\mathbf { I } ( x )$ is the indicator function, $\mathbf { I } ( x ) = 1$ if $x$ is true, else $\mathbf { I } ( x ) = 0$ . $y _ { i }$ is the label corresponding to $\mathbf { x } _ { i }$ . Then the probability that $\mathbf { x } _ { i }$ is classified to $j$ is,
$$p ( y _ { i } = j | \mathbf { x } _ { i } , \mathbf { w } ) = \frac { \exp ( \mathbf { w } _ { j } ^ { T } \mathbf { a } _ { i } ^ { n - 1 } ) } { \sum _ { l = 1 } ^ { K } \exp ( \mathbf { w } _ { l } ^ { T } \mathbf { a } _ { i } ^ { n - 1 } ) }$$
Taking derivatives, one can show that the gradient is,
$$\nabla J ( \mathbf { w } ) = - \frac { 1 } { N } \sum _ { i = 1 } ^ { N } [ \mathbf { x } _ { i } ( \mathbf { I } ( y _ { i } = j ) - p ( y _ { i } = j | \mathbf { x } _ { i } , \mathbf { w } ) ]$$
If the $n { - } 1$ layer’s neurons are more than the last layer, we can continue using MFA to map it. On the contrary, If the $n - 1$ layer’s neurons are less than last layer, we can randomly initialize the weight matrix between this two layers. Next, in order to improve the MDA, we introduce back propagation, denoising and dropout operation.
# 3.4 BACK PROPAGATION
In order to adjust the network, we use back propagation (Rumelhart et al., 1986) to compute partial derivative and stochastic gradient descent to update the weight matrixes and the bias terms. For each node $i$ in output layer $n$ -th layer), we compute an error term as
$$\delta _ { i } ^ { n } = \nabla J ( \mathbf { w } )$$
where, $J ( \mathbf { w } )$ is the cost function computed from Equ.8 and $\nabla J ( \mathbf { w } )$ computed from Equ.10. For each node $i$ in $( n - 1 )$ -th to second layer, the error term is computed as,
$$\delta _ { i } ^ { k } = ( \sum _ { j = 1 } ^ { k + 1 } w _ { j i } ^ { k } \delta _ { j } ^ { k + 1 } ) s ^ { \prime } ( z _ { i } ^ { k } )$$
The back propagation procedure relies on computing the gradient of an objective function with respect to the weights of a multilayer stacked modules. It starting from the output at the top and end to the input at the bottom.
# 3.5 DENOISING OPERATION
Vincent et al. proposed the denoising autoencoder to improve the robustness of autoencoder (Vincent et al., 2008). It’s very similar with the regularization methods and avoids the “overfitting” problem. The basic idea is to corrupt partial input data by the desired proportion of $\nu$ “destruction”. for each input $\mathbf { x }$ , a fixed number $\nu d$ of components are chosen at random, and their value is forced to 0, while the others are left untouched. The initial input $\mathbf { x }$ to get a partially destroyed version $\tilde { \mathbf { x } }$ by means of a stochastic mapping,
$$\tilde { \mathbf { x } } \sim q _ { D } ( \tilde { \mathbf { x } } | \mathbf { x } )$$
where, $q _ { D } ( \tilde { \mathbf { x } } | \mathbf { x } )$ is the unknown distribution. Then, for a hidden representation $\mathbf { h }$ ,
$$\mathbf { h } = s ( \mathbf { W } ^ { T } \widetilde { \mathbf { x } } + \mathbf { b } )$$
In our MDA, we use this idea to improve the network, please refer to Fig. 1 to find clear sight. For the input layer, the output of first hidden layer is represented as,
$$\mathbf { a } ^ { 2 } = s ( \mathbf { W } _ { r _ { 1 } } ^ { T } \tilde { \mathbf { x } } + \mathbf { b } _ { 1 } )$$
where, $\mathbf { W } _ { r _ { 1 } }$ is the first layer random weight matrix, $\mathbf { b } _ { 1 }$ is the bias term of first layer. The “denoising” operation is established to a hypothetical additional specific criterion: robustness to partial destruction of the input, which means a good intermediate representation is learned from unknown distribution of its observed input. This operation helps for learning more stable structure and avoids the overfitting problem in most cases.
# 3.6 DROPOUT
As the same reason with denoising operation, dropout is a trick to prevent overfitting (Hinton et al., 2012b). When a large feedforward neural network is trained on a small training set, dropout performed well on test set. In order to prevent the complex co-adaptations on the training data, the basic idea of dropout is that each hidden node is randomly omitted from the network with a probability of $\beta$ , so a hidden node can’t rely on other hidden node. In another view, dropout is as a very efficient way of performing model averaging with neural networks. On test set, we train many separate networks and then to apply each of these networks to the test data. Dropout operation can save the train time and then we average the predictions produced by a very large number of different networks. Fig. 1 shows the dropout operation in our MDA.
# 4 EXPERIMENTS
# 4.1 DATESET DESCRIPTIONS
We evaluate the performance of MDA on five benchmark data sets. The detail of the data is showed in Tab 1. The USPS 1 data set is a handwritten digits image data set includes 7291 training samples and 2007 test samples from 10 classes with 256 dimensional features. This task is to recognize the digits 0 to 9. The Isolet 2 data set is a collection of audio feature vectors of spoken letters from the English alphabet. It includes 6238 training samples and 1559 test samples from 26 classes with 614 dimensional features. The task is to identify which letter is spoken based on the recorded (and pre-processed) audio signal. Sensor 3 is a sensorless drive diagnosis data set includes 46816 training samples and 11693 test samples from 11 classes with 48 dimensional features. The features are extracted from electric current drive signals. The task is to classify 11 different classes with different conditions of the drive which has intact and defective components. Covertype 4 contains geological and map-based data from four wilderness areas located in the Roosevelt National Forest of northern Colorado. It includes 15120 training samples and 565892 test samples from 7 classes with 54 dimensional features. The task is to identify forest cover type from cartographic variables. For the IbnSina 5 ancient Arabic document data set, we use 50 pages of the manuscript for training (17543 training samples) and 10 pages for testing (3125 test samples). The data samples belong to 174 classes of subwords and are of dimensionality 200.
Table 1: Characteristics of datasets used in evaluation.
<table><tr><td colspan="6">DATASETSTATISTICS</td></tr><tr><td>dataset</td><td>n</td><td>train</td><td>test</td><td>[V</td><td>d(target)</td></tr><tr><td>USPS</td><td>9298</td><td>7291</td><td>2007</td><td>10</td><td>256(32)</td></tr><tr><td>Isolet</td><td>7797</td><td>6238</td><td>1559</td><td>26</td><td>614(308)</td></tr><tr><td>Sensor</td><td>58509</td><td>46816</td><td>11693</td><td>11</td><td>48(24)</td></tr><tr><td>Covertype</td><td>581012</td><td>15120</td><td>565892</td><td>7</td><td>54(27)</td></tr><tr><td>Ibnsina</td><td>20668</td><td>17543</td><td>3125</td><td>174</td><td>200(100)</td></tr><tr><td>CIFAR-10</td><td>60000</td><td>50000</td><td>10000</td><td>10</td><td>3072(64)</td></tr><tr><td>CMU</td><td>49</td><td>44</td><td>5</td><td>3</td><td>93(24)</td></tr></table>
In addition, we also use a large scale dataset CIFAR-10 6 to test our MDA on large scale applications. The CIFAR-10 dataset consists of $6 0 0 0 0 3 2 \times 3 2$ colour images in 10 classes, with 6000 images per class. There are 50000 training images and 10000 test images. We also test our MDA on a specific task which use the CMU motion capture (CMU mocap) data set 7. The CMU mocap data set includes three categories, namely, jumping, running and walking. We choose 49 video sequences from four subjects. For each sequence, the features are generated using Lawrences method 8, with dimensionality 93 (Zhong et al., 2010). By reason of the few samples of CMU, we adopt 10-fold cross-validation in our experiments and use the average error rate and standard deviation to evaluate the performance.
# 4.2 CLASSIFICATION ON FIVE BENCHMARK DATA SETS
# 4.2.1 BASELINE METHODS
In order to evaluate the performance of MDA, we compared our MDA with 5 deep learning models include autoencoder (AE) (Hinton & Salakhutdinov, 2006), stacked autoencoders, denoising autoencoders (Vincent et al., 2008), stacked denoising autoencoders (Vincent et al., 2010) and stacked denoising autoencoders with dropout, 2 feature learning models, MFA (Zhong et al., 2013; Yan et al., 2007) and PCA (Jolliffe, 2002), PCA deep architecture base on our uniform framework and the classification accuracy on original space.
# 4.2.2 EXPERIMENTAL SETTINGS
All of the deep learning methods have the same settings. The size of minibatch was set to 100, the learning rate and momentum were the default value 1 and 0.5, the number of epoch was set to 400, the dropout rate and denoising rate $\nu$ were set to 0.1. For the AE and SAE, weight penalty of the $L 2$ norm was set to $1 0 ^ { - 4 }$ . For MFA, the number of nearest neighbors for constructing the intrinsic graph was set to 5, while that for constructing the penalty graph was set to 20. The target spaces of MFA and PCA on different data sets were showed in Tab 1. For the USPS data set, The architecture was set to $2 5 6 - 5 1 2 - 2 5 6 - 1 2 8 - 6 4 - 3 2$ . For the Isolet data set ,the architecture was set to $6 1 7 - 1 3 2 4 - 6 1 7 - 3 0 8$ . For the Sensor data set, the architecture was set to $4 8 - 9 6 - 4 8 - 2 4$ .
Table 2: The classification accuracy on different datasets. “ORIG” represents the results obtained in the original data space. ‘PDA’ represents the PCA deep architecture. ‘MDA’ represents the MFA deep architecture. The best reslut is highlighted with boldface.
<table><tr><td>Method</td><td>ORIG</td><td>PCA</td><td>MFA</td><td>AE</td><td>SAE</td><td>DAE(dropout)</td><td>DAE</td><td>SDAE</td><td>PDA</td><td>MDA</td></tr><tr><td>USPS</td><td>0.8366</td><td>0.9402</td><td>0.9392</td><td>0.9402</td><td>0.9402</td><td>0.9581</td><td>0.9532</td><td>0.9452</td><td>0.9586</td><td>0.9601</td></tr><tr><td>Isolet</td><td>0.9467</td><td>0.9237</td><td>0.9269</td><td>0.9519</td><td>0.9506</td><td>0.9596</td><td>0.9519</td><td>0.9543</td><td>0.9584</td><td>0.9622</td></tr><tr><td>Sensor</td><td>0.8151</td><td>0.8042</td><td>0.8234</td><td>0.7995</td><td>0.8325</td><td>0.8178</td><td>0.7764</td><td>0.7870</td><td>0.8582</td><td>0.8558</td></tr><tr><td>Covertype</td><td>0.5576</td><td>0.5596</td><td>0.6057</td><td>0.7405</td><td>0.5576</td><td>0.7093</td><td>0.7397</td><td>0.7440</td><td>0.7458</td><td>0.7589</td></tr><tr><td>Ibnsina</td><td>0.8957</td><td>0.9190</td><td>0.9206</td><td>0.9363</td><td>0.9184</td><td>0.9402</td><td>0.9370</td><td>0.9261</td><td>0.9421</td><td>0.9491</td></tr></table>
Table 3: The structures on 5 data sets. “None” represents without second layer in MDA. “Twice” means the second layer’s nodes are as twice as the input layer. “Quadruple” represents the second layer’s nodes are as quadruple as the input layer. “Octuple” represents the second layer’s nodes are as octuple as the input layer.
<table><tr><td>Dataset</td><td>None</td><td>Twice</td><td>Quadruple</td><td>Octuple</td></tr><tr><td>USPS</td><td>256-128-64-32</td><td>256-512-256-128-64-32</td><td>256-1024-512-256-128-64-32</td><td>256-2048-1024-512-256-128-64-32</td></tr><tr><td>Isolet</td><td>617-308</td><td>617-1324-617-308</td><td>617-2648-1324-617-308</td><td>617-5296-2648-1324-617-308</td></tr><tr><td>Sensor</td><td>48-24</td><td>48-96-24</td><td>48-192-96-24</td><td>48-384-192-96-24</td></tr><tr><td>Covertype</td><td>54-27</td><td>54-108-27</td><td>54-216-108-54-27</td><td>54-432-216-108-54-27</td></tr><tr><td>Ibnsina</td><td>200-100</td><td>200-400-200-100</td><td>200-800-400-200-100</td><td>200-1600-800-400-200-100</td></tr></table>
For the Covertype data set, we set the architecture to $5 4 - 2 1 6 - 1 0 8 - 5 4 - 2 7$ . Finally, for Ibnsina data set, the architecture was set to $2 0 0 - 4 0 0 - 2 0 0 - 1 0 0$ .
# 4.2.3 CLASSIFICATION RESULTS
The experimental results are shown in Tab. 2. We can see that our MDA achieves the best results on four dataset except the Sensor dataset, but MDA achieves the second best result on Sensor data set and only below the PDA. The PDA achieves the best result on Sensor data set and the second best results on other data sets. These results demonstrate that our uniform deep architectures achieve the good performance in most case. In addition, MDA not only outperform the traditional deep learning models, but also the shallow feature learning models. It shows that our deep architectures based on stacked some feature learning models can learn the better feature than shallow feature learning models.
# 4.3 EVALUATION
# 4.3.1 DIFFERENT STRUCTURES FOR MDA
In order to evaluate the desired structures of MDA, we changed the node’s number of the second layer. For USPS data set, we get rid of the second layer and the architecture was $2 5 6 - 1 2 8 - 6 4 - 3 2$ . Then, we set the number of node of the second layer was as twice as the input layer, the architecture was $2 5 6 - 1 2 8 - 6 4 - 3 2$ . Next, the number of node was as quadruple as the input layer, the architecture was $2 5 6 - 1 0 2 4 - 5 1 2 - 2 5 6 - 1 2 8 - 6 4 - 3 2$ . Finally, the node’s number is as octuple as the input layer, the architecture was $2 5 6 \mathrm { ~ - ~ } 2 0 4 8 \mathrm { ~ - ~ } 1 0 2 4 \mathrm { ~ - ~ } 5 1 2 \mathrm { ~ - ~ } 2 5 6 \mathrm { ~ - ~ } 1 2 8 \mathrm { ~ - ~ } 6 4 \mathrm { ~ - ~ } 3 2$ . The structures of other data sets are shown in Tab. 3.
The experimental results are shown in Tab. 4. When the the number of nodes of the second layer is as twice as the input layer, MDA achieved the minimum classification error on all data sets except the Covertype data set. When the number of nodes of the second layer is as quadruple as the input layer, MDA get the worst result on Covertype data set. We can conclude that MDA can work well when the number of nodes of the second layer is as twice or quadruple as the input layer.
Table 4: The classification error with different structures on 5 data sets. The best results (minimum error) are highlighted with boldface.
<table><tr><td>Dataset</td><td>None</td><td>Twice</td><td>Quadruple</td><td>Octuple</td></tr><tr><td>USPS</td><td>0.0463</td><td>0.0399</td><td>0.0433</td><td>0.0453</td></tr><tr><td>Isolet</td><td>0.0398</td><td>0.0378</td><td>0.0417</td><td>0.0430</td></tr><tr><td>Sensor</td><td>0.2172</td><td>0.1442</td><td>0.1559</td><td>0.7856</td></tr><tr><td>Covertype</td><td>0.3876</td><td>0.3878</td><td>0.2411</td><td>0.3806</td></tr><tr><td>Ibnsina</td><td>0.0643</td><td>0.0509</td><td>0.0614</td><td>0.0858</td></tr></table>
Table 5: The classification error on 5 datasets with different number of hidden layers.
<table><tr><td>The number of hidden layers</td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td></tr><tr><td>USPS</td><td>0.05780</td><td>0.05032</td><td>0.05082</td><td>0.05182</td><td>0.03990</td><td>0.05730</td><td>0.05132</td></tr><tr><td>Isolet</td><td>0.03977</td><td>0.04169</td><td>0.03785</td><td>0.03849</td><td>0.05452</td><td>0.04234</td><td>0.04683</td></tr><tr><td>Covertype</td><td>0.27171</td><td>0.25601</td><td>0.24110</td><td>0.26731</td><td>0.27491</td><td></td><td></td></tr><tr><td>Sensor</td><td>0.20457</td><td>0.15522</td><td>0.14420</td><td>0.17027</td><td>0.15567</td><td></td><td></td></tr><tr><td>Ibnsina</td><td>0.05696</td><td>0.05184</td><td>0.05088</td><td>0.06016</td><td>0.06720</td><td></td><td></td></tr></table>
Table 6: The classification error on gray-CIFAR10 and CMU mocap data sets.
<table><tr><td colspan="2">(a)gray-CIFAR10</td><td colspan="2">(b) CMU mocap</td></tr><tr><td>Method</td><td>Error</td><td>Method</td><td>Error</td></tr><tr><td>AE</td><td>0.5117</td><td>AE</td><td>0.3970±0.1343</td></tr><tr><td>SAE</td><td>0.5252</td><td>SAE</td><td>0.4106 ± 0.1648</td></tr><tr><td>DAE(dropout)</td><td>0.5090</td><td>DAE(dropout)</td><td>0.3970±0.1343</td></tr><tr><td>DAE</td><td>0.5176</td><td>DAE</td><td>0.4061 ± 0.1540</td></tr><tr><td>SDAE</td><td>0.5113</td><td>SDAE</td><td>0.3970 ± 0.1343</td></tr><tr><td>PDA</td><td>0.5085</td><td>PDA</td><td>0.3591 ± 0.0815</td></tr><tr><td>MDA</td><td>0.4947</td><td>MDA</td><td>0.3636 ± 0.0958</td></tr></table>
# 4.3.2 DIFFERENT NUMBER OF HIDDEN LAYERS FOR MDA
In order to evaluate how many hidden layers adapt to different datasets, we designed some experiments which have different number of hidden layers. We used $1 \sim 7$ hidden layers on USPS and Isolet datasets and $1 \sim 5$ hidden layers on Covertype, Sensor and Ibnsina datasets. The experimental settings were same as previous experiments.
Tab. 5 shows the classification error on 5 datasets with different hidden layers. All the datasets achieved the best results when hidden layer’s number is 3 except USPS dataset. The USPS dataset achieved the best result when hidden layer’s number is 5. As $1 \sim 3$ hidden layers, with the increase of the number of layers, the classification error is decreasing on all datasets. As small and middle scale applications, we don’t need very deep architectures to handle it. As large scale applications, we can design deeper architectures to achieve better performance.
# 4.4 CLASSIFICATION ON LARGE SCALE DATASET CIFAR-10
The previous section introduced the advantages of MDA on small and middle scale applications. In order to evaluate the universality of MDA, we chose a relatively large scale dataset CIFAR-10 to test the performance of MDA.
In our experiments, we first transformed the color images to gray images in order to reduce the dimensionality of input. Then we took one sample as a 1024 dimensional vector which is the input of our MDA. So, we can call this data set gray-CIFAR10. The architecture was set to $1 0 2 4 - 2 0 4 8 -$ $1 0 2 4 - 5 1 2 - 2 5 6 - 1 2 8 - 6 4 .$ the minibatch’s size was set to 100, the dropout ratio and denoising ratio were set to 0.1, the number of epoch was set to 400, the learning rate was set to 1, the momentum was set to 0.5. We compared our MDA with previous 6 methods.
Table. 6(a) shows the classification error on gray-CIFAR10, we can see that PDA and MDA achieved the best results in these 7 methods. However, all of the methods on this framework didn’t perform well because we use the gray operation.
# 4.5 CLASSIFICATION ON CMU MOCAP DATA SET
CMU mocap data set is a very small dataset that only has 49 samples. Traditional deep learning methods didn’t work well in these kind of applications. We test our MDA and PDA and compared them with other 5 deep learning models. The architectures for all deep models (except the PDA) were set to $9 3 - 1 8 6 - 9 3 - 4 7 - 2 4$ . Specially, since the CMU mocap data set only has 49 samples, the PCA method only reduce the dimensionality to 49 at most, so the architecture of PDA was set to
$9 3 - 1 8 6 - 2 4 $ . The denoising ratio and dropout ratio were set to 0.1 on DAE, DAE with dropout, SDAE, SAE, PDA and MDA. The weight penalty on AE was set to $1 0 ^ { - 4 }$ . The learning rate was set to 0.01, the momentum was set to 0.5 and the number of epoch is set to 600. The experiment was test on 10-fold cross validation. The experimental results are shown in Tab. 6(b).
In Tab. 6(b), our PDA and MDA achieved the best results in this dataset and have lower standard deviation than other deep learning models. It demonstrates that our PDA and MDA are more stable than other deep learning models. The traditional autoencoder, SDAE, DAE with dropout achieved the same result in this dataset and better than SAE and DAE.
# 5 CONCLUSION
In this paper, we proposed a novel deep learning framework that based on stacked some feature learning models to handle small or middle data sets. Then we introduce MFA in this framework, called MDA. The deep learning tricks like backpropagation, denoising and dropout operation are applied on MDA to improve its performance. Extensive experiments on 7 different type data sets demonstrate that MDA performs not only better than shallow feature learning models, but also stateof-the-art deep learning models on small and middle scale applications. The evaluation of MDA show that how to adjust the parameters make the MDA work well. For future work, we plan to try other feature learning models and explore the different structures for this novel deep learning model. In addition, we plan to explore new deep architectures based on this framework to handle the large scale datasets.
# REFERENCES
T.-H. Chan, K. Jia, S. Gao, J. Lu, Z. Zeng, and Y. Ma. PCANet: A simple deep learning baseline for image classification? arXiv preprint arXiv:1404.3606, 2014. D. C. Ciresan, U. Meier, L. M. Gambardella, and J. Schmidhuber. Deep, big, simple neural nets for handwritten digit recognition. Neural computation, 22(12):3207–3220, 2010. R. Collobert and J. Weston. A unified architecture for natural language processing: Deep neural networks with multitask learning. In ICML, pp. 160–167, 2008. J. Donahue, Y. Jia, O. Vinyals, J. Hoffman, N. Zhang, E. Tzeng, and T. Darrell. Decaf: A deep convolutional activation feature for generic visual recognition. arXiv preprint arXiv:1310.1531, 2013. R. A. Fisher. The use of multiple measurements in taxonomic problems. Annals of eugenics, 7(2): 179–188, 1936. T. George, B. Konstantinos, Z. Stefanos, and Bjorn W. Schuller. A Deep Semi-NMF Model for ¨ Learning Hidden Representations. In ICML, pp. 1692–1700, 2014. G. Hinton and R. Salakhutdinov. Reducing the Dimensionality of Data with Neural Networks. Science, 313(5786):504–507, 2006. G. Hinton, L. Deng, D. Yu, G. E. Dahl, A. r. Mohamed, N. Jaitly, A. Senior, V. Vanhoucke, P. Nguyen, T. N. Sainath, et al. Deep neural networks for acoustic modeling in speech recognition: The shared views of four research groups. Signal Processing Magazine, IEEE, 29(6):82–97, 2012a. G. E. Hinton and S. T. Roweis. Stochastic neighbor embedding. In NIPS, pp. 833–840, 2002. G. E. Hinton, N. Srivastava, A. Krizhevsky, I. Sutskever, and R. R. Salakhutdinov. Improving neural networks by preventing co-adaptation of feature detectors. arXiv preprint arXiv:1207.0580, 2012b. I. Jolliffe. Principal component analysis. 2002. A. Krizhevsky, I. Sutskever, and G. E. Hinton. Imagenet classification with deep convolutional neural networks. In NIPS, pp. 1097–1105, 2012. Y. l. Boureau and Y.L. Cunand others. Sparse feature learning for deep belief networks. In NIPS, pp. 1185–1192, 2008. Q. V. Le, W. Y. Zou, S. Y. Yeung, and A. Y. Ng. Learning hierarchical invariant spatio-temporal features for action recognition with independent subspace analysis. In CVPR, pp. 3361–3368, 2011. Y. LeCun, Y. Bengio, and G. Hinton. Deep learning. Nature, pp. 436–444, 2015. H. Lee, R. Grosse, R. Ranganath, and A. Y. Ng. Convolutional deep belief networks for scalable unsupervised learning of hierarchical representations. In ICML, pp. 609–616, 2009a. H. Lee, P. Pham, Y. Largman, and A. Y. Ng. Unsupervised feature learning for audio classification using convolutional deep belief networks. In NIPS, pp. 1096–1104, 2009b. M. Long, Y. Cao, J. Wang, and M. Jordan. Learning Transferable Features with Deep Adaptation Networks. In ICML, pp. 97–105, 2015. J. Ngiam, A. Khosla, M. Kim, J. Nam, H. Lee, and A. Y. Ng. Multimodal deep learning. In ICML, pp. 689–696, 2011. X. Niyogi. Locality preserving projections. In NIPS, volume 16, pp. 153, 2004. D. E Rumelhart, G. E. Hinton, and R. G. Williams. Learning representations by back-propagating errors. Nature, pp. 323–533, 1986. I. Sutskever, O. Vinyals, and Q. V. Le. Sequence to sequence learning with neural networks. In NIPS, pp. 3104–3112, 2014. L. J. van der Maaten. An introduction to dimensionality reduction using matlab. Report, 1201 (07-07):62, 2007. L. J. van der Maaten, E. O. Postma, and H. J. van den Herik. Dimensionality reduction: A comparative review. The Journal of Machine Learning Research, 10(1-41):66–71, 2009. P. Vincent, H. Larochelle, Y. Bengio, and P.-A. Manzagol. Extracting and composing robust features with denoising autoencoders. In ICML, pp. 1096–1103, 2008. P. Vincent, H. Larochelle, I. Lajoie, Y. Bengio, and P.-A. Manzagol. Stacked denoising autoencoders: Learning useful representations in a deep network with a local denoising criterion. The Journal of Machine Learning Research, 11:3371–3408, 2010. H. Y. Xiong, B. Alipanahi, L. J. Lee, H. Bretschneider, D. Merico, R. K. Yuen, Y. Hua, S. Gueroussov, H. S. Najafabadi, T. R. Hughes, et al. The human splicing code reveals new insights into the genetic determinants of disease. Science, 347(6218):1254806, 2015. S. Yan, D. Xu, B. Zhang, H.-J. Zhang, Q. Yang, and S. Lin. Graph Embedding and Extensions: A General Framework for Dimensionality Reduction. Pattern Analysis and Machine Intelligence, IEEE Transactions on, 29(1):40–51, 2007. Y. Yuan, L. Mou, and X. Lu. Scene recognition by manifold regularized deep learning architecture. Neural Networks and Learning System, IEEE Transactions on. Y. Zheng, G. Zhong, J. Liu, X. Cai, and J. Dong. Visual Texture Perception with Feature Learning Models and Deep Architectures. In CCPR, pp. 401–410. 2014. Y. Zheng, Y. Cai, G. Zhong, Y. Chherawala, Y. Shi, and J. Dong. Stretching Deep Architectures for Text Recognition. In ICDAR, pp. 236–240, 2015. G. Zhong, W.-J. Li, D.-Y. Yeung, X. Hou, and C.-L. Liu. Gaussian Process Latent Random Field. In AAAI, 2010. G. Zhong, Y. Chherawala, and M. Cheriet. An Empirical Evaluation of Supervised Dimensionality Reduction for Recognition. In ICDAR, pp. 1315–1319, 2013. B. Zhou, A. Lapedriza, J. Xiao, A. Torralba, and A. Oliva. Learning deep features for scene recognition using places database. In NIPS, pp. 487–495, 2014.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335# Habitat 2.0: Training Home Assistants to Rearrange their Habitat
Andrew Szot2, ⇤ Alex Clegg1, Eric Undersander1, Erik Wijmans1,2, Yili Zhao1, John Turner1, Noah Maestre1, Mustafa Mukadam1, Devendra Chaplot1, Oleksandr Maksymets1, Aaron Gokaslan1, Vladimir Vondrus, Sameer Dharur2, Franziska Meier1, Wojciech Galuba1, Angel Chang4, Zsolt ${ \bf K i r a } ^ { 2 }$ , Vladlen Koltun3, Jitendra Malik1,5, Manolis Savva4, Dhruv Batra1,2 1Facebook AI Research, 2Georgia Tech, 3Intel Research, 4Simon Fraser University 5UC Berkeley
# Abstract
We introduce Habitat 2.0 (H2.0), a simulation platform for training virtual robots in interactive 3D environments and complex physics-enabled scenarios. We make comprehensive contributions to all levels of the embodied AI stack – data, simulation, and benchmark tasks. Specifically, we present: (i) ReplicaCAD: an artist-authored, annotated, reconfigurable 3D dataset of apartments (matching real spaces) with articulated objects (e.g. cabinets and drawers that can open/close); (ii) H2.0: a high-performance physics-enabled 3D simulator with speeds exceeding 25,000 simulation steps per second $\mathbf { 8 5 0 } \times$ real-time) on an 8-GPU node, representing $1 0 0 \times$ speed-ups over prior work; and, (iii) Home Assistant Benchmark (HAB): a suite of common tasks for assistive robots (tidy the house, stock groceries, set the table) that test a range of mobile manipulation capabilities. These large-scale engineering contributions allow us to systematically compare deep reinforcement learning (RL) at scale and classical sense-plan-act (SPA) pipelines in long-horizon structured tasks, with an emphasis on generalization to new objects, receptacles, and layouts. We find that (1) flat RL policies struggle on HAB compared to hierarchical ones; (2) a hierarchy with independent skills suffers from ‘hand-off problems’, and (3) SPA pipelines are more brittle than RL policies.
 Figure 1: A mobile manipulator (Fetch robot) simulated in Habitat 2.0 performing rearrangement tasks in a ReplicaCAD apartment – (left) opening a drawer before picking up an item from it, and (right) placing an object into the bowl after navigating to the table. Best viewed in motion at https://aihabitat.org/docs/habitat2.
# 1 Introduction
Consider a home assistant robot illustrated in Fig. 1 – a mobile manipulator (Fetch [1]) performing tasks like stocking groceries into the fridge, clearing the table and putting dishes into the dishwasher, fetching objects on command and putting them back, etc. Developing such embodied intelligent systems is a goal of deep scientific and societal value. So how should we accomplish this goal?
Training and testing such robots in hardware directly is slow, expensive, and difficult to reproduce. We aim to advance the entire ‘research stack’ for developing such embodied agents in simulation – (1) data: curating house-scale interactive 3D assets (e.g. kitchens with cabinets, drawers, fridges that can open/close) that support studying generalization to unseen objects, receptacles, and home layouts, (2) simulation: developing the next generation of high-performance photo-realistic 3D simulators that support rich interactive environments, (3) tasks: setting up challenging representative benchmarks to enable reproducible comparisons and systematic tracking of progress over the years. To support this long-term research agenda, we present:
• ReplicaCAD: an artist-authored fully-interactive recreation of ‘FRL-apartment’ spaces from the Replica dataset [2] consisting of 111 unique layouts of a single apartment background with 92 authored objects including dynamic parameters, semantic class and surface annotations, and efficient collision proxies, representing $9 0 0 +$ person-hours of professional 3D artist effort. ReplicaCAD (illustrated in figures and videos) was created with the consent of and compensation to artists, and will be shared under a Creative Commons license for non-commercial use with attribution (CC-BY-NC).
• Habitat 2.0 (H2.0): a high-performance physics-enabled 3D simulator, representing approximately 2 years of development effort and the next generation of the Habitat project [3] (Habitat 1. 0). H2.0 supports piecewise-rigid objects (e.g. door, cabinets, and drawers that can rotate about an axis or slide), articulated robots (e.g. mobile manipulators like Fetch [1], fixed-base arms like Franka [4], quadrupeds like AlienGo [5]), and rigid-body mechanics (kinematics and dynamics). The design philosophy of $\mathrm { H } 2 . 0$ is to prioritize performance (or speed) over the breadth of simulation capabilities. $\mathrm { H } 2 . 0$ by design and choice does not support non-rigid dynamics (deformables, fluids, films, cloths, ropes), physical state transformations (cutting, drilling, welding, melting), audio or tactile sensing – many of which are capabilities provided by other simulators [6–8]. The benefit of this focus is that we were able to design and optimize $\mathrm { H } 2 . 0$ to be exceedingly fast – simulating a Fetch robot interacting in ReplicaCAD scenes at 1200 steps per second (SPS), where each ‘step’ involves rendering 1 RGBD observation ( $1 2 8 \times 1 2 8$ pixels) and simulating rigid-body dynamics for $^ { 1 / 3 0 }$ sec. Thus, 30 SPS would be considered ‘real time’ and $1 2 0 0 \mathrm { S P S }$ is $4 0 \times$ real-time. $\mathrm { H } 2 . 0$ also scales well – achieving 8,200 SPS $2 7 3 \times$ real-time) multi-process on a single GPU and over 25,000 SPS ( $8 5 0 \times$ real-time) on a single node with 8 GPUs. For reference, existing simulators typically achieve 10-400 SPS (see Tab. 1). These $1 0 0 \times$ simulation-speedups correspond to cutting experimentation time from 6 months to under 2 days, unlocking experiments that were hitherto infeasible, allowing us to answer questions that were hitherto unanswerable. As we will show, they also directly translate to training-time speed-up and accuracy improvements from training agents (for object rearrangement tasks) on more experience.
• Home Assistant Benchmark (HAB): a suite of common tasks for assistive robots (TidyHouse, PrepareGroceries, SetTable) that are specific instantiations of the generalized rearrangement problem [9]. Specifically, a mobile manipulator (Fetch) is asked to rearrange a list of objects from initial to desired positions – picking/placing objects from receptacles (counter, sink, sofa, table), opening/closing containers (drawers, fridges) as necessary. We use the GeometricGoal specification prescribed by Batra et al. [9] – i.e., initial and desired 3D (center-of-mass) position of each target object $i$ to be rearranged $\left( s _ { i } ^ { 0 } , s _ { i } ^ { * } \right) _ { i = 1 } ^ { N }$ The choice of GeometricGoal is deliberate – we aim to create the PointNav [10] equivalent for mobile manipulators. As witnessed in the navigation literature, such a task becomes the testbed for exploring ideas [11–19] and a starting point for more semantic tasks [20–22]. The robot operates entirely from onboard sensing – head- and arm-mounted RGB-D cameras, proprioceptive joint-position sensors (for the arm), and egomotion sensors (for the mobile base) – and may not access any privileged state information (no prebuilt maps, no 3D models of rooms or objects, no physically-implausible sensors providing knowledge of mass, friction, articulation of containers, etc.). Notice that an object’s center-of-mass provides no information about its size or orientation. The target object may be located inside a container (drawer, fridge), on top of supporting surfaces (shelf, table, sofa) of varying heights and sizes, and surrounded by clutter; all of which must be sensed and maneuvered. Receptacles like drawers and fridges start closed, meaning that the agent must open and close articulated objects to succeed. An episode is considered successful if all target objects are placed within $\mathrm { 1 5 c m }$ of their desired positions (without considering orientation). The robot uses continuous end-effector control for the arm and velocity control for the base. We deliberately focus on gross motor control (the base and arm) and not fine motor control (the gripper), following
<table><tr><td rowspan="2"></td><td colspan="2">Rendering</td><td colspan="2">Physics</td><td rowspan="2">Scene Complexity</td><td rowspan="2">Speed (steps/sec)</td></tr><tr><td>Library</td><td>Supports</td><td>Library</td><td>Supports</td></tr><tr><td>Habitat [3]</td><td>Magnum</td><td>3D scans</td><td>none</td><td>continuous navigation (navmesh)</td><td>building-scale</td><td>3,000</td></tr><tr><td>AI2-THOR [6]</td><td>Unity</td><td>Unity</td><td>Unity</td><td>rigid dynamics,animated interactions</td><td>room-scale</td><td>30-60</td></tr><tr><td>ManipulaTHOR [33]</td><td>Unity</td><td>Unity</td><td>Unity</td><td>AI2-THOR + manipulation</td><td>room-scale</td><td>30-40</td></tr><tr><td>ThreeDWorld [7]</td><td>Unity</td><td>Unity</td><td>Unity (PhysX) + FLEX</td><td>rigid + particle dynamics</td><td>room/house-scale</td><td>5-168</td></tr><tr><td>SAPIEN [34]</td><td>OpenGL/OptiX</td><td>configurable</td><td>PhysX</td><td>rigid/articulated dynamics</td><td>object-level</td><td>200-400t</td></tr><tr><td>RLBench [35]</td><td>CoppeliaSim (OpenGL)</td><td>Gouraud shading</td><td>CoppeliaSim (Bullet/ODE)</td><td>rigid/articulated dynamics</td><td>table-top</td><td>1-60t</td></tr><tr><td>iGibson [36]</td><td>PyRender</td><td>PBR shading</td><td>PyBullet</td><td>rigid/articulated dynamics</td><td>house-scale</td><td>100</td></tr><tr><td>Habitat 2.0 (H2.0)</td><td>Magnum</td><td>3D scans + PBR shading</td><td>Bullet</td><td>rigid/articulated dynamics + navmesh</td><td>house-scale</td><td>1,200</td></tr></table>
Table 1: High-level comparison of different simulators. Note: Speeds were taken directly from respective publications or obtained via direct personal correspondence with the authors when not publicly available (indicated by †). Benchmarking was conducted by different teams on different hardware with different underlying 3D assets simulating different capabilities. Thus, these should be considered qualitative comparisons representing what a user expects to experience on a single instance of the simulator (no parallelization).
the ‘abstracted grasping’ recommendations from [9]. Specifically, once the end-effector reaches $1 5 \mathrm { c m }$ (or closer) to an object, a discrete grasp action becomes available that, if executed, snaps the object into its parallel-jaw gripper 2. We conduct a systematic study of two distinct techniques – monolithic ‘sensors-to-actions’ policies trained with reinforcement learning (RL) at scale, and classical senseplan-act pipelines (SPA) [26] – with a particular emphasis on systematic generalization to new objects, receptacles, apartment layouts (not just robot starting pose). Our findings include:
1. Flat vs hierarchical: Monolithic RL policies successfully learn diverse individual skills (pick/place, navigate, open/close drawer). However, crafting a combined reward function and learning scheme that elicits chaining of such skills for the long-horizon HAB tasks remained out of our reach. We saw significantly stronger results with a hierarchical approach that assumes knowledge of a perfect task planner (via STRIPS [27]) to break it down into a sequence of skills.
2. Hierarchy cuts both ways: However, a hierarchy with independent skills suffers from ‘hand-off problems’ where a succeeding skill isn’t set up for success by the preceding one – e.g., navigating to a bad location for subsequent manipulation, only partially opening a drawer to grab an object inside, or knocking an object out of reach that is later needed.
3. Brittleness of SensePlanAct: For simple skills, SPA performs just as well as monolithic RL. However, it is significantly more brittle since it needs to map all obstacles in the workspace for planning. More complex settings involving clutter, challenging receptacles, and imperfect navigation can poorly frame the target object and obstacles in the robot’s camera, leading to incorrect plans.
We hope our work will serve as a benchmark for many years to come. $\mathrm { H } 2 . 0$ is free, open-sourced under the MIT license, and under active development. 3 We believe it will reduce the community’s reliance on commercial lock-ins [28, 29] and non-photorealistic simulation engines [30–32].
# 2 Related Work
What is a simulator? Abstractly speaking, a simulator has two components: (1) a physics engine that evolves the world state $s$ over time $s _ { t } \to s _ { t + 1 }$ , and (2) a renderer that generates sensor observations $o$ from states: $s _ { t } \to o _ { t }$ . The boundary between the two is often blurred as a matter of convenience. Many physics engines implement minimal renderers to visualize results, and some rendering engines include integrations with a physics engine. PyBullet [37], MuJoCo [28], DART [38], ODE [39], PhysX/FleX [40, 41], and Chrono [42] are primarily physics engines with some level of rendering, while Magnum [43], ORRB [44], and PyRender [45] are primarily renderers. Game engines like Unity [46] and Unreal [47] provide tightly coupled integration of physics and rendering. Some simulators [3, 48, 49] involve largely static environments – the agent can move but not change the state of the environment (e.g. open cabinets). Thus, they are heavily invested in rendering with fairly lightweight physics (e.g. collision checking with the agent approximated as a cylinder).
How are interactive simulators built today? Either by relying on game engines [6, 50, 51] or via a ‘homebrew’ integration of existing rendering and physics libraries [7, 34, 36, 52]. Both options have problems. Game engines tend to be optimized for human needs (high image-resolution, ${ \sim } 6 0$ FPS, persistent display) not for AI’s needs [53] ( $1 0 \mathbf { k } +$ FPS, low-res, ‘headless’ deployment on a cluster). Reliance on them leads to limited control over the performance characteristics. On the other hand, they represent decades of knowledge and engineering effort whose value cannot be discounted. This is perhaps why ‘homebrew’ efforts involve a high-level (typically Python-based) integration of existing libraries. Unfortunately but understandably, this results in simulation speeds of 10-100s of SPS, which is orders of magnitude sub-optimal. $\mathrm { H } 2 . 0$ involved a deep low-level $( \mathbf { C } + + )$ integration of rendering (via Magnum [43]) and physics (via Bullet [37]), enabling precise control of scheduling and task-aware optimizations, resulting in substantial performance improvements.
Object rearrangement. Task- and motion-planning [54] and mobile manipulation have a long history in AI and robotics, whose full survey is beyond the scope of this document. Batra et al. [9] provide a good summary of the historical background of rearrangement, a review of recent efforts, a general framework, and a set of recommendations that we adopt here. Broadly speaking, our work is distinguished from prior literature by a combination of the emphasis on visual perception, lack of access to state, systematic generalization, and the experimental setup of visually-complex and ecologically-realistic home-scale environments. We now situate w.r.t. a few recent efforts. [55] study replanning in the presence of partial observability but do not consider mobile manipulation. [52] tackle ‘interactive navigation’, where the robot can bump into and push objects during navigation, but does not have an arm. Some works [56–58] abstract away gross motor control entirely by using symbolic interaction capabilities (e.g. a ‘pick up $X ^ { \prime }$ action) or a ‘magic pointer’ [9]. We use abstracted grasping but not abstract manipulation. [19] develop hierarchical methods for mobile manipulation, combining RL policies for goal-generation and motion-planning for executing them. We use the opposite combination of planning and learning – using task-planning to generate goals and RL for skills. [33] is perhaps the most similar to our work. Their task involves moving a single object from one location to another, excluding interactions with container objects (opening a drawer or fridge to place an object inside). We will see that rearrangement of multiple objects while handling containment is a much more challenging task. Interestingly, our experiments show evidence for the opposite conclusion reached therein – monolithic end-to-end trained RL methods are outperformed by a modular approach that is trained stage-wise to handle long-horizon rearrangement tasks.
# 3 Replica to ReplicaCAD: Creating Interactive Digital Twins of Real Spaces
We begin by describing our dataset that provides a rich set of indoor layouts for studying rearrangement tasks. Our starting point was Replica [2], a dataset of highly photo-realistic 3D reconstructions at room and building scale. Unfortunately, static 3D scans are unsuitable for studying rearrangement tasks because objects in a static scan cannot be moved or manipulated.
 Figure 2: Left: The original Replica scene. Right: the artist recreated scene ReplicaCAD. All objects (furniture, mugs) including articulated ones (drawers, fridge) in ReplicaCAD are fully physically simulated and interactive.
Asset Creation. ReplicaCAD is an artist-created, fully-interactive recreation of ‘FRL-apartment’ spaces from the Replica dataset [2]. First, a team of 3D artists authored individual 3D models (geometry, textures, and material specifications) to faithfully recreate nearly all objects (furniture, kitchen utensils, books, etc.; 92 in total) in all 6 rooms from the FRL-apartment spaces as well as an accompanying static backdrop (floor and walls). Fig. 2 compares a layout of ReplicaCAD with the original Replica scan. Next, each object was prepared for rigid-body simulation by authoring physical parameters (mass, friction, restitution), collision proxy shapes, and semantic annotations. Several objects (e.g. refrigerator, kitchen counter) were made ‘articulated’ through sub-part segmentation (annotating fridge door, counter cabinet) and authoring of URDF files describing joint configurations (e.g. fridge door swings around a hinge) and dynamic properties (e.g. joint type and limits). For each large furniture object (e.g. table), we annotated surface regions (e.g. table tops) and containment volumes (e.g. drawer space) to enable programmatic placement of small objects on top of or within.
Human Layout Generation. Next, a 3D artist authored an additional 5 semantically plausible ‘macro variations’ of the scenes – producing new scene layouts consisting only of larger furniture from the same 3D object assets. Each of these macro variations was further perturbed through 20 ‘micro variations’ that re-positioned objects – e.g. swapping the locations of similarly sized tables or a sofa and two chairs. This resulted in a total of 105 scene layouts that exhibit major and minor semantically-meaningful variations in furniture placement and scene layout, enabling controlled testing of generalization. Illustrations of these variations can be found in Appendix A.
Procedural Clutter Generation. To maximize the value of the human-authored assets we also develop a pipeline that allows us to generate new clutter procedurally. Specifically, we dynamically populate the annotated supporting surfaces (e.g. table-top, shelves in a cabinet) and containment volumes (e.g. fridge interior, drawer spaces) with object instances from appropriate categories (e.g., plates, food items). These inserted objects can come from ReplicaCAD or the YCB dataset [59]. We compute physically-stable insertions of clutter offline (i.e. letting an inserted bowl ‘settle’ on a shelf) and then load these stable arrangements into the scene dynamically at run-time.
ReplicaCAD is fully integrated with the $\mathrm { H } 2 . 0$ and a supporting configuration file structure enables simple import, instancing, and programmatic alternation of any of these interactive scenes. Overall, ReplicaCAD represents $9 0 0 +$ person-hours of professional 3D artist effort so far (with augmentations in progress). It was created with the consent of and compensation to artists, and will be shared under a Creative Commons license for non-commercial use with attribution (CC-BY-NC). Further ReplicaCAD details and statistics are in Appendix A.
# 4 Habitat 2.0 (H2.0): a Lazy Simulator
$\mathrm { H } 2 . 0$ ’s design philosophy is that speed is more important than the breadth of capabilities. H2.0 achieves fast rigid-body simulation in large photo-realistic 3D scenes by being lazy and only simulating what is absolutely needed. We instantiate this principle via 3 key ideas – localized physics and rendering (Sec. 4.1), interleaved physics and rendering (Sec. 4.2), and simplify-and-reuse (Sec. B.1). We also describe motion planning integration in Appendix B.2.
# 4.1 Localized Physics and Rendering
Realistic indoor 3D scenes can span houses with multiple rooms (kitchen, living room), hundreds of objects (sofa, table, mug) and ‘containers’ (fridge, drawer, cabinet), and thousands of parts (fridge shelf, cabinet door). Simulating physics for every part at all times is slow and unnecessary. We leverage Bullet’s built-in island sleep system to minimize simulation overhead for idle objects. In addition, we make several optimizations: (1) We employ a navigation mesh to move the robot base kinematically (which has been shown to transfer well to real the world [60]) rather than simulating wheel-ground contact. (2) For multi-body articulated furniture, we remove static parts (e.g. the walls and floor of a cabinet) from the Bullet multi-body and instead load these as separate static rigid objects. This improves the sleeping behavior of the entire simulation, for example, an idle object resting on the floor of the cabinet can sleep even while the cabinet door is moving. (3) We use the sleeping state of objects to optimize rendering by caching and re-using scene graph transformation matrices and frustum-culling results.
# 4.2 Interleaved rendering and physics
Most physics engines (e.g. Bullet) run on the CPU, while rendering (e.g. via Magnum) typically occurs on the GPU. After our initial optimizations, we found each to take nearly equal compute-time. This represents a glaring inefficiency – as illustrated in Fig. 3, at any given time either the CPU is sitting idle waiting for the GPU or vice-versa. Thus, interleaving them leads to significant gains. However, this is complicated by a sequential dependency – state transitions depend on robot actions $\mathcal { T } : ( s _ { t } , a _ { t } ) s _ { t + 1 }$ , robot actions depend on the sensor observations: $\pi : o _ { t } a _ { t }$ , and observations depend on the state $\mathcal { O } : s _ { t } \to o _ { t }$ . Thus, it ostensibly appears that physics and rendering outputs $( s _ { t + 1 }$ , $o _ { t }$ ) cannot be computed in parallel from $s _ { t }$ because computation of $a _ { t }$ cannot begin till $o _ { t }$ is available. We break this sequential dependency by changing the agent policy to be $\pi ( a _ { t } \mid o _ { t - 1 } )$ instead of $\pi ( \boldsymbol { a } _ { t } | \boldsymbol { o } _ { t } )$ . Thus, our agent predicts the current action $a _ { t }$ not from the current observations $o _ { t }$ but from an observation from 1 timestep ago $o _ { t - 1 }$ , essentially ‘living in the past and acting in the future’.
This simple change means that we can generate $s _ { t + 1 }$ on the CPU at the same time as $o _ { t }$ is being generated on the GPU.
This strategy not only increases simulation throughput, but also offers two other fortuitous benefits – increased biological plausibility and improved sim2real transfer potential. The former is due to closer analogy to all sensors (biological or artificial) having a sensing latency (e.g., the human visual system has approximately $1 5 0 \mathrm { m s }$ latency [61]). The latter is due to a line of prior work [62–64] showing that introducing this latency in simulators improves the transfer of learned agents to reality.
# 4.3 Benchmarking
# Sequential
 Figure 3: Interleaved physics and rendering. Top shows the normal sequential method of performing physics $( s _ { t } , a _ { t } ) \to s _ { t + 1 }$ then rendering $s _ { t + 1 } \to o _ { t + 1 }$ . Bottom shows $\mathrm { H } 2 . 0$ ’s interleaved physics and rendering.
We benchmark using a Fetch robot, equipped with (up to) two RGB-D cameras ( $1 2 8 \times 1 2 8$ pixels) in ReplicaCAD scenes under three scenarios: (1) Idle- $1 \times \mathrm { R G B }$ : with the robot initialized in the center of the living room somewhat far from furniture or any other object and taking random actions and equipped with a single RGB camera, (2) Idle- $2 \times \mathrm { R G B } { \cdot } \mathrm { D }$ , Idle-RGB with two RGB-D cameras, (3) Interact: with the robot initialized fairly close to the fridge and taking actions from a pre-computed trajectory that results in representative interaction with objects and equipped with two RGB-D cameras. Each simulation step consists of 1 rendering pass and 4 physics-steps, each simulating $1 / 1 2 0$ sec for a total of $1 / _ { 3 0 }$ sec. New joint position goals are set every $1 / _ { 3 0 }$ sec and a joint controller computes the joint torques to achieve the joint goals for the current joint state every $\mathbb { I } / 1 2 0$ sec. This is a fairly standard experimental configuration in robotics (with $3 0 \mathrm { F P S }$ cameras and $1 2 0 \mathrm { H z }$ control). In this setting, a simulator operating at 30 steps per (wallclock) second (SPS) corresponds to ‘real time’.
Benchmarking was done on machines with dual Intel Xeon Gold 6226R CPUs – 32 cores/64 threads (32C/64T) total – and 8 NVIDIA GeForce 2080 Ti GPUs. For single-GPU benchmarking processes are confined to 8C/16T of one CPU, simulating an 8C/16T single GPU workstation. For single-GPU multi-process benchmarking, 16 processes were used. For multi-GPU benchmarking, 64 processes were used with 8 processes assigned to each GPU. We used python-3.8 and gcc-9.3 for compiling H2.0. We report average SPS over 10 runs and a $9 5 \%$ confidence-interval computed via standard error of the mean. Note that 8 processes do not fully utilize a $2 0 8 0 \mathrm { T i }$ and thus multi-process multi-GPU performance may be better on machines with more CPU cores.
<table><tr><td></td><td colspan="7">1 Process</td><td colspan="6">1 GPU</td><td colspan="6">8 GPUs</td></tr><tr><td></td><td colspan="2">Idle 1×RGB</td><td colspan="2">Idle 2×RGB-D</td><td colspan="2">Interact 2×RGB-D</td><td colspan="2">Idle 1×RGB</td><td colspan="2">Idle 2×RGB-D</td><td colspan="2">Interact 2×RGB-D</td><td colspan="2">Idle 1×RGB</td><td colspan="2">Idle 2×RGB-D</td><td colspan="2">Interact 2×RGB-D</td></tr><tr><td>H2.0 (Full)</td><td>1191</td><td>±36</td><td>669</td><td>±13</td><td>510</td><td>±6</td><td>8186</td><td>±47</td><td>1926</td><td>±19</td><td>1660</td><td>±6</td><td>25734</td><td>±301</td><td>9542</td><td>±71</td><td>7699</td><td>±177</td></tr><tr><td>- render opts.</td><td>781</td><td>±9</td><td>364</td><td>±2</td><td>282</td><td>±2</td><td>6709</td><td>±89</td><td>1076</td><td>±6</td><td>1035</td><td>±3</td><td>18844</td><td>±285</td><td>6397</td><td>±43</td><td>5517</td><td>±31</td></tr><tr><td>- physics opts.</td><td>271</td><td>±3</td><td>252</td><td>±3</td><td>358</td><td>±6</td><td>2290</td><td>±5</td><td>1270</td><td>±30</td><td>1606</td><td>±6</td><td>7942</td><td>±50</td><td>5535</td><td>±41</td><td>6119</td><td>±51</td></tr><tr><td>- all opts.</td><td>242</td><td>±2</td><td>177</td><td>±3</td><td>224</td><td></td><td>2223</td><td>±3</td><td>814</td><td>±2</td><td>941</td><td>±2</td><td>7192</td><td>±55</td><td>3965</td><td>±30</td><td>4829</td><td>±50</td></tr></table>
Table 2: Benchmarking $\mathrm { H } 2 . 0$ performance: simulation steps per second (higher better) over 10 runs and a $9 5 \%$ confidence-interval In Idle, the agent is executing random actions but not interacting with the scene, while Interact uses a precomputed trajectory and thus results in representative interaction with objects. To put these numbers into context, see Tab. 1. Reproduce these numbers at https://aihabitat.org/docs/habitat2.
Table 2 reports benchmarking numbers for H2.0. We make a few observations. The ablations for $\mathrm { H } 2 . 0$ (denoted by ‘- render opts’, ‘-physics opts’, and ‘-all opts.’) show that principles followed in our system design lead to significant performance improvements.
Our ‘Idle- $\mathbf { \cdot l } \times \mathbf { R G B } ^ { \mathbf { \cdot } }$ setting is similar to the benchmarking setup of iGibson [36], which reports 100 SPS. In contrast, $\mathrm { H } 2 . 0$ single-process with all optimizations turned off is $240 \%$ faster (242 vs 100 SPS). H2.0 single-process with optimizations on is $\sim 1 2 0 0 \%$ faster than iGibson (1191 vs 100 SPS). The comparison to iGibson is particularly illustrative since it uses the ‘same’ physics engine (PyBullet) as $\mathrm { H } 2 . 0$ (Bullet). We can clearly see the benefit of working with the low-level $\mathrm { C } { + } { + }$ Bullet rather than PyBullet and the deep integration between rendering and physics. However, we note the comparison between the two benchmarks is not exact since the robot type, number of objects, and object assets are different. A direct comparison against other simulators is not feasible due to different capabilities, assets, hardware, and experimental settings. But a qualitative order-of-magnitude survey is illustrative – AI2-THOR [6] achieves 60/30 SPS in idle/interact, SAPIEN [34] achieves 200/400 SPS (personal communication), TDW [7] achieves 5 SPS in interact, and RLBench [35] achieves between 1 and 60 SPS depending on the sensor suite (personal communication). Finally, $\mathrm { H } 2 . 0$ scales well – achieving 8,186 SPS ( $2 7 2 \times$ real-time) multi-process on a single GPU and 25,734 SPS $8 5 0 \times$ real-time) on a single node with 8 GPUs. These $1 0 0 \times$ simulation-speedups correspond to cutting experimentation time from 6-month cycle to under 2 days. iGibson also supports multi-process parallization for speeding simulation speeds beyond the reported single process numbers in the current version of the paper [36], and we recommend following updates of their work for more details.
# 5 The Pick Task: a Base Case of Rearrangement
We first carry out systematic analyses on a relatively simple robotic manipulation task: picking up one object from a cluttered ‘receptacle’. This forms a ‘base case’ and an instructive starting point that we eventually expand to the more challenging Home Assistant Benchmark (HAB) (Sec. 6).
Task Definition: Pick $( s ^ { 0 } )$ . Fig. 4 illustrates an episode in the pick task. Our agent (a Fetch robot [1]) is spawned close to a receptacle (a table) that holds multiple objects (e.g. cracker box, bowl). The task for the robot is to pick up a target object with center-of-mass coordinates $s ^ { 0 } \in R ^ { 3 }$ (provided in robot’s coordinate system) as efficiently as possible without excessive collisions. We study systematic generalization to new clutter layout on the receptacle, to new objects, and to new receptacles. Agent embodiment and sensing. Fetch [1] is a wheeled base with a 7-DoF arm manipulator and a parallel-jaw gripper, equipped with two RGBD cameras ${ \mathrm { 9 0 ^ { \circ } F o V } } _ { : }$ , $1 2 8 \times 1 2 8$ pixels) mounted on its ‘head’ and arm.
It can sense its proprioceptive-state – arm joint angles (7- dim), end-effector position (3-dim), and base-egomotion (6-dim, also known as $\mathrm { G P S } { + }$ Compass in the navigation literature [3]). Note: the episodes in Pick are constructed such that the robot does not need to move its base. Thus, the egomotion sensor does not play a role in Pick but will be important in HAB tasks (Section 6).
Action space: gross motor control. The agent performs end-effector control at $3 0 \mathrm { H z }$ . At every step, it outputs the desired change in end-effector position $( \delta x , \delta y , \delta z )$ ; the desired end-effector position is fed into an inverse kinematics solver from PyBullet [37] to derive desired states for all joints, which are used to set the joint motor targets, achieved using PD control. The maximum endeffector displacement per step is $1 . 5 \mathrm { c m }$ , and the maximum impulse of the joint motors is 10Ns with a position gain of $\mathrm { K p } { = } 0 . 3$ . In Pick, the base is fixed but in HAB, the agent also emits linear and angular velocities for the base.
 Figure 4: Fetch with head and arm cameras picking up a bowl from the counter.
Abstracted grasping. The agent controls the gripper by emitting a scalar. If this scalar is positive and the gripper is not currently holding an object and the end-effector is within $1 5 c m$ of an object, then the object closest to the end-effector is snapped into the parallel-jaw gripper. The grasping is perfect and objects do not slide out. If the scalar is negative and the gripper is currently holding an object, then the object currently held in the gripper is released and simulated as falling. In all other cases, nothing happens. For analysis of other action spaces see Appendix F.6.
Evaluation. An object is considered successfully picked if the arm returns to a known ‘resting position’ with the target object grasped. The agent fails if the accumulated contact force experienced by the arm/body exceeds a threshold of 5k Newtons. If the agent picks up the wrong object, the episode terminates. Once the object is grasped, the drop action is masked out meaning the agent will never release the object. The episode horizon is 200 steps.
Methods. We compare two methods representing two distinctive approaches to this problem: 1. MonolithicRL: a ‘sensors-to-actions’ policy trained end-to-end with reinforcement learning (RL). The visual input is encoded using a CNN, concatenated with embeddings of proprioceptive-sensing and goal coordinates, and fed to a recurrent actor-critic network, trained with DD-PPO [11] for 100
Million steps of experience (see Appendix C for details). This baseline translates our community’s most-successful paradigm yet from navigation to manipulation.
2. SensePlanAct (SPA) pipeline: Sensing consists of constructing an accumulative 3D point-cloud of the scene from depth sensors, which is then used for collision queries. Motion planning is done using Bidirectional RRT [65] in the arm joint configuration space (see Appendix D). The controller was described in ‘Action Space’ above and is consistent with MonolithicRL. We also create SensePlanAct-Priviledged (SPA-Priv), that uses privileged information – perfect knowledge of scene geometry (from the simulator) and a perfect controller (arm is kinematically set to desired joint poses). The purpose of this baseline is to provide an upper-bound on the performance of SPA.
Systematic Generalization. With $\mathrm { H } 2 . 0$ we can compare how learning based systems generalize compared to SPA architectures. Tab. 3 shows the results of a systematic generalization study of 4 unseen objects, 3 unseen receptacles, and 20 unseen apartment layouts (from 1 unseen ‘macro variation’ in ReplicaCAD). In training the agent sees 9 objects from the YCB dataset kitchen and food categories (chef can, cracker box, sugar box, tomato soup can, tuna fish cap, pudding box, gelatin box, potted meat can, and
<table><tr><td rowspan="2">Method</td><td rowspan="2">Seen</td><td colspan="3">Unseen</td></tr><tr><td>Layouts</td><td>Objects</td><td>Receptacles</td></tr><tr><td>MonolithicRL 91.7 ±1.1</td><td></td><td>86.3 ±1.4</td><td>74.7 ±1.8</td><td>52.7 ±2.0</td></tr><tr><td>SPA</td><td>70.2 ±1.9</td><td>72.7 ±1.8</td><td>72.7 ±1.8</td><td>60.3 ±2.0</td></tr><tr><td>SPA-Priv</td><td>77.0 ±1.7</td><td>80.0±1.6</td><td>79.2 ±1.7</td><td>60.7 ±2.0</td></tr></table>
Table 3: Pick generalization analysis: success rates with mean and standard error on 600 episodes (and across 3 seeds for MonolithicRL).
bowl). During evaluation it is tested on 4 unseen objects (apple, orange, mug, sponge). Likewise, the agent is trained on the counter, sink, light table, cabinet, fridge, dark table, and sofa receptacles (view in Fig. 11) but evaluated on the unseen receptacles of tv stand, shelves, and chair (view in Fig. 12).
MonolithicRL generalizes fairly well from seen to unseen layouts $( 9 1 . 7 8 6 . 3 \%$ ), significantly outperforming SPA $( 7 2 . 7 \% )$ and even SPA-Priv $( 8 0 . 0 \% )$ . However, generalization to new objects is challenging $( 9 1 . 7 7 4 . 7 \% )$ as a result of the new visual feature distribution and new object obstacles. Generalization to new receptacles is poor $( 9 1 . 7 5 2 . 7 \% )$ ). However, the performance drop of SPA (and qualitative results) suggest that the unseen receptacles (shelf, armchair, tv stand) may be objectively more difficult to pick up objects from since the shelf and armchair are tight constrained areas whereas the majority of the training receptacles, such as counters and tables, have no such constraints (see Fig. 12). We believe the performance of MonolithicRL will improve as more receptacles 3D assets become available since the training distribution was only 4 receptacles. We cannot make any such claims for SPA.
In the supplementary we also analyze different sensor input modalities (Appendix F.1), the surprising success of “blind" policies (Appendix F.2), the effect of different camera placements (Appendix F.3), different action spaces (Appendix F.6), the effect of the time delay on performance (Appendix F.5), and qualitative evidence of self-tracking (Appendix F.4).
# 6 Home Assistant Benchmark (HAB)
We now describe our benchmark of common household assistive robotic tasks. We stress that these tasks illustrate the capabilities of $\mathrm { H } 2 . 0$ but do not delineate them – a lot more is possible but not feasible to pack into a single coherent document with clear scientific takeaways.
Task Definition. We study three (families of) long-range tasks that correspond to common activities:
1. TidyHouse: Move 5 objects from random (unimpeded) locations back to where they belong (see Fig. 19a). This task requires no opening or closing and no objects are contained.
• Start: 5 target objects objects spawned in 6 possible receptacles (excluding fridge and drawer).
• Goal: Each target object is assigned a goal in a different receptacle than the starting receptacle.
• Task length: 5000 steps.
2. PrepareGroceries: Remove 2 objects from the fridge to the counters and place one object back in the fridge (see Fig. 19b). This task requires no opening or closing and no objects are contained.
• Start: 2 target objects in the fridge and one on the left counter. The fridge is fully opened. • Goal: The goal for the target objects in the fridge are on the right counter and light table. The goal for the other target object is in the fridge. • Task length: 4000 steps
3. SetTable: Get a bowl from a drawer, a fruit from fridge, place the fruit in the bowl on the table (see Fig. 19c).
• Start: A target bowl object is in one of the drawers and a target fruit object in the middle fridge shelf. Both the fridge and drawer start closed. • Goal: The goal for the bowl is on the light table, the goal for the fruit is on top of the bowl. Both the fridge and drawer must be closed. • Task length: 4500 steps.
The list is in increasing order of complexity – from no interaction with containers (TidyHouse), to picking and placing from the fridge container (PrepareGroceries), to opening and closing containers (SetTable). Note that these descriptions are provided purely for human understanding; the robot operates entirely from a GeometricGoal specification [9] – given by the initial and desired 3D (center-of-mass) position of each target object $i$ to be moved $\left( s _ { i } ^ { 0 } , s _ { i } ^ { * } \right) _ { i = 1 } ^ { N }$ . Thus, Pick $( s _ { i } ^ { 0 } )$ is a special case where $N = 1$ and $s _ { i } ^ { * }$ is a constant (arm resting) location. For each task episode, we sample a ReplicaCAD layout with YCB [59] objects randomly placed on feasible placement regions (see procedural clutter generation in Section 3). Each task has 5 clutter objects per receptacle. Unless specified, objects are sampled from the ‘food’ and ‘kitchen’ YCB item categories in the YCB dataset.
The agent is evaluated on unseen layouts and configurations of objects, and so cannot simply memorize. We characterize task difficulty by the required number of rigid-body transitions (e.g., picking up a bowl, opening a drawer). The task evaluation, agent embodiment, sensing, and action space remain unchanged from Section 5, with the addition of base control via velocity commands. Details on episode statistics, as well as the evaluation protocols are in Appendix G.
Methods. We extend the methods from Sec. 5 to better handle the above long-horizon tasks with a high-level STRIPS planner using a parameterized set of skills: Pick, Place, Open fridge door, Close fridge door, Open drawer, Close drawer, and Navigate. The full details of the planner implementation and how methods are extended are in Appendix H. Here, we provide a brief overview.
1. MonolithicRL: Essentially unchanged from Sec. 5, with the exception of accepting a list of start and goal coordinates $\left( s _ { i } ^ { 0 } , s _ { i } ^ { * } \right) _ { i = 1 } ^ { N }$ , as opposed to just $s _ { 1 } ^ { 0 }$ .
2. TaskPlanning $^ +$ SkillsRL $\mathbf { \hat { \Pi } } \mathbf { T P } { + } \mathbf { S R L }$ ): a hierarchical approach that assumes knowledge of a perfect task planner (implemented with STRIPS [27]) and the initial object containment needed by the task planner to break down a task into a sequence of parameterized skills: Navigate, Pick, Place, Open fridge door, Close fridge door, Open drawer, Close drawer. Each skill is functionally identical to MonolithicRL in Sec. $5 -$ taking as input a single 3D position, either $s _ { i } ^ { 0 }$ or $s _ { i } ^ { * }$ . For instance, in the SetTable task, let $( a ^ { 0 } , a ^ { * } )$ and $( b ^ { 0 ^ { * } } , b ^ { * } )$ denote the start and goal positions of the apple and bowl, respectively. The task planner converts this task into:
Open Drawer Transport Bowl Close Drawer $\begin{array} { r } { \overbrace { \mathrm { ` a u r i g a t e } ( b ^ { 0 } ) } ^ { \substack { } } , \mathtt { O p e n ~ d r a w e r } ( b ^ { 0 } ) , \overbrace { \mathrm { ` e i c k } ( b ^ { 0 } ) , \mathtt { N a v i z a t e } ( b ^ { * } ) , \mathtt { P l a c e } ( b ^ { * } ) } ^ { \substack { } } , \overbrace { \mathrm { ` N a v i z a t e } ( b ^ { 0 } ) , \mathrm { C l o s s e ~ d r a w e r } ( b ^ { 0 } ) } ^ { \substack { } } , \overbrace { \mathrm { ` r a n s e ~ d r a w e r } ( b ^ { 0 } ) } ^ { \substack { } } , \overbrace { \mathrm { ` r a n s e ~ d r a w e r } ( b ^ { 0 } ) } ^ { \substack { } } , \overbrace { \mathrm { ` r a n s e ~ d r a w e r } ( b ^ { 0 } ) } ^ { \substack { } } , } \end{array}$ Navigate(a0), Open fridge door(a0) , Navigate(a⇤), Place(a⇤) , Navigate(a0), Close fridge door(a0) . {zOpen Fridge {zTransport Apple {zClose Fridge Simply listing out this sequence highlights the challenging nature of these tasks.
3. TaskPlanning $^ +$ SensePlanAct $\mathbf { \left( T P + S P A \right) }$ ): Same task planner as above, with each skill implemented via SPA from Sec. 5 except for Navigate where the same learned navigation policy from $\mathbf { T P + S P A }$ is used. $\mathbf { T P + S P A }$ -Priv is analogously defined. Crafting an SPA pipeline for opening/closing unknown articulated containers is an open unsolved problem in robotics – involving detecting and tracking articulation [66, 67] without models, constrained full-body planning [68–70] without hand engineering constraints, and designing controllers to handle continuous contact [71, 72] – making it out of scope for this work. Thus, we do not report $\mathbf { T P + S P A }$ on SetTable.
Results and Findings. Figure 5 shows progressive success rates for different methods on all tasks. Due to the difficulty of the full task, for analysis, the $\mathrm { X }$ -axis lists the sequence of agent-environment interactions (pick, place, open, close) required to accomplish the task, same as that used by the task-planner.4 The number of interactions is a proxy for task difficulty and the plot is analogous to precision-recall curves (with the ideal curve being a straight line at $100 \%$ ). Furthermore, since navigation is often executed between successive skills, we include versions of the task planning methods with an oracle navigation skill. We make the following observations (See Appendix I for skill learning curves and SPA failure statistics):
 Figure 5: Success rates for Home Assistant Benchmark tasks. Due to the difficulty of full HAB tasks, we analyze performance as completing a part of the overall task. For the TP methods that use an explicit navigation skill, we indicate with an arrow in the interaction names where navigation occurs and include versions for learned and oracle navigation. Results are on unseen layouts with mean and standard error computed for 100 episodes.
1. MonolithicRL performs abysmally. We were able to train individual skills with RL to reasonable degrees of success (see Appendix I.2). However, crafting a combined reward function and learning scheme that elicits chaining of such skills for a long-horizon task, without any architectural inductive bias about the task structure, remained out of our reach despite prolonged effort.
2. Learning a navigation policy to chain together skills is challenging as illustrated by the performance drop between learned and oracle navigation. In navigation for the sake of navigation (PointNav [10]), the agent is provided coordinates of the reachable goal location. In navigation for manipulation (Navigate), the agent is provided coordinates of a target object’s center-of-mass but needs to navigate to an unspecified non-unique suitable location from where the object is manipulable.
3. Compounding errors hurt performance of task planning methods. Even with the relatively easier skills in TidyHouse in Figure 5a all methods with oracle navigation gradually decrease in performance as the number of required interactions increases.
4. Sense-plan-act variants scale poorly to increasing task complexity. In the easiest setting, Tidy House with oracle navigation (Figure 5a), $\mathbf { T P + S P A }$ performs better than $\mathbf { T P + S R L }$ . However, this trend is reversed with learned navigation since $\mathbf { T P + S P A }$ methods, which rely on egocentric perception for planning, are not necessarily correctly positioned to sense the workspace. In the more complex task of PrepareGroceries (Figure 5b), $\mathbf { \hat { T } P + S R L }$ outperforms $\mathbf { T P + S P A }$ both with and without oracle navigation due to the perception challenge of the tight and cluttered fridge. $\mathbf { T P + S P A }$ fails to find a goal configuration 3x more often and fails to find a plan in the allowed time $3 \mathbf { x }$ more often in PrepareGroceries than TidyHouse.
# 7 Societal Impacts, Limitations, and Conclusion
ReplicaCAD was modeled upon apartments in one country (USA). Different cultures and regions may have different layouts of furniture, types of furniture, and types of objects not represented in ReplicaCAD; and this lack of representation can have negative social implications for the assistants developed. While $\mathrm { H } 2 . 0$ is a fast simulator, we find that the performance of the overall simulation+training loop is bottlenecked by factors like synchronization of parallel environments and reloading of assets upon episode reset. An exciting and complementary future direction is holistically reorganizing the rendering+physics $\scriptstyle \mathrm { + R L }$ interplay as studied by [73–78]. As illustrated in Figure 3, there is idle GPU time when rendering is faster than physics, because inference waits for both $o _ { t }$ and $s _ { t + 1 }$ to be ready despite not needing $s _ { t + 1 }$ . This is done because existing RL training systems expect the reward $r _ { t }$ to be returned when the agent takes an action $a _ { t }$ , but $r _ { t }$ is typically a function of $s _ { t } , a _ { t }$ , and $s _ { t + 1 }$ . Reorganizing the rendering $^ +$ physic $\mathrm { \ s + R L }$ interplay is an exciting problem for future work.
We presented the ReplicaCAD dataset, the Habitat 2.0 platform and a home assistant benchmark. $\mathrm { H } 2 . 0$ is a fully interactive, high-performance 3D simulator that enables efficient experimentation involving embodied AI agents rearranging richly interactive 3D environments. Coupled with the ReplicaCAD data these improvements allow us to investigate the performance of RL policies against classical MP approaches for the suite of challenging rearrangement tasks we defined. We hope that the Habitat 2.0 platform will catalyze work on embodied AI for interactive environments.
# 8 Acknowledgements
Funding in direct support of this work: The Georgia Tech portion of this work supported by state funds from Georgia Tech (AS, ZK), NSF (DB), AFRL (DB), DARPA (DB), ONR YIPs (DB), ARO PECASE (DB), Amazon (DB). The SFU portion of this work is supported by a CIFAR AI Chair (AC), a Canada Research Chair (MS), and NSERC Discovery Grants (AC,MS). This work was also supported by FAIR (AC, EU, YZ, JT, NM, MM, DC, OM, AG, FM, WG) and Intel (VK).
Additional revenues related to this work: NSF (ZK), DARPA (ZK), ONR (ZK), NGA (ZK), Samsung (ZK), Airbus (ZK), consulting for Marble Inc (ZK), paid talk by Data Science Connect (ZK), sponsored research funding by FAIR (AC,MS).
# References
[1] Fetch robotics. Fetch. http://fetchrobotics.com/, 2020. [2] Julian Straub, Thomas Whelan, Lingni Ma, Yufan Chen, Erik Wijmans, Simon Green, Jakob J Engel, Raul Mur-Artal, Carl Ren, Shobhit Verma, et al. The replica dataset: A digital replica of indoor spaces. arXiv preprint arXiv:1906.05797, 2019. [3] Manolis Savva, Abhishek Kadian, Oleksandr Maksymets, Yili Zhao, Erik Wijmans, Bhavana Jain, Julian Straub, Jia Liu, Vladlen Koltun, Jitendra Malik, et al. Habitat: A Platform for Embodied AI Research. In Proceedings of the IEEE/CVF International Conference on Computer Vision, pages 9339–9347, 2019. [4] Franka. Franka emika specification. https://www.franka.de, 2020. [5] Unitree robotics. Aliengo. https://www.unitree.com, 2020. [6] Eric Kolve, Roozbeh Mottaghi, Winson Han, Eli VanderBilt, Luca Weihs, Alvaro Herrasti, Daniel Gordon, Yuke Zhu, Abhinav Gupta, and Ali Farhadi. AI2-Thor: An interactive 3D environment for visual AI. arXiv preprint arXiv:1712.05474, 2017. [7] Chuang Gan, Jeremy Schwartz, Seth Alter, Martin Schrimpf, James Traer, Julian De Freitas, Jonas Kubilius, Abhishek Bhandwaldar, Nick Haber, Megumi Sano, et al. ThreeDWorld: A platform for interactive multi-modal physical simulation. arXiv preprint arXiv:2007.04954, 2020. [8] Daniel Seita, Pete Florence, Jonathan Tompson, Erwin Coumans, Vikas Sindhwani, Ken Goldberg, and Andy Zeng. Learning to Rearrange Deformable Cables, Fabrics, and Bags with Goal-Conditioned Transporter Networks. In IEEE International Conference on Robotics and Automation (ICRA), 2021. [9] Dhruv Batra, Angel X Chang, Sonia Chernova, Andrew J Davison, Jia Deng, Vladlen Koltun, Sergey Levine, Jitendra Malik, Igor Mordatch, Roozbeh Mottaghi, Manolis Savva, and Hao Su. Rearrangement: A challenge for embodied AI. arXiv preprint arXiv:2011.01975, 2020. [10] Peter Anderson, Angel Chang, Devendra Singh Chaplot, Alexey Dosovitskiy, Saurabh Gupta, Vladlen Koltun, Jana Kosecka, Jitendra Malik, Roozbeh Mottaghi, Manolis Savva, et al. On evaluation of embodied navigation agents. arXiv preprint arXiv:1807.06757, 2018. [11] Erik Wijmans, Abhishek Kadian, Ari Morcos, Stefan Lee, Irfan Essa, Devi Parikh, Manolis Savva, and Dhruv Batra. DD-PPO: Learning near-perfect pointgoal navigators from 2.5 billion frames. In International Conference on Learning Representations (ICLR), 2020. [12] Erik Wijmans, Irfan Essa, and Dhruv Batra. How to train pointgoal navigation agents on a (sample and compute) budget. arXiv preprint arXiv:2012.06117, 2020. [13] Joel Ye, Dhruv Batra, Erik Wijmans, and Abhishek Das. Auxiliary tasks speed up learning pointgoal navigation. arXiv preprint arXiv:2007.04561, 2020. [14] Yilun Du, Chuang Gan, and Phillip Isola. Curious representation learning for embodied intelligence. arXiv preprint arXiv:2105.01060, 2021. [15] Peter Karkus, Shaojun Cai, and David Hsu. Differentiable slam-net: Learning particle slam for visual navigation. In Proceedings of IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2021. [16] Claudia Pérez-D’Arpino, Can Liu, Patrick Goebel, Roberto Martín-Martín, and Silvio Savarese. Robot navigation in constrained pedestrian environments using reinforcement learning. In Proceedings of IEEE International Conference on Robotics and Automation (ICRA), 2021. [17] Santhosh K. Ramakrishnan, Ziad Al-Halah, and Kristen Grauman. Occupancy anticipation for efficient exploration and navigation. In ECCV, 2020. [18] Somil Bansal, Varun Tolani, Saurabh Gupta, Jitendra Malik, and Claire Tomlin. Combining optimal control and learning for visual navigation in novel environments. In Conference on Robot Learning (CoRL), 2019. [19] Fei Xia, Chengshu Li, Roberto Martín-Martín, Or Litany, Alexander Toshev, and Silvio Savarese. Relmogen: Leveraging motion generation in reinforcement learning for mobile manipulation. In Proceedings of IEEE International Conference on Robotics and Automation (ICRA), 2021. [20] Dhruv Batra, Aaron Gokaslan, Aniruddha Kembhavi, Oleksandr Maksymets, Roozbeh Mottaghi, Manolis Savva, Alexander Toshev, and Erik Wijmans. Objectnav revisited: On evaluation of embodied agents navigating to objects. arXiv preprint arXiv:2006.13171, 2020. [21] Alexander Ku, Peter Anderson, Roma Patel, Eugene Ie, and Jason Baldridge. Room-across-room: Multilingual vision-and-language navigation with dense spatiotemporal grounding. arXiv preprint arXiv:2010.07954, 2020. [22] Peter Anderson, Qi Wu, Damien Teney, Jake Bruce, Mark Johnson, Niko Sünderhauf, Ian Reid, Stephen Gould, and Anton Van Den Hengel. Vision-and-language navigation: Interpreting visually-grounded navigation instructions in real environments. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pages 3674–3683, 2018. [23] Adithyavairavan Murali, Arsalan Mousavian, Clemens Eppner, Chris Paxton, and Dieter Fox. 6-dof grasping for target-driven object manipulation in clutter. In 2020 IEEE International Conference on Robotics and Automation (ICRA), pages 6232–6238. IEEE, 2020. [24] Jeannette Bohg, Antonio Morales, Tamim Asfour, and Danica Kragic. Data-driven grasp synthesis—a survey. IEEE Transactions on Robotics, 30(2):289–309, 2013. [25] Kaiyu Hang, Miao Li, Johannes A Stork, Yasemin Bekiroglu, Florian T Pokorny, Aude Billard, and Danica Kragic. Hierarchical fingertip space: A unified framework for grasp planning and in-hand grasp adaptation. IEEE Transactions on robotics, 32(4):960–972, 2016. [26] Robin R Murphy. Introduction to AI robotics. MIT press, 2019. [27] Richard E Fikes and Nils J Nilsson. Strips: A new approach to the application of theorem proving to problem solving. Artificial intelligence, 2(3-4):189–208, 1971. [28] Emanuel Todorov, Tom Erez, and Yuval Tassa. Mujoco: A physics engine for model-based control. In 2012 IEEE/RSJ International Conference on Intelligent Robots and Systems, pages 5026–5033. IEEE, 2012. [29] Nvidia. Isaac Sim. https://developer.nvidia.com/isaac-sim, 2020. [30] Greg Brockman, Vicki Cheung, Ludwig Pettersson, Jonas Schneider, John Schulman, Jie Tang, and Wojciech Zaremba. Openai gym. arXiv preprint arXiv:1606.01540, 2016. [31] Marc G Bellemare, Yavar Naddaf, Joel Veness, and Michael Bowling. The arcade learning environment: An evaluation platform for general agents. Journal of Artificial Intelligence Research, 47:253–279, 2013. [32] Yuval Tassa, Yotam Doron, Alistair Muldal, Tom Erez, Yazhe Li, Diego de Las Casas, David Budden, Abbas Abdolmaleki, Josh Merel, Andrew Lefrancq, et al. Deepmind control suite. arXiv preprint arXiv:1801.00690, 2018. [33] Kiana Ehsani, Winson Han, Alvaro Herrasti, Eli VanderBilt, Luca Weihs, Eric Kolve, Aniruddha Kembhavi, and Roozbeh Mottaghi. ManipulaTHOR: A framework for visual object manipulation. In Proceedings of the IEEE/CVF conference on computer vision and pattern recognition, 2021. [34] Fanbo Xiang, Yuzhe Qin, Kaichun Mo, Yikuan Xia, Hao Zhu, Fangchen Liu, Minghua Liu, Hanxiao Jiang, Yifu Yuan, He Wang, Li Yi, Angel X. Chang, Leonidas J. Guibas, and Hao Su. SAPIEN: A simulated part-based interactive environment. In The IEEE Conference on Computer Vision and Pattern Recognition (CVPR), June 2020. [35] Stephen James, Zicong Ma, David Rovick Arrojo, and Andrew J Davison. Rlbench: The robot learning benchmark & learning environment. IEEE Robotics and Automation Letters, 5(2):3019–3026, 2020. [36] Bokui Shen, Fei Xia, Chengshu Li, Roberto Martın-Martın, Linxi Fan, Guanzhi Wang, Shyamal Buch, Claudia D’Arpino, Sanjana Srivastava, Lyne P Tchapmi, Kent Vainio, Li Fei-Fei, and Silvio Savarese. iGibson, a simulation environment for interactive tasks in large realistic scenes. arXiv preprint, 2020. [37] Erwin Coumans and Yunfei Bai. PyBullet, a Python module for physics simulation for games, robotics and machine learning. http://pybullet.org, 2016–2019. [38] Jeongseok Lee, Michael X Grey, Sehoon Ha, Tobias Kunz, Sumit Jain, Yuting Ye, Siddhartha S Srinivasa, Mike Stilman, and C Karen Liu. Dart: Dynamic animation and robotics toolkit. Journal of Open Source Software, 3(22):500, 2018. [39] R Smith. ODE: Open Dynamics Engine. http://www.ode.org/, 01 2009. [40] Nvidia. PhysX. https://developer.nvidia.com/gameworks-physx-overview. [41] Nvidia. FleX. https://developer.nvidia.com/flex, 2020. [42] Hammad Mazhar, Toby Heyn, Arman Pazouki, Dan Melanz, Andrew Seidl, Aaron Bartholomew, Alessandro Tasora, and Dan Negrut. CHRONO: A parallel multi-physics library for rigid-body, flexible-body, and fluid dynamics. Mechanical Sciences, 4:49–64, 02 2013. doi: 10.5194/ms-4-49-2013. URL https://projectchrono.org/. [43] Vladimír Vondruš and contributors. Magnum. https://magnum.graphics, 2020. [44] Lilian Weng Maciek Chociej, Peter Welinder. Orrb: Openai remote rendering backend. In eprint arXiv, 2019. URL https://arxiv.org/abs/1906.11633. [45] Matthew Matl. Pyrender. https://github.com/mmatl/pyrender, 2020. [46] Unity Technologies. Unity. https://unity.com/. [47] Epic Games. Unreal Engine. https://www.unrealengine.com/. [48] Manolis Savva, Angel X. Chang, Alexey Dosovitskiy, Thomas Funkhouser, and Vladlen Koltun. MINOS: Multimodal indoor simulator for navigation in complex environments. arXiv:1712.03931, 2017. [49] Yi Wu, Yuxin Wu, Georgia Gkioxari, and Yuandong Tian. Building generalizable agents with a realistic and rich 3d environment. arXiv preprint arXiv:1801.02209, 2018. [50] Claudia Yan, Dipendra Misra, Andrew Bennnett, Aaron Walsman, Yonatan Bisk, and Yoav Artzi. Chalet: Cornell house agent learning environment. arXiv preprint arXiv:1801.07357, 2018. [51] Xavier Puig, Kevin Ra, Marko Boben, Jiaman Li, Tingwu Wang, Sanja Fidler, and Antonio Torralba. VirtualHome: Simulating household activities via programs. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pages 8494–8502, 2018. [52] Fei Xia, William B Shen, Chengshu Li, Priya Kasimbeg, Micael Edmond Tchapmi, Alexander Toshev, Roberto Martín-Martín, and Silvio Savarese. Interactive gibson benchmark: A benchmark for interactive navigation in cluttered environments. IEEE Robotics and Automation Letters, 5(2):713–720, 2020. [53] HeeSun Choi, Cindy Crump, Christian Duriez, Asher Elmquist, Gregory Hager, David Han, Frank Hearl, Jessica Hodgins, Abhinandan Jain, Frederick Leve, Chen Li, Franziska Meier, Dan Negrut, Ludovic Righetti, Alberto Rodriguez, Jie Tan, and Jeff Trinkle. On the use of simulation in robotics: Opportunities, challenges, and suggestions for moving forward. Proceedings of the National Academy of Sciences, 118(1), 2021. ISSN 0027-8424. doi: 10.1073/pnas.1907856118. URL https://www.pnas.org/ content/118/1/e1907856118. [54] Caelan Reed Garrett, Rohan Chitnis, Rachel Holladay, Beomjoon Kim, Tom Silver, Leslie Pack Kaelbling, and Tomás Lozano-Pérez. Integrated task and motion planning. arXiv preprint arXiv:2010.01083, 2020. [55] Caelan Reed Garrett, Chris Paxton, Tomás Lozano-Pérez, Leslie Pack Kaelbling, and Dieter Fox. Online replanning in belief space for partially observable task and motion problems. In IEEE International Conference on Robotics and Automation (ICRA), 2020. [56] Dipendra Misra, Andrew Bennett, Valts Blukis, Eyvind Niklasson, Max Shatkhin, and Yoav Artzi. Mapping instructions to actions in 3d environments with visual goal prediction. arXiv preprint arXiv:1809.00786, 2018. [57] Mohit Shridhar, Jesse Thomason, Daniel Gordon, Yonatan Bisk, Winson Han, Roozbeh Mottaghi, Luke Zettlemoyer, and Dieter Fox. Alfred: A benchmark for interpreting grounded instructions for everyday tasks. In Proceedings of the IEEE/CVF conference on computer vision and pattern recognition, pages 10740–10749, 2020. [58] Luca Weihs, Matt Deitke, Aniruddha Kembhavi, and Roozbeh Mottaghi. Visual room rearrangement. In Proceedings of the IEEE/CVF conference on computer vision and pattern recognition, 2021. [59] Berk Calli, Arjun Singh, Aaron Walsman, Siddhartha Srinivasa, Pieter Abbeel, and Aaron M Dollar. The YCB object and model set: Towards common benchmarks for manipulation research. In 2015 international conference on advanced robotics (ICAR), pages 510–517. IEEE, 2015. [60] Abhishek Kadian, Joanne Truong, Aaron Gokaslan, Alexander Clegg, Erik Wijmans, Stefan Lee, Manolis Savva, Sonia Chernova, and Dhruv Batra. Sim2real predictivity: Does evaluation in simulation predict real-world performance? IEEE Robotics and Automation Letters, 5(4):6670–6677, 2020. [61] Simon Thorpe, Denis Fize, and Catherine Marlot. Speed of processing in the human visual system. nature, 381(6582):520–522, 1996. [62] Sandeep Singh Sandha, Luis Garcia, Bharathan Balaji, Fatima M Anwar, and Mani Srivastava. Sim2real transfer for deep reinforcement learning with stochastic state transition delays. CoRL 2020, 2020. [63] Gabriel Dulac-Arnold, Nir Levine, Daniel J. Mankowitz, Jerry Li, Cosmin Paduraru, Sven Gowal, and Todd Hester. An empirical investigation of the challenges of real-world reinforcement learning. arXiv preprint, 2020. [64] Jie Tan, Tingnan Zhang, Erwin Coumans, Atil Iscen, Yunfei Bai, Danijar Hafner, Steven Bohez, and Vincent Vanhoucke. Sim-to-real: Learning agile locomotion for quadruped robots. RSS 14, 2018. [65] Steven M LaValle. Planning algorithms. Cambridge university press, 2006. [66] Tanner Schmidt, Richard A Newcombe, and Dieter Fox. Dart: Dense articulated real-time tracking. In Robotics: Science and Systems, volume 2. Berkeley, CA, 2014. [67] Richard Sahala Hartanto, Ryoichi Ishikawa, Menandro Roxas, and Takeshi Oishi. Hand-motion-guided articulation and segmentation estimation. In 2020 29th IEEE International Conference on Robot and Human Interactive Communication (RO-MAN), pages 807–813. IEEE, 2020. [68] Dmitry Berenson, Siddhartha Srinivasa, and James Kuffner. Task space regions: A framework for poseconstrained manipulation planning. The International Journal of Robotics Research, 30(12):1435–1460, 2011. [69] Felix Burget, Armin Hornung, and Maren Bennewitz. Whole-body motion planning for manipulation of articulated objects. In 2013 IEEE International Conference on Robotics and Automation, pages 1656–1662. IEEE, 2013. [70] Zachary Kingston, Mark Moll, and Lydia E Kavraki. Sampling-based methods for motion planning with constraints. Annual review of control, robotics, and autonomous systems, 1:159–185, 2018. [71] Wim Meeussen, Melonee Wise, Stuart Glaser, Sachin Chitta, Conor McGann, Patrick Mihelich, Eitan Marder-Eppstein, Marius Muja, Victor Eruhimov, Tully Foote, et al. Autonomous door opening and plugging in with a personal robot. In 2010 IEEE International Conference on Robotics and Automation, pages 729–736. IEEE, 2010. [72] Advait Jain and Charles C Kemp. Pulling open doors and drawers: Coordinating an omni-directional base and a compliant arm with equilibrium point control. In 2010 IEEE International Conference on Robotics and Automation, pages 1807–1814. IEEE, 2010. [73] Steven Dalton, Iuri Frosio, and Michael Garland. Accelerating reinforcement learning through gpu atari emulation. In Conference on Neural Information Processing Systems (NeurIPS), 2020. [75] Lasse Espeholt, Hubert Soyer, Remi Munos, Karen Simonyan, Vlad Mnih, Tom Ward, Yotam Doron, Vlad Firoiu, Tim Harley, Iain Dunning, et al. Impala: Scalable distributed deep-rl with importance weighted actor-learner architectures. In International Conference on Machine Learning, pages 1407–1416. PMLR, 2018. [76] Lasse Espeholt, Raphaël Marinier, Piotr Stanczyk, Ke Wang, and Marcin Michalski. Seed rl: Scalable and efficient deep-rl with accelerated central inference. arXiv preprint arXiv:1910.06591, 2019. [77] Aleksei Petrenko, Zhehui Huang, Tushar Kumar, Gaurav Sukhatme, and Vladlen Koltun. Sample factory: Egocentric 3D control from pixels at 100000 FPS with asynchronous reinforcement learning. In International Conference on Machine Learning, pages 7652–7662. PMLR, 2020. [78] Brennan Shacklett, Erik Wijmans, Aleksei Petrenko, Manolis Savva, Dhruv Batra, Vladlen Koltun, and Kayvon Fatahalian. Large batch simulation for deep reinforcement learning. In International Conference on Learning Representations (ICLR), 2021. URL https://openreview.net/forum? id=cP5IcoAkfKa. [79] Binomial LLC. Basis universal. https://github.com/BinomialLLC/basis_universal, 2020. [80] Ioan A Sucan, Mark Moll, and Lydia E Kavraki. The open motion planning library. IEEE Robotics & Automation Magazine, 19(4):72–82, 2012. [81] John Schulman, Filip Wolski, Prafulla Dhariwal, Alec Radford, and Oleg Klimov. Proximal policy optimization algorithms. arXiv preprint arXiv:1707.06347, 2017. [82] Diederik P Kingma and Jimmy Ba. Adam: A method for stochastic optimization. arXiv preprint arXiv:1412.6980, 2014. [83] David Coleman, Ioan Sucan, Sachin Chitta, and Nikolaus Correll. Reducing the barrier to entry of complex robotic software: a moveit! case study. arXiv preprint arXiv:1404.3785, 2014. [84] James J Kuffner and Steven M LaValle. Rrt-connect: An efficient approach to single-query path planning. In Proceedings 2000 ICRA. Millennium Conference. IEEE International Conference on Robotics and Automation. Symposia Proceedings (Cat. No. 00CH37065), volume 2, pages 995–1001. IEEE, 2000. [85] Yoshiaki Kuwata, Gaston A Fiore, Justin Teo, Emilio Frazzoli, and Jonathan P How. Motion planning for urban driving using rrt. In 2008 IEEE/RSJ International Conference on Intelligent Robots and Systems, pages 1681–1686. IEEE, 2008. [86] Nathan Ratliff, Matt Zucker, J Andrew Bagnell, and Siddhartha Srinivasa. Chomp: Gradient optimization techniques for efficient motion planning. In 2009 IEEE International Conference on Robotics and Automation, pages 489–494. IEEE, 2009. [87] John Schulman, Yan Duan, Jonathan Ho, Alex Lee, Ibrahim Awwal, Henry Bradlow, Jia Pan, Sachin Patil, Ken Goldberg, and Pieter Abbeel. Motion planning with sequential convex optimization and convex collision checking. The International Journal of Robotics Research, 33(9):1251–1270, 2014. [88] Carlos Hernandez, Mukunda Bharatheesha, Wilson Ko, Hans Gaiser, Jethro Tan, Kanter van Deurzen, Maarten de Vries, Bas Van Mil, Jeff van Egmond, Ruben Burger, et al. Team delft’s robot winner of the amazon picking challenge 2016. In Robot World Cup, pages 613–624. Springer, 2016. [89] Mustafa Mukadam, Jing Dong, Xinyan Yan, Frank Dellaert, and Byron Boots. Continuous-time gaussian process motion planning via probabilistic inference. The International Journal of Robotics Research, 37 (11):1319–1340, 2018. [90] Brian Ichter, James Harrison, and Marco Pavone. Learning sampling distributions for robot motion planning. In 2018 IEEE International Conference on Robotics and Automation (ICRA), pages 7087–7094. IEEE, 2018. [91] Brian Hou, Sanjiban Choudhury, Gilwoo Lee, Aditya Mandalika, and Siddhartha S Srinivasa. Posterior sampling for anytime motion planning on graphs with expensive-to-evaluate edges. In 2020 IEEE International Conference on Robotics and Automation (ICRA), pages 4266–4272. IEEE, 2020. [92] Fahad Islam, Chris Paxton, Clemens Eppner, Bryan Peele, Maxim Likhachev, and Dieter Fox. Alternative paths planner (app) for provably fixed-time manipulation planning in semi-structured environments. arXiv preprint arXiv:2012.14970, 2020. [93] Michael Pantic, Lionel Ott, Cesar Cadena, Roland Siegwart, and Juan Nieto. Mesh manifold based riemannian motion planning for omnidirectional micro aerial vehicles. arXiv preprint arXiv:2102.10313, 2021. [94] Jonathan D Gammell, Siddhartha S Srinivasa, and Timothy D Barfoot. Informed rrt\*: Optimal samplingbased path planning focused via direct sampling of an admissible ellipsoidal heuristic. In 2014 IEEE/RSJ International Conference on Intelligent Robots and Systems, pages 2997–3004. IEEE, 2014. [95] Jonathan D Gammell, Siddhartha S Srinivasa, and Timothy D Barfoot. Batch informed trees (bit\*): Sampling-based optimal planning via the heuristically guided search of implicit random geometric graphs. In 2015 IEEE international conference on robotics and automation (ICRA), pages 3067–3074. IEEE, 2015. [96] Daniel Kappler, Franziska Meier, Jan Issac, Jim Mainprice, Cristina Garcia Cifuentes, Manuel Wüthrich, Vincent Berenz, Stefan Schaal, Nathan Ratliff, and Jeannette Bohg. Real-time perception meets reactive motion generation. IEEE Robotics and Automation Letters, 3(3):1864–1871, 2018. [97] Morgan Quigley, Ken Conley, Brian Gerkey, Josh Faust, Tully Foote, Jeremy Leibs, Rob Wheeler, and Andrew Y Ng. Ros: an open-source robot operating system. In ICRA workshop on open source software, volume 3, page 5. Kobe, Japan, 2009. [98] Aleksandra Faust, Kenneth Oslund, Oscar Ramirez, Anthony Francis, Lydia Tapia, Marek Fiser, and James Davidson. Prm-rl: Long-range robotic navigation tasks by combining reinforcement learning and sampling-based planning. In 2018 IEEE International Conference on Robotics and Automation (ICRA), pages 5113–5120. IEEE, 2018. [99] Mohak Bhardwaj, Byron Boots, and Mustafa Mukadam. Differentiable gaussian process motion planning. In 2020 IEEE International Conference on Robotics and Automation (ICRA), pages 10598–10604. IEEE, 2020. [100] Dmitry Berenson, Siddhartha S Srinivasa, Dave Ferguson, and James J Kuffner. Manipulation planning on constraint manifolds. In 2009 IEEE international conference on robotics and automation, pages 625–632. IEEE, 2009. [101] Naoki Yokoyama, Sehoon Ha, and Dhruv Batra. Success weighted by completion time: A dynamics-aware evaluation criteria for embodied navigation. arXiv preprint arXiv:2103.08022, 2021. [102] Ilya Kostrikov, Denis Yarats, and Rob Fergus. Image augmentation is all you need: Regularizing deep reinforcement learning from pixels. In International Conference on Learning Representations (ICLR), 2021. [103] 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 Proceedings of the IEEE International Conference on Computer Vision (ICCV), 2017. [104] Akanksha Atrey, Kaleigh Clary, and David Jensen. Exploratory not explanatory: Counterfactual analysis of saliency maps for deep reinforcement learning. In International Conference on Learning Representations (ICLR), 2020. URL https://openreview.net/forum?id=rkl3m1BFDB. [105] Julius Adebayo, Justin Gilmer, Ian Goodfellow, Moritz Hardt, and Been Kim. Sanity checks for saliency maps. In Conference on Neural Information Processing Systems (NeurIPS), 2018.
# Checklist
1. For all authors...
(a) Do the main claims made in the abstract and introduction accurately reflect the paper’s contributions and scope? [Yes] (b) Did you describe the limitations of your work? [Yes] See second paragraph of Sec. 7. (c) Did you discuss any potential negative societal impacts of your work? [Yes] See the first paragraph of Sec. 7. (d) Have you read the ethics review guidelines and ensured that your paper conforms to them? [Yes]
2. If you are including theoretical results...
(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]
3. If you ran experiments...
(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] Code and setup instructions can be found at https://github.com/facebookresearch/habitat-lab. (b) Did you specify all the training details (e.g., data splits, hyperparameters, how they were chosen)? [Yes] All methods and training details are described in detail in Sec. H. (c) Did you report error bars (e.g., with respect to the random seed after running experiments multiple times)? [Yes] Results in Sec. 5 are over three random seeds and 600 episodes each. Results in Sec. F.1 and Sec. F.3 are over 10 random seeds and 500 episodes each. Finally, results in Sec. 6 are over 100 episodes. (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] Compute resources for the benchmark are described in Section 4, for RL training in Appendix C.2, and for motion planning in Appendix D.
4. If you are using existing assets (e.g., code, data, models) or curating/releasing new assets...
(a) If your work uses existing assets, did you cite the creators? [Yes] Cited [59] for use of the YCB objects. (b) Did you mention the license of the assets? [Yes] ReplicaCAD is released under the Creative Commons license and $\mathrm { H } 2 . 0$ is open-sourced under the MIT license (c) Did you include any new assets either in the supplemental material or as a URL? [Yes] The ReplicaCAD dataset will be made publicly available for free prior to publication under the Creative Commons license. Download instructions can be found at https://github.com/facebookresearch/habitatlab. (d) Did you discuss whether and how consent was obtained from people whose data you’re using/curating? [N/A] (e) Did you discuss whether the data you are using/curating contains personally identifiable information or offensive content? [N/A] The released ReplicaCAD dataset includes furniture layouts and common kitchen items. There is no identifiable or offensive content.
5. If you used crowdsourcing or conducted research with human subjects...
(a) Did you include the full text of instructions given to participants and screenshots, if applicable? [N/A] (b) Did you describe any potential participant risks, with links to Institutional Review Board (IRB) approvals, if applicable? [N/A] (c) Did you include the estimated hourly wage paid to participants and the total amount spent on participant compensation? [N/A]123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260# RAT-SQL: RELATION-AWARE SCHEMA ENCODING AND LINKING FOR TEXT-TO-SQL PARSERS
Anonymous authors Paper under double-blind review
# ABSTRACT
When translating natural language questions into SQL queries to answer questions from a database, contemporary semantic parsing models struggle to generalize to unseen database schemas. The generalization challenge lies in (a) encoding the database relations in an accessible way for the semantic parser, and (b) modeling alignment between database columns and their mentions in a given query. We present a unified framework, based on the relation-aware self-attention mechanism, to address schema encoding, schema linking, and feature representation within a text-to-SQL encoder. On the challenging Spider dataset this framework boosts the exact match accuracy to $5 3 . 7 \%$ , compared to $4 7 . 4 \%$ for the state-of-the-art model unaugmented with BERT embeddings. In addition, we observe qualitative improvements in the model’s understanding of schema linking and alignment.
# 1 INTRODUCTION
The ability to effectively query databases with natural language has the potential to unlock the power of large datasets to the vast majority of users who are not proficient in query languages. As such, a large body of research has focused on the task of translating natural language questions into queries that existing database software can execute.
The release of large annotated datasets containing questions and the corresponding database SQL queries has catalyzed progress in the field, by enabling the training of supervised learning models for the task. In contrast to prior semantic parsing datasets (Finegan-Dollak et al., 2018), new tasks such as WikiSQL (Zhong et al., 2017) and Spider (Yu et al., 2018b) pose the real-life challenge of generalization to unseen database schemas. Every query is conditioned on a multi-table database schema, and the databases do not overlap between the train and test sets.
Schema generalization is challenging for three interconnected reasons. First, any text-to-SQL semantic parsing model must encode a given schema into column and table representations suitable for decoding a SQL query that might involve any of the given columns or tables. Second, these representations should encode all the information about the schema, including its column types, foreign key relations, and primary keys used for database joins. Finally, the model must recognize natural language used to refer to database columns and tables, which might differ from the referential language seen in training. The latter challenge is known as schema linking – aligning column/table references in the question to the corresponding schema columns/tables.
 Figure 1: A challenging text-to-SQL task from the Spider dataset.
While the question of schema encoding has been studied in recent literature (Bogin et al., 2019b), schema linking has been relatively less explored. Consider the example in Figure 1. It illustrates the challenge of ambiguity in linking: while “model” in the question refers to car_names.model rather than model_list.model, “cars” actually refers to both cars_data and car_names (but not car_makers) for the purpose of table joining. To resolve the column/table references properly, the semantic parser must take into account both the known schema relations (e.g. foreign keys) and the question context.
Prior work (Bogin et al., 2019b) addressed the schema representation problem by encoding the directed graph of foreign key relations among the columns with a graph neural network. While effective, this approach has two important shortcomings. First, it does not contextualize schema encoding with the question, thus making it difficult for the model to reason about schema linking after both the column representations and question word representations have been built. Second, it limits information propagation during schema encoding to predefined relations in the schema such as foreign keys. The advent of self-attentional mechanisms in natural language processing (Vaswani et al., 2017) shows that global reasoning is crucial to building effective representations of relational structures. However, we would like any global reasoning to also take into account the aforementioned predefined schema relations.
In this work, we present a unified framework, called RAT-SQL,1 for encoding relational structure in the database schema and a given question. It uses relation-aware self-attention to combine global reasoning over the schema entities and question words with structured reasoning over predefined schema relations. We then apply RAT-SQL to the problems of schema encoding and schema linking. As a result, we obtain $5 3 . 7 \%$ exact match accuracy on the Spider test set. At the time of writing, this result is the state of the art among models unaugmented with pretrained BERT embeddings. In addition, we experimentally demonstrate that RAT-SQL enables the model to build more accurate internal representations of the question’s true alignment with schema columns and tables.
# 2 RELATED WORK
Semantic parsing of natural language to SQL queries recently surged in popularity thanks to the creation of two new multi-table datasets with the challenge of schema generalization – WikiSQL (Zhong et al., 2017) and Spider (Yu et al., 2018b). Schema encoding is not as challenging in WikiSQL as in Spider thanks to the lack of multi-table relations. Schema linking is relevant for both tasks but also more challenging in Spider due to the richer natural language expressiveness and less restricted SQL grammar observed in it. Indeed, the state of the art semantic parser on WikiSQL (He et al., 2019) achieves a test set accuracy of $9 1 . 8 \%$ , significantly higher than the state of the art on Spider.
The recent state-of-the-art models evaluated on Spider use various attentional architectures for question/schema encoding and AST-based structural architectures for query decoding. IRNet (Guo et al., 2019) encodes the question and schema separately with LSTM and self-attention respectively, augmenting them with custom type vectors for schema linking. They further use the AST-based decoder of Yin and Neubig (2017) to decode a query in an intermediate representation (IR) that exhibits higher-level abstraction structure than SQL. Bogin et al. (2019b) encode the schema with a graph neural network and a similar grammar-based decoder. Both approaches highlight the importance of schema encoding and schema linking, but design separate feature engineering techniques to augment word vectors (as opposed to relations between words and columns) to resolve it. In contrast, the relational framework of RAT-SQL provides a unified way to encode arbitrary relational information among the inputs.
Concurrently with this work, Bogin et al. (2019a) published Global-GNN, a different approach to schema linking for Spider which applies global reasoning between question words and schema columns/tables. Global reasoning is implemented by gating the graph neural network that computes the representation of schema elements using question token representations. This conceptually differs from RAT-SQL in two important ways: (a) question word representations influence the schema representations but not vice versa, and (b) like in other GNN-based encoding approaches, message propagation is limited to the schema-induced edges such as foreign key relations. In contrast, our relation-aware transformer mechanism allows encoding arbitrary relations between question words and schema elements explicitly, and these representations are computed jointly using self-attention.
 Figure 2: An illustration of an example schema as a graph. We do not depict all edges and label types of Table 1 to reduce clutter.
We use the same formulation of relation-aware self-attention as Shaw et al. (2018). However, that work only applied it to sequences of words in the context of machine translation, and as such, their set of relation types only encoded the relative distance between two words. We extend their work and show that relation-aware self-attention can effectively encode more complex relationships that exist within an unordered sets of elements (in this case, columns and tables within a database schema as well as relations between the schema and the question). To the best of our knowledge, this is the first application of relation-aware self-attention to joint representation learning with both predefined and softly induced relations in the input structure.
# 3 RAT-SQL
We now describe the RAT-SQL framework and its application to the problems of schema encoding and linking. First, we formally define the text-to-SQL semantic parsing problem and its components. Then, we introduce the relation-aware self-attention mechanism, our framework for jointly encoding relational structure between the question and the schema. Finally, we present our implementation of schema linking in the RAT-SQL framework.
# 3.1 PROBLEM DEFINITION
Given a natural language question $Q$ and a schema $s = \langle \mathcal { C } , \mathcal { T } \rangle$ for a relational database, our goal is to generate the corresponding SQL $P$ . Here the question $Q = q _ { 1 } \ldots q _ { | Q | }$ is a sequence of words, and the schema consists of columns $\mathcal { C } = \{ c _ { 1 } , \ldots , c _ { | \mathcal { C } | } \}$ and tables $\mathcal { T } = \left\{ t _ { 1 } , \dots , t _ { | T | } \right\}$ . Each column name $c _ { i }$ contains words $c _ { i , 1 } , \ldots , c _ { i , \left| \boldsymbol { c } _ { i } \right| }$ and each table name $t _ { i }$ contains words $t _ { i , 1 } , \ldots , t _ { i , | t _ { i } | }$ . The desired program $P$ is represented as an abstract syntax tree $T$ in the context-free grammar of SQL.
Some columns in the schema are primary keys, used for uniquely indexing the corresponding table, and some are foreign keys, used to reference a primary key column in a different table. As described in Section 1, we would like to softly bias our schema encoding mechanism toward these predefined relations. In addition, each column has a type $\tau$ such as number or text.
Schema linking aims at finding the alignment between question words and mentioned columns or tables. It’s a crucial step for a parser to generate the right columns and tables in SQL. We model the latent alignment explicitly using an alignment matrix (Section 3.6), which is softly biased towards some string-match based relations, as inspired by Guo et al. (2019).
# 3.2 ENCODING THE SCHEMA AS A GRAPH
To support reasoning about relationships between schema elements in the encoder, we begin by representing the database schema using a directed graph $\mathcal { G }$ , where each node and edge has a label. We represent each table and column in the schema as a node in this graph, labeled with the words in the name; for columns, we prepend the type of the column to the label. For each pair of nodes $x$ and $y$ in the graph, Table 1 describes when there exists an edge from $x$ to $y$ and the label it should have. Figure 2 illustrates an example graph (although not all edges and labels are shown).
 Figure 3: Overview of the stages of our approach.
# 3.3 INITIAL ENCODING OF THE INPUT
We now obtain an initial representation for each of the nodes in the graph, as well as for the words in the input question. For the graph nodes, we use a bidirectional LSTM (BiLSTM) over the words contained in the label. We concatenate the output of the initial and final time steps of this LSTM to form the embedding for the node. For the question, we also use a bidirectional LSTM over the words:
$$\begin{array} { r l } & { c _ { i , 0 } ^ { \mathrm { f w d } } , c _ { i , 0 } ^ { \mathrm { r e v } } ) \cdot \cdot \cdot , ( c _ { i , | c _ { i } | } ^ { \mathrm { f w d } } , c _ { i , | c _ { i } | } ^ { \mathrm { r e v } } ) = \mathrm { B i L S T M } _ { \mathrm { C o h m m } } ( c _ { i } ^ { \mathrm { t p e } } , c _ { i , 1 } , \cdot \cdot , c _ { i , | c _ { i } | } ) ; \quad c _ { i } ^ { \mathrm { i n t } } = \mathrm { C o n c a t } ( c _ { i , | c _ { i } | } ^ { \mathrm { f w d } } , c _ { i , 0 } ^ { \mathrm { r e v } } ) } \\ & { ( t _ { i , 1 } ^ { \mathrm { f w d } } , t _ { i , 1 } ^ { \mathrm { r e v } } ) \cdot \cdot \cdot , ( t _ { i , | c _ { i } | } ^ { \mathrm { f w d } } , t _ { i , | i _ { i } | } ^ { \mathrm { r e v } } ) = \mathrm { B i L S T M } _ { \mathrm { T a b s } } ( t _ { i , 1 } , \cdot \cdot , t _ { i , | t _ { i } | } ) ; \quad t _ { i } ^ { \mathrm { i n t } } = \mathrm { C o n c a t } ( t _ { i , | c _ { i } | } ^ { \mathrm { f w d } } , t _ { i , 1 } ^ { \mathrm { r e v } } ) } \\ & { ( q _ { 1 } ^ { \mathrm { f w d } } , q _ { 1 } ^ { \mathrm { r e v } } ) , \cdot \cdot \cdot , ( q _ { | Q | } ^ { \mathrm { f w d } } , q _ { | Q | } ^ { \mathrm { r e v } } ) = \mathrm { B i L S T M } _ { \mathrm { Q u e s i o n } } ( q _ { 1 } , \cdot \cdot \cdot , q _ { | Q | } ) ; \quad q _ { i } ^ { \mathrm { i n t } } = \mathrm { C o n c a t } ( q _ { i } ^ { \mathrm { f w d } } , q _ { i } ^ { \mathrm { r e v } } ) } \end{array}$$
where each of the BiLSTM functions first lookup word embeddings for each of the input tokens. The LSTMs do not share any parameters.
# 3.4 RELATION-AWARE TRANSFORMER
At this point, we have representations $c _ { i } ^ { \mathrm { i n i t } } , t _ { i } ^ { \mathrm { i n i t } }$ , and $\pmb q _ { i } ^ { \mathrm { i n i t } }$ . Similar to encoders used in some previous papers, these initial representations are independent of each other (uninfluenced by which other columns or tables are present). Now, we would like to imbue these representations with the information in the schema graph. We use a form of self-attention (Vaswani et al., 2017) that is relation-aware (Shaw et al., 2018) to achieve this goal.
In one step of relation-aware self-attention, we begin with an input $_ { \textbf { \em x } }$ of $n$ elements (where $x _ { i } \in \mathbb { R } ^ { d _ { x } } .$ ) and transform each $x _ { i }$ into $y _ { i } \in \mathbb { R } ^ { d _ { x } }$ . We follow the formulation described in Shaw et al. (2018):
$$\begin{array} { r l } & { e _ { i j } ^ { ( h ) } = \cfrac { x _ { i } W _ { Q } ^ { ( h ) } ( x _ { j } W _ { K } ^ { ( h ) } + r _ { i j } ^ { K } ) ^ { T } } { \sqrt { d _ { z } / H } } ; \quad \alpha _ { i j } ^ { ( h ) } = \cfrac { \exp ( e _ { i j } ^ { ( h ) } ) } { \sum _ { l = 1 } ^ { n } \exp ( e _ { i l } ^ { ( h ) } ) } } \\ & { z _ { i } ^ { ( h ) } = \displaystyle \sum _ { j = 1 } ^ { n } \alpha _ { i j } ^ { ( h ) } ( x _ { j } W _ { V } ^ { ( h ) } + r _ { i j } ^ { V } ) ; \quad z _ { i } = \mathrm { C o n c a t } ( z _ { i } ^ { ( 1 ) } , \cdots , z _ { i } ^ { ( H ) } ) } \\ & { \tilde { y } _ { i } = \mathrm { L a y e r N o r m } ( x _ { i } + z _ { i } ) ; \quad y _ { i } = \mathrm { L a y e r N o r m } ( \tilde { y } _ { i } + \mathrm { F C } ( \mathrm { R e L U } ( \mathrm { F C } ( \tilde { y } _ { i } ) ) ) } \end{array}$$
where FC is a fully-connected layer, $1 \leq h \leq H$ , and $W _ { Q } ^ { ( h ) } , W _ { K } ^ { ( h ) } , W _ { V } ^ { ( h ) } \in \mathbb { R } ^ { d _ { x } \times ( d _ { x } / H ) }$ . The $r _ { i j }$ terms encode the relationship between the two elements $x _ { i }$ and $x _ { j }$ in the input. We explain how we obtain $r _ { i j }$ in the next part.
Application Within Our Encoder At the start, we construct the input $x$ of $| c | + | t | + | q |$ elements using $c _ { i } ^ { \mathrm { i n i t } } , t _ { i } ^ { \mathrm { i n i t } }$ , and $\pmb q _ { i } ^ { \mathrm { i n i t } }$ :
$$\boldsymbol { x } = ( \boldsymbol { c } _ { 1 } ^ { \mathrm { { i n i t } } } , \cdot \cdot \cdot , \boldsymbol { c } _ { | \mathcal { C } | } ^ { \mathrm { { i n i t } } } , t _ { 1 } ^ { \mathrm { { i n i t } } } , \cdot \cdot \cdot , t _ { | \mathcal { T } | } ^ { \mathrm { { i n i t } } } , \boldsymbol { q } _ { 1 } ^ { \mathrm { { i n i t } } } , \cdot \cdot \cdot , \boldsymbol { q } _ { | \mathcal { Q } | } ^ { \mathrm { { i n i t } } } ) .$$
We then apply a stack of $N$ relation-aware self-attention layers, where $N$ is a hyperparameter. The weights of the encoder layers are not tied; each layer has its own set of weights. After processing through the stack of $N$ encoder layers, we obtain
$$\begin{array} { r } { ( c _ { 1 } ^ { \mathrm { f i n a l } } , \cdot \cdot \cdot , c _ { | \mathcal { C } | } ^ { \mathrm { f i n a l } } , t _ { 1 } ^ { \mathrm { f i n a l } } , \cdot \cdot \cdot , t _ { | \mathcal { T } | } ^ { \mathrm { f i n a l } } , q _ { 1 } ^ { \mathrm { f i n a l } } , \cdot \cdot \cdot , q _ { | \mathcal { Q } | } ^ { \mathrm { f i n a l } } ) = y . } \end{array}$$
Table 1: Description of edge types present in the directed graph created to represent the schema. An edge exists from source node $x \in S$ to target node $y \in S$ if the pair fulfills one of the descriptions listed in the table, with the corresponding label. Otherwise, no edge exists from $x$ to $y$ .
<table><tr><td></td><td>Type of xType of y</td><td>Edge label</td><td>Description</td></tr><tr><td rowspan="3">Column</td><td rowspan="3">Column</td><td>SAME-TABLE</td><td>x and y belong to the same table.</td></tr><tr><td>FOREIGN-KEY-COL-F</td><td>x is a foreign key for y.</td></tr><tr><td>FOREIGN-KEY-COL-R</td><td>y is a foreign key for x.</td></tr><tr><td rowspan="2">Column</td><td rowspan="2">Table</td><td>PRIMARY-KEY-F</td><td>x is the primary key of y.</td></tr><tr><td>BELONGS-TO-F</td><td>x is a column of y (but not the primary key).</td></tr><tr><td rowspan="2">Table</td><td rowspan="2">Column</td><td>PRIMARY-KEY-R</td><td>y is the primary key of x.</td></tr><tr><td>BELONGS-TO-R</td><td>y is a column of x (but not the primary key).</td></tr><tr><td rowspan="3">Table</td><td rowspan="3">Table</td><td>FOREIGN-KEY-TAB-F</td><td>Table x has a foreign key column in y.</td></tr><tr><td>FOREIGN-KEY-TAB-R</td><td>Same as above,but x and y are reversed.</td></tr><tr><td>FOREIGN-KEY-TAB-B</td><td>x and y have foreign keys in both directions.</td></tr></table>
${ \boldsymbol { c } } _ { i } ^ { \mathrm { f i n a l } } , { \boldsymbol { t } } _ { i } ^ { \mathrm { f i n a l } } ,$ $\pmb q _ { i } ^ { \mathrm { f i n a l } }$
We define a discrete set of possible relation types, and map each type to an embedding to obtain $r _ { i j } ^ { V }$ and $r _ { i j } ^ { K }$ . We need a value of $r _ { i j }$ for every pair of elements in $x$ . In the subsequent sections, we describe the set of relation types we used.
# 3.5 SCHEMA ENCODING
If $x _ { i }$ and $x _ { j }$ both correspond to nodes in $\mathcal { G }$ (i.e. each is either a column or table) with an edge from $x _ { i }$ to $x _ { j }$ , then we use the label on that edge (possibilities listed in Table 1) for $r _ { i j }$ . However, this is not sufficient to obtain $r _ { i j }$ for every pair of $i$ and $j$ . The graph $\mathcal { G }$ has no nodes corresponding to the question words, not every pair of schema nodes has an edge between them, and there is no self-edges (for when $i = j$ ). As such, we add more types beyond what is defined in Table 1:
• If $i = j$ , then COLUMN-IDENTITY or TABLE-IDENTITY. • $x _ { i } \in$ question, $x _ { j } ~ \in$ question: QUESTION-DIST- $d$ , where $d = \mathrm { c l i p } ( j - i , D )$ ; $ \mathrm { c l i p } ( a , D ) =$ $\operatorname* { m a x } ( - D , \operatorname* { m i n } ( \tilde { D _ { \mathbf { \nu } } } , a ) )$ . We use $D = 2$ . • $x _ { i } \in$ question, $x _ { j } \in \mathsf { c o l u m n } \cup$ table; or $x _ { i } \in$ column ∪ table, $x _ { j } \in$ question: see Section 3.6. • Otherwise, one of COLUMN-COLUMN, COLUMN-TABLE, TABLE-COLUMN, or TABLE-TABLE.
# 3.6 SCHEMA LINKING
To aid the model with aligning column/table references in the question to the corresponding schema columns/tables, we furthermore define relation types which indicate when parts of the question textually match the names of the columns and tables. Specifically, for all n-grams of length 1 to 5 in the question, we determine (1) whether it exactly matches the name of a column/table (exact match); or (2) whether the n-gram is a subsequence of the name of a column/table (partial match).2
Therefore, for the case where $x _ { i } \in$ question, $x _ { j } \in$ column ∪ table; or $x _ { i } \in$ column ∪ table, $x _ { j } \in$ question, we set $r _ { i j }$ to QUESTION-COLUMN-M, QUESTION-TABLE-M, COLUMN-QUESTIONM or TABLE-QUESTION-M depending on the type of $x _ { i }$ and $x _ { j }$ . $\mathsf { M }$ is one of EXACTMATCH, PARTIALMATCH, or NOMATCH. In the end, we add $2 + 5 + ( 4 \times \mathsf { \bar { 3 } } ) + 4$ types (one term per bullet in Section 3.5) beyond the 10 in Table 1, for a total of 33 types.
Memory-Schema Alignment Matrix Our intuition suggests that the columns and tables which occur in the SQL $P$ will generally have a corresponding reference in the natural language question (for example, “cars” and “cylinders” in Figure 1). To capture this intuition in the model, we apply relation-aware attention as a pointer mechanism between every memory element in $y$ and all the columns/tables to compute explicit alignment matrices $L ^ { \mathrm { { c o l } } } \in \dot { \mathbb { R } ^ { | y | \times | C | } }$ and $L ^ { \mathrm { t a b } } \in \mathbb { R } ^ { | y | \times | T | }$ :
$$\begin{array} { r l } & { \tilde { L } _ { i , j } ^ { \mathrm { c o l } } = \frac { y _ { i } W _ { Q } ^ { \mathrm { c o l } } ( c _ { j } ^ { \mathrm { f i n a l } } W _ { K } ^ { \mathrm { c o l } } + r _ { i j } ^ { K } ) ^ { T } } { \sqrt { d _ { x } } } ; \quad L _ { i , j } ^ { \mathrm { c o l } } = \frac { \mathrm { e x p } ( \tilde { L } _ { i , j } ^ { \mathrm { c o l } } ) } { \sum _ { k = 1 } ^ { | \mathcal { C } | } \exp ( \tilde { L } _ { i , k } ^ { \mathrm { c o l } } ) } } \\ & { \tilde { L } _ { i , j } ^ { \mathrm { t a b } } = \frac { y _ { i } W _ { Q } ^ { \mathrm { t a b } } ( t _ { j } ^ { \mathrm { f i n a l } } W _ { K } ^ { \mathrm { t a b } } + r _ { i j } ^ { K } ) ^ { T } } { \sqrt { d _ { x } } } ; \quad L _ { i , j } ^ { \mathrm { t a b } } = \frac { \mathrm { e x p } ( \tilde { L } _ { i , j } ^ { \mathrm { t a b } } ) } { \sum _ { k = 1 } ^ { | \mathcal { T } | } \exp ( \tilde { L } _ { i , k } ^ { \mathrm { t a b } } ) } } \end{array}$$
The memory-schema alignment matrix is expected to resemble the real discrete alignments, therefore should respect certain constraints like sparsity. For example, the question word “model” in Figure 1 should be aligned with car_names.model rather than model_list.model or model_- list.model_id. To further bias the soft alignment towards the real discrete structures, we add an auxiliary loss to encourage sparsity of the alignment matrix. Specifically, for a column/table that is mentioned in the SQL query, we treat the model’s current belief of the best alignment as the ground truth. Then we use a cross-entropy loss, referred as alignment loss, to strengthen the model’s belief:
$$a l i g n \_ l o s s = - \frac { 1 } { | R e l ( \mathcal { C } ) | } \sum _ { \substack { j \in R e l ( \mathcal { C } ) } } \log \operatorname* { m a x } _ { i } L _ { i , j } ^ { \mathrm { c o l } } - \frac { 1 } { | R e l ( \mathcal { T } ) | } \sum _ { \substack { j \in R e l ( \mathcal { T } ) } } \log \operatorname* { m a x } _ { i } L _ { i , j } ^ { \mathrm { t a b } }$$
where $R e l ( \mathcal { C } )$ and $R e l ( \tau )$ denote the set of relevant columns and tables that appear in the SQL $P$ .
# 3.7 DECODER
Once we have obtained an encoding of the input, we used the decoder from Yin and Neubig (2017) to generate the SQL $P$ . The decoder generates $P$ as an abstract syntax tree in depth-first traversal order, by using an LSTM to output a sequence of decoder actions that (i) expand the last generated node in the tree according to the grammar, called APPLYRULE; or when necessary to complete the last node, (ii) chooses a column or table from the schema, called SELECTCOLUMN and SELECTTABLE. Formally, we have the following:
$$\operatorname* { P r } ( P \mid y ) = \prod _ { t } \operatorname* { P r } ( a _ { t } \mid a _ { < t } , y )$$
where $y$ is the final encoding of the question and schema from the previous section, and $a _ { < t }$ are all previous actions. We update the LSTM’s state in the following way: $m _ { t } , h _ { t } ~ =$ $f _ { \mathrm { L S T M } } \left( \left[ \pmb { a } _ { t - 1 } \right] \parallel \boldsymbol { z } _ { t } \parallel \boldsymbol { h } _ { p _ { t } } \parallel \pmb { a } _ { p _ { t } } \parallel \pmb { n } _ { f _ { t } } \right]$ , $\mathbf { \bar { \Gamma } } _ { m _ { t - 1 } , h _ { t - 1 } } )$ where $\mathbf { \nabla } m _ { t }$ is the LSTM cell state, $h _ { t }$ is the LSTM output at step $t$ , $\mathbf { } _ { a _ { t - 1 } }$ is the embedding of the previous action, $p _ { t }$ is the step corresponding to expanding the parent AST node of the current node, and $\boldsymbol { n } _ { f _ { t } }$ is the embedding of the current node type. We obtain ${ \boldsymbol { z } } _ { t }$ using multi-head attention (with 8 heads) on $h _ { t - 1 }$ over $y$ .
For APPLYRULE $[ R ]$ , we compute $\operatorname* { P r } ( a _ { t } = \mathrm { A P P L Y R U L E } [ R ] \mid a _ { < t } , y ) = { \mathsf { s o f t m a x } } _ { R } \left( g ( h _ { t } ) \right)$ where $g ( \cdot )$ is a 2-layer MLP with a tanh non-linearity. For SELECTCOLUMN, we compute
$$\tilde { \lambda } _ { i } = \frac { h _ { t } W _ { Q } ^ { \mathrm { s c } } ( y _ { i } W _ { K } ^ { \mathrm { s c } } ) ^ { T } } { \sqrt { d _ { x } } } ; \lambda _ { i } = \frac { \exp ( \tilde { \lambda } _ { i } ) } { \sum _ { j = 1 } ^ { | y | } \tilde { \lambda } _ { j } } ; \operatorname* { P r } ( a _ { t } = \mathrm { S E L E C T C O L U M N } [ i ] \mid a _ { < t } , y ) = \sum _ { j = 1 } ^ { | y | } \lambda _ { j } L _ { j , i } ^ { \mathrm { c o l l } } ;$$
and similarly for SELECTTABLE.
# 4 EXPERIMENTS
# 4.1 EXPERIMENTAL SETUP
We implemented our model using PyTorch (Paszke et al., 2017). During preprocessing, the input of questions, column names and table names are tokenized and lemmatized with the StandfordNLP toolkit (Manning et al., 2014). Within the encoder, we use GloVe (Pennington et al., 2014) word embeddings, held fixed in training except for the 50 most common words in the training set. All word embeddings have dimension 300. The bidirectional LSTMs have hidden size 128 per direction, and use the recurrent dropout method of Gal and Ghahramani (2016) with rate 0.2. We stack 8
Table 2: Our main results (all numbers are exact match $\%$ ).
(a) Accuracy on the Spider development and test sets, compared to the other approaches at the top of the dataset leaderboard as of Sept 24, 2019. The test set results were scored using the Spider evaluation server.
<table><tr><td>Model</td><td>Dev</td><td>Test</td></tr><tr><td>IRNet (Guo et al. (2019)) Global-GNN (Bogin et al. (2019a))</td><td>53.2 52.7</td><td>46.7 47.4</td></tr><tr><td>TPNet (anonymous) RAT-SQL (ours)</td><td>55.4 60.6</td><td>48.5 53.7</td></tr><tr><td>BERT</td><td></td><td></td></tr><tr><td>EditSQL + BERT (Zhang et al.(2019))</td><td>57.6</td><td>53.4</td></tr><tr><td>IRNet+ BERT (Guo et al. (2019))</td><td>61.9</td><td>54.7</td></tr><tr><td>GIRN+BERT (anonymous)</td><td>60.2</td><td>54.8</td></tr><tr><td>TPNet + BERT (anonymous)</td><td>63.9</td><td>55.0</td></tr></table>
(b) Accuracy on the Spider development and test sets, by difficulty as defined by $\mathrm { Y u }$ et al. (2018c).
<table><tr><td>Split</td><td>Easy</td><td>Medium</td><td>Hard</td><td>Extra Hard</td><td>All</td></tr><tr><td>Dev</td><td>80.0</td><td>61.4</td><td>50.6</td><td>40.6</td><td>60.6</td></tr><tr><td>Test</td><td>73.1</td><td>60.1</td><td>45.3</td><td>24.8</td><td>53.7</td></tr></table>
(c) Accuracy (and $\pm 9 5 \%$ confidence interval) of RATSQL ablations on the dev set. Schema linking makes a statistically significant difference $_ { \mathrm { { p < 0 . 0 0 1 } } }$ ).
<table><tr><td>Model</td><td>Accuracy</td></tr><tr><td>RAT-SQL</td><td>58.52 ± 0.84</td></tr><tr><td>RAT-SQL w/o alignment loss</td><td>58.61 ± 0.59</td></tr><tr><td>RAT-SQL w/o schema linking relations</td><td>46.16 ± 1.33</td></tr></table>
relation-aware self-attention layers on top of the bidirectional LSTMs. Within the relation-aware self-attention layers, we set $d _ { x } = d _ { z } = 2 5 6$ , $H = 8$ , and use dropout with rate 0.1. The position-wise feed-forward network has inner layer dimension 1024. Inside the decoder, we use rule embeddings of size 128, node type embeddings of size 64, and a hidden size of 512 inside the LSTM with dropout rate 0.21.
We used the Adam optimizer (Kingma and Ba, 2014) with $\beta _ { 1 } = 0 . 9$ , $\beta _ { 2 } = 0 . 9 9 9$ , and $\epsilon = 1 0 ^ { - 9 }$ , which are defaults in PyTorch. During the first warmup_ $\mathrm { \Delta } \mathrm { \cdot } t e p s = m a x \mathrm { \_ } s t e p s / 2 0$ steps of training, we linearly increase the learning rate from 0 to $7 . 4 \times 1 0 ^ { - 4 }$ . Afterwards, the learning rate is annealed to 0, with formula $\begin{array} { r } { 1 0 ^ { - 3 } ( 1 - \frac { \overline { { s t e p - w a r m u p \_ s t e p s } } } { m a x \_ s t e p s - w a r m u p \_ s t e p s } ) ^ { - 0 . 5 } \_ } \end{array}$ . For all parameters, we used the default initialization method in PyTorch. We use a batch size of 20 and train for up to 40,000 steps.
# 4.2 DATASET AND METRICS
We use the Spider dataset (Yu et al., 2018b) for all our experiments. As described by Yu et al. (2018b), the training data contains 8,659 examples, including 1,659 examples (questions and queries, with the accompanying schemas) from the Restaurants (Popescu et al., 2003; Tang and Mooney, 2000), GeoQuery (Zelle and Mooney, 1996), Scholar (Iyer et al., 2017), Academic (Li and Jagadish, 2014), Yelp and IMDB (Yaghmazadeh et al., 2017) datasets.
As Yu et al. (2018b) make the test set accessible only through an evaluation server, we perform most evaluations (other than the final accuracy measurement) using the development set. It contains 1,034 examples, with databases and schemas distinct from those in the training set. We report results using the same metrics as Yu et al. (2018a): exact match accuracy on all examples, as well as divided by difficulty levels specified in the dataset. As in previous work, these metrics do not measure the model’s performance on generating values within the queries.
# 4.3 RESULTS
In Table 2a we show accuracy on the (hidden) test set for RAT-SQL and compare to all other approaches that are at or near state-of-the-art (according to the official dataset leaderboard). RATSQL outperforms all other methods that, like RAT-SQL, are not augmented with BERT embeddings. It even comes within $1 . 3 \%$ of beating the best BERT-augmented model. Since the typical improvement achieved by BERT augmentation is about $7 \%$ for all models, we are hopeful that adding such augmentation to RAT-SQL will also lead to state-of-the-art performance among BERT models.
We also provide a breakdown of the accuracy by difficulty in Table 2b. As expected, performance drops with increasing difficulty. The overall generalization gap between development and test was strongly affected by the significant drop in accuracy $( 1 5 \% )$ on the extra hard questions.
Schema Linking Table 2c shows an ablation study without RAT-based schema linking relations. Schema linking makes a statistically significant improvement to accuracy $_ { ( \mathrm { p < 0 . 0 0 1 } ) }$ . The full model accuracy here differs from Table 2a because the latter shows the best single model from a hyper-parameter sweep (submitted for test evaluation) and the former gives the mean over ten runs.
 Figure 4: Alignment between the question “For the cars with 4 cylinders, which model has the largest horsepower” and the database car_1 schema (columns and tables).
Alignment Recall from Section 3 that we explicitly represent the alignment between question words and table columns which is used during decoding for column selection. The existence of the alignment matrix provides a mechanism for the model to align words to columns, but the additional terms in the loss encourage it to actually act like an alignment.
In our final model, the alignment loss terms do not make a difference in overall accuracy. This is surprising to us because in earlier development, the alignment loss did improve the model (statistically significantly, from $5 3 . 0 \%$ to $5 5 . 4 \%$ ). We hypothesize that hyper-parameter tuning that caused us to increase encoding depth also eliminated the need for explicit supervision of alignment.
An accurate alignment representation has other benefits as well, such as identifying question words to copy when a constant is needed (not part of the Spider dataset evaluation). In Figure 4 we show the alignment generated by our model on an example from the development set.3 For the three key words that reference columns (“cylinders”, “model”, “horsepower”), the alignment matrix correctly identifies their corresponding column (cylinders, model, horsepower) and the table (cars_data) except it mistakenly aligns ”model” to cars_data also instead of to car_names. The word “cars” aligns to the primary key of the cars_data table.
# 5 CONCLUSION
Despite the abundance of research in semantic parsing of text to SQL, many contemporary models struggle to learn good representations for a given database schema as well as to properly link column/table references in the question. These problems are related: to encode & use columns/tables from the schema, the model must reason about their role in the context of a given question. In this work, we present a unified framework for addressing the schema encoding and linking challenges. Thanks to relation-aware self-attention, it jointly learns schema and question word representations based on their alignment with each other and predefined schema relations.
Empirically, the RAT framework allows us to gain significant state of the art improvement on textto-SQL parsing. Qualitatively, it provides a way to combine predefined hard schema relations and inferred soft self-attended relations in the same encoder architecture. We foresee this joint representation learning being beneficial in many learning tasks beyond text-to-SQL, as long as the input has predefined structure.
# REFERENCES
Ben Bogin, Matt Gardner, and Jonathan Berant. Global reasoning over database structures for text-to-sql parsing. arXiv preprint arXiv:1908.11214, 2019a.
Ben Bogin, Matt Gardner, and Jonathan Berant. Representing schema structure with graph neural networks for text-to-sql parsing. arXiv preprint arXiv:1905.06241, 2019b.
Catherine Finegan-Dollak, Jonathan K. Kummerfeld, Li Zhang, Karthik Ramanathan, Sesh Sadasivam, Rui Zhang, and Dragomir Radev. Improving Text-to-SQL Evaluation Methodology. In Proceedings of the 56th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 351–360. Association for Computational Linguistics, 2018. URL http:// aclweb.org/anthology/P18-1033.
Yarin Gal and Zoubin Ghahramani. A Theoretically Grounded Application of Dropout in Recurrent Neural Networks. In D. D. Lee, M. Sugiyama, U. V. Luxburg, I. Guyon, and R. Garnett, editors, Advances in Neural Information Processing Systems 29, pages 1019– 1027. Curran Associates, Inc., 2016. URL http://papers.nips.cc/paper/6241- a-theoretically-grounded-application-of-dropout-in-recurrentneural-networks.pdf.
Jiaqi Guo, Zecheng Zhan, Yan Gao, Yan Xiao, Jian-Guang Lou, Ting Liu, and Dongmei Zhang. Towards complex text-to-sql in cross-domain database with intermediate representation. arXiv preprint arXiv:1905.08205, 2019.
Pengcheng He, Yi Mao, Kaushik Chakrabarti, and Weizhu Chen. X-sql: reinforce schema representation with context. arXiv preprint arXiv:1908.08113, 2019.
Srinivasan Iyer, Ioannis Konstas, Alvin Cheung, Jayant Krishnamurthy, and Luke Zettlemoyer. Learning a neural semantic parser from user feedback. In Proceedings of the 55th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 963–973, 2017. URL http://www.aclweb.org/anthology/P17-1089.
Diederik P. Kingma and Jimmy Ba. Adam: A Method for Stochastic Optimization. arXiv:1412.6980 [cs], December 2014. URL http://arxiv.org/abs/1412.6980.
Fei Li and H. V. Jagadish. Constructing an interactive natural language interface for relational databases. Proceedings of the VLDB Endowment, 8(1):73–84, September 2014. URL http: //dx.doi.org/10.14778/2735461.2735468.
Christopher D. Manning, Mihai Surdeanu, John Bauer, Jenny Finkel, Steven J. Bethard, and David McClosky. The Stanford CoreNLP natural language processing toolkit. In Association for Computational Linguistics (ACL) System Demonstrations, pages 55–60, 2014. URL http: //www.aclweb.org/anthology/P/P14/P14-5010.
Adam Paszke, Sam Gross, Soumith Chintala, Gregory Chanan, Edward Yang, Zachary DeVito, Zeming Lin, Alban Desmaison, Luca Antiga, and Adam Lerer. Automatic differentiation in PyTorch. October 2017. URL https://openreview.net/forum?id $=$ BJJsrmfCZ.
Jeffrey Pennington, Richard Socher, and Christopher Manning. Glove: Global vectors for word representation. In Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing (EMNLP), pages 1532–1543, Doha, Qatar, October 2014. Association for Computational Linguistics. URL http://www.aclweb.org/anthology/D14-1162.
Ana-Maria Popescu, Oren Etzioni, , and Henry Kautz. Towards a theory of natural language interfaces to databases. In Proceedings of the 8th International Conference on Intelligent User Interfaces, pages 149–157, 2003. URL http://doi.acm.org/10.1145/604045.604070.
Peter Shaw, Jakob Uszkoreit, and Ashish Vaswani. Self-Attention with Relative Position Representations. In Proceedings of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 2 (Short Papers), pages 464–468. Association for Computational Linguistics, 2018. doi: 10.18653/v1/N18-2074. URL http://aclweb.org/anthology/N18-2074.
Lappoon R. Tang and Raymond J. Mooney. Automated construction of database interfaces: Intergrating statistical and relational learning for semantic parsing. In 2000 Joint SIGDAT Conference on Empirical Methods in Natural Language Processing and Very Large Corpora, pages 133–141, 2000. URL http://www.aclweb.org/anthology/W00-1317.
Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Łukasz Kaiser, and Illia Polosukhin. Attention is All you Need. In I. Guyon, U. V. Luxburg, S. Bengio, H. Wallach, R. Fergus, S. Vishwanathan, and R. Garnett, editors, Advances in Neural Information Processing Systems 30, pages 5998–6008. Curran Associates, Inc., 2017. URL http://papers.nips.cc/paper/7181-attention-is-all-you-need.pdf.
Navid Yaghmazadeh, Yuepeng Wang, Isil Dillig, and Thomas Dillig. Sqlizer: Query synthesis from natural language. In International Conference on Object-Oriented Programming, Systems, Languages, and Applications, ACM, pages 63:1–63:26, October 2017. URL http://doi.org/ 10.1145/3133887.
Pengcheng Yin and Graham Neubig. A Syntactic Neural Model for General-Purpose Code Generation. In Proceedings of the 55th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 440–450. Association for Computational Linguistics, 2017. doi: 10.18653/v1/P17-1041. URL http://aclweb.org/anthology/P17-1041.
Tao Yu, Michihiro Yasunaga, Kai Yang, Rui Zhang, Dongxu Wang, Zifan Li, and Dragomir Radev. SyntaxSQLNet: Syntax Tree Networks for Complex and Cross-Domain Text-to-SQL Task. In Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing, pages 1653–1663. Association for Computational Linguistics, 2018a. URL http://aclweb.org/ anthology/D18-1193.
Tao Yu, Rui Zhang, Kai Yang, Michihiro Yasunaga, Dongxu Wang, Zifan Li, James Ma, Irene Li, Qingning Yao, Shanelle Roman, Zilin Zhang, and Dragomir Radev. Spider: A Large-Scale Human-Labeled Dataset for Complex and Cross-Domain Semantic Parsing and Text-to-SQL Task. In Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing, pages 3911–3921, 2018b. URL http://aclweb.org/anthology/D18-1425.
Tao Yu, Rui Zhang, Kai Yang, Michihiro Yasunaga, Dongxu Wang, Zifan Li, James Ma, Irene Li, Qingning Yao, Shanelle Roman, Zilin Zhang, and Dragomir Radev. Spider: A Large-Scale Human-Labeled Dataset for Complex and Cross-Domain Semantic Parsing and Text-to-SQL Task. In Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing, pages 3911–3921. Association for Computational Linguistics, 2018c. URL http://aclweb. org/anthology/D18-1425.
John M. Zelle and Raymond J. Mooney. Learning to parse database queries using inductive logic programming. In Proceedings of the Thirteenth National Conference on Artificial Intelligence - Volume 2, pages 1050–1055, 1996. URL http://dl.acm.org/citation.cfm?id= 1864519.1864543.
Rui Zhang, Tao Yu, He Yang Er, Sungrok Shim, Eric Xue, Xi Victoria Lin, Tianze Shi, Caiming Xiong, Richard Socher, and Dragomir Radev. Editing-based sql query generation for cross-domain context-dependent questions. In Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing. Association for Computational Linguistics, 2019.
Victor Zhong, Caiming Xiong, and Richard Socher. Seq2SQL: Generating Structured Queries from Natural Language using Reinforcement Learning. arXiv:1709.00103 [cs], August 2017. URL http://arxiv.org/abs/1709.00103.
Table 3: Accuracy (exact match $\%$ ) on development set with an oracle providing correct columns and tables (Oractle cols) and/or the AST sketch structure (Oracle sketch).
<table><tr><td>Model</td><td>Accuracy</td></tr><tr><td>RAT-SQL</td><td>60.6</td></tr><tr><td>RAT-SQL + Oracle cols</td><td>67.6</td></tr><tr><td>RAT-SQL + Oracle sketch</td><td>70.9</td></tr><tr><td>RAT-SQL + Oracle sketch + Oracle cols</td><td>99.4</td></tr></table>
# A THE NEED FOR SCHEMA LINKING
One natural question is how often does the decoder fail to select the correct column, even with the schema encoding and linking improvements we have made. To answer this, we conducted an oracle experiment (see Table 3).
For ”oracle sketch”, at every grammar nonterminal the decoder is forced to make the correct choice so the final SQL sketch exactly matches that of the correct answer. The rest of the decoding proceeds as if the decoder had made the choice on its own. Similarly, ”oracle cols” forces the decoder to output the correct column or table at terminal productions.
With both oracles, we see an accuracy of $9 9 . 4 \%$ which just verifies that our grammar is sufficient to answer nearly every question in the data set. With just ”oracle sketch”, the accuracy is only $7 0 . 9 \%$ , which means $7 3 . 5 \%$ of the questions that RAT-SQL gets wrong and could get right have incorrect column or table selection. Similarly, with just ”oracle cols”, the accuracy is $6 7 . 6 \%$ , which means that $8 2 . 0 \%$ of the questions that RAT-SQL gets wrong have incorrect structure. In other words, most questions have both column and structure wrong, so both problems will continue to be important to work on for the future.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321# A RESIZABLE MINI-BATCH GRADIENT DESCENT BASED ON A MULTI-ARMED BANDIT
Anonymous authors Paper under double-blind review
# ABSTRACT
Determining the appropriate batch size for mini-batch gradient descent is always time consuming as it often relies on grid search. This paper considers a resizable mini-batch gradient descent (RMGD) algorithm based on a multi-armed bandit that achieves performance equivalent to that of best fixed batch-size. At each epoch, the RMGD samples a batch size according to a certain probability distribution proportional to a batch being successful in reducing the loss function. Sampling from this probability provides a mechanism for exploring different batch size and exploiting batch sizes with history of success. After obtaining the validation loss at each epoch with the sampled batch size, the probability distribution is updated to incorporate the effectiveness of the sampled batch size. Experimental results show that the RMGD achieves performance better than the best performing single batch size. It is surprising that the RMGD achieves better performance than grid search. Furthermore, it attains this performance in a shorter amount of time than grid search.
# 1 INTRODUCTION
Gradient descent (GD) is a common optimization algorithm for finding the minimum of the expected loss. It takes iterative steps proportional to the negative gradient of the loss function at each iteration. It is based on the observation that if the multi-variable loss functions $f ( w )$ is differentiable at point $\pmb { w }$ , then $f ( w )$ decreases fastest in the direction of the negative gradient of $f$ at $\textbf { \em w }$ , i.e., $- \nabla f ( \boldsymbol { w } )$ . The model parameters are updated iteratively in GD as follows:
$$\pmb { w } _ { t + 1 } = \pmb { w } _ { t } - \eta _ { t } \pmb { g } _ { t } , \qquad \pmb { g } _ { t } = \nabla _ { \pmb { w } } f \big ( \pmb { w } _ { t } \big )$$
where ${ \mathbf { } } w _ { t } , { \mathbf { } } g _ { t }$ , and $\eta _ { t }$ are the model parameters, gradients of $f$ with respect to $\pmb { w }$ , and learning rate at time $t$ respectively. For small enough $\eta _ { t }$ , ${ f ( \pmb { w } _ { t } ) \geq f ( \pmb { w } _ { t + 1 } ) }$ and ultimately the sequence of ${ \pmb w } _ { t }$ will move down toward a local minimum. For a convex loss function, GD is guaranteed to converge to a global minimum with an appropriate learning rate.
There are various issues to consider in gradient-based optimization. First, GD can be extremely slow and impractical for large dataset: gradients of all the data have to be evaluated for each iteration. With larger data size, the convergence rate, the computational cost and memory become critical, and special care is required to minimize these factors. Second, for non-convex function which is often encountered in deep learning, GD can get stuck in a local minimum without the hope of escaping. Third, stochastic gradient descent (SGD), which is based on the gradient of a single training sample, has large gradient variance, and it requires a large number of iterations. This ultimately translates to slow convergence. Mini-batch gradient descent (MGD), which is based on the gradient over a small batch of training data, trades off between the robustness of SGD and the stability of GD. There are three advantages for using MGD over GD and SGD: 1) The batching allows both the efficiency of memory usage and implementations; 2) The model update frequency is higher than GD which allows for a more robust convergence avoiding local minimum; 3) MGD requires less iteration per epoch and provides a more stable update than SGD. For these reasons, MGD has been a popular algorithm for machine learning. However, selecting an appropriate batch size is difficult. Various studies suggest that there is a close link between performance and batch size used in MGD Breuel (2015); Keskar et al. (2016); Wilson & Martinez (2003).
There are various guidelines for selecting a batch size but have not been completely practical Bengio (2012). Grid search is a popular method but it comes at the expense of search time. There are a small number of adaptive MGD algorithms to replace grid search Byrd et al. (2012); De et al. (2016); Friedlander & Schmidt (2012). These algorithms increase the batch size gradually according to their own criterion. However, these algorithms are based on convex loss function and hard to be applied to deep learning. For non-convex optimization, it is difficult to determine the optimal batch size for best performance.
This paper considers a resizable mini-batch gradient descent (RMGD) algorithm based on a multi-armed bandit for achieving best performance in grid search by selecting an appropriate batch size at each epoch with a probability defined as a function of its previous success/failure. At each epoch, RMGD samples a batch size from its probability distribution, then uses the selected batch size for mini-batch gradient descent. After obtaining the validation loss at each epoch, the probability distribution is updated to incorporate the effectiveness of the sampled batch size. The benefit of RMGD is that it avoids the need for cumbersome grid search to achieve best performance and that it is simple enough to apply to any optimization algorithm using MGD. The detailed algorithm of RMGD are described in Section 4, and experimental results are presented in Section 5.
# 2 RELATED WORKS
There are only a few published results on the topic of batch size. It was empirically shown that SGD converged faster than GD on a large speech recognition database Wilson & Martinez (2003). It was determined that the range of learning rate resulting in low test errors was considerably getting smaller as the batch size increased on convolutional neural networks and that small batch size yielded the best test error, while large batch size could not yield comparable low error rate Breuel (2015). It was observed that larger batch size are more liable to converge to a sharp local minimum thus leading to poor generalization Keskar et al. (2016). It was found that the learning rate and the batch size controlled the trade-off between the depth and width of the minima in MGD Jastrzkebski et al. (2017).
A small number of adaptive MGD algorithms have been proposed. Byrd et al. (2012) introduced a methodology for using varying sample size in MGD. A relatively small batch size is chosen at the start, then the algorithm chooses a larger batch size when the optimization step does not produce improvement in the target objective function. They assumed that using a small batch size allowed rapid progress in the early stages, while a larger batch size yielded high accuracy. However, this assumption did not corresponded with later researches that reported the degradation of performance with large batch size Breuel (2015); Keskar et al. (2016); Mishkin et al. (2017). Another similar adaptive algorithm, which increases the batch size gradually as the iteration proceeded, was done by Friedlander & Schmidt (2012). The algorithm uses relatively few samples to approximate the gradient, and gradually increase the number of samples with a constant learning rate. It was observed that increasing the batch size is more effective than decaying the learning rate for reducing the number of iterations Smith et al. (2017). However, these increasing batch size algorithms lack flexibility since it is unidirectional. Balles et al. (2017) proposed a dynamic batch size adaptation algorithm. It estimates the variance of the stochastic gradients and adapts the batch size to decrease the variance. However, this algorithm needs to find the gradient variance and its computation depends on the number of model parameters.
Batch size can also be considered as a hyperparameter, and there have been some proposals based on bandit-based hyperparameter (but not batch size) optimization which maybe applicable for determining the best fixed batch size. Jamieson & Talwalkar (2016) introduced a successive halving algorithm. This algorithm uniformly allocates a budget to a set of hyperparameter configurations, evaluates the performance of all configurations, and throws out the worst half until one configuration remains. Li et al. (2017) introduced a novel bandit-based hyperparameter optimization algorithm referred as HYPERBAND. This algorithm considers the optimization problem as a resource allocation problem. The two algorithms mentioned above are not adaptive, and for searching a small hyperparameter space, the two algorithms will not be very effective. The experimental results in this paper show that adaptive MGD tends to perform better than fixed MGD.
 Figure 1: An overall framework of considered resizable mini-batch gradient descent algorithm (RMGD). The RMGD samples a batch size from a probability distribution, and parameters are updated by mini-batch gradient using the selected batch size. Then the probability distribution is updated by checking the validation loss.
# 3 SETUP
Let $\boldsymbol { B } = \{ b _ { k } \} _ { k = 1 } ^ { K }$ be the set of possible batch size and $\pmb { \pi } = \{ \pi ^ { k } \} _ { k = 1 } ^ { K }$ be the probability distribution of batch size where $b _ { k } , \pi ^ { k }$ , and $K$ are the $k ^ { \mathrm { t h } }$ batch size, the probability of $b _ { k }$ to be selected, and number of batch sizes respectively. This paper considers algorithm for multi-armed bandit over $\boldsymbol { B }$ according to Algorithm 1. Let $\mathbf { \boldsymbol { w } } _ { \tau } \in \mathcal { W }$ be the model parameters at epoch $\tau$ , and $\tilde { \mathbf { \ b { w } } } _ { t }$ be the temporal parameters at sub iteration $t$ . Let $J : \mathcal { W } \mathbb { R }$ be the training loss function and let $\mathbf { \delta } \mathbf { \mathbf { { g } } } = \nabla J ( \mathbf { \delta } \mathbf { \mathbf { { w } } } )$ be the gradients of training loss function with respect to the model parameters. $\eta _ { \tau }$ is the learning rate at epoch $\tau$ . Let $\ell : \mathcal { W } \to \mathbb { R }$ be the validation loss function, and $y ^ { k } \in \{ 0 , \dot { 1 } \}$ be the cost of choosing the batch size $b _ { k }$ . In here, $y ^ { k } = 0$ if the validation loss decreases by the selected batch size $b _ { k }$ (well-updating) and $y ^ { k } = 1$ otherwise (misupdating). The aim of the algorithm is to have low misupdating. For the cost function $y ^ { k }$ , graduated losses such as hinge loss and percentage of nonnegative changes in validation loss can be variations of 0-1 loss. However, there are no differences in regret bound among them in this setting and it is experimentally confirmed that there are little performance gaps among them. Therefore, this paper introduces the 0-1 loss, which is simple and basic.
# 4 RESIZABLE MINI-BATCH GRADIENT DESCENT
The resizable mini-batch gradient descent (RMGD) sets the batch sizes as multi arms, and at each epoch it samples one of the batch sizes from probability distribution. Then, it suffers a cost of selecting this batch size. Using the cost, probability distribution is updated.
# 4.1 ALGORITHMS
The overall framework of the RMGD algorithm is shown in Figure 1. The RMGD consists of two components: batch size selector and parameter optimizer. The selector samples a batch size from probability distribution and updates the distribution. The optimizer is usual mini-batch gradient.
Selector samples a batch size $b _ { k _ { \tau } } \in B$ from the probability distribution $\pi _ { \tau }$ at each epoch $\tau$ where $k _ { \tau }$ is selected index. Here $b _ { k }$ is associated with probability $\pi ^ { k }$ . The selected batch size $b _ { k _ { \tau } }$ is applied to optimizer for MGD at each epoch, and the selector gets cost $y ^ { k _ { \tau } }$ from optimizer. Then, the selector
# Algorithm 1 Resizable Mini-batch Gradient Descent
#
$\begin{array} { r } { B = \{ b _ { k } \} _ { k = 1 } ^ { K } : } \end{array}$ Set of batch sizes $\pi _ { 0 } = \{ 1 / K , \ldots , 1 / K \}$ : Prior probability distribution
# Procedure:
1: Initialize model parameters $\pmb { w } _ { 0 }$ 2: for epoch $\tau = 0 , 1 , 2 , \dots$ 3: Select batch size $b _ { k _ { \tau } } \in B$ from $\pi _ { \tau }$ 4: Set temporal parameters $\tilde { \mathbf { { w } } } _ { 0 } = \mathbf { w } _ { \tau }$ 5: for $t = 0 , 1 , \ldots , T - 1$ where $T = \lceil m / b _ { k _ { \tau } } \rceil$ 6: Compute gradient $\pmb { g } _ { t } = \nabla J ( \tilde { \pmb { w } } _ { t } )$ 7: Update $\tilde { \pmb { w } } _ { t + 1 } = \tilde { \pmb { w } } _ { t } - \eta _ { \tau } \pmb { g } _ { t }$ 8: end for 9: Update ${ \pmb w } _ { \tau + 1 } = \tilde { { \pmb w } } _ { T }$ 10: Observe validation loss $\ell ( w _ { \tau + 1 } )$ 11: if $\ell ( \pmb { w } _ { \tau + 1 } ) < \ell ( \pmb { w } _ { \tau } )$ 12: Get cost $y ^ { k _ { \tau } } = 0$ 13: else 14: Get cost $y ^ { k _ { \tau } } = 1$ 15: end if 16: for $i = 1 , 2 , \dots , K$ 17: if $i = k _ { \tau }$ 18: Set temporal probability π˜i = πi e−βykτ /πiτ 19: else 20: Set temporal probability $\tilde { \pi } ^ { i } = \pi _ { \tau } ^ { i }$ 21: end if 22: end for 23: Update $\begin{array} { r } { \forall i \in [ K ] , \pi _ { \tau + 1 } ^ { i } = \tilde { \pi } ^ { i } / \sum _ { j } \tilde { \pi } ^ { j } } \end{array}$ 24: end for
updates probabilities by randomized weighted majority,
$$\begin{array} { r l } { \mathrm { f o r } i = k _ { \tau } , } & { \tilde { \pi } ^ { i } = \pi _ { \tau } ^ { i } e ^ { - \beta y ^ { k _ { \tau } } / \pi _ { \tau } ^ { i } } } \\ { \mathrm { f o r } i \neq k _ { \tau } , } & { \tilde { \pi } ^ { i } = \pi _ { \tau } ^ { i } } \\ { \forall i , } & { \pi _ { \tau + 1 } ^ { i } = \tilde { \pi } ^ { i } / \sum _ { j } \tilde { \pi } ^ { j } } \end{array}$$
where $\beta \in ( 0 , 1 )$ is positive hyperparameter. When $\tau = 0$ , $\pi _ { \tau } = \{ 1 / K , \ldots , 1 / K \}$
Optimizer updates the model parameters $\pmb { w }$ . For each epoch, temporal parameters $\tilde { \pmb { w } } _ { 0 }$ is set to ${ \pmb w } _ { \tau }$ , and MGD iterates $T = \bar { \lceil m \ / } ^ { } / b _ { k _ { \tau } } \rceil ^ { 1 }$ times using the selected batch size $b _ { k _ { \tau } }$ where $m$ is the total number of training samples:
$$\pmb { \tilde { w } } _ { t + 1 } = \pmb { \tilde { w } } _ { t } - \eta _ { \tau } \pmb { g } _ { t } , \quad \pmb { g } _ { t } = \nabla J \big ( \pmb { \tilde { w } } _ { t } \big ) .$$
After $T$ iterations at epoch $\tau$ , the model parameters is updated as ${ \pmb w } _ { \tau + 1 } = \tilde { { \pmb w } } _ { T }$ . Then, the optimizer obtains validation loss $\ell$ , and outputs cost as follows:
$$y ^ { k _ { \tau } } = \left\{ \begin{array} { l l } { 0 } & { \mathrm { i f ~ } \ell ( { \pmb w } _ { \tau + 1 } ) < \ell ( { \pmb w } _ { \tau } ) } \\ { 1 } & { \mathrm { o t h e r w i s e } } \end{array} \right. .$$
The RMGD samples an appropriate batch size from a probability distribution at each epoch. This probability distribution encourages exploration of different batch size and then later exploits batch size with history of success, which means decreasing validation loss. Figure 2 shows an example of training progress of RMGD. The figure represents the probability distribution with respect to epoch. The white dot represents the selected batch size at each epoch. In the early stage of training, commonly, all batch sizes tend to decrease validation loss: $\pi$ is uniform. Thus, all batch size have equal probability of being sampled (exploration). In the later stages of training, the probability distribution varies based on success and failure. Thus, better performing batch size gets higher probability to be sampled (exploitation). In this case, 256 is the best performing batch size.
 Figure 2: The probability distribution vs epoch using the RMGD. (top) The early stages of the training. (bottom) The later stages of the training. The white dot represents the selected batch size at each epoch. In the early stages of the training, RMGD updates the probabilities to search various batch sizes (exploration), and in the later stages, RMGD increases the probability of successful batch size (exploitation).
# 4.2 REGRET BOUND
The regret bound of the RMGD follows the regret bound derived in Shalev-Shwartz et al. (2012). The goal of this algorithm is to have low regret for not selecting the best performing batch size such that
$$\mathrm { R e g r e t } _ { \mathcal T } ( S ) = \mathbb { E } \left[ \sum _ { \tau = 1 } ^ { \mathcal T } y _ { \tau } ^ { k _ { \tau } } \right] - \operatorname* { m i n } _ { i } \sum _ { \tau = 1 } ^ { \mathcal T } y _ { \tau } ^ { i }$$
where the expectation is over the algorithm’s randomness of batch size selection and the second term on the right-hand side is the cumulative sum of the cost by the best fixed batch size which minimizes the cumulative sum of the cost. The regret of the RMGD is bounded,
$$\mathbb { E } \left[ \sum _ { \tau = 1 } ^ { \mathcal { T } } y _ { \tau } ^ { k _ { \tau } } \right] - \operatorname* { m i n } _ { i } \sum _ { \tau = 1 } ^ { \mathcal { T } } y _ { \tau } ^ { i } \leq \frac { \log K } { \beta } + \beta K \mathcal { T } .$$
In particular, setting $\beta = \sqrt { \log ( K ) / ( K T ) }$ , the regret is bounded by $2 \sqrt { K \log ( K ) \mathcal { T } }$ , which is sublinear with $\tau$ . The detailed derivation of regret bound is described in the appendix A.
# 5 EXPERIMENTS
This section describes various experimental results on MNIST, CIFAR10, and CIFAR100 dataset. In the experiments, simple convolutional neural networks (CNN) is used for MNIST and ‘All-CNN$\mathbf { C } '$ Springenberg et al. (2014) is used for CIFAR10 and CIFAR100. The details of the dataset and experimental settings are presented in the appendix B.
 Figure 3: The probability distribution and selected batch size. The white dot is selected batch size at epoch. (top) The case that small batch size performs better. (middle) The case that large batch size performs better. (bottom) The case that best performing batch size varies.
 Figure 4: The results of test accuracy for the MNIST dataset. The error bar is standard error. (left) The test accuracy of 100 times repeated experiments with AdamOptimizer. (right) The test accuracy of 100 times repeated experiments with AdagradOptimizer. In both cases, most RMGD settings outperform all fixed MGD algorithms.
# 5.1 MNIST DATASET
The validity of the RMGD was assessed by performing image classification on the MNIST dataset using AdamOptimizer and AdagradOptimizer as optimizer. The experiments were repeated 100 times for each algorithm and each optimizer, then the results were analyzed for significance. Figure 3 shows the probability distribution and the selected batch size with respect to epoch during training for the RMGD. The white dot represents the batch size selected at each epoch. The top figure is the case that small batch size (32) performs better. After epoch 50, batch size 32 gets high probability and is selected more than others. It means that batch size 32 has less misupdating in this case. The gradually increasing batch size algorithm may not perform well in this case. The middle figure is the case that large batch size (512) performs better. After epoch 60, batch size 512 gets high probability and selected more than others. The bottom figure shows that the best performing batch size varies with epoch. During epoch from 40 to 55, batch size of 256 performs best, and best performing batch size switches to 128 during epoch from 60 to 70, then better performing batch size backs to 256 after epoch 80. In the results, any batch size can be a successful batch size in the later stages without any particular order. The RMGD is more flexible for such situation than the MGD or directional adaptive MGD such as gradually increasing batch size algorithm.
Figure 4 shows the test accuracy of each algorithm. The error bar is standard error. The number in parenthesis next to MGD represents the batch size used in the MGD. ’Basic’, ’sub’, ’super’, ’hinge’, and ’ratio’ in parenthesis next to RMGD represent RMGD settings ’batch size set equal to grid search, 0-1 loss’, ’subset of basic, 0-1 loss’, ’superset of basic, 0-1 loss’, ’basic set, hinge loss’, and ’basic set, percentage of non-negative changes in validation loss’, respectively. The left figure is the test accuracy with AdamOptimizer. The right figure is the test accuracy with AdagradOptimizer. Among the MGD algorithms, relatively small batch sizes (16 - 64) lead to higher performance than large batch sizes (128 - 512) and batch size 64 achieves the best performance in grid search. These results correspond with other studies Breuel (2015); Keskar et al. (2016); Mishkin et al. (2017). Most RMGD settings outperform all fixed MGD algorithms in both case. Although the performance of RMGD is not significantly increased compared to the best MGD, the purpose of this algorithm is not to improve performance, but to ensure that the best performance is achieved without performing a grid search on the batch size. Rather, the improved performance of the RMGD is a surprising result. Therefore, the RMGD is said to be valid. There are little performance gap among RMGD settings. The ’sub’ setting outperforms the ’basic’ setting in left figure, but the opposite result is shown in right figure. Therefore, there is no clear tendency of performance change depending on the size of the batch size set.
Table 1: Iterations and real time for training, and test accuracy of MNIST classification with AdamOptimizer. The ’total’ is the sum of the average values from MGD 16 to 512, which means the whole grid search is performed.
<table><tr><td rowspan=2 colspan=1>Algorithms</td><td rowspan=2 colspan=1>Iterations</td><td rowspan=2 colspan=1>Real time (sec)</td><td rowspan=1 colspan=3>Test accuracy (%)</td></tr><tr><td rowspan=1 colspan=1>Mean±SD</td><td rowspan=1 colspan=1>Max</td><td rowspan=1 colspan=1>Min</td></tr><tr><td rowspan=1 colspan=1>MGD (16)</td><td rowspan=1 colspan=1>343,800</td><td rowspan=1 colspan=1>1,221.54 ± 36.00</td><td rowspan=1 colspan=1>99.327 ± 0.064</td><td rowspan=1 colspan=1>99.480</td><td rowspan=1 colspan=1>99.140</td></tr><tr><td rowspan=1 colspan=1>MGD (32)</td><td rowspan=1 colspan=1>171,900</td><td rowspan=1 colspan=1>697.82 ± 19.70</td><td rowspan=1 colspan=1>99.322 ± 0.060</td><td rowspan=1 colspan=1>99.500</td><td rowspan=1 colspan=1>99.150</td></tr><tr><td rowspan=1 colspan=1>MGD (64)</td><td rowspan=1 colspan=1>86,000</td><td rowspan=1 colspan=1>379.14 ± 11.32</td><td rowspan=1 colspan=1>99.328 ± 0.058</td><td rowspan=1 colspan=1>99.460</td><td rowspan=1 colspan=1>99.170</td></tr><tr><td rowspan=1 colspan=1>MGD (128)</td><td rowspan=1 colspan=1>43,000</td><td rowspan=1 colspan=1>262.33 ± 2.34</td><td rowspan=1 colspan=1>99.314 ± 0.056</td><td rowspan=1 colspan=1>99.440</td><td rowspan=1 colspan=1>99.170</td></tr><tr><td rowspan=1 colspan=1>MGD (256)</td><td rowspan=1 colspan=1>21,500</td><td rowspan=1 colspan=1>208.13 ± 2.20</td><td rowspan=1 colspan=1>99.295 ± 0.059</td><td rowspan=1 colspan=1>99.470</td><td rowspan=1 colspan=1>99.170</td></tr><tr><td rowspan=1 colspan=1>MGD (512)</td><td rowspan=1 colspan=1>10,800</td><td rowspan=1 colspan=1>180.06 ± 0.37</td><td rowspan=1 colspan=1>99.254 ± 0.054</td><td rowspan=1 colspan=1>99.430</td><td rowspan=1 colspan=1>99.110</td></tr><tr><td rowspan=1 colspan=1>MGD (total)</td><td rowspan=1 colspan=1>677,000</td><td rowspan=1 colspan=1>2,949.02</td><td rowspan=1 colspan=1></td><td rowspan=1 colspan=1></td><td rowspan=1 colspan=1></td></tr><tr><td rowspan=1 colspan=1>RMGD (basic)</td><td rowspan=1 colspan=1>68,309 ± 8,900</td><td rowspan=1 colspan=1>333.73 ± 25.38</td><td rowspan=1 colspan=1>99.342 ± 0.064</td><td rowspan=1 colspan=1>99.480</td><td rowspan=1 colspan=1>99.110</td></tr><tr><td rowspan=1 colspan=1>RMGD (sub)</td><td rowspan=1 colspan=1>85,777 ± 12,112</td><td rowspan=1 colspan=1>400.73 ± 51.91</td><td rowspan=1 colspan=1>99.357± 0.057</td><td rowspan=1 colspan=1>99.510</td><td rowspan=1 colspan=1>99.060</td></tr><tr><td rowspan=1 colspan=1>RMGD (super)</td><td rowspan=1 colspan=1>67,948 ± 6,022</td><td rowspan=1 colspan=1>332.61 ± 22.26</td><td rowspan=1 colspan=1>99.345 ± 0.058</td><td rowspan=1 colspan=1>99.460</td><td rowspan=1 colspan=1>99.110</td></tr><tr><td rowspan=1 colspan=1>RMGD (hinge)</td><td rowspan=1 colspan=1>69,607 ± 8,887</td><td rowspan=1 colspan=1>337.38 ± 25.29</td><td rowspan=1 colspan=1>99.341 ± 0.062</td><td rowspan=1 colspan=1>99.480</td><td rowspan=1 colspan=1>99.130</td></tr><tr><td rowspan=1 colspan=1>RMGD (ratio)</td><td rowspan=1 colspan=1>95,530 ± 8,281</td><td rowspan=1 colspan=1>449.37 ± 26.71</td><td rowspan=1 colspan=1>99.339 ± 0.062</td><td rowspan=1 colspan=1>99.470</td><td rowspan=1 colspan=1>99.150</td></tr></table>
Table 2: Iterations and real time for training, and test accuracy of MNIST classification with AdagradOptimizer.
<table><tr><td rowspan=2 colspan=1>Algorithms</td><td rowspan=2 colspan=1>Iterations</td><td rowspan=2 colspan=1>Real time (sec)</td><td rowspan=1 colspan=3>Test accuracy (%)</td></tr><tr><td rowspan=1 colspan=1>Mean± SD</td><td rowspan=1 colspan=1>Max</td><td rowspan=1 colspan=1>Min</td></tr><tr><td rowspan=1 colspan=1>MGD (16)</td><td rowspan=1 colspan=1>343,800</td><td rowspan=1 colspan=1>1,160.87 ± 22.34</td><td rowspan=1 colspan=1>99.268 ± 0.090</td><td rowspan=1 colspan=1>99.430</td><td rowspan=1 colspan=1>98.920</td></tr><tr><td rowspan=1 colspan=1>MGD (32)</td><td rowspan=1 colspan=1>171,900</td><td rowspan=1 colspan=1>640.68 ± 15.53</td><td rowspan=1 colspan=1>99.270 ± 0.070</td><td rowspan=1 colspan=1>99.410</td><td rowspan=1 colspan=1>99.050</td></tr><tr><td rowspan=1 colspan=1>MGD (64)</td><td rowspan=1 colspan=1>86,000</td><td rowspan=1 colspan=1>367.40 ± 12.63</td><td rowspan=1 colspan=1>99.277 ± 0.077</td><td rowspan=1 colspan=1>99.440</td><td rowspan=1 colspan=1>99.110</td></tr><tr><td rowspan=1 colspan=1>MGD (128)</td><td rowspan=1 colspan=1>43,000</td><td rowspan=1 colspan=1>262.48 ± 1.37</td><td rowspan=1 colspan=1>99.269 ± 0.069</td><td rowspan=1 colspan=1>99.410</td><td rowspan=1 colspan=1>99.080</td></tr><tr><td rowspan=1 colspan=1>MGD (256)</td><td rowspan=1 colspan=1>21,500</td><td rowspan=1 colspan=1>195.60 ± 2.00</td><td rowspan=1 colspan=1>99.240 ± 0.072</td><td rowspan=1 colspan=1>99.390</td><td rowspan=1 colspan=1>99.030</td></tr><tr><td rowspan=1 colspan=1>MGD (512)</td><td rowspan=1 colspan=1>10,800</td><td rowspan=1 colspan=1>170.31 ± 1.41</td><td rowspan=1 colspan=1>99.198 ± 0.085</td><td rowspan=1 colspan=1>99.390</td><td rowspan=1 colspan=1>98.810</td></tr><tr><td rowspan=1 colspan=1>MGD (total)</td><td rowspan=1 colspan=1>677,000</td><td rowspan=1 colspan=1>2,797.34</td><td rowspan=1 colspan=1></td><td rowspan=1 colspan=1></td><td rowspan=1 colspan=1></td></tr><tr><td rowspan=1 colspan=1>RMGD (basic)</td><td rowspan=1 colspan=1>68,159 ± 8,447</td><td rowspan=1 colspan=1>323.33 ± 23.57</td><td rowspan=1 colspan=1>99.286 ± 0.088</td><td rowspan=1 colspan=1>99.490</td><td rowspan=1 colspan=1>98.900</td></tr><tr><td rowspan=1 colspan=1>RMGD (sub)</td><td rowspan=1 colspan=1>81,479 ± 9,141</td><td rowspan=1 colspan=1>356.16 ± 28.06</td><td rowspan=1 colspan=1>99.272 ± 0.092</td><td rowspan=1 colspan=1>99.460</td><td rowspan=1 colspan=1>98.960</td></tr><tr><td rowspan=1 colspan=1>RMGD (super)</td><td rowspan=1 colspan=1>67,638 ± 7,733</td><td rowspan=1 colspan=1>320.38 ± 23.55</td><td rowspan=1 colspan=1>99.280 ± 0.074</td><td rowspan=1 colspan=1>99.410</td><td rowspan=1 colspan=1>99.090</td></tr><tr><td rowspan=1 colspan=1>RMGD (hinge)</td><td rowspan=1 colspan=1>68,199 ± 8,642</td><td rowspan=1 colspan=1>322.33 ± 24.03</td><td rowspan=1 colspan=1>99.282 ± 0.089</td><td rowspan=1 colspan=1>99.420</td><td rowspan=1 colspan=1>98.900</td></tr><tr><td rowspan=1 colspan=1>RMGD (ratio)</td><td rowspan=1 colspan=1>93,523 ± 9,871</td><td rowspan=1 colspan=1>452.69 ± 34.71</td><td rowspan=1 colspan=1>99.283 ± 0.078</td><td rowspan=1 colspan=1>99.480</td><td rowspan=1 colspan=1>99.020</td></tr></table>
Table 1 and 2 present iterations and real time for training, mean, maximum, and minimum of test accuracies for each algorithm with AdamOptimizer and AdagradOptimizer respectively. The MGD (total) is the summation of the iterations and real time of whole MGDs for grid search. The RMGD (basic) outperforms best performing MGD and is, also, faster than best performing MGD. Furthermore, it is 8 times faster than grid search in both cases. In the results, the RMGD is effective regardless of the optimizer.
# 5.2 CIFAR10 AND CIFAR100 DATASET
The CIFAR10 and CIFAR100 dataset were, also, used to assess effectiveness of the RMGD. The experiments were repeated 25 times and 10 times, respectively. In these experiments, all images are whitened and contrast normalized before being input to the network. Figure 5 shows the test accuracy for each algorithm. The left figure represents the test accuracy on CIFAR10. In contrast to the MNIST results, relatively large batch sizes (128 - 256) lead to higher performance than small batch sizes (16 - 64) and batch size 256 achieves the best performance in grid search. The right figure represents the test accuracy on CIFAR100 and batch size 128 achieves the best performance in grid search. The results on MNIST, CIFAR10 and CIFAR100 indicate that it is difficult to know which batch size is optimal before performing a grid search. Meanwhile, all RMGD settings have again exceeded the best performance of fixed MGD. There are no significant performance gaps among RMGD settings, so there is no need to worry about choosing appropriate batch size set or selecting cost function.
 Figure 5: The results of test accuracy for the CIFAR10 and CIFAR100 dataset. The error bar is standard error. (left) The test accuracy of 25 times repeated experiments on CIFAR10. (right) The test accuracy of 10 times repeated experiments on CIFAR100. In both cases, all RMGD settings outperform all fixed MGD algorithms.
Table 3: Iterations and real time for training, and test accuracy on CIFAR10.
<table><tr><td rowspan=2 colspan=1>Algorithms</td><td rowspan=2 colspan=1>Iterations</td><td rowspan=2 colspan=1>Real time (sec)</td><td rowspan=1 colspan=3>Test accuracy (%)</td></tr><tr><td rowspan=1 colspan=1>Mean ± SD</td><td rowspan=1 colspan=1>Max</td><td rowspan=1 colspan=1>Min</td></tr><tr><td rowspan=1 colspan=1>MGD (16)</td><td rowspan=1 colspan=1>1,072,050</td><td rowspan=1 colspan=1>10,085.26 ± 216.48</td><td rowspan=1 colspan=1>87.778 ± 0.207</td><td rowspan=1 colspan=1>88.290</td><td rowspan=1 colspan=1>87.480</td></tr><tr><td rowspan=1 colspan=1>MGD (32)</td><td rowspan=1 colspan=1>536,200</td><td rowspan=1 colspan=1>7,643.93 ± 459.95</td><td rowspan=1 colspan=1>87.851 ± 0.160</td><td rowspan=1 colspan=1>88.250</td><td rowspan=1 colspan=1>87.630</td></tr><tr><td rowspan=1 colspan=1>MGD (64)</td><td rowspan=1 colspan=1>268,100</td><td rowspan=1 colspan=1>6,160.16 ± 68.54</td><td rowspan=1 colspan=1>87.853 ± 0.202</td><td rowspan=1 colspan=1>88.330</td><td rowspan=1 colspan=1>87.450</td></tr><tr><td rowspan=1 colspan=1>MGD (128)</td><td rowspan=1 colspan=1>134,050</td><td rowspan=1 colspan=1>5,675.15 ± 181.80</td><td rowspan=1 colspan=1>87.873 ± 0.234</td><td rowspan=1 colspan=1>88.210</td><td rowspan=1 colspan=1>87.090</td></tr><tr><td rowspan=1 colspan=1>MGD (256)</td><td rowspan=1 colspan=1>67,200</td><td rowspan=1 colspan=1>5,466.79 ± 402.20</td><td rowspan=1 colspan=1>87.897 ± 0.293</td><td rowspan=1 colspan=1>88.260</td><td rowspan=1 colspan=1>87.170</td></tr><tr><td rowspan=1 colspan=1>MGD (total)</td><td rowspan=1 colspan=1>2,077,600</td><td rowspan=1 colspan=1>35,031.29</td><td rowspan=1 colspan=1></td><td rowspan=1 colspan=1></td><td rowspan=1 colspan=1></td></tr><tr><td rowspan=1 colspan=1>RMGD (basic)</td><td rowspan=1 colspan=1>463,629 ± 48,692</td><td rowspan=1 colspan=1>7,592.43 ± 403.65</td><td rowspan=1 colspan=1>88.004 ± 0.167</td><td rowspan=1 colspan=1>88.380</td><td rowspan=1 colspan=1>87.780</td></tr><tr><td rowspan=1 colspan=1>RMGD (sub)</td><td rowspan=1 colspan=1>507,186 ± 93,961</td><td rowspan=1 colspan=1>7,614.16 ± 514.20</td><td rowspan=1 colspan=1>87.992 ± 0.147</td><td rowspan=1 colspan=1>88.270</td><td rowspan=1 colspan=1>87.730</td></tr><tr><td rowspan=1 colspan=1>RMGD (super)</td><td rowspan=1 colspan=1>397,685 ± 33,535</td><td rowspan=1 colspan=1>7,426.11 ± 228.28</td><td rowspan=1 colspan=1>88.027 ± 0.179</td><td rowspan=1 colspan=1>88.340</td><td rowspan=1 colspan=1>87.760</td></tr><tr><td rowspan=1 colspan=1>RMGD (hinge)</td><td rowspan=1 colspan=1>459,664± 56,086</td><td rowspan=1 colspan=1>7,584.01 ± 439.62</td><td rowspan=1 colspan=1>88.003 ± 0.167</td><td rowspan=1 colspan=1>88.380</td><td rowspan=1 colspan=1>87.810</td></tr><tr><td rowspan=1 colspan=1>RMGD (ratio)</td><td rowspan=1 colspan=1>426,123 ± 15,213</td><td rowspan=1 colspan=1>7,561.72 ± 220.56</td><td rowspan=1 colspan=1>88.002 ± 0.129</td><td rowspan=1 colspan=1>88.330</td><td rowspan=1 colspan=1>87.770</td></tr></table>
Table 4: Iterations and real time for training, and test accuracy on CIFAR100.
<table><tr><td rowspan=2 colspan=1>Algorithms</td><td rowspan=2 colspan=1>Iterations</td><td rowspan=2 colspan=1>Real time (sec)</td><td rowspan=1 colspan=3>Test accuracy (%)</td></tr><tr><td rowspan=1 colspan=1>Mean ± SD</td><td rowspan=1 colspan=1>Max</td><td rowspan=1 colspan=1>Min</td></tr><tr><td rowspan=1 colspan=1>MGD (16)</td><td rowspan=1 colspan=1>1,072,050</td><td rowspan=1 colspan=1>12,097.47 ± 57.47</td><td rowspan=1 colspan=1>60.247 ± 0.690</td><td rowspan=1 colspan=1>61.940</td><td rowspan=1 colspan=1>59.620</td></tr><tr><td rowspan=1 colspan=1>MGD (32)</td><td rowspan=1 colspan=1>536,200</td><td rowspan=1 colspan=1>8,058.14 ± 39.87</td><td rowspan=1 colspan=1>60.475 ± 0.721</td><td rowspan=1 colspan=1>61.750</td><td rowspan=1 colspan=1>59.290</td></tr><tr><td rowspan=1 colspan=1>MGD (64)</td><td rowspan=1 colspan=1>268,100</td><td rowspan=1 colspan=1>6,400.21 ± 12.78</td><td rowspan=1 colspan=1>60.628 ± 0.795</td><td rowspan=1 colspan=1>61.950</td><td rowspan=1 colspan=1>59.170</td></tr><tr><td rowspan=1 colspan=1>MGD (128)</td><td rowspan=1 colspan=1>134,050</td><td rowspan=1 colspan=1>5,598.85 ± 38.18</td><td rowspan=1 colspan=1>60.954 ± 0.834</td><td rowspan=1 colspan=1>62.120</td><td rowspan=1 colspan=1>59.530</td></tr><tr><td rowspan=1 colspan=1>MGD (256)</td><td rowspan=1 colspan=1>67,200</td><td rowspan=1 colspan=1>5,245.88 ± 40.67</td><td rowspan=1 colspan=1>60.504 ± 0.553</td><td rowspan=1 colspan=1>61.560</td><td rowspan=1 colspan=1>59.830</td></tr><tr><td rowspan=1 colspan=1>MGD (total)</td><td rowspan=1 colspan=1>2,077,600</td><td rowspan=1 colspan=1>37,400.55</td><td rowspan=1 colspan=1></td><td rowspan=1 colspan=1></td><td rowspan=1 colspan=1></td></tr><tr><td rowspan=1 colspan=1>RMGD (basic)</td><td rowspan=1 colspan=1>425,416± 44,392</td><td rowspan=1 colspan=1>7,503.09 ± 281.79</td><td rowspan=1 colspan=1>61.203 ± 0.502</td><td rowspan=1 colspan=1>62.050</td><td rowspan=1 colspan=1>60.310</td></tr><tr><td rowspan=1 colspan=1>RMGD (sub)</td><td rowspan=1 colspan=1>532,624 ± 69,195</td><td rowspan=1 colspan=1>7,841.88 ± 530.29</td><td rowspan=1 colspan=1>61.080 ± 0.720</td><td rowspan=1 colspan=1>61.910</td><td rowspan=1 colspan=1>59.900</td></tr><tr><td rowspan=1 colspan=1>RMGD (super)</td><td rowspan=1 colspan=1>397,717 ± 20,091</td><td rowspan=1 colspan=1>7,408.00 ± 163.74</td><td rowspan=1 colspan=1>61.166 ± 0.560</td><td rowspan=1 colspan=1>61.970</td><td rowspan=1 colspan=1>60.320</td></tr><tr><td rowspan=1 colspan=1>RMGD (hinge)</td><td rowspan=1 colspan=1>419,100 ± 53,491</td><td rowspan=1 colspan=1>7,476.71 ± 324.29</td><td rowspan=1 colspan=1>61.219 ± 0.714</td><td rowspan=1 colspan=1>62.060</td><td rowspan=1 colspan=1>59.580</td></tr><tr><td rowspan=1 colspan=1>RMGD (ratio)</td><td rowspan=1 colspan=1>412,532 ±15,660</td><td rowspan=1 colspan=1>7,456.50 ± 100.79</td><td rowspan=1 colspan=1>61.340 ± 0.411</td><td rowspan=1 colspan=1>61.880</td><td rowspan=1 colspan=1>60.550</td></tr></table>
Table 3 and 4 present the detailed results on CIFAR10 and CIFAR100 dataset. The RMGD (basic) is a little slower than single best performing MGD (256 for CIFAR10 and 128 for CIFAR100), however, it was much faster than grid search -about 4.6 times on CIFAR10 and 5.0 times on CIFAR100 faster. Therefore, this results, also, show the effectiveness of the RMGD.
It is difficult to compare the RMGD with other adaptive batch size algorithm, e.g. coupling adaptive batch sizes (CABS) Balles et al. (2017), directly since the underlying goals are different. While the goal of the RMGD is to reduce the validation loss in terms of generalization performance, the CABS determines the batch size to balance between the gradient variance and computation. However, it is obvious that the RMGD is simpler and easier to implement than any other adaptive algorithm cited in this paper, and comparing the test accuracy between the RMGD and the CABS on the CIFAR10 and CIFAR100 using the same experimental settings with ’All-CNN-C’ shows that the performance of the RMGD is higher than that of the CABS (CIFAR10: $8 7 . 8 6 2 \pm 0 . 1 4 2$ , CIFAR100: 60.782 $\pm \ : 0 . 4 2 1 $ ). And again, the purpose of this algorithm is not to outperform other algorithms, but to guarantee that the best performance is reached without grid search.
# CONCLUSION
Selecting batch size affects the model quality and training efficiency, and determining the appropriate batch size is time consuming and requires considerable resources as it often relies on grid search. The focus of this paper is to design a simple robust algorithm that is theoretically sound and applicable in many situations.
This paper considers a resizable mini-batch gradient descent (RMGD) algorithm based on a multiarmed bandit that achieves equivalent performance to that of best fixed batch-size. At each epoch, the RMGD samples a batch size according to certain probability distribution of a batch being successful in reducing the loss function. Sampling from this probability provides a mechanism for exploring different batch size and exploiting batch sizes with history of success. After obtaining the validation loss at each epoch with the sampled batch size, the probability distribution is updated to incorporate the effectiveness of the sampled batch size.
The goal of this algorithm is not to achieve state-of-the-art accuracy but rather to select appropriate batch size which leads low misupdating and performs better. The RMGD essentially assists the learning process to explore the possible domain of the batch size and exploit successful batch size. The benefit of RMGD is that it avoids the need for cumbersome grid search to achieve best performance and that it is simple enough to apply to various field of machine learning including deep learning using MGD. Experimental results show that the RMGD achieves the best grid search performance on various dataset, networks, and optimizers. Furthermore, it, obviously, attains this performance in a shorter amount of time than the grid search. Also, there is no need to worry about which batch size set or cost function to choose when setting RMGD. In conclusion, the RMGD is effective and flexible mini-batch gradient descent algorithm.
# REFERENCES
Lukas Balles, Javier Romero, and Philipp Hennig. Coupling adaptive batch sizes with learning rates. In Proceedings of the Thirty-Third Conference on Uncertainty in Artificial Intelligence, UAI 2017, Sydney, Australia, August 11-15, 2017, 2017. URL http://auai.org/uai2017/ proceedings/papers/141.pdf.
Yoshua Bengio. Practical recommendations for gradient-based training of deep architectures. In Neural networks: Tricks of the trade, pp. 437–478. Springer, 2012.
Thomas M Breuel. The effects of hyperparameters on sgd training of neural networks. arXiv preprint arXiv:1508.02788, 2015.
Richard H Byrd, Gillian M Chin, Jorge Nocedal, and Yuchen Wu. Sample size selection in optimization methods for machine learning. Mathematical programming, 134(1):127–155, 2012.
Soham De, Abhay Yadav, David Jacobs, and Tom Goldstein. Big batch sgd: Automated inference using adaptive batch sizes. arXiv preprint arXiv:1610.05792, 2016.
Michael P Friedlander and Mark Schmidt. Hybrid deterministic-stochastic methods for data fitting. SIAM Journal on Scientific Computing, 34(3):A1380–A1405, 2012. Elad Hazan and Satyen Kale. Extracting certainty from uncertainty: Regret bounded by variation in costs. Machine learning, 80(2-3):165–188, 2010. Kevin Jamieson and Ameet Talwalkar. Non-stochastic best arm identification and hyperparameter optimization. In Artificial Intelligence and Statistics, pp. 240–248, 2016. Stanislaw Jastrzkebski, Zachary Kenton, Devansh Arpit, Nicolas Ballas, Asja Fischer, Yoshua Bengio, and Amos Storkey. Three factors influencing minima in sgd. arXiv preprint arXiv:1711.04623, 2017. Nitish Shirish Keskar, Dheevatsa Mudigere, Jorge Nocedal, Mikhail Smelyanskiy, and Ping Tak Peter Tang. On large-batch training for deep learning: Generalization gap and sharp minima. arXiv preprint arXiv:1609.04836, 2016. Lisha Li, Kevin Jamieson, Giulia DeSalvo, Afshin Rostamizadeh, and Ameet Talwalkar. Hyperband: A novel bandit-based approach to hyperparameter optimization. The Journal of Machine Learning Research, 18(1):6765–6816, 2017. Dmytro Mishkin, Nikolay Sergievskiy, and Jiri Matas. Systematic evaluation of convolution neural network advances on the imagenet. Computer Vision and Image Understanding, 161:11–19, 2017. Shai Shalev-Shwartz et al. Online learning and online convex optimization. Foundations and Trends $\textsuperscript { \textregistered }$ in Machine Learning, 4(2):107–194, 2012. Samuel L Smith, Pieter-Jan Kindermans, and Quoc V Le. Don’t decay the learning rate, increase the batch size. arXiv preprint arXiv:1711.00489, 2017. Jost Tobias Springenberg, Alexey Dosovitskiy, Thomas Brox, and Martin Riedmiller. Striving for simplicity: The all convolutional net. arXiv preprint arXiv:1412.6806, 2014. D Randall Wilson and Tony R Martinez. The general inefficiency of batch training for gradient descent learning. Neural Networks, 16(10):1429–1451, 2003.
# APPENDIX
# A REGRET BOUND
In the RMGD algorithm, there are $K$ batch sizes as multi arms with the probability distribution $\pi \in S$ , and at each epoch the algorithm should select one of the batch sizes $b _ { k _ { \tau } }$ . Then it receives a cost of selecting this arm, $y _ { \tau } ^ { k _ { \tau } } \in \{ 0 , 1 \}$ by testing the validation loss $\ell$ . The vector ${ \pmb y } _ { \tau } \in \{ 0 , 1 \} ^ { K }$ represents the selecting cost for each batch size. The goal of this algorithm is to have low regret for not selecting the best performing batch size.
$$\mathrm { R e g r e t } _ { \mathcal { T } } ( S ) = \mathbb { E } \left[ \sum _ { \tau = 1 } ^ { \mathcal { T } } y _ { \tau } ^ { k _ { \tau } } \right] - \operatorname* { m i n } _ { i } \sum _ { \tau = 1 } ^ { \mathcal { T } } y _ { \tau } ^ { i }$$
where the expectation is over the algorithm’s randomness of batch size selection.
Let $S$ be the probability simplex, the selecting loss functions be $f _ { \tau } ( \pmb { \pi } ) = \langle \pmb { \pi } , \pmb { y } _ { \tau } \rangle ^ { 2 }$ and $R : S \mathbb { R }$ be a regularization function that is often chosen to be strongly convex with respect to some norm $\| \cdot \|$ . The algorithm select a batch size with probability $\mathbb { P } [ b _ { k _ { \tau } } ] = \pi _ { \tau } ^ { k _ { \tau } }$ and therefore $f _ { \tau } ( \pmb { \pi } _ { \tau } )$ is the expected cost of the selected batch size at epoch $\tau$ . The gradient of the selecting loss function is ${ \pmb y } _ { \tau }$ . However, only one element $y _ { \tau } ^ { k _ { \tau } }$ is known at each epoch. To estimate gradient, random vector $z _ { \tau }$ is defined as follows:
$$z _ { \tau } ^ { i } = \left\{ \begin{array} { c l } { { y _ { \tau } ^ { i } / \pi _ { \tau } ^ { i } } } & { { \mathrm { i f ~ } i = k _ { \tau } } } \\ { { 0 } } & { { \mathrm { o t h e r w i s e } } } \end{array} \right.$$
and expectation of $z _ { \tau }$ satisfies,
$$\mathbb { E } [ z _ { \tau } | z _ { \tau - 1 } , \dots , z _ { 0 } ] = \sum _ { i = 1 } ^ { K } \mathbb { P } [ b _ { k _ { \tau } } ] z _ { \tau } ^ { i } = \pi _ { \tau } ^ { k _ { \tau } } \frac { y _ { \tau } ^ { k _ { \tau } } } { \pi _ { \tau } ^ { k _ { \tau } } } = y _ { \tau } ^ { k _ { \tau } } .$$
The most natural learning rule is to set the probability distribution which has minimal cost on all past epochs. It is referred to as Follow-the-Regularized-Leader (FTRL) in online learning:
$$\forall \tau , \quad \pi _ { \tau + 1 } = \underset { \pi \in S } { \arg \operatorname* { m i n } } \left\{ \beta \sum _ { t = 1 } ^ { \tau } f _ { t } ( \pi ) + R ( \pi ) \right\} ,$$
where $\beta$ is positive hyperparameter. The FTRL has a problem that it requires solving an optimization problem at each epoch. To solve this problem, Online Mirror Descent (OMD) is applied. The OMD computes the current probability distribution iteratively based on a gradient update rule and the previous probability distribution and lies in the update being carried out in a ’dual’ space, defined by regularizer. This follows from considering $\nabla R$ as a mapping from $\mathbb { R } ^ { K }$ onto itself. The OMD relies on Bregman divergence. The Bregman divergence between $\pi$ and $\tilde { \pi }$ with respect to the regularizer $R$ is given as:
$$B _ { R } ( { \pmb \pi } \| { \tilde { \pmb \pi } } ) = R ( { \pmb \pi } ) - R ( { \tilde { \pmb \pi } } ) - \nabla R ( { \tilde { \pmb \pi } } ) \cdot ( { \pmb \pi } - { \tilde { \pmb \pi } } ) ,$$
and a Bregman projection of $\tilde { \pi }$ onto simplex $S$ :
$$\operatorname { a r g m i n } _ { \pi \in S } B _ { R } ( \pi \| { \tilde { \pi } } ) .$$
Then the probability distribution is updated by the OMD as follows:
$$\begin{array} { r c l } { \nabla R ( \tilde { \pmb { \pi } } _ { \tau + 1 } ) } & { = } & { \nabla R ( \tilde { \pmb { \pi } } _ { \tau } ) - \beta \pmb { z } _ { \tau } } \\ { \pmb { \pi } _ { \tau + 1 } } & { = } & { \underset { \pmb { \pi } \in S } { \arg \operatorname* { m i n } } B _ { R } ( \pmb { \pi } \| \tilde { \pmb { \pi } } _ { \tau + 1 } ) . } \end{array}$$
In general, if $R$ is strongly convex, then $\nabla R$ becomes a bijective mapping, thus $\tilde { \pi } _ { \tau + 1 }$ can be recovered by the inverse gradient mapping $( \nabla R ) ^ { - 1 }$ . Given that $R$ is strongly convex, the OMD and FTRL produce equivalent predictions:
$$\underset { \pi \in S } { \arg \operatorname* { m i n } } B _ { R } ( \pi \| \tilde { \pi } _ { \tau + 1 } ) = \underset { \pi \in S } { \arg \operatorname* { m i n } } \left\{ \beta \sum _ { t = 1 } ^ { \tau } f _ { t } ( \pi ) + R ( \pi ) \right\}$$
by the Lemma 1 in Hazan & Kale (2010). It makes sense to use the negative entropic regularization for $R$ in RMGD setting:
$$R ( { \pmb \pi } ) = \sum _ { i = 1 } ^ { K } \pi ^ { i } \log ( \pi ^ { i } ) .$$
Then, $\nabla R ( { \pmb \pi } ) _ { i } = \log ( \pi ^ { i } ) + 1$ . From the OMD, $\tilde { \pi } _ { \tau + 1 }$ is updated as follows:
$$\begin{array} { r c l } { \nabla R ( \tilde { \pi } _ { \tau + 1 } ) } & { = } & { \nabla R ( \tilde { \pi } _ { \tau } ) - \beta z _ { \tau } } \\ { \log ( \tilde { \pi } _ { \tau + 1 } ^ { i } ) + 1 } & { = } & { \log ( \tilde { \pi } _ { \tau } ^ { i } ) + 1 - \beta z _ { \tau } ^ { i } } \\ { \tilde { \pi } _ { \tau + 1 } ^ { i } } & { = } & { \tilde { \pi } _ { \tau } ^ { i } e ^ { - \beta z _ { \tau } ^ { i } } . } \end{array}$$
The Bregman projection with respect to the negative entropy function becomes scaling by the $\ell _ { 1 }$ - norm. Therefore,
$$\pi _ { \tau + 1 } ^ { i } = \frac { \tilde { \pi } _ { \tau + 1 } ^ { i } } { \sum _ { j } \tilde { \pi } _ { \tau + 1 } ^ { j } } .$$
The probability distribution $\pi _ { \tau }$ is updated by the rule of the normalized exponentiated gradient (normalized-EG) algorithm described in Algorithm 1. Also, the selecting loss function is linear and it is satisfied that $\forall \tau , i$ we have $\beta z _ { \tau } ^ { i } \geq 0$ . Then,
$$\sum _ { \tau = 1 } ^ { T } \langle \pi _ { \tau } - \pi ^ { * } , z _ { \tau } \rangle \leq \frac { \log ( K ) } { \beta } + \beta \sum _ { \tau = 1 } ^ { T } \sum _ { i = 1 } ^ { K } \pi _ { \tau } ^ { i } ( z _ { \tau } ^ { i } ) ^ { 2 }$$
by the Theorem 2.22 in Shalev-Shwartz et al. (2012), where $\pi ^ { * } \in S$ is a fixed vector which minimizes the cumulative selecting loss,
$$\pi ^ { * } = \arg \operatorname* { m i n } _ { \pi \in S } \sum _ { \tau = 1 } ^ { \tau } f _ { \tau } ( \pi ) .$$
Since $f _ { \tau }$ is convex and $z _ { \tau }$ is estimated gradients for all $\tau$
$$\mathbb { E } \left[ \sum _ { \tau = 1 } ^ { \mathcal { T } } ( f _ { \tau } ( \pi _ { \tau } ) - f _ { \tau } ( \pi ^ { * } ) ) \right] \leq \frac { \log ( K ) } { \beta } + \beta \sum _ { \tau = 1 } ^ { \mathcal { T } } \mathbb { E } \left[ \sum _ { i = 1 } ^ { K } \pi _ { \tau } ^ { i } ( z _ { \tau } ^ { i } ) ^ { 2 } \right]$$
by the Theorem 4.1 in Shalev-Shwartz et al. (2012). The last term is bounded as follows:
$$\begin{array} { r c l } { \mathbb { E } \left[ \displaystyle \sum _ { i = 1 } ^ { K } \pi _ { \tau } ^ { i } ( z _ { \tau } ^ { i } ) ^ { 2 } \right] } & { = } & { \displaystyle \sum _ { j = 1 } ^ { K } \mathbb { P } [ k _ { \tau } = j ] \sum _ { i = 1 } ^ { K } \pi _ { \tau } ^ { i } ( z _ { \tau } ^ { i } ) ^ { 2 } } \\ & { = } & { \displaystyle \sum _ { j = 1 } ^ { K } ( \pi _ { \tau } ^ { j } ) ^ { 2 } ( y _ { \tau } ^ { j } / \pi _ { \tau } ^ { j } ) ^ { 2 } } \\ & { = } & { \displaystyle \sum _ { j = 1 } ^ { K } ( y _ { \tau } ^ { j } ) ^ { 2 } \leq K . } \end{array}$$
Therefore, the regret of the RMGD is bounded,
$$\mathbb { E } \left[ \sum _ { \tau = 1 } ^ { \mathcal { T } } y _ { \tau } ^ { k _ { \tau } } \right] - \operatorname* { m i n } _ { i } \sum _ { \tau = 1 } ^ { \mathcal { T } } y _ { \tau } ^ { i } \leq \frac { \log K } { \beta } + \beta K \mathcal { T } .$$
In particular, setting $\beta = \sqrt { \log ( K ) / ( K T ) }$ , the regret is bounded by $2 \sqrt { K \log ( K ) \mathcal { T } }$ , which is sublinear with $\tau$ .
# B EXPERIMENTAL SETTINGS
# DATASET
MNIST is a dataset of handwritten digits that is commonly used for image classification. Each sample is a black and white image and $2 8 \times 2 8$ in size. The MNIST is split into three parts: 55,000 samples for training, 5,000 samples for validation, and 10,000 samples for test.
CIFAR10 consists of $6 0 { , } 0 0 0 \ 3 2 \times 3 2$ color images in 10 classes (airplane, automobile, bird, cat, deer, dog, frog, horse, ship, and truck), with 6,000 images per class. The CIFAR10 is split into three parts: 45,000 samples for training, 5,000 samples for validation, and 10,000 samples for test.
CIFAR100 consists of $6 0 { , } 0 0 0 \ 3 2 \times 3 2$ color images in 100 classes. The CIFAR100 is split into three parts: 45,000 samples for training, 5,000 samples for validation, and 10,000 samples for test.
# SETTINGS
The simple CNN consists of two convolution layers with $5 \times 5$ filter and $1 \times 1$ stride, two max pooling layers with $2 \times 2$ kernel and $2 \times 2$ stride, single fully-connected layer, and softmax classifier. Description of the ’All-CNN-C’ is provided in Table 5. For MNIST, AdamOptimizer with $\eta = 1 0 ^ { - 4 }$ and AdagradOptimizer with $\eta = 0 . 1$ are used as optimizer. The basic batch size set $B = \{ 1 6 , 3 2 , 6 4 , 1 2 8 , 2 5 6 , 5 1 2 \}$ , subset of basic $B ^ { - } ~ = ~ \{ 1 6 , 6 4 , 2 5 6 \}$ , and superset of basic $B ^ { + } ~ = ~ \{ 1 6 , 2 4 , 3 2 , 4 8 , 6 4 , 9 6 , 1 2 8 , 1 9 2 , 2 5 6 , 3 8 ^ { \circ }$ 4, 512}. The model is trained for a total of 100 epochs. For CIFAR10 and CIFAR100, MomentumOptimizer with fixed momentum of 0.9 is used as optimizer. The learning rate $\eta ^ { k }$ is scaled up proportionately to the batch size $( \eta ^ { k } = 0 . 0 5 * b _ { k } / 2 5 6 )$ and decayed by a schedule $S = [ 2 0 0 , 2 5 0 , 3 0 0 ]$ in which $\dot { \boldsymbol { \eta } } ^ { k }$ is multiplied by a fixed multiplier of 0.1 after 200, 250, and 300 epochs respectively. The model is trained for a total of 350 epochs. Dropout is applied to the input image as well as after each convolution layer with stride 2. The dropout probabilities are $20 \%$ for dropping out inputs and $50 \%$ otherwise. The model is regularized with weight decay $\lambda ~ = ~ 0 . 0 0 1$ . The basic batch size set $B = \{ 1 6 , 3 2 , 6 2 , 1 2 8 , 2 5 6 \}$ , subset of basic $B ^ { - } = \{ 1 6 , 6 4 , 2 5 6 \}$ , and superset of basic $B ^ { + } = \{ 1 6 , 2 4 , 3 2 , 4 8 , 6 4 , 9 6 , 1 2 8 , 1 9 2 , 2$ $2 5 6 \}$ . For all experiments, rectified linear unit (ReLU) is used as activation function. For RMGD, $\beta$ is set to $\sqrt { \log ( 6 ) / ( 6 * 1 0 0 ) } \approx 0 . 0 5 5$ for MNIST and $\sqrt { \log ( 5 ) / ( 5 * 3 5 0 ) } \approx 0 . 0 3 0$ for CIFAR10 and CIFAR100. The basic batch size selecting cost is 0-1 loss, hinge loss is $\operatorname* { m a x } \{ 0 , \ell _ { \tau } - \ell _ { \tau - 1 } \}$ , and ratio loss is $\operatorname* { m a x } \{ 0 , ( \ell _ { \tau } - \ell _ { \tau - 1 } ) / \ell _ { \tau - 1 } \}$ .
Table 5: Architecture of the All-CNN-C for CIFAR10 and CIFAR100
<table><tr><td>Layer</td><td>Layerdescription</td></tr><tr><td>input conv1</td><td>Input 32 × 32 RGB image 3 × 3 conv. 96 ReLU, stride 1, dropout 0.2</td></tr><tr><td>conv2</td><td>3 × 3 conv. 96 ReLU, stride 1</td></tr><tr><td>conv3</td><td>3 × 3 conv.96 ReLU, stride 2</td></tr><tr><td>conv4</td><td>3 × 3 conv.192 ReLU, stride 1, dropout 0.5</td></tr><tr><td>conv5</td><td>3 × 3 conv.192 ReLU, stride 1</td></tr><tr><td>conv6</td><td>3 × 3 conv. 192 ReLU, stride 2</td></tr><tr><td>conv7</td><td>3 × 3 conv.192 ReLU, stride 1, dropout 0.5</td></tr><tr><td>conv8</td><td>1 × 1 conv.192 ReLU, stride 1</td></tr><tr><td>conv9</td><td></td></tr><tr><td>pool</td><td>1 × 1 conv. 10 or 100 ReLU, stride 1</td></tr><tr><td></td><td>averaging over 6 × 6 spatial dimensions</td></tr><tr><td>softmax</td><td>10-way or 100-way softmax</td></tr></table>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242# WHY DO DEEP CONVOLUTIONAL NETWORKS GENERALIZE SO POORLY TO SMALL IMAGE TRANSFORMATIONS?
Anonymous authors Paper under double-blind review
# ABSTRACT
Deep convolutional network architectures are often assumed to guarantee generalization for small image translations and deformations. In this paper we show that modern CNNs (VGG16, ResNet50, and InceptionResNetV2) can drastically change their output when an image is translated in the image plane by a few pixels, and that this failure of generalization also happens with other realistic small image transformations. Furthermore, we see these failures to generalize more frequently in more modern networks. We show that these failures are related to the fact that the architecture of modern CNNs ignores the classical sampling theorem so that generalization is not guaranteed. We also show that biases in the statistics of commonly used image datasets makes it unlikely that CNNs will learn to be invariant to these transformations. Taken together our results suggest that the performance of CNNs in object recognition falls far short of the generalization capabilities of humans.
# 1 INTRODUCTION
Deep convolutional neural networks (CNNs) have revolutionized computer vision. Perhaps the most dramatic success is in the area of object recognition, where performance is now described as "superhuman" (He et al., 2015). A key to the success of any machine learning method is the inductive bias of the method, and clearly the choice of architecture in a neural network significantly affects the inductive bias. In particular, the choice of convolution and pooling in CNNs is motivated by the desire to endow the networks with invariance to irrelevant cues such as image translations, scalings, and other small deformations (Fukushima & Miyake, 1982; Zeiler & Fergus, 2014). This motivation was made explicit in the 1980s by Fukushima in describing the "neocognitron" architecture, which served as inspiration for modern CNNs (LeCun et al., 1989), "After finishing the process of learning, pattern recognition is performed on the basis of similarity in shape between patterns, and is not affected by deformation, nor by changes in size, nor by shifts in the position of the input patterns." (Fukushima, 1988)
Despite the excellent performance of CNNs on object recognition, the vulnerability to adversarial attacks suggests that superficial changes can result in highly non-human shifts in prediction (e.g. (Bhagoji et al., 2017; Su et al., 2017). In addition, filtering the image in the Fourier domain (in a way that does not change human prediction) also results in a substantial drop in prediction accuracy (Jo & Bengio, 2017). These and other results (Rodner et al., 2016) indicate that CNNs are not invariant to cues that are irrelevant to the object identity.
An argument against adversarial attacks on CNNs is that they often involve highly unnatural transformations to the input images, hence in some sense we would not expect CNNs to be invariant to these transformations. When considering more natural transformations, there is preliminary evidence that AlexNet (Krizhevsky et al., 2012) is robust to some of them (Zeiler & Fergus, 2014). On the other hand, there is also preliminary evidence for lack of robustness in the more modern networks for object classification (Bunne et al., 2018) and detection (Rosenfeld et al., 2018) along with studies suggesting that with small CNNs and the MNIST data, data augmentation is the main feature affecting CNN invariance (Kauderer-Abrams, 2017). An indirect method to probe for invariances measures the linearity of the learned representations under natural transformations to the input image (Lenc & Vedaldi, 2015; Hénaff & Simoncelli, 2015; Fawzi & Frossard, 2015; Cohen & Welling, 2014). The recent work of (Engstrom et al., 2017) investigates adversarial attacks that use only rotations and translations. They find that "simple transformations, namely translations and rotations alone, are sufficient to fool neural network-based vision models on a significant fraction of inputs" and show that advanced data augmentation methods can make the networks more robust.
 Figure 1: Examples of jagged predictions of modern deep convolutional neural networks. Top: A negligible vertical shift of the object (Kuvasz) results in an abrupt decrease in the network’s predicted score of the correct class. Middle: A tiny increase in the size of the object (Lotion) produces a dramatic decrease in the network’s predicted score of the correct class. Bottom: A very small change in the bear’s posture results in an abrupt decrease in the network’s predicted score of the correct class. Colored dots represent images chosen from interesting $\mathbf { X }$ -axis locations of the graphs on the right. These dots illustrate sensitivity of modern neural networks to small, insignificant (to a human), and realistic variations in the image.
In this paper, we directly ask "why are modern CNNs not invariant to natural image transformations despite the architecture being explicitly designed to provide such invariances?". Specifically, we systematically examine the invariances of three modern deep CNNs: VGG-16 (Simonyan & Zisserman, 2014), ResNet-50 (He et al., 2016), and InceptionResNet-V2 (Szegedy et al., 2017). We find that modern deep CNNs are not invariant to translations, scalings and other realistic image transformations, and this lack of invariance is related to the subsampling operation and the biases contained in image datasets.
# 2 FAILURES OF MODERN CNNS
Figure 1 contains examples of abrupt failures following tiny realistic transformations for the InceptionResNet-V2 CNN. Shifting or scaling the object by just one pixel could result in a sharp change in prediction. In the top row, we embed the original image in a larger image and shift it in the image plane (while filling in the rest of the image with a simple inpainting procedure). In the middle row, we repeat this protocol with rescaling. In the bottom row, we show frames from a BBC film in which the ice bear moves almost imperceptibly between frames and the network’s output changes dramatically1.
 Figure 2: Modern deep convolutional neural networks are sensitive to small image translations. A) Comparison of three networks of various depths in the task of vertical image translation depicted in figure 1. Images (rows) are randomly chosen from the ImageNet dataset (Deng et al., 2009), and are sorted by the network’s prediction sum in a descending order. B) More modern networks have more jagged predictions.
In order to measure how typical these failures are, we randomly chose images from the ImageNet validation set and measured the output of three modern CNNs as we embedded these images in a larger image and systematically varied the vertical translation. As was the case in figure 1, we used a simple inpainting procedure to fill in the rest of the image.
Results are shown in figure 2. Each row corresponds to an image under different translations and the color denotes the network’s estimate of the probability of the correct class. Thus a row that is all light corresponds to a correct classification that is invariant to translation, while a row that is all dark corresponds to an incorrect classification that is invariant to translation. Surprisingly, many rows show abrupt transitions from light to dark, indicating that the classification changes abruptly as the object is translated. We quantify the lack of invariance by a measure we call "jaggedness": the number of times the network’s predictions had the correct class in its top-5 and after just one pixel shift it moved outside of the top-5 (and also the opposite transition from non-top-5 to top5). Using this measure, we find that for approximately $30 \%$ of the images, the output is "jagged", i.e the network changes its prediction by a shift of a single pixel. Also, as shown in the right of figure 2, jaggedness is greater for the modern, deeper, networks compared to the less modern VGG16 network. While the deeper networks have better test accuracy, they are also less invariant. In the appendix we also show an alternative to the "jaggedness" measure, which gives similar results.
A natural criticism of these results is that they are somehow related to the image resizing and inpainting procedures that we used. To test this possibility, we repeated the experiment with a different protocol where we chose different crops of the original ImageNet image while making sure that the object bounding box remained within the crop. This protocol does not require any inpainting while still translating the object location within the new image. Results are shown in the appendix. We still have a large fraction of images for which the prediction is not invariant to translation. We also show in the appendix similar results for scaling rather than translation. Overall we find that regardless of the protocol used, modern CNNs often change their output significantly as a result of a small translation or scaling.
# 3 IGNORING THE SAMPLING THEOREM
The failure of CNNs to generalize to image translations is particularly puzzling. Intuitively, it would seem that if all layers in a network are convolutional then the representation should simply translate when an image is translated. If the final features for classification are obtained by a global pooling operation on the representation (as is done for example in ResNet50 and InceptionResNetV2) then these features should be invariant to translation. Where does this intuition fail?
 Figure 3: The deeper the network, the less shiftable are the feature maps. A) A vertical shift of a "Kuvasz" dog in the image plane. B) Feature maps from three different network architectures in response to the translated Kuvasz image. Layer depth assignments reflect the number of trainable convolutional layers preceding the selected layer. The last layer is always the last convolutional layer in each network.
This intuition ignores the subsampling operation which is prevalent in modern CNNs, also known as "stride". This failure of translation invariance in systems with subsampling was explicitly discussed in Simoncelli et al. (Simoncelli et al., 1992) who wrote "We cannot literally expect translation invariance in a system based on convolution and subsampling: translation of the input signal cannot produce simple translations of the transform coefficients, unless the translation is a multiple of each of the subsampling factors in the system". Since deep networks often contain many subsampling operations, the subsampling factor of the deep layers may be very large so that "literal" translation invariance only holds for very special translations. In InceptionResnetV2, for example, the subsampling factor is 60, so we expect exact translation invariance to hold only for $\scriptstyle { \frac { 1 } { 6 0 ^ { 2 } } }$ of possible translations.
Simoncelli et al. also defined a weaker form of translation invariance, which they called "shiftability" and showed that it can hold for systems with subsampling (this is related to weak translation invariance as defined by (Lenc & Vedaldi, 2015), see also (Esteves et al., 2017; Cohen & Welling, 2014) for related ideas applied to neural networks). Here we extend the basic shiftability result to show that when shiftability holds, then global pooling will indeed yield invariant representations.
We define $r ( x )$ as the response of a feature detector at location $x$ in the image plane. We say that this response is "convolutional" if translating the image by any translation $\delta$ yields a translation of the response by the same $\delta$ . This definition includes cases when the feature response is obtained by convolving the input image with a fixed filter, but also includes combinations of linear operations and nonlinear operations that do not include any subsampling.
We start by a trivial observation:
Observation: If $r ( x )$ is convolutional then global pooling $\begin{array} { r } { r = \sum _ { x } r ( x ) } \end{array}$ is translation invariant.
Proof: This follows directly from the definition of a convolutional response. If $r ( x )$ is the feature response to one image and $r _ { 2 } ( x )$ is the feature response to the same image translated, then $\textstyle \sum _ { x } r ( x ) =$ $\textstyle \sum _ { x } ^ { * } r _ { 2 } ( x )$ since the two responses are shifts of each other.
Definition: A feature detector $r ( x )$ with subsampling factor $s$ is called “shiftable” if for any $x$ the detector output at location $x$ can be linearly interpolated from the responses on the sampling grid:
$$r ( x ) = \sum _ { i } B _ { s } ( x - x _ { i } ) r ( x _ { i } )$$
where $x _ { i }$ are located on the sampling grid for subsampling factor $s$ and $B _ { s } ( x )$ is the basis function for reconstructing $r ( x )$ from the samples.
The classic Shannon-Nyquist theorem tells us that $r ( x )$ will be shiftable if and only if the sampling frequency is at least twice the highest frequency in $r ( x )$ .
Claim: If $r ( x )$ is shiftable then global pooling on the sampling grid $\begin{array} { r } { r = \sum _ { i } r ( x _ { i } ) } \end{array}$ is translation invariant.
Proof: This follows from the fact that global pooling on the sampling grid is (up to a constant) the same as global pooling for all $x$ .
$$\begin{array} { l c l } { \displaystyle \sum _ { x } r ( x ) } & { = } & { \displaystyle \sum _ { x } \sum _ { i } r ( x _ { i } ) B ( x - x _ { i } ) } \\ { \displaystyle } & { = } & { \displaystyle \sum _ { i } r ( x _ { i } ) \sum _ { x } B ( x - x _ { i } ) } \\ { \displaystyle } & { = } & { K \sum _ { i } r ( x _ { i } ) } \end{array}$$
where $\begin{array} { r } { K = \sum _ { x } B ( x - x _ { i } ) } \end{array}$ and $K$ does not depend on $x _ { i }$
While the claim focuses on a global translation, it can also be extended to piecewise constant transformations.
Corollary: Consider a set of transformations $T$ that are constant on a set of given image subareas. If $r ( x )$ is shiftable and for a given image, the support of $r ( x )$ and its receptive field is contained in the same subregion for all transformations in $T$ , then global pooling on the sampling grid is invariant to any transformation in $T$ .
Proof: This follows from the fact that applying any transformation in $T$ to an image has the same effect on the feature map $r ( x )$ as translating the image.
To illustrate the importance of the sampling theorem in guaranteeing invariance in CNNs, consider a convolutional layer in a deep CNN where each unit acts as a localized "part detector" (this has been reported to be the case for many modern CNNs (Zeiler & Fergus, 2014; Zhou et al., 2014)). Each such part detector has a spatial tuning function and the degree of sharpness of this tuning function will determine whether the feature map can be subsampled while preserving shiftability or not. For example, consider a part detector that fires only when the part is exactly at the center of its receptive field. If there is no subsampling, then as we translate the input image, the feature map will translate as well, and the global sum of the feature map is invariant to translation. But if we subsample by two (or equivalently use a stride of two), then there will only be activity in the feature map when the feature is centered on an even pixel, but not when it is centered on an odd pixel. This means that the global sum of the feature map will not be invariant to translation.
In the language of Fourier transforms, the problem with a part detector that fires only when the part is exactly at the center of the receptive field is that the feature map contains many high frequencies and hence it cannot be subsampled while preserving shiftability. On the other hand, if we have a part detector whose spatial tuning function is more broad, it can be shiftable and our claim (above) shows that the global sum of activities in a feature map will be preserved for all translations, even though the individual firing rates of units will still be different when the part is centered at an odd pixel or an even pixel. Our corollary (above), shows the importance of shiftability to other smooth transformations: in this case each "part detector" will translate with a different translation but it is still the case that nonshiftable representations will not preserve the global sum of activities as the image is transformed, while shiftable representations will.
Figure 3 examines the extent to which the representations learned by modern CNNs are invariant or shiftable. The top row shows an image that is translated vertically, while the bottom three rows show the representations in different layers for the three CNNs we consider. For VGG16 the representation appears to shift along with the object, including the final layer where the blurred pattern of response is not a simple translation of the original response, but seems to preserve the global sum for this particular image. For the two more modern networks, the responses are sharper but lose their shiftability in the later layers. In particular, the final layers show approximate invariance to one special translation but no response at all to another translation, suggesting that the many layers of subsampling yield a final response that is not shiftable.
We also performed a more quantitative measure of shiftability by counting for a given image the number of times the global sum of activities in each layer changes significantly (more than $20 \%$ of mean) as the input is shifted (for each image, we only considered feature maps where the maximum response was above a threshold). We call this measure "nonshiftability". According to the preceding analysis, in architectures that obey the sampling theorem, the global sum should be invariant to input translation so nonshiftability should be zero in all layers. We find that for all three networks, the initial layers have nonshiftability close to zero but as we go deeper and deeper nonshiftability increases. Furthermore, the deeper, more modern networks, exhibit larger nonshiftability in their deep layers compared to VGG16 (see appendix for graphs).
How can we guarantee that representations in CNNs will be shiftable? As explained above, we need to make sure that any feature map that uses stride does not contain frequencies above the Nyquist frequency. If CNNs were purely linear, we could simply blur the input images so that they would not include any frequencies higher than the Nyquist limit determined by the final sampling factor of the network. But since CNNs also include nonlinearities, they can add high frequencies that were not present in the input.
An important message of the sampling theorem is that you should always blur before subsampling. Translated to the language of neural networks this means that stride (i.e. subsampling) should always be combined with pooling (i.e. blurring) in the preceding layer. Indeed if we have an arbitrarily deep CNN where all the layers use stride $^ { = 1 }$ followed by one layer that has a stride greater than one, then by choosing the pooling window appropriately we can guarantee that the final layer will still be shiftable. If we do not use appropriate pooling then there is no guarantee that this layer will be shiftable. Even if we use appropriate pooling that ensures that a given layer is shiftable, the subsequent nonlinearities in a CNN may not preserve the shiftability, as the nonlinearities may again introduce high frequencies.
To illustrate the effect of pooling on shiftability in modern CNNs we replaced the $2 \times 2$ max pooling layers of VGG16 with $6 \times 6$ average pooling. This has the effect of reducing low freqencies but given the nonlinearities, it does not guarantee shiftability. As shown in figure 4 this simple change makes the representations approximately shiftable and, as predicted by our theory, the global sum is now invariant to both translations and rescalings of the input. This invariance of course comes with a price: the feature maps now have less detail and in preliminary experiments we find that recognition performance decreases somewhat. But the sampling theorem tells us that if we want to use subsampling while avoiding aliasing, we need to ensure that no high frequencies (relative to the Nyquist frequency) are present in the feature maps.
As an alternative to pooling, Ruderman et al. (Ruderman et al., 2018) have shown that networks may learn smooth filters that will lead to reduced sensitivity to transformations. Evidently, the filters learned in standard VGG16 are not smooth enough.
# 4 WHY DON’T MODERN CNNS LEARN TO BE INVARIANT FROM DATA?
While the preceding discussion suggests that the CNN architecture will not yield translation invariance "for free", there is still the possibility that the CNN will learn a translation invariant prediction from the training examples. This requires that the training set will actually be invariant to the irrelevant transformations. We examined the degree of invariance in the ImageNet training set by manually labeling the training images in five categories: Tibetan terrier, elephant, pineapple, bagel and rowing paddle.
Consistent with previous results on "dataset bias" (Simon et al., 2007; Raguram & Lazebnik, 2008; Berg & Berg, 2009; Torralba & Efros, 2011; Weyand & Leibe, 2011; Mezuman & Weiss, 2012) we find that the ImageNet dataset is not invariant to translations and rescalings. Figure 5 shows the distribution of the distances between the eyes of a "Tibetan terrier" and the positions of the center point between the dog’s eyes. Notice that both distributions are far from uniform. Similar results are obtained for the other four categories.
 Figure 4: Average pooling makes VGG representations approximately shiftable. Plotted are summation of feature maps from the last layer of VGG (spatial dimension $7 { \bf x } 7 $ ) as an input image is vertically translated in the image plane (top), or rescaled (bottom). Left: the original VGG16 with its $2 \mathbf { x } 2$ max pooling layers. Right: VGG16 where every $2 \mathbf { x } 2$ max pooling layer was replaced by a 6x6 average pooling layer. More randomly selected images are shown in the appendix.
 Figure 5: Photographer’s biases in the ImageNet’s “Tibetan terrier” category. Left: Example of the hand-labeling procedure. Middle: Positions of the middle point between the dog’s eyes. Right: Histogram of distances between the dog’s eyes. Notice the bias in both the object’s position and scale.
To be more quantitative, we used the available bounding-box labels, and extracted the center point of the bounding-box and its height as proxies for the object position and size respectively. We then applied a statistical significance test to ask whether object location and object sizes were uniform for that category. For more than 900 out of the 1000 categories we found that location and size were highly non uniform $( P < 1 0 ^ { - 1 0 }$ ). Given these strong biases, we cannot expect a learning system to learn to be invariant.
Even if the training set is not invariant, we can make it invariant using data augmentation. Will this make the CNN learn an invariant prediction? First, we note that we used pretrained networks and according to the authors’ description of the training procedure, all three networks were trained using data augmentation. Obviously, not any data augmentation is sufficient for the networks to learn invariances. To understand the failure of data augmentation, it is again instructive to consider the subsampling factor. Since in modern networks the subsampling factor is approximately 60, then for a system to learn complete invariance to translation only, it would need to see $6 0 ^ { \mathrm { { 2 } } } = 3 6 0 0$ augmented versions of each training example, or it would need to have an inductive bias that allows it to generalize over transformations. If we also add invariance to rotations and scalings, the number grows exponentially with the number of irrelevant transformations. Engstrom et al. (Engstrom et al., 2017) suggest a sophisticated data augmentation method and show that it increases the invariance to translation and rotation. However, for challenging datasets such as ImageNet the lack of invariance largely persists.
 Figure 6: The performance of modern CNNs on test images from ImageNet that are embedded in a random location in a larger image is quite poor (less than $50 \%$ accuracy). Human performance is not affected. Right: An example of a full sized image and the same image resized to $1 0 0 \mathrm { x } 1 0 0$ .
# 5 IMPLICATIONS FOR PRACTICAL SYSTEMS
Although our results show that modern CNNs fail to generalize for small image transformations, their performance on the ImageNet test set is still amazingly good and far better than previous techniques. This is related to the fact that the ImageNet test set contains the same photographer’s biases as the training set, so generalization to very different sizes and locations is not required. To highlight this point, we created a new test set in which ImageNet images were embedded in a larger image in a random location (and the missing pixels were filled in using a simple inpainting algorithm). Figure 6 shows that human performance is not affected by the rescaling and random translations, while the performance of modern CNNs deteriorates dramatically. In fact, when images are scaled to half their original size and randomly translated, the accuracy of modern CNNs is less than $50 \%$ , typically considered poor performance.
One way in which modern systems partially address the lack of invariance is using test time augmentation in which the system output on a given image is computed by a majority vote among many random crops of the image. Clearly this is wasteful in resources and still only provides partial invariance.
# 6 DISCUSSION
CNN architectures were designed based on an intuition that the convolutional structure and pooling operations will give invariance to translations and small image deformations "for free". In this paper we have shown that this intuition breaks down once subsampling, or "stride" is used and we have presented empirical evidence that modern CNNs do not display the desired invariances since the architecture ignores the classic sampling theorem. This still leaves open the possibility of a CNN learning invariance from the data but we have shown that the ImageNet training and testing examples include significant photographer’s bias so that it is unlikely that a system will learn invariance using these examples.
In addition to pointing out these failures, the sampling theorem also suggests a way to impose translation invariance by ensuring that all representations are sufficiently blurred to overcome the subsampling. However, such blurred representations may lead to a decrease in performance, especially in datasets and benchmarks that contain photographer’s bias. Alternatively, one could use specially designed features in which invariance is hard coded or neural network architectures that explicitly enforce invariance (Sifre & Mallat, 2013; Gens & Domingos, 2014; Cheng et al., 2016a;b; Dieleman et al., 2016; 2015; Xu et al., 2014; Worrall et al., 2017; Cohen & Welling, 2016). Again, as long as the datasets contain significant photographer’s bias, such invariant approaches may lead to a decrease in performance.
# REFERENCES
Tamara L Berg and Alexander C Berg. Finding iconic images. In Computer Vision and Pattern Recognition Workshops, 2009. CVPR Workshops 2009. IEEE Computer Society Conference on, pp. 1–8. IEEE, 2009.
Arjun Nitin Bhagoji, Warren He, Bo Li, and Dawn Song. Exploring the space of black-box attacks on deep neural networks. arXiv preprint arXiv:1712.09491, 2017.
Charlotte Bunne, Lukas Rahmann, and Thomas Wolf. Studying invariances of trained convolutional neural networks. arXiv preprint arXiv:1803.05963, 2018.
Gong Cheng, Peicheng Zhou, and Junwei Han. Learning rotation-invariant convolutional neural networks for object detection in vhr optical remote sensing images. IEEE Transactions on Geoscience and Remote Sensing, 54(12):7405–7415, 2016a.
Gong Cheng, Peicheng Zhou, and Junwei Han. Rifd-cnn: Rotation-invariant and fisher discriminative convolutional neural networks for object detection. In Computer Vision and Pattern Recognition (CVPR), 2016 IEEE Conference on, pp. 2884–2893. IEEE, 2016b.
Taco Cohen and Max Welling. Group equivariant convolutional networks. In International Conference on Machine Learning, pp. 2990–2999, 2016.
Taco S Cohen and Max Welling. Transformation properties of learned visual representations. arXiv preprint arXiv:1412.7659, 2014.
Jia Deng, Wei Dong, Richard Socher, Li-Jia Li, Kai Li, and Li Fei-Fei. Imagenet: A large-scale hierarchical image database. In Computer Vision and Pattern Recognition, 2009. CVPR 2009. IEEE Conference on, pp. 248–255. IEEE, 2009.
Sander Dieleman, Kyle W Willett, and Joni Dambre. Rotation-invariant convolutional neural networks for galaxy morphology prediction. Monthly notices of the royal astronomical society, 450(2): 1441–1459, 2015.
Sander Dieleman, Jeffrey De Fauw, and Koray Kavukcuoglu. Exploiting cyclic symmetry in convolutional neural networks. arXiv preprint arXiv:1602.02660, 2016.
Logan Engstrom, Dimitris Tsipras, Ludwig Schmidt, and Aleksander Madry. A rotation and a translation suffice: Fooling cnns with simple transformations. CoRR, abs/1712.02779, 2017. URL http://arxiv.org/abs/1712.02779.
Carlos Esteves, Christine Allen-Blanchette, Xiaowei Zhou, and Kostas Daniilidis. Polar transformer networks. arXiv preprint arXiv:1709.01889, 2017.
Alhussein Fawzi and Pascal Frossard. Manitest: Are classifiers really invariant? arXiv preprint arXiv:1507.06535, 2015.
Kunihiko Fukushima. Neocognitron: A hierarchical neural network capable of visual pattern recognition. Neural networks, 1(2):119–130, 1988.
Kunihiko Fukushima and Sei Miyake. Neocognitron: A self-organizing neural network model for a mechanism of visual pattern recognition. In Competition and cooperation in neural nets, pp. 267–285. Springer, 1982.
Robert Gens and Pedro M Domingos. Deep symmetry networks. In Advances in neural information processing systems, pp. 2537–2545, 2014.
Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Delving deep into rectifiers: Surpassing human-level performance on imagenet classification. In Proceedings of the IEEE international conference on computer vision, pp. 1026–1034, 2015.
Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Deep residual learning for image recognition. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 770–778, 2016.
Olivier J Hénaff and Eero P Simoncelli. Geodesics of learned representations. arXiv preprint arXiv:1511.06394, 2015.
Jason Jo and Yoshua Bengio. Measuring the tendency of cnns to learn surface statistical regularities. arXiv preprint arXiv:1711.11561, 2017.
Eric Kauderer-Abrams. Quantifying translation-invariance in convolutional neural networks. arXiv preprint arXiv:1801.01450, 2017.
Alex Krizhevsky, Ilya Sutskever, and Geoffrey E Hinton. Imagenet classification with deep convolutional neural networks. In Advances in neural information processing systems, pp. 1097–1105, 2012.
Yann LeCun, Bernhard Boser, John S Denker, Donnie Henderson, Richard E Howard, Wayne Hubbard, and Lawrence D Jackel. Backpropagation applied to handwritten zip code recognition. Neural computation, 1(4):541–551, 1989.
Karel Lenc and Andrea Vedaldi. Understanding image representations by measuring their equivariance and equivalence. In Computer Vision and Pattern Recognition (CVPR), 2015 IEEE Conference on, pp. 991–999. IEEE, 2015.
Elad Mezuman and Yair Weiss. Learning about canonical views from internet image collections. In Advances in Neural Information Processing Systems, pp. 719–727, 2012.
Rahul Raguram and Svetlana Lazebnik. Computing iconic summaries of general visual concepts. In Computer Vision and Pattern Recognition Workshops, 2008. CVPRW’08. IEEE Computer Society Conference on, pp. 1–8. IEEE, 2008.
Erik Rodner, Marcel Simon, Robert B Fisher, and Joachim Denzler. Fine-grained recognition in the noisy wild: Sensitivity analysis of convolutional neural networks approaches. arXiv preprint arXiv:1610.06756, 2016.
Amir Rosenfeld, Richard Zemel, and John K Tsotsos. The elephant in the room. arXiv preprint arXiv:1808.03305, 2018.
Avraham Ruderman, Neil C. Rabinowitz, Ari S. Morcos, and Daniel Zoran. Learned deformation stability in convolutional neural networks. CoRR, abs/1804.04438, 2018. URL http://arxiv. org/abs/1804.04438.
Laurent Sifre and Stéphane Mallat. Rotation, scaling and deformation invariant scattering for texture discrimination. In Computer Vision and Pattern Recognition (CVPR), 2013 IEEE Conference on, pp. 1233–1240. IEEE, 2013.
Ian Simon, Noah Snavely, and Steven M Seitz. Scene summarization for online image collections. In Computer Vision, 2007. ICCV 2007. IEEE 11th International Conference on, pp. 1–8. IEEE, 2007.
Eero P Simoncelli, William T Freeman, Edward H Adelson, and David J Heeger. Shiftable multiscale transforms. IEEE transactions on Information Theory, 38(2):587–607, 1992.
Karen Simonyan and Andrew Zisserman. Very deep convolutional networks for large-scale image recognition. arXiv preprint arXiv:1409.1556, 2014.
Jiawei Su, Danilo Vasconcellos Vargas, and Sakurai Kouichi. One pixel attack for fooling deep neural networks. arXiv preprint arXiv:1710.08864, 2017.
Christian Szegedy, Sergey Ioffe, Vincent Vanhoucke, and Alexander A Alemi. Inception-v4, inceptionresnet and the impact of residual connections on learning. In AAAI, volume 4, pp. 12, 2017.
Antonio Torralba and Alexei A Efros. Unbiased look at dataset bias. In Computer Vision and Pattern Recognition (CVPR), 2011 IEEE Conference on, pp. 1521–1528. IEEE, 2011.
Tobias Weyand and Bastian Leibe. Discovering favorite views of popular places with iconoid shift. In Computer Vision (ICCV), 2011 IEEE International Conference on, pp. 1132–1139. IEEE, 2011.
Daniel E Worrall, Stephan J Garbin, Daniyar Turmukhambetov, and Gabriel J Brostow. Harmonic networks: Deep translation and rotation equivariance. In Proc. IEEE Conf. on Computer Vision and Pattern Recognition (CVPR), volume 2, 2017.
Yichong Xu, Tianjun Xiao, Jiaxing Zhang, Kuiyuan Yang, and Zheng Zhang. Scale-invariant convolutional neural networks. arXiv preprint arXiv:1411.6369, 2014.
Matthew D Zeiler and Rob Fergus. Visualizing and understanding convolutional networks. In European conference on computer vision, pp. 818–833. Springer, 2014.
Bolei Zhou, Aditya Khosla, Àgata Lapedriza, Aude Oliva, and Antonio Torralba. Object detectors emerge in deep scene cnns. CoRR, abs/1412.6856, 2014. URL http://arxiv.org/abs/ 1412.6856.
# APPENDIX
# A PIPELINE FOR PRODUCING THE BOTTOM ROW OF FIGURE 1
We download this video: https://www.youtube.com/watch?v=0mgnf6t9VEc using an online downloader. We load the video frames and resize them to 299 by 299 as used by the standard Keras applications framework (https://keras.io/applications/). We preprocess the frames using the standard Keras preprocessing function. Finally, we use the predictions of the InceptionV3 model to demonstrate the jagged behavior shown in figure 1.
# B OTHER SUPPLEMENTARY MATERIAL
<table><tr><td>Network</td><td>Top-1</td><td>Top-5</td><td>Parameters</td><td>Depth</td></tr><tr><td>VGG16 (Simonyan & Zisserman, 2014)</td><td>0.715</td><td>0.901</td><td>138,357,544</td><td>16</td></tr><tr><td>ResNet50 (He et al., 2016)</td><td>0.759</td><td>0.929</td><td>25,636,712</td><td>50</td></tr><tr><td>InceptionResNetV2 (Szegedy et al., 2017)</td><td>0.804</td><td>0.953</td><td>55,873,736</td><td>134</td></tr></table>
Table 1: The networks used (taken from (https://keras.io/applications/))
 Figure 7: We also measure jaggedness using the Mean Absolute Difference (MAD) in the probability of the correct response as the image is shifted by a single pixel. Results are similar to those using the jaggedness measure described in the text.
 Figure 8: Modern deep convolutional neural networks are sensitive to small image translations (Without image downscaling). A) Example of InceptionResNetV2 sensitivity to very small horizontal translations. B) Comparison of three networks of various depths (16, 50, and 134 for VGG16, ResNet50, and InceptionResNetV2 respectively) in the task of horizontal image translation. Rows are sorted by sum. B) Modern networks have more jagged predictions. Jaggedness is calculated by counting the number of times the network’s predictions had the correct class in its top-5 and after just one pixel shift it moved outside of the top-5 (and also the opposite transition from non-top-5 to top5). Similar results can be seen with the alternative measure of jaggedness: Mean Absolute Difference (MAD)
 Figure 9: Modern deep convolutional neural networks are sensitive to small image rescalings A) Comparison of three networks of various depths (16, 50, and 134 for VGG16, ResNet50, and InceptionResNetV2 respectively) in the task of image rescaling. Rows are sorted by their sum. B) Quantification of the jagged behaviour of the deep neural networks.
 Figure 10: Nonshiftability as a function of depth in the three networks. Nonshiftability is defined as the number of times the global sum of a feature map changes by more than $20 \%$ of the mean as the input is translated. We only consider feature maps where the maximum response was above a threshold. According to our analysis, this measure should be zero if the representation is shiftable. Each line shows the nonshiftability in different layers in response to a randomly selected image.
 Figure 11: Another randomly selected image. Plotted are summation of feature maps from the last layer of VGG (spatial dimension $7 \mathrm { x } 7$ ) as the input is vertically translated in the image plane (top), or rescaled (bottom). Left: the original VGG16 with its $2 \mathbf { x } 2$ max pooling layers. Right: VGG16 where every $2 \mathbf { x } 2$ max pooling layer was replaced by a 6x6 average pooling layer.
 Figure 12: Another randomly selected image. Plotted are summation of feature maps from the last layer of VGG (spatial dimension $7 \mathrm { x } 7$ ) as the input is vertically translated in the image plane (top), or rescaled (bottom). Left: the original VGG16 with its $2 \mathbf { x } 2$ max pooling layers. Right: VGG16 where every 2x2 max pooling layer was replaced by a 6x6 average pooling layer.
 Figure 13: Another randomly selected image. Plotted are summation of feature maps from the last layer of VGG (spatial dimension $7 \mathrm { x } 7$ ) as the input is vertically translated in the image plane (top), or rescaled (bottom). Left: the original VGG16 with its $2 \mathbf { x } 2$ max pooling layers. Right: VGG16 where every $2 \mathbf { x } 2$ max pooling layer was replaced by a 6x6 average pooling layer.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499# A THEORETICAL ANALYSIS OF THE NUMBER OF SHOTS IN FEW-SHOT LEARNING
Tianshi $\mathbf { C a o ^ { 1 , 2 } }$ , Marc T. Law1,2,3, Sanja Fidler1,2,3 1 Department of Computer Science, University of Toronto 2 Vector Institute 3 NVIDIA {jcao, law, fidler}@cs.toronto.edu
# ABSTRACT
Few-shot classification is the task of predicting the category of an example from few labeled examples. The number of labeled examples per category is called the number of shots (or shot number). Recent works tackle this task through metalearning, where a meta-learner extracts information from observed tasks during meta-training to quickly adapt to new tasks during meta-testing. In this formulation, the number of shots exploited during meta-training has an impact on the recognition performance at meta-test time. Generally, the shot number used in meta-training should match the one used in meta-testing to obtain the best performance. We introduce a theoretical analysis of the impact of the shot number on Prototypical Networks, a state-of-the-art few-shot classification method. From our analysis, we propose a simple method that is robust to the choice of shot number used during meta-training, which is a crucial hyperparameter. The performance of our model trained for an arbitrary meta-training shot number shows great performance for different values of meta-testing shot numbers. We experimentally demonstrate our approach on different few-shot classification benchmarks.
# 1 INTRODUCTION
Human cognition has the impressive ability of grasping new concepts from exposure to a handful of examples (Yger et al., 2015). In comparison, while modern deep learning methods achieve unprecedented performances with very deep neural-networks (He et al., 2016; Szegedy et al., 2015), they require extensive amounts of data to train, often ranging in the millions. Few-shot learning aims to bridge the sample-efficiency gap between deep learning and human learning in fields such as computer vision, reinforcement learning and speech recognition (Santoro et al., 2016; Ravi & Larochelle, 2017; Finn et al., 2017; Vinyals et al., 2016; Wang et al., 2019a). These methods fall under the framework of meta-learning, in which a meta-learner extracts knowledge from many related tasks (in the meta-training phase) and leverages that knowledge to quickly learn new tasks (in the meta-testing phase). In this paper, we focus on the few-shot classification problem where each task is defined as a $N$ -way classification problem with $k$ samples (shots) per class available for training.
Many meta-learning methods use the episodic training setup in which the meta-learner iterates through episodes in the meta-training phase. In each episode, a task is drawn from some population and a limited amount of support and query data from that task is made available. The meta-learner then learns a task-specific classifier on the support data and the classifier predicts on the query data. Updates to the meta-learner is computed based on the performance of the classifier on the query set. Evaluation of the meta-learner (during a phase called meta-testing) is also carried out in episodes in a similar fashion, except that the meta-learner is no longer updated and the performance on query data across multiple episodes is aggregated.
In the episodic setup, the selection of $k$ during meta-training time can have significant effects on the learning outcomes of the meta-learner. Intuitively, if support data is expected to be scarce, the meta-learner needs to provide strong inductive bias to the task-specific learner as the danger of overfitting is high. In contrast, if support data is expected to be abundant, then the meta-learner can provide generally more relaxed biases to the task-specific learner to achieve better fitting to the task data. Therefore it is plausible that a meta-learner trained with one $k$ value can be suboptimal at adapting to tasks with a different $k$ value and thus exhibit meta-overfitting to $k$ . In experiments, $k$ is often simply kept fixed between meta-training and meta-testing, but in real-world usage, one cannot expect to know beforehand the amount of support data from unseen tasks during deployment.
In this paper we will focus on Prototypical networks (Snell et al., 2017), a.k.a. ProtoNet. ProtoNet is of practical interest because of its flexibility: a single trained instance of ProtoNet can be used on new tasks with any $k$ and $N$ . However, ProtoNet exhibits performance degradation when the $k$ used in training does not match the $k$ used in testing.1 First, we will undertake a theoretical investigation to elicit the connection from $k$ to a lower bound of expected performance, as well as to the intrinsic dimension of the learned embedding space. Then, we conduct experiments to empirically verify our theoretical results across various settings. Guided by our new understanding of the effects of $k$ , we propose an elegant method to tackle performance degradation in mismatched $k$ cases. Our contributions are threefold:
• We provide performance bounds for ProtoNets given an embedding function. From which, we argue that $k$ affects learning and performance by scaling the contribution of intra-class variance.
• Through VC-learnability theory, we connect the value of $k$ used in meta-training to the intrinsic dimension of the embedding space.
• The most important contribution of this paper (introduced in Section 3.3) is a new method that improves upon vanilla ProtoNets by eliminating the performance degradation in cases where the $k$ is mismatched between meta-training and meta-testing. Our evaluation protocol more closely adheres to real-world scenarios where the model is exposed to different numbers of training samples.
# 2 BACKGROUND
# 2.1 PROBLEM SETUP
The few-shot classification problem considered in this paper is set up as described below. Consider a space of classes $C$ with a probability distribution $\tau$ , $N$ classes $\mathbf { c } \doteq \{ c _ { 1 } , . . . , c _ { N } \}$ are sampled i.i.d. from $\tau$ to form a $N$ -way classification problem. For each class $c _ { i }$ , $k$ support data are sampled from class-conditional distribution $S _ { i } = \{ _ { s } { \bf x } _ { 1 } , . . , _ { s } { \bf x } _ { k } \} \stackrel { i i d } { \sim } P ( { \bf x } | Y ( { \bf x } ) = c _ { i } )$ , where $\mathbf { x } \in \mathbb { R } ^ { D }$ , $D$ denotes the dimension of data, and $Y ( \mathbf { x } )$ denotes the class assignment of $\mathbf { x }$ . Note that we assume that $Y ( \mathbf { x } )$ is singular (e.g. each $\mathbf { x }$ can only have 1 label), and does not depend on $N$ (e.g. a data point with a label “cat” will always have the label “cat”), in contrast to $y$ defined below.
Additionally, the set $Q = \{ _ { q } \mathbf { x } _ { 1 } , . . . , _ { q } \mathbf { x } _ { l } \}$ containing $l$ query data is sampled from the joint distribution $\begin{array} { r } { \frac { 1 } { N } \sum _ { i = 1 } ^ { N } P ( \mathbf { x } | c _ { i } ) } \end{array}$ .2 For each $\mathbf { x }$ , let $y \in \{ 1 , . . . , N \}$ denote its label in the context of the few-shot classificafor class $c _ { i }$ n task. Define , and denote t $\hat { S } _ { i } = \left\{ ( _ { s } \mathbf { x } _ { 1 } , y _ { 1 } = i ) , . . . , ( _ { s } \mathbf { x } _ { k } , y _ { k } = i ) \right\}$ $N$ as as $\textstyle S = \bigcup _ { i = 1 } ^ { N } { \hat { S } } _ { i }$ set of supports. The few-shot classification task is to predict $y$ for each $\mathbf { x }$ in $Q$ given $S$ . During meta-training, the ground truth label for $Q$ is also available to the learner.
# 2.2 META-LEARNING SETUP
Meta-learning approaches train on a distribution of tasks to obtain information that generalizes to unseen tasks. For few-shot classification, a task is determined by which classes are involved in the $N$ -way classification task. During meta-training, the meta-learner observes episodes of few-shot classification tasks consisting of $N$ classes, $k$ labelled samples per class, and $l$ unlabelled samples, as previously described. The collection of all classes observed during meta-training forms the metatraining split $\mathcal { D } _ { t r } = \{ { _ { t r } c _ { 1 } } , . . . , { _ { t r } c _ { R } } \}$ . Critically, we assume that every unseen class that the learner is evaluated upon (during meta-testing) is also drawn from the same distribution $\tau$ .
# 2.3 PROTOTYPICAL NETWORKS
ProtoNets (Snell et al., 2017) compute $E$ -dimensional embeddings for all samples in $S$ and $Q$ . The embedding function $\phi : \mathbb { R } ^ { D } \mathbb { R } ^ { \dot { E } }$ is usually a deep network.The prototype representation for each class is formed by averaging the embeddings for all supports of said class: $\begin{array} { r } { \overline { { \phi ( S _ { i } ) } } = \frac { 1 } { k } \sum _ { \mathbf { x } \in S _ { i } } \phi ( \mathbf { x } ) } \end{array}$ . Classification of any input $\mathbf { x }$ (e.g. $\mathbf { x } \in Q$ i) is performed by computing the softmax over squared Euclidean distances of the input point’s embedding to the prototypes. Let $\hat { y }$ denote the prediction of the classifier for one of the categories $j \in \{ 1 , \cdots , N \}$ :
$$p _ { \phi } ( \hat { y } = j | \mathbf { x } , S ) = \frac { e ^ { - \left\| \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { j } ) } } \right\| ^ { 2 } } } { \sum _ { i = 1 } ^ { N } e ^ { - \left\| \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { i } ) } } ^ { 2 } \right\| } } \quad , \mathrm { w h e r e } \quad \left\| \mathbf { v } \right\| ^ { 2 } = \sum _ { d = 1 } ^ { E } v _ { d } ^ { 2 }$$
The parameters of the embedding functions are learned through meta-training. Negative log-likelihood $J ( \phi ) = - \log \left( p ( \hat { y } = y | \mathbf { x } ) \right)$ of the correct class $y$ is minimized on the query points through SGD.
As explained in (Law et al., 2019), ProtoNets can be seen as a metric learning approach optimized for the supervised hard clustering task (Law et al., 2016). The model $\phi$ is learned so that the representations of similar examples (i.e. belonging to a same category) are all grouped into the same cluster in $\mathbb { R } ^ { E }$ . We propose in this paper a subsequent metric learning step which learns a linear transformation that maximizes inter-to-intra class variance ratio.
# 3 PROPOSED METHOD
We first present theoretical results explaining the effect of the shot number on ProtoNets, and then introduce our method for addressing performance degradation in cases of mismatched shots.
# 3.1 RELATING $k$ TO LOWER BOUND OF EXPECTED ACCURACY
To better understand the role of $k$ on the performance of ProtoNets, we study how it contributes to the expected accuracy across episodes when using any kind of fixed embedding function (e.g. the embedding function obtained at the end of the meta-training phase). With $I$ denoting the indicator function, we define the expected accuracy $R$ as:
$$R ( \phi ) = \mathbb { E } _ { \mathbf { c } } \mathbb { E } _ { S , \mathbf { x } , y } I [ \arg \operatorname* { m a x } _ { j } \left\{ p _ { \phi } ( \hat { y } = j | \mathbf { x } , S ) \right\} = y ]$$
Definitions: Throughout this section, we will use the following symbols to denote the means and variances of embeddings under different expectations:
$${ \begin{array} { r l } & { \mathbf { \mu } _ { c } \triangleq \mathbb { E } _ { \mathbf { x } } [ \phi ( \mathbf { x } ) | \ X ( \mathbf { x } ) = c ] \qquad \quad \Sigma _ { c } \triangleq \mathbb { E } _ { \mathbf { x } } [ ( \phi ( \mathbf { x } ) - \mathbf { \mu } _ { c } ) ( \phi ( \mathbf { x } ) - \mathbf { \mu } _ { c } ) ^ { T } | \ Y ( \mathbf { x } ) = c ] } \\ & { \quad \mathbf { \mu } \triangleq \mathbb { E } _ { c } [ \mathbf { \mu } _ { c } ] \qquad \quad \Sigma \triangleq \mathbb { E } _ { c } [ ( \mathbf { \mu } _ { c } - \mathbf { \mu } ) ( \mathbf { \mu } _ { c } - \mathbf { \mu } ) ^ { T } ] } \end{array} }$$
Remark. $\mu _ { c }$ is the expectation of the embedding conditioned on class $c , \mu$ is the (full) expectation of the embedding, which can be expressed as the expectation of $\mu _ { c }$ over classes. $\Sigma$ is the variance of class means in the embedding space - it can be interpreted as the signal of the input to the classifier, as larger $\Sigma$ implies larger distances between classes. $\Sigma _ { c }$ is the expected intra-class variance - it represents the noise in the above signal.
Modelling assumptions of ProtoNets: The use of the squared Euclidean distance and softmax activation in ProtoNets implies that classification with ProtoNets is equivalent to a mixture density estimation on the support set with spherical Gaussian densities (Snell et al., 2017). Specifically, we adopt the modelling assumptions that the distribution of $\phi ( \mathbf { x } )$ given any class assignment is normally distributed $( p ( \phi ( \mathbf { x } ) \bar { | } Y ( \mathbf { x } ) \bar { = } c ) = \mathcal { N } ( \mu _ { c } , \Sigma _ { c } ) )$ , with equal covariance for all classes in the embedding space $( \forall ( c , c ^ { \prime } ) , \Sigma _ { c } = \Sigma _ { c ^ { \prime } } ) ^ { 3 }$ .
We present the analysis for the special case of episodes with binary classification (i.e. with $N = 2$ ) for ease of presentation, but the conclusion can be generalized to arbitrary $N > 2$ (see appendix).
Also, as noted in Section 2.1, we assume equal likelihood between the classes. We would like to emphasize that the assignment of labels can be permuted freely and the classifier’s prediction would not be affected due to symmetry. Hence, we only need to consider one case for the ground truth label without loss of generality. Let $a$ and $b$ denote any pair of classes sampled from $\tau$ . Let $\mathbf { x }$ be drawn from $a$ , and overload $a$ and $b$ to also indicate the ground truth label in the context of that episode, then equation 2 can be written as:
$$R ( \phi ) = \mathbb { E } _ { a , b \sim \tau } \mathbb { E } _ { \mathbf { x } , S } I [ \hat { y } = a ]$$
Additionally, noting that $p ( \hat { y } = a )$ can be expressed as a sigmoid function $\sigma$ :
$$p ( \hat { y } = a | \mathbf { x } ) = \frac { e ^ { - \left\| \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { a } ) } } \right\| ^ { 2 } } } { e ^ { - \left\| \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { b } ) } } \right\| ^ { 2 } } + e ^ { - \left\| \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { a } ) } } \right\| ^ { 2 } } } = \sigma ( \left\| \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { b } ) } } \right\| ^ { 2 } - \left\| \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { a } ) } } \right\| ^ { 2 } )$$
We can express equation 3 as a probability:
$$R ( \phi ) = \operatorname* { P r } _ { a , b , \mathbf { x } , S } ( { \hat { y } } = a ) = \operatorname* { P r } _ { a , b , \mathbf { x } , S } ( \alpha > 0 )$$
We will introduce a few auxiliary results before stating the main result for this section.
Proposition 1. From the one-sided Chebyshev’s inequality, it immediately follows that:
$$R ( \phi ) = \mathrm { P r } ( \alpha > 0 ) \geq \frac { \mathbb { E } [ \alpha ] ^ { 2 } } { \mathrm { V a r } ( \alpha ) + \mathbb { E } [ \alpha ] ^ { 2 } }$$
In Lemma 1 and Lemma 2, we derive the expectation and variance of $\alpha$ when conditioned on the classes sampled in a episode. Then, in Theorem 3, we compose them into the $R H S$ of Proposition 1 through law of total expectation.
Lemma 1. Consider space of classes $C$ with sampling distribution $\tau$ $; , a , b \stackrel { i i d } { \sim } \tau .$ . Let $S = \{ S _ { a } , S _ { b } \}$ $S _ { a } = \left\{ { { \bf { \Psi } } _ { a } { \bf { x } } _ { 1 } } , . . . , { \bf { \Psi } } _ { a } { \bf { x } } _ { k } \right\}$ , $S _ { b } = \left\{ \vphantom { b } _ { b } \mathbf { x } _ { 1 } , . . . , \vphantom { b } _ { b } \mathbf { x } _ { k } \right\}$ , $k \in \mathbb N$ is the shot number, and $Y ( \mathbf { x } ) = a$ . Define ${ \overline { { \phi ( S _ { a } ) } } } \triangleq { \frac { 1 } { k } } \sum _ { \mathbf { x } \in S _ { a } } \phi ( \mathbf { x } )$ and ${ \overline { { \phi ( S _ { b } ) } } } \triangleq { \frac { 1 } { k } } \sum _ { \mathbf { x } \in S _ { b } } \phi ( \mathbf { x } )$ . Consider $\Sigma$ as defined earlier. Assume $p ( \phi ( \mathbf { x } ) | Y ( \mathbf { x } ) = c ) = N ( \mu _ { c } , \Sigma _ { c } )$ and $\Sigma _ { c } = \Sigma _ { c ^ { \prime } }$ for any choice of $c , c ^ { \prime } \in C$ , then,
$$\mathbb { E } _ { \mathbf { x } , S | a , b } [ \alpha ] = \left( \mathtt { u } _ { a } - \mathtt { u } _ { b } \right) ^ { T } ( \mathtt { u } _ { a } - \mathtt { u } _ { b } ) \qquad , a n d \qquad \mathbb { E } _ { a , b , \mathbf { x } , S } [ \alpha ] = 2 \mathrm { T r } ( \Sigma ) .$$
Lemma 2. Under the same notation and assumptions as Lemma $I$ , additionally invoking definition for $\Sigma _ { c } ,$ then,
$$\mathbb { E } _ { a , b } [ \mathrm { V a r } ( \alpha | a , b ) ] \leq 8 ( 1 + \frac { 1 } { k } ) \mathrm { T r } \left( \Sigma _ { c } ( ( 1 + \frac { 1 } { k } ) \Sigma _ { c } + 2 \Sigma ) \right) .$$
The proofs of the above lemmas are in the appendix. With the results above, we are ready to state our main theoretical result in this section.
Theorem 3. Under the conditions where Lemma 1 and 2 hold, we have:
$$R ( \phi ) \geq \frac { 4 \mathrm { T r } ( \Sigma ) ^ { 2 } } { 8 ( 1 + 1 / k ) ^ { 2 } \mathrm { T r } ( \Sigma _ { c } ^ { 2 } ) + 1 6 ( 1 + 1 / k ) \mathrm { T r } ( \Sigma \Sigma _ { c } ) + \mathbb { E } _ { a , b } [ ( \mathbf { \mu } ( \mathbf { \mu } _ { a } - \mathbf { \mu } \mathbf { \mu } _ { b } ) ^ { T } ( \mathbf { \mu } _ { a } - \mathbf { \mu } \mathbf { \mu } _ { b } ) ) ^ { 2 } ] } .$$
Proof. First, we use decompose the $\mathrm { V a r } ( \alpha )$ term in Proposition 1 by Law of Total Expectation.
$$\begin{array} { r l } & { \mathrm { V a r } ( \boldsymbol \alpha ) = \mathbb { E } _ { a , b , \mathbf { x } , S } [ \boldsymbol \alpha ^ { 2 } ] - \mathbb { E } _ { a , b , \mathbf { x } , S } [ \boldsymbol \alpha ] ^ { 2 } = \mathbb { E } _ { a , b } \mathbb { E } _ { \mathbf { x } , S } [ \boldsymbol \alpha ^ { 2 } | a , b ] - \mathbb { E } _ { a , b , \mathbf { x } , S } [ \boldsymbol \alpha ] ^ { 2 } } \\ & { \quad \quad \quad \quad = \mathbb { E } _ { a , b } [ \mathrm { V a r } ( \boldsymbol \alpha | a , b ) + \mathbb { E } _ { \mathbf { x } , S } [ \boldsymbol \alpha | a , b ] ^ { 2 } ] - \mathbb { E } _ { a , b , \mathbf { x } , S } [ \boldsymbol \alpha ] ^ { 2 } . } \end{array}$$
Hence, Proposition 1 can also be expressed as
$$R ( \phi ) \geq \frac { \mathbb { E } [ \alpha ] ^ { 2 } } { \mathbb { E } _ { a , b } [ \mathrm { V a r } ( \alpha \vert a , b ) + \mathbb { E } _ { \mathbf { x } , S } [ \alpha \vert a , b ] ^ { 2 } ] } .$$
Finally, we arrive at Theorem 3 by plugging Lemma 1 and 2 into equation 10.
Several observations can be made from Theorem 3:
1. The shot number $k$ only appears in the first two terms of the denominator, implying that the bound saturates quickly with increasing $k$ . This is also in agreement with the empirical observation that meta-testing accuracy has diminishing improvements when more support data is added.
2. By observing the degree of terms in equation 7 (and treating the last term of the denominator as a constant), it is clear that increasing $k$ will decrease the sensitivity (magnitude of partial derivative) of this lower bound to $\Sigma _ { c }$ , and increase its sensitivity to $\Sigma$ .
3. If one postulates that meta-learning updates on $\phi$ are similar to gradient ascent on this accuracy lower bound, then learning with smaller $k$ emphasizes minimizing noise, while learning with higher $k$ emphasizes maximizing signal.
In conclusion, these observations give us a plausible reason for the performance degradation observed in mismatched shots: when an embedding function has been optimized (trained) for $k _ { t r a i n } ~ >$ $k _ { t e s t }$ , the relatively high $\Sigma _ { c }$ is amplified by the now smaller $k$ , resulting in degraded performance. Conversely, an embedding function trained for $k _ { t r a i n } ~ < ~ k _ { t e s t }$ already has small $\Sigma _ { c }$ , such that increasing $k$ during testing has further diminished improvement on performance.
# 3.2 INTERPRETATION IN TERMS OF VC DIMENSION
In any given episode, a nearest neighbour prediction is performed from the support data (with a fixed embedding function). Therefore, a PAC learnability interpretation of the relation between the number of support data and complexity of the classifier can be made. Specifically, for binary classification, classical PAC learning theory (Vapnik et al., 1994) states that with probability of at least $1 - \delta$ , the following inequality on the difference between empirical error $e r r _ { t r a i n }$ (of the support samples) and true error $e r r _ { t r u e }$ holds for any classifier $h$ :
$$e r r _ { t r u e } ( h ) - e r r _ { t r a i n } ( h ) \leq \sqrt { \frac { D ( \ln \frac { 4 k } { D } + 1 ) + \ln \frac { 4 } { \delta } } { 2 k } }$$
Where $D$ is the VC dimension, and $k$ is the number of support samples per class 4. Under this binary classification setting, the predictions of prototypical network are equal to $\sigma ( \alpha )$ as shown earlier. Denoting $\mathbf { z } _ { c } = \overline { { \phi ( S _ { c } ) } }$ and $\mathbf { z } _ { c ^ { \prime } } = \overline { { \phi ( S _ { c ^ { \prime } } ) } }$ , we can manipulate $\alpha$ as follows:
$$\begin{array} { r l } { \alpha = \left\| \phi ( \mathbf { x } ) - \mathbf { z } _ { c } \right\| ^ { 2 } - \left\| \phi ( \mathbf { x } ) - \mathbf { z } _ { c ^ { \prime } } \right\| ^ { 2 } } & { { } = 2 ( \mathbf { z } _ { c ^ { \prime } } - \mathbf { z } _ { c } ) ^ { T } \phi ( \mathbf { x } ) + ( \mathbf { z } _ { c } ^ { T } \mathbf { z } _ { c } - \mathbf { z } _ { c ^ { \prime } } ^ { T } \mathbf { z } _ { c ^ { \prime } } ) } \end{array}$$
From equation 12, the prototypes form a linear classifier with offset in the embedding space. The VC dimension of this type of classifier is $1 + d$ where $d$ is the intrinsic dimension of the embedding space (Vapnik, 1998). In ProtoNets, the intrinsic dimension of the embedding space is not only influenced by network architecture, but more importantly determined by the parameter themselves, making it a learned property. For example, if the embedding function can be represented with a linear transformation $\phi ( \mathbf { x } ) = \Phi \cdot \mathbf { x }$ , then the intrinsic dimension of the embedding space is upper bounded by the rank of $\Phi$ (since all embeddings must lie in the column space of $\Phi$ ). Thus, the number of support samples required to learn from an episode is proportional to the intrinsic dimension of the embedding space. We hypothesize that an embedding function optimal for lower shot (e.g. one-shot) classification affords fewer intrinsic dimensions than one that is optimal for higher shot (e.g. 10-shot) classification.
# 3.3 RECONCILING SHOT DISCREPANCY THROUGH EMBEDDING SPACE TRANSFORMATION
Observations in Section 3.2 reveal that an ideal $\phi$ would have an output space whose intrinsic dimension $d$ is as small as possible to minimize the right-hand side of equation 11 but just large enough to allow low $e r r _ { t r a i n }$ ; the balance between the two objectives is dictated by $k$ . Similarly, observations in Section 3.1 suggest that an ideal $\phi$ would balance between minimizing $\Sigma _ { c }$ and maximizing $\Sigma$ also according to $k$ . As a result, when there is discrepancy between meta-training shots and meta-testing shots5, accuracy at meta-test time will suffer. A naive solution is to prepare many embedding functions trained for different shots, and select the embedding function according to the availability of label data at test-time. However, this solution is computationally burdensome as it requires multiple models to be trained and stored. Instead, we want to train and store a single model, and then adapt the embedding function’s variance characteristics and the embedding space dimensionality to achieve good performance for any test shot.
Linear Discriminant Analysis (LDA) is a dimensionality reduction method suited for downstream classification (Fukunaga, 1990). Its goal is to find a maximally discriminating subspace (maximum inter-class variance and minimal intra-class variance) for a given classification task. Theoretically, performance can be maximized in each individual episode by computing the LDA transformation matrix using support samples of that episode. LDA computes the eigenvectors of the matrix $S ^ { - 1 } S _ { \mu }$ , where $S _ { \mu }$ is the covariance matrix of prototypes and $S$ is the class-conditional covariance matrix. In practice, $S _ { \mu }$ and $S$ cannot be stably estimated in few-shot episodes, preventing the direct application of LDA.
We propose an alternative which we call Embedding Space Transformation (EST). The purpose of EST is to perform dimensionality reduction on the features, while also improving the ratio in Theorem 3. This is a different goal from LDA because Theorem 3 demonstrates that the expected performance across many episodes can be improved by maximizing $\Sigma$ and minimizing $\Sigma _ { c }$ . Similar to LDA, EST works by applying a linear transformation
$$\phi ( \mathbf { x } ) \mapsto V ^ { * } ( \phi ( \mathbf { x } ) )$$
to the outputs of the embedding function. Here, $V ^ { * }$ is a linear transformation computed using $\mathcal { D } _ { t r }$ after meta-training has completed. To compute $V ^ { * }$ , we first iterate through all classes in $\mathcal { D } _ { t r }$ and compute their in-class means and covariance matrices in the embedding space. We can then find the covariance of means $\Sigma _ { \mu }$ , and the mean of covariances $\overline { { \Sigma } } _ { s }$ across $\mathcal { D } _ { t r }$ . Finally, $V ^ { * }$ is computed by taking the leading eigenvectors of $\Sigma _ { \mu } - \rho \overline { { \Sigma } } _ { s }$ - the difference between the covariance matrix of the mean and the mean covariance matrix with weight parameter $\rho$ . The exact procedure for computing $V ^ { * }$ is presented in the appendix.
# 4 EXPERIMENTS AND RESULTS
In this section, our first two experiments aim at supporting our theoretical results in Sections 3.1 and 3.2, while our third experiment demonstrates the improvement of EST on benchmark data sets over vanilla ProtoNets. To illustrate the applicability of our results to different embedding function architectures, all experiments are performed with both a vanilla 4-layer CNN (as in (Snell et al., 2017)) and a 7-layer Residual network (He et al., 2016). Detailed description of the architecture can be found in the appendix. Experiments are performed on three data sets: Omniglot (Lake et al., 2015), miniImageNet (Vinyals et al., 2016), and tieredImageNet (Ren et al., 2018). We followed standard data processing procedures which are detailed in the appendix.
# 4.1 TRAINING SHOTS AFFECT VARIANCE CONTRIBUTION
The total variance observed among embeddings of all data points can be seen as a composition of inter-class and (expected) intra-class variance based on the law of total variance $\mathrm { ( V a r } [ \mathbf { x } ] \ =$ $\mathbb { E } [ \mathrm { V a r } ( \mathbf { x } | c ) ] + \mathrm { V a r } ( \mathbb { E } [ \mathbf { x } | c ] ) = \mathbb { E } [ \Sigma _ { c } ] + \Sigma _ { \mu } )$ . Our analysis predicts that as we increase the shot number used during training, the ratio of inter-class to intra-class variance will decrease.
To verify this hypothesis, we trained ProtoNets (vanilla and residual) with a range of shots (1 to 10 on miniImageNet and tiered imagenet, 1 to 5 on Omniglot) until convergence with 3 random initializations per group. Then, we computed the inter-class and intra-class covariance matrices across all samples in the training-set embedded by each network. To qualify the amplitude of each matrix, we take the trace of each covariance matrix. The ratio of inter-class to intra-class variance is presented in Figure 1: as we increase $k$ used during training, the inter-class to intra-class variance ratio decreases. This trend can be observed in both vanilla and residual embeddings, and across all three data sets, lending strong support to our result in Section 3.1. Another observation can be made that the ratio between inter-class and intra-class variance is significantly higher in the Omniglot data set than the other two data sets. This may indeed be reflective of the relative difficulty of each data set and the accuracy of ProtoNet on the data sets.
 Figure 1: Inter-class to Intra-class variance ratios of embedding space varies with $k$ used in training. Left: Omniglot. Right: miniImageNet and tieredImageNet.
# 4.2 TRAINING SHOTS AFFECT INTRINSIC DIMENSION
We consider the intrinsic dimension (id) of an embedding function with extrinsic dimension $E$ (operated on a data set) to be defined as the minimum integer $d$ where all embedded points of that data set lie within a $d$ -dimensional subspace of $\mathbb { R } ^ { E }$ (Bishop, 2006). A simple method for estimating $d$ is through principal component analysis (PCA) of the embedded data set. By eigendecomposing the covariance matrix of embeddings, we obtain the principal components expressed as the significant eigenvalues, and the principal directions expressed as the eigenvectors corresponding to those eigenvalues. The number of significant eigenvalues approximates the intrinsic dimension of the embedding space. When the subspace is linear, this approximation is exact; otherwise, it serves as an upper bound to the true intrinsic dimension (Fukunaga & Olsen, 1971).
We determine the number of significant eigenvalues by an explained-variance over total-variance criterion. The qualifying metric is $\begin{array} { r } { r _ { d } \triangleq \sum _ { i \in [ 1 , d ] } \lambda _ { i } / \sum _ { i \in [ 1 , E ] } \lambda _ { i } } \end{array}$ . In our experiments, we set the threshold for $r _ { d }$ at 0.9. Similar to the previous experiment, we train ProtoNets with different shots to convergence. The total covariance matrix is then computed on the training set and eigendecomposition is performed. The approximate id is plotted for various values of $k$ in Figure 2. We can see a clear trend that as we increase training shot, the id of the embedding space increases.
 Figure 2: Intrinsic dimension approximated by the number of significant eigenvalues varies with $k$ used in training. Left: Omniglot. Right: miniImageNet and tieredImageNet
# 4.3 EXPERIMENTS WITH EST
We evaluate the performance of EST on the three aforementioned data sets. The performance is compared against our implementation of vanilla ProtoNets as a baseline, as well as a variant of ProtoNets using principal components obtained from all embedding points (ProtoNet-PCA).
All methods in this section use the same set of trained ProtoNets. As with before, networks are trained with $k \in \{ 1 , . . . , 5 \}$ on Omniglot and $k \in \{ 1 , . . . , 1 0 \}$ on miniImageNet and tieredImageNet. Additionally, we also trained a mixed-shot network for each data set. This is done by randomly selecting a value for $k$ within the specified range for each episode, and then sampling the corresponding number of support samples. Hyper-parameters for training are described in the appendix.
(a) Omniglot-20-way, with 4 layer CNN.
Table 1: Classification accuracies of ProtoNet variants. Best performing methods and any other runs within $9 5 \%$ confidence margin is in bold (b) Omniglot-20-way, with 7 layer ResNet.
<table><tr><td>MODEL</td><td>TRAINING SHOTS</td><td colspan="2">TESTING SHOTS</td><td>AVERAGE ACCURACY</td><td>MODEL</td><td>TRAINING SHOTS</td><td colspan="2">TESTING SHOTS</td><td>AVERAGE ACCURACY</td></tr><tr><td></td><td></td><td>1</td><td>5</td><td></td><td></td><td></td><td>1</td><td>5</td><td></td></tr><tr><td>VANILLA PROTONET</td><td>1</td><td>95.07%</td><td>98.89%</td><td>97.81%</td><td>VANILLA PROTONET</td><td>1</td><td>96.46%</td><td>99.07%</td><td>98.35%</td></tr><tr><td>VANILLA PROTONET</td><td>5</td><td>93.42%</td><td>98.78%</td><td>97.25%</td><td>VANILLA PROTONET</td><td>5</td><td>94.42%</td><td>98.99%</td><td>97.75%</td></tr><tr><td>MIXED-k SHOT</td><td>1-5</td><td>94.84%</td><td>98.92%</td><td>97.74%</td><td>MIXED-k PROTONET</td><td>1-5</td><td>96.53%</td><td>99.15%</td><td>98.43%</td></tr><tr><td>PCAPROTONET</td><td>1</td><td>94.94%</td><td>98.85%</td><td>97.78%</td><td>PCA PROTONET</td><td>1</td><td>96.02%</td><td>98.99%</td><td>98.19%</td></tr><tr><td>EST PROTONET</td><td>1</td><td>95.11%</td><td>98.84%</td><td>97.83 %</td><td>EST PROTONET</td><td>1</td><td>95.55%</td><td>99.02%</td><td>98.19%</td></tr></table>
(c) miniImageNet-5-way, with 4 layer CNN.
<table><tr><td rowspan="2">MODEL</td><td rowspan="2">TRAINING SHOTS</td><td colspan="3">TESTING SHOTS</td><td rowspan="2">AVERAGE ACCURACY</td></tr><tr><td>1</td><td>5</td><td>10</td></tr><tr><td>PROTONET</td><td>1</td><td>48.89%</td><td>64.70%</td><td>68.90%</td><td>63.15%</td></tr><tr><td>PROTONET</td><td>5</td><td>44.75%</td><td>67.23%</td><td>72.36%</td><td>65.08%</td></tr><tr><td>PROTONET</td><td>10</td><td>39.99%</td><td>66.23%</td><td>72.47%</td><td>63.54%</td></tr><tr><td>MIXED-k SHOT</td><td>1-10</td><td>49.36%</td><td>67.96%</td><td>72.27%</td><td>65.83%</td></tr><tr><td>PCA PROTONET</td><td>5</td><td>49.36%</td><td>68.63%</td><td>72.82%</td><td>66.12%</td></tr><tr><td>EST PROTONET</td><td>5</td><td>50.22%</td><td>68.25%</td><td>73.29%</td><td>66.60%</td></tr></table>
(d) miniImageNet-5-way, with 7 layer ResNet.
<table><tr><td></td><td>TRAINING</td><td colspan="3">TESTING SHOTS</td><td>AVERAGE</td></tr><tr><td>MODEL</td><td>SHOTS</td><td>1</td><td>5</td><td>10</td><td>ACCURACY</td></tr><tr><td>PROTONET</td><td>1</td><td>52.65%</td><td>68.27%</td><td>72.29 %</td><td>66.73%</td></tr><tr><td>PROTONET</td><td>5</td><td>47.40%</td><td>69.93%</td><td>74.35%</td><td>67.18%</td></tr><tr><td>PROTONET</td><td>10</td><td>42.20%</td><td>68.23%</td><td>74.54%</td><td>65.75%</td></tr><tr><td>MIXED-k SHOT</td><td>1-10</td><td>51.74%</td><td>69.09%</td><td>73.63%</td><td>67.41%</td></tr><tr><td>PCA PROTONET</td><td>5</td><td>50.09%</td><td>69.25%</td><td>74.24%</td><td>67.63%</td></tr><tr><td>EST PROTONET</td><td>5</td><td>51.93%</td><td>69.98%</td><td>74.80%</td><td>68.19%</td></tr></table>
(e) tieredImageNet-5-way, with 4 layer CNN.
<table><tr><td></td><td>TRAINING</td><td colspan="3">TESTING SHOTS</td><td>AVERAGE</td></tr><tr><td>MODEL</td><td>SHOTS</td><td>1</td><td>5</td><td>10</td><td>ACCURACY</td></tr><tr><td>PROTONET</td><td>1</td><td>47.37%</td><td>63.70%</td><td>67.99%</td><td>61.85%</td></tr><tr><td>PROTONET</td><td>5</td><td>42.33%</td><td>66.51%</td><td>72.05%</td><td>64.05%</td></tr><tr><td>PROTONET</td><td>10</td><td>35.38%</td><td>64.56%</td><td>71.03%</td><td>61.24%</td></tr><tr><td>MIXED-k SHOT</td><td>1-10</td><td>47.67%</td><td>66.34%</td><td>70.96%</td><td>64.33%</td></tr><tr><td>PCA PROTONET</td><td>5</td><td>48.34%</td><td>67.07%</td><td>71.65%</td><td>64.96%</td></tr><tr><td>EST PROTONET</td><td>5</td><td>48.85%</td><td>67.24%</td><td>72.09 %</td><td>65.46%</td></tr></table>
(f) tieredImageNet-5-way, with 7 layer ResNet.
<table><tr><td></td><td>TRAINING</td><td colspan="3">TESTING SHOTS</td><td>AVERAGE</td></tr><tr><td>MODEL</td><td>SHOTS</td><td>1</td><td>5</td><td>10</td><td>ACCURACY</td></tr><tr><td>PROTONET</td><td>1</td><td>49.78%</td><td>65.17%</td><td>69.88%</td><td>63.98%</td></tr><tr><td>PROTONET</td><td>5</td><td>47.88%</td><td>69.12%</td><td>73.80%</td><td>66.99 %</td></tr><tr><td>PROTONET</td><td>10</td><td>40.86%</td><td>69.37%</td><td>74.72%</td><td>65.95%</td></tr><tr><td>MIXED-k SHOT</td><td>1-10</td><td>50.74%</td><td>69.28%</td><td>73.01 %</td><td>66.95%</td></tr><tr><td>PCA PROTONET</td><td>5</td><td>51.21%</td><td>68.88%</td><td>72.17 %</td><td>67.14%</td></tr><tr><td>EST PROTONET</td><td>5</td><td>53.05%</td><td>69.30%</td><td>73.63%</td><td>67.91%</td></tr></table>
Each model is evaluated on the test splits of the corresponding data sets (e.g. networks trained on Omniglot are only evaluated on Omniglot). Five test runs are performed per network on Omniglot to evaluate the $k$ -shot performance $( k \in [ 1 , 5 ] )$ ). Each run consists of 600 episodes formed by 1-5 support samples and 5 query sample per class. The performance is aggregated across runs for the combined performance. Similarly, on miniImageNet and tieredImageNet, 10 test runs are performed with support per sample $k \in [ 1 , 1 0 ]$ , 600 episodes per run, and 15 query samples in each episode.
Model configuration: Vanilla ProtoNet is used as our baseline. We present the performance of multiple ProtoNets trained with different shots to illustrate the performance degradation issue. ProtoNet-PCA uses principal components of the training split embeddings in place of $V ^ { * }$ , with components other than the $d$ leading ones zeroed out. We carry out a parameter sweep on miniImageNet and set $d = 6 0$ ; the same value is used on the other two data sets. For selecting the training shot of the embedding network, we find that overall performance to be optimal using $k = 5$ . ProtoNet-EST contains three parameters that need to be determined: $\rho , d$ , and training shots of the embedding network. For our experiments, we set $\rho = 0 . 0 0 1$ and $d = 6 0$ based on performance on miniImageNet. For selecting the number of training shots, we use the same strategy as before by evaluating ProtoNetEST with all trained embedding networks and found the same trend to hold.
As an abalation study, FC-ProtoNet adds a fully connected layer to the embedding network such that the output dimension is also 60. Results of this variant can be found in the appendix.
EST performance results: Table 1 summarizes the performance of the evaluated methods on all data sets. Due to space constraints, only 1-shot, 5-shot, 10-shot and 1-10 shot average performance are included. Additional results are in the appendix. The best performing method in each evaluation is in bold. On Omniglot, there is no significant difference in performance between the best performing vanilla ProtoNet and any other methods. We attribute this to the already high accuracy of the baseline model. On miniImageNet and tieredImageNet, EST-ProtoNet significantly outperforms baseline methods and PCA-protonet in terms of average accuracy over test runs with different shots.
We observe that matching the training shot to the test shot generally provides the best performance for vanilla ProtoNets. Also importantly, training with a mixture of different values of $k$ does not provide optimal performance when evaluated on the same mixture of $k$ values. Instead, the resulting performance is mediocre in all test shots. ProtoNet-EST provides minor improvements over the best-performing baseline method under most test shots settings. We hypothesize that this is due to EST aligning the embedding space to the directions with high inter-class variance and low intra-class variance. Comparison against the direct PCA approach demonstrates that the performance uplift is not entirely attributed to reducing the dimensions of the embedding space.
In conclusion, EST improves the performance of ProtoNets on the more challenging data sets when evaluated with various test shots. It successfully tackles performance degradation when testing shots and training shots are different. This improvement is vital to the deployment of ProtoNets in real world scenarios where the number of support samples cannot be determined in advance.
# 5 RELATED WORK
We summarize related work on extensions of ProtoNets, on improving the few-shot classification setup, and on analyzing theoretical properties of meta-learning methods.
Extensions of ProtoNets: Allen et al. (2019) build upon ProtoNets by allowing each class to be represented by multiple prototypes, thereby improving the representation power of ProtoNets. Oreshkin et al. (2018) use a context-conditioned embedding network to produce prototypes that are aware of the other classes. These prior works assume matched training and testing shots whereas our work focuses on setups where testing shots are not fixed (i.e. not necessarily the same as training shots). Our work is parallel to these works in that EST can be applied on the embeddings learned by these methods.
Improvement of few-shot classification setup: Chen et al. (2019) extend the few-shot learning problem setup by considering domain adaptation in addition to learning novel classes. Specifically, they look at how well models trained on miniImageNet can perform on few-shot learning in CUB200. Importantly, they still force the number of shots to be consistent between training time and testing time. While their work deals with varying the domain of the episodes at test time, our work deals with varying shots. Concurrent to our work, Triantafillou et al. (2020) further broaden the scope of few-shot learning by introducing a benchmark composed of data from various domains; methods are tested on their ability to adapt to different domains and deal with class imbalance. We extend their work with a thorough analysis of how the number of shots affects the learning outcome, and further propose a method to overcome the negative impact of mismatched shots.
Theoretical analysis of few-shot learning: Despite the myriad of methodological improvements, theoretical work on few-shot learning has been sparse. Wang et al. (2019b) provide a unifying formulation for few-shot learning methods, and clearly outline the key challenge in few-shot learning through a PAC argument, but do not introduce any new theoretical results. In contrast, our work introduces a novel bound for the accuracy of ProtoNets; this bound provides useful intuitions pertaining to how ProtoNets adapt to few-shot episodes. Additionally, we demonstrate theoretically and experimentally that the intrinsic dimension of the embedding function’s output space varies with the number of shots as a direct consequence of the challenges outlined in the PAC argument. To the best of our knowledge, Amit & Meir (2017) provide the only prior work to bound the error of a meta-learning agent. Specifically, they use the generalized PAC-Bayes framework to derive an error-rate bound for a MAML-style learning algorithm (where the hypothesis class is fixed). Their main result relates the performance of the learning algorithm to both the number of tasks encountered during meta-training and the number of shots given in any task. In contrast to our work, their result does not apply to non-parametric methods such as ProtoNets because the hypothesis class in ProtoNets can change from episode to episode depending on the number of ways.
# 6 CONCLUSION AND FUTURE WORK
We have explored how the number of support samples used during meta-training can influence the learned embedding function’s performance and intrinsic dimensions. Our proposed method transforms the embedding space to maximize inter-to-intra class variance ratio while constraining the dimensions of the space itself. In terms of applications, our method can be combined other works (Oreshkin et al., 2018; Ye et al., 2018; Rusu et al., 2019; Dong & Xing, 2018; Ren et al., 2018; Tapaswi et al., 2019) with an embedding learning component. We believe our approach is a significant step to reduce the impact of the shot number in meta-training, which is a crucial hyperparameter for few-shot classification.
# ACKNOWLEDGMENTS
We acknowledge partial support from NSERC COHESA NETGP485577-15 and Samsung. We thank Chaoqi Wang for discussion on the initial idea, and Clement Fuji Tsang, Mark Brophy and the ´ anonymous reviewers for helpful feedback on early versions of this paper.
# REFERENCES
Kelsey R. Allen, Evan Shelhamer, Hanul Shin, and Joshua B. Tenenbaum. Infinite mixture prototypes for few-shot learning. CoRR, abs/1902.04552, 2019. URL http://arxiv.org/abs/1902. 04552.
Ron Amit and Ron Meir. Meta-learning by adjusting priors based on extended pac-bayes theory. In ICML, 2017.
Christopher M. Bishop. Pattern Recognition and Machine Learning (Information Science and Statistics). Springer-Verlag, Berlin, Heidelberg, 2006. ISBN 0387310738.
Wei-Yu Chen, Yen-Cheng Liu, Zsolt Kira, Yu-Chiang Frank Wang, and Jia-Bin Huang. A closer look at few-shot classification. ArXiv, abs/1904.04232, 2019.
Nanqing Dong and Eric P. Xing. Few-shot semantic segmentation with prototype learning. In British Machine Vision Conference (BMVC), 2018.
Chelsea Finn, Pieter Abbeel, and Sergey Levine. Model-agnostic meta-learning for fast adaptation of deep networks. In Doina Precup and Yee Whye Teh (eds.), Proceedings of the 34th International Conference on Machine Learning (ICML), volume 70 of Proceedings of Machine Learning Research, pp. 1126–1135, International Convention Centre, Sydney, Australia, 06–11 Aug 2017. PMLR. URL http://proceedings.mlr.press/v70/finn17a.html.
Keinosuke Fukunaga. Introduction to Statistical Pattern Recognition (2Nd Ed.). Academic Press Professional, Inc., San Diego, CA, USA, 1990. ISBN 0-12-269851-7.
Keinosuke Fukunaga and David R. Olsen. An algorithm for finding intrinsic dimensionality of data. IEEE Transactions on Computers, C-20:176–183, 1971.
Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Deep residual learning for image recognition. In Proceedings of the IEEE conference on computer vision and pattern recognition (CVPR), pp. 770–778, 2016.
Sergey Ioffe and Christian Szegedy. Batch normalization: Accelerating deep network training by reducing internal covariate shift. In Francis Bach and David Blei (eds.), Proceedings of the 32nd International Conference on Machine Learning (ICML), volume 37 of Proceedings of Machine Learning Research, pp. 448–456, Lille, France, 07–09 Jul 2015. PMLR. URL http://proceedings.mlr.press/v37/ioffe15.html.
Diederik Kingma and Jimmy Ba. Adam: A method for stochastic optimization. International Conference on Learning Representations (ICLR), 2014.
Brenden M. Lake, Ruslan Salakhutdinov, and Joshua B. Tenenbaum. Human-level concept learning through probabilistic program induction. Science, 350(6266):1332–1338, 2015. ISSN 0036-8075. doi: 10.1126/science.aab3050. URL http://science.sciencemag.org/ content/350/6266/1332.
Marc T. Law, Yaoliang Yu, Matthieu Cord, and Eric P. Xing. Closed-form training of mahalanobis distance for supervised clustering. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), pp. 3909–3917, 2016.
Marc T. Law, Jake Snell, Amir massoud Farahmand, Raquel Urtasun, and Richard S. Zemel. Dimensionality reduction for representing the knowledge of probabilistic models. In International Conference on Learning Representations (ICLR), 2019. URL https://openreview.net/ forum?id $\underline { { \underline { { \mathbf { \Pi } } } } } =$ SygD-hCcF7.
Boris Oreshkin, Pau Rodr´ıguez Lopez, and Alexandre Lacoste. Tadam: Task dependent adaptive ´ metric for improved few-shot learning. In Advances in Neural Information Processing Systems (NeurIPS), pp. 721–731, 2018.
Sachin Ravi and Hugo Larochelle. Optimization as a model for few-shot learning. In In International Conference on Learning Representations (ICLR), 2017.
Mengye Ren, Eleni Triantafillou, Sachin Ravi, Jake Snell, Kevin Swersky, Joshua B. Tenenbaum, Hugo Larochelle, and Richard S. Zemel. Meta-learning for semi-supervised few-shot classification. In Proceedings of 6th International Conference on Learning Representations (ICLR), 2018.
Alvin C. Rencher and G. Bruce Schaalje. Linear Models in Statistics. John Wiley & Sons, Inc., 2nd edition, 2008.
Andrei A. Rusu, Dushyant Rao, Jakub Sygnowski, Oriol Vinyals, Razvan Pascanu, Simon Osindero, and Raia Hadsell. Meta-learning with latent embedding optimization. CoRR, abs/1807.05960, 2019.
Adam Santoro, Sergey Bartunov, Matthew Botvinick, Daan Wierstra, and Timothy Lillicrap. Metalearning with memory-augmented neural networks. In Maria Florina Balcan and Kilian Q. Weinberger (eds.), Proceedings of The 33rd International Conference on Machine Learning (ICML), volume 48 of Proceedings of Machine Learning Research, pp. 1842–1850, New York, New York, USA, 20–22 Jun 2016. PMLR. URL http://proceedings.mlr.press/v48/ santoro16.html.
Jake Snell, Kevin Swersky, and Richard Zemel. Prototypical networks for few-shot learning. In Advances in Neural Information Processing Systems (NIPS), pp. 4077–4087, 2017.
Christian Szegedy, Wei Liu, Yangqing Jia, Pierre Sermanet, Scott Reed, Dragomir Anguelov, Dumitru Erhan, Vincent Vanhoucke, and Andrew Rabinovich. Going deeper with convolutions. In Computer Vision and Pattern Recognition (CVPR), 2015. URL http://arxiv.org/abs/1409.4842.
Makarand Tapaswi, Marc T. Law, and Sanja Fidler. Video face clustering with unknown number of clusters. In The IEEE International Conference on Computer Vision (ICCV), October 2019.
Eleni Triantafillou, Tyler Zhu, Vincent Dumoulin, Pascal Lamblin, Utku Evci, Kelvin Xu, Ross Goroshin, Carles Gelada, Kevin Swersky, Pierre-Antoine Manzagol, and Hugo Larochelle. Metadataset: A dataset of datasets for learning to learn from few examples. In International Conference on Learning Representations, 2020.
Vladimir Vapnik, Esther Levin, and Yann Le Cun. Measuring the vc-dimension of a learning machine. Neural Computation, 6(5):851–876, 1994. doi: 10.1162/neco.1994.6.5.851. URL https://doi.org/10.1162/neco.1994.6.5.851.
Vladimir N. Vapnik. Statistical Machine Learning. JOHN WILEY & SONS, INC., 1998.
Oriol Vinyals, Charles Blundell, Timothy Lillicrap, Koray Kavukcuoglu, and Daan Wierstra. Matching networks for one shot learning. In Proceedings of the 30th International Conference on Neural Information Processing Systems (NIPS), NIPS’16, pp. 3637–3645, USA, 2016. Curran Associates Inc. ISBN 978-1-5108-3881-9. URL http://dl.acm.org/citation.cfm? id=3157382.3157504.
Jixuan Wang, Kuan-Chieh Wang, Marc T. Law, Frank Rudzicz, and Michael Brudno. Centroid-based deep metric learning for speaker recognition. In ICASSP 2019-2019 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP), pp. 3652–3656. IEEE, 2019a.
Yaqing Wang, Quanming Yao, James T. Kwok, and Lionel M. Ni. Generalizing from a few examples: A survey on few-shot learning. 2019b.
Han-Jia Ye, Hexiang Hu, De-Chuan Zhan, and Fei Sha. Learning embedding adaptation for few-shot learning. CoRR, abs/1812.03664, 2018. URL http://arxiv.org/abs/1812.03664.
Pierre Yger, Marcel Stimberg, and Romain Brette. Fast learning with weak synaptic plasticity. Journal of Neuroscience, 35(39):13351–13362, 2015. ISSN 0270-6474. doi: 10.1523/JNEUROSCI. 0607-15.2015. URL http://www.jneurosci.org/content/35/39/13351.
# A APPENDIX
# A.1 ALGORITHM FOR EST
Below is the exact procedure for computing $\tau$ for embedding space transformation.
Algorithm 1 Algorithm for computing the transformation $\tau$ . $L _ { n }$ is the number of samples belonging to class $n$ ; $\mu _ { n }$ and $\Sigma _ { n }$ are the mean and covariance of the embeddings of that class; $\mu _ { T }$ and $\widetilde { \Sigma } _ { s }$ are the average of mean embeddings and covariances; $\Sigma _ { \mu }$ is the covariance of the mean embeddings; $V ^ { * }$ is the matrix of eigenvectors that correspoinds to the $d$ largest eigenvalues in $\Lambda$ .
Input: Training set $\mathcal { D } _ { t r } = \{ ( \mathbf { x } _ { 1 } , y _ { 1 } ) , . . . , ( \mathbf { x } _ { M } , y _ { M } \}$ , where $y _ { i } \in \{ 1 , . . . , N \}$ , $\mathcal { D } _ { n }$ denotes the subset of $\mathcal { D } _ { t r }$ where $\forall y \in { \mathcal { D } } _ { n } , y = n$ , embedding function $\phi$ , weighting parameter $\rho$ , dimension parameter $d$ .
$$\begin{array} { r } { \Sigma [ n ] = \frac { 1 } { L _ { n } } \sum _ { ( \mathbf { x } _ { i } , y _ { i } ) \in \mathcal { D } _ { n } } ^ { L _ { n } } ( \phi ( \mathbf { x } _ { i } ) - \mu _ { n } ) ( \phi ( \mathbf { x } _ { i } ) - \mu _ { n } ) ^ { T } } \end{array}$$
# end for
$$\begin{array} { r l } & { \mu _ { T } = \frac { 1 } { M } \sum _ { ( \mathbf { x } _ { i } , y _ { i } ) \in \mathcal { D } _ { t r } } \phi ( \mathbf { x } _ { i } ) } \\ & { \Sigma _ { \mu } = \frac { 1 } { N } \sum _ { n \in [ 1 , N ] } ( \mu [ n ] - \mu _ { T } ) ( \mu [ n ] - \mu _ { T } ) ^ { T } } \\ & { \overline { { \Sigma } } _ { s } = \frac { 1 } { N } \sum _ { n \in [ 1 , N ] } \Sigma [ n ] } \end{array}$$
# A.2 NETWORK ARCHITECTURE
The vanilla CNN has the exact same architecture as the original ProtoNet (Snell et al., 2017). It consists of four convolution layers with depth of 64; each convolution layer is followed by Relu activation, max-pooling, and batch normalization (Ioffe & Szegedy, 2015). Resnet of 7 layers is constructed with one vanilla convolution layer of depth 64 followed by three residual blocks, all joined by max-pooling layers; each residual block consists of two sets of conv-batchnorm-Relu layers, of depth 128-256-256.
# A.3 DATA SET DESCRIPTION AND PRE-PROCESSING
Experiments are performed on three data sets: Omniglot (Lake et al., 2015), miniImageNet (Vinyals et al., 2016), and tieredImageNet (Ren et al., 2018). For Omniglot experiments, we follow the same configuration as in the original paper where 1200 classes augmented with rotations (4800 total) are used for training, and the remaining classes are used for testing.
For miniImageNet experiments, we use the splits proposed by (Ravi & Larochelle, 2017) where 64 classes are used for training, 16 for validation, and 20 for testing. Mirroring the original paper, we resize all miniImageNet images to $8 4 \mathrm { x } 8 4$ . No data augmentation is applied. As most state-of-art few-shot classification methods achieve saturating accuracies on Omniglot, and miniImageNet’s small number of classes make claims about generalization difficult, we also conduct experiments of tieredImageNet.
TieredImageNet is also a subset of Imagenet1000. TieredImageNet groups classes into broader categories corresponding to higher-level nodes in the ImageNet hierarchy. It includes 34 categories, with each category containing between 10 and 30 classes. These are split into 20 training, 6 validation and 8 testing categories. In total, there are 351 classes in training, 97 in validation, and 160 in testing. Preprocessing of images follow the same steps as used for miniImageNet.
# A.4 PROTONET TRAINING
Training procedure of ProtoNets largely mirrors the protocol used by Snell et al. (2017). On Omniglot, we train the network to convergence after 30000 episodes. On miniImageNet and tieredImageNet, we monitor the performance of the network on the validation set and select the best performing checkpoint after training for 50000 episodes. Adam (Kingma & Ba, 2014) optimizer is used with $\alpha = 0 . 9$ , $\beta = 0 . 9 9 9$ , $\epsilon = 1 0 ^ { - 8 }$ , and an initial learning rate of 0.001 that is decayed by half every 2000 episodes. On Omniglot, we train with 60 classes and 5 query points per episode. On miniImageNet and tieredImageNet, we train with 20 classes and 15 query points per episode.
# A.5 DERIVATION DETAILS
Proof of Lemma 1:
Proof. First, from the definition of $\alpha$ , we split $\mathbb { E } _ { \mathbf { x } , S \mid a , b } [ \alpha ]$ in to two parts and examine them separately:
$$\mathbb { E } _ { \mathbf { x } , S | a , b } [ \alpha ] = \underbrace { \mathbb { E } [ \left. \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { b } ) } } \right. ^ { 2 } ] } _ { i } - \underbrace { \mathbb { E } [ \left. \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { a } ) } } \right. ^ { 2 } ] } _ { i i } .$$
In general, for random vector $X$ , the expectation of the quadratic form is $\mathbb { E } [ \left. X \right. ^ { 2 } ] = \operatorname { T r } ( \operatorname { V a r } ( X ) ) +$ $\mathbb { E } [ { \bar { X } } ] ^ { T } \mathbb { E } [ X ]$ . Hence,
$$\begin{array} { r l } & { i = \mathbb { E } _ { \mathbf { x } , S \mid a , b } [ \Big \| \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { b } ) } } \Big \| ^ { 2 } ] } \\ & { \phantom { = } = \mathrm { T r } ( \Sigma _ { \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { b } ) } } } ) + \mathbb { E } [ \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { b } ) } } ] ^ { T } \mathbb { E } [ \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { b } ) } } ] , } \end{array}$$
where the first term inside the trace can be expanded as:
$$\begin{array} { l l } { { \displaystyle \Sigma _ { \phi ( { \bf x } ) - \overline { { \phi ( S _ { b } ) } } } = \mathrm { V a r } [ \phi ( { \bf x } ) - \overline { { \phi ( S _ { b } ) } } ] } } \\ { { } } & { { = \mathbb E [ ( \phi ( { \bf x } ) - \overline { { \phi ( S _ { b } ) } } ) ( \phi ( { \bf x } ) - \overline { { \phi ( S _ { b } ) } } ) ^ { T } ] - ( \mathbf { \mu } _ { a } - \mathbf { \mu } _ { b } ) ( \mathbf { \mu } _ { a } - \mathbf { \mu } _ { b } ) ^ { T } } } \\ { { } } & { { = \Sigma _ { c } + \mathbf { \mu } _ { a } \mathbf { \mu } _ { a } ^ { T } + \displaystyle \frac { 1 } { k } \Sigma _ { c } + \mathbf { \mu } _ { b } \mathbf { \mu } _ { b } ^ { T } - \displaystyle \mathbf { \mu } _ { a } \mathbf { \mu } _ { b } ^ { T } - \displaystyle \mathbf { \mu } _ { b } \mathbf { \mu } _ { a } ^ { T } - ( \mathbf { \mu } _ { a } - \mathbf { \mu } _ { b } ) ( \mathbf { \mu } _ { a } - \mathbf { \mu } _ { b } ) ^ { T } } } \\ { { } } & { { = ( 1 + \displaystyle \frac { 1 } { k } ) \Sigma _ { c } ~ \displaystyle ( \mathrm { L a s t ~ t e r m s ~ c a n c e l ~ o u t } ) . } } \end{array}$$
To go from (18) to (19), we note that $\operatorname { V a r } ( X ) = \mathbb { E } [ X X ^ { T } ] - \mathbb { E } [ X ] \mathbb { E } [ X ] ^ { T }$ and $\Sigma _ { c } \overset { \Delta } { = } \mathrm { V a r } ( \phi ( \mathbf { x } ) )$ . Hence (19) can be obtained by expanding out the first term and taking the expectation of each resulting item.
The second term of (16) is simply:
$$\mathbb { E } _ { \mathbf { x } , S | a , b } [ \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { b } ) } } ] = \mu _ { a } - \mu _ { b } .$$
Putting them together:
$$i = ( 1 + \frac { 1 } { k } ) \mathrm { T r } ( \Sigma _ { c } ) + ( \mu _ { a } - \mu _ { b } ) ^ { T } ( \mu _ { a } - \mu _ { b } ) .$$
Similarly for $_ { i i }$
$$\begin{array} { l } { { \displaystyle i i = \mathbb { E } _ { { \bf x } , S \vert a , b } [ \left. \phi ( { \bf x } ) - \overline { { \phi ( S _ { a } ) } } \right. ^ { 2 } ] } \ ~ } \\ { { \displaystyle ~ = \mathrm { T r } ( \Sigma _ { \phi ( { \bf x } ) - \overline { { \phi ( S _ { a } ) } } } ) + \mathbb { E } [ \phi ( { \bf x } ) - \overline { { \phi ( S _ { a } ) } } ] ^ { T } \mathbb { E } [ \phi ( { \bf x } ) - \overline { { \phi ( S _ { a } ) } } ] } \ } \\ { { \displaystyle ~ = ( 1 + \frac { 1 } { k } ) \mathrm { T r } ( \Sigma _ { c } ) . } } \end{array}$$
Putting together $i$ and $\romannumeral 2$ :
$$\begin{array} { l } { \displaystyle \mathbb { E } _ { { \mathbf { x } } , S | a , b } [ \alpha ] = ( 1 + \frac { 1 } { k } ) \mathrm { T r } ( \Sigma _ { c } ) + ( \mathbf { \mu } _ { a } - \mathbf { \mu } _ { b } ) ( \mathbf { \mu } _ { a } - \mathbf { \mu } _ { b } ) ^ { T } - ( 1 + \frac { 1 } { k } ) \mathrm { T r } ( \Sigma _ { c } ) } \\ { = ( \mathbf { \mu } _ { a } - \mathbf { \mu } _ { b } ) ^ { T } ( \mathbf { \mu } _ { a } - \mathbf { \mu } _ { b } ) } \end{array}$$
Then, since $\mathbb { E } _ { a , b , \mathbf { x } , S } [ \alpha ] = \mathbb { E } _ { a , b } [ \mathbb { E } _ { \mathbf { x } , S | a , b } [ \alpha ] ]$ , we have:
$$\begin{array} { r l } & { \mathbb { E } _ { a , b , \mathbf { x } , S } [ \alpha ] = \mathbb { E } _ { a , b } [ ( \mu _ { a } - \mu _ { b } ) ^ { T } ( \mu _ { a } - \mu _ { b } ) ] } \\ & { \qquad = \mathbb { E } _ { a , b } [ \mu _ { a } ^ { T } \mu _ { a } + \mu _ { b } ^ { T } \mu _ { b } - \mu _ { a } ^ { T } \mu _ { b } - \mu _ { b } ^ { T } \mu _ { a } ] } \\ & { \qquad = \mathrm { T r } ( \Sigma ) + \mu ^ { T } \mu + \mathrm { T r } ( \Sigma ) + \mu ^ { T } \mu - 2 \mu ^ { T } \mu } \\ & { \qquad = 2 \mathrm { T r } ( \Sigma ) } \end{array}$$
Where from the second to the third line, we note that $\mu _ { a } ^ { T } \mu _ { a }$ and $\mu _ { b } ^ { T } \mu _ { b }$ are quadratic forms while $\mu _ { a } ^ { T } \mu _ { b }$ describe a dot product between two independent randomly drawn samples which has expectation $\mu ^ { T } \mu$ . □
For proof of Lemma 2, we first re-state the result on quadratic forms of normally distributed random vectors by Rencher & Schaalje (2008).
Theorem 4. Consider random vector y $\sim \cal { N } ( \{ \mathfrak { u } , \Sigma \}$ and symmetric matrix of constants $A$ , we have:
$$\mathrm { V a r } ( y ^ { T } A y ) = 2 \mathrm { T r } ( ( A \Sigma ) ^ { 2 } ) + 4 { \mu } ^ { T } A \Sigma A { \mu } .$$
Proof of Lemma 2:
Proof.
$$\begin{array} { r l } { \mathrm { V a r } ( \alpha | a , b ) = \mathrm { V a r } ( \left\| \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { b } ) } } \right\| ^ { 2 } - \left\| \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { b } ) } } \right\| ^ { 2 } ) } & { } \\ { = \mathrm { V a r } ( \left\| \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { b } ) } } \right\| ^ { 2 } ) + \mathrm { V a r } ( \left\| \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { a } ) } } \right\| ^ { 2 } ) } & { } \\ { - 2 \mathrm { C o v } ( \left\| \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { a } ) } } \right\| ^ { 2 } , \left\| \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { b } ) } } \right\| ^ { 2 } ) } & { } \\ { \leq \mathrm { V a r } ( \left\| \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { b } ) } } \right\| ^ { 2 } ) + \mathrm { V a r } ( \left\| \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { a } ) } } \right\| ^ { 2 } ) } & { } \\ { + 2 \sqrt { \mathrm { V a r } ( \left\| \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { b } ) } } \right\| ^ { 2 } ) \mathrm { V a r } ( \left\| \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { a } ) } } \right\| ^ { 2 } ) } } & { } \\ { \leq 2 \mathrm { V a r } ( \left\| \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { b } ) } } \right\| ^ { 2 } ) + 2 \mathrm { V a r } ( \left\| \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { a } ) } } \right\| ^ { 2 } ) } & { } \end{array}$$
From 33 to 35, we used Cauchy Schwarz inequality. From line 35 to line 37, we use the fact that $2 a b \leq a ^ { 2 } + b ^ { 2 }$ for all $a , b \in \mathcal { R } ^ { + }$ .
By applying Theorem 4, we have:
$${ \begin{array} { r l } & { \operatorname { V a r } ( \left\| \phi ( \mathbf { x } ) - { \overline { { \phi ( S _ { b } ) } } } \right\| ^ { 2 } ) = 2 ( 1 + { \frac { 1 } { k } } ) ^ { 2 } \operatorname { T r } ( \Sigma _ { c } ^ { 2 } ) + 4 ( 1 + { \frac { 1 } { k } } ) ( \mu _ { a } - \mu _ { b } ) ^ { T } \Sigma _ { c } ( \mu _ { a } - \mu _ { b } ) } \\ & { \operatorname { V a r } ( \left\| \phi ( \mathbf { x } ) - { \overline { { \phi ( S _ { a } ) } } } \right\| ^ { 2 } ) = 2 ( 1 + { \frac { 1 } { k } } ) ^ { 2 } \operatorname { T r } ( \Sigma _ { c } ^ { 2 } ) } \end{array} }$$
Finally,
$$\begin{array} { r l } & { \mathbb { E } _ { a , b } [ \mathrm { V a r } ( \alpha | a , b ) ] \leq \mathbb { E } _ { a , b } [ 2 \mathrm { V a r } ( \left\| \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { b } ) } } \right\| ^ { 2 } ) + 2 \mathrm { V a r } ( \left\| \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { a } ) } } \right\| ^ { 2 } ) ] } \\ & { \qquad = \mathbb { E } _ { a , b } [ 8 ( 1 + \frac { 1 } { k } ) ^ { 2 } \mathrm { T r } ( \Sigma _ { c } ^ { 2 } ) + 8 ( 1 + \frac { 1 } { k } ) ( \mathbf { \mu } _ { a } - \mathbf { \mu } _ { b } ) ^ { T } \Sigma _ { c } ( \mathbf { \mu } _ { a } - \mathbf { \mu } _ { b } ) ] } \\ & { \qquad = 8 ( 1 + \frac { 1 } { k } ) \mathbb { E } _ { a , b } [ \mathrm { T r } \{ ( 1 + \frac { 1 } { k } ) \Sigma _ { c } ^ { 2 } + \Sigma _ { c } ( \mathbf { \mu } _ { a } - \mathbf { \mu } _ { b } ) ( \mathbf { \mu } _ { a } - \mathbf { \mu } _ { b } ) ^ { T } \} ] } \\ & { \qquad = 8 ( 1 + \frac { 1 } { k } ) \mathrm { T r } \{ \Sigma _ { c } [ ( 1 + \frac { 1 } { k } ) \Sigma _ { c } + 2 \Sigma ] \} } \end{array}$$
Extending to $N$ class: Let $\mathbf x , y$ denote the query data pair, and the set of $N$ classes be denoted as c. Let $\alpha _ { i } = \left\| \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { i } } } ) \right\| ^ { 2 } - \left\| \phi ( \mathbf { x } ) - \overline { { \phi ( S _ { y } } ) } \right\| ^ { 2 }$ . Then we have a correct prediction $\hat { y } = y$ if $\forall i \in [ 1 , N ] , i \neq y , \alpha _ { i } > 0$ . Hence: $R ( \phi ) = \operatorname* { P r } _ { \mathbf { c } , \mathbf { x } , S } ( \bigcup _ { i \neq y } ^ { N } \alpha _ { i } > 0 )$
By Frechet’s inequality:
$$R ( \phi ) \geq \sum _ { \stackrel { i = 1 } { i \neq y } } ^ { N } \operatorname* { P r } ( \alpha _ { i } > 0 ) - ( N - 2 )$$
Noting that Theorem 3 can be applied to each term in the summation:
$$\mathfrak { L } ( \phi ) \geq \sum _ { \stackrel { i = 1 } { i \neq y } } ^ { N } \frac { 4 \mathrm { T r } ( \Sigma ) ^ { 2 } } { 8 ( 1 + 1 / k ) ^ { 2 } \mathrm { T r } ( \Sigma _ { c } ^ { 2 } ) + 1 6 ( 1 + 1 / k ) \mathrm { T r } ( \Sigma \Sigma _ { c } ) + \mathbf { E } _ { i , y } [ ( ( \mu _ { y } - \mu _ { i } ) ( \mu _ { y } - \mu _ { i } ) ^ { T } ) ^ { 2 } ] } - ( N - 2 )$$
It is then clear that the observations made on the binary case also applies to the multiclass case.
# A.6 ADDITIONAL RESULTS
Additionally, we experimented with directly setting the output dimension of the embedding network to 60 by adding a fully connected layer to the embedding network. This variant of protonet performs worse than both the base variant and all other methods.
Table 2: Classification Accuracy on miniImageNet-5-way, with 4 layer $\mathrm { C N N } + 1$ Fully connected layer embedding network.
<table><tr><td rowspan="2"></td><td rowspan="2">TRAINING SHOTS</td><td colspan="9">2 3</td><td rowspan="2">10</td><td rowspan="2">AVERAGE ACCURACY</td></tr><tr><td></td><td></td><td></td><td>4</td><td>5</td><td>TESTING SHOTS 6</td><td>7</td><td>8</td><td>9</td></tr><tr><td>PROTONET + FC</td><td>5</td><td>44.77%</td><td>53.75%</td><td>58.04%</td><td>61.06%</td><td>62.26%</td><td>64.60%</td><td>65.19%</td><td>66.63%</td><td>66.65%</td><td></td><td>67.52%</td><td>61.05±0.28%</td></tr></table>
 Figure 3: Effect of hyperparameters on k-shot testing performance on miniImageNet.
Table 3: Classification Accuracy on miniImageNet-5-way, with 4 layer CNN embedding network.
<table><tr><td>MODEL</td><td>TRAINING</td><td colspan="10">TESTING SHOTS</td><td>AVERAGE</td></tr><tr><td></td><td>SHOTS</td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td><td>8</td><td>9</td><td>10</td><td>ACCURACY</td></tr><tr><td>VANILLA PROTONET</td><td>1</td><td>48.89%</td><td>56.54%</td><td>60.31%</td><td>63.12%</td><td>64.70%</td><td>66.02%</td><td>66.62%</td><td>67.99%</td><td>68.41%</td><td>68.90%</td><td>63.15±0.21%</td></tr><tr><td>EST PROTONET</td><td>1</td><td>49.07%</td><td>56.49%</td><td>60.62%</td><td>62.67%</td><td>64.83%</td><td>66.23%</td><td>66.84%</td><td>67.90%</td><td>67.68%</td><td>68.73%</td><td>63.11±0.22%</td></tr><tr><td>PCA PROTONET</td><td>1</td><td>49.01%</td><td>56.35%</td><td>60.07%</td><td>62.42%</td><td>64.38%</td><td>65.28%</td><td>66.56%</td><td>67.81%</td><td>67.59%</td><td>68.26%</td><td>62.77 ±0.22%</td></tr><tr><td>VANILLA PROTONET</td><td>5</td><td>44.75%</td><td>56.61%</td><td>61.52%</td><td>65.32%</td><td>67.23%</td><td>69.04%</td><td>70.66%</td><td>71.47%</td><td>71.84%</td><td>72.36%</td><td>65.08±0.23%</td></tr><tr><td>EST PROTONET</td><td>5</td><td>50.22%</td><td>59.04 %</td><td>64.14%</td><td>66.61%</td><td>68.25%</td><td>69.46%</td><td>70.80%</td><td>71.60%</td><td>72.61%</td><td>73.29%</td><td>66.60±0.23%</td></tr><tr><td>PCA PROTONET</td><td></td><td>48.72%</td><td>58.43%</td><td>63.17%</td><td>66.07%</td><td>68.63%</td><td>69.56%</td><td>70.55%</td><td>71.21%</td><td>72.09%</td><td>72.82%</td><td>66.12±0.24%</td></tr><tr><td>VANILLA PROTONET</td><td>10</td><td>39.99%</td><td>52.73%</td><td>59.71%</td><td>63.41%</td><td>66.23%</td><td>68.27%</td><td>69.86%</td><td>71.03%</td><td>71.72%</td><td>72.47%</td><td>63.54±0.25%</td></tr><tr><td>EST PROTONET</td><td>10</td><td>48.98%</td><td>57.83%</td><td>63.13%</td><td>66.39%</td><td>68.12%</td><td>69.82%</td><td>70.63%</td><td>71.85%</td><td>72.79%</td><td>73.22%</td><td>66.28±0.23%</td></tr><tr><td>PCA PROTONET</td><td>10</td><td>48.04%</td><td>57.05%</td><td>62.46%</td><td>64.63%</td><td>67.61%</td><td>68.98%</td><td>69.71%</td><td>71.78%</td><td>71.75%</td><td>72.42%</td><td>65.44±0.24%</td></tr><tr><td>VANILLA PROTONET</td><td>1-10</td><td>49.36%</td><td>58.67%</td><td>62.77 %</td><td>65.76%</td><td>67.96%</td><td>69.20%</td><td>70.05%</td><td>70.90%</td><td>71.34%</td><td>72.27%</td><td>65.83±0.21%</td></tr></table>
 Figure 4: Comparison between estimated accuracy lower bound and empirical accuracy for various training and test shots. Experiment is 2-way few-shot classification performed on miniImageNet.
Table 4: Classification Accuracy on tieredImageNet-5-way, with 4 layer CNN embedding network.
<table><tr><td>MODEL</td><td>TRAINING SHOTS</td><td>2</td><td></td><td>4</td><td>5</td><td>TESTING SHOTS</td><td>6</td><td>7</td><td>8</td><td>9</td><td>10</td><td>AVERAGE ACCURACY</td></tr><tr><td></td><td></td><td>1</td><td></td><td>3</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>61.85±0.29%</td></tr><tr><td>VANILLA PROTONET EST PROTONET</td><td>1 1</td><td>47.37% 47.71%</td><td>55.72% 55.05%</td><td>59.27% 59.31%</td><td>61.50% 61.97%</td><td>63.70% 63.48%</td><td>64.28% 64.65%</td><td>65.01% 65.35%</td><td>66.43% 66.33%</td><td>67.20% 66.42%</td><td>67.99% 67.44%</td><td>61.77±0.31%</td></tr><tr><td>PCA PROTONET</td><td>1</td><td>47.72%</td><td>54.60%</td><td>58.69%</td><td>60.73%</td><td>62.78%</td><td>64.92%</td><td>65.88%</td><td>65.88%</td><td>66.11%</td><td>66.87%</td><td>61.42±0.32%</td></tr><tr><td>VANILLA PROTONET</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>EST PROTONET</td><td>55</td><td>42.33% 48.85%</td><td>55.06%</td><td>61.32%</td><td>64.57%</td><td>66.51%</td><td>67.86%</td><td>69.33%</td><td>70.15%</td><td>71.32% 70.87%</td><td>72.05% 72.09%</td><td>64.05±0.33% 65.46±0.32%</td></tr><tr><td>PCA PROTONET</td><td>5</td><td>48.34%</td><td>58.38% 57.44%</td><td>62.75% 0.79%</td><td>65.16% 64.96%</td><td>67.24% 67.07%</td><td>68.39% 67.93%</td><td>69.89% 69.08%</td><td>70.99% 70.40%</td><td>70.38%</td><td>71.65%</td><td>64.96±0.31%</td></tr><tr><td>VANILLA PROTONET</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>EST PROTONET</td><td>10</td><td>35.38%</td><td>49.40%</td><td>56.76%</td><td>61.25%</td><td>64.56%</td><td>66.56%</td><td>68.05%</td><td>69.31%</td><td>70.12%</td><td>71.03%</td><td>61.24±0.36% 65.26±0.32%</td></tr><tr><td>PCA PROTONET</td><td>10 10</td><td>47.33% 46.55%</td><td>56.75% 56.61%</td><td>62.80% 60.81%</td><td>65.78% 64.01%</td><td>66.84% 66.53%</td><td>69.07% 67.70%</td><td>69.98% 69.18%</td><td>70.82% 69.83%</td><td>71.99% 70.62%</td><td>71.20% 71.22%</td><td>64.31 ±0.33%</td></tr><tr><td>VANILLA PROTONET</td><td>1-10</td><td>47.65%</td><td>56.23%</td><td>62.12 %</td><td>63.93%</td><td>66.34%</td><td>67.94%</td><td>68.44%</td><td>68.93%</td><td>70.80%</td><td>70.96%</td><td>64.33±0.30%</td></tr></table>
Table 5: Classification Accuracy on Omniglot-20-way, with 4 layer CNN embedding network.
<table><tr><td rowspan="2">MODEL</td><td rowspan="2">TRAINING SHOTS 1</td><td colspan="6">TESTING SHOTS</td></tr><tr><td></td><td>2</td><td>3</td><td>4</td><td>5</td><td>AVERAGE ACCURACY</td></tr><tr><td>VANILLA PROTONET</td><td>1</td><td>95.07 ±0.17 %</td><td>97.89 ±0.09 %</td><td>98.45 ±0.08 %</td><td>98.75 ±0.06 %</td><td>98.89 ±0.06%</td><td>97.81±0.06 %</td></tr><tr><td>VANILLA PROTONET</td><td>2</td><td>94.59 ±0.18 %</td><td>97.69 ±0.09 %</td><td>98.44 ±0.07 %</td><td>98.69 ±0.06 %</td><td>98.89 ±0.06 %</td><td>97.66 ±0.07 %</td></tr><tr><td>VANILLA PROTONET</td><td>3</td><td>94.19 ±0.18 %</td><td>97.57 ±0.09 %</td><td>98.30±0.07 %</td><td>98.63±0.07 %</td><td>98.79 ±0.06 %</td><td>97.50 ±0.07 %</td></tr><tr><td>VANILLA PROTONET</td><td>4</td><td>93.79 ±0.18 %</td><td>97.41 ±0.10 %</td><td>98.19 ±0.08 %</td><td>98.54 ±0.07 %</td><td>98.75±0.06%</td><td>97.34 ±0.07 %</td></tr><tr><td>VANILLA PROTONET</td><td>5</td><td>93.42 ±0.18 %</td><td>97.34±0.10 %</td><td>98.18 ±0.07 %</td><td>98.53 ±0.07 %</td><td>98.78 ±0.05 %</td><td>97.25 ±0.07 %</td></tr><tr><td>MIXED-k SHOT</td><td>1-5</td><td>94.84±0.17 %</td><td>97.81 ±0.09 %</td><td>98.45±0.07 %</td><td>98.70 ±0.06 %</td><td>98.92 ±0.54 %</td><td>97.74 ±0.06 %</td></tr><tr><td>PCA PROTONET</td><td>1</td><td>94.94 ±0.16 %</td><td>97.81 ±0.09 %</td><td>98.53±0.07 %</td><td>98.79 ±0.06 %</td><td>98.85±0.06%</td><td>97.78 ±0.06 %</td></tr><tr><td>EST PROTONET</td><td>1</td><td>95.11 ±0.17 %</td><td>97.95 ±0.09 %</td><td>98.46±0.07 %</td><td>98.77 ±0.06 %</td><td>98.84±0.06%</td><td>97.83 ±0.06 %</td></tr></table>
Table 6: Classification Accuracy on miniImageNet-5-way, with 7 layer ResNet embedding network.
<table><tr><td rowspan="2">MODEL</td><td rowspan="2">TRAINING SHOTS</td><td rowspan="2">2</td><td colspan="9">TESTING SHOTS 3 4</td><td rowspan="2">AVERAGE</td><td rowspan="2">ACCURACY</td></tr><tr><td></td><td></td><td></td><td></td><td>5</td><td>6</td><td>7</td><td>8</td><td></td></tr><tr><td>VANILLA PROTONET</td><td>1</td><td>52.65%</td><td>60.46%</td><td>64.18%</td><td>66.83%</td><td>68.27%</td><td></td><td>69.23%</td><td>70.19%</td><td>71.37%</td><td>71.83%</td><td>72.29%</td><td>66.73±0.20%</td></tr><tr><td>EST PROTONET</td><td>1</td><td>52.56%</td><td>60.63%</td><td>64.50%</td><td>66.53%</td><td>68.33%</td><td>69.36%</td><td></td><td>70.04%</td><td>71.21%</td><td>71.37%</td><td>71.60%</td><td>66.61±0.22%</td></tr><tr><td>PCA PROTONET</td><td>1</td><td>52.78%</td><td>60.35%</td><td>64.05%</td><td>66.24%</td><td>67.51%</td><td></td><td>69.64%</td><td>69.85%</td><td>71.13%</td><td>71.88%</td><td>71.79%</td><td>66.52±0.22%</td></tr><tr><td>VANILLA PROTONET</td><td>5</td><td>47.40%</td><td>58.23%</td><td>64.60%</td><td>67.52%</td><td></td><td>69.93%</td><td>71.05%</td><td>72.27%</td><td>72.90%</td><td>73.55%</td><td>74.35%</td><td>67.18±0.23%</td></tr><tr><td>EST PROTONET</td><td>5</td><td>51.93%</td><td>60.70%</td><td>65.33%</td><td>68.06%</td><td></td><td>69.98%</td><td>71.26%</td><td>72.33%</td><td>73.46%</td><td>74.03%</td><td>74.80%</td><td>68.19±0.23 %</td></tr><tr><td>PCA PROTONET</td><td>5</td><td>50.90%</td><td>60.38%</td><td>64.66%</td><td>67.23%</td><td></td><td>69.25%</td><td>71.30%</td><td>71.72%</td><td>72.75%</td><td>73.84%</td><td>74.24%</td><td>67.63±0.23%</td></tr><tr><td>VANILLA PROTONET</td><td></td><td></td><td></td><td></td><td></td><td></td><td>68.23%</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>EST PROTONET</td><td>10 10</td><td>42.20% 51.24%</td><td>55.98% 60.46%</td><td>61.67%</td><td>66.08%</td><td></td><td>70.06%</td><td>69.95% 71.07%</td><td>72.20% 72.55%</td><td>72.56% 73.39%</td><td>74.04% 73.85%</td><td>74.54 % 74.69%</td><td>65.75±0.25% 68.00±0.23%</td></tr><tr><td>PCAPROTONET</td><td>10</td><td>50.52%</td><td>59.20%</td><td>65.11% 64.44%</td><td>67.63% 66.86%</td><td>69.36%</td><td></td><td>71.00%</td><td>71.73%</td><td>73.19%</td><td>73.73%</td><td>73.82%</td><td>67.38±0.23%</td></tr><tr><td>VANILLA PROTONET</td><td>1-10</td><td>51.74%</td><td>60.10%</td><td>65.13%</td><td>67.12%</td><td>69.09%</td><td></td><td>70.53%</td><td>71.57%</td><td>72.22%</td><td>72.99%</td><td>73.63%</td><td>67.41±0.21%</td></tr></table>
Table 7: Classification Accuracy on tieredImageNet-5-way, with 7 layer ResNet embedding network.
<table><tr><td>MODEL</td><td>TRAINING</td><td colspan="10">TESTING SHOTS</td><td>AVERAGE</td></tr><tr><td></td><td>SHOTS</td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td><td>8</td><td>9</td><td>10</td><td>ACCURACY</td></tr><tr><td>VANILLA PROTONET</td><td>1</td><td>49.78%</td><td>57.67%</td><td>61.37%</td><td>64.88%</td><td>65.17%</td><td>66.73%</td><td>67.53%</td><td>68.58%</td><td>68.21%</td><td>69.88%</td><td>63.98±0.29%</td></tr><tr><td>EST PROTONET</td><td>1</td><td>51.19%</td><td>57.61%</td><td>61.85%</td><td>64.43%</td><td>65.48%</td><td>67.64%</td><td>67.69%</td><td>67.76%</td><td>68.51%</td><td>68.20%</td><td>64.04±0.30%</td></tr><tr><td>PCA PROTONET</td><td>1</td><td>51.38%</td><td>57.89%</td><td>61.68%</td><td>64.32%</td><td>65.96%</td><td>66.15%</td><td>66.83%</td><td>68.00%</td><td>68.58%</td><td>68.77%</td><td>63.95±0.30%</td></tr><tr><td>VANILLA PROTONET</td><td>5</td><td>47.88%</td><td>58.70%</td><td>63.95%</td><td>66.58%</td><td>69.12%</td><td>71.69%</td><td>71.95%</td><td>73.15%</td><td>73.11%</td><td>73.80%</td><td>66.99 ±0.31%</td></tr><tr><td>EST PROTONET</td><td>5</td><td>53.05%</td><td>61.13 %</td><td>65.67%</td><td>68.07%</td><td>69.30%</td><td>71.47%</td><td>71.59 %</td><td>72.42%</td><td>72.80%</td><td>73.63%</td><td>67.91 ±0.31%</td></tr><tr><td>PCA PROTONET</td><td></td><td>51.21%</td><td>59.86%</td><td>63.91%</td><td>66.92%</td><td>68.88%</td><td>70.38%</td><td>71.48%</td><td>72.77%</td><td>73.81%</td><td>72.17%</td><td>67.14±0.32%</td></tr><tr><td>VANILLA PROTONET</td><td>10</td><td>40.84%</td><td>56.24%</td><td>62.10%</td><td>66.28%</td><td>69.37%</td><td>71.43%</td><td>72.09%</td><td>72.91%</td><td>73.56%</td><td>74.72%</td><td>65.95±0.35%</td></tr><tr><td>EST PROTONET</td><td>10</td><td>50.45%</td><td>60.41%</td><td>65.19%</td><td>68.46%</td><td>69.55%</td><td>70.87%</td><td>72.07%</td><td>72.66%</td><td>73.78%</td><td>74.79%</td><td>67.82 ±0.32%</td></tr><tr><td>PCA PROTONET</td><td>10</td><td>50.18%</td><td>59.59%</td><td>64.24%</td><td>67.43%</td><td>69.52%</td><td>70.65%</td><td>71.78%</td><td>72.10%</td><td>72.78%</td><td>73.65%</td><td>67.19±0.31%</td></tr><tr><td>VANILLA PROTONET</td><td>1-10</td><td>50.74%</td><td>60.03%</td><td>64.17 %</td><td>67.26%</td><td>69.28%</td><td>69.56%</td><td>71.07%</td><td>72.41%</td><td>71.99%</td><td>73.01%</td><td>66.95 ±0.29 %</td></tr></table>
Table 8: Classification Accuracy on Omniglot-20-way, with 7 layer ResNet embedding network.
<table><tr><td></td><td colspan="7">TESTING SHOTS</td></tr><tr><td>MODEL</td><td>TRAINING SHOTS</td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>AVERAGE ACCURACY</td></tr><tr><td>VANILLA PROTONET</td><td>1</td><td>96.46%</td><td>98.39 %</td><td>98.82%</td><td>99.01 %</td><td>99.07%</td><td>98.35 ±0.05 %</td></tr><tr><td>VANILLA PROTONET</td><td>2</td><td>95.85%</td><td>98.32%</td><td>98.80%</td><td>98.95%</td><td>99.07%</td><td>98.20±0.05 %</td></tr><tr><td>VANILLA PROTONET</td><td>3</td><td>95.35 %</td><td>98.15%</td><td>98.73 %</td><td>98.91 %</td><td>99.03%</td><td>98.03 ±0.06%</td></tr><tr><td>VANILLA PROTONET</td><td>4</td><td>95.00%</td><td>98.05%</td><td>98.62 %</td><td>98.90%</td><td>98.99%</td><td>97.91 ±0.06 %</td></tr><tr><td>VANILLA PROTONET</td><td>5</td><td>94.42 %</td><td>97.98 %</td><td>98.60%</td><td>98.77 %</td><td>98.99%</td><td>97.75 ±0.06 %</td></tr><tr><td>VANILLA PROTONET</td><td>1-5</td><td>96.53%</td><td>98.53%</td><td>98.90%</td><td>99.06%</td><td>99.15%</td><td>98.43 ±0.05 %</td></tr><tr><td>EST PROTONET</td><td>1</td><td>96.18%</td><td>98.23 %</td><td>98.68%</td><td>98.87%</td><td>98.99%</td><td>98.19 ±0.05 %</td></tr><tr><td>PCA PROTONET</td><td>1</td><td>96.02%</td><td>98.22 %</td><td>98.76%</td><td>98.93%</td><td>99.02 %</td><td>98.19 ±0.05 %</td></tr></table>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391# MIXOUT: EFFECTIVE REGULARIZATION TO FINETUNE LARGE-SCALE PRETRAINED LANGUAGE MODELS
Cheolhyoung Lee∗
cheolhyoung.lee@kaist.ac.kr
Kyunghyun Cho† ‡ § kyunghyun.cho@nyu.edu
Wanmo Kang∗
wanmo.kang@kaist.ac.kr
# ABSTRACT
In natural language processing, it has been observed recently that generalization could be greatly improved by finetuning a large-scale language model pretrained on a large unlabeled corpus. Despite its recent success and wide adoption, finetuning a large pretrained language model on a downstream task is prone to degenerate performance when there are only a small number of training instances available. In this paper, we introduce a new regularization technique, to which we refer as “mixout”, motivated by dropout. Mixout stochastically mixes the parameters of two models. We show that our mixout technique regularizes learning to minimize the deviation from one of the two models and that the strength of regularization adapts along the optimization trajectory. We empirically evaluate the proposed mixout and its variants on finetuning a pretrained language model on downstream tasks. More specifically, we demonstrate that the stability of finetuning and the average accuracy greatly increase when we use the proposed approach to regularize finetuning of BERT on downstream tasks in GLUE.
# 1 INTRODUCTION
Transfer learning has been widely used for the tasks in natural language processing (NLP) (Collobert et al., 2011; Devlin et al., 2018; Yang et al., 2019; Liu et al., 2019; Phang et al., 2018). In particular, Devlin et al. (2018) recently demonstrated the effectiveness of finetuning a large-scale language model pretrained on a large, unannotated corpus on a wide range of NLP tasks including question answering and language inference. They have designed two variants of models, BERTLARGE (340M parameters) and BERTBASE (110M parameters). Although BERTLARGE outperforms BERTBASE generally, it was observed that finetuning sometimes fails when a target dataset has fewer than 10,000 training instances (Devlin et al., 2018; Phang et al., 2018).
When finetuning a big, pretrained language model, dropout (Srivastava et al., 2014) has been used as a regularization technique to prevent co-adaptation of neurons (Vaswani et al., 2017; Devlin et al., 2018; Yang et al., 2019). We provide a theoretical understanding of dropout and its variants, such as Gaussian dropout (Wang & Manning, 2013), variational dropout (Kingma et al., 2015), and dropconnect (Wan et al., 2013), as an adaptive $L ^ { 2 }$ -penalty toward the origin (all zero parameters 0) and generalize dropout by considering a target model parameter $\textbf { \em u }$ (instead of the origin), to which we refer as $\mathtt { m i x o u t } ( { \pmb u } )$ . We illustrate mixout $( { \pmb u } )$ in Figure 1. To be specific, $\mathtt { m i x o u t } ( { \pmb u } )$ replaces all outgoing parameters from a randomly selected neuron to the corresponding parameters of $\textbf { \em u }$ . mixout $( { \pmb u } )$ avoids optimization from diverging away from $\textbf { \em u }$ through an adaptive $L ^ { 2 }$ -penalty toward $\textbf { \em u }$ . Unlike mixout $( { \pmb u } )$ , dropout encourages a move toward the origin which deviates away from $\textbf { \em u }$ since dropout is equivalent to mixout(0).
We conduct experiments empirically validating the effectiveness of the proposed $\mathtt { m i x o u t } ( w _ { \mathrm { p r e } } )$ where ${ \pmb w } _ { \mathrm { p r e } }$ denotes a pretrained model parameter. To validate our theoretical findings, we train a fully connected network on EMNIST Digits (Cohen et al., 2017) and finetune it on MNIST. We observe that a finetuning solution of $\mathtt { m i x o u t } ( w _ { \mathrm { p r e } } )$ deviates less from ${ \pmb w } _ { \mathrm { p r e } }$ in the $L ^ { 2 }$ -sense than that of dropout. In the main experiment, we finetune $\mathrm { B E R T _ { L A R G E } }$ with mixout $( w _ { \mathrm { p r e } } )$ on small training sets of GLUE (Wang et al., 2018). We observe that $\mathtt { m i x o u t } ( w _ { \mathrm { p r e } } )$ reduces the number of unusable models that fail with the chance-level accuracy and increases the average development (dev) scores for all tasks. In the ablation studies, we perform the following three experiments for finetuning BERTLARGE with mixout $( { \pmb w } _ { \mathrm { p r e } } )$ : (i) the effect of $\mathtt { m i x o u t } ( w _ { \mathrm { p r e } } )$ on a sufficient number of training examples, (ii) the effect of a regularization technique for an additional output layer which is not pretrained, and (iii) the effect of probability of $\mathtt { m i x o u t } ( w _ { \mathrm { p r e } } )$ compared to dropout. From these ablation studies, we observe that three characteristics of mixout $( w _ { \mathrm { p r e } } )$ : (i) finetuning with mixout $( { \pmb w } _ { \mathrm { p r e } } )$ does not harm model performance even with a sufficient number of training examples; (ii) It is beneficial to use a variant of mixout as a regularization technique for the additional output layer; (iii) The proposed mixout $( w _ { \mathrm { p r e } } )$ is helpful to the average dev score and to the finetuning stability in a wider range of its hyperparameter $p$ than dropout.
 Figure 1: Illustration of mixout $( { \pmb u } )$ . Suppose that $\textbf { \em u }$ and $\pmb { w }$ are a target model parameter and a current model parameter, respectively. (a): We first memorize the parameters of the vanilla network at $\textbf { \em u }$ . (b): In the dropout network, we randomly choose an input neuron to be dropped (a dotted neuron) with a probability of $p$ . That is, all outgoing parameters from the dropped neuron are eliminated (dotted connections). (c): In the mixout $( { \pmb u } )$ network, the eliminated parameters in (b) are replaced by the corresponding parameters in (a). In other words, the mixout $( { \pmb u } )$ network at $\pmb { w }$ is the mixture of the vanilla network at $\textbf { \em u }$ and the dropout network at $\pmb { w }$ with a probability of $p$ .
# 1.1 RELATED WORK
For large-scale pretrained language models (Vaswani et al., 2017; Devlin et al., 2018; Yang et al., 2019), dropout has been used as one of several regularization techniques. The theoretical analysis for dropout as an $L ^ { 2 }$ -regularizer toward 0 was explored by Wan et al. (2013) where 0 is the origin. They provided a sharp characterization of dropout for a simplified setting (generalized linear model). Mianjy & Arora (2019) gave a formal and complete characterization of dropout in deep linear networks with squared loss as a nuclear norm regularization toward 0. However, neither Wan et al. (2013) nor Mianjy $\&$ Arora (2019) gives theoretical analysis for the extension of dropout which uses a point other than 0.
Wiese et al. (2017), Kirkpatrick et al. (2017), and Schwarz et al. (2018) used $L ^ { 2 }$ -penalty toward a pretrained model parameter to improve performance. They focused on preventing catastrophic forgetting to enable their models to learn multiple tasks sequentially. They however do not discuss nor demonstrate the effect of $L ^ { 2 }$ -penalty toward the pretrained model parameter on the stability of finetuning. Barone et al. (2017) introduced tuneout, which is a special case of mixout. They applied various regularization techniques including dropout, tuneout, and $L ^ { 2 }$ -penalty toward a pretrained model parameter to finetune neural machine translation. They however do not demonstrate empirical significance of tuneout compared to other regularization techniques nor its theoretical justification.
# 2 PRELIMINARIES AND NOTATIONS
Norms and Loss Functions Unless explicitly stated, a norm $\| \cdot \|$ refers to $L ^ { 2 }$ -norm. A loss function of a neural network is written as $\begin{array} { r } { \mathcal { L } ( \mathbf { w } ) = \frac { 1 } { n } \sum _ { i = 1 } ^ { n } \mathcal { L } _ { i } ( \ddot { \mathbf { w } } ) } \end{array}$ , where $\pmb { w }$ is a trainable model parameter. $\mathcal { L } _ { i }$ is “a per-example loss function” computed on the $i$ -th data point.
Strong Convexity A differentiable function $f$ is strongly convex if there exists $m > 0$ such that
$$f ( pmb { y } ) \geq f ( \pmb { x } ) + \nabla f ( \pmb { x } ) ^ { \top } ( \pmb { y } - \pmb { x } ) + \frac { m } { 2 } \| \pmb { y } - \pmb { x } \| ^ { 2 } ,$$
for all $_ { \textbf { \em x } }$ and $\textbf { { y } }$
Weight Decay We refer as “wdecay $( \pmb { u } , \lambda ) ^ { \prime }$ to minimizing
$$\mathcal { L } ( \boldsymbol { \boldsymbol { w } } ) + \frac { \lambda } { 2 } \| \boldsymbol { \boldsymbol { w } } - \boldsymbol { u } \| ^ { 2 } ,$$
instead of the original loss function $\mathcal { L } ( w )$ where $\lambda$ is a regularization coefficient. Usual weight decay of $\lambda$ is equivalent to wdecay $( \mathbf { 0 } , \lambda )$ .
Probability for Dropout and Dropconnect Dropout (Srivastava et al., 2014) is a regularization technique selecting a neuron to drop with a probability of $p$ . Dropconnect (Wan et al., 2013) chooses a parameter to drop with a probability of $p$ . To emphasize their hyperparameter $p$ , we write dropout and dropconnect with a drop probability of $p$ as “dropout $( p )$ ” and “dropconnect $( p ) ^ { \dag }$ , respectively. dropout $( p )$ is a special case of dropconnect $( p )$ if we simultaneously drop the parameters outgoing from each dropped neuron.
Inverted Dropout and Dropconnect In the case of dropout $( p )$ , a neuron is retained with a probability of $1 - p$ during training. If we denote the weight parameter of that neuron as $\pmb { w }$ during training, then we use $( 1 - p ) \pmb { w }$ for that weight parameter at test time (Srivastava et al., 2014). This ensures that the expected output of a neuron is the same as the actual output at test time. In this paper, dropout $( p )$ refers to inverted dropout $( p )$ which uses ${ \pmb w } / ( 1 - p )$ instead of $\textbf { \em w }$ during training. By doing so, we do not need to compute the output separately at test time. Similarly, dropconnect $( p )$ refers to inverted dropconnect $( p )$ .
# 3 ANALYSIS OF DROPOUT AND ITS GENERALIZATION
We start our theoretical analysis by investigating dropconnect which is a general form of dropout and then apply the result derived from dropconnect to dropout. The iterative SGD equation for dropconnect $( p )$ with a learning rate of $\eta$ is
$$\pmb { w } ^ { ( t + 1 ) } = \pmb { w } ^ { ( t ) } - \eta \pmb { B } ^ { ( t ) } \nabla \mathcal { L } \left( \left( \mathbb { E } B _ { 1 } ^ { ( t ) } \right) ^ { - 1 } \pmb { B } ^ { ( t ) } \pmb { w } ^ { ( t ) } \right) , t = 0 , 1 , 2 , \cdots ,$$
where $\pmb { B } ^ { ( t ) } = \mathrm { d i a g } ( \boldsymbol { B } _ { 1 } ^ { ( t ) } , \boldsymbol { B } _ { 2 } ^ { ( t ) }$ , · · · , $B _ { d } ^ { ( t ) } )$ ) and $B _ { i } ^ { ( t ) }$ ’s are mutually independent Bernoulli $( 1 - p )$ random variables with a drop probability of $p$ for all $i$ and $t$ . We regard equation 2 as finding a solution to the minimization problem below:
$$\operatorname* { m i n } _ { \pmb { w } } \mathbb { E } \mathcal { L } \left( ( \mathbb { E } B _ { 1 } ) ^ { - 1 } \pmb { B } \pmb { w } \right) ,$$
where $B = \operatorname { d i a g } ( B _ { 1 } , ~ B _ { 2 } , ~ \cdot \cdot \cdot , ~ B _ { d } )$ and $B _ { i }$ ’s are mutually independent Bernoulli $( 1 - p )$ random variables with a drop probability of $p$ for all $i$ .
Gaussian dropout (Wang & Manning, 2013) and variational dropout (Kingma et al., 2015) use other random masks to improve dropout rather than Bernoulli random masks. To explain these variants of dropout as well, we set a random mask matrix $M = \mathrm { d i a g } ( M _ { 1 } , M _ { 2 }$ , · · · , $M _ { d } )$ ) to satisfy $\mathbb { E } M _ { i } = \mu$ and $\mathrm { V a r } ( M _ { i } ) = \sigma ^ { 2 }$ for all $i$ . Now we define a random mixture function with respect to $\textbf { \em w }$ from $\textbf { \em u }$ and $M$ as
and a minimization p
$$\begin{array} { r l } & { \Phi ( w ; \boldsymbol { u } , M ) = \mu ^ { - 1 } \big ( ( I - M ) \boldsymbol { u } + M \boldsymbol { w } - ( 1 - \mu ) \boldsymbol { u } \big ) , } \\ & { \mathrm { r o b l e m ~ w i t h ~ } ^ { * } \mathrm { m i x c o n n e c t } ( \boldsymbol { u } , \mu , \boldsymbol { \sigma } ^ { 2 } ) ^ { , * } \mathrm { a s } } \\ & { ~ \operatorname* { m i n } _ { \boldsymbol { w } } \mathbb { E } \mathcal { L } \big ( \Phi ( \boldsymbol { w } ; \boldsymbol { u } , M ) \big ) . } \end{array}$$
We can view dropconnect $( p )$ equation 3 as a special case of equation 5 where ${ \pmb u } = { \bf 0 }$ and $M = B$ We investigate how mixconnect $( \pmb { u } , \mu , \sigma ^ { 2 } )$ differs from the vanilla minimization problem
$$\operatorname* { m i n } _ { \boldsymbol { w } } \mathbb { E } \mathcal { L } ( \boldsymbol { w } ) .$$
If the loss function $\mathcal { L }$ is strongly convex, we can derive a lower bound of $\mathbb { E } \mathscr { L } \big ( \Phi ( { \boldsymbol w } ; { \boldsymbol u } , M ) \big )$ as in Theorem 1:
Theorem 1. Assume that the loss function $\mathcal { L }$ is strongly convex. Suppose that a random mixture function with respect to $\pmb { w }$ from $\textbf { \em u }$ and $M$ is given by $\Phi ( { \pmb w } ; { \pmb u } , M )$ in equation $^ { 4 }$ where $M$ is $\mathrm { d i a g } ( M _ { 1 } , ~ M _ { 2 } , ~ \cdot \cdot \cdot , ~ M _ { d } ) $ satisfying $\mathbb { E } M _ { i } = \mu$ and $\mathrm { V a r } ( M _ { i } ) = \sigma ^ { 2 }$ for all $i$ . Then, there exists $m > 0$ such that
$$\mathbb { E } \mathcal { L } \big ( \Phi ( { \boldsymbol w } ; { \boldsymbol u } , M ) \big ) \ge \mathcal { L } ( { \boldsymbol w } ) + \frac { m \sigma ^ { 2 } } { 2 \mu ^ { 2 } } \| { \boldsymbol w } - { \boldsymbol u } \| ^ { 2 } ,$$
for all $\textbf { \em w }$ (Proof in Supplement $A$ ).
Theorem 1 shows that minimizing the l.h.s. of equation 7 minimizes the r.h.s. of equation 7 when the r.h.s. is a sharp lower limit of the l.h.s. The strong convexity of $\mathcal { L }$ means that $\mathcal { L }$ is bounded from below by a quadratic function, and the inequality of equation 7 comes from the strong convexity. Hence, the equality holds if $\mathcal { L }$ is quadratic, and mixconnect $( \pmb { u } , \mu , \sigma ^ { 2 } )$ is an $L ^ { 2 }$ -regularizer with a regularization coefficient of $m \sigma ^ { 2 } { \dot { / } } \mu ^ { 2 }$ .
# 3.1 MIXCONNECT TO MIXOUT
We propose mixout as a special case of mixconnect, which is motivated by the relationship between dropout and dropconnect. We assume that
$$\begin{array} { r } { { \pmb w } = \left( { \pmb w } _ { 1 } ^ { ( N _ { 1 } ) } , \ \cdots , \ { \pmb w } _ { d _ { 1 } } ^ { ( N _ { 1 } ) } , \ w _ { 1 } ^ { ( N _ { 2 } ) } , \ \cdots , \ w _ { d _ { 2 } } ^ { ( N _ { 2 } ) } , \ \cdots \dots , w _ { 1 } ^ { ( N _ { k } ) } , \ \cdots , \ w _ { d _ { k } } ^ { ( N _ { k } ) } \right) , } \end{array}$$
where $w _ { j } ^ { ( N _ { i } ) }$ is the $j$ th parameter outgoing from the neuron $N _ { i }$ . We set the corresponding $M$
$$M = \mathrm { d i a g } \left( M ^ { ( N _ { 1 } ) } , \ \cdots \ , \ M ^ { ( N _ { 1 } ) } , \ M ^ { ( N _ { 2 } ) } , \ \cdots \ , \ M ^ { ( N _ { 2 } ) } , \ \cdots \ \cdots \ , \ M ^ { ( N _ { k } ) } , \ \cdots \ , \ M ^ { ( N _ { k } ) } \right) ,$$
where $\mathbb { E } M ^ { ( N _ { i } ) } = \mu$ and $\mathrm { V a r } ( M ^ { ( N _ { i } ) } ) = \sigma ^ { 2 }$ for all $i$ . In this paper, we set $M ^ { ( N _ { i } ) }$ to Bernoull $( 1 - p )$ for all $i$ and mixout $( { \pmb u } )$ hereafter refers to this correlated version of mixconnect with Bernoulli random masks. We write it as “mixout $( \boldsymbol { u } , \boldsymbol { p } ) ^ { \flat }$ when we emphasize the mix probability $p$ .
Corollary 1.1. Assume that the loss function $\mathcal { L }$ is strongly convex. We denote the random mixture function of mixout $( \pmb { u } , \ p )$ , which is equivalent to that of mixconnect $( \pmb { u } , \ 1 - p , \ p - p ^ { 2 } )$ , as $\Phi ( { \pmb w } ; { \pmb u } , M )$ where $M$ is defined in equation 8. Then, there exists $m > 0$ such that
$$\mathbb { E } \mathcal { L } \big ( \Phi ( { \boldsymbol w } ; { \boldsymbol u } , B ) \big ) \ge \mathcal { L } ( { \boldsymbol w } ) + \frac { m p } { 2 ( 1 - p ) } \| { \boldsymbol w } - { \boldsymbol u } \| ^ { 2 } ,$$
for all $\textbf { \em w }$
Corollary 1.1 is a straightforward result from Theorem 1. As the mix probability $p$ in equation 9 increases to 1, the $L ^ { 2 }$ -regularization coefficient of $m p / ( 1 - p )$ increases to infinity. It means that $p$ of mixout $( \boldsymbol { \mathscr { u } } , \boldsymbol { p } )$ can adjust the strength of $L ^ { 2 }$ -penalty toward $\textbf { \em u }$ in optimization. mixout $( { \pmb u } )$ differs from wdecay $( { \pmb u } )$ since the regularization coefficient of mixout $( { \pmb u } )$ depends on $m$ determined by the current model parameter $\pmb { w }$ . mixout $( \pmb { u } , \ p )$ indeed regularizes learning to minimize the deviation from $\textbf { \em u }$ . We validate this by performing least squares regression in Supplement D.
We often apply dropout to specific layers. For instance, Simonyan & Zisserman (2014) applied dropout to fully connected layers only. We generalize Theorem 1 to the case in which mixout is only applied to specific layers, and it can be done by constructing $M$ in a particular way. We demonstrate this approach in Supplement B and show that mixout for specific layers adaptively $L ^ { 2 }$ -penalizes their parameters.
# 3.2 MIXOUT FOR PRETRAINED MODELS
Hoffer et al. (2017) have empirically shown that
$$\left\| \mathbfcal { w } _ { t } - \mathbfcal { w } _ { 0 } \right\| \sim \log t ,$$
where ${ \pmb w } _ { t }$ is a model parameter after the $t$ -th SGD step. When training from scratch, we usually sample an initial model parameter $\pmb { w } _ { 0 }$ from a normal/uniform distribution with mean 0 and small variance. Since ${ \pmb w } _ { 0 }$ is close to the origin, ${ \pmb w } _ { t }$ is away from the origin only with a large $t$ by equation 10. When finetuning, we initialize our model parameter from a pretrained model parameter ${ \pmb w } _ { \mathrm { p r e } }$ . Since we usually obtain ${ \pmb w } _ { \mathrm { p r e } }$ by training from scratch on a large pretraining dataset, ${ \pmb w } _ { \mathrm { p r e } }$ is often far away from the origin. By Corollary 1.1, dropout $L ^ { 2 }$ -penalizes the model parameter for deviating away from the origin rather than ${ \pmb w } _ { \mathrm { p r e } }$ . To explicitly prevent the deviation from ${ \pmb w } _ { \mathrm { p r e } }$ , we instead propose to use mixout $( w _ { \mathrm { p r e } } )$ .
# 4 VERIFICATION OF THEORETICAL RESULTS FOR MIXOUT ON MNIST
Wiese et al. (2017) have highlighted that wdecay $( w _ { \mathrm { p r e } } )$ is an effective regularization technique to avoid catastrophic forgetting during finetuning. Because mixout $( w _ { \mathrm { p r e } } )$ keeps the finetuned model to stay in the vicinity of the pretrained model similarly to wdecay $( \dot { \boldsymbol { w } } _ { \mathrm { p r e } } )$ , we suspect that the proposed mixout $( w _ { \mathrm { p r e } } )$ has a similar effect of alleviating the issue of catastrophic forgetting. To empirically verify this claim, we pretrain a 784-300-100-10 fully-connected network on EMNIST Digits (Cohen et al., 2017), and finetune it on MNIST. For more detailed description of the model architecture and datasets, see Supplement C.1.
In the pretraining stage, we run five random experiments with a batch size of 32 for $\{ 1 , 2 , \cdots , 2 0 \}$ training epochs. We use Adam (Kingma & Ba, 2014) with a learning rate of $1 0 ^ { - 4 }$ , $\beta _ { 1 } ~ = ~ 0 . 9$ , $\beta _ { 2 } ~ = ~ 0 . 9 9 9$ , wdecay $\mathbf { ( 0 , \eta 0 . 0 1 ) }$ , learning rate warm-up over the first $10 \%$ steps of the total steps, and linear decay of the learning rate after the warm-up. We use dropout(0.1) for all layers except the input and output layers. We select ${ \pmb w } _ { \mathrm { p r e } }$ whose validation accuracy on EMNIST Digits is best (0.992) in all experiments.
For finetuning, most of the model hyperparameters are kept same as in pretraining, with the exception of the learning rate, number of training epochs, and regularization techniques. We train with a learning rate of $\zeta \times 1 0 ^ { - 5 }$ for 5 training epochs. We replace dropout $( p )$ with mixout $( \mathbf { \boldsymbol { w } } _ { \mathrm { p r e } } , \mathbf { \boldsymbol { p } } )$ . We do not use any other regularization technique such as wdecay(0) and wdecay $( { \pmb w } _ { \mathrm { p r e } } )$ . We monitor $\lvert | \boldsymbol { w } _ { \mathrm { f t } } - \boldsymbol { w } _ { \mathrm { p r e } } \rvert | ^ { 2 }$ ,1 validation accuracy on MNIST, and validation accuracy on EMNIST Digits to compare mixout $( { \pmb w } _ { \mathrm { p r e } } , \ p )$ to dropout $( p )$ across 10 random restarts.2
 Figure 2: We present $\lvert | \boldsymbol { w } _ { \mathrm { f t } } - \boldsymbol { w } _ { \mathrm { p r e } } \rvert | ^ { 2 }$ , validation accuracy on MNIST (target task), and validation accuracy on EMNIST Digits (source task), as the function of the probability $p$ where ${ \pmb w } _ { \mathrm { f t } }$ and ${ \pmb w } _ { \mathrm { p r e } }$ are the model parameter after finetuning and the pretrained model parameter, respectively. We report mean (curve) $\pm$ std. (shaded area) across 10 random restarts. (a): mixout $( { \pmb w } _ { \mathrm { p r e } } , \ p ) \ \bar { L } ^ { 2 }$ -penalizes the deviation from ${ \pmb w } _ { \mathrm { p r e } }$ , and this penalty becomes strong as $p$ increases. However, with dropout $( p )$ , ${ \pmb w } _ { \mathrm { f t } }$ becomes away from ${ \pmb w } _ { \mathrm { p r e } }$ as $p$ increases. (b): After finetuning on MNIST, both mixout $( \pmb { w } _ { \mathrm { p r e } } , p )$ and dropout $( p )$ result in high validation accuracy on MNIST for $p \in \{ 0 . 1 , 0 . 2 , 0 . 3 \}$ . (c): Validation accuracy of dropout $( p )$ on EMNIST Digits drops more than that of mixout $( \mathbf { \boldsymbol { w } } _ { \mathrm { p r e } } , \mathbf { \boldsymbol { p } } )$ for all $p$ . mixout $( \mathbf { \boldsymbol { w } } _ { \mathrm { p r e } } , \mathbf { \boldsymbol { p } } )$ minimizes the deviation from ${ \pmb w } _ { \mathrm { p r e } }$ and memorizes the source task better than dropout $( p )$ for all $p$ .
As shown in Figure 2 (a), after finetuning with mixout $( \mathbf { \boldsymbol { w } } _ { \mathrm { p r e } } , \mathbf { \boldsymbol { p } } )$ , the deviation from ${ \pmb w } _ { \mathrm { p r e } }$ is minimized in the $L ^ { 2 }$ -sense. This result verifies Corollary 1.1. We demonstrate that the validation accuracy of mixout $( \mathbf { \boldsymbol { w } } _ { \mathrm { p r e } } , \mathbf { \boldsymbol { p } } )$ has greater robustness to the choice of $p$ than that of dropout $( p )$ . In Figure 2 (b), both dropout $( p )$ and mixout $( \mathbf { \boldsymbol { w } } _ { \mathrm { p r e } } , \mathbf { \boldsymbol { p } } )$ result in high validation accuracy on the target task (MNIST) for $p \in \{ 0 . 1 , \ 0 . 2 , \ 0 . 3 \}$ , although mixout $( \mathbf { \boldsymbol { w } } _ { \mathrm { p r e } } , \mathbf { \boldsymbol { p } } )$ is much more robust with respect to the choice of the mix probability $p$ . In Figure 2 (c), the validation accuracy of mixout $( { \pmb w } _ { \mathrm { p r e } } , \ p )$ on the source task (EMNIST Digits) drops from the validation accuracy of the model at ${ \pmb w } _ { \mathrm { p r e } }$ (0.992) to approximately 0.723 regardless of $p$ . On the other hand, the validation accuracy of dropout $( p )$ on the source task respectively drops by 0.041, 0.074 and 0.105 which are more than those of mixout $( \pmb { w } _ { \mathrm { p r e } } , p )$ for $p \in \{ \bar { 0 } . 1 , 0 . \bar { 2 } , 0 . 3 \bar \}$ .
# 5 FINETUNING A PRETRAINED LANGUAGE MODEL WITH MIXOUT
In order to experimentally validate the effectiveness of mixout, we finetune BERTLARGE on a subset of GLUE (Wang et al., 2018) tasks (RTE, MRPC, CoLA, and STS-B) with mixout $( w _ { \mathrm { p r e } } )$ . We choose them because Phang et al. (2018) have observed that it was unstable to finetune BERTLARGE on these four tasks. We use the publicly available pretrained model released by Devlin et al. (2018), ported into PyTorch by HuggingFace.3 We use the learning setup and hyperparameters recommended by Devlin et al. (2018). We use Adam with a learning rate of $\overset { \cdot } { 2 } \times \overset { \cdot } { 1 } 0 ^ { - 5 }$ , $\beta _ { 1 } ~ = ~ 0 . 9$ , $\beta _ { 2 } ~ = ~ 0 . 9 \dot { 9 } 9$ , learning rate warmup over the first $10 \%$ steps of the total steps, and linear decay of the learning rate after the warmup finishes. We train with a batch size of 32 for 3 training epochs. Since the pretrained BERTLARGE is the sentence encoder, we have to create an additional output layer, which is not pretrained. We initialize each parameter of it with $\mathcal { N } ( 0 , 0 . 0 2 ^ { 2 } )$ . We describe our experimental setup further in Supplement C.2.
The original regularization strategy used in Devlin et al. (2018) for finetuning BERTLARGE is using both dropout(0.1) and wdecay $\mathbf { ( 0 , \eta 0 . 0 1 ) }$ for all layers except layer normalization and intermediate layers activated by GELU (Hendrycks & Gimpel, 2016). We however cannot use mixout $( { \pmb w } _ { \mathrm { p r e } } )$ nor wdecay $( { \pmb w } _ { \mathrm { p r e } } )$ for the additional output layer which was not pretrained and therefore does not have ${ \pmb w } _ { \mathrm { p r e } }$ . We do not use any regularization for the additional output layer when finetuning BERTLARGE with mixout $( { \boldsymbol { w } } _ { \mathrm { p r e } } )$ and wdecay $( w _ { \mathrm { p r e } } )$ . For the other layers, we replace dropout(0.1) and wdecay $\mathbf { ( 0 , \ 0 . 0 1 ) }$ with mixout $( { \boldsymbol { w } } _ { \mathrm { p r e } } )$ and wdecay $( w _ { \mathrm { p r e } } )$ , respectively.
Phang et al. (2018) have reported that large pretrained models (e.g., $\mathrm { B E R T _ { L A R G E } } \backslash$ ) are prone to degenerate performance when finetuned on a task with a small number of training examples, and that multiple random restarts4 are required to obtain a usable model better than random prediction. To compare finetuning stability of the regularization techniques, we need to demonstrate the distribution of model performance. We therefore train $\mathrm { B E R T _ { L A R G E } }$ with each regularization strategy on each task with 20 random restarts. We validate each random restart on the dev set to observe the behaviour of the proposed mixout and finally evaluate it on the test set for generalization. We present the test score of our proposed regularization strategy on each task in Supplement C.3.
We finetune $\mathrm { B E R T _ { L A R G E } }$ with mixout $( w _ { \mathrm { p r e } }$ , $\{ 0 . 7 , 0 . 8 , 0 . 9 \} \mathrm { , }$ ) on RTE, MRPC, CoLA, and STSB. For the baselines, we finetune $\mathrm { B E R T _ { L A R G E } }$ with both dropout(0.1) and wdecay $\mathbf { ( 0 , \ 0 . 0 1 ) }$ as well as with wdecay $\mathbf { \Delta } _ { w _ { \mathrm { p r e } } }$ , $\{ 0 . 0 1 , 0 . 0 4 , 0 . 0 7 , 0 . 1 0 \} )$ . These choices are made based on the experiments in Section 6.3 and Supplement F. In Section 6.3, we observe that finetuning BERTLARGE with mixout $( \mathbf { \boldsymbol { w } } _ { \mathrm { p r e } } , \mathbf { \boldsymbol { p } } )$ on RTE is significantly more stable with $p \in \{ 0 . 7 , \ 0 . 8 , \ 0 . 9 \}$ while finetuning with $\operatorname { d r o p o u t } ( p )$ becomes unstable as $p$ increases. In Supplement F, we demonstrate that dropout(0.1) is almost optimal for all the tasks in terms of mean dev score although Devlin et al. (2018) selected it to improve the maximum dev score.
In Figure 3, we plot the distributions of the dev scores from 20 random restarts when finetuning BERTLARGE with various regularization strategies on each task. For conciseness, we only show four regularization strategies; Devlin et al. (2018)’s: both dropout(0.1) and wdecay $\mathbf { ( 0 , \theta 0 . 0 1 ) }$ , Wiese et al. (2017)’s: wdecay $( w _ { \mathrm { p r e } } , \ 0 . 0 1 )$ , ours: mixout $( w _ { \mathrm { p r e } } , \ 0 . 7 )$ , and ours $^ +$ Wiese et al. (2017)’s: both mixout $( { \pmb w } _ { \mathrm { p r e } } , \ 0 . 7 )$ and wdecay $( w _ { \mathrm { p r e } } , \ 0 . 0 1 )$ . As shown in Figure 3 (a–c), we observe many finetuning runs that fail with the chance-level accuracy when we finetune BERTLARGE with both dropout(0.1) and wdecay $\mathbf { ( 0 , \ 0 . 0 1 ) }$ on RTE, MRPC, and CoLA. We also have a bunch of degenerate model configurations when we use wdecay $( w _ { \mathrm { p r e } } , \ 0 . 0 1 )$ without mixout $( w _ { \mathrm { p r e } } , \ 0 . 7 )$ .
Unlike existing regularization strategies, when we use mixout $( { \pmb w } _ { \mathrm { p r e } } , \ 0 . 7 )$ as a regularization technique with or without wdecay $( { \pmb w } _ { \mathrm { p r e } } , \ 0 . 0 1 )$ for finetuning $\mathrm { B E R T _ { L A R G E } }$ , the number of degenerate model configurations that fail with a chance-level accuracy significantly decreases. For example, in Figure 3 (c), we have only one degenerate model configuration when finetuning BERTLARGE with mixout $( { \pmb w } _ { \mathrm { p r e } } , \ 0 . 7 )$ on CoLA while we observe respectively seven and six degenerate models with Devlin et al. (2018)’s and Wiese et al. (2017)’s regularization strategies.
 Figure 3: Distribution of dev scores on each task from 20 random restarts when finetuning BERTLARGE with Devlin et al. (2018)’s: both dropout(0.1) and wdecay(0, 0.01), Wiese et al. (2017)’s: wdecay $( { \pmb w } _ { \mathrm { p r e } } , \ 0 . 0 1 )$ , ours: mixout $( w _ { \mathrm { p r e } } , \ 0 . 7 )$ , and ours $+$ Wiese et al. (2017)’s: both mixout $( w _ { \mathrm { p r e } } , \ 0 . 7 )$ and wdecay( $( w _ { \mathrm { p r e } } , \ 0 . 0 1 )$ . We write them as Devlin (blue), Wiese (orange), Our (green), and $\mathrm { O u r + W }$ (red), respectively. We use the same set of 20 random initializations across all the regularization setups. Error intervals show mean±std. For all the tasks, the number of finetuning runs that fail with the chance-level accuracy is significantly reduced when we use our regularization mixout $( { \pmb w } _ { \mathrm { p r e } } , \ 0 . 7 )$ regardless of using wdecay $( { \pmb w } _ { \mathrm { p r e } } , \ 0 . 0 1 )$ .
In Figure 3 (a), we further improve the stability of finetuning BERTLARGE by using both mixout $( w _ { \mathrm { p r e } } , 0 . 7 )$ and wdecay( $\mathbf { \Delta } _ { w _ { \mathrm { p r e } } }$ , 0.01). Figure 3 (d) shows respectively two and one degenerate model configurations with Devlin et al. (2018)’s and Wiese et al. (2017)’s, but we do not have any degenerate resulting model with ours and ours $+$ Wiese et al. (2017)’s. In Figure 3 (b, c), we observe that the number of degenerate model configurations increases when we use wdecay $( { \pmb w } _ { \mathrm { p r e } } , \ 0 . 0 1 )$ ) additionally to mixout $( { \pmb w } _ { \mathrm { p r e } } , \ 0 . 7 )$ . In short, applying our proposed mixout significantly stabilizes the finetuning results of BERTLARGE on small training sets regardless of whether we use wdecay $( \mathbf { \mathscr { w } } _ { \mathrm { p r e } } , \ 0 . 0 1 )$ .
In Table 1, we report the average and the best dev scores across 20 random restarts for each task with various regularization strategies. The average dev scores with mixout( $\mathbf { \Delta } w _ { \mathrm { p r e } }$ , $\{ 0 . 7 , \ 0 . 8 , \ 0 . 9 \} ,$ ) increase for all the tasks. For instance, the mean dev score of finetuning with mixout $( { \pmb w } _ { \mathrm { p r e } } , \ 0 . 8 )$ on CoLA is 57.9 which is $4 9 . 2 \%$ increase over 38.8 obtained by finetuning with both dropout $( p )$ and wdecay $\mathbf { ( 0 , \ 0 . 0 1 ) }$ . We observe that using wdecay( $\mathbf { \Delta } w _ { \mathrm { p r e } }$ , $\{ \bar { 0 . 0 1 } , 0 . 0 4 , \mathsf { \bar { 0 } . 0 7 } , 0 . 1 0 \} \}$ ) also improves the average dev scores for most tasks compared to using both dropout $( p )$ and wdecay $\mathbf { ( 0 , \ 0 . 0 1 ) }$ . We however observe that finetuning with mixout $: ( w _ { \mathrm { p r e } } , ~ \{ 0 . 7 , 0 . 8 , 0 . 9 \} )$ outperforms that with wdecay $\mathbf { \Delta } _ { w _ { \mathrm { p r e } } }$ $_ \mathrm { e } , \ \{ 0 . 0 1 , 0 . 0 4 , 0 . 0 7 , 0 . 1 0 \}$ ) on average. This confirms that $\mathtt { m i x o u t } ( w _ { \mathrm { p r e } } )$ has a different effect for finetuning BERTLARGE compared to wdecay $( { \pmb w } _ { \mathrm { p r e } } )$ since mixout $( w _ { \mathrm { p r e } } )$ is an adaptive $L ^ { 2 }$ -regularizer along the optimization trajectory.
Since finetuning a large pretrained language model such as $\mathrm { B E R T _ { L A R G E } }$ on a small training set frequently fails, the final model performance has often been reported as the maximum dev score (Devlin et al., 2018; Phang et al., 2018) among a few random restarts. We thus report the best dev score for each setting in Table 1. According to the best dev scores as well, mixout( $\mathbf { \Delta } _ { w _ { \mathrm { p r e } } }$ , $\{ 0 . 7 , ~ 0 . 8 , ~ 0 . 9 \} )$ improves performance for all the tasks compared to using both dropout $( p )$ and wdecay $\mathbf { ( 0 , \ 0 . 0 1 ) }$ . For instance, using $\mathrm { m i x o u t } ( w _ { \mathrm { p r e } } , \ 0 . 9 )$ improves the maximum dev score by 0.9 compared to using both dropout $( p )$ and wdecay(0, 0.01) on MRPC. Unlike the average dev scores, the best dev scores achieved by using wdecay $( w _ { \mathrm { p r e } }$ , $\{ 0 . 0 1 , 0 . 0 4 , 0 . 0 7 , 0 . 1 0 \}$ ) are better than those achieved by using mixout( $\mathbf { \Delta } _ { w _ { \mathrm { p r e } } }$ , $\{ 0 . 7 , 0 . 8 , 0 . 9 \}$ ) except RTE on which it was better to use mixout $\mathbf { \Delta } _ { w _ { \mathrm { p r e } } }$ , $\left\{ 0 . 7 , 0 . 8 , 0 . 9 \right\}$ ) than wdecay( ${ \pmb w } _ { \mathrm { p r e } }$ , $\{ 0 . 0 \bar { 1 } , 0 . 0 4 , 0 . 0 7 , 0 . 1 0 \}$ ).
Table 1: Mean (max) dev scores across 20 random restarts when finetuning BERTLARGE with various regularization strategies on each task. We show the following baseline results on the first and second cells: Devlin et al. (2018)’s regularization strategy (both dropout $( p )$ and wdecay $\mathbf { ( 0 , \ 0 . 0 1 ) } )$ ) and Wiese et al. (2017)’s regularization strategy (wdecay( $( w _ { \mathrm { p r e } }$ , $\{ 0 . 0 1 , 0 . 0 4 , 0 . 0 7 , 0 . 1 0 \} )$ ). In the third cell, we demonstrate finetuning results with only mixout $( w _ { \mathrm { p r e } }$ , $\{ 0 . 7 , \ 0 . 8 , \ 0 . 9 \} $ ). The results with both mixout $\mathbf { \Delta } _ { w _ { \mathrm { p r e } } }$ , $\{ 0 . 7 , 0 . 8 , \mathbf { \bar { 0 } } . 9 \} )$ and wdecay( $\mathbf { \Delta } w _ { \mathrm { p r e } }$ , 0.01) are also presented in the fourth cell. Bold marks the best of each statistics within each column. The mean dev scores greatly increase for all the tasks when we use mixout( $\mathbf { \Delta } _ { w _ { \mathrm { p r e } } }$ , $\{ 0 . 7 , 0 . 8 , 0 . 9 \}$ ).
<table><tr><td>TECHNIQUE 1</td><td>TECHNIQUE 2</td><td>RTE</td><td>MRPC</td><td>CoLA</td><td>STS-B</td></tr><tr><td>dropout(0.1)</td><td>wdecay(0, 0.01)</td><td>56.5 (73.6)</td><td>83.4 (90.4)</td><td>38.8 (63.3)</td><td>82.4 (90.3)</td></tr><tr><td>-</td><td>wdecay( (wpre, 0.01)</td><td>56.3 (71.5)</td><td>86.2 (91.6)</td><td>41.9 (65.6)</td><td>85.4 (90.5)</td></tr><tr><td></td><td>wdecay( (wpre, 0.04)</td><td>51.5 (70.8)</td><td>85.8 (91.5)</td><td>35.4 (64.7)</td><td>80.7 (90.6)</td></tr><tr><td></td><td>wdecay( (wpre, 0.07</td><td>57.0 (70.4)</td><td>85.8 (91.0)</td><td>48.1 (63.9)</td><td>89.6 (90.3)</td></tr><tr><td>-</td><td>wdecay( (wpre, 0.10)</td><td>54.6 (71.1)</td><td>84.2 (91.8)</td><td>45.6 (63.8)</td><td>84.3 (90.1)</td></tr><tr><td>mixout(wpre, 0.7)</td><td></td><td>61.6 (74.0)</td><td>87.1 (91.1)</td><td>57.4 (62.1)</td><td>89.6 (90.3)</td></tr><tr><td>mixout( (Wpre, 0.8</td><td></td><td>64.0 (74.0)</td><td>89.0 (90.7)</td><td>57.9 (63.8)</td><td>89.4 (90.3)</td></tr><tr><td>mixout( (Wpre, 0.9)</td><td></td><td>64.3 (73.3)</td><td>88.2 (91.4)</td><td>55.2 (63.4)</td><td>89.4 (90.0)</td></tr><tr><td>mixout( 0.7)</td><td>wdecay 0.01)</td><td>65.3 (74.4)</td><td>87.8 (91.8)</td><td>51.9 (64.0)</td><td></td></tr><tr><td>(wpre, mixout( 0.8</td><td>(wpre, wdecay( 0.01)</td><td>62.8 (74.0)</td><td>86.3 (90.9)</td><td>58.3 (65.1)</td><td>89.6 (90.6) 89.7 (90.3)</td></tr><tr><td>(Wpre,</td><td>(wpre,</td><td></td><td></td><td></td><td></td></tr><tr><td>mixout(wpre, 0.9</td><td>wdecay( (wpre, 0.01)</td><td>65.0 (75.5)</td><td>88.6 (91.3)</td><td>58.1 (65.1)</td><td>89.5 (90.0)</td></tr></table>
We investigate the effect of combining both mixout $( { \pmb w } _ { \mathrm { p r e } } )$ and wdecay $( { \pmb w } _ { \mathrm { p r e } } )$ to see whether they are complementary. We finetune BERTLARGE with both mixout( $\mathbf { \Delta } _ { w _ { \mathrm { p r e } } }$ , {0.7, 0.8, 0.9}) and wdecay $( \mathbf { { w } } _ { \mathrm { { p r e } } } , \ 0 . 0 1 )$ . This leads not only to the improvement in the average dev scores but also in the best dev scores compared to using wdecay $( w _ { \mathrm { p r e } }$ , $\{ 0 . 0 1 , 0 . 0 4 , 0 . 0 7 , 0 . 1 0 \} )$ ) and using both $\operatorname { d r o p o u t } ( p )$ and wdecay(0, 0.01). The experiments in this section confirm that using mixout $( w _ { \mathrm { p r e } } )$ as one of several regularization techniques prevents finetuning instability and yields gains in dev scores.
# 6 ABLATION STUDY
In this section, we perform ablation experiments to better understand mixout $( w _ { \mathrm { p r e } } )$ . Unless explicitly stated, all experimental setups are the same as in Section 5.
# 6.1 MIXOUT WITH A SUFFICIENT NUMBER OF TRAINING EXAMPLES
We showed the effectiveness of the proposed mixout finetuning with only a few training examples in Section 5. In this section, we investigate the effectiveness of the proposed mixout in the case of a larger finetuning set. Since it has been stable to finetune $\mathrm { B E R T _ { L A R G E } }$ on a sufficient number of training examples (Devlin et al., 2018; Phang et al., 2018), we expect to see the change in the behaviour of mixout $( { \pmb w } _ { \mathrm { p r e } } )$ when we use it to finetune BERTLARGE on a larger training set.
We train BERTLARGE by using both mixout $( w _ { \mathrm { p r e } } , \ 0 . 7 )$ and wdecay( ${ \pmb w } _ { \mathrm { p r e } }$ , 0.01) with 20 random restarts on SST-2.5 We also train $\mathrm { B E R T _ { L A R G E } }$ by using both dropout $( p )$ and wdecay(0, 0.01) with 20 random restarts on SST-2 as the baseline. In Table 2, we report the mean and maximum of
SST-2 dev scores across 20 random restarts with each regularization strategy. We observe that there is little difference between their mean and maximum dev scores on a larger training set, although using both mixout $( w _ { \mathrm { p r e } } , \ 0 . 7 )$ and wdecay $( { \pmb w } _ { \mathrm { p r e } } , \ 0 . 0 1 )$ outperformed using both dropout $( p )$ and wdecay(0, 0.01) on the small training sets in Section 5.
Table 2: Mean (max) SST-2 dev scores across 20 random restarts when finetuning BERTLARGE with each regularization strategy. Bold marks the best of each statistics within each column. For a large training set, both mean and maximum dev scores are similar to each other.
<table><tr><td>TECHNIQUE 1</td><td>TECHNIQUE 2</td><td>SST-2</td></tr><tr><td>dropout(0.1)</td><td>wdecay(0, ( 0.01)</td><td>93.4 (94.0)</td></tr><tr><td>mixout(wpre, 0.7)</td><td>wdecay(wpre, 0.01)</td><td>93.5 (94.3)</td></tr></table>
# 6.2 EFFECT OF A REGULARIZATION TECHNIQUE FOR AN ADDITIONAL OUTPUT LAYER
In this section, we explore the effect of a regularization technique for an additional output layer. There are two regularization techniques available for the additional output layer: dropout $( p )$ and mixout $( \boldsymbol { w } _ { 0 } , \boldsymbol { p } )$ where $\pmb { w } _ { 0 }$ is its randomly initialized parameter. Either of these strategies differs from the earlier experiments in Section 5 where we did not put any regularization for the additional output layer.
Table 3: We present mean (max) dev scores across 20 random restarts with various regularization techniques for the additional output layers (ADDITIONAL) when finetuning BERTLARGE on each task. For all cases, we apply mixout $( w _ { \mathrm { p r e } } , \ 0 . 7 )$ to the pretrained layers (PRETRAINED). The first row corresponds to the setup in Section 5. In the second row, we apply mixout $( w _ { 0 } , \ 0 . 7 )$ to the additional output layer where $\pmb { w } _ { 0 }$ is its randomly initialized parameter. The third row shows the results obtained by applying dropout(0.7) to the additional output layer. In the fourth row, we demonstrate the best of each result from all the regularization strategies shown in Table 1. Bold marks the best of each statistics within each column. We obtain additional gains in dev scores by varying the regularization technique for the additional output layer.
<table><tr><td>PRETRAINED</td><td>ADDITIONAL</td><td>RTE</td><td>MRPC</td><td>CoLA</td><td>STS-B</td></tr><tr><td>mixout(wpre, 0.7)</td><td>1</td><td>61.6 (74.0)</td><td>87.1 (91.1)</td><td>57.4 (62.1)</td><td>89.6 (90.3)</td></tr><tr><td>mixout( (wpre, 0.7)</td><td>mixout(wo, 0.7)</td><td>66.5 (75.5)</td><td>88.1 (92.4)</td><td>58.7 (65.6)</td><td>89.7 (90.6)</td></tr><tr><td>mixout(wpre, 0.7)</td><td>dropout(0.7)</td><td>57.2 (70.8)</td><td>85.9 (92.5)</td><td>48.9 (64.3)</td><td>89.2 (89.8)</td></tr><tr><td colspan="2">The best of each result from Table 1</td><td>65.3 (75.5)</td><td>89.0 (91.8)</td><td>58.3 (65.6)</td><td>89.7 (90.6)</td></tr></table>
We report the average and best dev scores across 20 random restarts when finetuning BERTLARGE with mixout $( w _ { \mathrm { p r e } } , 0 . 7 )$ while varying the regularization technique for the additional output layer in Table 3.6 We observe that using mixout $( w _ { 0 } , 0 . 7 )$ for the additional output layer improves both the average and best dev score on RTE, CoLA, and STS-B. In the case of MRPC, we have the highest best-dev score by using dropout(0.7) for the additional output layer while the highest mean dev score is obtained by using mixout $( w _ { 0 } , 0 . 7 )$ for it. In Section 3.2, we discussed how mixout $( \pmb { w } _ { 0 } )$ does not differ from dropout when the layer is randomly initialized, since we sample ${ \pmb w } _ { 0 }$ from w whose mean and variance are 0 and small, respectively. Although the additional output layer is randomly initialized, we observe the significant difference between dropout and mixout $( \pmb { w } _ { 0 } )$ in this layer. We conjecture that $\lVert \mathbf { \boldsymbol { w } } _ { 0 } - \mathbf { 0 } \rVert$ is not sufficiently small because $\mathbb { E } \lVert \mathbf { w } - \mathbf { 0 } \rVert$ is proportional to the dimensionality of the layer (2,048). We therefore expect mixout $\mathbf { \Pi } ( \pmb { w } _ { 0 } )$ to behave differently from dropout even for the case of training from scratch.
In the last row of Table 3, we present the best of the corresponding result from Table 1. We have the highest mean and best dev scores when we respectively use mixout $( { \pmb w } _ { \mathrm { p r e } } , \ 0 . 7 )$ and mixout $( w _ { 0 } , 0 . 7 )$ for the pretrained layers and the additional output layer on RTE, CoLA, and STSB. The highest mean dev score on MRPC is obtained by using mixout $( { \pmb w } _ { \mathrm { p r e } } , \ 0 . 8 )$ for the pretrained layers which is one of the results in Table 1. We have the highest best dev score on MRPC when we use mixout $( w _ { \mathrm { p r e } } , \ 0 . 7 )$ and dropout(0.7) for the pretrained layers and the additional output layer, respectively. The experiments in this section reveal that using mixout $\mathbf { \Pi } ( \pmb { w } _ { 0 } )$ for a randomly initialized layer of a pretrained model is one of the regularization schemes to improve the average dev score and the best dev score.
# 6.3 EFFECT OF MIX PROBABILITY FOR MIXOUT AND DROPOUT
We explore the effect of the hyperparameter $p$ when finetuning BERTLARGE with mixout $( \boldsymbol { \mathbf { \mathit { w } } } _ { \mathrm { p r e } } , \boldsymbol { \mathbf { \mathit { p } } } )$ and dropout $( p )$ . We train $\mathrm { B E R T _ { L A R G E } }$ with mixout $\mathbf { \Delta } ( w _ { \mathrm { p r e } }$ , $\{ 0 . 0 , 0 . 1 , \ \cdot \cdot \ , \ 0 . 9 \} )$ on RTE with 20 random restarts. We also train $\mathrm { B E R T _ { L A R G E } }$ after replacing mixout $( { \pmb w } _ { \mathrm { p r e } } , \ p )$ by dropout $( p )$ with 20 random restarts. We do not use any regularization technique for the additional output layer. Because we use neither wdecay(0) nor wdecay $( { \pmb w } _ { \mathrm { p r e } } )$ in this section, dropout(0.0) and mixout $( { \pmb w } _ { \mathrm { p r e } } , \ 0 . 0 )$ are equivalent to finetuning without regularization.
 Figure 4: Distribution of RTE dev scores (Accuracy) from 20 random restarts when finetuning BERTLARGE with dropout $( p )$ (orange) or mixout $( \pmb { w } _ { \mathrm { p r e } } , \ p )$ (blue). Error intervals show mean $\pm$ std. We do not use wdecay(0) nor wdecay $( { \boldsymbol { w } } _ { \mathrm { p r e } } )$ . In the case of mixout $( \mathbf { \boldsymbol { w } } _ { \mathrm { p r e } } , \mathbf { \boldsymbol { p } } )$ , the number of usable models after finetuning with mixout $\omega _ { \mathrm { p r e } }$ , $\{ 0 . 7 , \ 0 . 8 , \ 0 . 9 \} ,$ is significantly more than the number of usable models after finetuning with dropout $( p )$ for all $p$ .
It is not helpful to vary $p$ for dropout $( p )$ while mixout $( \pmb { w } _ { \mathrm { p r e } } , p )$ helps significantly in a wide range of $p$ . Figure 4 shows distributions of RTE dev scores across 20 random restarts when finetuning BERTLARGE with dropout $( p )$ and mixout $( \mathbf { \boldsymbol { w } } _ { \mathrm { p r e } } , \mathbf { \boldsymbol { p } } )$ for $p \in \{ 0 . 0 , 0 . 1 , \ \cdot \cdot \cdot , 0 . 9 \}$ . The mean dev score of finetuning BERTLARGE with mixout $( \boldsymbol { \mathbf { \mathit { w } } } _ { \mathrm { p r e } } , \boldsymbol { \mathbf { \mathit { p } } } )$ increases as $p$ increases. On the other hand, the mean dev score of finetuning $\mathrm { B E R T _ { L A R G E } }$ with dropout $( p )$ decreases as $p$ increases. If $p$ is less than 0.4, finetuning with mixout $( \boldsymbol { \mathbf { \mathit { w } } } _ { \mathrm { p r e } } , \boldsymbol { \mathbf { \mathit { p } } } )$ does not improve the finetuning results of using dropout $\left( \{ 0 . 0 , 0 . 1 , 0 . 2 \} \right)$ . We however observe that mixout( $\mathbf { \Delta } _ { w _ { \mathrm { p r e } } }$ , $\{ 0 . 7 , 0 . 8 , 0 . { \bar { 9 } } \} )$ yields better average dev scores than dropout $( p )$ for all $p$ , and significantly reduces the number of finetuning runs that fail with the chance-level accuracy.
We notice that the proposed mixout spends more time than dropout from the experiments in this section. It takes longer to finetune a model with the proposed mixout than with the original dropout, although this increase is not significant especially considering the waste of time from failed finetuning runs using dropout. In Supplement E, we describe more in detail the difference between mixout and dropout in terms of wall-clock time.
# 7 CONCLUSION
The special case of our approach, mixout $( w _ { \mathrm { p r e } } )$ , is one of several regularization techniques modifying a finetuning procedure to prevent catastrophic forgetting. Unlike wdecay $( w _ { \mathrm { p r e } } )$ proposed earlier by Wiese et al. (2017), mixout $( { \pmb w } _ { \mathrm { p r e } } )$ is an adaptive $L ^ { 2 }$ -regularizer toward ${ \pmb w } _ { \mathrm { p r e } }$ in the sense that its regularization coefficient adapts along the optimization path. Due to this difference, the proposed mixout improves the stability of finetuning a big, pretrained language model even with only a few training examples of a target task. Furthermore, our experiments have revealed the proposed approach improves finetuning results in terms of the average accuracy and the best accuracy over multiple runs. We emphasize that our approach can be used with any pretrained language models such as RoBERTa (Liu et al., 2019) and XLNet (Yang et al., 2019), since mixout does not depend on model architectures, and leave it as future work.
# ACKNOWLEDGMENTS
The first and third authors’ work was supported by the National Research Foundation of Korea (NRF) grants funded by the Korea government (MOE, MSIT) (NRF-2017R1A2B4011546, NRF2019R1A5A1028324). The second author thanks support by AdeptMind, eBay, TenCent, NVIDIA and CIFAR and was partly supported by Samsung Electronics (Improving Deep Learning using Latent Structure).
# REFERENCES
Jimmy Lei Ba, Jamie Ryan Kiros, and Geoffrey E Hinton. Layer normalization. arXiv preprint arXiv:1607.06450, 2016.
Antonio Valerio Miceli Barone, Barry Haddow, Ulrich Germann, and Rico Sennrich. Regularization techniques for fine-tuning in neural machine translation. arXiv preprint arXiv:1707.09920, 2017.
Daniel Cer, Mona Diab, Eneko Agirre, Inigo Lopez-Gazpio, and Lucia Specia. Semeval-2017 task 1: Semantic textual similarity-multilingual and cross-lingual focused evaluation. arXiv preprint arXiv:1708.00055, 2017.
Gregory Cohen, Saeed Afshar, Jonathan Tapson, and Andre van Schaik. Emnist: an extension of ´ mnist to handwritten letters. arXiv preprint arXiv:1702.05373, 2017.
Ronan Collobert, Jason Weston, Leon Bottou, Michael Karlen, Koray Kavukcuoglu, and Pavel ´ Kuksa. Natural language processing (almost) from scratch. Journal of machine learning research, 12(Aug):2493–2537, 2011.
Ido Dagan, Oren Glickman, and Bernardo Magnini. The PASCAL recognising textual entailment challenge. In Machine learning challenges. evaluating predictive uncertainty, visual object classification, and recognising tectual entailment, pp. 177–190. Springer, 2006.
Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. Bert: Pre-training of deep bidirectional transformers for language understanding. arXiv preprint arXiv:1810.04805, 2018.
William B Dolan and Chris Brockett. Automatically constructing a corpus of sentential paraphrases. In Proceedings of the International Workshop on Paraphrasing, 2005.
Dan Hendrycks and Kevin Gimpel. Gaussian error linear units (gelus). arXiv preprint arXiv:1606.08415, 2016.
Elad Hoffer, Itay Hubara, and Daniel Soudry. Train longer, generalize better: closing the generalization gap in large batch training of neural networks. In Advances in Neural Information Processing Systems, pp. 1731–1741, 2017.
Diederik P Kingma and Jimmy Ba. Adam: A method for stochastic optimization. arXiv preprint arXiv:1412.6980, 2014.
Durk P Kingma, Tim Salimans, and Max Welling. Variational dropout and the local reparameterization trick. In Advances in Neural Information Processing Systems, pp. 2575–2583, 2015.
James Kirkpatrick, Razvan Pascanu, Neil Rabinowitz, Joel Veness, Guillaume Desjardins, Andrei A Rusu, Kieran Milan, John Quan, Tiago Ramalho, Agnieszka Grabska-Barwinska, et al. Overcoming catastrophic forgetting in neural networks. Proceedings of the national academy of sciences, 114(13):3521–3526, 2017.
Yinhan Liu, Myle Ott, Naman Goyal, Jingfei Du, Mandar Joshi, Danqi Chen, Omer Levy, Mike Lewis, Luke Zettlemoyer, and Veselin Stoyanov. Roberta: A robustly optimized bert pretraining approach. arXiv preprint arXiv:1907.11692, 2019.
Poorya Mianjy and Raman Arora. On dropout and nuclear norm regularization. In Kamalika Chaudhuri and Ruslan Salakhutdinov (eds.), Proceedings of the 36th International Conference on Machine Learning, volume 97 of Proceedings of Machine Learning Research, pp. 4575–4584, Long Beach, California, USA, 09–15 Jun 2019. PMLR. URL http : / / proceedings . mlr . press/v97/mianjy19a.html.
Vinod Nair and Geoffrey E Hinton. Rectified linear units improve restricted boltzmann machines. In Proceedings of the 27th international conference on machine learning (ICML-10), pp. 807–814, 2010.
Jason Phang, Thibault Fevry, and Samuel R Bowman. Sentence encoders on stilts: Supplementary ´ training on intermediate labeled-data tasks. arXiv preprint arXiv:1811.01088, 2018.
Jonathan Schwarz, Jelena Luketina, Wojciech M Czarnecki, Agnieszka Grabska-Barwinska, Yee Whye Teh, Razvan Pascanu, and Raia Hadsell. Progress & compress: A scalable framework for continual learning. arXiv preprint arXiv:1805.06370, 2018.
Karen Simonyan and Andrew Zisserman. Very deep convolutional networks for large-scale image recognition. arXiv preprint arXiv:1409.1556, 2014.
Richard Socher, Alex Perelygin, Jean Wu, Jason Chuang, Christopher D Manning, Andrew $\mathrm { N g }$ , and Christopher Potts. Recursive deep models for semantic compositionality over a sentiment treebank. In Proceedings of EMNLP, pp. 1631–1642, 2013.
Nitish Srivastava, Geoffrey Hinton, Alex Krizhevsky, Ilya Sutskever, and Ruslan Salakhutdinov. Dropout: a simple way to prevent neural networks from overfitting. The Journal of Machine Learning Research, 15(1):1929–1958, 2014.
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, pp. 5998–6008, 2017.
Li Wan, Matthew Zeiler, Sixin Zhang, Yann Le Cun, and Rob Fergus. Regularization of neural networks using dropconnect. In International conference on machine learning, pp. 1058–1066, 2013.
Alex Wang, Amanpreet Singh, Julian Michael, Felix Hill, Omer Levy, and Samuel R Bowman. Glue: A multi-task benchmark and analysis platform for natural language understanding. arXiv preprint arXiv:1804.07461, 2018.
Sida Wang and Christopher Manning. Fast dropout training. In international conference on machine learning, pp. 118–126, 2013.
Alex Warstadt, Amanpreet Singh, and Samuel R. Bowman. Neural network acceptability judgments. arXiv preprint 1805.12471, 2018.
Georg Wiese, Dirk Weissenborn, and Mariana Neves. Neural domain adaptation for biomedical question answering. arXiv preprint arXiv:1706.03610, 2017.
Zhilin Yang, Zihang Dai, Yiming Yang, Jaime Carbonell, Ruslan Salakhutdinov, and Quoc V Le. Xlnet: Generalized autoregressive pretraining for language understanding. arXiv preprint arXiv:1906.08237, 2019.
SUPPLEMENTARY MATERIAL
A PROOFS FOR THEOREM 1
Theorem 1. Assume that the loss function $\mathcal { L }$ is strongly convex. Suppose that a random mixture function with respect to $\textbf { \em w }$ from $\textbf { \em u }$ and $M$ is given by
$$\Phi ( { \pmb w } ; { \pmb u } , M ) = \mu ^ { - 1 } \big ( ( { \pmb I } - M ) { \pmb u } + M { \pmb w } - ( 1 - \mu ) { \pmb u } \big ) ,$$
where $M$ is $\mathrm { d i a g } ( M _ { 1 } , ~ M _ { 2 } , ~ \cdot \cdot \cdot , ~ M _ { d } ) $ satisfying $\mathbb { E } M _ { i } = \mu$ and $\mathrm { V a r } ( M _ { i } ) = \sigma ^ { 2 }$ for all $i$ . Then, there exists $m > 0$ such that
$$\mathbb { E } \mathcal { L } \big ( \Phi ( { \boldsymbol w } ; { \boldsymbol u } , M ) \big ) \ge \mathcal { L } ( { \boldsymbol w } ) + \frac { m \sigma ^ { 2 } } { 2 \mu ^ { 2 } } \| { \boldsymbol w } - { \boldsymbol u } \| ^ { 2 } ,$$
for all $\textbf { \em w }$
Proof. Since $\mathcal { L }$ is strongly convex, there exist $m > 0$ such that
$$\begin{array} { r l } & { \mathbb { E } \mathcal { L } \big ( \Phi ( w ; u , M ) \big ) = \mathbb { E } \mathcal { L } \Big ( w + \big ( \Phi ( w ; u , M ) - w \big ) \Big ) } \\ & { \qquad \quad \geq \mathcal { L } ( w ) + \nabla \mathcal { L } ( w ) ^ { \top } \mathbb { E } [ \Phi ( w ; u , M ) - w ] + \frac { m } { 2 } \mathbb { E } \| \Phi ( w ; u , M ) - w \| ^ { 2 } , } \end{array}$$
for all $\pmb { w }$ by equation 1. Recall that $\mathbb { E } M _ { i } = \mu$ and $\mathrm { V a r } ( M _ { i } ) = \sigma ^ { 2 }$ for all $i$ . Then, we have
$$\mathbb { E } [ \Phi ( { \pmb w } ; { \pmb u } , M ) - { \pmb w } ] = { \bf 0 } ,$$
and
$$\begin{array} { l } { \displaystyle \mathbb { E } \| \Phi ( \boldsymbol { w } ; ~ \boldsymbol { u } , \boldsymbol { M } ) - \boldsymbol { w } \| ^ { 2 } = \mathbb { E } \left\| \frac { 1 } { \mu } ( \boldsymbol { w } - \boldsymbol { u } ) ( \boldsymbol { M } - \mu \boldsymbol { I } ) \right\| ^ { 2 } } \\ { \displaystyle \qquad = \frac { 1 } { \mu ^ { 2 } } \sum _ { i = 1 } ^ { d } ( w _ { i } - u _ { i } ) ^ { 2 } \mathbb { E } ( M _ { i } - \mu ) ^ { 2 } } \\ { \displaystyle \qquad = \frac { \sigma ^ { 2 } } { \mu ^ { 2 } } \| \boldsymbol { w } - \boldsymbol { u } \| ^ { 2 } . } \end{array}$$
By using equation 13 and equation 14, we can rewrite equation 12 as
$$\mathbb { E } \mathcal { L } \big ( \Phi ( { \boldsymbol w } ; { \boldsymbol u } , M ) \big ) \ge \mathcal { L } ( { \boldsymbol w } ) + \frac { m \sigma ^ { 2 } } { 2 \mu ^ { 2 } } \| { \boldsymbol w } - { \boldsymbol u } \| ^ { 2 } .$$
# B APPLYING TO SPECIFIC LAYERS
We often apply dropout to specific layers. For instance, Simonyan & Zisserman (2014) applied dropout to fully connected layers only. We generalize Theorem 1 to the case in which mixconnect is only applied to specific layers, and it can be done by constructing $M$ in a particular way. To better characterize mixconnect applied to specific layers, we define the index set $\mathbb { I }$ as $\mathbb { I } = \{ i : \ \boldsymbol { M } _ { i } = 1 \}$ . Furthermore, we use $\tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } ^ { v }$ and $\tilde { \mathbf { \pmb { u } } }$ to denote $( w _ { i } ) _ { i \notin \mathbb { I } }$ and $( u _ { i } ) _ { i \notin \mathbb { I } }$ , respectively. Then, we generalize equation 7 to
$$\mathbb { E } \mathcal { L } \big ( \Phi ( { \boldsymbol w } ; { \boldsymbol u } , M ) \big ) \ge \mathcal { L } ( { \boldsymbol w } ) + \frac { m \sigma ^ { 2 } } { 2 \mu ^ { 2 } } \| \tilde { { \boldsymbol w } } - \tilde { { \boldsymbol u } } \| ^ { 2 } .$$
From equation 15, applying mixconnec $\scriptstyle ; ( u , \mu , \sigma ^ { 2 } )$ is to use adaptive wdecay $( \tilde { u } )$ on the weight parameter of the specific layers $\tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } ^ { \tilde { \mathbf { \Gamma } } } \tilde { \mathbf { \Gamma } } ^ { \tilde { \mathbf { \Gamma } } } \tilde { \mathbf { \Gamma } } ^ { \tilde { \mathbf { \Gamma } } } \tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } \tilde { \mathbf { \Gamma } } \tilde \mathrm { \Gamma }$ . Similarly, we can regard applying mixout $( \boldsymbol { \mathscr { u } } , \boldsymbol { \mathscr { p } } )$ to specific layers as adaptive wdecay $( \tilde { u } )$ .
# C EXPERIMENTAL DETAILS
# C.1 FROM EMNIST DIGITS TO MNIST
Model Architecture The model architecture in Section 4 is a 784-300-100-10 fully connected network with a softmax output layer. For each hidden layer, we add layer normalization (Ba et al., 2016) right after the ReLU (Nair & Hinton, 2010) nonlinearity. We initialize each parameter with $\mathcal { N } ( 0 , 0 . \bar { 0 } 2 ^ { 2 } )$ and each bias with 0.
Regularization In the pretraining stage, we use dropout(0.1) and wdecay $\mathbf { ( 0 , \ 0 . 0 1 ) }$ . We apply dropout(0.1) to all hidden layers. That is, we do not drop neurons of the input and output layers. wdecay $\mathbf { ( 0 , \eta 0 . 0 1 ) }$ does not penalize the parameters for bias and layer normalization. When we finetune our model on MNIST, we replace dropout $( p )$ with mixout $( \mathbf { \boldsymbol { w } } _ { \mathrm { p r e } } , \mathbf { \boldsymbol { p } } )$ . We use neither wdecay(0) nor wdecay $( { \pmb w } _ { \mathrm { p r e } } )$ for finetuning.
Dataset For pretraining, we train our model on EMNIST Digits. This dataset has 280,000 characters into 10 balanced classes. These characters are compatible with MNIST characters. EMNIST Digits provides 240,000 characters for training and 40,000 characters for test. We use 240,000 characters provide for training and split these into the training set (216,000 characters) and validation set (24,000 characters). For finetuning, we train our model on MNIST. This has 70,000 characters into 10 balance classes. MNIST provide 60,000 characters for training and 10,000 characters for test. We use 60,000 characters given for training and split these into the training set (54,000 characters) and validation set (6,000 characters).
Data Preprocessing We only use normalization after scaling pixel values into [0, 1]. We do not use any data augmentation.
# C.2 FINETUNING BERT ON PARTIAL GLUE TASKS
Model Architecture Because the model architecture of $\mathrm { B E R T _ { L A R G E } }$ is identical to the original (Devlin et al., 2018), we omit its exhaustive description. Briefly, BERTLARGE has 24 layers, 1024 hidden size, and 16 self-attention heads (total 340M parameters). We use the publicly available pretrained model released by Devlin et al. (2018), ported into PyTorch by HuggingFace.7 We initialize each weight parameter and bias for an additional output layer with $\mathcal { N } ( 0 , 0 . 0 2 ^ { 2 } )$ and 0, respectively.
Regularization In the finetuning stage, Devlin et al. (2018) used wdecay $\mathbf { ( 0 , \ 0 . 0 1 ) }$ for all parameters except bias and layer normalization. They apply dropout(0.1) to all layers except each hidden layer activated by GELU (Hendrycks & Gimpel, 2016) and layer normalization. We substitute wdecay $( { \boldsymbol { w } } _ { \mathrm { p r e } } )$ and mixout $( { \pmb w } _ { \mathrm { p r e } } )$ for wdecay $\mathbf { ( 0 , \ 0 . 0 1 ) }$ and dropout(0.1), respectively.
Dataset We use a subset of GLUE (Wang et al., 2018) tasks. The brief description for each dataset is as the following:
• RTE (2,500 training examples): Binary entailment task (Dagan et al., 2006) • MRPC (3,700 training examples): Semantic similarity (Dolan & Brockett, 2005) • CoLA (8,500 training examples): Acceptability classification (Warstadt et al., 2018) STS-B (7,000 training examples): Semantic textual similarity (Cer et al., 2017) • SST-2 (67,000 training examples): Binary sentiment classification (Socher et al., 2013)
In this paper, we reported F1 accuracy scores for MRPC, Mattew’s correlation scores for CoLA, Spearman correlation scores for STS-B, and accuracy scores for the other tasks.
Data Preprocessing We use the publicly available implementation of BERTLARGE by HuggingFace.8
# C.3 TEST RESULTS ON GLUE TASKS
We expect that using mixout stabilizes finetuning results of BERTLARGE on a small training set. To show this, we demonstrated distributions of dev scores from 20 random restarts on RTE, MRPC, CoLA, and STS-B in Figure 3. We further obtained the highest average/best dev score on each task in Table 3. To confirm the generalization of the our best model on the dev set, we demonstrate the test results scored by the evaluation server9 in Table 4.
Table 4: We present the test score when finetuning BERTLARGE with each regularization strategy on each task. The first row shows the test scores obtained by using both dropout $( p )$ and wdecay $\mathbf { ( 0 , \ 0 . 0 1 ) }$ . These results in the first row are reported by Devlin et al. (2018). They used the learning rate of $\lbrace 2 \times 1 0 ^ { - 5 }$ , $3 \times 1 0 ^ { - 5 }$ , $4 \times 1 0 ^ { - 5 }$ , $5 \times 1 0 ^ { - 5 } \}$ and a batch size of 32 for 3 epochs with multiple random restarts. They selected the best model on each dev set. In the second row, we demonstrate the test scores obtained by using the proposed mixout in Section 6.2: using mixout $( w _ { \mathrm { p r e } } , \ 0 . 7 )$ for the pretrained layers and mixout $( w _ { 0 } , \ 0 . 7 )$ for the additional output layer where $\pmb { w } _ { 0 }$ is its randomly initialized weight parameter. We used the learning rate of $2 \times 1 0 ^ { - 5 }$ and a batch size of 32 for 3 epochs with 20 random restarts. We submitted the best model on each dev set. The third row shows that the test scores obtained by using both dropout $( p )$ and wdecay $\mathbf { ( 0 , \ 0 . 0 1 ) }$ with same experimental setups of the second row. Bold marks the best within each column. The proposed mixout improves the test scores except MRPC compared to the original regularization strategy proposed by Devlin et al. (2018).
<table><tr><td>STRATEGY</td><td>RTE</td><td>MRPC</td><td>CoLA</td><td>STS-B</td></tr><tr><td>Devlin et al. (2018)</td><td>70.1</td><td>89.3</td><td>60.5</td><td>86.5</td></tr><tr><td>mixout(wpre, 0.7)& mixout(wo,0.7)</td><td>70.2</td><td>89.1</td><td>62.1</td><td>87.3</td></tr><tr><td>dropout(p) + wdecay(0, 0.01)</td><td>68.2</td><td>88.3</td><td>59.6</td><td>86.0</td></tr></table>
For all the tasks except MRPC, the test scores obtained by the proposed mixout10 are better than those reported by Devlin et al. (2018). We explored the behaviour of finetuning $\mathrm { B E R T _ { L A R G E } }$ with mixout by using the learning rate of $2 \times 1 0 ^ { - 5 }$ while Devlin et al. (2018) obtained their results by using the learning rate of $\lbrace 2 \times 1 0 ^ { - 5 }$ , $3 \times 1 0 ^ { - 5 }$ , $4 \times 1 0 ^ { - 5 }$ , $5 \times 1 0 ^ { - 5 } \}$ . We thus present the test scores obtained by the regularization strategy of Devlin et al. (2018) when the learning rate is $2 \times 1 0 ^ { - 5 }$ . The results in this section show that the best model on the dev set generalizes well, and all the experiments based on dev scores in this paper are proper to validate the effectiveness of the proposed mixout. For the remaining GLUE tasks such as SST-2 with a sufficient number of training instances, we observed that using mixout does not differs from using dropout in Section 6.1. We therefore omit the test results on the other tasks in GLUE.
# D VERIFICATION OF COROLLARY 1.1 WITH LEAST SQUARES REGRESSION
Corollary 1.1 shows that mixout $( \pmb { u } , p )$ regularizes learning to minimize the deviation from the target model parameter $\textbf { \em u }$ , and the strength of regularization increases as $p$ increases when the loss function is strongly convex. In order to validate this, we explore the behavior of least squares regression with mixout $( \pmb { u } , p )$ on a synthetic dataset. For randomly given $w _ { 1 } ^ { * }$ and $w _ { 2 } ^ { * }$ , we generated an observation $y$ satisfying $y = w _ { 1 } ^ { * } x + w _ { 2 } ^ { * } + \epsilon$ where $\epsilon$ is Gaussian noise. We set the model to $\hat { y } = w _ { 1 } x + w _ { 2 }$ . That is, the model parameter $\pmb { w }$ is given by $( w _ { 1 } , w _ { 2 } )$ . We randomly pick $\textbf { \em u }$ as a target model parameter for $\mathtt { m i x o u t } ( { \boldsymbol { u } } , { \boldsymbol { p } } )$ and perform least squares regression with $\tilde { \mathrm { m i x o u t } } ( u , \ \{ 0 . 0 \dot { , } \ 0 . 3 , \ 0 . 6 , \ 0 . 9 \} )$ . As shown in Figure 5, $\pmb { w }$ converges to the target model parameter $\textbf { \em u }$ rather than the true model parameter $\boldsymbol { w ^ { * } } = ( w _ { 1 } ^ { * } , \ w _ { 2 } ^ { * } )$ as the mix probability $p$ increases.
 Figure 5: Behavior of mixout $( \pmb { u } , \pmb { p } )$ for a strongly convex loss function. We plot the line obtained by least squares regression with mixout $( { \pmb u } , \ \{ 0 . \bar { 0 } , \ 0 . 3 , \ 0 . 6 , \ 0 . 9 \} )$ (each green line) on a synthetic dataset (blue dots) generated by the true line (each blue dotted line). As $p$ increases, the regression line (each green line) converges to the target line generated by the target model parameter $\textbf { \em u }$ (each orange dotted line) rather than the true line (each blue dotted line).
# E TIME USAGE OF MIXOUT COMPARED TO DROPOUT
We recorded the training time of the experiment in Section 6.3 to compare the time usage of mixout and that of dropout. It took about 843 seconds to finetune $\mathrm { B E R T _ { L A R G E } }$ with mixout $( { \pmb w } _ { \mathrm { p r e } } )$ . On the other hand, it took about 636 seconds to finetune BERTLARGE with dropout. mixout $( w _ { \mathrm { p r e } } )$ spends $3 2 . 5 \%$ more time than dropout since mixout $( { \boldsymbol { w } } _ { \mathrm { p r e } } )$ needs an additional computation with the pretrained model parameter ${ \pmb w } _ { \mathrm { p r e } }$ . However, as shown in Figure 4, at least 15 finetuning runs among 20 random restarts fail with the chance-level accuracy on RTE with dropout $( p )$ for all $p$ while only 4 finetuning runs out of 20 random restarts are unusable with mixout( $\mathbf { \Delta } _ { w _ { \mathrm { p r e } } }$ , 0.8). From this result, it is reasonable to finetune with the proposed mixout although this requires additional time usage compared to dropout.
# F EXTENSIVE HYPERPARAMETER SEARCH FOR DROPOUT
Devlin et al. (2018) finetuned BERTLARGE with dropout(0.1) on all GLUE (Wang et al., 2018) tasks. They chose it to improve the maximum dev score on each downstream task, but we have reported not only the maximum dev score but also the mean dev score to quantitatively compare various regularization techniques in our paper. In this section, we explore the effect of the hyperparameter $p$ when finetuning BERTLARGE with dropout $( p )$ on RTE, MRPC, CoLA, and STS-B to show dropout(0.1) is optimal in terms of mean dev score. All experimental setups for these experiments are the same as Section 6.3.
 Figure 6: Distribution of dev scores on each task from 20 random restarts when finetuning BERTLARGE with dropout $( \{ 0 . 0 , 0 . 1 , \ \cdot \cdot \ , 0 . 5 \} )$ . Error intervals show mean±std. When we use dropout(0.1), we have the highest average dev scores on MRPC and STS-B and the second-highest average dev scores on RTE and CoLA. These results show that dropout(0.1) is almost optimal for all tasks in terms of mean dev score.
As shown in Figure 6, we have the highest average dev score on MRPC with dropout(0.1) as well as on STS-B. We obtain the highest average dev scores with dropout(0.0) on RTE and CoLA, but we get the second-highest average dev scores with dropout(0.1) on them. These experiments confirm that the drop probability 0.1 is almost optimal for the highest average dev score on each task.md/train/--rcOeCKRh/--rcOeCKRh.mdAdded+236
md/train/5GihaaZKL4/5GihaaZKL4.mdAdded+394
md/train/9Y7_c5ZAd5i/9Y7_c5ZAd5i.mdAdded
md/train/9c-IsSptbmA/9c-IsSptbmA.mdAdded+257
md/train/B1eB5xSFvr/B1eB5xSFvr.mdAdded+432
md/train/B1gJ1L2aW/B1gJ1L2aW.mdAdded+289
md/train/B1lda1HtvB/B1lda1HtvB.mdAdded+600
md/train/BJe932EYwS/BJe932EYwS.mdAdded+342
md/train/Bk7wvW-C-/Bk7wvW-C-.mdAdded+261
md/train/Bki4EfWCb/Bki4EfWCb.mdAdded+366
md/train/BylVcTNtDS/BylVcTNtDS.mdAdded+251
md/train/BysZhEqee/BysZhEqee.mdAdded+277
md/train/CR1XOQ0UTh-/CR1XOQ0UTh-.mdAdded
md/train/DPHsCQ8OpA/DPHsCQ8OpA.mdAdded+335
md/train/H1egcgHtvB/H1egcgHtvB.mdAdded+260
md/train/H1lGHsA9KX/H1lGHsA9KX.mdAdded+321
md/train/HJxYwiC5tm/HJxYwiC5tm.mdAdded+242
md/train/HkgB2TNYPS/HkgB2TNYPS.mdAdded+499
md/train/HkgaETNtDB/HkgaETNtDB.mdAdded+391
md/train/HkgrZ0EYwB/HkgrZ0EYwB.mdAdded
md/train/HkuGJ3kCb/HkuGJ3kCb.mdAdded
md/train/I3HOxaZIJ0J/I3HOxaZIJ0J.mdAdded
md/train/L7Irrt5sMQa/L7Irrt5sMQa.mdAdded
md/train/Ov_sMNau-PF/Ov_sMNau-PF.mdAdded
md/train/PKubaeJkw3/PKubaeJkw3.mdAdded
md/train/S1efxTVYDr/S1efxTVYDr.mdAdded
md/train/SPrVNsXnGd/SPrVNsXnGd.mdAdded
md/train/Syl7OsRqY7/Syl7OsRqY7.mdAdded
md/train/Syx72jC9tm/Syx72jC9tm.mdAdded
md/train/Ysuv-WOFeKR/Ysuv-WOFeKR.mdAdded
md/train/ZsGg52s-cQZ/ZsGg52s-cQZ.mdAdded
md/train/aDjoksTpXOP/aDjoksTpXOP.mdAdded
md/train/aFvG-DNPNB9/aFvG-DNPNB9.mdAdded
md/train/fATZNtA1-V0/fATZNtA1-V0.mdAdded
md/train/fmgYOUahK9/fmgYOUahK9.mdAdded
md/train/iKQAk8a2kM0/iKQAk8a2kM0.mdAdded
md/train/lxHgXYN4bwl/lxHgXYN4bwl.mdAdded
md/train/nYz2_BbZnYk/nYz2_BbZnYk.mdAdded
md/train/r1gRTCVFvB/r1gRTCVFvB.mdAdded
md/train/r1kNDlbCb/r1kNDlbCb.mdAdded
md/train/rG2ponW2Si/rG2ponW2Si.mdAdded
md/train/rJYFzMZC-/rJYFzMZC-.mdAdded
md/train/rJlUhhVYvS/rJlUhhVYvS.mdAdded
md/train/rk6cfpRjZ/rk6cfpRjZ.mdAdded
md/train/rk6qdGgCZ/rk6qdGgCZ.mdAdded
md/train/ryGDEjCcK7/ryGDEjCcK7.mdAdded
md/train/rylSzl-R-/rylSzl-R-.mdAdded
md/train/tPCrkaLa9Y5ld/tPCrkaLa9Y5ld.mdAdded
md/train/x2TMPhseWAW/x2TMPhseWAW.mdAdded
md/train/xpFFI_NtgpW/xpFFI_NtgpW.mdAdded