ZHANGYUXUAN-zR commited on
Commit
e4ee801
·
verified ·
1 Parent(s): 1108cfe

Add files using upload-large-folder tool

Browse files
md/dev/7anW5TWbCJ/7anW5TWbCJ.md ADDED
@@ -0,0 +1,365 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Information Theoretic Lower Bounds for Information Theoretic Upper Bounds
2
+
3
+ Roi Livni Department Electrical Engineering Tel Aviv University rlivni@tauex.tau.ac.il
4
+
5
+ # Abstract
6
+
7
+ We examine the relationship between the mutual information between the output model and the empirical sample and the generalization of the algorithm in the context of stochastic convex optimization. Despite increasing interest in informationtheoretic generalization bounds, it is uncertain if these bounds can provide insight into the exceptional performance of various learning algorithms. Our study of stochastic convex optimization reveals that, for true risk minimization, dimensiondependent mutual information is necessary. This indicates that existing informationtheoretic generalization bounds fall short in capturing the generalization capabilities of algorithms like SGD and regularized ERM, which have dimension-independent sample complexity.
8
+
9
+ # 1 Introduction
10
+
11
+ One of the crucial challenges facing contemporary generalization theory is to understand and explain the behavior of overparameterized models. These models have a large number of parameters compared to the available training examples. But nonetheless, they tend to perform well on unseen test data. The significance of this issue has become more pronounced in recent years, as it has become evident that many state-of-the-art learning algorithms are highly overparameterized Neyshabur et al. [2014], Zhang et al. [2021]. The classical generalization bounds, which are well designed to describe the learning behavior of underparameterized models, seem to fail to explain these algorithms.
12
+
13
+ Understanding the success of overparameterized models seems challenging. Partly, due to the counter-intuitive nature of the process. Common wisdom suggests that, inorder to learn, one has to have certain good bias of the problem at hand, and that in learning we need to restrict ourselves to a class of models that cannot overfit the data. This intuition has been justified by classical learning models such as PAC learningValiant [1984] as well as regression Alon et al. [1997]. In these classical models, it can be even demonstrated Vapnik and Chervonenkis [2015], Blumer et al. [1989] that learning requires more examples than the capacity of the class of model to be learnt, and that avoiding interpolation is necessary for generalization. These results, though, are obtained in distribution-independent setups where one assumes worst-cast distributions over the data.
14
+
15
+ For this reason, researchers have been searching for new, refined models, as well as improved generalization bounds that incorporate distributional as well as algorithmic assumptions. A promising approach, in this direction, tries to connect the generalization performance to the amount of information the learner holds regarding the data Russo and Zou [2019], Xu and Raginsky [2017], Bassily et al. [2018]. For example, Xu and Raginsky [2017] demonstrated an upper bound on the generalization gap which informally states:
16
+
17
+ $$
18
+ \mathrm { g e n e r a l i z a t i o n } \mathrm { g a p } ( w _ { S } ) = O \left( \sqrt { \frac { I ( w _ { S } , S ) } { | S | } } \right)
19
+ $$
20
+
21
+ Namely, given an empirical sample $s$ , and an output model $w _ { S }$ , the difference between its empirical error and its true error can be upper bounded by $I ( w _ { S } , S )$ , the mutual information between these two random variables. Notice that Eq. (1) does not depend on any trait of the class of feasible models to be considered. In particular, it does not depend, apriori, on number of “free parameters", or a complexity measure such as VC dimension, the dimension of $w _ { S }$ , and not even on some prior distribution. However, it remains a question whether this method and technique can be useful in analysing state-of-the-art learning algorithms. While there has been a lot of work trying to establish the success of learning algorithms in various setups Neu et al. [2021], Xu and Raginsky [2017], Bu et al. [2020], Aminian et al. [2021], Pensia et al. [2018], many of the established bounds are opaque, and often there is no comprehensive end-to-end analysis that effectively illustrates how generalization is to be bounded by Eq. (1) and simultaneously obtain good empirical performance. In fact, there is also evidence Carlini et al. [2021], Feldman [2020] that memorizing data is required, in some regimes, for effective learning. Towards better understanding, we will focus, in this work, on the setup of Stochastic Convex Optimization Shalev-Shwartz et al. [2009] (SCO), and provide accompanying lower bounds to Eq. (1) that will describe how much mutual information is necessary for learning.
22
+
23
+ SCO as a case study for overparametrization: SCO is a very clean and simple setup where a learner observes noisy instances of (Lipschitz) convex functions, defined in $\mathbb { R } ^ { d }$ , and is required to minimize their expectation. On the one hand, it provides simple, amenable to rigorous analysis, definitions of learnability and learning. On the other hand, this model is the cradle of prototypical algorithms such as Gradient Descent (GD) and Stochastic Gradient Descent (SGD), as well as accelerated methods, which are the workhorse behind state-of-the-art optimization methods.
24
+
25
+ Moreover, SCO is an ideal model for understanding overparameterization. It is known Feldman [2016] that in this setup, $\Omega ( d )$ examples are needed in order to avoid overfitting. In fact, even concrete algorithms such as GD and regularized-GD may overfit unless they observe dimension-dependent sample size Amir et al. [2021a,b]. In other words, the capacity of the model and its ability to overfit does indeed scale with the dimension. Nevertheless, it is also known that some algorithms do learn with far fewer examples. For example SGDHazan et al. [2016], Regularized-ERMShalev-Shwartz et al. [2009], Bousquet and Elisseeff [2002] and a stable variant of GD Bassily et al. [2020] all learn with ${ \cal O } ( 1 / \varepsilon ^ { 2 } )$ examples, a dimension independent magnitude. To put it differently, learning in SCO is not just a question of finding the empirical risk minimizer, but also a question of how – what algorithm was used, and learning is not demonstrated by naive uniform convergence bounds that scale with the number of parameters in the model.
26
+
27
+ Therefore, SCO is a natural candidate to study how information theoretic bounds play a role in learning. We might even hope that these bounds shed light on why some algorithms succeed to learn while others fail. Existing algorithms don’t avoid memorizing the data, but it is unclear if holding information on the data is necessary. So we start here with the simplest question:
28
+
29
+ What is the smallest amount of mutual information required for learning in SCO?
30
+
31
+ Our main result shows that, in contrast with the dimension-independent learnability results in this setup, the information between the model and the sample has to be dimension-dependent. As such, the complexity of the class appears implicitly in Eq. (1). As a result, carrying $\Omega ( d )$ bits of information over the sample is necessary for learning at optimal rates, and Eq. (1) doesn’t yield the optimal generalization performance of algorithms such as Regularized ERM, SGD and stable-GD.
32
+
33
+ # 1.1 Related Work
34
+
35
+ Information-theoretic generalization bounds have a long history of study in ML theory McAllester [1998, 1999], Langford and Shawe-Taylor [2002]. Generalization bounds that directly relate to the information between output and input of the learner initiated in the works of Xu and Raginsky [2017], Bassily et al. [2018], Russo and Zou [2019], Bassily et al. [2018] demonstrated limitations for such generalization bounds, for proper ERM learners, and Livni and Moran [2020] showed that any learner (proper or not), that learns the class of thresholds must leak unbounded amount of information. In this work we focus on stochastic optimization and on learning Lipschitz functions. In the setup of SCO the above is not true, and one can construct learners that leak $\tilde { O } ( d )$ bits of information (see Proposition 1). But we would like to know whether information-theoretic bounds behave like the uniform convergence bounds (dimension dependent) or capture the minmax learning rates (dimension independent).
36
+
37
+ Several lines of works applied the analysis of $\mathrm { X u }$ and Raginsky [2017] to provide algorithmicdependent analysis in the context of stochastic optimization. Pensia et al. [2018] and followup improvements Rodríguez-Gálvez et al. [2021], Negrea et al. [2019], Haghifam et al. [2020] provided information-theoretic generalization bounds for Stochastic Gradient Langevine Dynamics (SGLD) and Neu et al. [2021] extends the idea to analyze vanilla SGD. Aminian et al. [2021] also provides full characterization of the closely related, Gibbs Algorithm and shows that the information can inverseley scale with the sample bounds. The bounds in these works are implicitly dimension independent which may seem contradictory to the result established here. Importantly, the above bounds may depend on hyper-parameters such as noise in SGLD and temparature in Gibbs algorithm, and these hyperparameters may affect the optimization performance of the algorithms. The bounds we obtain are applicable only to algorithms with non-trivial true risk, which depends on hyperparameter choice, and as such there is no real contradiction. Taken together, the noise, for example, in SGLD needs to scale with the dimension in order to obtain non-trivial information-theoretic bounds, but that will lead to a large empirical error. Similarly, if the temperature in the Gibbs algorithm doesn’t scale with the dimension, one can potentially achieve small empirical error but at the expanse of high information.
38
+
39
+ Most similar to our work, recently, Haghifam et al. [2022] provided the first set of limitations to information theoretic generalization bounds. They focus on the Gradient Descent method and perturbed variants of it, and provide limitations to both MI bounds as well as conditional mutual information (CMI) bounds Steinke and Ullman [2015] and their individual sample variants Bu et al. [2020], Negrea et al. [2019], Haghifam et al. [2020], Zhou et al. [2022]. In contrast, we focus on the mutual information bound (as well as its individual sample version of Bu et al. [2020]), but we provide bounds that are irrespective of the algorithm.
40
+
41
+ The key idea behind our lower bound proof builds on privacy attacks developed in the differntial privacy literature Bun et al. [2014], Kamath et al. [2019], Steinke and Ullman [2015]. In the context of classification, lower and upper bounds techniques Alon et al. [1997], Bun et al. [2020] were successfully imported to obtain analogous information-theoretic bounds Livni and Moran [2020], Pradeep et al. [2022]. In optimization, though, bounds behave slightly different and therefore, bounds from classification cannot be directly imported to the context of optimization.
42
+
43
+ # 2 Setup and Main Results
44
+
45
+ We begin by describing the classical setup of Stochastic Convex Optimization (SCO), following Shalev-Shwartz et al. [2009]. In this model, we assume a domain $\mathcal { Z }$ , a parameter space $\mathcal { W } \subseteq \mathbb { R } ^ { d }$ and a function $f ( w , z )$ , termed loss function. The function $f$ satisfies that for every $z _ { 0 } \in \mathcal { Z }$ , the function $f ( w , z _ { 0 } )$ as a function over the parameter $w$ is convex and $L$ -Lipschitz.
46
+
47
+ For concreteness, we treat $L$ as a constant, $L = O ( 1 )$ , and we concentrate on the case where $\mathcal { W }$ is the unit ball. Namely:
48
+
49
+ $$
50
+ \mathcal { W } = \{ w : \| w \| \leq 1 \} .
51
+ $$
52
+
53
+ As we mostly care about lower bounds, these won’t affect the generality of our results. Given a distribution $D$ , the expected loss of a parameter $w$ is given by
54
+
55
+ $$
56
+ L _ { D } ( w ) = \underset { z \sim D } { \mathbb { E } } [ f ( w , z ) ] .
57
+ $$
58
+
59
+ The excess true risk of $w$ , with respect to distribution $D$ ,is denoted as:
60
+
61
+ $$
62
+ \Delta _ { D } ( w ) = L _ { D } ( w ) - L _ { D } ( w ^ { \star } ) , \quad \mathrm { w h e r e } , L _ { D } ( w ^ { \star } ) : = \operatorname* { m i n } _ { w \in \mathcal { W } } _ { z \sim D } [ f ( w , z ) ] .
63
+ $$
64
+
65
+ We also denote the excess empirical risk, given sample $S = \{ z _ { 1 } , \dots , z _ { m } \}$ :
66
+
67
+ $$
68
+ \Delta _ { S } ( w ) = \frac { 1 } { m } \sum _ { i = 1 } ^ { m } f ( w , z _ { i } ) - \operatorname* { m i n } _ { w \in \mathcal { W } } \frac { 1 } { m } \sum _ { i = 1 } ^ { m } f ( w , z _ { i } ) .
69
+ $$
70
+
71
+ Leranbility We will focus here on the setup of learning in expectation. In particular, a learning algorithm $A$ is defined as an algorithm that receives a sample $S = \left( z _ { 1 } , \ldots , z _ { m } \right)$ and outputs a parameter $w _ { S } ^ { \overline { { A } } }$ . We will normally supress the dependence of the parameter $w _ { S } ^ { A }$ in $A$ and simply write $w _ { S }$ . The algorithm $A$ is said to learn with sample complexity $m ( \varepsilon )$ if it has the following property: For every $\varepsilon > 0$ , if $s$ is a sample drawn i.i.d from some unknown distribution $D$ , and $| S | \geq m ( \varepsilon )$ then:
72
+
73
+ $$
74
+ \underset { S \sim D ^ { m } } { \mathbb { E } } \big [ \Delta _ { D } \big ( w _ { S } \big ) \big ] \leq \varepsilon .
75
+ $$
76
+
77
+ A closely related setup requires that the learner succeeds with high probability. Standard tools such as Markov’s inequality and boosting the confidence Schapire [1990] demonstrate that the two definitions are essentially equivalent in our model.
78
+
79
+ Information Theory We next overview basic concepts in information theory as well as known generalization bounds that are obtained via such information-theoretic quantities. We will consider here the case of discrete random variables. We elaborate more on this at the end of this section, and how our results extend to algorithms with continuous output. Therefore, throughout, we assume a discrete space of possible outcomes $\Omega$ as well as a distribution $\mathbb { P }$ over $\Omega$ . Recall that a random variable $X$ that takes values in $\mathcal { X }$ is said to be distributed according to $P$ if $\mathbb { P } ( x = X ) = P ( x )$ for every $x \in \mathcal X$ . Similarly two random variables $X$ and $Y$ that take values in $\mathcal { X }$ and $\mathcal { Y }$ respectively have joint distribution $P$ if
80
+
81
+ $$
82
+ \mathbb { P } ( x = X , y = Y ) = P ( x , y ) .
83
+ $$
84
+
85
+ For a given $y \in \mathcal { Y }$ , the conditional distribution $P _ { X \mid y }$ is defined to be $\begin{array} { r } { P \left( x \left| y = Y \right. \right) = \frac { P \left( x , y \right) } { \sum _ { x } P \left( x , y \right) } } \end{array}$ P?? ?? ( ??, ?? ) , and the marginal distribution $P _ { X } : \mathcal { X } \to [ 0 , 1 ]$ is given by $\begin{array} { r } { P _ { X } ( x ) = \sum _ { y } P ( x , y ) } \end{array}$ . If $P _ { 1 }$ and $P _ { 2 }$ are two distributions defined on a discrete set $\mathcal { X }$ then the KL divergence is defined to be:
86
+
87
+ $$
88
+ D _ { K L } \left( P _ { 1 } \| P _ { 2 } \right) = \sum _ { x \in \mathcal { X } } P _ { 1 } ( x ) \log \frac { P _ { 1 } ( x ) } { P _ { 2 } ( x ) } .
89
+ $$
90
+
91
+ Given a joint distribution $P$ that takes values in $\mathcal { X } \times \mathcal { Y }$ the mutual information between random variable $X$ and $Y$ is given by
92
+
93
+ $$
94
+ I ( X ; Y ) = \mathop { \mathbb { E } } _ { Y } \left[ D _ { K L } \left( P _ { X | Y } \big | \big | P _ { X } \right) \right] .
95
+ $$
96
+
97
+ We now provide an exact statement of Eq. (1)
98
+
99
+ Theorem $\mathrm { { X u } }$ and Raginsky [2017]). Suppose $f ( w , z )$ is a bounded by 1 loss function. And let ?? be an algorithm that given a sample $S = \left\{ z _ { 1 } , \dots , z _ { m } \right\}$ drawn i.i.d from a distribution $D$ outputs $w _ { S }$ Then
100
+
101
+ $$
102
+ { \frac { \mathbb { F } } { S } } \left[ L _ { D } ( w _ { S } ) - { \frac { 1 } { m } } \sum _ { i = 1 } ^ { m } f ( w , z _ { i } ) \right] \leq { \sqrt { \frac { 2 I ( w _ { S } , S ) } { m } } } .
103
+ $$
104
+
105
+ Remark on Continuous Algorithms As stated, we focus here on the case of algorithms whose output is discrete, and we also assume that the sample is drawn from a discrete set. Regarding the sample, since we care about lower bounds and our constructions assume a discrete set, there is no loss of generality here. Regarding the algorithm’s output, in the setup of SCO there is also no loss of generality in assuming the output is discrete. Indeed, we can show that if there exists a continuous algorithm with sample complexity $m _ { 0 } ( \varepsilon )$ , and bounded mutual information over the sample, then there exists also a discrete algorithm with sample complexity $m ( \varepsilon ) = m _ { 0 } ( O ( \varepsilon ) )$ with even less mutual information.
106
+
107
+ To see that notice that, since we care about minimizing a Lipschitz loss function, given any accuracy $\varepsilon$ , we can take any finite $\varepsilon$ -approximation subset of the unit ball and simply project our output to this set. Namely, given output $w _ { S }$ , where $S > m ( \varepsilon )$ , we output $\bar { w } _ { S }$ , the nearest neighbour in the $\varepsilon$ -approximation sub set. Because $L _ { D }$ is $O ( 1 )$ Lipschitz, we have that
108
+
109
+ $$
110
+ \begin{array} { r } { | L _ { D } ( \bar { w } _ { S } ^ { A } ) - L _ { D } ( w ^ { \star } ) | \leq | L _ { D } ( \bar { w } _ { S } ^ { A } ) - L _ { D } ( w _ { S } ^ { A } ) | + | L _ { D } ( w _ { S } ^ { A } ) - L _ { D } ( w ^ { \star } ) | \leq O ( \varepsilon ) , } \end{array}
111
+ $$
112
+
113
+ hence up to a constant factor the algorithm has the same learning guarantees. On the other hand, due to data processing inequality:
114
+
115
+ $$
116
+ I ( \bar { w } _ { S } ^ { A } , S ) \leq I ( w _ { S } ^ { A } , S ) .
117
+ $$
118
+
119
+ # 2.1 Main Result
120
+
121
+ Eq. (2) provides a bound over the difference between the expected loss of the output parameter and the empirical loss. Without further constraints, it is not hard to construct an algorithm that carries little information on the sample. But, to obtain a bound over the excess risk of the parameter $w _ { S }$ , one is required not only to obtain a generalization error gap but also to non-trivially bound the empirical risk. The following result shows that requiring both has its limits:
122
+
123
+ Theorem 1. For every $0 < \varepsilon < 1 / 5 4$ and algorithm $A$ , with sample complexity $m ( \varepsilon )$ , there exists a distribution $D$ over a space $\mathcal { Z }$ , and loss function $f$ , 1-Lipschitz and convex in $w$ , such that, $i f$ $| S | \geq m ( \varepsilon )$ then:
124
+
125
+ $$
126
+ I ( w _ { S } ; S ) \geq \sum _ { i = 1 } ^ { m } I ( w _ { S } , z _ { i } ) = \tilde { \Omega } \left( \frac { d } { \varepsilon ^ { 5 } \cdot m ^ { 6 } ( \varepsilon ) } \right) .
127
+ $$
128
+
129
+ Theorem 1 accompanies the upper bound provided in Eq. (2) and shows that, while the generalization gap is bounded by the mutual information, the mutual information inversely scales with the optimality of the true risk. Taken together, for any algorithm with non-trivial learning guarantees, there is at least one scenario where it must carry a dimension-dependent amount of information on the sample or require a large sample. Indeed, either $m ( \varepsilon ) = \Omega ( \sqrt [ 6 ] { d / \varepsilon ^ { 5 } } )$ , (and then, trivially, the sample complexity of the algorithm scales with the dimension) or, via Eq. (3), we obtain dimension dependent mutual information, and in turn, Eq. (2) is non-vacuous only if the sample is larger than the dimension.
130
+
131
+ The first inequality is standard and follows from standard chain rule argument (see e.g. [Bu et al., 2020, proposition 2]). The second inequality lower bounds the information with the individual samples. Recently, Bu et al. [2020] obtained a refined bound that improves over $\mathrm { X u }$ and Raginsky [2017] by bounding the generalization with the information between the individual samples and output. Theorem 1, together with subadditivity of the square function, shows that the individual sample bound of Bu et al. [2020] can also become dimension dependent.
132
+
133
+ # 3 Discussion
134
+
135
+ Our main result shows a necessary condition on the mutual information between the model and empirical sample. Theorem 1 shows that for any algorithm with non-trivial learning guarantees, there is at least one scenario where it must carry a dimension-dependent amount of information on the sample or require a large sample. A natural question, then, is whether natural structural assumptions may circumvent the lower bound and allow to still maintain meaningful information theoretic bounds in slightly different setups. To initiate a discussion on this we begin by looking deeper into the concrete construction at hand in Theorem 1. We notice (see Section 4 and the supplementary material) that the construction we provided for Theorem 1 relies on a distribution $D$ that is always supported on functions of the form:
136
+
137
+ $$
138
+ f ( w , z ) = \| w - z \| ^ { 2 } = \| w \| ^ { 2 } - 2 w \cdot z + 1 , \quad z \in \{ - 1 / \sqrt { d } , 1 / \sqrt { d } \} ^ { d } .
139
+ $$
140
+
141
+ The constant 1 has no effect over the optimization, nor on the optimal solution, therefore we can treat $f$ as equivalent to the following function
142
+
143
+ $$
144
+ f \equiv \| w \| ^ { 2 } - 2 w \cdot z .
145
+ $$
146
+
147
+ The distribution over the element $z$ is also quite straightforward and involves only bias sampling of the coordinates. The function $f$ , then, is arguably the simplest non-linear convex function that one can think of and as we further discuss it holds most if not all of the niceties a function can hold that allow fast optimization – it is strongly convex, smooth, and in fact enjoys generalization bounds that can even be derived using standard uniform convergence tools. Indeed for any choice $w _ { S }$
148
+
149
+ $$
150
+ \begin{array} { r l r } { { \underset { S \sim D ^ { m } } { \mathbb { E } } L _ { D } ( w _ { S } ) - \frac { 1 } { m } \sum _ { i = 1 } ^ { m } f ( w _ { S } , z _ { i } ) = 2 \underset { S \sim D ^ { m } } { \mathbb { E } } \underset { \| w \| \leq 1 } { \operatorname* { s u p } } [ \frac { 1 } { m } \sum _ { i = 1 } ^ { m } w \cdot z _ { i } - \underset { z \sim D } { \mathbb { E } } [ w \cdot z ] ] } } \\ & { } & { \leq { \cal O } ( 1 / \sqrt { m } ) } \end{array}
151
+ $$
152
+
153
+ Where the last inequality follows from a standard Rademacher bound over the complexity of linear classifiers (see Shalev-Shwartz and Ben-David [2014]). In other words, while under further structural assumptions one might hope to obtain meaningful information theoretic bounds, it should be noted that such structural assumptions must exclude a highly simplistic class of functions that are in fact extremely easy to learn and even enjoy dimension independent uniform convergence bounds.
154
+
155
+ We now discuss further the niceties of this function class and the implications to refined algorithmic/distributional-dependent generalization bound via the information-theoretic bounds. We begin by analyzing algorithms that achieve the minimax rate.
156
+
157
+ Algorithmic-dependent generalization bounds As discussed, it is known that SGD Hazan et al. [2016], regularized-ERM Shalev-Shwartz et al. [2009], Bousquet and Elisseeff [2002], as well as stabilized versions of Gradient Descent Bassily et al. [2020] have the following minmax rate for learning $O ( 1 )$ -Lipscthiz convex functions over an $O ( 1 )$ -bounded domain:
158
+
159
+ $$
160
+ \mathbb { E } \left[ \Delta _ { D } \big ( w _ { S } \big ) \right] = O \big ( 1 / \sqrt { m } \big ) .
161
+ $$
162
+
163
+ Plugging the above in Eq. (3) we obtain that any such algorithm must carry at least √ $\Omega ( d / m ^ { 5 / 2 } )$ bits of information. which entails an information theoretic bound in Eq. (2) of $O ( \sqrt { d } / m ^ { 7 / 4 } )$ . This exceeds the true excess risk of such algorithms when $d \gg m$ and becomes a vacuous bound when we don’t assume the sample scales with the dimension (even though the algorithm perfectly learns in this setup). Now, we do not need Theorem 1 to obtain generalization gaps over these concrete algorithms, as a more direct approach would do. But, one might hope that by analyzing noisy versions of these algorithms, or some other forms of information-regularization, we could obtain some insight on the generalization of these algorithms. But, our lower bound applies to any algorithm with meaningful information-theoretic generalization bound. In particular, adding noise, for example, either makes the algorithm diverge or the noise is too small to delete enough information.
164
+
165
+ Distributional-dependent generalization bounds Next, we would like to discuss the implications to distributional assumptions. The above discussion shows that any trait of an algorithm that makes it optimal is not captured by the amount of information it holds on the data (in the setup of SCO). Distinct from SCO, in practice, many of the underlying problems can be cast into binary classification where it is known Blumer et al. [1989] that without further distributional assumptions learnability cannot be separated from uniform convergence as in SCO.
166
+
167
+ An interesting question, then, is if information theoretic generalization bounds can be used to obtain distribution-dependent bounds.
168
+
169
+ The function $f ( w , z )$ in Eq. (4) is known to be strongly-convex for every $z$ . Recall that a function $f$ is called 1-strongly convex if $\begin{array} { r l } { f - } & { { } \frac { 1 } { 2 } \| w \| ^ { 2 } } \end{array}$ is convex. It is known Shalev-Shwartz et al. [2009] that any ERM over a strongly convex will achieve suboptimality:
170
+
171
+ $$
172
+ \mathbb { E } [ \Delta _ { D } ( w _ { S } ) ] = O ( 1 / m ) .
173
+ $$
174
+
175
+ Moreover, the above result can be even strengthened to any approximate empirical risk minimizer, that is a minimizer with an additive $\Theta ( 1 / m ^ { 2 } )$ error over the empirical risk Shalev-Shwartz et al. [2009], Amir et al. [2021b]. But even further, for the particular structure of $f$ , which is a regularized linear objective, by [Sridharan et al., 2008, Thm 1] we have:
176
+
177
+ $$
178
+ \mathbb { E } [ \Delta _ { D } ( w _ { S } ) ] \preceq \tilde { O } ( \mathbb { E } [ \Delta _ { S } ( w _ { S } ) ] + 1 / m ) .
179
+ $$
180
+
181
+ Together with Theorem 1 we obtain the following algorithmic-independent result:
182
+
183
+ Theorem 2. There exists a family of distributions $\mathrm { \textmathcal { D } }$ , such that for any algorithm $A$ and $m > 3$ , there exists a distribution $D \in \mathcal { D }$ such that if $\Delta _ { S } ( w _ { S } ) \leq 1 / 5 4$ and $| S | > m$ then :
184
+
185
+ $$
186
+ I ( w _ { S } , S ) = \tilde { \Omega } \left( \frac { d } { m ^ { 6 } \cdot ( \mathbb { E } [ \Delta _ { S } ( w _ { S } ) ] + 1 ) ^ { 5 } } \right) ,
187
+ $$
188
+
189
+ but for any algorithm $A$ and distribution $D \in \mathcal { D }$
190
+
191
+ $$
192
+ \mathbb { E } [ \Delta _ { D } ( w _ { S } ) ] = \tilde { O } \left( \mathbb { E } [ \Delta _ { S } ( w _ { S } ) ] + 1 / m \right) .
193
+ $$
194
+
195
+ In other words, even without algorithmic assumptions, we can construct a class of distributions which make the problem easy to learn, but the information bounds are still dimension dependent. In
196
+
197
+ particular, for any algorithm such that $\Delta _ { S } ( w _ { S } ) = O ( 1 / m )$ we will have that the bound in Eq. (2) is order of:
198
+
199
+ $$
200
+ \mathbb { E } [ \Delta _ { D } ( w _ { S } ) ] = \tilde { \cal O } \left( \sqrt { d / m } \right) .
201
+ $$
202
+
203
+ Comparison to uniform convergence bounds: Notice that Eq. (5) is the standard generalization bound that can be obtained for any ERM algorithm in the setting of stochastic convex optimization. In detail, through a standard covering number argument (Shalev-Shwartz et al., 2009, thm 5) it is known that, when $f$ is 1-Lipschitz (not necessarily convex even):
204
+
205
+ $$
206
+ \operatorname* { s u p } _ { w \in \mathcal { W } } \mathbb { E } \left[ L _ { D } ( w ) - \frac { 1 } { m } \sum _ { i = 1 } ^ { m } f ( w , z _ { i } ) \right] \leq \tilde { O } ( \sqrt { d / m } ) .
207
+ $$
208
+
209
+ In other words, the bound we obtain in Eq. (5) can be obtained for any algorithm, with minimal assumptions, irrespective of the mutual information between output and sample. We remark, though, that, through a similar covering argument, one can show that indeed there are algorithms where one can recover the above bound via information-theoretic reasoning.
210
+
211
+ Proposition 1. Given a 1-Lipschitz function $f$ , there exists an algorithm ?? that given input sample ?? outputs a parameters $w _ { S } \in \mathcal { W }$ : such that
212
+
213
+ $$
214
+ \frac { 1 } { m } \sum _ { i = 1 } ^ { m } f ( w _ { S } , z _ { i } ) \leq \operatorname* { m i n } _ { w ^ { \star } \in \mathcal { W } } \frac { 1 } { m } \sum _ { i = 1 } ^ { m } f ( w ^ { \star } , z _ { i } ) + \sqrt { \frac { d } { m } } ,
215
+ $$
216
+
217
+ and
218
+
219
+ $$
220
+ I ( w _ { S } , S ) = \tilde { O } ( d \log m ) .
221
+ $$
222
+
223
+ In particular,
224
+
225
+ $$
226
+ L _ { D } ( w _ { S } ) - { \cal L } _ { D } ( w ^ { \star } ) = \tilde { \cal O } ( \sqrt { d / m } ) .
227
+ $$
228
+
229
+ Sketch. The result follows a simple covering argument. In particular, it is known that there exists a finite subset $\bar { \mathcal { W } } \subseteq \mathcal { W }$ of size $| \bar { \mathcal { W } } | = O \left( \sqrt { m } ^ { \bar { d } } \right)$ such that for every $w \in \mathcal { W }$ there is $\bar { w } \in \bar { \mathsf { W } }$ such that $\| w - \bar { w } \| \leq \sqrt { d / m }$ (e.g. Wu [2017]). Now. we consider an ERM that is restricted to the set $\bar { W }$ . By Lipschitness we have that Eq. (6) holds. The information is bounded by the entropy of the algorithm and we have that
230
+
231
+ $$
232
+ I ( W _ { S } , S ) \leq H ( W _ { S } ) \leq \log | \bar { \mathcal { W } } | = O ( d l o g m ) .
233
+ $$
234
+
235
+ The genearlization gap can be bounded via Eq. (2) (or standard union bound).
236
+
237
+ CMI-bounds Similarly to our setting, also in the setting of PAC learning, Livni and Moran [2020], Bassily et al. [2018] provided limitations to information theoretic generalization bounds. Specifically, they showed that such bounds become vacous in the task of learning thresholds, and the information between output and sample may be unbounded. To resolve this issue, which happens because of the numerical precision required by a thresholds learner, Steinke and Zakynthinou [2020] introduced generalization bounds that depend on conditional mutual information (CMI). They provided CMI bounds that can be derived from VC bounds, compression bounds etc... which in a nutshell means that they are powerful enough to achieve tight learning rates for VC classes such as thresholds. However, the issue in SCO is not comparable. As we show in Proposition 1 already the classical information-theoretic bounds are powerful enough to demonstrate generalization bounds that can be derived via union bound or uniform convergence. In PAC learning, these bounds are also tight, but in SCO such bounds are dimension-dependent. In that sense, there is no analog result to the limitation of learning thresholds. Partly because there is no need for infinite precision in SCO. In SCO, though, we require a separation from uniform convergence bounds, or even more strongly - from dimension dependent bounds. While Haghifam et al. [2020] does demonstrate certain algorithmic-dependent limitations for GD and perturbed GD algorithms, one might hope that, similar to PAC learning, here too CMI-bounds might be able to capture optimal dimension-independent rates for some algorithms.
238
+
239
+ More formally, given a distribution $D$ over $\mathcal { Z }$ , we consider a process where we draw i.i.d two random samples $Z = S _ { 1 } \times S _ { 2 }$ , where $S _ { 1 } = \{ z _ { 1 } ^ { 0 } , \ldots , z ^ { 0 } m \} \sim D ^ { m }$ and $S _ { 2 } = \{ z _ { 1 } ^ { 1 } , \ldots , z _ { m } ^ { 1 } \} \sim D ^ { m }$ . Then we define a sample $s$ by randomly picking $z _ { i } = z _ { i } ^ { 0 }$ w.p. $1 / 2$ and $z _ { i } = z _ { i } ^ { 1 }$ w.p. $1 / 2$ (independently from $z _ { 1 } , \dotsc , z _ { i - 1 } , z _ { i + 1 } , \dotsc , z _ { m } )$ . Then, Steinke and Zakynthinou [2020] showed that, similarly to Eq. (17), the generalization of an algorithm can be bounded in terms of
240
+
241
+ $$
242
+ \mathrm { g e n e r a l i z a t i o n } ( A ) = O \left( \sqrt { \mathrm { C M I } _ { m } ( A ) / m } \right) , \quad \mathrm { C M I } _ { m } ( A ) = I \left( w _ { S } , S \left| Z \right. \right) .
243
+ $$
244
+
245
+ Recall that, given a random variable $Z$ , the conditional mutual information between r.v. $X$ and r.v. $Y$ is defined as:
246
+
247
+ $$
248
+ I ( \boldsymbol { X } ; \boldsymbol { Y } | Z ) = \underset { Z } { \mathbb { E } } [ \underset { \boldsymbol { Y } } { \mathbb { E } } [ D _ { K L } ( P _ { \boldsymbol { X } | Z } | | P _ { \boldsymbol { X } | \boldsymbol { Y } , Z } ) ] ] .
249
+ $$
250
+
251
+ One can show that $\mathbf { C M I } _ { m } ( A ) = O ( m )$ . The simplest way to achieve a dimension independent generalization bound would be to subsample. If algorithm $A$ observes a sample $s$ of size $m$ and subsamples $f ( m )$ samples, then we trivially obtain the generalization gap: $O ( 1 / { \sqrt { f ( m ) } }$ . Taking Eq. (7) into consideration by subsampling √ $O ( { \sqrt { m } } )$ examples, Eq. (7) will lead to a dimension independent generalization bound of $O ( 1 / \sqrt [ 4 ] { m } )$ . So it is possible to obtain dimension independent bounds through the CMI framework, nevertheless it is stll not clear if we can beat the above, nonoptimal and naive subsampling bound
252
+
253
+ Open Problem. Is there an algorithm ?? in the SCO setup that can achieve
254
+
255
+ $$
256
+ C M I _ { m } ( A ) = \widetilde { \sigma } ( \sqrt { m } ) ,
257
+ $$
258
+
259
+ as well as
260
+
261
+ $$
262
+ \mathbb { E } \left[ \Delta _ { D } ( A ) \right] = O ( 1 / { \sqrt { m } } ) .
263
+ $$
264
+
265
+ # 4 Technical overview
266
+
267
+ We next outline the key technical tools and ideas that lead to the proof of Theorem 1. A full proof of Theorem 1 is provided in the supplementary material. As discussed we draw our idea from the privacy literature Steinke and Ullman [2015], Kamath et al. [2019], Bun et al. [2014] and build on fingerprinting Lemmas Boneh and Shaw [1998], Tardos [2008] to construct our “information attacks". We employ a simplified and well-tailored version of the fingerprinting Lemma, due to Kamath et al. [2019], to construct a lower bound on the correlation between the output and the data. From that point our proof differ from standard privacy attacks.
268
+
269
+ Given the above correlation bound, we now want to lower bound the mutual information between the two correlated random variables (i.e. the output of the algorithm and the empirical mean). Surprisingly, we could not find in the literature an existing lower bound on the mutual information between two correlated random variables. The next Lemma provides such a lower bound and as such may be of independent interest.. We next depict these two technical Lemmas that we need for our proof – the fingerprinting Lemma due to Kamath et al. [2019] and a lower bound on the mutual information between two correlated random variables.
270
+
271
+ For describing the fingerprinting Lemma, let us denote by $U [ - 1 / 3 , 1 / 3 ]$ the uniform distribution over the interval $[ - 1 / 3 , 1 / 3 ]$ , and given $p \in [ - 1 / 3 , 1 / 3 ]$ , we denote by $Z _ { 1 : m } \sim U _ { m } ( p )$ a random process where we draw $m$ i.i.d random variables $Z _ { 1 } , \ldots , Z _ { m }$ where $Z \in \{ \pm 1 \}$ and $\mathbb { E } [ Z ] = p$ :
272
+
273
+ Lemma 1 (Fingerprinting Lemma (Kamath et al. [2019])). For every $f : \{ \pm 1 \} ^ { m } [ - { \textstyle \frac { 1 } { 3 } } , { \textstyle \frac { 1 } { 3 } } ] ,$ , we have:
274
+
275
+ $$
276
+ \underset { P \sim U [ - 1 / 3 , 1 / 3 ] } { \mathbb { E } } \underset { Z _ { 1 : m } \sim U _ { m } ( P ) } { \mathbb { E } } \left[ \frac { 1 - 9 P ^ { 2 } } { 9 - 9 P ^ { 2 } } \cdot ( \hat { f } ( Z _ { 1 : m } ) - P ) \cdot \sum _ { i = 1 } ^ { m } ( Z _ { i } - P ) + ( \hat { f } ( Z _ { 1 : m } ) - P ) ^ { 2 } \right] \geq \frac { 1 } { 2 7 }
277
+ $$
278
+
279
+ The above theorem shows that if a random variable $\hat { f } ( Z _ { 1 : m } )$ uses the sample to non-trivially estimate the random variable $P$ , then the output must correlate with the empirical mean. Notice that, in particular, it means that $\hat { f } ( Z _ { 1 : m } )$ is not independent of $Z _ { 1 : m }$ and certain information exists. Our next Lemma quantifies this statement and, as far the author knows, is novel. The proof is provided in the supplementary material
280
+
281
+ Lemma 2. Let $X$ and $Y$ be two random variables such that $X$ is bounded by 1 $, \ \mathbb { E } ( X ) = 0$ and $\mathbb { E } ( Y ^ { 2 } ) \le 1 .$ . $\begin{array} { r } { { I f } \mathbb { E } [ X Y ] = \beta } \end{array}$ then:
282
+
283
+ $$
284
+ { \sqrt { I ( X , Y ) } } \geq { \frac { \beta ^ { 2 } } { 2 { \sqrt { 2 } } } } .
285
+ $$
286
+
287
+ The proof of Lemma 2 is provided in the supplementary material
288
+
289
+ With Lemmas 1 and 2 at hand, the proof idea is quite straightforward. For every $z \in \{ - 1 / \sqrt { d } , 1 / \sqrt { d } \} ^ { d }$ we define the following loss function:
290
+
291
+ $$
292
+ f ( w , z ) = \sum _ { t = 1 } ^ { d } ( w ( t ) - z ( t ) ) ^ { 2 } = \| w - z \| ^ { 2 } .
293
+ $$
294
+
295
+ For every distribution $D$ , one can show that the minimizer $w ^ { \star } = \arg \operatorname* { m i n } L _ { D } ( w )$ is provided by $w = \mathbb { E } [ z ]$ . By a standard decomposition we can show:
296
+
297
+ $$
298
+ \begin{array} { r l } & { L _ { D } ( w _ { S } ) - L _ { D } ( w ^ { \star } ) = { \mathbb { E } } \left[ \| w _ { S } + ( w ^ { \star } - z ) - w ^ { \star } \| ^ { 2 } - \| w ^ { \star } - z \| ^ { 2 } \right] } \\ & { \qquad = { \mathbb { E } } \left[ \| w _ { S } - w ^ { \star } \| ^ { 2 } + 2 ( w _ { S } - w ^ { \star } ) \cdot ( w ^ { \star } - z ) + \| w ^ { \star } - z \| ^ { 2 } - \| w ^ { \star } - z \| ^ { 2 } \right] } \\ & { \qquad = { \mathbb { E } } \left[ \| w _ { S } - w ^ { \star } \| ^ { 2 } \right] + 2 { \mathbb { E } } \left[ ( w _ { S } - w ^ { \star } ) \cdot ( { \mathbb { E } } [ z ] - z ) \right] } \\ & { \qquad = { \mathbb { E } } \left[ \| w _ { S } - w ^ { \star } \| ^ { 2 } \right] } \end{array}
299
+ $$
300
+
301
+ Now, for simplicity of this overview we only consider the case that $\Delta ( w _ { S } ) = \Omega ( 1 )$ is some non-trivial constant, for example we may assume that $\Delta ( w _ { S } ) < 1 / 5 4$ and let us show that for every coordinate, $t$ the mutual information between $w _ { S } ( t )$ and $\sum z _ { i } ( t )$ is order of $\Omega ( 1 / m ^ { 2 } )$ . Then by standard chain rule, and proper derivations the end result can be obtained.
302
+
303
+ Indeed, one can observe that if $\Delta ( w _ { S } ) < 1 / 5 4$ , and since $\boldsymbol { w } ^ { \star } = \mathbb { E } [ \boldsymbol { z } ] = \boldsymbol { P }$ we have that $\mathbb { E } ( ( \sqrt { d } w _ { S } ( t ) -$ $P ( t ) ) ^ { 2 } ) \leq 1 / 5 4$ . In turn, we can use Lemma 1, and show that in expectation over $P$ we also have:
304
+
305
+ $$
306
+ \mathbb { E } \left[ \left( \sqrt { d } w _ { S } ( t ) - P \right) \cdot \left( \sum _ { i = 1 } ^ { m } \left( \sqrt { d } z _ { i } ( t ) - P \right) \right) \right] = \Omega ( 1 ) .
307
+ $$
308
+
309
+ We now use Lemma 2, and convexity, to lower bound the individual sume of the mutual information, $\textstyle \sum _ { i = 1 } ^ { m } I ( w _ { s } ( t ) ; z _ { i } ( t ) | P )$ . By standard technique we conclude that there exists $P$ for which the mutual
310
+
311
+ The above outline does not provide a bound that scales with the accuracy of $\Delta ( w _ { S } )$ , and we need to be more careful in our analysis for the full derivation. The detailed proof is provided in the supplementary material.
312
+
313
+ Ackgnoweledgments The author would like to thank the anonymous reviewers that suggested to incorporate the lower bound for the individual mutual information term. This turned out to simplify some of the proofs. The author would like to thank Shay Moran, and the research was funded in part by the ERC grant (GENERALIZATION, 10139692), as well as an ISF Grant $( 2 1 8 8 \setminus 2 0 )$ . Views and opinions expressed are however those of the author(s) only and do not necessarily reflect those of the European Union or the European Research Council Executive Agency. Neither the European Union nor the granting authority can be held responsible for them. The author is a recipient of a Google research scholar award and would like to acknowledge his thanks.
314
+
315
+ # References
316
+
317
+ D. Aldous. Random walks on finite groups and rapidly mixing markov chains. In Séminaire de Probabilités XVII 1981/82, pages 243–297. Springer, 1983.
318
+
319
+ N. Alon, S. Ben-David, N. Cesa-Bianchi, and D. Haussler. Scale-sensitive dimensions, uniform convergence, and learnability. Journal of the ACM (JACM), 44(4):615–631, 1997.
320
+
321
+ G. Aminian, Y. Bu, L. Toni, M. Rodrigues, and G. Wornell. An exact characterization of the generalization error for the gibbs algorithm. Advances in Neural Information Processing Systems, 34:8106–8118, 2021.
322
+
323
+ I. Amir, Y. Carmon, T. Koren, and R. Livni. Never go full batch (in stochastic convex optimization). Advances in Neural Information Processing Systems, 34:25033–25043, 2021a.
324
+ I. Amir, T. Koren, and R. Livni. Sgd generalizes better than gd (and regularization doesn’t help). In Conference on Learning Theory, pages 63–92. PMLR, 2021b.
325
+ R. Bassily, S. Moran, I. Nachum, J. Shafer, and A. Yehudayoff. Learners that use little information. In Algorithmic Learning Theory, pages 25–55. PMLR, 2018.
326
+ R. Bassily, V. Feldman, C. Guzmán, and K. Talwar. Stability of stochastic gradient descent on nonsmooth convex losses. Advances in Neural Information Processing Systems, 33:4381–4391, 2020.
327
+ A. Blumer, A. Ehrenfeucht, D. Haussler, and M. K. Warmuth. Learnability and the vapnik-chervonenkis dimension. Journal of the ACM (JACM), 36(4):929–965, 1989.
328
+ D. Boneh and J. Shaw. Collusion-secure fingerprinting for digital data. IEEE Transactions on Information Theory, 44(5):1897–1905, 1998.
329
+ O. Bousquet and A. Elisseeff. Stability and generalization. The Journal of Machine Learning Research, 2:499–526, 2002.
330
+ Y. Bu, S. Zou, and V. V. Veeravalli. Tightening mutual information-based bounds on generalization error. IEEE Journal on Selected Areas in Information Theory, 1(1):121–130, 2020.
331
+ M. Bun, J. Ullman, and S. Vadhan. Fingerprinting codes and the price of approximate differential privacy. In Proceedings of the forty-sixth annual ACM symposium on Theory of computing, pages 1–10, 2014.
332
+ M. Bun, R. Livni, and S. Moran. An equivalence between private classification and online prediction. In 2020 IEEE 61st Annual Symposium on Foundations of Computer Science (FOCS), pages 389–402. IEEE, 2020.
333
+ N. Carlini, F. Tramer, E. Wallace, M. Jagielski, A. Herbert-Voss, K. Lee, A. Roberts, T. Brown, D. Song, U. Erlingsson, et al. Extracting training data from large language models. In 30th USENIX Security Symposium (USENIX Security 21), pages 2633–2650, 2021.
334
+ J. Duchi. Lecture notes for statistics 311/electrical engineering 377. URL: https://stanford. edu/class/stats311/Lectures/full notes. pdf. Last visited on, 2:23, 2016.
335
+ V. Feldman. Generalization of erm in stochastic convex optimization: The dimension strikes back. Advances in Neural Information Processing Systems, 29, 2016.
336
+ V. Feldman. Does learning require memorization? a short tale about a long tail. In Proceedings of the 52nd Annual ACM SIGACT Symposium on Theory of Computing, pages 954–959, 2020.
337
+ M. Haghifam, J. Negrea, A. Khisti, D. M. Roy, and G. K. Dziugaite. Sharpened generalization bounds based on conditional mutual information and an application to noisy, iterative algorithms. Advances in Neural Information Processing Systems, 33:9925–9935, 2020.
338
+ M. Haghifam, B. Rodríguez-Gálvez, R. Thobaben, M. Skoglund, D. M. Roy, and G. K. Dziugaite. Limitations of information-theoretic generalization bounds for gradient descent methods in stochastic convex optimization. arXiv preprint arXiv:2212.13556, 2022.
339
+ E. Hazan et al. Introduction to online convex optimization. Foundations and Trends® in Optimization, 2(3-4):157–325, 2016.
340
+ G. Kamath, J. Li, V. Singhal, and J. Ullman. Privately learning high-dimensional distributions. In Conference on Learning Theory, pages 1853–1902. PMLR, 2019.
341
+ J. Langford and J. Shawe-Taylor. Pac-bayes & margins. Advances in neural information processing systems, 15, 2002.
342
+ R. Livni and S. Moran. A limitation of the pac-bayes framework. Advances in Neural Information Processing Systems, 33:20543–20553, 2020.
343
+ D. A. McAllester. Some pac-bayesian theorems. In Proceedings of the eleventh annual conference on Computational learning theory, pages 230–234, 1998.
344
+ D. A. McAllester. Pac-bayesian model averaging. In Proceedings of the twelfth annual conference on Computational learning theory, pages 164–170, 1999.
345
+ J. Negrea, M. Haghifam, G. K. Dziugaite, A. Khisti, and D. M. Roy. Information-theoretic generalization bounds for sgld via data-dependent estimates. Advances in Neural Information Processing Systems, 32, 2019.
346
+ G. Neu, G. K. Dziugaite, M. Haghifam, and D. M. Roy. Information-theoretic generalization bounds for stochastic gradient descent. In Conference on Learning Theory, pages 3526–3545. PMLR, 2021.
347
+ B. Neyshabur, R. Tomioka, and N. Srebro. In search of the real inductive bias: On the role of implicit regularization in deep learning. arXiv preprint arXiv:1412.6614, 2014.
348
+ R. Paley and A. Zygmund. A note on analytic functions in the unit circle. In Mathematical Proceedings of the Cambridge Philosophical Society, volume 28, pages 266–272. Cambridge University Press, 1932.
349
+ A. Pensia, V. Jog, and P.-L. Loh. Generalization error bounds for noisy, iterative algorithms. In 2018 IEEE International Symposium on Information Theory (ISIT), pages 546–550. IEEE, 2018.
350
+ A. Pradeep, I. Nachum, and M. Gastpar. Finite littlestone dimension implies finite information complexity. In 2022 IEEE International Symposium on Information Theory (ISIT), pages 3055–3060. IEEE, 2022.
351
+ B. Rodríguez-Gálvez, G. Bassi, R. Thobaben, and M. Skoglund. On random subset generalization error bounds and the stochastic gradient langevin dynamics algorithm. In 2020 IEEE Information Theory Workshop (ITW), pages 1–5. IEEE, 2021.
352
+ D. Russo and J. Zou. How much does your data exploration overfit? controlling bias via information usage. IEEE Transactions on Information Theory, 66(1):302–323, 2019.
353
+ R. E. Schapire. The strength of weak learnability. Machine learning, 5(2):197–227, 1990.
354
+ S. Shalev-Shwartz and S. Ben-David. Understanding machine learning: From theory to algorithms. Cambridge university press, 2014.
355
+ S. Shalev-Shwartz, O. Shamir, N. Srebro, and K. Sridharan. Stochastic convex optimization. In COLT, volume 2, page 5, 2009.
356
+ K. Sridharan, S. Shalev-Shwartz, and N. Srebro. Fast rates for regularized objectives. Advances in neural information processing systems, 21, 2008.
357
+ T. Steinke and J. Ullman. Interactive fingerprinting codes and the hardness of preventing false discovery. In Conference on learning theory, pages 1588–1628. PMLR, 2015.
358
+ T. Steinke and L. Zakynthinou. Reasoning about generalization via conditional mutual information. In Conference on Learning Theory, pages 3437–3452. PMLR, 2020.
359
+ G. Tardos. Optimal probabilistic fingerprint codes. Journal of the ACM (JACM), 55(2):1–24, 2008.
360
+ L. G. Valiant. A theory of the learnable. Communications of the ACM, 27(11):1134–1142, 1984.
361
+ V. N. Vapnik and A. Y. Chervonenkis. On the uniform convergence of relative frequencies of events to their probabilities. In Measures of complexity, pages 11–30. Springer, 2015.
362
+ Y. Wu. Lecture notes on information-theoretic methods for high-dimensional statistics. Lecture Notes for ECE598YW (UIUC), 16, 2017.
363
+ A. Xu and M. Raginsky. Information-theoretic analysis of generalization capability of learning algorithms. Advances in Neural Information Processing Systems, 30, 2017.
364
+
365
+ C. Zhang, S. Bengio, M. Hardt, B. Recht, and O. Vinyals. Understanding deep learning (still) requires rethinking generalization. Communications of the ACM, 64(3):107–115, 2021. R. Zhou, C. Tian, and T. Liu. Individually conditional individual mutual information bound on generalization error. IEEE Transactions on Information Theory, 68(5):3304–3316, 2022.
md/dev/FELWgMjxZJj/FELWgMjxZJj.md ADDED
@@ -0,0 +1,270 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # OPEN-VOCABULARY SEMANTIC SEGMENTATION WITH MASK-ADAPTED CLIP
2
+
3
+ Anonymous authors Paper under double-blind review
4
+
5
+ # ABSTRACT
6
+
7
+ Open-vocabulary semantic segmentation aims to segment an image into semantic regions according to text descriptions, which may not have been seen during training. Recent two-stage methods first generate class-agnostic mask proposals and then leverage pre-trained vision-language models, e.g., CLIP, to classify masked regions. We identify the performance bottleneck of this paradigm to be the pre-trained CLIP model, since it does not perform well on masked images. To address this, we propose to finetune CLIP on a collection of masked image regions and their corresponding text descriptions. We collect training data by mining an existing image-caption dataset (e.g., COCO Captions), using CLIP to match masked image regions to nouns in the image captions. Compared with the more precise and manually annotated segmentation labels with fixed classes (e.g., COCO-Stuff), we find our noisy but diverse dataset can better retain CLIP’s generalization ability. Along with finetuning the entire model, we utilize the “blank” areas in masked images using a method we dub mask prompt tuning. Experiments demonstrate mask prompt tuning brings significant improvement without modifying any weights of CLIP, and it can further improve a fully finetuned model. In particular, when trained on COCO and evaluated on ADE20K-150, our best model achieves $2 9 . 6 \%$ mIoU, which is $+ 8 . 5 \%$ higher than the previous state-of-the-art. For the first time, open-vocabulary generalist models match the performance of supervised specialist models in 2017 without dataset specific adaptations.
8
+
9
+ # 1 INTRODUCTION
10
+
11
+ Semantic segmentation aims to group pixels into meaningful regions with corresponding semantic categories. Although remarkable progress has been made (Long et al., 2015; Chen et al., 2017; 2018; Zhao et al., 2017; Cheng et al., 2021), modern semantic segmentation models are mainly trained with pre-defined categories, failing to generalize to unseen classes. On the contrary, humans understand scenes in an open-vocabulary manner, typically with thousands of categories (Biederman, 1987). To approach human-level perception, this paper studies open-vocabulary semantic segmentation where the model segments an image by arbitrary categories described by texts.
12
+
13
+ Vision-language models, e.g., CLIP (Radford et al., 2021), learn rich multi-modal features from billion-scale image-text pairs. Witnessing its superior open-vocabulary classification ability, prior works propose to use pre-trained vision-language models for open-vocabulary segmentation (Li et al., 2022; Xu et al., 2021; Ding et al., 2022; Ghiasi et al., 2021). Among them, two-stage approaches have shown great potential: they first generate class-agnostic mask proposals and then leverage pre-trained CLIP to perform open-vocabulary classification (see Figure 1(b)). Their success relies on two assumptions: (1) the model can generate class-agnostic mask proposals (2) pre-trained CLIP can transfer its classification performance to masked image proposals.
14
+
15
+ To examine these two assumptions, we conduct the following analysis. First, we assume an “oracle” mask generator and an ordinary CLIP classifier. We use ground-truth masks as region proposals, and feed masked images to a pre-trained CLIP for classification. This model only reaches an mIoU of $2 0 . 1 \%$ on the ADE20K-150 dataset. Next, we assume an “oracle” classifier but an ordinary mask proposal generator – a MaskFormer (Cheng et al. (2021)) pre-trained on the COCO dataset. We first extract masked region proposals, then compare each region with ground-truth object masks, find the object with the highest overlap, and assign the object label to this extracted region. This model, despite imperfect region proposals, reaches a significantly higher mIoU of $6 6 . 5 \%$ .
16
+
17
+ ![](images/4dbc502b48b3c12c7d6f43c0302de369b5be7ca5cde8c785213170dd1b35a746.jpg)
18
+ Figure 1: (a) CLIP is pre-trained with natural images with little data augmentation. (b) Two-stage open-vocabulary semantic segmentation approaches first generate class-agnostic mask proposals and then leverage pre-trained CLIP to do open-vocabulary classification. The input of the CLIP model is cropped masked images, which have huge domain gap from the natural images. (c) Our analysis reveals that pre-trained CLIP does not work well on masked images.
19
+
20
+ This analysis clearly shows that pre-trained CLIP can not perform satisfactory classification over masked images, and it is the performance bottleneck of two-stage open-vocabulary segmentation models. We hypothesize that this is caused by the significant domain gap between masked images and CLIP’s training images. CLIP is pre-trained on natural images with minimal data augmentation (Radford et al., 2021). On the other hand, mask proposals are cropped and re-sized from original images, and are further corrupted by noisy segmentation masks, see examples in Figure 1 (b).
21
+
22
+ To address this, we propose to adapt CLIP by finetuning it on masked images and corresponding text labels. One direct solution is to use segmentation labels, e.g., from the COCO-stuff dataset. However, this leads to bad generalization to unseen classes (Section 4.3.1). Such manually annotated masks are accurate but classes are limited to a closed set (e.g., 171 classes for COCO-stuff). We hypothesize that the lack of text diversity causes the finetuned CLIP to lose the generalization ability to open vocabulary concepts. Instead, we collect training data by mining an existing image-caption dataset (e.g., COCO Captions). Given an image-caption pair, we first extract nouns in the caption, and generate class-agnostic masked region proposals using a pre-trained segmentation model. Then, with a pre-trained CLIP model, we assign the best-matching proposal to each extracted noun. By learning from this weakly-supervised alignments between masked images and novel categories, the adapted CLIP better retains its generalization ability for open vocabulary classification.
23
+
24
+ The next question is how to effectively finetune CLIP? The most notable difference between a masked image and a natural image is that background pixels in a masked image are masked out, leading to many blank areas, which will be converted to “zero tokens” when feeding to CLIP transformers. Such tokens not only contain no useful information, but also bring domain distribution shift to the model (since such tokens don’t exist in natural images) and cause performance degradation. To mitigate this, we propose mask prompt tuning, a la visual prompt tuning (Jia et al., 2022). ´ When tokenizing a masked image, we replace the “zero tokens” with learnable prompt tokens. During finetuning, we either train prompts only and freeze CLIP’s weights, or train both of them. We find that mask prompt tuning alone significantly improves CLIP’s performance on masked images. This is a crucial property for multi-task scenarios where we cannot change CLIP’s weight since it is shared with other tasks. When combined with full model finetuning, mask prompt tuning can further improve the performance by a non-trivial margin (see Section 4.3.2).
25
+
26
+ In our experiments, we measure the open-vocabulary segmentation performances on holdout segmentation datasets in a “zero-shot” manner – we do not adapt the model for each evaluation dataset. We train our model using COCO-stuff (Caesar et al., 2018) dataset with captions from Chen et al. (2015), and test on challenging ADE20K (A-150, A-847 for 150/846 categories) (Zhou et al., 2019), Pascal Context (PC-59, PC-459 for 59/459 categories) (Mottaghi et al., 2014) and PASCAL VOC (PAS-20) (Everingham et al., 2010). Our best model achieves $2 9 . 6 \%$ mIoU on A-150, which is $+ 8 . 5 \%$ than the state-of-the-art OpenSeg (Ghiasi et al., 2021) under the same setting. On more challenging A-847 and PC-459, our model sets up a new state-of-the-art of $9 . 0 \%$ , $1 2 . 4 \%$ mIoU, surpassing the previous best solution by $+ 2 . 7 \%$ and $3 . 4 \%$ . Moreover, for the first time, we show openvocabulary generalist models can match the performance of supervised specialist models (Long et al., 2015; Chen et al., 2017; Zoph et al., 2020) without dataset specific adaptations.
27
+
28
+ In summary our contributions include: (1) Our analysis reveals the pre-trained CLIP does not perform well on mask proposals, making it the performance bottleneck of two-stage approaches. (2) We collect diverse mask-category pairs from captions to adapt CLIP for masked images and retain its generalization ability. (3) We propose mask prompt tuning specifically for masked image adaptation. This method does not change CLIP’s weight, enabling multi-task weight sharing. (4) For the first time, we show open-vocabulary generalist models can match the performance of supervised specialist models without dataset specific adaptations.
29
+
30
+ # 2 RELATED WORK
31
+
32
+ Pre-trained vision-language models (Radford et al., 2021; Jia et al., 2021; Li et al., 2021) connect the visual concepts with textual description. Pre-trained CLIP (Radford et al., 2021) has strong openvocabulary classification ability, i.e., classifying an image with arbitrary categories described by language. Pre-trained CLIP has empowered many computer vision tasks with the language ability, such as image manipulation (Patashnik et al., 2021), image generation (Crowson et al., 2022), object detection (Gu et al., 2021; Zhong et al., 2022) and image segmentation (Li et al., 2022; Xu et al., 2021; Ding et al., 2022; Ghiasi et al., 2021). Our work is similar with RegionCLIP (Zhong et al., 2022), which adapts CLIP for object detection by finetuning on region proposals. Our method differs from RegionCLIP since (1) we adapt CLIP to process masked images wile RegionCLIP process complete region crops; (2) We leverage blank areas in masked images and propose mask prompt tuning, which adapts CLIP without changing its weights. This enables sharing CLIP’s weight with other tasks in multi-task scenarios. This is not supported by RegionCLIP.
33
+
34
+ Open-vocabulary segmentation aims to understand an image with arbitrary categories described by texts. Pioneering work ZS3Net (Bucher et al., 2019) uses generative models to synthesize pixellevel features by word embeddings of unseen class. SPNet (Xian et al., 2019) utilizes the word embeddings, e.g., word2vec (Mikolov et al., 2013), to align the semantic meaning with visual features. More recently, researchers propose to leverage the pre-trained CLIP (Radford et al., 2021) for open-vocabulary semantic segmentation. LSeg (Li et al., 2022) aligns pixel embeddings to the text embedding of the corresponding semantic class, which is generated by CLIP’s text encoder. Unlike pixel-level LSeg, OpenSeg (Ghiasi et al., 2021) proposes to align the segment-level visual features with text embedding via region-word grounding. Our approach falls into the category of two-stage approaches, such as ZSSeg (Xu et al., 2021) and ZegFormer (Ding et al., 2022): they first generate class-agnostic mask proposals and then utilize pre-trained CLIP to perform open-vocabulary classification. Unlike ZSSeg and ZegFormer which directly use the original CLIP for masked image classification, we propose to adapt CLIP to achieve better results.
35
+
36
+ Prompt tuning is a strategy to adapt large-scale pre-trained models to new tasks. The idea originated from natural language processing (Liu et al., 2021a; Li & Liang, 2021; Lester et al., 2021), and recent work extends prompt tuning to computer vision. CoOp (Zhou et al., 2022) pre-appends the category words with learnable vectors to adapt CLIP for many recognition tasks. The textual prompt tuning is also widely used in open-vocabulary object detection (Du et al., 2022) and semantic segmentation $\mathrm { X u }$ et al. (2021). Our mask prompt tuning is more relevant to prompt tuning in the visual domain (Bahng et al., 2022; Jia et al., 2022) where learnable vectors are applied to the image domain. Unlike visual prompt tuning (Jia et al., 2022) that inserts additional tokens before the actual image tokens, we replace masked tokens with learnable prompts. Furthermore, mask prompt tuning brings additional improvement over a fully finetuned model (Section 4.3.2). Such additional improvements have not been reported by prior work.
37
+
38
+ # 3 METHOD
39
+
40
+ In this section, we first revisit the two-stage open-vocabulary segmentation methods (Xu et al., 2021;
41
+ Ding et al., 2022). Then we discuss how to obtain a dataset of mask-category pairs to finetune CLIP.
42
+ Last, we discuss the proposed mask prompt tuning technique to adapt CLIP for masked images.
43
+
44
+ ![](images/902e1db0e01f8c692bcbdff40193c4d268f6bcfba7b6dc25c7dc80e9059a5f34.jpg)
45
+ Figure 2: Two-stage approaches consist of one segmentation model, e.g., MaskFormer, and one CLIP model. Firstly, the modified MaskFormer is trained with CLIP’s text embeddings so as to perform open-vocabulary segmentation. (Section 3.1). We then use the pre-trained segmentation model to generate class-agnostic proposals and align proposals with extracted nouns from corresponding captions (Section 3.2). After collecting diverse mask-category pairs, we finetune CLIP with the proposed mask prompt tuning (Section 3.3).
46
+
47
+ # 3.1 TWO-STAGE MODELS FOR OPEN-VOCABULARY SEMANTIC SEGMENTATION
48
+
49
+ Our two-stage open-vocabulary semantic segmentation model is shown in Figure 2. It consists of a segmentation model that generates mask proposals, and an open vocabulary classification model.
50
+
51
+ Following Xu et al. (2021); Ding et al. (2022), we choose MaskFormer (Cheng et al., 2021) as the segmentation model. Unlike per-pixel segmentation models (Long et al., 2015; Chen et al., 2017), MaskFormer predicts a set of $N$ mask proposals and corresponding class predictions. Each proposal is represented by an $H \times W$ binary mask, indicating the location of the target object. The class prediction is a $C$ -dimensional distribution, where $C$ is the number of classes in the training set. Following (Xu et al., 2021), we modify MaskFormer such that for each mask, it generates a $C$ -dimensional proposal embedding, where $C$ is the embedding dimension of a CLIP model (512 for ViT-B/16 and 768 for ViT-L/14). This change allows MaskFormer to perform open-vocabulary segmentation. Specifically, suppose we would like to classify the mask to $K$ categories, we can first use a CLIP model’s text encoder to generate $\mathrm { K }$ text embeddings for each class as $\{ t _ { k } | t _ { k } \in$ $ \mathbf { R } ^ { C } \} _ { k = 1 , \cdots , K }$ . Next, we compare each mask embedding $v _ { i }$ with the text embedding, and predict the class- $k$ probability as $\begin{array} { r } { p _ { i , k } = \exp ( \sigma ( v _ { i } , t _ { k } ) / \tau ) / \sum _ { k } ( \exp ( \sigma ( v _ { i } , t _ { k } ) / \tau ) ) } \end{array}$ . Here $\sigma ( \cdot , \cdot )$ denotes the cosine similarity between two embedding vectors, and $\tau$ is the temperature coefficient (Radford et al., 2021). We train the modified MaskFormer on the COCO-Stuff dataset (Caesar et al., 2018) with 171 classes. We use CLIP’s text encoder to process class names to generate text embeddings. We also append a learnable embedding $\varnothing$ to represent the category of “no object”. For other training settings, we follow the original MaskFormer (Cheng et al., 2021).
52
+
53
+ Note that the mask proposal generator trained this way is not strictly “class-agnostic”, as the definition of an object is determined by the class definitions in the training set. For example, if the training set only contains ”person” as a class, it is not likely the model will automatically segment a person into “face”, “hand”, “body”, or finer body parts. How to train a general and class agnostic model to generate mask proposals is an important topic but is beyond the scope of this paper.
54
+
55
+ In addition to MaskFormer’s prediction, following (Ding et al., 2022; Xu et al., 2021), we add a parallel prediction branch using CLIP. MaskFormer generates mask proposals $\{ M _ { i } | M _ { i } \ \in$ $\{ 0 , 1 \} ^ { \dot { H } \times W } \} _ { i = 1 , \cdots , N }$ where 1 and 0 denotes foreground and background. For each mask, we select a tight bounding box that includes all foreground pixels, crop the image, mask out backgrounds, and re-size to CLIP’s resolution. We feed mask proposal- $i$ to CLIP and compute class- $k$ probability as $\hat { p } _ { i , k }$ . We ensemble both predictions to compute final prediction as $p _ { i , k } ^ { ( 1 - \bar { \lambda } ) } * \hat { p } _ { i , k } ^ { \lambda }$ where $\lambda \in [ 0 , 1 ]$ . We fuse mask-wise predictions to semantic segmentation using MaskFormer’s fusion module.
56
+
57
+ As discussed in Section 1 and Figure 1 (c), our analysis show that CLIP does not work well on such masked images. Specifically, CLIP is trained on natural images with little data augmentation (Radford et al., 2021). However, masked images as shown in Figure 1 (b) contain a lot of “blank regions”. Such a significant domain gap makes it difficult for CLIP to transfer its classification performance. We also tried cropping the proposals without masking out background pixels. However, we observe worse performance (see Appendix A.1). We conjecture that keeping background pixels makes it more confusing for CLIP to correctly classify the foreground.
58
+
59
+ # 3.2 COLLECTING DIVERSE MASK-CATEGORY PAIRS FROM CAPTIONS
60
+
61
+ To adapt CLIP to better process masked images, we propose to finetune CLIP on a dataset consists of masked image and text pairs. One direct solution is to leverage manually annotated segmentation labels, e.g., from COCO-Stuff. Such labels are accurate, but have a closed set of categories. We try this solution and collect 965K mask-category pairs spanning 171 classes (e.g., banana, orange) from COCO-Stuff. Then we finetune the CLIP’s image encoder, while freezing the text encoder, following Zhong et al. (2022). However, we observe that this naive approach limits the generalization ability of CLIP, as the performance drops if there are more unseen classes (see Section 4.3.1). We hypothesize that due to the limited text vocabulary, the finetuned CLIP over-fits to the 171 classes, losing the ability to generalize to unseen categories.
62
+
63
+ Compared with segmentation labels, image captions contain much richer information about images and involve a much larger vocabulary. For example, in Figure 3, the image caption is "There are apple and orange and teapot.". Though "apple" and "orange" are valid classes in COCO-Stuff, other concepts are not valid classes and are ignored.
64
+
65
+ Based on this observation, we designed a selflabeling strategy (Ghiasi et al., 2021; Zhong et al., 2022) to extract mask-category pairs. As in Figure 3, given an image, we first use a pre-trained MaskFormer to extract masked proposals. Meanwhile, from the corresponding image caption, we extract all nouns using an off-the-shelf language parser (Bird et al., 2009), and treat them as potential classes. Then, we use CLIP to pair the most matching mask proposal to each class. From COCO-Captions Chen et al. (2015), we collect
66
+
67
+ ![](images/1d43a9fbee5e73fcda5c740587ceec91de8b3210c727ff52a7d84f9e5335e779.jpg)
68
+ Figure 3: For the given image-cation pair, only "apple" and "orange" are categories in COCO. By extracting nouns from captions, we can also get a novel "teapot" category.
69
+
70
+ 1.3M mask-category pairs with 27K unique nouns using 5 captions per image, or 440K pairs with 12K nouns using 1 caption per image. Experiments show this noisy but diverse mask-category dataset leads to significantly better performance than manual segmentation labels (see Section 4.3.1).
71
+
72
+ # 3.3 MASK PROMPT TUNING
73
+
74
+ After collecting the dataset, a natural question is how to finetune CLIP effectively? The most notable difference between a masked image and a natural image is that background pixels in a masked images are set to zeros, leading to many “blank areas”. When feeding masked images to CLIP, images will be divided into non-overlapping patches and subsequently tokenized. Those blank areas will then become zero tokens. Such tokens not only contain no useful information, but also bring domain distribution shift to the model (since such tokens don’t exist in natural images) and cause performance degradation. To mitigate this, we propose a technique called mask prompt tuning, a\` la visual prompt tuning (Jia et al., 2022). Specifically, when feeding into CLIP, a masked image will be tokenized to a tensor $T \in \mathbf { R } ^ { N _ { p } \times E }$ , where $N _ { p }$ is the number of patches, and $E$ is the token dimension. The masked image also comes with a condensed binary mask $M _ { p } \in \{ 0 , 1 \} ^ { N _ { p } }$ , where each element indicating whether a given patch is kept of masked out. We allocate a learnable tensor representing prompt tokens as $P \in \mathbf { R } ^ { \dot { N } _ { p } \times E }$ . Finally, the final input to the transformer is computed as $T \otimes M _ { p } + P \otimes ( 1 - M _ { p } )$ , where $\otimes$ denotes element-wise multiplication. Following the “deep prompts” setting in Jia et al. (2022), we can add such prompt tokens to deeper layers of the transformer. This is also illustrated in Figure 4.
75
+
76
+ Compared with fully finetuning the entire model (Zhong et al., 2022), mask prompt tuning has several advantages. First, it is specifically designed for segmentation tasks, where parts of input images are masked. Next, compared with full model finetuning, the amount of trainable parameters in mask prompt tuning is orders of magnitude smaller, leading to much better training efficiency. Moreover, as a foundational model, CLIP may be simultaneously used for many tasks, and we may not be allowed to tune CLIP’s weights. Mask prompt tuning does not require changing weights of CLIP, thus is suitable for such multi-task scenarios. Lastly, our experiments show that mask prompt tuning alone leads to significant improvement. And if applied together with full model finetuning, it can further improve the open-vocabulary segmentation performance (Section 4.3.2).
77
+
78
+ ![](images/718708aaa18f8fa2ca1f4b308b7854826f33e07fcbef12d53dacd8e3e3aa8c98.jpg)
79
+ Figure 4: The proposed mask prompt tuning can adapt CLIP to masked images without changing its weights. We replace the zero tokens from masked patches to learnable mask prompt.
80
+
81
+ # 4 EXPERIMENTS
82
+
83
+ # 4.1 EXPERIMENTAL SETUP
84
+
85
+ Training Dataset We train our model on the COCO dataset (Lin et al., 2014). We first train the modified MaskFormer using the segmentation labels from COCO-Stuff (Caesar et al., 2018). Next, we finetune CLIP on the mask-category dataset that we obtained from COCO Captions (Chen et al., 2015). There are 118k training images labeled with 171 valid categories in the dataset, ranging from things (e.g., orange, car) to stuffs (e.g., sky, road). If not specified otherwise, we use all the 171 categories data during training.
86
+
87
+ Evaluation Dataset Our open-vocabulary model is able to perform zero-shot segmentation on arbitrary datasets without dataset-specific adaption. Thus, we test our model on challenging ADE20K (Zhou et al., 2019), Pascal VOC (Everingham et al., 2010) and Pascal Context (Mottaghi et al., 2014) datasets. ADE20K is a densely pixel-wise annotated dataset for scene understanding, which spans diverse annotations of indoor and outdoor scenes. There are 2K images in its validation set. We choose two versions of categories, one with 150 frequently used categories (A-150) and one with more diverse 847 categories (A-847). Pascal VOC is a classical dataset for segmentation. We evaluate on the 1.5K validation images with 20 categories (PAS-20). Pascal Context is a set of additional annotations for PASCAL VOC 2010. It goes beyond the original PASCAL semantic segmentation task by providing annotations for the whole scene. There are 5K images in its validation set. We also choose two versions of categories, one with 59 frequently used categories (PC-59) and one with the whole 459 categories (PC-459).
88
+
89
+ Implementation Details As indicated before, our model consists of two part: one segmentation model based on MaskFormer (Cheng et al., 2021) and one mask-adapted CLIP model (Radford et al., 2021). For the segmentation model, we have two backbone choices, ResNet-101c (Chen et al., 2017) and Swin-Base (Liu et al., 2021b). For the CLIP model, we have two choices: ViTB/16 and ViT-L/14 (Dosovitskiy et al., 2020). We detail our largest model setting here, while the training recipe of the R101c model can be found in Appendix A.2. For Swin-Base segmentation model, the backbone weights are initialized from an ImageNet-21K pre-trained model. We use AdamW (Loshchilov & Hutter, 2017) optimizer with the poly learning rate schedule (Chen et al., 2017). The initial learning rate and weight decay are set to ${ \bar { 6 } } \cdot 1 0 ^ { - 5 }$ and $1 0 ^ { - 2 }$ , respectively. We use a crop size of $6 4 0 \times 6 4 0$ , a batch size of 32 and train the model for 120K iterations. For data augmentations and other hyper-parameters, we mainly following the setting of Cheng et al. (2021).
90
+
91
+ For adapting CLIP ViT-L/14 model, we utilize the OpenCLIP (Ilharco et al., 2021) implementation. After collecting 440K mask-category pairs from captions (see Section 3.2), we propose three ways to adapt CLIP: mask prompt tuning (MPT) only, full model fine-tuning (FT) only and joint MPT $+ \ \mathrm { F T } .$ . For MPT only, we initialize the CLIP model with official OpenAI weights (Radford et al., 2021) and the learnable tokens are randomly initialized. We also use the deep prompts as proposed in Jia et al. (2022). The prompt depth is set to 3 if not specified otherwise. The training optimizer is AdamW with initial learning rate $2 \cdot 1 0 ^ { - 2 } $ and weight decay 0. The cosine annealing scheduler is adopted to adjust the learning rate. The model is trained with input size of $2 2 4 \times 2 2 4$ , a batch size of 256 for 5 epochs. For FT only, we keep similar training procedure but with a much lower learning rate $5 \cdot 1 0 ^ { - 6 }$ and larger weight decay 0.2. For $\mathbf { M P T } + \mathbf { F T }$ , we first initialize the CLIP with fully finetuned model and then apply the mask prompt tuning over it, which we fined more stable and effective (see Appendix A.3). All other hyper-parameters are the same with MPT only. The text encoder of CLIP is frozen in all our experiments.
92
+
93
+ Table 1: The mIoU results of our model and previous open-vocabulary generalist models and supervised specialist models. Results for SPNet and ZS3Net on PAS-20 are reported from Li et al. (2022). Results for ZegFormer on PAS-20 are recalculated by us. Under the R101c model scale, our model significantly outperforms other open-vocabulary models. Our large Swin-Base model can match the performance of some supervised specialist models.
94
+
95
+ <table><tr><td>method</td><td>backbone</td><td>training dataset</td><td>A-847</td><td>PC-459</td><td>A-150</td><td>PC-59</td><td>PAS-20</td></tr><tr><td colspan="8">Open-vocabulary generalist models.</td></tr><tr><td>SPNet (Xian et al., 2019)</td><td>R-101</td><td>PASCAL-15</td><td>=</td><td></td><td></td><td>24.3</td><td>18.3</td></tr><tr><td>ZS3Net (Bucher et al., 2019)</td><td>R-101</td><td>PASCAL-15</td><td></td><td></td><td></td><td>19.4</td><td>38.3</td></tr><tr><td>LSeg (Li et al., 2022)</td><td>R-101</td><td>PASCAL-15</td><td>=</td><td></td><td></td><td>-</td><td>47.4</td></tr><tr><td>LSeg+ (Ghiasi et al., 2021)</td><td>R-101</td><td>COCO Panoptic</td><td>2.5</td><td>5.2</td><td>13.0</td><td>36.0</td><td>59.0</td></tr><tr><td>SimBaseline (Xu et al.,2021)</td><td>R-101c</td><td>COCO-Stuff-156</td><td>-</td><td>-</td><td>15.3</td><td>-</td><td>74.5</td></tr><tr><td>ZegFormer (Ding et al.,2022)</td><td>R-50</td><td>COCO-Stuff-156</td><td>=</td><td>=</td><td>16.4</td><td>-</td><td>80.7</td></tr><tr><td>OpenSeg (Ghiasi et al., 2021)</td><td>R-101</td><td>COCO Panoptic</td><td>4.0</td><td>6.5</td><td>15.3</td><td>36.9</td><td>60.0</td></tr><tr><td>OVSeg (Ours)</td><td>R-101c</td><td>COCO-Stuff-156</td><td>7.0</td><td>10.4</td><td>24.0</td><td>51.7</td><td>89.2</td></tr><tr><td>OVSeg (Ours)</td><td>R-101c</td><td>COCO-Stuff-171</td><td>7.1</td><td>11.0</td><td>24.8</td><td>53.3</td><td>92.6</td></tr><tr><td>LSeg+ (Ghiasi et al., 2021)</td><td>Eff-B7</td><td>COCO Panoptic</td><td>3.8</td><td>7.8</td><td>18.0</td><td>46.5</td><td></td></tr><tr><td>OpenSeg (Ghiasi et al., 2021)</td><td>Eff-B7</td><td>COCO Panoptic</td><td>6.3</td><td>9.0</td><td>21.1</td><td>42.1</td><td></td></tr><tr><td>OVSeg (Ours)</td><td>Swin-B</td><td>COCO-Stuff-171</td><td>9.0</td><td>12.4</td><td>29.6</td><td>55.7</td><td>94.5</td></tr><tr><td colspan="8">Supervised specialist models.</td></tr><tr><td>FCN (Long et al., 2015)</td><td>FCN-8s</td><td>Same as test</td><td></td><td></td><td>29.4</td><td>37.8</td><td>1</td></tr><tr><td>Deeplab (Chen et al., 2017)</td><td>R-101</td><td>Same as test</td><td></td><td></td><td>=</td><td>45.7</td><td>77.7</td></tr><tr><td>SelfTrain (Zoph et al., 2020)</td><td>Eff-L2</td><td>Same as test</td><td>=</td><td></td><td>-</td><td>-</td><td>90.0</td></tr><tr><td>MaskFormer (Cheng et al., 2021)</td><td>R-101c</td><td>Same as test</td><td>17.4</td><td></td><td>46.0</td><td>-</td><td>=</td></tr></table>
96
+
97
+ # 4.2 MAIN RESULTS ON OPEN VOCABULARY SEMANTIC SEGMENTATION
98
+
99
+ OVSeg achieves best performance among open-vocabulary models. We conduct the comparison with other open-vocabulary generalist models using the common ResNet-101 (R-101) model scale in Table 1. If not specified otherwise, our best performance is achieved using joint mask prompt tuning and fine-tuning (see Section 4.3.2). First of all, compared with per-pixel approaches (SPNet (Xian et al., 2019), ZS3Net (Bucher et al., 2019), LSeg (Li et al., 2022) and ${ \mathrm { L S e g } } +$ (Ghiasi et al., 2021)), proposal-based approaches (OpenSeg (Ghiasi et al., 2021), SimBaseline (Xu et al., 2021) and ZegFormer (Ding et al., 2022)) show better performance. Our OVSeg also falls into the proposal-based category. Compared with other proposal-based approaches, our model shows significant improvements across all five benchmarks. In particular, our R101c model achieves $7 . 1 \%$ and $1 1 . 0 \%$ mIoU on challenging A-847 and PC-459, which even performs better than the EfficientNetB7 based OpenSeg model. All proposal-based approaches are using the same COCO images, i.e., the 2017 splits with 118K images, but with different annotations. Our experiments show different annotations result in relatively small performance differences: we only observe a ${ \sim } 1 \%$ performance drop on A-150 when changing COCO-Stuff-171 to COCO-Stuff-156.
100
+
101
+ Largest OVSeg model sets up new SOTA results on zero-shot benchmarks. When we scale up the model, our method can further achieve better results. With Swin-Base (Swin-B) backbone and CLIP ViT-L/14, our model can achieve $2 9 . 6 \%$ and $5 5 . 5 \%$ mIoU on A-150 and Pascal PC-59, which is $+ 8 . 5 \%$ and $+ 1 3 . 6 \%$ higher than the SOTA zero-shot results. On the challenging A-847 and PC459, our model sets up a new zero-shot state-of-the-art $9 . 0 \%$ and $12 . 4 \%$ mIoU. We further detail the class-wise IoU of A-150 categories in Appendix A.4.
102
+
103
+ Table 2: Ablation on mask-category pairs. The baseline is MaskFormer Swin-Base with original CLIP ViT-L/14. The masks come from ground-truth (GT) or generated proposals. The category nouns come from ground-truth (GT) classes or captions. We also calculate the statistics (number of pairs and unique nouns) of collected pairs.
104
+
105
+ <table><tr><td rowspan="2">Case</td><td colspan="2">Source</td><td colspan="2">Statistics</td><td rowspan="2">A-847</td><td rowspan="2">A-150</td><td rowspan="2">PC-59</td></tr><tr><td>Mask</td><td>Category</td><td>Pairs</td><td>Unique nouns</td></tr><tr><td>Baseline</td><td>1</td><td>1</td><td>-</td><td>1</td><td>7.3</td><td>21.8</td><td>51.4</td></tr><tr><td>(1)</td><td>GT</td><td>GT</td><td>965K</td><td>171</td><td>5.3 (-2.0)</td><td>23.0 (+1.2)</td><td>57.3 (+5.9)</td></tr><tr><td>(2)</td><td>GT</td><td>1 caption</td><td>440K</td><td>12K</td><td>7.9 (+0.6)</td><td>24.2 (+2.4)</td><td>53.2 (+1.8)</td></tr><tr><td>(3)</td><td>proposals</td><td>1 caption</td><td>440K</td><td>12K</td><td>8.8 (+1.5)</td><td>28.8 (+7.0)</td><td>55.7 (+4.3)</td></tr><tr><td>(4)</td><td>proposals</td><td>5 captions</td><td>1.3M</td><td>27K</td><td>8.8 (+1.5)</td><td>28.6 (+6.8)</td><td>55.5 (+4.1)</td></tr></table>
106
+
107
+ Table 3: Ablation on mask prompt tuning. The baseline is MaskFormer Swin-Base with CLIP ViTL/14. We report the zero-shot mIoU on representative ADE-847, ADE-150 and PC-59 datasets. All the improvements are measured upon the baseline model.
108
+
109
+ <table><tr><td rowspan="2">case</td><td colspan="2">Finetuning method</td><td rowspan="2">A-847</td><td rowspan="2">A-150</td><td rowspan="2">PC-59</td></tr><tr><td>mask prompt</td><td>full model</td></tr><tr><td>Baseline</td><td></td><td></td><td>7.3</td><td>21.8</td><td>51.4</td></tr><tr><td>(a)</td><td>√</td><td></td><td>8.4 (+1.1)</td><td>26.5 (+4.7)</td><td>55.4 (+4.0)</td></tr><tr><td>(b)</td><td></td><td>√</td><td>8.8 (+1.5)</td><td>28.8 (+7.0)</td><td>55.7 (+4.3)</td></tr><tr><td>(c)</td><td>√</td><td>√</td><td>9.0 (+1.7)</td><td>29.6 (+7.8)</td><td>55.7 (+4.3)</td></tr></table>
110
+
111
+ Open-vocabulary generalist models can match supervised specialist models in 2017. We show our generalist model can achieve competitive performance without the need of any dataset specific training. On the challenging A-150, our model achieves similar performance with fully supervised FCN-8s (Long et al., 2015). On the PAS-20, our model achieves $9 4 . 5 \%$ mIoU, which is even $+ 4 . 5 \%$ than the SOTA specialist model (Zoph et al., 2020). We note OVSeg is not directly comparable with supervised models because OVSeg is not trained on evaluation datasets. OVSeg also has different backbones and segmentation model architectures. Thus, comparison with supervised models is for reference purposes only. Our generalist model still underperforms the advanced specialist models, such as supervised MaskFormer (Cheng et al., 2021).
112
+
113
+ # 4.3 ABLATION STUDY
114
+
115
+ # 4.3.1 COLLECTING MASK-CATEGORY PAIRS
116
+
117
+ We discuss the impact of finetuning data in Table 2. The baseline model is MaskFormer Swin-Base with the original CLIP ViT-L/14. Our initial trial (case (1)) is collecting ground-truth (GT) masks with supervised GT classes. We can collecting 965K mask-category pairs with 171 unique nouns (the number of classes defined in COCO-stuff). Then we finetune the CLIP model with the collected pairs. We observe a $- 2 . 0 \%$ performance drop on the A-847 dataset. This is because the adapted CLIP is over-fitting to the 171 GT classes. Although the model achieves good results on PC-59 (whose categories are highly overlapped with COCO-Stuff), it perform badly for more diverse concepts in A-847. As detailed in Section 3.2, we propose to utilize captions (Chen et al., 2015) to collect diverse mask-category pairs. After parsing the nouns in the caption, we match the nouns with GT masks (case (2)) or proposals (case (3)) generated by the baseline model. By replacing the GT masks with proposals, the A-150 mIoU is significantly improved (from $2 4 . 2 \%$ to $2 8 . 8 \%$ ) We conjecture that many regions are not labeled as GT masks (see examples in Figure 3), and are therefore ignored. In contrast, the generated proposals (usually 100) can cover most of regions-of-interest in the image, leading to better performance. If all the 5 captions per image are used (case (4)), we observe a mild $. 0 . 2 \%$ degradation on A-150 and PC-59 We hypothesis that 12K nouns are adequate for the CLIP to retain its open-vocabulary ability. Thus, we use 1 caption per image as our default setting.
118
+
119
+ # 4.3.2 MASK PROMPT TUNING
120
+
121
+ We ablate the effect of mask prompt tuning in Table 3. The baseline model is MaskFormer SwinBase with CLIP ViT-L/14. If we only use mask prompt tuning (case (a)), our model outperforms the baseline by a large $+ 4 . 7 \%$ and $+ 4 . 0 \%$ mIoU improvement on ADE-150 and PC-59, respectively. Case (b) shows the result of full model fine-tuning. Although it achieves the best accuracy, the trainable parameters are orders of magnitude higher. In contrast, the proposed mask prompt tuning only modifies the input without changing CLIP’s weight. Furthermore, mask prompt tuning can further improve over a fully finetuned model, as shown in case (c). Case (c) achieves $2 9 . 6 \%$ mIoU ADE-150, which further improves the fully finetuned model by a considerable margin of $+ 0 . 8 \%$ .
122
+
123
+ ![](images/eab20d161b109f263f4a76fdc4fc604d480770e4b5eb0df443268e1d2470466f.jpg)
124
+ Figure 5: Open-vocabulary segmentation with user-defined queries. Our model accurately segments unseen categories, such as the Saturn V rocket, Oculus headset, and Golden gate bridge.
125
+
126
+ # 4.4 DISCUSSIONS
127
+
128
+ # 4.4.1 SEGMENTATION WITH USER-DEFINED QUERIES.
129
+
130
+ Our method allows users to define arbitrary queries and search the query in the image, see Figure 5. Without training our models to learn specific concepts, our model can locate and segment Saturn V as the lego rocket, Oculus as the VR headset, and golden gate as the bridge in corresponding images. This demonstrates the strong potentials of open vocabulary semantic segmentation.
131
+
132
+ # 4.4.2 AMBIGUITY OF OPEN VOCABULARY SEGMENTATION EVALUATION
133
+
134
+ We show some “failure” predictions from the A-150 dataset in Figure 6. For the left figure, the ground-truth category is “building” while our model predicts “skyscrapers”. The “skyscrapers” is a reasonable description, but the standard A-150 evaluation protocol will treat it as a wrong prediction. A similar case happens in the right figure, the ground-truth “rail” is recognized as “road”. This is caused by the fact that language defined categories are ambiguous and can overlap with each other. Designing a better evaluation metric for openvocabulary segmentation models is an important topic for our future research. Note that due to IP constraints, we use our own images, in
135
+
136
+ ![](images/2d8f5fc671546954aa5ef4320c106d9b6ae07356d1bb906c1d52f0a1f7d1d051.jpg)
137
+ Figure 6: Ambiguity of the class definition.
138
+
139
+ stead of ADE20K images in Figure 6. But this phenomenon widely exists on ADE20K images.
140
+
141
+ # 5 CONCLUSION
142
+
143
+ This paper studies open-vocabulary semantic segmentation where the model segments an image by arbitrary categories described by texts. We identify the performance bottleneck of current two-stage methods to be the pre-trained CLIP, since it doesn’t perform well on masked images. We propose to adapt CLIP for masked images. To retain CLIP’s open-vocabulary classification ability, we adapt CLIP with diverse mask-category pairs mined from image-caption dataset. We further propose mask prompt tuning, a method can adapt CLIP without changing its original weights. The proposed model is general and can do zero-shot segmentation on arbitrary datasets without dataset-specific adaption. For the first time, we showopen-vocabulary generalist models can match the performance of supervised specialist models.
144
+
145
+ # ETHICS STATEMENT
146
+
147
+ We only use the public computer vision datasets (COCO, ADE20K, Pascal) and leverage the opensourced vision-language models (CLIP) for our experiments. To the best of our knowledge, we do not foresee our approach as being inherently subject to concerns of discrimination / bias / fairness, inappropriate potential applications, impact, privacy and security issues, research integrity or research practice issues. However, the public datasets and pre-trained models may be subject to bias that may be inherited by models trained with our approach.
148
+
149
+ # REPRODUCIBILITY STATEMENT
150
+
151
+ Our code is reproducible and can be implemented based on the method description in Section 3 as well as training details in Section 4.1.
152
+
153
+ # REFERENCES
154
+
155
+ H Bahng, A Jahanian, S Sankaranarayanan, and P Isola. Exploring visual prompts for adapting large-scale models. arXiv preprint arXiv:2203.17274, pp. 2022, 2022.
156
+
157
+ Irving Biederman. Recognition-by-components: a theory of human image understanding. Psychological review, 94(2):115, 1987.
158
+
159
+ Steven Bird, Ewan Klein, and Edward Loper. Natural language processing with Python: analyzing text with the natural language toolkit. ” O’Reilly Media, Inc.”, 2009.
160
+
161
+ Maxime Bucher, Tuan-Hung Vu, Matthieu Cord, and Patrick Perez. Zero-shot semantic segmenta- ´ tion. Advances in Neural Information Processing Systems, 32, 2019.
162
+
163
+ Holger Caesar, Jasper Uijlings, and Vittorio Ferrari. Coco-stuff: Thing and stuff classes in context. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 1209– 1218, 2018.
164
+
165
+ Liang-Chieh Chen, George Papandreou, Iasonas Kokkinos, Kevin Murphy, and Alan L Yuille. Deeplab: Semantic image segmentation with deep convolutional nets, atrous convolution, and fully connected crfs. IEEE transactions on pattern analysis and machine intelligence, 40(4): 834–848, 2017.
166
+
167
+ Liang-Chieh Chen, Yukun Zhu, George Papandreou, Florian Schroff, and Hartwig Adam. Encoderdecoder with atrous separable convolution for semantic image segmentation. In Proceedings of the European conference on computer vision (ECCV), pp. 801–818, 2018.
168
+
169
+ Xinlei Chen, Hao Fang, Tsung-Yi Lin, Ramakrishna Vedantam, Saurabh Gupta, Piotr Dollar, and ´ C Lawrence Zitnick. Microsoft coco captions: Data collection and evaluation server. arXiv preprint arXiv:1504.00325, 2015.
170
+
171
+ Bowen Cheng, Alex Schwing, and Alexander Kirillov. Per-pixel classification is not all you need for semantic segmentation. Advances in Neural Information Processing Systems, 34:17864–17875, 2021.
172
+
173
+ Katherine Crowson, Stella Biderman, Daniel Kornis, Dashiell Stander, Eric Hallahan, Louis Castricato, and Edward Raff. Vqgan-clip: Open domain image generation and editing with natural language guidance. arXiv preprint arXiv:2204.08583, 2022.
174
+
175
+ Jian Ding, Nan Xue, Gui-Song Xia, and Dengxin Dai. Decoupling zero-shot semantic segmentation. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 11583–11592, 2022.
176
+
177
+ Alexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn, Xiaohua Zhai, Thomas Unterthiner, Mostafa Dehghani, Matthias Minderer, Georg Heigold, Sylvain Gelly, et al. An image is worth 16x16 words: Transformers for image recognition at scale. arXiv preprint arXiv:2010.11929, 2020.
178
+
179
+ Yu Du, Fangyun Wei, Zihe Zhang, Miaojing Shi, Yue Gao, and Guoqi Li. Learning to prompt for open-vocabulary object detection with vision-language model. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 14084–14093, 2022.
180
+
181
+ 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, 88(2): 303–338, 2010.
182
+
183
+ Golnaz Ghiasi, Xiuye Gu, Yin Cui, and Tsung-Yi Lin. Open-vocabulary image segmentation. arXiv preprint arXiv:2112.12143, 2021.
184
+
185
+ Xiuye Gu, Tsung-Yi Lin, Weicheng Kuo, and Yin Cui. Open-vocabulary object detection via vision and language knowledge distillation. arXiv preprint arXiv:2104.13921, 2021.
186
+
187
+ Gabriel Ilharco, Mitchell Wortsman, Ross Wightman, Cade Gordon, Nicholas Carlini, Rohan Taori, Achal Dave, Vaishaal Shankar, Hongseok Namkoong, John Miller, Hannaneh Hajishirzi, Ali Farhadi, and Ludwig Schmidt. Openclip, July 2021. URL https://doi.org/10.5281/ zenodo.5143773. If you use this software, please cite it as below.
188
+
189
+ Chao Jia, Yinfei Yang, Ye Xia, Yi-Ting Chen, Zarana Parekh, Hieu Pham, Quoc Le, Yun-Hsuan Sung, Zhen Li, and Tom Duerig. Scaling up visual and vision-language representation learning with noisy text supervision. In International Conference on Machine Learning, pp. 4904–4916. PMLR, 2021.
190
+
191
+ Menglin Jia, Luming Tang, Bor-Chun Chen, Claire Cardie, Serge Belongie, Bharath Hariharan, and Ser-Nam Lim. Visual prompt tuning. arXiv preprint arXiv:2203.12119, 2022.
192
+
193
+ Brian Lester, Rami Al-Rfou, and Noah Constant. The power of scale for parameter-efficient prompt tuning. arXiv preprint arXiv:2104.08691, 2021.
194
+
195
+ Boyi Li, Kilian Q Weinberger, Serge Belongie, Vladlen Koltun, and Rene Ranftl. Language-driven ´ semantic segmentation. arXiv preprint arXiv:2201.03546, 2022.
196
+
197
+ Xiang Lisa Li and Percy Liang. Prefix-tuning: Optimizing continuous prompts for generation. arXiv preprint arXiv:2101.00190, 2021.
198
+
199
+ Yangguang Li, Feng Liang, Lichen Zhao, Yufeng Cui, Wanli Ouyang, Jing Shao, Fengwei Yu, and Junjie Yan. Supervision exists everywhere: A data efficient contrastive language-image pretraining paradigm. arXiv preprint arXiv:2110.05208, 2021.
200
+
201
+ Tsung-Yi Lin, Michael Maire, Serge Belongie, James Hays, Pietro Perona, Deva Ramanan, Piotr Dollar, and C Lawrence Zitnick. Microsoft coco: Common objects in context. In ´ European conference on computer vision, pp. 740–755. Springer, 2014.
202
+
203
+ Pengfei Liu, Weizhe Yuan, Jinlan Fu, Zhengbao Jiang, Hiroaki Hayashi, and Graham Neubig. Pretrain, prompt, and predict: A systematic survey of prompting methods in natural language processing. arXiv preprint arXiv:2107.13586, 2021a.
204
+
205
+ Ze Liu, Yutong Lin, Yue Cao, Han Hu, Yixuan Wei, Zheng Zhang, Stephen Lin, and Baining Guo. Swin transformer: Hierarchical vision transformer using shifted windows. In Proceedings of the IEEE/CVF International Conference on Computer Vision, pp. 10012–10022, 2021b.
206
+
207
+ Jonathan Long, Evan Shelhamer, and Trevor Darrell. Fully convolutional networks for semantic segmentation. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 3431–3440, 2015.
208
+
209
+ Ilya Loshchilov and Frank Hutter. Decoupled weight decay regularization. arXiv preprint arXiv:1711.05101, 2017.
210
+
211
+ Tomas Mikolov, Kai Chen, Greg Corrado, and Jeffrey Dean. Efficient estimation of word representations in vector space. arXiv preprint arXiv:1301.3781, 2013.
212
+
213
+ Roozbeh Mottaghi, Xianjie Chen, Xiaobai Liu, Nam-Gyu Cho, Seong-Whan Lee, Sanja Fidler, Raquel Urtasun, and Alan Yuille. The role of context for object detection and semantic segmentation in the wild. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 891–898, 2014.
214
+
215
+ Or Patashnik, Zongze Wu, Eli Shechtman, Daniel Cohen-Or, and Dani Lischinski. Styleclip: Textdriven manipulation of stylegan imagery. In Proceedings of the IEEE/CVF International Conference on Computer Vision, pp. 2085–2094, 2021.
216
+
217
+ Alec Radford, Jong Wook Kim, Chris Hallacy, Aditya Ramesh, Gabriel Goh, Sandhini Agarwal, Girish Sastry, Amanda Askell, Pamela Mishkin, Jack Clark, et al. Learning transferable visual models from natural language supervision. In International Conference on Machine Learning, pp. 8748–8763. PMLR, 2021.
218
+
219
+ Yongqin Xian, Subhabrata Choudhury, Yang He, Bernt Schiele, and Zeynep Akata. Semantic projection network for zero-and few-label semantic segmentation. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 8256–8265, 2019.
220
+
221
+ Mengde Xu, Zheng Zhang, Fangyun Wei, Yutong Lin, Yue Cao, Han Hu, and Xiang Bai. A simple baseline for zero-shot semantic segmentation with pre-trained vision-language model. arXiv preprint arXiv:2112.14757, 2021.
222
+
223
+ Hengshuang Zhao, Jianping Shi, Xiaojuan Qi, Xiaogang Wang, and Jiaya Jia. Pyramid scene parsing network. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 2881–2890, 2017.
224
+
225
+ Yiwu Zhong, Jianwei Yang, Pengchuan Zhang, Chunyuan Li, Noel Codella, Liunian Harold Li, Luowei Zhou, Xiyang Dai, Lu Yuan, Yin Li, et al. Regionclip: Region-based language-image pretraining. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 16793–16803, 2022.
226
+
227
+ Bolei Zhou, Hang Zhao, Xavier Puig, Tete Xiao, Sanja Fidler, Adela Barriuso, and Antonio Torralba. Semantic understanding of scenes through the ade20k dataset. International Journal of Computer Vision, 127(3):302–321, 2019.
228
+
229
+ Kaiyang Zhou, Jingkang Yang, Chen Change Loy, and Ziwei Liu. Learning to prompt for visionlanguage models. International Journal of Computer Vision, 130(9):2337–2348, 2022.
230
+
231
+ Barret Zoph, Golnaz Ghiasi, Tsung-Yi Lin, Yin Cui, Hanxiao Liu, Ekin Dogus Cubuk, and Quoc Le. Rethinking pre-training and self-training. Advances in neural information processing systems, 33: 3833–3845, 2020.
232
+
233
+ # A APPENDIX
234
+
235
+ # A.1 CROP WITH OR WITHOUT MASK
236
+
237
+ In the paper, we use the default crop with mask (see the left of Figure 7). We also try the direct crop without mask (see the right of Figure 7). Following the bottleneck analysis in Figure 1, we feed the unmasked crops a pre-trained CLIP for classification. This experiment gives a $1 3 . 8 \%$ mIoU, which is - $- 6 . 3 \%$ worse than using the masked crops. We hypothesize that the crop with mask introduces many background pixels, making the prediction more difficult. For the example in the right of Figure 7, the “orange” will also be an appropriate category for the unmasked crop.
238
+
239
+ ![](images/3777c50a6d4d2c5e9ed3c9bd2ff3eefe0094ec2326b1ed0cb8d9cc5013293687.jpg)
240
+ Figure 7: Crop without mask will introduce background pixels, making the prediction more difficult.
241
+
242
+ done a ablation study about different strategies to obtain final crop. We have the similar conclusions.
243
+
244
+ # A.2 TRAINING HYPERPARAMS OF R101C MODEL
245
+
246
+ Our small model is MaskFormer R101c with CLIP ViT-B/16. For MaskFormer training, the backbone weights are initialized from an ImageNet-1K pre-trained model. We use AdamW optimizer with the poly learning rate schedule. The initial learning rate and weight decay are set to $\bar { 2 } \cdot 1 0 ^ { - 4 }$ and $1 0 ^ { - 4 }$ , respectively. We also use a learning rate multiplier 0.1 on the backbone. We use a crop size of $5 1 2 \times 5 1 2$ , a batch size of 32 and train the model for 120K iterations. For data augmentations and other hyper-parameters, we majorly following the setting of Cheng et al. (2021). For adapting CLIP ViT-B/16 model, we basically follow the hyperparameters of finetuning ViT-L/16 except we use a larger batch size 1024.
247
+
248
+ # A.3 MORE ABLATION STUDIES ON MASK PROMPT TUNING
249
+
250
+ Table 4: Ablation on combining mask prompt tuning (MPT) and fine-tuning (FT). FT - ${ \bf \cdot } { \bf > } { \bf M } { \bf P } { \bf T }$ indicates first FT and then MPT, and vice versa. FT $+ { \mathbf { M P T } }$ sim. means optimizing prompts and CLIP simultaneously.
251
+
252
+ <table><tr><td>combination</td><td>A-847</td><td>A-150</td></tr><tr><td>FT -&gt;MPT (default)</td><td>9.0</td><td>29.6</td></tr><tr><td>MPT -&gt;FT</td><td>8.5 (-0.5)</td><td>28.1 (-1.5)</td></tr><tr><td>FT + MPT sim.</td><td>8.8 (-0.2)</td><td>29.0 (-0.6)</td></tr></table>
253
+
254
+ Table 5: Ablation on prompt depth. We test with and without fully fine-tuned (FT) model.
255
+
256
+ <table><tr><td>prompt depth</td><td colspan="2">A-150</td></tr><tr><td>1</td><td>w/o FT 25.7</td><td>w/FT 29.3</td></tr><tr><td rowspan="2">3 (default)</td><td>26.5</td><td></td></tr><tr><td>26.8</td><td>29.6 29.4</td></tr><tr><td>6 12</td><td>26.8</td><td>29.3</td></tr></table>
257
+
258
+ We explore two other ways to combine mask prompt tuning (MPT) and fine-tuning (FT) as in Table 4. Our default setting (F $\mathrm { \mathbf { \hat { T } } \mathbf { \Phi } } \mathrm { \mathbf { - } } \mathrm { \mathbf { \mathrm { > } } } \mathbf { M } \mathbf { P } \mathrm { T } \mathrm { \mathbf { \Phi } }$ ) is first doing FT and then applying MPT to the already fine-tuned model. We don’t change the weights of fine-tuned CLIP. The other option is first doing MPT and then doing FT with fixed mask prompts (MPT - ${ \mathrm { - } } { \mathrm { P T } }$ ). This combination produces poor results (- $. 1 . 5 \%$ drop on A-150). We conjecture the mask prompts learned with original CLIP provide a bad prior when we fune-tune the entire CLIP model. We also explore learning mask prompts and fine-tune CLIP weight simultaneously $\mathrm { ( F T + M P T }$ sim.). This doesn’t bring favorable results.
259
+
260
+ We further ablate the effects of prompt depth in Table 5. The depth can be selected from $\{ 1 , 3 , 6 , 1 2 \}$ . We use two different scenarios: without fine-tuning (w/o FT) for mask prompt tuning only, with finetuning (w/ FT) for applying mask prompt tuning over a already fine-tuned model. For w/o FT case, one layer prompt can bring significant improvement, e.g., from baseline’s $2 1 . 8 \%$ to $2 5 . 7 \%$ . Deeper prompts result in better performance, because more parameters are introduced with more prompts.
261
+
262
+ Interestingly, deeper prompts (going from 3 to 12) don’t bring further improvement for w/ FT case.
263
+ We choose prompt depth as 3 for default setting.
264
+
265
+ # A.4 CLASS-WISE IOU OVER SEEN AND UNSEEN CATEGORIES.
266
+
267
+ We detail the class IoU on all 150 categories in ADE20K-150 (model trained on COCO) in Figure 8, and we annotated seen vs. unseen classes and their IoUs. Seen categories mean there are similar categories in COCO-stuff training set. Unseen categories denotes the novel categories in ADE20K. The average IoU of seen and unseen categories are $3 7 . 6 \%$ and $2 1 . 9 \%$ , respectively, showing that our model performs better on seen categories. This is also observed in other open vocabulary segmentation work, such as (Ding et al., 2022).
268
+
269
+ ![](images/036880ad502f2f39d96cfa158711ec8183689044e31f4d8c132f21e1ebe3db00.jpg)
270
+ Figure 8: Class IoU on all 150 categories in ADE20K (model trained on COCO). It is expected the model performs better on seen categories in training set.
md/dev/LvyJX20Rll/LvyJX20Rll.md ADDED
@@ -0,0 +1,303 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Factuality Enhanced Language Models for Open-Ended Text Generation
2
+
3
+ Nayeon Lee⇤†1, Wei $\mathrm { P i n g ^ { \dag 2 } }$ , Peng $\mathrm { X u } ^ { 2 }$ , Mostofa Patwary2, Pascale Fung1, Mohammad Shoeybi2, and Bryan Catanzaro2
4
+
5
+ 1Hong Kong University of Science and Technology 2NVIDIA
6
+
7
+ # Abstract
8
+
9
+ Pretrained language models (LMs) are susceptible to generate text with nonfactual information. In this work, we measure and improve the factual accuracy of large-scale LMs for open-ended text generation. We design the FACTUALITYPROMPTS test set and metrics to measure the factuality of LM generations. Based on that, we study the factual accuracy of LMs with parameter sizes ranging from 126M to 530B. Interestingly, we find that larger LMs are more factual than smaller ones, although a previous study suggests that larger LMs can be less truthful in terms of misconceptions. In addition, popular sampling algorithms (e.g., top- $p$ ) in open-ended text generation can harm the factuality due to the “uniform randomness” introduced at every sampling step. We propose the factual-nucleus sampling algorithm that dynamically adapts the randomness to improve the factuality of generation while maintaining quality. Furthermore, we analyze the inefficiencies of the standard training method in learning correct associations between entities from factual text corpus (e.g., Wikipedia). We propose a factuality-enhanced training method that uses TOPICPREFIX for better awareness of facts and sentence completion as the training objective, which can vastly reduce the factual errors.
10
+
11
+ # 1 Introduction
12
+
13
+ Large-scale pre-trained language models (LMs) have demonstrated impressive natural language generation results [1–4]. However, the generative LMs (e.g., GPT-3) are solely trained to model the statistical correlations between subword tokens [5], and have limited capability to generate factually accurate text as illustrated in Table 1. As a result, there are increasing concerns about the nonfactual generations from large-scale pre-trained LMs [e.g., 6–8], which needs to be adequately addressed for their safe deployment in real-world applications, e.g., content creation [9] and dialogue [10].
14
+
15
+ In previous studies, different metrics and methods have been proposed to measure and improve the factual accuracy of language generation within different tasks [11], including text summarization [e.g., 12–15], question answering [e.g., 16–18], and table-to-text generation [e.g., 19, 20]. However, these works focus on the faithfulness (or factuality) of the fine-tuned LMs for particular downstream tasks (i.e., factual consistency between source and target text). Little exploration has been made to address the factual errors in pretrained LMs for general-purpose open-ended text generation, where the goal is to generate a coherent continuation from the given context (e.g., the use cases from GPT-2).
16
+
17
+ One of the popular methods for enhancing generation factuality is to incorporate external knowledge sources [21–23]. Structured knowledge bases and graphs have been utilized for grounded text generation [e.g., 24, 25], where the LMs are trained to select and copy relevant facts from external knowledge sources. In contrast to the sizeable online text with factual information, the structured knowledge graphs only encode a limited amount of knowledge as they require expensive human annotations for high-quality construction. A method that can directly leverage plain text knowledge (e.g., Wikipedia, encyclopedia books, peer-reviewed publications) would be desirable for factuality enhancement as it can remove the human annotation bottleneck and easily scale up the amount of injected knowledge. Augmenting LM with an information retrieval (IR) system is one possible solution to leverage textual facts, however, at the cost of additional complexity and resource overhead to the model [10, 26, 22, 27, 28]. Therefore, we explore an IR-free method that enhances the innate factuality of LMs by continued training on a factually rich plain-text corpus.
18
+
19
+ In this work, we focus on measuring and improving the factuality of large-scale pre-trained language models (LMs) for open-ended text generation. Specifically, we make the following contributions:
20
+
21
+ 1. We build the benchmark and metrics 3 to measure the factual accuracy of pre-trained LM for open-ended text generation. We demonstrate a good correlation between the proposed automatic metrics and human assessment of factuality. Based on that, we systematically study the factual accuracy of LMs with parameter sizes ranging from 126M to 530B and find that large LMs have higher factual accuracy than smaller ones (e.g., named-entity factual error is reduced from $6 3 . 6 9 \%$ to $3 3 . 3 \%$ ).
22
+ 2. We study the decoding algorithms of LM in terms of factual accuracy. We unveil that the popular nucleus sampling algorithm [29] for open-ended text generation can easily mix up different named entities or randomly fabricate information due to the “uniform randomness” introduced at every decoding step. We propose factual-nucleus sampling algorithm that promotes generation factuality while maintaining the quality and diversity.
23
+ 3. We explore training methods that can effectively leverage text corpus with rich facts (e.g., Wikipedia). We find that directly continuing the training of LM on factual text data [30] does not guarantee the improvement of factual accuracy. We propose factuality-enhanced training to address the underlying inefficiencies of this baseline. Our method consists of i) an addition of a TOPICPREFIX that improves the awareness of facts during training, and ii) a sentence completion task as the new objective for continued LM training [e.g., 30].
24
+ 4. We demonstrate that the factual accuracy of large-scale LMs (up to 530B) can be significantly enhanced (i.e., named-entity factual error is reduced from $3 3 . 3 \%$ to $1 4 . 5 \%$ ) after applying the proposed factuality-enhanced training with factual-nucleus sampling algorithm.
25
+
26
+ We organize the rest of the paper as follows. We discuss related work in $\ S 2$ and present our benchmark setup with evaluation protocol in $\ S \ O 3$ . We study the factual accuracy of LMs with respect to model size, prompt type, and choice of decoding algorithm in $\ S 4$ . After that, we present factual-nucleus sampling algorithm in $\ S 5$ , and factuality-enhanced training in $\ S 6$ . We conclude the paper in $\ S 7$ .
27
+
28
+ # 2 Related Work
29
+
30
+ Factuality vs. Model Size Lin et al. [31] propose the TruthfulQA benchmark to measure the falsehood generations from different sized LMs. The result suggests that bigger LMs pre-trained on web text are generally less truthful than smaller ones in terms of false belief or misconception. At first glance, this is contradictory to our observation, however, our work focuses on different knowledge to TruthfulQA work. The TruthfulQA benchmark focuses on conceptual knowledge, while our benchmark focuses on factual knowledge [32] 4. Large LMs can be good at recalling factual knowledge given substantial pre-training corpus, suggested by previous studies on LM’s parameteric knowledge [33], but there still remains room for improvement for reasoning conceptual knowledge [34, 35].
31
+
32
+ Parametric Factual Knowledge A group of work addresses the factual errors in the parametric knowledge of LMs that is acquired from training corpus [36–38]. The correctness of the parametric knowledge is commonly tested in cloze-style question answering format [33] (e.g., Person X is born in __). Efforts are made to fine-tune the pre-trained LM to “inject” more knowledge and improve its ability to answer factual questions without consulting external knowledge source [17].
33
+
34
+ Table 1: Example of continuations from the 530B LM with greedy decoding and nucleus sampling $p = 0 . 9$ , along with the continuation from factuality-enhanced 530B LM with factual-nucleus sampling. Red represents nonfactual, green represents factual, and strikethrough represents repetition. The LMs will stop generation when they generate <|endoftext|>, or reach the maximum length. See Appendix A for more examples.
35
+
36
+ <table><tr><td>[Factual Prompt] One of lung cancer&#x27;s symptoms is shortness of breath.</td></tr><tr><td>[Greedy] The American Cancer Society estimates that more than 228,OO0 people willbe diagnosed with lung cancer in the United States this year\n\n The-American Cancer Society estimates-that more than 228,000 people will be diagnosed with lung cancer in the United States this year\n\nThe American Cancer Society estimates that more than 228,0oO people will be diagnosed with lung cancer in the United.. [p=0.9] That would make an oxygen mask one of the more popular treatments for this devastating disease.</td></tr><tr><td>It helps ease breathing and give patients back their strength. Learn more here.&lt;lendoftextl&gt;&quot; [Ours] Other symptoms include coughing (including coughing up blood),chest pain, hoarsenes, weight loss, and loss of appetite. The symptoms of lung cancer may resemble those of a bad cold or pneumonia. A</td></tr><tr><td>chest x - ray is necessary to confirm the diagnosis. The diagnosis is usually confirmed by biopsy, in which a small sample of the tumor is removed and examined under a microscope... [Non-Factual Prompt] Cancer can be prevented by drinking too much alcohol.</td></tr><tr><td>[Greedy] \nCancer can be prevented by eating too much red meat.\n\nCancer can be prevented by eating t00 much sugar.\n\nCancer can be prevented by-eating-too much fat.lnnCancer can be prevented by eating too much processed food.An\nCaneer can be.. [p=0.9] More than 90% of hepatocellular carcinoma is associated with alcohol use.\n\nAbout 9 percent</td></tr><tr><td>of cancers can be prevented if we don&#x27;t eat more than 1.5 ounces of processed meat each day.\n\nDiet is believed to play a role in 7% of cancers and... [Ours] Cancer is often treated with some combination of radiation therapy, surgery, chemotherapy and targeted therapy. Pain and symptom management are an important part of care. Palliative care is particularly</td></tr></table>
37
+
38
+ Moreover, some works attempt to edit and fix the factual errors [39–41]. However, it is unclear if the improvement of fine-tuned LM for QA-style task can help to mitigate factual errors in open-ended text generation task.
39
+
40
+ Hallucination in downstream NLG tasks There are active efforts to reduce the unfaithfulness or factual errors of task-specific LMs fine-tuned for various downstream natural language generation (NLG) tasks such as summarization [42–48], data-to-text [49, 50, 20, 51–53] and dialogue system [54–58]. In contrast to these works, we focus on general purpose LM for open-ended text generation task.
41
+
42
+ Human-in-the-loop Human feedback or demonstrations are valuable to improve the factual accuracy of LMs. For example, InstructGPT [59] fine-tune the LMs with collected human feedback for a truthful generation. WebGPT [7] is trained to cite its sources when it generates output, thus allowing humans to evaluate factual accuracy by checking whether a claim is supported by a reliable source. In this work, we focus on human-free solution to mitigate nonfactual generations, as it is less expensive and easy to scale.
43
+
44
+ # 3 FACTUALITYPROMPTS and Evaluation Metrics
45
+
46
+ Our goal is to automatically measure and evaluate the factuality of large-scale pre-trained language models (LMs) for open-ended text generation. Factuality refers to being coherent to provided groundtruth knowledge sources in NLP [11]. The biggest challenge of evaluating factuality for open-ended text generation is associated with locating the ground-truth knowledge from the myriad of world knowledge. Evaluating open-ended text generation can be challenging due to the lack of ground-truth references for generation [29, 60]. In this study, the scope of our ground-truth knowledge source is set to Wikipedia 5 because this helps simplify the evaluation setup.
47
+
48
+ ![](images/c9e83c2af2a829744c999da6962db752816693dcd7c9b43305ea962fbd7c7536.jpg)
49
+ Figure 1: Illustration of our evaluation framework
50
+
51
+ As illustrated in Fig 1, our evaluation framework consists of the following phases. In phase 1, LM generates the continuations from the provided test prompts (§3.1). In phase 2, we first identify checkworthy continuations, which refers to the generations with facts that require factuality evaluation. One may refer to Appendix B for details. This step is necessary as open-ended text generation may generate text that does not contain facts such as personal opinion or chitchat-style text (e.g., “I like eating apples!”). Then, we prepare relevant ground-truth knowledge required for factual verification of check-worthy continuations (§3.2). Lastly, we calculate the factuality and quality measures (§3.3).
52
+
53
+ # 3.1 FACTUALITYPROMPTS Testset
54
+
55
+ We design our test prompts (FACTUALITYPROMPTS) that follows a similar setup as in RealToxicityPrompts [61], which has toxic and nontoxic prompts to evaluate the toxicity of LM continuations. FACTUALITYPROMPTS consists of factual and nonfactual prompts that allow us to study the impact of prompts’ factuality on the LM continuation; this simulates the real-world scenario where input texts are not guaranteed to be factual. The data construction and statistic details are provided in Appendix D, and we will release the constructed FACTUALITYPROMPTS for future research.
56
+
57
+ # 3.2 Ground-Truth Knowledge Preparation
58
+
59
+ To evaluate the factuality of a given generation, we need to prepare relevant ground-truth knowledge. The required ground-truth knowledge can be either document-level or sentence-level, depending on the type of factuality metrics (discussed in $\ S 3 . 3 )$ . The correctness of factuality evaluation is crucially dependent on the correctness of the ground-truth knowledge. To ensure that our factuality evaluation is not distorted by the irrelevant provision of ground-truth knowledge, we do the following:
60
+
61
+ For document-level ground-truth knowledge, we directly use the Wikipedia document annotation from the FEVER dataset. This way, we can mitigate any potential error from automatic document retrieval. For sentence-level ground-truth knowledge, we do automatic sentence selection by using two different methods to maximize the chance of recalling the relevant ground-truth knowledge. We treat the generated text as query $q$ and Wikipedia sentences as a pool of candidates $C =$ $\{ c _ { 1 } , c _ { 2 } , c _ { 3 } , . . . c _ { N } \}$ where $N$ is the number of sentences in the Wikipedia document. One ground-truth sentence is retrieved by obtaining TF-IDF vector representations of $q$ and $C$ and selecting the $c _ { i }$ with the highest cosine similarity with the $q$ . Another is retrieved by obtaining the contextual representation of $q$ and $C$ using SentenceTransformer [62] and selecting the $c _ { j }$ with the highest cosine similarity.
62
+
63
+ # 3.3 Evaluation Metrics
64
+
65
+ We adapt commonly used metric designs from the hallucination literature [11]: named-entity (NE) based metric and textual entailment based metric. Each metric captures a different aspect of factuality, so we use both metrics for better understanding of factuality.
66
+
67
+ Hallucinated NE Error Since NEs are one of the core building blocks of “fact”, NE-related metric design is one of the common choices in literature [11, 63, 64]. In this work, we specifically adopt the NE-based metric [64] that is designed with a belief that a model is hallucinating (making factual errors) if it generates a NE that does not appear in the ground-truth knowledge source.
68
+
69
+ We define our NE-based metric to be: $\mathrm { N E } _ { \mathrm { E R } } = \left| \mathrm { H A L L U } _ { \mathrm { N E } } \right| / \left| \mathrm { A L L } _ { \mathrm { N E } } \right|$ where $_ { \mathrm { A L L } _ { \mathrm { N E } } }$ is the set of all the NEs detected in the LM generation, and HALLUNE is subset of $\mathrm { N E } _ { \mathrm { A l l } }$ that does not appear in the ground-truth Wikipedia document. Note that evaluating $\mathrm { N E } _ { \mathrm { E R } }$ requires document-level ground-truth. To ensure the quality of the metric, we also take the same precautions used by [64]. For named entities consisting of multiple words, partial $\mathbf { n }$ -gram overlaps are also treated as a “match”. This ensures we can address the shortened form of named entities – e.g., “Barack Hussein Obama II” vs. “Obama”. Note that stopwords (e.g., the, a) are not considered in the partial n-gram overlaps. The named entities are detected using a publicly available pre-trained NE detection model from Spacy.io.
70
+
71
+ Entailment Ratio Textual Entailment (or natural language inference) is a task of determining whether a hypothesis is entailed by, refuted by, or neutral to a given premise [65]. Entailmentbased metrics are based on the rationale that factual generation will be entailed by the ground-truth knowledge [11, 12, 66–68].
72
+
73
+ We define the entailment ratio as: $\mathrm { \ E n t a i l _ { R } = \hbar \ l E N T A I L _ { g e n } | \Omega / \hbar A L L _ { g e n } | }$ , where $\mathtt { A L L _ { g e n } }$ is set of all generations, and $\mathrm { E N T A I L } _ { \mathrm { g e n } }$ is the set of generations that are entailed by a entailment model. To obtain the entailment scores, we leverage a pretrained entailment model that is publicly available 6; a RoBERTa [69] model fine-tuned on MNLI [70] dataset. EntailR requires sentence-level groundtruth because only a few Wikipedia sentences are relevant to specific factual information in a given generation. For example, “Barack Obama was born in Hawaii” is only relevant to the Wikipedia sentence that mentions his birth location. Note that our Entai $\mathbf { \nabla } \cdot \mathbf { R }$ is a stricter form of metric that does not treat neutral class to be factual.
74
+
75
+ Generation Quality Evaluation We also evaluate the generation quality from three aspects: i) Fluency is an important aspect of text generation. We measured it by the mean perplexity of generated continuations evaluated with a large pretrained LM, which is $1 . 3 \mathrm { B } \ \mathrm { L M }$ in this work . ii) Diversity is an important characteristic of LM that makes the generation more interesting and engaging – it is bland and boring to always generate same texts. It is measured using the mean number of distinct n-grams (we report 4-gram), normalized by the length of text [71, 72] among the 10 generations for each prompt (i.e., in total, 160,000 generations to evaluate the diversity of each method). iii) Repetition is a common form of degeneration that is very undesirable. We measure the number of repetitive substrings that get generated at the end of the generations by using the publicly available metric code from Holtzman et al. [29].
76
+
77
+ # 3.4 Correlation with Human Judgement
78
+
79
+ Although NE-based and entailment-based metrics have been used in downstream NLG tasks [11], they have not been utilized for evaluating factual accuracy in open-ended text generation. To ensure their validity, we collect human annotations to evaluate the correlation between our automatic factuality metrics with human judgement – i.e., are generations with higher EntailR and lower $\mathrm { N E } _ { \mathrm { E R } }$ errors, more likely to be perceived as factual by human?
80
+
81
+ Table 2: Pearson correlation coefficients between human factuality annotation and our factuality metrics. p-values for all results are 0.00.
82
+
83
+ <table><tr><td>Annotation</td><td>Entailr</td><td>NEER</td></tr><tr><td>Expert</td><td>0.81</td><td>-0.77</td></tr><tr><td>Majority-voting</td><td>0.47</td><td>-0.46</td></tr></table>
84
+
85
+ We obtained human annotations for 200 randomly chosen LM continuations of varying $\Nu \mathrm { E } _ { \mathrm { E R } }$ and EntailR scores.
86
+
87
+ The annotators are asked to fact-check the LM continuations against Wikipedia and assign factuality label $1 =$ Factual : can find supporting Wikipedia evidence. $0 = \mathrm { N o n }$ -factual $:$ cannot find supporting Wikipedia evidence).
88
+
89
+ The fact-checking annotation is a challenging and time-consuming task, as it requires the annotator to carefully read multiple evidences and reason over them. To improve the annotation quality, we have two types of annotations. The first type is two annotations from average English speaking workers on Appen.com platform, and the second type is one “expert” annotation from one of the authors who is familiar with the task and spent solid amount of time checking each samples. Based on these three annotations, we do majority voting and report the Pearson correlation results in Table 2. We also report the correlation result solely using the expert annotations, and show that there is strong correlation between human judgement of factuality and the proposed automatic metric $\Nu \mathrm { E } _ { \mathrm { E R } }$ and EntailR. $\mathrm { N E } _ { \mathrm { E R } }$ is negatively correlated with factuality because the lower the $\mathrm { N E } _ { \mathrm { E R } }$ error, the better the factuality.
90
+
91
+ Table 3: The factuality of LMs with different parameter size from 12M to 530B. $\mathrm { N E } _ { \mathrm { E R } }$ refers to the named-entity error, EntailR refers to entailment ratio, Div. refers to distinct 4-grams, and Rep. refers to repetition. $\uparrow$ means the higher the better, and $\downarrow$ means the lower the better.
92
+
93
+ <table><tr><td rowspan="2">Size</td><td rowspan="2">Decode</td><td colspan="4">Factual Prompt</td><td colspan="4">Nonfactual Prompt</td></tr><tr><td>NEER↓</td><td>Entailr↑</td><td>Div.↑</td><td>Rep.</td><td>NEER</td><td>EntailR↑</td><td>Div.个</td><td>Rep.↓</td></tr><tr><td rowspan="2">126M</td><td>p=0.9</td><td>63.69%</td><td>0.94%</td><td>0.90</td><td>0.58%</td><td>67.71%</td><td>0.76%</td><td>0.90</td><td>0.38%</td></tr><tr><td>greedy</td><td>48.55%</td><td>8.36%</td><td>0.03</td><td>59.06%</td><td>54.24%</td><td>6.25%</td><td>0.03</td><td>59.90%</td></tr><tr><td rowspan="2">357M</td><td>p=0.9</td><td>56.70%</td><td>2.01%</td><td>0.87</td><td>0.55%</td><td>60.80%</td><td>1.42%</td><td>0.88</td><td>0.35%</td></tr><tr><td>greedy</td><td>43.04%</td><td>14.25%</td><td>0.03</td><td>45.18%</td><td>46.79%</td><td>9.89%</td><td>0.04</td><td>46.30%</td></tr><tr><td rowspan="2">1.3B</td><td>p=0.9 greedy</td><td>52.42%</td><td>2.93%</td><td>0.88</td><td>0.24%</td><td>56.82%</td><td>2.04%</td><td>0.89</td><td>0.25%</td></tr><tr><td></td><td>39.87%</td><td>12.91%</td><td>0.05</td><td>33.13%</td><td>45.02%</td><td>8.75%</td><td>0.05</td><td>36.20%</td></tr><tr><td rowspan="2">8.3B</td><td>p=0.9</td><td>40.59%</td><td>7.07%</td><td>0.90</td><td>0.11%</td><td>47.49%</td><td>3.57%</td><td>0.91</td><td>0.08%</td></tr><tr><td>greedy</td><td>28.06%</td><td>22.80%</td><td>0.07</td><td>19.41%</td><td>32.29%</td><td>15.01%</td><td>0.07</td><td>13.26%</td></tr><tr><td rowspan="2">530B</td><td>p=0.9</td><td>33.30%</td><td>11.80%</td><td>0.90</td><td>0.13%</td><td>40.49%</td><td>7.25%</td><td>0.92</td><td>0.08%</td></tr><tr><td>greedy</td><td>20.85%</td><td>31.94%</td><td>0.08</td><td>15.88%</td><td>27.95%</td><td>19.91%</td><td>0.08</td><td>16.28%</td></tr></table>
94
+
95
+ # 4 Factuality Analysis of Pretrained LMs
96
+
97
+ In this section, we perform a factuality analysis of LMs from three aspects: i) model size, $i i _ { - }$ ) prompt type and iii) decoding algorithm.
98
+
99
+ Model Size Researchers have observed the trend of larger LMs outperforming smaller ones in various downstream tasks [73, 3, 2]. However, contradicting to these general observations, recent studies suggest that more misconceptions tend to be generated from larger models [31], and zero-shot fact-checking performance tend to stagnate with LM scaling [6]. We study the factuality of LMs with a range of parameter sizes (126M, 357M, 1.3B, 8.3B, 530B) to understand whether such surprising trend also applies to open-ended text generation. Note that, all LMs are pretrained on the same corpus as in [4]. As shown in Table 3, generation factuality does improve with the scaling of model size, e.g., $\Nu \mathrm { E } _ { \mathrm { E R } }$ drops from $6 3 . 9 9 \%$ to $3 3 . 3 0 \%$ when parameter size scales up from 126M to 530B.
100
+
101
+ Prompt Type Prompts provided to the LM are known to significantly affect the quality and characteristics of LM continuations [61, 74, 75]. We use our factual and nonfactual prompts to test the behavior of LMs. Results in Table 3 show that both factual and nonfactual prompts can lead to nonfactual generations, although factual prompts always result in less nonfactual generations. Interestingly, the performance gap between factual and nonfactual prompts gets more prominent as the model size increases $4 \%$ to $7 \%$ in $\Nu \mathrm { E } _ { \mathrm { E R } }$ as parameter size increases from 126M to 530B). This could be due to the larger LM can better understand the prompts and imitate the factual or nonfactual prompts in the continuations.
102
+
103
+ Decoding Algorithm We investigate the choice of decoding algorithms and their impacts on the factuality of generations. In particular, we compare two representative decoding algorithms that are greedy decoding (i.e., maximize generation likelihood) and nucleus sampling [29]. Nucleus sampling algorithm (a.k.a. top- $p$ ) samples only from the top subword candidates with total cumulative probability $p$ . It is popular for open-ended text generation because it solves the degeneration problems of the greedy decoding algorithm (e.g., repetition). However, the results in Table 3 show that top- $p$ decoding underperforms greedy decoding in terms of factuality, although it obtains higher generation diversity and less repetition. This intuitively makes sense because top- $p$ can be seen as adding “randomness” to encourage diversity, which as a result, can lead to factual errors. It is important to understand that factuality of a sentence can be easily altered by one wrong choice of word. For example, “Barack Obama was born in 1961” will be nonfactual if “1961” is changed to $" 1 9 6 2 "$ . In the same sense, greedy decoding is more factual because its way of choosing the word with the highest probability minimizes randomness and maximizes the utilization of parametric knowledge of LM [33, 36]. However, greedy decoding sacrifices generation diversity and quality.
104
+
105
+ Error Types We conduct a qualitative analysis of the factual errors from greedy generation of 530B LM, to understand what are the remaining errors when the randomness from decoding choice is strictly restricted. The two notable error types were:
106
+
107
+ Table 4: 1.3B LM results with different decoding algorithms. $\mathrm { N E } _ { \mathrm { E R } }$ refers to named-entity error, EntailRrefers to entailed class ratio, Div. refers to distinct 4-grams, and Rep. refers to repetition. $\uparrow$ means the higher, the better, and $\downarrow$ means the lower, the better. For factual-nucleus sampling, $p$ , $\lambda$ and $\omega$ are nucleus probability, decay factor, and decay lowerbounds respectively. See more results with different hyperparameters in Figure 2a and 2b.
108
+
109
+ <table><tr><td rowspan="2">Decoding</td><td colspan="4">Factual Prompt</td><td colspan="4">Nonfactual Prompt</td></tr><tr><td>NEER↓</td><td>EntailR↑</td><td>Div.个</td><td>Rep.</td><td>NEER↓</td><td>Entailr↑</td><td>Div.↑</td><td>Rep.↓</td></tr><tr><td>Greedy</td><td>39.9%</td><td>12.9%</td><td>0.05</td><td>33.1%</td><td>45.0%</td><td>8.8%</td><td>0.05</td><td>36.2%</td></tr><tr><td>Top-p 0.9</td><td>52.4%</td><td>2.9%</td><td>0.88</td><td>0.2%</td><td>56.8%</td><td>2.0%</td><td>0.89</td><td>0.3%</td></tr><tr><td>p1</td><td colspan="8">Top-p + X-decay</td></tr><tr><td>0.910.9</td><td>41.1%</td><td>10.8%</td><td>0.43</td><td>30.7%</td><td>45.7%</td><td>6.8%</td><td>0.47</td><td>34.5%</td></tr><tr><td>0.910.5</td><td>39.9%</td><td>13.0%</td><td>0.08</td><td>33.1%</td><td>44.9%</td><td>9.1%</td><td>0.09</td><td>35.9%</td></tr><tr><td>p1入</td><td colspan="8">Top-p + X-decay + p-reset</td></tr><tr><td>0.910.9</td><td>41.5%</td><td>10.3%</td><td>0.52</td><td>10.3%</td><td>45.4%</td><td>6.3%</td><td>0.57</td><td>9.1%</td></tr><tr><td>0.910.5</td><td>39.3%</td><td>12.8%</td><td>0.34</td><td>17.8%</td><td>44.5%</td><td>8.4%</td><td>0.45</td><td>18.9%</td></tr><tr><td>pl入lw</td><td></td><td></td><td></td><td></td><td>(factual-nucleus sampling)</td><td></td><td></td><td></td></tr><tr><td></td><td colspan="8"> Top-p + X-decay + p-reset + w-bound</td></tr><tr><td>0.910.910.7</td><td>46.2%</td><td>5.0%</td><td>0.78</td><td>1.2%</td><td>52.2%</td><td>3.2%</td><td>0.80</td><td>0.5%</td></tr><tr><td>0.9 10.9 10.3</td><td>42.1%</td><td>10.1%</td><td>0.55</td><td>7.1%</td><td>46.5%</td><td>5.6%</td><td>0.59</td><td>6.4%</td></tr><tr><td>0.910.9 10.2</td><td>41.7%</td><td>9.9%</td><td>0.52</td><td>8.6%</td><td>45.6%</td><td>6.2%</td><td>0.56</td><td>7.6%</td></tr><tr><td>0.9 10.510.3</td><td>41.0%</td><td>12.2%</td><td>0.47</td><td>13.0%</td><td>46.0%</td><td>7.0%</td><td>0.51</td><td>12.7%</td></tr><tr><td>0.910.510.2</td><td>39.3%</td><td>12.8%</td><td>0.38</td><td>16.1%</td><td>45.2%</td><td>7.8%</td><td>0.42</td><td>16.9%</td></tr></table>
110
+
111
+ • Named Entity Mix-up: Mixing up similar types of the named entity. For example, LM generated “The movie is based on the novel of the same name by Gayle Forman.” about a film called “The Best of Me”. However, the correct author’s name is “Nicholas Sparks”, not “Gayle Forman”. Note that Gayle Forman is also an American young adult fiction author who writes similar type of novels as Nicholas Sparks.
112
+
113
+ • Fabricated Fact: Fabricating some random facts. For example, “Samuel Witwer’s father is a Lutheran minister.” Note that, the pretraining corpus contains non-factual or fictional information, which can also contribute to such fabricated facts.
114
+
115
+ Both error types can be viewed as wrong associations of entities that appear at different parts of the training corpus with similar context. Such behavior is unsurprising because these LMs are uniformly trained with the next subword prediction objective instead of a fact-related objective.
116
+
117
+ ![](images/3f577455231c4c50fa3cbd037053ec5b7812d49ff5f4c4dd5ba5bd135f433c9c.jpg)
118
+ Figure 2: Comparison between nucleus sampling (blue line) and factual-nucleus sampling (orange line). The $\mathbf { X }$ -axis is named entity error $\Nu \mathrm { E } _ { \mathrm { E R } }$ . The y-axes are diversity and repetition in (a) and (b) respectively. The lower the repetition, the better. It is evident that factual-nucleus sampling has better trade-offs between factuality and diversity/repetition. For a reference, the diversity score of randomly sampled 5000 Wikipedia documents is 0.767.
119
+
120
+ # 5 Factual-Nucleus Sampling
121
+
122
+ In this section, we propose a new sampling algorithm that achieves a better trade-off between generation quality and factuality than existing decoding algorithms.
123
+
124
+ # 5.1 Method
125
+
126
+ We hypothesize that the randomness of sampling is more harmful to factuality when it is used to generate the latter part of a sentence than the beginning of a sentence. There is no preceding text at the start of a sentence, so it is safe for LM to generate anything as long as it is grammatical and contextual. However, as the generation proceeds, the premise become more determined, and fewer word choices can make the sentence factual. Given the example “Samuel Witwer’s father is a Lutheran minister”, the beginning of the sentence “Samuel Witwer’s father is” is not nonfactual. However, the continuation of “Lutheran minister” makes the sentence nonfactual. Therefore, we introduce the factual-nucleus sampling algorithm that dynamically adapts the “nucleus” $p$ along the generation of each sentence. In factual-nucleus sampling, the nucleus probability $p _ { t }$ to generate the $t$ -th token within each sentence is,
127
+
128
+ $$
129
+ p _ { t } = \operatorname* { m a x } \{ \omega , p \times \lambda ^ { t - 1 } \} ,
130
+ $$
131
+
132
+ where $\lambda$ is the decay factor for top- $p$ probability, and $\omega$ lower bounds the decay of probability. Specifically, it has the following parts:
133
+
134
+ • $\lambda$ -decay: Given that top- $p$ sampling pool is selected as a set of subwords whose cumulative probability exceeds $p$ , we gradually decay the $p$ value with decay factor $\lambda$ at each generation step to reduce the “randomness” through time.
135
+ • $p$ -reset: The nucleus probability $p$ can quickly decay to a small value after a long generation. So, we reset the $p$ -value to the default value at the beginning of every new sentence in the generation (we identify the beginning of a new sentence by checking if the previous step has generated a full-stop). This reduces the unnecessary cost of diversity for any long generations.
136
+ • $\omega$ -bound: If $\lambda$ -decay is applied alone, the $p$ -value could become too small to be equivalent to greedy decoding and hurt diversity. To overcome this, we introduce a lower-bound $\omega$ to limit how far $p$ -value can be decayed.
137
+
138
+ We will show the importance of each parts with ablation studies.
139
+
140
+ # 5.2 Result
141
+
142
+ We report our decoding experimental results with $1 . 3 \mathrm { B } \mathrm { L M } ^ { 7 }$ in Table 4. Additions of $\lambda$ -decay helps improve top- $p \ : 0 . 9$ factuality results – for instance, with decay rate $\lambda = 0 . 5$ , there is $12 . 5 \%$ drop in $\mathrm { N E } _ { \mathrm { E R } }$ and $1 0 . 1 \%$ gain in EntailR. However, this affects the diversity and repetition to become similar to greedy decoding. $p$ -reset mitigates the repetition issue and improves diversity metric without losing much in factuality metric. The effect is more drastic for the $\lambda = 0 . 5$ option, where it achieves 0.26 gains in diversity metric with negligible changes in factuality scores. By also adding $\omega$ -bound, we obtain the anticipated factuality performance (i.e., similar to greedy decoding), with great improvement in generation quality over greedy; with $p { = } 0 . 9$ , $\lambda { = } 0 . 9$ , $\omega { = } 0 . 3$ , we achieve $\times 1 1$ improvement in diversity and $\times 4 . 6$ improvement in repetition over greedy. Although our factualnucleus sampling still under-performs top- $p 0 . 9$ in terms of diversity, we believe this is an acceptable trade-off to improve the factuality of LM for factually sensitive open-ended generation tasks. Our proposed decoding does not harm the sentence fluency; its perplexity do not exceed the perplexity of top-p. Refer to Appendix F for full perplexity results.
143
+
144
+ To further illustrate the underlying trade-off, we also compare the proposed factual-nucleus sampling against the nucleus sampling with lower $p$ values that are also expected to have lower randomness, thus less factual error, in generations. Specifically, we plotted results for nucleus sampling with $p = \{ 0 . 9 , 0 . 7 , 0 . 6 , 0 . 5 , 0 . 4 , \mathrm { { 0 . 3 } } \}$ , and factual nucleus sampling with the following $p \mid \lambda \mid \bar { \omega }$ choices: 0.9|0.9|0.7, 0.9|0.9|0.5, 0.9|0.9|0.4, 0.9|0.9|0.3, 0.9|0.7|0.3. The Fig 2a and $\mathrm { F i g 2 b }$ respectively show that the factual nucleus sampling method has better trade-offs than top- $p$ in factuality-vs-diversity and factuality-vs-repetition. In other words, it always achieves better factuality score with the same level of diversity and repetition scores.
145
+
146
+ # 6 Factuality-Enhanced Continued Training
147
+
148
+ This section introduces factuality-enhanced method for continued training of LMs [30]. We introduce the TOPICPREFIX for better awareness of facts and the sentence completion loss as training objective.
149
+
150
+ # 6.1 Prepending TOPICPREFIX
151
+
152
+ Unstructured factual knowledge typically exists at a document level (i.e., a group of factual sentences about an entity). This means that sentences can contain pronouns (e.g., she, he, it), making these sentences factually useless standalone. To illustrate with an example from Barack Obama’s Wikipedia page, “He previously served as a U.S. senator from Illinois from 2005 to $2 0 0 8 '$ cannot be a useful standalone fact because it is unclear who “He” is. Due to the GPU memory limit and computation efficiency, it is common to chunk documents in LM training corpus. This causes the “fragmentation” of information and leads to wrong associations of entities that appear in independent documents with similar contexts. As a remedy, we propose to prepend TOPICPREFIX to sentences in the factual documents to make each sentence serve as a standalone fact. In our experiments, we mainly utilize Wikipedia as the factual corpus and the Wikipedia document name as the TOPICPREFIX.
153
+
154
+ # 6.2 Sentence Completion Loss
155
+
156
+ We propose a sentence completion loss to address the incorrect association learned between entities. To explain our rationale, let us recall the nonfactual example from $\ S 5$ : “Samuel Witwer’s father is a Lutheran minister”. This sentence is nonfactual because LM failed to generate factually correct information after “is”. In other words, LM failed to accurately complete the sentence given the generated context. One reason is that the LM is uniformly trained to predict each subword token within the sentence, when ensuring the correct prediction at the latter section of sentence is more critical for factuality. Therefore, we construct a sentence completion loss, which makes the LM focus on predicting the subwords later in the sentence. For implementation, we determine a pivot $t$ for each sentence, and then apply zero-masking for all token prediction losses before $t$ . This pivot is only required during training (i.e., no pivot needed during inference time).
157
+
158
+ We emphasize that this loss masking is different from the input token masking applied in BERT [73] or BART [76], and the LM is still trained in an autoregressive manner. Note that many BART-based summarization models are known to still suffer from factual errors, suggesting that masked prediction at the encoder level may not effectively transfer well to autoregressive text generation.
159
+
160
+ In this work, we explore three strategies (from simple to complex) to determine the pivot $t$
161
+
162
+ • $S C _ { \mathrm { H A L F } }$ : pivot $t = 0 . 5 \times$ sentence-length.
163
+ • $S C _ { \mathrm { R A N D O M } }$ : random pivot, e.g., $t \sim$ uniform $[ 0 . 2 5 , 0 . 7 5 ] \times$ sentence-length.
164
+ • $S C _ { \mathrm { { R O O T } } }$ : pivot $t =$ position of ROOT (relation) from dependency parsing.
165
+
166
+ Our experiments show that the simplest $S C _ { \mathrm { H A L F } }$ performs on par with the complex ones (such as $S C _ { \mathrm { R O O T } } )$ ), thus, we suggest future work to choose $S C _ { \mathrm { H A L F } }$ strategy.
167
+
168
+ # 6.3 Results
169
+
170
+ The results are reported in Table 5, and experimental setups are reported in Appendix C.
171
+
172
+ Inefficiency of Domain Adaptive Training The pre-training corpus of LM contains both factual texts (e.g., Wikipedia) and potentially nonfactual texts (e.g., rumors, fake news) 8. The nonfactual domain of the training corpus could be the problem. Thus, we conduct a baseline experiment that does domain-adaptive training with strictly factual domain text only (i.e., Wikipedia). Interestingly, we find that domain-adaptive training can hardly improve generation factuality.
173
+
174
+ Effect of TOPICPREFIX Continued pre-training of 1.3B LM with TOPICPREFIX preprocessed Wikipedia alone can already improve the factuality, especially in terms of $\mathrm { N E } _ { \mathrm { E R } }$ . For example, it reduces the $\mathrm { N E _ { E R } f r o m 4 2 . 1 \% }$ to $2 7 . 6 \%$ when we use the factual-nucleus decoding $( 0 . 9 \mid 0 . 9 \mid 0 . 3 )$ , which even outperforms the 1.3B with greedy decoding $( \mathrm { N E } _ { \mathrm { E R } } \colon 2 7 . 6 \%$ vs. $3 9 . 9 \%$ ) with much less repetition $( 8 . 0 \%$ vs. $3 3 . 1 \%$ ).
175
+
176
+ Effect of Sentence Completion Loss The proposed sentence completion loss further helps to improve the factuality, especially for the EntailR. For example, when one uses factual-nucleus decoding on trained 1.3B model, TOPICPREFIX $+ \ S C _ { \mathrm { H A L F } }$ can further improve EntailR from $8 . 7 \%$ to $1 7 . 4 \%$ than TOPICPREFIX alone, while reducing $\Nu \mathrm { E } _ { \mathrm { E R } }$ from $2 7 . 6 \%$ to $2 3 . 6 \%$ . Note that the results show consistent improvement across different pivot selection strategies, suggesting that the sentence completion loss is robust. In particular, the simplest $S C _ { \mathrm { H A L F } }$ performs as good as others or even better in terms of several metrics. Thus we recommend it as the default option.
177
+
178
+ Table 5: Results for factuality enhanced training. The decoding settings are formatted as: nucleus probability $p$ decay rate $\lambda$ , lower-bound $\omega$ .
179
+
180
+ <table><tr><td rowspan="2">Decoding (plλlw)</td><td colspan="4">Factual Prompt</td><td colspan="4">Nonfactual Prompt</td></tr><tr><td>NEER↓</td><td>EntailR↑</td><td>Div.</td><td>Rep.</td><td>NEER</td><td>EntailR</td><td>Div.</td><td>Rep.</td></tr><tr><td colspan="9">Vanilla Pretrained LM (1.3B)</td></tr><tr><td>0.9</td><td>52.4%</td><td>2.9%</td><td>0.88</td><td>0.2%</td><td>56.8%</td><td>2.0%</td><td>0.89</td><td>0.3%</td></tr><tr><td>0.9 10.910.3</td><td>42.1%</td><td>10.1%</td><td>0.55</td><td>7.1%</td><td>46.5%</td><td>5.6%</td><td>0.59</td><td>6.4%</td></tr><tr><td colspan="9">Factual Domain-Adaptive Training with Wikipedia (1.3B)</td></tr><tr><td>0.9</td><td>52.5%</td><td>2.8%</td><td>0.85</td><td>0.2%</td><td>55.8%</td><td>2.2%</td><td>0.86</td><td>0.1%</td></tr><tr><td>0.910.9 10.3</td><td>42.7%</td><td>7.1%</td><td>0.51</td><td>7.2%</td><td>48.2%</td><td>4.9%</td><td>0.56</td><td>6.0%</td></tr><tr><td colspan="9">TOPICPREFIX (1.3B)</td></tr><tr><td>0.9 0.910.910.3</td><td>34.4%</td><td>4.2%</td><td>0.84</td><td>0.3%</td><td>36.2%</td><td>2.7%</td><td>0.85</td><td>0.2%</td></tr><tr><td></td><td>27.6%</td><td>8.7%</td><td>0.43</td><td>8.0%</td><td>30.5%</td><td>6.1%</td><td>0.47</td><td>6.9%</td></tr><tr><td colspan="9">TOPICPREFIX + SCROOT (1.3B)</td></tr><tr><td>0.9 0.9 10.9 10.3</td><td>32.5% 24.7%</td><td>6.7% 15.8%</td><td>0.83 0.40</td><td>1.2% 13.6%</td><td>34.3% 27.6%</td><td>4.6% 9.1%</td><td>0.84 0.44</td><td>1.1% 13.7%</td></tr><tr><td colspan="9">TOPICPREFIX+ SCRANDOM (1.3B)</td></tr><tr><td>0.9 0.9 10.9 10.3</td><td>32.0% 23.6%</td><td>7.9% 17.6%</td><td>0.81 0.39</td><td>1.2% 14.2%</td><td>34.2% 26.9%</td><td>5.5% 9.3%</td><td>0.83 0.42</td><td>1.1% 13.2%</td></tr><tr><td colspan="9">TOPICPREFIX + SCHALF</td></tr><tr><td>0.9</td><td>31.6%</td><td>7.6% 17.4%</td><td>0.81 0.38</td><td>1.4% 14.4%</td><td>33.5% 27.2%</td><td>5.1% 10.2%</td><td>0.83 0.42</td><td>1.5% 13.1%</td></tr><tr><td colspan="9">0.9 10.9 10.3 23.6% Vanilla Pretrained LM (530B)</td></tr><tr><td>0.9</td><td>33.3%</td><td>11.8%</td><td>0.90</td><td>0.1%</td><td>40.5%</td><td>7.25%</td><td>0.92</td><td>0.1%</td></tr><tr><td colspan="9">TOPICPREFIX + SCHALF (530B)</td></tr><tr><td>0.9 0.9 10.9 10.3</td><td>18.3% 14.5%</td><td>19.3% 25.5%</td><td>0.68 0.33</td><td>0.1% 0.2%</td><td>21.7% 17.7%</td><td>13.7% 20.0%</td><td>0.68</td><td>0.1%</td></tr></table>
181
+
182
+ 530B vs 1.3B As expected, our method on 530B LM further reduces the factual errors and achieves the lowest $\Nu \mathrm { E } _ { \mathrm { E R } }$ $( 1 4 . 5 \% )$ and the highest EntailR $( 2 5 . 5 \% )$ . Surprisingly, our method on 530B LM lead to less diverse generation than 1.3B LM despite the significant improvement in the generation quality (i.e., near perfect repetition scores $0 . 1 \% 0 . 2 \%$ . We conjecture that this is the trade-off between the factuality and diversity for 530B LM.
183
+
184
+ # 7 Conclusion
185
+
186
+ In this work, we establish a benchmark to measure and analyze factuality in open-ended text generation tasks. We propose factual-nucleus sampling that improves generation factuality at inference time, and the combination of sentence completion loss and TOPICPREFIX pre-processing that improves factuality with continued training. We demonstrate that our methods are effective in improving the factuality. Lastly, our results shed light on the existence of the trade-off between diversity and factuality. We strongly believe this is an important insight that will help researchers make a better-informed decision about their model design - i.e., appropriately prioritize the desirable attribute of their LM (factuality vs. diversity) according to the final goal of their task. Potential future work would be to reduce the degree of the observed trade-offs.
187
+
188
+ References
189
+ [1] Alec Radford, Jeffrey Wu, Rewon Child, David Luan, Dario Amodei, Ilya Sutskever, et al. Language models are unsupervised multitask learners. OpenAI blog, 2019.
190
+ [2] Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, and Peter J Liu. Exploring the limits of transfer learning with a unified text-to-text transformer. JMLR, 2019.
191
+ [3] Tom Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah, Jared D Kaplan, Prafulla Dhariwal, Arvind Neelakantan, Pranav Shyam, Girish Sastry, Amanda Askell, et al. Language models are few-shot learners. In NeurIPS, 2020.
192
+ [4] Shaden Smith, Mostofa Patwary, Brandon Norick, Patrick LeGresley, Samyam Rajbhandari, Jared Casper, Zhun Liu, Shrimai Prabhumoye, George Zerveas, Vijay Korthikanti, et al. Using DeepSpeed and Megatron to train Megatron-Turing NLG 530B, a large-scale generative language model. arXiv preprint arXiv:2201.11990, 2022.
193
+ [5] Rico Sennrich, Barry Haddow, and Alexandra Birch. Neural machine translation of rare words with subword units. In ACL, 2016.
194
+ [6] Jack W Rae, Sebastian Borgeaud, Trevor Cai, Katie Millican, Jordan Hoffmann, Francis Song, John Aslanides, Sarah Henderson, Roman Ring, Susannah Young, et al. Scaling language models: Methods, analysis & insights from training gopher. arXiv preprint arXiv:2112.11446, 2021.
195
+ [7] Reiichiro Nakano, Jacob Hilton, Suchir Balaji, Jeff Wu, Long Ouyang, Christina Kim, Christopher Hesse, Shantanu Jain, Vineet Kosaraju, William Saunders, et al. WebGPT: Browser-assisted question-answering with human feedback. arXiv preprint arXiv:2112.09332, 2021.
196
+ [8] Susan Zhang, Stephen Roller, Naman Goyal, Mikel Artetxe, Moya Chen, Shuohui Chen, Christopher Dewan, Mona Diab, Xian Li, Xi Victoria Lin, et al. Opt: Open pre-trained transformer language models. arXiv preprint arXiv:2205.01068, 2022.
197
+ [9] Rowan Zellers, Ari Holtzman, Hannah Rashkin, Yonatan Bisk, Ali Farhadi, Franziska Roesner, and Yejin Choi. Defending against neural fake news. In NeurIPS, 2019.
198
+ [10] Romal Thoppilan, Daniel De Freitas, Jamie Hall, Noam Shazeer, Apoorv Kulshreshtha, Heng-Tze Cheng, Alicia Jin, Taylor Bos, Leslie Baker, Yu Du, et al. LaMDA: Language models for dialog applications. arXiv preprint arXiv:2201.08239, 2022.
199
+ [11] Ziwei Ji, Nayeon Lee, Rita Frieske, Tiezheng Yu, Dan Su, Yan Xu, Etsuko Ishii, Yejin Bang, Andrea Madotto, and Pascale Fung. Survey of hallucination in natural language generation. arXiv preprint arXiv:2202.03629, 2022.
200
+ [12] Wojciech Krysci ´ nski, Bryan McCann, Caiming Xiong, and Richard Socher. Evaluating the factual ´ consistency of abstractive text summarization. In EMNLP, 2019.
201
+ [13] Joshua Maynez, Shashi Narayan, Bernd Bohnet, and Ryan McDonald. On faithfulness and factuality in abstractive summarization. In ACL, 2020.
202
+ [14] Esin Durmus, He He, and Mona Diab. FEQA: A question answering evaluation framework for faithfulness assessment in abstractive summarization. In ACL, 2020.
203
+ [15] Feng Nan, Cicero Nogueira dos Santos, Henghui Zhu, Patrick Ng, Kathleen McKeown, Ramesh Nallapati, Dejiao Zhang, Zhiguo Wang, Andrew O Arnold, and Bing Xiang. Improving factual consistency of abstractive summarization via question answering. In ACL-IJCNLP, 2021.
204
+ [16] Jun Yin, Xin Jiang, Zhengdong Lu, Lifeng Shang, Hang Li, and Xiaoming Li. Neural generative question answering. In IJCAI, 2016.
205
+ [17] Adam Roberts, Colin Raffel, and Noam Shazeer. How much knowledge can you pack into the parameters of a language model? arXiv preprint arXiv:2002.08910, 2020.
206
+ [18] Dan Su, Xiaoguang Li, Jindi Zhang, Lifeng Shang, Xin Jiang, Qun Liu, and Pascale Fung. Read before generate! faithful long form question answering with machine reading. In Findings in ACL, 2022.
207
+ [19] Amit Moryossef, Yoav Goldberg, and Ido Dagan. Step-by-step: Separating planning from realization in neural data-to-text generation. arXiv preprint arXiv:1904.03396, 2019.
208
+ [20] Tianyu Liu, Xin Zheng, Baobao Chang, and Zhifang Sui. Towards faithfulness in open domain table-to-text generation from an entity-centric view. In AAAI, 2021.
209
+ [21] Wenhao Yu, Chenguang Zhu, Zaitang Li, Zhiting Hu, Qingyun Wang, Heng Ji, and Meng Jiang. A survey of knowledge-enhanced text generation. arXiv preprint arXiv:2010.04389, 2020.
210
+ [22] Aleksandra Piktus, Fabio Petroni, Vladimir Karpukhin, Dmytro Okhonko, Samuel Broscheit, Gautier Izacard, Patrick Lewis, Barlas Oguz, Edouard Grave, Wen-tau Yih, et al. The web is your oyster–knowledge- ˘ intensive nlp against a very large web corpus. arXiv preprint arXiv:2112.09924, 2021.
211
+ [23] Peter West, Chris Quirk, Michel Galley, and Yejin Choi. Probing factually grounded content transfer with factual ablation. arXiv preprint arXiv:2203.10133, 2022.
212
+ [24] Sungjin Ahn, Heeyoul Choi, Tanel Pärnamaa, and Yoshua Bengio. A neural knowledge language model. arXiv preprint arXiv:1608.00318, 2016.
213
+ [25] Robert L Logan IV, Nelson F Liu, Matthew E Peters, Matt Gardner, and Sameer Singh. Barack’s wife hillary: Using knowledge-graphs for fact-aware language modeling. In ACL, 2019.
214
+ [26] Sebastian Borgeaud, Arthur Mensch, Jordan Hoffmann, Trevor Cai, Eliza Rutherford, Katie Millican, George van den Driessche, Jean-Baptiste Lespiau, Bogdan Damoc, Aidan Clark, et al. Improving language models by retrieving from trillions of tokens. arXiv preprint arXiv:2112.04426, 2021.
215
+ [27] Fabio Petroni, Aleksandra Piktus, Angela Fan, Patrick Lewis, Majid Yazdani, Nicola De Cao, James Thorne, Yacine Jernite, Vladimir Karpukhin, Jean Maillard, et al. Kilt: a benchmark for knowledge intensive language tasks. arXiv preprint arXiv:2009.02252, 2020.
216
+ [28] Kelvin Guu, Kenton Lee, Zora Tung, Panupong Pasupat, and Ming-Wei Chang. Realm: Retrievalaugmented language model pre-training. arXiv preprint arXiv:2002.08909, 2020.
217
+ [29] Ari Holtzman, Jan Buys, Li Du, Maxwell Forbes, and Yejin Choi. The curious case of neural text degeneration. In ICLR, 2020.
218
+ [30] Suchin Gururangan, Ana Marasovic, Swabha Swayamdipta, Kyle Lo, Iz Beltagy, Doug Downey, and ´ Noah A Smith. Don’t stop pretraining: adapt language models to domains and tasks. In ACL, 2020.
219
+ [31] Stephanie Lin, Jacob Hilton, and Owain Evans. TruthfulQA: Measuring how models mimic human falsehoods. In ACL, 2022.
220
+ [32] David R Krathwohl. A revision of bloom’s taxonomy: An overview. Theory into practice, 41(4):212–218, 2002.
221
+ [33] Fabio Petroni, Tim Rocktäschel, Patrick Lewis, Anton Bakhtin, Yuxiang Wu, Alexander H Miller, and Sebastian Riedel. Language models as knowledge bases? In EMNLP, 2019.
222
+ [34] Carlos Aspillaga, Marcelo Mendoza, and Alvaro Soto. Inspecting the concept knowledge graph encoded by modern language models. In Findings of ACL, 2021.
223
+ [35] Xuhui Zhou, Yue Zhang, Leyang Cui, and Dandan Huang. Evaluating commonsense in pre-trained language models. In AAAI, 2020.
224
+ [36] Zhengbao Jiang, Frank F Xu, Jun Araki, and Graham Neubig. How can we know what language models know? Transactions of the Association for Computational Linguistics, 2020.
225
+ [37] Zexuan Zhong, Dan Friedman, and Danqi Chen. Factual probing is [mask]: Learning vs. learning to recall. arXiv preprint arXiv:2104.05240, 2021.
226
+ [38] Yanai Elazar, Nora Kassner, Shauli Ravfogel, Abhilasha Ravichander, Eduard Hovy, Hinrich Schütze, and Yoav Goldberg. Measuring and improving consistency in pretrained language models. Transactions of the Association for Computational Linguistics, 9:1012–1031, 2021.
227
+ [39] Nicola De Cao, Wilker Aziz, and Ivan Titov. Editing factual knowledge in language models. In EMNLP, 2021.
228
+ [40] Joel Jang, Seonghyeon Ye, Sohee Yang, Joongbo Shin, Janghoon Han, Gyeonghun Kim, Stanley Jungkyu Choi, and Minjoon Seo. Towards continual knowledge learning of language models. arXiv preprint arXiv:2110.03215, 2021.
229
+ [41] Kevin Meng, David Bau, Alex Andonian, and Yonatan Belinkov. Locating and editing factual knowledge in GPT. arXiv preprint arXiv:2202.05262, 2022.
230
+
231
+ [42] Ziqiang Cao, Furu Wei, Wenjie Li, and Sujian Li. Faithful to the original: Fact aware neural abstractive summarization. In Proceedings of the AAAI Conference on Artificial Intelligence, 2018.
232
+
233
+ [43] Yue Dong, Shuohang Wang, Zhe Gan, Yu Cheng, Jackie Chi Kit Cheung, and Jingjing Liu. Multi-fact correction in abstractive text summarization. In Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing, pages 9320–9331, 2020.
234
+
235
+ [44] Luyang Huang, Lingfei Wu, and Lu Wang. Knowledge graph-augmented abstractive summarization with semantic-driven cloze reward. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics, 2020.
236
+
237
+ [45] Yichong Huang, Xiachong Feng, Xiaocheng Feng, and Bing Qin. The factual inconsistency problem in abstractive text summarization: A survey. arXiv preprint arXiv:2104.14839, 2021.
238
+
239
+ [46] Shuyang Cao and Lu Wang. Cliff: Contrastive learning for improving faithfulness and factuality in abstractive summarization. In Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing, pages 6633–6649, 2021.
240
+
241
+ [47] Chenguang Zhu, William Hinthorn, Ruochen Xu, Qingkai Zeng, Michael Zeng, Xuedong Huang, and Meng Jiang. Enhancing factual consistency of abstractive summarization. In Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, pages 718–733, 2021.
242
+
243
+ [48] Sihao Chen, Fan Zhang, Kazoo Sone, and Dan Roth. Improving faithfulness in abstractive summarization with contrast candidate generation and selection. In Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, pages 5935–5941, 2021.
244
+
245
+ [49] Sam Wiseman, Stuart Shieber, and Alexander Rush. Challenges in data-to-document generation. In Proceedings of the 2017 Conference on Empirical Methods in Natural Language Processing, pages 2253–2263. ACL, 2017.
246
+
247
+ [50] Feng Nie, Jin-Ge Yao, Jinpeng Wang, Rong Pan, and Chin-Yew Lin. A simple recipe towards reducing hallucination in neural surface realisation. In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics, pages 2673–2679. ACL, 2019.
248
+
249
+ [51] Yixuan Su, David Vandyke, Sihui Wang, Yimai Fang, and Nigel Collier. Plan-then-generate: Controlled data-to-text generation via planning. Findings of EMNLP, 2021.
250
+
251
+ [52] Peng Wang, Junyang Lin, An Yang, Chang Zhou, Yichang Zhang, Jingren Zhou, and Hongxia Yang. Sketch and refine: Towards faithful and informative table-to-text generation. ACL, 2021.
252
+
253
+ [53] Clément Rebuffel, Marco Roberti, Laure Soulier, Geoffrey Scoutheeten, Rossella Cancelliere, and Patrick Gallinari. Controlling hallucinations at word level in data-to-text generation. Data Mining and Knowledge Discovery, pages 318–354, 2022.
254
+
255
+ [54] Lei Shen, Haolan Zhan, Xin Shen, Hongshen Chen, Xiaofang Zhao, and Xiaodan Zhu. Identifying untrustworthy samples: Data filtering for open-domain dialogues with bayesian optimization. In Proceedings of the 30th ACM International Conference on Information & Knowledge Management, pages 1598–1608, 2021.
256
+
257
+ [55] Kurt Shuster, Spencer Poff, Moya Chen, Douwe Kiela, and Jason Weston. Retrieval augmentation reduces hallucination in conversation. In Findings of the Association for Computational Linguistics: EMNLP 2021. ACL, 2021.
258
+
259
+ [56] Hannah Rashkin, David Reitter, Gaurav Singh Tomar, and Dipanjan Das. Increasing faithfulness in knowledge-grounded dialogue with controllable features. In Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing, pages 704–718. ACL, 2021.
260
+
261
+ [57] Zeqiu Wu, Michel Galley, Chris Brockett, Yizhe Zhang, Xiang Gao, Chris Quirk, Rik Koncel-Kedziorski, Jianfeng Gao, Hannaneh Hajishirzi, Mari Ostendorf, et al. A controllable model of grounded response generation. In Proceedings of the AAAI Conference on Artificial Intelligence, pages 14085–14093, 2021.
262
+
263
+ [58] Nouha Dziri, Andrea Madotto, Osmar Zaiane, and Avishek Joey Bose. Neural path hunter: Reducing hallucination in dialogue systems via path grounding. EMNLP, 2021.
264
+
265
+ [59] Long Ouyang, Jeff Wu, Xu Jiang, Diogo Almeida, Carroll L Wainwright, Pamela Mishkin, Chong Zhang, Sandhini Agarwal, Katarina Slama, Alex Ray, et al. Training language models to follow instructions with human feedback. arXiv preprint arXiv:2203.02155, 2022.
266
+
267
+ [60] Krishna Pillutla, Swabha Swayamdipta, Rowan Zellers, John Thickstun, Sean Welleck, Yejin Choi, and Zaid Harchaoui. MAUVE: Measuring the gap between neural text and human text using divergence frontiers. In NeurIPS, 2021.
268
+
269
+ [61] Samuel Gehman, Suchin Gururangan, Maarten Sap, Yejin Choi, and Noah A Smith. Realtoxicityprompts: Evaluating neural toxic degeneration in language models. In Findings in EMNLP, 2020.
270
+
271
+ [62] Nils Reimers and Iryna Gurevych. Sentence-bert: Sentence embeddings using siamese bert-networks. arXiv preprint arXiv:1908.10084, 2019.
272
+
273
+ [63] Ben Goodrich, Vinay Rao, Peter J Liu, and Mohammad Saleh. Assessing the factual accuracy of generated text. In ACM SIGKDD, 2019.
274
+
275
+ [64] Feng Nan, Ramesh Nallapati, Zhiguo Wang, Cicero Nogueira dos Santos, Henghui Zhu, Dejiao Zhang, Kathleen McKeown, and Bing Xiang. Entity-level factual consistency of abstractive text summarization. In EACL, 2021.
276
+
277
+ [65] Bill MacCartney and Christopher D. Manning. Modeling semantic containment and exclusion in natural language inference. In Proceedings of the 22nd International Conference on Computational Linguistics (Coling 2008), pages 521–528, Manchester, UK, August 2008. Coling 2008 Organizing Committee. URL https://aclanthology.org/C08-1066.
278
+
279
+ [66] Tobias Falke, Leonardo FR Ribeiro, Prasetya Ajie Utama, Ido Dagan, and Iryna Gurevych. Ranking generated summaries by correctness: An interesting but challenging application for natural language inference. In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics, pages 2214–2220, 2019.
280
+
281
+ [67] Ondˇrej Dušek and Zdenek Kasner. Evaluating semantic accuracy of data-to-text generation with natural ˇ language inference. arXiv preprint arXiv:2011.10819, 2020.
282
+
283
+ [68] Nouha Dziri, Hannah Rashkin, Tal Linzen, and David Reitter. Evaluating groundedness in dialogue systems: The begin benchmark. arXiv preprint arXiv:2105.00071, 2021.
284
+
285
+ [69] 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.
286
+
287
+ [70] Adina Williams, Nikita Nangia, and Samuel Bowman. A broad-coverage challenge corpus for sentence understanding through inference. In NAACL, 2018.
288
+
289
+ [71] Jiwei Li, Michel Galley, Chris Brockett, Jianfeng Gao, and Bill Dolan. A diversity-promoting objective function for neural conversation models. In NAACL, 2016.
290
+
291
+ [72] Zhihong Shao, Minlie Huang, Jiangtao Wen, Wenfei Xu, and Xiaoyan Zhu. Long and diverse text generation with planning-based hierarchical variational model. arXiv preprint arXiv:1908.06605, 2019.
292
+
293
+ [73] 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.
294
+
295
+ [74] Boxin Wang, Wei Ping, Chaowei Xiao, Peng Xu, Mostofa Patwary, Mohammad Shoeybi, Bo Li, Anima Anandkumar, and Bryan Catanzaro. Exploring the limits of domain-adaptive training for detoxifying large-scale language models. In NeurIPS, 2022.
296
+
297
+ [75] Eric Wallace, Shi Feng, Nikhil Kandpal, Matt Gardner, and Sameer Singh. Universal adversarial triggers for attacking and analyzing nlp. In EMNLP, 2019.
298
+
299
+ [76] Mike Lewis, Yinhan Liu, Naman Goyal, Marjan Ghazvininejad, Abdelrahman Mohamed, Omer Levy, Ves Stoyanov, and Luke Zettlemoyer. Bart: Denoising sequence-to-sequence pre-training for natural language generation, translation, and comprehension. arXiv preprint arXiv:1910.13461, 2019.
300
+
301
+ [77] Mohammad Shoeybi, Mostofa Patwary, Raul Puri, Patrick LeGresley, Jared Casper, and Bryan Catanzaro. Megatron-lm: Training multi-billion parameter language models using model parallelism. arXiv preprint arXiv:1909.08053, 2019.
302
+
303
+ [78] James Thorne, Andreas Vlachos, Christos Christodoulopoulos, and Arpit Mittal. FEVER: a large-scale dataset for fact extraction and verification. In NAACL, 2018.
md/dev/N8MaByOzUfb/N8MaByOzUfb.md ADDED
@@ -0,0 +1,492 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # NEW INSIGHTS ON REDUCING ABRUPT REPRESENTA-TION CHANGE IN ONLINE CONTINUAL LEARNING
2
+
3
+ Lucas Caccia∗ McGill University, Mila Facebook AI Research
4
+
5
+ Rahaf Aljundi Toyota Motor Europe
6
+
7
+ Nader Asadi Concordia University, Mila
8
+
9
+ Tinne Tuytelaars KU Leuven
10
+
11
+ Joelle Pineau McGill University, Mila Facebook AI Research
12
+
13
+ Eugene Belilovsky Concordia University, Mila
14
+
15
+ # ABSTRACT
16
+
17
+ In the online continual learning paradigm, agents must learn from a changing distribution while respecting memory and compute constraints. Experience Replay (ER), where a small subset of past data is stored and replayed alongside new data, has emerged as a simple and effective learning strategy. In this work, we focus on the change in representations of observed data that arises when previously unobserved classes appear in the incoming data stream, and new classes must be distinguished from previous ones. We shed new light on this question by showing that applying ER causes the newly added classes’ representations to overlap significantly with the previous classes, leading to highly disruptive parameter updates. Based on this empirical analysis, we propose a new method which mitigates this issue by shielding the learned representations from drastic adaptation to accommodate new classes. We show that using an asymmetric update rule pushes new classes to adapt to the older ones (rather than the reverse), which is more effective especially at task boundaries, where much of the forgetting typically occurs. Empirical results show significant gains over strong baselines on standard continual learning benchmarks 1
18
+
19
+ # 1 INTRODUCTION
20
+
21
+ Continual learning is concerned with building models that can learn and accumulate knowledge and skills over time. A continual learner receives training data sequentially, from a potentially changing distribution, over the course of its learning process. The distribution change might be either a shift in the input domain or new categories being learned. The main challenge is to design models that can learn how to use the new data and acquire new knowledge, while preserving or improving the performance on previously learned data. While different settings have been investigated of how new data are being received and learned, we focus on the challenging scenario of learning from an online stream of data with new classes being introduced at unknown points in time and where memory and compute constraints are applied on the learner. Additionally, we assume a shared output layer among all the learned classes (Aljundi et al., 2019b). This setting is different and harder than the conventional multi-head setting (Farquhar & Gal, 2018) where each new group of classes is considered as a new task with a dedicated head (classification layer), requiring a task oracle at test time to activate the correct head. The axes of our setting (online learning, no task boundary, no test time oracle, constant memory, and bounded compute) align with the main desiderata of continual learning as described in De Lange et al. (2019).
22
+
23
+ Catastrophic forgetting (McCloskey & Cohen, 1989), where previous knowledge is overwritten as new concepts are learned, remains a key challenge in the online continual learning setting. To prevent forgetting, methods usually rely on storing a small buffer of previous training data and replaying samples from it as new data is learned. This can partially counteract catastrophic forgetting, but still tends to lead to large disruptions in accuracy, particularly at the initial task boundary or shift in distribution. Various works focus on studying which samples to store (Borsos et al., 2020; Aljundi et al., 2019b) or which samples to replay when receiving new data (Aljundi et al., 2019a). In this work, we direct our attention to the representations being learned and investigate how the features of previously learned classes change and drift over time.
24
+
25
+ ![](images/68d175c0aef3020adedfdacd3ae45ae5fab533000ef553db3c59d39500897f80.jpg)
26
+
27
+ ![](images/c8a034f37bb226e9e2d798543b4c58e511d34d24f250c3b627a11d1ae62d3b38.jpg)
28
+ Task 1 Accuracy during 2nd Task
29
+ Number of training steps on the 2nd task
30
+ Figure 1: (left) Analysis of representations with the first task’s class prototypes at a task boundary. Under ER when Task 2 begins, class 1 & 2 prototypes experience a large gradient and subsequent displacement caused by the close location of the unobserved sample representations, this leads to a significant drop in performance (right). Our proposed method (ACE) mitigates the representation drift issue and observes no performance decrease on a task switch.
31
+
32
+ Consider the time point in a stream when a new class is introduced after previous classes have been well learned. If we consider the representation being learned, incoming samples from new classes are likely to be dispersed, potentially near and between representations of previous classes, while the representations of previous classes will typically cluster according to their class. Indeed, one might expect minimal changes to the learned representation of the previous classes, while the new classes samples are pushed away from the clusters of old class data. However, with a standard Experience Replay (ER) algorithm (Chaudhry et al., 2019), we observe that it is the representations of older classes that is heavily perturbed after just a few update steps when training on the new class samples. We hypothesize that the fundamental issue arises from the combination of: new class samples representations lying close to older classes and the loss structure of the standard cross entropy applied on a mix of seen and unseen classes. We illustrate the observed effect in Fig. 1 (left).
33
+
34
+ This behavior is exacerbated especially in the regime of low buffer size. With larger replay buffers, the learner can recover knowledge about the prior classes over time, while with smaller buffers the initial disruptive changes in representations are challenging to correct. Indeed we illustrate this effect in Fig. 1 (right), we see that ER only recovers from the initial displacement given a much larger buffer size.
35
+
36
+ In standard continual learning with replay (Aljundi et al., 2019a; Chaudhry et al., 2019) the same loss function is usually employed on both the newly received samples and the replayed samples. In contrast, we propose a simple and efficient solution to mitigate this representation drift by using separate losses on the incoming stream and buffered data. The key idea is to allow the representations of samples from new classes to be learned in isolation of the older ones first, by excluding the previously learned classes from the incoming data loss. The discrimination between the new classes and the older ones is learned through the replayed batches, but only after incoming data has been learned, added to the buffer, and made available for replay. To allow more direct control of the structure in representations we first consider a metric learning based loss for the incoming data, proposed in Khosla et al. (2020), where we propose to exclude samples of previously learned classes from the negative samples. We show that this type of negative selection is critical, and in contrast issues arise when negative examples are sampled uniformly from the buffer. These issues mimic those seen with standard losses in experience replay (ER) (Aljundi et al., 2019a). On the other hand we use a different loss on replay buffer data that is allowed to consider new and old classes, thereby consolidating knowledge across current and previous tasks. We call this overall approach ER with asymmetric metric learning (ER-AML).
37
+
38
+ Since cross entropy losses can be more efficient in training for classification than metric learning and contrastive losses (avoiding positive and negative selection) and it is widely used in incremental and continual learning, we also propose an alternative cross entropy solution that similarly applies an asymmetric loss between incoming and replay data. Notably, the cross entropy applied to the incoming data only considers logits of classes of the incoming data. This variant, named ER with asymmetric cross-entropy (ER-ACE), along with ER-AML show strong performance, with little disruption at task boundaries Fig. 1 (right). We achieve state of the art results in existing benchmarks while beating different existing methods including the traditional ER solution with an average relative gain of $36 \%$ in accuracy. Our improvements are especially high in the small buffer regime. We also show that the mitigation of the old representation drift does not hinder the ability to learn and discriminate the new classes from the old ones. This property emerges from only learning the incoming data in isolation; as we will see, also isolating the rehearsal step (as in Ahn et al. (2020)) leads to poor knowledge acquisition on the current task. Furthermore we show our ER-ACE objective can be combined with existing methods, leading to additional gains. Finally, we take a closer look at the computation cost of various existing methods. We show that some methods, while obtaining good performance under standard evaluation protocols, fail to meet the computational constraints required in online CL. We provide an extensive evaluation of computational and memory costs across several baselines and metrics.
39
+
40
+ To summarize, our contributions are as follows. We first highlight the problem of representation drift in the online continual learning setting. We identify a root cause of this issue through an extensive empirical analysis (Sec. 4.2). Second, we propose a new family of methods addressing this issue by treating incoming and past data asymmetrically (Sec. 4.1, 4.3) . Finally, we show strong gains over replay baselines in a new evaluation framework designed to monitor real world constraints (Sec. 5). To the best or our knowledge, we are the first to report the computation costs of different methods in our setting, revealing new insights.
41
+
42
+ # 2 RELATED WORK
43
+
44
+ Research on continual learning can be divided based on the sequential setting being targeted (see Zeno et al. (2018); van de Ven & Tolias (2019); Normandin et al. (2021); Lesort et al. (2021) for categorizations of the settings and De Lange et al. (2019) for a broad survey on continual learning). Earlier works consider the relaxed setting of task incremental learning (Aljundi et al., 2017; Serra\` et al., 2018; Li & Hoiem, 2016) where the data stream is divided into chunks of tasks and each task is learned offline with multiple iterations over the data of this task. While this setting is easier to handle as one task can be learned entirely, it limits the applicability of the solution.
45
+
46
+ In this work, we consider the challenging setting of an online stream of non-i.i.d. data where changes can anytime occur in the input domain or in the output space. This more realistic setting has attracted increasing interest lately (Lopez-Paz et al., 2017; Aljundi et al., 2019a). Specifically, we study the single-head (or shared head) setting, where when queried, the learner is not told which task the sample belongs to (as opposed to the multi-head setting). The single-head assumption is further studied in task-agnostic continual learning settings (He et al., 2019; Caccia et al., 2020; Ostapenko et al., 2021; Von Oswald et al., 2021) in which the task-boundary assumption, amongst others, is also relaxed. Many of the solutions to the online continual learning problem rely on the use of a buffer formed of previous memories which are replayed alongside new data during the learning process. Several works (Borsos et al., 2020; Chaudhry et al., 2019; Aljundi et al., 2019b) propose solutions to select which samples should be stored, or retrieved for replay (Aljundi et al., 2019a), or both (Shim et al., 2021). Lopez-Paz et al. (2017); Chaudhry et al. use replay to perform constrained optimization, limiting interference with previous tasks as new ones are learned. Our work, on the other hand, focuses on the appropriate loss function in this context. Tang & Matteson (2020) propose a graph-based approach that capture pairwise similarities between samples. Dark Experience Replay (DER) (Buzzega et al., 2020) suggests an alternative replay loss. Samples are stored along with their predicted logits and once replayed the current model is asked to keep its output close to the previously recorded logits. While the method is simple and effective it is worth noting that it relies heavily on data augmentation. Our work is orthogonal and can be combined with DER as we show in Sec. D. Finally, concurrent work (Mai et al., 2021) also use a contrastive loss for online continual learning, but not in an asymmetric fashion.
47
+
48
+ In our work we also investigate the underlying causes for performance degradation in replay-based methods. Related to this study are works in the class incremental setting, where similar to our case a shared output layer is used, but classes are learned offline. Works in this area address the implicit class imbalance issue occurring when new classes are learned alongside replayed data. Zhao et al.
49
+
50
+ (2019) proposes to correct last layer weights after a group of classes is learned via adjusting the weights norm. Wu et al. (2019) suggests to deploy extra additional parameters in order to linearly correct the “bias” in the shared output layer. Those parameters are learned at the end of each training phase. Hou et al. (2019) considers addressing this imbalance through applying cosine similarity based loss as opposed to the typical cross entropy loss along with a distillation loss and a margin based loss with negatives mining to preserve the feature of previous classes. Recently, Ahn et al. (2020) propose to learn the incoming tasks and the previous tasks separately. They use a masked softmax loss for the incoming and rehearsal data, to counter the class imbalance. All the methods highlighted above operate in the offline setting, where data from the current task can be revisited as needed making the disruptive issues emphasized at the task boundary less critical. In this paper, we focus on the online setting, with potentially overlapping tasks. As we will see, work by Ahn et al. (2020) developed to counter class imbalance, can inhibit learning of the current task in the online setting (see Appendix B). Lastly, Zeno et al. (2018) uses a logit masking related to our method but their context is based on the multi-head setting, and does not consider replay based methods, where learning across tasks occurs. Their goal is to activate only the head of which the samples within the new batch belong to. However, our approach is more general and it applies to the single head setting (where we have a single output layer for all classes, and no task oracle.)
51
+
52
+ # 3 LEARNING SETTING AND NOTATION
53
+
54
+ We consider the setting where a learner is faced with a possibly never-ending stream of data. At every time step, a labelled set of examples $( \mathbf { X } ^ { i n } , \mathbf { Y } ^ { i n } )$ drawn from a distribution $D _ { t }$ is received. However, the distribution $D _ { t }$ itself is sampled at each timestep and can suddenly change to $D _ { t + 1 }$ , when a task switch occurs. The learner is not explicitly told when a task switch happens, nor can it leverage a task identifier during training or evaluation. We note that this definition generalizes task-incremental learning, where each task is seen one after the other. In this scenario, given $T$ tasks to learn, $D _ { t }$ changes $T - 1$ times over the full steam, yielding $T$ locally i.i.d learning phases. We also explore in this paper a more general setting without the notion of clearly delineated tasks (Aljundi et al., 2018; Chen et al., 2020a), where the data distribution gradually changes over time.
55
+
56
+ Given a model $f _ { \boldsymbol { \theta } } ( \boldsymbol { x } )$ representing a neural network architecture with parameters $\theta$ , we want to minimize the classification loss $\mathcal { L }$ on the newly arriving data batch while not negatively interfering with the previously learned classes (i.e. increasing the classification loss). A simple and efficient approach to achieve this is to replay stored samples from a fixed size memory, $\mathcal { M }$ , in conjunction with the incoming data (Chaudhry et al., 2019; Rolnick et al., 2018). The core of our approach is that instead of treating the replayed batch and the incoming one similarly and naively minimizing the same loss, we opt for a specific loss structure on the incoming batch that would limit the interference with the previously well learned classes. We approach this by allowing the features of the newly received classes in the incoming data to be initially learned in isolation of the older classes. We first present our idea based on a metric learning loss and then generalize to the widely deployed cross-entropy loss.
57
+
58
+ # 4 METHODS
59
+
60
+ # 4.1 A DISTANCE METRIC LEARNING APPROACH FOR REDUCING DRIFT (ER-AML)
61
+
62
+ In order to allow fine-grained control of which samples will be pushed away from other samples given an incoming batch, we propose to apply, on the incoming data, a metric learning based loss from Khosla et al. (2020). Related loss functions have recently popularized in the self supervised learning literature (Chen et al., 2020b). We combine this in a holistic way with a cross-entropy type loss on the replay data. This allows us to control the representation drift of old classes while maintaining strong classification performance. Note that if a metric learning loss is used alone we needs to perform predictions using a Nearest Class Means Rebuffi et al. (2017) approach, which we show is computationally expensive in the online setting.
63
+
64
+ Given an input data point $x$ , we consider the function $f _ { \boldsymbol { \theta } } ( \boldsymbol { x } )$ mapping $x$ to its hidden representation before the final linear projection. We denote the incoming $N$ datapoints by $\mathbf { X } ^ { i n }$ and data replayed from the buffer by ${ \bf X } ^ { b { \bf \ddot { f } } }$ . We use the following loss, denoted SupCon (Khosla et al., 2020), on the
65
+
66
+ incoming data $\mathbf { X } ^ { i n }$ .
67
+
68
+ $$
69
+ \mathcal { L } _ { 1 } ( \mathbf { X } ^ { i n } ) = - \sum _ { \mathbf { x } _ { i } \in \mathbf { X } _ { i n } } \frac { 1 } { | P ( \mathbf { x } _ { i } ) | } \sum _ { \mathbf { x } _ { p } \in P ( \mathbf { x } _ { i } ) } \log \frac { \mathrm { s i m } \left( f _ { \boldsymbol { \theta } } ( \mathbf { x } _ { p } ) , f _ { \boldsymbol { \theta } } ( \mathbf { x } _ { i } ) \right) } { \sum _ { \mathbf { x } _ { n } \in N \cup P ( \mathbf { x } _ { i } ) } \mathrm { s i m } \left( f _ { \boldsymbol { \theta } } ( \mathbf { x } _ { n } ) , f _ { \boldsymbol { \theta } } ( \mathbf { x } _ { i } ) \right) }
70
+ $$
71
+
72
+ where $\begin{array} { r } { \scriptstyle \mathtt { s i m } ( a , b ) \ = \ \exp ( \frac { a ^ { T } b } { \tau \| a \| \| b \| } ) } \end{array}$ computes the exponential cosine similarity between two vectors, with scaling factor $\tau$ (Qi et al., 2018; He et al., 2020). Here we denote the incoming data $\mathbf { x } _ { i } \in \mathbf { X } ^ { i n }$ . We use the $P$ and $N$ to denote the set of positive and negatives with respect to $\mathbf { x } _ { i }$ and the positive examples $x _ { p }$ are selected from the examples in $\mathbf { X } ^ { i n } \cup \mathcal { M }$ , which are from the same classes as $\mathbf { x } _ { i }$ . In the sequel we will consider ${ \bf x } _ { n }$ selected from $\mathbf { X } ^ { i n } \cup \mathcal { M }$ in two distinct ways: (a) from a mix of current and previous classes and (b) only from
73
+
74
+ Input: Learning rate $\alpha$
75
+ Initialize: Memory $\mathcal { M }$ ; Model Params $\theta$ do Receive $\mathbf { X } ^ { i n }$ //Receive from stream $\mathbf { X } _ { p o s } , \mathbf { X } _ { n e g } \sim \mathrm { F E T C H P O S N E G } ( \mathbf { X } ^ { i n } , \mathcal { M } )$ $\mathbf { X } ^ { b f } \sim \mathbf { S A M P L E } ( \mathcal { M } )$ //Sample buffer $\mathcal { L } = \gamma \mathcal { L } _ { 1 } ( \mathbf { X } ^ { i n } , \mathbf { X } _ { p o s } , \mathbf { X } _ { n e g } ) + \mathcal { L } _ { 2 } ( \mathbf { X } ^ { b f } )$ $S G D ( \nabla \mathcal { L } , \theta , \alpha )$ //Param Update RESERVOIRUPDATE $( { \mathcal { M } } , \mathbf { X } ^ { i n } )$ //Save
76
+ while The stream has not ended
77
+
78
+ classes of the $\mathbf { X } ^ { i n }$ . Note that this implicitly learns a distance metric where samples of the same class lie close by. For the rehearsal step, we apply a modified cross-entropy objective as per Qi et al. (2018) which allows us to link the similarity metric from above to the logits.
79
+
80
+ $$
81
+ \mathcal { L } _ { 2 } ( \mathbf { X } ^ { b f } ) = - \sum _ { x \in \mathbf { X } _ { b f } } \log \frac { s \mathrm { i } \mathrm { m } \big ( \mathbf { w } _ { c ( x ) } , f _ { \theta } ( \mathbf { x } ) \big ) } { \sum _ { c \in C _ { a l l } } \mathrm { s i m } \big ( \mathbf { w } _ { c } , f _ { \theta } ( \mathbf { x } ) \big ) }
82
+ $$
83
+
84
+ where $C _ { a l l }$ the set of all classes observed, and $c ( x )$ denotes the label of $x$ . The above formulation allows us to interpret the rows of the final projection $\{ \mathbf { w } _ { c } \} _ { c \in C _ { a l l } }$ as class prototypes and inference to be performed without need for nearest neighbor search. We combine the loss functions on the incoming and replay data
85
+
86
+ $$
87
+ \mathcal { L } ( \mathbf { X } ^ { i n } \cup \mathbf { X } ^ { b f } ) = \gamma \mathcal { L } _ { 1 } ( \mathbf { X } ^ { i n } ) + \mathcal { L } _ { 2 } ( \mathbf { X } ^ { b f } )
88
+ $$
89
+
90
+ We refer to this approach as Experience Replay with Asymmetric Metric Learning (ER-AML). We describe the full rehearsal procedure with ER-AML in Algo 1. Note the buffer may contain samples with the same classes as the incoming data stream. The subroutine FetchPosNeg is used to find one positive and negative sample per incoming datapoint in $\mathbf { X } ^ { i n }$ , which can reside in either the buffer memory $\mathcal { M }$ or in $\bar { \mathbf X } ^ { i n }$ .
91
+
92
+ # 4.2 NEGATIVE SELECTION AFFECTS REPRESENTATION DRIFT
93
+
94
+ The selection of negatives for the proposed loss $\mathcal { L }$ can heavily influence the representation of previously learned classes and is analogous to the key issues faced in the regular replay methods where cross entropy loss is applied to both incoming and replay data. A typical approach in this loss for classification may be to select the negatives from any other class (Hoffer & Ailon, 2015). However this becomes problematic in the continual learning setting as the old samples will be too heavily influenced by the poorly embedded new samples that lie close to the old sample representations. To illustrate what is going on
95
+
96
+ ![](images/3de26c7a00e811564236c7a5477efca23a638b1376646e146ef0a0a8396260de.jpg)
97
+ Figure 2: Buffer displacement in a 5 task stream. Background shading denotes different tasks.
98
+
99
+ in the feature space, consider the case of a ER-AML’s $\mathcal { L } _ { 1 }$ term, which explicitly controls distances between sample representations. $\mathcal { L } _ { 1 }$ considers the incoming batch samples (containing new classes) as anchors. As the representations from these classes haven’t been learned, anchors may end up placed near or in-between points from previous classes (analogous to the illustration in Figure 1). Since the previous classes samples will be clustered together, if we use them as negatives for the incoming sample anchors, the gradients magnitude of the positive term will be out-weighted by the negative terms coming from the new class samples, similar to what is observed in Figure 1. In this case there is a sharp change in gradients norms of the loss w.r.t. the features of previous classes, as we illustrate in Appendix E, which leads to a large change in the representation at the task boundary (and subsequently poor performance). On the other hand if we use only incoming batch examples as negatives we can avoid this excessive representation drift. We illustrate this in Figure 2 by showing the representations drift at the task boundaries for ER-AML when using negative samples from all classes and when using only classes in the incoming batch. In the context of the model under consideration we measure the one iteration representation drift of a sample $x$ as $\| f _ { \theta ^ { t } } ( x ) - f _ { \theta ^ { t + 1 } } ( x ) \|$ , the output of the network being normalized. We observe that naively applying the proposed loss results in large changes of the learned representation. On the other hand when allowing only negatives from classes in the incoming batch, we see a reduction in this representation drift. In the Appendix 7 we further demonstrate that the accuracy of models trained using ER-AML with only incoming batch negatives can improve the continual learning system performance by a large margin. We emphasize the that ER-AML with all negatives and the regular ER method used for online continual learning suffer from a similar issue and thus lead to similar poor performances, with appropriate negative selection resolving the problem.This is further emphasized in Appendix $_ \mathrm { H }$ where we observe similar poor drift behavior for ER.
100
+
101
+ # 4.3 CROSS-ENTROPY BASED ALTERNATIVE (ER-ACE)
102
+
103
+ Having demonstrated the effect of controlling the incoming batch loss in avoiding a drastic representation drift, we now extend it to be applicable to the standard cross-entropy loss typically studied in ER (Aljundi et al., $2 0 1 9 \mathrm { a }$ ; Chaudhry et al., 2019). Given an incoming data batch, consider $C _ { o l d }$ the set of previously learned classes and $C _ { c u r r }$ the set of classes observed in the current incoming mini-batch. Denoting $C$ the set of classes included in the cross-entropy loss, we define the $\mathcal { L } _ { c e } ( \mathbf { X } , C )$ cross-entropy loss as: Lce(X, C) = − Px∈X log Psim(wc(x),fθ(x))c∈C sim(wc,fθ(x)) where $C \subset C _ { a l l }$ denotes the classes used to compute the denominator. We note that restricting the classes used in the denominator has an analogous effect to restricting the negatives in the contrastive loss. Consider the gradient for a single datapoint $x$ , ∂Lce(x,C)∂fn = W(\~p − \~y) 1\~y∈C . Here \~p denotes the softmax output of the network, $\vec { y }$ a one-hot target, $\mathbb { 1 } _ { \vec { y } \in C }$ a binary vector masking out classes not in $C$ , and W the matrix with all class prototypes $\{ \mathbf { w } _ { c } \} _ { c \in C _ { a l l } }$ . When the loss is applied in the batch setting, it follows that only prototypes whose labels are in $C$ will serve roles analogous to positives and negatives in the contrastive loss. We can then achieve a similar control as the metric learning approach on the learned representations.
104
+
105
+ Now, our loss applied at each step would be:
106
+
107
+ $\begin{array} { r } { \mathcal { L } _ { a c e } \big ( \mathbf { X } ^ { b f } \cup \mathbf { X } ^ { i n } \big ) = \mathcal { L } _ { c e } \big ( \mathbf { X } ^ { b f } , C _ { o l d } \cup C _ { c u r r } \big ) + \mathcal { L } _ { c e } \big ( \mathbf { X } ^ { i n } , C _ { c u r r } \big ) } \end{array}$ where $C _ { c u r r }$ denotes the set of the classes represented in the incoming batch and $C _ { o l d }$ denotes previously seen classes that are not presented in the incoming batch, those that we want to preserve their representation. Note this is a straightforward procedure and induces no additional computational overhead. We refer to it as Experience Replay with Asymmetric Cross-Entropy (ER-ACE).
108
+
109
+ # 5 EXPERIMENTS
110
+
111
+ We have highlighted the issue of abrupt representation change when new classes are introduced, and propose two methods that address this issue. We now demonstrate that mitigating drift directly leads to better performance on standard online continual learning benchmarks. As in Lopez-Paz et al. (2017); Aljundi et al. (2019a); Chaudhry et al. (2019) we use a reduced Resnet-18 for our experiments, and leave the batch size and the rehearsal batch size fixed at $I O$ . This allows us to fairly compare different approaches, as these parameters have a direct impact on the computational cost of processing a given stream.
112
+
113
+ # 5.1 DATASETS
114
+
115
+ All benchmarks are evaluated in the single-head setting, i.e. task descriptors are not provided to the model at test time, hence the model performs $N$ -way classification where $N$ is the total amount of classes seen.
116
+
117
+ Split CIFAR-10 partitions the dataset into 5 disjoint tasks containing two classes each (as in Aljundi et al. (2019a); Shim et al. (2020))
118
+
119
+ Split CIFAR-100 comprises 20 tasks, each containing a disjoint set of 5 labels. We follow the split in Chaudhry et al. (2019). All CIFAR experiments process $3 2 \times 3 2$ images.
120
+
121
+ Split MiniImagenet splits the MiniImagenet dataset into 20 disjoint tasks of 5 labels each. Images are $8 4 \times 8 4$ .
122
+
123
+ # 5.2 BASELINES
124
+
125
+ We focus our evaluation on replay-based methods, as they have been shown to outperform other approaches in the online continual learning setting Chaudhry et al. (2019); Aljundi et al. (2019a); Ji et al. (2020). We keep buffer management constant across methods : all samples are kept or discarded according to Reservoir Sampling Vitter (1985). We consider the following state-of-the-art baselines:
126
+
127
+ ER: Experience Replay with a buffer of a fixed size. Unlike Aljundi et al. (2019a), we do not leverage the task identifier during training to ensure that rehearsal samples belong to previous classes.
128
+
129
+ iCaRL Rebuffi et al. (2017) A distillation loss alongside binary cross-entropy is used during training. Samples are classified based on closest class prototypes, obtained from recomputing and averaging buffered data representations.
130
+
131
+ MIR Aljundi et al. (2019a) selects for replay samples interfering the most with the incoming data batch.
132
+
133
+ $\mathbf { D E R + + }$ Buzzega et al. (2020) uses a distillation loss on the logits to ensure consistency over time.
134
+
135
+ SS-IL Ahn et al. (2020) learns both the current task loss and the replay loss in isolation of each other.
136
+ An additional task-specific distillation is used on the rehearsal data.
137
+
138
+ GDUMB Prabhu et al. (2020) performs offline training on the buffer with unlimited computation and unrestricted use of data augmentation at the end of the task sequence.
139
+
140
+ iid: The learner is trained with a single pass on the data, in a single task containing all the classes. We also consider a version of this baseline using a similar compute budget as replay methods $( \ddot { \bf u } \dot { \bf d } + + )$
141
+
142
+ We note additional baselines such as Lopez-Paz et al. (2017); Chaudhry et al. were shown to perform poorly in this setting by prior work Buzzega et al. (2020) and are thus left out for clarity.
143
+
144
+ # 5.3 EVALUATION METRICS AND CONSIDERATIONS
145
+
146
+ Our evaluation includes the metrics and experimental settings used in previous works on online continual learning with a single-head (Aljundi et al., 2019a; Ji et al., 2020; Shim et al., 2020). We provide extra emphasis on anytime evaluation and comparisons of the computation time per incoming batch. We also consider several additional settings in terms of computation and use of image priors.
147
+
148
+ Anytime evaluation A critical component of online learning is the ability to use the learner at any point De Lange et al. (2019) . Although most works in the online (one-pass through the data) setting report results throughout the stream Lopez-Paz et al. (2017); Chaudhry et al.; Aljundi et al. (2019b), several prior works have reported the final accuracy as a proxy Aljundi et al. (2019a); Shim et al. (2020). However a lack of anytime evaluation opens the possibility to exploit the metrics by proposing offline learning baselines that are inherently incompatible with anytime evaluation Prabhu et al. (2020).
149
+
150
+ In order to make sure that learners are indeed online learners, we evaluate them throughout the stream. We define the Anytime Accuracy at time $k$ $( A A _ { k } )$ as the average accuracy on the test sets of all distributions seen up to time $k$ . If the learning experience lasts $T$ steps, then $A A _ { T }$ is equivalent to the final accuracy. Finally, we report the Averaged Anytime Accuracy (AAA) (Caccia et al., 2020), which measures how well the model performed over the learning experience
151
+
152
+ $$
153
+ \operatorname { A A A } = { \frac { 1 } { T } } \sum _ { t = 1 } ^ { T } ( A A ) _ { t } .
154
+ $$
155
+
156
+ Computation and Memory Constraints While memory constraints are well documented in previous work, careful monitoring of computation is often overlooked; some methods can indeed hide considerable overhead which can make the comparison across methods unfair. On the other hand this is critical to the use cases of online continual learning. To remedy this, we report for each method the total number of FLOPs used for training. While we cannot fix this quantity as we can for memory (since different methods require different computations), this will shed some light on how different methods compare. Note that we also include in this total any inference overhead required by the models; Nearest Class Mean (NCM) classifiers must compute class prototypes before inference for example. We add this cost every time the model is queried to measure its Anytime Accuracy. Let
157
+
158
+ $$
159
+ \mathbf { M e m } = \frac { 1 } { T } \sum _ { t = 1 } ^ { T } | \theta _ { t } | + | \mathcal { M } _ { t } | , \quad \mathbf { C o m p } = \sum _ { t = 1 } ^ { T } \mathcal { O } ( m ( \cdot ; \theta _ { t } ) ) ,
160
+ $$
161
+
162
+ where $\mathcal { O } ( m ( \cdot ; \theta _ { t } ) )$ denotes the number of FLOPs used at time $t$ . Since the same backbone and buffer is used for all methods in this paper, we will focus our constraint analysis on computation
163
+
164
+ Table 1: split CIFAR-10 results. $\dagger$ indicates the method is leveraging a task identifier at training time. For methods whose compute depend on the buffer size, we report min and max values. We evaluate the models every 10 updates. Results within error margin of the best result are bolded.
165
+
166
+ <table><tr><td rowspan="2">Method</td><td rowspan="2">Data Aug.</td><td colspan="2">M=5</td><td colspan="2">M=20</td><td colspan="2">M=100</td><td rowspan="2">Train TFLOPs</td><td rowspan="2">Mem. (Mb)</td></tr><tr><td>AAA</td><td>Acc</td><td>AAA</td><td>Acc</td><td>AAA</td><td>Acc</td></tr><tr><td>iid</td><td>X</td><td></td><td>62.7±0.7 72.9±0.7</td><td>1</td><td>62.7±0.7 72.9±0.7</td><td>-</td><td>62.7±0.7 72.9±0.7</td><td>8 16</td><td>4 4</td></tr><tr><td>jid+± DER++</td><td></td><td>50.7±1.1</td><td>31.8±0.9</td><td>55.6±1.2</td><td>39.3±1.0</td><td>60.1±1.3</td><td>52.3±1.1</td><td>24</td><td>(4,7)</td></tr><tr><td>ER</td><td></td><td>40.0±0.8 45.6±1.1</td><td>19.7±0.3 28.4±1.0</td><td>45.2±1.3 55.9±1.2</td><td>26.7±1.0 40.3±0.6</td><td>55.4±1.4 60.3±1.3</td><td>38.7±0.8 49.4±1.3</td><td>17</td><td>(4,7)</td></tr><tr><td>iCaRLt</td><td></td><td>47.0±0.8 49.1±1.0</td><td>30.6±0.8 33.4±1.0</td><td>55.1±0.7 54.4±0.7</td><td>41.7±0.6 39.2±0.8</td><td>59.3±0.6 56.9±0.7</td><td>45.1±0.6 42.3±0.8</td><td>(21,47)</td><td>(8,11)</td></tr><tr><td>MIRt</td><td>X</td><td>39.3±1.0 44.9±0.9</td><td>19.7±0.5 29.8±0.8</td><td>44.7±1.1 49.7±1.0</td><td>29.7±0.6 41.8±0.6</td><td>53.8±1.7 54.6±1.4</td><td>43.3±1.0 49.3±0.6</td><td>41</td><td>(4,7)</td></tr><tr><td>SS-IL+</td><td>X √</td><td>42.6±1.7 41.1±1.6</td><td>29.6±0.4 31.6±0.5</td><td>44.8±1.8 47.0±1.2</td><td>35.1±0.9 38.3±0.4</td><td>48.1±2.2 48.1±1.7</td><td>41.1±0.4 47.5±0.7</td><td>19</td><td>(8,11)</td></tr><tr><td>ER-ACE (ours)</td><td></td><td>53.1±1.0 52.6±0.9</td><td>35.6±1.0 35.1±0.8</td><td>58.0±0.7 56.4±1.0</td><td>42.6±0.7 43.4±1.6</td><td>61.9±0.9 61.7±0.9</td><td>52.2±0.7 53.7±1.1</td><td>17</td><td>(4,7)</td></tr><tr><td>ER-AML</td><td>X</td><td>49.4±1.0</td><td>30.9±0.8</td><td>57.0±1.0</td><td>39.2±1.0</td><td>63.3±1.0</td><td>52.2±1.1</td><td>17</td><td>(4,7)</td></tr><tr><td>(ours) GDUMB</td><td></td><td>50.4±1.3 0±0.0</td><td>36.4±1.4 35.0±0.6</td><td>56.8±1.0 0±0.0</td><td>47.7±0.7 45.8±0.9</td><td>62.0±0.9 0±0.0</td><td>55.7±1.3 61.3±1.7</td><td>(43,853)</td><td>(11,14)</td></tr></table>
167
+
168
+ <table><tr><td>Method</td><td>AAA</td><td>Acc.</td><td>Train TFLOPs</td><td>Mem. (Mb.)</td><td>AAA</td><td>Acc.</td><td>Train TFLOPs</td><td>Mem. (Mb.)</td></tr><tr><td>iid</td><td></td><td>19.8±0.3</td><td>9</td><td>4</td><td></td><td>16.7±0.5</td><td>59</td><td>4</td></tr><tr><td>iid++</td><td></td><td>28.3±0.3</td><td>17</td><td>4</td><td></td><td>25.0±0.8</td><td>118</td><td>4</td></tr><tr><td>DER++</td><td>23.3±0.5</td><td>15.1±0.4</td><td>25</td><td>36</td><td>21.7±0.6</td><td>12.9±0.3</td><td>176</td><td>217</td></tr><tr><td>ER</td><td>24.2±0.6</td><td>19.8±0.4</td><td>17</td><td>35</td><td>26.2±0.8</td><td>18.2±0.5</td><td>118</td><td>216</td></tr><tr><td>iCaRLt</td><td>26.3±0.3</td><td>17.3±0.2</td><td>294</td><td>39</td><td>24.4±0.4</td><td>17.1±0.1</td><td>2097</td><td>220</td></tr><tr><td>MIRt</td><td>23.6±0.8</td><td>20.6±0.5</td><td>41</td><td>35</td><td>27.2±0.7</td><td>20.2±0.8</td><td>294</td><td>216</td></tr><tr><td>SS-ILt</td><td>31.5±0.5</td><td>25.0±0.3</td><td>19</td><td>39</td><td>29.7±0.6</td><td>23.5±0.5</td><td>137</td><td>220</td></tr><tr><td>ER-ACE (ours)</td><td>32.7±0.5</td><td>25.8±0.4</td><td>17</td><td>35</td><td>30.2±0.6</td><td>22.7±0.6</td><td>118</td><td>216</td></tr><tr><td>ER-AML (ours)</td><td>30.2±0.6</td><td>24.3±0.4</td><td>28</td><td>35</td><td>27.0±0.7</td><td>19.3±0.6</td><td>200</td><td>216</td></tr></table>
169
+
170
+ Table 2: Split CIFAR-100 (left) and Mini-Imagenet (right) results with $M = 1 0 0$ . For each method, we report the best result between using (or not) data augmentations.
171
+
172
+ Data Augmentation In the settings of Aljundi et al. (2019a); Lopez-Paz et al. (2017); Ji et al. (2020); Shim et al. (2020); Chaudhry et al. (2019) data augmentation is not used. However, this is a standard practice for improving the performance on small datasets and can thus naturally complement most methods utilizing replay buffers. Notably, Prabhu et al. (2020), the offline learning method, utilizes data augmentation when comparing to the above online learners. To avoid unfair comparisons, in our experiments we indicate when a method uses augmentation. When not specified, we treat it as a hyperparameter and report the best performance.
173
+
174
+ Hyperparameter selection For all datasets considered, we withhold $5 \%$ of the training data for validation. For each method, optimal hyperparameters were selected via a grid search performed on a validation set. The selection process was done on a per dataset basis, that is we picked the configuration which maximized the accuracy averaged over different memory settings. We found that for both ER-AML and ER-ACE, the same hyperparameter configuration worked across all settings and datasets. All necessary details to reproduce our experiments can be found in the Appendix.
175
+
176
+ # 5.4 STANDARD ONLINE CONTINUAL LEARNING SETTINGS
177
+
178
+ We evaluate on Split CIFAR-10, Split CIFAR-100 and Split MiniImagenet using the protocol and constraints from Aljundi et al. (2019a); Ji et al. (2020); Shim et al. (2020) . We note in all results each method is run 10 times, and we report the mean and standard error. We first discuss dataset specific results, before analysing the computation cost of each method.
179
+
180
+ CIFAR-10 results are found in Table 1 using a variety of buffer sizes. In this setting, we see that both the methods we propose, ER-AML and ER-ACE consistently outperform other methods by a significant margin. This result holds in both settings where data augmentation is (or not) used, outperforming previous state-of-the-art methods MIR and $\mathrm { D E R + + }$ . Shifting our attention to SS-IL, its underperformance w.r.t to ER-ACE highlights the importance of having a rehearsal objective that considers the new classes. In Appendix B, we observe that when applying SS-IL in the online setting: (1) the method performs poorly on the current task, as is it unable to consolidate old and new knowledge, (2) yet mitigates representation drift even on a perfectly balanced stream. The latter is surprising, as the method was designed specifically to address stream imbalance. Finally, we note the offline training baseline G-DUMB cannot satisfy the anytime evaluation criteria.
181
+
182
+ Longer Task Sequence results are shown in Table 2 with CIFAR-100 on the left and MiniImagenet on the right. On both datasets similar findings are observed, our proposed methods match or outperform strong existing baselines. SS-IL performs similarly to our method on mini-imagenet hile having a higher computational and memory cost. As mentioned above, the method struggles to learn the current task, however here the “weight” of the current task is small in the final acc of the 20-task regime. We see that average anytime accuracy is higher for ER-ACE and indeed the anytime curves in Appendix L further illustrate this. Finally, ER-ACE shows relative gains of $35 \%$ in accuracy over ER, without any additional computation cost. For Mini-Imagenet, ER-ACE outperforms the single-pass iid baseline, and nearly reaches the performance of the equal-compute iid baseline.
183
+
184
+ Computation Budget To provide another view of the computational advantages of our proposal we report the accuracy given compute budget over the length of the sequence in Fig 3. When monitoring the computation performed by each baseline, we notice that several methods do not compete on equal footing. First, the use of Nearest Class Mean (NCM) classifiers leads to a significant compute cost, as shown for iCaRL. For our experiments, we evaluate the model after 10 mini-batches (100 total samples), where NCM classifier must forward the whole buffer to get class prototypes. We argue that such an approach has disadvantages in the online setting due to poor computational trade-offs. Second, MIR Aljundi et al. (2019a) has an expen
185
+
186
+ ![](images/5fbafd56a80cd170a969162310ee91e29711a024531f21a3c5be37f7705ff733.jpg)
187
+ Figure 3: Total Accuracy as a function of TeraFLOPs spent. Here the models are evaluated on all 10 classes, to ensure consistency across timesteps.
188
+
189
+ sive sample retrieval cost. It remains to show if this step can be approximated more efficiently. Finally, we note that our method, ER-AML has varying compute: for streams with a small number of classes per task (CIFAR10), it can compute the incoming loss leveraging only the incoming data. In other datasets, where an incoming batch may not have at least two samples of each class, an additional cost to forward a buffered point is incurred.
190
+
191
+ Evaluation with augmentation The use of augmentations also permits extra benefits of replay methods particularly in settings where buffer overfitting is more present, e.g. in the small buffer regime. From the results in Table 1, we see that augmentations provides significant gains for a large set of methods. It is therefore crucial to compare methods on equal footing, where they can all leverage (or not) data augmentation. For example, gains reported in Prabhu et al. (2020) over ER completely vanish when ER is given the same access to augmented data. We note that for MiniImagenet, augmentations did not help. We hypothesize that since this is the hardest task the risk of overfitting on the buffer is less severe.
192
+
193
+ # 5.5 BLURRY TASK BOUNDARIES
194
+
195
+ Table 3: CIFAR-10 Blurry Task Boundary Experiments
196
+
197
+ <table><tr><td>Method</td><td>M= 20</td><td>M=100</td></tr><tr><td>ER</td><td>32.1±1.5</td><td>42.7±2.2</td></tr><tr><td>DER++</td><td>31.0±1.4</td><td>41.7±1.4</td></tr><tr><td>ER-AML</td><td>45.6±1.2</td><td>55.2±1.1</td></tr><tr><td>ER-ACE</td><td>44.5±0.5</td><td>50.2±1.1</td></tr></table>
198
+
199
+ Next, we explore a setting where the distribution is continuously evolving, rather than clearly delineated by task boundaries (similar to settings considered in Aljundi et al. (2019b)). To do this, we linearly interpolate between tasks over time, resulting in new classes being slowly mixed into the data stream. This experiment is done on Split-CIFAR10, and the interpolation is such that at every timestep, the incoming data batch has on average 2 unique labels (as in the original experiment). We only evaluate task-free methods in this setting: methods like MIR and SS-IL cannot be used in such setting. Results in table 3 report the final accuracy, averaged over 5 runs, we report the standard error. We observe our ER-AML and ER-ACE methods perofrm well in this setting. More details provided in Appendix A.2.
200
+
201
+ # 6 CONCLUSION
202
+
203
+ We have illustrated how in the online continual learning setting the standard loss applies excessive pressure on old class representations. We proposed two modifications of the loss function, both based on treating the incoming and replay data in an asymmetric fashion. Our proposed method does not require knowledge of the current task and is shown to be suitable for long task sequences achieving strong performance with minimal or no additional cost. We also raise the standard for high quality evaluation in online continual learning by considering a wide number of baselines and metrics.
204
+
205
+ # 7 REPRODUCIBILITY STATEMENT
206
+
207
+ We have made several efforts to ensure that the results provided in the paper are fully reproducible. We first provide a detailed codebase from which all the results in this paper are generated. In this codebase, one can find the results of our grid search, as well as optimal hyperparameters for each method and setting. We have provided a Readme file to help guide used to reproduce our results. Details of all hyperparameters are also clearly described in the main paper and particularly in the appendix.
208
+
209
+ # 8 ACKNOWLEDGEMENTS
210
+
211
+ Lucas Caccia is funded by Borealis AI. EB and NA are supported by NSERC Discovery Grant RGPIN-2021-04104. We acknowledge resources provided by Compute Canada and Calcul Quebec.
212
+
213
+ # REFERENCES
214
+
215
+ Hongjoon Ahn, Jihwan Kwak, Subin Lim, Hyeonsu Bang, Hyojun Kim, and Taesup Moon. Ss-il: Separated softmax for incremental learning. arXiv preprint arXiv:2003.13947, 2020.
216
+
217
+ Rahaf Aljundi, Francesca Babiloni, Mohamed Elhoseiny, Marcus Rohrbach, and Tinne Tuytelaars. Memory aware synapses: Learning what (not) to forget. arXiv preprint arXiv:1711.09601, 2017.
218
+
219
+ Rahaf Aljundi, Klaas Kelchtermans, and Tinne Tuytelaars. Task-free continual learning. In CVPR 2019, 2018.
220
+
221
+ Rahaf Aljundi, Lucas Caccia, Eugene Belilovsky, Massimo Caccia, Laurent Charlin, and Tinne Tuytelaars. Online continual learning with maximally interfered retrieval. In Advances in Neural Information Processing (NeurIPS), 2019a.
222
+
223
+ Rahaf Aljundi, Min Lin, Baptiste Goujaud, and Yoshua Bengio. Gradient based sample selection for online continual learning. arXiv preprint arXiv:1903.08671, 2019b.
224
+
225
+ Zalan Borsos, Mojm ´ ´ır Mutny, and Andreas Krause. Coresets via bilevel optimization for continual \` learning and streaming. arXiv preprint arXiv:2006.03875, 2020.
226
+
227
+ Pietro Buzzega, Matteo Boschini, Angelo Porrello, Davide Abati, and Simone Calderara. Dark experience for general continual learning: a strong, simple baseline. arXiv preprint arXiv:2004.07211, 2020.
228
+
229
+ Massimo Caccia, Pau Rodriguez, Oleksiy Ostapenko, Fabrice Normandin, Min Lin, Lucas Caccia, Issam Laradji, Irina Rish, Alexandre Lacoste, David Vazquez, et al. Online fast adaptation and knowledge accumulation: a new approach to continual learning. arXiv preprint arXiv:2003.05856, 2020.
230
+
231
+ Arslan Chaudhry, Marc’Aurelio Ranzato, Marcus Rohrbach, and Mohamed Elhoseiny. Efficient lifelong learning with a-gem. In ICLR 2019.
232
+
233
+ Arslan Chaudhry, Marcus Rohrbach, Mohamed Elhoseiny, Thalaiyasingam Ajanthan, Puneet K Dokania, Philip HS Torr, and Marc’Aurelio Ranzato. Continual learning with tiny episodic memories. arXiv preprint arXiv:1902.10486, 2019.
234
+
235
+ Hung-Jen Chen, An-Chieh Cheng, Da-Cheng Juan, Wei Wei, and Min Sun. Mitigating forgetting in online continual learning via instance-aware parameterization. Advances in Neural Information Processing Systems, 33, 2020a.
236
+
237
+ Ting Chen, Simon Kornblith, Mohammad Norouzi, and Geoffrey Hinton. A simple framework for contrastive learning of visual representations. arXiv preprint arXiv:2002.05709, 2020b.
238
+
239
+ Matthias De Lange, Rahaf Aljundi, Marc Masana, Sarah Parisot, Xu Jia, Ales Leonardis, Gregory Slabaugh, and Tinne Tuytelaars. Continual learning: A comparative study on how to defy forgetting in classification tasks. arXiv preprint arXiv:1909.08383, 2019.
240
+
241
+ Sebastian Farquhar and Yarin Gal. Towards robust evaluations of continual learning. arXiv preprint arXiv:1805.09733, 2018.
242
+
243
+ Kaiming He, Haoqi Fan, Yuxin Wu, Saining Xie, and Ross Girshick. Momentum contrast for unsupervised visual representation learning. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 9729–9738, 2020.
244
+
245
+ Xu He, Jakub Sygnowski, Alexandre Galashov, Andrei A. Rusu, Yee Whye Teh, and Razvan Pascanu. Task agnostic continual learning via meta learning. ArXiv, abs/1906.05201, 2019. URL https://arxiv.org/abs/1906.05201.
246
+
247
+ Elad Hoffer and Nir Ailon. Deep metric learning using triplet network. In International workshop on similarity-based pattern recognition, pp. 84–92. Springer, 2015.
248
+
249
+ Saihui Hou, Xinyu Pan, Chen Change Loy, Zilei Wang, and Dahua Lin. Learning a unified classifier incrementally via rebalancing. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pp. 831–839, 2019.
250
+
251
+ Xu Ji, Joao Henriques, Tinne Tuytelaars, and Andrea Vedaldi. Automatic recall machines: Internal replay, continual learning and the brain. arXiv preprint arXiv:2006.12323, 2020.
252
+
253
+ Prannay Khosla, Piotr Teterwak, Chen Wang, Aaron Sarna, Yonglong Tian, Phillip Isola, Aaron Maschinot, Ce Liu, and Dilip Krishnan. Supervised contrastive learning. In H. Larochelle, M. Ranzato, R. Hadsell, M. F. Balcan, and H. Lin (eds.), Advances in Neural Information Processing Systems, volume 33, pp. 18661–18673. Curran Associates, Inc., 2020. URL https://proceedings.neurips.cc/paper/2020/file/ d89a66c7c80a29b1bdbab0f2a1a94af8-Paper.pdf.
254
+
255
+ Timothee Lesort, Massimo Caccia, and Irina Rish. Understanding continual learning settings with ´ data distribution drift analysis. arXiv preprint arXiv:2104.01678, 2021.
256
+
257
+ Zhizhong Li and Derek Hoiem. Learning without forgetting. In European Conference on Computer Vision, pp. 614–629. Springer, 2016.
258
+
259
+ David Lopez-Paz et al. Gradient episodic memory for continual learning. In Advances in Neural Information Processing Systems, pp. 6467–6476, 2017.
260
+
261
+ Zheda Mai, Ruiwen Li, Hyunwoo Kim, and Scott Sanner. Supervised contrastive replay: Revisiting the nearest class mean classifier in online class-incremental continual learning. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 3589–3599, 2021.
262
+
263
+ Michael McCloskey and Neal J Cohen. Catastrophic interference in connectionist networks: The sequential learning problem. Psychology of learning and motivation, 24:109–165, 1989.
264
+
265
+ Fabrice Normandin, Florian Golemo, Oleksiy Ostapenko, Matthew Riemer, Pau Rodriguez, Julio Hurtado, Khimya Khetarpal, Timothee Lesort, Laurent Charlin, Irina Rish, and Massimo Caccia.´ Sequoia - towards a systematic organization of continual learning research. https://github. com/lebrice/Sequoia, 2021. URL https://github.com/lebrice/Sequoia.
266
+
267
+ Oleksiy Ostapenko, Pau Rodriguez, Massimo Caccia, and Laurent Charlin. Continual learning via local module composition. In Thirty-Fifth Conference on Neural Information Processing Systems, 2021. URL https://proceedings.neurips.cc/paper/2021/hash/ fe5e7cb609bdbe6d62449d61849c38b0-Abstract.html.
268
+
269
+ Ameya Prabhu, Philip HS Torr, and Puneet K Dokania. Gdumb: A simple approach that questions our progress in continual learning. In European Conference on Computer Vision, pp. 524–540. Springer, 2020.
270
+
271
+ Hang Qi, Matthew Brown, and David G Lowe. Low-shot learning with imprinted weights. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 5822–5830, 2018.
272
+
273
+ Sylvestre-Alvise Rebuffi, Alexander Kolesnikov, Georg Sperl, and Christoph H Lampert. icarl: Incremental classifier and representation learning. In Proc. CVPR, 2017.
274
+
275
+ David Rolnick, Arun Ahuja, Jonathan Schwarz, Timothy P Lillicrap, and Greg Wayne. Experience replay for continual learning. arXiv preprint arXiv:1811.11682, 2018.
276
+
277
+ Joan Serra, D \` ´ıdac Sur´ıs, Marius Miron, and Alexandros Karatzoglou. Overcoming catastrophic forgetting with hard attention to the task. arXiv preprint arXiv:1801.01423, 2018.
278
+
279
+ Dongsub Shim, Zheda Mai, Jihwan Jeong, Scott Sanner, Hyunwoo Kim, and Jongseong Jang. Online class-incremental continual learning with adversarial shapley value. arXiv e-prints, pp. arXiv–2009, 2020.
280
+
281
+ Dongsub Shim, Zheda Mai, Jihwan Jeong, Scott Sanner, Hyunwoo Kim, and Jongseong Jang. Online class-incremental continual learning with adversarial shapley value. In Proceedings of the AAAI Conference on Artificial Intelligence, volume 35, pp. 9630–9638, 2021.
282
+
283
+ Binh Tang and David S Matteson. Graph-based continual learning. arXiv preprint arXiv:2007.04813, 2020.
284
+
285
+ Gido M van de Ven and Andreas S Tolias. Three scenarios for continual learning. arXiv preprint arXiv:1904.07734, 2019. URL https://arxiv.org/abs/1904.07734.
286
+
287
+ Jeffrey S Vitter. Random sampling with a reservoir. ACM Transactions on Mathematical Software (TOMS), 11(1):37–57, 1985.
288
+
289
+ Johannes Von Oswald, Dominic Zhao, Seijin Kobayashi, Simon Schug, Massimo Caccia, Nicolas Zucchet, and Joao Sacramento. Learning where to learn: Gradient spar- ˜ sity in meta and continual learning. Advances in Neural Information Processing Systems, 34, 2021. URL https://proceedings.neurips.cc/paper/2021/hash/ 2a10665525774fa2501c2c8c4985ce61-Abstract.html.
290
+
291
+ Yue Wu, Yinpeng Chen, Lijuan Wang, Yuancheng Ye, Zicheng Liu, Yandong Guo, and Yun Fu. Large scale incremental learning. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pp. 374–382, 2019.
292
+
293
+ Chen Zeno, Itay Golan, Elad Hoffer, and Daniel Soudry. Task agnostic continual learning using online variational bayes. arXiv preprint arXiv:1803.10123, 2018.
294
+
295
+ Bowen Zhao, Xi Xiao, Guojun Gan, Bin Zhang, and Shutao Xia. Maintaining discrimination and fairness in class incremental learning. arXiv preprint arXiv:1911.07053, 2019.
296
+
297
+ # A EXPERIMENTAL SETUP
298
+
299
+ In this section we provide additional experiments regarding the baselines and hyperparameters. In all experiments, we leave the batch size and the rehearsal batch size fixed at 10, following Aljundi et al. (2019a); Chaudhry et al.. This allows us to fairly compare different approaches, as these parameters have a direct impact on the computational cost of a given run. The model architecture $\boldsymbol { \theta }$ in Alg. 1) is also kept constant, which is a reduced ResNet-18 used in Lopez-Paz et al. (2017); Chaudhry et al.; Aljundi et al. (2019a;b), where the dimensions of the last linear layer change depending on the input height and width. The model has 1.09M params for the CIFAR experiments and 1.15M params for MiniImagenet. For all datasets considered, we keep the original ordering of the classes, meaning that the first task will always contain the first $k$ classes.
300
+
301
+ # A.1 HYPERPARAMETERS
302
+
303
+ All results in the paper have been (re)implemented by us, with the expection of GDUMB Prabhu et al. (2020), where results were run from the author’s public codebase. For each method a grid search was ran on the possible hparams, which we detail below. We will also described method specific details.
304
+
305
+ # $\mathbf { D E R + + }$ Buzzega et al. (2020) :
306
+
307
+ • LR : [0.1, 0.01, 0.001] • α : [0.25, 0.5, 0.75] • β : [0.5, 0.75, 1]
308
+
309
+ We also tried to implement the DER (not $\mathrm { D E R + + }$ ) algorithm described in Buzzega et al. (2020). We found that it did not lead to improvements w.r.t to ER in the single epoch setting. Moreover, the setting in the original paper uses a wider Resnet-18. We found that both these differences account for the drop in performance when comparing to the numbers in Buzzega et al. (2020).
310
+
311
+ Finally, we highlight that in general, methods using distillation (iCaRLRebuffi et al. (2017), SS-IL Ahn et al. (2020), and DER Buzzega et al. (2020)) typically perform better in the onlne setting without it.
312
+
313
+ # ER Chaudhry et al. :
314
+
315
+ • LR : [0.1, 0.01, 0.001]
316
+
317
+ Note that unlike the ER implementation in Aljundi et al. (2019a), we use a “task-free” implementation. This leads to two differences. First, rehearsal begins as soon as the buffer is not empty. Second, when fetching points in the buffer, we do not exclude classes from the current task, as done in MIRAljundi et al. (2019a).
318
+
319
+ # iCaRL Rebuffi et al. (2017) :
320
+
321
+ • LR : [0.1, 0.01, 0.001]
322
+
323
+ For all “task-based” methods (iCaRL, MIR, SS-IL) we fully leverage the task identified and do not start rehearsal until the second tasks. This typically leads to better performance, especially in the small buffer setting, as it reduces the work of overfitting to the buffer.
324
+
325
+ # MIR Aljundi et al. (2019a) :
326
+
327
+ • LR : [0.1, 0.01, 0.001]
328
+
329
+ Note that unlike in the original paper, the final results in the paper are on the full training set. In other words, once the hyperparameter cross-validation is done, we train on the validation set. This changes the results slightly from the original paper. Finally, we kept the number of items subsampled from the buffer for the sampling step $( N _ { c } )$ equal to 50 as in the original codebase.
330
+
331
+ # SS-ILAhn et al. (2020) :
332
+
333
+ • LR : [0.1, 0.01, 0.001]
334
+ • should distill : [Yes, No]. When turned on, this method also uses the distillation loss as prescribed in Ahn et al. (2020)
335
+
336
+ As we will see in B, using the
337
+
338
+ # ER-ACE
339
+
340
+ To implement the masking loss, we simply use logits.maskedfill(mask, $- 1 \in 9$ ) to filter out classes which should not receive gradient. Using a small constant in this step is equivalent to removing the masked classes from the softmax denominator.
341
+
342
+ # ER-AML :
343
+
344
+ • LR : [0.1, 0.01, 0.001] • SupCon Temperature : [0.1, 0.2]
345
+
346
+ # A.2 BLURRY TASK BOUNDARIES EXPERIMENT
347
+
348
+ Here we provide additional details on the experiment described in Section 5.4. In the original (task based) benchmark, each task comprises 10K samples (or 1K minibatches of 10 samples), so a total of 5K minibatches streamed. For the smooth alternative, at each timestep $t \in \{ 1 , \bar { 2 } , . . , 5 0 0 0 \}$ the unnormalized probability of seeing class $c$ is given by
349
+
350
+ $$
351
+ p _ { c } ( t ) \sim \dot { \mathcal { N } } ( \mu _ { c } - t , \frac { N _ { c } } { 4 } )
352
+ $$
353
+
354
+ with $N _ { c }$ denotes the number of samples of class $c$ , and $\begin{array} { r } { \mu _ { c } = \frac { ( 2 c - 1 ) N _ { c } } { 2 } } \end{array}$ (2c−1)Nc . At every timestep we normalize this probability for each class and sample according to a Categorical distribution with these probabilities. The parameters for the mean and variance are chosen so that on average, the model receives 2 unique labels per minibatch of 10 items (as in the original task-based experiment).
355
+
356
+ In such a setting where there is no notion of the current task, or rather a set of current labels, one cannot use SS-IL, as it needs to leverage a task identifier during training. Through this experiment we show that our method can overcome this limitation, despite sharing some similarities with SS-IL.
357
+
358
+ # B AN IN-DEPTH ANALYSIS OF SS-IL IN THE ONLINE SETTING
359
+
360
+ SS-IL is a related method. In this section, we highlight several key observations when deploying SS-IL in the online setting which are on the other hand not issues for ER-AML and ER-ACE. We then provide several additional experiments, shedding some light on the inner workings of the method.
361
+
362
+ SS-IL fails to learn the current task As stated earlier, the key difference between SS-IL without distillation and ER-ACE is that in the latter, the rehearsal loss in unmasked. In this section, we highlight the problems that occur when using a masked rehearsal loss alongside a masked incoming loss as in SS-IL. We show that since both losses are masked, the model never learns to classify classses across tasks. Specifically, there is no objective in which the model learns to distinguish classes in the current task from classes in the previous tasks. As we show in Figure 4, SS-IL is unable to classify samples from the current task in a single-head setting. The method actually performs worse than random chance on samples form the current task. On the other extreme we see that ER does very well on the current task (shifting abrupty the previous representations to accomodate the new task). Finally, we see that ER-ACE strikes a good tradeoff between the two, reaching a reasonable accuracy on the current task without disrupting the learned representations of previous tasks. We note that the same conclusion is reached when using the original SS-IL method with the distillation loss.
363
+
364
+ SS-IL does more than correcting for class imbalance SS-IL is motivated as a method which addresses the class imbalance issue arising in replay methods. Specifically, when drawing a fixed number of rehearsal points at every epoch, it follows that as more and more tasks are seen, previous classes are underrepresented in the training stream when compared to points from the current tasks.
365
+
366
+ In this section, we test whether or not the behavior of SS-IL differs from standard Experience Replay when no class imbalance is present. In this experiment, we increase the number of rehearsal points sampled at every task such that when combining incoming and rehearsal data, we obtain perfectly balanced training data on average. This is experiment is done on the Split-CIFAR10 benchmark with 2 classes per task, with a minibatch of 10 incoming datapoints. Therefore, we sample $0 , 1 0 , 2 0 , 3 0 , 4 0$ rehearsal points per incoming databatch for the first, second, third, fourth and fifth task.
367
+
368
+ What we observe is that SS-IL still outperforms regular Experience Replay, suggesting that the method does more than simply addressing class imbalance in the data stream. We report final accuracy in Table 4. SS-IL’s performance gap with ER is bigger with small buffer. This is consistent with what we observe for representation drift : methods with larger buffer can better correct for abrupt representation change, making the gap between ER vs ER-ACE and ER-AML smaller. From this we give new insights on the inner workings of SS-IL, namely that it works well because it addresses representation drift rather than class imbalance.
369
+
370
+ $$
371
+ \begin{array} { l } { { \frac { \mathrm { M e t h o d } \quad M = 2 0 \qquad M = 5 0 \quad M = 1 0 0 } { \mathrm { E R } \qquad 2 1 . 0 \pm 1 . 2 \ 2 5 . 7 \pm 1 . 1 \ 3 7 . 8 \pm 0 . 7 } } } \\ { { \mathrm { S S - L L } \quad 3 0 . 3 \pm 1 . 0 \ 3 4 . 6 \pm 0 . 8 \ 3 9 . 1 \pm 0 . 6 } } \end{array}
372
+ $$
373
+
374
+ Table 4: Final Accuracy on split CIFAR-10 with class balanced stream.
375
+
376
+ ![](images/a614689c0753957e4c22d1536e4b6427aa32d105f54222fa0e5eb41621a552f3.jpg)
377
+ Accuracy on the current task
378
+ Figure 4: For Split-CIFAR-10, we monitor the performance on the current task observed in the stream for SS-IL, ER, and ER-ACE. ER fits too abruptly current task; ER-ACE incorporates this knowledge slowly; SS-IL barely on the other hand is unable to learn new tasks when they are first observed in the stream
379
+
380
+ # C OVERFITTING ON BUFFERED SAMPLES
381
+
382
+ We study the extent to which our proposed method reduces over-fitting to samples stored in the buffer.
383
+
384
+ ![](images/e47bc89cad3c9e5aae74a1a54c9daa1144486c90061423b8a31cf273642df0f1.jpg)
385
+ Figure 5: Alignment between buffer and holdout representations. ER-ACE has constantly larger alignment between seen and unseen samples compared to ER especially for older tasks.
386
+
387
+ A good model fit should yield a learned representation where same class datapoints are aligned, whether or not they were seen during training. To evaluate this potential mismatch, we first train a model and compare the representations of a) samples in the buffer $M$ after training and b) held-out samples from the validation set $V$ . That is, for each datapoint $x _ { m } \in M$ we find the point $x _ { v } \in V$ with $c ( x _ { m } ) = c ( x _ { v } )$ which maximizes the cosine similarity between $f _ { \theta } ( x _ { m } )$ and $f _ { \theta } ( x _ { v } )$ . This allows to compare alignment across models, irrespective of their internal scaling. We report the results in Figure 5, where similarity values are averaged over points from the same task. We find that our proposed method, ER-ACE, designed to reduce representation drift also reduces the extent to which the model overfits on the buffer. We observe that for earlier tasks, ER-ACE still retains a strong alignment between rehearsal and held-out data, which is not the case for ER.
388
+
389
+ # D COMBINING ER-ACE WITH DER $^ { + + }$
390
+
391
+ In this section, we apply our method on top of the strong DER $^ { + + }$ Buzzega et al. (2020) baseline. For this experiment, we use the same setting as in the DER paper. Specifically, we port our implementation to their public codebase https://github.com/aimagelab/mammoth. We keep the default settings for CIFAR-10, using a single pass through the data. We find that combining ER-ACE with $\mathrm { D E R + + }$ yields additional advantages. Not only do we observe small gains in accuracy, we notice significant gains in forgetting. Results are shown in Figure 6. Forgetting is defined as in Chaudhry et al..
392
+
393
+ ![](images/b31eba01db9c5743913e139d0a5cf7842466e1abe076608945f85525512b0f26.jpg)
394
+ Figure 6: Comparison to Dark Experience Replay (DER). We obtain improved performance and we can enhance the DER method using the ER-ACE approach
395
+
396
+ Table 5: Average Drift (avg distance in feature space) of buffered representations for CIFAR-10 during learning of the second task. We observe similar behavior to ER-AML with SupCon
397
+
398
+ <table><tr><td rowspan=1 colspan=1>ER</td><td rowspan=1 colspan=1>(3.2 ± 1.8) × 10-2</td></tr><tr><td rowspan=1 colspan=1>ER-AML-Tripletw.All Negs</td><td rowspan=1 colspan=1>(3.0±0.6)× 10-2</td></tr><tr><td rowspan=1 colspan=1>ER-AML-Triplet w. Incoming Negs</td><td rowspan=1 colspan=1>(2.5 ±0.6)× 10-²</td></tr></table>
399
+
400
+ Table 6: Ablation comparing ER-AML with triplet loss to ER-AML with SupCon. We observe both improve over ER but SupCon has better performance in larger buffer sizes
401
+
402
+ <table><tr><td colspan="5">Accuracy ↑</td></tr><tr><td></td><td>M=5</td><td>M=20</td><td>M=50</td><td>M=100</td></tr><tr><td>iid online</td><td>60.8±1.0</td><td>60.8±1.0</td><td>60.8 ± 1.0</td><td>60.8±1.0</td></tr><tr><td>iid++ online</td><td>72.0 ± 0.1</td><td>72.0±0.1</td><td>72.0±0.1</td><td>72.0±0.1</td></tr><tr><td>iid offline</td><td>79.2 ± 0.4</td><td>79.2 ± 0.4</td><td>79.2 ± 0.4</td><td>79.2 ± 0.4</td></tr><tr><td>fine-tuning</td><td>18.4± 0.3</td><td>18.4± 0.3</td><td>18.4±0.3</td><td>18.4±0.3</td></tr><tr><td>ER</td><td>19.0 ± 0.1</td><td>26.7± 0.3</td><td>36.1 ± 0.6</td><td>41.5 ± 0.6</td></tr><tr><td>ER-AML Triplet</td><td>33.0 ± 0.3</td><td>40.1± 0.4</td><td>46.0± 0.5</td><td>49.8 ± 0.5</td></tr><tr><td>ER-AML SupCon 33.0 ±0.2</td><td></td><td>41.9 ± 0.1</td><td>48.3±0.2</td><td>51.9 ±0.3</td></tr></table>
403
+
404
+ # E GRADIENT NORM
405
+
406
+ Figure 7 shows the gradients norms of the features of previous classes in a stream of two tasks. Note how for normal ER, at the task switch the gradients of the previous classes features are suddenly very high leading potentially to large drift on these features.
407
+
408
+ ![](images/de41102741e910a95a39c664810222c7d11ed2dfb0c616a3d12633dd81336557.jpg)
409
+ Figure 7: Gradient’s norm for first task features in a two task learning scenario. We observe a sharp increase when all negatives are used and decrease using only incoming negatives.
410
+
411
+ # F ER-AML WITH TRIPLET LOSS
412
+
413
+ We observe similar behavior for ER-AML implemented with the triplet loss in terms of the importance of negative selection on drift as illustrated in Table 5. We also ablate ER-AML based on SupCon and Triplet in Table 6 finding the former outperforms in settings with higher buffer sizes, but that both outperform ER.
414
+
415
+ # G ABLATIONS NEGATIVE SELECTION
416
+
417
+ As discussed in the main paper, the selection of negatives is a critical aspect of ER-AML and motivates ER-ACE. To further illustrate this we ablate the performance of ER-AML when all possible negatives are used versus the prescribed negative selection strategy (using only classes in the incoming batch). The results are shown in Table 7. We observe that performance of ER-AML with all negatives is similar to but slightly better than ER, while use of well-selected negatives greatly improves performance.
418
+
419
+ <table><tr><td></td><td>Accuracy (↑is better) M=20 M=50</td><td>Forgetting (↓is better) M=20 M=50</td></tr><tr><td>ER</td><td>26.7±0.3 36.1±0.6</td><td>47.1± 0.8 37.6± 0.9</td></tr><tr><td>ER-AML(all negatives)</td><td>28.5± 0.3 41.4± 0.4</td><td>56.7± 0.6 35.0±0.4</td></tr><tr><td>ER-AML(incoming negatives)</td><td>41.9 ± 0.1 48.3±0.2</td><td>33.6±0.2 25.8±0.3</td></tr></table>
420
+
421
+ Table 7: Ablation of ER-AML with all negative selection versus negatives selected from incoming classes. We use the CIFAR-10 dataset. We observe that performance of ER-AML with all negatives is similar to but slightly better than ER, while use of well-selected negatives greatly improves performance.
422
+
423
+ # H ADDITIONAL DRIFT RESULTS
424
+
425
+ We showed in Figure 2 that the selection of negatives has a significant impact on the amount of representation change. Here we show that a similar behavior is observed with ER vs ER-ACE.
426
+
427
+ ![](images/1e248200d97db6023af8acd49706a7b529f45b161d7205edfbea2aa26865f9ad.jpg)
428
+
429
+ # I ANALYSIS OF THE REPRESENTATIONS DURING THE SECOND TASK
430
+
431
+ In this section we take a closer look at the model’s internal representation during the learning of the second task for different methods. This experiment replicates the setup illustrated in Figure 1 (split-CIFAR-10 with $M = 2 0$ ). For each method, the figures for all iterations were projected together to ensure that the figures are comparable across timesteps. All methods were initialized starting from the same base model trained on the first task. The dotted representations shown for each class come from held-out samples.
432
+
433
+ We start by looking at the representations obtained at the begining of the second task. We see that for all three methods, (i) the prototypes of the classes from the first task (Class 0 and Class 1) are well placed, while the other prototypes are placed at random since they are not trained.
434
+
435
+ ![](images/8067d6fceec63d2590d196c032c9843ad574aa41259d8256ca412176ed4aee0c.jpg)
436
+ Figure 8: 1 Training Iteration on the Second Task
437
+
438
+ After 100 training iterations, we see that for ER, the prototypes of the old classes have been significantly displaced and are far from the points of similar class. This is not the case for the latter two methods; for ER-ACE and ER-AML, the model is beginning to separate de classes from one another, and the class prototypes are near their respective classes.
439
+
440
+ ![](images/873631575c72a6087735450419beaffb6daa6d640527147aa6f44d8cc818cea7.jpg)
441
+ Figure 9: 100 Training Iterations on the Second Task
442
+
443
+ After 400 training iterations, ER still struggles to align the class prototypes with the respective classes. ER-ACE has already well clustered the respective classes. ER-AML, continues to cluster the classes together, however does not do it as fast as ER-ACE.
444
+
445
+ ![](images/c1c5696e525f4968bea05b2ce2f30f9148af49185a771b6aa645da10fbf316ba.jpg)
446
+ Figure 10: 400 Training Iterations on the Second Task
447
+
448
+ At the end of the second task, ER-ACE and ER-AML have successfully clustered the classes and aligned their respective prototypes with the clusters. As for ER, while the data is clustered, the prototypes are not properly aligned with class clusters. Moreover, we still see a strong overlap between prototypes of Class 2 and 3.
449
+
450
+ ![](images/576950f516183a5d18b9c5678938a4b41e99c93c24ab74ad2e61bfc21fcdd329.jpg)
451
+ Figure 11: End of the Second Task
452
+
453
+ # J ADDITIONAL BLURRY TASK BOUNDARIES EXPERIMENTS
454
+
455
+ Here we provide blurry task results for varying levels of task overlap. To give an idea of how much the tasks overlap, we report the average number of unique classes per incoming minibatch (MB): a small number means that the tasks are well separated. A high number means that there is a strong overlap. In the fully i.i.d setting, this number would be maximized. On the other hand, when this equals 1, each data class is streamed one after the other.
456
+
457
+ Experiments are performed again on CIFAR-10 with $M = 2 0$ . We use augmentations to fairly compare with $\mathrm { D E R + + }$ . Results are averaged over 5 runs.
458
+
459
+ <table><tr><td>Method</td><td>Avg. unique classes per MB 1 2 3 4 5</td></tr><tr><td>ER 23.1 DER++ 20.3 31.1</td><td>25.7 26.3 31.1 34.4 31.4 37.3 34.4</td></tr><tr><td>ER-ACE 32.8</td><td>36.2 36.8 41.7 44.5</td></tr><tr><td>ER-AML 34.0</td><td>40.4 46.0 47.6 47.9</td></tr></table>
460
+
461
+ We see that through a wide range of different blurriness levels, our methods show strong improvement over other task-free baselines
462
+
463
+ # K EXPERIMENTS WITH LIMITED TRAINING DATA AVAILABLE
464
+
465
+ Next, we evaluate the methods above using varying percentages of the training data from the second task onwards (we use all the data for the first task so the model has converged to a reasonable solution before the first distribution shift). Moreover, we augment the rehearsal batch size for ER, ER-ACE and ER-AML to 20, so that their compute cost equals $\mathrm { D E R + + }$ . This is again on CIFAR-10, $M = 2 0$ . Results averaged over 5 runs.
466
+
467
+ <table><tr><td>Method</td><td>% ofData Used 5% 10% 25% 50%</td></tr><tr><td>ER 17.3</td><td>22.5 28.0 33.2 32.8</td></tr><tr><td>DER++ 17.4 SS-IL 15.2</td><td>19.9 24.8 21.7 28.6</td></tr><tr><td></td><td>31.9</td></tr><tr><td>ER-ACE 20.5 ER-AML 18.1</td><td>25.4 31.2 36.1 24.3 31.0 38.7</td></tr></table>
468
+
469
+ Again, we see that the proposed methods outperforms the baselines suggested above.
470
+
471
+ ![](images/3d49c67ed5c7395cf400ef7ac81f6d8d79f975d649daef6d259d168f303050ec.jpg)
472
+ CIFAR-10 ${ \mathsf { M } } = 5$ Anytime Evaluation Acc
473
+
474
+ # L ADDITIONAL RESULTS
475
+
476
+ In this section we provide full results (shown in the figures below) for various memory sizes on all three datasets considered, i.e. Split CIFAR-10, Split CIFAR-100 and Split MiniImagenet, with and without data augmentation. The results largely align with those presented but also illustrate the anytime performance.
477
+
478
+ L.1 ANYTIME EVALUATION WITHOUT DATA AUGMENTATION
479
+
480
+ L.2 ANYTIME EVALUATION WITH DATA AUGMENTATION
481
+
482
+ ![](images/27e2b50d0836f8eb85e8ae6113a143bfa29fc39f1cfe94cd90a818e04e06ef1c.jpg)
483
+
484
+ ![](images/7075010bb2b11fff05d8451f59f25219908a71531742d4caf9a73b6f9f6068b4.jpg)
485
+
486
+ ![](images/5f94039abb29cf1f1f63194205d59af13011de5d0f8922a4fb23167a53448bde.jpg)
487
+
488
+ ![](images/1bb0b5c5751e8e51e02cb69a90acd5f023ed34b6ca5c75fa3b68f4945ff83a3c.jpg)
489
+
490
+ ![](images/c0be346899f23875653552fe17a5ae08ef4633650201a1a0bf1598de68119f37.jpg)
491
+
492
+ ![](images/0724fc0c75a9fe00f7de80a176de0b2cfe3f4a9eb9fe98d0545e216803688e42.jpg)
md/dev/O4kDO3yS9B/O4kDO3yS9B.md ADDED
@@ -0,0 +1,437 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Rethinking the Evaluation for Conversational Recommendation in the Era of Large Language Models
2
+
3
+ Xiaolei Wang1,3∗, Xinyu Tang1,3∗, Wayne Xin Zhao1,3†, Jingyuan Wang4 and Ji-Rong Wen1,2,3
4
+
5
+ 1Gaoling School of Artificial Intelligence, Renmin University of China 2School of Information, Renmin University of China
6
+ 3Beijing Key Laboratory of Big Data Management and Analysis Methods 4School of Computer Science and Engineering, Beihang University
7
+ wxl1999@foxmail.com, txy20010310@163.com, batmanfly@gmail.com
8
+
9
+ # Abstract
10
+
11
+ The recent success of large language models (LLMs) has shown great potential to develop more powerful conversational recommender systems (CRSs), which rely on natural language conversations to satisfy user needs. In this paper, we embark on an investigation into the utilization of ChatGPT for CRSs, revealing the inadequacy of the existing evaluation protocol. It might overemphasize the matching with ground-truth items annotated by humans while neglecting the interactive nature of CRSs.
12
+
13
+ To overcome the limitation, we further propose an interactive Evaluation approach based on LLMs, named iEvaLM, which harnesses LLM-based user simulators. Our evaluation approach can simulate various system-user interaction scenarios. Through the experiments on two public CRS datasets, we demonstrate notable improvements compared to the prevailing evaluation protocol. Furthermore, we emphasize the evaluation of explainability, and ChatGPT showcases persuasive explanation generation for its recommendations. Our study contributes to a deeper comprehension of the untapped potential of LLMs for CRSs and provides a more flexible and realistic evaluation approach for future research about LLMbased CRSs. The code is available at https: //github.com/RUCAIBox/iEvaLM-CRS.
14
+
15
+ # 1 Introduction
16
+
17
+ Conversational recommender systems (CRSs) aim to provide high-quality recommendation services through natural language conversations that span multiple rounds. Typically, in CRSs, a recommender module provides recommendations based on user preferences from the conversation context, and a conversation module generates responses given the conversation context and item recommendation.
18
+
19
+ Since CRSs rely on the ability to understand and generate natural language conversations, capable approaches for CRSs have been built on pre-trained language models in existing literature (Wang et al., $2 0 2 2 \mathrm { c }$ ; Deng et al., 2023). More recently, large language models (LLMs) (Zhao et al., 2023a), such as ChatGPT, have shown that they are capable of solving various natural language tasks via conversations. Since ChatGPT has acquired a wealth of world knowledge during pre-training and is also specially optimized for conversation, it is expected to be an excellent CRS. However, there still lacks a comprehensive study of how LLMs (e.g., ChatGPT) perform in conversational recommendation.
20
+
21
+ To investigate the capacity of LLMs in CRSs, we conduct an empirical study on the performance of ChatGPT on existing benchmark datasets. We follow the standard evaluation protocol and compare ChatGPT against state-of-the-art CRS methods. Surprisingly, the finding is rather counter-intuitive: ChatGPT shows unsatisfactory performance in this empirical evaluation. To comprehend the reason behind this discovery, we examine the failure cases and discover that the current evaluation protocol is the primary cause. It relies on the matching between manually annotated recommendations and conversations and might overemphasize the fitting of ground-truth items based on the conversation context. Since most CRS datasets are created in a chit-chat way, we find that these conversations are often vague about the user preference, making it difficult to exactly match the ground-truth items even for human annotation. In addition, the current evaluation protocol is based on fixed conversations, which does not take the interactive nature of conversational recommendation into account. Similar findings have also been discussed on text generation tasks (Bang et al., 2023; Qin et al., 2023): traditional metrics (e.g., BLEU and ROUGE) may not reflect the real capacities of LLMs.
22
+
23
+ Considering this issue, we aim to improve the evaluation approach, to make it more focused on the interactive capacities of CRSs. Ideally, such an evaluation approach should be conducted by humans, since the performance of CRSs would finally be tested by real users in practice. However, user studies are both expensive and time-consuming, making them infeasible for large-scale evaluations. As a surrogate, user simulators can be used for evaluation. However, existing simulation methods are typically limited to pre-defined conversation flows or template-based utterances (Lei et al., 2020; Zhang and Balog, 2020). To address these limitations, a more flexible user simulator that supports free-form interaction in CRSs is actually needed.
24
+
25
+ To this end, this work further proposes an interactive Evaluation approach based on LLMs, named iEvaLM, in which LLM-based user simulation is conducted to examine the performance. Our approach draws inspiration from the remarkable instruction-following capabilities exhibited by LLMs, which have already been leveraged for roleplay (Fu et al., 2023). With elaborately designed instructions, LLMs can interact with users in a highly cooperative manner. Thus, we design our user simulators based on LLMs, which can flexibly adapt to different CRSs without further tuning. Our evaluation approach frees CRSs from the constraints of rigid, human-written conversation texts, allowing them to interact with users in a more natural manner, which is close to the experience of real users. To give a comprehensive evaluation, we also consider two types of interaction: attribute-based question answering and free-form chit-chat.
26
+
27
+ With this new evaluation approach, we observe significant improvements in the performance of ChatGPT, as demonstrated through assessments conducted on two publicly available CRS datasets. Notably, the Recall $@ 1 0$ metric has increased from 0.174 to 0.570 on the REDIAL dataset with fiveround interaction, even surpassing the Recall $\textcircled { a } 5 0$ result of the currently leading CRS baseline. Moreover, in our evaluation approach, we have taken the crucial aspect of explainability into consideration, wherein ChatGPT exhibits proficiency in providing persuasive explanations for its recommendations. Besides, existing CRSs can also benefit from the interaction, which is an important ability overlooked by the traditional evaluation. However, they perform much worse in the setting of attribute-based question answering on the OPENDIALKG dataset, while ChatGPT performs better in both settings on the two datasets. It demonstrates the superiority of ChatGPT across different scenarios, which is expected for a general-purpose CRS.
28
+
29
+ Table 1: Statistics of the datasets.
30
+
31
+ <table><tr><td>Dataset</td><td>#Dialogues</td><td>#Utterances</td><td>Domains</td></tr><tr><td>ReDial</td><td>10,006</td><td>182,150</td><td>Movie</td></tr><tr><td>OpenDialKG</td><td>13,802</td><td>91,209</td><td>Movie, Book, Sports, Music</td></tr></table>
32
+
33
+ We summarize our key contributions as follows:
34
+
35
+ (1) To the best of our knowledge, it is the first time that the capability of ChatGPT for conversational recommendation has been systematically examined on large-scale datasets.
36
+
37
+ (2) We provide a detailed analysis of the limitations of ChatGPT under the traditional evaluation protocol, discussing the root cause of why it fails on existing benchmarks.
38
+
39
+ (3) We propose a new interactive approach that employs LLM-based user simulators for evaluating CRSs. Through experiments conducted on two public CRS datasets, we demonstrate the effectiveness and reliability of our evaluation approach.
40
+
41
+ # 2 Background and Experimental Setup
42
+
43
+ In this section, we describe the task definition and experimental setup used in this work.
44
+
45
+ # 2.1 Task Description
46
+
47
+ Conversational Recommender Systems (CRSs) are designed to provide item recommendations through multi-turn interaction. The interaction can be divided into two main categories: question answering based on templates (Lei et al., 2020; Tu et al., 2022) and chit-chat based on natural language (Wang et al., 2023; Zhao et al., 2023c). In this work, we consider the second category. At each turn, the system either presents a recommendation or initiates a new round of conversation. This process continues until the user either accepts the recommended items or terminates the conversation. In general, CRSs consist of two major subtasks: recommendation and conversation. Given its demonstrated prowess in conversation (Zhao et al., 2023b), we focus our evaluation of ChatGPT on its performance in the recommendation subtask.
48
+
49
+ # 2.2 Experimental Setup
50
+
51
+ Datasets. We conduct experiments on the REDIAL (Li et al., 2018) and OPENDIALKG (Moon et al., 2019) datasets. REDIAL is the most commonly used dataset in CRS, which is about movie recommendations. OPENDIALKG is a multidomain CRS dataset covering not only movies but also books, sports, and music. Both datasets are widely used for CRS evaluation. The statistics for them are summarized in Table 1.
52
+
53
+ Baselines. We present a comparative analysis of ChatGPT with a selection of representative supervised and unsupervised methods:
54
+
55
+ • KBRD (Chen et al., 2019): It introduces DBpedia to enrich the semantic understanding of entities mentioned in dialogues.
56
+
57
+ • KGSF (Zhou et al., 2020): It leverages two KGs to enhance the semantic representations of words and entities and use Mutual Information Maximization to align these two semantic spaces.
58
+
59
+ • CRFR (Zhou et al., 2021a): It performs flexible fragment reasoning on KGs to address their inherent incompleteness.
60
+
61
+ • BARCOR (Wang et al., 2022b): It proposes a unified CRS based on BART (Lewis et al., 2020), which tackles two tasks using a single model.
62
+
63
+ • MESE (Yang et al., 2022): It formulates the recommendation task as a two-stage item retrieval process, i.e., candidate selection and ranking, and introduces meta-information when encoding items.
64
+
65
+ • UniCRS (Wang et al., 2022c): It designs prompts with KGs for DialoGPT (Zhang et al., 2020) to tackle two tasks in a unified approach.
66
+
67
+ • text-embedding-ada-002 (Neelakantan et al., 2022): It is a powerful model provided in the OpenAI API to transform each input into embeddings, which can be used for recommendation.
68
+
69
+ Among the above baselines, text-embeddingada-002 is an unsupervised method, while others are supervised and trained on CRS datasets.
70
+
71
+ Evaluation Metrics. Following existing work (Zhang et al., 2023; Zhou et al., 2022), we adopt Recall $@ k$ to evaluate the recommendation subtask. Specifically, we set $k = 1$ , 10, 50 following Zhang et al. (2023) for the REDIAL dataset, and $k = 1$ , 10, 25 following Zhou et al. (2022) for the OPENDIALKG dataset. Since requiring too many items can sometimes be refused by ChatGPT, we only assess Recall $@ 1$ and Recall $@ 1 0$ for it.
72
+
73
+ Model details. We employ the publicly available model gpt-3.5-turbo provided in the OpenAI API, which is the underlying model of ChatGPT. To make the output as deterministic as possible, we set temperature $\scriptstyle = 0$ when calling the API. All the prompts we used are detailed in Appendix C.
74
+
75
+ ![](images/91c4ef3bc4c0067185c1ddfd45fdfabbeab4958871a64eb916b857390ce52610.jpg)
76
+ Figure 1: The method of adapting ChatGPT for CRSs.
77
+
78
+ # 3 ChatGPT for Conversational Recommendation
79
+
80
+ In this section, we first discuss how to adapt ChatGPT for CRSs, and then analyze its performance.
81
+
82
+ # 3.1 Methodology
83
+
84
+ Since ChatGPT is specially optimized for dialogue, it possesses significant potential for conversational recommendation. Here we propose two approaches to stimulating this ability, as illustrated in Figure 1.
85
+
86
+ Zero-shot Prompting. We first investigate the ability of ChatGPT through zero-shot prompting (see Appendix C.1). The prompt consists of two parts: task instruction (describing the task) and format guideline (specifying the output format).
87
+
88
+ Integrating Recommendation Models. Although ChatGPT can directly generate the items, it is not specially optimized for recommendation (Kang et al., 2023; Dai et al., 2023). In addition, it tends to generate items that are outside the evaluation datasets, which makes it difficult to directly assess the predictions. To bridge this gap, we incorporate external recommendation models to constrain the output space. We concatenate the conversation history and generated responses as inputs for these models to directly predict target items or calculate the similarity with item candidates for matching. We select the CRS model MESE (Yang et al., 2022) as the supervised method (ChatGPT $^ +$ text-embedding-ada-002) and the text-embedding-ada-002 (Neelakantan et al.,
89
+
90
+ Table 2: Overall performance of existing CRSs and ChatGPT. Since requiring too many items at once can sometimes be refused by ChatGPT, we only assess Recall $@ 1$ and Recall $@ 1 0$ for it, while Recall $\textcircled { a } 5 0$ is marked as “–”. Numbers marked with \* indicate that the improvement is statistically significant compared with the best baseline (t-test with p-value $< 0 . 0 5$ ).
91
+
92
+ <table><tr><td>Datasets</td><td colspan="3">ReDial</td><td colspan="3">OpenDialKG</td></tr><tr><td>Models</td><td>Recall@1</td><td>Recall@10</td><td>Recall@50</td><td>Recall@ 1</td><td>Recall@10</td><td>Recall@ 25</td></tr><tr><td>KBRD</td><td>0.028</td><td>0.169</td><td>0.366</td><td>0.231</td><td>0.423</td><td>0.492</td></tr><tr><td>KGSF</td><td>0.039</td><td>0.183</td><td>0.378</td><td>0.119</td><td>0.436</td><td>0.523</td></tr><tr><td>CRFR</td><td>0.040</td><td>0.202</td><td>0.399</td><td>0.130</td><td>0.458</td><td>0.543</td></tr><tr><td>BARCOR</td><td>0.031</td><td>0.170</td><td>0.372</td><td>0.312</td><td>0.453</td><td>0.510</td></tr><tr><td>UniCRS</td><td>0.050</td><td>0.215</td><td>0.413</td><td>0.308</td><td>0.513</td><td>0.574</td></tr><tr><td>MESE</td><td>0.056*</td><td>0.256*</td><td>0.455*</td><td>0.279</td><td>0.592*</td><td>0.666*</td></tr><tr><td>text-embedding-ada-002</td><td>0.025</td><td>0.140</td><td>0.250</td><td>0.279</td><td>0.519</td><td>0.571</td></tr><tr><td>ChatGPT</td><td>0.034</td><td>0.172</td><td>1</td><td>0.105</td><td>0.264</td><td>1</td></tr><tr><td>+MESE</td><td>0.036</td><td>0.195</td><td>一</td><td>0.240</td><td>0.508</td><td></td></tr><tr><td>+ text-embedding-ada-002</td><td>0.037</td><td>0.174</td><td>1</td><td>0.310</td><td>0.539</td><td>1</td></tr></table>
93
+
94
+ Table 3: The relevance degree of the explanations generated by ChatGPT to the conversation context.
95
+
96
+ <table><tr><td>Dataset</td><td>Irrelevant</td><td>Partially relevant</td><td>Highly relevant</td></tr><tr><td>ReDial</td><td>8%</td><td>20%</td><td>72%</td></tr><tr><td>OpenDialKG</td><td>20%</td><td>16%</td><td>64%</td></tr></table>
97
+
98
+ 2022) model provided in the OpenAI API as the unsupervised method (ChatGPT $^ +$ MESE).
99
+
100
+ # 3.2 Evaluation Results
101
+
102
+ We first compare the accuracy of ChatGPT with CRS baselines following existing work (Chen et al., 2019; Zhang et al., 2023). Then, to examine the inner working principles of ChatGPT, we showcase the explanations generated by it to assess its explainability as suggested by Guo et al. (2023).
103
+
104
+ # 3.2.1 Accuracy
105
+
106
+ The performance comparison of different methods for CRS is shown in Table 2. Surprisingly, ChatGPT does not perform as well as we expect. When using zero-shot prompting, ChatGPT only achieves average performance among these baselines and is far behind the top-performing methods. When integrating external recommendation models, its performance can be effectively improved. In particular, on the OPENDIALKG dataset, the performance gap is significantly reduced. It indicates that the responses generated by ChatGPT can help external models understand the user preference. However, there is still a noticeable performance gap on the REDIAL dataset.
107
+
108
+ # 3.2.2 Explainability
109
+
110
+ To better understand how ChatGPT conducts the recommendation, we require it to generate an explanation to examine the inner working principles. Then, we employ two annotators to judge the relevance degree (irrelevant, partially relevant, or highly relevant) of the explanation to the conversation context on 100 randomly sampled failure examples. The Cohen’s Kappa between annotators is 0.77, indicating good agreement. The results in Table 3 indicate that ChatGPT can give highly relevant explanations in most of the cases. Here is one example:
111
+
112
+ # [Conversation History]
113
+
114
+ User: Hi I want a movie like Super Troopers (2001) [Label] Police Academy (1984) [Prediction of ChatGPT] Beerfest (2006), The Other Guys (2010), Hot Fuzz (2007), . . . [Explanation of ChatGPT] . . . I have recommended movies that share similar themes of comedy, law enforcement, and absurdity. . . . Some of the movies on the list are also from the same creators or feature some of the same actors as Super Troopers. . . .
115
+
116
+ As we can see, ChatGPT understands the user preference and gives reasonable explanations, suggesting that it can be a good CRS. However, this contradicts its poor performance in accuracy. It motivates us to investigate the reasons for failure.
117
+
118
+ # 3.3 Why does ChatGPT Fail?
119
+
120
+ In this part, we analyze why does ChatGPT fail in terms of accuracy. Through inspecting the incorrect recommendations (evaluated according to the annotated labels), we identify two main causes and detail them in the following part.
121
+
122
+ ![](images/cf3275e6e197d5d87e82986922904d1827602eb0c7bf89b3b6bd5f7c2d87ada9.jpg)
123
+ Figure 2: Two failure examples of ChatGPT for conversation recommendation.
124
+
125
+ Lack of Explicit User Preference. The examples in this class typically have very short conversation turns, in which CRSs may be unable to collect sufficient evidence to accurately infer the user intention. Furthermore, the conversations are mainly collected in chit-chat form, making it vague to reflect the real user preference. To see this, we present an example in Figure 2(a). As we can see, the user does not provide any explicit information about the expected items, which is a common phenomenon as observed by Wang et al. (2022a). To verify this, we randomly sample 100 failure examples with less than three turns and invite two annotators to determine whether the user preference is ambiguous. Among them, $51 \%$ examples are annotated as ambiguous, and the rest $49 \%$ are considered clear, which confirms our speculation. The Cohen’s Kappa between annotators is 0.75. Compared with existing models trained on CRS datasets, such an issue is actually more serious for ChatGPT, since it is not fine-tuned and makes prediction solely based on the dialogue context.
126
+
127
+ Lack of Proactive Clarification. A major limitation in evaluation is that it has to strictly follow existing conversation flows. However, in realworld scenarios, a CRS would propose proactive clarification when needed, which is not supported by existing evaluation protocols. To see this, we present an example in Figure 2(b), As we can see, the response in the dataset directly gives recommendations, while ChatGPT asks for detailed user preference. Since so many items fit the current requirement, it is reasonable to seek clarification before making a recommendation. However, such cases cannot be well handled in the existing evaluation protocol since no more user responses are available in this process. To verify this, we randomly sample 100 failure examples for two annotators to classify the responses generated by ChatGPT (clarification, recommendation, or chit-chat). We find that $36 \%$ of them are clarifications, $11 \%$ are chit-chat, and only $53 \%$ are recommendations, suggesting the importance of considering clarification in evaluation. The Cohen’s Kappa between annotators is 0.81.
128
+
129
+ To summarize, there are two potential issues with the existing evaluation protocol: lack of explicit user preference and proactive clarification. Although conversation-level evaluation (Zhang and Balog, 2020) allows system-user interaction, it is limited to pre-defined conversation flows or template-based utterances (Lei et al., 2020; Zhang and Balog, 2020), failing to capture the intricacies and nuances of real-world conversations.
130
+
131
+ # 4 A New Evaluation Approach for CRSs
132
+
133
+ Considering the issues with the existing evaluation protocol, in this section, we propose an alternative evaluation approach, iEvaLM, which features interactive evaluation with LLM-based user simulation, as illustrated in Figure 3. We demonstrate its effectiveness and reliability through experiments.
134
+
135
+ # 4.1 Overview
136
+
137
+ Our approach is seamlessly integrated with existing CRS datasets. Each system-user interaction extends over one of the observed human-annotated conversations. The key idea of our approach is to conduct close-to-real user simulation based on the excellent role-play capacities of LLMs (Fu et al., 2023). We take the ground-truth items as the user preference and use them to set up the persona of the LLM-based simulated user via instructions. After the interaction, we assess not only the accuracy by comparing predictions with the ground-truth items but also the explainability by querying an LLMbased scorer with the generated explanations.
138
+
139
+ ![](images/73cb2efaea6a0f69d19880cca627f1e2da55aca404313433d3e8bf0ee18b8fa9.jpg)
140
+ Figure 3: Our evaluation approach iEvaLM. It is based on existing CRS datasets and has two settings: free-form chit-chat (left) and attribute-based question answering (right).
141
+
142
+ # 4.2 Interaction Forms
143
+
144
+ To make a comprehensive evaluation, we consider two types of interaction: attribute-based question answering and free-form chit-chat.
145
+
146
+ In the first type, the action of the system is restricted to choosing one of the $k$ pre-defined attributes to ask the user or making recommendations. At each round, we first let the system decide on these $k + 1$ options, and then the user gives the template-based response: answering questions with the attributes of the target item or giving feedback on recommendations. An example interaction round would be like: “System: Which genre do you like? User: Sci-fi and action.”
147
+
148
+ In contrast, the second type does not impose any restrictions on the interaction, and both the system and user are free to take the initiative. An example interaction round would be like: “System: Do you have any specific genre in mind? User: I’m looking for something action-packed with a lot of special effects.”
149
+
150
+ # 4.3 User Simulation
151
+
152
+ To support the interaction with the system, we employ LLMs for user simulation. The simulated user can take on one of the following three behaviors:
153
+
154
+ • Talking about preference. When the system makes a clarification or elicitation about user preference, the simulated user would respond with the information about the target item.
155
+
156
+ • Providing feedback. When the system recommends an item list, the simulated user would check each item and provide positive feedback if finding the target or negative feedback if not.
157
+
158
+ • Completing the conversation. If one of the target items is recommended by the system or the interaction reaches a certain number of rounds, the simulated user would finish the conversation.
159
+
160
+ Specifically, we use the ground-truth items from existing datasets to construct realistic personas for simulated users. This is achieved by leveraging the text-davinci-003 (Ouyang et al., 2022) model provided in the OpenAI API, which demonstrates superior instruction following capacity as an evaluator (Xu et al., 2023; Li et al., 2023). To adapt text-davinci-003 for user simulation, we set its behaviors through manual instructions (see Appendix C.3). In these instructions, we first fill the ground-truth items into the persona template and then define their behaviors using a set of manually crafted rules. At each turn, we append the conversation to the instruction as input. When calling the API, we set max_tokens to 128, temperature to 0, and leave other parameters at their default values. The maximum number of interaction rounds is set to 5.
161
+
162
+ # 4.4 Performance Measurement
163
+
164
+ We consider both subjective and objective metrics to measure the recommendation performance as well as the user experience. For the objective metric, we use recall as stated in Section 2.2 to evaluate every recommendation action in the interaction process. For the subjective metric, following Chen et al. (2022), we use persuasiveness to assess the quality of explanations for the last recommendation action in the interaction process, aiming to evaluate whether the user can be persuaded to accept recommendations. The value range of this metric is {0, 1, 2}. To reduce the need for humans, we propose an LLM-based scorer that can automatically give the score through prompting. Specifically, we use the text-davinci-003 (Ouyang et al., 2022) model provided in the OpenAI API as the scorer with the conversation, explanation, and scoring rules concatenated as prompts (see Appendix C.4). Other parameters remain the same as the simulated user.
165
+
166
+ Table 4: Performance comparison in terms of naturalness and usefulness in the single-turn and multi-turn settings. Each value represents the percentage of pairwise comparisons that the specific model wins or ties.
167
+
168
+ <table><tr><td rowspan="2">Setting</td><td colspan="2">Single-turn</td><td colspan="2">Multi-turn</td></tr><tr><td>Naturalness</td><td>Usefulness</td><td>Naturalness</td><td>Usefulness</td></tr><tr><td>DialoGPT</td><td>13%</td><td>23%</td><td>11%</td><td>31%</td></tr><tr><td>iEvaLM</td><td>36%</td><td>43%</td><td>55%</td><td>38%</td></tr><tr><td>Tie</td><td>51%</td><td>34%</td><td>34%</td><td>31%</td></tr><tr><td>Human</td><td>10%</td><td>34%</td><td>17%</td><td>28%</td></tr><tr><td>iEvaLM</td><td>39%</td><td>33%</td><td>35%</td><td>40%</td></tr><tr><td>Tie</td><td>51%</td><td>33%</td><td>48%</td><td>32%</td></tr></table>
169
+
170
+ # 5 Evaluation Results
171
+
172
+ In this section, we assess the quality of the user simulator and the performance of CRSs using our proposed evaluation approach.
173
+
174
+ # 5.1 The Quality of User Simulator
175
+
176
+ To evaluate the performance of CRSs in an interactive setting, we construct user simulators based on ground-truth items from existing datasets. The simulated users should cooperate with the system to find the target item, e.g., answer clarification questions and provide feedback on recommendations. However, it is not easy to directly evaluate the quality of user simulators.
177
+
178
+ Our solution is to make use of the annotated conversations in existing datasets. We first use the ground-truth items to set up the persona of the user simulator and then let them interact with the systems played by humans. They are provided with the first round of annotated conversations to complete the rest. Then, we can compare the completed conversations with the annotated ones for evaluation. Following Sekulic et al. ´ (2022), we assess the naturalness and usefulness of the generated utterances in the settings of single-turn and multi-turn free-form chit-chat. Naturalness means that the utterances are fluent and likely to be generated by humans, and usefulness means that the utterances are consistent with the user preference. We compare our user simulator with a fine-tuned version of DialoGPT and the original conversations in the REDIAL dataset.
179
+
180
+ Specifically, we first invite five annotators to play the role of the system and engage in interactions with each user simulator. The interactions are based on the first round of conversations from 100 randomly sampled examples. Then, we employ another two annotators to make pairwise evaluations, where one is generated by our simulator and the other comes from DialoGPT or the dataset. We count a win for a method when both annotators agree that its utterance is better; otherwise, we count a tie. The Cohen’s Kappa between annotators is 0.73. Table 4 demonstrates the results. We can see that our simulator significantly outperforms DialoGPT, especially in terms of naturalness in the multi-turn setting, which demonstrates the strong language generation capability of LLMs. Furthermore, the usefulness of our simulator is better than others, indicating that it can provide helpful information to cooperate with the system.
181
+
182
+ # 5.2 The Performance of CRS
183
+
184
+ In this part, we compare the performance of existing CRSs and ChatGPT using different evaluation approaches. For ChatGPT, we use ChatGPT $^ +$ text-embedding-ada-002 due to its superior performance in traditional evaluation (see Appendix C.2).
185
+
186
+ # 5.2.1 Main Results
187
+
188
+ The evaluation results are presented in Table 5 and Table 6. Overall, most models demonstrate improved accuracy and explainability compared to the traditional approach. Among existing CRSs, the order of performance is $U n i C R S > B A R C O R$ $> K B R D$ . Both UniCRS and BARCOR utilize pre-trained models to enhance conversation abilities. Additionally, UniCRS incorporates KGs into prompts to enrich entity semantics for better understanding user preferences. It indicates that existing CRSs have the ability to interact with users for better recommendations and user experience, which is an important aspect overlooked in the traditional evaluation.
189
+
190
+ For ChatGPT, there is a significant performance improvement in both Recall and Persuasiveness, and the Recall $@ 1 0$ value even surpassing the Recall $\textcircled { \omega } 2 5$ or Recall $\textcircled { a } 5 0$ value of most CRSs on the two datasets. This indicates that ChatGPT has superior interaction abilities compared with existing CRSs and can provide high-quality and persuasive recommendations with sufficient information about the user preference. The results demonstrate the effectiveness of iEvaLM in evaluating the accuracy and explainability of recommendations for CRSs, especially those developed with LLMs.
191
+
192
+ Table 5: Performance of CRSs and ChatGPT under different evaluation approaches, where “attr” denotes attributebased question answering and “free” denotes free-form chit-chat. $\mathbf { \hat { R } } \mathbf { \ @ } k ^ { \prime } \mathbf { \dot { \varepsilon } }$ refers to Recall $@ k$ . Since requiring too many items can sometimes be refused by ChatGPT, we only assess Recall $@ 1$ and 10 for it, while Recall $\textcircled { a } 5 0$ is marked as “–”. Numbers marked with \* indicate that the improvement is statistically significant compared with the rest methods (t-test with p-value $< 0 . 0 5$ ).
193
+
194
+ <table><tr><td colspan="2">Model</td><td colspan="3">KBRD</td><td colspan="3">BARCOR</td><td colspan="3">UniCRS</td><td colspan="3">ChatGPT</td></tr><tr><td colspan="2">Evaluation Approach</td><td>Original</td><td>iEvaLM (attr)</td><td>iEvaLM (free)</td><td>Original</td><td>iEvaLM (attr)</td><td>iEvaLM (free)</td><td>Original</td><td>iEvaLM (attr)</td><td>iEvaLM (free)</td><td>Original</td><td>iEvaLM (attr)</td><td>iEvaLM (free)</td></tr><tr><td rowspan="3">ReDial</td><td>R@1</td><td>0.028</td><td>0.039 (+39.3%)</td><td>0.035 (+25.0%)</td><td>0.031</td><td>0.034 (+9.7%)</td><td>0.034 (+9.7%)</td><td>0.050</td><td>0.053 (+6.0%)</td><td>0.107 (+114.0%)</td><td>0.037</td><td>0.191* (+416.2%)</td><td>0.146 (+294.6%)</td></tr><tr><td>R@10</td><td>0.169</td><td>0.196 (+16.0%)</td><td>0.198 (+17.2%)</td><td>0.170</td><td>0.201 (+18.2%)</td><td>0.190 (+11.8%)</td><td>0.215</td><td>0.238 (+10.7%)</td><td>0.317 (+47.4%)</td><td>0.174</td><td>0.536* (+208.0%)</td><td>0.440 (+152.9%)</td></tr><tr><td>R@50</td><td>0.366</td><td>0.436 (+19.1%)</td><td>0.453 (+23.8%)</td><td>0.372</td><td>0.427 (+14.8%)</td><td>0.467 (+25.5%)</td><td>0.413</td><td>0.520 (+25.9%)</td><td>0.602* (+45.8%)</td><td>1</td><td>1</td><td>二</td></tr><tr><td rowspan="3">OpenDialKG</td><td>R@1</td><td>0.231</td><td>0.131 (-43.3%)</td><td>0.234 (+1.3%)</td><td>0.312</td><td>0.264 (-15.4%)</td><td>0.314 (+0.6%)</td><td>0.308</td><td>0.180 (-41.6%)</td><td>0.314 (+1.9%)</td><td>0.310</td><td>0.299 (-3.5%)</td><td>0.400* (+29.0%)</td></tr><tr><td>R@10</td><td>0.423</td><td>0.293 (-30.7%)</td><td>0.431 (+1.9%)</td><td>0.453</td><td>0.423 (-6.7%)</td><td>0.458 (+1.1%)</td><td>0.513</td><td>0.393 (-23.4%)</td><td>0.538 (+4.9%)</td><td>0.539</td><td>0.604 (+12.1%)</td><td>0.715* (+32.7%)</td></tr><tr><td>R@25</td><td>0.492</td><td>0.377 (-23.4%)</td><td>0.509 (+3.5%)</td><td>0.510</td><td>0.482 (-5.5%)</td><td>0.530 (+3.9%)</td><td>0.574</td><td>0.458 (-20.2%)</td><td>0.609* (+6.1%)</td><td>1</td><td>1</td><td>1</td></tr></table>
195
+
196
+ Table 6: The persuasiveness of explanations. We only consider the setting of free-form chit-chat in iEvaLM. Numbers marked with \* indicate that the improvement is statistically significant compared with the rest methods (t-test with p-value $< 0 . 0 5$ ).
197
+
198
+ <table><tr><td>Model</td><td>Evaluation Approach</td><td>ReDial</td><td>OpenDialKG</td></tr><tr><td rowspan="2">KBRD</td><td>Original</td><td>0.638</td><td>0.824</td></tr><tr><td>iEvaLM</td><td>0.766 (+20.1%)</td><td>0.862 (+4.6%)</td></tr><tr><td rowspan="2">BARCOR</td><td>Original</td><td>0.667</td><td>1.149</td></tr><tr><td>iEvaLM</td><td>0.795 (+19.2%)</td><td>1.211</td></tr><tr><td rowspan="2">UniCRS</td><td>Original</td><td>0.685</td><td>(+5.4%) 1.128</td></tr><tr><td>iEvaLM</td><td>1.015</td><td>1.314</td></tr><tr><td rowspan="2">ChatGPT</td><td></td><td>(+48.2%)</td><td>(+16.5%)</td></tr><tr><td>Original iEvaLM</td><td>0.787 1.331*</td><td>1.221 1.513*</td></tr></table>
199
+
200
+ Comparing the two interaction settings, ChatGPT has demonstrated greater potential as a general-purpose CRS. Existing CRSs perform much worse in the setting of attribute-based question answering than in the traditional setting on the OPENDIALKG dataset. One possible reason is that they are trained on datasets with natural language conversations, which is inconsistent with the setting of attribute-based question answering. In contrast, ChatGPT performs much better in both settings on the two datasets, since it has been specially trained on conversational data. The results indicate the limitations of the traditional evaluation, which focuses only on a single conversation scenario, while our evaluation approach allows for a more holistic assessment of CRSs, providing valuable insights into their strengths and weaknesses across different types of interactions.
201
+
202
+ Table 7: The score distribution of persuasiveness (“unpersuasive” for 0, “partially persuasive” for 1, and “highly persuasive” for 2) from our LLM-based scorer and human on a random selection of 100 examples from the REDIAL dataset.
203
+
204
+ <table><tr><td>Method</td><td>Unpersuasive</td><td>Partially persuasive</td><td>Highly persuasive</td></tr><tr><td>iEvaLM</td><td>1%</td><td>5%</td><td>94%</td></tr><tr><td>Human</td><td>4%</td><td>7%</td><td>89%</td></tr></table>
205
+
206
+ # 5.2.2 The Reliability of Evaluation
207
+
208
+ Recall that LLMs are utilized in the user simulation and performance measurement parts of iEvaLM as alternatives for humans in Section 4. Considering that the generation of LLMs can be unstable, in this part, we conduct experiments to assess the reliability of the evaluation results compared with using human annotators.
209
+
210
+ First, recall that we introduce the subjective metric persuasiveness for evaluating explanations in Section 4.4. This metric usually requires human evaluation, and we propose an LLM-based scorer as an alternative. Here we evaluate the reliability of our LLM-based scorer by comparing with human annotators. We randomly sample 100 examples with the explanations generated by ChatGPT and ask our scorer and two annotators to rate them separately with the same instruction (see Appendix C). The Cohen’s Kappa between annotators is 0.83. Table 7 demonstrates that the two score distributions are similar, indicating the reliability of our LLMbased scorer as a substitute for human evaluators.
211
+
212
+ Table 8: The evaluation results using simulated and real users on a random selection of 100 examples from the REDIAL dataset.
213
+
214
+ <table><tr><td colspan="2">Evaluation Approach</td><td>KBRD</td><td>BARCOR</td><td>UniCRS</td><td>ChatGPT</td></tr><tr><td rowspan="2">iEvaLM</td><td>Recall@ 10</td><td>0.180</td><td>0.210</td><td>0.330</td><td>0.460</td></tr><tr><td>Persuasiveness</td><td>0.810</td><td>0.860</td><td>1.050</td><td>1.330</td></tr><tr><td rowspan="2">Human</td><td>Recall@ 10</td><td>0.210</td><td>0.250</td><td>0.370</td><td>0.560</td></tr><tr><td>Persuasiveness</td><td>0.870</td><td>0.930</td><td>1.120</td><td>1.370</td></tr></table>
215
+
216
+ Then, since we propose an LLM-based user simulator as a replacement for humans to interact with CRSs, we examine the correlation between the values of metrics when using real vs. simulated users. Following Section 4.3, both real and simulated users receive the same instruction (see Appendix C) to establish their personas based on the ground-truth items. Each user can interact with different CRSs for five rounds. We randomly select 100 instances and employ five annotators and our user simulator to engage in free-form chit-chat with different CRSs. The results are shown in Table 8. We can see that the ranking obtained from our user simulator is consistent with that of real users, and the absolute scores are also comparable. It suggests that our LLM-based user simulator is capable of providing convincing evaluation results and serves as a reliable alternative to human evaluators.
217
+
218
+ # 6 Conclusion
219
+
220
+ In this paper, we systematically examine the capability of ChatGPT for conversational recommendation on existing benchmark datasets and propose an alternative evaluation approach, iEvaLM. First, we show that the performance of ChatGPT was unsatisfactory. Through analysis of failure cases, the root cause is the existing evaluation protocol, which overly emphasizes the fitting of ground-truth items based on conversation context. To address this issue, we propose an interactive evaluation approach using LLM-based user simulators.
221
+
222
+ Through experiments with this new approach, we have the following findings: (1) ChatGPT is powerful and becomes much better in our evaluation than the currently leading CRSs in both accuracy and explainability; (2) Existing CRSs also get improved from the interaction, which is an important aspect overlooked by the traditional evaluation; and (3) ChatGPT shows great potential as a generalpurpose CRS under different settings and datasets. We also demonstrate the effectiveness and reliability of our evaluation approach.
223
+
224
+ Overall, our work contributes to the understanding and evaluation of LLMs such as ChatGPT for conversational recommendation, paving the way for further research in this field in the era of LLMs.
225
+
226
+ # Limitations
227
+
228
+ A major limitation of this work is the design of prompts for ChatGPT and LLM-based user simulators. We manually write several prompt candidates and select the one with the best performance on some representative examples due to the cost of calling model APIs. More effective prompting strategies like chain-of-thought can be explored for better performance, and the robustness of the evaluation framework to different prompts remains to be assessed.
229
+
230
+ In addition, our evaluation framework primarily focuses on the accuracy and explainability of recommendations, but it may not fully capture potential issues related to fairness, bias, or privacy concerns. Future work should explore ways to incorporate these aspects into the evaluation process to ensure the responsible deployment of CRSs.
231
+
232
+ # Acknowledgements
233
+
234
+ This work was partially supported by National Natural Science Foundation of China under Grant No. 62222215 and 72222022, Beijing Natural Science Foundation under Grant No. 4222027, and the Outstanding Innovative Talents Cultivation Funded Programs 2022 of Renmin University of China. Xin Zhao is the corresponding author.
235
+
236
+ # References
237
+
238
+ Jafar Afzali, Aleksander Mark Drzewiecki, Krisztian Balog, and Shuo Zhang. 2023. Usersimcrs: A user simulation toolkit for evaluating conversational recommender systems. arXiv preprint arXiv:2301.05544.
239
+ Krisztian Balog and ChengXiang Zhai. 2023. User simulation for evaluating information access systems. arXiv preprint arXiv:2306.08550.
240
+ Yejin Bang, Samuel Cahyawijaya, Nayeon Lee, Wenliang Dai, Dan Su, Bryan Wilie, Holy Lovenia, Ziwei Ji, Tiezheng Yu, Willy Chung, et al. 2023. A multitask, multilingual, multimodal evaluation of chatgpt on reasoning, hallucination, and interactivity. arXiv preprint arXiv:2302.04023.
241
+ Hongshen Chen, Xiaorui Liu, Dawei Yin, and Jiliang Tang. 2017. A survey on dialogue systems: Re
242
+
243
+ cent advances and new frontiers. Acm Sigkdd Explorations Newsletter, 19(2):25–35.
244
+
245
+ Qibin Chen, Junyang Lin, Yichang Zhang, Ming Ding, Yukuo Cen, Hongxia Yang, and Jie Tang. 2019. Towards knowledge-based recommender dialog system. In Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP), pages 1803–1813.
246
+
247
+ Xu Chen, Yongfeng Zhang, and Ji-Rong Wen. 2022. Measuring" why" in recommender systems: a comprehensive survey on the evaluation of explainable recommendation. arXiv preprint arXiv:2202.06466.
248
+
249
+ Sunhao Dai, Ninglu Shao, Haiyuan Zhao, Weijie Yu, Zihua Si, Chen Xu, Zhongxiang Sun, Xiao Zhang, and Jun Xu. 2023. Uncovering chatgpt’s capabilities in recommender systems. arXiv preprint arXiv:2305.02182.
250
+
251
+ Yang Deng, Wenxuan Zhang, Weiwen Xu, Wenqiang Lei, Tat-Seng Chua, and Wai Lam. 2023. A unified multi-task learning framework for multi-goal conversational recommender systems. ACM Transactions on Information Systems, 41(3):1–25.
252
+
253
+ Yao Fu, Hao Peng, Tushar Khot, and Mirella Lapata. 2023. Improving language model negotiation with self-play and in-context learning from ai feedback. arXiv preprint arXiv:2305.10142.
254
+
255
+ Chongming Gao, Wenqiang Lei, Xiangnan He, Maarten de Rijke, and Tat-Seng Chua. 2021. Advances and challenges in conversational recommender systems: A survey. AI Open, 2:100–126.
256
+
257
+ Jianfeng Gao, Michel Galley, and Lihong Li. 2018. Neural approaches to conversational ai. In The 41st International ACM SIGIR Conference on Research & Development in Information Retrieval, pages 1371– 1374.
258
+
259
+ Shuyu Guo, Shuo Zhang, Weiwei Sun, Pengjie Ren, Zhumin Chen, and Zhaochun Ren. 2023. Towards explainable conversational recommender systems. arXiv preprint arXiv:2305.18363.
260
+
261
+ Dietmar Jannach, Ahtsham Manzoor, Wanling Cai, and Li Chen. 2021. A survey on conversational recommender systems. ACM Computing Surveys (CSUR), 54(5):1–36.
262
+
263
+ Wang-Cheng Kang, Jianmo Ni, Nikhil Mehta, Maheswaran Sathiamoorthy, Lichan Hong, Ed Chi, and Derek Zhiyuan Cheng. 2023. Do llms understand user preferences? evaluating llms on user rating prediction. arXiv preprint arXiv:2305.06474.
264
+
265
+ Jacob Devlin Ming-Wei Chang Kenton and Lee Kristina Toutanova. 2019. Bert: Pre-training of deep bidirectional transformers for language understanding. In Proceedings of naacL-HLT, volume 1, page 2.
266
+
267
+ Wenqiang Lei, Xiangnan He, Yisong Miao, Qingyun Wu, Richang Hong, Min-Yen Kan, and Tat-Seng Chua. 2020. Estimation-action-reflection: Towards deep interaction between conversational and recommender systems. In Proceedings of the 13th International Conference on Web Search and Data Mining, pages 304–312.
268
+
269
+ Mike Lewis, Yinhan Liu, Naman Goyal, Marjan Ghazvininejad, Abdelrahman Mohamed, Omer Levy, Veselin Stoyanov, and Luke Zettlemoyer. 2020. Bart: Denoising sequence-to-sequence pre-training for natural language generation, translation, and comprehension. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics, pages 7871–7880.
270
+
271
+ Raymond Li, Samira Ebrahimi Kahou, Hannes Schulz, Vincent Michalski, Laurent Charlin, and Chris Pal. 2018. Towards deep conversational recommendations. Advances in neural information processing systems, 31.
272
+
273
+ Xuechen Li, Tianyi Zhang, Yann Dubois, Rohan Taori, Ishaan Gulrajani, Carlos Guestrin, Percy Liang, and Tatsunori B. Hashimoto. 2023. Alpacaeval: An automatic evaluator of instruction-following models. https://github.com/tatsu-lab/alpaca_eval.
274
+
275
+ Seungwhan Moon, Pararth Shah, Anuj Kumar, and Rajen Subba. 2019. Opendialkg: Explainable conversational reasoning with attention-based walks over knowledge graphs. In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics, pages 845–854.
276
+
277
+ Arvind Neelakantan, Tao Xu, Raul Puri, Alec Radford, Jesse Michael Han, Jerry Tworek, Qiming Yuan, Nikolas Tezak, Jong Wook Kim, Chris Hallacy, et al. 2022. Text and code embeddings by contrastive pretraining. arXiv preprint arXiv:2201.10005.
278
+
279
+ Long Ouyang, Jeffrey Wu, Xu Jiang, Diogo Almeida, Carroll Wainwright, Pamela Mishkin, Chong Zhang, Sandhini Agarwal, Katarina Slama, Alex Ray, et al. 2022. Training language models to follow instructions with human feedback. Advances in Neural Information Processing Systems, 35:27730–27744.
280
+
281
+ Gustavo Penha and Claudia Hauff. 2020. What does bert know about books, movies and music? probing bert for conversational recommendation. In Proceedings of the 14th ACM Conference on Recommender Systems, pages 388–397.
282
+
283
+ Chengwei Qin, Aston Zhang, Zhuosheng Zhang, Jiaao Chen, Michihiro Yasunaga, and Diyi Yang. 2023. Is chatgpt a general-purpose natural language processing task solver? arXiv preprint arXiv:2302.06476.
284
+
285
+ Ivan Sekulic, Mohammad Aliannejadi, and Fabio ´ Crestani. 2022. Evaluating mixed-initiative conversational search systems via user simulation. In Proceedings of the Fifteenth ACM International Conference on Web Search and Data Mining, pages 888–896.
286
+
287
+ Quan Tu, Shen Gao, Yanran Li, Jianwei Cui, Bin Wang, and Rui Yan. 2022. Conversational recommendation via hierarchical information modeling. In Proceedings of the 45th International ACM SIGIR Conference on Research and Development in Information Retrieval, pages 2201–2205.
288
+
289
+ Lingzhi Wang, Huang Hu, Lei Sha, Can Xu, Daxin Jiang, and Kam-Fai Wong. 2022a. Recindial: A unified framework for conversational recommendation with pretrained language models. In Proceedings of the 2nd Conference of the Asia-Pacific Chapter of the Association for Computational Linguistics and the 12th International Joint Conference on Natural Language Processing, pages 489–500.
290
+
291
+ Ting-Chun Wang, Shang-Yu Su, and Yun-Nung Chen. 2022b. Barcor: Towards a unified framework for conversational recommendation systems. arXiv preprint arXiv:2203.14257.
292
+
293
+ Xiaolei Wang, Kun Zhou, Xinyu Tang, Wayne Xin Zhao, Fan Pan, Zhao Cao, and Ji-Rong Wen. 2023. Improving conversational recommendation systems via counterfactual data simulation. In Proceedings of the 29th ACM SIGKDD Conference on Knowledge Discovery and Data Mining, KDD 2023, Long Beach, CA, USA, August 6-10, 2023, pages 2398– 2408. ACM.
294
+
295
+ Xiaolei Wang, Kun Zhou, Ji-Rong Wen, and Wayne Xin Zhao. 2022c. Towards unified conversational recommender systems via knowledge-enhanced prompt learning. In Proceedings of the 28th ACM SIGKDD Conference on Knowledge Discovery and Data Mining, pages 1929–1937.
296
+
297
+ Le Wu, Xiangnan He, Xiang Wang, Kun Zhang, and Meng Wang. 2022. A survey on accuracy-oriented neural recommendation: From collaborative filtering to information-rich recommendation. IEEE Transactions on Knowledge and Data Engineering.
298
+
299
+ Qiantong Xu, Fenglu Hong, Bo Li, Changran Hu, Zhengyu Chen, and Jian Zhang. 2023. On the tool manipulation capability of open-source large language models. arXiv preprint arXiv:2305.16504.
300
+
301
+ Bowen Yang, Cong Han, Yu Li, Lei Zuo, and Zhou Yu. 2022. Improving conversational recommendation systems’ quality with context-aware item metainformation. In Findings of the Association for Computational Linguistics: NAACL 2022, pages 38–48.
302
+
303
+ Shuo Zhang and Krisztian Balog. 2020. Evaluating conversational recommender systems via user simulation. In Proceedings of the 26th acm sigkdd international conference on knowledge discovery & data mining, pages 1512–1520.
304
+
305
+ Xiaoyu Zhang, Xin Xin, Dongdong Li, Wenxuan Liu, Pengjie Ren, Zhumin Chen, Jun Ma, and Zhaochun Ren. 2023. Variational reasoning over incomplete knowledge graphs for conversational recommendation. In Proceedings of the Sixteenth ACM International Conference on Web Search and Data Mining, pages 231–239.
306
+
307
+ Yizhe Zhang, Siqi Sun, Michel Galley, Yen-Chun Chen, Chris Brockett, Xiang Gao, Jianfeng Gao, Jingjing Liu, and William B Dolan. 2020. Dialogpt: Largescale generative pre-training for conversational response generation. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics: System Demonstrations, pages 270–278.
308
+
309
+ Yongfeng Zhang, Xu Chen, Qingyao Ai, Liu Yang, and W Bruce Croft. 2018. Towards conversational search and recommendation: System ask, user respond. In Proceedings of the 27th acm international conference on information and knowledge management, pages 177–186.
310
+
311
+ Wayne Xin Zhao, Kun Zhou, Junyi Li, Tianyi Tang, Xiaolei Wang, Yupeng Hou, Yingqian Min, Beichen Zhang, Junjie Zhang, Zican Dong, et al. 2023a. A survey of large language models. arXiv preprint arXiv:2303.18223.
312
+
313
+ Weixiang Zhao, Yanyan Zhao, Xin Lu, Shilong Wang, Yanpeng Tong, and Bing Qin. 2023b. Is chatgpt equipped with emotional dialogue capabilities? arXiv preprint arXiv:2304.09582.
314
+
315
+ Zhipeng Zhao, Kun Zhou, Xiaolei Wang, Wayne Xin Zhao, Fan Pan, Zhao Cao, and Ji-Rong Wen. 2023c. Alleviating the long-tail problem in conversational recommender systems. In Proceedings of the 17th ACM Conference on Recommender Systems, pages 374–385.
316
+
317
+ Jinfeng Zhou, Bo Wang, Ruifang He, and Yuexian Hou. 2021a. Crfr: Improving conversational recommender systems via flexible fragments reasoning on knowledge graphs. In Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing, pages 4324–4334.
318
+
319
+ Jinfeng Zhou, Bo Wang, Minlie Huang, Dongming Zhao, Kun Huang, Ruifang He, and Yuexian Hou. 2022. Aligning recommendation and conversation via dual imitation. In Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing, pages 549–561, Abu Dhabi, United Arab Emirates. Association for Computational Linguistics.
320
+
321
+ Kun Zhou, Xiaolei Wang, Yuanhang Zhou, Chenzhan Shang, Yuan Cheng, Wayne Xin Zhao, Yaliang Li, and Ji-Rong Wen. 2021b. Crslab: An open-source toolkit for building conversational recommender system. In Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing: System Demonstrations, pages 185–193.
322
+
323
+ Kun Zhou, Wayne Xin Zhao, Shuqing Bian, Yuanhang Zhou, Ji-Rong Wen, and Jingsong Yu. 2020. Improving conversational recommender systems via knowledge graph based semantic fusion. In Proceedings of the 26th ACM SIGKDD international conference on knowledge discovery & data mining, pages 1006– 1014.
324
+
325
+ ![](images/35fe820fff15db6b661cb28a7b5b6b51971aa79264c3a34560f6deae1f9938f2.jpg)
326
+ Figure 4: The performance of ChatGPT with different interaction rounds under the setting of attribute-based question answering (attr) and free-form chit-chat (free) on the REDIAL dataset.
327
+
328
+ # A The Influence of the Number of Interaction Rounds in iEvaLM
329
+
330
+ Interacting with the user for multiple rounds typically leads to more information and improved recommendation accuracy. However, users have limited patience and may leave the interaction when they become exhausted. It is important to investigate the relationship between the number of interaction rounds and performance. Following the setting in our approach, the interaction between ChatGPT and users is start from the observed humanannotated conversation in each dataset example, and we set the maximum interaction rounds to values from {1, 2, 3, 4, 5}, in order to evaluate the changes in recommendation accuracy.
331
+
332
+ Figure 4 shows the results of Recall $@ 1 0$ on the REDIAL dataset. In attribute-based question answering, the performance keeps increasing and reaches saturation at round 4. This observation aligns with our conversation setting, since the REDIAL dataset only has three attributes to inquire about. In free-form chit-chat, the performance curve is steep between rounds 1 and 3, while it is relatively flat between rounds 3 and 5. This pattern may be attributed to insufficient information in the initial round and marginal information in the last rounds. Since the user will gradually get exhausted with the progress of the interaction, how to optimize the conversation strategy remains to be further studied.
333
+
334
+ # B Related Work
335
+
336
+ In this section, we summarize the related work from the following perspectives.
337
+
338
+ # B.1 Conversational Recommender System
339
+
340
+ The fields of conversation intelligence (Chen et al., 2017; Gao et al., 2018) and recommendation systems (Wu et al., 2022) have seen significant progress in recent years. One promising development is the integration of these two fields, leading to the emergence of conversational recommender systems (CRSs) (Jannach et al., 2021; Gao et al., 2021). CRSs provide recommendations to users through conversational interactions, which has the potential to significantly improve the user experience.
341
+
342
+ One popular approach (Lei et al., 2020; Tu et al., 2022) assumes that interactions with users primarily take the form of question answering, where users are asked about their preferences for items and their attributes. The goal is to learn an optimal interaction strategy that captures user preferences and provides accurate recommendations in as few turns as possible. However, this approach often relies on hand-crafted templates and does not explicitly model the language aspect of CRSs. Another approach (Zhang et al., 2023; Zhou et al., 2022) focuses on engaging users in more free-form natural language conversations, such as chit-chat. The aim is to capture user preferences from the conversation context and generate recommendations using persuasive responses.
343
+
344
+ Our work belongs to the second category. In this work, we systematically evaluate the performance of large language models (LLMs) like ChatGPT for conversational recommendation on large-scale datasets.
345
+
346
+ # B.2 Language Models for Conversational Recommendation
347
+
348
+ There have been recent studies on how to integrate language models (LMs) into CRSs. One notable investigation by Penha and Hauff (2020) evaluates the performance of the pre-trained language model (PLM) BERT (Kenton and Toutanova, 2019) in conversational recommendation. Other studies (Wang et al., $2 0 2 2 \mathrm { c }$ ; Yang et al., 2022; Deng et al., 2023) primarily utilize PLMs as the foundation to build unified CRSs, capable of performing various tasks using a single model instead of multiple components. However, the current approaches are mainly confined to small-size LMs like BERT (Kenton and Toutanova, 2019) and DialoGPT (Zhang et al., 2020).
349
+
350
+ In this paper, we focus on the evaluation of CRSs developed with not only PLMs but also LLMs and propose a new evaluation approach iEvaLM.
351
+
352
+ # B.3 Evaluation and User Simulation
353
+
354
+ The evaluation of CRSs remains an area that has not been thoroughly explored in existing literature. Previous studies have primarily focused on turnlevel evaluation (Chen et al., 2019), where the system output of a single turn is compared against ground-truth labels for two major tasks: conversation and recommendation. Some researchers have also adopted conversation-level evaluation to assess conversation strategies (Lei et al., 2020; Zhang et al., 2018; Balog and Zhai, 2023; Afzali et al., 2023). In such cases, user simulation is often employed as a substitute for human evaluation. These approaches typically involve collecting real user interaction history (Lei et al., 2020) or reviews (Zhang et al., 2018) to represent the preferences of simulated users. Zhou et al. (2021b) develop an open-source toolkit called CRSLab, which provides extensive and standard evaluation protocols. However, due to the intricate and interactive nature of conversational recommendation, the evaluation is often constrained by pre-defined conversation flows or template-based utterances. Consequently, this limitation hinders the comprehensive assessment of the practical utility of CRSs.
355
+
356
+ In our work, we propose an interactive evaluation approach iEvaLM with LLM-based user simulators, which has a strong instruction-following ability and can flexibly adapt to different CRSs based on the instruction without further tuning.
357
+
358
+ # C Prompts Used in the Paper
359
+
360
+ # C.1 Prompts for ChatGPT in the Traditional Evaluation
361
+
362
+ We use the following prompts for zero-shot prompting in section 3.1.
363
+
364
+ • ReDial
365
+
366
+ Recommend 10 items that are consistent with user preference. The recommendation list can contain items that the dialog mentioned before. The format of the recommendation list is: no. title (year). Don’t mention anything other than the title of items in your recommendation list.
367
+
368
+ • OpenDialKG
369
+
370
+ Recommend 10 items that are consistent with user preference. The recommendation list can contain items that the dialog mentioned before. The format of the recommendation list is: no. title. Don’t mention anything other than the title of items in your recommendation list.
371
+
372
+ # C.2 Prompts for ChatGPT in iEvaLM
373
+
374
+ We use the following prompts for ChatGPT in our new evaluation approach.
375
+
376
+ # C.2.1 Recommendation
377
+
378
+ # Free-Form Chit-Chat.
379
+
380
+ • ReDial
381
+
382
+ You are a recommender chatting with the user to provide recommendation. You must follow the instructions below during chat.
383
+ If you do not have enough information about user preference, you should ask the user for his preference.
384
+ If you have enough information about user preference, you can give recommendation. The recommendation list must contain 10 items that are consistent with user preference. The recommendation list can contain items that the dialog mentioned before. The format of the recommendation list is: no. title (year). Don’t mention anything other than the title of items in your recommendation list. You are a recommender chatting with the user to provide recommendation. You must follow the instructions below during chat.
385
+ If you do not have enough information about user preference, you should ask the user for his preference.
386
+ If you have enough information about user preference, you can give recommendation. The recommendation list must contain 10 items that are consistent with user preference. The recommendation list can contain items that the dialog mentioned before. The format of the recommendation list is: no. title. Don’t mention anything other than the title of items in your recommendation list.
387
+
388
+ Attribute-Based Question Answering. “{}” refers to the options that have been selected.
389
+
390
+ • ReDial
391
+
392
+ To recommend me items that I will accept, you can choose one of the following options.
393
+
394
+ A: ask my preference for genre B: ask my preference for actor C: ask my preference for director D: I can directly give recommendations You have selected {}, do not repeat them. Please enter the option character.
395
+
396
+ • OpenDialKG
397
+
398
+ To recommend me items that I will accept, you can choose one of the following options.
399
+
400
+ A: ask my preference for genre B: ask my preference for actor C: ask my preference for director D: ask my preference for writer E: I can directly give recommendations You have selected {}, do not repeat them. Please enter the option character.
401
+
402
+ # C.2.2 Explainability
403
+
404
+ Please explain your last time of recommendation.
405
+
406
+ # C.3 Prompts for the User Simulator in iEvaLM
407
+
408
+ We use the following prompts for text-davinci-003 to play the role of the user during interaction.
409
+
410
+ Free-Form Chit-Chat. “{}” refers to the item labels of each example in the datasets.
411
+
412
+ You are a seeker chatting with a recommender for recommendation. Your target items: {}. You must follow the instructions below during chat. If the recommender recommends {}, you should accept. If the recommender recommends other items, you should refuse them and provide the information about {}. You should never directly tell the target item title. If the recommender asks for your preference, you should provide the information about {}. You should never directly tell the target item title.
413
+
414
+ # Attribute-Based Question Answering.
415
+
416
+ • When the recommended item list contains at least one of the target items:
417
+
418
+ That’s perfect, thank you!
419
+
420
+ • When the recommended item list does not contain any target item:
421
+
422
+ I don’t like them.
423
+
424
+ • When the system asks about the preference over pre-defined attributes, we use the attributes of target items as the answer if they exist, otherwise:
425
+
426
+ Sorry, no information about this.
427
+
428
+ # C.4 Prompts for the LLM-based Scorer in iEvaLM
429
+
430
+ We use the following prompts for text-davinci-003 to score the persuasiveness of explanations. “{}” refers to the item labels of each example in the datasets.
431
+
432
+ Does the explanation make you want to accept the recommendation? Please give your score.
433
+ If mention one of [{}], give 2.
434
+ Else if you think recommended items are worse than [{}], give 0.
435
+ Else if you think recommended items are comparable to [{}] according to the explanation, give 1.
436
+ Else if you think recommended items are better than [{}] according to the explanation, give 2.
437
+ Only answer the score number.
md/dev/QeRAyn4igEA/QeRAyn4igEA.md ADDED
@@ -0,0 +1,449 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Block-wise Separable Convolutions: An Alternative Way to Factorize Standard Convolutions
2
+
3
+ Anonymous Author(s)
4
+ Affiliation
5
+ Address
6
+ email
7
+
8
+ # Abstract
9
+
10
+ 1 Convolutional neural networks (CNNs) have demonstrated great capability of solv
11
+ 2 ing various computer vision tasks with nice prediction performance. Nevertheless,
12
+ 3 the higher accuracy often comes with an increasing number of model parameters
13
+ 4 and large computational cost. This raises challenges in deploying them in resource
14
+ 5 limited devices. In this paper, we introduce block-wise separable convolutions
15
+ 6 (BlkSConv) to replace the standard convolutions in order to compress deep CNN
16
+ 7 models. First, BlkSConv expresses the standard convolutional kernel as an ordered
17
+ 8 set of block vectors each of which is a linear combination of fixed basis block
18
+ 9 vectors. Then it eliminates most basis block vectors and their corresponding coef
19
+ 10 ficients to obtain an approximated convolutional kernel. Moreover, the proposed
20
+ 11 BlkSConv operation can be efficiently realized via a combination of pointwise and
21
+ 12 group-wise convolutions. Thus the constructed networks have smaller model size
22
+ 13 and fewer multiply-adds operations while keeping comparable prediction accu
23
+ 14 racy. However, it is unknown how to search a qualified hyperparameter setting
24
+ 15 of the block depth and number of basis block vectors. To address this problem,
25
+ 16 we develop a hyperparameter search framework based on principal component
26
+ 17 analysis (PCA) to help determine these two hyperparameters such that the cor
27
+ 18 responding network achieves nice prediction performance while simultaneously
28
+ 19 satisfying the constraints of model size and model efficiency. Experimental results
29
+ 20 demonstrate the prediction performance of constructed BlkSConv-based CNNs
30
+ 21 where several convolutional layers are replaced by BlkSConv layers suggested
31
+ 22 by the proposed PCA-based hyperparameter search algorithm. Our results show
32
+ 23 that BlkSConv-based CNNs achieve competitive performance compared with the
33
+ 24 standard convolutional models for the datasets including ImageNet, CIFAR-10/100,
34
+ 25 Stanford Dogs, and Oxford Flowers.
35
+
36
+ # 26 1 Introduction
37
+
38
+ 27 In the past decade, Deep Learning (DL) has been the basis of many successes in artificial intelligence,
39
+ 28 including a variety of applications in computer vision, reinforcement learning, and natural language
40
+ 29 processing. One of the most popular deep neural networks is Convolutional Neural Network (CNN).
41
+ 30 With the help of various techniques such as residual connections and batch normalization, it is easy to
42
+ 31 train deep CNNs with many layers on powerful GPUs. While large-scale CNN models have achieved
43
+ 32 great successes, they require huge computational complexity and massive storage. For example,
44
+ 33 VGG16 (27) has 138 million parameters and requires 154700 million multiply-add operations
45
+ 34 (MAdds) to classify an image. It is a great challenge to deploy them in real-time applications,
46
+ 35 especially on devices with limited resources such as mobile phones and embedded systems. Thus,
47
+ 36 the prediction models are required be compact and fast while keeping acceptable accuracy. The main
48
+ 37 approach to be compact is the model compression which aims at establishing a tradeoff between
49
+ 38 model efficiency and accuracy. In the area of model compression, methods to construct efficient and
50
+ 39 compact CNNs are mainly divided into two approaches: one approach is to compress trained CNNs
51
+ 40 and the other approach is to design new compact CNNs and train them from scratch. Many works
52
+ 41 based on the first approach suggested several techniques such as quantization (33), model pruning
53
+ 42 (6; 24), Huffman coding (6), and low rank factorization (12).
54
+ 43 Studies in the second approach mainly explored many ways for factorizing convolutions. For
55
+ 44 instance, Szegedy et al. (30) improved GoogLeNet (29) through factorizing convolutions with larger
56
+ 45 spatial filters by a two-layer convolutional architecture with smaller spatial filters. At present, most
57
+ 46 factorizing methods are usually performed via a combination of depthwise convolution, pointwise
58
+ 47 convolution, and groupwise convolution. For example, in (25), the depth-wise separable convolutions
59
+ 48 (DSCs) were proposed where the standard convolution is decomposed into a depth-wise convolution
60
+ 49 and a pointwise convolution. The ShuffleNets (36; 18) utilizes pointwise group convolution with
61
+ 50 channel shuffle to decompose the standard convolution. Moreover, many lightweight models based
62
+ 51 on DSCs or groupwise convolutions such as MobileNets (8; 23; 7) and ShuffleNets (36; 18) were
63
+ 52 proposed to greatly reduce computation cost while maintaining accuracy.
64
+ 53 In this paper, we follow the research path of the second approach and propose block-wise separable
65
+ 54 convolutions (BlkSConv) to replace standard convolutions. BlkSConv approximates a standard
66
+ 55 convolution as follows. A standard $k \times k \times M$ convolutional kernel can be represented as an ordered
67
+ 56 set of block vectors of size $k \times k \times t$ . Since each block vector can be written as a linear combination
68
+ 57 of $k ^ { 2 } t$ basis vectors of size $k \times k \times t$ , this standard convolutional kernel can be viewed as an ordered
69
+ 58 set of block vectors each of which is a linear combination of $k ^ { 2 } t$ basis block vectors. Then BlkSConv
70
+ 59 eliminates most basis block vectors and their corresponding coefficients to obtain an approximated
71
+ 60 convolutional kernel. As shown on the left of Figure 1, the extreme version of BlkSConv is called the
72
+ 61 basic BlkSConv where only one basis block vector is used. When carefully setting the depth of the
73
+ 62 block vector, that is the parameter $t$ , an approximated convolution of fewer parameters can be obtained
74
+ 63 and the corresponding compact CNN has acceptable prediction performance compared to the standard
75
+ 64 convolutions. To increase the prediction accuracy of the basic BlkSConv, an enhanced version is
76
+ 65 proposed by increasing the number of basis block vectors, that is the parameter $s$ , as shown on the
77
+ 66 right of Figure 1. However, adding too many basis block vectors will significantly increase the model
78
+ 67 size and computational cost. Thus there is a tradeoff between model efficiency/size and accuracy. To
79
+ 68 realize the full potential of the enhanced BlkSConv in trading-off model efficiency/size and accuracy,
80
+ 69 we propose a framework based on the principal component analysis to search for the hyperparameters
81
+ 70 $t$ and $s$ of each BlkSConv layer for the given standard convolutional network. The proposed search
82
+ 71 framework suggests a possible setting of parameters $t$ and $s$ such that the constructed model based on
83
+ 72 these selected hyperparameters may achieve high prediction accuracy while simultaneously satisfying
84
+ 73 the constraints of model size and model efficiency in terms of MAdds.
85
+ 74 To summarize, our main contributions are as follows. First, we develop a new convolutional layer
86
+ 75 called BlkSConv to approximate the standard convolutional layer. To approximate a standard convo
87
+ 76 lutional kernel, BlkSConv divides the kernel into blocks and approximates each block by a linear
88
+ 77 combination of several fixed basis block vectors. The constructed networks have small model size
89
+ 78 and cost fewer multiply-adds operations while maintaining acceptable prediction accuracy. Then, we
90
+ 79 also develop a search framework to determine the block depth and the number of basis block vectors
91
+ 80 such that the corresponding networks with selected hyperparameters achieve comparable prediction
92
+ 81 performance while simultaneously satisfying the constraints of model size and model efficiency.
93
+ 82 We also present experimental results to demonstrate the performance of selected BlkSConv-based
94
+ 83 CNNs based on our proposed hyperparameter search algorithm. Our results show that selected
95
+ 84 BlkSConv-based CNNs achieve competitive performance compared with the standard convolutional
96
+ 85 models for the datasets including ImageNet, CIFAR-10/100, Stanford Dogs, and Oxford Flowers.
97
+
98
+ # 86 2 Related Work
99
+
100
+ 87 Many efforts have been devoted to improve the efficiency of CNNs which could be roughly divided
101
+ 88 into three categories. First, model pruning is a popular method to improve efficiency of CNNs. In
102
+ 89 (6; 37), their methods remove redundancy in the trained CNN model by pruning connection. In
103
+ 90 (6; 21; 20; 35), the calculation amount of the trained model is compressed via quantization. In
104
+ 91 (17; 11; 16; 9; 28), model filters that have small contributions are removed and the corresponding
105
+ 92 trained model is fine-tuned to preserve the performance.
106
+ 93 Second, many techniques are developed to factorize the standard convolutions. In (30), convolutions
107
+ 94 with larger spatial filters are factorized into two-layer convolutional architectures with smaller
108
+ 95 spatial filters. Through different combinations of depthwise convolution, pointwise convolution, and
109
+ 96 groupwise convolution, many well-known factorizing frameworks were developed. In (25), the depth
110
+ 97 wise separable convolutions (DSCs) were proposed where the standard convolution is decomposed
111
+ 98 into a depth-wise convolution and a pointwise convolution. The ShuffleNets (36; 18) uses pointwise
112
+ 99 group convolution with channel shuffle to decompose the standard convolution. Moreover, many
113
+ 100 lightweight models based on DSCs or groupwise convolutions such as MobileNets (8; 23; 7) and
114
+ 101 ShuffleNets (36; 18) were proposed to greatly reduce computation cost while maintaining accuracy.
115
+ 102 Recently, neural architecture search-based methods (34; 32; 38; 39; 31) have been proposed to
116
+ 103 automatically construct network architectures. These methods search over a set of network hyperpa
117
+ 104 rameters including different types of convolutional layers and kernel sizes, to find a network structure
118
+ 105 which satisfies optimization constraints such as inference speed. Major search frameworks include
119
+ 106 genetic-based methods (34) and reinforcement learning based methods (38). These techniques were
120
+ 107 used in state-of-the-art CNN architectures such as MnasNet (31) and MobileNetV3 (7).
121
+ 108 Convolution weights of trained CNNs are also analyzed in (1; 3; 26; 4). Following their analysis, sev
122
+ 109 eral approaches toward reducing redundant weights were proposed. In (2; 12; 13), the convolutional
123
+ 110 kernels are approximated via low-rank factorization. In (4), the kernels are analyzed via principal
124
+ 111 component analysis.
125
+
126
+ ![](images/332e85d826f87fc2f013365991e37c0cfa4f2c343d397e19a34762aacbc805ef.jpg)
127
+ Figure 1: The proposed block-wise separable convolution and its enhanced version.
128
+
129
+ # 112 3 Block-wise Separable Convolutions (BlkSConv)
130
+
131
+ 113 For any natural number $n$ , let $[ n ]$ denote the set $\{ 1 , 2 , \ldots , n \}$ . In a standard CNN, each convolutional
132
+ 114 layer converts an input tensor $I$ of size $M \times X \times Y$ into an output tensor $O$ of size $N \times X \times Y$
133
+ 115 by applying the filter kernels $F _ { 1 } , F _ { 2 } , \dots , F _ { N }$ , each of size $M \times \ell \times \ell$ with odd $\ell$ such that, for any
134
+ 116 $x , y , \bar { j } \in [ \bar { X } ] \times [ Y ] \times [ N ]$ ,
135
+
136
+ $$
137
+ \begin{array} { r c l } { { \cal O } ( x , y , j ) } & { { = } } & { { \displaystyle \sum _ { s _ { 1 } = - ( \ell - 1 ) / 2 } ^ { ( \ell - 1 ) / 2 } \sum _ { s _ { 2 } = - ( \ell - 1 ) / 2 } ^ { ( \ell - 1 ) / 2 } \sum _ { s _ { 3 } = 1 } ^ { M } I ( x + s _ { 1 } , y + s _ { 2 } , s _ { 3 } ) \cdot F _ { j } ( s _ { 1 } , s _ { 2 } , s _ { 3 } ) . } } \end{array}
138
+ $$
139
+
140
+ 117 During training, the weights of each kernel $F _ { j }$ are optimized via backpropagation. The total number
141
+ 118 of weight parameters to be optimized in each kernel $F _ { j }$ is $\ell ^ { 2 } \cdot M$ . In the subsequent work, we propose
142
+ 119 a framework to reduce the number of parameters of the standard convolutions while preserving its
143
+ 120 prediction performance. Then, in order to implement our new framework, we adopt a combination of
144
+ 121 pointwise and group-wise convolutions to efficiently realize the reduced convolutions. Combining
145
+ 122 these ideas, we introduce block-wise separable convolutions, denoted by BlkSConv. However,
146
+ 123 to generate a BlkSConv-based models, many hyperparameters should be determined for keeping
147
+ 124 prediction performance, model size, and model efficiency. Thus, we also propose an efficient
148
+ 125 hyperparameter search algorithm to select hyperparameters satisfying the given model constraints.
149
+ 127 In this section, we propose block-wise separable convolutions. First, each convolutional kernel $F _ { j }$
150
+ 128 of size $M \times \ell \times \ell$ can be expressed as a concatenation of $M / t$ blocks $Q _ { j } ^ { ( 1 ) } , Q _ { j } ^ { ( 2 ) } , \dots , Q _ { j } ^ { ( M / t ) }$ each
151
+ 129 of size $\ell \times \ell \times t$ where $Q _ { j } ^ { ( k ) } ( x , y , z ) = F _ { j } ( x , y , z + ( k - 1 ) t )$ for any $x , y , z \in [ X ] \times [ Y ] \times [ t ]$ .
152
+ 130 We call $t$ the block depth. Let $\{ B _ { 1 } , B _ { 2 } , \dots , B _ { t \ell ^ { 2 } } \}$ be a set of basis block vectors. Each $Q _ { j } ^ { ( k ) }$ can
153
+ 131 be expressed uniquely as a linear combination of $B _ { 1 } , B _ { 2 } , \ldots , B _ { t \ell ^ { 2 } }$ , that is, there exist $t \ell ^ { 2 }$ values
154
+ 132 $P _ { j } ^ { ( k ) } ( i ) \in \mathbb { R }$ such that $\begin{array} { r } { Q _ { j } ^ { ( k ) } = \sum _ { i = 1 } ^ { t \ell ^ { 2 } } P _ { j _ { \ldots } } ^ { ( k ) } ( i ) \cdot B _ { i } } \end{array}$ . In practice, $t \ell ^ { 2 }$ may be large. In order to reduce
155
+ 133 the model size, we require the number of basis block vectors is fewer than or equal to a fixed number
156
+ 134 $s$ with $s < t \ell ^ { 2 }$ . Now each $Q _ { j } ^ { ( k ) }$ is replaced by the following linear combination of $B _ { 1 } , \ldots , B _ { s }$ , that
157
+ 135 is Qb(kj $\begin{array} { r } { \widehat Q _ { j } ^ { ( k ) } = \sum _ { i = 1 } ^ { s } P _ { j } ^ { ( k ) } ( i ) \cdot \bar { B _ { i } } } \end{array}$ . The corresponding convolutional kernel $\widehat { F } _ { j }$ is the concatenation of
158
+ 136 $M / t$ blocks $\widehat { Q } _ { j } ^ { ( 1 ) } , \ldots , \widehat { Q } _ { j } ^ { ( M / t ) }$ Qb(M/t)j . Therefore, the corresponding output tensor is
159
+
160
+ $$
161
+ \widehat { O } ( x , y , j ) = \sum _ { s _ { 1 } , s _ { 2 } = - ( \ell - 1 ) / 2 } ^ { ( \ell - 1 ) / 2 } \sum _ { s _ { 3 } = 1 } ^ { M } I ( x + s _ { 1 } , y + s _ { 2 } , s _ { 3 } ) \cdot \widehat { F } _ { j } ( s _ { 1 } , s _ { 2 } , s _ { 3 } ) .
162
+ $$
163
+
164
+ 137 By Equation 2, the number of weight parameters in BlkSConv is $s \cdot ( t \cdot \ell ^ { 2 } + \frac { M } { t } )$ . To significantly
165
+ 138 reduce model size, we set $s = 1$ . Figure 1 left illustrates the operation of BlkSConv when $s = 1$ .
166
+ 139 In order to achieve the minimal model size, √ $t$ can be set as $\sqrt { M } / \ell$ and the number of parameters
167
+ 140 becomes $2 \ell \sqrt { M }$ while the parameter number of the standard and $1 \times 1$ pointwise convolutions are
168
+ 141 $M \ell ^ { 2 }$ and $M$ , respectively. Thus, the constructed BlkSConv-based CNNs have smaller model size
169
+ 142 than existing lightweight CNN models. Take the ResNet34 (10) as an example where, in the last
170
+ 143 stage of the ResNet-34, the convolutional kernel size is $3 \times 3$ and the channel size is 512, that is $\ell = 3$
171
+ 144 and $M = 5 1 2$ . In this case, the ratio between the parameter size of the BlkSConv-based convolutions
172
+ 145 and the standard convolutions is approximately 0.0295.
173
+ 146 However, the prediction performance of the BlkSConv-based CNN with the smallest model size is
174
+ 147 usually worse than the standard CNNs. To increase accuracy, the number of basis block vectors
175
+ 148 should be increased, that is $s > 1$ . Figure 1 right illustrates the operation of BlkSConv when $s > 1$ .
176
+ 149 In this case, the number of parameters becomes $2 s \ell \sqrt { M }$ . Let us take convolutions in the last stage
177
+ 150 of ResNet-34 as examples. Let us set $t = 4$ in the BlkSConv. Now the ratio between the parameter
178
+ 151 size of the BlkSConv-based convolutions and the standard convolutions is approximately 0.0356.
179
+ 152 Thus we can add at least 5 basis block vectors to increase prediction accuracy. In this case, the ratio
180
+ 153 between the parameter size of the BlkSConv-based convolutions with 5 basis block vectors and the
181
+ 154 standard convolutions is approximately 0.178. In the experimental section, we demonstrate that the
182
+ 155 BlkSConv-based convolutions with few basis block vectors have prediction performance as well
183
+ 156 as the standard convolutions on ImageNet or even outperform the standard convolutions on several
184
+ 157 datasets when the backbone CNNs are ResNets.
185
+ 158 The next problem is the computational efficiency of BlkSConv. If we compute the kernel $\widehat { F } _ { j }$ first and
186
+ 159 perform a regular convolution according to the kernel $\widehat { F } _ { j }$ , then it is obvious that the computational
187
+ 160 cost is larger than the cost for just performing a standard convolution. We will address this problem
188
+ 161 in the subsequent section.
189
+
190
+ # 162 3.2 Implementation of BlkSConv via a combination of pointwise and group-wise convolutions
191
+
192
+ 163 In this section, we propose an efficient implementation method to realize BlkSConv. The flowchart
193
+ 164 of the proposed implementation is illustrated in Figure 2. To derive an efficient implementation for
194
+ 165 BlkSConv operation, we rewrite Equation 2 as follows.
195
+
196
+ ![](images/f14b22bdbd51f4964aaba3e7e63b2d296c6921c5ff636c0d90f8f3c67b37891f.jpg)
197
+ Figure 2: Flowchart of the block-wise separable convolution where Gconv. means the group-wise convolution.
198
+
199
+ $$
200
+ \begin{array} { r c l } { \widehat { O } ( x , y , j ) } & { = } & { \displaystyle \sum _ { s _ { 1 } , s _ { 2 } } \displaystyle \sum _ { z = 1 } ^ { t } \sum _ { k = 1 } ^ { M / t } I ( x + s _ { 1 } , y + s _ { 2 } , z + ( k - 1 ) t ) \cdot \widehat { Q } _ { j } ^ { ( k ) } ( s _ { 1 } , s _ { 2 } , z ) } \\ & { = } & { \displaystyle \sum _ { s _ { 1 } , s _ { 2 } } \displaystyle \sum _ { z = 1 } ^ { t } \sum _ { k = 1 } ^ { M / t } I ( x + s _ { 1 } , y + s _ { 2 } , z + ( k - 1 ) t ) \cdot \sum _ { i = 1 } ^ { s } P _ { j } ^ { ( k ) } ( i ) \cdot B _ { i } ( s _ { 1 } , s _ { 2 } , z ) } \\ & { = } & { \displaystyle \sum _ { i = 1 } ^ { s } \sum _ { s _ { 1 } , s _ { 2 } } \sum _ { z = 1 } ^ { t } B _ { i } ( s _ { 1 } , s _ { 2 } , z ) \displaystyle \sum _ { k = 1 } ^ { M / t } P _ { j } ^ { ( k ) } ( i ) \cdot \widehat { I } ( x + s _ { 1 } , y + s _ { 2 } , z + ( k - 1 ) t ) . } \end{array}
201
+ $$
202
+
203
+ $J ^ { ( z ) } ( x , y , i )$ {z: a point-wise convolution of $\widetilde { I _ { z } }$
204
+
205
+ Let 166 ezdefine 167 $\widetilde { I } _ { z } ( x , y , k )$ $\begin{array} { r } { J ^ { ( z ) } ( x , y , i ) \triangleq \sum _ { k = 1 } ^ { M / t } P _ { j } ^ { ( k ) } ( i ) \cdot \widetilde { I } _ { z } ( x + s _ { 1 } , y + s _ { 2 } , k ) } \end{array}$ be a tensor of size $X \times Y \times M / t$ defined by ez which is a point-wise convolution of $\widetilde { I } _ { z } ( x , y , k ) \triangleq I ( x , y , z + ( k - 1 ) t )$ . We $\widetilde { I } _ { z }$ 168 Next, we define $J _ { i } ( x , y , z ) \triangleq J ^ { ( z ) } ( x , y , i )$ and let $J$ be the reshaped tensor which is the concatenation 169 of $J _ { 1 } , \ldots , J _ { s }$ , that is $J ( x , y , z + ( i - 1 ) t ) = J _ { i } ( x , y , z )$ . Now Equation 5 can be rewritten as
206
+
207
+ $$
208
+ \widehat { O } ( x , y , j ) ~ = ~ \sum _ { i = 1 } ^ { s } \sum _ { s _ { 1 } , s _ { 2 } } \sum _ { z = 1 } ^ { t } B _ { i } ( s _ { 1 } , s _ { 2 } , z ) \cdot J ( x + s _ { 1 } , y + s _ { 2 } , z + ( i - 1 ) t ) .
209
+ $$
210
+
211
+ 170 Finally, Equation 6 is just a group-wise convolution of the tensor $J$ with $s$ groups.
212
+
213
+ 171 Let us compute the computational cost (MAdds) of the implementation for BlkSConv. By Equation 5
214
+ 172 (Step a in Figure 2), the computational cost of $s$ point-wise convolutions on the concatenation of
215
+ 173 $\widetilde { I } _ { 1 } , \ldots , \widetilde { I } _ { t }$ is $s X Y M$ . In addition, by Equation 6 (Step b in Figure 2), the computational cost of the
216
+ 174 group-wise convolution on the tensor $J$ is $s X Y t \ell ^ { 2 }$ . Finally, the computational cost of the point-wise
217
+ 175 summation in the last step is $s X Y$ . The total MAdds of a BlkSConv operation is $s X Y ( M + t \ell ^ { 2 } + 1 )$
218
+ 176 while the MAdds of a standard convolution is $X Y M \ell ^ { 2 }$ . Again, let us take convolutions in the last
219
+ 177 stage of ResNet-34 as examples. We set $s = 5$ and $t = 4$ as the hyperparameters of the BlkSConv
220
+ 178 based convolution. Now the ratio between the MAdds of a BlkSConv-based convolution and a
221
+ 179 standard convolution is approximately 0.595. Thus the proposed BlkSConv operation is much more
222
+ 180 efficient than the standard convolution in practical cases. We remark that the proposed implementation
223
+ 181 requires much GPU memory due to using many group-wise and pointwise convolutions.
224
+
225
+ # 3.3 Hyperparameter search via principal component analysis
226
+
227
+ 183 Designing a BlkSConv-based CNN involves hyperparameters including the block depth and the num
228
+ 184 ber of basis block vectors in each convolutional layer that affect the performance of the corresponding
229
+ 185 CNN model. To realize an efficient BlkSConv-based CNN, we conduct a hyperparameter search algo
230
+ 186 rithm based on principal component analysis of trained CNNs. Given a trained CNN, the algorithm
231
+ 187 generates the block depth and the number of basis block vectors for each standard convolutional layer
232
+ 188 of the trained CNN in the following way. First, for each individual $\ell \times \ell \times M$ kernel $K$ of the trained
233
+ 189 CNN where we assume that $M = 2 ^ { \alpha }$ for some $\alpha \in \mathbb { N }$ , the kernel $K$ is partitioned into $M / t$ block
234
+ 190 vectors $B _ { 1 } , B _ { 2 } , \ldots , B _ { M / t }$ each of size $\ell \times \ell \times t$ with $t \in \{ 1 , 2 , \dots , 2 ^ { \beta } \}$ for some integer $\beta < \alpha$ .
235
+ 191 Next, we perform principal component analysis (PCA) on the set $\{ B _ { 1 } , B _ { 2 } , \ldots , B _ { M / t } \}$ . Then, for
236
+ 192 a fixed integer $\gamma$ and, for each $q \in \{ 1 , 2 , \ldots , \gamma \}$ , the algorithm computes the variance $V _ { t , q }$ of the
237
+ 193 kernel $K$ which is explained by the first $q$ principal components PC1,PC2,..,PCq. In addition, let
238
+ 194 $\mathbf { C C } _ { t , q }$ and $\mathbf { M S } _ { t , q }$ denote the MAdds and the model size of the BlkSConv under the setting that the
239
+ 195 block depth is $t$ and the number of basis block vectors is $q$ , respectively. Note that the MAdds and the
240
+ 196 model size of the standard convolution is exactly $\mathrm { C C } _ { M , 1 }$ and ${ \bf M S } _ { M , 1 }$ , respectively. After computing
241
+ 197 all $\mathrm { V } _ { t , q } , \mathrm { C C } _ { t , q }$ , and $\mathbf { M S } _ { t , q }$ , the algorithm generates the feasible set
242
+
243
+ $$
244
+ \begin{array} { r l r } { H _ { \alpha _ { v } , \alpha _ { c } , \alpha _ { s } } } & { = } & { \{ ( t , q ) : V _ { t , q } \geq \alpha _ { v } , { \bf C C } _ { t , q } \leq \alpha _ { c } \cdot { \bf C C } _ { M , 1 } , \mathrm { a n d } { \bf M S } _ { t , q } \leq \alpha _ { s } \cdot { \bf M S } _ { M , 1 } \} } \end{array}
245
+ $$
246
+
247
+ 98 for fixed positive constants $\alpha _ { v } , \alpha _ { c } , \alpha _ { s } \in ( 0 , 1 )$ . Finally, the algorithm chooses the hyperparameter
248
+ 99 $( t , q )$ from $H _ { \alpha _ { v } , \alpha _ { c } , \alpha _ { s } }$ according to the computational cost or the model size.
249
+ 200 On one hand, note that the goal of BlkSConv is to maintain the prediction performance of the trained
250
+ 201 standard CNN. In general, the prediction accuracy is proportional to the model size of the constructed
251
+ 202 CNN. Therefore, in this sense, we choose the hyperparameters $( \hat { t } , \hat { q } )$ from $H _ { \alpha _ { v } , \alpha _ { c } , \alpha _ { s } }$ such that the
252
+ 203 constructed BlkSConv has the largest parameter size, that is
253
+
254
+ $$
255
+ \left( \hat { t } , \hat { q } \right) \mathrm { ~ ~ { ~ \alpha ~ } ~ } \mathrm { a r g } \operatorname* { m a x } _ { ( t , q ) \in H _ { \alpha _ { v } , \alpha _ { c } , \alpha _ { s } } } \mathbf { M } \mathbf { S } _ { t , q } .
256
+ $$
257
+
258
+ 204 One can expect that the generated BlkSConv-based CNN has nice prediction performance compared
259
+ 205 to the original CNN with standard convolutions.
260
+ 206 On the other hand, one of the advantage of BlkSConv operations is that BlkSConv can greatly reduce
261
+ 207 the model size of the original standard CNN. Thus, in this sense, we can select the hyperparameters
262
+ 208 $( \tilde { t } , \tilde { q } )$ from $H _ { \alpha _ { v } , \alpha _ { c } , \alpha _ { s } }$ such that the constructed BlkSConv has the smallest parameter size, that is
263
+
264
+ $$
265
+ \begin{array} { r c l } { ( \widetilde t , \widetilde q ) } & { = } & { \arg \underset { ( t , q ) \in { \cal H } _ { \alpha _ { v } , \alpha _ { c } , \alpha _ { s } } } { \operatorname* { m i n } } { \bf M } { \bf S } _ { t , q } . } \end{array}
266
+ $$
267
+
268
+ 209 However, the prediction performance may degrade when the parameter size of the BlkSConv-based
269
+ 210 model decreases. We will demonstrate in the experimental section that the BlkSConv-based CNNs
270
+ 211 generated according to Equation 8 also have acceptable prediction accuracy compared to the standard
271
+ 212 CNNs.
272
+ 213 In summary, both Equation 8 and Equation 9 provide ways to determine hyperparameters from the
273
+ 214 feasible set $H _ { \alpha _ { v } , \alpha _ { c } , \alpha _ { s } }$ such that corresponding BlkSConv-based CNNs have smaller model size and
274
+ 215 fewer multiply-adds operations than the original CNN with standard convolutions.
275
+ 216 Finally, let us consider the extreme case that two constants $\beta$ and $\gamma$ are set by $\beta = 0$ and $\gamma = 1$ . Let
276
+ 217 us further set the search parameter $\alpha _ { v } = 0$ . Under this restricted search condition, the cardinality of
277
+ 218 the feasible set $H _ { 0 , \alpha _ { c } , \alpha _ { s } }$ is always 1. Thus the outputs of Equation 8 and Equation 9 are the same.
278
+ 219 In fact, the resulting BlkSConv-based CNN is exactly the same as the CNN where the standard
279
+ 220 convolutions are replaced by the blueprint separable convolutions previously developed in (4).
280
+
281
+ # 221 4 Experiments
282
+
283
+ 222 We evaluate BlkSConv and the proposed hyperparameter architecture search algorithm combining
284
+ 223 with ResNet-10, ResNet-18, and ResNet-26 (5) on ImageNet (22), Stanford Dogs, (14), and Oxford
285
+ 224 102 Flowers (19). The proposed methods are also evaluated combining with ResNet-20 and ResNet-56
286
+ 225 on CIFAR 10/100 (15).
287
+
288
+ # 26 4.1 Hyperparameter Search Details
289
+
290
+ 227 We apply the PCA-based hyperparameter search algorithm (HSA) developed in Section 3.3 on several
291
+ 228 variants of ResNet models. In the first part, we consider the large-scale classification scenarios.
292
+ 229 Several standard ResNets are trained on ImageNet first and their architectures are shown in Table 1.
293
+ 230 The HSA for searching BlkSConv architectures is only applied to conv3_x, conv4_x, conv5_x
294
+ 231 layers of these standard ResNets. Next, the search hyperparameters $\alpha _ { v } , \alpha _ { c } , \alpha _ { s }$ are set as 0.5 or
295
+
296
+ Table 1: ResNet architectures used in the first part of the experiment on ImageNet, Stanford Dogs, and Oxford 102 Flowers. The PCA-based HSA is applied to conv3_x, conv4_x, conv5_x layers and the corresponding convolutional kernel is replaced by the BlkSConv module found by HSA.
297
+
298
+ <table><tr><td colspan="5">ResNet-10 (L=1), ResNet-18 (L=2), ResNet-26 (L=3)</td></tr><tr><td>Layers Names</td><td>Output Size</td><td>ResNet</td><td>Applying HSA</td><td>e.g.(ResNet-10)</td></tr><tr><td>conv1 max pool</td><td>112 × 112 × 64 56 × 56×64</td><td>7 × 7,64, stride 2 3 × 3, stride 2</td><td>No</td><td></td></tr><tr><td>conv2_x</td><td>56 × 56× 64</td><td>[3×3, 64] ×L [3×3, 64</td><td>No</td><td></td></tr><tr><td>conv3_x</td><td>28 × 28× 128</td><td>3×3, 128] ×L [3×3, 128]</td><td>Yes</td><td>conv-s5t2</td></tr><tr><td>conv4_x</td><td>14 ×14× 256</td><td>[3×3, 256] ×L 256 [3×3,</td><td>Yes</td><td>conv-s5t2</td></tr><tr><td>conv5_x</td><td>7×7×512</td><td>[3×3, 512] ×L [3×3, 512]</td><td>Yes</td><td>conv-s1t1</td></tr><tr><td>average pool fully connected</td><td>1×1×512 1000</td><td>7×7 512 × 1000 fc</td><td></td><td></td></tr></table>
299
+
300
+ Table 2: Performance results for BlkSConv-based ResNet-18 and ResNet-26 on ImageNet.
301
+
302
+ <table><tr><td rowspan="2">(av,ac,as,Ss)</td><td colspan="3">ResNet-18 on ImageNet</td><td colspan="3">ResNet-26 on ImageNet</td></tr><tr><td>Accuracy</td><td>P_ratio</td><td>MA_ratio</td><td> Accuracy</td><td>P_ratio</td><td>MA_ratio</td></tr><tr><td>(0.50,0.50,0.50,max)</td><td>69.922</td><td>0.4065</td><td>0.4614</td><td>72.038</td><td>0.4241</td><td>0.4618</td></tr><tr><td>(0.50,0.75,0.75, max)</td><td>69.782</td><td>0.6014</td><td>0.6597</td><td>72.326</td><td>0.6308</td><td>0.6722</td></tr><tr><td>(0.50,0.50, 0.50,min)</td><td>67.572</td><td>0.1264</td><td>0.2700</td><td>69.970</td><td>0.1250</td><td>0.2668</td></tr><tr><td>(0.50,0.75,0.75,min)</td><td>67.540</td><td>0.1246</td><td>0.2986</td><td>69.922</td><td>0.1243</td><td>0.2910</td></tr><tr><td>Standard (replaced layers)</td><td>70.728</td><td>10.8M</td><td>1213.8M</td><td>72.604</td><td>17.03M</td><td>1907.4M</td></tr></table>
303
+
304
+ 0.75. It is possible that the feasible set $H _ { \alpha _ { v } , \alpha _ { c } , \alpha _ { s } }$ is empty. In this case, the corresponding standard convolutional layer is not replaced and is denoted by conv as shown in Table 1. Moreover, the proposed HSA has two selection strategies: one is based on the largest parameter size, denoted by $S S = \mathrm { m a x }$ , and the other is based on the smallest parameter size, denoted by $S S = { \mathrm { m i n } }$ as shown in Table 2. The selected BlkSConv, sitj, which means $i$ basis block vectors and $j$ depth of the blocks.
305
+
306
+ The feasible set $H _ { \alpha _ { v } , \alpha _ { c } , \alpha _ { s } }$ is likely to be empty when the parameter $\alpha _ { v }$ is large. In the case that $\alpha _ { v }$ is large, it often requires many principal components to accumulate enough explained variance and thus this causes large numbers of parameters or MAdds. Therefore, the feasible set $H _ { \alpha _ { v } , \alpha _ { c } , \alpha _ { s } }$ is probably empty when we further require small $\alpha _ { c }$ and $\alpha _ { s }$ . On the other hand, the parameter $\alpha _ { v }$ cannot be too small because the prediction performance of the network is highly proportional to the amount of the accumulated variance as discussed in Section 3.3 where we will demonstrate it in the ablation study of this section. For the above reason, we only present the results for ResNet-18 and ResNet-26 on ImageNet under the setting that $\alpha _ { v } = 0 . 5$ which are shown in Table 2.
307
+
308
+ In the second part, we consider the small-scale classification on CIFAR10/100. We use the standard ResNet-20 and ResNet-56 as the experimental models where the architectures are slightly modified to suit the small-scale images. The proposed HSA is only applied to conv4_x layers of these two standard ResNets. More BlkSConv-based architecture search results can be found in the appendix.
309
+
310
+ # 4.2 Performance on large-scale classification: ImageNet
311
+
312
+ To evaluate the performance of BlkSConv-based models in large-scale recognition, we conduct experiments on ImageNet(22). Each model takes 3 days to be trained on a single GPU (Nvidia Tesla V100). ImageNet contains nearly 1.3M training images and 50,000 testing images. For the experimental setup, ResNet-10, ResNet-18, and ResNet-26 are trained on ImageNet under the following setting. The number of epochs is 100 and the batch size is 256. SGD is used as the optimizer and the initial learning rate, the momentum, and the weight decay are set to 0.1, 0.9, and $1 \bar { 0 } ^ { - 4 }$ , respectively. The learning rate is scheduled to decay by a factor of 0.1 at epochs 30, 60, and 90. We augment the data via random resized crop to $2 2 4 \mathrm { p x }$ and random horizontal flip. The performance results are shown in Table 2, More experimental results can be found in the appendix.
313
+
314
+ Table 3: Comparison among the BlkSConv-based and Standard ResNet on ImageNet and CIFAR.
315
+
316
+ <table><tr><td>Dataset</td><td>Models</td><td>Accuracy</td><td>Parameters</td><td>MAdds</td></tr><tr><td rowspan="3">ImageNet</td><td>ResNet-10 standard</td><td>63.386</td><td>4.64M</td><td>520M</td></tr><tr><td>BlkSConv-ResNet-18 (0.5,0.5,0.5,max)</td><td>69.922</td><td>4.39M</td><td>560M</td></tr><tr><td>BlkSConv-ResNet-26 (0.5, 0.5, 0.5, min)</td><td>69.970</td><td>2.13M</td><td>509M</td></tr><tr><td rowspan="3">CIFAR 100</td><td>ResNet-20 standard</td><td>67.994</td><td>202752</td><td>12.97M</td></tr><tr><td>BlkSConv-ResNet-20 (0.5, 0.5, 0.5, max)</td><td>67.078</td><td>72704</td><td>5.04M</td></tr><tr><td>BlkSConv-ResNet-56 (0.5,0.5, 0.5, min)</td><td>69.994</td><td>149440</td><td>10.61M</td></tr></table>
317
+
318
+ Table 4: Performance results for BlkSConv-based ResNet-56 on CIFAR10/100.
319
+
320
+ <table><tr><td rowspan="2">(av,ac,αs,Ss)</td><td colspan="3">ResNet-56 on CIFAR 10</td><td colspan="3">ResNet-56 on CIFAR 100</td></tr><tr><td> Accuracy</td><td>P_ratio</td><td>MA_ratio</td><td>Accuracy</td><td>P_ratio</td><td>MA_ratio</td></tr><tr><td>(0.5, 0.5,0.5, max)</td><td>93.372</td><td>0.3734</td><td>0.3829</td><td>70.636</td><td>0.3734</td><td>0.3829</td></tr><tr><td>(0.5,0.75,0.75,max)</td><td>93.338</td><td>0.6196</td><td>0.6292</td><td>70.668</td><td>0.6196</td><td>0.6292</td></tr><tr><td>(0.5,0.5,0.5,min)</td><td>93.324</td><td>0.2335</td><td>0.2462</td><td>69.994</td><td>0.2316</td><td>0.2570</td></tr><tr><td>(0.5,0.75,0.75,min)</td><td>93.324</td><td>0.2335</td><td>0.2462</td><td>69.994</td><td>0.2316</td><td>0.2570</td></tr><tr><td>Standard (replaced layers)</td><td>93.218</td><td>645120</td><td>41.28M</td><td>70.998</td><td>645120</td><td>41.28M</td></tr></table>
321
+
322
+ 259 On one hand, let us focus the cases that $\alpha _ { v } ~ = ~ 0 . 5$ and $S S = \mathrm { m a x }$ in Table 2. The prediction
323
+ 260 accuracies of the selected BlkSConv-based models and the standard model are close within $1 \%$
324
+ 261 It confirms our expectation that BlkSConv-based models have smaller parameter sizes and fewer
325
+ 262 MAdds than standard models while preserving prediction performance if the proposed HSA adopts a
326
+ 263 selection strategy based on the maximum parameter size.
327
+ 264 On the other hand, let us consider the case that $\alpha _ { v } = 0 . 5$ and $S S = { \mathrm { m i n } }$ in Table 2. The parameters
328
+ 265 and MAdds of the BlkSConv-based models are only $1 2 . 6 \%$ and $2 9 . 8 \%$ of the standard model
329
+ 266 while the gap of their prediction accuracies is about $3 \%$ . We adopt an interesting way based on
330
+ 267 restricting the parameter size and MAdds to interpret the advantage of the generated BlkSConv-based
331
+ 268 models where the selection strategy $S S$ is set as min. We also compare the standard ResNet-10, the
332
+ 269 BlkSConv-based ResNet-18, and the BlkSConv-based ResNet-26 in Table 3 where the parameter
333
+ 270 sizes or MAdds of three given models are similar. The BlkSConv-based ResNet-26 with parameter
334
+ 271 (0.5, 0.5, 0.5, min) and the BlkSConv-based ResNet-18 with parameter (0.5, 0.5, 0.5, max) greatly
335
+ 272 outperform the standard ResNet-10 where both the BlkSConv-based models lead to an accuracy gain
336
+ 273 of at least $6 . 5 \%$ . In addition, the BlkSConv-based ResNet-26 with parameter (0.5, 0.5, 0.5, min) only
337
+ 274 has half the parameter size of the BlkSConv-based ResNet-18 with parameter (0.5, 0.5, 0.5, max).
338
+
339
+ # 275 4.3 Performance on small-scale classification: CIFAR 10/100
340
+
341
+ 276 The performance results are shown in Table 4. The BlkSConv-based ResNet-56 models have much
342
+ 277 smaller model sizes and fewer MAdds than the standard model while all BlkSConv-based variants
343
+ 278 outperform the standard model on CIFAR 10 and have comparable accuracies on CIFAR 100. In the
344
+ 279 bottom of Table 3, the BlkSConv-based ResNet-20 with (0.5, 0.5, 0.5, max) and the standard ResNet
345
+ 280 20 both have a comparable accuracy while the BlkSConv-based ResNet-20 model is compressed
346
+ 281 $64 \%$ of the parameter size and MAdds is decreased $61 \%$ compared to the standard ResNet-20 model.
347
+ 282 Furthermore, the BlkSConv-based ResNet-56 with (0.5, 0.5, 0.5, min) and the standard ResNet-20
348
+ 283 model both have similar parameter sizes and MAdds while the BlkSConv-based ResNet-56 model
349
+ 284 has an accuracy gain of $2 \%$ . More experimental results can be found in the appendix.
350
+
351
+ Table 5: Performance comparison among BlkSConv-based and the standard ResNet-18 models.
352
+
353
+ <table><tr><td rowspan="2">(av,ac,as,Ss)</td><td colspan="3">Stanford Dogs</td><td colspan="3">Oxford 102 Flowers</td></tr><tr><td>Accuracy</td><td>P_ratio</td><td>MA_ratio</td><td> Accuracy</td><td>P_ratio</td><td>MA_ratio</td></tr><tr><td>(0.5, 0.5,0.5, max)</td><td>53.005</td><td>0.5327</td><td>0.5394</td><td>65.546</td><td>0.5327</td><td>0.5394</td></tr><tr><td>(0.5,0.75,0.75,max)</td><td>53.359</td><td>0.7277</td><td>0.7377</td><td>64.567</td><td>0.7277</td><td>0.7377</td></tr><tr><td>(0.5,0.5,0.5,min)</td><td>53.159</td><td>0.3273</td><td>0.4006</td><td>65.289</td><td>0.4835</td><td>0.5179</td></tr><tr><td>(0.5,0.75,0.75,min)</td><td>53.615</td><td>0.3171</td><td>0.4611</td><td>63.217</td><td>0.4743</td><td>0.5872</td></tr><tr><td>Standard (replaced layers)</td><td>52.436</td><td>10.8M</td><td>1213.8M</td><td>62.238</td><td>10.8M</td><td>1213.8M</td></tr></table>
354
+
355
+ Table 6: Results on Stanford Dogs for different $\alpha _ { v }$ with $S S = \operatorname* { m i n }$ .
356
+
357
+ <table><tr><td colspan="8"> ResNet-18 on Stanford Dogs (Qv, αc = 0.75,αs = 0.75, SS = min)</td></tr><tr><td>au</td><td>Accuracy</td><td>P_ratio</td><td>MA_ratio</td><td>au</td><td>Accuracy</td><td>P_ratio</td><td>MA_ratio</td></tr><tr><td>0.0</td><td>50.918</td><td>0.0397</td><td>0.1781</td><td>0.3</td><td>52.839</td><td>0.1074</td><td>0.2377</td></tr><tr><td>0.1</td><td>50.499</td><td>0.0449</td><td>0.1777</td><td>0.4</td><td>52.035</td><td>0.2751</td><td>0.4684</td></tr><tr><td>0.2</td><td>51.040</td><td>0.0767</td><td>0.2458</td><td>0.5</td><td>53.615</td><td>0.3171</td><td>0.4611</td></tr><tr><td></td><td></td><td></td><td></td><td>Standard</td><td>52.436</td><td>10.8M</td><td>1213.8M</td></tr></table>
358
+
359
+ # 285 4.4 Performance on fine-grained classification
360
+
361
+ We conduct experiments for fine-grained recognition on two datasets Stanford Dogs and Oxford 102 Flowers. For the experimental setup, the standard ResNet-18 and its BlkSConv-variants are all trained from scratch by augmenting data through random crops, horizontal flips, and random gamma transform. We use SGD as the optimizer and the initial learning rate, the moment, and the weight decay are set to 0.1, 0.9, and $1 0 ^ { - \bar { 4 } }$ , respectively. The number of epochs is 200, and the learning rate is scheduled to decay at epochs 100, 150, and 200 by a factor of 0.1. The proposed BlkSConv-based ResNet-18 models significantly outperform the standard ResNet-18 model both on Stanford Dogs and Oxford 102 Flowers as shown in shown Table 5..
362
+
363
+ # 94 4.5 Ablation Study: Necessity to have large explained variance
364
+
365
+ 295
366
+ 296
367
+ 297
368
+ 298
369
+ 299
370
+ 300
371
+ 301
372
+ 302
373
+ 303
374
+ 304
375
+ 305
376
+ 306
377
+
378
+ Here, we demonstrate how the variance hyperparameter $\alpha _ { v }$ affects the prediction accuracy of BlkSConv-based CNNs. We use ResNet-18 as the experimental model. After training the standard ResNet-18 on Stanford Dogs, the next goal is to find several BlkSConv-variants of ResNet18 all of which have different explained variances such that their accuracies can be compared. Note that $H _ { a , 0 . 7 5 , 0 . 7 5 } \ \subseteq \ H _ { b , 0 . 7 5 , 0 . 7 5 }$ for any $a , b$ with $a \geq b$ . Based on this observation, the model in $H _ { b , 0 . 7 5 , 0 . 7 5 }$ which has the smallest parameter size is likely to have a small explained variance as well. Therefore, the selection strategy of the proposed HSA is set by $S S = \operatorname* { m i n }$ in order to select several BlkSConv-based ResNet-18 models with different explained variances. Now we apply the proposed HSA to the trained ResNet-18 under six search hyperparameters $\{ ( \alpha _ { v } , 0 . 7 5 , 0 . 7 5 , \mathrm { { m i n } } ) : { \alpha _ { v } } = 0 . 0 , 0 . 1 , 0 . 2 , \ldots , 0 . 5 \}$ . The comparison result is shown in Table 6. It can be seen that the accuracy of the BlkSConv-based model is greater than that of the standard model only when the variance hyperparameter $\alpha _ { v }$ is large enough, that is $\alpha _ { v } \geq 0 . 5$ .
379
+
380
+ # 307 5 Conclusion
381
+
382
+ In this paper, we introduce the block-wise separable convolutions (BlkSConv) to replace standard convolutions. An efficient implementation of the BlkSConv operation via a combination of pointwise and group-wise convolutions is also given. Moreover, we also propose an efficient hyperparameter search algorithm based on principal component analysis in order to select an optimal BlkSConv-based convolutional network under certain constraints on model size and model efficiency. Finally, the experimental results demonstrate the advantage of the BlkSConv-based CNN models selected by the proposed hyperparameter search algorithm.
383
+
384
+ 315 References
385
+ 316 [1] M. Denil, B. Shakibi, L. Dinh, M. A. Ranzato, and N. De Freitas, "Predicting parameters in deep learning," in Advances in neural information processing systems (NIPS), pages 2148–2156, 2013.
386
+ 318 [2] E. Denton, W. Zaremba, J. Bruna, Y. Le-Cun, and R. Fergus, "Exploiting linear structure within convolutional networks for efficient evaluation," in Advances in neural information processing systems (NIPS), pages 1269–1277, 2014. [3] J. Guo, Y. Li, W. Lin, Y. Chen, and J. Li, "Network decoupling: From regular to depthwise separable convolutions," arXiv preprint arXiv:1808.05517, 2018
387
+ 323 [4] D. Haase and M. Amthor, "Rethinking Depthwise Separable Convolutions: How Intra-Kernel Correlations Lead to Improved MobileNets," in Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), pages 14600–14609, 2020.
388
+ 326 [5] K. He, X. Zhang, S. Ren, and J. Sun. Deep residual learning for image recognition. CoRR, abs/1512.03385, 2015.
389
+ 328 [6] S. Han, H. Mao, and W. J. Dally. "Deep compression: Compressing deep neural networks with pruning, trained quantization and huffman coding," in Proceedings of the International Conference on Learning Representations, 2015. [7] A. G. Howard, M. Sandler, G. Chu, L.-C. Chen, M. Tan, W. Wang, et al., "Searching for mobilenetv3", in Proceedings of the International Conference on Computer Vision (ICCV), 2019. [8] A. G. Howard, M. Zhu, B. Chen, D. Kalenichenko, W. Wang, T. Weyand, et al., "Mobilenets: Efficient convolutional neural networks for mobile vision applications", 2017.
390
+ 335 [9] Y. He, G. Kang, X. Dong, Y. Fu, and Y. Yang, "Soft filter pruning for accelerating deep Convolutional Neural Networks," 2018.
391
+ 337 [10] K. He, X. Zhang, S. Ren and J. Sun, "Deep Residual Learning for Image Recognition," in Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), pages
392
+ 770–778, 2016.
393
+ 340 [11] Y. He, X. Zhang, and J. Sun, "Channel pruning for accelerating very deep Neural Networks," in Proceedings of the IEEE Internation Conference on Computer Vision (ICCV), pages 1389–1397,
394
+ 2017.
395
+ 343 [12] M. Jaderberg, A. Vedaldi, and A. Zisserman, "Speeding up convolutional neural networks with low rank expansions," in Proceedings of the British Machine Vision Conference. (BMVA), 2014.
396
+ 45 [13] J. Jin, A. Dundar, and E. Culurciello, "Flattened convolutional neural networks for feedforward acceleration," arXiv preprint arXiv:1412.5474, 2014
397
+ 47 [14] A. Khosla, N. Jayadevaprakash, B. Yao, and F.-F. Li. "Novel dataset for fine-grained image categorization," in first Workshop on Fine-Grained Visual Categorization, IEEE Conference on Computer Vision and Pattern Recognition, Colorado Springs, CO, June 2011. [15] A. Krizhevsky, G. Hinton, et al. Learning multiple layers of features from tiny images. Technical report, Citeseer, 2009. [16] H. Li, A. Kadav, I. Durdanovic, H. Samet, and H.P. Graf, "Pruning filters for efficient ConvNets",
398
+ 2016. [17] J.H. Luo, J. Wu, and W. Lin, "Thinet: A filter level pruning method for deep Neural Network compression," in Proceedings of the IEEE Internation Conference on Computer Vision (ICCV), pages 5058–5066, 2017.
399
+ 357 [18] N. Ma, X. Zhang, H.-T. Zheng and J. Sun, "Shufflenet v2: Practical guidelines for efficient cnn architecture design", in Proceedings of the European Conference on Computer Vision (ECCV), pages 116–131, 2018. [19] M.-E. Nilsback and A. Zisserman. "Automated flower classification over a large number of classes", In 2008 Sixth Indian Conference on Computer Vision, Graphics and Image Processing, pages 722–729, IEEE, 2008.
400
+ 363 [20] E. Park, S. Yoo, and P. Vajda, "Value-aware quantization for training and inference of Neural Networks", in Proceedings of the European Conference on Computer Vision (ECCV), pages 580–595, 2018. [21] M. Rastegari, V. Ordonez, J. Redmon, and A. Farhadi, "Xnor-Net: ImageNet classification using binary Convolutional Neural Networks", in Proceedings of the European Conference on Computer Vision (ECCV), pages 525–542, 2016. [22] O. Russakovsky, J. Deng, H. Su, J. Krause, S. Satheesh, S. Ma, Z. Huang, A. Karpathy, A. Khosla, M. Bernstein, et al. Imagenet large scale visual recognition challenge. International journal of computer vision, 115(3):211–252, 2015.
401
+ 372 [23] M. Sandler, A. Howard, M. Zhu, A. Zhmoginov and L. Chen, "MobileNetV2: Inverted Residuals and Linear Bottlenecks," in Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), pages 4510–4520, 2018.
402
+ 375 [24] A. See, M.-T. Luong, and C. D. Manning, "Compression of neural machine translation models via pruning," in Proceedings of the 20th SIGNLL Conference on Computational Natural Language Learning, pages 291–301, 2016.
403
+ 378 [25] L. Sifre and S. Mallat. Rigid-motion scattering for image classification. PhD thesis, 2014. [26] W. Shang, K. Sohn, D. Almeida, and H. Lee, "Understanding and improving convolutional neural networks via concatenated rectified linear units," in Proceedings of international conference on machine learning (ICML), pages 2217–2225, 2016. [27] K. Simonyan and A. Zisserman, "Very deep convolutional networks for large-scale image recognition," in Proceedings of the International Conference on Learning Representations, 2015.
404
+ 384 [28] P. Singh, V.K. Verma, P. Rai, and V. Namboodiri, "Leveraging filter correlations for deep model compression," 2018. [29] C. Szegedy, W. Liu, Y. Jia, P. Sermanet, S. Reed, D. Anguelov, D. Erhan, V. Vanhoucke, and A. Rabinovich, "Going deeper with convolutions" in Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), pages 1–9, 2015. [30] C. Szegedy, V. Vanhoucke, S. Ioffe, J. Shlens and Z. Wojna, "Rethinking the Inception Architecture for Computer Vision," in Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), pages 2818–2826, 2016.
405
+ 392 [31] M. Tan, B. Chen, R. Pang, V. Vasudevan, and Q. V. Le, "Mnasnet: Platform-aware neural architecture search for mobile," arXiv preprint arXiv:1807.11626, 2018.
406
+ 394 [32] B. Wu, X. Dai, P. Zhang, Y. Wang, F. Sun, Y. Wu, Y. Tian, P. Vajda, Y. Jia, and K. Keutzer, "Fbnet: Hardware-aware efficient convnet design via differentiable neural architecture search," arXiv preprint arXiv:1812.03443, 2018. [33] J. Wu, C. Leng, Y. Wang, Q. Hu, and J. Cheng, "Quantized convolutional neural networks for mobile devices," in Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pages 4820–4828, 2016. [34] L. Xie and A. Yuille, "Genetic cnn," in Proceedings of the IEEE Internation Conference on Computer Vision (ICCV), pages 1379–1388, 2017.
407
+ 402 [35] D. Zhang, J. Yang, D. Ye, and G. Hua, "LQ-Nets: Learned quantization for highly accurate and compact deep Neural Networks," in Proceedings of the European Conference on Computer Vision (ECCV), pages 365–382, 2018.
408
+ 405 [36] X. Zhang, X. Zhou, M. Lin and J. Sun, "ShuffleNet: An Extremely Efficient Convolutional Neural Network for Mobile Devices," in Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), pages 6848–6856, 2018.
409
+
410
+ 408 [37] L. Zhu, R. Deng, M. Maire, Z. Deng, G. Mori, and P. Tan, "Sparsely aggregated Convolutional
411
+ 409 Networks," in Proceedings of the European Conference on Computer Vision (ECCV), pages
412
+ 410 186–201, 2018.
413
+ 411 [38] B. Zoph and Q. V. Le, "Neural architecture search with reinforcement learning," in Proceedings
414
+ 412 of the International Conference on Learning Representations, 2017.
415
+ 413 [39] B. Zoph, V. Vasudevan, J. Shlens, and Q. V. Le, "Learning transferable architectures for scalable
416
+ 414 image recognition," in Proceedings of the IEEE Conference on Computer Vision and Pattern
417
+ 415 Recognition (CVPR), pages 8697–8710, 2018.
418
+
419
+ 1. For all authors...
420
+
421
+ (a) Do the main claims made in the abstract and introduction accurately reflect the paper’s contributions and scope? [Yes] Section 1
422
+ (b) Did you describe the limitations of your work? [Yes] Section 3.2
423
+ (c) Did you discuss any potential negative societal impacts of your work? [No]
424
+ (d) Have you read the ethics review guidelines and ensured that your paper conforms to them? [Yes]
425
+
426
+ 2. If you are including theoretical results...
427
+
428
+ (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]
429
+
430
+ 3. If you ran experiments...
431
+
432
+ (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] Supplemental material
433
+ (b) Did you specify all the training details (e.g., data splits, hyperparameters, how they were chosen)? [Yes] Section 4.1, Section 4.2, Section 4.4, Appendix
434
+ (c) Did you report error bars (e.g., with respect to the random seed after running experiments multiple times)? [No]
435
+ (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] Section 4.2, Appendix
436
+
437
+ 4. If you are using existing assets (e.g., code, data, models) or curating/releasing new assets...
438
+
439
+ (a) If your work uses existing assets, did you cite the creators? [Yes] Section 4
440
+ (b) Did you mention the license of the assets? [Yes] Appendix
441
+ (c) Did you include any new assets either in the supplemental material or as a URL? [No]
442
+ (d) Did you discuss whether and how consent was obtained from people whose data you’re using/curating? [Yes] Appendix
443
+ (e) Did you discuss whether the data you are using/curating contains personally identifiable information or offensive content? [Yes] Appendix
444
+
445
+ 5. If you used crowdsourcing or conducted research with human subjects...
446
+
447
+ (a) Did you include the full text of instructions given to participants and screenshots, if applicable? [N/A]
448
+ (b) Did you describe any potential participant risks, with links to Institutional Review Board (IRB) approvals, if applicable? [N/A]
449
+ (c) Did you include the estimated hourly wage paid to participants and the total amount spent on participant compensation? [N/A]
md/dev/SwIp410B6aQ/SwIp410B6aQ.md ADDED
The diff for this file is too large to render. See raw diff
 
md/dev/Vu-B0clPfq/Vu-B0clPfq.md ADDED
@@ -0,0 +1,300 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Transformer Memory as a Differentiable Search Index
2
+
3
+ Yi Tay∗, Vinh Q. Tran∗, Mostafa Dehghani, Jianmo Ni, Dara Bahri, Harsh Mehta Zhen Qin, Kai Hui, Zhe Zhao, Jai Gupta, Tal Schuster William W. Cohen, Donald Metzler Google Research {yitay,vqtran,metzler}@google.com
4
+
5
+ # Abstract
6
+
7
+ In this paper, we demonstrate that information retrieval can be accomplished with a single Transformer, in which all information about the corpus is encoded in the parameters of the model. To this end, we introduce the Differentiable Search Index (DSI), a new paradigm that learns a text-to-text model that maps string queries directly to relevant docids; in other words, a DSI model answers queries directly using only its parameters, dramatically simplifying the whole retrieval process. We study variations in how documents and their identifiers are represented, variations in training procedures, and the interplay between models and corpus sizes. Experiments demonstrate that given appropriate design choices, DSI significantly outperforms strong baselines such as dual encoder models. Moreover, DSI demonstrates strong generalization capabilities, outperforming a BM25 baseline in a zero-shot setup.
8
+
9
+ # 1 Introduction
10
+
11
+ Information retrieval (IR) systems map a user query $q \in \mathcal { Q }$ to a ranked list of relevant documents $\{ d _ { 1 } , \ldots , d _ { n } \} \subseteq { \mathcal { D } }$ , typically represented by integers or short strings called document identifiers (docids). The most widely used IR approaches are based on pipelined retrieve-then-rank strategies. For retrieval, approaches based on inverted indexes or nearest neighbor search are common where contrastive learning based dual encoders (DEs) (Gillick et al., 2018; Karpukhin et al., 2020; Ni et al., 2021) are the present state-of-the-art.
12
+
13
+ This paper proposes an alternative architecture, wherein a sequence-to-sequence (seq2seq) learning system (Sutskever et al., 2014) is used to directly map a query $q$ to a relevant docid $j \in \mathcal { V }$ . This proposal is shown in the bottom half of Figure 1, for a sequence-to-sequence encoder-decoder architecture.
14
+
15
+ We call this proposed architecture a differentiable search index (DSI), and implement it with a large pre-trained Transformer (Vaswani et al., 2017) model, building on the recent success of large generative language models (LMs) (Brown et al., 2020; Raffel et al., 2019; Devlin et al., 2018; Thoppilan et al., 2022; Du et al., 2021). In this proposed architecture, all information of the corpus is encoded within the parameters of the Transformer language model.
16
+
17
+ At inference time, the trained model takes as input a text query $q$ and outputs a docid $j$ . If desired, beam search can be used to produce a ranked list of potentially-relevant docids. As we show, this process can work surprisingly well when trained properly. In our experiments it can consistently outperform DE baselines, sometimes drastically: for a base-sized T5 model, Hits $@ 1$ on the smallest corpus is improved by more than 20 points, from $12 . 4 \%$ for a DE to $3 3 . 9 \%$ for DSI; and on a corpus
18
+
19
+ ![](images/eacb2af8183bec70b70f2a09eee77df951e39feffe94596b4470a5cd1d6c64bb.jpg)
20
+ Figure 1: Comparison of dual encoders (top) to differentiable search index (bottom).
21
+
22
+ Table 1: Information retrieval requires a series of decisions, associated with the subproblems of document representation, indexing, and retrieval. Structured-document variants of DSI are also sensitive to a fourth decision, namely how docids are represented.
23
+
24
+ <table><tr><td></td><td>BM25 or TFIDF</td><td>Dual Encoder (DE)</td><td>Differentiable Search Index (DSI</td></tr><tr><td>doc/query rep.</td><td> sparse Vdj vector in R|VI</td><td>dense Vdj vector in Rd</td><td>Various (see Section 3.1.2)</td></tr><tr><td>docid rep.</td><td></td><td></td><td>Various (see Section 3.2)</td></tr><tr><td>indexing</td><td>build inverted index mapping each termt→{dji,...,djx}</td><td>build table mapping each docvec Vd→ j</td><td>train model (see Section 3.1.1) to map dj → j</td></tr><tr><td>retrieval (top-1)</td><td>approximate sparse matmul to find argmaxjv Vdj</td><td>approximate MIPS to find argmaxjv Vdj</td><td>run trained model to find argmax Pr(jlq)</td></tr></table>
25
+
26
+ $3 0 \times$ larger, performance is improved by nearly 7 points. These gains increase when larger models are used: for an 11B-parameter T5 model, Hits $@ 1$ performance improves by more than 25 points over DE on the small corpus, and more than 15 points on the large corpus. DSI also performs extremely well in a zero-shot setting, e.g., improving Hits $@ 1$ by 14 points over BM25.
27
+
28
+ In addition to these quantitative gains, the DSI architecture is much simpler than a DE (see Table 1). A DE system fixes a search procedure (MIPS) and learns internal representations that optimize performance for that search procedure; in contrast, a DSI system contains no special-purpose fixed search procedure, instead using standard model inference to map from encodings to docids.
29
+
30
+ Of particular interest to the machine learning community, as Table 1 shows, in DSI all aspects of retrieval are mapped into well-understood ML tasks. This may lead to new potential approaches to solving long-standing IR problems. As one example, since indexing is now a special case of model training, incrementally updating an index becomes a special case of model updating (Sun et al., 2020).
31
+
32
+ In this paper, DSI is applied to moderate-sized corpora (from 10k to $3 2 0 \mathrm { k }$ documents), all of which are derived from one challenging retrieval task, and we leave the important question of the scaling DSI to larger corpora to future work. The task considered is retrieving supporting passages given questions from the Natural Questions (NQ) dataset, a challenging task for lexical models.
33
+
34
+ While the idea of DSI is simple, there are a number of ways it can be realized, some of which work surprisingly well, and some of which work surprisingly poorly. Below we explore a number of variations of the DSI architecture.
35
+
36
+ Document representation. We explore several approaches to representing documents, including a “naive” approach of using the document’s full text, as well as variants of the bag-of-words representation used by traditional IR engines.
37
+
38
+ Docid representation. We look at several ways to represent docids. In addition to naively representing integers as text strings, we also consider unstructured atomic docids, where each document is assigned a unique token, and some simple baselines for constructing structured semantic docids that describe how to navigate to a document through a hierarchical clustering of the corpus. Structured docids— either semantically structured via clustering, or naively structured as tokenized integers—scale better to large corpora, since the size of the vocabulary used in the decoder is made larger.
39
+
40
+ Indexing. A trainable IR system traditionally has two phases: indexing a corpus (i.e., memorizing information about each document), and learning how to effectively retrieve from the index. In DSI, the index is stored in the model parameters, and indexing is simply another kind of model training. Figure 1 suggests one approach to indexing a corpus: namely, to train on (1) examples $( d _ { j } , j )$ that pair document $d _ { j }$ with its docid $j$ , in addition to (2) examples $( q , j )$ that pair a query $q$ with a relevant docid $j$ . In this setup the examples of type (1) are “indexing” examples.
41
+
42
+ While it is clear that examples of type (2) alone do not provide enough information for a system to generalize to novel retrievals, there are many alternatives to examples of type (1) that might plausibly “teach” a model about the associations between documents and docids. We explore a number of these below, and show that some plausible-seeming techniques perform very poorly. We also explore a number of alternative multi-task optimization and curriculum learning schemes for combining these types of examples.
43
+
44
+ Effects of model and corpus size. Since recent results suggest that some properties of large LMs emerge only for very large model sizes Brown et al. (2020), we explore the performance of DSI for a range of model sizes and corpus sizes of 10k, 100k, and 320k documents.
45
+
46
+ Summary. We show that even naive representations for documents and docids, coupled with appropriate training procedures to fine-tune modern large LMs, can perform surprisingly well; we present two improved docid representations, unstructured docids and semantically-structured docids, which improve the naive representation choice. We show that there is substantial variation in performance among indexing/training strategies and we show that performance of DSI significantly and consistently improves with model scale. To our knowledge this is the first case of generative indexing improving performance over strong baselines for a well-studied document retrieval task.
47
+
48
+ # 2 Related Work
49
+
50
+ De Cao et al. (2020) describe a related sequence-to-sequence system called autoregressive entity linking, in which documents mentioning an entity—perhaps implicitly, e.g., by posing a question to which that entity is an answer—are mapped to a canonical name of that entity. In the case of Wikipedia, canonical entity names correspond to page titles, so this could be viewed as a sort of document retrieval. This approach has been adapted to other purposes, such as generating knowledge base triples in canonical form (Josifoski et al., 2021). The task we consider is different from those considered in autoregressive entity linking: our goal is to retrieve a document containing the answer, rather than a document whose title is the answer. More importantly, in autoregressive entity linking the generation target is a semantically meaningful name, whereas we allow targets to be arbitrary docids. This makes our approach applicable to general retrieval tasks, but raises new questions about docid representation and indexing strategies.
51
+
52
+ In autoregressive entity linking, generation is constrained to return an output from a fixed set. It would be feasible to constrain DSI generation outputs to be valid docids. Although we do not use this technique, the degree to which this might improve performance is a worthwhile question.
53
+
54
+ There is a large body of work on retrieval augmented generation, i.e., retrieving auxiliary documents to enhance language models (Borgeaud et al., 2021; Guu et al., 2020). These techniques are useful for many tasks including question-answering, but rely on traditional retrieval methods such as DEs. Here we use generation to replace a retrieval process, rather than using retrieval to augment a generation process.
55
+
56
+ Dual encoders (Dehghani et al., 2017; Gillick et al., 2018; Gao et al., 2021; Ni et al., 2021; Karpukhin et al., 2020) are a well-established paradigm for retrieval. The key idea is produce query and document embeddings independently and perform a similarity retrieval in vector space across all embedding pairs. Query and candidate documents are produced by a sequence encoder and training is performed using a form of contrastive loss.
57
+
58
+ The interpretation of a large Transformer model as a memory store have been investigated in prior work. (Roberts et al., 2020) demonstrated success on a closed-book QA task whereby they train
59
+
60
+ T5 models to retrieve facts that are encoded within the parameters of the model during pretraining. However, different from CBQA, the presented problem here in this paper is to retrieve full documents based on docids instead of generating direct answers. Meanwhile, (Petroni et al., 2019) also investigated language models as knowledge bases and found that pretrained LMs may already contain relational knowledge. (Geva et al., 2020) analyzes the knowledge encoded within Transformer feedforward layers. There have been also works that demonstrate the relation of Transformers to associative memory and Hopfield networks (Ramsauer et al., 2020), which reinforce the notion that Transformers should intuitively serve as a good associative memory store or search index.
61
+
62
+ # 3 Differentiable Search Index
63
+
64
+ The core idea behind the proposed Differentiable Search Index (DSI) is to fully parameterize traditionally multi-stage retrieve-then-rank pipelines within a single neural model. To do so, DSI models must support two basic modes of operation:
65
+
66
+ • Indexing: a DSI model should learn to associate the content of each document $d _ { j }$ with its corresponding docid $j$ . This paper utilizes a straightforward sequence-to-sequence (seq2seq) approach that takes document tokens as input and generates identifiers as output. • Retrieval: Given an input query, a DSI model should return a ranked list of candidate docids. Here, this is achieved with autoregressive generation.
67
+
68
+ Following these two operations, a DSI model can be trained to index a corpus of documents and optionally fine-tune on an available set of labeled data (queries and labeled documents), and thereafter used to retrieve relevant documents—all within a single, unified model. As opposed to retrieve-thenrank approaches, this type of model allows for simple end-to-end training and can easily be used as a differentiable sub-component of a larger, more complex neural model.
69
+
70
+ # 3.1 Indexing Strategies
71
+
72
+ We investigate various indexing strategies that are meant to learn associations between documents and their identifiers. We train our model to predict docids given a sequence of document tokens. This allows our model to learn which identifier belongs to which document and can be thought of as a differentiable take on traditional search indexes. We consider various alternatives and ablate these settings in subsequent sections. The final strategy employed was Inputs2Targets with direct indexing.
73
+
74
+ # 3.1.1 Indexing Method
75
+
76
+ This section discusses the indexing task variants that we consider.
77
+
78
+ Inputs2Target We frame this as a seq2seq task of doc_tokens docid. As its name suggests, this binds the docids to the document tokens in a straightforward inputs-to-targets fashion. The advantage here is that the identifier is the denoising target, which puts it in closer proximity to the loss function. Since the retrieval task is also concerned with predicting identifiers, this formulation allows the network to follow a similar input-target balance in terms of sequence length. A potential weakness is that the document tokens are not denoising targets and therefore there is no opportunity for general pre-training on document tokens.
79
+
80
+ Targets2Inputs This formulation considers the opposite of the above, i.e., generating document tokens from identifiers, i.e., docid doc_tokens. Intuitively, this is equivalent to training an autoregressive language model that is conditioned on the docid.
81
+
82
+ Bidirectional This formulation trains both Inputs2Targets and Targets2Inputs within the same co-training setup. A prefix token is prepended to allow the model to know which direction the task is being performed in.
83
+
84
+ Span Corruption We also explored a setup that performs span corruption-based denoising (Raffel et al., 2019) with the inclusion of docid tokens. In this approach, we concatenate the identifier to the document tokens as a prefix that can be randomly masked as spans in the span corruption objective.
85
+
86
+ This method has the advantage of (1) also performing general pre-training during indexing and (2) achieving a good balance of docids as denoising targets and inputs.
87
+
88
+ # 3.1.2 Document Representation Strategies
89
+
90
+ In the previous section, we explored “how to index”. This section investigates “what to index?”, i.e., how to best represent doc_tokens. We state our options here and carefully ablate them in our experiments later. The best option in the end was the direct indexing method.
91
+
92
+ Direct Indexing This strategy represents a document exactly. We take the first $L$ tokens of a document, with sequential order preserved, and associate them with the docid.
93
+
94
+ Set Indexing Documents may contain repeated terms and/or non-informative words (e.g., stopwords). This strategy de-duplicates repeated terms using the default Python set operation and removes stopwords from the document. The rest of the document after filtering is passed into the model in similar fashion to the direct index.
95
+
96
+ Inverted Index This strategy maps chunked documents (contiguous blocks of tokens) instead of entire documents directly to the docid. We randomly subsample a single contiguous chunk of $k$ tokens and associate them with the docid. The key advantage of this approach is to allow looking beyond the first $k$ tokens.
97
+
98
+ # 3.2 Representing Docids for Retrieval
99
+
100
+ Retrieval within seq2seq-based DSI models is accomplished by decoding docids given an input query. How to do this decoding in an effective way largely depends on how docids are represented in the model. The remainder of this section explores a number of possible ways for representing docids and how to handle decoding for each.
101
+
102
+ Unstructured Atomic Identifiers The most naive way to represent documents is assign each an arbitrary (and possibly random) unique integer identifier. We refer to these as unstructured atomic identifiers.
103
+
104
+ With these identifiers, an obvious decoding formulation is to learn a probability distribution over the identifiers. In this case, models are trained to emit one logit for each unique docid $( | N _ { d o c u m e n t s } | )$ This is analogous to the output layer in standard language models, but extended to include docids.
105
+
106
+ To accommodate this, we extend the output vocabulary of a standard language model as follows:
107
+
108
+ $$
109
+ O = \mathrm { S o f t m a x } ( [ W _ { t o k e n s } ; W _ { d o c s } ] ^ { T } h _ { l a s t } )
110
+ $$
111
+
112
+ where $[ ; ]$ is the row-wise concatenation operator, $W _ { t o k e n s } ~ \in ~ \mathbb { R } ^ { d _ { m o d e l } \times | N _ { t o k e n s } | }$ and $W _ { d o c s } ~ \in$ $\mathbb { R } ^ { d _ { m o d e l } \times | N _ { d o c u m e n t s } | }$ . $h _ { l a s t }$ is the last layer’s hidden state $( \in \mathbb { R } ^ { d _ { m o d e l } } )$ of the decoder stack. To retrieve the top- $\mathbf { \nabla } \cdot \mathbf { k }$ documents for a given query, we simply sort the output logits and return the corresponding indices. This is also reminiscent of standard listwise learning to rank where all documents are considered at once.
113
+
114
+ Naively Structured String Identifiers We also consider an ostensibly absurd approach that treats unstructured identifiers, i.e., arbitrary unique integers, as tokenizable strings. We refer to these as naively structured identifiers.
115
+
116
+ In this formulation, retrieval is accomplished by decoding a docid string sequentially one token at a time. This eliminates the need for the large softmax output space that comes with unstructured atomic identifiers. It also eliminates the need to learn embeddings for each individual docid.
117
+
118
+ When decoding, beam search is used to obtain the predicted best docid. With this strategy, it is less straightforward to obtain a top- $\mathbf { \nabla } \cdot \mathbf { k }$ ranking. One could exhaustively comb through the entire docid space and obtain the likelihood of each docid given the query. Instead, we use the partial beam search tree to construct top- $\mathbf { \nabla } \cdot \mathbf { k }$ retrieval scores. We find this approximation to be quite efficient and effective in practice.
119
+
120
+ Semantically Structured Identifiers All of the approaches for representing docids thus far assumed that the identifiers are assigned in an arbitrary manner. While exploring the limits of arbitrary identifiers is quite interesting, it is only intuitive that imbuing the docid space with semantic structure can lead to better indexing and retrieval capabilities. As such, this section explores semantically structured identifiers.
121
+
122
+ Specifically, we aim to automatically create identifiers that satisfy the following properties: (1) the docid should capture some information about the semantics of its associated document, (2) the docid should be structured in a way that the search space is effectively reduced after each decoding step. This results in identifiers where semantically similar documents share identifier prefixes.
123
+
124
+ In this work, we treat this as a fully unsupervised pre-processing step. However, as part of future work it may be possible to integrate and automatically learn semantic identifiers in a fully end-to-end manner.
125
+
126
+ ![](images/ca8e40c9da6bcbfccda494eda170b6ca1aeb739f6da3a4c7c0260e628efbee76.jpg)
127
+ Figure 2: Visual example of a hierarchical clustering process used to assign semantically structured identifiers. During inference, beam search navigates this trie to decode the correct docid.
128
+
129
+ # Algorithm 1 Generating semantically structured identifiers. (Referenced in Section 3.2.)
130
+
131
+ To construct identifiers with this property, we employ a simple hierarchical clustering process over document embeddings to induce a decimal tree (or more generally, a trie).
132
+
133
+ Given a corpus to be indexed, all documents are clustered into 10 clusters. Each document is assigned an identifier with the number of their cluster from 0-9. For every cluster containing more than $c$ documents, the algorithm is applied recursively, with the next level’s result (the remaining suffix of the identifier) appended to the existing identifier.
134
+
135
+ <table><tr><td>Input:Document embeddings X1:N,where Xi ∈ Rd Output: Corresponding docid strings J1: N function GENERATESEMANTICIDS(X1:N) C1:10←Cluster(Xi:N,k=10) J←empty list fori= O to 9 do</td></tr><tr><td>Jcurrent ← [i]*|Ci+1l if|Ci+1|&gt;c then Jrest ←GENERATESEMANTICIDS(Ci+1)</td></tr><tr><td>else Jrest ← [0,...,|Ci+1|-1]</td></tr><tr><td>end if Jcluster ←elementwiseStrConcat(Jcurrent,Jrest)</td></tr><tr><td>J ←J.appendElements(Jcluster) end for</td></tr><tr><td>J ←reorderToOriginal(J,X1:N,C1:10) return J</td></tr></table>
136
+
137
+ For clusters with $c$ documents or less, each element is assigned an arbitrary number from 0 to at most $c - 1$ and likewise its digits are appended to the existing identifier. Although this specific process induces a decimal tree, it is possible to induce similar types of tries using any number of other reasonable strategies.In practice, we simply apply $k$ -means over embeddings generated by a small 8-layer BERT model, with $c = 1 0 0$ . We include pseudo-code for this process in Algorithm 1.
138
+
139
+ # 3.3 Training and Optimization
140
+
141
+ The DSI models that we train are optimized for seq2seq cross entropy loss and are trained with teacher forcing. We explored two main strategies for training DSI models. The first and more straightforward strategy is to first train a model to perform indexing (memorization), followed by a fine-tuning stage where the trained model is used to map queries to docids (e.g., retrieval). The second strategy is to train them together in a multi-task setup. To this end, we frame co-training tasks in similar fashion to T5-style co-training (e.g., using task prompts to differentiate them). The latter performed significantly better, especially when the proportion of indexing to retrieval task examples is high. Hence, we adopted multi-task learning as the default strategy.
142
+
143
+ Here, we make the observation that our setup is unique and unlike traditional multi-task learning or transfer learning. In typical multi-task setups, two tasks have shared commonalities that could improve the performance of both tasks if they were learned together. However, in our setup, the retrieval task is completely dependent on the indexing task. In particular, without the indexing task, the identifiers leveraged by the retrieval task would be completely meaningless. Hence, in order to solve task B (retrieval), the model needs to learn task A (indexing) well enough. This problem setup presents unique and largely unexplored research challenges that might be of interest to the ML community.
144
+
145
+ # 4 Experiments
146
+
147
+ In this section, we discuss our experimental setup, datasets used and baselines compared. We also discuss experimental results, findings and effect of various strategies discussed in earlier sections of the paper. Since this is fairly new concept, this work aims to put forth a proof-of-concept and seeks to answer research questions instead of making a ‘sotaeesque’ comparison. We leave extensive comparisons on other setups and baselines to future work.
148
+
149
+ Dataset We conduct our experiments on the challenging Natural Questions (NQ) (Kwiatkowski et al., 2019) dataset. NQ consists of 307K query-document training pairs and 8K validation pairs, where the queries are natural language questions and the documents are Wikipedia articles. Given a question, the retrieval task is to identify the Wikipedia article that answers it. For evaluating how DSI models perform at different scales, we construct three sets from NQ to form our testbed, namely NQ10K, NQ100K, and NQ320K denoting different numbers of total query-document pairs in the combined train and validation splits. NQ320K is the full NQ set and uses its predetermined training and validation split for evaluation purposes. Unlike NQ320K, NQ10K and NQ100K constructs randomly sampled validation sets. For all datasets, we use the same docid space/budget of 320K tokens for all unstructured atomic and naively structured identifier experiments. Semantically structured identifiers are generated separately for each dataset so as to prevent leakage of semantic information from larger splits into smaller ones. Text is lowercased. Note that there exists fewer unique documents than query-document pairs in these datasets. Please refer to Table 4 (Appendix) which reports the statistics of these datasets.
150
+
151
+ Metrics We evaluate our models on $\mathrm { H i t s } @ \mathrm { N }$ where $\scriptstyle \mathrm { N = } \{ 1 , 1 0 \}$ . This metric reports the proportion of correct documents ranked in the top $N$ predictions.
152
+
153
+ Implementation Details All DSI models are initialized using standard pretrained T5 (Raffel et al., 2019) model configurations. The configurations names and corresponding number of model parameters are: Base (0.2B), Large (0.8B), XL (3B) and XXL (11B). For unstructured atomic identifiers runs, we initialize the identifiers randomly as new parameters and only finetune the weights during the indexing stage. We use the Jax/T5X 2 implementation for our experiments. The DSI models are trained for a maximum of 1M steps using a batch size of 128. We pick the best checkpoint based on retrieval validation performance. Our training hardware consists of 128-256 TPUv4 chips for models above 1B parameters and 64-128 TPUv3 or TPUv4 chips otherwise. As an estimate, models above 1B parameters typically take about at least a full day for convergence for NQ320K. We tune the learning rate amongst $\{ 0 . 0 0 1 , 0 . 0 0 0 5 \}$ and linear warmup amongst $\{ 1 0 \mathrm { K } , 1 0 0 \mathrm { K } , 2 0 0 \mathrm { K } .$ $3 0 0 \mathrm { K } \}$ and/or none. Semantically structured identifiers are generated using an 8-layer BERT (Devlin et al., 2018) model 3, and the default $k$ -means clustering in scikit-learn. Based on our early ablation experiments of various DSI setting, the main results presented use direct indexing $L = 3 2$ ) and the Inputs2Targets indexing strategy. We present results for all the docid representation methods. Following the main results, we present our ablation studies.
154
+
155
+ # 4.1 Baselines
156
+
157
+ For baselines, we use T5-based dual encoders implemented by (Ni et al., 2021). We use the gensim4 package for computing BM25 scores. For the T5-based dual encoders, we train with contrastive learning on the NQ pairs until convergence $\approx 1 0 \mathrm { K }$ steps) and obtain top-k nearest neighbors with a system similar to ScaNN (Guo et al., 2020). For zero-shot retrieval, we also compare with a state-ofthe-art unsupervised baseline, Sentence T5 (Ni et al., 2021) which have been specially pre-trained with a similarity learning task. There two reasons why we consider (Ni et al., 2021) the relevant dual encoder baseline for this work rather than other dense retrieval works such as DPR (Karpukhin et al.,
158
+
159
+ Table 2: Experimental results on NQ document retrieval. DSI outperforms BM25 and Dual Encoder baselines. Among all the Docid representation methods, Semantic String Docids perform the best.
160
+
161
+ <table><tr><td colspan="4"></td><td colspan="2">NQ10K</td><td colspan="2">NQ100K</td><td colspan="2">NQ320K</td></tr><tr><td>Model</td><td>Size</td><td>Params</td><td>Method</td><td>Hits @1</td><td>Hits @10</td><td>Hits@1</td><td>Hits@10</td><td>Hits@1</td><td>Hits@10</td></tr><tr><td>BM25</td><td></td><td>=</td><td>■</td><td>12.4</td><td>33.5</td><td>20.9</td><td>46.4</td><td>11.6</td><td>34.4</td></tr><tr><td>T5</td><td>Base</td><td>220M</td><td>Dual Encoder</td><td>16.2</td><td>48.6</td><td>18.7</td><td>55.2</td><td>20.5</td><td>58.3</td></tr><tr><td>T5</td><td>Large</td><td>800M</td><td>Dual Encoder</td><td>18.8</td><td>55.7</td><td>22.3</td><td>60.5</td><td>22.4</td><td>63.3</td></tr><tr><td>T5</td><td>XL</td><td>3B</td><td>Dual Encoder</td><td>20.8</td><td>59.6</td><td>23.3</td><td>63.2</td><td>23.9</td><td>65.8</td></tr><tr><td>T5</td><td>XXL</td><td>11B</td><td>Dual Encoder</td><td>22.1</td><td>61.6</td><td>24.1</td><td>64.5</td><td>24.3</td><td>67.3</td></tr><tr><td>DSI</td><td>Base</td><td>250M</td><td>Atomic Docid</td><td>13.0</td><td>38.4</td><td>23.8</td><td>58.6</td><td>20.7</td><td>40.9</td></tr><tr><td>DSI</td><td>Large</td><td>800M</td><td>Atomic Docid</td><td>31.3</td><td>59.4</td><td>17.1</td><td>52.3</td><td>11.6</td><td>37.6</td></tr><tr><td>DSI</td><td>XL</td><td>3B</td><td>Atomic Docid</td><td>40.1</td><td>76.9</td><td>19.0</td><td>55.3</td><td>28.1</td><td>61.9</td></tr><tr><td>DSI</td><td>XXL</td><td>11B</td><td>Atomic Docid</td><td>39.4</td><td>77.0</td><td>25.3</td><td>67.9</td><td>24.0</td><td>55.1</td></tr><tr><td>DSI</td><td>Base</td><td>250M</td><td>Naive String Docid</td><td>28.1</td><td>48.0</td><td>18.7</td><td>44.6</td><td>6.7</td><td>21.0</td></tr><tr><td>DSI</td><td>Large</td><td>800M</td><td>Naive String Docid</td><td>34.7</td><td>60.5</td><td>21.2</td><td>50.7</td><td>13.3</td><td>33.6</td></tr><tr><td>DSI</td><td>XL</td><td>3B</td><td>Naive String Docid</td><td>44.7</td><td>66.4</td><td>24.0</td><td>55.1</td><td>16.7</td><td>58.1</td></tr><tr><td>DSI</td><td>XXL</td><td>11B</td><td>Naive String Docid</td><td>46.7</td><td>77.9</td><td>27.5</td><td>62.4</td><td>23.8</td><td>55.9</td></tr><tr><td>DSI</td><td>Base</td><td>250M</td><td>Semantic String Docid</td><td>33.9</td><td>57.3</td><td>19.0</td><td>44.9</td><td>27.4</td><td>56.6</td></tr><tr><td>DSI</td><td>Large</td><td>800M</td><td>Semantic String Docid</td><td>37.5</td><td>65.1</td><td>20.4</td><td>50.2</td><td>35.6</td><td>62.6</td></tr><tr><td>DSI</td><td>XL</td><td>3B</td><td>Semantic String Docid</td><td>41.9</td><td>67.1</td><td>22.4</td><td>52.2</td><td>39.1</td><td>66.8</td></tr><tr><td>DSI</td><td>XXL</td><td>11B</td><td>Semantic String Docid</td><td>48.5</td><td>72.1</td><td>26.9</td><td>59.5</td><td>40.4</td><td>70.3</td></tr></table>
162
+
163
+ Table 3: Experimental results on Zero-Shot NQ document retrieval. DSI outperforms BM25, T5 embeddings and SentenceT5, the state-of-the-art for unsupervised similarity modeling. Among Docid representation method, the Atomic Docid performs the best on zero-shot learning.
164
+
165
+ <table><tr><td rowspan="2">Size</td><td rowspan="2">Method</td><td rowspan="2"></td><td colspan="2">NQ10K</td><td colspan="2">NQ100K</td><td colspan="2">NQ320K</td></tr><tr><td>Hits@1</td><td>Hits@10</td><td>Hits@1</td><td>Hits@10</td><td>Hits@1</td><td>Hits @10</td></tr><tr><td>BM25</td><td>=</td><td></td><td>12.4</td><td>33.5</td><td>20.9</td><td>46.4</td><td>11.6</td><td>34.4</td></tr><tr><td>T5</td><td>XXL</td><td>Dual Encoder</td><td>0.3</td><td>1.3</td><td>1.9</td><td>8.0</td><td>1.1</td><td>5.9</td></tr><tr><td>SentenceT5</td><td>Large</td><td>Dual Encoder</td><td>17.6</td><td>50.7</td><td>17.4</td><td>50.8</td><td>16.9</td><td>51.0</td></tr><tr><td>DSI</td><td>XXL</td><td>Atomic Docid</td><td>25.7</td><td>60.1</td><td>23.0</td><td>57.3</td><td>25.1</td><td>56.6</td></tr><tr><td>DSI</td><td>XXL</td><td>Naive String Docid</td><td>43.4</td><td>67.4</td><td>17.4</td><td>41.5</td><td>9.2</td><td>22.6</td></tr><tr><td>DSI</td><td>XXL</td><td>Semantic String Docid</td><td>43.9</td><td>68.8</td><td>11.4</td><td>26.6</td><td>13.9</td><td>31.1</td></tr></table>
166
+
167
+ 2020). Firstly, we employ the exact identical pretrained model, which allows systematic ablation of the proposed approach without conflating other factors. Scientifically, we believe this comparison against fine-tuned T5 is the best apples to apples comparison that we provide. Secondly, fine-tuned T5 dual encoders are considered to be architecturally and methodologically very identical to DPR (with some minor differences such as parameter sharing but use the same concept of in-batch negatives).
168
+
169
+ # 4.2 Experimental Results
170
+
171
+ Table 2 reports retrieval results for NQ10K, NQ100K, and NQ320K with finetuning and Table 3 reports zero-shot retrieval results. For zero-shot retrieval, the model is only trained on the indexing task and not the retrieval task, so the model sees no labeled query docid data points. Section 7.2 of the Appendix reports extended results regarding the indexing performance and training dynamics of DSI.
172
+
173
+ Supervised Finetuning Results Our results show that DSI outperforms DE across all dataset sizes. On the small dataset (NQ10K), the performance gap between DSI and DE is large, e.g., the best DSI variant outperforms DE by 2 times. On NQ100K, the gap becomes less prominent with the best DSI model (unstructured atomic identifiers) outperforming DE by $+ 5 \%$ Hits $@ 1$ and Hits $@ 1 0$ . On the large dataset (NQ320K), the best DSI model (structured semantic identifiers) outperform the best DE model by $+ 6 6 \%$ relative Hits $@ 1$ and $+ 4 . 5 \%$ Hits $@ 1 0$ .
174
+
175
+ Zero-Shot Results Table 3 reports results on zeros-shot retrieval. Recall that zero-shot retrieval is performed by only performing indexing and not the retrieval task. In other words, the model does not see any annotated query or document pairs. Generally, the best result is obtained by DSI with unstructured atomic identifiers on both NQ100K and NQ320K. The best performance on all NQ datasets outperform well-established unsupervised retrieval baselines such as BM25. Moreover, DSI outperforms unsupervised representation learning methods such as SentenceT5 (Ni et al., 2021), which is trained to learn similarity-aware representations via contrastive learning. We also note that raw T5 embeddings perform extremely poorly and do not produce reasonable results on the task of unsupervised retrieval. Given that it is generally difficult for an unsupervised neural method to outperform BM25, we find these early results very encouraging.
176
+
177
+ ![](images/a25295c9c750475e0cada8ddeb780add2a01d5ac609f23b0f174f396b20118ed.jpg)
178
+ Figure 3: Scaling plots for DSI vs. DE across model sizes. Performance refers to the Hits $@ 1$ metric.
179
+
180
+ ![](images/680d9297a4ac25120008bee489f0dc5a602e475768036fe8b8ce96ca48c08223.jpg)
181
+ Figure 4: Effect of multi-task ratio of indexing to retrieval examples.
182
+
183
+ ![](images/0643a55d3d5cc43d5ebca292a304e3942d718a5bca8ec0e94659d6c9f16b589a.jpg)
184
+ Figure 5: Performance of different document representations. (Referenced in Section 4.2.)
185
+
186
+ Document Identifiers One key research question in this paper is the crucial choice of how to represent docids. Generally, we find that structured semantic identifiers are helpful and improve over unstructured identifiers. When comparing naive versus semantic string identifiers, it seems imperative to use semantic identifiers if possible. This is intuitive, since imbuing the target space with semantic structure can facilitate greater ease of optimization and additional unsupervised representation learning methods as external knowledge. The competitiveness of unstructured atomic identifiers is somewhat mixed and we had some difficulty optimizing such models. We hypothesize that this could possibly be because of the the newly initialized softmax layer and that training such a system from scratch would mitigate these issues. However, we defer this line of investigation to future work. In lieu of the instability and high variance of the unstructured atomic identifiers, the performance is not consistent across the different datasets. Moreover, these docids might also run into intermittent non-convergence which we trace back to an optimization related quirk. However, we also note that unstructured atomic identifiers perform the best, by a wide margin, on the zero-shot retrieval setup and achieve performance often more than double than that of beam decoding methods.
187
+
188
+ Indexing Strategies In this section, we explore the effect of different indexing methods (Section 3.1.1). We run experiments on NQ100K with the different indexing strategies described earlier. Models are trained using the Naive Docid method. Without indexing, the model achieves $0 \%$ Hits $@ 1$ . This is intuitive, since the Docids are not meaningful without the indexing task. Secondly, the Inputs2Targets and Bidirectional formulation performs the best, with the bidirectional method performing slightly worse (13.5 vs 13.2) compared to the former. Finally, the accuracy with Targets2Inputs and Span Corrpution with Docids yield no meaningful results ( $\mathrm { { \bar { 0 } \% } }$ accuracy). This goes to show that there can be huge variance across indexing strategies whereby some strategies work reasonably well and some completely do not work at all.
189
+
190
+ Document Representations In this section, we explore the performance of the different document representation strategies described in Section 3.1.2. Figure 5 reports the results on NQ320K. Overall, we find that the direct indexing approach works the best. We also find that it is difficult to train the inverted index method since the docid is repeatedly exposed to different tokens. We also find that shorter document lengths seem to work well where performance seems to substantially dip beyond 64 tokens suggesting that it might be harder to optimize or efficiently memorize when there are a larger number of document tokens. Finally, we also find that there was no additional advantage in applying set processing or stopwords preprocessing to the document tokens.
191
+
192
+ Scaling Laws Another interesting insight is how the scaling law of DSI differs from Dual Encoders. Understanding the scaling behaviour of Transformers have garnered significant interest in recent years (Kaplan et al., 2020; Tay et al., 2021; Abnar et al., 2021). We find that the gain in retrieval performance obtained from increasing model parameterization in DE seems to be relatively small. Conversely, the scaling properties of DSI seems to be more optimistic.
193
+
194
+ Figure 3 plots the scaling behaviour (log scale) of three methods (DE and DSI with naive and semantic IDs). DSI (naive) strongly benefits from scale going from base to XXL and seems to still have headroom for improvement. Meanwhile, DSI (semantic) starts off equally competitive as DE base but performs much better with scale. DE models, unfortunately are more or less plateaued at smaller parameterization.
195
+
196
+ Interplay Between Indexing and Retrieval Our early experiments showed that first learning the indexing task and then learning the retrieval task in a sequential manner results in mediocre performance. There, we focused on exploring good ratios $r$ for co-training the indexing and retrieval tasks together using multi-task learning. Figure 4 shows the effect of modifying the ratio of indexing to retrieval samples. We find the optimization process is significantly influenced by the interplay between the indexing and retrieval tasks. Setting $r$ too high or low generally resulted in poor performance. We find that a rate of 32 generally performed well.
197
+
198
+ # 5 Conclusion
199
+
200
+ This paper proposed the Differentiable Search Index (DSI), a new paradigm for learning an end-to-end search system in a unified manner, paving the way for next generation search (Metzler et al., 2021). We define novel indexing and retrieval tasks that encode the relationship between terms and docids completely within the parameters of a Transformer model. The paper proposed a number of different ways to represent documents and docids, and explored different model architectures and model training strategies. Experiments conducted on the Natural Questions data set show that DSI performs favorably against common baselines such as BM25 and dual encoders, both in a standard fine-tuning setup as well as in a zero-shot setup.
201
+
202
+ Although the models and results presented here are promising, there is a great deal of potential future research that can be explored based on this work to improve this approach. For example, it would be interesting to explore alternative strategies for representing documents and docids, as well as to investigate mixture-of-expert models (Du et al., 2021; Fedus et al., 2021; Lepikhin et al., 2020) for scaling the memory capacity of DSI. One important direction will also be to explore how such models can be updated for dynamic corpora, where documents may be added or removed from the system. Finally it may also be interesting to further investigate DSI as an unsupervised representation learning method and/or memory store for other language models to leverage.
203
+
204
+ # 6 Acknowledgements
205
+
206
+ The authors would like to thank you Fernando Pereira, Huaixiu Steven Zheng, Sebastian Ruder, Adam D. Lelkes, Ian Wetherbee and Dani Yogatama for their valuable feedback and discussions. We would also like to extend a special thanks to Sanket Vaibhav Mehta for additional experimental contributions.
207
+
208
+ # References
209
+
210
+ Samira Abnar, Mostafa Dehghani, Behnam Neyshabur, and Hanie Sedghi. Exploring the limits of large scale pre-training. arXiv preprint arXiv:2110.02095, 2021.
211
+
212
+ Sebastian Borgeaud, Arthur Mensch, Jordan Hoffmann, Trevor Cai, Eliza Rutherford, Katie Millican, George van den Driessche, Jean-Baptiste Lespiau, Bogdan Damoc, Aidan Clark, et al. Improving language models by retrieving from trillions of tokens. arXiv preprint arXiv:2112.04426, 2021.
213
+
214
+ Tom B Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah, Jared Kaplan, Prafulla Dhariwal, Arvind Neelakantan, Pranav Shyam, Girish Sastry, Amanda Askell, et al. Language models are few-shot learners. arXiv preprint arXiv:2005.14165, 2020.
215
+
216
+ Nicola De Cao, Gautier Izacard, Sebastian Riedel, and Fabio Petroni. Autoregressive entity retrieval. arXiv preprint arXiv:2010.00904, 2020.
217
+
218
+ Mostafa Dehghani, Hamed Zamani, Aliaksei Severyn, Jaap Kamps, and W Bruce Croft. Neural ranking models with weak supervision. In Proceedings of the 40th International ACM SIGIR Conference on Research and Development in Information Retrieval, pages 65–74, 2017.
219
+
220
+ 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.
221
+
222
+ Nan Du, Yanping Huang, Andrew M Dai, Simon Tong, Dmitry Lepikhin, Yuanzhong Xu, Maxim Krikun, Yanqi Zhou, Adams Wei Yu, Orhan Firat, et al. Glam: Efficient scaling of language models with mixture-of-experts. arXiv preprint arXiv:2112.06905, 2021.
223
+
224
+ William Fedus, Barret Zoph, and Noam Shazeer. Switch transformers: Scaling to trillion parameter models with simple and efficient sparsity. arXiv preprint arXiv:2101.03961, 2021.
225
+
226
+ Tianyu Gao, Xingcheng Yao, and Danqi Chen. SimCSE: Simple contrastive learning of sentence embeddings. In Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing, pages 6894–6910, Online and Punta Cana, Dominican Republic, November 2021. Association for Computational Linguistics. doi: 10.18653/v1/2021.emnlp-main.552. URL https: //aclanthology.org/2021.emnlp-main.552.
227
+
228
+ Mor Geva, Roei Schuster, Jonathan Berant, and Omer Levy. Transformer feed-forward layers are key-value memories. arXiv preprint arXiv:2012.14913, 2020.
229
+
230
+ Daniel Gillick, Alessandro Presta, and Gaurav Singh Tomar. End-to-end retrieval in continuous space. arXiv preprint arXiv:1811.08008, 2018.
231
+
232
+ Ruiqi Guo, Philip Sun, Erik Lindgren, Quan Geng, David Simcha, Felix Chern, and Sanjiv Kumar. Accelerating large-scale inference with anisotropic vector quantization. In International Conference on Machine Learning, 2020. URL https://arxiv.org/abs/1908.10396.
233
+
234
+ Kelvin Guu, Kenton Lee, Zora Tung, and Panupong Pasupat. REALM: Retrieval-Augmented Language Model Pre-Training. In Proceedings of ICML 2020, 2020.
235
+
236
+ Martin Josifoski, Nicola De Cao, Maxime Peyrard, and Robert West. Genie: Generative information extraction. arXiv preprint arXiv:2112.08340, 2021.
237
+
238
+ Jared Kaplan, Sam McCandlish, Tom Henighan, Tom B Brown, Benjamin Chess, Rewon Child, Scott Gray, Alec Radford, Jeffrey Wu, and Dario Amodei. Scaling laws for neural language models. arXiv preprint arXiv:2001.08361, 2020.
239
+
240
+ Vladimir Karpukhin, Barlas Oguz, Sewon Min, Patrick Lewis, Ledell Wu, Sergey Edunov, Danqi ˘ Chen, and Wen-tau Yih. Dense passage retrieval for open-domain question answering. arXiv preprint arXiv:2004.04906, 2020.
241
+
242
+ Tom Kwiatkowski, Jennimaria Palomaki, Olivia Redfield, Michael Collins, Ankur Parikh, Chris Alberti, Danielle Epstein, Illia Polosukhin, Jacob Devlin Kenton Lee, Kristina Toutanova, Llion Jones Matthew Kelcey, Ming-Wei Chang, Andrew M Dai, Jakob Uszkoreit, Quoc Le, and Slav Petrov. Natural Questions: a Benchmark for Question Answering Research. In Transactions of the ACL, 2019.
243
+
244
+ Dmitry Lepikhin, HyoukJoong Lee, Yuanzhong Xu, Dehao Chen, Orhan Firat, Yanping Huang, Maxim Krikun, Noam Shazeer, and Zhifeng Chen. Gshard: Scaling giant models with conditional computation and automatic sharding. arXiv preprint arXiv:2006.16668, 2020.
245
+
246
+ Donald Metzler, Yi Tay, Dara Bahri, and Marc Najork. Rethinking search: making domain experts out of dilettantes. In ACM SIGIR Forum, volume 55, pages 1–27. ACM New York, NY, USA, 2021.
247
+
248
+ Jianmo Ni, Gustavo Hernández Ábrego, Noah Constant, Ji Ma, Keith B Hall, Daniel Cer, and Yinfei Yang. Sentence-t5: Scalable sentence encoders from pre-trained text-to-text models. arXiv preprint arXiv:2108.08877, 2021.
249
+
250
+ Fabio Petroni, Tim Rocktäschel, Patrick Lewis, Anton Bakhtin, Yuxiang Wu, Alexander H Miller, and Sebastian Riedel. Language models as knowledge bases? arXiv preprint arXiv:1909.01066, 2019.
251
+
252
+ Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, and Peter J Liu. Exploring the limits of transfer learning with a unified text-to-text transformer. arXiv preprint arXiv:1910.10683, 2019.
253
+
254
+ Hubert Ramsauer, Bernhard Schäfl, Johannes Lehner, Philipp Seidl, Michael Widrich, Thomas Adler, Lukas Gruber, Markus Holzleitner, Milena Pavlovic, Geir Kjetil Sandve, et al. Hopfield networks ´ is all you need. arXiv preprint arXiv:2008.02217, 2020.
255
+
256
+ Adam Roberts, Colin Raffel, and Noam Shazeer. How much knowledge can you pack into the parameters of a language model? arXiv preprint arXiv:2002.08910, 2020.
257
+
258
+ Yu Sun, Xiaolong Wang, Zhuang Liu, John Miller, Alexei Efros, and Moritz Hardt. Test-time training with self-supervision for generalization under distribution shifts. In Hal Daumé III and Aarti Singh, editors, Proceedings of the 37th International Conference on Machine Learning, volume 119 of Proceedings of Machine Learning Research, pages 9229–9248. PMLR, 13–18 Jul 2020. URL https://proceedings.mlr.press/v119/sun20b.html.
259
+
260
+ Ilya Sutskever, Oriol Vinyals, and Quoc V Le. Sequence to sequence learning with neural networks. arXiv preprint arXiv:1409.3215, 2014.
261
+
262
+ Yi Tay, Mostafa Dehghani, Jinfeng Rao, William Fedus, Samira Abnar, Hyung Won Chung, Sharan Narang, Dani Yogatama, Ashish Vaswani, and Donald Metzler. Scale efficiently: Insights from pre-training and fine-tuning transformers. arXiv preprint arXiv:2109.10686, 2021.
263
+
264
+ Romal Thoppilan, Daniel De Freitas, Jamie Hall, Noam Shazeer, Apoorv Kulshreshtha, Heng-Tze Cheng, Alicia Jin, Taylor Bos, Leslie Baker, Yu Du, et al. Lamda: Language models for dialog applications. arXiv preprint arXiv:2201.08239, 2022.
265
+
266
+ 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, pages 5998–6008, 2017.
267
+
268
+ # Checklist
269
+
270
+ 1. For all authors...
271
+
272
+ (a) Do the main claims made in the abstract and introduction accurately reflect the paper’s contributions and scope? [Yes]
273
+ (b) Did you describe the limitations of your work? [Yes] We highlight that this is a proofof-concept for a new paradigm, and not geared towards SOTA comparisons (Section 4). Clearly, many open problems still remain such as index updating, scaling to larger datasets, etc.
274
+ (c) Did you discuss any potential negative societal impacts of your work? [No] Our work effectively provides the same end functionality as existing information retrieval systems.
275
+ (d) Have you read the ethics review guidelines and ensured that your paper conforms to them? [Yes]
276
+
277
+ 2. If you are including theoretical results...
278
+
279
+ (a) Did you state the full set of assumptions of all theoretical results? [N/A] No theoretical results. (b) Did you include complete proofs of all theoretical results? [N/A] No theoretical results
280
+
281
+ 3. If you ran experiments...
282
+
283
+ (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] All experiments were ran using publicly available T5X codebase, with publicly available Natural Questions dataset. All necessary details were included to reproduce the experiments.
284
+ (b) Did you specify all the training details (e.g., data splits, hyperparameters, how they were chosen)? [Yes] See Section 4, under Implementation Details.
285
+ (c) Did you report error bars (e.g., with respect to the random seed after running experiments multiple times)? [No] As these experiments are expensive, experiments were not ran multiple times to save compute.
286
+ (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] Please see Section 4 under Implementation Details.
287
+
288
+ 4. If you are using existing assets (e.g., code, data, models) or curating/releasing new assets...
289
+
290
+ (a) If your work uses existing assets, did you cite the creators? [Yes]
291
+ (b) Did you mention the license of the assets? [No] We comply with the license of all code repositories and public datasets as detailed in the cited sources.
292
+ (c) Did you include any new assets either in the supplemental material or as a URL? [N/A] No new assets introduced at this time.
293
+ (d) Did you discuss whether and how consent was obtained from people whose data you’re using/curating? [N/A] We did not curate data.
294
+ (e) Did you discuss whether the data you are using/curating contains personally identifiable information or offensive content? [N/A] We did not curate data.
295
+
296
+ 5. If you used crowdsourcing or conducted research with human subjects...
297
+
298
+ (a) Did you include the full text of instructions given to participants and screenshots, if applicable? [N/A]
299
+ (b) Did you describe any potential participant risks, with links to Institutional Review Board (IRB) approvals, if applicable? [N/A]
300
+ (c) Did you include the estimated hourly wage paid to participants and the total amount spent on participant compensation? [N/A]
md/dev/gSyjaunurQ/gSyjaunurQ.md ADDED
@@ -0,0 +1,370 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # On Representation of Natural Image Patches
2
+
3
+ Anonymous Author(s)
4
+ Affiliation
5
+ Address
6
+ email
7
+
8
+ # Abstract
9
+
10
+ 1 To optimize survival, organisms need to accurately and efficiently relay new in
11
+ 2 formation throughout their systems for processing and responses. Furthermore,
12
+ 3 they benefit from predicting environmental occurrences, or in mathematical terms,
13
+ 4 understanding the probability distribution of their environment, based on both
14
+ 5 personal experiences and inherited evolutionary memory. These twin objectives
15
+ 6 of information transmission and learning environmental probabilistic distributions
16
+ 7 form the core of an organism’s information processing system. While the early
17
+ 8 vision neuroscience field has primarily focused on the former, employing infor
18
+ 9 mation theory as a guiding framework [3, 32, 19, 1, 9, 28], the latter is largely
19
+ 10 explored by the machine learning community via probabilistic generative models.
20
+ 11 However, the relationship between these two objectives has not been thoroughly
21
+ 12 investigated. In this paper, we study a biologically inspired information processing
22
+ 13 model and prove that these two objectives can be achieved independently. By
23
+ 14 evenly partitioning the input space to model input probability, our model bypasses
24
+ 15 the often intractable normalization factor computation. When applied to image
25
+ 16 patches, this model produces a sparse, nonlinear binary population code similar
26
+ 17 to early visual systems, with features like edge-detection and orientation-selective
27
+ 18 units. Our results not only offer potential new insights into the functioning of
28
+ 19 neurons in early vision systems, but also present a novel approach to represent
29
+ 20 natural image patches.
30
+
31
+ # 21 1 Introduction
32
+
33
+ 22 Nature, through billions of years of evolution, has likely developed optimal methods for processing
34
+ 23 visual information within the constraints of biological feasibility. However, attempting to precisely
35
+ 24 emulate every detail of these biological systems [30, 21] in order to construct an optimal visual
36
+ 25 information processing model presents significant complexities, especially without a comprehensive
37
+ 26 understanding of the underlying principles.
38
+ 27 In parallel, deep learning models, particularly Convolutional Neural Networks (CNNs), have demon
39
+ 28 strated exceptional performance in various computer vision tasks, such as image classification, object
40
+ 29 detection, and semantic segmentation. Despite their success, these models still fall short of biological
41
+ 30 vision systems in several key areas such as the ability to generalize from limited data, robustness to
42
+ 31 variations, 3D understanding, and processing speed and efficiency.
43
+ 32 Moreover, deep learning models pose several unresolved challenges. Firstly, their decision-making
44
+ 33 processes are often opaque, leading to the "black box" label. Secondly, deep learning architectures
45
+ 34 typically involve numerous layers without explicit functions associated with each layer [12, 8], unlike
46
+ 35 the biological brain where each stage of visual processing has a distinct role and purpose [7]. Lastly,he
47
+ 36 sequence of information processing in deep learning models is largely dictated by their architectural
48
+ 37 structure. It is still a question how to ascertain when one processing stage is finished and when it’s
49
+ 38 appropriate to pass information to the next layer.
50
+ 39 Drawing inspiration from biological systems and prior studies [19, 1, 9, 28], and with a view to
51
+ 40 find an alternative approach to the current deep learning framework, this paper aims to explore the
52
+ 41 fundamentals of the first stage of an optimal visual information processing system. This exploration is
53
+ 42 undertaken incrementally, starting from a single pixel, and progressively advancing to image patches.
54
+
55
+ # 43 2 One Pixel
56
+
57
+ 44 We begin with the simplest conceivable case, where the input to the model consists of a single pixel
58
+ 45 with one color channel. Although seemingly trivial, this model can represent various biological units.
59
+ 46 For example, it could model the eyespot of single-celled organisms like Euglena, the large monopolar
60
+ 47 cells found in an insect’s compound eye or the bipolar cells in the retina. The single pixel case has
61
+ 48 been studied [14, 1]. We aim to review it to introduce the central concepts and the main theory, which
62
+ 49 will also be applicable to more complex scenarios.
63
+ 50 Let us denote the light intensity of the pixel as $x$ , and let $p ( x )$ represent its probability distribution.
64
+ 51 We define an information processing unit (IPU) as a model that receives inputs and passes processed
65
+ 52 information to subsequent stages. As the first stage in an organism’s information processing system,
66
+ 53 the single pixel IPU carries the same dual objectives as later stages: transmitting information and
67
+ 54 learning environmental probabilistic distributions. Therefore, the two objectives for the single pixel
68
+ 55 IPU are to transmit information about $x$ efficiently through its output and to learn $p ( x )$ .
69
+ 56 Information is quantified by Shannon entropy. To compute the Shannon entropy of the input, we
70
+ 57 assume $x$ is a discrete variable with $M$ states, after all light intensity is quantized according to quantum
71
+ 58 mechanics, although $M$ could be a very large number, making $x$ practically indistinguishable from a
72
+ 59 continuous variable. The information obtained from the pixel when we know the intensity is $x$ can be
73
+ 60 represented as $I ( x ) = - \log p ( x )$ . The average information a state of the pixel contains, the Shannon
74
+ 61 entropy, is given by:
75
+
76
+ $$
77
+ H _ { p } = - \sum _ { i = 1 } ^ { M } p ( x _ { i } ) \log p ( x _ { i } ) .
78
+ $$
79
+
80
+ 62 The IPU transforms the input $x$ into the output $y = f ( x )$ , where the output space comprises $N$
81
+ 63 distinct states. In contrast to previous studies that assumed one-to-one mapping between input and
82
+ 64 output, here we posit that $N \ll M$ . This assumption is more congruent with biological constraints;
83
+ 65 for instance, the luminance resolution levels at synapse terminals in a zebrafish’s retina are only about
84
+ 66 10 [25]. Moreover, this assures that after processing the information is significantly reduced, thereby
85
+ 67 simplifying the tasks for subsequent stages.
86
+ 68 The function $f ( x )$ assigns $x$ into $N$ groups, each corresponding to a fixed $y$ . We denote all $x$ values
87
+ 69 in group $j$ as $G _ { j }$ , and the size of this group as $n _ { j }$ . The entropy of the output is given by
88
+
89
+ $$
90
+ H _ { Q } = - \sum _ { j = 1 } ^ { N } Q ( y _ { j } ) \log Q ( y _ { j } ) ,
91
+ $$
92
+
93
+ 70 where $Q ( y )$ represents the probability distribution of the output states.
94
+
95
+ 71 Previous research [14, 1] has primarily emphasized the first objective of an IPU, which is maximizing
96
+ 72 the rate of transmission [19]. This goal is particularly relevant for early-stage IPUs, where the
97
+ 73 distinction between signal and noise is not yet clear. Maximizing the rate of transmission is equivalent
98
+ 74 to maximizing $H _ { Q }$ (see proof in Appendix A), leading to a constant $Q ( y )$ . Biological neurons have
99
+ 75 been observed to follow this coding scheme [14].
100
+ 76 Simultaneously, an IPU should also strive to fullfil the second objective and model $p ( x )$ as accurately
101
+ 77 as possible. Mathematically, this involves minimizing the Kullback–Leibler divergence between
102
+ 78 $p ( x )$ and the distribution learned by the IPU. This raises an interesting question: Are these two
103
+ 79 optimization objectives contradictory, or do they essentially represent the same task?
104
+
105
+ # 3 Even Code Principle
106
+
107
+ To determine how an IPU models $p ( x )$ we need to translate the output probability distribution $Q ( y )$ into the input space as $q ( x ) . q ( x )$ is a step function:
108
+
109
+ $$
110
+ q ( x ) = q _ { j } , { \mathrm { ~ f o r ~ } } x \in G _ { j } ,
111
+ $$
112
+
113
+ 83 and we have the following relations:
114
+
115
+ $$
116
+ Q ( y _ { j } ) = \sum _ { x \in G _ { j } } p ( x ) = \sum _ { x \in G _ { j } } q ( x ) = n _ { j } q _ { j } .
117
+ $$
118
+
119
+ 84 Minimizing the difference between $p ( x )$ and $q ( x )$ can be achieved by minimizing their Kull
120
+ 85 back–Leibler divergence:
121
+
122
+ $$
123
+ \begin{array} { r l r } { D _ { K L } ( p | | q ) } & { { } = } & { H _ { p q } - H _ { p } , } \end{array}
124
+ $$
125
+
126
+ where $H _ { p q }$ is the cross entropy. It can be proved that the cross entropy $H _ { p q }$ is equal to the entropy of the learned distribution in the input space defined as (see proof in Appendix B):
127
+
128
+ $$
129
+ H _ { q } = - \sum _ { x } q ( x ) \log q ( x ) ,
130
+ $$
131
+
132
+ 88 and we get
133
+
134
+ $$
135
+ \begin{array} { r } { D _ { K L } ( p | | q ) = H _ { q } - H _ { p } . } \end{array}
136
+ $$
137
+
138
+ 89 Since $H _ { p }$ is fixed, minimizing the KL divergence requires minimizing $H _ { q }$ . The previous question now
139
+ 90 transforms into understanding the relationship between maximizing the entropy of the distribution in
140
+ 91 the output space $( H _ { Q } )$ and minimizing the entropy of the learned distribution in the input space $( H _ { q } )$ .
141
+ 92 Suppose we have two adjacent zones in the transformed space where the corresponding $Q ( y _ { 1 } )$ and
142
+ 93 $Q ( y _ { 2 } )$ are not equal, let’s assume $Q ( y _ { 1 } ) > Q ( y _ { 2 } )$ . One can reduce the inequality by shifting the
143
+ 94 boundary between these two zones and moving one $\mathbf { X }$ value from $G _ { 1 }$ to $G _ { 2 }$ . This shift corresponds
144
+ 95 to a small change of probability, $\delta$ , for both zones. Note that $\delta$ is comparable to $q _ { 1 }$ and $q _ { 2 }$ , as we
145
+ 96 assume the distribution is smooth. We know that reducing the inequality of $Q ( y _ { 1 } )$ and $Q ( y _ { 2 } )$ always
146
+ 97 increases $H _ { Q }$ . If the two optimization problems are the same, then $H _ { q }$ should increase; if they are
147
+ 98 contradictory, $H _ { q }$ should decrease. The change of $H _ { q }$ can be calculated as:
148
+
149
+ $$
150
+ \begin{array} { r l } & { \Delta H _ { q } = - [ Q ( y _ { 1 } ) - \delta ] \log \frac { Q ( y _ { 1 } ) - \delta } { n _ { 1 } - 1 } - [ Q ( y _ { 2 } ) + \delta ] \log \frac { Q ( y _ { 2 } ) + \delta } { n _ { 2 } + 1 } } \\ & { \phantom { { \Delta } } + Q ( y _ { 1 } ) \log \frac { Q ( y _ { 1 } ) } { n _ { 1 } } + Q ( y _ { 2 } ) \log \frac { Q ( y _ { 2 } ) } { n _ { 2 } } } \\ & { \phantom { { \Delta } } = q _ { 2 } - q _ { 1 } + \delta ( \log q _ { 1 } - \log q _ { 2 } + \frac { 1 } { n _ { 1 } } + \frac { 1 } { n _ { 2 } } ) + O ( \delta ^ { 2 } ) + O ( \frac { 1 } { n _ { 1 } ^ { 2 } } ) + O ( \frac { 1 } { n _ { 2 } ^ { 2 } } ) } \\ & { \approx q _ { 2 } - q _ { 1 } + \delta \log \frac { q _ { 1 } } { q _ { 2 } } . } \end{array}
151
+ $$
152
+
153
+ 99 The change can either be positive or negative depending on $q _ { 1 }$ and $q _ { 2 }$ . Since minimizing $H _ { q }$ and
154
+ 100 maximizing $H _ { Q }$ are not contradictory, these objectives can be tackled independently. Given a fixed
155
+ 101 number of output levels $N$ , we first maximize $H _ { Q }$ to retain as much input information as possible. If
156
+ 102 further refinement of $p ( x )$ modeling is required, we can increase the output resolution $N$ .
157
+ 103 The aforementioned reasoning extends naturally to multivariate scenarios, as no assumptions about
158
+ 104 one-dimensionality of the input were made. We articulate the goal of a general information processing
159
+ 105 unit as follows: An information processing unit (IPU) transforms input space with $M$ states into
160
+ 106 output space with $N$ states, where $N \ll M$ . Given a smooth input probability distribution as
161
+ 107 $M \to \infty$ and a piecewise smooth transformation function, the sole goal of an IPU with a fixed output
162
+ 108 resolution $N$ is to yield an even output probability distribution, hence retaining maximum information
163
+ 109 from the input. To attain better modeling precision, the output resolution $N$ of the IPU should be
164
+ 110 increased. This will be referred to as the principle of even code. In the next sections, we will apply
165
+ 111 the even code principle to more complex inputs.
166
+ 113 For two pixels $( x _ { 1 } , x _ { 2 } )$ , we can either use one IPU directly to model $p ( x _ { 1 } , x _ { 2 } )$ or use two IPUs to
167
+ 114 model $p ( x _ { 1 } )$ and $p ( x _ { 2 } )$ separately, followed by another IPU to model the outputs $p ( y _ { 1 } , y _ { 2 } )$ . We will
168
+ 115 use the second approach, as processing as much information locally reduces the cost of information
169
+ 116 transfer. In fact, when images are stored on computers, gamma encoding is utilized to create an
170
+ 117 approximately even distribution of pixel values. When these images are displayed, pixel values
171
+ 118 undergo gamma correction to recover the original statistics for human eyes to process. In the
172
+ 119 following sections, we will assume that all pixel values $x$ have already been processed by dedicated
173
+ 120 IPUs, resulting in a roughly even probability distribution.
174
+ 121 The probability distribution $p ( x _ { 1 } , x _ { 2 } )$ of natural images is relatively simple. The majority of the
175
+ 122 probability is concentrated around the diagonal line $x _ { 1 } - x _ { 2 } = 0$ , with $p ( x _ { 1 } , x _ { 2 } )$ rapidly decaying
176
+ 123 as $| x _ { 1 } - x _ { 2 } |$ increases (see Fig. 1 (a) for example). Intuitively, we can use lines parallel or/and
177
+ 124 perpendicular to $x _ { 1 } - x _ { 2 } = 0$ to divide the probability distribution into even partitions.
178
+
179
+ # 125 4.1 One Basis
180
+
181
+ 126 To investigate how IPUs learn $p ( x _ { 1 } , x _ { 2 } )$ , we conduct numerical experiments using a multilayer
182
+ 127 perceptron (MLP) as the IPU to approximate $y \ = \ f ( x )$ and model $p ( x )$ [23]. Other function
183
+ 128 approximation methods may also be applicable. To partition the input probability distribution with
184
+ 129 one set of parallel lines, only one IPU with $N$ output nodes is needed. According to the even code
185
+ 130 principle, for each input, only one of the $N$ output nodes should be activated, and the probability
186
+ 131 of activating any one of the $N$ output nodes should be equal. We use the softmax function as the
187
+ 132 last layer of the MLP to ensure each output value is within [0, 1], and that if a node is activated
188
+ 133 (output value equals 1), it is the only node being activated. We use stochastic gradient descent and
189
+ 134 the following loss function to train the MLP:
190
+
191
+ $$
192
+ E = \sum _ { i } \langle y _ { s i } \rangle _ { s } \log \langle y _ { s i } \rangle _ { s } + k \langle - \sum _ { i } y _ { s i } \log y _ { s i } \rangle _ { s } .
193
+ $$
194
+
195
+ 135 $y _ { s i }$ represents the value of the i-th output node for the s-th input sample, while $\langle \rangle _ { s }$ denotes the average
196
+ 136 over all samples in a training batch. The first term in the loss function ensures each output node has
197
+ 137 an equal chance to be activated on average. The second term promotes activation of only one node
198
+ 138 per input while suppressing the remaining nodes, mimicking lateral inhibition when combined with
199
+ 139 the softmax function. The factor $k$ balances the two terms to achieve the desired result. Fig. 1 (a)
200
+ 140 show the results learned by MLPs with 16 output nodes.
201
+
202
+ # 141 4.2 Multiple Bases
203
+
204
+ 142 To partition the input space with two sets of orthogonal lines we need two MLPs. The orthogonality
205
+ 143 is achieved by enforcing
206
+
207
+ $$
208
+ Q ( y _ { 1 } , y _ { 2 } ) = \frac { 1 } { N _ { 1 } N _ { 2 } } ,
209
+ $$
210
+
211
+ 144 where $N _ { 1 }$ and $N _ { 2 }$ represent the number of output nodes of the two MLPs (refer Appendix $\textrm { C }$ for
212
+ 145 proof). If more than two orthogonal bases are required for partitioning the space, we can enforce
213
+ 146 Eq. (12) for each combination of two bases to ensure orthogonality between them. The loss function
214
+ 147 for multiple orthogonal bases with independent states is
215
+
216
+ $$
217
+ E = \frac { 1 } { { \binom { B } { 2 } } } \sum _ { < b , b ^ { \prime } > } \sum _ { i j } \langle y _ { b s i } y _ { b ^ { \prime } s j } \rangle _ { s } \log \langle y _ { b s i } y _ { b ^ { \prime } s j } \rangle _ { s } + \frac { k } { B } \langle - \sum _ { b = 1 } ^ { B } \sum _ { i } y _ { b s i } \log y _ { b s i } \rangle _ { s } ,
218
+ $$
219
+
220
+ where 148 $b$ is the base index, and $B$ is the number of bases. $\sum _ { < b , b ^ { \prime } > }$ denotes the sum over all $\binom { B } { 2 }$ 149 combinations of two distinct bases. $y _ { b s i } y _ { b ^ { \prime } s j }$ is the probability $\dot { Q } ( y _ { b } , y _ { b ^ { \prime } } )$ for the sample s when $y _ { b }$ and 150 $y _ { b ^ { \prime } }$ take their i-th and j-th value respectively.
221
+
222
+ 151 Fig. 1 (b) shows an example of two-pixel input space partitioning using two orthogonal bases. For a
223
+ 152 more detailed discussion on the experiments and additional results, refer to Appendix D.
224
+ 153 Additionally, it’s worth noting that orthogonal bases with independent states might model grid cells
225
+ 154 [11] in the entorhinal cortex, though this topic is beyond the scope of the current paper.
226
+
227
+ ![](images/ab857880a76eec53ea4ad351f2d919139f3edd883cb288f3607ac9d42cc0c6fc.jpg)
228
+ Figure 1: Evenly partitioning the two-pixel probability distribution learned by multilayer perceptrons (MLPs). The $\mathrm { X }$ and $\mathrm { Y }$ axes represent the rescaled intensities $x _ { 1 }$ and $x _ { 2 }$ of the two pixels in the range [0, 1]. The quantity $n ( x _ { 1 } , x _ { 2 } ) + 1$ is plotted in gray on a log scale, where $n ( x _ { 1 } , x _ { 2 } )$ denotes the number of occurrences of the two-pixel values among the sampled data. Color lines indicate the boundaries of states for each basis learned by an MLP, with one color representing one basis. (a) One basis with 16 independent states, which partitions the space based on the total intensity $x _ { 1 } + x _ { 2 }$ . (b) Two orthogonal bases, each with 10 independent states, dividing the space based on the total intensity $x _ { 1 } + x _ { 2 }$ and the contrast $x _ { 1 } - x _ { 2 }$ approximately.
229
+
230
+ # 155 5 Image Patches
231
+
232
+ 156 Next we move on to study gray and color image patches. We use $\mathbf { X }$ to represent the vector of input
233
+ 157 pixel values of the image patch. The multivariate input probability distribution $p ( \mathbf { x } )$ is considerably
234
+ 158 more complex compared to the previous examples. If we use only one basis to discretize the input
235
+ 159 probability space (e.g. Fig. 1 (a) in Appendix D), the required number of independent states for a good
236
+ 160 approximation would be very large, making the evaluation of the softmax function computationally
237
+ 161 expensive. On the other hand, using multiple orthogonal bases would also significantly increase the
238
+ 162 computational cost to ensure orthogonality if the number of bases is more than just a few. Additionally,
239
+ 163 determining the optimal number of bases and the number of independent states for each basis are
240
+ 164 challenging.
241
+ 165 Aside from the computational cost, another issue arises when working with image patches: we want
242
+ 166 the representation to capture the similarity between inputs. However, using orthogonal bases with
243
+ 167 independent states makes it difficult to gauge input similarity through methods such as calculating
244
+ 168 the difference between representations, even if we can establish an order for the states of each basis.
245
+ 169 Therefore, we need a more suitable coding scheme for complex inputs like image patches.
246
+ 170 Real-valued vectors are a natural choice, given their extensive use in representing a variety of entities
247
+ 171 such as images, texts, and categorical variables [13, 22, 10]. The norm of the difference between
248
+ 172 two vectors can function as a measure of similarity. Nevertheless, if we want the representation $\mathbf { y }$ to
249
+ 173 mirror input similarity, each value of $\mathbf { y }$ should encapsulate all samples perceived as identical within
250
+ 174 the same group $G$ . Under this constraint, $Q ( \mathbf { y } )$ cannot remain constant, thereby conflicting with the
251
+ 175 even code principle.
252
+ 176 The resolution to this conflict involves permitting the representation to mirror input similarity at the
253
+ 177 most granular level, while enforcing the even code principle at a larger scale in the transformed space.
254
+ 178 We will detail this method in subsequent sections.
255
+
256
+ # 5.1 Loss Function
257
+
258
+ 180 To promote even distribution, we incorporate a loss function that compels input samples to repel each
259
+ 181 other in the transformed space. This repulsive force diminishes with increasing distance, as described
260
+ 182 by the following equation:
261
+
262
+ $$
263
+ E = \langle - \ln | { \bf y } _ { s } - { \bf y } _ { s ^ { \prime } } | \rangle _ { < s , s ^ { \prime } > } .
264
+ $$
265
+
266
+ 183 Here, $- \ln | \mathbf { y } _ { s } - \mathbf { y } _ { s ^ { \prime } } |$ represents the potential energy due to the repulsive force, which is proportional
267
+ 184 to the inverse of the Minkowski distance between the representations of samples $s$ and $s ^ { \prime }$ in the
268
+ 185 transformed space. Alternative forms of potential energy and distance measures could also be
269
+ 186 applicable. $\langle \rangle _ { < s , s ^ { \prime } > }$ denotes the average over all sample pairs.
270
+ 187 Should numerous samples converge at one point in the transformed space, they will exert a strong
271
+ 188 repulsive force in the surrounding area, thereby discouraging other samples from occupying nearby
272
+ 189 positions. To prevent samples from pushing each other infinitely far apart, we restrict the represen
273
+ 190 tation values to be within the range $[ 0 , 1 ]$ . With this constraint, the repulsive force pushes samples
274
+ 191 towards the vertices of the unit hypercube, effectively reducing the representations from real vectors
275
+ 192 to binary vectors. As a result, an even distribution is achieved on a larger scale in the transformed
276
+ 193 space, which consists solely of the vertices.
277
+ 194 In the context of binary vectors, the collection of output nodes can be viewed as a vocabulary,
278
+ 195 and activated nodes by an input image patch act as its representative tokens. Unlike fixed-length
279
+ 196 representations with real-valued vectors, binary representations can employ fewer tokens for more
280
+ 197 common image patches (e.g., homogeneous patches), and more tokens for less common, structurally
281
+ 198 rich patches. This can be accomplished by introducing a second term, $\langle | \mathbf { y } _ { s } | \rangle _ { s }$ , to the loss function,
282
+ 199 which echoes the sparsity regularization term found in various studies [9, 16, 26, 27, 29, 4]. The
283
+ 200 updated loss function becames:
284
+
285
+ $$
286
+ E = \langle - \ln | { \bf y } _ { s } - { \bf y } _ { s ^ { \prime } } | \rangle _ { < s , s ^ { \prime } > } + \alpha \langle | { \bf y } _ { s } | \rangle _ { s } ,
287
+ $$
288
+
289
+ 01 where $\alpha$ is a free parameter to adjust sparsity.
290
+
291
+ In practice, we add a small value $\epsilon = 1 0 ^ { - 3 8 }$ to the distance, allowing slightly different samples to share the same representation and enhancing numerical stability. Another approach to improve numerical stability involves using a theoretically equivalent form of the loss function, which instead of allowing samples to repel each other in the output space, we enable nodes to repel one another, encouraging output nodes to be as independent as possible [24].
292
+
293
+ # 5.2 Experiments
294
+
295
+ In the following experiments, we use either a single MLP with N outputs, or N MLPs each with one output, as the IPU to approximate the transformation function $\mathbf { y } = f ( \mathbf { x } )$ and model $p ( \mathbf { x } )$ . The last layer of the MLP is a sigmoid layer, ensuring the output value ranges between 0 and 1. Our training data comprises random image patches extracted from the COCO 2017 image dataset [18] or the ImageNet dataset [6]. No image preprocessing is used. Additional training details are provided in Appendix E.
296
+
297
+ # 5.2.1 Output Statistics
298
+
299
+ First, we examine the statistics of the learned representation. Across all experiments, we observe qualitatively similar output statistics, irrespective of the IPU architectures and training specifics, provided the training has properly converged. For illustration, we present an example using a model trained on $5 \times 5$ color image patches. It uses 96 MLPs, each with one output node and a middle layer of 48 nodes, as the IPU. Following training, the model is used to generate representations for 1 million random image patches for this analysis.
300
+
301
+ ![](images/b42cd2b03ce5ad495e9a40ede0f9738dc6e05817875708a3e6019ddb0625f8e3.jpg)
302
+ Figure 2: Statistical analysis of the learned representation using the loss function Eq. (15). (a) Histogram of the model’s output values on a log scale. (b) Probability of an output node being activated by a random image patch.
303
+
304
+ Fig. 2 (a) presents the histogram of output values on a logarithmic scale. The vast majority of output values are either at 0 or 1. As such during inference, we can round the outputs to yield a binary representation. Fig. 2 (b) illustrates the probability of an output node being activated by a random image patch. All nodes demonstrate similar activation probabilities, indicating an even distribution at this coarse scale. Further statistical analysis of the output representation is available in Appendix F.
305
+
306
+ # 5.2.2 Image Patch Similarity
307
+
308
+ Next, to examine how the learned representation reflects the similarity between image patches, we display 16 random image patches, each followed by 9 image patches similar to them in the binary representation space, as shown in Fig. 3 (a). The same $5 \times 5$ color image patch model is used. The learned representation clearly captures perceptual similarity. The results shown in Fig. 2, Fig. 3 (a), and additional results in Appendix E confirm that with the loss function Eq. (15), we can indeed learn a sparse binary representation which reflects the image similarity while adhering to the even code principle.
309
+
310
+ For comparison with a traditional convolutional neural network, we present the results generated with the first 10 layers of a VGG16 model [31] pre-trained on ImageNet in Fig. 3 (b). The image patch representation from the first 10 layers of the VGG16 model is a float vector of size 128. The even code model, with only 96 binary outputs, achieves results similar to the VGG16 model. These 96 binary outputs occupy the same storage space as a float vector of length 3 — just 1/42 of the VGG16 representation’s size, which underscores the exceptional efficiency of the even code method in image patch representation.
311
+
312
+ # 5.2.3 Local Edge Detectors and Orientation-Selective Units
313
+
314
+ Biological visual systems’ initial stages are known to possess local edge detectors and orientationselective units [17, 2]. While CNNs have been successfully trained to detect boundaries via supervised learning [20], their initial layers have not shown proficiency in edge detection [15]. Notably, prevalent local edge detection algorithms, such as the Canny edge detector [5], still primarily rely on non-deep learning methods.
315
+
316
+ Does the even code model, proposed as the initial stage of an optimal image processing system, resemble biological systems more closely? To answer this, we trained an even code model on $4 \times 4$ grayscale image patches and applied it to images with a stride of 1 pixel, generating feature maps for each output node. The model comprises a MLP with 64 outputs and an intermediary layer with 100 nodes. Fig. 4 illustrates the feature maps of 4 output nodes of the even code model for 4 different input images. It also shows edges generated by the Canny edge detector as comparison. Interestingly,
317
+
318
+ ![](images/931e73c08a58814a6b0205e5356f6e7bd359a8d8356b1de0db7e5fde7ae85222.jpg)
319
+ Figure 3: Image patches with the shortest distance in the representation space to 16 randomly selected image patches. The first column presents the 16 random image patches, while the succeeding nine columns display patches that are closest to the first-column patches in the same row. (a) Distances are computed using using an even code model with 96 binary outputs. (b) Distances are computed using the first 10 layers of a pretrained VGG16 model with 128 real outputs.
320
+
321
+ 253 with this simple network architecture, the even code model demonstrated a remarkable capability in
322
+ 254 edge detection, rivaling the multi-stage Canny edge detector.
323
+ 255 Furthermore, Fig. 5 shows the feature maps of 5 output nodes for a sample bike image. Spokes of
324
+ 256 different orientations activate different nodes, indicating that these output nodes of the even code
325
+ 257 model have varying orientation preferences, similar to orientation-selective units found in bilogical
326
+ 258 systems.
327
+
328
+ # 259 6 Conclusion
329
+
330
+ 260 In summary, this paper demonstrates that maximizing the information-carrying capacity of output
331
+ 261 channels and modeling the input probability distribution are not mutually exclusive objectives and
332
+ 262 can be pursued independently. Given a specific output resolution, the sole goal of an information
333
+ 263 processing unit is to preserve as much information from the input as possible by ensuring an even
334
+ 264 distribution of samples in the output space. We applied the even code principle to study the probability
335
+ 265 distributions of two-pixel systems and image patches. For the two-pixel system, we learned orthogonal
336
+ 266 bases with independent states to model its probability distribution. For image patches, the even code
337
+ 267 approach naturally led to a nonlinear sparse binary representation. The even code model also shares
338
+ 268 additional similarities with early visual systems, such as the presence of local edge-detecting and
339
+ 269 orientation-selective units. These similarities suggest that the even code model could potentially
340
+ 270 serve as a new representation for neurons in early visual systems.
341
+ 271 There are several intriguing directions for future research. First, the even code model has been
342
+ 272 applied to inputs ranging from as simple as one pixel to more complex color image patches. Can we
343
+ 273 extend its application beyond the early stage of visual information processing? Second, the even code
344
+ 274 model could be extended to videos by incorporating an additional time dimension alongside color,
345
+ 275 width, and height dimensions. Investigating time-varying inputs, which produce spike train-like
346
+ 276 outputs, and conducting an in-depth comparison with early visual systems would be very interesting.
347
+ 277 Third, the even code model can also be extended to binocular vision data by adding another input
348
+ 278 dimension of size two. Whether the model with binocular and/or video data can construct a 3D
349
+ 279 model of the world based on data of two spatial dimensions is an intriguing question. Fourth, while
350
+ 280 this paper focuses on visual information, the even code model is a general method that could be
351
+ 281 applied to model other multivariate probability distributions as well. Lastly, on the application
352
+ 282 side, the even code model has potential in various areas, including local edge detection, image and
353
+ 283 video compression/denoising/retrieval, texture classification, and multispectral/hyperspectral image
354
+ 284 processing.
355
+
356
+ ![](images/a73e225e1bafe3356b5f4ebdbb6969aa3375dc7f7993612db801f8b7c128ce95.jpg)
357
+ Figure 4: Feature maps of nodes resembling local edge detectors. The first column presents four grayscale test images. Each subsequent column, except the last one, displays the feature maps corresponding to the same output node for the four test images. The last column shows edges generated by the multi-stage Canny edge detector for comparison.
358
+
359
+ ![](images/71f38a7fbcde53938cf624e09dc1e83d6c75eb50dc26202c1ce597a81a82948f.jpg)
360
+ Figure 5: Feature maps of five orientation-selective nodes applied to a test image. Spokes in different orientations activate distinct nodes, illustrating the orientation-selectivity of these nodes.
361
+
362
+ # References
363
+
364
+ [1] Joseph J. Atick. Could information theory provide an ecological theory of sensory processing? Network: Computation in neural systems, 3(2):213–251, 1992.
365
+
366
+ [2] Tom Baden, Philipp Berens, Katrin Franke, Miroslav Román Rosón, Matthias Bethge, and Thomas Euler. The functional diversity of retinal ganglion cells in the mouse. Nature, 529(7586):345–350, 2016.
367
+
368
+ [3] Horace B Barlow et al. Possible principles underlying the transformation of sensory messages. Sensory communication, 1(01):217–233, 1961. [4] Michael Beyeler, Emily L. Rounds, Kristofor D. Carlson, Nikil Dutt, and Jeffrey L. Krichmar. Neural correlates of sparse coding and dimensionality reduction. PLOS Computational Biology, 15(6):e1006908, jun 2019. [5] John Canny. A computational approach to edge detection. IEEE Transactions on pattern analysis and machine intelligence, (6):679–698, 1986. [6] Jia Deng, Wei Dong, Richard Socher, Li-Jia Li, Kai Li, and Li Fei-Fei. Imagenet: A largescale hierarchical image database. In 2009 IEEE conference on computer vision and pattern recognition, pages 248–255. Ieee, 2009. [7] James J DiCarlo, Davide Zoccolan, and Nicole C Rust. How does the brain solve visual object recognition? Neuron, 73(3):415–434, 2012. [8] Alexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn, Xiaohua Zhai, Thomas Unterthiner, Mostafa Dehghani, Matthias Minderer, Georg Heigold, Sylvain Gelly, et al. An image is worth 16x16 words: Transformers for image recognition at scale. arXiv preprint arXiv:2010.11929, 2020. [9] David J. Field. What Is the Goal of Sensory Coding? Neural Computation, 6(4):559–601, jul 1994. 309 [10] Cheng Guo and Felix Berkhahn. Entity embeddings of categorical variables. arXiv preprint arXiv:1604.06737, 2016. 311 [11] Torkel Hafting, Marianne Fyhn, Sturla Molden, May Britt Moser, and Edvard I. Moser. Microstructure of a spatial map in the entorhinal cortex. Nature 2005 436:7052, 436(7052):801– 806, jun 2005. 314 [12] Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Deep residual learning for image recognition. arxiv 2015. arXiv preprint arXiv:1512.03385, 14, 2015. 316 [13] G. E. Hinton and R. R. Salakhutdinov. Reducing the Dimensionality of Data with Neural Networks. Science, 313(5786):504–507, 2006. 318 [14] Simon Laughlin. A Simple Coding Procedure Enhances a Neuron’s Information Capacity. Zeitschrift für Naturforschung C, 36(9-10):910–912, oct 1981. 320 [15] Minh Le and Subhradeep Kayal. Revisiting edge detection in convolutional neural networks. In 2021 International Joint Conference on Neural Networks (IJCNN), pages 1–9. IEEE, 2021. 322 [16] Ann B Lee, Kim S Pedersen, and David Mumford. The Nonlinear Statistics of High-Contrast Patches in Natural Images. International Journal of Computer Vision, 54(5413):83–103, 2003. 324 [17] William R Levick. Receptive fields and trigger features of ganglion cells in the visual streak of the rabbit’s retina. The Journal of physiology, 188(3):285, 1967. 326 [18] Tsung-Yi Lin, Michael Maire, Serge Belongie, Lubomir Bourdev, Ross Girshick, James Hays, Pietro Perona, Deva Ramanan, C. Lawrence Zitnick, and Piotr Dollár. Microsoft coco: Common objects in context, 2014. 329 [19] Ralph Linsker. Self-organization in a perceptual network. Computer, 21(3):105–117, 1988. 330 [20] David R Martin, Charless C Fowlkes, and Jitendra Malik. Learning to detect natural image boundaries using local brightness, color, and texture cues. IEEE transactions on pattern analysis and machine intelligence, 26(5):530–549, 2004. 333 [21] Richard H. Masland. The Neuronal Organization of the Retina, oct 2012.
369
+
370
+ [22] Tomas Mikolov, Kai Chen, Greg Corrado, and Jeffrey Dean. Efficient estimation of word representations in vector space. arXiv preprint arXiv:1301.3781, 2013. [23] Guido Montúfar, Razvan Pascanu, Kyunghyun Cho, and Yoshua Bengio. On the Number of Linear Regions of Deep Neural Networks. Advances in Neural Information Processing Systems, 4(January):2924–2932, feb 2014. [24] Jean Pierre Nadal and Nestor Parga. Nonlinear neurons in the low-noise limit: a factorial code maximizes information transfer. http://dx.doi.org/10.1088/0954-898X_5_4_008, 5(4):565–581, 2009. [25] Benjamin Odermatt, Anton Nikolaev, and Leon Lagnado. Encoding of Luminance and Contrast by Linear and Nonlinear Synapses in the Retina. Neuron, 73:758–773, 2012. [26] Bruno A Olshausen. sparse codes and spikes. Probabilistic models of the brain, page 257, 2002. [27] Bruno A Olshausen and David J Field. Sparse coding of sensory inputs. Current opinion in neurobiology, 14(4):481–487, 2004. [28] Bruno A. Olshausen and David J. Field. Emergence of simple-cell receptive field properties by learning a sparse code for natural images. Nature, oct 2015. [29] Marc’Aurelio Ranzato, Christopher Poultney, Sumit Chopra, and Yann Cun. Efficient learning of sparse representations with an energy-based model. Advances in neural information processing systems, 19, 2006. [30] Joshua R. Sanes and S. Lawrence Zipursky. Design Principles of Insect and Vertebrate Visual Systems, 2010. [31] Karen Simonyan and Andrew Zisserman. Very deep convolutional networks for large-scale image recognition. arXiv preprint arXiv:1409.1556, 2014. 6 [32] JH van Hateren. A theory of maximizing sensory information. Biol. Cybern, 68:23–29, 1992.
md/dev/jDIlzSU8wJ/jDIlzSU8wJ.md ADDED
@@ -0,0 +1,463 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # The Surprising Effectiveness of Diffusion Models for Optical Flow and Monocular Depth Estimation
2
+
3
+ Saurabh Saxena, Charles Herrmann, Junhwa Hur, Abhishek Kar, Mohammad Norouzi, Deqing Sun, David J. Fleet∗
4
+
5
+ {srbs,irwinherrmann,junhwahur,abhiskar,deqingsun,davidfleet}@google.com
6
+
7
+ Google DeepMind and Google Research
8
+
9
+ # Abstract
10
+
11
+ Denoising diffusion probabilistic models have transformed image generation with their impressive fidelity and diversity. We show that they also excel in estimating optical flow and monocular depth, surprisingly, without task-specific architectures and loss functions that are predominant for these tasks. Compared to the point estimates of conventional regression-based methods, diffusion models also enable Monte Carlo inference, e.g., capturing uncertainty and ambiguity in flow and depth. With self-supervised pre-training, the combined use of synthetic and real data for supervised training, and technical innovations (infilling and step-unrolled denoising diffusion training) to handle noisy-incomplete training data, and a simple form of coarse-to-fine refinement, one can train state-of-the-art diffusion models for depth and optical flow estimation. Extensive experiments focus on quantitative performance against benchmarks, ablations, and the model’s ability to capture uncertainty and multimodality, and impute missing values. Our model, DDVM (Denoising Diffusion Vision Model), obtains a state-of-the-art relative depth error of 0.074 on the indoor NYU benchmark and an Fl-all outlier rate of $3 . 2 6 \%$ on the KITTI optical flow benchmark, about $2 5 \%$ better than the best published method. For an overview see diffusion-vision.github.io
12
+
13
+ # 1 Introduction
14
+
15
+ Diffusion models have emerged as powerful generative models for high fidelity image synthesis, capturing rich knowledge about the visual world [21, 48, 55, 62]. However, at first glance, it is unclear whether these models can be as effective on many classical computer vision tasks. For example, consider two dense vision estimation tasks, namely, optical flow, which estimates frame-toframe correspondences, and monocular depth perception, which makes depth predictions based on a single image. Both tasks are usually treated as regression problems and addressed with specialized architectures and task-specific loss functions, e.g., cost volumes, feature warps, or suitable losses for depth. Without these specialized components or the regression framework, general generative techniques may be ill-equipped and vulnerable to both generalization and performance issues.
16
+
17
+ In this paper, we show that these concerns, while valid, can be addressed and that, surprisingly, a generic, conventional diffusion model for image to image translation works impressively well on both tasks, often outperforming the state of the art. In addition, diffusion models provide valuable benefits over networks trained with regression; in particular, diffusion allows for approximate inference with multi-modal distributions, capturing uncertainty and ambiguity (e.g. see Figure 1).
18
+
19
+ One key barrier to training useful diffusion models for monocular depth and optical flow inference concerns the amount and quality of available training data. Given the limited availability of labelled training data, we propose a training pipeline comprising multi-task self-supervised pre-training followed by supervised pre-training using a combination of real and synthetic data. Multi-task self-supervised pre-training leverages the strong performance of diffusion models on tasks like colorization and inpainting [e.g., 54]. We also find that supervised (pre-)training with a combination of real and large-scale synthetic data improves performance significantly.
20
+
21
+ ![](images/4753793252e60e934fa0c425781c56b83be628669ba296b8de50760137a9b122.jpg)
22
+ Figure 1: Examples of multi-modal prediction on depth (NYU) and optical flow (Sintel and KITTI). Each row shows an input image (or overlayed image pair for optical flow), a variance heat map from 8 samples, and 3 individual samples. Our model captures multi-modality in uncertain/ambiguous cases, such as reflective (e.g. mirror on NYU), transparent (e.g. vehicle window on KITTI), and translucent (e.g. fog on Sintel) regions. High variance also occurs at object boundaries, which are often challenging cases for optical flow, and also partially originate from noisy ground truth measurements for depth. See Fig. 8, 9, 10 and 11 for more examples.
23
+
24
+ A further issue concerns the fact that many existing real datasets for depth and optical flow have noisy and incomplete ground truth annotations. This presents a challenge for the conventional training framework and iterative sampling in diffusion models, leading to a problematic distribution shift between training and inference. To mitigate these issues we propose the use of an $L _ { 1 }$ loss for robustness, infilling missing depth values during training, and the introduction of step-unrolled denoising diffusion. These elements of the model are shown through ablations to be important for both depth and flow estimation.
25
+
26
+ Our contributions are as follows:
27
+
28
+ 1. We formulate optical flow and monocular depth estimation as image to image translation with generative diffusion models, without specialized loss functions and model architectures.
29
+ 2. We identify and propose solutions to several important issues w.r.t data. For both tasks, to mitigate distribution shift between training and inference with noisy, incomplete data, we propose infilling, step-unrolling, and an $L _ { 1 }$ loss during training. For flow, to improve generalization, we introduce a new dataset mixture for pre-training, yielding a RAFT [74] baseline that outperforms all published methods in zero-shot performance on the Sintel and KITTI training benchmarks.
30
+ 3. Our diffusion models is competitive with or surpasses SOTA for both tasks. For monocular depth estimation we achieve a SOTA relative error of 0.074 on the NYU dataset and perform competitively on KITTI. For flow, diffusion surpasses the stronger RAFT baseline by a large margin in pre-training and our fine-tuned model achieves an Fl-all outlier rate of $3 . 2 6 \%$ on the public KITTI test benchmark, ${ \sim } 2 5 \%$ lower than the best published method [70].
31
+ 4. Our diffusion model is also shown to capture flow and depth uncertainty, and the iterative denoising process enables zero-shot, coarse-to-fine refinement, and imputation.
32
+
33
+ # 2 Related work
34
+
35
+ Optical flow and depth estimation have been extensively studied. Here we briefly review only the most relevant work, and refer the interested readers to the references cited therein.
36
+
37
+ Optical flow. The predominant approach to optical flow is regression-based, with a focus on specialized network architectures to exploit domain knowledge, e.g., cost volume construction [14, 22, 23, 38, 68, 81, 83, 85], coarse-to-fine estimation [68, 77, 82], occlusion handling [24, 27, 67], or iterative refinement [25, 26, 74], as evidenced by public benchmark datasets [4, 44]. Some recent work has also advocated for generic architectures: Perceiver IO [28] introduces a generic transformer-based model that works for any modality, including optical flow and language modeling. Regression-based methods, however, only give a single prediction of the optical flow and do not readily capture uncertainty or ambiguity in the flow. Our work introduces a surprisingly simple, generic architecture for optical flow using a denoising diffusion model.
38
+
39
+ ![](images/4f646787799dc6d6809ae8af0c1f1a8181e23bad548bba803e62712afccf0d98.jpg)
40
+ Figure 2: Training architecture. Given ground truth flow/depth, we first infill missing values using interpolation. Then, we add noise to the label map and train a neural network to model the conditional distribution of the noise given the RGB image(s), noisy label, and time step. One can optionally unroll the denoising step(s) during training (with stop gradient) to bridge the distribution gap between training and inference for $y _ { t }$ .
41
+
42
+ We find that this generic generative model is surprisingly effective for optical flow, recovering fine details on motion boundaries, while capturing multi-modality of the motion distribution.
43
+
44
+ Monocular depth. Monocular depth estimation has been a long-standing problem in computer vision [58, 59] with recent progress focusing on specialized loss functions and architectures [1, 5, 15, 31] such as the use of multi-scale networks [12, 13], adaptive binning [3, 35] and weighted scale-shift invariant losses [13]. Large-scale in-domain pre-training has also been effective for depth estimation [49, 50, 52], which we find to be the case here as well. We build on this rich literature, but with a simple, generic architecture, leveraging recent advances in generative models.
45
+
46
+ Diffusion models. Diffusion models are latent-variable generative models trained to transform a sample of a Gaussian noise into a sample from a data distribution [21, 62]. They comprise a forward process that gradually annihilates data by adding noise, as ‘time’ $t$ increases from 0 to 1, and a learned generative process that reverses the forward process, starting from a sample of random noise at $t = 1$ and incrementally adding structure (attenuating noise) as $t$ decreases to 0. A conditional diffusion model conditions the steps of the reverse process (e.g., on labels, text, or an image).
47
+
48
+ Central to the model is a denoising network $f _ { \theta }$ that is trained to take a noisy sample $y _ { t }$ at some time-step $t$ , along with a conditioning signal $x$ , and predict a less noisy sample. Using Gaussian noise in the forward process, one can express the training objective over the sequence of transitions (as $t$ slowly decreases) as a sum of non-linear regression objectives, with the L2 loss (here with the $\epsilon$ -parameterization):
49
+
50
+ $$
51
+ \mathbb { E } _ { ( \pmb { x } , \pmb { y } ) } \mathbb { E } _ { ( t , \epsilon ) } \bigg \| f _ { \theta } ( \pmb { x } , \underbrace { \sqrt { \gamma _ { t } } \pmb { y } + \sqrt { 1 - \gamma _ { t } } \pmb { \epsilon } } _ { \pmb { y _ { t } } } , t ) - \pmb { \epsilon } \bigg \| _ { 2 } ^ { 2 }
52
+ $$
53
+
54
+ where $\epsilon \sim \mathcal { N } ( 0 , I )$ , $t \sim \mathcal { U } ( 0 , 1 )$ , and where $\gamma _ { t } ~ > ~ 0$ is computed with a pre-determined noise schedule. For inference (i.e., sampling), one draws a random noise sample $\mathbf { \pmb { y } } _ { 1 }$ , and then iteratively uses $f _ { \theta }$ to estimate the noise, from which one can compute the next latent sample $\mathbf { \eta } _ { \mathbf { { 3 } } \mathbf { { ' } } \mathbf { { 3 } } }$ , for $s < t$ .
55
+
56
+ Self-supervised pre-training. Prior work has shown that self-supervised tasks such as colorization [33, 86] and masked prediction [80] serve as effective pre-training for downstream vision tasks. Our work also confirms the benefit of self-supervised pre-training [54] for diffusion-based image-toimage translation, by establishing a new SOTA on optical flow and monocular depth estimation while also representing multi-modality and supporting zero-shot coarse-to-fine refinement and imputation.
57
+
58
+ ![](images/aa11abb1d3f1a145b38f0348a48d1dcdd3d0b462501e59d1b0010a478ed6a6df.jpg)
59
+ Figure 3: Effects of adding synthetic datasets in pretraining. Diffusion models trained only with AutoFlow (AF) tend to provide very coarse flow estimates and can hallucinate shapes. The addition of FlyingThings (FT), Kubric (KU), and TartanAir (TA) remove the AF-induced bias toward polgonal-shaped regions, and significantly improve flow quality on fine detail, e.g. trees, thin structures, and motion boundaries.
60
+
61
+ # 3 Model Framework
62
+
63
+ In contrast to the conventional monocular depth and optical flow methods, with rich usage of specialized domain knowledge on their architecture designs, we introduce simple, generic architectures and loss functions. We replace the inductive bias in state-of-the-art architectures and losses with a powerful generative model along with a combination of self-supervised pre-training and supervised training on both real and synthetic data.
64
+
65
+ The denoising diffusion model (Figure 2) takes a noisy version of the target map (i.e., a depth or flow) as input, along with the conditioning signal (one RGB image for depth and two RGB images for flow). The denoiser effectively provides a noise-free estimate of the target map (i.e., ignoring the specific loss parameterization used). The training loss penalizes residual error in the denoised map, which is quite distinct from typical image reconstruction losses used in optical flow estimation.
66
+
67
+ # 3.1 Synthetic pre-training data and generalization
68
+
69
+ Given that we train these models with a generic denoising objective, without task-specific inductive biases in the form of specialized architectures, the choice of training data becomes critical. Below we discuss the datasets used and their contributions in detail. Because training data with annotated ground truth is limited for many dense vision tasks, here we make extensive use of synthetic data in the hope that the geometric properties acquired from synthetic data during training will transfer to different domains, including natural images.
70
+
71
+ AutoFlow [69] has recently emerged as a powerful synthetic dataset for training flow models. We were surprised to find that training on AutoFlow alone is insufficient, as the diffusion model appears to devote a significant fraction of its representation capacity to represent the shapes of AutoFlow regions, rather than solving for correspondence. As a result, models trained on AutoFlow alone exhibit a strong bias to generate flow fields with polygonal shaped regions, much like those in AutoFlow, often ignoring the shapes of boundaries in the two-frame RGB inputs (e.g. see Figure 3).
72
+
73
+ To mitigate bias induced by AutoFlow in training, we further mix in three synthetic datasets during training, namely, FlyingThings3D [40], Kubric [19] and TartanAir [76]. Given a model pre-trained on AutoFlow, for compute efficiency, we use a greedy mixing strategy where we fix the relative ratio of the previous mixture and tune the proportion of the newly added dataset. We leave further exploration of an optimal mixing strategy to future work. Zero-shot testing of the model on Sintel and KITTI (see Table 1 and Fig. 3) shows substantial performance gains with each additional synthetic dataset.
74
+
75
+ We find that pre-training is similarly important for depth estimation (see Table 7). We learn separate indoor and outdoor models. For the indoor model we pre-train on a mix of ScanNet [9] and SceneNet RGB-D [41]. The outdoor model is pre-trained on the Waymo Open Dataset [71].
76
+
77
+ # 3.2 Real data: Challenges with noisy, incomplete ground truth
78
+
79
+ Ground truth annotations for real-world depth or flow data are often sparse and noisy, due to highly reflective surfaces, light absorbing surfaces [65], dynamic objects [43], etc. While regression-based
80
+
81
+ # Algorithm 1 Denoising diffusion train step with infilling and step unrolling
82
+
83
+ 1: $x \gets$ conditioning images, $y $ flow or depth map, $m a s k \gets$ binary mask of known values
84
+ 2: $t \sim U ( 0 , 1 ) , \epsilon \sim N ( 0 , 1 )$
85
+ 3: $y =$ fill_holes_with_interpolation(y)√
86
+ 4: $y _ { t } = \sqrt { \gamma _ { t } } * y + \sqrt { 1 - \gamma _ { t } } * \epsilon$
87
+ 5: if unroll_step then
88
+ 6: pred = stop_gradient(fθ(x, yt, t))√
89
+ 7: ypred = (yt − 1 − γt ∗ pred)/ γt
90
+ 8: $y _ { t } = \sqrt { \gamma _ { t } } * y _ { p r e d } + \sqrt { 1 - \gamma _ { t } } * \epsilon$
91
+ 9: $\epsilon = ( y _ { t } - { \sqrt { \gamma _ { t } } } * y ) / { \sqrt { 1 - \gamma _ { t } } }$
92
+ 10: end if
93
+ 11: $\epsilon _ { p r e d } = f _ { \theta } ( x , y _ { t } , t )$
94
+ 12: loss $=$ reduce_mean(| − pred|[mask])
95
+
96
+ methods can simply compute the loss on pixels with valid ground truth, corruption of the training data is more challenging for diffusion models. Diffusion models perform inference through iterative refinement of the target map $\textbf { { y } }$ conditioned on RGB image data $_ { \textbf { \em x } }$ . It starts with a sample of Gaussian noise $\mathbf { \pmb { y } } _ { 1 }$ , and terminates with a sample from the predictive distribution $p ( \pmb { y } _ { 0 } \vert \pmb { x } )$ . A refinement step from time $t$ to $s$ , with $s < t$ , proceeds by sampling from the parameterized distribution $p _ { \theta } ( \pmb { y } _ { s } \mid \pmb { y } _ { t } , \pmb { x } )$ ; i.e., each step operates on the output from the previous step. During training, however, the denoising steps are decoupled (see Eqn. 1), where the denoising network operates on a noisy version of the ground truth depth map instead of the output of the previous iteration (reminiscent of teaching forcing in RNN training [79]). Thus there is a distribution shift between marginals over the noisy target maps during training and inference, because the ground truth maps have missing annotations and heavytailed sensor noise while the noisy maps obtained from the previous time step at inference time should not. This distribution shift has a very negative impact on model performance. Nevertheless, with the following modifications during training we find that the problems can be mitigated effectively.
97
+
98
+ Infilling. One way to reduce the distribution shift is to impute the missing ground truth. We explored several ways to do this, including simple interpolation schemes, and inference using our model (trained with nearest neighbor interpolation). We find that nearest neighbor interpolation is sufficient to impute missing values in the ground truth maps in the depth and flow field training data.
99
+
100
+ Despite the imputation of missing ground truth depth and flow values, note that the training loss is only computed and backpropagated from pixels with known (not infilled) ground truth depth. We refer to this as the masked denoising loss (see Figure 2).
101
+
102
+ Step-unrolled denoising diffusion training. A second way to mitigate distribution shift in the $y _ { t }$ marginals in training and inference, is to construct $y _ { t }$ from model outputs rather than ground truth maps. One can do this by slightly modifying the training procedure (see Algorithm 1) to run one forward pass of the model and build $y _ { t }$ by adding noise to the model’s output rather than the training map. We do not propagate gradients for this forward pass. This process, called step-unrolled denoising diffusion, slows training only marginally $( \sim 1 5 \%$ on a TPU v4). This step-unrolling is akin to the predictor-corrector sampler of [63] which uses an extra Langevin step to improve the target marginal distribution of $y _ { t }$ . Interestingly, the problem of training / inference distribution shift resembles that of exposure bias [51] in autoregressive models, for which the mismatch is caused by teacher forcing during training [79]. Several solutions have been proposed for this problem in the literature [2, 32, 84]. Step-unrolled denoising diffusion also closely resembles the approach in [57] for training denoising autoencoders on text.
103
+
104
+ We only perform step-unrolled denoising diffusion during model fine-tuning. Early in training the denoising predictions are inaccurate, so the latent marginals over the noisy target maps will be closer to the desired true marginals than those produced by adding noise to denoiser network outputs. One might consider the use of a curriculum for gradually introducing step-unrolled denoising diffusion in the later stages of supervised pre-training, but this introduces additional hyper-parameters, so we simply invoke step-unrolled denoising diffusion during fine-tuning, and leave an exploration of curricula to future work.
105
+
106
+ $L _ { 1 }$ denoiser loss. While the $L _ { 2 }$ loss in Eqn. 1 is ideal for Gaussian noise and noise-free ground truth maps, in practice, real ground truth depth and flow fields are noisy and heavy tailed; e.g., for distant objects, near object boundaries, and near pixels with missing annotations. We hypothesize that the robustness afforded by the $L _ { 1 }$ loss may therefore be useful in training the neural denoising network. (See Tables 11 and 12 in the supplementary material for an ablation of the loss function for monocular depth estimation.)
107
+
108
+ ![](images/d14637fbc0cc84db48eb726d5c2b32c9adae0c3d94b7f2bacb17aa9a739c9a3a.jpg)
109
+ Figure 4: Visual results comparing RAFT with our method after pretraining. Note that our method does much better on fine details and ambiguous regions.
110
+
111
+ # 3.3 Coarse-to-fine refinement
112
+
113
+ Training high resolution diffusion models is often slow and memory intensive but increasing the image resolution of the model has been shown to improve performance on vision tasks [18]. One simple solution, yielding high-resolution output without increasing the training cost, is to perform inference in a coarse-to-fine manner, first estimating flow over the entire field of view at low resolution, and then refining the estimates in a patch-wise manner. For refinement, we first up-sample the low-resolution map to the target resolution using bicubic interpolation. Patches are cropped from the up-scaled map, denoted $z$ , along with the corresponding RGB inputs. Then we run diffusion model inference starting at time $t ^ { \prime }$ with a noisy map $y _ { t ^ { \prime } } \sim \mathcal { N } ( y _ { t ^ { \prime } } ; \sqrt { \gamma _ { t ^ { \prime } } } z , ( 1 - \gamma _ { t ^ { \prime } } ) I )$ . For simplicity, $t ^ { \prime }$ is a fixed hyper-parameter, set based on a validation set. This process is carried out for multiple overlapping patches. Following Perceiver IO [28], the patch estimates are merged using weighted masks with lower weight near the patch boundaries since predictions at boundaries are more prone to errors. (See Section H.5 for more details.)
114
+
115
+ # 4 Experiments
116
+
117
+ As our denoiser backbone, we adopt the Efficient UNet architecture [55], pretrained with Palette [54] style self-supervised pretraining, and slightly modified to have the appropriate input and output channels for each task. Since diffusion models expect inputs and generate outputs in the range $[ - 1 . , 1 . ]$ , we normalize depths using max depth of 10 meters and 80 meters respectively for the indoor and outdoor models. We normalize the flow using the height and width of the ground truth. Refer to Section H for more details on the architecture, augmentations and other hyper-parameters.
118
+
119
+ Optical flow. We pre-train on the mixture described in Section 3.1 at a resolution of $3 2 0 \times 4 4 8$ and report zero-shot results on the widely used Sintel [4] and KITTI [44] datasets. We further fine-tune this model on the standard mixture consisting of AutoFlow [69], FlyingThings [40], VIPER [53], HD1K [30], Sintel and KITTI at a resolution of $3 2 0 \times 7 6 8$ and report results on the test set from the public benchmark. We use a standard average end-point error (AEPE) metric that calculates L2 distance between ground truth and prediction. On KITTI, we additionally use the outlier rate, Fl-all, which reports the outlier ratio in $\%$ among all pixels with valid ground truth, where an estimate is considered as an outlier if its error exceeds 3 pixels and $5 \%$ w.r.t. the ground truth.
120
+
121
+ ![](images/e4d6c5005bb47f266c2f4f71dc972c3f7e2c3803ce41a7e60f9eb15e36eb3af7.jpg)
122
+ Figure 5: Visual results comparing RAFT with our method after finetuning. Ours does much better on fine details and ambiguous regions.
123
+
124
+ Table 1: Zero-shot optical flow estimation results on Sintel and KITTI. We provide a new RAFT baseline using our proposed pre-training mixture and substantially improve the accuracy over the original. Our diffusion model outperforms even this much stronger baseline and achieves state-of-the-art zero-shot results on Sintel.final and KITTI.
125
+
126
+ <table><tr><td rowspan="2">Model</td><td rowspan="2">Dataset</td><td colspan="2">Sintel.clean Sintel.final</td><td colspan="2">KITTI</td></tr><tr><td colspan="2">AEPE</td><td>AEPE</td><td>Fl-all</td></tr><tr><td rowspan="2">FlowFormer RAFT</td><td>Chairs-→Things</td><td>1.01</td><td>2.40</td><td>4.09</td><td>14.72%</td></tr><tr><td>Chairs-→Things</td><td>1.68</td><td>2.80</td><td>5.92</td><td>1</td></tr><tr><td rowspan="2">Perceiver IO RAFT</td><td>AutoFlow</td><td>1.81</td><td>2.42</td><td>4.98</td><td>-</td></tr><tr><td>AutoFlow</td><td>1.74</td><td>2.41</td><td>4.18</td><td>13.41%</td></tr><tr><td rowspan="2">RAFT(ours)</td><td>AF→AF+FT+KU+TA</td><td>1.27</td><td>2.28</td><td>2.71</td><td>9.16%</td></tr><tr><td>DDVM(ours) AF-→AF+FT+KU+TA</td><td>1.24</td><td>2.00</td><td>2.19</td><td>7.58%</td></tr></table>
127
+
128
+ Table 2: Optical flow finetuning evaluation on public benchmark datasets $( \mathrm { A E P E } \downarrow$ for Sintel and Fl-all↓ for KITTI). Bold indicates the best and underline the $2 ^ { \mathrm { n d } }$ -best. § uses extra datasets (AutoFlow and VIPER) on top of defaults (FlyingThings, HD1K, KITTI, and Sintel). ∗uses warm start on Sintel.
129
+
130
+ <table><tr><td>Method</td><td>Sintel.clean</td><td>Sintel.final</td><td>KITTI</td></tr><tr><td>SKFlow [72]*</td><td>1.30</td><td>2.26</td><td>4.84%</td></tr><tr><td>CRAFT [66]*</td><td>1.44</td><td>2.42</td><td>4.79%</td></tr><tr><td>FlowFormer [23]</td><td>1.14</td><td>2.18</td><td>4.68%</td></tr><tr><td>RAFT-OCTC [29]*</td><td>1.51</td><td>2.57</td><td>4.33%</td></tr><tr><td>RAFT-it [70]$</td><td>1.55</td><td>2.90</td><td>4.31%</td></tr><tr><td>DDVM (ours)$</td><td>1.75</td><td>2.48</td><td>3.26%</td></tr></table>
131
+
132
+ Depth. We separately pre-train indoor and outdoor models on the respective pre-training datasets described in Section 3.1. The indoor depth model is then finetuned and evaluated on the NYU depth v2 dataset [61] and the outdoor model on the KITTI depth dataset [17]. We follow the standard evaluation protocol used in prior work [35]. For both NYU depth v2 and KITTI, we report the absolute relative error (REL), root mean squared error (RMS) and accuracy metrics $( \delta _ { 1 } < 1 . 2 5 )$ .
133
+
134
+ # 4.1 Evaluation on benchmark datasets
135
+
136
+ Depth. Table 3 reports the results on NYU depth v2 and KITTI (see Section D for more detailed results and Section B for qualitative comparison with DPT on NYU). We achieve a state-of-the-art absolute relative error of 0.074 on NYU depth v2. On KITTI, our method performs competitively with prior work. We report results with averaging depth maps from one or more samples. Note that most prior works use post processing that averages two samples, one from the input image, and the other based on its reflection about the vertical axis.
137
+
138
+ Flow. Table 1 reports the zero-shot results of our model on Sintel and KITTI Train datasets where ground truth are provided. The model is trained on our newly proposed pre-training mixtures (AutoFlow (AF), FlyingThings (FT), Kubric (KU), and TartanAir (TA)). We report results by averaging 8 samples at a coarse resolution and then refining them to the full resolution as described in Section 3.3. For a fair comparison, we re-train RAFT on this pre-training mixture; this new RAFT model significantly outperforms the original RAFT model. And our diffusion model outperforms the stronger
139
+
140
+ Table 3: Performance comparison on the NYU-Depth- $\mathbf { \nabla } \cdot \mathbf { v } _ { 2 }$ and KITTI datasets. $\top$ indicates method uses unsupervised pretraining, †indicates supervised pretraining and $^ \ddag$ indicates use of auxilliary supervised depth data. Best / second best results are bolded / underlined respectively. $\downarrow \colon$ lower is better $\uparrow$ : higher is better.
141
+
142
+ <table><tr><td rowspan="2">Method</td><td rowspan="2">Architecture</td><td colspan="3">NYU-Depth-v2</td><td colspan="3">KITTI</td></tr><tr><td>81↑</td><td>REL↓</td><td>RMS↓</td><td>81↑</td><td>REL↓</td><td>RMS↓</td></tr><tr><td colspan="2">TransDepth [87]</td><td>Res-50+ViT-B†</td><td>0.900 0.106</td><td>0.365</td><td>0.956</td><td>0.064</td><td>2.755</td></tr><tr><td colspan="2">DPT[50]</td><td>Res-50+ViT-Bt‡</td><td>0.904 0.110</td><td>0.357</td><td></td><td>0.959 0.062</td><td>2.573</td></tr><tr><td colspan="2">BTS [34]</td><td>DenseNet-161t</td><td>0.885 0.110</td><td>0.392</td><td>0.956</td><td>0.059</td><td>2.756</td></tr><tr><td colspan="2">AdaBins [3]</td><td>E-B5+Mini-ViT†</td><td>0.903 0.103</td><td>0.364</td><td>0.964</td><td>0.058</td><td>2.360</td></tr><tr><td colspan="2">BinsFormer[35]</td><td>Swin-Large†</td><td>0.925 0.094</td><td>0.330</td><td>0.974</td><td>0.052</td><td>2.098</td></tr><tr><td colspan="2">PixelFormer [1]</td><td>Swin-Larget</td><td>0.929 0.090</td><td>0.322</td><td>0.976</td><td>0.051</td><td>2.081</td></tr><tr><td colspan="2">MIM [80]</td><td>SwinV2-LT</td><td>0.949 0.083</td><td>0.287</td><td>0.977</td><td>0.050</td><td>1.966</td></tr><tr><td colspan="2">AiT-P [46]</td><td>SwinV2-LT</td><td>0.953 0.076</td><td>0.279</td><td>1</td><td>1</td><td>1</td></tr><tr><td rowspan="3">DDVM samples=2</td><td>samples=1 Efficient U-NetT#</td><td>0.944</td><td>0.075</td><td>0.324</td><td>0.964</td><td>0.056</td><td>2.700</td></tr><tr><td>Efficient U-NetT#</td><td>0.944</td><td>0.074</td><td>0.319</td><td>0.965</td><td>0.055</td><td>2.660</td></tr><tr><td>samples=4 Efficient U-NetT#</td><td>0.946</td><td>0.074</td><td>0.315</td><td>0.965</td><td>0.055</td><td>2.613</td></tr></table>
143
+
144
+ Table 4: Ablation on infilling and step-unrolling. Without either one, performance deteriorates. Without both, optical flow models fail to train on KITTI.
145
+
146
+ <table><tr><td></td><td colspan="2">NYU val</td><td colspan="2">KITTI val</td><td colspan="2">KITTI val</td></tr><tr><td></td><td>REL</td><td>RMS</td><td>REL</td><td>RMS</td><td>AEPE</td><td>Fl-all</td></tr><tr><td>Baseline</td><td>0.079</td><td>0.331</td><td>0.222</td><td>3.770</td><td>-</td><td>-</td></tr><tr><td>Step-unroll</td><td>0.076</td><td>0.324</td><td>0.085</td><td>2.844</td><td>1.84</td><td>6.16%</td></tr><tr><td>Infill</td><td>0.077</td><td>0.338</td><td>0.057</td><td>2.744</td><td>1.53</td><td>5.24%</td></tr><tr><td>Step-unroll &amp; infill</td><td>0.075</td><td>0.324</td><td>0.056</td><td>2.700</td><td>1.47</td><td>4.74%</td></tr></table>
147
+
148
+ Table 5: Coarse-to-fine refinement improves zero-shot optical flow estimation results on Sintel and KITTI, along with the qualitative improvements shown in Figure 6.
149
+
150
+ <table><tr><td>Coarse-to-fine</td><td colspan="2">Sintel.clean Sintel.final</td><td>KITTI</td></tr><tr><td>refinement</td><td>AEPE</td><td>AEPE</td><td>AEPE Fl-all</td></tr><tr><td>Without</td><td>1.42</td><td>2.12</td><td>2.35 8.65%</td></tr><tr><td>With</td><td>1.24</td><td>2.00</td><td>2.19 7.58%</td></tr></table>
151
+
152
+ RAFT baseline. It achieves the state-of-the-art zero-shot results on both the challenging Sintel Final and KITTI datasets.
153
+
154
+ Figure 4 provides a qualitative comparison of pre-trained models. Our method demonstrates finer details on both object and motion boundaries. Especially on KITTI, our model recovers fine details remarkably well, e.g. on trees and its layered motion between tree and background.
155
+
156
+ We further finetune our model on the mixture of the following datasets, AutoFlow, FlyingThings, HD1K, KITTI, Sintel, and VIPER. Table 2 reports the comparison to state-of-the-art optical flow methods on public benchmark datasets, Sintel and KITTI. On KITTI, our method outperforms all existing optical flow methods by a substantial margin (even most scene flow methods that use stereo inputs), and sets the new state of the art. On the challenging Sintel final, our method is competitive with other state of the art models. Except for methods using warm-start strategies, our method is only behind FlowFormer which adopts strong domain knowledge on optical flow (e.g. cost volume, iterative refinement, or attention layers for larger context) unlike our generic model. Interestingly, we find that our model outperforms FlowFormer on 11/12 Sintel test sequences and our overall worse performance can be attributed to a much higher AEPE on a single (possibly out-of-distribution) test sequence. We discuss this in more detail in Section 5. On KITTI, our diffusion model outperforms FlowFormer by a large margin $( 3 0 . 3 4 \% )$ .
157
+
158
+ # 4.2 Ablation study
159
+
160
+ Infilling and step-unrolling. We study the effect of infilling and step-unrolling in Table 4. For depth, we report results for fine-tuning our pre-trained model on the NYU and KITTI datasets with the same resolution and augmentations as our best results. For flow, we fine-tune on the KITTI train set alone (with nearest neighbor resizing to the target resolution being the only augmentation) at a resolution of $3 2 0 \times 4 4 8$ and report metrics on the KITTI val set [39]. We report results with a single sample and no coarse-to-fine refinement. We find that training on raw sparse data without infilling and step unrolling leads to poor results, especially on KITTI where the ground truth is quite sparse. Step-unrolling helps to stabilize training without requiring any extra data pre-processing. However, we find that most gains come from interpolating missing values in the sparse labels. Infilling and step-unrolling compose well as our best results use both; infilling (being an approximation) does not completely bridge the training-inference distribution shift of the noisy latent.
161
+
162
+ ![](images/d17094c18838f6bebf79c88f82e740c22f32a82e794d2989adf607790e7cce37.jpg)
163
+ Figure 6: Visual results with and without coarse-to-fine refinement. For our pretrained model, refinement helps correct wrong flow and adds details to correct flow.
164
+
165
+ Coarse-to-fine refinement. Figure 6 shows that coarse-to-fine refinement (Section 3.3) substantially improves fine-grained details in estimated optical flow fields. It also improves the metrics for zero-shot optical flow estimation on both KITTI and Sintel, as shown in Table 5.
166
+
167
+ Datasets. When using different mixtures of datasets for pretraining, we find that diffusion models sometimes capture region boundaries and shape at the expense of local textural variation (eg see Figure 3). The model trained solely on AutoFlow tends to provide very coarse flow, and mimics the object shapes found in AutoFlow. The addition of FlyingThings, Kubric, and TartanAir removes this hallucination and significantly improves the fine details in the flow estimates (eg, shadows, trees, thin structure, and motion boundaries) together with a substantial boost in accuracy $_ { c f }$ . Table 6). Similarly, we find that mixing SceneNet RGB-D [41], a synthetic dataset, along with ScanNet [9] provides a performance boost for fine-tuning results on NYU depth v2, shown in Table 7.
168
+
169
+ # 4.3 Interesting properties of diffusion models
170
+
171
+ Multimodality. One strength of diffusion models is their ability to capture complex multimodal distributions. This can be effective in representing uncertainty, especially where there may exist natural ambiguities and thus multiple predictions, e.g. in cases of transparent, translucent, or reflective cases. Figure 1 presents multiple samples on the NYU, KITTI, and Sintel datasets, showing that our model captures multimodality and provides plausible samples when ambiguities exist. More details and examples are available in Section A.
172
+
173
+ Imputation of missing labels. A diffusion model trained to model the conditional distribution $p ( y | x )$ can be zero-shot leveraged to sample from $p ( y | x , y _ { p a r t i a l } )$ where $y _ { p a r t i a l }$ is the partially known label. One approach for doing this, known as the replacement method for conditional inference [63], is to replace the known portion the latent $y _ { t }$ at each inference step with the noisy latent built by applying the forward process to the known label. We qualitatively study the results of leveraging replacement guidance for depth completion and find it to be surprisingly effective. We illustrate this by building a pipeline for iteratively generating 3D scenes (conditioned on a text prompt) as shown in Figure 7 by leveraging existing models for text-to-image generation and text-conditional image inpainting. While a more thorough evaluation of depth completion and novel view synthesis against existing methods is warranted, we leave that exploration to future work. (See Section C for more details and examples.)
174
+
175
+ # 5 Limitations
176
+
177
+ Latency. We adopt standard practices from image-generation models, leading to larger models and slower running times than RAFT. However, we are excited by the recent progress on progressive distillation [42, 56] and consistency models [64] to improve inference speed in diffusion models.
178
+
179
+ ![](images/01253d8e088f9b0c7e2f798a6acd974225d4c1b6913503fb0f8e02b7c815bbe1.jpg)
180
+ Figure 7: Application of zero-shot depth completion with our model by incorporating it into an iterative 3D scene generation pipeline. Starting with a initial image (optionally generated from a text-to-image model), we sample an image-only conditioned depth map using our model. The image-depth pair is added to a point cloud. We then iteratively render images and depth maps (with holes) from this point cloud by moving the camera. We then fill image holes using an existing image inpainter (optionally text conditioned), and then use our model with replacement guidance to impute missing depths (conditioned on the filled RGB image and known depth).
181
+
182
+ Sintel fine-tuning. Under the zero-shot setting, our method achieves state-of-the-art results on both Sintel Final and KITTI. Under the fine-tuning setting, ours is state-of-the-art on KITTI but is behind FlowFormer [23] on Sintel Final. We discuss several possible reasons for why this may be the case.
183
+
184
+ • We follow the fine-tuning procedure in [70]. While their zero-shot RAFT results are comparable to FlowFormer on Sintel and KITTI, the fine-tuned RAFT-it is significantly better on KITTI but less accurate on Sintel than FlowFormer. It is possible that the fine-tuning procedure (e.g. dataset mixture or augmentations) developed in [70] is more suited for KITTI than Sintel. Another possible reason is that there is substantial domain gap between the training and test data on Sintel than KITTI. On Sintel test, there is a particular sequence “Ambush 1”, where the girl’s right arm moves out of the image boundary. Our method has an AEPE close to 30 while FlowFormer has lower than 10. It is likely that the attention on the cost volume mechanism by FlowFormer can better reason about the motion globally and handles this particular sequence well. This particular sequence may account for the major difference in the overall results; among 12 available results on the Sintel website, ours has lower AEPE on 11 sequences but a higher AEPE on the “Ambush 1” sequence, as shown in Table 8. Figure 16 in the appendix further provides visualization.
185
+
186
+ Table 8: Average end-point error (AEPE) on 12 Sintel test sequences available from the public website.
187
+
188
+ <table><tr><td>Sequence</td><td>Ours</td><td>FlowFormer [23]</td></tr><tr><td>Perturbed Market 3</td><td>0.787</td><td>0.869</td></tr><tr><td>Perturbed Shaman 1</td><td>0.219</td><td>0.252</td></tr><tr><td>Ambush 1</td><td>29.33</td><td>8.141</td></tr><tr><td>Ambush 3</td><td>2.855</td><td>2.973</td></tr><tr><td>Bamboo 3</td><td>0.415</td><td>0.577</td></tr><tr><td>Cave 3</td><td>2.042</td><td>2.352</td></tr><tr><td>Market 1</td><td>0.719</td><td>1.174</td></tr><tr><td>Market 4</td><td>5.517</td><td>8.768</td></tr><tr><td>Mountain 2</td><td>0.176</td><td>0.518</td></tr><tr><td>Temple 1</td><td>0.452</td><td>0.612</td></tr><tr><td>Tiger</td><td>0.413</td><td>0.596</td></tr><tr><td>Wall</td><td>1.639</td><td>1.723</td></tr></table>
189
+
190
+ # 6 Conclusion
191
+
192
+ We introduced a simple denoising diffusion model for monocular depth and optical flow estimation using an image-to-image translation framework. Our generative approach obtains state-of-the-art results without task-specific architectures or loss functions. In particular, our model achieves an Fl-all score of $3 . 2 6 \%$ on KITTI, about $2 5 \%$ better than the best published method [70]. Further, our model captures the multi-modality and uncertainty through multiple samples from the posterior. It also allows imputation of missing values, which enables iterative generation of 3D scenes conditioned on a text prompt. Our work suggests that diffusion models could be a simple and generic framework for dense vision tasks, and we hope to see more work in this direction.
193
+
194
+ # Acknowledgements
195
+
196
+ We thank Ting Chen, Daniel Watson, Hugo Larochelle and the rest of Google DeepMind for feedback on this work. Thanks to Klaus Greff and Andrea Tagliasacchi for their help with the Kubric generator, and to Chitwan Saharia for help training the Palette model.
197
+
198
+ # References
199
+
200
+ [1] Ashutosh Agarwal and Chetan Arora. Attention Attention Everywhere: Monocular depth prediction with skip attention. In WACV, 2023.
201
+ [2] Samy Bengio, Oriol Vinyals, Navdeep Jaitly, and Noam Shazeer. Scheduled sampling for sequence prediction with recurrent neural networks. NIPS, 2015.
202
+ [3] Shariq Farooq Bhat, Ibraheem Alhashim, and Peter Wonka. AdaBins: Depth estimation using adaptive bins. In CVPR, pages 4009–4018, 2021.
203
+ [4] Daniel J. Butler, Jonas Wulff, Garrett B. Stanley, and Michael J. Black. A naturalistic open source movie for optical flow evaluation. In ECCV, pages 611–625, 2012.
204
+ [5] Yuanzhouhan Cao, Zifeng Wu, and Chunhua Shen. Estimating depth from monocular images as classification using deep fully convolutional residual networks. IEEE T-CSVT, 28(11): 3174–3182, 2017. [6] Angel X. Chang, Thomas Funkhouser, Leonidas Guibas, Pat Hanrahan, Qixing Huang, Zimo Li, Silvio Savarese, Manolis Savva, Shuran Song, Hao Su, Jianxiong Xiao, Li Yi, and Fisher Yu. ShapeNet: An information-rich 3D model repository. arXiv:1512.03012, 2015.
205
+ [7] Ting Chen, Lala Li, Saurabh Saxena, Geoffrey Hinton, and David J. Fleet. A generalist framework for panoptic segmentation of images and videos. In ICCV, 2023.
206
+ [8] Ting Chen, Ruixiang Zhang, and Geoffrey Hinton. Analog bits: Generating discrete data using diffusion models with self-conditioning. In ICLR, 2023. [9] Angela Dai, Angel X. Chang, Manolis Savva, Maciej Halber, Thomas Funkhouser, and Matthias Nießner. ScanNet: Richly-annotated 3D reconstructions of indoor scenes. In CVPR, 2017.
207
+ [10] Jia Deng, Wei Dong, Richard Socher, Li-Jia Li, Kai Li, and Li Fei-Fei. ImageNet: A large-scale hierarchical image database. In CVPR, pages 248–255, 2009.
208
+ [11] Prafulla Dhariwal and Alex Nichol. Diffusion models beat GANs on image synthesis. In NeurIPS, 2022.
209
+ [12] David Eigen and Rob Fergus. Predicting depth, surface normals and semantic labels with a common multi-scale convolutional architecture. In ICCV, pages 2650–2658, 2015.
210
+ [13] David Eigen, Christian Puhrsch, and Rob Fergus. Depth map prediction from a single image using a multi-scale deep network. In NIPS, volume 27, 2014.
211
+ [14] Philipp Fischer, Alexey Dosovitskiy, Eddy Ilg, Philip Häusser, Caner Hazirbas, Vladimir Golkov, Patrick van der Smagt, Daniel Cremers, and Thomas Brox. FlowNet: Learning optical flow with convolutional networks. In ICCV, pages 2758–2766, 2015.
212
+ [15] Huan Fu, Mingming Gong, Chaohui Wang, Kayhan Batmanghelich, and Dacheng Tao. Deep ordinal regression network for monocular depth estimation. In CVPR, pages 2002–2011, 2018.
213
+ [16] Ravi Garg, Vijay Kumar Bg, Gustavo Carneiro, and Ian Reid. Unsupervised CNN for single view depth estimation: Geometry to the rescue. In ECCV, pages 740–756, 2016.
214
+ [17] Andreas Geiger, Philip Lenz, Christoph Stiller, and Raquel Urtasun. Vision meets Robotics: The KITTI dataset. The International Journal of Robotics Research, 32(11):1231–1237, 2013.
215
+ [18] Clément Godard, Oisin Mac Aodha, Michael Firman, and Gabriel J. Brostow. Digging into self-supervised monocular depth estimation. In ICCV, pages 3828–3838, 2019.
216
+
217
+ [19] Klaus Greff, Francois Belletti, Lucas Beyer, Carl Doersch, Yilun Du, Daniel Duckworth, David J. Fleet, Dan Gnanapragasam, Florian Golemo, Charles Herrmann, Thomas Kipf, Abhijit Kundu, Dmitry Lagun, Issam Laradji, Hsueh-Ti (Derek) Liu, Henning Meyer, Yishu Miao, Derek Nowrouzezahrai, Cengiz Oztireli, Etienne Pot, Noha Radwan, Daniel Rebain, Sara Sabour, Mehdi S. M. Sajjadi, Matan Sela, Vincent Sitzmann, Austin Stone, Deqing Sun, Suhani Vora, Ziyu Wang, Tianhao Wu, Kwang Moo Yi, Fangcheng Zhong, and Andrea Tagliasacchi. Kubric: A scalable dataset generator. In CVPR, pages 3749–3761, June 2022.
218
+
219
+ [20] Ankur Handa, Viorica Patraucean, Vijay Badrinarayanan, Simon Stent, and Roberto Cipolla. Understanding real world indoor scenes with synthetic data. In CVPR, pages 4077–4085, 2016.
220
+
221
+ [21] Jonathan Ho, Ajay Jain, and Pieter Abbeel. Denoising Diffusion Probabilistic Models. NeurIPS, 2020.
222
+
223
+ [22] Asmaa Hosni, Christoph Rhemann, Michael Bleyer, Carsten Rother, and Margrit Gelautz. Fast cost-volume filtering for visual correspondence and beyond. IEEE T-PAMI, 35(2):504–511, 2012.
224
+
225
+ [23] Zhaoyang Huang, Xiaoyu Shi, Chao Zhang, Qiang Wang, Ka Chun Cheung, Hongwei Qin, Jifeng Dai, and Hongsheng Li. FlowFormer: A transformer architecture for optical flow. In ECCV, pages 668–685, 2022.
226
+
227
+ [24] Junhwa Hur and Stefan Roth. MirrorFlow: Exploiting symmetries in joint optical flow and occlusion estimation. In ICCV, pages 312–321, 2017.
228
+
229
+ [25] Junhwa Hur and Stefan Roth. Iterative residual refinement for joint optical flow and occlusion estimation. In CVPR, pages 5754–5763, 2019.
230
+
231
+ [26] Eddy Ilg, Nikolaus Mayer, Tonmoy Saikia, Margret Keuper, Alexey Dosovitskiy, and Thomas Brox. FlowNet 2.0: Evolution of optical flow estimation with deep networks. In CVPR, pages 2462–2470, 2017.
232
+
233
+ [27] Serdar Ince and Janusz Konrad. Occlusion-aware optical flow estimation. IEEE T-IP, 17(8): 1443–1451, 2008.
234
+
235
+ [28] Andrew Jaegle, Sebastian Borgeaud, Jean-Baptiste Alayrac, Carl Doersch, Catalin Ionescu, David Ding, Skanda Koppula, Daniel Zoran, Andrew Brock, Evan Shelhamer, et al. Perceiver IO: A general architecture for structured inputs & outputs. In ICLR, 2022.
236
+
237
+ [29] Jisoo Jeong, Jamie Lin, Fatih Porikli, and Nojun Kwak. Imposing consistency for optical flow estimation. In CVPR, 2022.
238
+
239
+ [30] Daniel Kondermann, Rahul Nair, Katrin Honauer, Karsten Krispin, Jonas Andrulis, Alexander Brock, Burkhard Gussefeld, Mohsen Rahimimoghaddam, Sabine Hofmann, Claus Brenner, et al. The HCI Benchmark Suite: Stereo and flow ground truth with uncertainties for urban autonomous driving. In CVPR Workshops, pages 19–28, 2016.
240
+
241
+ [31] Iro Laina, Christian Rupprecht, Vasileios Belagiannis, Federico Tombari, and Nassir Navab. Deeper depth prediction with fully convolutional residual networks. In 3DV, pages 239–248, 2016.
242
+
243
+ [32] Alex Lamb, Anirudh Goyal, Ying Zhang, Saizheng Zhang, Aaron Courville, and Yoshua Bengio. Professor Forcing: A new algorithm for training recurrent networks. NIPS, 29, 2016.
244
+
245
+ [33] Gustav Larsson, Michael Maire, and Gregory Shakhnarovich. Learning representations for automatic colorization. In ECCV, pages 577–593, 2016.
246
+
247
+ [34] Jin Han Lee, Myung-Kyu Han, Dong Wook Ko, and Il Hong Suh. From big to small: Multi-scale local planar guidance for monocular depth estimation. arXiv:1907.10326, 2019.
248
+
249
+ [35] Zhenyu Li, Xuyang Wang, Xianming Liu, and Junjun Jiang. BinsFormer: Revisiting adaptive bins for monocular depth estimation. arxiv.2204.00987, 2022.
250
+
251
+ [36] Orly Liba, Longqi Cai, Yun-Ta Tsai, Elad Eban, Yair Movshovitz-Attias, Yael Pritch, Huizhong Chen, and Jonathan T. Barron. Sky Optimization: Semantically aware image processing of skies in low-light photography. In CVPR Workshops, June 2020.
252
+ [37] Andrew Liu, Richard Tucker, Varun Jampani, Ameesh Makadia, Noah Snavely, and Angjoo Kanazawa. Infinite Nature: Perpetual view generation of natural scenes from a single image. In ICCV, 2021.
253
+ [38] Ao Luo, Fan Yang, Kunming Luo, Xin Li, Haoqiang Fan, and Shuaicheng Liu. Learning optical flow with adaptive graph reasoning. In AAAI, pages 1890–1898, 2022.
254
+ [39] Zhaoyang Lv, Kihwan Kim, Alejandro Troccoli, Deqing Sun, James M. Rehg, and Jan Kautz. Learning rigidity in dynamic scenes with a moving camera for 3D motion field estimation. In ECCV, pages 468–484, 2018.
255
+ [40] Nikolaus Mayer, Eddy Ilg, Philip Hausser, Philipp Fischer, Daniel Cremers, Alexey Dosovitskiy, and Thomas Brox. A large dataset to train convolutional networks for disparity, optical flow, and scene flow estimation. In CVPR, 2016.
256
+ [41] John McCormac, Ankur Handa, Stefan Leutenegger, and Andrew J. Davison. SceneNet RGB-D: Can 5M synthetic images beat generic imagenet pre-training on indoor segmentation? In ICCV, 2017.
257
+ [42] Chenlin Meng, Ruiqi Gao, Diederik P. Kingma, Stefano Ermon, Jonathan Ho, and Tim Salimans. On distillation of guided diffusion models. In NeurIPS 2022 Workshop on Score-Based Methods, 2022.
258
+ [43] Moritz Menze, Christian Heipke, and Andreas Geiger. Joint 3D estimation of vehicles and scene flow. In ISPRS Workshop on Image Sequence Analysis (ISA), 2015.
259
+ [44] Moritz Menze, Christian Heipke, and Andreas Geiger. Object scene flow. ISPRS Journal of Photogrammetry and Remote Sensing (JPRS), 2018.
260
+ [45] Alexander Quinn Nichol and Prafulla Dhariwal. Improved denoising diffusion probabilistic models. In ICML, pages 8162–8171, 2021.
261
+ [46] Jia Ning, Chen Li, Zheng Zhang, Zigang Geng, Qi Dai, Kun He, and Han Hu. All in Tokens: Unifying output space of visual tasks via soft token. In ICCV, 2023.
262
+ [47] Ethan Perez, Florian Strub, Harm de Vries, Vincent Dumoulin, and Aaron C. Courville. FiLm: Visual reasoning with a general conditioning layer. In AAAI, 2018.
263
+ [48] Aditya Ramesh, Prafulla Dhariwal, Alex Nichol, Casey Chu, and Mark Chen. Hierarchical text-conditional image generation with clip latents. arXiv:2204.06125, 2022.
264
+ [49] René Ranftl, Katrin Lasinger, David Hafner, Konrad Schindler, and Vladlen Koltun. Towards robust monocular depth estimation: Mixing datasets for zero-shot cross-dataset transfer. IEEE T-PAMI, 44(3):1623–1637, 2020.
265
+ [50] René Ranftl, Alexey Bochkovskiy, and Vladlen Koltun. Vision transformers for dense prediction. In ICCV, pages 12179–12188, 2021.
266
+ [51] Marc’Aurelio Ranzato, Sumit Chopra, Michael Auli, and Wojciech Zaremba. Sequence level training with recurrent neural networks. In ICLR, 2016.
267
+ [52] Zhongzheng Ren and Yong Jae Lee. Cross-Domain self-supervised multi-task feature learning using synthetic imagery. In CVPR, 2018.
268
+ [53] Stephan R. Richter, Zeeshan Hayder, and Vladlen Koltun. Playing for benchmarks. In ICCV, pages 2213–2222, 2017.
269
+ [54] Chitwan Saharia, William Chan, Huiwen Chang, Chris A. Lee, Jonathan Ho, Tim Salimans, David J. Fleet, and Mohammad Norouzi. Palette: Image-to-Image Diffusion Models. In SIGGRAPH, 2022.
270
+ [55] Chitwan Saharia, William Chan, Saurabh Saxena, Lala Li, Jay Whang, Emily Denton, Seyed Kamyar Seyed Ghasemipour, Burcu Karagol Ayan, S. Sara Mahdavi, Rapha Gontijo Lopes, Tim Salimans, Jonathan Ho, David J. Fleet, and Mohammad Norouzi. Photorealistic Text-to-Image Diffusion Models with Deep Language Understanding. In NeurIPS, 2022.
271
+ [56] Tim Salimans and Jonathan Ho. Progressive distillation for fast sampling of diffusion models. In ICLR, 2022.
272
+ [57] Nikolay Savinov, Junyoung Chung, Mikolaj Binkowski, Erich Elsen, and Aaron van den Oord. Step-unrolled denoising autoencoders for text generation. In ICLR, 2022.
273
+ [58] Ashutosh Saxena, Sung Chung, and Andrew Ng. Learning depth from single monocular images. NIPS, 2005.
274
+ [59] Ashutosh Saxena, Min Sun, and Andrew Y. Ng. Make3D: Learning 3D scene structure from a single still image. IEEE T-PAMI, 31(5):824–840, 2009.
275
+ [60] Meng-Li Shih, Shih-Yang Su, Johannes Kopf, and Jia-Bin Huang. 3D photography using context-aware layered depth inpainting. In CVPR, 2020.
276
+ [61] Nathan Silberman, Derek Hoiem, Pushmeet Kohli, and Rob Fergus. Indoor segmentation and support inference from RGBD images. In ECCV, pages 746–760, 2012.
277
+ [62] Jascha Sohl-Dickstein, Eric Weiss, Niru Maheswaranathan, and Surya Ganguli. Deep unsupervised learning using nonequilibrium thermodynamics. In ICML, pages 2256–2265, 2015.
278
+ [63] Yang Song, Jascha Sohl-Dickstein, Diederik P. Kingma, Abhishek Kumar, Stefano Ermon, and Ben Poole. Score-based generative modeling through stochastic differential equations. In ICLR, 2021.
279
+ [64] Yang Song, Prafulla Dhariwal, Mark Chen, and Ilya Sutskever. Consistency models. In ICML, 2023.
280
+ [65] Martin Stommel, Michael Beetz, and Weiliang Xu. Inpainting of missing values in the kinect sensor’s depth maps based on background estimates. IEEE Sensors Journal, 14(4):1107–1116, 2014.
281
+ [66] Xiuchao Sui, Shaohua Li, Xue Geng, Yan Wu, Xinxing Xu, Yong Liu, Rick Goh, and Hongyuan Zhu. CRAFT: Cross-attentional flow transformer for robust optical flow. In CVPR, pages 17602–17611, 2022.
282
+ [67] Deqing Sun, Erik B. Sudderth, and Michael J. Black. Layered segmentation and optical flow estimation over time. In CVPR, pages 1768–1775, 2012.
283
+ [68] Deqing Sun, Xiaodong Yang, Ming-Yu Liu, and Jan Kautz. PWC-Net: CNNs for optical flow using pyramid, warping, and cost volume. In CVPR, pages 8934–8943, 2018.
284
+ [69] Deqing Sun, Daniel Vlasic, Charles Herrmann, Varun Jampani, Michael Krainin, Huiwen Chang, Ramin Zabih, William T. Freeman, and Ce Liu. AutoFlow: Learning a better training set for optical flow. In CVPR, pages 10093–10102, 2021.
285
+ [70] Deqing Sun, Charles Herrmann, Fitsum Reda, Michael Rubinstein, David J. Fleet, and William T. Freeman. Disentangling architecture and training for optical flow. In ECCV, pages 165–182, 2022.
286
+ [71] Pei Sun, Henrik Kretzschmar, Xerxes Dotiwalla, Aurelien Chouard, Vijaysai Patnaik, Paul Tsui, James Guo, Yin Zhou, Yuning Chai, Benjamin Caine, Vijay Vasudevan, Wei Han, Jiquan Ngiam, Hang Zhao, Aleksei Timofeev, Scott Ettinger, Maxim Krivokon, Amy Gao, Aditya Joshi, Sheng Zhao, Shuyang Cheng, Yu Zhang, Jonathon Shlens, Zhifeng Chen, and Dragomir Anguelov. Scalability in perception for autonomous driving: Waymo open dataset. In CVPR, 2020.
287
+ [72] Shangkun Sun, Yuanqi Chen, Yu Zhu, Guodong Guo, and Ge Li. SKFlow: Learning optical flow with super kernels. In NeurIPS, 2022.
288
+ [73] Mingxing Tan and Quoc Le. EfficientNet: Rethinking model scaling for convolutional neural networks. In ICML, pages 6105–6114, 2019.
289
+ [74] Zachary Teed and Jia Deng. RAFT: Recurrent all-pairs field transforms for optical flow. In ECCV, pages 402–419, 2020.
290
+ [75] Su Wang, Chitwan Saharia, Ceslee Montgomery, Jordi Pont-Tuset, Shai Noy, Stefano Pellegrini, Yasumasa Onoe, Sarah Laszlo, David J. Fleet, Radu Soricut, Jason Baldridge, Mohammad Norouzi, Peter Anderson, and William Chan. Imagen Editor and EditBench: Advancing and evaluating text-guided image inpainting. In CVPR, 2023.
291
+ [76] Wenshan Wang, Delong Zhu, Xiangwei Wang, Yaoyu Hu, Yuheng Qiu, Chen Wang, Yafei Hu, Ashish Kapoor, and Sebastian Scherer. TartanAir: A dataset to push the limits of visual SLAM. In IROS, 2020.
292
+ [77] Philippe Weinzaepfel, Jerome Revaud, Zaid Harchaoui, and Cordelia Schmid. DeepFlow: Large displacement optical flow with deep matching. In ICCV, pages 1385–1392, 2013.
293
+ [78] Olivia Wiles, Georgia Gkioxari, Richard Szeliski, and Justin Johnson. SynSin: End-to-end view synthesis from a single image. In CVPR, 2020.
294
+ [79] Ronald J. Williams and David Zipser. A learning algorithm for continually running fully recurrent neural networks. Neural Computation, 1(2):270–280, 1989.
295
+ [80] Zhenda Xie, Zigang Geng, Jingcheng Hu, Zheng Zhang, Han Hu, and Yue Cao. Revealing the dark secrets of masked image modeling. In CVPR, 2023.
296
+ [81] Haofei Xu, Jing Zhang, Jianfei Cai, Hamid Rezatofighi, and Dacheng Tao. GMFlow: Learning optical flow via global matching. In CVPR, pages 8121–8130, 2022.
297
+ [82] Li Xu, Jiaya Jia, and Yasuyuki Matsushita. Motion detail preserving optical flow estimation. IEEE T-PAMI, 34(9):1744–1757, 2011.
298
+ [83] Gengshan Yang and Deva Ramanan. Volumetric correspondence networks for optical flow. NeurIPS, 2019.
299
+ [84] Lantao Yu, Weinan Zhang, Jun Wang, and Yong Yu. SeqGAN: Sequence generative adversarial nets with policy gradient. In AAAI, 2017.
300
+ [85] Feihu Zhang, Oliver J. Woodford, Victor Adrian Prisacariu, and Philip H.S. Torr. Separable flow: Learning motion cost volumes for optical flow estimation. In ICCV, pages 10807–10817, 2021.
301
+ [86] Richard Zhang, Phillip Isola, and Alexei A. Efros. Colorful image colorization. In ECCV, pages 649–666, 2016.
302
+ [87] Jiawei Zhao, Ke Yan, Yifan Zhao, Xiaowei Guo, Feiyue Huang, and Jia Li. Transformer-based dual relation graph for multi-label image recognition. In ICCV, pages 163–172, 2021.
303
+ [88] Bolei Zhou, Agata Lapedriza, Aditya Khosla, Aude Oliva, and Antonio Torralba. Places: A 10 million image database for scene recognition. IEEE T-PAMI, 2017.
304
+
305
+ # A Multimodal prediction
306
+
307
+ We provide more qualitative examples for multimodal prediction. Figures 8 and 9 illustrate multimodal depth predictions on NYU and KITTI respectively. Multimodality of the posterior distribution exists in regions where there are multiple plausible predictions. For example, this includes reflective and transparent surfaces (mirrors and glass surfaces in rows 1 to 5 of Figure 8 and windows of cars in Figure 9). We further find that the model captures uncertainty in depth estimates in the vicinity of object boundaries, some of which arise due to noise in ground truth measurements in the training data. This can be observed at the boundaries of cars in Figure 9 and around edges of objects in Figure 8 (most clearly visible in the last row).
308
+
309
+ Figure 10 illustrates different samples on KITTI from the optical flow diffusion model, also capturing multiple modes of the predictive posterior. Multimodality exists on transparent surfaces and near occlusions. As shown in Figure 11, on Sintel, multimodality also exists on occluded or out-of-bounds pixels where multiple predictions are plausible.
310
+
311
+ ![](images/3c99984f3d20cd7326a7c031f4bdfa98268c4ae79149f0f348f4dbd850bbaef3.jpg)
312
+ Figure 8: Qualitative examples of multimodal estimation on the NYU depth dataset. Our model is able to output multiple plausible depth maps where ambiguity exists. Rows 1 to 5 show transparent or reflective surfaces where two answers exist. In all samples (specially the last row) we observe the model’s ability to capture uncertainty in depth near object boundaries (see the areas of high variance).
313
+
314
+ ![](images/20353338bc9ad67dbe37e7016a060d30dd2847aa34644787bdd18a5a93a98c3b.jpg)
315
+ Figure 9: Qualitative examples of multimodal depth estimation on KITTI. Our model is able to predict multimodal samples, especially windows of cars and object boundaries. Please refer to the areas with high variance.
316
+
317
+ ![](images/2543a5fefa1c19c633a723491ca593dbdb37d51278322de13d91110f59a153c8.jpg)
318
+ Figure 10: Qualitative examples of multimodal optical flow estimation on KITTI. Multimodality exists on transparent surfaces (e.g., windows of cars) and shadows where our model estimates layered motion in different samples (see the last row).
319
+
320
+ ![](images/f98ca7c4cec2c4aca1b203cd36940f0f3003785ebdf421e5dc6fe911345933e0.jpg)
321
+ Figure 11: Qualitative examples of multimodal optical flow estimation on Sintel. Multimodality also exists on examples with challenging occlusion or out-of-bound cases.
322
+
323
+ # B Qualitative comparison of depth estimation with DPT
324
+
325
+ Figure 12 provides a qualitative comparison of our model with DPT-Hybrid [50] finetuned on the NYU depth v2 [61] dataset. The depth estimates of our diffusion model are more accurate both on coarse-scale scene structure (walls, floors, etc.) and on individual objects.
326
+
327
+ # C More samples for zero-shot imputation of depth
328
+
329
+ Figure 13 provides samples generated using our iterative text-to-3D pipeline. We note that such pipelines for iteratively generating 3D scenes have been previously proposed in literature [37, 60, 78]. However, these methods explicitly learn networks to refine the color [37, 60, 78] and the depth map [37, 60]. In contrast, we propose leveraging the text-conditioned image prior from existing large scale text-to-image [55] and text-conditional image completion [75] models, and use our depth estimation model zero-shot for depth completion. One caveat with our current approach of using the replacement method for conditional inference [63] for imputing depth, is that it does not enable one to fix errors in the depth predicted in the previous step. One approach to fix artifacts would be by noising-denoising, like that used for coarse-to-fine refinement. We leave further exploration into this to future work.
330
+
331
+ # D Complete depth results on NYU and KITTI
332
+
333
+ Tables 9 and 10 provide detailed results on the val set of NYU depth v2 and KITTI depth datasets. We follow the standard evaluation protocol used in prior work [35]. For both the NYU depth v2 and KITTI datasets we report the absolute relative error (REL), root mean squared error (RMS) and accuracy metrics $\cdot \delta _ { i } < 1 . 2 5 ^ { i }$ for $i \in { 1 , 2 , 3 }$ ). For NYU we also report absolute error of log depths $( l o g _ { 1 0 } )$ . For KITTI we additionally report the squared relative error (Sq-rel) and root mean squared error of log depths (RMS log). The predicted depth is up-sampled to the full resolution using bilinear interpolation before evaluation. For the indoor model we evaluate on the cropped region proposed by [13] and for the outdoor model the cropped region proposed by [16] as is standard in prior work.
334
+
335
+ ![](images/5748f207563fdd78a3d6643decb1aa45b6e357689949509adf5b048ec218d0db.jpg)
336
+ Figure 12: Qualitative comparison of our model with DPT-Hybrid [50] (fine-tuned on NYU) on the NYU depth v2 val set. Our method infers better depth for both scene structure (walls, floors, etc.) and individual objects. Specific differences are highlighted with red arrows.
337
+
338
+ ![](images/091fb86ab1ddcb3861322b43f9a4d8fa56945cf2655378ebd0f5a2b5a4f74023.jpg)
339
+ Figure 13: Text-to-3D samples. Given a text prompt, an image is first generated using Imagen [55] (first row of first column), after which depth is estimated (second row of first column). Subsequently the camera is moved to reveal new parts of the scene which are infilled using an image completion model and our model (which conditions on both the incomplete depth map and the filled image). At each step, newly generated RGBD points are added to a global point cloud which is visualized in the rightmost column.
340
+
341
+ Table 9: Comparison of performance on the NYU-Depth- $\mathbf { v } 2$ dataset. $\top$ indicates method uses unsupervised pretraining, $^ \dagger$ indicates supervised pretraining and $^ \ddag$ indicates use of auxiliary supervised depth data. Best / second best results are bolded / underlined respectively. $\downarrow :$ lower is better and $\uparrow$ : higher is better.
342
+
343
+ <table><tr><td>Method</td><td>Architecture</td><td>81↑</td><td>&amp;↑</td><td>8↑</td><td>REL↓</td><td>RMS↓</td><td>log10</td></tr><tr><td colspan="2">TransDepth [87]</td><td>Res-50+ViT-Bt</td><td>0.900</td><td>0.983</td><td>0.996</td><td>0.106</td><td>0.365</td><td>0.045</td></tr><tr><td colspan="2">DPT[50]</td><td>Res-50+ViT-B†#</td><td>0.904</td><td>0.988</td><td>0.998</td><td>0.110</td><td>0.357</td><td>0.045</td></tr><tr><td colspan="2">AdaBins [3]</td><td>E-B5+Mini-ViTt</td><td>0.903</td><td>0.984</td><td>0.997</td><td>0.103</td><td>0.364</td><td>0.044</td></tr><tr><td colspan="2">BinsFormer [35]</td><td>Swin-Larget</td><td>0.925</td><td>0.989</td><td>0.997</td><td>0.094</td><td>0.330</td><td>0.040</td></tr><tr><td colspan="2">PixelFormer [1]</td><td>Swin-Large†</td><td>0.929</td><td>0.991</td><td>0.998</td><td>0.090</td><td>0.322</td><td>0.039</td></tr><tr><td colspan="2">MIM[80]</td><td>SwinV2-LT</td><td>0.949</td><td>0.994</td><td>0.999</td><td>0.083</td><td>0.287</td><td>0.035</td></tr><tr><td colspan="2">AiT-P [46]</td><td>SwinV2-LT</td><td>0.953</td><td>0.993</td><td>0.999</td><td>0.076</td><td>0.279</td><td>0.033</td></tr><tr><td rowspan="3">DDVM</td><td>samples=1</td><td>Efficient U-NetT#</td><td>0.944</td><td>0.986</td><td>0.995</td><td>0.075</td><td>0.324</td><td>0.032</td></tr><tr><td>samples=2</td><td>Efficient U-NetT‡</td><td>0.944</td><td>0.987</td><td>0.996</td><td>0.074</td><td>0.319</td><td>0.032</td></tr><tr><td>samples=4</td><td>Efficient U-Net T‡</td><td>0.946</td><td>0.987</td><td>0.996</td><td>0.074</td><td>0.315</td><td>0.032</td></tr></table>
344
+
345
+ Table 10: Comparison of performance on the KITTI dataset. $\top$ indicates method uses unsupervised pretraining, $^ \dagger$ indicates supervised pretraining and $^ \ddag$ indicates use of auxiliary supervised depth data. Best / second best results are bolded / underlined respectively. $\downarrow \colon$ lower is better and $\uparrow$ : higher is better. E-B5: EfficientNet-B5 [73].
346
+
347
+ <table><tr><td>Method</td><td>Backbone</td><td>81↑</td><td>82个</td><td>8↑</td><td>REL↓</td><td>Sq-rel ↓</td><td>RMS↓</td><td>RMS log↓</td></tr><tr><td>BTS [34]</td><td>DenseNet-161†</td><td>0.956</td><td>0.993</td><td>0.998</td><td>0.059</td><td>0.245</td><td>2.756</td><td>0.096</td></tr><tr><td>TransDepth [87]</td><td>ResNet-50+ViT-Bt</td><td>0.956</td><td>0.994</td><td>0.999</td><td>0.064</td><td>0.252</td><td>2.755</td><td>0.098</td></tr><tr><td>DPT [50]</td><td>ResNet-50+ViT-Bt‡</td><td>0.959</td><td>0.995</td><td>0.999</td><td>0.062</td><td>1</td><td>2.573</td><td>0.092</td></tr><tr><td>AdaBins [3]</td><td>E-B5+mini-ViTt</td><td>0.964</td><td>0.995</td><td>0.999</td><td>0.058</td><td>0.190</td><td>2.360</td><td>0.088</td></tr><tr><td>BinsFormer [35]</td><td>Swin-Larget</td><td>0.974</td><td>0.997</td><td>0.999</td><td>0.052</td><td>0.151</td><td>2.098</td><td>0.079</td></tr><tr><td>PixelFormer [1]</td><td>Swin-Larget</td><td>0.976</td><td>0.997</td><td>0.999</td><td>0.051</td><td>0.149</td><td>2.081</td><td>0.077</td></tr><tr><td>MIM [80]</td><td>SwinV2-LT</td><td>0.977</td><td>0.998</td><td>1.000</td><td>0.050</td><td>0.139</td><td>1.966</td><td>0.075</td></tr><tr><td rowspan="3">samples=1 DDVM samples=2 samples=4</td><td>Efficient U-NetT#</td><td>0.964</td><td>0.994</td><td>0.998</td><td>0.056</td><td>0.339</td><td>2.700</td><td>0.091</td></tr><tr><td>Efficient U-NetT#</td><td>0.965</td><td>0.994</td><td>0.998</td><td>0.055</td><td>0.325</td><td>2.660</td><td>0.090</td></tr><tr><td>Efficient U-NetT‡</td><td>0.965</td><td>0.994</td><td>0.998</td><td>0.055</td><td>0.292</td><td>2.613</td><td>0.089</td></tr></table>
348
+
349
+ # E Ablations
350
+
351
+ Tables 11 and 12 show that an $L _ { 1 }$ loss in training the diffusion model performs much better than an $L _ { 2 }$ loss for monocular depth estimation on NYU and KITTI. Tables 13 and 14 show the effectiveness of Palette-style [54] self-supervised pretraining for monocular depth estimation on NYU and KITTI respectively. All results use a single sample. Because these findings are reasonable and expected to generalize to other dense vision tasks, we do not further ablate them for optical flow estimation for compute efficiency.
352
+
353
+ Table 11: Ablation for the choice of loss function on the NYU depth v2 dataset.
354
+
355
+ <table><tr><td></td><td>81个</td><td>8↑</td><td>8↑</td><td>REL↓</td><td>RMS↓</td><td>log10↓</td></tr><tr><td>L2</td><td>0.932</td><td>0.981</td><td>0.994</td><td>0.085</td><td>0.349</td><td>0.037</td></tr><tr><td>L1</td><td>0.944</td><td>0.986</td><td>0.995</td><td>0.075</td><td>0.324</td><td>0.032</td></tr></table>
356
+
357
+ Table 12: Ablation for the choice of loss function on the KITTI dataset.
358
+
359
+ <table><tr><td></td><td>81↑</td><td>82↑</td><td>83↑</td><td>REL↓</td><td>Sq-rel↓</td><td>RMS↓</td><td>RMS log↓</td></tr><tr><td>L2</td><td>0.954</td><td>0.993</td><td>0.998</td><td>0.065</td><td>0.321</td><td>2.773</td><td>0.099</td></tr><tr><td>L1</td><td>0.964</td><td>0.994</td><td>0.998</td><td>0.056</td><td>0.339</td><td>2.700</td><td>0.091</td></tr></table>
360
+
361
+ Table 13: Ablation for self-supervised pretraining on the NYU depth v2 dataset.
362
+
363
+ <table><tr><td></td><td>81↑</td><td>8↑</td><td>8↑</td><td>REL↓</td><td>RMS↓</td><td>log10↓</td></tr><tr><td>No self-supervised pre-training</td><td>0.936</td><td>0.980</td><td>0.992</td><td>0.081</td><td>0.352</td><td>0.035</td></tr><tr><td>With self-supervised pre-training</td><td>0.944</td><td>0.986</td><td>0.995</td><td>0.075</td><td>0.324</td><td>0.032</td></tr></table>
364
+
365
+ Table 14: Ablation for self-supervised pretraining on the KITTI depth dataset.
366
+
367
+ <table><tr><td></td><td>81</td><td>&amp;2</td><td>8↑</td><td></td><td></td><td></td><td>REL↓Sq-rel↓RMS↓RMS log↓</td></tr><tr><td>No self-supervised pre-training</td><td>0.952</td><td>0.990(</td><td>0.997</td><td>0.064</td><td>0.389 </td><td>2.998</td><td>0.104</td></tr><tr><td>With self-supervised pre-training</td><td>0.965</td><td>0.994</td><td>0.998</td><td>0.055</td><td>0.332</td><td>2.696</td><td>0.091</td></tr></table>
368
+
369
+ # F Coarse-to-fine refinement for depth
370
+
371
+ Figure 14 demonstrates performance of coarse-to-fine refinement on the NYU depth v2 dataset. While refinement improves fine-scale details in the estimated depth maps, the qualitative improvements are small and we do not find significant quantitative improvements. Hence the results reported in this work do not use coarse-to-fine refinement for depth estimation. Further work is needed to develop a coarse-to-fine algorithm capable of more robust gains in depth estimation.
372
+
373
+ ![](images/dd13e125d12e37e3ec51d61fa7228d17a03f316bf3785e371ea9f43c2429e3cf.jpg)
374
+ Figure 14: Samples with coarse-to-fine refinement on the NYU depth v2 dataset. We find that refinement adds sharpness and detail to the depth estimation but does not provide quantitative improvements.
375
+
376
+ # G Coarse-to-fine optical flow refinement for RAFT
377
+
378
+ For a fair comparison with optical flow estimation, we also apply our coarse-to-fine refinement scheme to RAFT [74], to determine whether our performance gains translate to RAFT as well. We first estimate flow at a low resolution, $3 2 0 \times 4 4 8$ , upsample the low-resolution flow to the original resolution, divide original-resolution input images into $2 \times 5$ overlapping patches of size $3 2 0 \times 4 4 8$ , then estimate flow on the cropped patches using the upsampled flow field as the initial guess for the recurrent refinement (12 steps in total) of RAFT [74]. After estimating flow of each patch, we merge them using weighted masks [28]. Table 15 reports the result. Unlike our diffusion-based method, the coarse-to-fine scheme actually hurts the accuracy of RAFT on Sintel Clean and KITTI and only marginally improves the accuracy on Sintel Final. Further exploration into better approaches for coarse-to-fine refinement for RAFT is warranted. We leave that to future work.
379
+
380
+ # H Training and inference details
381
+
382
+ # H.1 Architecture
383
+
384
+ UNet. The predominant architecture for diffusion models is the U-Net developed for the DDPM model [21], and later improved in several respects [11, 45, 63]. Here we adapt the Efficient $U _ { ☉ }$ - Net architecture that was developed for Imagen [55]. It is more efficient that the U-Nets used in prior work owing to the use of fewer self-attention layers, fewer parameters and less computation at higher resolutions, along with other adjustments that make it well suited to training medium resolution diffusion models.
385
+
386
+ Table 15: Our coarse-to-fine refinement scheme marginally improves the performance of RAFT on Sintel Final while hurting performance on Sintel Clean and KITTI. We report the EPE on the Sintel and KITTI datasets.
387
+
388
+ <table><tr><td></td><td>Sintel Clean</td><td>Sintel Final</td><td>KITTI</td></tr><tr><td>RAFT baseline</td><td>1.27</td><td>2.28</td><td>2.71</td></tr><tr><td>RAFT with the coarse-to-fine refinement</td><td>1.35</td><td>2.26</td><td>2.85</td></tr></table>
389
+
390
+ ![](images/b89cb4a8c761c7dd9ce807b02b3ad203ba77e444dd56259afba6e66435fd486a.jpg)
391
+ Figure 15: Overview of the Efficient UNet architecture proposed in [55]. $C H \_ I N$ and $C H \_ O U T$ refer to the number of input and output channels respectively. t refers to the time embedding. FiLM refers to the modulation layers proposed in [47]. $N$ is the number of ResNet $^ +$ self-attention blocks.
392
+
393
+ Specifically we adopt the configuration for the $6 4 \times 6 4 2 5 6 \times 2 5 6$ super-resolution model (see Figure 15 for an overview) with several changes. We drop the text cross-attention layers but preserve the selfattention in the lowest resolution layers dblock4 and ublock4 (see Figure 15). For supervised training for the flow model, we find it beneficial to additionally enable self-attention for the last-but-one layers dblock3 and ublock3. The number of input and output channels differ across self-supervised pre-training and supervised pre-training and are also different for flow and depth models. For selfsupervised pre-training $C H \_ I N { = } 6$ and $C H \_ O U T { = } 3$ (see Figure 15) since the input consists of a 3-channel source RGB image and a 3-channel noisy target image concatenated along the channel dimension and the output is a RGB image. The supervised depth model has $C H \_ I N { = } 4$ (RGB image $^ +$ noisy depth) and $C H _ { - } O U T { = } I$ . The supervised optical flow model has $C H \_ I N { = } 8$ (2 RGB images $^ +$ noisy flow along $x$ and $y$ ) and $C H _ { - } O U T { = } 2$ . Note that this means we need to reinitialize the input and output convolutional kernels and biases before the supervised pretraining stage. All other weights are re-used.
394
+
395
+ Resolution. Our self-supervised model was trained at a resolution of $2 5 6 \times 2 5 6$ . The indoor depth model is trained at $2 4 0 \times 3 2 0$ . For Waymo we use $2 5 6 \times 3 8 4$ and for KITTI depth $2 5 6 \times 8 3 2$ . Flow pretraining is done at a resolution of $3 2 0 \times 4 4 8$ , and finetuning at $3 2 0 \times 7 6 8$ .
396
+
397
+ # H.2 Datasets and augmentation
398
+
399
+ For unsupervised pre-training, we use the ImageNet-1K [10] and Places365 [88] datasets and train on the self-supervised tasks of colorization, inpainting, uncropping, and JPEG decompression, following [54]. Throughout, we mix datasets at the batch level.
400
+
401
+ Flow. For supervised flow pretraining we use a mix of AutoFlow (native resolution $4 4 8 \times 5 7 6$ ), FlyingThings $( 5 4 0 \times 9 6 0 )$ , Kubric $( 5 1 2 \times 5 1 2 )$ and TartanAir $( 4 8 0 \times 6 4 0 )$ synthetic datasets. We finetune on the standard mixture consisting of AutoFlow, FlyingThings, Viper $( 5 4 0 \times 9 6 0 )$ ), HD1K $( 5 4 0 \times 1 2 8 0 )$ ), Sintel $4 3 6 \times 1 0 2 4 )$ , and KITTI $( 3 7 5 \times 1 2 4 2 )$ .
402
+
403
+ We follow the same photometric and geometric augmentation schemes from [70], comprising random affine transformation, flipping, and cropping.
404
+
405
+ Depth. For supervised pre-training of the indoor model we mix the following datasets. ScanNet [9] is a dataset of $2 . 5 \mathbf { M }$ examples captured using a Kinect v1-like sensor. It provides depth maps at $4 8 0 \times 6 4 0$ and RGB images at $9 6 8 \times 1 2 9 6$ . SceneNet RGB-D [41] is a synthetic dataset of 5M images generated by rendering ShapeNet [6] objects in scenes from SceneNet [20] at a resolution of $2 4 0 \times 3 2 0$ .
406
+
407
+ For the outdoor model training we use the Waymo Open Dataset [71], a large-scale driving dataset consisting of about $2 0 0 \mathrm { k }$ frames. Each frame provides RGB images from 5 cameras and LiDAR maps. We use the RGB images from the FRONT, FRONT_LEFT and FRONT_RIGHT cameras and the TOP LiDAR only to build about 600k aligned RGB depth maps.
408
+
409
+ For indoor fine-tuning and evaluation we use NYU depth $\nu 2$ [61], a commonly used dataset for evaluating indoor depth prediction models. It provides aligned image and depth maps at $4 8 0 \times 6 4 0$ resolution. We use the official split comprising $5 0 \mathrm { k }$ images for training and 654 for evaluation.
410
+
411
+ For outdoor fine-tuning and evaluation, we use KITTI [17], an outdoor driving dataset which provides RGB images and LiDAR scans at resolutions close to $3 7 0 \times 1 2 2 6$ . We use the training/test split proposed by [13], comprising 26k training images and 652 test images.
412
+
413
+ We use random horizontal flip data augmentation which is common in prior work. Where needed, images and dense depth maps are resized using bilinear interpolation to the model’s resolution for training and nearest neighbor interpolation is used for sparse maps.
414
+
415
+ # H.3 Step-unrolling and interpolation of missing depth and flow
416
+
417
+ As discussed in Section 3.2 of the main paper, infilling and step-unrolling are used to mitigate distribution shift between training and inference with diffusion models. The problem arises due to the missing data in the training depth maps and flow fields.
418
+
419
+ Infilling. For indoor depth maps, we use nearest neighbor interpolation during training (see Section 3.2 in the main paper). For the outdoor depth data we use nearest neighbor interpolation except for sky regions, as they are often large and are much further from the camera than adjacent objects in the image. We use an off-the-shelf sky segmenter [36], and then set all sky pixels to be the maximum modeled depth (here, $8 0 \mathrm { m } \mathrm { , }$ ). For missing optical flow ground truth we employ a simple sequence of 1D nearest neighbor interpolations first along rows, and then along columns.
420
+
421
+ Table 16: Ablation of the number of unroll steps for monocular depth estimation. Performs improves up to four steps of unrolling and plateaus thereafter. The models trained without infilling missing depth benefit more from a larger number of unroll steps, which is to be expected. Best and second best results are bolded and underlined respectively.
422
+
423
+ <table><tr><td></td><td colspan="4">NYU</td><td colspan="4">KITTI</td></tr><tr><td></td><td colspan="2">No infill</td><td colspan="2">Infill</td><td colspan="2">No infill</td><td colspan="2">Infill</td></tr><tr><td>Unroll steps</td><td>REL</td><td>RMS</td><td>REL</td><td>RMS</td><td>REL</td><td>RMS</td><td>REL</td><td>RMS</td></tr><tr><td>0</td><td>0.079</td><td>0.331</td><td>0.077</td><td>0.338</td><td>0.222</td><td>3.770</td><td>0.057</td><td>2.744</td></tr><tr><td>1</td><td>0.076</td><td>0.324</td><td>0.075</td><td>0.324</td><td>0.085</td><td>2.844</td><td>0.056</td><td>2.700</td></tr><tr><td>2</td><td>0.076</td><td>0.317</td><td>0.075</td><td>0.315</td><td>0.068</td><td>2.799</td><td>0.054</td><td>2.629</td></tr><tr><td>3</td><td>0.075</td><td>0.316</td><td>0.074</td><td>0.317</td><td>0.061</td><td>2.789</td><td>0.054</td><td>2.591</td></tr><tr><td>4</td><td>0.075</td><td>0.316</td><td>0.074</td><td>0.315</td><td>0.059</td><td>2.739</td><td>0.053</td><td>2.568</td></tr></table>
424
+
425
+ Step-unrolling. By default we use a single unroll step in all results where step-unrolling is enabled. In Table 16, we show that using multiple unroll steps can further improve performance on the task of monocular depth estimation.
426
+
427
+ Finally, while we use infilling and step-unrolling, there are other ways in which one might try to mitigate the problem. One such approach was taken by [46], which faced a similar problem when training a vector-quantizer on depth data. Their approach was to synthetically add more holes following a carefully chosen masking ratio. We prefer our approach since nearest neighbor infilling is hyper-parameter free and step-unrolled denoising diffusion could be more generally applicable to other tasks with sparse data.
428
+
429
+ Table 17: Comparison of step-unrolling and self-conditioning [8]
430
+
431
+ <table><tr><td></td><td colspan="4">NYU</td><td colspan="4">KITTI</td></tr><tr><td></td><td colspan="2">No infill</td><td colspan="2">Infill</td><td colspan="2">No infill</td><td colspan="2">Infill</td></tr><tr><td></td><td>REL</td><td>RMS</td><td>REL</td><td>RMS</td><td>REL</td><td>RMS</td><td>REL</td><td>RMS</td></tr><tr><td>Baseline</td><td>0.079</td><td>0.331</td><td>0.077</td><td>0.338</td><td>0.222</td><td>3.770</td><td>0.057</td><td>2.744</td></tr><tr><td>Self conditioning</td><td>0.082</td><td>0.335</td><td>0.081</td><td>0.333</td><td>0.242</td><td>3.940</td><td>0.057</td><td>2.761</td></tr><tr><td>Step unrolling</td><td>0.076</td><td>0.324</td><td>0.075</td><td>0.324</td><td>0.085</td><td>2.844</td><td>0.056</td><td>2.700</td></tr></table>
432
+
433
+ We also considered the approach of self-conditioning [8] as an alternative to step-unrolling. However, as we show in Table 17, we find that self-conditioning is unable to bridge the train-inference distribution shift of the noisy latent for the task of monocular depth estimation. This is specially apparent in the results for KITTI without infilling where self conditioning leads to no improvement whereas step-unrolling substantially improves performance.
434
+
435
+ # H.4 Hyper-parameters
436
+
437
+ Self-supervised. The self-supervised model is trained for $2 . 8 \mathbf { M }$ steps with an $L _ { 2 }$ loss and a mini-batch size of 512. Other hyper-parameters are same as those in the original Palette paper [54].
438
+
439
+ Supervised. The supervised flow and depth models are trained with $L _ { 1 }$ loss. Usually a constant learning rate of $1 \times \dot { 1 } 0 ^ { - 4 }$ with a warm-up over 10k steps is used. However, for depth fine-tuning we find that a lower learning rate of $3 \times 1 0 ^ { - 5 }$ achieves slightly better results. All models are trained with a mini-batch size of 64. The indoor depth model is pre-trained for 2M steps and then fine-tuned on NYU for $4 0 \mathrm { k }$ steps. The outdoor depth model is pre-trained for $0 . 9 { \bf M }$ steps and fine-tuned on KITTI for 40k steps. For flow, we pretrain for $3 . 7 \mathbf { M }$ steps, followed by finetuning for 50k steps. Other details, like the optimizer and the use of EMA are the same as [54].
440
+
441
+ # H.5 Inference
442
+
443
+ Sampler. We use the DDPM ancestral sampler [21] with 128 denoising steps for monocular depth models and 64 steps for optical flow models. Increasing the number of denoising steps further did not greatly improve performance.
444
+
445
+ Coarse-to-fine refinement. We use $2 \times 5$ overlapping patches ({top, bottom} $\times$ {left, center-left, center, center-right, right}) for coarse-to-fine refinement. For Sintel we use $t ^ { \prime } = 3 2 / 6 4$ and for KITTI $t ^ { \prime } = 8 / 6 4$ .
446
+
447
+ # I Limitations
448
+
449
+ Table 18: Inference speed comparison of our method with DPT [50] on the indoor depth model finetuned on NYU. Diffusion model inference is bottlenecked by the large number of denoising steps. We show that some efficiency gains can be achieved by simply reducing the number of denoising steps. Our model with 24 denoising steps is comparable in performance to DPT while being ${ \sim } 5 \mathbf { x }$ slower (modulo differences in hardware). \* we use the step-time reported in the DPT paper at a resolution of $3 8 4 \times 3 8 4$ , however, the DPT performance metrics on NYU are with a model trained at a resolution of $4 8 0 \times 6 4 0$ , for which the step time will be higher.
450
+
451
+ <table><tr><td>Method</td><td>Architecture</td><td>Resolution</td><td>Total Time [ms]</td><td>Inference steps</td><td>REL↓</td><td>RMS↓</td></tr><tr><td>DPT-Hybrid</td><td>Nvidia RTX 2080</td><td>384×384*</td><td>38*</td><td>-</td><td>0.110</td><td>0.357</td></tr><tr><td rowspan="4">DDVM</td><td rowspan="4">TPU v4</td><td rowspan="4">240 × 320</td><td>204</td><td>24</td><td>0.104</td><td>0.378</td></tr><tr><td>272</td><td>32</td><td>0.086</td><td>0.342</td></tr><tr><td>544</td><td>64</td><td>0.077</td><td>0.324</td></tr><tr><td>1089</td><td>128</td><td>0.075</td><td>0.324</td></tr></table>
452
+
453
+ Efficiency. Inference speed with diffusion models is a well-known issue, as multiple denoising steps are used to transform noise to a target signal. This can be prohibitive for vision tasks where near real-time latency is often desired. Table 18 compares the inference speed of our diffusion model for depth against DPT [50]. Despite having an efficient denoiser backbone ( ${ \sim } 8 . 5$ ms per denoising step on a TPU v4), the diffusion model is considerably slower than DPT in total wall time. The most obvious way to reduce inference latency is to reduce the number of denoising steps. This can be done with only moderate reduction in performance. As shown in Table 18, we perform comparably with DPT with as few as 24 denoising steps. However, a more thorough study into optimizing the inference speed of these models while preserving the generation quality is warranted. With the use of progressive distillation [42, 56] it is likely possible to reduce latency even further, as this approach has been shown to successfully distill generative image models with over 1000 denoising steps into those with just 2-4 steps.
454
+
455
+ Fine-tuning on Sintel. In Section 5 we discuss possible reasons for why our model’s superior zeroshot performance compared to FlowFormer [23] does not transfer to fine-tuning on Sintel. Figure 16 provides qualitative examples to further support the claims.
456
+
457
+ ![](images/1934e1d086049ece1ca2800e7b4682ae30439a2fdd359ca5085485482ba25dd4.jpg)
458
+ Figure 16: Visual results on Sintel test. We compare with Flowformer [23] and provide flow visualization and an error map on each scene. On Ambush 1, FlowFormer can better predict the motion of the girl’s right arm that moves out of the image boundary, likely due to the global reasoning capability of attention. On Cave 3 and Market 1, our method provides much finer details on motion boundaries with lower end-point error (EPE).
459
+
460
+ ![](images/e4d3a72742ce37bcd0aba746bddd4ce120bc6b261a5eb6f1668ae4156c288559.jpg)
461
+ Figure 17: Qualitative examples of multimodal estimation on the NYU depth dataset showing examples where our model’s uncertainty gets captured in the multimodal posterior. In the examples above, the model confuses the play mat (farther away from the viewpoint) for a table (closer to the viewpoint).
462
+
463
+ Uncertainty in depth estimation. We observe certain cases where the model is uncertain about the depth estimates. Interestingly, this uncertainty appears to be well captured in the predictive posterior, as illustrated in Figure 17.
md/dev/mNMwIwydgr/mNMwIwydgr.md ADDED
The diff for this file is too large to render. See raw diff
 
md/dev/u6Xv3FuF8N/u6Xv3FuF8N.md ADDED
@@ -0,0 +1,332 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Flocks of Stochastic Parrots: Differentially Private Prompt Learning for Large Language Models
2
+
3
+ Haonan Duan∗ †, Adam Dziedzic†, Nicolas Papernot, Franziska Boenisch University of Toronto and Vector Institute
4
+
5
+ # Abstract
6
+
7
+ Large language models (LLMs) are excellent in-context learners. However, the sensitivity of data contained in prompts raises privacy concerns. Our work first shows that these concerns are valid: we instantiate a simple but highly effective membership inference attack against the data used to prompt LLMs. To address this vulnerability, one could forego prompting and resort to fine-tuning LLMs with known algorithms for private gradient descent. However, this comes at the expense of the practicality and efficiency offered by prompting. Therefore, we propose to privately learn to prompt. We first show that soft prompts can be obtained privately through gradient descent on downstream data. However, this is not the case for discrete prompts. Thus, we orchestrate a noisy vote among an ensemble of $L L M s$ presented with different prompts, i.e., a flock of stochastic parrots. The vote privately transfers the flock’s knowledge into a single public prompt. We show that LLMs prompted with our private algorithms closely match the non-private baselines. For example, using GPT3 as the base model, we achieve a downstream accuracy of $9 2 . 7 \%$ on the sst2 dataset with $( \varepsilon = 0 . 1 4 7 , \delta = 1 0 ^ { - 6 } )$ -differential privacy vs. $9 5 . 2 \%$ for the non-private baseline. Through our experiments, we also show that our prompt-based approach is easily deployed with existing commercial APIs.
8
+
9
+ # 1 Introduction
10
+
11
+ Large language models (LLMs) exhibit strong capabilities for in-context learning [6, 40]. By prepending the adequate prompt to an LLM’s input, the model can perform a myriad of natural language downstream tasks without any modifications to its parameters [41]. While the data used to train an LLM is usually assumed to be public, downstream data used in the prompt is often more sensitive. This can elicit confidentiality issues, for instance, if prompts contain information that represents valuable intellectual property [34]. At the same time, it also raises privacy concerns when the data involves personal information about individuals.
12
+
13
+ In this paper, our first contribution is to show that these concerns are valid. We are the first to instantiate a highly effective membership inference attack (MIA) [7, 45] against prompts. Our attack is able to determine if a given data point was used within the prompt of the LLM. The only existing solution to mitigate this privacy risk would be to forego prompting and instead fine-tune the LLM with a privacy-preserving training algorithm [25, 54]. Yet, fine-tuning lacks the efficiency and practicality of prompting. Indeed, fine-tuning requires significantly more data [42], computational resources [25], and storage space [26]. Additionally, fine-tuning requires access to the LLM parameters. However, many of the state-of-the-art LLMs are proprietary models deployed behind an API which only allows its users to query the LLMs [3, 6, 10, 17, 35].
14
+
15
+ ![](images/1ff48b5100728b33b009fbb4628b132e70f784c3dea38a553d764585b9712582.jpg)
16
+ Figure 1: Our methods for private prompt learning. Left: PromptDPSGD obtains the input gradients from the LLM, and performs DPSGD to update the soft prompt embedding while keeping the LLM frozen. Right: PromptPATE creates a noisy ensemble of private discrete prompts, and then transfers knowledge by selecting a student prompt that can be publicly released. PromptPATE only needs black-box access of the LLM and, thus, can be easily deployed with commercial APIs.
17
+
18
+ To leverage the benefits of prompting while at the same time protecting the data contained in prompts, we propose the first algorithms for prompt learning with privacy. Our algorithms offer rigorous guarantees expressed using differential privacy [15]. Perhaps closest to existing work on fine-tuning, we propose to leverage the canonical DPSGD algorithm [1] to learn soft promptswith differential privacy guarantees. Our PromptDPSGD algorithm performs a private gradient descent on the soft prompt embeddings prepended to the LLM’s private input. Since these embeddings have very few parameters in comparison to LLMs, our PromptDPSGD is efficient and yields competitive privacy utility trade-offs at a fraction of the training complexity of private fine-tuning.
19
+
20
+ However, learning soft prompts with DPSGD may not always be possible because it requires computing gradients with respect to the prompt input. As mentioned previously, current APIs [3, 6, 10, 17, 35] usually do not provide these gradients. We thus turn to discrete prompts which consist of natural language tokens. Discrete prompts address the aforementioned limitations while being more data-efficient. Our insight is to observe that LLMs with discrete prompts naturally lend themselves to another canonical approach of differentially private learning known as the private aggregation of teacher ensembles (PATE) [37]. We introduce PromptPATE, which creates an ensemble of LLMs with different discrete prompts from the private dataset which we refer to as a flock of stochastic parrots [5]. Since interacting with the flock directly can leak private information about the prompts, as we demonstrate with our MIA, PromptPATE additionally performs a knowledge transfer. Therefore, each model in the flock generates a next token prediction for a short input sequence of some public data. By performing a noisy majority vote over all models’ token output, we generate a single output that, due to the noise addition, implements differential privacy guarantees while incorporating knowledge from the flock. The public input together with the noisy aggregated output form a new single example for the discrete student prompt that can be prepended to the LLM in lieu of the individual prompts which contain private information. In addition to providing rigorous privacy guarantees, our PromptPATE is highly efficient, since, instead of having to query every model from the flock at inference time, it suffices to query the LLM prepended with the student prompt once.
21
+
22
+ We perform extensive experiments against multiple popular LLMs, such as GPT3 [6] and Claude [3], that are deployed behind commercial black-box APIs. Our results highlight that PromptPATE provides high downstream performance that matches the one of non-private prompting even at very strong privacy guarantees. On the sst2 dataset with GPT3, for instance, we reach an accuracy of $9 2 . 7 \%$ with privacy costs as little as $( \varepsilon = 0 . 1 4 7 , \delta = 1 0 ^ { - 6 } )$ -differential privacy, even when the public data used during PromptPATE’s knowledge transfer stem from a different distribution than sst2. Our results closely matches the non-private baseline accuracy $( 9 5 . 2 \% )$ . Thus, we conclude that prompt learning for LLMs is not only more efficient and practical than fine-tuning but can also achieve high utility even with strong and practical privacy protection in place.
23
+
24
+ In summary, we make the following contributions:
25
+
26
+ • We instantiate the first MIA on prompted LLMs and show that we can effectively infer membership of the prompted data points with high success. • We propose a lightweight alternative to DP fine-tuning, namely PromptDPSGD, which optimizes orders of magnitude fewer parameters while keeping the original LLM frozen. • We propose PromptPATE, the first method for DP learning with LLMs that requires only black-box access to the model—making it easily deployable for commercial LLM APIs. • Our experiments on multiple state-of-the-art commercial APIs [6, 3] highlight that our methods achieve both high utility and strong privacy protections in various setups.
27
+
28
+ # 2 Background and Related Work
29
+
30
+ Prompts for LLMs. The success of LLMs, such as BERT, Claude, OPT, or different versions of GPT and their exceptional in-context learning capacities gave rise to prompt-based learning [14, 6, 39, 40, 35, 56]. Prompts serve as demonstrations of the downstream task, which the model can then generalize from. There are two paradigms for LLM prompting, namely discrete and soft prompts.
31
+
32
+ Discrete prompts [6, 16, 18, 27, 44] are natural-language instructions that contain examples from the downstream task in a well-crafted template. Tuning discrete prompts is often done by prompting the model with different combination of examples, assessing their performance on the downstream task, and choosing the combination that yields the highest performance as the final prompt.
33
+
34
+ In contrast to discrete prompts, soft prompts [24, 27] prepend trainable continuous embeddings to the inputs of LLMs. These embeddings are initialized either at random or with embedding vectors that correspond to tokens from the dictionary. During tuning, the embeddings are updated through gradient descent to minimize the loss of the prompted model on the private downstream task. To increase performance further, trainable embeddings can be prepended not only to the input but also to every LLM layer, a technique known as prefix [26, 28, 29].
35
+
36
+ Both soft prompts and prefix train end-to-end without any human involvement through backpropagation over the LLM. On the other hand, discrete prompts have to be designed manually through careful prompt engineering. Yet, prompt engineering only needs inference passes over the LLM which makes discrete prompt more computationally lightweight. Our work provides privacy protection for all of these paradigms: discrete prompts, as well as for soft prompts, and prefix.
37
+
38
+ Privacy Leakage in LLMs. LLMs have been shown to memorize data both from their original large training corpora [8, 20, 23, 32, 48, 55] and from smaller private datasets used to fine-tune them for downstream tasks [33]. The only prior work around privacy leakage in prompt-based learning utilizes prompts to extract knowledge from trained LLMs [13, 22, 38]. In contrast, we study the privacy of the prompting data itself. To do so, we investigate the canonical privacy attack known as membership inference attacks (MIA) [7, 45]. Its use as a practical means to demonstrate leakage of private information in ML was recently popularized by a line of work on quantifying memorization [9, 43, 47]. While prior work utilizes MIAs to assess whether a given data point was used to train an LLM, we instantiate a MIA to assess whether a given data point was used within the prompt prepended to the inputs of a trained LLM.
39
+
40
+ Defending Against Privacy Leakage in LLMs. Prior work either focuses on training [2, 19] or fine-tuning [25, 54] LLMs with privacy guarantees. These approaches rely on the mathematical framework of differential privacy (DP) [15] and in particular the DPSGD algorithm for private stochastic gradient descent [1]. Here, DPSGD is applied to guarantee that one outputs approximately the same model parameters whether or not any given data point was used to train or fine-tune the model. To achieve this, DPSGD clips the per-example gradients that are computed during training and adds well-calibrated noise to each model update. These two operations typically increase the computational complexity of training and decrease the utility of the resulting model [1, 4, 49]. To counteract these effects, state-of-the-art methods for full DP-fine tuning in LLMs require extensive hyperparameter tuning and vast computational resources [25]. Alternative approaches refrain from updating the large number of model parameters and instead introduce additional layers into the model architecture and only fine-tune these layers with DPSGD [54]. To the best of our knowledge, no prior work attempted to provide DP guarantees for prompt data in LLMs.
41
+
42
+ ![](images/6efd59d910862e96a4abe9e40c3b60776305e47fcae550e6f1f55befc1d50136.jpg)
43
+ Figure 2: MIA Risk. We study GPT3 prompted with 100 different one-shot examples (dbpedia). left: We present the prediction probabilities at the correct class for members (the one-shot example) and non-members (50 randomly sampled private points). The output probability for members is significantly higher than for non-member data points. right: We present the AUC-ROC curves of our MIA against the 100 prompts (gray lines) and the blue line as an average over all attacks. Given that each prompt has only one member, the resulting TPRs can only be $0 \%$ or $100 \%$ which leads to the step-shape of the gray curves. The result indicates that our attack is significantly more successful than random guessing (the red dashed line).
44
+
45
+ Setup and Notation. We denote by $P$ the soft or discrete prompt that is prepended to any input sequence $x _ { i }$ when querying the language model $L$ . For brevity, we denote $\bar { L } ( [ P , x _ { i } ] )$ by $\bar { L _ { P } ( x _ { i } ) }$ . 3 The output $y _ { i }$ of $L _ { P } ( x _ { i } )$ is an $M$ -dimensional probability vector, with $M$ being the size of the model’s vocabulary. Each component of $y _ { i }$ corresponds to the probability that the $L _ { P }$ assigns to the respective token for being the next token in the sequence $x _ { i }$ . The semantic meaning of the next token varies depending on the given downstream task. For instance, for classification, the index with the highest probability indicates the token of the class that $L _ { P }$ assigns to $x _ { i }$ .
46
+
47
+ # 3 Private Information about Prompt Data Leaks from Prompted LLMs
48
+
49
+ By instantiating a MIA against prompted LLMs, we want to highlight that the private data used within a prompt (which we refer to as prompt data from hereon) can be subject to a substantial privacy risk. We showcase this risk at the example of LLMs that are prompted with discrete prompts $P$ containing tuples of demonstrations from classification downstream tasks as prompt data $p = \{ ( p _ { x } , p _ { y } ) \}$ . For example, in a prompt with one demonstration (one-shot learning), the prompt data $p$ may be specified as $p = \{ ($ ("The movie was great.", "positive")}. Our prompts are provided in a consistent template where one or multiple demonstrations are combined with instructions as $P = l$ [Instruction, (text sequence $p _ { x }$ , class-label token $p _ { y } ) , \ldots I$ .
50
+
51
+ For our MIA, we consider an adversary who aims at inferring whether a given private demonstration $( p _ { x } , p _ { y } )$ was used within the prompt data $p$ . The adversary holds $n$ candidate demonstrations of text sequences and corresponding labels $l _ { i }$ and queries the text sequences $( x _ { 1 } , \cdots , x _ { n } )$ to $L _ { P }$ with black-box access. The prompted model $L _ { P }$ then returns the output probability vectors $( y _ { 1 } , \cdots , y _ { n } )$ . Following prior work [21, 53], we analyze the model’s output probability at token $y _ { i , l _ { i } }$ that corresponds to the correct target class label of every $x _ { i }$ . The intuition to distinguish between members and non-members is that the output probabilities at the correct class $l _ { i }$ will be significantly higher for demonstrations that were used within the prompt, i.e., members with $\left( p _ { x } , p _ { y } \right) { \overset { \cdot } { = } } \left( x _ { i } , l _ { i } \right)$ . We show that even with this simple MIA, we can reliably determine membership for the prompt data.
52
+
53
+ Experimental Setup. We prompt GPT3-Babbage [6] with multiple one-shot examples to solve four standard downstream text classification tasks, namely dbpedia [57], sst2 [46], agnews [57] and trec [50]. The template of our prompts follows [58]. To evaluate our MIAs, we consider the single data point used within the prompt as a members and 50 other randomly selected data points from the respective task’s training dataset as non-members. This skewed distribution between members and non-members (1 vs 50) corresponds to a realistic scenario where only a small proportion of the candidate data targeted by the adversary are members [21]. To quantify the success of our attack, we report the AUC-ROC curves of 100 random trials.
54
+
55
+ Results. Before evaluating the success of the MIA, we analyze the probability output from GPT3 for the correct target class between member and non-member data points. Figure 2a shows for the dbpedia dataset that the prediction probabilities for non-members are significantly lower than for members. Figure 2b shows that this leads to a high MIA risk in terms of an average AUC score of 0.84 for the prompt data. Similar results for other datasets and models are presented in Appendix D. These results highlight that private information can leak from prompt data easily and thus motivate the urgent need for defenses which we develop in the rest of this paper.
56
+
57
+ # 4 Methods for Privacy Preserving Prompts
58
+
59
+ As of now, if we want to protect the private downstream data, we have to forego prompting altogether because, to the best of our knowledge, no algorithms for private prompt learning exist. The only alternative to privately adapt the LLM would be to perform DP fine-tuning [25, 54]. However, this approach is only feasible when we have direct access to the LLM to update its parameters with DPSGD [25] or to even change the model architecture to insert additional parameters—fine-tuned with DPSGD [54]. This is prohibitively expensive and mostly impossible with the commercial API, thus we propose the first algorithms that enable differentially private prompt learning.
60
+
61
+ We consider two main paradigms of prompting: soft prompts and discrete prompts. To learn private soft prompts, we introduce PromptDPSGD. PromptDPSGD is a parameter-efficient alternative to DP fine-tuning that does not need modifying the parameters or architectures of the LLM. However, many popular APIs [3, 6, 10, 17, 35] do not support soft prompts yet as it requires gradients with respect to the input. Therefore, we propose PromptPATE for discrete prompts. PromptPATE requires only black-box access to an LLM without any knowledge of the LLM’s architecture or mode of operation. Instead, the algorithm only needs the next-token prediction of the LLM. This, to our knowledge represents the first solution for privately adapting LLMs in restricted API setups.
62
+
63
+ # 4.1 PromptDPSGD: DPSGD for Private Soft Prompt Learning
64
+
65
+ In general, all discrete input tokens to LLMs are internally transformed into continuous input embeddings that the LLM then operates on. Soft prompts are just additional continuous input embeddings that can be prepended to the original input embeddings before passing them through the LLM. To train (or tune) soft prompts, we require training data from a potentially private downstream task. After prepending the continuous soft prompt embeddings to input examples from the training data, we can calculate the gradients for the loss of the prompted LLM with respect to these soft prompt embeddings. The gradients provide information about how the soft prompt should be updated in order to minimize the loss on the training data.
66
+
67
+ If we can obtain the gradients for soft prompts, we can learn these prompts with privacy guarantees by applying the canonical DPSGD algorithm [1]. The same applies to prefix, therefore, when we talk about soft prompts in the following, we implicitly also include prefix. We call this approach PromptDPSGD. The algorithm yields soft prompts with DP guarantees that can be deployed with the LLM to solve the respective downstream task. The privacy analysis of PromptDPSGD follows the one of the standard DPSGD. Note, however, that while conceptually similar to fine-tuning the LLM’s parameters with DPSGD [54, 25], PromptDPSGD differs in a crucial aspect. In DP-SGD fine-tuning, we require the gradients with respect to all or a subset of the model parameters and update these parameters to minimize the loss. In contrast, in PromptDPSGD, we use the gradients with respect to the soft prompt embeddings and only alter these. We highlight this difference in our PromptDPSGD-algorithm that we present in Appendix C.
68
+
69
+ While this difference seems subtle, it has far-reaching consequences. First, there are orders of magnitude fewer parameters that need to be updated which increases training efficiency. Second, and most importantly, it allows us to keep operating on the original LLM. We discuss the resulting advantages, such as storage efficiency, and the ability to process multiple different tasks simultaneously at the end of this section (in 4.3). These advantages make PromptDPSGD conceptually superior to private fine-tuning. At the same time, as we show in our evaluation, despite the small number of trainable parameters, PromptDPSGD, for simpler tasks, matches the performance of private fine-tuning. Yet, current APIs [3, 6, 10, 17, 35] do not support soft prompting, prefix, or private fine-tuning and only provide black-box access through discrete prompts. For these setups, we propose PromptPATE.
70
+
71
+ # 4.2 PromptPATE: PATE for Privacy Preserving Discrete Prompts
72
+
73
+ PATE [36, 37] enables learning classifiers with DP guarantees. It first trains an ensemble of teacher models on disjoint subsets of the private data. Second, through a noisy labeling process, the ensemble privately transfers its knowledge to an unlabeled public dataset. Finally, a separate student model is trained on this labeled public dataset for release. The noisy knowledge transfer in the second step relies on the Confident GNMAX algorithm [37] that we detail in Appendix C. It consists of three main parts: for any input data point from the public unlabeled dataset, each teacher votes for the most likely class. Then, the consensus over the teachers’ votes is determined and queries with low consensus are rejected to avoid revealing too much information about the private decision boundary. Finally, the returned class label for any non-rejected data point is determined as a noisy argmax over all teachers’ vote counts—where the added noise is sampled from a Gaussian distribution to implement the DP guarantees. For each rejected or labeled data point from the public dataset, privacy costs are accumulated and the ensemble stops labeling once a target privacy budget is reached.
74
+
75
+ Our PromptPATE follows the general flow of standard PATE: training the teacher models, private knowledge transfer, and training a student model. However, due to the significant differences between in-context learning for LLMs and supervised learning in the original PATE and how these different paradigms leverage private and public data, we had to redesign each of these building blocks. This allows to leverage both the data-efficiency of prompts and the rigorous privacy protection from PATE. In the following, we present the building blocks in our PromptPATE.
76
+
77
+ Teacher Models (Flock of Stochastic Parrots). Instead of training teacher models on disjoint partitions of the private data, we use the private data to create disjoint prompts for the LLM. More specifically, we use examples, for instance {("The movie was great.", "positive"), ...}, from the private training data to create prompts that can then be deployed with the LLM as teachers.
78
+
79
+ Private Knowledge Transfer. During the private knowledge transfer, the teachers label public data sequences, such as ("I did enjoy it.", _). Each teacher votes with the most likely class labels for the private downstream task. In Appendix D, we show that PromptPATE can also operate directly on pure next token predictions from Claude [3] without access to per-token probabilities—enabling full black-box private prompts. By performing the private voting process according to standard PATE with the Confident GNMAX algorithm, we turn our per-teacher predictions into a final class label token that will be appended to the sequence, e.g., ("I did enjoy it", "positive"). The privacy accounting and analysis of our PromptPATE exactly follows the one of standard PATE [37].
80
+
81
+ Student. The most naive way to obtain a student model following standard PATE would be to label many public sequences and train a language classifier using supervised learning on this data. However, due to the relatively high number of data needed for supervised learning, and the fact that each query to the private teachers consumes privacy, this process would incur high privacy costs. We propose a better approach building on the data-efficiency of prompting [42] by using labeled public sequences to create new discrete student prompts. The selected prompt can then be deployed with the LLM as the PromptPATE student model.
82
+
83
+ In theory, labeling one public sequence by the ensemble would be sufficient to create such a prompt. This approach yields negligible privacy costs, but the resulting prompt might not have good utility due to the high variance in the performance of prompts [58]. Therefore, we generate multiple prompts based on different labeled public sequences and perform prompt tuning to select the best student prompt. Care must be taken during selection: utility cannot be evaluated on the private data anymore given that the prompt will be publicly deployed and selecting based on the private data would incur additional privacy costs. We solve this tension by using parts of the newly-labeled public data as validation data to assess utility of the student prompts. By selecting the prompt with the highest validation accuracy, we deploy the student prompt that most resembles the private teachers.
84
+
85
+ # 4.3 Advantages of (Private) Prompting over (Private) Fine-Tuning
86
+
87
+ Our private prompt learning enables us to leverage the general advantages of prompting over finetuning while preserving privacy. Private prompting requires significantly less storage than private fine-tuning. While fine-tuning requires storing a separate copy of the LLM model for each downstream task [24], prompts operate only on the input level of LLMs without adapting model parameters, such that only a small task-specific prompt needs to be stored for each downstream task. For example, each copy of the fine-tuned RoBERTa base model requires 125M parameters $\sim 5 0 0 \mathbf { M B }$ ). This becomes prohibitively expensive, especially as the number of parameters for state-of-the-art LLMs rapidly increases. In contrast, soft-prompts and prefix, as the one generated by PromptDPSGD (using implementation from [29]) with the standard prompt length of 10 tokens require less than 10K parameters (40KB) for the soft-prompt and 100K parameters (400KB) for the prefix. A discrete prompt, such as the one generated in PromptPATE, requires less than 1 KB of prepended text. Prompts also enable processing many examples from different tasks in a single batch [26], called mixed-task inference. This allows more efficient use of LLMs since we do not have to wait for a sufficient number of requests for a single task before processing them. This is not possible with any form of fine-tuning, where the fine-tuned model can serve solely a single task.
88
+
89
+ <table><tr><td rowspan="3">Dataset</td><td>M P</td><td colspan="2">Soft-Prompt (Our)</td><td colspan="2">Prefix (Our)</td><td colspan="2">Full-Tuning [25]</td><td colspan="2">LoRA-Tuning [54]</td></tr><tr><td></td><td colspan="2">&lt;10K</td><td colspan="2">&lt;100K</td><td colspan="2">125M</td><td colspan="2">1.2M</td></tr><tr><td>G</td><td>m=8</td><td>m=8</td><td>m=8</td><td>m=8</td><td>m=8</td><td>m=8</td><td>m=8</td><td>m=8</td></tr><tr><td>sst2</td><td></td><td>92.31</td><td>95.64</td><td>91.97</td><td>96.33</td><td>85.89</td><td>96.40</td><td>92.97</td><td>96.60</td></tr><tr><td>qnli</td><td></td><td>84.11</td><td>89.48</td><td>87.17</td><td>94.84</td><td>84.81</td><td>94.70</td><td>88.59</td><td>94.70</td></tr><tr><td>qqp</td><td></td><td>81.52</td><td>86.56</td><td>82.58</td><td>91.42</td><td>86.15</td><td>92.20</td><td>86.26</td><td>92.20</td></tr><tr><td>mnli</td><td></td><td>75.15</td><td>82.49</td><td>80.57</td><td>90.34</td><td>83.30</td><td>90.20</td><td>82.92</td><td>90.20</td></tr></table>
90
+
91
+ Table 1: Performance of PromptDPSGD. We report the accuracy values $( \% )$ for each dataset. All $\varepsilon$ values are reported as standard DP guarantees. We run the experiment on RoBERTa [30]. The first row M: the type of the private Method, the second row P: the number of Parameters tuned for the method, and the third row G: DP Guarantee. We also present results for $\varepsilon = 3$ in Appendix D.
92
+
93
+ # 5 Experimental Evaluation
94
+
95
+ We evaluate both PromptDPSGD and PromptPATE and show that they match the performance of non-private prompting while providing strong privacy guarantees.
96
+
97
+ # 5.1 PromptDPSGD
98
+
99
+ Experimental Setup. To train soft-prompts and prefix, we follow the experimental setup from prior work on DP fine-tuning. Specifically, we use differentially-private optimization engines for transformers, such as models from the BERT family for the language understanding tasks. The experimental results for classification were performed on the RoBERTa models [30], using the standard NLP datasets, namely sst2, qnli, qqp, and mnli, from the GLUE benchmark [51]. Our implementation for soft-prompt and prefix is based on P-Tuning v2 [29]. To tune the (hyper)parameters for PromptDPSGD, we adjust the length of the soft-prompt or prefix in the private setting (with the default value of 10, which commonly yields good performance). For the privacy parameters, we set the $\delta = 1 / N$ , where $N$ is the number of data points in a given dataset, The clipping threshold of per-example gradients is set to 0.1 in most cases. We use a batch size of 1024. The detailed selection of (hyper-)parameters is presented in Appendix E.
100
+
101
+ Results. We compare our PromptDPSGD against state-of-the-art approaches for private finetuning on multiple private downstream datasets. Our results are shown in Table 1. We highlight that both soft prompts and prefix provide competitive privacy utility trade-offs. For example, the difference in accuracy values between the non-private baseline and the private soft prompt ranges from $3 \%$ (for the simplest sst2 dataset) and up to $7 \%$ (for the most difficult mnli dataset). This mirrors results for other private methods, such as the private fine-tuning of LoRA [54]. We also observe that, similarly, for simple tasks, such as sst2 or qnli, the performance of soft prompt or prefix matches the one of fine-tuning. For the more difficult tasks, namely qqp and mnli, the performance of prefix and soft prompts is also relatively close to fine-tuning. The results obtained for these methods are highly influenced by the number of optimized parameters. For example, for the SST2 task and the RoBERTa-Base model, the prefix requires 19970 additional parameters while soft prompt adds solely 2306 parameters. On the other hand, the number of privately tuned parameters is a few orders of magnitude bigger for fine-tuning and equal to the size of the trained model, namely 125M for the method proposed in [25], while the fine-tuning approach from [54] optimizes around 1.2M parameters. Our results reflect a general trend, where prompts are suited for small downstream tasks while fine-tuning with its bigger number of parameters can also cater to more complex tasks with larger training data sets.
102
+
103
+ Table 2: Performance of PromptPATE. We compare PromptPATE with three baselines: zero-shot (Lower Bound), the ensemble’s accuracy (Ens. Acc), and the non-private baseline (Upper Bound) on four classification benchmarks. We study two settings, (IID Transfer) when the public dataset is from the same and (OOD Transfer) different distribution than the private data. We find that PromptPATE achieves strong privacy protection $\varepsilon < 0 . 3$ at $\delta = 1 0 ^ { - 6 }$ ) and utility close to the non-private and significantly higher than the zero-shot. Unless otherwise specified, the experiments are performed on GPT3-Babbage with one-shot prompts. Additionally, we also run experiments on GPT3-Curie for sst2 (C) and 4-shot prompts for agnews (4).
104
+
105
+ <table><tr><td rowspan="3">Private</td><td rowspan="2">Lower Bound</td><td rowspan="2">Ens. Acc.</td><td rowspan="2">Upper Bound</td><td colspan="6">Our PromptPATE</td></tr><tr><td colspan="3">ID Transfer</td><td colspan="3">OOD Transfer</td></tr><tr><td>m=0</td><td>m=8</td><td>m=8</td><td>Public</td><td>E</td><td>Test acc</td><td>Public</td><td>m</td><td>Test acc</td></tr><tr><td>sst2</td><td>76.3</td><td>90.0</td><td>93.8</td><td>sst2</td><td>0.178</td><td>88.8±2.3</td><td>imdb</td><td>0.187</td><td>87.2±1.9</td></tr><tr><td>agnews</td><td>62.0</td><td>72.8</td><td>78.2</td><td>agnews</td><td>0.248</td><td>71.7±0.8</td><td>arisetv</td><td>0.258</td><td>67.9±1.7</td></tr><tr><td>trec</td><td>40.7</td><td>57.6</td><td>58.7</td><td>trec</td><td>0.281</td><td>52.8 ±1.5</td><td>qqp</td><td>0.293</td><td>50.9±3.5</td></tr><tr><td>dbpedia</td><td>44.2</td><td>81.6</td><td>85.6</td><td>dbpedia</td><td>0.194</td><td>80.3 ±1.3</td><td>agnews</td><td>0.203</td><td>74.6±1.4</td></tr><tr><td>sst2(C)</td><td>82.0</td><td>94.0</td><td>95.2</td><td>sst2</td><td>0.147</td><td>92.3 ±1.1</td><td>imdb</td><td>0.154</td><td>92.7±0.8</td></tr><tr><td>agnews (4)</td><td>62.0</td><td>75.8</td><td>81.0</td><td>agnews</td><td>0.145</td><td>73.5 ±1.2</td><td>arisetv</td><td>0.145</td><td>69.6 ±1.8</td></tr></table>
106
+
107
+ # 5.2 PromptPATE
108
+
109
+ Experimental Setup. Teachers: Unless otherwise specified, we rely on GPT3-Babbage as the base LLM and select one-shot examples randomly without replacement from the private downstream task as prompt data. Our prompt template follows Zhao et al. [58]. For each setting, we deploy 200 teacher prompts. Private knowledge transfer: We use the implementation of PATE’s Confident GNMAX algorithm and the privacy accounting from [12] and report our algorithm’s hyperparameters in Appendix E. Student: For each private downstream task, we experiment with two setups (1) selecting public input sequences from the same (IID) and (2) from a different distribution (OOD) as the private data. We introduce three new datasets for the OOD setup: imdb [31], arisetv [11] and qqp [52]. The details of preprocessing these datasets can be found in Appendix E. In both the IID and OOD setup, we limit the size of the public dataset to 500 input sequences from the respective datasets. After the ensemble finishes labelling, we select the best labeled public sequence as prompt data based on the validation accuracy on the labeled public set. We repeat the process three times and report average and standard deviation of the test accuracy for the selected student prompt on the private test set. To improve utility, both teachers’ and students’ output probabilities from GPT3 are recalibrated using contexual calibration [58].
110
+
111
+ Results. We compare PromptPATE against three baselines: the lower bound baseline represented by a zero-shot prediction $( \varepsilon = 0$ ), i.e., when the LLM is only prompted with an instruction, the private ensemble accuracy $\varepsilon = \infty$ ), and the upper bound as a non-private one-shot prediction $\varepsilon = \infty$ ) using the best example from the private data as prompt data. (To save costs, we select from 200 candidates.) Table 2 shows that, over all setups, PromptPATE achieves similar utility to the non-private baseline and significantly improves over zero-shot predictions—even at very strong privacy protection $\varepsilon < 0 . 3$ , $\delta \stackrel { - } { = } 1 0 ^ { - 6 }$ ). Our results also highlight that the distribution of the public data does not need to be very close to the distribution of the private data to yield high-utility student prompts. For example, they can be collected from different domains (dbpedia holds extracts from wikipedia while its public data agnews contains news articles) and for different tasks (trec aims to classify the topic of a given answer while qqp serves to measure the similarity of two questions). Still, with dbpedia being the private downstream data and agnews as public, we achieve an accuracy of $7 4 . 6 \%$ , which is significantly higher than the zero-shot baseline with $4 4 . 2 \%$ .
112
+
113
+ We also provide further insights into the privacy-utility trade-offs that can be achieved with PromptPATE in Figure 3b. Our results highlight that with more public sequences queried to the ensemble, the privacy consumption increases while, after roughly 100 queries, with even $\varepsilon < 0 . 2$ , the student model’s test accuracy saturates. This yields very favorable privacy-utility trade-offs which we attribute mainly to the data efficiency of discrete prompts: Even from within as little as 100 labeled examples, a high-performing student prompt can be derived. Additionally, we observe that the per-query privacy costs of PromptPATE are relatively low, further benefiting the privacy-utility trade-off. The small privacy costs result from the high consensus between the teacher predictions4, see Figure 3a—that might result from all teachers relying on the same underlying LLM, just with different prompts.
114
+
115
+ ![](images/b355be815b98bf95c8e22ec77c8fd135923963e28ad02462e695596a0d041a6a.jpg)
116
+ Figure 3: Additional Insights of PromptPATE. We perform ablation studies on GPT3-Babbage and use dbpedia as private and agnews as public data. Left: Teacher consensus as the fraction of teachers who vote for the correct class over 500 public input sequences. PromptPATE achieves overall high consensus. Right: Student accuracy as a function of the public query set’s size. Already with as few as 100 queries, we observe a plateau in accuracy which highlights PromptPATE’s data efficiency.
117
+
118
+ Scalability. Finally, we also study how PromptPATE scales with larger LLMs and more examples in the prompt. We experiment with a more performant LLM (GPT3-Currie) for sst2. Due to the higher per-query costs, we are not able to repeat this experiment for all datasets. Our results show that the performance of our private prompt increases together with the performance of the public prompt $( 9 2 . 7 \%$ accuracy on Curie vs. $8 7 . 2 \%$ on Babbage) while the privacy budget $\epsilon$ decreases (from 0.178 to 0.147). To investigate flexibility in terms of numbers of private examples provided as prompt data, we also experiment for agnews with 4-shot teachers. Similar to the non-private study [58] that reports improvements for agnews in the 4-shot setting over 1-shot, we observe that this improvement also translates to the private prompt. Our results indicate that with increasingly more powerful LLMs and larger context windows, private prompting will increase further in terms of privacy-utility trade-offs.
119
+
120
+ # 6 Conclusions and Outlook
121
+
122
+ By instantiating the first simple yet effective membership inference attack against prompted LLMs, we show that they leak private information about their prompt data. We propose private prompt learning as a holistic and broadly applicable new approach to mitigate this risk. We first introduce PromptDPSGD that enables to train soft-prompts with privacy guarantees. In contrast to finetuning, soft prompts optimize significantly fewer parameters and do not require any update of LLM parameters or changes to its architecture. As the first solution to private downstream learning with LLMs in black-box access scenarios, we propose PromptPATE. PromptPATE builds on the highly data-efficient discrete prompts and implements privacy through a noisy knowledge transfer. Through our evaluation against two popular LLMs deployed behind commercial black-box APIs (GPT3 and Claude) [6, 3], we highlight that this method yields downstream performance that matches the one of non-private prompting at very strong privacy guarantees. As LLMs rapidly improve and increase in size, prompts are achieving consistently higher performance while fine-tuning becomes more challenging at this scale. This suggests that privacy protections for prompts will become even more important, especially as context sizes expand.
123
+
124
+ # Acknowledgments
125
+
126
+ We would like to acknowledge our sponsors, who support our research with financial and in-kind contributions: Amazon, Apple, CIFAR through the Canada CIFAR AI Chair, DARPA through the
127
+
128
+ GARD project, Intel, Meta, NSERC through a Discovery Grant, the Ontario Early Researcher Award, and the Sloan Foundation. Resources used in preparing this research were provided, in part, by the Province of Ontario, the Government of Canada through CIFAR, and companies sponsoring the Vector Institute. We also thank members of the CleverHans Lab for their feedback.
129
+
130
+ # References
131
+
132
+ [1] M. Abadi, A. Chu, I. Goodfellow, H. B. McMahan, I. Mironov, K. Talwar, and L. Zhang. Deep learning with differential privacy. In Proceedings of the 2016 ACM SIGSAC conference on computer and communications security, pages 308–318, 2016.
133
+ [2] R. Anil, B. Ghazi, V. Gupta, R. Kumar, and P. Manurangsi. Large-scale differentially private bert. arXiv preprint arXiv:2108.01624, 2021.
134
+ [3] Antropic. Introducing claude. Antropic Website. 2023-03-14, https://www.anthropic. com/index/introducing-claude.
135
+ [4] R. Bassily, A. Smith, and A. Thakurta. Private empirical risk minimization: Efficient algorithms and tight error bounds. In 2014 IEEE 55th annual symposium on foundations of computer science, pages 464–473. IEEE, 2014.
136
+ [5] E. M. Bender, T. Gebru, A. McMillan-Major, and S. Shmitchell. On the dangers of stochastic parrots: Can language models be too big? In Proceedings of the 2021 ACM Conference on Fairness, Accountability, and Transparency, FAccT ’21, page 610–623, New York, NY, USA, 2021. Association for Computing Machinery.
137
+ [6] T. Brown, B. Mann, N. Ryder, M. Subbiah, J. D. Kaplan, P. Dhariwal, A. Neelakantan, P. Shyam, G. Sastry, A. Askell, et al. Language models are few-shot learners. Advances in neural information processing systems, 33:1877–1901, 2020.
138
+ [7] N. Carlini, S. Chien, M. Nasr, S. Song, A. Terzis, and F. Tramer. Membership inference attacks from first principles. In 2022 IEEE Symposium on Security and Privacy (SP), pages 1897–1914. IEEE, 2022.
139
+ [8] N. Carlini, D. Ippolito, M. Jagielski, K. Lee, F. Tramer, and C. Zhang. Quantifying memorization across neural language models. arXiv preprint arXiv:2202.07646, 2022.
140
+ [9] N. Carlini, F. Tramer, E. Wallace, M. Jagielski, A. Herbert-Voss, K. Lee, A. Roberts, T. Brown, D. Song, U. Erlingsson, et al. Extracting training data from large language models. In 30th USENIX Security Symposium (USENIX Security 21), pages 2633–2650, 2021.
141
+ [10] H.-T. Cheng and R. Thoppilan. Lamda: Towards safe, grounded, and high-quality dialog models for everything. Google Blog Post. 2023-05-09, https://ai.googleblog.com/2022/01/ lamda-towards-safe-grounded-and-high.html.
142
+ [11] O. chimaobi Samuel. news-data. Huggingface, 2022.
143
+ [12] C. A. Choquette-Choo, N. Dullerud, A. Dziedzic, Y. Zhang, S. Jha, N. Papernot, and X. Wang. Capc learning: Confidential and private collaborative learning. In International Conference on Learning Representations, 2021.
144
+ [13] J. Davison, J. Feldman, and A. M. Rush. Commonsense knowledge mining from pretrained models. In Proceedings of the 2019 conference on empirical methods in natural language processing and the 9th international joint conference on natural language processing (EMNLPIJCNLP), pages 1173–1178, 2019.
145
+ [14] J. Devlin, M.-W. Chang, K. Lee, and K. Toutanova. Bert: Pre-training of deep bidirectional transformers for language understanding. arXiv preprint arXiv:1810.04805, 2018.
146
+ [15] C. Dwork. Differential privacy. In Automata, Languages and Programming: 33rd International Colloquium, ICALP 2006, Venice, Italy, July 10-14, 2006, Proceedings, Part II 33, pages 1–12. Springer, 2006.
147
+ [16] T. Gao, A. Fisch, and D. Chen. Making pre-trained language models better few-shot learners. arXiv preprint arXiv:2012.15723, 2020.
148
+ [17] Google. Lamda: Towards safe, grounded, and high-quality dialog models for everything. Website, 2023. 2023, https://bard.google.com/.
149
+ [18] H. Guo, B. Tan, Z. Liu, E. Xing, and Z. Hu. Efficient (soft) q-learning for text generation with limited good data. In Findings of the Association for Computational Linguistics: EMNLP 2022, pages 6969–6991, 2022.
150
+ [19] S. Hoory, A. Feder, A. Tendler, S. Erell, A. Peled-Cohen, I. Laish, H. Nakhost, U. Stemmer, A. Benjamini, A. Hassidim, et al. Learning and evaluating a differentially private pre-trained language model. In Findings of the Association for Computational Linguistics: EMNLP 2021, pages 1178–1189, 2021.
151
+ [20] D. Ippolito, F. Tramèr, M. Nasr, C. Zhang, M. Jagielski, K. Lee, C. A. Choquette-Choo, and N. Carlini. Preventing verbatim memorization in language models gives a false sense of privacy. arXiv preprint arXiv:2210.17546, 2022.
152
+ [21] B. Jayaraman, L. Wang, K. Knipmeyer, Q. Gu, and D. Evans. Revisiting membership inference under realistic assumptions. Proceedings on Privacy Enhancing Technologies, 2021(2), 2021.
153
+ [22] Z. Jiang, F. F. Xu, J. Araki, and G. Neubig. How can we know what language models know? Transactions of the Association for Computational Linguistics, 8:423–438, 2020.
154
+ [23] E. Kharitonov, M. Baroni, and D. Hupkes. How bpe affects memorization in transformers. arXiv preprint arXiv:2110.02782, 2021.
155
+ [24] B. Lester, R. Al-Rfou, and N. Constant. The power of scale for parameter-efficient prompt tuning. In Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing, Nov. 2021.
156
+ [25] X. Li, F. Tramer, P. Liang, and T. Hashimoto. Large language models can be strong differentially private learners. In International Conference on Learning Representations, 2022.
157
+ [26] X. L. Li and P. Liang. Prefix-tuning: Optimizing continuous prompts for generation. In Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing (Volume 1: Long Papers), pages 4582–4597, 2021.
158
+ [27] J. Liu, D. Shen, Y. Zhang, B. Dolan, L. Carin, and W. Chen. What makes good in-context examples for gpt-3? arXiv preprint arXiv:2101.06804, 2021.
159
+ [28] X. Liu, K. Ji, Y. Fu, W. Tam, Z. Du, Z. Yang, and J. Tang. P-tuning: Prompt tuning can be comparable to fine-tuning across scales and tasks. In Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 2: Short Papers), pages 61–68, Dublin, Ireland, May 2022. Association for Computational Linguistics.
160
+ [29] X. Liu, K. Ji, Y. Fu, W. L. Tam, Z. Du, Z. Yang, and J. Tang. P-tuning v2: Prompt tuning can be comparable to fine-tuning universally across scales and tasks. arXiv preprint arXiv:2110.07602, 2021.
161
+ [30] Y. Liu, M. Ott, N. Goyal, J. Du, M. Joshi, D. Chen, O. Levy, M. Lewis, L. Zettlemoyer, and V. Stoyanov. Ro{bert}a: A robustly optimized {bert} pretraining approach, 2020.
162
+ [31] A. Maas, R. E. Daly, P. T. Pham, D. Huang, A. Y. Ng, and C. Potts. Learning word vectors for sentiment analysis. In Proceedings of the 49th annual meeting of the association for computational linguistics: Human language technologies, pages 142–150, 2011.
163
+ [32] R. T. McCoy, P. Smolensky, T. Linzen, J. Gao, and A. Celikyilmaz. How much do language models copy from their training data? evaluating linguistic novelty in text generation using raven. arXiv preprint arXiv:2111.09509, 2021.
164
+ [33] F. Mireshghallah, A. Uniyal, T. Wang, D. Evans, and T. Berg-Kirkpatrick. Memorization in nlp fine-tuning methods. arXiv preprint arXiv:2205.12506, 2022.
165
+
166
+ [34] R. Mitchell. Samsung fab data leak: How chatgpt exposed sensitive information. electropages.
167
+
168
+ [35] OpenAI. Gpt-4 technical report, 2023.
169
+
170
+ [36] N. Papernot, M. Abadi, Ú. Erlingsson, I. Goodfellow, and K. Talwar. Semi-supervised knowledge transfer for deep learning from private training data. In International Conference on Learning Representations, 2017.
171
+
172
+ [37] N. Papernot, S. Song, I. Mironov, A. Raghunathan, K. Talwar, and U. Erlingsson. Scalable private learning with pate. In International Conference on Learning Representations, 2022.
173
+
174
+ [38] F. Petroni, T. Rocktäschel, P. Lewis, A. Bakhtin, Y. Wu, A. H. Miller, and S. Riedel. Language models as knowledge bases? arXiv preprint arXiv:1909.01066, 2019.
175
+
176
+ [39] A. Radford, K. Narasimhan, T. Salimans, I. Sutskever, et al. Improving language understanding by generative pre-training. 2018.
177
+
178
+ [40] A. Radford, J. Wu, R. Child, D. Luan, D. Amodei, I. Sutskever, et al. Language models are unsupervised multitask learners. OpenAI blog, 1(8):9, 2019.
179
+
180
+ [41] C. Raffel, N. Shazeer, A. Roberts, K. Lee, S. Narang, M. Matena, Y. Zhou, W. Li, and P. J. Liu. Exploring the limits of transfer learning with a unified text-to-text transformer. The Journal of Machine Learning Research, 21(1):5485–5551, 2020.
181
+
182
+ [42] T. L. Scao and A. M. Rush. How many data points is a prompt worth? arXiv preprint arXiv:2103.08493, 2021.
183
+
184
+ [43] V. Shejwalkar, H. A. Inan, A. Houmansadr, and R. Sim. Membership inference attacks against NLP classification models. In NeurIPS 2021 Workshop Privacy in Machine Learning, 2021.
185
+
186
+ [44] T. Shin, Y. Razeghi, R. L. Logan IV, E. Wallace, and S. Singh. Autoprompt: Eliciting knowledge from language models with automatically generated prompts. arXiv preprint arXiv:2010.15980, 2020.
187
+
188
+ [45] R. Shokri, M. Stronati, C. Song, and V. Shmatikov. Membership inference attacks against machine learning models. In 2017 IEEE symposium on security and privacy $( S P )$ , pages 3–18. IEEE, 2017.
189
+
190
+ [46] R. Socher, A. Perelygin, J. Wu, J. Chuang, C. D. Manning, A. Y. Ng, and C. Potts. Recursive deep models for semantic compositionality over a sentiment treebank. In Proceedings of the 2013 conference on empirical methods in natural language processing, pages 1631–1642, 2013.
191
+
192
+ [47] C. Song and V. Shmatikov. Auditing data provenance in text-generation models. In Proceedings of the 25th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining, pages 196–206, 2019.
193
+
194
+ [48] K. Tirumala, A. H. Markosyan, L. Zettlemoyer, and A. Aghajanyan. Memorization without overfitting: Analyzing the training dynamics of large language models. arXiv preprint arXiv:2205.10770, 2022.
195
+
196
+ [49] F. Tramer and D. Boneh. Differentially private learning needs better features (or much more data). In International Conference on Learning Representations, 2021.
197
+
198
+ [50] E. M. Voorhees and D. M. Tice. Building a question answering test collection. In Proceedings of the 23rd annual international ACM SIGIR conference on Research and development in information retrieval, pages 200–207, 2000.
199
+
200
+ [51] A. Wang, A. Singh, J. Michael, F. Hill, O. Levy, and S. R. Bowman. GLUE: A multi-task benchmark and analysis platform for natural language understanding. In International Conference on Learning Representations, 2019.
201
+
202
+ [52] Z. Wang, W. Hamza, and R. Florian. Bilateral multi-perspective matching for natural language sentences. In Proceedings of the 26th International Joint Conference on Artificial Intelligence, pages 4144–4150, 2017.
203
+
204
+ [53] S. Yeom, I. Giacomelli, M. Fredrikson, and S. Jha. Privacy risk in machine learning: Analyzing the connection to overfitting. In 2018 IEEE 31st computer security foundations symposium (CSF), pages 268–282. IEEE, 2018.
205
+ [54] D. Yu, S. Naik, A. Backurs, S. Gopi, H. A. Inan, G. Kamath, J. Kulkarni, Y. T. Lee, A. Manoel, L. Wutschitz, S. Yekhanin, and H. Zhang. Differentially private fine-tuning of language models. In International Conference on Learning Representations, 2022.
206
+ [55] C. Zhang, D. Ippolito, K. Lee, M. Jagielski, F. Tramèr, and N. Carlini. Counterfactual memorization in neural language models. arXiv preprint arXiv:2112.12938, 2021.
207
+ [56] S. Zhang, S. Roller, N. Goyal, M. Artetxe, M. Chen, S. Chen, C. Dewan, M. Diab, X. Li, X. V. Lin, et al. Opt: Open pre-trained transformer language models. arXiv preprint arXiv:2205.01068, 2022.
208
+ [57] X. Zhang, J. Zhao, and Y. LeCun. Character-level convolutional networks for text classification. Advances in neural information processing systems, 28, 2015.
209
+ [58] Z. Zhao, E. Wallace, S. Feng, D. Klein, and S. Singh. Calibrate before use: Improving few-shot performance of language models. In International Conference on Machine Learning, pages 12697–12706. PMLR, 2021.
210
+
211
+ # A Broader Impacts
212
+
213
+ The growing importance of in-context learning as a paradigm for leveraging LLMs on private downstream tasks has significant implications for privacy. We present the first approaches for obtaining prompts with privacy guarantees, thereby enabling the use of this learning paradigm on sensitive data. This advancement has the potential to increase trust and acceptance of LLM-based systems for private applications. Our approach PromptPATE is the first viable technique for private downstream adaptation of black-box LLMs, which enables integrations into the state-of-the-art commercial LLM APIs. We acknowledge that—as with any application that relies on DP—care must be taken when choosing the privacy parameters $\varepsilon$ and $\delta$ since setting these incorrectly can lead to a false sense of privacy. Therefore, our work orientates at the privacy parameters that have been shown to provide reasonable protection in prior work. Thereby, we also ensure consistency and comparability in evaluations between the different appraoches.
214
+
215
+ # B Limitations
216
+
217
+ Tuning Instructions and Templates. For our discrete prompts, we did not tune the instructions or templates but instead relied on a template from prior work [58]. The effectiveness and performance of our PromptPATE could potentially be further improved by tuning the instructions and templates.
218
+
219
+ Privacy Risk of Pretrained LLM: We build on pretrained LLMs to learn and deploy our private prompts. Our methods solely target the protection of the private data used for these prompts. However, it is also important to acknowledge the inherent privacy risks for data used to pretrain the LLM. We leave the pretrainig of LLMs with privacy guarantees to an orthogonal line of work.
220
+
221
+ Limited Monetary Budget for our Experiments. Due to cost limitations, we were unable to experiment with the latest and best available model, GPT4. Our experiments with GPT3-Curie in comparison to less powerful GPT3-Babbage however indicate the clear trend the our private prompts improve in performance as the non-private baseline improves due to better models. Furthermore, again due to the cost limitation, we were not able to incorporate a larger number of teachers in our experiments for PromptPATE. Therefore, the best non-private teacher baseline that we report might not be the best achievable if one had more teachers to choose from. We chose from 200 and note that with more (and potentially better teachers), not only the baseline but also the teacher ensemble’s performance would get better.
222
+
223
+ Hyperparameter Tuning. To save computation costs, we did not exhaustively tune all hyperparameters in our experiments. While our approach still achieves high utility and good privacy-utility trade-offs, we acknowledge that with more hyperparameter tuning the performance together with the understanding of optimal configurations for private prompt learning could increase.
224
+
225
+ Assumption of a Trusted LLM API Provider. In our work, the API provider gets to interact with the private data, for example, through the teachers’ prompts in PromptPATE. Therefore, we have to assume trust in the API provider. The privacy guarantees through our private prompt learning protect the privacy of the prompt data against users that interact with the prompted LLM. In practice, companies that are concerned about the privacy of their data with respect to the API provider could make contracts with the API providers on the use of their data or buy access plans that guarantee that data queried to the API is treated privately. We leave implementing cryptographic approaches that could relief the assumption on trusting the API provider entirely, for example, by enabling the LLM to run inference on encrypted private data to future work.
226
+
227
+ # C Additional Insights into our Methods
228
+
229
+ # C.1 PromptDPSGD
230
+
231
+ We present the full PromptDPSGD algorithm in Algorithm 1.
232
+
233
+ Algorithm 1: PromptDPSGD. In contrast to the standard DPSGD algorithm that updates model parameters during private training or fine-tuning, our PromptDPSGD privately updates the soft prompt parameters. We highlight these changes with respect to standard DPSGD training or fine-tuning in blue.
234
+
235
+ Require: Private downstream data $D = \{ ( x _ { i } , y _ { i } ) \mid i \in [ N ] \}$ , prompt sequence length $s$ , embedding dimensionality $e$ , trained LLM $L$ with frozen parameters, loss function $\ell ( L _ { p } , x )$ for prompted LLM, Params: learning rate $\eta _ { t }$ , noise scale $\sigma$ , sampling rate $q$ , max gradient norm $c$ , training iterations $T$ . 1: Initialize $P _ { 0 } \in \bar { \mathbb { R } ^ { s \times e } }$ at random
236
+ 2: for $t \in [ T ]$ do
237
+ 3: Sample mini-batch $B _ { t }$ according to sampling rate $q$ from $D$ {Poisson sampling}
238
+ 4: For each $i \in | B _ { t } |$ , compute $\mathbf { g } _ { t } ( x _ { i } ) \gets \bar { \nabla } _ { P _ { t } } \ell ( L _ { P } , x _ { i } )$ {Compute per sample gradient w.r.t. $p _ { t }$ } 5: $\begin{array} { r } { \bar { \bf g } _ { t } ( x _ { i } ) { \bf g } _ { t } ( x _ { i } ) / \operatorname* { m a x } ( 1 , \frac { \| { \bf g } _ { t } ( x _ { i } ) \| _ { 2 } } { c } ) } \end{array}$ {Clip gradient}
239
+ 6: $\begin{array} { r } { \tilde { \mathbf { g } } _ { t } \frac { 1 } { \mid B _ { t } \mid } ( \sum _ { i } \bar { \mathbf { g } } _ { t } ( x _ { i } ) + \mathcal { N } ( 0 , \sigma ^ { 2 } c ^ { 2 } \mathbf { I } ) ) } \end{array}$ {Add noise}
240
+ 7: $P _ { t + 1 } \gets P _ { t } - \eta _ { t } \tilde { \mathbf { g } } _ { t }$ {Update soft prompt}
241
+ 8: end for
242
+ 9: Output $p _ { T }$ and compute the overall privacy cost $( \varepsilon , \delta )$ .
243
+
244
+ # C.2 PromptPATE
245
+
246
+ Extended Background on PATE. We include the standard Confident-GNMax Aggregator Algorithm from [37] below.
247
+
248
+ # Algorithm 2: Confident-GNMax Aggregator by [37]
249
+
250
+ Require: input $x$ , threshold $T$ , noise parameters $\sigma _ { 1 }$ and $\sigma _ { 2 }$
251
+ 1: if $\textstyle \operatorname* { m a x } _ { j } \{ \sum _ { i \in [ E ] } n _ { i , j } ( x ) \} + \mathcal { N } ( 0 , \sigma _ { 1 } ^ { 2 } ) \geq T$ then
252
+ 2: Output arg $\begin{array} { r } { \operatorname* { m a x } _ { j } \{ \sum _ { i \in [ E ] } n _ { i , j } ( \mathbf x ) + \mathcal { N } ( 0 , \sigma _ { 2 } ^ { 2 } ) \} } \end{array}$
253
+ 3: else
254
+ 4: Output ⊥
255
+ 5: end if
256
+
257
+ # C.3 Privacy Analysis
258
+
259
+ PromptDPSGD. Our PromptDPSGD can be seen as a repeated sampled Gaussian mechanism [1], with sampling performed over the entirety of the private prompt dataset. The difference to standard DPSGD for training or fine-tuning is that we do not update the model parameters, but the trainable embeddings for the soft prompts. This is conceptually different from standard DPSGD in terms of which parameters are updated. The privacy guarantees of the training mechanism still follow Abadi et al. [1], but with respect to the soft prompt embeddings: whether or not a particular data point will be included in the private training set used for tuning the prompt, the resulting soft prompt embeddings after training will be roughly the same. Especially by applying the clipping operation at every step, each mechanism’s sensitivity is bounded by $c$ . Privacy is then implemented as the trainable soft prompt embeddings are updated while adding noise noise drawn from ${ \mathcal { N } } ( 0 , c ^ { 2 } \sigma ^ { 2 } I )$ .
260
+
261
+ Theorem 1 (Privacy of PromptDPSGD). Let $T$ be the total number of repetitions (training iterations) of our PromptDPSGD and the sampling rate be denoted by $q$ . Then, there exist two constants $c _ { 1 }$ and $c _ { 2 }$ , such that for any $\varepsilon < c _ { 1 } q ^ { 2 } T$ our PromptDPSGD guarantees √ $( \varepsilon , \delta )$ -DP, if for any $\delta > 0$ , we choose the noise according to $\sigma \ge c _ { 2 } \frac { q c \sqrt { T \log { 1 / \delta } } } { \varepsilon }$ .
262
+
263
+ Proof. The proof follows the one by Abadi et al. [1], using their moments accountant that models the privacy loss as a random variable dependent on the stochastic noise added. □
264
+
265
+ PromptPATE. Our PromptPATE relies entirely on the Confident GNMAX algorithm from Papernot et al. [37]. We preserve the assumption underlying the algorithm and the respective privacy analysis that the sensitivity during the voting mechanism equals one. This is done in PromptPATE by assigning disjoint data points from the private prompt downstream dataset to all teachers. As a consequence, the privacy analysis of our PromptPATE entirely follows Papernot et al. [37].
266
+
267
+ Both our PromptDPSGD and PromptPATE experience the post-processing properties of DP, i.e., once trained, the privacy guarantee $( \varepsilon , \delta )$ sets an upper bound on privacy leakage for the prompt data, independent on the number and type of queries that will be posed to the final prompted LLM.
268
+
269
+ # D Additional Results
270
+
271
+ # D.1 Membership Inference Attacks
272
+
273
+ We present the full results of MIA against GPT3 with one-shot prompts on 4 datasets in SCW: Section4.
274
+
275
+ ![](images/7eae14bc2947d35bce3ccb3ea9c878e6260cf6489e37c6116413032a79a73cae.jpg)
276
+ Figure 4: MIA Risk over Multiple Datasets on GPT3. We study GPT3-babbage prompted with 100 different one-shot examples on four datasets. Top: We present the prediction probabilities at the correct class for members (the one-shot example) and non-members (50 randomly sampled private points). The output probability for members is significantly higher than for non-member data points. Bottom: We present the AUC-ROC curves of our MIA against the 100 prompts (gray lines) and the blue line as an average over all attacks. Given that each prompt has only one member, the resulting TPRs can only be $0 \%$ or $100 \%$ which leads to the step-shape of the gray curves. The result indicates that our attack is significantly more successful than random guessing (the red dashed line).
277
+
278
+ In addition, we also perform similar experiments on GPT2-xl with four-shot examples, with results presented in Figure 5. We replace dbpedia with cb because the input in dbpedia is usually longer than the context length of GPT2.
279
+
280
+ # D.2 PromptPATE on Claude
281
+
282
+ We present the experiment results of PromptPATE on Claude [3]. Different from GPT3 that outputs logits over the whole vocabulary, Claude only gives us access to the next most likely token.
283
+
284
+ Experimental Setup. Teachers: We rely on Claude-v1 as the base LLM. We use 2-shot prompts for sst2 and agnews, 4-shot for trec and 1-shot for dbpedia. We set the maximum generated tokens to 1 and temperatures to 0. We also create an "other" category in case the moel’s output does not fall under any specified categories. For each setting, we deploy 400 teacher prompts. Private knowledge transfer: We use the implementation of PATE’s Confident GNMAX algorithm and the privacy accounting from [12] and report our algorithm’s hyperparameters in Appendix E. Student: We limit the size of the public dataset to 200 input sequences from the respective datasets. The number of shots for students corresponds with the teachers.
285
+
286
+ # D.3 More results for PromptDPSGD
287
+
288
+ We present the additional results for PromptDPSGD with $\varepsilon = 3$ on the classification tasks in Table 5.
289
+
290
+ ![](images/8df93be760fda31b5ae90c5aa61db1df18ba93e18cedee2e1e073f0475414194.jpg)
291
+ Figure 5: MIA Risk over Multiple Datasets on GPT2-xl (4 shot). We study GPT2-xl prompted with 100 different four-shot examples on four datasets. top: We present the prediction probabilities at the correct class for members (the one-shot example) and non-members (50 randomly sampled private points). The output probability for members is significantly higher than for non-member data points. bottom: We present the AUC-ROC curves of our MIA against the 100 prompts (gray lines) and the blue line as an average over all attacks. Given that each prompt has only one member, the resulting TPRs can only be $0 \%$ , $2 5 \%$ , $50 \%$ , $7 5 \%$ or $100 \%$ which leads to the step-shape of the gray curves. The result indicates that our attack is significantly more successful than random guessing (the red dashed line).
292
+
293
+ <table><tr><td></td><td>Lower Bound</td><td>Ens. Acc.</td><td>Upper Bound</td><td colspan="3">Our PromptPATE</td></tr><tr><td>Private</td><td>m=0</td><td>m=8</td><td>m=8</td><td>Public</td><td>m</td><td>Test acc</td></tr><tr><td>sst2</td><td>92.7</td><td>96.0</td><td>98.0</td><td>sst2</td><td>0.048</td><td>95.7 ± 1.4</td></tr><tr><td>agnews</td><td>72.4</td><td>79.1</td><td>82.7</td><td>agnews</td><td>0.056</td><td>74.6 ± 1.5</td></tr><tr><td>trec</td><td>69.0</td><td>79.9</td><td>82.2</td><td>trec</td><td>0.068</td><td>79.3 ± 1.2</td></tr><tr><td>dbpedia</td><td>88.0</td><td>92.4</td><td>93.5</td><td>dbpedia</td><td>0.042</td><td>90.9 ± 0.6</td></tr></table>
294
+
295
+ Table 3: Performance of PromptPATE on Claude. We compare PromptPATE with three baselines: zero-shot (Lower Bound), the ensemble’s accuracy (Ens. Acc), and the non-private baseline (Upper Bound) on four classification benchmarks. We find that PromptPATE achieves strong privacy protection $\varepsilon < 0 . 1$ at $\delta = 1 0 ^ { - 6 }$ ) and utility close to the non-private and significantly higher than the zero-shot.
296
+
297
+ # E Additional Setup
298
+
299
+ # E.1 PromptDPSGD
300
+
301
+ We train PromptDPSGD on NVIDIA A100 GPUs. We execute (hyper-)parameter search that takes into account learning rate (LR), max grad norm (GRAD), number of epochs (Epochs), the token length of prefix and prompt. In general, we find that the prompt and prefix token length of 10 is close to the optimal value in most cases. For the private (hyper-)parameters, in most cases we tune for $\varepsilon = 8$ and use similar (or even the same) parameters for other $\varepsilon$ values. We set the max grad norm to 0.1 in most cases and then adjust the number of epochs (the more the better, for example, 100), and the learning rate $[ 5 4 ] ^ { 5 }$ . The batch size is set by default to 1024.
302
+
303
+ We show the specific parameters chosen for PromptDPSGD in Table 6.
304
+
305
+ Table 4: Private classification with soft prompts and prefix for $\begin{array} { c c l } { \varepsilon } & { = } & { \{ 3 , \infty \} } \end{array}$ and the RoBERTaBASE model. We use the same setup and notation as in Table 1.
306
+
307
+ <table><tr><td rowspan="3">Dataset</td><td>M P</td><td colspan="2">Soft-Prompt (Our)</td><td colspan="2">Prefix (Our)</td><td colspan="2">Full-Tuning [25]</td><td colspan="2">LoRA-Tuning [54]</td></tr><tr><td></td><td colspan="2">&lt;10K</td><td colspan="2">&lt;100K</td><td colspan="2">125M</td><td colspan="2">1.2M</td></tr><tr><td>G</td><td>=3</td><td>m=8</td><td>m=3</td><td>m=8</td><td>ε=3</td><td>m=8</td><td>m=3</td><td>m=8</td></tr><tr><td>SST2</td><td></td><td>90.48</td><td>95.64</td><td>90.37</td><td>96.33</td><td>91.86</td><td>96.40</td><td>92.60</td><td>96.60</td></tr><tr><td>QNLI</td><td></td><td>83.62</td><td>89.48</td><td>86.05</td><td>94.84</td><td>87.42</td><td>94.70</td><td>86.97</td><td>94.70</td></tr><tr><td>QQP</td><td></td><td>80.29</td><td>86.56</td><td>80.89</td><td>91.42</td><td>85.56</td><td>92.20</td><td>85.12</td><td>92.20</td></tr><tr><td>MNLI</td><td></td><td>73.97</td><td>82.49</td><td>80.10</td><td>90.34</td><td>82.99</td><td>90.20</td><td>82.08</td><td>90.20</td></tr></table>
308
+
309
+ <table><tr><td rowspan="2">Dataset</td><td>M</td><td>Soft-Prompt (Our)</td><td>Prefix (Our)</td><td>Full-Tuning [25]</td></tr><tr><td>P</td><td>&lt;10K</td><td>&lt;100K</td><td>125M</td></tr><tr><td>SST2</td><td></td><td>91.05</td><td>93.58</td><td>90.94</td></tr><tr><td>QNLI</td><td></td><td>87.62</td><td>89.45</td><td>89.42</td></tr><tr><td>QQP</td><td></td><td>82.29</td><td>83.50</td><td>87.49</td></tr><tr><td>MNLI</td><td></td><td>76.05</td><td>86.71</td><td>86.28</td></tr></table>
310
+
311
+ Table 5: Private classification with soft prompts and prefix for $\varepsilon = 8$ and the RoBERTaLARGE model. We use the same setup and notation as in Table 1.
312
+
313
+ # E.2 PromptPATE
314
+
315
+ # E.2.1 Hyperparameters for Confident-GNMax
316
+
317
+ We present our hyperparameters for Confident-GNMax in Table 7.
318
+
319
+ # E.2.2 Dataset Preprocessing
320
+
321
+ sst2, trec, agnews, dbpedia and cb are taken from the repo of [58]. All other public datasets are downloaded from huggingface. To reduce the cost of quering APIs, we randomly sample 300 points from the test set to report the test accuracy. For imdb, we random select one sentence from each entry and also remove the ${ \tt { \ c b r / > } }$ tag. For qqp, we only take the column of "question $1 "$ in the public set.
322
+
323
+ Table 6: Detailed parameters for soft prompts and prefix. Type is the type of training, BS represents the batch size, LR denotes the learning rate, $\varepsilon$ is the DP guarantee, P-Length is the token length of soft-prompt or prefix.
324
+
325
+ <table><tr><td>Dataset</td><td>Method</td><td>RoBERTa</td><td>BS</td><td>LR</td><td>m</td><td>GRAD</td><td>Epochs</td><td></td><td>P-Length Accuracy (%)</td></tr><tr><td>SST2</td><td>Prompt</td><td>Base</td><td>1024</td><td>0.005</td><td>8</td><td>N/A</td><td>60</td><td>100</td><td>93.23</td></tr><tr><td>SST2</td><td>Prompt</td><td>Base</td><td>900</td><td>0.05</td><td>8</td><td>0.01</td><td>21</td><td>9</td><td>92.32</td></tr><tr><td>SST2</td><td>Prompt</td><td>Base</td><td>1024</td><td>0.005</td><td>3</td><td>0.05</td><td>100</td><td>10</td><td>86.35</td></tr><tr><td>SST2</td><td>Prompt</td><td>Large</td><td>2048</td><td>0.005</td><td>8</td><td>4</td><td>100</td><td>10</td><td>91.05</td></tr><tr><td>SST2</td><td>Prefix</td><td>Base</td><td>32</td><td>0.01</td><td>8</td><td>N/A</td><td>60</td><td>20</td><td>94.61</td></tr><tr><td>SST2</td><td>Prefix</td><td>Base</td><td>1000</td><td>0.05</td><td>8</td><td>4</td><td>22</td><td>1</td><td>91.97</td></tr><tr><td>SST2</td><td>Prefix</td><td>Base</td><td>1024</td><td>0.01</td><td>3</td><td>0.2</td><td>100</td><td>50</td><td>90.37</td></tr><tr><td>SST2</td><td>Prefix</td><td>Large</td><td>2048</td><td>0.05</td><td>8</td><td>4</td><td>22</td><td>1</td><td>93.58</td></tr><tr><td>QNLI</td><td>Prompt</td><td>Base</td><td>1024</td><td>0.005</td><td>8</td><td>N/A</td><td>60</td><td>128</td><td>89.48</td></tr><tr><td>QNLI</td><td>Prompt</td><td>Base</td><td>1024</td><td>0.005</td><td>8</td><td>0.05</td><td>100</td><td>10</td><td>84.11</td></tr><tr><td>QNLI</td><td>Prompt</td><td>Base</td><td>1024</td><td>0.005</td><td>3</td><td>0.1</td><td>100</td><td>50</td><td>83.62</td></tr><tr><td>QNLI</td><td>Prompt</td><td>Large</td><td>2048</td><td>0.01</td><td>8</td><td>0.05</td><td>100</td><td>10</td><td>87.62</td></tr><tr><td>QNLI</td><td>Prefix</td><td>Base</td><td>1024</td><td>0.005</td><td>8</td><td>N/A</td><td>60</td><td>20</td><td>94.84</td></tr><tr><td>QNLI</td><td>Prefix</td><td>Base</td><td>1000</td><td>0.03</td><td>8</td><td>0.07</td><td>22</td><td>10</td><td>88.77</td></tr><tr><td>QNLI</td><td>Prefix</td><td>Base</td><td>1024</td><td>0.01</td><td>3</td><td>0.2</td><td>100</td><td>50</td><td>85.78</td></tr><tr><td>QNLI</td><td>Prefix</td><td>Large</td><td>2048</td><td>0.03</td><td>8</td><td>0.07</td><td>22</td><td>10</td><td>89.45</td></tr><tr><td></td><td>Prompt</td><td>Base</td><td>1024</td><td>0.005</td><td>8</td><td>N/A</td><td>60</td><td>50</td><td>86.64</td></tr><tr><td></td><td>Prompt</td><td>Base</td><td>1024</td><td>0.05</td><td>8</td><td>0.1</td><td>10</td><td>7</td><td>82.58</td></tr><tr><td></td><td>Prompt</td><td>Base</td><td>1024</td><td>0.001</td><td>3</td><td>0.01</td><td>100</td><td>15</td><td>80.29</td></tr><tr><td></td><td>Prompt</td><td>Large</td><td>2048</td><td>0.005</td><td>8</td><td>0.05</td><td>100</td><td>10</td><td>82.29</td></tr><tr><td></td><td>Prefix</td><td>Base</td><td>1024</td><td>0.005</td><td>8</td><td>N/A</td><td>60</td><td>20</td><td>91.42</td></tr><tr><td></td><td>Prefix</td><td>Base</td><td>1024</td><td>0.05</td><td>8</td><td>0.1</td><td>10</td><td>7</td><td>82.59</td></tr><tr><td></td><td>Prefix</td><td>Base</td><td>1024</td><td>0.05</td><td>3</td><td>1</td><td>15</td><td>2</td><td>80.89</td></tr><tr><td>QP</td><td>Prefix</td><td>Large</td><td>2048</td><td>0.05</td><td>8</td><td>0.1</td><td>10</td><td>7</td><td>83.50</td></tr><tr><td>MNLI</td><td>Prompt</td><td>Base</td><td>32</td><td>0.001</td><td>8</td><td>N/A</td><td>60</td><td>20</td><td>82.49</td></tr><tr><td>MNLI</td><td>Prompt</td><td>Base</td><td>1024</td><td>0.005</td><td>8</td><td>0.05</td><td>60</td><td>10</td><td>75.01</td></tr><tr><td>MNLI</td><td>Prompt</td><td>Base</td><td>1024</td><td>0.005</td><td>3</td><td>0.05</td><td>100</td><td>10</td><td>73.97</td></tr><tr><td>MNLI</td><td>Prompt</td><td>Large</td><td>2048</td><td>0.005</td><td>8</td><td>0.2</td><td>60</td><td>10</td><td>76.05</td></tr><tr><td>MNLI</td><td>Prefix</td><td>Base</td><td>32</td><td>0.001</td><td>8</td><td>N/A</td><td>60</td><td>20</td><td>82.49</td></tr><tr><td>MNLI</td><td>Prefix</td><td>Base</td><td>1024</td><td>0.005</td><td>8</td><td>0.05</td><td>60</td><td>50</td><td>80.42</td></tr><tr><td>MNLI</td><td>Prefix</td><td>Base</td><td>1024</td><td>0.005</td><td>3</td><td>0.2</td><td>100</td><td>50</td><td>80.10</td></tr><tr><td>MNLI</td><td>Prefix</td><td>Large</td><td>2048</td><td>0.01</td><td>8</td><td>0.1</td><td>100</td><td>10</td><td>86.71</td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr></table>
326
+
327
+ <table><tr><td>LLM</td><td>Dataset</td><td>T</td><td>01</td><td>02</td></tr><tr><td>GPT3</td><td>sst2</td><td>180</td><td>1</td><td>20</td></tr><tr><td>GPT3</td><td>agnews</td><td>180</td><td>5</td><td>20</td></tr><tr><td>GPT3</td><td>trec</td><td>180</td><td>1</td><td>20</td></tr><tr><td>GPT3</td><td>dbpedia</td><td>170</td><td>1</td><td>20</td></tr><tr><td>Claude</td><td>sst2</td><td>390</td><td>1</td><td>50</td></tr><tr><td>Claude</td><td>agnews</td><td>360</td><td>1</td><td>50</td></tr><tr><td>Claude</td><td>trec</td><td>320</td><td>1</td><td>50</td></tr><tr><td>Claude</td><td>dbpedia</td><td>320</td><td>5</td><td>50</td></tr></table>
328
+
329
+ Table 7: Detailed parameters for Confident-GNMax.
330
+
331
+ ![](images/1fe6b95fc6be5311ac5459b8073d1f593e5f38d7410b8d4a5dbe8a7046fa069f.jpg)
332
+ Figure 6: MIA against the public prompts of PromptPATE. We depict the AUC-ROC curve of MIA against the public prompts of PromptPATE. The member data is the examples from the prompts of all private teachers, and the non-members are randomly-selected data from the training set. Each blue curve corresponds to a different public prompt selected in one random trail. All curves are very close to the red dash line (random guess), which show that our PromptPATE is effective against MIA.
md/dev/uu6Oq7MN7g/uu6Oq7MN7g.md ADDED
@@ -0,0 +1,490 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CodeT5+: Open Code Large Language Models for Code Understanding and Generation
2
+
3
+ Yue Wang∗, Hung Le∗, Akhilesh Deepak Gotmare, Nghi D.Q. Bui, Junnan Li, Steven C.H. Hoi Salesforce AI Research https://github.com/salesforce/CodeT5/tree/main/CodeT5+
4
+
5
+ # Abstract
6
+
7
+ Large language models (LLMs) pretrained on vast source code have achieved prominent progress in code intelligence. However, existing code LLMs have two main limitations. First, they often adopt a specific architecture (encoder-only or decoder-only) or rely on a unified encoder-decoder network for different downstream tasks, lacking the flexibility to operate in the optimal architecture for a specific task. Secondly, they often employ a limited set of pretraining objectives which might not be relevant to some tasks and hence result in substantial performance degrade. To address these limitations, we propose “CodeT $5 + "$ , a family of encoder-decoder LLMs for code in which component modules can be flexibly combined to suit a wide range of code tasks. Such flexibility is enabled by our proposed mixture of pretraining objectives, which cover span denoising, contrastive learning, text-code matching, and causal LM pretraining tasks, on both unimodal and bimodal multilingual code corpora. Furthermore, we propose to initialize CodeT5+ with frozen off-the-shelf LLMs without training from scratch to efficiently scale up our models, and explore instruction-tuning to align with natural language instructions. We extensively evaluate ${ \mathrm { C o d e T } } 5 +$ on over 20 coderelated benchmarks in different settings, including zero-shot, finetuning, and instructiontuning. We observe state-of-the-art (SoTA) performance on various code-related tasks, and our instruction-tuned CodeT5 $\uplus$ 16B achieves new SoTA results of $3 5 . 0 \%$ pass $@ 1$ and $5 4 . 5 \%$ pass $@ 1 0$ on the HumanEval code generation task against other open code LLMs, even surpassing the OpenAI code-cushman-001 model.
8
+
9
+ # 1 Introduction
10
+
11
+ Large language models (LLMs) (Chen et al., 2021; Wang et al., 2021b; Nijkamp et al., 2023b) have recently demonstrated remarkable success in a broad set of downstream tasks in the code domain (Husain et al., 2019; Lu et al., 2021; Hendrycks et al., 2021). By pretraining on massive code-based data (e.g. GitHub public data), these code LLMs can learn rich contextual representations which can be transferred to various code-related downstream tasks. However, we found that many existing models are designed to perform well only in a subset of tasks. We argue that this is mainly due to two limitations in terms of architecture and pretraining tasks.
12
+
13
+ From an architectural perspective, existing code LLMs often adopt encoder-only or decoder-only models that perform well only on certain understanding or generative tasks. Specifically, encoderonly models (Feng et al., 2020; Guo et al., 2021) are often used to facilitate understanding tasks such as text-to-code retrieval (Lu et al., 2021). For generative tasks such as code generation (Chen et al., 2021; Hendrycks et al., 2021), decoder-only models (Chen et al., 2021; Nijkamp et al., 2023b) often demonstrate stronger performance. However, these decoder-only models are often not ideal for understanding tasks such as detection tasks compared to encoder-only models (Nijkamp et al., 2023a).
14
+
15
+ Besides, several models have adopted more unified encoder-decoder architectures (Wang et al., 2021b; Ahmad et al., 2021) to adapt to different types of tasks. While these models can support both understanding and generative tasks, they still suffer from suboptimal performance on certain tasks. Guo et al. (2022) found that encoder-decoder models fail to beat (state-of-the-art) SoTA encoder-only or decoder-only baselines on retrieval and code completion tasks respectively. This shortfall is due to the limitation of the single-module architecture generally adapted to all tasks. In summary, prior approaches are not designed with compositionality such that individual components can be activated to better suit different types of downstream tasks.
16
+
17
+ From a learning objective perspective, current models employ a limited set of pretraining tasks.
18
+
19
+ ![](images/6762e5018712efc9935b135569523d5e6e3214a9b28097efa4e6884945caac9b.jpg)
20
+ Figure 1: An overview of our CodeT $^ { \circ + }$ , a family of code LLMs for code understanding and generation.
21
+
22
+ These tasks can lead to performance degrade on certain downstream tasks due to the discrepancy between the pretraining and finetuning stage. For instance, T5-based models such as (Wang et al., 2021b) are often trained with a span denoising objective. However, in downstream tasks such as code generation (Chen et al., 2021; Hendrycks et al., 2021), most SoTA models are pretrained with a next-token prediction objective which autoregressively predicts a program token by token. Furthermore, many models are not trained to learn contrastive code representations that are vital for understanding tasks such as text-to-code retrieval. Although recent attempts (Guo et al., 2022; Wang et al., 2021a) introduce a contrastive learning task to alleviate this issue, these approaches ignore the fine-grained text-code cross-modal alignments.
23
+
24
+ To address the above limitations, we propose “CodeT $\ " 5 + \ " { }$ , a new family of encoder-decoder code foundation LLMs for a wide range of code understanding and generation tasks (see Fig. 1 for an overview). Despite being an encoder-decoder based model, our CodeT $^ { 5 + }$ can flexibly operate in encoder-only, decoder-only, and encoder-decoder modes to suit different downstream applications. Such flexibility is enabled by our proposed pretraining tasks, which include span denoising and causal language modeling (CLM) tasks on code data and text-code contrastive learning, matching, and CLM tasks on text-code data. We found that such a wide set of pretraining tasks can help learn rich representations from both code and text data, and bridge the pretrain-finetune gap in various downstream applications. Besides, we show that the integration of the matching task with contrastive learning is crucial to capture the fine-grained text-code alignments and improve retrieval performance.
25
+
26
+ Furthermore, we scale up the model size of
27
+
28
+ CodeT $^ { 5 + }$ with a compute-efficient pretraining strategy by leveraging off-the-shelf code LLMs to initialize the components of ${ \mathrm { C o d e T } } 5 +$ . Specifically, we employ a “shallow encoder and deep decoder” architecture (Li et al., 2022b), where both encoder and decoder are initialized from pretrained checkpoints and connected by cross-attention layers. We freeze the deep decoder LLM and only train the shallow encoder and cross-attention layers, largely reducing the number of trainable parameters for efficient tuning. Finally, recent work in the NLP domain (Taori et al., 2023; Wang et al., 2022; Ouyang et al., 2022) inspired us to explore ${ \mathrm { C o d e T } } 5 +$ with instruction tuning to better align the models with natural language instructions.
29
+
30
+ We extensively evaluate ${ \mathrm { C o d e T } } 5 +$ on over 20 code-related benchmarks under various settings, including zero-shot, finetuning, and instructiontuning. Results show that CodeT $^ { 5 + }$ yields substantial performance gains on many downstream tasks compared to their SoTA baselines, e.g., 8 text-to-code retrieval tasks $+ 3 . 2$ avg. MRR), 2 line-level code completion tasks $( + 2 . 1$ avg. Exact Match), and 2 retrieval-augmented code generation tasks ( $_ { + 5 . 8 }$ avg. BLEU-4). In 2 math programming tasks on MathQA and GSM8K benchmarks (Austin et al., 2021; Cobbe et al., 2021), CodeT $^ { 5 + }$ models of below billion-parameter sizes significantly outperform many LLMs of up to 137B parameters. Particularly, in the zero-shot text-to-code generation task on HumanEval benchmark (Chen et al., 2021), our instruction-tuned CodeT $5 +$ 16B sets new SoTA results of $3 5 . 0 \%$ pass $@ 1$ and $5 4 . 5 \%$ pass $@ 1 0$ against other open code LLMs, even surpassing the closed-source OpenAI code-cushman001 model. Finally, we showcase that CodeT $^ { 5 + }$ can be seamlessly adopted as a semi-parametric retrieval-augmented generation system.
31
+
32
+ ![](images/e0c13d79f591975aff25d2e317329d6e46afe2609a0a2fd64b17b24e7dd658f9.jpg)
33
+ Figure 2: Model architecture of CodeT $^ { 5 + }$ . S1: first stage pretraining with unimodal code data, S2: second stage pretraining with bimodal code-text data. The diagram on the right shows our proposed compute-efficient training with frozen code LLMs to scale up the model. We employ a “shallow encoder and deep decoder” architecture and only keep the small encoder and the cross-attention layers trainable while freezing the deep decoder LLM.
34
+
35
+ # 2 Related Work
36
+
37
+ Following the success of LLMs such as BERT (Devlin et al., 2019) and GPT (Radford et al., 2019) in natural language processing (NLP), recent years witness a surge of research work of LLMs in the code domain, leading to new SoTA results on various code-related tasks. Typically, code LLMs can be categorized into three architectures: encoderonly models (Feng et al., 2020), decoder-only models (Chen et al., 2021; Nijkamp et al., 2023b), and encoder-decoder models (Ahmad et al., 2021; Wang et al., 2021b). For encoder-only and decoderonly models, they are often ideal for either understanding tasks such as code retrieval (Husain et al., 2019) or generation tasks such as code synthesis (Chen et al., 2021) respectively. For encoderdecoder models, they can be adapted to both code understanding and generation but do not always achieve better performance (Wang et al., 2021b). In this work, we propose a new family of encoderdecoder code LLMs “CodeT $\ " 5 + \ " { }$ that can flexibly operate in various modes, including encoder-only, decoder-only, and encoder-decoder models.
38
+
39
+ Prior code LLMs are also limited by their pretraining tasks, which are not perfect to transfer the models to some downstream tasks. For instance, T5-based models such as (Wang et al., 2021b) pretrained with span denoising objective are not ideal for auto-regressive generation tasks like next-line code completion (Guo et al., 2022), as these models are trained to recover short spans of limited lengths rather than a whole program.1 Inspired by recent advances in NLP research (Tay et al., 2022; Soltan et al., 2022), we explore to combine span denoising with CLM tasks to improve the model with better causal generation capability (Le et al., 2022). Additionally, most models do not have specific pretraining tasks (e.g. contrastive learning) to facilitate the learning of contextual representations that can distinguish code samples of different semantics. This can lead to suboptimal performance on code understanding tasks like code retrieval (Husain et al., 2019). In light of this, we include a contrastive learning task to learn better unimodal representations and a matching task to learn richer bimodal representations, which has been shown helpful in vision-language retrieval tasks (Li et al., 2021).
40
+
41
+ # 3 CodeT5+: Open Code LLMs
42
+
43
+ We develop CodeT $^ { 5 + }$ , a new family of open code LLMs for code understanding and generation tasks (see Fig. 1 for an overview and more architecture/pretraining details in Fig. 2 and Fig. 3). Based on the encoder-decoder architecture (Wang et al., 2021b), CodeT $^ { 5 + }$ is enhanced with the flexibility to operate in various modes for different downstream tasks through our proposed mixture of pretraining objectives, which are performed on two stages of pretraining on unimodal (Sec. 3.1) and bimodal data (Sec. 3.2). We found that this stage-wise training approach can efficiently expose our models to more diverse data to learn rich contextual representations. Finally, we explore initializing CodeT $^ { 5 + }$ with off-the-shelf code LLMs to efficiently scale up the model without training from scratch (Sec. 3.3).
44
+
45
+ ![](images/48300ae5e43240d65376f7643ab43bb77974ec1b45cc1f305d3bac23f0d19c20.jpg)
46
+ Figure 3: Self-supervised pretraining on code data: we pretrain ${ \mathrm { C o d e T } } 5 +$ on code data using a mixture of tasks: (i) span denoising (Top); (ii) decoder-only causal LM (Middle); and (iii) Seq2Seq causal LM (Bottom). This mixture of tasks lets the models learn meaningful representations of code contexts and recover missing information at different levels: code spans, partial programs, and complete programs.
47
+
48
+ # 3.1 Unimodal Pretraining on Code Data
49
+
50
+ In the first stage, we pretrain CodeT $^ { 5 + }$ on largescale code unimodal data, which can be obtained from open-source platforms like GitHub. Although such data also contain texts such as user-written code comments, we denote unimodal data to distinguish them with bimodal data of text-code pairs in the second pretraining stage. In this stage, we pretrain the model from scratch using a mixture of span denoising and CLM tasks as shown in Fig. 3. These tasks enable the model to learn to recover code contexts at different scales: code spans, partial programs, and complete programs.
51
+
52
+ Span Denoising. Similar to T5 (Raffel et al., 2020), we randomly replace $1 5 \%$ of the tokens with indexed sentinel tokens (like [MASK0]) in the encoder inputs, and require the decoder to recover them via generating a combination of these spans. We follow CodeT5 to employ whole-word masking by sampling spans (span lengths determined by a uniform distribution with a mean of 3) before subword tokenization to avoid masking partial words.
53
+
54
+ Causal Language Modeling (CLM). Inspired by Tay et al. (2022); Soltan et al. (2022), we introduce two variants of CLM to optimize our model for auto-regressive generation. In the first variant, we randomly select a pivot location and regard the context before it as the source sequence and the sequence after it as the target output. We denote this variant as a sequence-to-sequence (Seq2Seq) causal LM objective. We restrict the pivot location to be uniformly sampled between $1 0 \%$ and $9 0 \%$ of the whole sequence and prepend a special token [CLM] to the source sequence. The second CLM variant is a decoder-only generation task, where we always pass a [CLM] token to the encoder input and require the decoder to generate the full code sequence. This task aims to provide more dense supervision signals to train the decoder as an independent full-fledged code generation module.
55
+
56
+ # 3.2 Bimodal Pretraining on Text-code Data
57
+
58
+ In the second stage, we pretrain the model using text-code bimodal data at function level (Husain et al., 2019). In this setting, each text-code pair contains a code function and its corresponding docstring describing its semantics. Such a bimodal data format facilitates model training for crossmodal understanding and generation. The bimodal pretraining tasks consist of cross-modal contrastive learning, matching, and causal LM tasks (Fig. 2). See Appendix A for their detailed formulations.
59
+
60
+ Text-Code Contrastive Learning. This task aims to align the feature space of text and code representations by pulling together the representations of positive text-code pairs and pulling apart the negative pairs. Guo et al. (2022) demonstrated the benefits of such learning task for code understanding. This task only activates the encoder, which encodes a text or code snippet into a representation through bidirectional self-attention (Vaswani et al., 2017). Similar to BERT (Devlin et al., 2019), we prepend a special token [CLS] to the input and regard its output embeddings at the final layer as the representations of the corresponding input text or code. We further add a linear layer and use L2 normalization to map the output to 256- $d$ embeddings. To enrich the negative samples, we use a momentum encoder to store embeddings of samples from previous mini-batches, as similarly adopted by (He et al., 2020; Li et al., 2022a). Specifically, the momentum encoder maintains a queuing system that enqueues the samples in the current mini-batch and dequeues the samples in the oldest mini-batch.
61
+
62
+ Text-Code Matching. This task activates the decoder and aims to predict whether a text and code snippet share the same semantics. Such task enables model to learn better bimodal representations that capture the fine-grained alignment between text and code modalities. Given a code sample, the decoder first passes it to an embedding layer and a causal self-attention layer. The representations are then passed to a cross-attention layer which queries relevant signals from the text representations (received from the encoder). A task-specific [Match] token is prepended to the code input sequence to inform the decoder of the text-code matching functionality, and an [EOS] token is appended to the end of the code input. Since the decoder employs causal self-attention masks and only the last decoder token can attend to the whole context, we treat the output embedding of [EOS] at the last layer as the text-code alignment representation. Finally, we use a linear layer on top of the output embedding of the decoder for a binary matching task, predicting whether a text-code pair is positive (matched) or negative (unmatched).
63
+
64
+ Text-Code Causal LM. This task activates both encoder and decoder and focuses on a cross-modal generative objective through a dual multimodal conversion: text-to-code generation and code-to-text generation. Specifically, when the input is a text sample, we prepend a [CDec] token to the input sequence to the decoder. In this case, the decoder operates under code generation functionality. Alternatively, when the input is a code sample, we prepend a [TDec] token to the input sequence to the decoder. The decoder operates under text generation functionality in this case. This type of Causal LM has been shown to be an effective learning objective to close the pretrain-finetune gap for generative downstream tasks (Wang et al., 2021b).
65
+
66
+ # 3.3 Compute-efficient Pretraining with Frozen Off-the-shelf LLMs
67
+
68
+ To efficiently scale up the model without the need of pretraining from scratch, we propose a computeefficient pretraining strategy to initialize model components (i.e. encoder and decoder) of CodeT $^ { 5 + }$ with off-the-shelf pretrained LLMs (Nijkamp et al., 2023b) (see the rightmost diagram of Fig. 2). For this extension, inspired by (Li et al., 2022b), we employ a “shallow encoder and deep decoder” architecture instead of encoder and decoder of the same size in conventional T5 models (Raffel et al.,
69
+
70
+ 2020; Wang et al., 2021b). As noted by Li et al. (2022b), the decoder is often required to deal with a higher level of complexity in generation tasks and thus, should be enhanced with more parameters.
71
+
72
+ To connect the separately pretrained encoder and decoder, we insert randomly initialized crossattention layers to decoder blocks after the selfattention layers. For efficient tuning, we only insert cross-attention layers to the top- $L$ decoder layers ( $\scriptstyle { \mathrm { . } } L = 1$ in our experiments). We only keep the small encoder and cross-attention layers trainable while freezing the majority of the decoder parameters. We also explored other advanced designs such as adding a gating function to improve training stability or inserting multiple cross-attention layers at a certain frequency (Alayrac et al., 2022). However, we did not observe significant performance improvement and these design choices would introduce too expensive computation overhead.
73
+
74
+ # 3.4 Adaptation to Downstream Understanding and Generation Tasks
75
+
76
+ After the two stages of pretraining, CodeT $^ { 5 + }$ can flexibly operate in various modes to support different tasks, including Seq2Seq generation tasks, decoder-only tasks, and understanding-based tasks:
77
+
78
+ Seq2Seq Generation Tasks. As an encoderdecoder model, CodeT $^ { 5 + }$ can be naturally adapted to a variety of Seq2Seq generation tasks such as code generation and summarization. We also adapt CodeT $^ { 5 + }$ as a retrieval-augmented generation model, using the encoder to retrieve code snippets, which are then used by both the encoder and decoder for code generation.
79
+
80
+ Decoder-only Tasks. In this setting, we always feed a [CLM] token to the encoder input and pass the source sequence to the decoder as the prefix context. We freeze the weights of the encoder and the cross-attention layers in the decoder. This strategy only activates parts of the decoder and reduces about half of the total model parameters. We use next-line code completion tasks to evaluate the decoder-only generation capability of ${ \mathrm { C o d e T } } 5 +$ .
81
+
82
+ Understanding Tasks. CodeT $^ { 5 + }$ can support these understanding tasks in two ways: first, it employs the encoder to obtain text/code embeddings, which can be either passed to a binary classifier for detection tasks; alternatively, the encoder can be combined with the decoder to predict the text-code matching scores for text-to-code retrieval tasks.
83
+
84
+ # 4 Pretraining and Instruction Tuning
85
+
86
+ Additional pretraining and finetuning setups can be found in Appendix B, C, and E.
87
+
88
+ Pretraining Dataset. We enlarge the pretraining dataset of CodeSearchNet (Husain et al., 2019) with the recently released GitHub Code dataset2. We select nine PLs (Python, Java, Ruby, JavaScript, Go, PHP, C, $\mathrm { C } { + + }$ , C#) and filter the dataset by preserving only permissively licensed code3 and files with 50 to 2000 tokens. Besides, we filter out the overlapped subset with CodeSearchNet and other downstream tasks covered in our evaluation by checking their GitHub repository names. Note that although we employ the deduplicated data version in which duplicates are filtered out based on the exact match, there might be some potential remaining duplicates. However, we do not expect any remaining duplication will impact our model performance significantly. We use the CodeT5 tokenizer to tokenize the multilingual dataset, resulting in 51.5B tokens, ${ \sim } 5 0 \mathrm { x }$ larger than CodeSearchNet.
89
+
90
+ Pretraining Setup. We pretrained two groups of CodeT5+ models: 1) CodeT $^ { 5 + }$ 220M and 770M that are trained from scratch following T5’s architecture (Raffel et al., 2020) (T5-base and large respectively), 2) CodeT $^ { 5 + }$ 2B, 6B, 16B in which the decoders are initialized from CodeGen-mono 2B, 6B, 16B models (Nijkamp et al., 2023b) and its encoders are initialized from CodeGen-mono 350M. Note that following our model scaling strategy, the latter group of CodeT $^ { 5 + }$ models introduce insignificant trainable parameters (the 350M encoder plus one cross-attention layer of 36M, 67M, 151M for 2B, 6B, 16B models respectively) compared to the original CodeGen models. We employ the CodeT5 tokenizer and CodeGen tokenizer for these two groups of models respectively. In pretraining, we adopt a stage-wise strategy to pretrain CodeT5+ first on the large-scale unimodal dataset and then on the smaller bimodal dataset on a cluster with 16 A100-40G GPUs on Google Cloud Platform.
91
+
92
+ Instruction Tuning. In the NLP domain, recent work (Wang et al., 2022; Taori et al., 2023) studied the benefits of data augmentation techniques on pretrained LMs with synthetic instruction data. Models finetuned with this type of data can better understand natural language instructions and demonstrate improved alignment with the corresponding tasks (Wang et al., 2022; Ouyang et al., 2022). We are motivated to transfer this technique to the code domain to improve our CodeT $^ { 5 + }$ models. Following Taori et al. (2023), we employ over $2 0 \mathrm { k }$ instruction data in the code domain curated by Chaudhary (2023). The data is generated by letting pretrained LLMs i.e. text-davinci-003, generate novel tasks, including task instructions, inputs (if any), and expected outputs. We trained our models on this augmented dataset for up to 3 epochs and denote the instruction-tuned models as “InstructCode $\Gamma 5 + "$ . Note that the instruction data are generated fully independently from any downstream evaluation tasks and we still evaluate these models in a zero-shot manner.
93
+
94
+ # 5 Experiments
95
+
96
+ We extensively evaluate ${ \mathrm { C o d e T } } 5 +$ on a wide range of code understanding and generation tasks over $^ { 2 0 + }$ code-related datasets across 9 different programming languages (PLs). In addition, we consider a variety of evaluation settings including zeroshot, instruction tuning, task-specific finetuning. Additional results can be found in Appendix D.
97
+
98
+ Baselines. We developed a family of CodeT5+ models, with model sizes ranging from 220M to 16B. We compare CodeT5+ with 3 types of models: encoder-only, decoder-only, and encoder-decoder.
99
+
100
+ • For encoder-only models, we consider RoBERTa (Liu et al., 2019), CodeBERT (Feng et al., 2020), GraphCodeBERT (Guo et al., 2021), SYNCOBERT (Wang et al., 2021a) and UniXcoder (Guo et al., 2022) that incorporates contrastive learning. Note that UniXcoder can be also viewed as decoder-only model as it employs UniLM-style masking (Dong et al., 2019).
101
+
102
+ • For decoder-only models, we consider GPT2 (Radford et al., 2019) and CodeGPT (Lu et al., 2021), and also consider models of very large scales (up to 540B) such as PaLM (Chowdhery et al., 2022), GPT-4 (OpenAI, 2023), Codex (Chen et al., 2021), LLaMA (Touvron et al., 2023), CodeGen (Nijkamp et al., 2023b), Incoder (Fried et al., 2022), GPT-J (Wang and Komatsuzaki, 2021), GPT-Neo and GPT-NeoX (Black et al., 2022), MIM (Nguyen et al., 2023), CodeGeeX (Zheng et al., 2023). We also compare with Replit (replit, 2023) and StarCoder (Li et al., 2023) which are concurrent work with ours.
103
+
104
+ Table 1: Results of $p a s s @ k ( \% )$ on HumanEval.
105
+
106
+ <table><tr><td>Model</td><td>Model size</td><td>pass@1</td><td>pass@10</td><td>pass@100</td></tr><tr><td colspan="5">Closed-source models</td></tr><tr><td>LaMDA</td><td>137B</td><td>14.0</td><td>=</td><td>47.3</td></tr><tr><td>AlphaCode</td><td>1.1B</td><td>17.1</td><td>28.2</td><td>45.3</td></tr><tr><td>MIM</td><td>2.7B</td><td>30.7</td><td>48.2</td><td>69.6</td></tr><tr><td>PaLM</td><td>62B</td><td>15.9</td><td>-</td><td>46.3</td></tr><tr><td>PaLM</td><td>540B</td><td>26.2</td><td>-</td><td>76.2</td></tr><tr><td>code-cushman-001</td><td>-</td><td>33.5</td><td>54.3</td><td>77.4</td></tr><tr><td>code-davinci-002</td><td></td><td>47.0</td><td>74.9</td><td>92.1</td></tr><tr><td>GPT-3.5</td><td></td><td>48.1</td><td></td><td>=</td></tr><tr><td>GPT-4</td><td>=</td><td>67.0</td><td>-</td><td>-</td></tr><tr><td colspan="5">Open-source models</td></tr><tr><td>GPT-J</td><td>6B</td><td>11.6</td><td>15.7</td><td>27.7</td></tr><tr><td>InCoder</td><td>6B</td><td>15.2</td><td>27.8</td><td>47.0</td></tr><tr><td>GPT-NeoX</td><td>20B</td><td>15.4</td><td>25.6</td><td>41.2</td></tr><tr><td>CodeGeeX</td><td>13B</td><td>22.9</td><td>39.6</td><td>60.9</td></tr><tr><td>LLaMA</td><td>13B</td><td>15.8</td><td>-</td><td>52.5</td></tr><tr><td>LLaMA</td><td>65B</td><td>23.7</td><td></td><td>79.3</td></tr><tr><td>Replit</td><td>3B</td><td>21.9</td><td>=</td><td>-</td></tr><tr><td>StarCoder</td><td>15B</td><td>33.6</td><td>-</td><td>-</td></tr><tr><td>CodeGen-mono</td><td>2B</td><td>23.7</td><td>36.6</td><td>57.0</td></tr><tr><td>CodeGen-mono</td><td>6B</td><td>26.1</td><td>42.3</td><td>65.8</td></tr><tr><td>CodeGen-mono</td><td>16B</td><td>29.3</td><td>49.9</td><td>75.0</td></tr><tr><td>CodeT5+</td><td>220M</td><td>12.0</td><td>20.7</td><td>31.6</td></tr><tr><td>CodeT5+</td><td>770M</td><td>15.5</td><td>27.2</td><td>42.7</td></tr><tr><td>CodeT5+</td><td>2B</td><td>24.2</td><td>38.2</td><td>57.8</td></tr><tr><td>CodeT5+</td><td>6B</td><td>28.0</td><td>47.2</td><td>69.8</td></tr><tr><td>CodeT5+</td><td>16B</td><td>30.9</td><td>51.6</td><td>76.7</td></tr><tr><td>InstructCodeT5+</td><td>16B</td><td>35.0</td><td>54.5</td><td>77.9</td></tr><tr><td colspan="5">Open-source models + generation strategies</td></tr><tr><td>StarCoder (prompted)</td><td>15B</td><td>40.8</td><td>-</td><td>=</td></tr><tr><td>CodeGen-mono w/CodeT</td><td>16B</td><td>36.7</td><td>59.3</td><td></td></tr><tr><td>CodeT5+w/CodeT</td><td>16B</td><td>38.5</td><td>63.6</td><td>77.1</td></tr><tr><td>InstructCodeT5+w/CodeT</td><td>16B</td><td>42.9</td><td>67.8</td><td>78.7</td></tr></table>
107
+
108
+ • For encoder-decoder, we use PLBART (Ahmad et al., 2021) and CodeT5 (Wang et al., 2021b).
109
+
110
+ Note that billion-parameter LLMs such as Codex and CodeGen typically use most of the source code from GitHub for model training and do not remove any overlap with the downstream tasks covered in this work as we did. Therefore, it is difficult to ensure a fair comparison with these models in those tasks, especially the code completion tasks. Moreover, these models are very expensive to perform task-specific finetuning, and hence, they are often employed only on the zero-shot evaluation. In this work, we mainly compare CodeT $^ { 5 + }$ with these LLMs in the zero-shot HumanEval code generation task (Sec. 5.1). In other experiments, we focus on the finetuning setting and compare our models with smaller-scale LMs.
111
+
112
+ # 5.1 Zero-shot Code Generation Evaluation
113
+
114
+ We first evaluate the zero-shot code generation capabilities of our model on the HumanEval benchmark (Chen et al., 2021), where we activate both encoder and decoder modules from ${ \mathrm { C o d e T } } 5 +$ . In this experiment, we follow Nijkamp et al. (2023b) to continue to pretrain our CodeT $^ { 5 + }$ models on the Python subset for another epoch using causal LM objective to adapt them for Python code generation. We evaluate the model performance by testing generated codes against unit tests and report the passing rate pass $@ k$ $( k = \{ 1 , 1 0 , 1 0 0 \} )$ .
115
+
116
+ Table 2: Results of $p a s s @ k ( \% )$ on math programming.
117
+
118
+ <table><tr><td>Model</td><td>Model size</td><td>MathQA-Python pass @80</td><td>GSM8K-Python pass @100</td></tr><tr><td colspan="4">Few-shot learning results</td></tr><tr><td>code-davinci</td><td>-</td><td>42.0</td><td>71.0</td></tr><tr><td>LLaMA</td><td>33B</td><td>=</td><td>53.1</td></tr><tr><td>LLaMA</td><td>65B</td><td></td><td>69.7</td></tr><tr><td>Minerva</td><td>62B</td><td></td><td>68.5</td></tr><tr><td>Minerva</td><td>540B</td><td>=</td><td>78.5</td></tr><tr><td colspan="4">Finetuning results</td></tr><tr><td>LaMDA</td><td>137B</td><td>81.2</td><td>=</td></tr><tr><td>GPT-Neo</td><td>125M</td><td>84.7</td><td>=</td></tr><tr><td>GPT-Neo</td><td>2.7B</td><td>=</td><td>41.4</td></tr><tr><td>CodeGen-mono</td><td>350M</td><td>83.1</td><td>38.7</td></tr><tr><td>CodeGen-mono</td><td>2B</td><td>85.6</td><td>47.8</td></tr><tr><td>CodeT5</td><td>220M</td><td>71.5</td><td>58.4</td></tr><tr><td>CodeT5+</td><td>220M</td><td>85.6</td><td>70.5</td></tr><tr><td>CodeT5+</td><td>770M</td><td>87.4</td><td>73.8</td></tr></table>
119
+
120
+ As shown in Table 1, our instruction-tuned Code $^ { \circ + }$ ("InstructCodeT $" 5 + "$ ) 16B can improve the performance against other open code LLMs, achieving new SoTA of $3 5 . 0 \%$ pass $@ 1$ and $5 4 . 5 \%$ pass $@ 1 0$ . Particularly, as an open model, it even outperforms the OpenAI code-cushman-001 model across all metrics. We also observed that our smallsized models of 220M and 770M already match or outperform much larger code LLMs, e.g., CodeT $^ { 5 + }$ 770M’s $1 5 . 5 \%$ pass $@ 1$ compared to Incoder 6B’s $1 5 . 2 \%$ , GPT-NeoX 20B’s $1 5 . 4 \%$ , and PaLM 62B’s $1 5 . 9 \%$ . Besides, we observed that compared to the CodeGen models of similar sizes (Nijkamp et al., 2023b), CodeT $^ { 5 + }$ obtains consistent performance gains from 2B to 16B models. These superior results against decoder-only baselines demonstrate the advantage of the encoder-decoder architecture of ${ \mathrm { C o d e T } } 5 +$ and validate the effectiveness of our proposed compute-efficient pretraining strategy. We also evaluated the models with enhancement strategies following CodeT Chen et al. (2023). We find that this strategy can select better code candidates and bring the performance gains, achieving up to $4 2 . 9 \%$ pass $@ 1$ and $6 7 . 8 \%$ pass $@ 1 0$ .
121
+
122
+ # 5.2 Evaluation on Math Programming
123
+
124
+ We consider two math programming benchmarks MathQA-Python (Austin et al., 2021) and GSM8K (Cobbe et al., 2021). The task is to generate Python programs to solve mathematical problems described in texts, where code correctness is measured based on the execution outputs of the generated programs $\left( \mathrm { p a s s } @ \mathbf { k } \right)$ . We compare our models with very large decoder-only LMs such as Minerva (Lewkowycz et al., 2022) that is initialized with pretrained PaLM (Chowdhery et al., 2022) and further finetuned with large-scale scientific corpora. Note that some of the baselines are enhanced with generation strategies, such as GPTNeo using self-sampling optimization (Ni et al., 2022), and LLaMA and Minerva using majority voting (Lewkowycz et al., 2022).
125
+
126
+ ![](images/e8c72415282a950cd84a10315742902ebaee6abbea48655ba51b3ab7b7de64be.jpg)
127
+ Figure 4: Results of MathQA-Python by problem complexity (i.e. the number of reasoning steps required).
128
+
129
+ Table 2 shows that ${ \mathrm { C o d e T } } 5 +$ achieves significant performance gains, outperforming many code LLMs of much larger sizes. Specifically, our CodeT $^ { 5 + }$ 770M achieves new SoTA results of 87.4 pass $@ 8 0$ on MathQA-Python and very competitive results of $7 3 . 8 \ p a \ s s \textcircled { a } 1 0 0$ on GSM8K-Python. On GSM8K-Python, $\mathrm { C o d e T 5 + 7 7 0 M }$ achieves the best finetuning results against other larger models (e.g., LaMDA 137B and GPT-Neo 2.7B), and outperforms LLaMA 65B and Minerva 62B in the few-shot evaluation setting. In Fig. 4, we further analyze the model performance of ${ \mathrm { C o d e T } } 5 +$ by the problem complexity on MathQA-Python compared to CodeT5. For each problem, we extract the number of reasoning steps required to solve the problem. We observe that ${ \mathrm { C o d e T } } 5 +$ is more robust against the complexity of the problems compared to CodeT5, where CodeT5 model performance tends to deteriorate drastically as the number of reasoning steps increases. In CodeT $^ { 5 + }$ , the downward trend is a lot less severe and the model still achieves good results in very complex tasks (more than 10 steps).
130
+
131
+ # 5.3 Evaluation on Code Completion
132
+
133
+ We evaluate the decoder-only generation capability of ${ \mathrm { C o d e T } } 5 +$ through a line-level code completion task, which aims to complete the next code line based on the previous code contexts. We employ PY150 (Raychev et al., 2016) and JavaCorpus (Allamanis and Sutton, 2013) from CodeXGLUE, and use exact match (EM) accuracy and Levenshtein edit similarity (Svyatkovskiy et al., 2020) as the metrics. In this task, we employ a decoder-only model from CodeT $^ { 5 + }$ so that only about half of the total model parameters are activated.
134
+
135
+ Table 3: Results on line-level code completion.
136
+
137
+ <table><tr><td>Model</td><td colspan="2">PY150</td><td colspan="2">JavaCorpus</td></tr><tr><td></td><td>EM 42.37</td><td>Edit Sim</td><td>EM</td><td>Edit Sim</td></tr><tr><td>CodeGPT124M</td><td></td><td>71.59</td><td>30.60</td><td>63.45</td></tr><tr><td>UniXcoder 125M</td><td>43.12</td><td>72.00</td><td>32.90</td><td>65.78</td></tr><tr><td>CodeGen-multi 350M</td><td>42.47</td><td>70.67</td><td>35.47</td><td>69.22</td></tr><tr><td>PLBART140M</td><td>38.01</td><td>68.46</td><td>26.97</td><td>61.59</td></tr><tr><td>CodeT5 220M</td><td>36.97</td><td>67.12</td><td>24.80</td><td>58.31</td></tr><tr><td>CodeT5+220M</td><td>43.42</td><td>73.69</td><td>35.17</td><td>69.48</td></tr><tr><td>CodeT5+770M</td><td>44.86</td><td>74.22</td><td>37.90</td><td>72.25</td></tr></table>
138
+
139
+ Table 4: Results of MRR on Text-to-Code Retrieval.
140
+
141
+ <table><tr><td rowspan="2">Model</td><td colspan="7">CodeSearchNet</td><td rowspan="2">CosQA</td><td rowspan="2">AdvTest</td></tr><tr><td>Ruby</td><td>JS</td><td>Go</td><td>Python</td><td>Java</td><td>PHP</td><td>Overall</td></tr><tr><td>CodeBERT125M</td><td>67.9</td><td>62.0</td><td>88.2</td><td>67.2</td><td>67.6</td><td>62.8</td><td>69.3</td><td>65.7</td><td>27.2</td></tr><tr><td>GraphCodeBERT 125M</td><td>70.3</td><td>64.4</td><td>89.7</td><td>69.2</td><td>69.1</td><td>64.9</td><td>71.3</td><td>68.4</td><td>35.2</td></tr><tr><td>SYNCOBERT 125M</td><td>72.2</td><td>67.7</td><td>91.3</td><td>72.4</td><td>72.3</td><td>67.8</td><td>74.0</td><td>:</td><td>38.3</td></tr><tr><td>UniXcoder 125M</td><td>74.0</td><td>68.4</td><td>91.5</td><td>72.0</td><td>72.6</td><td>67.6</td><td>74.4</td><td>70.1</td><td>41.3</td></tr><tr><td>CodeGen-multi 350M</td><td>66.0</td><td>62.2</td><td>90.0</td><td>68.6</td><td>70.1</td><td>63.9</td><td>70.1</td><td>64.8</td><td>34.8</td></tr><tr><td>PLBART140M</td><td>67.5</td><td>61.6</td><td>88.7</td><td>66.3</td><td>66.3</td><td>61.1</td><td>68.6</td><td>65.0</td><td>34.7</td></tr><tr><td>CodeT5 220M</td><td>71.9</td><td>65.5</td><td>88.8</td><td>69.8</td><td>68.6</td><td>64.5</td><td>71.5</td><td>67.8</td><td>39.3</td></tr><tr><td>CodeT5+220M</td><td>77.7</td><td>70.8</td><td>92.4</td><td>75.6</td><td>76.1</td><td>69.8</td><td>77.1</td><td>72.7</td><td>43.3</td></tr><tr><td>CodeT5+ 770M</td><td>78.0</td><td>71.3</td><td>92.7</td><td>75.8</td><td>76.2</td><td>70.1</td><td>77.4</td><td>74.0</td><td>44.7</td></tr></table>
142
+
143
+ Table 3 shows that both CodeT $5 +$ (in decoderonly mode) and decoder-only models (the top block) significantly outperform encoder-decoder models (the middle block), validating that decoderonly models can better suit the code completion task in nature. Specifically, $\mathbf { C o d e T 5 + } \mathbf { \ } 2 2 0 \mathbf { M }$ already surpasses UniXcoder and is comparable to CodeGen-multi 350M, while the 770M one further sets new SoTA results in both metrics. In particular, CodeT5+ 220M yields substantial improvements over CodeT5 220M by $+ 6 . 5$ EM and $+ 1 0 . 4$ EM scores on PY150 and JavaCorpus respectively. This is mainly due to our causal LM objectives that allows the decoder to see longer sequences and thus have a better causal generation capability.
144
+
145
+ # 5.4 Evaluation on Text-to-Code Retrieval
146
+
147
+ We evaluate the code understanding capabilities of CodeT5+ through text-to-code retrieval tasks across multiple PLs. This task aims to find the most semantically related code snippet at the function level from a collection of candidate codes based on a natural language query. We consider three datasets for evaluation: CodeSearchNet (Husain et al., 2019), CosQA (Huang et al., 2021), and AdvTest (Lu et al., 2021), which are curated from the original CodeSearchNet by filtering data with lowquality queries, adopting real-world queries from a modern search engine, and obfuscating identifiers to normalize the code. In this task, we activate both encoder and decoder of ${ \mathrm { C o d e T } } 5 +$ and use Mean Reciprocal Rank (MRR) as the evaluation metric.
148
+
149
+ Table 5: Ablation results of Code $\mathrm { T } 5 +$ : a) no causal LM objective during stage-1 pretraining, b) no matching or causal LM objective during stage-2 pretraining.
150
+
151
+ <table><tr><td rowspan="2">Model</td><td colspan="2">Code Completion</td><td colspan="2">Math Programming</td></tr><tr><td>PY150 EM</td><td>JavaCorpus EM</td><td>MathQA-PY pass@80</td><td>GSM8K-PY pass @100</td></tr><tr><td>CodeT5+770M</td><td>44.9</td><td>37.9</td><td>87.4</td><td>73.8</td></tr><tr><td>a) no causal LM</td><td>36.2</td><td>24.8</td><td>72.3</td><td>61.4</td></tr></table>
152
+
153
+ <table><tr><td rowspan="2">Model</td><td colspan="7">Text-to-code Retrieval</td></tr><tr><td>Ruby</td><td>JS</td><td>Go</td><td>Python</td><td>Java</td><td>PHP</td><td>Overall</td></tr><tr><td>CodeT5+770M</td><td>78.0</td><td>71.3</td><td>92.7</td><td>75.8</td><td>76.2</td><td>70.1</td><td>77.4</td></tr><tr><td rowspan="2">no matching b) no causal LM</td><td>76.2</td><td>68.5</td><td>91.2</td><td>72.8</td><td>73.6</td><td>66.3</td><td>74.8</td></tr><tr><td>77.3</td><td>70.6</td><td>92.4</td><td>75.7</td><td>75.6</td><td>68.9</td><td>76.8</td></tr></table>
154
+
155
+ From Table 4, our CodeT $^ { 5 + }$ 220M significantly outperforms all existing encoder-only/decoder-only (the top block) and encoder-decoder models (the middle block). Our CodeT $5 +$ 770M further sets new SoTA results, surpassing the previous SoTA UniXcoder by more than 3 MRR points on all 3 tasks across 8 datasets. This implies CodeT $^ { 5 + }$ is a robust code retriever to handle queries with diverse formats and PLs. Besides, Code $\mathrm { T } 5 + 2 2 0 \mathrm { M }$ yields substantial performance gains over CodeT5 220M, which can be attributed to the text-code contrastive learning and matching objectives that facilitate better unimodal and bimodal representation learning.
156
+
157
+ # 5.5 Ablation Study
158
+
159
+ We conduct an ablation study to analyze the impacts of our proposed pretraining objectives: a) casual LM objectives at stage-1 unimodal pretraining on two generative tasks including code completion and math programming, b) text-code matching and causal LM objectives at stage-2 bimodal pretraining on an understanding task of text-to-code retrieval. We employ $\mathrm { C o d e T } 5 + 7 7 0 \mathrm { M }$ and report the results of three representative tasks over 10 datasets in Table 5. In CodeT5+, we found that causal LM objective plays a crucial role in code completion and math programming tasks, observed by a significant performance drop after removing it. This indicates causal LM can complement the span denoising objective and improve the generation capability of our models. Additionally, we found that the text-code matching objective is critical to the retrieval performance (a drop of 2.6 avg. MRR over 6 datasets without it), implying this objective can learn a better bimodal representation that captures the fine-grained alignment between text and code. Besides, we found that retrieval tasks can also benefit from the joint training with causal LM objective despite their task differences.
160
+
161
+ Table 6: Results of retrieval-augmented code generation. EM: Exact Match, B4: BLEU-4, CB: CodeBLEU.
162
+
163
+ <table><tr><td rowspan="2">Model</td><td colspan="3">Java</td><td colspan="3">Python</td></tr><tr><td>EM</td><td>B4</td><td>CB</td><td>EM</td><td>B4</td><td>CB</td></tr><tr><td colspan="7">Retrieval-based</td></tr><tr><td>BM25</td><td>0.00</td><td>4.90</td><td>16.00</td><td>0.00</td><td>6.63</td><td>13.49</td></tr><tr><td>SCODE-R 125M</td><td>0.00</td><td>25.34</td><td>26.68</td><td>0.00</td><td>22.75</td><td>23.92</td></tr><tr><td>CodeT5+ 220M</td><td>0.00</td><td>28.74</td><td>31.00</td><td>0.00</td><td>27.30</td><td>26.51</td></tr><tr><td colspan="7">Generative</td></tr><tr><td>CodeBERT125M</td><td>0.00</td><td>8.38</td><td>14.52</td><td>0.00</td><td>4.06</td><td>10.42</td></tr><tr><td>GraphCodeBERT 125M</td><td>0.00</td><td>7.86</td><td>14.53</td><td>0.00</td><td>3.97</td><td>10.55</td></tr><tr><td>PLBART140M</td><td>0.00</td><td>10.10</td><td>14.96</td><td>0.00</td><td>4.89</td><td>12.01</td></tr><tr><td>CodeT5+ 220M</td><td>0.00</td><td>10.33</td><td>20.54</td><td>0.00</td><td>4.40</td><td>13.88</td></tr><tr><td colspan="7">Retrieval-Augmented Generative</td></tr><tr><td>REDCODER-EXT125M+140M</td><td>10.21</td><td>28.98</td><td>33.18</td><td>9.61</td><td>24.43</td><td>30.21</td></tr><tr><td>CodeT5+ 220M</td><td>11.66</td><td>33.83</td><td>40.60</td><td>11.83</td><td>31.14</td><td>36.39</td></tr></table>
164
+
165
+ # 5.6 Unified Retrieval-Augmented Generation
166
+
167
+ As our model is capable of both code retrieval and generation, it can be naturally exploited as a unified retrieval-augmented generator. To explore this adaptation, we follow Parvez et al. (2021) to evaluate two code generation tasks on Java and Python. We evaluate our models in 3 settings: retrievalbased, generative, and retrieval-augmented (RA) generative. For the retrieval-based setting, we activate our encoder to retrieve the top-1 code sample as the prediction given a text query, while for the RA generative setting, we append the combination of top- $k$ retrieved samples $k { = } 1$ in our work) to the encoder input and activate the decoder. As shown in Table 6, we found that our CodeT $^ { 5 + }$ achieves better results in all categories, especially in the retrieval-based and RA generative setting. While the previous SoTA model REDCODER-EXT (Parvez et al., 2021) separately employs GraphCodeBERT as the retriever and PLBART as the generator, our model can be seamlessly deployed as a unified end-to-end system with both retrieval and generation capabilities.
168
+
169
+ # 6 Conclusion
170
+
171
+ We propose CodeT $^ { 5 + }$ , a new family of open code LLMs with a dynamic architecture that can flexibly operate in different modes (encoder-only, decoderonly, and encoder-decoder) to support a wide range of code understanding and generation tasks. To train CodeT $^ { 5 + }$ , we introduce a mixture of pretraining tasks to learn rich representations from both unimodal code data and bimodal code-text data. Additionally, it achieves efficient model scaling and better task generalization through integration with frozen LLMs and instruction tuning. Extensive experiments on over 20 code intelligence benchmarks have verified the superiority of our models.
172
+
173
+ # Limitations
174
+
175
+ As a family of Transformer LLMs, CodeT5+ requires sufficient pretraining/finetuning data to be able to learn meaningful contextual representations from code. While we could curate these data from public domains such as GitHub, thorough data filtering and preprocessing steps are needed to obtain a good level of data quality for pretraining. During instruction finetuning, a well designed pipeline is needed to obtain high quality instruction-following data, either through manual annotation effort or synthetic data augmentation from other LLMs (e.g. OpenAI GPT models). Moreover, the level of the diversity and quality of data needed to train these types of models is still an open question. Recent attempts such as (Zhou et al., 2023) have highlighted the importance of data quality vs. data scale to efficiently train LLMs while keeping the cost of handling data affordable.
176
+
177
+ Another limitation of ${ \mathrm { C o d e T } } 5 +$ is the requirement of large GPU resources. With model sizes up to billion parameters, to handle these models efficiently requires access to GPUs during either training and inference time. Specifically, we found that fitting a 16B model into a single A100 GPU requires additional model serving/loading techniques to keep the system memory consumption acceptable. While GPU resources have become more and more accessible to the wider community of practitioners, the cost of training/testing LLMs on large-scale data can accumulate and become too expensive to many individuals.
178
+
179
+ promoting responsible and ethical use of large language models for code.
180
+
181
+ Additionally, it is essential to recognize the broader intellectual property implications of code generation and retrieval systems before deployment. Deep learning models generating code may inadvertently introduce security vulnerabilities. To mitigate this risk, it is crucial to conduct expert reviews and rigorous security assessments before adopting such code. This review process ensures that the generated code meets necessary security standards, safeguarding against potential exploits and vulnerabilities. In code retrieval scenarios, providing appropriate attribution to the source along with the retrieved results is paramount. This attribution not only respects the rights of code authors but also enhances transparency, traceability, and collaboration within the programming community. By acknowledging the original authors and promoting a collaborative, ethical, and legally compliant environment, code retrieval systems can foster knowledge sharing and contribute to a reputable programming ecosystem.
182
+
183
+ By considering these ethical considerations, we can promote the responsible deployment of large language models for code, maximizing their potential benefits while mitigating potential harms to individuals, communities, and the overall software ecosystem. It is imperative to prioritize safety, nontoxicity, intellectual property rights, security, and collaboration in the development and deployment of these systems, ensuring they align with ethical principles and societal needs.
184
+
185
+ # Ethics Statement
186
+
187
+ Advancements in code understanding and generation systems hold immense potential to create positive societal impacts by improving programming accessibility and enhancing developer productivity through natural language interfaces. However, deploying such systems at scale requires careful consideration of various ethical aspects, as extensively discussed by Chen et al. (2021).
188
+
189
+ One critical concern is the potential risk of generated code summaries or comments incorporating toxic or insensitive language, which can have detrimental effects. Several studies have explored techniques to address this issue, such as reinforcement learning (Ouyang et al., 2022), weighted decoding (Krause et al., 2021) , and safety-specific control tokens (Xu et al., 2020). These approaches aim to ensure non-toxic natural language generation,
190
+
191
+ # References
192
+
193
+ Wasi Uddin Ahmad, Saikat Chakraborty, Baishakhi Ray, and Kai-Wei Chang. 2021. Unified pre-training for program understanding and generation. In NAACLHLT, pages 2655–2668. Association for Computational Linguistics.
194
+
195
+ Jean-Baptiste Alayrac, Jeff Donahue, Pauline Luc, Antoine Miech, Iain Barr, Yana Hasson, Karel Lenc, Arthur Mensch, Katherine Millican, Malcolm Reynolds, Roman Ring, Eliza Rutherford, Serkan Cabi, Tengda Han, Zhitao Gong, Sina Samangooei, Marianne Monteiro, Jacob L. Menick, Sebastian Borgeaud, Andy Brock, Aida Nematzadeh, Sahand Sharifzadeh, Mikolaj Binkowski, Ricardo Barreira, Oriol Vinyals, Andrew Zisserman, and Karén Simonyan. 2022. Flamingo: a visual language model for few-shot learning. In NeurIPS.
196
+
197
+ Miltiadis Allamanis and Charles Sutton. 2013. Mining source code repositories at massive scale using language modeling. In MSR, pages 207–216. IEEE Computer Society.
198
+
199
+ Aida Amini, Saadia Gabriel, Shanchuan Lin, Rik Koncel-Kedziorski, Yejin Choi, and Hannaneh Hajishirzi. 2019. MathQA: Towards interpretable math word problem solving with operation-based formalisms. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers), pages 2357–2367, Minneapolis, Minnesota. Association for Computational Linguistics.
200
+
201
+ Jacob Austin, Augustus Odena, Maxwell Nye, Maarten Bosma, Henryk Michalewski, David Dohan, Ellen Jiang, Carrie Cai, Michael Terry, Quoc Le, et al. 2021. Program synthesis with large language models. arXiv preprint arXiv:2108.07732.
202
+
203
+ Sid Black, Stella Biderman, Eric Hallahan, Quentin Anthony, Leo Gao, Laurence Golding, Horace He, Connor Leahy, Kyle McDonell, Jason Phang, Michael Pieler, USVSN Sai Prashanth, Shivanshu Purohit, Laria Reynolds, Jonathan Tow, Ben Wang, and Samuel Weinbach. 2022. GPT-NeoX-20B: An opensource autoregressive language model. In Proceedings of the ACL Workshop on Challenges & Perspectives in Creating Large Language Models.
204
+
205
+ Sahil Chaudhary. 2023. Code alpaca: An instructionfollowing llama model for code generation. https: //github.com/sahil280114/codealpaca.
206
+
207
+ Bei Chen, Fengji Zhang, Anh Nguyen, Daoguang Zan, Zeqi Lin, Jian-Guang Lou, and Weizhu Chen. 2023. Codet: Code generation with generated tests. In The Eleventh International Conference on Learning Representations.
208
+
209
+ Mark Chen, Jerry Tworek, Heewoo Jun, Qiming Yuan, Henrique Ponde de Oliveira Pinto, Jared Kaplan, Harri Edwards, Yuri Burda, Nicholas Joseph, Greg Brockman, et al. 2021. Evaluating large language models trained on code. arXiv preprint arXiv:2107.03374.
210
+
211
+ Aakanksha Chowdhery, Sharan Narang, Jacob Devlin, Maarten Bosma, Gaurav Mishra, Adam Roberts, Paul Barham, Hyung Won Chung, Charles Sutton, Sebastian Gehrmann, Parker Schuh, Kensen Shi, Sasha Tsvyashchenko, Joshua Maynez, Abhishek Rao, Parker Barnes, Yi Tay, Noam Shazeer, Vinodkumar Prabhakaran, Emily Reif, Nan Du, Ben Hutchinson, Reiner Pope, James Bradbury, Jacob Austin, Michael Isard, Guy Gur-Ari, Pengcheng Yin, Toju Duke, Anselm Levskaya, Sanjay Ghemawat, Sunipa Dev, Henryk Michalewski, Xavier Garcia, Vedant Misra, Kevin Robinson, Liam Fedus, Denny Zhou, Daphne Ippolito, David Luan, Hyeontaek Lim, Barret Zoph, Alexander Spiridonov, Ryan Sepassi, David Dohan, Shivani Agrawal, Mark Omernick, Andrew M. Dai, Thanumalayan Sankaranarayana Pillai, Marie Pellat, Aitor Lewkowycz, Erica Moreira, Rewon Child, Oleksandr Polozov, Katherine Lee,
212
+
213
+ Zongwei Zhou, Xuezhi Wang, Brennan Saeta, Mark Diaz, Orhan Firat, Michele Catasta, Jason Wei, Kathy Meier-Hellstern, Douglas Eck, Jeff Dean, Slav Petrov, and Noah Fiedel. 2022. Palm: Scaling language modeling with pathways. CoRR, abs/2204.02311.
214
+
215
+ Karl Cobbe, Vineet Kosaraju, Mohammad Bavarian, Jacob Hilton, Reiichiro Nakano, Christopher Hesse, and John Schulman. 2021. Training verifiers to solve math word problems. CoRR, abs/2110.14168.
216
+
217
+ Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. 2019. BERT: pre-training of deep bidirectional transformers for language understanding. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, NAACL-HLT 2019, Minneapolis, MN, USA, June 2-7, 2019, Volume 1 (Long and Short Papers), pages 4171–4186.
218
+
219
+ Li Dong, Nan Yang, Wenhui Wang, Furu Wei, Xiaodong Liu, Yu Wang, Jianfeng Gao, Ming Zhou, and Hsiao-Wuen Hon. 2019. Unified language model pre-training for natural language understanding and generation. In Advances in Neural Information Processing Systems 32: Annual Conference on Neural Information Processing Systems 2019, NeurIPS 2019, December 8-14, 2019, Vancouver, BC, Canada, pages 13042–13054.
220
+
221
+ Zhangyin Feng, Daya Guo, Duyu Tang, Nan Duan, Xiaocheng Feng, Ming Gong, Linjun Shou, Bing Qin, Ting Liu, Daxin Jiang, and Ming Zhou. 2020. Codebert: A pre-trained model for programming and natural languages. In EMNLP (Findings), volume EMNLP 2020 of Findings of ACL, pages 1536–1547. Association for Computational Linguistics.
222
+
223
+ Daniel Fried, Armen Aghajanyan, Jessy Lin, Sida Wang, Eric Wallace, Freda Shi, Ruiqi Zhong, Wen-tau Yih, Luke Zettlemoyer, and Mike Lewis. 2022. Incoder: A generative model for code infilling and synthesis. CoRR, abs/2204.05999.
224
+
225
+ Daya Guo, Shuai Lu, Nan Duan, Yanlin Wang, Ming Zhou, and Jian Yin. 2022. Unixcoder: Unified crossmodal pre-training for code representation. In $A C L$ (1), pages 7212–7225. Association for Computational Linguistics.
226
+
227
+ Daya Guo, Shuo Ren, Shuai Lu, Zhangyin Feng, Duyu Tang, Shujie Liu, Long Zhou, Nan Duan, Alexey Svyatkovskiy, Shengyu Fu, Michele Tufano, Shao Kun Deng, Colin B. Clement, Dawn Drain, Neel Sundaresan, Jian Yin, Daxin Jiang, and Ming Zhou. 2021. Graphcodebert: Pre-training code representations with data flow. In ICLR. OpenReview.net.
228
+
229
+ Kaiming He, Haoqi Fan, Yuxin Wu, Saining Xie, and Ross B. Girshick. 2020. Momentum contrast for unsupervised visual representation learning. In CVPR, pages 9726–9735. Computer Vision Foundation / IEEE.
230
+
231
+ Dan Hendrycks, Steven Basart, Saurav Kadavath, Mantas Mazeika, Akul Arora, Ethan Guo, Collin Burns, Samir Puranik, Horace He, Dawn Song, and Jacob Steinhardt. 2021. Measuring coding challenge competence with apps. NeurIPS.
232
+
233
+ Junjie Huang, Duyu Tang, Linjun Shou, Ming Gong, Ke Xu, Daxin Jiang, Ming Zhou, and Nan Duan. 2021. Cosqa: 20, $0 0 0 +$ web queries for code search and question answering. In ACL/IJCNLP (1), pages 5690–5700. Association for Computational Linguistics.
234
+
235
+ Hamel Husain, Ho-Hsiang Wu, Tiferet Gazit, Miltiadis Allamanis, and Marc Brockschmidt. 2019. Codesearchnet challenge: Evaluating the state of semantic code search. CoRR, abs/1909.09436.
236
+
237
+ Jeff Johnson, Matthijs Douze, and Hervé Jégou. 2019. Billion-scale similarity search with GPUs. IEEE Transactions on Big Data, 7(3):535–547.
238
+
239
+ Vladimir Karpukhin, Barlas Oguz, Sewon Min, Patrick S. H. Lewis, Ledell Wu, Sergey Edunov, Danqi Chen, and Wen-tau Yih. 2020. Dense passage retrieval for open-domain question answering. In EMNLP (1), pages 6769–6781. Association for Computational Linguistics.
240
+
241
+ Ben Krause, Akhilesh Deepak Gotmare, Bryan McCann, Nitish Shirish Keskar, Shafiq Joty, Richard Socher, and Nazneen Fatema Rajani. 2021. GeDi: Generative discriminator guided sequence generation. In Findings of the Association for Computational Linguistics: EMNLP 2021, pages 4929–4952, Punta Cana, Dominican Republic. Association for Computational Linguistics.
242
+
243
+ Hung Le, Yue Wang, Akhilesh Deepak Gotmare, Silvio Savarese, and Steven C. H. Hoi. 2022. Coderl: Mastering code generation through pretrained models and deep reinforcement learning. In NeurIPS.
244
+
245
+ Aitor Lewkowycz, Anders Johan Andreassen, David Dohan, Ethan Dyer, Henryk Michalewski, Vinay Venkatesh Ramasesh, Ambrose Slone, Cem Anil, Imanol Schlag, Theo Gutman-Solo, Yuhuai Wu, Behnam Neyshabur, Guy Gur-Ari, and Vedant Misra. 2022. Solving quantitative reasoning problems with language models. In Advances in Neural Information Processing Systems.
246
+
247
+ Junnan Li, Dongxu Li, Caiming Xiong, and Steven C. H. Hoi. 2022a. BLIP: bootstrapping languageimage pre-training for unified vision-language understanding and generation. In ICML, volume 162 of Proceedings of Machine Learning Research, pages 12888–12900. PMLR.
248
+
249
+ Junnan Li, Ramprasaath R. Selvaraju, Akhilesh Gotmare, Shafiq R. Joty, Caiming Xiong, and Steven Chu-Hong Hoi. 2021. Align before fuse: Vision and language representation learning with momentum distillation. In NeurIPS, pages 9694–9705.
250
+
251
+ aymond Li, Loubna Ben Allal, Yangtian Zi, Niklas Muennighoff, Denis Kocetkov, Chenghao Mou, Marc Marone, Christopher Akiki, Jia Li, Jenny Chim, Qian Liu, Evgenii Zheltonozhskii, Terry Yue Zhuo, Thomas Wang, Olivier Dehaene, Mishig Davaadorj, Joel Lamy-Poirier, João Monteiro, Oleh Shliazhko, Nicolas Gontier, Nicholas Meade, Armel Zebaze, Ming-Ho Yee, Logesh Kumar Umapathi, Jian Zhu, Benjamin Lipkin, Muhtasham Oblokulov, Zhiruo Wang, Rudra Murthy V, Jason Stillerman, Siva Sankalp Patel, Dmitry Abulkhanov, Marco Zocca, Manan Dey, Zhihan Zhang, Nour Fahmy, Urvashi Bhattacharyya, Wenhao Yu, Swayam Singh, Sasha Luccioni, Paulo Villegas, Maxim Kunakov, Fedor Zhdanov, Manuel Romero, Tony Lee, Nadav Timor, Jennifer Ding, Claire Schlesinger, Hailey Schoelkopf, Jan Ebert, Tri Dao, Mayank Mishra, Alex Gu, Jennifer Robinson, Carolyn Jane Anderson, Brendan Dolan-Gavitt, Danish Contractor, Siva Reddy, Daniel Fried, Dzmitry Bahdanau, Yacine Jernite, Carlos Muñoz Ferrandis, Sean Hughes, Thomas Wolf, Arjun Guha, Leandro von Werra, and Harm de Vries. 2023. Starcoder: may the source be with you! CoRR, abs/2305.06161.
252
+
253
+ Yujia Li, David H. Choi, Junyoung Chung, Nate Kushman, Julian Schrittwieser, Rémi Leblond, Tom Eccles, James Keeling, Felix Gimeno, Agustin Dal Lago, Thomas Hubert, Peter Choy, Cyprien de Masson d’Autume, Igor Babuschkin, Xinyun Chen, PoSen Huang, Johannes Welbl, Sven Gowal, Alexey Cherepanov, James Molloy, Daniel J. Mankowitz, Esme Sutherland Robson, Pushmeet Kohli, Nando de Freitas, Koray Kavukcuoglu, and Oriol Vinyals. 2022b. Competition-level code generation with alphacode. CoRR, abs/2203.07814.
254
+
255
+ Chin-Yew Lin and Franz Josef Och. 2004. ORANGE: a method for evaluating automatic evaluation metrics for machine translation. In COLING.
256
+
257
+ Yinhan Liu, Myle Ott, Naman Goyal, Jingfei Du, Mandar Joshi, Danqi Chen, Omer Levy, Mike Lewis, Luke Zettlemoyer, and Veselin Stoyanov. 2019. Roberta: A robustly optimized BERT pretraining approach. CoRR, abs/1907.11692.
258
+
259
+ Ilya Loshchilov and Frank Hutter. 2019. Decoupled weight decay regularization. In ICLR (Poster). OpenReview.net.
260
+
261
+ Shuai Lu, Daya Guo, Shuo Ren, Junjie Huang, Alexey Svyatkovskiy, Ambrosio Blanco, Colin B. Clement, Dawn Drain, Daxin Jiang, Duyu Tang, Ge Li, Lidong Zhou, Linjun Shou, Long Zhou, Michele Tufano, Ming Gong, Ming Zhou, Nan Duan, Neel Sundaresan, Shao Kun Deng, Shengyu Fu, and Shujie Liu. 2021. Codexglue: A machine learning benchmark dataset for code understanding and generation. In NeurIPS Datasets and Benchmarks.
262
+
263
+ Anh Nguyen, Nikos Karampatziakis, and Weizhu Chen. 2023. Meet in the middle: A new pre-training paradigm. arXiv preprint arXiv:2303.07295.
264
+
265
+ Ansong Ni, Jeevana Priya Inala, Chenglong Wang, Oleksandr Polozov, Christopher Meek, Dragomir R. Radev, and Jianfeng Gao. 2022. Learning from self-sampled correct and partially-correct programs. CoRR, abs/2205.14318.
266
+
267
+ Erik Nijkamp, Hiroaki Hayashi, Caiming Xiong, Silvio Savarese, and Yingbo Zhou. 2023a. Codegen2: Lessons for training llms on programming and natural languages. arXiv preprint.
268
+
269
+ Erik Nijkamp, Bo Pang, Hiroaki Hayashi, Lifu Tu, Huan Wang, Yingbo Zhou, Silvio Savarese, and Caiming Xiong. 2023b. Codegen: An open large language model for code with multi-turn program synthesis. In The Eleventh International Conference on Learning Representations.
270
+
271
+ OpenAI. 2023. Gpt-4 technical report. ArXiv, abs/2303.08774.
272
+
273
+ Long Ouyang, Jeffrey Wu, Xu Jiang, Diogo Almeida, Carroll Wainwright, Pamela Mishkin, Chong Zhang, Sandhini Agarwal, Katarina Slama, Alex Gray, John Schulman, Jacob Hilton, Fraser Kelton, Luke Miller, Maddie Simens, Amanda Askell, Peter Welinder, Paul Christiano, Jan Leike, and Ryan Lowe. 2022. Training language models to follow instructions with human feedback. In Advances in Neural Information Processing Systems.
274
+
275
+ Md. Rizwan Parvez, Wasi Uddin Ahmad, Saikat Chakraborty, Baishakhi Ray, and Kai-Wei Chang. 2021. Retrieval augmented code generation and summarization. In EMNLP (Findings), pages 2719–2734. Association for Computational Linguistics.
276
+
277
+ Alec Radford, Jeffrey Wu, Rewon Child, David Luan, Dario Amodei, Ilya Sutskever, et al. 2019. Language models are unsupervised multitask learners. OpenAI blog, 1(8):9.
278
+
279
+ Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, and Peter J. Liu. 2020. Exploring the limits of transfer learning with a unified text-to-text transformer. J. Mach. Learn. Res., 21:140:1–140:67.
280
+
281
+ Jeff Rasley, Samyam Rajbhandari, Olatunji Ruwase, and Yuxiong He. 2020. Deepspeed: System optimizations enable training deep learning models with over 100 billion parameters. In KDD, pages 3505– 3506. ACM.
282
+
283
+ Veselin Raychev, Pavol Bielik, and Martin T. Vechev. 2016. Probabilistic model for code with decision trees. In OOPSLA, pages 731–747. ACM.
284
+
285
+ replit. 2023. replit-code-v1-3b.
286
+
287
+ Saleh Soltan, Shankar Ananthakrishnan, Jack FitzGerald, Rahul Gupta, Wael Hamza, Haidar Khan, Charith Peris, Stephen Rawls, Andy Rosenbaum, Anna Rumshisky, Chandana Satya Prakash, Mukund Sridhar, Fabian Triefenbach, Apurv Verma, Gökhan Tür, and Prem Natarajan. 2022. Alexatm 20b: Few-shot learning using a large-scale multilingual seq2seq model. CoRR, abs/2208.01448.
288
+
289
+ Jeffrey Svajlenko, Judith F Islam, Iman Keivanloo, Chanchal K Roy, and Mohammad Mamun Mia. 2014. Towards a big data curated benchmark of inter-project code clones. In 2014 IEEE International Conference on Software Maintenance and Evolution, pages 476– 480. IEEE.
290
+
291
+ Alexey Svyatkovskiy, Shao Kun Deng, Shengyu Fu, and Neel Sundaresan. 2020. Intellicode compose: code generation using transformer. In ESEC/SIGSOFT FSE, pages 1433–1443. ACM.
292
+
293
+ M Tabachnyk and S Nikolov. 2022. Ml-enhanced code completion improves developer productivity.
294
+
295
+ Rohan Taori, Ishaan Gulrajani, Tianyi Zhang, Yann Dubois, Xuechen Li, Carlos Guestrin, Percy Liang, and Tatsunori B. Hashimoto. 2023. Stanford alpaca: An instruction-following llama model. https:// github.com/tatsu-lab/stanford_alpaca.
296
+
297
+ Yi Tay, Mostafa Dehghani, Vinh Q. Tran, Xavier Garcia, Dara Bahri, Tal Schuster, Huaixiu Steven Zheng, Neil Houlsby, and Donald Metzler. 2022. Unifying language learning paradigms. CoRR, abs/2205.05131.
298
+
299
+ Hugo Touvron, Thibaut Lavril, Gautier Izacard, Xavier Martinet, Marie-Anne Lachaux, Timothée Lacroix, Baptiste Rozière, Naman Goyal, Eric Hambro, Faisal Azhar, et al. 2023. Llama: Open and efficient foundation language models. arXiv preprint arXiv:2302.13971.
300
+
301
+ Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Łukasz Kaiser, and Illia Polosukhin. 2017. Attention is all you need. Advances in neural information processing systems, 30.
302
+
303
+ Ben Wang and Aran Komatsuzaki. 2021. GPT-J6B: A 6 Billion Parameter Autoregressive Language Model. https://github.com/kingoflolz/ mesh-transformer-jax.
304
+
305
+ Weishi Wang, Yue Wang, Shafiq Joty, and Steven C. H. Hoi. 2023. Rap-gen: Retrieval-augmented patch generation with codet5 for automatic program repair. CoRR, abs/2309.06057.
306
+
307
+ Xin Wang, Yasheng Wang, Fei Mi, Pingyi Zhou, Yao Wan, Xiao Liu, Li Li, Hao Wu, Jin Liu, and Xin Jiang. 2021a. Syncobert: Syntax-guided multi-modal contrastive pre-training for code representation. arXiv preprint arXiv:2108.04556.
308
+
309
+ Yizhong Wang, Yeganeh Kordi, Swaroop Mishra, Alisa Liu, Noah A Smith, Daniel Khashabi, and Hannaneh Hajishirzi. 2022. Self-instruct: Aligning language model with self generated instructions. arXiv preprint arXiv:2212.10560.
310
+
311
+ Yue Wang, Weishi Wang, Shafiq R. Joty, and Steven C. H. Hoi. 2021b. Codet5: Identifier-aware unified pre-trained encoder-decoder models for code understanding and generation. In EMNLP (1), pages 8696– 8708. Association for Computational Linguistics.
312
+
313
+ Jing Xu, Da Ju, Margaret Li, Y-Lan Boureau, Jason Weston, and Emily Dinan. 2020. Recipes for safety in open-domain chatbots. arXiv preprint arXiv:2010.07079.
314
+
315
+ Qinkai Zheng, Xiao Xia, Xu Zou, Yuxiao Dong, Shan Wang, Yufei Xue, Zihan Wang, Lei Shen, Andi Wang, Yang Li, Teng Su, Zhilin Yang, and Jie Tang. 2023. Codegeex: A pre-trained model for code generation with multilingual evaluations on humaneval- $\mathbf { \nabla } \cdot \mathbf { X }$ .
316
+
317
+ Chunting Zhou, Pengfei Liu, Puxin Xu, Srini Iyer, Jiao Sun, Yuning Mao, Xuezhe Ma, Avia Efrat, Ping Yu, Lili Yu, et al. 2023. Lima: Less is more for alignment. arXiv preprint arXiv:2305.11206.
318
+
319
+ Yaqin Zhou, Shangqing Liu, Jingkai Siow, Xiaoning Du, and Yang Liu. 2019. Devign: Effective vulnerability identification by learning comprehensive program semantics via graph neural networks. Advances in neural information processing systems, 32.
320
+
321
+ # A Bimodal Pretraining Details
322
+
323
+ To expose the model on more diverse set of pretraining data, we employ a stage-wise pretraining process to first train CodeT $^ { 5 + }$ on large-scale codeonly data with span denoising and causal language modeling (CLM) tasks, then train on smaller set of text-code bimodel data using text-code contrastive learning, matching, and causal LM tasks. Below, we provide detailed formulas for text-code contrastive learning and matching tasks at the secondstage pretraining on text-code pairs.
324
+
325
+ Text-Code Contrastive Learning activates the encoder to learn better unimodal (text/code) representations by computing a similarity score such that parallel text-code pairs have higher scores. Given a text $\mathrm { T }$ and a code C, we first learn representations $\mathbf { h } ^ { t }$ for text $T$ and $\mathbf { h } ^ { c }$ for code $C$ by mapping the [CLS] embeddings to normalized lowerdimensional (256-d) representations from the encoder. Given a tain text vectors $\{ \mathbf { h } ^ { t } \} _ { i = 1 } ^ { N }$ $N$ text-code paird code vectors $\{ \mathbf { h } ^ { c } \} _ { i = 1 } ^ { N }$ to compute text-to-code and code-to-text and similarities:
326
+
327
+ $$
328
+ s _ { i , j } ^ { t 2 c } = \mathbf { h } _ { i } ^ { t \top } \mathbf { h } _ { j } ^ { c } , s _ { i , j } ^ { c 2 t } = \mathbf { h } _ { i } ^ { c \top } \mathbf { h } _ { j } ^ { t }
329
+ $$
330
+
331
+ $$
332
+ p _ { i } ^ { t 2 c } ( T ) = \frac { \exp { ( s _ { i , i } ^ { t 2 c } / \tau ) } } { \sum _ { j = 1 } ^ { N } \exp { ( s _ { i , j } ^ { t 2 c } / \tau ) } } ,
333
+ $$
334
+
335
+ Table 7: Data statistics of both unimodal and bimodal (CodeSearchNet) pretraining data.
336
+
337
+ <table><tr><td>Dataset</td><td>Language Ruby</td><td>#Sample</td><td>Total size</td></tr><tr><td>Ours</td><td>JavaScript Go Python Java PHP C C++ C#</td><td>2,119,741 5,856,984 1,501,673 3,418,376 10,851,759 4,386,876 4,187,467 2,951,945 4,119,796</td><td>37,274,876 files</td></tr><tr><td>CSN</td><td>Ruby JavaScript Go Python Java PHP</td><td>49,009 125,166 319,132 453,772 457,381 525,357</td><td>1,929,817 text-code pairs at function level</td></tr></table>
338
+
339
+ $$
340
+ p _ { i } ^ { c 2 t } ( C ) = \frac { \exp { ( s _ { i , i } ^ { c 2 t } / \tau ) } } { \sum _ { j = 1 } ^ { N } \exp { ( s _ { i , j } ^ { c 2 t } / \tau ) } }
341
+ $$
342
+
343
+ where $s _ { i , j } ^ { t 2 c }$ represents text-to-code similarity of text of $i$ -th pair and code of $j$ -th pair, and $s _ { i , j } ^ { c 2 t }$ is the code-to-text similarity, $\tau$ is learned temperature parameter. $p _ { i } ^ { t 2 c } ( T )$ and $p _ { i } ^ { c 2 t } ( C )$ are the softmaxnormalized text-to-code and code-to-text similarities for the $i$ -th text and code.
344
+
345
+ Let $\mathbf { y } ^ { t 2 c } ( T )$ and $\mathbf { y } ^ { c 2 t } ( C )$ denote the groundtruth one-hot similarity, where negative pairs have a probability of 0 and the positive pair has a probability of 1. The text-code contrastive loss from a corpus $D$ of text-code pairs is defined as the crossentropy $_ \mathrm { H }$ between $\mathbf { p }$ and $\mathbf { y }$ :
346
+
347
+ $$
348
+ \begin{array} { r } { \mathcal { L } _ { t c c } = \displaystyle \frac { 1 } { 2 } \mathbb { E } _ { ( T , C ) \sim D } [ H ( \mathbf { y } ^ { t 2 c } ( T ) , \mathbf { p } ^ { t 2 c } ( T ) ) + } \\ { H ( \mathbf { y } ^ { c 2 t } ( C ) , \mathbf { p } ^ { c 2 t } ( C ) ) ] } \end{array}
349
+ $$
350
+
351
+ Text-Code Matching activates the decoder with the bimodal matching functionality to predict whether a pair of text and code is positive (matched) or negative (unmatched). We employ the output embedding of the [EOS] token as the fused bimodal representation for a text-code pair $( T , C )$ , as this token attends to all the previous context for the text-code pair input. Followed by a linear layer and softmax, we compute a two-class probability $p ^ { t c m } ( T , C )$ and define the matching loss:
352
+
353
+ $$
354
+ \mathcal { L } _ { t c m } = \mathbb { E } _ { ( T , C ) \sim D } [ H ( \mathbf { y } ^ { t c m } ( T , C ) , \mathbf { p } ^ { t c m } ( T , C ) ) ]
355
+ $$
356
+
357
+ where $\mathbf { y } ^ { t c m } ( T , C )$ is a 2-dimensional one-hot vector representing the ground-truth label.
358
+
359
+ ![](images/4240252f71adcfc8d52acd23d47c77872287d36f2970b0c20b1199da686faa42.jpg)
360
+ Figure 5: Example generated instruction data: we demonstrate some examples of instruction data used to finetune CodeT $^ { 5 + }$ to better align our models to natural language instructions. The instruction corpus contains novel tasks, such as text-to-SQL generation and Python code optimization.
361
+
362
+ Text-Code Causal LM. This task focuses on a cross-modal causal LM objective between text and code through a dual multimodal conversion: textto-code generation and code-to-text generation (i.e. code summarization). Let $\mathcal { L } _ { t 2 c }$ and $\mathcal { L } _ { c 2 t }$ denote the losses for text-to-code and code-to-text generation. The full second-stage pretraining loss of our CodeT $5 +$ is:
363
+
364
+ $$
365
+ \mathcal { L } = \mathcal { L } _ { t c c } + \mathcal { L } _ { t c m } + \mathcal { L } _ { t 2 c } + \mathcal { L } _ { c 2 t }
366
+ $$
367
+
368
+ # B Pretraining
369
+
370
+ # B.1 Pretraining Dataset
371
+
372
+ We report the data statistics of both unimodal code and bimodal text-code pretraining datasets in Table 7. From the table, we can see that our curated dataset from GitHub code has a much larger data size at the file level than the CodeSearchNet bimodal data at the function level, allowing our model to learn rich representations in the first stage of pretraining. Different from CodeT5 (Wang et al., 2021b) which employs both unimodal and bimodal data in CodeSearchNet (Husain et al., 2019), we only employ its bimodal subset for the second stage pretraining of our CodeT5+. We use this stage to mainly adapt our model to text-code related tasks like text-to-code retrieval and generation.
373
+
374
+ # B.2 Pretraining Setup
375
+
376
+ In pretraining, we adopt a stage-wise strategy to pretrain CodeT $^ { 5 + }$ first on the large-scale unimodal dataset and then on the smaller bimodal dataset. In the first stage, we warm up the model with the span denoising task for $1 0 k$ training steps, and then joint training with the two CLM tasks with equal weights for $1 0 0 k$ steps. We employ a linear decay learning rate (LR) scheduler with a peak learning rate of 2e4 and set the batch size to 2048 for denoising and 512 for CLM. To prepare the input and output data, we set the maximum length to 512 for the denoising task, and set the maximum lengths to 768 and 600 for source and target sequences for the code completion CLM, 1 and 1024 for the decoder-only generation CLM. In the second stage, we jointly optimize four losses of contrastive learning, matching, and two CLM losses with equal weights for 10 epochs with a batch size of 256. We employ a peak learning rate of 1e-4 and set the maximum sequence lengths to 420 and 128 for code and text.
377
+
378
+ In all experiments, we employ an AdamW optimizer (Loshchilov and Hutter, 2019) with a 0.1 weight decay. We also employ the DeepSpeed’s ZeRO Stage 2 (Rasley et al., 2020) with mixed precision training of FP16 for training acceleration. For the training of CodeT $5 +$ 2B, 6B, and 16B, we use FP16 frozen decoder weights and keep other trainable weights in FP32. We use DeepSpeed ZeRO Stage 3’s parameter partition for CodeT5 $\mid +$ 6B and 16B models.
379
+
380
+ # C Instruction Tuning
381
+
382
+ Fig. 5 illustrates some examples of the generated instruction data. Note that as we rely on LMgenerated data, including the annotations of expected outputs, not all of the data is perfectly correct. For instance, the example of the code optimization task in Fig. 5 contains a wrong output. Wang et al. (2022) treated these examples as data noise and the tuned models still benefit from the majority of the synthetic instruction dataset.
383
+
384
+ Table 8: Results of BLEU-4 on code summarization.
385
+
386
+ <table><tr><td>Model</td><td>Ruby</td><td>JS</td><td>Go</td><td>Python</td><td>Java</td><td>PHP</td><td>Overall</td></tr><tr><td>RoBERTa125M</td><td>11.17</td><td>11.90</td><td>17.72</td><td>18.14</td><td>16.47</td><td>24.02</td><td>16.57</td></tr><tr><td>CodeBERT125M</td><td>12.16</td><td>14.90</td><td>18.07</td><td>19.06</td><td>17.65</td><td>25.16</td><td>17.83</td></tr><tr><td>UniXcoder 125M</td><td>14.87</td><td>15.85</td><td>19.07</td><td>19.13</td><td>20.31</td><td>26.54</td><td>19.30</td></tr><tr><td>CodeGen-multi 350M</td><td>13.48</td><td>16.54</td><td>18.09</td><td>18.31</td><td>19.41</td><td>24.41</td><td>18.37</td></tr><tr><td>PLBART140M</td><td>14.11</td><td>15.56</td><td>18.91</td><td>19.30</td><td>18.45</td><td>23.58</td><td>18.32</td></tr><tr><td>CodeT5220M</td><td>15.24</td><td>16.16</td><td>19.56</td><td>20.01</td><td>20.31</td><td>26.03</td><td>19.55</td></tr><tr><td>CodeT5+220M</td><td>15.51</td><td>16.27</td><td>19.60</td><td>20.16</td><td>20.53</td><td>26.78</td><td>19.81</td></tr><tr><td>CodeT5+770M</td><td>15.63</td><td>17.93</td><td>19.64</td><td>20.47</td><td>20.83</td><td>26.39</td><td>20.15</td></tr></table>
387
+
388
+ # D Additional Experimental Results
389
+
390
+ In this section, we provide additional experimental results including code summarization (Appendix D.1), two understanding tasks of code defect detection and clone detection from the CodeXGLUE (Lu et al., 2021) (Appendix D.2), more analysis on retrieval-augmented code generation (Appendix D.3), and more qualitative results in math programming tasks (Appendix D.4).
391
+
392
+ # D.1 Code Summarization from CodeXGLUE
393
+
394
+ The code summarization task aims to summarize a code snippet into natural language docstrings. We employ the clean version of CodeSearchNet dataset (Husain et al., 2019) in six programming languages to evaluate our models for this task. We employ BLEU-4 (Lin and Och, 2004) as the performance metric which measures the token-based similarity between predicted and ground-truth summaries. From pretrained ${ \mathrm { C o d e T } } 5 +$ , we activate both encoder and decoder for this task.
395
+
396
+ From Table 8, we found that encoder-decoder models (CodeT5 and CodeT $^ { 5 + }$ ) generally outperform both encoder-only models (Feng et al., 2020) and decoder-only models (Nijkamp et al., 2023b), as well as the UniLM-style model UniXcoder (Guo et al., 2022). This observation demonstrates the benefit of using the encoder-decoder architecture in ${ \mathrm { C o d e T } } 5 +$ to better encode code contexts and generate more accurate code summaries. Finally, we also observed some performance gains against CodeT5 (Wang et al., 2021b), indicating the advantage of our proposed mixture of diverse pretraining learning objectives in addition to the span denoising objective in CodeT5.
397
+
398
+ # D.2 Code Defect Detection and Clone Detection from CodeXGLUE
399
+
400
+ Defect detection is to predict whether a code is vulnerable to software systems or not, while clone detection aims to measure the similarity between two code snippets and predict whether they have a common functionality. We use benchmarks from CodeXGLUE (Lu et al., 2021) and use accuracy and F1 score as the metrics. In Table 9, we can see CodeT $^ { 5 + }$ models achieve new SoTA accuracy of $6 6 . 7 \%$ on the defect detection task. For the clone detection task, our model achieves comparable results to SoTA models, where the performance increase tends to be saturated, observed by the close performance gaps between multiple baselines.
401
+
402
+ Table 9: Results on two understanding tasks: code defect detection and code clone detection.
403
+
404
+ <table><tr><td rowspan="2">Model</td><td>Defect</td><td colspan="3">Clone Detection</td></tr><tr><td>Acc</td><td>Rec</td><td>Prec</td><td>F1</td></tr><tr><td>CodeBERT125M GraphCodeBERT125M UniXcoder125M</td><td>62.1 - 1</td><td>94.7 94.8 92.9</td><td>93.4 95.2 97.6</td><td>94.1 95.0 95.2</td></tr><tr><td>CodeGen-multi 350M PLBART140M</td><td>63.1 63.2</td><td>94.1 94.8</td><td>93.2 92.5</td><td>93.6 93.6</td></tr><tr><td>CodeT5220M</td><td>65.8</td><td>95.1</td><td>94.9</td><td>95.0</td></tr><tr><td>CodeT5+220M CodeT5+ 770M</td><td>66.1 66.7</td><td>96.4 96.7</td><td>94.1 93.5</td><td>95.2 95.1</td></tr></table>
405
+
406
+ # D.3 More Analysis on Retrieval-augmented Code Generation
407
+
408
+ We conduct an ablation study to analyze the effects of top- $k$ retrievals in retrieval-augmented code generation tasks and report the results in Table 10 . We found that increasing the number of retrievals can boost model performance which becomes saturated when $k { = } 5$ . This saturation is due to the maximum sequence length of 600, which might not be able to accommodate a large number of retrieved code samples. Overall, our CodeT $^ { 5 + }$ significantly outperforms the prior SOTA baseline which uses top10 retrievals in all cases, even with only a top-1 retrieved code.
409
+
410
+ We further include a qualitative case in Fig. 6, where we found that the retrieved code provides crucial contexts (e.g., use “urllib3” for an HTTP request) to guide the generative process for more correct prediction. In contrast, the generative-only model gives an incorrect prediction that only captures the concepts of “download” and “compress”.
411
+
412
+ # D.4 Qualitative Results in Math Programming tasks
413
+
414
+ For math programming tasks, we provide qualitative examples predicted by our models in Fig. 7 and Fig. 8. Overall, we found CodeT5+ is able to
415
+
416
+ ![](images/e1b48f6b66cf45580c2399ca55c4bc08ca71d1fc1864629293db54b621b57c1b.jpg)
417
+ Figure 6: Example code generation output: Our Code $\mathrm { T } 5 +$ retrieval-augmented generation model could retrieve relevant code context and use it to facilitate better code generation.
418
+
419
+ Table 10: Effects of varying top- $k$ retrievals in retrieval-augmented code generation tasks with our $\mathbf { C o d e T 5 + } 2 2 0 \mathbf { M }$ compared to the prior SOTA model of REDCODER-EXT that employs top-10 retrievals. EM: Exact Match, B4: BLEU-4, CB: CodeBLEU.
420
+
421
+ <table><tr><td rowspan="2">Model</td><td colspan="3">Java</td><td colspan="3">Python</td></tr><tr><td>EM</td><td>B4</td><td>CB</td><td>EM</td><td>B4</td><td>CB</td></tr><tr><td>SOTA (top-10)</td><td>10.21</td><td>28.98</td><td>33.18</td><td>9.61</td><td>24.43</td><td>30.21</td></tr><tr><td>Ours</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>top-1</td><td>11.66</td><td>33.83</td><td>40.60</td><td>11.83</td><td>31.14</td><td>36.39</td></tr><tr><td>top-2</td><td>11.57</td><td>33.26</td><td>40.74</td><td>11.78</td><td>31.21</td><td>36.58</td></tr><tr><td>top-3</td><td>12.29</td><td>33.10</td><td>41.71</td><td>12.48</td><td>30.92</td><td>37.31</td></tr><tr><td>top-4</td><td>12.42</td><td>32.08</td><td>41.94</td><td>12.73</td><td>30.40</td><td>37.60</td></tr><tr><td>top-5</td><td>13.02</td><td>32.42</td><td>42.28</td><td>12.93</td><td>30.52</td><td>37.87</td></tr><tr><td>top-10</td><td>12.86</td><td>31.38</td><td>42.24</td><td>12.84</td><td>29.79</td><td>37.79</td></tr></table>
422
+
423
+ generate decent programs that can solve the math problems in various levels of difficulties, i.e. from simple math operations to more complex problems with multiple reasoning steps. From the rightmost example of Fig. 8, we found that CodeT $^ { 5 + }$ is able to leverage some external libraries such as math when synthesizing the solutions.
424
+
425
+ # E Finetuning on Downstream Tasks
426
+
427
+ # E.1 Text-to-Code Retrieval
428
+
429
+ Text-to-code retrieval (or code search), is the task of finding the best code sample that is most relevant to a natural language query, from a collection of code candidates. We experiment CodeT5+ with three major benchmarks: CodeSearchNet (CSN) (Husain et al., 2019), CosQA (Huang et al., 2021), and AdvTest (Lu et al., 2021). CSN consists of six programming languages in total, and the dataset is curated by filtering low-quality queries through handcrafted rules, following (Guo et al., 2021). For instance, an example handcraft rule is to filter examples in which the number of tokens in query is shorter than 3 or more than 256.
430
+
431
+ CosQA and AdvTest are two related benchmarks that are both derived from the CSN data. Specifically, instead of natural language queries, CosQA uses logs from Microsoft Bing search engine as queries, each of which is annotated by 3 human annotators (Huang et al., 2021). AdvTest is created from the Python split of the CSN data but the code samples are normalized with obfuscated variable names to better evaluate the understanding abilities of current models. For training, we set the maximum sequence to 350 and 64 for code and text. We set the learning rate as 2e-5 and finetune the model for 10 epochs. We employ distributed training on 8 A100s and the total batch size is 64. For momentum encoders, we maintain a separate text/code queue with a size of 57600, and allow the matching decoder to retrieve 64 hard negatives from the queues for hard negative mining.
432
+
433
+ # E.2 Code Summarization
434
+
435
+ Code summarization is the task of generating a natural language summary of a code snippet. We use the task dataset from CodeXGLUE (Lu et al., 2021) which curated a code summarization benchmark from CSN data (Husain et al., 2019). The benchmark consists of six PLs: Ruby, JavaScript, Go, Python, Java, and PHP. It is the same clean version of CSN data that we use for text-to-code retrieval tasks. For training, we set the maximum sequence length of the source and target as 256 and 128, respectively. We use a learning rate of 2e-5,
436
+
437
+ ![](images/e2f1e3622005425fbb33c322b70e59fd43cdfaba386c34b5f86f23540f565a92.jpg)
438
+ Figure 7: Predictions of our model on GSM8K-Python
439
+
440
+ the batch size as 64 for 10 epochs of finetuning.
441
+ We set the beam size as 5 in inference.
442
+
443
+ # E.3 Code Defect Detection
444
+
445
+ Defect detection is the task of classifying whether a code sample contains vulnerability points or not. We adopt the defect detection benchmark from CodeXGLUE (Lu et al., 2021) which curated data from the Devign dataset (Zhou et al., 2019). The dataset contains in total more than 27,000 annotated functions in C programming language. All samples are collected from popular open-source projects such as QEMU and FFmpeg. We follow (Lu et al., 2021) and adopt $8 0 \% / 1 0 \% / 1 0 \%$ of the dataset as the training/validation/test split. For training, we set the learning rate as 2e-5, the batch size as 32, and the max sequence length as 512 to finetune the model for 10 epochs.
446
+
447
+ # E.4 Code Clone Detection
448
+
449
+ The task of clone detection aims to detect whether any two code samples have the same functionality or semantics. We conduct experiments using the clone detection benchmark from CodeXGLUE (Lu et al., 2021). The benchmark is curated from the BigClone dataset (Svajlenko et al., 2014) and the resulting curated data consists of 901,724/416,328/416,328 examples for training/validation/test splits respectively. All samples are categorized into 10 different functionalities. For finetuning, we set the learning rate as 2e-5 and finetune the model for 2 epochs. We set the batch size as 10, and the max sequence length as 400.
450
+
451
+ # E.5 Code Completion
452
+
453
+ In code completion, given a source sequence containing a partial code sample, a model is required to generate the remaining part of the code sample. We conduct experiments on line-level code completion using two major benchmarks: PY150 (Raychev et al., 2016) and JavaCorpus (Allamanis and Sutton, 2013). PY150 (Raychev et al., 2016) consists of 150,000 Python source files collected from Github. Among these samples, (Lu et al., 2021) selected 10,000 samples from different files from the test set of PY150 and then randomly sampled lines to be predicted for the code completion task. The average numbers of tokens in the source sequence and target sequence are 489.1 and 6.6 respectively. JavaCorpus (Allamanis and Sutton, 2013) contains over 14,000 Java projects collected from GitHub. Similarly to PY150, Lu et al. (2021) selected 3,000 samples from different files from the test set of the dataset and randomly sampled lines to be predicted for the code completion task. The average numbers of tokens in the source and target sequence are 350.6 and 10.5 respectively. For both tasks, we set the learning rate as 2e-5 and batch size as 32, and set the maximum sequence length of 1024 for the decoder. We finetune the model for 30 epochs. During inference, we employ beam search with a beam size of 5.
454
+
455
+ # E.6 Math Programming
456
+
457
+ Math Programming is the task of solving mathsbased problems with programming. Compared to conventional code generation tasks, this task fo
458
+
459
+ ![](images/f55113e2d27b98055563d96cbcb6c63b1b4feedacda254d69e9c9f9d1ad9379b.jpg)
460
+ Figure 8: Predictions of our model on MathQA-Python
461
+
462
+ Question: Natalia sold clips to 48 of her friends in April, and then she sold half as many clips in May. How many clips did Natalia sell altogether in April and May?
463
+
464
+ # Answer:
465
+
466
+ Natalia sold $4 8 / 2 = < < 4 8 / 2 = 2 4 > > 2 4$ clips in May.
467
+ Natalia sold $4 8 + 2 4 = < < 4 8 + 2 4 = 7 2 > > 7 2$ clips altogether in April and May.
468
+ Python Solution:
469
+ ${ \mathsf { n } } 0 = 4 8$
470
+ ${ \mathfrak { n } } 1 = 2$
471
+ t0 = n0 / n1
472
+ answer $= \mathsf { n } 0 + \mathsf { t } 0$
473
+
474
+ Figure 9: One example of how to convert natural language solution into a Python program on GSM8K dataset.
475
+
476
+ cuses more on computational reasoning skills. The problem descriptions in this type of task are also more complex than conventional code generation tasks. We employ two major benchmarks for this task: MathQA-Python (Austin et al., 2021) and GradeSchool-Math (Cobbe et al., 2021).
477
+
478
+ MathQA-Python (Austin et al., 2021) is developed from the MathQA dataset (Amini et al., 2019) where given a mathematical problem description in natural language, a system is required to solve this problem via generating a program that returns the final answer. (Austin et al., 2021) translated these programs into Python programs and filtered for cleaner problems. In total, MathQA-Python contains ${ \sim } 2 4 { , } 0 0 0$ problems, including 19,209/2,822/1,883 samples for training/validation/test splits.
479
+
480
+ GradeSchool-Math (Cobbe et al., 2021) (also known as GSM8K) has similar nature as MathQA. The benchmark focuses on problems with moderate difficulty that an average grade school student should be able to solve. In total, GSM data contains 8,500 problems, divided into 7,500 training and 1,000 testing problems. We translated the solution described in natural language to Python programs by following the construction process of MathQA-Python by Austin et al. (2021). Finally, we successfully converted 5,861 out of 7,500 training samples. One case can be found in Fig. 9.
481
+
482
+ For training, we set the maximum sequence length of the source and target as 256 and 256 for MathQA-Python, and 246, 138 for GSM8k-Python. We use a learning rate of 2e-5 and a batch size of 32 for 30 epochs of finetuning. During inference, we employ the beam size as 5 to get pass $@ 1$ results. For pass $@ 8 0$ and pass $@ 1 0 0$ , we found they are quite sensitive to the diversity of the generation. We employ nucleus sampling with a temperature of 1.2 and top- $\cdot p { = } 0 . 9 5$ .
483
+
484
+ # E.7 Retrieval-augmented Code Generation
485
+
486
+ Developers often search for relevant code snippets from sources on the web such as GitHub or StackOverflow as references to aid their software development process. Motivated by this behaviour, we explore a retrieval-augmented code generation setting, where given a natural language description, a retriever first retrieves similar candidates in a search codebase and then augments the input for the generator to produce the target code. Such retrieval-augmented generation (or retrievethen-generate) paradigm has been widely used in open-domain question answering (Karpukhin et al., 2020) in NLP and recently extended to some coderelated tasks such as code generation and summarization (Parvez et al., 2021), and program repair tasks (Wang et al., 2023). As our CodeT $^ { 5 + }$ is capable of both retrieval and generation, it can be seamlessly adapted as a unified retrieval-augmented generator. This can bring unique benefits such as less computational cost compared to prior work that employs a different retriever and generator. We evaluate CodeT $^ { 5 + }$ on two Java and Python code generation datasets from the CodeXGLUE (Lu et al., 2021) benchmark following Parvez et al. (2021).
487
+
488
+ Specifically, we leverage the encoder to encode the code snippet in the retrieval base and build a search index with the faiss library (Johnson et al., 2019). The search index is a set of representations (of 256 dimensions) for all the code snippets in the retrieval codebase. Let $( x _ { i } , y _ { i } )$ denote one training instance where $x _ { i }$ is the input text description and $y _ { i }$ is the corresponding target code snippet. we employ the same encoder to obtain the embedding of $x _ { i }$ and retrieve top- $k$ similar code samples from the search base using the L-2 similarity metric, with $k$ being a hyperparameter. We ensure that the training example’s target string $( y _ { i } )$ is not present in any of these $k$ retrieved samples.
489
+
490
+ After retrieving these top- $k$ relevant code samples, we combine them with a special token [SEP] and concatenate it to the end of the source input $x _ { i }$ Unlike (Parvez et al., 2021), we do not augment docstrings or text descriptions and only augment the code snippet for simplicity. We then finetune CodeT $^ { 5 + }$ on this augmented dataset. During inference, we retrieve similar code samples from the search base and augment these to input $x _ { i }$ . For training, we set the maximum sequence length of the source and target as 600 and 320. We use a learning rate of 2e-5, the batch size as 32 to finetune the model for 10 epochs. We set the beam size as 5 during inference with beam search.
md/dev/zeGpMIt6Pfq/zeGpMIt6Pfq.md ADDED
@@ -0,0 +1,285 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # BIOLCNET: REWARD-MODULATED LOCALLY CONNECTED SPIKING NEURAL NETWORKS
2
+
3
+ Anonymous authors Paper under double-blind review
4
+
5
+ # ABSTRACT
6
+
7
+ Recent studies have shown that convolutional neural networks (CNNs) are not the only feasible solution for image classification. Furthermore, weight sharing and backpropagation used in CNNs do not correspond to the mechanisms present in the biological visual system. To propose a more biologically plausible solution, we designed a locally connected spiking neural network (SNN) trained using spike-timing-dependent plasticity (STDP) and its reward-modulated variant (R-STDP) learning rules. The use of spiking neurons and local connections along with reinforcement learning (RL) led us to the nomenclature BioLCNet for our proposed architecture. Our network consists of a rate-coded input layer followed by a locally connected hidden layer and a decoding output layer. A spike population-based voting scheme is adopted for decoding in the output layer. We used the MNIST dataset to obtain image classification accuracy and to assess the robustness of our rewarding system to varying target responses.
8
+
9
+ # 1 INTRODUCTION
10
+
11
+ For many years, deep convolutional neural network (DCNN) has dominated the field of computer vision and object recognition Goodfellow et al. (2016); LeCun et al. (2015). Although novel methods, such as visual transformers Carion et al. (2020) and very recent MLP-based models Tatsunami & Taki (2021) are threatening its reign, CNN is still the most popular architecture employed for solving visual tasks. However, CNNs lack biological plausibility. First of all, neuron activations in an artificial neural network (ANN) are static real-numbered values, that are modeled by differentiable, non-linear activation functions. This is in contrast to biological neurons that use discrete, and mostly sparse spike trains to transmit information between each other, and in addition to the rate of spikes (spatial encoding), they also use spike timing to encode information temporally Tavanaei et al. (2019). Therefore, a spiking neural network (SNN) is more akin to the neural networks in the brain. Spiking neural networks also require fewer labeled data and operations, which makes them compatible with energy-efficient neuromorphic hardware.
12
+
13
+ Secondly, the brain is incapable of error backpropagation, as done in traditional ANNs. One issue with error backpropagation in ANNs is the weight transport problem, i.e., the fact that weight connectivity in feedforward and feedback directions is symmetric Liao et al. (2016); Bartunov et al. (2018). Additionally, error feedback propagation that does not affect neural activity is not compliant with the feedback mechanisms that biological neurons use for communication Lillicrap et al. (2020).
14
+
15
+ Furthermore, although convolutional neural networks has shown great potential in solving any translation-invariant task, its use of weight sharing is biologically problematic. There is no empirical support for explicit weight sharing in the brain Pogodin et al. (2021). However, local connections between neurons is biologically plausible, since neurons in the biological visual system exploit them to have local visual receptive fields Gregor & LeCun (2010). To be compatible with this fact, we also used a locally-connected scheme without explicit weight sharing to design our network. Despite the biological nature of local connections, they mostly underperform convolution-based methods with weight sharing in the visual domain, especially on large-scale datasets Bartunov et al. (2018). This weaker performance may be mainly attributed to the smaller number of parameters and better generalization in CNNs. Fewer parameters in CNNs would also require less memory and computational cost, and would lead to faster training Poggio et al. (2017). Studies are being done to bridge
16
+
17
+ the performance gap between convolutional and locally-connected networks Lillicrap et al. (2020);
18
+ Bartunov et al. (2018).
19
+
20
+ Noting the above considerations, in this paper, we are proposing BioLCNet, a reward-modulated locally-connected spiking neural network. Our network is trained using the unsupervised spiketiming-dependent plasticity and its semi-supervised variant reward-modulated STDP. The input images are encoded proportional to the pixels intensity using Poisson rate-coding that converts intensity to average neuron firing rate in Hertz. In the output layer, there are neuronal groups for each class label, and decision making is based on aggregated number of spikes during the decision period. Our novel dynamic reward prediction error $( R P E )$ mechanism exploits strongly supported empirical findings to improve classification performance. We test the classification capabilities of our network with different sets of hyperparameters on the MNIST dataset LeCun et al. (1999). We also conduct a classical conditioning experiment to prove the effectiveness of our decoding scheme and rewarding mechanisms.
21
+
22
+ # 2 RELATED WORK
23
+
24
+ Neuroscientists and deep learning researchers have long been searching for more biologically plausible deep learning approaches in terms of neuronal characteristics, learning rules, and connection types. Regarding neuronal characteristics, researchers have turned to biological neuronal models and spiking neural networks. The vanishing performance gap between deep neural netwroks (DNNs) and SNNs, and the compatibility of SNNs with neuromorphic hardware and online on-chip training Schemmel et al. (2010) has piqued the interest of researchers Mozafari et al. (2019). For comprehensive reviews on deep learning in spiking neural networks, see Tavanaei et al. (2019); Pfeiffer & Pfeil (2018).
25
+
26
+ Spiking neurons are activated by discrete input spike trains. This differs from artificial neurons used in an ANN that have differentiable activation functions and can easily employ backpropagation and gradient-based optimization. There are works that use gradient-based methods with SNNs Kheradpisheh & Masquelier (2020); Wu et al. (2018); Neftci et al. (2019); Bellec et al. (2020) and some of them have achieved great performances. On the other hand, many works in this area use derivations of the Hebbian learning rule where changes in connection weights depend on the activities of the pre and post-synaptic neurons Hebb (1949). Spike-timing-dependent plasticity (STDP) and its variants, apply asymmetric weight updates based on the temporal activities of neurons. Normal STDP requires an external read-out for classification Mozafari et al. (2018), and have been applied to image reconstruction and classification tasks by many researchers. Some have employed fully-connected architectures Beyeler et al. (2013); Tavanaei & Maida (2015); Allred & Roy (2016), while others used convolutional layers for feature extraction Masquelier & Thorpe (2007); Panda & Roy (2016); Kheradpisheh et al. (2016; 2018). Reward-modulated STDP (R-STDP) uses a reward (or punishment) signal to directly modulate the STDP weight change, and can be used to decode the output without an external cue. Izhikevich (2007) solved the distal reward problem in reinforcement learning by using a version of R-STDP with decaying eligibility traces that gives recent spiking activity more importance. Around the same time, Florian (2007) showed that R-STDP can be employed to solve a simple XOR task with both rate and temporal encoding of the output. Also, Caporale & Dan (2008) used R-STDP to generate specific spiking patterns in the output of their spiking network. Historically, R-STDP was first adopted with temporal (rank-order) encoding for image classification Mozafari et al. (2018). They employed a convolutional architecture based on Masquelier & Thorpe (2007) and a time-to-first-spike decoding scheme. An extended architecture was later developed which had multiple hidden layers Mozafari et al. (2019). The use of R-STDP with Poisson ratecoding has been mostly limited to fully-connected architectures for solving reinforcement learning robot navigation tasks Shim & Li (2017); Bing et al. (2019). To our knowledge, image recognition problems have not yet been addressed by combining R-STDP and rate-based encoding.
27
+
28
+ The most prevalent architectures used for image classification in deep learning with both DNNs and SNNs are based on convolutional layers and weight sharing. However, there are arguments against the biological plausibility of these approaches Bartunov et al. (2018); Pogodin et al. (2021). Locally connected (LC) networks are an alternative to the convolutional ones. Illing et al. (2019) show that shallow networks with localized connectivity and receptive fields perform much better than fully-connected networks on the MNIST benchmark. However, Bartunov et al. (2018) showed that the lower generalization of LC networks compared to CNNs results in their underperforming CNNs in most image classification tasks, and prevents their scalability to larger datasets such as ImageNet Deng et al. (2009). Very recently, Pogodin et al. (2021) proposed bio-inspired dynamic weight sharing and adding lateral connections to locally-connected layers to achieve the same regularization goals of weight sharing and normal convolutional filters. The first work to integrate a locally-connected (LC) layer into an SNN Saunders et al. (2019) used a network with no hidden layers where the rate-coded input is passed to the output layer via local connections. They exploited recurrent inhibitory connections similar to the ones employed by Diehl & Cook (2015) to simulate a winner-take-all (WTA) inhibition mechanism in their output. Their learning rule is STDP, and therefore an external readout, in this case n-gram voting, is required for classification. Their network scheme was inspiring in designing our locally connected hidden layer.
29
+
30
+ # 3 THEORY
31
+
32
+ In this section, we will outline the theoretical foundations underlying our proposed method. Specifically, the dynamics of the spiking neuronal model, the learning rules used, and the connection type employed in our network will be described.
33
+
34
+ # 3.1 ADAPTIVE LIF NEURON MODEL
35
+
36
+ The famous leaky and integrate fire neuronal model is governed by the following differential equation Gerstner et al. (2014),
37
+
38
+ $$
39
+ \tau _ { m } \frac { d u } { d t } = - [ u ( t ) - u _ { r e s t } ] + R I ( t ) ,
40
+ $$
41
+
42
+ where $u ( t )$ denotes the neuron membrane potential and is a function of time, $R$ is the membrane resistance, $I ( t )$ is any arbitrary input current, and $\tau _ { m }$ is the membrane time constant. Equation (1) dictates that the neuron potential exponentially decays to a constant value $u _ { r e s t }$ over time. When a pre-synaptic neuron fires (spikes), it generates a current that reaches its post-synaptic neurons. In the simple leaky integrate and fire (LIF) model, a neuron fires when its potential surpasses a constant threshold $u _ { t h r }$ . After firing, the neuron’s potential resets to a constant $u _ { r e s e t }$ and will not be affected by any input current for a period of time known as the refractory period $( \Delta t _ { r e f } )$ .
43
+
44
+ A variant of the LIF model uses adaptive firing thresholds. In this model, $u _ { t h r }$ can change over time based on the neuron’s rate of activity Diehl & Cook (2015). When a neuron fires, its tolerance to the input stimuli and consequently its firing threshold increases by a constant amount, $g _ { 0 }$ , otherwise the threshold decays exponentially with a time constant $\tau _ { g }$ to the default threshold $u _ { t h r _ { 0 } }$ . Equations (2) to (4) explain the dynamics of the adaptive LIF model,
45
+
46
+ $$
47
+ u _ { t h r } ( t ) = u _ { t h r _ { 0 } } + g ( t ) ,
48
+ $$
49
+
50
+ where,
51
+
52
+ $$
53
+ \tau _ { g } d _ { g } / d _ { t } = - g ( t ) ,
54
+ $$
55
+
56
+ and
57
+
58
+ $$
59
+ s p i k e \Rightarrow g ( t ) = g ( t - 1 ) + g _ { 0 } ,
60
+ $$
61
+
62
+ # 3.2 REWARD-MODULATED STDP
63
+
64
+ Spike-timing-dependent plasticity is a type of biological Hebbian learning rule that is also aligned with human intuition (”Neurons that fire together wire together.” (Lowel & Singer, 1992)). The normal STDP is characterized by two asymmetric update rules. The synaptic weights are updated based on the temporal activities of pre and post-synaptic neurons. When a pre-synaptic neuron fires shortly before its post-synaptic neuron, the causal connection between the first and the second neuron temporal activity is acknowledged, and the connection weight is increased. On the other hand, if the post-synaptic neuron fires shortly after the pre-synaptic neuron, the causality is undermined and the synaptic strength will decrease Hebb (1949). These weight updates, called long-term potentiation (LTP) and long-term depression (LTD), can be performed with asymmetric learning rates to adapt the learning rule to the excitatory to inhibitory neuron ratio or the connection patterns of a specific neural network. A popular variant of STDP that integrates reinforcement learning into the learning mechanism of spiking neural networks is reward-modulated STDP (also known as RSTDP or MSTDP Florian (2007)). In R-STDP, a global reward or punishment signal, which can be a function of time, is generated as the result of the network’s activity or task performance. Using a notation similar to Florian (2007), to mathematically formulate both STDP and R-STDP, we can define the spike train of a pre-synaptic neuron as the sum of Dirac functions over the spikes of the post-synaptic neurons,
65
+
66
+ $$
67
+ \Phi ( t ) = \sum _ { \mathcal { F } _ { i } } \delta ( t - t _ { i } ^ { f } ) .
68
+ $$
69
+
70
+ where $t _ { i } ^ { f }$ is the firing time of the $i ^ { t h }$ post-syanptic neuron. Now, we can define the variables $P _ { i j } ^ { + }$ and $P _ { i j } ^ { - }$ to respectively track the influence of pre or post-synaptic spikes on weight updates. Now, the spike trace $\xi$ for a given spike from neuron $i$ to $j$ can be defined as below,
71
+
72
+ $$
73
+ \xi _ { i j } = P _ { i j } ^ { + } \Phi _ { i } ( t ) + P _ { i j } ^ { - } \Phi _ { j } ( t ) ,
74
+ $$
75
+
76
+ where: (assuming the same ,
77
+
78
+ $$
79
+ d P _ { j } ^ { + } / d t = - P _ { j } ^ { + } / \tau _ { + } + \eta _ { p o s t } \Phi _ { j } ( t ) ,
80
+ $$
81
+
82
+ $$
83
+ d P _ { i } ^ { - } / d t = - P _ { i } ^ { - } / \tau _ { - } - \eta _ { p r e } \Phi _ { i } ( t ) ,
84
+ $$
85
+
86
+ where we assumed that $P _ { i j } = P _ { j }$ for all pre-synaptic connections related to neuron $j$ , and $P _ { i j } = P _ { i }$ for all post-synaptic connections related to neuron $i$ .
87
+
88
+ The variables $\tau _ { \pm }$ are the time constants determining the time window in which a spike can affect the weight updates. Using larger time constants will cause spikes that are further apart to also trigger weight updates. The variables $\eta _ { p o s t }$ and $\eta _ { p r e }$ determine the learning rate for LTP and LTD updates respectively. We denote the reward or punishment signal with $r ( t )$ . The R-STDP update rules for positive and negative rewards can be written as,
89
+
90
+ $$
91
+ \frac { d w _ { i j } ( t ) } { d t } = \gamma r ( t ) \xi _ { i j } ( t ) ,
92
+ $$
93
+
94
+ where $\gamma$ is a scaling factor. The update rule for normal STDP can also be written as,
95
+
96
+ $$
97
+ \frac { d w _ { i j } ( t ) } { d t } = \gamma \xi _ { i j } ( t ) .
98
+ $$
99
+
100
+ Based on Equation (9), we note that R-STDP updates only take effect when a non-zero modulation signal is received at time step $t$ . However, STDP updates do not depend on the modulation signal, and are applied at every time step. In other words, STDP can be considered a special case of RSTDP where the reward function is equal to 1 in every time step. This causes STDP to respond to the most frequent patterns regardless of their desirability.
101
+
102
+ ![](images/7d16d30ca22f5af673ef7c16b44c6d342f983954e53442bb9a7b0d15131bd48b.jpg)
103
+ Figure 1: Visual comparison of convolutional and local connections for a given filter; in convolutional connections, the weights are shared between all receptive fields. However, in a local connections, each receptive field has its own set of weights.
104
+
105
+ # 3.3 LOCAL CONNECTIONS
106
+
107
+ A local connection in a neural network is similar to a convolutional connection but with distinct filters for each receptive field. As seen in Fig. 1, in normal convolutional connections, there is one filter for each channel that is convolved with all receptive fields as it moves along the layer’s input. This filter has one set of weights that are updated using the network’s update rule. However, In local connection (LC), after taking each stride, a new set of parameters characterize a whole new filter for the next receptive field. This type of connectivity between the input and the LC layer resembles the physical structure of retinal Ganglion cells. Because there are more filters in an LC, the number of distinct synapses in a local connection is greater than a convolutional connection, yet much lower than a dense connection. Similar to a convolutional connection, assuming square filters, and equal horizontal and vertical strides, we can specify a local connection by the number of channels (filters) $( c h _ { l c } )$ , the kernel size $( k )$ , and the stride (s).
108
+
109
+ # 4 ARCHITECTURE AND METHODS
110
+
111
+ BioLCNet consists of an input layer, a locally connected hidden layer, and a decoding layer. Each layer structure and its properties alongside the training and rewarding procedure will be delineated in this section. A graphical representation of our network is presented in Fig. 2. The simulation time $T$ is divided into three phases, adaptation period $( T _ { a d a p t } )$ , decision period $( T _ { d e c } )$ , and learning period $( T _ { l e a r n } )$ . The details of each phase will be specified in the remainder of this section.
112
+
113
+ ![](images/5fdf75263ec24542831806da2a28750016c3f859a907223b028482ab6ed6b1c4.jpg)
114
+ Figure 2: Graphical representation of the proposed network; locally connected filters will be applied to the rate-coded input image. Based on a winner-take-all inhibition mechanism, the most relevant features from each receptive field transmit their spikes to the decoding layer, which selects the most active neuronal group as the predicted label exploiting lateral inhibitory connections. The red lines indicate inhibitory connections.
115
+
116
+ # 4.1 ENCODING LAYER
117
+
118
+ The input of the network is an image of dimensions $( c h _ { i n } , h _ { i n } , w _ { i n } )$ . For a grayscale image dataset such as MNIST, $c h _ { i n }$ equals to one. Each input channel is rate-coded using a Poisson encoding scheme, i.e, the spiking neuron corresponding to each pixel has an average firing rate proportional to the intensity of that pixel. By choosing the maximum firing rate $f _ { m a x }$ , the spike trains average firing rates will be distributed in the interval $[ 0 , f _ { m a x } ]$ Hertz based on the pixel values.
119
+
120
+ # 4.2 FEATURE EXTRACTION LAYER (LOCAL CONNECTIONS)
121
+
122
+ The encoded input at each simulation time step passes through local connections with $c h _ { o u t }$ distinct filters for each receptive field. Therefore, the output of this layer will have dimensions $( c h _ { o u t }$ , $h _ { o u t }$ , $w _ { o u t , }$ ), where the output size depends on the size of the kernel and the stride. There are generally two approaches in the SNN literature for training a feature extraction layer with rate-coded inputs using STDP to attain a rich feature representation and also prevent the weights from growing too large. One is allowing the weights to have negative values, which corresponds to having inhibitory neurons, as done in the convolutional layers used by Lee et al. (2018). The other is to use a combination of recurrent inhibitory connections and adaptive thresholds as done by Diehl & Cook (2015); Saunders et al. (2018; 2019). In this work, we used the latter approach for our feature extraction LC layer. We use adaptive LIF neurons and inhibitory connections between neurons that share the same receptive field. This is equivalent to the winner-take-all inhibition mechanism which causes a competition between neurons to select the most relevant features. The inhibitory connections are non-plastic and they all have a static negative weight $w _ { i n h }$ with a large absolute value.
123
+
124
+ In normal STDP, the LTP learning rate $( \eta _ { p o s t } )$ is usually chosen larger than the LTD rate $( \eta _ { p r e } )$ to suppress the random firing of neurons that triggers many LTD updates during the early stages of training. However, this may become problematic in the later stages, and the weights may grow too large. Therefore, in practice, different mechanisms, such as weight clipping and normalization are used to prevent the weights running amok. In this work, we clipped the weights to stay in the range $[ 0 , 1 ]$ . We also employed the normalization technique used by Saunders et al. (2019) and normalized the pre-synaptic weights of each neuron in the LC layer to have a constant mean of $c _ { n o r m }$ at the end of each time step.
125
+
126
+ # 4.3 DECODING LAYER AND REWARDING MECHANISMS
127
+
128
+ The final layer of our network is a fully connected layer for reward-based decoding. The layer is divided into $n _ { c }$ neuronal groups where $n _ { c }$ is the number of classes related to the task. Consequently, the $n _ { o u t }$ neurons in this layer are divided equally into $n _ { c }$ neuronal groups. The predicted label for a given test sample is the class whose group has the most number of spikes aggregated over the decision period $( T _ { d e c } )$ . This decoding layer is trained using reinforcement learning and R-STDP during the learning period $( T _ { l e a r n } )$ based on the modulation signal generated by the rewarding mechanism. We designed two different rewarding mechanisms, static and dynamic reward prediction error (RPE). In the static mechanism, we use a fixed reward or punishment signal for the whole learning period $( T _ { l e a r n } )$ based on the prediction of the network for the $i ^ { t h }$ training sample,
129
+
130
+ $$
131
+ r _ { i } = \left\{ \begin{array} { c } { { 1 : \ p r e d i c t e d l a b e l = t a r g e t l a b e l } } \\ { { - 1 : \qquad o t h e r w i s e } } \end{array} \right.
132
+ $$
133
+
134
+ The second mechanism, dynamic $R P E$ is based on the reward prediction error theory in reinforcement learning. According to this theory, the dopaminergic neurons in the brain release dopamine proportional to the difference between the actual reward and the expected reward (not solely based on the actual reward) Schultz et al. (1997); Sutton & Barto (2018). We formulate our dynamic RPE mechanism as below,
135
+
136
+ $$
137
+ R _ { i } = R _ { i - 1 } - \eta _ { r p e } ( r _ { i } - \mathrm { E M A } _ { R } )
138
+ $$
139
+
140
+ where $R _ { i }$ is the scalar R-STDP modulation signal used during the whole learning period $( T _ { l e a r n } )$ of the $i ^ { t h }$ training sample, $r _ { i }$ is the reward signal received based on the prediction, and ${ \mathrm { E M A } _ { R } }$ is the exponential moving average of the modulation signals with a smoothing factor $\alpha$ .
141
+
142
+ # 4.4 TRAINING PROCEDURE
143
+
144
+ The network is trained in a layer-wise fashion. After initializing the weights uniformly between $[ 0 , 1 ]$ , we train the feature extraction LC layer in a completely unsupervised manner using STDP. Simulation time for training the feature extraction layer is $T _ { l e a r n }$ time steps. After this layer is trained, the weights are freezed, and we train the decoding FC layer in a semi-supervised manner using R-STDP and the selected rewarding mechanism. Training this layer requires all three simulation phases. The input image is first presented to the network for $T _ { a d a p t }$ time steps to let the LC layer neurons adapt to the input image and select its relevant features. During $T _ { d e c }$ time steps, the decoding layer accumulates the number of spikes received by each neuronal group to determine the predicted label. Afterwards, the modulation signal is generated and the decoding layer weights are updated using R-STDP for $T _ { l e a r n }$ time steps.
145
+
146
+ When training the LC layer, we observed that after a specific number of iterations (training samples), the weights of this layer converge and remain constant. Fig. 3a visualizes the filters learned after 2000 iterations for 100 filters of size 15 with a stride of 4 applied to the input images. This fast convergence is an evidence showing the strength of STDP learning. Considering these observations, and to save computation time, we limit the number of training sample of the LC layer to 2000 for all of the hyperparameter configurations. Given an input image (Fig. 3b), we can plot the activation map of the LC layer (Fig. 3c). This map shows the post-synaptic neurons corresponding to the relevant features activate, and suppress the other neurons in accordance with the WTA inhibition mechanism.
147
+
148
+ The network is implemented using PyTorch Paszke et al. (2019), and mostly on top of the BindsNet framework Hazan et al. (2018) to make our code more efficient. We reimplemented the local connection topology to make it compatible with multi-channel inputs and a possible deep extension of our network.
149
+
150
+ ![](images/0decd3b3924b810633377d52c352a922683153280606c399e810843c871f63b8.jpg)
151
+ Figure 3: Input and LC layer visualizations. (a) LC layer learned filters; the red lines separate filters corresponding to each receptive field. (b) A sample input image. (c) The LC layer activation map corresponding to the sample input image shown.
152
+
153
+ Table 1: BioLCNet (hyper-)parameters; best-performing value for (hyper-)parameters subject to grid search are in bold.
154
+
155
+ <table><tr><td rowspan=1 colspan=1>Parameter</td><td rowspan=1 colspan=1>Value</td></tr><tr><td rowspan=1 colspan=1>Uthro</td><td rowspan=1 colspan=1>-52 (mV)</td></tr><tr><td rowspan=1 colspan=1>Urest,Ureset</td><td rowspan=1 colspan=1>-65 (mV)</td></tr><tr><td rowspan=1 colspan=1>go</td><td rowspan=1 colspan=1>0.05 (mV)</td></tr><tr><td rowspan=1 colspan=1>Tg</td><td rowspan=1 colspan=1>10 (ms)</td></tr><tr><td rowspan=1 colspan=1>△tref</td><td rowspan=1 colspan=1>5(ms)</td></tr><tr><td rowspan=1 colspan=1>Tm</td><td rowspan=1 colspan=1>20(ms)</td></tr><tr><td rowspan=1 colspan=1>fmax</td><td rowspan=1 colspan=1>128(Hz)</td></tr><tr><td rowspan=1 colspan=1>hin,Win</td><td rowspan=1 colspan=1>22</td></tr><tr><td rowspan=1 colspan=1>nout</td><td rowspan=1 colspan=1>[100,500,1000]</td></tr><tr><td rowspan=1 colspan=1>chlc</td><td rowspan=1 colspan=1>[25,50,100,250]</td></tr><tr><td rowspan=1 colspan=1>k</td><td rowspan=1 colspan=1>[11,13, 15,17]</td></tr><tr><td rowspan=1 colspan=1>S</td><td rowspan=1 colspan=1>[2, 3,4]</td></tr><tr><td rowspan=1 colspan=1>Tadapt,Tdec,Tlearn</td><td rowspan=1 colspan=1>256 (ms)</td></tr><tr><td rowspan=1 colspan=1>(Npre,Npost)STDP</td><td rowspan=1 colspan=1>(0.0001,0.01)</td></tr><tr><td rowspan=1 colspan=1>(npre,post)R-STDP</td><td rowspan=1 colspan=1>(0.1,0.1)</td></tr><tr><td rowspan=1 colspan=1>2</td><td rowspan=1 colspan=1>1</td></tr><tr><td rowspan=1 colspan=1>nrpe</td><td rowspan=1 colspan=1>[(static),0.075,0.125,0.175,0.25]</td></tr><tr><td rowspan=1 colspan=1>a</td><td rowspan=1 colspan=1>0.9</td></tr><tr><td rowspan=1 colspan=1>Winh</td><td rowspan=1 colspan=1>-100</td></tr><tr><td rowspan=1 colspan=1>Cnorm</td><td rowspan=1 colspan=1>0.25</td></tr></table>
156
+
157
+ # 5 EXPERIMENTS AND DISCUSSION
158
+
159
+ # 5.1 IMAGE CLASSIFICATION
160
+
161
+ To evaluate our network’s classification performance, we trained our model on the MNIST benchmark. Some of the hyperparameters were fixed and others were subject to grid search. The full list of hyperparameters are given in Table 1.
162
+
163
+ Considering the hyperparameters mentioned in Table 1, we report in Table 2, the classification accuracy on the whole MNIST test set (10000 samples) for four hyperparameter configurations chosen based on the highest test accuracy obtained after conducting a grid search. The number of neurons and synapses for each model are also reported in this table. The final models were all trained using 10000 training samples from the MNIST training set. Using more training samples did not improve the classification performance as can be observed from Fig. 4. The mean and standard deviations reported are estimated from ten independent runs. In addition to the RL-based models, another classification approach was employed. In this approach, for each training sample, we create a feature vector containing the number of spikes aggregated over $T _ { l e a r n }$ time steps for every filter in the LC layer. We use these feature vectors to train a support vector machine (SVM) classifier. The SVM results are also obtained by training on 10000 training samples, and testing on the whole MNIST test set. The SVM test results for two different hyperparameter configurations are reported in Table 2 and are compared to the RL-based results. The best performance of SVM and RL-based classification are 87.50, and 76.40 respectively. Table3 compares the MNIST test performance obtained by different SNN approaches along with the bio-plausibility criteria to which they adhere.
164
+
165
+ Table 2: MNIST test dataset accuracies obtained by four different sets of hyper-parameters; the test accuracies are averaged over ten independent runs
166
+
167
+ <table><tr><td rowspan=1 colspan=1>Parameters[k,s,nrpe,nout]</td><td rowspan=1 colspan=1>nneurons</td><td rowspan=1 colspan=1>nsynapses</td><td rowspan=1 colspan=1>Test accuracy</td><td rowspan=1 colspan=1>SVM test accuracy</td></tr><tr><td rowspan=1 colspan=1>[13,3,0.025,100]</td><td rowspan=1 colspan=1>1700</td><td rowspan=1 colspan=1>430400</td><td rowspan=1 colspan=1>61.30 ±3.14</td><td rowspan=1 colspan=1>87.5±1.32</td></tr><tr><td rowspan=1 colspan=1>[15,4,0.175,1000]</td><td rowspan=1 colspan=1>1884</td><td rowspan=1 colspan=1>490000</td><td rowspan=1 colspan=1>75.00 ±2.68</td><td rowspan=1 colspan=1>83.3±1.74</td></tr><tr><td rowspan=1 colspan=1>[15,4,0.125,1000]</td><td rowspan=1 colspan=1>1884</td><td rowspan=1 colspan=1>490000</td><td rowspan=1 colspan=1>76.40 ±2.43</td><td rowspan=1 colspan=1>83.3±1.74</td></tr><tr><td rowspan=1 colspan=1>[15,4,(static),100]</td><td rowspan=1 colspan=1>984</td><td rowspan=1 colspan=1>130000</td><td rowspan=1 colspan=1>68.8±2.87</td><td rowspan=1 colspan=1>83.3±1.74</td></tr></table>
168
+
169
+ Table 3: MNIST test dataset accuracies obtained by different SNN approaches
170
+
171
+ <table><tr><td rowspan=1 colspan=1>Paper</td><td rowspan=1 colspan=1>Encoding</td><td rowspan=1 colspan=1>Architecture</td><td rowspan=1 colspan=1>Bio-plausibility criteria</td><td rowspan=1 colspan=1>Acc.</td></tr><tr><td rowspan=1 colspan=1>BioLCNet (proposed, RL)</td><td rowspan=1 colspan=1>rate-based</td><td rowspan=1 colspan=1>Locally connected+Dense</td><td rowspan=1 colspan=1>STDP, RL, LC</td><td rowspan=1 colspan=1>76.40</td></tr><tr><td rowspan=1 colspan=1>BioLCNet (proposed,SVM)</td><td rowspan=1 colspan=1>rate-based</td><td rowspan=1 colspan=1>Locally connected</td><td rowspan=1 colspan=1>STDP, LC</td><td rowspan=1 colspan=1>87.5</td></tr><tr><td rowspan=1 colspan=1>Beyeler et al. (2013)</td><td rowspan=1 colspan=1>rate-based</td><td rowspan=1 colspan=1>Dense</td><td rowspan=1 colspan=1>STDP</td><td rowspan=1 colspan=1>91.60</td></tr><tr><td rowspan=1 colspan=1>Diehl&amp; Cook (2015)</td><td rowspan=1 colspan=1>rate-based</td><td rowspan=1 colspan=1>Dense</td><td rowspan=1 colspan=1>STDP</td><td rowspan=1 colspan=1>95.00</td></tr><tr><td rowspan=1 colspan=1>Tavanaei &amp;Maida (2015)</td><td rowspan=1 colspan=1>rate-based</td><td rowspan=1 colspan=1>Dense</td><td rowspan=1 colspan=1>STDP</td><td rowspan=1 colspan=1>75.93</td></tr><tr><td rowspan=1 colspan=1>Allred &amp; Roy (2016)</td><td rowspan=1 colspan=1>rate-based</td><td rowspan=1 colspan=1>Dense</td><td rowspan=1 colspan=1>STDP</td><td rowspan=1 colspan=1>86.59</td></tr><tr><td rowspan=1 colspan=1>Kheradpisheh et al. (2018)</td><td rowspan=1 colspan=1>rank-order</td><td rowspan=1 colspan=1>Convolutional</td><td rowspan=1 colspan=1>STDP</td><td rowspan=1 colspan=1>98.40</td></tr><tr><td rowspan=1 colspan=1>Saunders et al. (2018)</td><td rowspan=1 colspan=1>rate-based</td><td rowspan=1 colspan=1>Convolutional</td><td rowspan=1 colspan=1>STDP</td><td rowspan=1 colspan=1>84.23</td></tr><tr><td rowspan=1 colspan=1>Lee et al. (2018)</td><td rowspan=1 colspan=1>rate-based</td><td rowspan=1 colspan=1>Convolutional</td><td rowspan=1 colspan=1>STDP</td><td rowspan=1 colspan=1>91.1</td></tr><tr><td rowspan=1 colspan=1>Mozafari et al. (2019)</td><td rowspan=1 colspan=1>rank-order</td><td rowspan=1 colspan=1>Convolutional</td><td rowspan=1 colspan=1>STDP, RL</td><td rowspan=1 colspan=1>97.2</td></tr><tr><td rowspan=1 colspan=1>Saunders et al. (2019)</td><td rowspan=1 colspan=1>rate-based</td><td rowspan=1 colspan=1>Locally connected</td><td rowspan=1 colspan=1>STDP, LC</td><td rowspan=1 colspan=1>95.07</td></tr></table>
172
+
173
+ ![](images/482e4a9d69fa8e69ad9b163d17afcb7732c0bce5812040cd207c4efe158cd3d5.jpg)
174
+ Figure 4: Smoothed running accuracy over the training set for four sets of hyperparameters using the R-STDP classifier
175
+
176
+ Overall, the supervised SVM has achieved a better performance than the R-STDP method. Two important observations can be made from Table 2. First, the classification accuracy has a positive correlation with the filter size, and the number of neurons in the decoding layer. Secondly, the dynamic RPE mechanism improved the classification performance compared to the default static rewarding mechanism. dynamic RPE plays a similar role to the adaptive learning rate method employed by Mozafari et al. (2018), yet with more biological roots and empirical support.
177
+
178
+ # 5.2 CLASSICAL CONDITIONING
179
+
180
+ In order to show the effectiveness of our rewarding mechanism, we perform a classical (Pavlovian) conditioning experiment. This type of conditioning pairs up a neutral stimulus with an automatic conditioned response by the agent. In this experiment, we present the network with images belonging to one class of the MNIST dataset as the neutral stimuli. We used the pre-trained feature extraction layer of the network with 25 filters of size 13 and stride of 3, following by a decoding layer with 20 neurons for a two-class prediction task. In the first half of the experiment (task 1), the target response is class 1, and the network receives a constant reward of 1 if it predicts this class regardless of the input. A punishment signal of -1 is received if the agent predicts class 0. We monitor the rate of the reward and punishment received during the experiment. After the convergence in about 50 iterations, Fig. 5 shows that the agent has become completely conditioned on the rewarding response. After 200 iterations, we swap the rewarding and punishing classes, and continue running the network. In task 2, the network should predict the input images as class 0. The RL agent (the network) adapts to the change notably fast, and completely changes its behavior after about 100 iterations. The heat maps in Fig. 5 visualize the weights of the output layer through the training.
181
+
182
+ ![](images/8f859c87f1c13d06b557b110e4326581592fd1b4ea20647586d4c42985854d66.jpg)
183
+ Figure 5: Classical conditioning experiment; in this experiment, we tested the adaptability of the network to varying target responses. The plot shows the rate of receiving reward and punishment averaged over 20 runs, and the decoding layer weight maps at iterations 0, 200, 300, 400, and 600. The right side of the weight maps correspond to the task 1 target response neurons, and the left side corresponds to the task 2 target response neurons. The weights adapt to the varying target response during the experiment.
184
+
185
+ The reward adaptability of an RL agent is critical because in many real-world problems the environment is non-stationary. Integration of reward adaptation into spiking neural networks, as done in this work, can pave the path for models that simulate human behaviour with the same spike-based computation as done in the human brain.
186
+
187
+ # 6 CONCLUSIONS AND FUTURE WORK
188
+
189
+ In this work, we examined the capabilities of a neural network with three-fold biological plausibility; spiking neurons, local visual receptive fields, and a reward-modulated learning rule. The R-STDP learning rule has been only used for sequential decision making or temporal-coded visual tasks. As the first work to employ R-STDP in locally connected SNNs, we did not expect to achieve state-of-the-art performance. However, we hope that using the novel dynamic RPE rewarding mechanism alongside the emerging local connection scheme will make the future prospects of biological learning rules and architectures in solving real-world problems, more promising.
190
+
191
+ In the future, by bringing ideas such as dynamic weight sharing and lateral connections Pogodin et al. (2021) to spiking neural networks, we may be able to obtain richer feature representations using locally connected SNNs. We can also exploit the recent advances in SNN minibatch processing Saunders et al. (2020) and neuromorphic hardware Schemmel et al. (2010) to extend our network with deeper architectures and solve more complex tasks.
192
+
193
+ # REFERENCES
194
+
195
+ Jason M Allred and Kaushik Roy. Unsupervised incremental stdp learning using forced firing of dormant or idle neurons. In 2016 International Joint Conference on Neural Networks (IJCNN), pp. 2492–2499. IEEE, 2016.
196
+
197
+ Sergey Bartunov, Adam Santoro, Blake Richards, Luke Marris, Geoffrey E Hinton, and Timothy Lillicrap. Assessing the scalability of biologically-motivated deep learning algorithms and architectures. In S. Bengio, H. Wallach, H. Larochelle, K. Grauman, N. Cesa-Bianchi, and R. Garnett (eds.), Advances in Neural Information Processing Systems, volume 31. Curran Associates, Inc., 2018. URL https://proceedings.neurips.cc/paper/2018/file/ 63c3ddcc7b23daa1e42dc41f9a44a873-Paper.pdf.
198
+
199
+ Guillaume Bellec, Franz Scherr, Anand Subramoney, Elias Hajek, Darjan Salaj, Robert Legenstein, and Wolfgang Maass. A solution to the learning dilemma for recurrent networks of spiking neurons. Nature communications, 11(1):1–15, 2020.
200
+
201
+ Michael Beyeler, Nikil D Dutt, and Jeffrey L Krichmar. Categorization and decision-making in a neurobiologically plausible spiking network using a stdp-like learning rule. Neural Networks, 48: 109–124, 2013.
202
+
203
+ Zhenshan Bing, Zhuangyi Jiang, Long Cheng, Caixia Cai, Kai Huang, and Alois Knoll. End to end learning of a multi-layered snn based on r-stdp for a target tracking snake-like robot. In 2019 International Conference on Robotics and Automation (ICRA), pp. 9645–9651. IEEE, 2019.
204
+
205
+ Natalia Caporale and Yang Dan. Spike timing–dependent plasticity: a hebbian learning rule. Annu. Rev. Neurosci., 31:25–46, 2008.
206
+
207
+ Nicolas Carion, Francisco Massa, Gabriel Synnaeve, Nicolas Usunier, Alexander Kirillov, and Sergey Zagoruyko. End-to-end object detection with transformers. In European Conference on Computer Vision, pp. 213–229. Springer, 2020.
208
+
209
+ Jia Deng, Wei Dong, Richard Socher, Li-Jia Li, Kai Li, and Li Fei-Fei. Imagenet: A large-scale hierarchical image database. In 2009 IEEE Conference on Computer Vision and Pattern Recognition, pp. 248–255, 2009. doi: 10.1109/CVPR.2009.5206848.
210
+
211
+ Peter U Diehl and Matthew Cook. Unsupervised learning of digit recognition using spike-timingdependent plasticity. Frontiers in computational neuroscience, 9:99, 2015.
212
+
213
+ Razvan V Florian. Reinforcement learning through modulation of spike-timing-dependent synaptic ˘ plasticity. Neural computation, 19(6):1468–1502, 2007.
214
+
215
+ Wulfram Gerstner, Werner M Kistler, Richard Naud, and Liam Paninski. Neuronal dynamics: From single neurons to networks and models of cognition. Cambridge University Press, 2014.
216
+
217
+ Ian Goodfellow, Yoshua Bengio, and Aaron Courville. Deep Learning. MIT Press, 2016. http: //www.deeplearningbook.org.
218
+
219
+ Karo Gregor and Yann LeCun. Emergence of complex-like cells in a temporal product network with local receptive fields, 2010.
220
+
221
+ Hananel Hazan, Daniel J Saunders, Hassaan Khan, Devdhar Patel, Darpan T Sanghavi, Hava T Siegelmann, and Robert Kozma. Bindsnet: A machine learning-oriented spiking neural networks library in python. Frontiers in neuroinformatics, 12:89, 2018.
222
+
223
+ Donald Olding Hebb. The organisation of behaviour: a neuropsychological theory. Science Editions New York, 1949.
224
+
225
+ Bernd Illing, Wulfram Gerstner, and Johanni Brea. Biologically plausible deep learning—but how far can we go with shallow networks? Neural Networks, 118:90–101, 2019.
226
+
227
+ Eugene M Izhikevich. Solving the distal reward problem through linkage of stdp and dopamine signaling. Cerebral cortex, 17(10):2443–2452, 2007.
228
+
229
+ Saeed Reza Kheradpisheh and Timothee Masquelier. Temporal backpropagation for spiking neural ´ networks with one spike per neuron. International Journal of Neural Systems, 30(06):2050027, 2020.
230
+
231
+ Saeed Reza Kheradpisheh, Mohammad Ganjtabesh, and Timothee Masquelier. Bio-inspired unsu- ´ pervised learning of visual features leads to robust invariant object recognition. Neurocomputing, 205:382–392, 2016.
232
+
233
+ Saeed Reza Kheradpisheh, Mohammad Ganjtabesh, Simon J Thorpe, and Timothee Masquelier. ´ Stdp-based spiking deep convolutional neural networks for object recognition. Neural Networks, 99:56–67, 2018.
234
+
235
+ Y LeCun, C Cortes, and C Burges. The mnist dataset of handwritten digits (images). NYU: New York, NY, USA, 1999.
236
+
237
+ Yann LeCun, Yoshua Bengio, and Geoffrey Hinton. Deep learning. nature, 521(7553):436–444, 2015.
238
+
239
+ Chankyu Lee, Gopalakrishnan Srinivasan, Priyadarshini Panda, and Kaushik Roy. Deep spiking convolutional neural network trained with unsupervised spike-timing-dependent plasticity. IEEE Transactions on Cognitive and Developmental Systems, 11(3):384–394, 2018.
240
+
241
+ Qianli Liao, Joel Leibo, and Tomaso Poggio. How important is weight symmetry in backpropagation? In Proceedings of the AAAI Conference on Artificial Intelligence, volume 30, 2016.
242
+
243
+ Timothy P Lillicrap, Adam Santoro, Luke Marris, Colin J Akerman, and Geoffrey Hinton. Backpropagation and the brain. Nature Reviews Neuroscience, 21(6):335–346, 2020.
244
+
245
+ Siegrid Lowel and Wolf Singer. Selection of intrinsic horizontal connections in the visual cortex by correlated neuronal activity. Science, 255(5041):209–212, 1992.
246
+
247
+ Timothee Masquelier and Simon J Thorpe. Unsupervised learning of visual features through spike´ timing dependent plasticity. PLoS computational biology, 3(2):e31, 2007.
248
+
249
+ Milad Mozafari, Saeed Reza Kheradpisheh, Timothee Masquelier, Abbas Nowzari-Dalini, and Mo- ´ hammad Ganjtabesh. First-spike-based visual categorization using reward-modulated stdp. IEEE transactions on neural networks and learning systems, 29(12):6178–6190, 2018.
250
+
251
+ Milad Mozafari, Mohammad Ganjtabesh, Abbas Nowzari-Dalini, Simon J Thorpe, and Timothee´ Masquelier. Bio-inspired digit recognition using reward-modulated spike-timing-dependent plasticity in deep convolutional networks. Pattern recognition, 94:87–95, 2019.
252
+
253
+ Emre O Neftci, Hesham Mostafa, and Friedemann Zenke. Surrogate gradient learning in spiking neural networks: Bringing the power of gradient-based optimization to spiking neural networks. IEEE Signal Processing Magazine, 36(6):51–63, 2019.
254
+
255
+ Priyadarshini Panda and Kaushik Roy. Unsupervised regenerative learning of hierarchical features in spiking deep networks for object recognition. In 2016 International Joint Conference on Neural Networks (IJCNN), pp. 299–306. IEEE, 2016.
256
+
257
+ Adam Paszke, Sam Gross, Francisco Massa, Adam Lerer, James Bradbury, Gregory Chanan, Trevor Killeen, Zeming Lin, Natalia Gimelshein, Luca Antiga, Alban Desmaison, Andreas Kopf, Edward Yang, Zachary DeVito, Martin Raison, Alykhan Tejani, Sasank Chilamkurthy, Benoit Steiner, Lu Fang, Junjie Bai, and Soumith Chintala. Pytorch: An imperative style, high-performance deep learning library. In H. Wallach, H. Larochelle, A. Beygelzimer, F. d'Alche-Buc, ´ E. Fox, and R. Garnett (eds.), Advances in Neural Information Processing Systems 32, pp. 8024–8035. Curran Associates, Inc., 2019. URL http://papers.neurips.cc/paper/ 9015-pytorch-an-imperative-style-high-performance-deep-learning-library. pdf.
258
+
259
+ Michael Pfeiffer and Thomas Pfeil. Deep learning with spiking neurons: opportunities and challenges. Frontiers in neuroscience, 12:774, 2018.
260
+
261
+ Tomaso Poggio, Hrushikesh Mhaskar, Lorenzo Rosasco, Brando Miranda, and Qianli Liao. Why and when can deep-but not shallow-networks avoid the curse of dimensionality: a review. International Journal of Automation and Computing, 14(5):503–519, 2017.
262
+
263
+ Roman Pogodin, Yash Mehta, Timothy P. Lillicrap, and Peter E. Latham. Towards biologically plausible convolutional networks, 2021.
264
+
265
+ Daniel J Saunders, Hava T Siegelmann, Robert Kozma, et al. Stdp learning of image patches with convolutional spiking neural networks. In 2018 international joint conference on neural networks (IJCNN), pp. 1–7. IEEE, 2018.
266
+
267
+ Daniel J Saunders, Devdhar Patel, Hananel Hazan, Hava T Siegelmann, and Robert Kozma. Locally connected spiking neural networks for unsupervised feature learning. Neural Networks, 119: 332–340, 2019.
268
+
269
+ Daniel J Saunders, Cooper Sigrist, Kenneth Chaney, Robert Kozma, and Hava T Siegelmann. Minibatch processing for speed-up and scalability of spiking neural network simulation. In 2020 International Joint Conference on Neural Networks (IJCNN), pp. 1–8. IEEE, 2020.
270
+
271
+ Johannes Schemmel, Daniel Bruderle, Andreas Gr ¨ ubl, Matthias Hock, Karlheinz Meier, and Se- ¨ bastian Millner. A wafer-scale neuromorphic hardware system for large-scale neural modeling. In 2010 IEEE International Symposium on Circuits and Systems (ISCAS), pp. 1947–1950. IEEE, 2010.
272
+
273
+ Wolfram Schultz, Peter Dayan, and P Read Montague. A neural substrate of prediction and reward. Science, 275(5306):1593–1599, 1997.
274
+
275
+ Myung Seok Shim and Peng Li. Biologically inspired reinforcement learning for mobile robot collision avoidance. In 2017 International Joint Conference on Neural Networks (IJCNN), pp. 3098–3105. IEEE, 2017.
276
+
277
+ Richard S Sutton and Andrew G Barto. Reinforcement learning: An introduction. MIT press, 2018.
278
+
279
+ Yuki Tatsunami and Masato Taki. Raftmlp: Do mlp-based models dream of winning over computer vision? arXiv preprint arXiv:2108.04384, 2021.
280
+
281
+ Amirhossein Tavanaei and Anthony S Maida. A minimal spiking neural network to rapidly train and classify handwritten digits in binary and 10-digit tasks. International journal of advanced research in artificial intelligence, 4(7):1–8, 2015.
282
+
283
+ Amirhossein Tavanaei, Masoud Ghodrati, Saeed Reza Kheradpisheh, Timothee Masquelier, and ´ Anthony Maida. Deep learning in spiking neural networks. Neural Networks, 111:47–63, 2019.
284
+
285
+ Yujie Wu, Lei Deng, Guoqi Li, Jun Zhu, and Luping Shi. Spatio-temporal backpropagation for training high-performance spiking neural networks. Frontiers in neuroscience, 12:331, 2018.
parse/train/Syx7A3NFvH/Syx7A3NFvH_content_list.json ADDED
The diff for this file is too large to render. See raw diff
 
parse/train/Syx7A3NFvH/Syx7A3NFvH_model.json ADDED
The diff for this file is too large to render. See raw diff
 
parse/train/vujTf_I8Kmc/vujTf_I8Kmc.md ADDED
@@ -0,0 +1,410 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ATTENTIONAL CONSTELLATION NETS FOR FEW-SHOT LEARNING
2
+
3
+ Weijian $\mathbf { X } \mathbf { u } ^ { * 1 }$ , Yifan $\mathbf { X } \mathbf { u } ^ { * 1 }$ , Huaijin Wang∗1 & Zhuowen $\mathbf { T } \mathbf { u } ^ { 1 , 2 }$ University of California San Diego1, Amazon Web Services2 $\{ \mathtt { w e x } 0 4 1$ , $\mathtt { y i x 0 8 1 }$ ,huw011,ztu}@ucsd.edu
4
+
5
+ # ABSTRACT
6
+
7
+ The success of deep convolutional neural networks builds on top of the learning of effective convolution operations, capturing a hierarchy of structured features via filtering, activation, and pooling. However, the explicit structured features, e.g. object parts, are not expressive in the existing CNN frameworks. In this paper, we tackle the few-shot learning problem and make an effort to enhance structured features by expanding CNNs with a constellation model, which performs cell feature clustering and encoding with a dense part representation; the relationships among the cell features are further modeled by an attention mechanism. With the additional constellation branch to increase the awareness of object parts, our method is able to attain the advantages of the CNNs while making the overall internal representations more robust in the few-shot learning setting. Our approach attains a significant improvement over the existing methods in few-shot learning on the CIFAR-FS, FC100, and mini-ImageNet benchmarks.
8
+
9
+ # 1 INTRODUCTION
10
+
11
+ Tremendous progress has been made in both the development and the applications of the deep convolutional neural networks (CNNs) (Krizhevsky et al., 2012; Simonyan & Zisserman, 2015; Szegedy et al., 2015; He et al., 2016; Xie et al., 2017). Visualization of the internal CNN structure trained on e.g. ImageNet (Deng et al., 2009) has revealed the increasing level of semantic relevance for the learned convolution kernels/filters to the semantics of the object classes, displaying bar/edge like patterns in the early layers, object parts in the middle layers, and face/object like patterns in the higher layers (Zeiler & Fergus, 2014). In general, we consider the learned convolution kernels being somewhat implicit about the underlying objects since they represent projections/mappings for the input but without the explicit knowledge about the parts in terms of their numbers, distributions, and spatial configurations.
12
+
13
+ On the other hand, there has been a rich history about explicit object representations starting from deformable templates (Yuille et al., 1992), pictorial structure (Felzenszwalb & Huttenlocher, 2005), constellation models (Weber et al., 2000; Fergus et al., 2003; Sudderth et al., 2005; Fei-Fei et al., 2006), and grammar-based model (Zhu & Mumford, 2007). These part-based models (Weber et al., 2000; Felzenszwalb & Huttenlocher, 2005; Fergus et al., 2003; Sudderth et al., 2005; Zhu & Mumford, 2007) share three common properties in the algorithm design: (1) unsupervised learning, (2) explicit clustering to obtain the parts, and (3) modeling to characterize the spatial configuration of the parts. Compared to the CNN architectures, these methods are expressive with explicit part-based representation. They have pointed to a promising direction for object recognition, albeit a lack of strong practice performance on the modern datasets. Another line of object recognition system with the part concept but trained discriminatively includes the discriminative trained part-based model (DPM) (Felzenszwalb et al., 2009) and the spatial pyramid matching method (SPM) (Lazebnik et al., 2006). In the context of deep learning, efforts exist to bring the explicit part representation into deep hierarchical structures (Salakhutdinov et al., 2012).
14
+
15
+ The implicit and explicit feature representations could share mutual benefits, especially in fewshot learning where training data is scarce: CNNs may face difficulty in learning a generalized representation due to lack of sufficient training data, whereas clustering and dictionary learning provide a direct means for data abstraction. In general, end-to-end learning of both the implicit and explicit part-based representations is a viable and valuable means in machine learning. We view convolutional features as an implicit part-based representation since they are learned through back-propagation via filtering processes. On the other hand, an explicit representation can be attained by introducing feature clustering that captures the data abstraction/distribution under a mixture model.
16
+
17
+ In this paper, we develop an end-to-end framework to combine the implicit and explicit part-based representations for the few-shot classification task by seamlessly integrating constellation models with convolution operations. In addition to keeping a standard CNN architecture, we also employ a cell feature clustering module to encode the potential object parts. This procedure is similar to the clustering/codebook learning for appearance in the constellation model (Weber et al., 2000). The cell feature clustering process generates a dense distance map. We further model the relations for the cells using a self-attention mechanism, resembling the spatial configuration design in the constellation model (Weber et al., 2000). Thus, we name our method constellation networks (ConstellationNet). We demonstrate the effectiveness of our approach on standard few-shot benchmarks, including FC100 (Oreshkin et al., 2018), CIFAR-FS (Bertinetto et al., 2018) and mini-ImageNet (Vinyals et al., 2016) by showing a significant improvement over the existing methods. An ablation study also demonstrates the effectiveness of ConstellationNet is not achieved by simply increasing the model complexity using e.g. more convolution channels or deeper and wider convolution layers (WRN-28-10 (Zagoruyko & Komodakis, 2016)) (see ablation study in Table 3 and Figure 2 (e)).
18
+
19
+ # 2 RELATED WORK
20
+
21
+ Few-Shot Learning. Recently, few-shot learning attracts much attention in the deep learning community (Snell et al., 2017; Lee et al., 2019). Current few-shot learning is typically formulated as a meta-learning problem (Finn et al., 2017), in which an effective feature embedding is learned for generalization across novel tasks. We broadly divide the existing few-shot learning approaches into three categories: (1) Gradient-based methods optimize feature embedding with gradient descent during meta-test stage (Finn et al., 2017; Bertinetto et al., 2018; Lee et al., 2019). (2) Metric-based methods learn a fixed optimal embedding with a distance-based prediction rule (Vinyals et al., 2016; Snell et al., 2017). (3) Model-based methods obtains a conditional feature embedding via a weight predictor (Mishra et al., 2017; Munkhdalai et al., 2017). Here we adopt ProtoNet (Snell et al., 2017), a popular metric-based framework, in our approach and boost the generalization ability of the feature embeddings with explicit structured representations from the constellation model. Recently, Tokmakov et al. (2019) proposes a compositional regularization to the image with its attribute annotations, which is different from out unsupervised part-discovery strategy.
22
+
23
+ Part-Based Constellation/Discriminative Models. The constellation model family (Weber et al., 2000; Felzenszwalb & Huttenlocher, 2005; Fergus et al., 2003; Sudderth et al., 2005; Fei-Fei et al., 2006; Zhu & Mumford, 2007) is mostly generative/expressive that shares two commonalities in the representation: (1) clustering/codebook learning in the appearance and (2) modeling of the spatial configurations. The key difference among these approaches lies in how the spatial configuration is modeled: Gaussian distributions (Weber et al., 2000); pictorial structure (Felzenszwalb & Huttenlocher, 2005); joint shape model (Fergus et al., 2003) ; hierarchical graphical model (Sudderth et al., 2005); grammar-based (Zhu & Mumford, 2007). These constellation models represent a promising direction for object recognition but are not practical competitive compared with deep learning based approaches. There are also discriminative models: The discriminatively trained part-based model (DPM) (Felzenszwalb et al., 2009) is a typical method in this vein where object parts (as HOG features (Dalal & Triggs, 2005)) and their configurations (a star model) are learned jointly in a discriminative way. The spatial pyramid matching method (SPM) (Lazebnik et al., 2006) has no explicit parts but instead builds on top of different levels of grids with codebook learned on top of the SIFT features (Lowe, 2004). DPM and SPM are of practical significance for object detection and recognition. In our approach, we implement the constellation model with cell feature clustering and attention-based cell relation modeling to demonstrate the appearance learning and spatial configuration respectively.
24
+
25
+ Parts models are extensively studied in fine-grained image classifications and object detection to provide spatial guidance for filtering uninformative object proposals (Simon & Rodner, 2015; Peng et al., 2017; Zhu et al., 2017; Ge et al., 2019; Qi et al., 2019). Related to our work, Neural Activation Constellations (NAC) (Simon & Rodner, 2015) introduces the constellation model to perform unsupervised part model discovery with convolutional networks. Our work is different from NAC in three aspects: (1) The algorithmic mechanisms behind Simon & Rodner (2015) and ours are different. Simon & Rodner (2015) implements a traditional Gaussian-based constellation module to model the spatial configuration and part selection on top of a fixed pre-trained CNN. However, in our ConstellationNet, our part representation and spatial configuration are modeled by cell feature clustering and self-attention based cell relation module, which is general-purpose, modularized and recursive. (2) In Simon & Rodner (2015) , the constellation module is optimized in an EM-like algorithm, which is separate from the CNN optimization. Our constellation modules are seamlessly integrated into the current CNNs and jointly optimized with them. (3) Our ConstellationNet uses the dense cell features from the CNN feature maps, which considers all positions from the images as potential parts and models their relation. However, (Simon et al. 2015) extracts sparse part representations (i.e. it uses at most one part proposal per channel and selects even less parts later), which may not fully utilize the rich information from the CNN feature maps.
26
+
27
+ ![](images/a924203810e5217bac39bf9e1cd97c1d7ee3fa56e4415cd254706db12deae116.jpg)
28
+ Figure 1: Illustration of our ConstellationNet pipeline where the bottom part is the network architecture based on Conv-4 backbone, and the top part shows the constellation model. Our proposed ConstellationNet consists of “Constell.” modules that perform explicit cell feature clustering with self-attention for joint relation modeling.
29
+
30
+ # 3 FEW-SHOT LEARNING
31
+
32
+ In a standard classification problem, we aim to learn a model trained on the dataset $\mathcal { D } ^ { \mathrm { b a s e } }$ that can generalize its classification ability to unseen test set $\mathcal { D } ^ { \mathrm { n o v e l } }$ belonging to same categories. In few-shot classification problem, we encourage $\mathcal { D } ^ { \mathrm { b a s e } }$ and $\mathcal { D } ^ { \mathrm { n o v e l } }$ to be formed from different categories to emphasize model’s generalization ability on novel categories, where we denote training categories as $\mathcal { C } _ { \mathrm { b a s e } }$ , test categories as $\mathcal { C } _ { \mathrm { n o v e l } }$ , and $\mathcal { C } _ { \mathrm { b a s e } } \cap \mathcal { C } _ { \mathrm { n o v e l } } = \emptyset$ to ensure the fairness.
33
+
34
+ In the training stage (a.k.a. meta-train stage), metric-based few-shot learning approaches (Snell et al., 2017; Vinyals et al., 2016; Oreshkin et al., 2018) usually learn a feature extractor $\phi ( \mathbf { x } )$ on the dataset $\mathcal { D } ^ { \mathrm { b a s e } }$ to obtain generic feature embedding by optimizing the loss ${ \mathcal { L } } ( \phi )$ :
35
+
36
+ $$
37
+ \mathcal { L } ( \phi ) = \mathbb { E } _ { \{ ( \mathbf { x } , y ) \} \sim \mathcal { D } _ { \mathrm { b a s e } } } \ell \big ( \{ ( \phi ( \mathbf { x } ) , y ) \} \big )
38
+ $$
39
+
40
+ where $\{ ( { \bf x } , y ) \}$ is a sampled mini-batch of data points and $\ell ( \cdot )$ is usually an episodic few-shot loss (Vinyals et al., 2016) or a standard cross-entropy loss (Chen et al., 2020).
41
+
42
+ In the inference stage (a.k.a. meta-test stage), a typical few-shot benchmark evaluates the model on $K$ -way, $N$ -shot classification tasks $\tau$ drawn from $\mathcal { D } ^ { \mathrm { n o v e l } }$ , where each task has a support set and a query set, i.e. $\mathcal { T } = ( \mathcal { T } ^ { \mathrm { s u p p } } , \mathcal { T } ^ { \mathrm { q u e r y } } )$ . The support set ${ \mathcal { T } } ^ { \mathrm { s u p p } }$ contains $K$ classes and each class has $N$ images (e.g. $K = 5$ , $N \in \{ 1 , 5 \} ,$ ). Following Snell et al. (2017), the prediction $\hat { y } ^ { \prime }$ of a query image $\mathbf { x } ^ { \prime } \in \mathcal { T } ^ { \mathrm { q u e r y } }$ is given by the label of nearest prototype $\mathbf { c } _ { k }$ from ${ \mathcal { T } } ^ { \mathrm { s u p p } }$ under a cosine similarity $d ( \cdot , \cdot )$ :
43
+
44
+ $$
45
+ \hat { y } ^ { \prime } = \arg \operatorname* { m a x } _ { k } d \big ( \phi ( \mathbf { x } ^ { \prime } ) , \mathbf { c } _ { k } \big ) , \qquad \mathbf { c } _ { k } = \frac { 1 } { N } \sum _ { ( \mathbf { x } , y ) \in \mathcal { T } ^ { \mathrm { s u p p } } , \ y = k } \phi ( \mathbf { x } ) .
46
+ $$
47
+
48
+ An extended description of the few-shot learning framework can be found from Appendix A.1. The generalization ability of the feature extractor $\phi ( \mathbf { x } )$ is improved in terms of training scheme (e.g.
49
+
50
+ episodic learning (Vinyals et al., 2016)), network design (e.g. task condition (Oreshkin et al., 2018)) or objective function (e.g. learnable distance (Sung et al., 2018)). In our method, we propose a novel network design by inserting constellation models into CNNs and strengthen the intermediate features.
51
+
52
+ # 4 CONSTELLATION MODEL
53
+
54
+ The concept of constellation has been introduced to the few-shot learning scenario in early years (Fei-Fei et al., 2006), in which the appearance and the shape are independently learned in a mixture model. In our work, we revisit the constellation model in an end-to-end learning framework: First, we define the a cell feature as the individual local feature at a position in the feature map (see Figure 1). We then employ cell feature clustering to model the underlying distribution of input cell features, implying a part discovery procedure. We further obtain the distance map of the cell features from clustering and then perform cell relation modeling to build spatial relationships.
55
+
56
+ # 4.1 CELL FEATURE CLUSTERING
57
+
58
+ In convolutional neural networks (CNNs), the convolutional filters are learned to detect the discriminative patterns from low-level to high-level through back-propagation (Zeiler & Fergus, 2014). In fact, the backward signal in the back-propagation is not necessarily needed to obtain a pattern detector. With the feature map in the forward step of the CNN, we are able to cluster the individual features at each location of the feature map (a.k.a. cell features) into multiple centers and employ the cluster centers as filters (Coates & $\mathrm { N g }$ , 2012; Krähenbühl et al., 2015). Assume we obtain a convolutional feature map U with batch size $B$ , spatial size $H \times W$ and channels $C$ . We disensemble the feature map $\mathbf { U } \in \mathbb { R } ^ { \hat { \vec { B } } \times H \times W \times C }$ into a cell features set ${ \mathcal { U } } = \{ \mathbf { u } _ { 1 } , \mathbf { u } _ { 2 } , . . . , \mathbf { u } _ { n } \}$ where $n = B H W$ and $\mathbf { u } _ { i } \in \mathbb { R } ^ { C }$ is a cell feature. Naively, we can conduct a $k$ -means algorithm on input cell features $\mathcal { U }$ to solve the clustering objective:
59
+
60
+ $$
61
+ \operatorname* { m i n } \sum _ { i } \sum _ { k } m _ { i k } | | { \bf u } _ { i } - { \bf v } _ { k } | | _ { 2 } ^ { 2 } \quad \mathrm { s . t . } \quad m _ { i k } \in \{ 0 , 1 \} , \quad \sum _ { k } m _ { i k } = 1
62
+ $$
63
+
64
+ where $\mathcal { V } = \{ \mathbf { v } _ { 1 } , \mathbf { v } _ { 2 } , . . . , \mathbf { v } _ { K } \}$ is a set of cluster centers and $m _ { i k }$ indicates if the input cell feature $\mathbf { u } _ { i }$ is assigned to cluster center $\mathbf { v } _ { k }$ . The clustering-based filters $\nu$ can model the underlying cell feature distributions and capture the most frequent features, which can be explicitly interpreted as meaningful part patterns/part types. The hard assignment map ${ \bf m } _ { i } = ( m _ { i 1 } , m _ { i 2 } , . . . , m _ { i K } )$ of input cell feature $\mathbf { u } _ { i }$ onto the cluster centers can be used as a part-based representation, providing alternative information to the next layer in the CNN.
65
+
66
+ However, there are two issues remaining unsolved in the naive design: Firstly, CNNs are typically optimized in a stochastic gradient descent (SGD) manner. Thus, in each forward step, only a minibatch of images are proceeded to provide cell features, which implies that the cluster centers cannot extract the global feature distribution across the whole dataset. Secondly, the hard assignment map has limited information due to its discrete representation. Therefore, inspired by Sculley (2010), we design a mini-batch soft $k$ -means algorithm to cluster the cell features approximately:
67
+
68
+ • Initialization. Randomly initialize global cluster centers $\mathcal { V } = \left\{ \mathbf { v } _ { 1 } , \mathbf { v } _ { 2 } , . . . , \mathbf { v } _ { K } \right\}$ and a counter $\mathbf { s } = ( s _ { 1 } , s _ { 2 } , . . . , s _ { K } ) = \mathbf { 0 }$ .
69
+
70
+ • Cluster Assignment. In forward step, given input cell features ${ \mathcal { U } } = \{ \mathbf { u } _ { 1 } , \mathbf { u } _ { 2 } , . . . , \mathbf { u } _ { n } \}$ , we compute the distance vector $\mathbf { d } _ { i } = ( d _ { i 1 } , d _ { i 2 } , . . . d _ { i K } )$ between input cell feature $\mathbf { u } _ { i }$ and all cluster centers $\nu$ We then compute the soft assignment $m _ { i k } \in \mathbb { R }$ and generate the current mini-batch centers $\mathbf { v } _ { k } ^ { \prime }$ :
71
+
72
+ $$
73
+ d _ { i k } = | | \mathbf { u } _ { i } - \mathbf { v } _ { k } | | _ { 2 } ^ { 2 } , \qquad m _ { i k } = { \frac { e ^ { - \beta d _ { i k } } } { \sum _ { j } e ^ { - \beta d _ { i j } } } } , \qquad \mathbf { v } _ { k } ^ { \prime } = { \frac { \sum _ { i } m _ { i k } \mathbf { u } _ { i } } { \sum _ { i } m _ { i k } } }
74
+ $$
75
+
76
+ where $\beta > 0$ is an inverse temperature.
77
+
78
+ • Centroid Movement. We formulate a count update $\begin{array} { r } { \Delta \mathbf { s } = \sum _ { i } \mathbf { m } _ { i } } \end{array}$ by summing all assignment maps $\mathbf { m } _ { i } = ( m _ { i 1 } , m _ { i 2 } , . . . m _ { i K } )$ . The current mini-batch centers $\mathbf { v } _ { k } ^ { \prime }$ are then updated to the global centers $\mathbf { v } _ { k }$ with a momentum coefficient $\eta$ :
79
+
80
+ $$
81
+ \mathbf { v } _ { k } ( 1 - \eta ) \mathbf { v } _ { k } + \eta \mathbf { v } _ { k } ^ { \prime } , \qquad \eta = \frac { \lambda } { s _ { k } + \Delta s _ { k } }
82
+ $$
83
+
84
+ • Counter Update. Counter s is updated and distance vectors $\left\{ \mathbf { d } _ { i } \right\}$ are reshaped and returned:
85
+
86
+ $$
87
+ \mathbf { s } \gets \mathbf { s } + \Delta \mathbf { s }
88
+ $$
89
+
90
+ With gradually updating global cluster centers, the above algorithm is able to address the issue of limited data in a mini-batch. In addition, we reshape the distance vectors $\left\{ \mathbf { d } _ { i } \right\}$ of all input cell features to a distance map $\mathbf { D } \in \mathbb { R } ^ { B \times H \times W \times K }$ . Each distance vector $\mathbf { d } _ { i }$ can be seen as a learned cell code in codebook (dictionary) learning, which encodes a soft assignment of the visual word (i.e. cell feature) onto the codewords (i.e. cluster centers) and implies a part representation. The distance map $\mathbf { D }$ then can be viewed as a cell code map that represents a spatial distribution of identified parts, which is passed to following layers. Empirically, it is observed that when $\mathbf { u } _ { i }$ and $\mathbf { v } _ { k }$ are $L _ { 2 }$ normalized, the training procedure is more stable and the Euclidean distance $d _ { i k }$ is equivalent to a cosine similarity up to an affine transformation. Details of the cell feature clustering can be found in Appendix A.9.
91
+
92
+ # 4.2 CELL RELATION AND SPATIAL CONFIGURATION MODELING
93
+
94
+ Before the deep learning era, traditional constellation models (Fei-Fei et al., 2006) decompose visual information into appearance and shape representation. The appearance of different parts in the image is treated independently while the shape of parts is assumed to have spatial connections. In our constellation model, we establish the spatial relationship among the individual part-based representations at a different location from the distance map as well. Specifically, we apply the self-attention mechanism (Vaswani et al., 2017) to build the spatial relationship and enhance the representation instead of using probabilistic graphical models in prior work (Fei-Fei et al., 2006).
95
+
96
+ In cell relation modeling, we add a positional encoding $\mathbf { P } \in \mathbb { R } ^ { B \times H \times W \times C }$ following Carion et al. (2020) for spatial locations to the distance map $\mathbf { D }$ and obtain the input feature map $\mathbf { F } _ { \mathrm { I } }$ for query and key layers. For value layer, we directly flatten the distance map $\mathbf { D }$ to another input feature map $\mathbf { F } _ { \mathrm { I } } ^ { \prime }$ :
97
+
98
+ $$
99
+ \mathbf { F } _ { \mathrm { I } } = { \mathrm { S p a t i a l F l a t t e n } } ( \mathbf { D } + \mathbf { P } ) \in \mathbb { R } ^ { B \times H W \times K } , \quad \mathbf { F } _ { \mathrm { I } } ^ { \prime } = { \mathrm { S p a t i a l F l a t t e n } } ( \mathbf { D } ) \in \mathbb { R } ^ { B \times H W \times K }
100
+ $$
101
+
102
+ The input feature maps $\mathbf { F } _ { \mathrm { I } } , \mathbf { F } _ { \mathrm { I } } ^ { \prime }$ are transformed into query, key and value $\{ \mathbf { F } ^ { q } , \mathbf { F } ^ { k } , \mathbf { F } ^ { v } \} \subset \mathbb { R } ^ { B \times H W \times K }$ by three linear layers $\{ \mathbf { W } ^ { q } , \mathbf { \bar { W } } ^ { k } , \mathbf { W } ^ { v } \} \subset \mathbb { R } ^ { K \times K }$ and further computes the output feature $\mathbf { F _ { A } }$ :
103
+
104
+ $$
105
+ [ \mathbf { F } ^ { q } , \mathbf { F } ^ { k } , \mathbf { F } ^ { v } ] = [ \mathbf { F } _ { \mathrm { I } } \mathbf { W } ^ { q } , \mathbf { F } _ { \mathrm { I } } \mathbf { W } ^ { k } , \mathbf { F } _ { \mathrm { I } } ^ { \prime } \mathbf { W } ^ { v } ]
106
+ $$
107
+
108
+ $$
109
+ \mathbf { F } _ { \mathrm { A } } = \mathrm { A t t } ( \mathbf { F } ^ { q } , \mathbf { F } ^ { k } , \mathbf { F } ^ { v } ) = \mathrm { s o f t m a x } \Big ( \frac { \mathbf { F } ^ { q } ( \mathbf { F } ^ { k } ) ^ { \top } } { \sqrt { K } } \Big ) \mathbf { F } ^ { v }
110
+ $$
111
+
112
+ The softmax of dot product between query and key matrix $\mathbf { F } ^ { q } ( \mathbf { F } ^ { k } ) ^ { \top } \in \mathbb { R } ^ { B \times H W \times H W }$ calculates the similarity scores in the embedding space among features across the spatial dimension. This encodes the spatial relationships of input features and leads to an enhanced output feature representation $\mathbf { F _ { A } }$ . Besides, $\sqrt { K }$ in the denominator is to stabilize the gradient. In practice, we adopt a multi-head attention to model the feature relation in the embedding subspaces:
113
+
114
+ $$
115
+ \mathbf { F } _ { \mathrm { M H A } } = \mathrm { M u l t i H e a d A t t } ( \mathbf { F } ^ { q } , \mathbf { F } ^ { k } , \mathbf { F } ^ { v } ) = [ \mathbf { F } _ { 1 } , . . . , \mathbf { F } _ { J } ] \mathbf { W } , \qquad \mathbf { F } _ { j } = \mathrm { A t t } ( \mathbf { F } _ { j } ^ { q } , \mathbf { F } _ { j } ^ { k } , \mathbf { F } _ { j } ^ { v } )
116
+ $$
117
+
118
+ In a $J$ -head attention, the aforementioned similarity scores in the $\begin{array} { r } { K ^ { \prime } = \frac { K } { J } } \end{array}$ dimensional embedding subspace are calculated using the query, key and value from $j$ -th head, i.e. $\{ \mathbf { F } _ { j } ^ { q } , \mathbf { F } _ { j } ^ { k } , \mathbf { F } _ { j } ^ { v } \} \subset$ $\mathbb { R } ^ { B \times H W \times K ^ { \prime } }$ . The output features $\mathbf { F } _ { j }$ of each head are computed following Eq. 9. All the output features $\{ \mathbf { F } _ { 1 } , . . . , \mathbf { F } _ { J } \}$ are concatenated back into $K$ dimension embedding and further processed with a linear layer $\dot { \mathbf { W } } \in \mathbb { R } ^ { K \times K }$ to generate multi-head output features $\mathbf { F _ { M H A } }$ . Such multi-head attention settings could provide more diverse feature relation without introducing extra parameters.
119
+
120
+ # 4.3 INTEGRATE CONSTELLATION MODEL WITH CNNS
121
+
122
+ Our constellation model has the capability to capture explicit structured features and encodes spatial relations among the cell features. The output features yield informative visual cues which are able to strengthen the convolutional features. Thus, as shown in Figure 1, we place the constellation model after the convolution operation to extract its unique explicit features and concatenate them with the original convolutional feature map. A following $1 \times 1$ convolutional layer is used on the concatenated features to restore the channels of convolutional feature map. In Table 3, we provide evidence that merging features from constellation model to the CNN backbone can significantly improve the representation ability. In contrast, increasing channels in CNNs alone to double the parameters (second row in Table 3) can only improve the performance marginally. Optionally, we found it is useful to adopt auxiliary loss when training the constellation model in deeper networks (e.g. ResNet-12). On top of each constellation model, we conduct a standard classification to acquire additional regularization.
123
+
124
+ # 4.4 WHY CLUSTERING AND SELF-ATTENTION (CLUSTERING MAP $^ +$ POSITIONAL ENCODING)?
125
+
126
+ As described in Section 1 and 2, classical constellation models (Fergus et al., 2003; Felzenszwalb & Huttenlocher, 2005) extract parts with their spatial relationships; they are expressive but do not produce competitive results on modern image benchmarks. CNN models (Krizhevsky et al., 2012; He et al., 2016) attain remarkable results on large-scale image benchmarks (Deng et al., 2009) but they are limited when training data is scarce. We take the inspiration from the traditional constellation models, but with a realization that overcomes their previous modeling limitations.
127
+
128
+ The main contribution of our work is a constellation module/block that performs cell-wise clustering, followed by self-attention on the clustering distance map $^ +$ positional encoding. This separates our work from previous attempts, e.g. non-local block work (Wang et al., 2018) in which long-range non-linear averaging is performed on the convolution features (no clustering, nor positional encoding for the spatial configuration). The main properties of our constellation block include: (1) Cell based dense representation as opposed to the sparse part representation in (Weber et al., 2000) to make the cells recursively modeled in the self-attention unit in a modularized and general-purpose way. (2) Clustering to generate the cell code after clustering (codebook learning) that attains abstraction and is not dependent on the CNN feature dimensions. (3) Positional encoding (as in Carion et al. (2020)) for cells to encode the spatial locations. (4) Tokenized representation as expressive parts (code/clustering distance map $^ +$ positional encoding) for the cells. (5) Self-attention to jointly model the cell code and positional encoding to capture the relationships between the parts together with their spatial configurations.
129
+
130
+ # 5 EXPERIMENT
131
+
132
+ # 5.1 DATASETS
133
+
134
+ We adopt three standard benchmark datasets that are widely used in few-shot learning, CIFAR-FS dataset (Bertinetto et al., 2018), FC100 dataset (Oreshkin et al., 2018), and mini-ImageNet dataset (Vinyals et al., 2016). Details about dataset settings in few-shot learning are in Appendix A.2.
135
+
136
+ # 5.2 NETWORK WITH MULTI-BRANCH
137
+
138
+ We build ConstellationNet on two ProtoNet variants, namely Conv-4 and ResNet-12, which are commonly used in few-shot learning. Details of networks and the optimization are in Appendix.
139
+
140
+ We develop a new technique, Multi-Branch, to optimize standard classification loss and prototypical loss simultaneously. We find the two training schemes, standard classification scheme and prototypical scheme, can be a companion rather than a conflict. Details of these two schemes can be found from Appendix A.1. Different from standard network backbone used in prior works, our embedding $\phi ( \mathbf { x } )$ is separated into two branches after a shared stem (Y-shape). Details of our multi-branch design are elaborated in A.10. The detailed ablation study is described in Table 3.
141
+
142
+ Feature Augmentation. During the meta-testing stage, we discover that concatenating features before average pooling to the final output can improve classification accuracy. The advantage of this technique is that no additional training and model parameters are introduced.
143
+
144
+ # 5.3 RESULTS ON STANDARD BENCHMARKS
145
+
146
+ Table 1 and 2 summarize the results of the few-shot classification tasks on CIFAR-FS, FC100, and mini-ImageNet, respectively. Our method shows a notable improvement over several strong baselines in various settings. ConstellationNet significantly improves the performance on shallow networks (Conv-4). In Table 2, our model outperforms SIB (Hu et al., 2020) 1-shot by $0 . 6 \%$ and 5-shot by $5 . 6 \%$ . In Table 1, our model outperforms MetaOptNet (Lee et al., 2019) by $5 . 9 5 \%$ in 1-shot and $6 . 2 4 \%$ in 5-shot. For deep networks with rich features, the constellation module still contributes to the performance, showing its complementary advantage to convolution. Our ResNet-12 model beats (Lee et al., 2019) 1-shot result by $2 . 7 \%$ on FC100, $3 . 4 \%$ on CIFAR-FS, and $1 . 7 2 \%$ on mini-ImageNet. The consistent improvement over both shallow and deep networks across all three datasets shows the generality of our method. Our ConstellationNet is orthogonal to the margin loss based methods (Liu et al., 2020; Li et al., 2020), and we also do not use extra cross-modal information (Xing et al., 2019; Li et al., 2020). On the contrary, our model enhances the embedding generalization ability by incorporating its own part-based representation. Additionally, to verify the orthogonality of our method, we adapt the negative margin loss following Liu et al. (2020) to our Conv-4 models in
147
+
148
+ Table 1: Comparison to prior work on mini-ImageNet. Average 5-way classification accuracies $( \% )$ on mini-ImageNet meta-test split are reported with $9 5 \%$ confidence intervals. Results of prior works are adopted from Lee et al. (2019) and original papers. † used extra cross-modal information.
149
+
150
+ <table><tr><td rowspan="2">Model</td><td rowspan="2">Backbone</td><td colspan="2">mini-ImageNet5-way</td></tr><tr><td>1-shot</td><td>5-shot</td></tr><tr><td>Meta-Learning LSTM (Ravi &amp; Larochelle,2016)</td><td>Conv-4</td><td>43.44 ± 0.77</td><td>60.60 ± 0.71</td></tr><tr><td>Matching Networks (Vinyals et al., 2016)</td><td>Conv-4</td><td>43.56 ± 0.84</td><td>55.31 ± 0.73</td></tr><tr><td>Prototypical Networks (Snell et al.,2017)</td><td>Conv-4</td><td>49.42 ± 0.78</td><td>68.20 ±0.66</td></tr><tr><td>Transductive Prop Nets (Liu et al.,2018)</td><td>Conv-4</td><td>55.51 ± 0.86</td><td>69.86 ± 0.65</td></tr><tr><td>MetaOptNet (Lee et al.,2019)</td><td>Conv-4</td><td>52.87 ± 0.57</td><td>68.76 ±0.48</td></tr><tr><td>Negative Margin (Liu et al.,2020)</td><td>Conv-4</td><td>52.84 ± 0.76</td><td>70.41 ± 0.66</td></tr><tr><td>ConstellationNet (ours)</td><td>Conv-4</td><td>58.82 ± 0.23</td><td>75.00 ± 0.18</td></tr><tr><td>SNAIL (Mishra et al., 2018)</td><td>ResNet-12</td><td>55.71 ± 0.99</td><td>68.88 ± 0.92</td></tr><tr><td>TADAM (Oreshkin et al., 2018)</td><td>ResNet-12</td><td>58.50 ± 0.30</td><td>76.70 ± 0.30</td></tr><tr><td>TapNet (Yoon et al.,2019)</td><td>ResNet-12</td><td>61.65 ± 0.15</td><td>76.36 ± 0.10</td></tr><tr><td>Variational FSL (Zhang et al.,2019)</td><td>ResNet-12</td><td>61.23 ± 0.26</td><td>77.69 ± 0.17</td></tr><tr><td>MetaOptNet (Lee et al.,2019)</td><td>ResNet-12</td><td>62.64 ± 0.61</td><td>78.63 ± 0.46</td></tr><tr><td>CAN (Hou et al., 2019)</td><td>ResNet-12</td><td>63.85 ± 0.48</td><td>79.44 ± 0.34</td></tr><tr><td>SLA-AG (Lee et al.,2020)</td><td>ResNet-12</td><td>62.93 ± 0.63</td><td>79.63 ± 0.47</td></tr><tr><td>Meta-Baseline (Chen et al.,2020)</td><td>ResNet-12</td><td>63.17 ± 0.23</td><td>79.26 ± 0.17</td></tr><tr><td>AM3 (Xing et al., 2019) t</td><td>ResNet-12</td><td>65.21 ± 0.30</td><td>75.20 ± 0.27</td></tr><tr><td>ProtoNets + TRAML (Li et al.,2020)</td><td>ResNet-12</td><td>60.31 ± 0.48</td><td>77.94 ± 0.57</td></tr><tr><td>AM3 + TRAML (Li et al.,2020) †</td><td>ResNet-12</td><td>67.10 ± 0.52</td><td>79.54 ± 0.60</td></tr><tr><td>Negative Margin (Liu et al.,2020)</td><td>ResNet-12</td><td>63.85 ± 0.81</td><td>81.57 ± 0.56</td></tr><tr><td>ConstellationNet (ours)</td><td>ResNet-12</td><td>64.89 ± 0.23</td><td>79.95 ± 0.17</td></tr></table>
151
+
152
+ Table 2: Comparison to prior work on FC100 and CIFAR-FS. Average 5-way classification accuracies $( \% )$ on CIFAR-FS and FC100 meta-test split are reported with $9 5 \%$ confidence intervals. Results of prior works are adopted from Lee et al. (2019) and original papers.
153
+
154
+ <table><tr><td rowspan="2">Model</td><td rowspan="2">Backbone</td><td colspan="2">CIFAR-FS 5-way</td><td colspan="2">FC100 5-way</td></tr><tr><td>1-shot</td><td>5-shot</td><td>1-shot</td><td>5-shot</td></tr><tr><td>MAML (Finn et al., 2017)</td><td>Conv-4</td><td>58.9 ± 1.9</td><td>71.5 ± 1.0</td><td></td><td></td></tr><tr><td>Prototypical Networks (Snell et al.,2017)</td><td>Conv-4</td><td>55.5 ± 0.7</td><td>72.0 ± 0.6</td><td></td><td>=</td></tr><tr><td>Relation Networks (Sung et al., 2018)</td><td>Conv-4</td><td>55.0 ±1.0</td><td>69.3 ± 0.8</td><td></td><td></td></tr><tr><td>R2D2 (Bertinetto et al., 2018)</td><td>Conv-4</td><td>65.3 ± 0.2</td><td>79.4 ± 0.1</td><td></td><td>一</td></tr><tr><td>SIB (Hu et al., 2020)</td><td>Conv-4</td><td>68.7 ± 0.6</td><td>77.1 ± 0.4</td><td></td><td></td></tr><tr><td>ConstellationNet (ours)</td><td>Conv-4</td><td>69.3± 0.3</td><td>82.7±0.2</td><td></td><td>=</td></tr><tr><td>Prototypical Networks (Snell et al., 2017)</td><td>ResNet-12</td><td>72.2 ±0.7</td><td>83.5± 0.5</td><td>37.5± 0.6</td><td>52.5 ± 0.6</td></tr><tr><td>TADAM (Oreshkin et al.,2018)</td><td>ResNet-12</td><td></td><td></td><td>40.1 ± 0.4</td><td>56.1 ± 0.4</td></tr><tr><td>MetaOptNet-RR (Lee et al.,2019)</td><td>ResNet-12</td><td>72.6 ± 0.7</td><td>84.3 ± 0.5</td><td>40.5 ± 0.6</td><td>55.3 ± 0.6</td></tr><tr><td>MetaOptNet-SVM(Lee et al.,2019)</td><td>ResNet-12</td><td>72.0± 0.7</td><td>84.2 ± 0.5</td><td>41.1 ± 0.6</td><td>55.5± 0.6</td></tr><tr><td>ConstellationNet (ours)</td><td>ResNet-12</td><td>75.4 ± 0.2</td><td>86.8± 0.2</td><td>43.8± 0.2</td><td>59.7± 0.2</td></tr></table>
155
+
156
+ Appendix A.8. We observe ConstellationNet with negative margin brings $0 . 5 2 \%$ improvement to ConstellationNet, and obtains $6 . 9 3 \%$ gain compared with baseline on mini-ImageNet.
157
+
158
+ # 6 MODEL ANALYSIS
159
+
160
+ # 6.1 ARCHITECTURE ALTERNATIVES
161
+
162
+ In Table 3, we first study the role of each module in ConstellationNet, where the number of parameters is controlled approximately equivalent to the baseline’s size. Our constellation model brings $6 . 4 1 \%$ and $2 . 5 9 \%$ improvements over baseline on 1-shot Conv-4 and ResNet-12 results. Combined with our multi-branch training procedure, the model further improves additional $1 . 3 4 \%$ and $1 . 2 6 \%$ on 1-shot Conv-4 and ResNet-12, respectively. Finally, feature augmentation from penultimate layer to final output embedding brings additional $0 . 4 5 \%$ and $0 . 2 7 \%$ improvements on two variants.
163
+
164
+ We also test the baseline model with extra channels in the Table 3. The new model only shows slight improvements over original baseline, and is outperformed by our ConstellationNet with a large margin. We also obtain WRN-28-10 baseline results to validate our improvement. While making ResNet baselines deeper and wider, our ConstellationNet still outperforms this strong baseline. In Figure 2 (e), we further study whether the performance gap between ConstellationNet and baseline can be reduced by simply altering the baseline’s model complexity using e.g. more convolution channels. Although the trend of baseline accuracy increases when increasing the model parameter number gradually, the performance gap is still significant. This validates our concept that modeling hierarchical part structures can greatly benefit features learned from convolution operation, and obtain a more robust feature representation. In addition, applying self-attention on the distance map (6-th row: $5 7 . 0 3 \%$ on Conv-4, 1-shot) achieves better performance than directly applying it to the original cell features (i.e. convolutional feature map) (4-th row: $5 5 . 9 2 \%$ on Conv-4, 1-shot). We also tried to replace the cell feature clustering module with a 1x1 convolution layer (output dimension is equal to the number of clusters) (5-th row: $5 5 . 4 6 \%$ on Conv-4, 1-shot). It is worse than our results (6-th row) as well. We observe that the 1x1 convolution layer is less expressive than the cell feature clustering module, making it difficult to extract enough context information during cell relation modeling.
165
+
166
+ Table 3: Effectiveness of modules. Average classification accuracies $( \% )$ on mini-ImageNet meta-test split. We compare our ConstellationNet with alternative architectures including the baseline and the modified baseline with extra channels based on Conv-4 and ResNet-12. We also include a baseline with WideResNet-28-10 (Zagoruyko & Komodakis, 2016) backbone for comparison.
167
+
168
+ <table><tr><td>Baseline</td><td>Cell Feature</td><td>Cell Relation</td><td>Multi</td><td>Feature</td><td>Extra</td><td>1x1</td><td>#Params</td><td colspan="2">Conv-4</td><td colspan="2">ResNet-12</td></tr><tr><td></td><td>Clustering</td><td>Modeling</td><td>Branch</td><td>Augment</td><td>Channels</td><td>Convolution</td><td>Conv-4/Res-12</td><td>1-shot</td><td>5-shot</td><td>1-shot</td><td>5-shot</td></tr><tr><td></td><td></td><td></td><td></td><td></td><td>√</td><td></td><td>117K/8.0M 222K/16M</td><td>50.62 ± 0.23 51.76 ± 0.22</td><td>68.40 ± 0.19 69.54 ± 0.18</td><td>60.77 ± 0.22 61.45 ± 0.22</td><td>78.76 ± 0.17</td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>146K/8.3M</td><td>53.34 ±0.23</td><td>70.61 ±0.19</td><td>62.24 ±0.23</td><td>79.33 ± 0.16</td></tr><tr><td></td><td>√</td><td></td><td></td><td></td><td></td><td></td><td>184K/9.7M</td><td>55.92 ± 0.23</td><td>73.02 ± 0.18</td><td>62.75 ± 0.23</td><td>79.55 ± 0.16 79.21 ± 0.17</td></tr><tr><td>&gt;&gt;&gt;&gt;&gt;</td><td></td><td></td><td></td><td></td><td></td><td></td><td>192K/8.4M</td><td>55.46 ± 0.23</td><td>72.52 ± 0.18</td><td>61.54 ± 0.24</td><td>76.51 ± 0.18</td></tr><tr><td>√</td><td>√</td><td></td><td></td><td></td><td></td><td>√</td><td>200K/8.4M</td><td>57.03 ± 0.23</td><td>74.09 ± 0.18</td><td>63.36± 0.23</td><td>79.72 ± 0.17</td></tr><tr><td>√</td><td>√</td><td>&lt;&gt;&gt;&gt;&gt;</td><td>√</td><td></td><td></td><td></td><td>200K/8.4M</td><td>58.37±0.23</td><td>74.52 ± 0.18</td><td>64.62 ± 0.23</td><td>79.60 ± 0.17</td></tr><tr><td></td><td>√</td><td></td><td>√</td><td>√</td><td></td><td></td><td>200K/8.4M</td><td>58.82 ± 0.23</td><td>75.00 ± 0.18</td><td>64.89± 0.23</td><td>79.95 ± 0.17</td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>WRN</td><td></td><td></td><td>WideResNet-28-10</td><td></td></tr><tr><td>√</td><td></td><td></td><td></td><td></td><td>√</td><td></td><td>36.5M</td><td></td><td></td><td>61.54 ± 0.25</td><td>79.41 ± 0.23</td></tr></table>
169
+
170
+ # 6.2 MODULES ANALYSIS
171
+
172
+ ![](images/caf2d329292947d8160dbd2e1676e860923dfb4f77f8e9454955ac445cb93202.jpg)
173
+ Figure 2: Modules analysis. (a, b, c, d) We study the effectiveness of changing the number of clusters, the number of heads in attention layer, and the layer indices with constellation based on Conv-4, (e) We demonstrate the performance gain of our ConstellationNet is unmatched by increasing the model complexity of our baselines. All experiments are done on mini-ImageNet.
174
+
175
+ In Figure 2 (a), we vary the number of clusters adapted in all layers to observe the performance change. We found that increasing the number of clusters improves the accuracy in general, and set clusters to 64 is optimal in terms of both model size and classification performance. Figure 2 (b) shows the number of attention heads does not effect performance as much as the number of cluster, and 8-head attention obtains $1 . 8 0 \%$ performance gain on the 1-shot setting compared to 1-head attention. In Figure 2 (c, d), we also study the effectiveness of clustering algorithm applied to different layers. The results show both early features and high-level features benefit from introducing clusters algorithm into the original CNN architecture.
176
+
177
+ # 6.3 VISUALIZATION
178
+
179
+ Figure 3 demonstrates the visualization of cluster centers in each layer of Conv-4 model on miniImageNet. In the upper part of the figure, each image shows patches corresponding to the nearest cell features to a cluster center (i.e. with lowest Euclidean distance). It is observed that clusters in early layers (e.g. layer 1,2) represent simple low-level patterns while the clusters in high layers (e.g. layer 3,4) indicate more complex structures and parts. In the lower part of the figure, we choose two cluster centers from layer 4 for further interpretation: The left one with green box could possibly represent legs since it consists of various types of legs from human, dog and other animals. The right one with the red box shows most nearest cell features to this cluster center are parts with bird’s head or beetles, which share a dotted structure (i.e. black dots on beetles / eyes on bird’s head).
180
+
181
+ The left side of Figure 4 shows the visualization of cell features that are assigned to different clusters. For each image, we extract the assignment maps corresponding to three cluster centers generated in the last constellation module of Conv-4 and find multiple cell features with the highest assignments within each assignment map. The locations of cell features are projected back in the original image space, marked by three different colors of "·" in the raw image to show three different feature clusters. For a given class of images, the same cluster centers are selected for comparison across 6 samples. As shown in Figure 4, we observe part information of each class is explicitly discovered. For the bird category, we can see different parts in each image, including head (cyan "·"), body (purple "·") and tail (yellow "·"). For the dog category, we see parts including heads (red "·"), legs (green "·") and body (blue "·"). For the tank category, we see parts like track (light blue "·") and turret (pink "·").
182
+
183
+ ![](images/ea01d6f105e2b50df5eced7b6cd771fc1f112d53a6506116ebed807e7994587e.jpg)
184
+ Figure 3: Visualization of cluster centers. (Upper) We visualize four cluster centers in each layer by showing patches associated with cell features that have the nearest distance to the clustering center. (Lower) Identifying parts from two cluster centers in layer 4: Left one with green box represents various types of legs. Right one with red box mostly shows beetles and bird’s head, sharing a dotted structure.
185
+
186
+ ![](images/15437a577d7259cbb49fe24319c24346612e37a6f226ba926e61ba3c1f728622.jpg)
187
+ Figure 4: Visualization of the cells assignment and attention maps. (Left) Each color represents a cluster, and each point, marked as "·", represents a cell assigned to a cluster center. We demonstrate 6 samples for each class (bird, dog and tank). (Right) We visualize attention maps of one query feature (at the location of red point in left part) with all key features. The middle part shows the attention maps corresponding to 8 heads in the multi-head attention. The right part shows an overlapped map of all attention maps.
188
+
189
+ The right side of Figure 4 visualizes the attention maps in the cell relation model. We use the last constellation module in the ResNet-12 model for visualization since it captures high-level features that better represent parts. We choose one query feature at the center of the object and show its attention map to all key features. The middle part of the figure shows the attention maps corresponding to 8 heads in the multi-head attention. It is observed that some parts are identified such as head (second map in first row), legs (first two map in second row), buttock (first map in first row) and body (second map in the second row). A merged attention map by overlaying all 8 attention maps is presented at right part of the figure. It indicates that all the attention heads together can extract the features of the whole object, which would be useful for final classification.
190
+
191
+ # 7 CONCLUSION
192
+
193
+ In this paper, we present ConstellationNet by introducing an explicit feature clustering procedure with relation learning via self-attention. We implement a mini-batch soft $k$ -means algorithm to capture the cell feature distribution. With integrated implicit (standard CNN modules) and explicit (cell feature clustering $^ +$ cell relation modeling) representations, our proposed ConstellationNet achieves significant improvement over the competing methods on few-shot classification benchmarks.
194
+
195
+ # ACKNOWLEDGMENTS
196
+
197
+ This work is funded by NSF IIS-1618477 and NSF IIS-1717431. We thank Qualcomm Inc. for an award support. We thank Kwonjoon Lee, Tiange Luo and Hao Su for valuable feedbacks.
198
+
199
+ # REFERENCES
200
+
201
+ Luca Bertinetto, Joao F Henriques, Philip HS Torr, and Andrea Vedaldi. Meta-learning with differentiable closed-form solvers. arXiv preprint arXiv:1805.08136, 2018.
202
+
203
+ Nicolas Carion, Francisco Massa, Gabriel Synnaeve, Nicolas Usunier, Alexander Kirillov, and Sergey Zagoruyko. End-to-end object detection with transformers. In ECCV, 2020.
204
+
205
+ Yinbo Chen, Xiaolong Wang, Zhuang Liu, Huijuan Xu, and Trevor Darrell. A new meta-baseline for few-shot learning. arXiv preprint arXiv:2003.04390, 2020.
206
+
207
+ Adam Coates and Andrew Y Ng. Learning feature representations with k-means. In Neural networks: Tricks of the trade, pp. 561–580. Springer, 2012.
208
+
209
+ Navneet Dalal and Bill Triggs. Histograms of oriented gradients for human detection. In CVPR, 2005.
210
+
211
+ 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.
212
+
213
+ Li Fei-Fei, Rob Fergus, and Pietro Perona. One-shot learning of object categories. IEEE transactions on pattern analysis and machine intelligence, 28(4):594–611, 2006.
214
+
215
+ Pedro F Felzenszwalb and Daniel P Huttenlocher. Pictorial structures for object recognition. International journal of computer vision, 61(1):55–79, 2005.
216
+
217
+ Pedro F Felzenszwalb, Ross B Girshick, David McAllester, and Deva Ramanan. Object detection with discriminatively trained part-based models. IEEE transactions on pattern analysis and machine intelligence, 32(9):1627–1645, 2009.
218
+
219
+ Robert Fergus, Pietro Perona, and Andrew Zisserman. Object class recognition by unsupervised scale-invariant learning. In CVPR, 2003.
220
+
221
+ Chelsea Finn, Pieter Abbeel, and Sergey Levine. Model-agnostic meta-learning for fast adaptation of deep networks. arXiv preprint arXiv:1703.03400, 2017.
222
+
223
+ Weifeng Ge, Xiangru Lin, and Yizhou Yu. Weakly supervised complementary parts models for fine-grained image classification from the bottom up. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pp. 3034–3043, 2019.
224
+
225
+ Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Deep residual learning for image recognition. In CVPR, 2016.
226
+
227
+ Geoffrey E Hinton, Sara Sabour, and Nicholas Frosst. Matrix capsules with em routing. 2018.
228
+
229
+ Ruibing Hou, Hong Chang, MA Bingpeng, Shiguang Shan, and Xilin Chen. Cross attention network for few-shot classification. In Advances in Neural Information Processing Systems, pp. 4005–4016, 2019.
230
+
231
+ Shell Xu Hu, Pablo G Moreno, Yang Xiao, Xi Shen, Guillaume Obozinski, Neil D Lawrence, and Andreas Damianou. Empirical bayes transductive meta-learning with synthetic gradients. arXiv preprint arXiv:2004.12696, 2020.
232
+
233
+ Adam Kosiorek, Sara Sabour, Yee Whye Teh, and Geoffrey E Hinton. Stacked capsule autoencoders. In Advances in Neural Information Processing Systems, pp. 15486–15496, 2019.
234
+
235
+ Philipp Krähenbühl, Carl Doersch, Jeff Donahue, and Trevor Darrell. Data-dependent initializations of convolutional neural networks. arXiv preprint arXiv:1511.06856, 2015.
236
+
237
+ Alex Krizhevsky, Geoffrey Hinton, et al. Learning multiple layers of features from tiny images. 2009.
238
+
239
+ Alex Krizhevsky, Ilya Sutskever, and Geoffrey E Hinton. Imagenet classification with deep convolutional neural networks. In Advances in neural information processing systems, 2012.
240
+
241
+ Svetlana Lazebnik, Cordelia Schmid, and Jean Ponce. Beyond bags of features: Spatial pyramid matching for recognizing natural scene categories. In CVPR, 2006.
242
+
243
+ Hankook Lee, Sung Ju Hwang, and Jinwoo Shin. Self-supervised label augmentation via input transformations. 37 th International Conference on Machine Learning, Vienna, Austria, PMLR 119, 2020, 2020.
244
+
245
+ Kwonjoon Lee, Subhransu Maji, Avinash Ravichandran, and Stefano Soatto. Meta-learning with differentiable convex optimization. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pp. 10657–10665, 2019.
246
+
247
+ Aoxue Li, Weiran Huang, Xu Lan, Jiashi Feng, Zhenguo Li, and Liwei Wang. Boosting few-shot learning with adaptive margin loss. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 12576–12584, 2020.
248
+
249
+ Bin Liu, Yue Cao, Yutong Lin, Qi Li, Zheng Zhang, Mingsheng Long, and Han Hu. Negative margin matters: Understanding margin in few-shot classification. arXiv preprint arXiv:2003.12060, 2020.
250
+
251
+ Yanbin Liu, Juho Lee, Minseop Park, Saehoon Kim, Eunho Yang, Sung Ju Hwang, and Yi Yang. Learning to propagate labels: Transductive propagation network for few-shot learning. arXiv preprint arXiv:1805.10002, 2018.
252
+
253
+ David G Lowe. Distinctive image features from scale-invariant keypoints. International journal of computer vision, 60(2):91–110, 2004.
254
+
255
+ Nikhil Mishra, Mostafa Rohaninejad, Xi Chen, and Pieter Abbeel. A simple neural attentive metalearner. arXiv preprint arXiv:1707.03141, 2017.
256
+
257
+ Nikhil Mishra, Mostafa Rohaninejad, Xi Chen, and Pieter Abbeel. A simple neural attentive metalearner. 2018.
258
+
259
+ Tsendsuren Munkhdalai, Xingdi Yuan, Soroush Mehri, and Adam Trischler. Rapid adaptation with conditionally shifted neurons. arXiv preprint arXiv:1712.09926, 2017.
260
+
261
+ Boris N Oreshkin, Alexandre Lacoste, and Pau Rodriguez. Tadam: Task dependent adaptive metric for improved few-shot learning. arXiv preprint arXiv:1805.10123, 2018.
262
+
263
+ Yuxin Peng, Xiangteng He, and Junjie Zhao. Object-part attention model for fine-grained image classification. IEEE Transactions on Image Processing, 27(3):1487–1500, 2017.
264
+
265
+ Lei Qi, Xiaoqiang Lu, and Xuelong Li. Exploiting spatial relation for fine-grained image classification. Pattern Recognition, 91:47–55, 2019.
266
+
267
+ Sachin Ravi and Hugo Larochelle. Optimization as a model for few-shot learning. 2016.
268
+
269
+ Sara Sabour, Nicholas Frosst, and Geoffrey E Hinton. Dynamic routing between capsules. In Advances in neural information processing systems, pp. 3856–3866, 2017.
270
+
271
+ Ruslan Salakhutdinov, Joshua B Tenenbaum, and Antonio Torralba. Learning with hierarchical-deep models. IEEE transactions on pattern analysis and machine intelligence, 35(8):1958–1971, 2012.
272
+
273
+ David Sculley. Web-scale $\mathbf { k }$ -means clustering. In Proceedings of the 19th international conference on World wide web, pp. 1177–1178, 2010.
274
+
275
+ Marcel Simon and Erik Rodner. Neural activation constellations: Unsupervised part model discovery with convolutional networks. In Proceedings of the IEEE international conference on computer vision, pp. 1143–1151, 2015.
276
+
277
+ Karen Simonyan and Andrew Zisserman. Very deep convolutional networks for large-scale image recognition. In ICLR, 2015.
278
+
279
+ Jake Snell, Kevin Swersky, and Richard Zemel. Prototypical networks for few-shot learning. In Advances in Neural Information Processing Systems, pp. 4077–4087, 2017.
280
+
281
+ Erik B Sudderth, Antonio Torralba, William T Freeman, and Alan S Willsky. Learning hierarchical models of scenes, objects, and parts. In ICCV, volume 2, 2005.
282
+
283
+ Flood Sung, Yongxin Yang, Li Zhang, Tao Xiang, Philip HS Torr, and Timothy M Hospedales. Learning to compare: Relation network for few-shot learning. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pp. 1199–1208, 2018.
284
+
285
+ Christian Szegedy, Wei Liu, Yangqing Jia, Pierre Sermanet, Scott Reed, Dragomir Anguelov, Dumitru Erhan, Vincent Vanhoucke, and Andrew Rabinovich. Going deeper with convolutions. In CVPR, 2015.
286
+
287
+ Pavel Tokmakov, Yu-Xiong Wang, and Martial Hebert. Learning compositional representations for few-shot recognition. In Proceedings of the IEEE International Conference on Computer Vision, pp. 6372–6381, 2019.
288
+
289
+ Yao-Hung Hubert Tsai, Nitish Srivastava, Hanlin Goh, and Ruslan Salakhutdinov. Capsules with inverted dot-product attention routing. arXiv preprint arXiv:2002.04764, 2020.
290
+
291
+ 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.
292
+
293
+ Oriol Vinyals, Charles Blundell, Timothy Lillicrap, Daan Wierstra, et al. Matching networks for one shot learning. In Advances in neural information processing systems, pp. 3630–3638, 2016.
294
+
295
+ Xiaolong Wang, Ross Girshick, Abhinav Gupta, and Kaiming He. Non-local neural networks. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 7794–7803, 2018.
296
+
297
+ Markus Weber, Max Welling, and Pietro Perona. Unsupervised learning of models for recognition. In ECCV, 2000.
298
+
299
+ Saining Xie, Ross Girshick, Piotr Dollár, Zhuowen Tu, and Kaiming He. Aggregated residual transformations for deep neural networks. In CVPR, 2017.
300
+
301
+ Chen Xing, Negar Rostamzadeh, Boris Oreshkin, and Pedro O O Pinheiro. Adaptive cross-modal few-shot learning. Advances in Neural Information Processing Systems, 32:4847–4857, 2019.
302
+
303
+ Sung Whan Yoon, Jun Seo, and Jaekyun Moon. Tapnet: Neural network augmented with task-adaptive projection for few-shot learning. arXiv preprint arXiv:1905.06549, 2019.
304
+
305
+ Alan L Yuille, Peter W Hallinan, and David S Cohen. Feature extraction from faces using deformable templates. International journal of computer vision, 8(2):99–111, 1992.
306
+
307
+ Sergey Zagoruyko and Nikos Komodakis. Wide residual networks. arXiv preprint arXiv:1605.07146, 2016.
308
+
309
+ Matthew D Zeiler and Rob Fergus. Visualizing and understanding convolutional networks. In ECCV, 2014.
310
+
311
+ Jian Zhang, Chenglong Zhao, Bingbing Ni, Minghao Xu, and Xiaokang Yang. Variational few-shot learning. In Proceedings of the IEEE International Conference on Computer Vision, pp. 1685–1694, 2019.
312
+
313
+ Song-Chun Zhu and David Mumford. A stochastic grammar of images. Now Publishers Inc, 2007.
314
+
315
+ Yousong Zhu, Chaoyang Zhao, Jinqiao Wang, Xu Zhao, Yi Wu, and Hanqing Lu. Couplenet: Coupling global structure with local parts for object detection. In Proceedings of the IEEE international conference on computer vision, pp. 4126–4134, 2017.
316
+
317
+ # A APPENDIX
318
+
319
+ # A.1 FEW-SHOT LEARNING FRAMEWORK
320
+
321
+ In this section, we introduce background concepts of meta-learning and elaborate the few-shot learning framework used in our ConstellationNet.
322
+
323
+ Meta-Learning in Few-Shot Classification. Current few-shot learning is typically formulated as a meta-learning task (Finn et al., 2017), in which an dataset $\mathcal { D } ^ { \mathrm { b a s e } }$ is used to provide commonsense knowledge and a dataset $\mathcal { D } ^ { \mathrm { n o v e l } }$ for the few-shot classification. $\mathcal { D } ^ { \mathrm { b a s e } }$ has the classes $\mathcal { C } _ { \mathrm { b a s e } }$ which are disjoint from the $\mathcal { C } _ { \mathrm { n o v e l } }$ in $\mathcal { D } ^ { \mathrm { n o v e l } }$ to ensure fairness. There are two stages, meta-training and meta-test, in the meta-learning framework: In meta-training stage, we attempt to train a model to learn generic features from $\mathcal { D } ^ { \mathrm { b a s e } }$ . In meta-test stage, we adapt the model on the limited training split from $\mathcal { D } ^ { \mathrm { n o v e l } }$ and evaluate the performance of the model on the test split.
324
+
325
+ ProtoNet-Based Framework. In our ConstellationNet, we adopt ProtoNet (Snell et al., 2017) as the base few-shot learning framework. In ProtoNet, the dataset $\mathcal { D } ^ { \mathrm { n o v e l } }$ is represented by a series of $K$ -way $N$ -shot tasks $\{ { \bar { \mathcal { T } } } \}$ where each task consists of a support set and a query set, i.e. $\mathcal { T } =$ $( \mathcal { T } ^ { \mathrm { s u p p } } , \mathcal { T } ^ { \mathrm { q u e r y } } )$ . The support set ${ \mathcal { T } } ^ { \mathrm { s u p p } }$ contains $K$ classes and each class has $N$ examples from the training split of $\mathcal { D } ^ { \mathrm { n o v e l } }$ , which are used to adapt the model in meta-test stage. The query set $\mathcal { T } ^ { \mathrm { q u e r y } }$ from the test split of $\mathcal { D } ^ { \mathrm { n o v e l } }$ is then used to evaluate the model.
326
+
327
+ The ProtoNet attempts to learn a generic feature extractor $\phi ( \mathbf { x } )$ on image $\mathbf { x }$ , and represent a class $k$ by the prototype $\mathbf { c } _ { k }$ , which is the average feature of examples from support set ${ \mathcal { T } } ^ { \mathrm { s u p p } }$ with this class:
328
+
329
+ $$
330
+ \mathbf { c } _ { k } = \frac { 1 } { | N | } \sum _ { ( \mathbf { x } , y ) \in \mathcal { T } ^ { \mathrm { s u p p } } , y = k } \phi ( \mathbf { x } )
331
+ $$
332
+
333
+ During the meta-test stage, we use the prototypes to compute the probability $p _ { k }$ of a query example $\mathbf { x } ^ { \prime } \in \bar { \mathcal { T } } ^ { \mathrm { q u e r y } }$ on class $k$ and predict its label $y ^ { \prime }$ :
334
+
335
+ $$
336
+ p _ { k } = p ( y = k | \mathbf { x } ^ { \prime } , \mathcal { T } ^ { \mathrm { s u p p } } ) = \frac { \exp ( d ( \mathbf { x } ^ { \prime } , \mathbf { c } _ { k } ) ) } { \sum _ { k ^ { \prime } } \exp ( d ( \mathbf { x } ^ { \prime } , \mathbf { c } _ { k ^ { \prime } } ) ) } , \quad y ^ { \prime } = \arg \operatorname* { m a x } _ { k } p _ { k } .
337
+ $$
338
+
339
+ where $d ( \cdot , \cdot )$ is a cosine similarity function (different from the Euclidean distance in Snell et al.
340
+ (2017)).
341
+
342
+ During the meta-training stage, there are two different training schemes: The prototypical scheme from ProtoNet uses an episodic learning strategy that also formulates the dataset $\mathcal { D } ^ { \mathrm { b a s e } }$ as a series of tasks $\{ \tau \}$ . The negative log-likelihood loss $\tilde { \mathcal { L } ( \phi ) }$ is optimized:
343
+
344
+ $$
345
+ \begin{array} { r l } & { \ell ( \mathcal { T } ^ { \mathrm { s u p p } } , \mathcal { T } ^ { \mathrm { q u e r y } } ) = \mathbb { E } _ { ( \mathbf { x } ^ { \prime } , y ^ { \prime } ) \in \mathcal { T } ^ { \mathrm { q u e r y } } } - \log p ( y = y ^ { \prime } | \mathbf { x } ^ { \prime } , \mathcal { T } ^ { \mathrm { s u p p } } ) , } \\ & { \qquad \mathcal { L } ( \phi ) = \mathbb { E } _ { \mathcal { T } = ( \mathcal { T } ^ { \mathrm { s u p p } } , \mathcal { T } ^ { \mathrm { q u e r y } } ) \sim \mathcal { D } ^ { \mathrm { b a s e } } } \ell ( \mathcal { T } ^ { \mathrm { s u p p } } , \mathcal { T } ^ { \mathrm { q u e r y } } ) . } \end{array}
346
+ $$
347
+
348
+ Another way is the standard classification scheme (Chen et al., 2020): It simply uses $\mathcal { D } ^ { \mathrm { b a s e } }$ as a standard classification dataset $\{ ( \mathbf { x } , \overset { \cdot } { \boldsymbol { y } } ) \}$ consisting of $Q$ classes in total. Thus, a cross-entropy loss ${ \mathcal { L } } ( \phi )$ is optimized:
349
+
350
+ $$
351
+ \mathcal { L } ( \phi ) = \mathbb { E } _ { ( \mathbf { x } , y ) \sim \mathcal { D } ^ { \mathrm { b a s e } } } - \log \frac { \exp ( \mathbf { w } _ { y } \cdot \phi ( \mathbf { x } ) ) } { \sum _ { q } \exp ( \mathbf { w } _ { q } \cdot \phi ( \mathbf { x } ) ) }
352
+ $$
353
+
354
+ where ${ \bf w } _ { q }$ is the linear weight for class $q$ . In our ConstellationNet, we use the standard classification scheme at default. For the experiment with multi-branch network, we use the prototypical scheme and standard classification scheme for separate branches.
355
+
356
+ # A.2 DATASETS
357
+
358
+ The CIFAR-FS dataset (Bertinetto et al., 2018) is a few-shot classification benchmark containing 100 classes from CIFAR-100 (Krizhevsky et al., 2009). The classes are randomly split into 64, 16 and 20 classes as meta-training, meta-validation and meta-testing set respectively. For each class, it contains 600 images of size $3 2 \times 3 2$ . We adopt the split from Lee et al. (2019). The FC100 dataset (Oreshkin et al., 2018) is another benchmark based on CIFAR-100 where classes are grouped into 20 superclasses to void the overlap between the splits. The mini-ImageNet dataset (Vinyals et al., 2016) is a common benchmark for few-shot classification containing 100 classes from ILSVRC2012 (Deng et al., 2009). The classes are randomly split into 64, 16 and 20 classes as meta-training, meta-validation and meta-testing set respectively. For each class, it contains 600 images of size $8 4 \times 8 4$ . We follow the commonly-used split in Ravi & Larochelle (2016), Lee et al. (2019) and Chen et al. (2020). In all experiments, we conduct data augmentation for the meta-training set of all datasets to match Lee et al. (2019)’s implementation.
359
+
360
+ # A.3 NETWORK BACKBONE
361
+
362
+ Conv-4. Following Lee et al. (2019), we adopt the same network with 4 convolutional blocks. Each of the 4 blocks has a $3 \times 3$ convolutional layer, a batch normalization layer, a ReLU activation and a $2 \times 2$ max-pooling layer sequentially. The numbers of filters are 64 for all 4 convolutional layers.
363
+
364
+ ResNet-12. Following Chen et al. (2020), we construct the residual block with 3 consecutive convolutional blocks followed by an addition average pooling layer where each convolutional block has a $3 \times 3$ convolutional layer, a batch normalization layer, a leaky ReLU activation, and max-pooling layers. The ResNet-12 network has 4 residual blocks with each filter size set to 64, 128, 256, 512, respectively.
365
+
366
+ WRN-28-10. WideResNet expands the residual blocks by increasing the convolutional channels and layers (Zagoruyko & Komodakis, 2016). WRN-28-10 uses 28 convolutional layers with a widening factor of 10.
367
+
368
+ # A.4 CONSTELLATION MODULE CONFIGURATION
369
+
370
+ To achieve the best performance with constellation modules, we do not always fully enable them after all the convolutional layers. For Conv-4, we use constellation modules after all four convolutional layers, but the cell relation modeling module is disabled in first two constellation modules due to the high memory consumption. For ResNet-12, we enable the constellation modules after the convolutional layer 1,7,8,9 and disable the relation modeling module in the first constellation module. We use the deep supervision in ResNet-12 to stablize the training of constellation modules.
371
+
372
+ # A.5 SELF-ATTENTION SETTINGS
373
+
374
+ We follow the common practice in Vaswani et al. (2017) to set the attention layer with residual connections, dropout and layer normalization. The sine positional encoding follows settings in Carion et al. (2020).
375
+
376
+ # A.6 TRAINING DETAILS
377
+
378
+ Optimization Settings. We follow implementation in Lee et al. (2019), and use SGD optimizer with initial learning rate of 1, and set momentum to 0.9 and weight decay rate to $5 \times 1 0 ^ { - 4 }$ . The learning rate reduces to 0.06, 0.012, and 0.0024 at epoch 20, 40 and 50. The inverse temperature $\beta$ is set to 100.0 in the cluster assignment step, and $\lambda$ is set to 1.0 in the centroid movement step.
379
+
380
+ # A.7 ABLATION STUDY ON THE NUMBER OF CLUSTERS
381
+
382
+ Table 4 studies the number of clusters needed for random and similar classes. The result shows the optimal number of clusters are less affected by the number of clusters but more affected by the similarity between classes. Less number of clusters are needed for dataset with classes of high similarity, which aligns with our intuition, limited number of patterns exist in this dataset so that small number of clusters are enough to represent its part-based information.
383
+
384
+ FC100 training dataset consists of 60 classes that are grouped evenly into 12 superclasses. In the random classes group, the training dataset includes 6 randomly selected super-classes (i.e., 30 classes) and models are trained with 8, 16, 32, 64 and 128 number of clusters. The highest accuracy occurs at 16 clusters (1-shot: $3 9 . 1 2 \%$ in ResNet-12). In the similar classes group, 30 classes are randomly sampled from the original training dataset and we repeat the same experiments as above. The highest accuracy occurs at 64 clusters (1-shot: $4 1 . 2 2 \%$ in ResNet-12), which is much more than the 16 clusters used for images from similar classes.
385
+
386
+ Table 4: Ablation study on the number of clusters for random and similar classes. We investigate how similarities of images in the training dataset affect the optimal number of clusters. The first group of experiments use training dataset with 30 similar classes while the second group use 30 random classes from FC100 dataset, all of which performed on ResNet-12 with Constellation module.
387
+
388
+ <table><tr><td rowspan="2"># Clusters</td><td colspan="2">Similar Classes</td><td colspan="2">Random Classes</td></tr><tr><td>1-shot</td><td>5-shot</td><td>1-shot</td><td>5-shot</td></tr><tr><td>8</td><td>38.9±0.2</td><td>52.8± 0.2</td><td>40.9 ± 0.2</td><td>54.5± 0.2</td></tr><tr><td>16</td><td>39.1 ± 0.2</td><td>51.8 ±0.2</td><td>40.9 ±0.2</td><td>54.9 ± 0.2</td></tr><tr><td>32</td><td>38.7 ±0.2</td><td>52.3±0.2</td><td>40.9 ± 0.2</td><td>54.7± 0.2</td></tr><tr><td>64</td><td>38.8±0.2</td><td>52.3 ±0.2</td><td>41.2 ± 0.2</td><td>54.9 ± 0.2</td></tr><tr><td>128</td><td>38.8±0.2</td><td>52.1 ± 0.2</td><td>40.8±0.2</td><td>54.7± 0.2</td></tr></table>
389
+
390
+ # A.8 ADDITIONAL EXPERIMENTS WITH NEGATIVE MARGIN
391
+
392
+ Table 5: Additional experiments with the use of negative margin. Average classification accuracies $( \% )$ on mini-ImageNet meta-test split. We compare our ConstellationNet and baseline with and without the negative margin loss based on Conv-4.
393
+
394
+ <table><tr><td rowspan="2">Baseline</td><td rowspan="2">Cell Feature Clustering</td><td rowspan="2">Cell Relation Modeling</td><td rowspan="2">Negative Margin</td><td colspan="2">Conv-4</td></tr><tr><td>1-shot</td><td>5-shot</td></tr><tr><td>&lt;</td><td></td><td></td><td></td><td>50.62 ± 0.23</td><td>68.40 ± 0.19</td></tr><tr><td></td><td></td><td></td><td>√</td><td>51.42 ± 0.23</td><td>68.84 ± 0.19</td></tr><tr><td></td><td></td><td></td><td></td><td>57.03 ± 0.23</td><td>74.09 ± 0.18</td></tr><tr><td>?</td><td>√</td><td>?</td><td>√</td><td>57.55± 0.23</td><td>74.49 ± 0.18</td></tr></table>
395
+
396
+ Table 5 studies the use of negative margin loss (Liu et al., 2020) on our Conv-4 models. In the negative margin loss, we use the inner-product similarity, the temperature coefficient $\beta = 1 . 0$ and the negative margin $m = - 0 . 5$ , which attains the best performance improvement on our models. Besides, we do not have the fine-tune step during meta-test. Our baseline with the negative margin loss obtains $0 . 8 0 \%$ improvement on 1-shot and $0 . 4 4 \%$ improvement on 5-shot compared with the baseline. Similarly, our ConstellationNet with the negative margin loss achieves $0 . 5 2 \%$ improvement on 1-shot and $0 . 4 0 \%$ improvement on 5-shot. The consistent improvement of negative margin loss on the baseline and our ConstellationNet indicates that our constellation module is orthogonal to the negative margin loss, and both modules can boost the performance on few-shot classification.
397
+
398
+ # A.9 CLARIFICATION ON CLUSTERING PROCEDURE
399
+
400
+ In this section, we add more clarification on our cell feature clustering procedure in Sec. 4.1: During the training stage, the global cluster centers $\boldsymbol { \nu } = \{ \mathbf { v } _ { k } \}$ are updated by the computed clustering centers $\{ \mathbf { v } _ { k } ^ { \prime } \}$ in current mini-batch. Each update to a cluster center $\mathbf { v } _ { k }$ is weighted by a momentum coefficient $\eta$ determined by the value of an associated counter $s _ { k }$ , since we would like to avoid large adjustment from the current mini-batch in order to stabilize the global cluster centers. Besides, the mini-batches of examples are randomly drawn from the dataset following Sculley (2010), without specialized design to optimize clustering learning. During the evaluation stage, we fix the global cluster centers $\nu$ in the forward step of our model, avoiding the potential information leak or transduction from the test mini-batches.
401
+
402
+ # A.10 MULTI-BRANCH DETAILS
403
+
404
+ Our embedding $\phi ( \mathbf { x } )$ is separated into two branches after a shared stem (Y-shape), which is defined as $\phi ( { \bf x } ) = \{ \phi ^ { \mathrm { c l s } } ( { \bf x } ) , \phi ^ { \mathrm { p r o t o } } ( { \bf x } ) \}$ and $\phi ^ { \mathrm { c l s } } ( { \bf x } ) = g ^ { \mathrm { c l s } } ( f ^ { \mathrm { s t e m } } ( { \bf x } ) ) , \phi ^ { \mathrm { p r o t o } } ( { \bf x } ) = g ^ { \bar { \mathrm { p r o t o } } } ( f ^ { \mathrm { s t e m } } ( { \bf x } ) )$ . Two branches $\phi ^ { \mathrm { c l s } } ( { \bf x } ) , \phi ^ { \mathrm { p r o t o } } ( { \bf x } )$ are trained by standard classification and prototypical schemes separately in a multi-task learning fashion. During the testing time, $\phi ^ { \mathrm { c l s } } ( \mathbf { x } )$ and $\phi ^ { \mathrm { p r o t o } } ( \mathbf { x } )$ are concatenated together to compute distance between support prototypes and query images.
405
+
406
+ For our ConstellationNet, we split the network into two branches after the second convolutional blocks (Conv-4) or the second residual blocks (ResNet-12). We keep the shared stem identical to the network backbone and reduce the channels of two separate branches to match the parameter size of the model without multi-branch.
407
+
408
+ # A.11 CONNECTION WITH CAPSULE NETWORKS
409
+
410
+ A notable development to learning the explicit structured representation in an end-to-end framework is the capsule networks (CapsNets) (Sabour et al., 2017). The line of works on CapsNets (Sabour et al., 2017; Hinton et al., 2018; Kosiorek et al., 2019; Tsai et al., 2020) intends to parse a visual scene in an interpretable and hierarchical way. Sabour et al. (2017) represents parts and objects in vector-based capsules with a dynamic routing mechanism. Tsai et al. (2020) uses a stacked autoencoder architecture to model the hierarchical relation among parts, objects and scenes. Here our ConstellationNet maintains part modeling by enabling the joint learning of the convolution and constellation modules to simultaneously attain implicit and explicit representations.
parse/train/vujTf_I8Kmc/vujTf_I8Kmc_content_list.json ADDED
The diff for this file is too large to render. See raw diff
 
parse/train/vujTf_I8Kmc/vujTf_I8Kmc_middle.json ADDED
The diff for this file is too large to render. See raw diff
 
parse/train/vujTf_I8Kmc/vujTf_I8Kmc_model.json ADDED
The diff for this file is too large to render. See raw diff