ZHANGYUXUAN-zR commited on
Commit
5d2ded3
·
verified ·
1 Parent(s): ff169fc

Add files using upload-large-folder tool

Browse files
parse/dev/03RLpj-tc_/03RLpj-tc__model.json ADDED
The diff for this file is too large to render. See raw diff
 
parse/dev/AJg35fkqOPA/AJg35fkqOPA_content_list.json ADDED
@@ -0,0 +1,1387 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "type": "text",
4
+ "text": "TEXT-DRIVEN IMAGE MANIPULATION VIA SEMANTIC-AWARE KNOWLEDGE TRANSFER ",
5
+ "text_level": 1,
6
+ "bbox": [
7
+ 176,
8
+ 98,
9
+ 704,
10
+ 146
11
+ ],
12
+ "page_idx": 0
13
+ },
14
+ {
15
+ "type": "text",
16
+ "text": "Anonymous authors Paper under double-blind review ",
17
+ "bbox": [
18
+ 184,
19
+ 170,
20
+ 398,
21
+ 198
22
+ ],
23
+ "page_idx": 0
24
+ },
25
+ {
26
+ "type": "text",
27
+ "text": "ABSTRACT ",
28
+ "text_level": 1,
29
+ "bbox": [
30
+ 454,
31
+ 234,
32
+ 544,
33
+ 251
34
+ ],
35
+ "page_idx": 0
36
+ },
37
+ {
38
+ "type": "text",
39
+ "text": "Semantic-level facial attribute transfer is a special task to edit facial attribute, when reference images are viewed as conditions to control the image editing. In order to achieve better performance, semantic-level facial attribute transfer needs to fulfil two requirements: (1) specific attributes extracted from reference face should be precisely transferred to target face; (2) irrelevant information should be completely retained after transferring. Some existing methods locate and modify local support regions of facial images, which are not effective when editing global attributes; the other methods disentangle the latent code as different attributerelevant parts, which may transfer redundant knowledge to target faces. In this paper, we first propose a novel text-driven directional latent mapping network with semantic direction consistency (SDC) constrain to explore the latent semantic space for effective attribute editing, leveraging the semantic-aware knowledge of Contrastive Language-Image Pre-training (CLIP) model as guidance. This latent space manipulation strategy is designed to disentangle the facial attribute, removing the redundant knowledge in the transfer process. And on this basis, a novel attribute transfer method, named semantic directional decomposition network (SDD-Net), is proposed to achieve semantic-level facial attribute transfer by latent semantic direction decomposition, improving the interpretability and editability of our method. Extensive experiments on CelebA-HQ dataset show that our method achieves impressive performance over the state-of-the-art methods. ",
40
+ "bbox": [
41
+ 233,
42
+ 266,
43
+ 764,
44
+ 544
45
+ ],
46
+ "page_idx": 0
47
+ },
48
+ {
49
+ "type": "text",
50
+ "text": "1 INTRODUCTION ",
51
+ "text_level": 1,
52
+ "bbox": [
53
+ 176,
54
+ 571,
55
+ 334,
56
+ 587
57
+ ],
58
+ "page_idx": 0
59
+ },
60
+ {
61
+ "type": "text",
62
+ "text": "Generative Adversarial Networks (GANs) (Goodfellow et al., 2014) have revolutionized a variety of fields due to its powerful ability to generate realistic and meaningful outputs. Recent works (Jahanian et al., 2019; He et al., 2019; Goetschalckx et al., 2019) have shown that deep generative models can capture real-world data distribution, and encode them into a semantically-rich latent space. Inspired by this, a lot of tasks draw their attention on the latent space manipulation, including image enhancement (Ledig et al., 2017; Yang et al., 2021b), editing (Shen et al., 2020; Hark ¨ onen ¨ et al., 2020; Patashnik et al., 2021), and discriminative tasks (Nitzan et al., 2021; Xu et al., 2021). ",
63
+ "bbox": [
64
+ 174,
65
+ 603,
66
+ 825,
67
+ 700
68
+ ],
69
+ "page_idx": 0
70
+ },
71
+ {
72
+ "type": "text",
73
+ "text": "With the tremendous success of deep generative models, facial attribute editing (Yeh et al., 2017; Liu et al., 2019; He et al., 2020; Dorta et al., 2020), aiming to edit the specific attributes of the target facial image, has become topical. As a special case of facial attribute editing, facial attribute transfer (Xiao et al., 2018; Lin et al., 2018; Yin et al., 2019; Choi et al., 2018; 2020) uses knowledge from reference image as a condition to edit the corresponding attribute from the target image. In order to ensure that the manipulated facial image meets the requirements and interests, facial attribute transfer task tackles two challenges simultaneously: (1) editing relevance: the relevant attribute should be edited precisely according to the given condition; and (2) keeping irrelevance: the irrelevant part (e.g., identify information, background, or other attributes) should not be modified during attribute transfer. Due to strong entanglement of the attributes, meeting both requirements is an intractable task. For example, without fully disentanglement, transferring the “smile” attribute to the target facial image may cause that, another irrelevant but coupled attribute, e.g. “cheek color” attribute, would be changed during editing. ",
74
+ "bbox": [
75
+ 174,
76
+ 708,
77
+ 825,
78
+ 888
79
+ ],
80
+ "page_idx": 0
81
+ },
82
+ {
83
+ "type": "text",
84
+ "text": "In view of the above issues, recently a variety of methods explore the attribute disentanglement in two ways. Some methods (He et al., 2020; Kwak et al., 2020) resort to the way of spatial attention detection, which disentangle the attribute by searching specific support region spatially and only manipulate the image in such a confined area. Obviously, these methods totally ignore the facial details beyond the support region when the edited attribute is a global attribute, such as “smile” or “age”. Meanwhile, other methods (Shen et al., 2020; Yang et al., 2021a; Patashnik et al., 2021) pay attention to the latent space factorization through pre-trained GAN. These methods employ the high-level semantic information as guidance to manipulate image in latent spaces, which are more suitable to handle both global and local attribute editing. However, owing to over-coupled semantic features, these methods are hard to manipulate specific attribute without powerful supervision. ",
85
+ "bbox": [
86
+ 174,
87
+ 896,
88
+ 823,
89
+ 922
90
+ ],
91
+ "page_idx": 0
92
+ },
93
+ {
94
+ "type": "text",
95
+ "text": "",
96
+ "bbox": [
97
+ 174,
98
+ 103,
99
+ 825,
100
+ 214
101
+ ],
102
+ "page_idx": 1
103
+ },
104
+ {
105
+ "type": "text",
106
+ "text": "To overcome the problems mentioned above, we explore the latent semantic space for disentangled attribute editing, and apply the discovered manipulation method to facial attribute transfer task. As for attribute editing task, in order to disentangle and edit the attribute specified by the text prompt, we design the directional latent mapping network, which leverages semantic direction consistency (SDC) loss to constrain the manipulation in the CLIP-space (Radford et al., 2021). The key idea of the SDC loss is employing the change direction of semantic feature to estimate the latent manipulation. Furthermore, in order to apply this effective editing method to facial attribute transfer task, we propose a novel semantic-level facial attribute transfer method driven by text prompt, named as semantic directional decomposition network (SDD-Net). The SDD-Net extracts and transfers the specific attribute without redundant information through attribute-manipulated semantic directional decomposition. ",
107
+ "bbox": [
108
+ 174,
109
+ 222,
110
+ 825,
111
+ 375
112
+ ],
113
+ "page_idx": 1
114
+ },
115
+ {
116
+ "type": "text",
117
+ "text": "Our contributions are summarized as follows: ",
118
+ "bbox": [
119
+ 176,
120
+ 382,
121
+ 472,
122
+ 396
123
+ ],
124
+ "page_idx": 1
125
+ },
126
+ {
127
+ "type": "text",
128
+ "text": "• We propose a novel method namely directional latent mapping network for facial attribute editing, which utilizes the semantic direction consistency regularization to ensure attribute disentanglement. • To further take advantage of semantic direction constrain, we propose a text-driven semantic directional decomposition network (SDD-Net) for semantic-level attribute transfer, by transferring the knowledge from the reference image to the target image. • Extensive experiments on CelebA-HQ (Karras et al., 2017) dataset show that our method achieves significant improvements over the state-of-art approaches. ",
129
+ "bbox": [
130
+ 217,
131
+ 407,
132
+ 825,
133
+ 531
134
+ ],
135
+ "page_idx": 1
136
+ },
137
+ {
138
+ "type": "text",
139
+ "text": "2 RELATED WORK ",
140
+ "text_level": 1,
141
+ "bbox": [
142
+ 176,
143
+ 551,
144
+ 344,
145
+ 568
146
+ ],
147
+ "page_idx": 1
148
+ },
149
+ {
150
+ "type": "text",
151
+ "text": "Latent Space Manipulation. Recent studies (Bau et al., 2020; Goetschalckx et al., 2019; Shen et al., 2020) have shown that numerous GAN models can encode rich crucial information in the intermediate latent space, such as $\\mathcal { W }$ , $\\mathcal { W } +$ (Abdal et al., 2019), or StyleSpace $s$ (Wu et al., 2021). By learning to modify the intermediate latent code, generative models can transfer attributes from one face to another face (Xiao et al., 2018; Choi et al., 2020). To find a latent code that allows for meaningful manipulation, some methods try to learn an effective encoder network, which inverts a real image into latent space: encoder4editing (e4e) (Tov et al., 2021) method presents an encoder that is specifically designed for balancing distortion-editability tradeoff and a distortion-perception tradeoff within the StyleGAN latent space; Stylespace (Wu et al., 2021) proposes a space of channelwise style parameters that disentangle attributes by controlling attribute-related style channels; The pixel2style2pixel (pSp) (Richardson et al., 2021) method utilizes a novel encoder architecture that inverts a real image into $\\mathcal { W } +$ space without optimization. Other methods mainly focus on finding such latent code modification approach as used to traverse latent space, result in the desired manipulation: AttGAN (He et al., 2019) applies attribute classification constraint to model the relation between the attributes and the latent representation; InterfaceGAN (Shen et al., 2020) decouples some entangled semantic features with subspace projection; GANspace (Hark ¨ onen et al., 2020) leverages ¨ principal component analysis to identify mainly direction in latent space; L2M-GAN (Yang et al., 2021a) imposes an orthogonality constraint to ensure disentanglement in latent space; StyleCLIP (Patashnik et al., 2021) leverages CLIP models to guide the attributes manipulation by latent semantic matching. ",
152
+ "bbox": [
153
+ 173,
154
+ 583,
155
+ 825,
156
+ 861
157
+ ],
158
+ "page_idx": 1
159
+ },
160
+ {
161
+ "type": "text",
162
+ "text": "Different from the methods mentioned above, our method aligns the guidance direction, which is derived directly from text prompt, with the change direction of semantic features extracted by CLIP to guide the manipulation in the latent space. By constraining the consistency of these directions, our method can achieve disentangled attribute editing. ",
163
+ "bbox": [
164
+ 174,
165
+ 867,
166
+ 823,
167
+ 924
168
+ ],
169
+ "page_idx": 1
170
+ },
171
+ {
172
+ "type": "image",
173
+ "img_path": "images/0a855f9fd91735343743771b0cbbcd356d2018299f616cd16110b5d15d287c9f.jpg",
174
+ "image_caption": [
175
+ "Figure 1: Overview of our idea for directional latent mapping network. By enforcing the change direction of semantic feature to align with desired direction in CLIP-space, our method can achieve impressive disentangled image manipulation. "
176
+ ],
177
+ "image_footnote": [],
178
+ "bbox": [
179
+ 290,
180
+ 103,
181
+ 707,
182
+ 270
183
+ ],
184
+ "page_idx": 2
185
+ },
186
+ {
187
+ "type": "text",
188
+ "text": "Semantic-level Attribute Transfer. Semantic-level attribute transfer is a more challenging facial attribute editing task. Recent studies have attempted more detailed approaches for facial attribute transfer: StarGAN (Choi et al., 2018) applies cycle consistency to preserve identity, and uses classification loss to transfer between different domains. In addition, StarGANv2 (Choi et al., 2020) also could synthesize reference-guide images leveraging multiple domain translation. Some works are specialized for specific attributes: ExprGAN (Ding et al., 2018) proposes a model to learn the disentangled identity and expression representations explicitly for facial expression transfer. Besides, ERGAN (Hu et al., 2020) proposes a dual learning scheme to simultaneously learn two inverse manipulations for attribute transfer. ",
189
+ "bbox": [
190
+ 174,
191
+ 357,
192
+ 825,
193
+ 483
194
+ ],
195
+ "page_idx": 2
196
+ },
197
+ {
198
+ "type": "text",
199
+ "text": "Different from these works, our proposed method focuses not only on one attribute, but also on various global or local attributes. Given an explicit text prompt, our method can automatically extract the specific attribute from the reference, and transfer the knowledge to the target image. ",
200
+ "bbox": [
201
+ 174,
202
+ 489,
203
+ 823,
204
+ 531
205
+ ],
206
+ "page_idx": 2
207
+ },
208
+ {
209
+ "type": "text",
210
+ "text": "3 METHODOLOGY ",
211
+ "text_level": 1,
212
+ "bbox": [
213
+ 176,
214
+ 556,
215
+ 339,
216
+ 571
217
+ ],
218
+ "page_idx": 2
219
+ },
220
+ {
221
+ "type": "text",
222
+ "text": "In the following section, we first provide the preliminaries and problem formulation. Then, we introduce our text-driven directional latent mapping network for disentangled facial attribute editing. Finally, we describe the text-driven semantic directional decomposition network (SDD-Net) for semantic-aware facial attribute transfer. ",
223
+ "bbox": [
224
+ 174,
225
+ 590,
226
+ 825,
227
+ 646
228
+ ],
229
+ "page_idx": 2
230
+ },
231
+ {
232
+ "type": "text",
233
+ "text": "3.1 PRELIMINARIES ",
234
+ "text_level": 1,
235
+ "bbox": [
236
+ 174,
237
+ 669,
238
+ 326,
239
+ 683
240
+ ],
241
+ "page_idx": 2
242
+ },
243
+ {
244
+ "type": "text",
245
+ "text": "StyleGAN. The StyleGAN (Karras et al., 2019; 2020) generator consists of two main components: mapping network and synthesis network. The former translates latent code $z$ to latent code $w$ , which is in semantic-rich latent space $\\mathcal { W }$ , and the latter utilizes latent code $w$ to synthesize final images through different layers. Due to the rich information inside, the latent code $w$ can control the multigranularity semantic features of the synthetic image, which is utilized for effective facial attribute transfer in semantic-level. In this paper, we leverage the pre-trained synthesis network as our image generator. ",
246
+ "bbox": [
247
+ 173,
248
+ 695,
249
+ 825,
250
+ 794
251
+ ],
252
+ "page_idx": 2
253
+ },
254
+ {
255
+ "type": "text",
256
+ "text": "StyleCLIP. The StyleCLIP (Patashnik et al., 2021) method first combines StyleGAN and CLIP as a strong tool for text-driven image editing. The key idea of StyleCLIP is to leverage the CLIP as latent manipulation guidance. By mapping multi-modal inputs to the CLIP-space, StyleCLIP could ensure that the synthetic image matches with the text prompt in semantic-level. The objective is given by: ",
257
+ "bbox": [
258
+ 173,
259
+ 799,
260
+ 825,
261
+ 857
262
+ ],
263
+ "page_idx": 2
264
+ },
265
+ {
266
+ "type": "equation",
267
+ "img_path": "images/69a233d8e91a3dd215da362e1e5bd4716b3123fadd6f7d836f115bb3d7176c4f.jpg",
268
+ "text": "$$\n\\mathcal { L } _ { s t y l e c l i p } = D _ { \\mathrm { C L I P } } ( G ( w ) , t e x t ) ,\n$$",
269
+ "text_format": "latex",
270
+ "bbox": [
271
+ 387,
272
+ 867,
273
+ 609,
274
+ 886
275
+ ],
276
+ "page_idx": 2
277
+ },
278
+ {
279
+ "type": "text",
280
+ "text": "where $D _ { \\mathrm { C L I P } }$ is the cosine distance metric in CLIP-space, and $G$ is the pre-trained StyleGAN generator. ",
281
+ "bbox": [
282
+ 176,
283
+ 895,
284
+ 823,
285
+ 924
286
+ ],
287
+ "page_idx": 2
288
+ },
289
+ {
290
+ "type": "image",
291
+ "img_path": "images/9ab91a6a5e91c830f4013b388d228e7380eb6299535eaee7b90d708604bbb256.jpg",
292
+ "image_caption": [
293
+ "Figure 2: The architecture of our directional latent mapping network. Given the text prompt, we manipulate the latent code inverted by the facial images. Then we use $g$ group channel-wise mapping networks to manipulate the different parts of latent code $w$ respectively. Multiple loss functions are used to constrain the synthetic image to fulfil the requirements. "
294
+ ],
295
+ "image_footnote": [],
296
+ "bbox": [
297
+ 181,
298
+ 104,
299
+ 816,
300
+ 291
301
+ ],
302
+ "page_idx": 3
303
+ },
304
+ {
305
+ "type": "text",
306
+ "text": "3.2 PROBLEM FORMULATION ",
307
+ "text_level": 1,
308
+ "bbox": [
309
+ 176,
310
+ 387,
311
+ 392,
312
+ 401
313
+ ],
314
+ "page_idx": 3
315
+ },
316
+ {
317
+ "type": "text",
318
+ "text": "Our method leverages two latent space: $\\mathcal { W } +$ space and CLIP-space, to transfer semantic-level facial attributes. For better expression, let $\\mathcal { X }$ and $\\mathcal { V }$ denote the set of images and semantic features in CLIP-space, respectively. The image $x \\in \\mathcal { X }$ is inverted into corresponding latent code $w \\in \\mathcal { W } +$ . $t$ denotes the input text prompt, with corresponding semantic feature $y _ { t }$ . Meanwhile, the parameters of pre-trained StyleGANv2 generator $G$ are frozen during training. ",
319
+ "bbox": [
320
+ 174,
321
+ 412,
322
+ 825,
323
+ 483
324
+ ],
325
+ "page_idx": 3
326
+ },
327
+ {
328
+ "type": "text",
329
+ "text": "Given the text prompt $t$ , the goal of facial attribute transfer model is to train a latent mapping network, which translates $w \\backslash y$ to $\\hat { w } \\textcircled { y }$ , and synthesizes the edited image $\\hat { x }$ that meets the specific requirements. Our basic editing model can be formally defined as $\\hat { x } = \\mathbf { \\bar { \\cal G } } ( M ( x , t ) )$ , where $M$ is the manipulation network. Hence given the reference image $x _ { r e f } \\in \\mathcal { X }$ , our semantic-aware attribute transfer model can be formally defined as $\\hat { x } = G ( M ( x , x _ { r e f } , t ) )$ . ",
330
+ "bbox": [
331
+ 174,
332
+ 489,
333
+ 825,
334
+ 560
335
+ ],
336
+ "page_idx": 3
337
+ },
338
+ {
339
+ "type": "text",
340
+ "text": "3.3 DIRECTIONAL LATENT MAPPING ",
341
+ "text_level": 1,
342
+ "bbox": [
343
+ 176,
344
+ 577,
345
+ 444,
346
+ 590
347
+ ],
348
+ "page_idx": 3
349
+ },
350
+ {
351
+ "type": "text",
352
+ "text": "Only focusing on matching $\\hat { y }$ with $y _ { t }$ may cause irrelevant attribute changed. Therefore, we enforce the mapping network to focus on the change direction of semantic features in CLIP-space, and illustrate this idea in Figure 1. The details of the proposed directional latent mapping network is described as follows: ",
353
+ "bbox": [
354
+ 174,
355
+ 602,
356
+ 825,
357
+ 659
358
+ ],
359
+ "page_idx": 3
360
+ },
361
+ {
362
+ "type": "text",
363
+ "text": "Architecture. It has been shown that the different layers of synthesis network, which correspends to different parts of the latent code, control different granularity of semantic feature. In order to better exploit this property, we design the directional latent mapping network, and depict it in Figure 2. To a great extent, the degree of attributes disentanglement depends on the disentanglement of latent features. Therefore, we split the layers into $g$ groups, instead three (coarse, medium, and fine), with $g$ fully connected mapping networks, one for each group. The divided part of the latent code can be denoted as $w = [ w _ { 1 } , w _ { 2 } , . . . , w _ { g } ]$ , so the mapping network is defined by: ",
364
+ "bbox": [
365
+ 173,
366
+ 665,
367
+ 825,
368
+ 763
369
+ ],
370
+ "page_idx": 3
371
+ },
372
+ {
373
+ "type": "equation",
374
+ "img_path": "images/49c6a828e010a65035483d74ffcde1a47b6189a8bc56236546b6cdf166822ef9.jpg",
375
+ "text": "$$\nM ( w ) = [ M _ { 1 } ( w _ { 1 } ) , M _ { 2 } ( w _ { 2 } ) , . . . , M _ { g } ( w _ { g } ) ] ,\n$$",
376
+ "text_format": "latex",
377
+ "bbox": [
378
+ 357,
379
+ 765,
380
+ 637,
381
+ 782
382
+ ],
383
+ "page_idx": 3
384
+ },
385
+ {
386
+ "type": "text",
387
+ "text": "where $M _ { i }$ is the $i$ -th mapping network, and $[ \\cdot , \\cdot ]$ means concat operation. Then we use skipconnection operation to obtain the final manipulated latent code $\\hat { w } = w + \\alpha M ( w )$ , and feed it to the pre-trained StyleGANv2 generator $G$ to get the final manipulated facial image $\\hat { x } = G ( \\hat { w } )$ . ",
388
+ "bbox": [
389
+ 174,
390
+ 785,
391
+ 825,
392
+ 828
393
+ ],
394
+ "page_idx": 3
395
+ },
396
+ {
397
+ "type": "text",
398
+ "text": "Training Objective. The edited desired attribute is determined by the textual prompt $t$ . Without paired training data, the mapping network could not correctly manipulate the latent code. In order to obtain extra powerful supervision, we use CLIP model to effectively extract semantic features (attributes) $y$ of the corresponding images and text: ",
399
+ "bbox": [
400
+ 174,
401
+ 833,
402
+ 823,
403
+ 890
404
+ ],
405
+ "page_idx": 3
406
+ },
407
+ {
408
+ "type": "equation",
409
+ "img_path": "images/d692d41f4d85fba6dd6347bdc6553942435c17270e95d9fab483361e38e3f855.jpg",
410
+ "text": "$$\n\\begin{array} { c } { { y _ { i } ; \\hat { y _ { i } } = E _ { I } ( x ; \\hat { x } ) , } } \\\\ { { y _ { t } = E _ { T } ( t ) , } } \\end{array}\n$$",
411
+ "text_format": "latex",
412
+ "bbox": [
413
+ 437,
414
+ 892,
415
+ 558,
416
+ 929
417
+ ],
418
+ "page_idx": 3
419
+ },
420
+ {
421
+ "type": "image",
422
+ "img_path": "images/6319cd20319308bfa543afbc202eb39dd245bfa6a592ab33ebaa36a063af4ee0.jpg",
423
+ "image_caption": [
424
+ "Figure 3: The illustration of attribute transfer loss $\\mathcal { L } _ { \\mathrm { A T } }$ in our Semantic Directional Decomposition Network (SDD-Net). We embed both the text prompt and reference\\target face into CLIP-space. When the projected vector $\\vec { \\mathcal { V } _ { p } }$ has the same direction with desired direction, the same attribute (e.g., smile) is transferred to the target face. Reversely, the opposite attribute (e.g., black hair) will be transferred when the direction is inverse. "
425
+ ],
426
+ "image_footnote": [],
427
+ "bbox": [
428
+ 320,
429
+ 102,
430
+ 674,
431
+ 295
432
+ ],
433
+ "page_idx": 4
434
+ },
435
+ {
436
+ "type": "text",
437
+ "text": "where $E$ denotes the pre-trained multi-modal feature extractor integrated in CLIP, $y _ { i }$ and $\\hat { y } _ { i }$ denotes the extracted semantic features of $x$ and $\\hat { x }$ , respectively. $y _ { t }$ is the desired semantic feature extracted from textual prompt $t$ . ",
438
+ "bbox": [
439
+ 174,
440
+ 410,
441
+ 825,
442
+ 453
443
+ ],
444
+ "page_idx": 4
445
+ },
446
+ {
447
+ "type": "text",
448
+ "text": "In the latent CLIP-space, simply optimizing the matching degree between $\\hat { y } _ { i }$ and $y _ { t }$ may cause irrelevant attribute to be changed. Therefore, rather than optimizing the matching degree to the utmost extent, we enforce the change direction between $y$ and $\\hat { y } _ { i }$ to align with the $y _ { t }$ , and propose the semantic direction consistency (SDC) loss. The SDC loss is given by: ",
449
+ "bbox": [
450
+ 174,
451
+ 459,
452
+ 825,
453
+ 516
454
+ ],
455
+ "page_idx": 4
456
+ },
457
+ {
458
+ "type": "equation",
459
+ "img_path": "images/f59c5b0bec3f30a57dcb81418bab713dd45fe09b294dd777f151994b1f371180.jpg",
460
+ "text": "$$\n\\begin{array} { c } { { \\vec { I } = \\hat { y _ { i } } - y _ { i } , } } \\\\ { { \\vec { T } = y _ { t } , } } \\\\ { { \\vec { \\mathcal { L } } _ { \\mathrm { S D C } } = 1 - S ( \\vec { I } , \\vec { T } ) , } } \\end{array}\n$$",
461
+ "text_format": "latex",
462
+ "bbox": [
463
+ 423,
464
+ 521,
465
+ 573,
466
+ 587
467
+ ],
468
+ "page_idx": 4
469
+ },
470
+ {
471
+ "type": "text",
472
+ "text": "where $S ( \\cdot , \\cdot )$ is the similarity measurement. In this paper, we use the effective cosine similarity as the measurement. ",
473
+ "bbox": [
474
+ 171,
475
+ 592,
476
+ 825,
477
+ 621
478
+ ],
479
+ "page_idx": 4
480
+ },
481
+ {
482
+ "type": "text",
483
+ "text": "The above objective can guide the mapping network to manipulate the latent code along the direction of textual prompt. In order to preserve the irrelevant parts, we use the following identity loss: ",
484
+ "bbox": [
485
+ 171,
486
+ 627,
487
+ 823,
488
+ 656
489
+ ],
490
+ "page_idx": 4
491
+ },
492
+ {
493
+ "type": "equation",
494
+ "img_path": "images/61cc6a1853b9263316c0aaef5278d94a5ae258b28b820e46d89df03d26dd8671.jpg",
495
+ "text": "$$\n\\mathcal { L } _ { \\mathrm { I D } } = 1 - \\left. R ( G ( w ) ) , R ( G ( \\hat { w } ) ) \\right. ,\n$$",
496
+ "text_format": "latex",
497
+ "bbox": [
498
+ 382,
499
+ 662,
500
+ 614,
501
+ 680
502
+ ],
503
+ "page_idx": 4
504
+ },
505
+ {
506
+ "type": "text",
507
+ "text": "where $R$ is a pre-trained ArcFace (Deng et al., 2019) network for face recognition, and $\\langle \\cdot , \\cdot \\rangle$ computes the cosine similarity between its two arguments. Meanwhile, we use $L _ { 2 }$ distance in $\\mathcal { W } +$ space to control the degree of manipulation. Then, the whole training objective for directional latent mapping network is denoted as: ",
508
+ "bbox": [
509
+ 174,
510
+ 686,
511
+ 825,
512
+ 743
513
+ ],
514
+ "page_idx": 4
515
+ },
516
+ {
517
+ "type": "equation",
518
+ "img_path": "images/0573425177fb302ecf79de2e26095c35a9c9ca1301c074c28b52a763aca7325e.jpg",
519
+ "text": "$$\n\\underset { w \\in \\mathcal { W } + } { \\arg \\operatorname* { m i n } } \\lambda _ { \\mathrm { S D C } } \\mathcal { L } _ { \\mathrm { S D C } } ( w , t ) + \\lambda _ { L 2 } | | M ( w ) | | _ { 2 } + \\lambda _ { \\mathrm { I D } } \\mathcal { L } _ { \\mathrm { I D } } ( w ) .\n$$",
520
+ "text_format": "latex",
521
+ "bbox": [
522
+ 305,
523
+ 750,
524
+ 694,
525
+ 777
526
+ ],
527
+ "page_idx": 4
528
+ },
529
+ {
530
+ "type": "text",
531
+ "text": "3.4 SEMANTIC DIRECTIONAL DECOMPOSITION ",
532
+ "text_level": 1,
533
+ "bbox": [
534
+ 173,
535
+ 791,
536
+ 516,
537
+ 808
538
+ ],
539
+ "page_idx": 4
540
+ },
541
+ {
542
+ "type": "text",
543
+ "text": "Inspired by the above method, we found that a semantic attribute translation can be represented as a directional vector in CLIP-space. Based on this, we leverage the same architecture of directional mapping network, and propose a facial attribute transfer method via semantic-aware knowledge transfer, named as semantic directional decomposition network (SDD-Net). ",
544
+ "bbox": [
545
+ 174,
546
+ 818,
547
+ 825,
548
+ 875
549
+ ],
550
+ "page_idx": 4
551
+ },
552
+ {
553
+ "type": "text",
554
+ "text": "Given the textual prompt $t$ , we want to transfer the attribute, extracted from the reference image $x _ { r e f }$ , to the target image $x _ { t a r }$ . The $y _ { r e f }$ and $y _ { t a r }$ are their corresponding semantic features respectively. And the semantic feature of textual prompt $t$ is $y _ { t }$ . ",
555
+ "bbox": [
556
+ 174,
557
+ 881,
558
+ 823,
559
+ 924
560
+ ],
561
+ "page_idx": 4
562
+ },
563
+ {
564
+ "type": "image",
565
+ "img_path": "images/a42c290dc0d3755ecd6b895c9e1dbab8d88f351e03476d25131bed5a4d947f7a.jpg",
566
+ "image_caption": [
567
+ "Figure 4: Qualitative results for facial attribute editing on attribute “smile”. The left column are the target images sampled from CelebA-HQ dataset. The other column from left to right are the editing results of L2M-GAN (Yang et al., 2021a), StyleCLIP\\* (Patashnik et al., 2021), and our directional latent mapping network. "
568
+ ],
569
+ "image_footnote": [],
570
+ "bbox": [
571
+ 305,
572
+ 106,
573
+ 687,
574
+ 375
575
+ ],
576
+ "page_idx": 5
577
+ },
578
+ {
579
+ "type": "text",
580
+ "text": "Due to the above direction-based manipulation, we can treat the facial attribute transfer problem as the attribute semantic feature projection problem. In the CLIP-space, a facial image can be treated as the composition of different semantic features. Therefore, we assume that different facial images can be converted to each other in semantic-level. In other words, one semantic feature can be translated to another semantic feature. ",
581
+ "bbox": [
582
+ 173,
583
+ 474,
584
+ 825,
585
+ 545
586
+ ],
587
+ "page_idx": 5
588
+ },
589
+ {
590
+ "type": "text",
591
+ "text": "Under such an assumption, we first define the RT (reference-target) vector as: $\\mathcal { V } _ { R T } ^ { } = y _ { r e f } - y _ { t a r }$ , which is the variance of two semantic features, and also is the direction of translation. We set the $y _ { t }$ as the projection direction. In order to extract knowledge from the reference, we project RT vector $\\vec { \\nu _ { R T } }$ onto desired direction $\\vec { \\mathcal { V } } _ { t } = \\boldsymbol { y } _ { t }$ : ",
592
+ "bbox": [
593
+ 173,
594
+ 551,
595
+ 825,
596
+ 611
597
+ ],
598
+ "page_idx": 5
599
+ },
600
+ {
601
+ "type": "equation",
602
+ "img_path": "images/e912408a07b24d5148334f231af090ff538834d0c1cb68d630df53996cf1eced.jpg",
603
+ "text": "$$\n\\vec { \\mathcal { V } _ { p } } = \\mathcal { V } _ { R T } ^ { } \\cdot ( \\frac { \\vec { \\mathcal { V } _ { t } } } { | \\mathcal { V } _ { t } | } ) ^ { 2 } ,\n$$",
604
+ "text_format": "latex",
605
+ "bbox": [
606
+ 421,
607
+ 631,
608
+ 576,
609
+ 676
610
+ ],
611
+ "page_idx": 5
612
+ },
613
+ {
614
+ "type": "text",
615
+ "text": "where $\\vec { \\mathcal { V } _ { p } }$ is the projected vector. Then we add it to the target semantic feature $y _ { t a r }$ to get the final goal: ",
616
+ "bbox": [
617
+ 174,
618
+ 684,
619
+ 825,
620
+ 714
621
+ ],
622
+ "page_idx": 5
623
+ },
624
+ {
625
+ "type": "equation",
626
+ "img_path": "images/b1953999dce094da238953578e9aaac69ac01fc5c4bbd6cbf37a6a90510864b7.jpg",
627
+ "text": "$$\ny _ { g o a l } = y _ { t a r } + \\beta \\vec { \\mathcal { V } _ { p } } ,\n$$",
628
+ "text_format": "latex",
629
+ "bbox": [
630
+ 429,
631
+ 715,
632
+ 566,
633
+ 736
634
+ ],
635
+ "page_idx": 5
636
+ },
637
+ {
638
+ "type": "text",
639
+ "text": "where $\\beta$ is the hyperparameter. ",
640
+ "bbox": [
641
+ 174,
642
+ 742,
643
+ 379,
644
+ 757
645
+ ],
646
+ "page_idx": 5
647
+ },
648
+ {
649
+ "type": "text",
650
+ "text": "Training Objective. We use same architecture of directional latent mapping network to obtain the manipulated image $\\hat { x } = G ( M ( \\hat { w } ) )$ , then match the semantic feature $\\hat { y } = E _ { I } ( \\hat { x } )$ with $y _ { g o a l }$ in CLIP-space. As illustrated in Figure 3, the attribute transfer loss $\\mathcal { L } _ { \\mathrm { A T } }$ is given by: ",
651
+ "bbox": [
652
+ 174,
653
+ 763,
654
+ 825,
655
+ 806
656
+ ],
657
+ "page_idx": 5
658
+ },
659
+ {
660
+ "type": "equation",
661
+ "img_path": "images/cba301187b893805ac784915bab18c511d3f9fae6ee99a377ff5e5792104f7db.jpg",
662
+ "text": "$$\n\\mathcal { L } _ { \\mathrm { A T } } = \\mathrm { M S E } ( \\hat { y } , y _ { g o a l } ) ,\n$$",
663
+ "text_format": "latex",
664
+ "bbox": [
665
+ 419,
666
+ 815,
667
+ 576,
668
+ 833
669
+ ],
670
+ "page_idx": 5
671
+ },
672
+ {
673
+ "type": "text",
674
+ "text": "where $\\mathrm { M S E } ( \\cdot , \\cdot )$ is the mean squared error. ",
675
+ "bbox": [
676
+ 176,
677
+ 842,
678
+ 455,
679
+ 858
680
+ ],
681
+ "page_idx": 5
682
+ },
683
+ {
684
+ "type": "text",
685
+ "text": "Meanwhile, we use the same $L 2$ loss and identity loss to preserve the irrelevant parts. The whole training objective of SDD-Net is: ",
686
+ "bbox": [
687
+ 171,
688
+ 863,
689
+ 825,
690
+ 892
691
+ ],
692
+ "page_idx": 5
693
+ },
694
+ {
695
+ "type": "equation",
696
+ "img_path": "images/ddd12d3cb52042f904e9e898825e776d66ce2a50abdd6fadab0ca762686b1ff4.jpg",
697
+ "text": "$$\n\\operatorname* { a r g m i n } _ { w \\in \\mathcal { W } + } \\lambda _ { \\mathrm { A T } } \\mathcal { L } _ { \\mathrm { A T } } + \\lambda _ { \\mathrm { L 2 } } \\mathcal { L } _ { \\mathrm { 2 } } + \\lambda _ { \\mathrm { I D } } \\mathcal { L } _ { \\mathrm { I D } } .\n$$",
698
+ "text_format": "latex",
699
+ "bbox": [
700
+ 370,
701
+ 901,
702
+ 629,
703
+ 928
704
+ ],
705
+ "page_idx": 5
706
+ },
707
+ {
708
+ "type": "image",
709
+ "img_path": "images/32527924cb4a64c62e9b2fa1e9563a20ec8e5225f4869fab2b07231e7afb59eb.jpg",
710
+ "image_caption": [
711
+ "Figure 5: The qualitative results of our SDD-Net on single attribute transfer. Reference images in the left column. Target images in the first row of each parts, the rest is our manipulated images. Given the text prompt, our SDD-Net transfer the specific attribute (“smile”) to the target images (top part) when the reference have the specific attribute. By contrast, the reverse attribute (“unsmiling”) will be transferred (bottom part) when the specific attribute is not contained in the reference. Notice that, we only input one text prompt. So the SDD-Net could determine the forward or reverse transferring direction, according to the reference. "
712
+ ],
713
+ "image_footnote": [],
714
+ "bbox": [
715
+ 200,
716
+ 104,
717
+ 803,
718
+ 397
719
+ ],
720
+ "page_idx": 6
721
+ },
722
+ {
723
+ "type": "text",
724
+ "text": "4 EXPERIMENTS ",
725
+ "text_level": 1,
726
+ "bbox": [
727
+ 176,
728
+ 539,
729
+ 326,
730
+ 554
731
+ ],
732
+ "page_idx": 6
733
+ },
734
+ {
735
+ "type": "text",
736
+ "text": "In this section, we first introduce the involved dataset and the implementation details. Then we will present the comparison results with several state-of-the-art facial attribute editing and facial attribute transfer methods to prove the effectiveness of our proposed method. Finally, the ablation studies will be presented to prove the effectiveness of our method. ",
737
+ "bbox": [
738
+ 174,
739
+ 570,
740
+ 825,
741
+ 626
742
+ ],
743
+ "page_idx": 6
744
+ },
745
+ {
746
+ "type": "text",
747
+ "text": "4.1 DATASET ",
748
+ "text_level": 1,
749
+ "bbox": [
750
+ 174,
751
+ 645,
752
+ 279,
753
+ 659
754
+ ],
755
+ "page_idx": 6
756
+ },
757
+ {
758
+ "type": "text",
759
+ "text": "In order to achieve text-driven facial attribute editing and transfer, we choose the widely-used CelebA-HQ (Karras et al., 2017) dataset, which consists of 30,000 high quality facial images picked from the original CelebA (Liu et al., 2015) dataset. The size of each high quality image is $1 0 2 4 \\times 1 0 2 4$ . In the original dataset, each image has 40 attributes annotations inherited from the original CelebA. However in this work, we remove these annotations, and leverage CLIP model as powerful supervision. We also use the standard training, validation and test splits inherited from CelebA dataset. ",
760
+ "bbox": [
761
+ 174,
762
+ 670,
763
+ 825,
764
+ 768
765
+ ],
766
+ "page_idx": 6
767
+ },
768
+ {
769
+ "type": "text",
770
+ "text": "4.2 IMPLEMENTATION DETAILS ",
771
+ "text_level": 1,
772
+ "bbox": [
773
+ 176,
774
+ 786,
775
+ 405,
776
+ 800
777
+ ],
778
+ "page_idx": 6
779
+ },
780
+ {
781
+ "type": "text",
782
+ "text": "In this subsection we provide the implementation details of our proposed networks. All images taken from the CelebA-HQ are inverted by e4e (Tov et al., 2021). We set the batch size and the number of total iterations to 5 and 50k respectively, during training. Our image editing is performed on StyleGANv2 pre-trained on FFHQ (Karras et al., 2019) dataset. We keep the StyleGANv2 generator fixed during training. The CLIP model is pre-trained on 400 million image-text pairs. We use the Vision Transformer (ViT) (Dosovitskiy et al., 2020) and a normal Transformer (Vaswani et al., 2017), which are integrated in CLIP model, as our image encoder and text encoder, respectively. Our directional latent mapping module is initialized using the pre-trained StyleGANv2, and trained using Adam with the learning rate 5e-3. We set $g = 9$ , $\\alpha = 0 . 1$ , and $\\beta = 1 3 0$ . For facial attribute editing, the hyperparameters are empirically set as $\\lambda _ { S D C } = 1$ , $\\lambda _ { L 2 } = 0 . 4$ , and $\\lambda _ { \\mathrm { I D } } = 0 . 0 2$ . For facial attribute transfer, the hyperparameters are empirically set as $\\lambda _ { \\mathrm { A T } } = 1$ , $\\lambda _ { L 2 } = 0 . 2$ , and $\\lambda _ { \\mathrm { I D } } =$ 0.02. Our methods are trained on PyTorch with a single TITAN RTX GPU. We optimize training objective through gradient descent, by back-propagating the gradient through the pre-trained and fixed StyleGAN generator $G$ and CLIP multi-modal encoder $E$ . ",
783
+ "bbox": [
784
+ 174,
785
+ 811,
786
+ 825,
787
+ 924
788
+ ],
789
+ "page_idx": 6
790
+ },
791
+ {
792
+ "type": "image",
793
+ "img_path": "images/881485244855762ebbec0b98b0a6e810c0a3080469b5802969e477e744d83c5a.jpg",
794
+ "image_caption": [
795
+ "Figure 6: Experiments on reference-guided image synthesis on CelebA-HQ. Reference and target images both in the first row. The second and third raw are the synthetic results of StarGANv2 (Choi et al., 2020) and our SDD-Net respectively. "
796
+ ],
797
+ "image_footnote": [],
798
+ "bbox": [
799
+ 179,
800
+ 103,
801
+ 820,
802
+ 287
803
+ ],
804
+ "page_idx": 7
805
+ },
806
+ {
807
+ "type": "text",
808
+ "text": "",
809
+ "bbox": [
810
+ 174,
811
+ 378,
812
+ 825,
813
+ 463
814
+ ],
815
+ "page_idx": 7
816
+ },
817
+ {
818
+ "type": "text",
819
+ "text": "4.3 BASELINE METHODS",
820
+ "text_level": 1,
821
+ "bbox": [
822
+ 176,
823
+ 487,
824
+ 361,
825
+ 501
826
+ ],
827
+ "page_idx": 7
828
+ },
829
+ {
830
+ "type": "text",
831
+ "text": "Facial Attribute Editing Methods. We first compare our directional latent mapping network with the state-of-the-art facial attribute editing methods (i.e., L2M-GAN (Yang et al., 2021a), and StyleCLIP (Patashnik et al., 2021)) for the specific attribute: “smile”. Due to the requirements of highlevel semantic-aware knowledge, the smile attribute has become one of the most challenging global attributes. For L2M-GAN, we set the attribute domains as two (“smile” and “sad”), leveraging the domain label to guide the manipulation. For StyleCLIP, we use the latent mapper network as the baseline model, which is marked as StyleCLIP\\*. ",
832
+ "bbox": [
833
+ 174,
834
+ 516,
835
+ 825,
836
+ 613
837
+ ],
838
+ "page_idx": 7
839
+ },
840
+ {
841
+ "type": "text",
842
+ "text": "Facial Attribute Transfer Methods. The StarGANv2 (Choi et al., 2020) learns to transform a source image reflecting the style of a given reference image. We compare our SDD-Net with StarGANv2 method on reference-guided image synthesis, which is a challenging facial attribute transfer task. Reference-guided image synthesis requires that various high-level attributes in the reference images, such as hairstyle, makeup, beard and expression, should be transferrd to the target images, while the irrelevant information such as pose and identity should be preserved. For fair comparison, we resize the images to $2 5 6 \\times 2 5 6$ in reference-guided image synthesis. ",
843
+ "bbox": [
844
+ 174,
845
+ 619,
846
+ 825,
847
+ 718
848
+ ],
849
+ "page_idx": 7
850
+ },
851
+ {
852
+ "type": "text",
853
+ "text": "4.4 RESULTS AND ANALYSIS ",
854
+ "text_level": 1,
855
+ "bbox": [
856
+ 176,
857
+ 742,
858
+ 387,
859
+ 756
860
+ ],
861
+ "page_idx": 7
862
+ },
863
+ {
864
+ "type": "text",
865
+ "text": "Facial Attribute Editing. The qualitative results are shown in Figure 4. After careful comparison, we have following observations: (1) The L2M-GAN performs well at disentangling attributes during editing. However, due to the strong constrain of orthogonal loss, the manipulated attribute is not obvious. (2) Although the StyleCLIP\\* method can make the best use of semantic knowledge of CLIP-space, the irrelevant attributes are changed in facial attribute editing without correct guidance direction. (3) Our directional latent mapping network manipulates the attribute correctly and naturally, which demonstrates that the proposed semantic directional consistency (SDC) loss could enforce the editing model to change specific attributes while preserving irrelevant parts. It also proves that there exists latent directions corresponding to different semantic properties in latent space. By manipulating latent code along such direction or its opposite direction, we can add or remove attributes. ",
866
+ "bbox": [
867
+ 174,
868
+ 770,
869
+ 825,
870
+ 924
871
+ ],
872
+ "page_idx": 7
873
+ },
874
+ {
875
+ "type": "text",
876
+ "text": "Facial Attribute Transfer. Inspired by the above direction-based latent space manipulation for facial attribute transfer, we leverage this peculiarity for facial attribute transfer task. ",
877
+ "bbox": [
878
+ 173,
879
+ 103,
880
+ 823,
881
+ 132
882
+ ],
883
+ "page_idx": 8
884
+ },
885
+ {
886
+ "type": "text",
887
+ "text": "We first execute our SDD-Net on the “smile” attribute for single attribute transfer, and input the corresponding text prompt to the model. The qualitative results are shown in Figure 5. We observe that when reference has the consistent attribute appointed by the prompt, the SDD-Net could correctly transfer the specific attribute to the target face with irrelevant information preserved, as shown in the top part. On the contrary, when the reference has the opposite attribute, our SDD-Net also could transfer opposite attribute to the target without extra guidance. By fully leveraging the knowledge of CLIP-space, our SDD-Net could find the semantic-aware latent direction in the latent space. The experiments show the excellent performance of our SDD-Net. ",
888
+ "bbox": [
889
+ 174,
890
+ 138,
891
+ 825,
892
+ 251
893
+ ],
894
+ "page_idx": 8
895
+ },
896
+ {
897
+ "type": "text",
898
+ "text": "For the reference-guide image synthesis, we set the projected vector $\\vec { \\mathcal { V } _ { p } }$ is equal to the RT vector $\\vec { \\nu _ { R T } }$ . Figure 6 provides qualitative comparison of the results. We observe that StarGANv2 mothed synthesizes images with a same style code. However, the results show that StarGANv2 model manipulates images in a limited space. As a result, the attributes of the synthetic faces tend to be exactly alike. In addition, the expression attribute such as “smile” is ignored during transferring. Compared to StarGANv2, our SDD-Net transfers the multiple meaningful attributes to each of the target faces in semantic-level. Meanwhile, our method manipulates the image along the latent direction leveraging the knowledge of CLIP in latent space, which allows our method to synthesize realistic facial images, rather than simple style transfer. ",
899
+ "bbox": [
900
+ 174,
901
+ 258,
902
+ 825,
903
+ 387
904
+ ],
905
+ "page_idx": 8
906
+ },
907
+ {
908
+ "type": "text",
909
+ "text": "4.5 ABLATION STUDY ",
910
+ "text_level": 1,
911
+ "bbox": [
912
+ 176,
913
+ 409,
914
+ 339,
915
+ 422
916
+ ],
917
+ "page_idx": 8
918
+ },
919
+ {
920
+ "type": "text",
921
+ "text": "We conduct a qualitative ablation study, as shown in Figure 7, and show the significance of identity loss. We observe that, when hyperparameter $\\lambda _ { \\mathrm { I D } } = 0 . 1$ , the ID loss hinders the attribute transfer. Then we experiment with $\\lambda _ { \\mathrm { I D } } ~ = ~ 0$ , the attribute could be correctly transferred, but the identity information is changed. To trade-off, we set the $\\lambda _ { \\mathrm { I D } } = 0 . 0 2$ . ",
922
+ "bbox": [
923
+ 174,
924
+ 436,
925
+ 825,
926
+ 492
927
+ ],
928
+ "page_idx": 8
929
+ },
930
+ {
931
+ "type": "image",
932
+ "img_path": "images/a6296e98bdcc63d20c6418746537725052a3e376b135b68d3f5699b724454f5e.jpg",
933
+ "image_caption": [
934
+ "Figure 7: The ablation study of identity loss. Under each column we specify $( \\lambda _ { \\mathrm { I D } } )$ ) identity loss. Obviously the ID loss is significant for facial attribute transfer. "
935
+ ],
936
+ "image_footnote": [],
937
+ "bbox": [
938
+ 294,
939
+ 512,
940
+ 705,
941
+ 712
942
+ ],
943
+ "page_idx": 8
944
+ },
945
+ {
946
+ "type": "text",
947
+ "text": "5 CONCLUSIONS ",
948
+ "text_level": 1,
949
+ "bbox": [
950
+ 176,
951
+ 792,
952
+ 328,
953
+ 808
954
+ ],
955
+ "page_idx": 8
956
+ },
957
+ {
958
+ "type": "text",
959
+ "text": "In this paper, we first propose directional latent mapping network for text-driven facial attribute editing. By leveraging semantic direction consistency (SDC) loss, the directional latent mapping network could correctly edit relevant attribute while preserving irrelevant attributes. And on this basis, we propose semantic directional decomposition network (SDD-Net) for text-driven facial attribute transfer, which correctly transfers the semantic-aware attributes of reference image to the target image. Experiments show that our method achieves impressive performance on CelebA-HQ dataset. ",
960
+ "bbox": [
961
+ 173,
962
+ 825,
963
+ 825,
964
+ 922
965
+ ],
966
+ "page_idx": 8
967
+ },
968
+ {
969
+ "type": "text",
970
+ "text": "REFERENCES ",
971
+ "text_level": 1,
972
+ "bbox": [
973
+ 176,
974
+ 102,
975
+ 285,
976
+ 117
977
+ ],
978
+ "page_idx": 9
979
+ },
980
+ {
981
+ "type": "text",
982
+ "text": "Rameen Abdal, Yipeng Qin, and Peter Wonka. Image2stylegan: How to embed images into the stylegan latent space? In Proceedings of the IEEE/CVF International Conference on Computer Vision, pp. 4432–4441, 2019. ",
983
+ "bbox": [
984
+ 174,
985
+ 126,
986
+ 821,
987
+ 169
988
+ ],
989
+ "page_idx": 9
990
+ },
991
+ {
992
+ "type": "text",
993
+ "text": "David Bau, Hendrik Strobelt, William Peebles, Jonas Wulff, Bolei Zhou, Jun-Yan Zhu, and Antonio Torralba. Semantic photo manipulation with a generative image prior. arXiv preprint arXiv:2005.07727, 2020. ",
994
+ "bbox": [
995
+ 173,
996
+ 179,
997
+ 823,
998
+ 222
999
+ ],
1000
+ "page_idx": 9
1001
+ },
1002
+ {
1003
+ "type": "text",
1004
+ "text": "Yunjey Choi, Minje Choi, Munyoung Kim, Jung-Woo Ha, Sunghun Kim, and Jaegul Choo. Stargan: Unified generative adversarial networks for multi-domain image-to-image translation. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 8789–8797, 2018. ",
1005
+ "bbox": [
1006
+ 174,
1007
+ 232,
1008
+ 826,
1009
+ 287
1010
+ ],
1011
+ "page_idx": 9
1012
+ },
1013
+ {
1014
+ "type": "text",
1015
+ "text": "Yunjey Choi, Youngjung Uh, Jaejun Yoo, and Jung-Woo Ha. Stargan v2: Diverse image synthesis for multiple domains. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 8188–8197, 2020. ",
1016
+ "bbox": [
1017
+ 174,
1018
+ 299,
1019
+ 826,
1020
+ 342
1021
+ ],
1022
+ "page_idx": 9
1023
+ },
1024
+ {
1025
+ "type": "text",
1026
+ "text": "Jiankang Deng, Jia Guo, Niannan Xue, and Stefanos Zafeiriou. Arcface: Additive angular margin loss for deep face recognition. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 4690–4699, 2019. ",
1027
+ "bbox": [
1028
+ 173,
1029
+ 352,
1030
+ 823,
1031
+ 395
1032
+ ],
1033
+ "page_idx": 9
1034
+ },
1035
+ {
1036
+ "type": "text",
1037
+ "text": "Hui Ding, Kumar Sricharan, and Rama Chellappa. Exprgan: Facial expression editing with controllable expression intensity. In Proceedings of the AAAI Conference on Artificial Intelligence, volume 32, 2018. ",
1038
+ "bbox": [
1039
+ 174,
1040
+ 405,
1041
+ 823,
1042
+ 448
1043
+ ],
1044
+ "page_idx": 9
1045
+ },
1046
+ {
1047
+ "type": "text",
1048
+ "text": "Garoe Dorta, Sara Vicente, Neill DF Campbell, and Ivor JA Simpson. The gan that warped: Semantic attribute editing with unpaired data. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 5356–5365, 2020. ",
1049
+ "bbox": [
1050
+ 173,
1051
+ 458,
1052
+ 825,
1053
+ 502
1054
+ ],
1055
+ "page_idx": 9
1056
+ },
1057
+ {
1058
+ "type": "text",
1059
+ "text": "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. ",
1060
+ "bbox": [
1061
+ 174,
1062
+ 511,
1063
+ 825,
1064
+ 568
1065
+ ],
1066
+ "page_idx": 9
1067
+ },
1068
+ {
1069
+ "type": "text",
1070
+ "text": "Lore Goetschalckx, Alex Andonian, Aude Oliva, and Phillip Isola. Ganalyze: Toward visual definitions of cognitive image properties. In Proceedings of the IEEE/CVF International Conference on Computer Vision, pp. 5744–5753, 2019. ",
1071
+ "bbox": [
1072
+ 173,
1073
+ 578,
1074
+ 823,
1075
+ 622
1076
+ ],
1077
+ "page_idx": 9
1078
+ },
1079
+ {
1080
+ "type": "text",
1081
+ "text": "Ian Goodfellow, Jean Pouget-Abadie, Mehdi Mirza, Bing Xu, David Warde-Farley, Sherjil Ozair, Aaron Courville, and Yoshua Bengio. Generative adversarial nets. Advances in neural information processing systems, 27, 2014. ",
1082
+ "bbox": [
1083
+ 173,
1084
+ 631,
1085
+ 825,
1086
+ 675
1087
+ ],
1088
+ "page_idx": 9
1089
+ },
1090
+ {
1091
+ "type": "text",
1092
+ "text": "Erik Hark ¨ onen, Aaron Hertzmann, Jaakko Lehtinen, and Sylvain Paris. Ganspace: Discovering ¨ interpretable gan controls. arXiv preprint arXiv:2004.02546, 2020. ",
1093
+ "bbox": [
1094
+ 173,
1095
+ 685,
1096
+ 823,
1097
+ 714
1098
+ ],
1099
+ "page_idx": 9
1100
+ },
1101
+ {
1102
+ "type": "text",
1103
+ "text": "Zhenliang He, Wangmeng Zuo, Meina Kan, Shiguang Shan, and Xilin Chen. Attgan: Facial attribute editing by only changing what you want. IEEE transactions on image processing, 28(11):5464– 5478, 2019. ",
1104
+ "bbox": [
1105
+ 173,
1106
+ 723,
1107
+ 826,
1108
+ 766
1109
+ ],
1110
+ "page_idx": 9
1111
+ },
1112
+ {
1113
+ "type": "text",
1114
+ "text": "Zhenliang He, Meina Kan, Jichao Zhang, and Shiguang Shan. Pa-gan: Progressive attention generative adversarial network for facial attribute editing. arXiv preprint arXiv:2007.05892, 2020. ",
1115
+ "bbox": [
1116
+ 169,
1117
+ 776,
1118
+ 823,
1119
+ 806
1120
+ ],
1121
+ "page_idx": 9
1122
+ },
1123
+ {
1124
+ "type": "text",
1125
+ "text": "Bingwen Hu, Zhedong Zheng, Ping Liu, Wankou Yang, and Mingwu Ren. Unsupervised eyeglasses removal in the wild. IEEE Transactions on Cybernetics, 2020. ",
1126
+ "bbox": [
1127
+ 171,
1128
+ 816,
1129
+ 823,
1130
+ 845
1131
+ ],
1132
+ "page_idx": 9
1133
+ },
1134
+ {
1135
+ "type": "text",
1136
+ "text": "Ali Jahanian, Lucy Chai, and Phillip Isola. On the” steerability” of generative adversarial networks. arXiv preprint arXiv:1907.07171, 2019. ",
1137
+ "bbox": [
1138
+ 171,
1139
+ 856,
1140
+ 823,
1141
+ 885
1142
+ ],
1143
+ "page_idx": 9
1144
+ },
1145
+ {
1146
+ "type": "text",
1147
+ "text": "Tero Karras, Timo Aila, Samuli Laine, and Jaakko Lehtinen. Progressive growing of gans for improved quality, stability, and variation. arXiv preprint arXiv:1710.10196, 2017. ",
1148
+ "bbox": [
1149
+ 174,
1150
+ 895,
1151
+ 820,
1152
+ 924
1153
+ ],
1154
+ "page_idx": 9
1155
+ },
1156
+ {
1157
+ "type": "text",
1158
+ "text": "Tero Karras, Samuli Laine, and Timo Aila. A style-based generator architecture for generative adversarial networks. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 4401–4410, 2019. ",
1159
+ "bbox": [
1160
+ 176,
1161
+ 103,
1162
+ 823,
1163
+ 146
1164
+ ],
1165
+ "page_idx": 10
1166
+ },
1167
+ {
1168
+ "type": "text",
1169
+ "text": "Tero Karras, Samuli Laine, Miika Aittala, Janne Hellsten, Jaakko Lehtinen, and Timo Aila. Analyzing and improving the image quality of stylegan. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 8110–8119, 2020. ",
1170
+ "bbox": [
1171
+ 176,
1172
+ 155,
1173
+ 821,
1174
+ 198
1175
+ ],
1176
+ "page_idx": 10
1177
+ },
1178
+ {
1179
+ "type": "text",
1180
+ "text": "Jeong-gi Kwak, David K Han, and Hanseok Ko. Cafe-gan: Arbitrary face attribute editing with complementary attention feature. In Computer Vision–ECCV 2020: 16th European Conference, Glasgow, UK, August 23–28, 2020, Proceedings, Part XIV 16, pp. 524–540. Springer, 2020. ",
1181
+ "bbox": [
1182
+ 176,
1183
+ 205,
1184
+ 821,
1185
+ 248
1186
+ ],
1187
+ "page_idx": 10
1188
+ },
1189
+ {
1190
+ "type": "text",
1191
+ "text": "Christian Ledig, Lucas Theis, Ferenc Huszar, Jose Caballero, Andrew Cunningham, Alejandro ´ Acosta, Andrew Aitken, Alykhan Tejani, Johannes Totz, Zehan Wang, et al. Photo-realistic single image super-resolution using a generative adversarial network. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 4681–4690, 2017. ",
1192
+ "bbox": [
1193
+ 173,
1194
+ 256,
1195
+ 825,
1196
+ 314
1197
+ ],
1198
+ "page_idx": 10
1199
+ },
1200
+ {
1201
+ "type": "text",
1202
+ "text": "Chen-Hsuan Lin, Ersin Yumer, Oliver Wang, Eli Shechtman, and Simon Lucey. St-gan: Spatial transformer generative adversarial networks for image compositing. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pp. 9455–9464, 2018. ",
1203
+ "bbox": [
1204
+ 174,
1205
+ 321,
1206
+ 821,
1207
+ 364
1208
+ ],
1209
+ "page_idx": 10
1210
+ },
1211
+ {
1212
+ "type": "text",
1213
+ "text": "Ming Liu, Yukang Ding, Min Xia, Xiao Liu, Errui Ding, Wangmeng Zuo, and Shilei Wen. Stgan: A unified selective transfer network for arbitrary image attribute editing. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 3673–3682, 2019. ",
1214
+ "bbox": [
1215
+ 174,
1216
+ 372,
1217
+ 823,
1218
+ 416
1219
+ ],
1220
+ "page_idx": 10
1221
+ },
1222
+ {
1223
+ "type": "text",
1224
+ "text": "Ziwei Liu, Ping Luo, Xiaogang Wang, and Xiaoou Tang. Deep learning face attributes in the wild. In Proceedings of the IEEE international conference on computer vision, pp. 3730–3738, 2015. ",
1225
+ "bbox": [
1226
+ 173,
1227
+ 424,
1228
+ 821,
1229
+ 454
1230
+ ],
1231
+ "page_idx": 10
1232
+ },
1233
+ {
1234
+ "type": "text",
1235
+ "text": "Yotam Nitzan, Rinon Gal, Ofir Brenner, and Daniel Cohen-Or. Large: Latent-based regression through gan semantics. arXiv preprint arXiv:2107.11186, 2021. ",
1236
+ "bbox": [
1237
+ 174,
1238
+ 462,
1239
+ 821,
1240
+ 491
1241
+ ],
1242
+ "page_idx": 10
1243
+ },
1244
+ {
1245
+ "type": "text",
1246
+ "text": "Or Patashnik, Zongze Wu, Eli Shechtman, Daniel Cohen-Or, and Dani Lischinski. Styleclip: Textdriven manipulation of stylegan imagery. arXiv preprint arXiv:2103.17249, 2021. ",
1247
+ "bbox": [
1248
+ 173,
1249
+ 498,
1250
+ 820,
1251
+ 529
1252
+ ],
1253
+ "page_idx": 10
1254
+ },
1255
+ {
1256
+ "type": "text",
1257
+ "text": "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. arXiv preprint arXiv:2103.00020, 2021. ",
1258
+ "bbox": [
1259
+ 174,
1260
+ 536,
1261
+ 823,
1262
+ 579
1263
+ ],
1264
+ "page_idx": 10
1265
+ },
1266
+ {
1267
+ "type": "text",
1268
+ "text": "Elad Richardson, Yuval Alaluf, Or Patashnik, Yotam Nitzan, Yaniv Azar, Stav Shapiro, and Daniel Cohen-Or. Encoding in style: a stylegan encoder for image-to-image translation. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 2287–2296, 2021. ",
1269
+ "bbox": [
1270
+ 176,
1271
+ 587,
1272
+ 825,
1273
+ 631
1274
+ ],
1275
+ "page_idx": 10
1276
+ },
1277
+ {
1278
+ "type": "text",
1279
+ "text": "Yujun Shen, Jinjin Gu, Xiaoou Tang, and Bolei Zhou. Interpreting the latent space of gans for semantic face editing. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 9243–9252, 2020. ",
1280
+ "bbox": [
1281
+ 176,
1282
+ 638,
1283
+ 823,
1284
+ 681
1285
+ ],
1286
+ "page_idx": 10
1287
+ },
1288
+ {
1289
+ "type": "text",
1290
+ "text": "Omer Tov, Yuval Alaluf, Yotam Nitzan, Or Patashnik, and Daniel Cohen-Or. Designing an encoder for stylegan image manipulation. ACM Transactions on Graphics (TOG), 40(4):1–14, 2021. ",
1291
+ "bbox": [
1292
+ 168,
1293
+ 689,
1294
+ 825,
1295
+ 719
1296
+ ],
1297
+ "page_idx": 10
1298
+ },
1299
+ {
1300
+ "type": "text",
1301
+ "text": "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. ",
1302
+ "bbox": [
1303
+ 174,
1304
+ 727,
1305
+ 825,
1306
+ 770
1307
+ ],
1308
+ "page_idx": 10
1309
+ },
1310
+ {
1311
+ "type": "text",
1312
+ "text": "Zongze Wu, Dani Lischinski, and Eli Shechtman. Stylespace analysis: Disentangled controls for stylegan image generation. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 12863–12872, 2021. ",
1313
+ "bbox": [
1314
+ 176,
1315
+ 779,
1316
+ 823,
1317
+ 821
1318
+ ],
1319
+ "page_idx": 10
1320
+ },
1321
+ {
1322
+ "type": "text",
1323
+ "text": "Taihong Xiao, Jiapeng Hong, and Jinwen Ma. Elegant: Exchanging latent encodings with gan for transferring multiple face attributes. In Proceedings of the European conference on computer vision (ECCV), pp. 168–184, 2018. ",
1324
+ "bbox": [
1325
+ 174,
1326
+ 830,
1327
+ 823,
1328
+ 872
1329
+ ],
1330
+ "page_idx": 10
1331
+ },
1332
+ {
1333
+ "type": "text",
1334
+ "text": "Yinghao Xu, Yujun Shen, Jiapeng Zhu, Ceyuan Yang, and Bolei Zhou. Generative hierarchical features from synthesizing images. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 4432–4442, 2021. ",
1335
+ "bbox": [
1336
+ 176,
1337
+ 881,
1338
+ 825,
1339
+ 924
1340
+ ],
1341
+ "page_idx": 10
1342
+ },
1343
+ {
1344
+ "type": "text",
1345
+ "text": "Guoxing Yang, Nanyi Fei, Mingyu Ding, Guangzhen Liu, Zhiwu Lu, and Tao Xiang. L2m-gan: Learning to manipulate latent space semantics for facial attribute editing. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 2951–2960, 2021a. ",
1346
+ "bbox": [
1347
+ 178,
1348
+ 103,
1349
+ 823,
1350
+ 146
1351
+ ],
1352
+ "page_idx": 11
1353
+ },
1354
+ {
1355
+ "type": "text",
1356
+ "text": "Tao Yang, Peiran Ren, Xuansong Xie, and Lei Zhang. Gan prior embedded network for blind face restoration in the wild. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 672–681, 2021b. ",
1357
+ "bbox": [
1358
+ 176,
1359
+ 155,
1360
+ 821,
1361
+ 196
1362
+ ],
1363
+ "page_idx": 11
1364
+ },
1365
+ {
1366
+ "type": "text",
1367
+ "text": "Raymond A Yeh, Chen Chen, Teck Yian Lim, Alexander G Schwing, Mark Hasegawa-Johnson, and Minh N Do. Semantic image inpainting with deep generative models. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 5485–5493, 2017. ",
1368
+ "bbox": [
1369
+ 174,
1370
+ 207,
1371
+ 823,
1372
+ 250
1373
+ ],
1374
+ "page_idx": 11
1375
+ },
1376
+ {
1377
+ "type": "text",
1378
+ "text": "Weidong Yin, Ziwei Liu, and Chen Change Loy. Instance-level facial attributes transfer with geometry-aware flow. In Proceedings of the AAAI Conference on Artificial Intelligence, volume 33, pp. 9111–9118, 2019. ",
1379
+ "bbox": [
1380
+ 174,
1381
+ 257,
1382
+ 825,
1383
+ 300
1384
+ ],
1385
+ "page_idx": 11
1386
+ }
1387
+ ]
parse/dev/FPCMqjI0jXN/FPCMqjI0jXN.md ADDED
The diff for this file is too large to render. See raw diff
 
parse/dev/FPCMqjI0jXN/FPCMqjI0jXN_content_list.json ADDED
The diff for this file is too large to render. See raw diff
 
parse/dev/FPCMqjI0jXN/FPCMqjI0jXN_middle.json ADDED
The diff for this file is too large to render. See raw diff
 
parse/dev/PUIqjT4rzq7/PUIqjT4rzq7.md ADDED
@@ -0,0 +1,410 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # TRAINING-FREE STRUCTURED DIFFUSION GUIDANCE FOR COMPOSITIONAL TEXT-TO-IMAGE SYNTHESIS
2
+
3
+ Weixi Feng1, Xuehai $\mathbf { H e } ^ { 2 }$ , Tsu-jui $\mathbf { F u } ^ { 1 }$ , Varun Jampani3, Arjun Akula3, Pradyumna Narayana3, Sugato Basu3, Xin Eric Wang2, William Yang Wang1 1University of California, Santa Barbara, 2University of California, Santa Cruz, 3Google
4
+
5
+ # ABSTRACT
6
+
7
+ Large-scale diffusion models have achieved state-of-the-art results on text-to-image synthesis (T2I) tasks. Despite their ability to generate high-quality yet creative images, we observe that attribution-binding and compositional capabilities are still considered major challenging issues, especially when involving multiple objects. Attribute-binding requires the model to associate objects with the correct attribute descriptions, and compositional skills require the model to combine and generate multiple concepts into a single image. In this work, we improve these two aspects of T2I models to achieve more accurate image compositions. To do this, we incorporate linguistic structures with the diffusion guidance process based on the controllable properties of manipulating cross-attention layers in diffusion-based T2I models. We observe that keys and values in cross-attention layers have strong semantic meanings associated with object layouts and content. Therefore, by manipulating the cross-attention representations based on linguistic insights, we can better preserve the compositional semantics in the generated image. Built upon Stable Diffusion, a SOTA T2I model, our structured cross-attention design is efficient that requires no additional training samples. We achieve better compositional skills in qualitative and quantitative results, leading to a significant $5- 8 \%$ advantage in head-to-head user comparison studies. Lastly, we conduct an in-depth analysis to reveal potential causes of incorrect image compositions and justify the properties of cross-attention layers in the generation process.
8
+
9
+ # 1 INTRODUCTION
10
+
11
+ Text-to-Image Synthesis (T2I) is to generate natural and faithful images given a text prompt as input. Recently, there has been a significant advancement in the quality of generated images by extremely large-scale vision-language models, such as DALL-E 2 (Ramesh et al., 2022), Imagen (Saharia et al., 2022), and Parti (Yu et al., 2022). In particular, Stable Diffusion (Rombach et al., 2022) is the state-of-the-art open-source implementation showing superior evaluation metric gains after training over billions of text-image pairs.
12
+
13
+ In addition to generating high-fidelity images, the ability to compose multiple objects into a coherent scene is also essential. Given a text prompt from the user end, T2I models need to generate an image that contains all necessary visual concepts as mentioned in the text. Achieving such ability requires the model to understand both the full prompt and individual linguistic concepts from the prompt. As a result, the model should be able to combine multiple concepts and generate novel objects that have never been included in the training data. In this work, we mainly focus on improving the compositionality of the generation process, as it is essential to achieve controllable and generalized text-to-image synthesis with multiple objects in a complex scene.
14
+
15
+ Attribute binding is a critical compositionality challenge (Ramesh et al., 2022; Saharia et al., 2022) to existing large-scale diffusion-based models. Despite the improvements in generating multiple objects in the same scene, existing models still fail when given a prompt such as “a brown bench in front of a white building” (see Fig. 1). The output images contains “a white bench” and “a brown building” instead, potentially due to strong training set bias or imprecise language understanding. From a practical perspective, explaining and solving such a two-object binding challenge is a primary step to understanding more complex prompts with multiple objects. Therefore, how to bind the attributes to the correct objects is a fundamental problem for a more complicated and reliable compositional generation. While previous work has addressed compositional T2I (Park et al., 2021), our work tackles open-domain foreground objects with counterfactual attributes, such as color and materials.
16
+
17
+ ![](images/b61a2adf2a0c4ffb5419a27d01d3d821224796a6f7589f156e3de323e338125e.jpg)
18
+ Figure 1: Three challenging phenomena in the compositional generation. Attribute leakage: The attribute of one object is (partially) observable in another object. Interchanged attributes: the attributes of two or more objects are interchanged. Missing objects: one or more objects are missing. With slight abuse of attribute binding definitions, we aim to address all three problems in this work.
19
+
20
+ Even though state-of-the-art (SOTA) T2I models are trained on large-scale text-image datasets, they can still suffer from inaccurate results for simple prompts similar to the example above. Hence, we are motivated to seek an alternative, data-efficient method to improve the compositionality. We observe that the attribute-object relation pairs can be obtained as text spans for free from the parsing tree of the sentence. Therefore, we propose to combine the structured representations of prompts, such as a constituency tree or a scene graph, with the diffusion guidance process. Text spans only depict limited regions of the whole image. Conventionally, we need spatial information such as coordinates (Yang et al., 2022) as input to map their semantics into corresponding images. However, coordinate inputs cannot be interpreted by T2I models. Instead, we make use of the observations that attention maps provide free token-region associations in trained T2I models (Hertz et al., 2022). By modifying the key-value pairs in cross-attention layers, we manage to map the encoding of each text span into attended regions in 2D image space.
21
+
22
+ In this work, we discover similar observations in Stable Diffusion (Rombach et al., 2022) and utilize the property to build structured cross-attention guidance. Specifically, we use language parsers to obtain hierarchical structures from the prompts. We extract text spans across all levels, including visual concepts or entities, and encode them separately to disentangle the attribute-object pairs from each other. Compared to using a single sequence of text embedding for guidance, we improve the compositionality by multiple sequences where each emphasizes an entity or a union of entities from multiple hierarchies in the structured language representations. We refer to our method as Structured Diffusion Guidance (StructureDiffusion). Our contributions can be summarized as three-fold:
23
+
24
+ • We propose an intuitive and effective method to improve compositional text-to-image synthesis by utilizing structured representations of language inputs. Our method is efficient and training-free that requires no additional training samples.
25
+ • Experimental results show that our method achieves more accurate attribute binding and compositionality in the generated images. We also propose a benchmark named Attribute Binding Contrast set (ABC-6K) to measure the compositional skills of T2I models.
26
+ • We conduct extensive experiments and analysis to identify the causes of incorrect attribute binding, which points out future directions in improving the faithfulness and compositionality of text-to-image synthesis.
27
+
28
+ ![](images/09bca81db2a15f234e6b30d656ac74ab6f9b1cbc101365fd59e52c1916f786df.jpg)
29
+ Figure 2: An illustration of cross-attention operations and the token-region associations from attention maps. We omit some tokens for simplicity.
30
+
31
+ # 2 DIFFUSION MODELS & STRUCTURED GUIDANCE
32
+
33
+ In this section, we propose a simple yet effective approach incorporating structured language representations into the cross-attention layers. We briefly introduce the Stable Diffusion model and its critical components in Sec. 2.1. Then, we present our method in detail in Sec. 2.2.
34
+
35
+ # 2.1 BACKGROUND
36
+
37
+ Stable Diffusion We implement our approach and experiments on the state-of-the-art T2I model, Stable Diffusion (Rombach et al., 2022). It is a two-stage method that consists of an autoencoder and a diffusion model. The pre-trained autoencoder encodes images as lower-resolution latent maps for diffusion training. During inference, it decodes generated outputs from the diffusion model into images. The diffusion model generates lower-resolution latent maps based on a random Gaussian noise input $z ^ { T }$ . Given $z ^ { T }$ , it outputs a noise estimation $\epsilon$ at each step $t$ and subtracts it from $z ^ { t }$ . The final noise-free latent map prediction $z ^ { 0 }$ is fed into the autoencoder to generate images. Stable Diffusion adopts a modified UNet (Ronneberger et al., 2015) for noise estimation and a frozen CLIP text encoder (Radford et al., 2021) to encode text inputs as embedding sequences. The interactions between the image space and the textual embeddings are achieved through multiple cross-attention layers in both downsampling and upsampling blocks.
38
+
39
+ CLIP Text Encoder Given an input prompt $\mathcal { P }$ , the CLIP encoder encodes it as a sequence of embeddings ${ \mathcal { W } } _ { \mathrm { p } } = \mathbf { C } \mathbf { L I P } _ { \mathrm { t e x t } } ( \mathcal { P } )$ where $c _ { \mathrm { p } }$ is the embedding dimension and $l$ is the sequence length. Our key observation is that the contextualization of CLIP embeddings is a potential cause of incorrect attribute binding. Due to the causal attention masks, tokens in the later part of a sequence are blended with the token semantics before them. For example, When the user indicates some rare color for the second object (e.g. “a yellow apple and red bananas”), Stable Diffusion tends to generate “banana” in “yellow”, as the embeddings of “yellow” is attended by token “banana”.
40
+
41
+ Cross Attention Layers The cross-attention layers take the embedding sequences from the CLIP text encoder and fuse them with latent feature maps to achieve classifier-free guidance. Denote a 2D feature map $\mathcal { X } ^ { t }$ , it is projected into queries by a linear layer $f _ { Q } ( \cdot )$ and reshaped as $Q ^ { t } \in R ^ { ( n , h \times w , d ) }$ where $n$ denotes the number of attention heads, $d$ is the feature dimension. Similarly ${ \mathcal W } _ { \mathfrak p }$ is projected as keys and values $K _ { \mathfrak { p } } , V _ { \mathfrak { p } } \in R ^ { ( n , l , d ) }$ by linear layers $f _ { K } ( \cdot ) , f _ { V } ( \cdot )$ . The attention maps refer to the product between queries and keys, denoted as a function $f _ { M } ( \cdot )$
42
+
43
+ $$
44
+ M ^ { t } = f _ { M } ( Q ^ { t } , K _ { p } ) = \mathrm { S o f t m a x } ( \frac { Q ^ { t } K _ { \mathrm { p } } ^ { T } } { \sqrt { d } } ) , M ^ { t } \in R ^ { ( n , h \times w , l ) } .
45
+ $$
46
+
47
+ ![](images/a4f20aec4802f8a65ee210c0541bcc6905c7389daea131d1a009bc1e10573207.jpg)
48
+ Figure 3: An illustration of our cross-attention design with structured representations. We unflatten the query and attention maps and omit the feature dimension $d$ of all query, key, and value tensors for demonstration purposes. Note that noun phrases at multiple hierarchies are extracted and encoded through the frozen CLIP text encoder and projected to value vectors.
49
+
50
+ Cross Attention Controls Hertz et al. (2022) observes that the spatial layouts depend on the cross attention maps in Imagen Saharia et al. (2022). These maps control the layout and structure of generated images, while the values contain rich semantics mapped into attended regions. Therefore, we assume that the image layout and content can be disentangled by controlling attention maps and values separately.
51
+
52
+ # 2.2 STRUCTURED DIFFUSION GUIDANCE
53
+
54
+ Given the challenging prompts in Fig. 1, the attribute-object pairs are available for free1 in many structured representations, such as a constituency tree or a scene graph. We seek an implicit way of combining language structures with the cross-attention layers. As is shown in Fig. 3, we can extract multiple noun phrases (NPs) and map their semantics into corresponding regions. Since $M _ { t }$ provides natural token-region associations (see Fig. 2), we can apply it to multiple values from different NPs to achieve region-wise semantic guidance.
55
+
56
+ Specifically, given a parser $\xi ( \cdot )$ , we first extract a collection of concepts from all hierarchical levels as $\mathcal { C } = \{ c _ { 1 } , c _ { 2 } , \ldots , c _ { k } \}$ . For constituency parsing, we extract all NPs from the tree structure (see Fig.3 left). For the scene graphs, we extract objects and their relations with another object as text segments. We encode each NP separately:
57
+
58
+ $$
59
+ \mathbb { W } = [ \mathcal { W } _ { \mathrm { p } } , \mathcal { W } _ { 1 } , \mathcal { W } _ { 2 } , \ldots , \mathcal { W } _ { k } ] , \mathcal { W } _ { i } = \mathbf { C } \mathbf { L } \mathbf { I } \mathbf { P } _ { \mathrm { t e x t } } ( c _ { i } ) , i = 1 , \ldots k .
60
+ $$
61
+
62
+ The embedding sequence $\mathcal { W } _ { i }$ is realigned with $\mathcal { W } _ { p }$ as shown in the middle of Fig. 3. Embeddings between $\left. \mathbf { b o s } \right.$ and $\langle \mathrm { p a d } \rangle$ are inserted into $\mathcal { W } _ { p }$ to create a new sequence, denoted as $\overline { { \mathcal { W } } } _ { i }$ . We use $\overline { { \mathcal { W } } } _ { \mathrm { p } }$ to obtain $K _ { \mathfrak { p } }$ and $M ^ { t }$ as in Eq. 1, assuming that the full-prompt key is able to generate layouts without missing objects. We obtain a set of values from $\mathbb { W }$ and multiply each with ${ \bf { \bar { \boldsymbol { M } } } } ^ { t }$ to achieve a conjunction of $k$ NPs in $\mathcal { C }$ :
63
+
64
+ $$
65
+ \begin{array} { c } { \mathbb { V } = [ f _ { V } ( \mathcal { W } _ { \mathrm { p } } ) , f _ { V } ( \overline { { \mathcal { W } } } _ { 1 } ) , \ldots , f _ { V } ( \overline { { \mathcal { W } } } _ { k } ) ] = [ V _ { \mathrm { p } } , V _ { 1 } , \ldots , V _ { k } ] . } \\ { O ^ { t } = \displaystyle \frac { 1 } { ( k + 1 ) } \sum _ { i } ( M ^ { t } V _ { i } ) , i = \mathrm { p } , 1 , 2 , \ldots , k . } \end{array}
66
+ $$
67
+
68
+ Compared to using $f _ { V } ( \mathscr { W } _ { p } )$ only, Eq. 4 does not modify the image layout or composition since $M ^ { t }$ is still calculated from $Q ^ { t } , K _ { p }$ . Empirically, we justify the claim by a series of visualizations of $M _ { t }$
69
+
70
+ # Algorithm 1 StructureDiffusion Guidance.
71
+
72
+ # Require:
73
+
74
+ Input: Prompt $\mathcal { P }$ , Parser $\xi$ , decoder $\psi$ , trained diffusion model $\phi$ .
75
+ Output: Generated image $x$ .
76
+ 1: Retrieve concept set ${ \mathcal { C } } = [ c _ { 1 } , \ldots , c _ { k } ]$ by traversing $\xi ( \mathcal { P } )$ ;
77
+ 2: $\mathcal { W } _ { \mathrm { p } } \mathrm { C L I P } _ { \mathrm { t e x t } } ( \mathcal { P } ) .$ , ${ \mathcal { W } } _ { i } \gets \mathbf { C } \mathbf { L I P _ { \mathrm { t e x t } } } ( c _ { i } )$ ; $i = 1 , \ldots , k$
78
+ 3: for $t = T , T - 1 , \dots , 1$ do
79
+ 4: for each cross attention layer in $\phi$ do
80
+ 5: Obtain previous layer’s output $\mathcal { X } ^ { t }$ .
81
+ 6: $Q ^ { t } \gets \hat { f } _ { Q } ( \mathcal { X } ^ { t } ) , \ \dot { K _ { \mathrm { p } } } \gets \boldsymbol { f } _ { K } \mathsf { \bar { ( } } \mathcal { W _ { \mathrm { p } } ) } , \ V _ { i } \gets f _ { V } ( \overline { { \mathcal { W } } } _ { i } ) ;$ $\begin{array} { r } { i = { \tt p } , 1 , \ldots , k } \\ { \{ { \tt E q . ~ } 1 \} } \\ { \{ { \tt E q . ~ } 4 \} } \end{array}$
82
+ 7: Obtain attention maps $M ^ { t }$ from $Q ^ { t } , K _ { \mathrm { p } }$ ;
83
+ 8: Obtain $O ^ { t }$ from $M ^ { t }$ , $\{ V _ { i } \}$ , and feed to following layers;
84
+ 9: end for
85
+ 10: end for
86
+ 11: Feed $z ^ { 0 }$ to decoder $\psi ( \cdot )$ to generate $\mathbf { X }$ .
87
+
88
+ (see Appendix C). However, Stable Diffusion tends to omit objects in generated images (Fig. 1), especially for concept conjunctions that connect two objects with the word “and”. We devise a variant of our method that computes a set of attention maps $\ddot { \mathbb { M } } = \{ M _ { p } ^ { t } , M _ { 1 } ^ { t } , \dots \}$ from $\mathcal { C }$ and multiply them to $\mathbb { V }$ :
89
+
90
+ $$
91
+ \begin{array} { c } { { \mathbb { K } = \{ f _ { K } ( \mathcal { W } _ { i } ) \} , \mathbb { M } ^ { t } = \{ f _ { M } ( Q ^ { t } , K _ { i } ) \} , i = \mathrm { p } , 1 , 2 , \ldots , k . } } \\ { { O ^ { t } = \displaystyle \frac { 1 } { ( k + 1 ) } \sum _ { i } ( M _ { i } ^ { t } V _ { k } ) , i = \mathrm { p } , 1 , 2 , \ldots , k . } } \end{array}
92
+ $$
93
+
94
+ $O ^ { t }$ is the output of a certain cross-attention layer and the input into downstream layers to generate final image $x$ . Our algorithm can be summarized as 1, which requires no training or additional data.
95
+
96
+ # 3 EXPERIMENT
97
+
98
+ # 3.1 EXPERIMENT SETTINGS
99
+
100
+ Datasets To address attribute binding and compositional generation, we propose a new benchmark, Attribute Binding Contrast set (ABC-6K). It consists of natural prompts from MSCOCO where each contains at least two color words modifying different objects. We also switch the position of two color words to create a contrast caption (Gardner et al., 2020). We end up with $6 . 4 \mathrm { K }$ captions or 3.2K contrastive pairs. In addition to natural compositional prompts, we challenge our method with less detailed prompts that conjunct two concepts together. These prompts follow the sentence pattern of “a red apple and a yellow banana” and conjunct two objects with their attribute descriptions. We refer to this set of prompts as Concept Conjunction 500 (CC-500). We also evaluate our method on 10K randomly sampled captions from MSCOCO (Lin et al., 2014). We show that our method generalizes beyond attribute binding and introduces no quality degradation for general prompts.
101
+
102
+ Evaluation Metrics We mainly rely on human evaluations for compositional prompts and concept conjunction (ABC-6K & CC-500). We ask annotators to compare two generated images, from Stable Diffusion and our method respectively, and indicate which image demonstrates better image-text alignment or image fidelity. For image fidelity, we ask the annotators “Regardless of the text, which image is more realistic and natural?”. We also investigate an automatic evaluation metric for image compositions, i.e., using a SOTA phrase grounding model GLIP (Li et al., 2022) to match phraseobject pairs. As for system-level evaluation, we follow previous work to utilize Inception Score (IS) (Salimans et al., 2016), Frechet Inception Distance (FID) (Heusel et al., 2017) and CLIP R-precision ´ (R-prec.) (Park et al., 2021). IS and FID mainly measure the image bank’s systematic quality and diversity, while R-prec measures image-level alignment.
103
+
104
+ # 3.2 COMPOSITIONAL PROMPTS
105
+
106
+ Here we show the quantitative and qualitative evaluation results on ABC-6K. We observe that our method sometimes generates very similar images to Stable Diffusion. Hence, we first generate two images per prompt for our method and Stable Diffusion, involving around 12K image pairs to compare. Then, we filter out $20 \%$ of the most similar pairs and then randomly sampled 1500 pairs for human evaluations. As shown in Table 1, annotators indicate around a $42 \%$ chance of our method winning the comparison, $7 \%$ higher than losing the comparison. There is still a $22 \%$ of chance that our images are tied with images from Stable Diffusion.
107
+
108
+ Table 1: Percentage of generated images of StructureDiffusion that are better than (win), tied with, or worse than (lose) the compared model in terms of text-image alignment and image fidelity. We filtered out $20 \%$ most similar image pairs for comparison (See Sec. E). Composable Diffusion cannot be applied to ABC-6K as those prompts may not contain explicit “and” words that separate concepts.
109
+
110
+ <table><tr><td rowspan="2">Benchmark</td><td rowspan="2">StructureDiffusion (ours) v.s.</td><td colspan="3">Alignment</td><td colspan="3">Fidelity</td></tr><tr><td>Win (↑)</td><td>Lose (↓)</td><td>Tie</td><td>Win (↑)</td><td>Lose (↓)</td><td>Tie</td></tr><tr><td>ABC-6K</td><td>Stable Diffusion</td><td>42.2</td><td>35.6</td><td>22.2</td><td>48.3</td><td>39.1</td><td>12.6</td></tr><tr><td rowspan="2">CC-500</td><td>Stable Diffusion</td><td>31.8</td><td>27.7</td><td>38.9</td><td>37.8</td><td>30.6</td><td>31.6</td></tr><tr><td>Composable Diffusion</td><td>46.5</td><td>30.1</td><td>22.8</td><td>61.4</td><td>19.8</td><td>18.8</td></tr></table>
111
+
112
+ ![](images/cde95ccdebc9693de8c741688cd3b4fadc9ef5c3215551ed35f2b60c361cda4c.jpg)
113
+ Figure 4: Qualitative results on ABC-6K. Our method improves both object-level and scene-level compositionality.
114
+
115
+ We show qualitative examples characterizing three different perspectives in Fig. 4. Our method fills in the correct color for different parts of an object or different objects, as shown in the first two examples. The third example demonstrates that our method can mitigate the issue of “missing objects”. Among the $42 \%$ winning cases, there are $31 \%$ for “fewer missing objects”, $1 4 . 1 \%$ for “better-matched colors”, and $5 4 . 8 \%$ for “other attributes or details” as indicated by annotators. The results certify that the improvement goes beyond colors to component completeness and fine-grained details. More qualitative examples characterizing all three aspects can be found in Fig. 14 in the Appendix.
116
+
117
+ # 3.3 CONCEPT CONJUNCTION
118
+
119
+ Here we address challenging concept conjunction prompts and evaluate our method on CC-500. Apart from Stable Diffusion, we also compare to Composable Diffusion (Liu et al., 2022) implemented on top of Stable Diffusion. For Composable Diffusion, we separate the prompts into text segments by the keyword “and” and feed each span into an independent diffusion process. We generate three images per prompt and use all images for human evaluation for Stable Diffusion. We randomly sampled 600 images for comparison to Composable Diffusion.
120
+
121
+ <table><tr><td rowspan="2"></td><td colspan="6">CC-500 (Prompt format: “a [colorA] [objectA] and a [colorB] [objectB]&quot;)</td></tr><tr><td></td><td>Human Annotations</td><td></td><td>GLIP</td><td></td><td>Human-GLIP</td></tr><tr><td>Methods</td><td>Zero/One obj. ()</td><td>Two obj.</td><td>Two obj. w/ correct colors</td><td>Zero/One obj.(↓)</td><td>Two obj.</td><td>Consistency</td></tr><tr><td>Stable Diffusion</td><td>65.5</td><td>34.5</td><td>19.2</td><td>69.0</td><td>31.0</td><td>46.4</td></tr><tr><td>Composable Diffusion</td><td>69.7</td><td>30.3</td><td>20.6</td><td>74.2</td><td>25.8</td><td>48.9</td></tr><tr><td>StructureDiffusion (Ours)</td><td>62.0</td><td>38.0</td><td>22.7</td><td>68.8</td><td>31.2</td><td>47.6</td></tr></table>
122
+
123
+ Table 2: Fine-grained human and automatic evaluation results on CC-500. Recall that each prompt is a conjunction of two different objects with different colors. “Zero/One obj.” means that the model fails to generate all desired objects in the image. “Human-GLIP consistency” reflects the percentage of images where human annotations align with GLIP detection results.
124
+
125
+ ![](images/3902d5a9c111e4d4a12e67c65e27de1a9c2c07d74efa1fca4dfa19aefa3dbcb9.jpg)
126
+ Figure 5: Qualitative results on CC-500 prompts that emphasize two aspects. (a) Color leakage: our method prevents the green color from invading the bird or apple. (b) Missing objects: our method completes the “blue bowl” and improves the quality of the “blue apple”.
127
+
128
+ As shown in Table 1, our method outperforms Stable Diffusion by around $4 . 1 \%$ and Composable Diffusion by $1 6 . 4 \%$ in terms of image-text alignment. We also observe that our method enhances some fine-grained details in the generated images, leading to a $7 . 2 \%$ improvement in image fidelity when compared with Stable Diffusion. We observe that images from composable diffusion can be oversaturated with unnatural visual textures and layouts, which could be the reason for StructureDiffusion to have high win rate in image fidelity. As shown in Fig. 5 and Fig. 13. Our approach prevents color bleeding (left), missing objects (right) and strengthens details (right).
129
+
130
+ To further quantify the text-image alignment, we consider both human annotations and automatic evaluations. For each object mentioned in the prompt, we ask annotators whether the object exists in the image and whether it is in the correct color. We also apply a state-of-the-art detection model GLIP (Li et al., 2022) to ground each “a [color] [object]” phrase into bounding boxes. We report the percentage of images that contain incomplete objects / complete objects / complete objects with correct colors in Table 2. StructureDiffusion improves the compositionality by $3 . 5 \%$ based on human annotations while only $0 . 2 \%$ based on GLIP. We discover that humans disagree with GLIP for more than $50 \%$ of the images, as entailed by the low consistency rate. Previous work also suggests the deficiency of large pre-trained models in compositional understanding (Thrush et al., 2022).
131
+
132
+ # 3.4 OTHER PROMPTS
133
+
134
+ We show that our StructureDiffusion maintain the overall image quality and diversity on general prompts. We follow the standard evaluation process and generate 10,000 images from randomly
135
+
136
+ ![](images/e0cc7567ff201cd421e0f017febca9fe7cd7bc251c12c2c41f6a6f273c0b81cb.jpg)
137
+ Figure 6: Qualitative results of using scene graph parser to generate structured representations.
138
+
139
+ ![](images/7dfce557e99a420d3ccd8d1cf8e3979db4bd6ad9b3761a1fd404947bf41071bb.jpg)
140
+ Figure 7: Ablation study on the text sequence embeddings. We find that the padding embeddings are fully contextualized, representing the prompt’s high-level semantics. However, not all padding tokens are necessary to maintain a high-fidelity output from Stable Diffusion.
141
+
142
+ sampled MSCOCO captions. Stable Diffusion obtains 39.9 IS, 18.0 FID and 72.2 R-Precision. Our method achieves 40.9 IS, 17.9 FID and $7 2 . 3 \mathrm { R }$ -Precision. StructureDiffusion maintains the image fidelity and diversity as indicated in the comparable IS/FID/R-Prec scores.
143
+
144
+ # 3.5 SCENE GRAPH INPUT
145
+
146
+ We show that our method is not limited to constituency parsing but can also be extended to other structured representations, such as scene graphs. As shown in Fig. 6, we first adopt the scene graph parser (Wu et al., 2019) and obtain a graph like the ones next to each image from the input prompt. The parser returns basic entities and their relations in between. We extract text spans of basic entities with their attributes attached and text spans that include two related entities. We provide examples in Appendix 3 and make comparison to the constituency parser. Similarly, we encode these spans separately and re-align each with the entire prompt encoding sequence. On MS-COCO, the scene graph parser setting maintains the image quality with 39.2 IS, 17.9 FID, and 72.0 R-Precision. When compared to Stable Diffusion on ABC-6K, the scene graph parser achieves $3 4 . 2 \% - 3 2 . 9 \% - 3 2 . 9 \%$ Win-Lose-Tie in image-text alignment and $3 4 . 5 \% - 3 2 . 5 \% - 3 3 . 0 \%$ Win-Lose-Tie in image fidelity. As for CC-500, the scene graph parser leads to the same output images due to the same text spans. We refer to Table 3 and Fig. 12 for more results and comparison.
147
+
148
+ # 4 ABLATION STUDY
149
+
150
+ # 4.1 RE-ALIGNING SEQUENCE
151
+
152
+ In Section 2, we describe a method to realign the encoding of a text span back into the sequence of the full prompt. Since the noun-phrase text spans are shorter than the full sequence, re-alignment ensures that each token’s value vector corresponds to the correct attention map. On the other hand, naively expanding the span to the length of the full sequence degrades the image quality by ${ \sim } 2 \mathrm { I S } /$ FID (37.5 IS, 19.8 FID) compared to images with re-alignment or Stable Diffusion.
153
+
154
+ # 4.2 CONTEXTUALIZED TEXT EMBEDDINGS
155
+
156
+ One limitation brought by our StructureDiffusion is that the cross-attention computation costs increase by the number of noun phrases. Yet we noticed that most of the attention maps are computed from padding embeddings, as Stable Diffusion adopts CLIP text encoders and automatically pads the sequence to 77 tokens. We conjecture that not all padding tokens are necessary for generating high-quality images. As is shown in Fig. 7, we study four different patterns of token embeddings. We discover that leaving the nearest padding embeddings maintains a similar IS / FID score as the full sequence. Further removing this padding embedding results in apparent degradation. While only using the nearest padding embedding results in the worst image quality, we find that the high-level image layout and semantics are preserved (see bottom right of Fig. 7). This phenomenon indicates that the padding embeddings are fully contextualized with the full prompt semantics. This also justifies our re-alignment operation that preserves padding embeddings of the main sequence ${ \mathcal { W } } _ { \mathrm { f u l l } }$ .
157
+
158
+ # 5 RELATED WORK
159
+
160
+ Text-to-Image Synthesis The diffusion model is an emerging type of model that generate highquality images with a much more stable training process (Song & Ermon, 2019; Ho et al., 2020). Rombach et al. (2022) proposes to encode an image with an autoencoder and then leverage a diffusion model to generate continuous feature maps in the latent space. Stable Diffusion Rombach et al. (2022) adopts similar architecture but is trained on large-scale image-text datasets with fixed CLIP text encoder. Imagen (Saharia et al., 2022) addresses the importance of language understanding by using a frozen T5 encoder (Raffel et al., 2020), a dedicated large language model. We mainly focus on diffusion models and conduct our experiments on Stable Diffusion (Rombach et al., 2022), the SOTA open-sourced T2I model.
161
+
162
+ Compositional Generation The compositional or controllable generation has been an essential direction for T2I models to understand and disentangle basic concepts in the generation process. As text inputs are relatively weak conditions, previous work leverage layout or scene graph to enhance compositionality (Johnson et al., 2018; Hong et al., 2018; Yang et al., 2022; Gafni et al., 2022). More recently, Liu et al. (2022) proposes an approach where the concept conjunctions are achieved by adding estimated scores from a parallel set of diffusion processes. In contrast, our method can be directly merged into the cross-attention layers with much less computational overhead.
163
+
164
+ Diffusion Guidance Ho & Salimans (2022) develops classifier-free guidance where a single diffusion model is jointly trained under conditional and unconditional inputs. Most large-scale SOTA models, including autoregressive ones, adopt this technique for flexible and improved conditional synthesis results (Rombach et al., 2022; Ramesh et al., 2022; Gafni et al., 2022; Yu et al., 2022; Saharia et al., 2022). Hertz et al. (2022) discovers unique properties of cross attention maps on Imagen (Saharia et al., 2022) and achieves structure-preserving image editing by manipulating these maps. We observe similar properties in Stable Diffusion (Rombach et al., 2022) but propose a different algorithm for fine-grained, compositional text-to-image generation.
165
+
166
+ # 6 CONCLUSION
167
+
168
+ In this work, we propose a training-free method for compositional text-to-image generation. First, we observe that existing large-scale T2I diffusion models can still struggle in compositional image synthesis. We address this challenge by explicitly focusing on binding objects with the correct attributes. Second, we propose structured diffusion guidance incorporating language structures into the cross-attention layers. We propose two simple techniques to align the structured encoding with the attention maps. Using our structured guidance on Stable Diffusion, attributes can be bound more accurately while maintaining the overall image quality and diversity. In addition, we justify our approach by conducting an in-depth analysis of the frozen language encoder and attention maps. Future work may explore explicit approaches to generate plausible image layouts without missing components. We hope that our approach accelerates the development of interpretable and efficient methods for diffusion-based text-to-image models.
169
+
170
+ # ACKNOWLEDGEMENT
171
+
172
+ We would like to thank the Robert N. Noyce Trust for their generous gift to the University of California via the Noyce Initiative. The work was also partially funded by an unrestricted gift from Google and by the National Science Foundation award #2048122. The writers’ opinions and conclusions in this publication are their own and should not be construed as representing the sponsors’ official policy, expressed or inferred.
173
+
174
+ # REPRODUCIBILITY STATEMENT
175
+
176
+ We release our core codebase containing the methodology implementation, settings, benchmarks containing compositional prompts under supplementary materials.
177
+
178
+ # ETHICAL STATEMENT
179
+
180
+ As for the data collection and verification, we use the Amazon Mechanical Turk platform and form the comparison task as batches of HITs. We select workers from English-speaking countries, including the US, CA, UK, AU, and NZ, since the task require understanding the English input prompt. Each HIT takes around 15-30 seconds on average to accomplish, and we pay each submitted HIT with 0.15 US dollars, resulting in an hourly payment of 18 US dollars.
181
+
182
+ # REFERENCES
183
+
184
+ Prafulla Dhariwal and Alexander Nichol. Diffusion models beat gans on image synthesis. Advances in Neural Information Processing Systems, 34:8780–8794, 2021.
185
+
186
+ Ming Ding, Wendi Zheng, Wenyi Hong, and Jie Tang. Cogview2: Faster and better text-to-image generation via hierarchical transformers. arXiv preprint arXiv:2204.14217, 2022.
187
+
188
+ Alaaeldin El-Nouby, Shikhar Sharma, Hannes Schulz, Devon Hjelm, Layla El Asri, Samira Ebrahimi Kahou, Yoshua Bengio, and Graham W.Taylor. Tell, Draw, and Repeat: Generating and Modifying Images Based on Continual Linguistic Instruction. In ICCV, 2019.
189
+
190
+ Tsu-Jui Fu, Xin Eric Wang, Scott Grafton, Miguel Eckstein, and William Yang Wang. SSCR: Iterative Language-Based Image Editing via Self-Supervised Counterfactual Reasoning. In EMNLP, 2020.
191
+
192
+ Oran Gafni, Adam Polyak, Oron Ashual, Shelly Sheynin, Devi Parikh, and Yaniv Taigman. Make-ascene: Scene-based text-to-image generation with human priors. arXiv preprint arXiv:2203.13131, 2022.
193
+
194
+ Matt Gardner, Yoav Artzi, Victoria Basmov, Jonathan Berant, Ben Bogin, Sihao Chen, Pradeep Dasigi, Dheeru Dua, Yanai Elazar, Ananth Gottumukkala, et al. Evaluating models’ local decision boundaries via contrast sets. Findings of Empirical Methods in Natural Language Processing, 2020.
195
+
196
+ Shuyang Gu, Dong Chen, Jianmin Bao, Fang Wen, Bo Zhang, Dongdong Chen, Lu Yuan, and Baining Guo. Vector quantized diffusion model for text-to-image synthesis. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 10696–10706, 2022a.
197
+
198
+ Shuyang Gu, Dong Chen, Jianmin Bao, Fang Wen, Bo Zhang, Dongdong Chen, Lu Yuan, and Baining Guo. Vector quantized diffusion model for text-to-image synthesis. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 10696–10706, 2022b.
199
+
200
+ Amir Hertz, Ron Mokady, Jay Tenenbaum, Kfir Aberman, Yael Pritch, and Daniel Cohen-Or. Promptto-prompt image editing with cross attention control. arXiv preprint arXiv:2208.01626, 2022.
201
+
202
+ Martin Heusel, Hubert Ramsauer, Thomas Unterthiner, Bernhard Nessler, and Sepp Hochreiter. Gans trained by a two time-scale update rule converge to a local nash equilibrium. Advances in neural information processing systems, 30, 2017.
203
+
204
+ Jonathan Ho and Tim Salimans. Classifier-free diffusion guidance. arXiv preprint arXiv:2207.12598, 2022.
205
+
206
+ Jonathan Ho, Ajay Jain, and Pieter Abbeel. Denoising diffusion probabilistic models. Advances in Neural Information Processing Systems, 33:6840–6851, 2020.
207
+
208
+ Seunghoon Hong, Dingdong Yang, Jongwook Choi, and Honglak Lee. Inferring semantic layout for hierarchical text-to-image synthesis. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 7986–7994, 2018.
209
+
210
+ Justin Johnson, Agrim Gupta, and Li Fei-Fei. Image generation from scene graphs. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 1219–1228, 2018.
211
+
212
+ Doyup Lee, Chiheon Kim, Saehoon Kim, Minsu Cho, and Wook-Shin Han. Autoregressive image generation using residual quantization. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 11523–11532, 2022.
213
+
214
+ Bowen Li, Xiaojuan Qi, Thomas Lukasiewicz, and Philip Torr. Controllable text-to-image generation. Advances in Neural Information Processing Systems, 32, 2019.
215
+
216
+ Liunian Harold Li, Pengchuan Zhang, Haotian Zhang, Jianwei Yang, Chunyuan Li, Yiwu Zhong, Lijuan Wang, Lu Yuan, Lei Zhang, Jenq-Neng Hwang, et al. Grounded language-image pre-training. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 10965–10975, 2022.
217
+
218
+ 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.
219
+
220
+ Luping Liu, Yi Ren, Zhijie Lin, and Zhou Zhao. Pseudo numerical methods for diffusion models on manifolds. In International Conference on Learning Representations, 2021a.
221
+
222
+ Nan Liu, Shuang Li, Yilun Du, Antonio Torralba, and Joshua B Tenenbaum. Compositional visual generation with composable diffusion models. arXiv preprint arXiv:2206.01714, 2022.
223
+
224
+ Xihui Liu, Dong Huk Park, Samaneh Azadi, Gong Zhang, Arman Chopikyan, Yuxiao Hu, Humphrey Shi, Anna Rohrbach, and Trevor Darrell. More control for free! image synthesis with semantic diffusion guidance. arXiv preprint arXiv:2112.05744, 2021b.
225
+
226
+ Chao Lou, Wenjuan Han, Yuhuan Lin, and Zilong Zheng. Unsupervised vision-language parsing: Seamlessly bridging visual scene graphs with language structures via dependency relationships. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), pp. 15607–15616, June 2022.
227
+
228
+ Alex Nichol, Prafulla Dhariwal, Aditya Ramesh, Pranav Shyam, Pamela Mishkin, Bob McGrew, Ilya Sutskever, and Mark Chen. Glide: Towards photorealistic image generation and editing with text-guided diffusion models. ICML, 2021.
229
+
230
+ Dong Huk Park, Samaneh Azadi, Xihui Liu, Trevor Darrell, and Anna Rohrbach. Benchmark for compositional text-to-image synthesis. In Thirty-fifth Conference on Neural Information Processing Systems Datasets and Benchmarks Track (Round 1), 2021.
231
+
232
+ Peng Qi, Yuhao Zhang, Yuhui Zhang, Jason Bolton, and Christopher D. Manning. Stanza: A Python natural language processing toolkit for many human languages. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics: System Demonstrations, 2020.
233
+
234
+ 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.
235
+
236
+ Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, and Peter J. Liu. Exploring the limits of transfer learning with a unified text-to-text transformer. Journal of Machine Learning Research, 21(140):1–67, 2020. URL http://jmlr.org/papers/v21/20-074.html.
237
+
238
+ Aditya Ramesh, Mikhail Pavlov, Gabriel Goh, Scott Gray, Chelsea Voss, Alec Radford, Mark Chen, and Ilya Sutskever. Zero-shot text-to-image generation. In International Conference on Machine Learning, pp. 8821–8831. PMLR, 2021.
239
+
240
+ Aditya Ramesh, Prafulla Dhariwal, Alex Nichol, Casey Chu, and Mark Chen. Hierarchical textconditional image generation with clip latents. arXiv preprint arXiv:2204.06125, 2022.
241
+
242
+ Robin Rombach, Andreas Blattmann, Dominik Lorenz, Patrick Esser, and Bjorn Ommer. High- ¨ resolution image synthesis with latent diffusion models. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 10684–10695, 2022.
243
+
244
+ Olaf Ronneberger, Philipp Fischer, and Thomas Brox. U-net: Convolutional networks for biomedical image segmentation. In International Conference on Medical image computing and computerassisted intervention, pp. 234–241. Springer, 2015.
245
+
246
+ Nataniel Ruiz, Yuanzhen Li, Varun Jampani, Yael Pritch, Michael Rubinstein, and Kfir Aberman. Dreambooth: Fine tuning text-to-image diffusion models for subject-driven generation. arXiv preprint arXiv:2208.12242, 2022.
247
+
248
+ 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, et al. Photorealistic text-to-image diffusion models with deep language understanding. arXiv preprint arXiv:2205.11487, 2022.
249
+
250
+ Tim Salimans, Ian Goodfellow, Wojciech Zaremba, Vicki Cheung, Alec Radford, and Xi Chen. Improved techniques for training gans. Advances in neural information processing systems, 29, 2016.
251
+
252
+ Sebastian Schuster, Ranjay Krishna, Angel Chang, Li Fei-Fei, and Christopher D Manning. Generating semantically precise scene graphs from textual descriptions for improved image retrieval. In Proceedings of the fourth workshop on vision and language, pp. 70–80, 2015.
253
+
254
+ Yang Song and Stefano Ermon. Generative modeling by estimating gradients of the data distribution. Advances in Neural Information Processing Systems, 32, 2019.
255
+
256
+ Ming Tao, Hao Tang, Fei Wu, Xiao-Yuan Jing, Bing-Kun Bao, and Changsheng Xu. Df-gan: A simple and effective baseline for text-to-image synthesis. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 16515–16525, 2022.
257
+
258
+ Tristan Thrush, Ryan Jiang, Max Bartolo, Amanpreet Singh, Adina Williams, Douwe Kiela, and Candace Ross. Winoground: Probing vision and language models for visio-linguistic compositionality. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 5238–5248, 2022.
259
+
260
+ Bo Wan, Wenjuan Han, Zilong Zheng, and Tinne Tuytelaars. Unsupervised vision-language grammar induction with shared structure modeling. In International Conference on Learning Representations, 2021.
261
+
262
+ Hao Wu, Jiayuan Mao, Yufeng Zhang, Yuning Jiang, Lei Li, Weiwei Sun, and Wei-Ying Ma. Unified visual-semantic embeddings: Bridging vision and language with structured meaning representations. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 6609–6618, 2019.
263
+
264
+ Zuopeng Yang, Daqing Liu, Chaoyue Wang, Jie Yang, and Dacheng Tao. Modeling image composition for complex scene generation. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 7764–7773, 2022.
265
+
266
+ Jiahui Yu, Yuanzhong Xu, Jing Yu Koh, Thang Luong, Gunjan Baid, Zirui Wang, Vijay Vasudevan, Alexander Ku, Yinfei Yang, Burcu Karagol Ayan, et al. Scaling autoregressive models for contentrich text-to-image generation. arXiv preprint arXiv:2206.10789, 2022.
267
+
268
+ Han Zhang, Jing Yu Koh, Jason Baldridge, Honglak Lee, and Yinfei Yang. Cross-modal contrastive learning for text-to-image generation. In Proceedings of the IEEE/CVF conference on computer vision and pattern recognition, pp. 833–842, 2021.
269
+
270
+ Yiwu Zhong, Liwei Wang, Jianshu Chen, Dong Yu, and Yin Li. Comprehensive image captioning via scene graph decomposition. In European Conference on Computer Vision, pp. 211–229. Springer, 2020.
271
+
272
+ Yufan Zhou, Ruiyi Zhang, Changyou Chen, Chunyuan Li, Chris Tensmeyer, Tong Yu, Jiuxiang Gu, Jinhui Xu, and Tong Sun. Towards language-free training for text-to-image generation. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 17907–17917, 2022.
273
+
274
+ Minfeng Zhu, Pingbo Pan, Wei Chen, and Yi Yang. Dm-gan: Dynamic memory generative adversarial networks for text-to-image synthesis. In Proceedings of the IEEE/CVF conference on computer vision and pattern recognition, pp. 5802–5810, 2019.
275
+
276
+ # A RELATED WORK
277
+
278
+ Text-to-Image Synthesis There are mainly three types of models for text-to-image synthesis: GAN-based (Tao et al., 2022; Zhu et al., 2019; Li et al., 2019; Fu et al., 2020; El-Nouby et al., 2019), autoregressive (Gu et al., 2022b; Lee et al., 2022; Ding et al., 2022) and diffusion models (Liu et al., 2021b; Nichol et al., 2021; Ruiz et al., 2022). Zhang et al. (2021) proposes XMC-GAN, a one-stage GAN that employs multiple contrastive losses between image-image, image-text, and region-token pairs. More recently, LAFITE (Zhou et al., 2022) enables language-free training by constructing pseudo image-text feature pairs using CLIP (Radford et al., 2021). As for autoregressive models, DALL-E adopts VQ-VAE to quantize image patches into tokens and then uses a transformer to generate discrete tokens sequentially (Ramesh et al., 2021). Parti (Yu et al., 2022) and Make-A-Scene (Gafni et al., 2022) both leverage classifier-free guidance to improve controllability. As for diffusion models, Gu et al. (2022a) concatenates VQ-VAE with the diffusion model and shows that the diffusion process can operate in discrete latent space. DALL-E 2 adopts the CLIP text encoder so that the diffusion process inverts the textual features into images (Ramesh et al., 2022).
279
+
280
+ Structured Representations for Vision and Language Inferring shared structures across language and vision has been a long-term pursuit in unifying these modalities (Schuster et al., 2015; Johnson et al., 2018; Zhong et al., 2020; Lou et al., 2022). Wu et al. (2019) utilizes the structure from semantic parsing in a visual-semantic embedding framework to facilitate embedding learning. Wan et al. (2021) proposes a new task in which the goal is to learn a joint structure between semantic parsing and image regions. To the best of our knowledge, our work is the first attempt in T2I to incorporate language structures into the image synthesizing process.
281
+
282
+ Diffusion Guidance To convert an unconditional diffusion model into a class-conditional one, Dhariwal & Nichol (2021) input the noisy image from each step into a classifier and calculate the classification loss. The loss can be back-propagated to the image space to provide a gradient that marginalizes the score estimation from the log of conditional probability. Similarly, in the T2I subdomain, Liu et al. (2021b) and Nichol et al. (2021) apply a noisy CLIP model to measure the cosine similarity between text prompts and noisy images.
283
+
284
+ # B IMPLEMENTATION DETAILS
285
+
286
+ Throughout the experiments, we implement our method upon Stable Diffusion v1.4. For all comparisons between our method and Stable Diffusion, we fix the seed to generate the same initial Gaussian map and use 50 diffusion steps with PLMS sampling (Liu et al., 2021a). We fix the guidance scale to 7.5 and equally weight the key-value matrices in cross-attention layers if not otherwise specified. We do not add hand-crafted prompts such as “a photo of” to the text input. We use the Stanza Library (Qi et al., 2020) for constituency parsing and obtain noun phrases if not otherwise specified.
287
+
288
+ # C VISUALIZATION OF ATTENTION MAPS
289
+
290
+ In this section, we demonstrate the visualization of cross-attention maps to support our assumptions and claims in Sec. 2. As is shown in Fig. 8, the attention maps of Stable Diffusion and our method have similar spatial distribution and highlights throughout the diffusion process. This phenomenon supports our assumption in Sec. 2.2 that the attention map $M _ { t }$ is unchanged even with multiple values in each cross-attention layer. We can observe a similar phenomenon in Fig. 9 except that our method accelerates the formation of interpretable attentions for both “green” and “clock” tokens.
291
+
292
+ ![](images/e22e2d5e7ace9b5fbcfe4a7cc12e67be8180444f5dc3271034867469bdbfde5a.jpg)
293
+ Figure 8: Visualization of cross attention maps of Stable Diffusion and our method. We compare maps of multiple tokens throughout the whole diffusion process with equal intervals.
294
+
295
+ Fig. 8, 9 also justify our claim that values represent rich textual semantics mapped to the image space as contents. For instance, our method parses the prompt in Fig. 8 into “A long narrow yellow kitchen” and “black and white floor tiles”, encodes and aligns them separately to form V. Empirically, these operations enhance the semantics of “yellow” and “black and white” separately and mitigate “yellow” being blended into “black and white”. This explains the disappearance of color leakage in our image compared to Stable Diffusion. Though one may attribute the leakage to incorrect attention distribution of the “yellow” token, we argue that this is not the critical reason. Despite the attention maps of “yellow” from our method slightly highlighting the “floor tile” regions, we cannot observe any yellow in our generated image. This proves that inaccurate attention distributions contribute little to the final image content. In addition, we also show in Fig. 10 that using multiple Keys is able to rectify the image layouts to mitigate missing object issues. The sheep-like attention maps in the third row verify the proposed variants of our method for concept conjunctions.
296
+
297
+ ![](images/0be7b80d0f76ab47ff37221209affb8a234d6aaf76276fa61011c736050abb18.jpg)
298
+ Figure 9: Visualization of cross attention maps corresponding to token “green” and “clock” across the full diffusion timestamps from step 50 to step 1 in equal intervals. Red boxes highlight steps where our method accelerates the formation of correct attention on the clock region. The evolution of the token “green” is also more interpretable in our method. Although the image composition is imperfect, the visualization still supports our assumptions and claims in Sec. 2.2.
299
+
300
+ ![](images/6ce94909eda492a7e78221376ea5b39def302a7a1f5a92084ca40943ea3a1fda.jpg)
301
+ Figure 10: Visualization of attention maps for token “sheep” of different methods. Our method with multiple Keys successfully rectify image layouts.
302
+
303
+ # D ABLATION STUDY
304
+
305
+ # D.1 A CASE STUDY OF ATTRIBUTE BINDING
306
+
307
+ Here, we present a case study to show evidence of two root causes of incorrect attribute binding. The first one is the contextualized token embeddings due to causal attention masks. As is shown on the left side of Fig. 11, we first encode two different prompts with a shared component, e.g. “a red apple” as the naive one and “a green bag and a red apple”. Using the encoding sequence of the naive prompt, we are able to get an image of red apple only. It is reasonable to assume that the yellow green regions are natural results of learning from authentic apple images. Then, we replace the tokens of the naive prompt with embeddings of the same token from the more complicated prompt. We use the same gaussian noise as initialization and generate an unnatural image with a solid green region (in the yellow bounding box). This result proves that the token “red” is contaminated with the semantics of “green” before it and explains some images with color leakage problems (e.g., Fig. 1).
308
+
309
+ ![](images/3523608906863534f4a3e158ef3281942b6bb6822477164e5d40472b91acf880.jpg)
310
+ Figure 11: Examples showing the potential root causes of incorrect attribute binding. Left: The large green regions in the second image prove that the hidden state’s output of token “red” is contextualized with token “green” before it. Right: Visualization of attention maps showing that the semantics from the token “bird” is mistakenly attended to the mouth region of the bear. The final image shows the unnatural beak-like shape of the bear.
311
+
312
+ The second reason attributes to inaccurate attention maps. In Fig. 11 (right), we visualize five crossattention maps (averaged across attention heads) from both downsample and upsampling blocks. The attention maps show the salient regions corresponding to the token “bird”. These maps demonstrate highlighted regions in the bottom left corner where the bird is located in the final image. Despite the interpretable structures, the maps also show saliency around the mouth region of the bear across all five layers. Thus, the inaccurate attention maps lead to a beak-like mouth of the bear in the image.
313
+
314
+ # D.2 COMPARISON OF PARSERS
315
+
316
+ In this subsection, we compare the difference between using a constituency parser and a scene graph parser to obtain text spans and generate images. Table 3 compares the extracted text spans using constituency parser and scene graph parser. Example 0 shows that both parsers end up with the same results for CC-500 prompts. For Example 1-4, the scene graph parser generates more spans than the constituency parser. We notice that concepts in the middle of the sentence appear more often in these spans than other noun tokens, like “egg” or “red sauce” in Example 3. This imbalance potentially explains why the “egg” looks more highlighted in Fig. 12 (bottom left). On the other hand, “orange slices” appear more often in constituency parsing results, leading to better “orange” textures in the generated image. Similar observations can be made in Example 2, where “green pole” is emphasized more often by the constituency parser.
317
+
318
+ # E LIMITATIONS & FUTURE WORK
319
+
320
+ There are several limitations of our work. First of all, our method depends on an external parsing function that may not be perfect. We adopt the commonly used Stanza Library Qi et al. (2020) for constituency parsing. The parsing function can be replaced with a more advanced learning-based method for improvement. Secondly, our method mainly focuses on compositional T2I neglecting any style descriptions. The parsing mechanism may categorize a style description, e.g. “in Van Gogh style” as a separate noun phrase that cannot be grounded in the image space. In addition, we discover that StructureDiffusion tends to generate similar images as Stable Diffusion. Thus we filtered out $20 \%$ of most similar image pairs in Table 1, considering the efficiency of human evaluation. Therefore, the improvement could be compromised when evaluated on the full set of generated images. Future work may focus on devising explicit methods to associate attributes to objects using spatial information as input. For example, how to make a text-to-image synthesis model interpret coordinate information with limited fine-tuning or prompt tuning steps would be an appealing direction.
321
+
322
+ Table 3: Comparison between the constituency parser and scene graph parser. For CC-500 prompts, both parsers end up with the same results. As for general prompts, scene graph parser tends to generate more text spans with middle concepts appearing multiple times across different spans.
323
+
324
+ <table><tr><td rowspan=1 colspan=1></td><td rowspan=1 colspan=1>Constituency Parser</td><td rowspan=1 colspan=1>Scene Graph Parser</td></tr><tr><td rowspan=2 colspan=1>Example 0</td><td rowspan=1 colspan=2>CC-500 Prompt: A white sheep and a red car</td></tr><tr><td rowspan=1 colspan=1>“A white sheep”,“a red car”</td><td rowspan=1 colspan=1>“A white sheep”,“a red car”</td></tr><tr><td rowspan=2 colspan=1>Example 1</td><td rowspan=1 colspan=2>Prompt: A silver car with a black cat sleeping on top of it</td></tr><tr><td rowspan=1 colspan=1>“A silver car”,“a black cat”,“A silver car with a black cat”</td><td rowspan=1 colspan=1>“A silver car”,&quot;a black cat”,“top of it”,“a black cat sleeping on top of it&quot;</td></tr><tr><td rowspan=2 colspan=1>Example 2</td><td rowspan=1 colspan=2>Prompt:A horse running in a white field next to a black and green pole</td></tr><tr><td rowspan=1 colspan=1>“Ahorse”,“a white feld&quot;,“a black and green pole&quot;,“a white field next to a black and green pole”</td><td rowspan=1 colspan=1>“Ahorse”,“a white field”,“a black and green pole”,“A horse running in a white field&quot;</td></tr><tr><td rowspan=2 colspan=1>Example 3</td><td rowspan=1 colspan=2>Prompt:Rice with red sauce with eggs over the top and orange slices on the side</td></tr><tr><td rowspan=1 colspan=1>“red sauce”,“the side”,“the top and orange slices”,“the top and orange slices on the side&quot;</td><td rowspan=1 colspan=1>“red sauce”,“the side”,“the top and orange slices”,“Rice with red sauce”,“red sauce with eggs”,“the top and orange slices on the side&quot;,“red sauce with eggs over the top and orange slices”</td></tr><tr><td rowspan=2 colspan=1>Example 4</td><td rowspan=1 colspan=2>Prompt:A pink scooter with a black seat next to a blue car</td></tr><tr><td rowspan=1 colspan=1>“A pink scooter”,“a black seat”,“a blue car”</td><td rowspan=1 colspan=1>“A pink scooter”,“a black seat”,“a blue car”,&quot;a pink scooter with a black seat&quot;,“a black seat next to a blue car”</td></tr></table>
325
+
326
+ ![](images/5505e9c9fabb63da9b36d9e776d538f607231efc48fb6c2f6bc627e1951a2d11.jpg)
327
+ Figure 12: Synthesized images corresponding to prompts in Table 3. Yellow boxes annotate compositions that are improved using different parsers.
328
+
329
+ ![](images/9a323a017b67c428078490d9067e77f606d8f54878028c43b59103d5e505fc9b.jpg)
330
+ Figure 13: Qualitative results on CC-500
331
+
332
+ # Stable Diffusion
333
+
334
+ # Ours
335
+
336
+ # Stable Diffusion
337
+
338
+ # Ours
339
+
340
+ # Stable Diffusion
341
+
342
+ # Ours
343
+
344
+ a purple cat with a orange hat on its head
345
+
346
+ A red cat sits on a rug with a black cord
347
+
348
+ A yellow cat is wearing a blue plastic baseball hat.
349
+
350
+ ![](images/660bc275b91b59866cd20e3a88baefb5a552b3ad21116d920fca9476c0987944.jpg)
351
+
352
+ ![](images/44f8df4e6174cfaee77c876deda6de6350198075800255d17326b31cbf9a0166.jpg)
353
+
354
+ ![](images/26a9991969c15534788eae2f5acc0d8cda40c915d13508aea40a64234a837dfe.jpg)
355
+ A red helmet is on a yellow toilet in the dirt
356
+
357
+ A red stop sign above a white walk across road sign
358
+
359
+ Two elephants walking by a green wall with tan palm trees painted on it
360
+
361
+ ![](images/cfd38b6e692be180d8d214269d4b921af9c6ea51e92262d22844436ebebe2b8b.jpg)
362
+
363
+ ![](images/408e26c582eccff899a6069e2265d99daf61980c8cc47f66c6c8328d8054ffd6.jpg)
364
+
365
+ ![](images/7c5f1e143277e8913a928bce5fd0f6aacb27ceb05fed39986d71058a5a715923.jpg)
366
+
367
+ # A bathroom with red tile and a green shower curtain
368
+
369
+ A spacious kitchen has white walls , red countertops , and a large stove
370
+
371
+ A large white bed sitting in a hotel room next to a red couch
372
+
373
+ ![](images/4a43f884cd58a3781a856b40d946e06aa95a3781630c49ecd2683d6082a67e4e.jpg)
374
+
375
+ ![](images/91f6e969166829de16eb4f631fbb73f19ef0d5390410d037d4a690f99df02786.jpg)
376
+
377
+ ![](images/c40deaf2eb3b4751d7c5816cee4083bcc77c9b78e322402b3ca26513daf3706d.jpg)
378
+
379
+ A pink towel stands out greatly in the white bathroom
380
+
381
+ ![](images/bacd240485e26a532174d993863ebd922208a129b432bdb6bcd36b94119a092b.jpg)
382
+ A white toilet bowl with a purple rug in front
383
+
384
+ # A large pizza on a white plate sitting on a blue table
385
+
386
+ ![](images/fc3d8bd9df11cad37a11762b0e2c5fd1165c80053f07eca502b775632458b10e.jpg)
387
+
388
+ ![](images/48b52b815f2fadf7e93602f86d613241414c34c280fa91397edfec9c1c36a9c5.jpg)
389
+
390
+ A spoon and bowl of red pea soup and green beans with onions
391
+
392
+ A cow standing outside of a white building with a blue entrance
393
+
394
+ A black and white curtain
395
+ hanging in a room that is
396
+ decorated in black, white and
397
+ red
398
+
399
+ ![](images/b7fd1fb2b097479ee0c8daa0225ada709939a000e386f9227ee3d53632006091.jpg)
400
+
401
+ ![](images/6fd1de4853b4e135bbd29c014613e0ba1aebc6158a4201d581f5433d4629e15d.jpg)
402
+
403
+ ![](images/d5d8e5dbed72e828a9bba99342c7933385ffcda9b12e7d2758d88218380089c8.jpg)
404
+ Figure 14: Qualitative results on ABC-6K
405
+
406
+ ![](images/cfdda3c5e52b24145788d8db72809206b16643bae64a24cf322cb9114b08223e.jpg)
407
+ Figure 15: Qualitative results characterizing attributes beyond colors, including shape, size and materials.
408
+
409
+ ![](images/228590b790dbd98fc2e4f38e8af5d5b6c518ba667976fe594af7a5e67dfcd7e5.jpg)
410
+ Figure 16: A prompt “an astronaut riding a horse” appended with different (combinations of) style descriptions. Our method has no negative effects on the image style. “base” refers to Stable Diffusion.
parse/dev/PUIqjT4rzq7/PUIqjT4rzq7_content_list.json ADDED
@@ -0,0 +1,2214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "type": "text",
4
+ "text": "TRAINING-FREE STRUCTURED DIFFUSION GUIDANCE FOR COMPOSITIONAL TEXT-TO-IMAGE SYNTHESIS ",
5
+ "text_level": 1,
6
+ "bbox": [
7
+ 174,
8
+ 98,
9
+ 820,
10
+ 146
11
+ ],
12
+ "page_idx": 0
13
+ },
14
+ {
15
+ "type": "text",
16
+ "text": "Weixi Feng1, Xuehai $\\mathbf { H e } ^ { 2 }$ , Tsu-jui $\\mathbf { F u } ^ { 1 }$ , Varun Jampani3, Arjun Akula3, Pradyumna Narayana3, Sugato Basu3, Xin Eric Wang2, William Yang Wang1 1University of California, Santa Barbara, 2University of California, Santa Cruz, 3Google ",
17
+ "bbox": [
18
+ 184,
19
+ 169,
20
+ 764,
21
+ 213
22
+ ],
23
+ "page_idx": 0
24
+ },
25
+ {
26
+ "type": "text",
27
+ "text": "ABSTRACT ",
28
+ "text_level": 1,
29
+ "bbox": [
30
+ 454,
31
+ 250,
32
+ 544,
33
+ 265
34
+ ],
35
+ "page_idx": 0
36
+ },
37
+ {
38
+ "type": "text",
39
+ "text": "Large-scale diffusion models have achieved state-of-the-art results on text-to-image synthesis (T2I) tasks. Despite their ability to generate high-quality yet creative images, we observe that attribution-binding and compositional capabilities are still considered major challenging issues, especially when involving multiple objects. Attribute-binding requires the model to associate objects with the correct attribute descriptions, and compositional skills require the model to combine and generate multiple concepts into a single image. In this work, we improve these two aspects of T2I models to achieve more accurate image compositions. To do this, we incorporate linguistic structures with the diffusion guidance process based on the controllable properties of manipulating cross-attention layers in diffusion-based T2I models. We observe that keys and values in cross-attention layers have strong semantic meanings associated with object layouts and content. Therefore, by manipulating the cross-attention representations based on linguistic insights, we can better preserve the compositional semantics in the generated image. Built upon Stable Diffusion, a SOTA T2I model, our structured cross-attention design is efficient that requires no additional training samples. We achieve better compositional skills in qualitative and quantitative results, leading to a significant $5- 8 \\%$ advantage in head-to-head user comparison studies. Lastly, we conduct an in-depth analysis to reveal potential causes of incorrect image compositions and justify the properties of cross-attention layers in the generation process. ",
40
+ "bbox": [
41
+ 233,
42
+ 281,
43
+ 766,
44
+ 559
45
+ ],
46
+ "page_idx": 0
47
+ },
48
+ {
49
+ "type": "text",
50
+ "text": "1 INTRODUCTION ",
51
+ "text_level": 1,
52
+ "bbox": [
53
+ 176,
54
+ 585,
55
+ 336,
56
+ 602
57
+ ],
58
+ "page_idx": 0
59
+ },
60
+ {
61
+ "type": "text",
62
+ "text": "Text-to-Image Synthesis (T2I) is to generate natural and faithful images given a text prompt as input. Recently, there has been a significant advancement in the quality of generated images by extremely large-scale vision-language models, such as DALL-E 2 (Ramesh et al., 2022), Imagen (Saharia et al., 2022), and Parti (Yu et al., 2022). In particular, Stable Diffusion (Rombach et al., 2022) is the state-of-the-art open-source implementation showing superior evaluation metric gains after training over billions of text-image pairs. ",
63
+ "bbox": [
64
+ 174,
65
+ 617,
66
+ 825,
67
+ 700
68
+ ],
69
+ "page_idx": 0
70
+ },
71
+ {
72
+ "type": "text",
73
+ "text": "In addition to generating high-fidelity images, the ability to compose multiple objects into a coherent scene is also essential. Given a text prompt from the user end, T2I models need to generate an image that contains all necessary visual concepts as mentioned in the text. Achieving such ability requires the model to understand both the full prompt and individual linguistic concepts from the prompt. As a result, the model should be able to combine multiple concepts and generate novel objects that have never been included in the training data. In this work, we mainly focus on improving the compositionality of the generation process, as it is essential to achieve controllable and generalized text-to-image synthesis with multiple objects in a complex scene. ",
74
+ "bbox": [
75
+ 174,
76
+ 708,
77
+ 825,
78
+ 819
79
+ ],
80
+ "page_idx": 0
81
+ },
82
+ {
83
+ "type": "text",
84
+ "text": "Attribute binding is a critical compositionality challenge (Ramesh et al., 2022; Saharia et al., 2022) to existing large-scale diffusion-based models. Despite the improvements in generating multiple objects in the same scene, existing models still fail when given a prompt such as “a brown bench in front of a white building” (see Fig. 1). The output images contains “a white bench” and “a brown building” instead, potentially due to strong training set bias or imprecise language understanding. From a practical perspective, explaining and solving such a two-object binding challenge is a primary step to understanding more complex prompts with multiple objects. Therefore, how to bind the attributes to the correct objects is a fundamental problem for a more complicated and reliable compositional generation. While previous work has addressed compositional T2I (Park et al., 2021), our work tackles open-domain foreground objects with counterfactual attributes, such as color and materials. ",
85
+ "bbox": [
86
+ 174,
87
+ 827,
88
+ 825,
89
+ 924
90
+ ],
91
+ "page_idx": 0
92
+ },
93
+ {
94
+ "type": "image",
95
+ "img_path": "images/b61a2adf2a0c4ffb5419a27d01d3d821224796a6f7589f156e3de323e338125e.jpg",
96
+ "image_caption": [
97
+ "Figure 1: Three challenging phenomena in the compositional generation. Attribute leakage: The attribute of one object is (partially) observable in another object. Interchanged attributes: the attributes of two or more objects are interchanged. Missing objects: one or more objects are missing. With slight abuse of attribute binding definitions, we aim to address all three problems in this work. "
98
+ ],
99
+ "image_footnote": [],
100
+ "bbox": [
101
+ 210,
102
+ 103,
103
+ 782,
104
+ 335
105
+ ],
106
+ "page_idx": 1
107
+ },
108
+ {
109
+ "type": "text",
110
+ "text": "",
111
+ "bbox": [
112
+ 174,
113
+ 434,
114
+ 825,
115
+ 476
116
+ ],
117
+ "page_idx": 1
118
+ },
119
+ {
120
+ "type": "text",
121
+ "text": "Even though state-of-the-art (SOTA) T2I models are trained on large-scale text-image datasets, they can still suffer from inaccurate results for simple prompts similar to the example above. Hence, we are motivated to seek an alternative, data-efficient method to improve the compositionality. We observe that the attribute-object relation pairs can be obtained as text spans for free from the parsing tree of the sentence. Therefore, we propose to combine the structured representations of prompts, such as a constituency tree or a scene graph, with the diffusion guidance process. Text spans only depict limited regions of the whole image. Conventionally, we need spatial information such as coordinates (Yang et al., 2022) as input to map their semantics into corresponding images. However, coordinate inputs cannot be interpreted by T2I models. Instead, we make use of the observations that attention maps provide free token-region associations in trained T2I models (Hertz et al., 2022). By modifying the key-value pairs in cross-attention layers, we manage to map the encoding of each text span into attended regions in 2D image space. ",
122
+ "bbox": [
123
+ 174,
124
+ 482,
125
+ 825,
126
+ 650
127
+ ],
128
+ "page_idx": 1
129
+ },
130
+ {
131
+ "type": "text",
132
+ "text": "In this work, we discover similar observations in Stable Diffusion (Rombach et al., 2022) and utilize the property to build structured cross-attention guidance. Specifically, we use language parsers to obtain hierarchical structures from the prompts. We extract text spans across all levels, including visual concepts or entities, and encode them separately to disentangle the attribute-object pairs from each other. Compared to using a single sequence of text embedding for guidance, we improve the compositionality by multiple sequences where each emphasizes an entity or a union of entities from multiple hierarchies in the structured language representations. We refer to our method as Structured Diffusion Guidance (StructureDiffusion). Our contributions can be summarized as three-fold: ",
133
+ "bbox": [
134
+ 174,
135
+ 656,
136
+ 825,
137
+ 767
138
+ ],
139
+ "page_idx": 1
140
+ },
141
+ {
142
+ "type": "text",
143
+ "text": "• We propose an intuitive and effective method to improve compositional text-to-image synthesis by utilizing structured representations of language inputs. Our method is efficient and training-free that requires no additional training samples. \n• Experimental results show that our method achieves more accurate attribute binding and compositionality in the generated images. We also propose a benchmark named Attribute Binding Contrast set (ABC-6K) to measure the compositional skills of T2I models. \n• We conduct extensive experiments and analysis to identify the causes of incorrect attribute binding, which points out future directions in improving the faithfulness and compositionality of text-to-image synthesis. ",
144
+ "bbox": [
145
+ 217,
146
+ 782,
147
+ 825,
148
+ 924
149
+ ],
150
+ "page_idx": 1
151
+ },
152
+ {
153
+ "type": "image",
154
+ "img_path": "images/09bca81db2a15f234e6b30d656ac74ab6f9b1cbc101365fd59e52c1916f786df.jpg",
155
+ "image_caption": [
156
+ "Figure 2: An illustration of cross-attention operations and the token-region associations from attention maps. We omit some tokens for simplicity. "
157
+ ],
158
+ "image_footnote": [],
159
+ "bbox": [
160
+ 176,
161
+ 103,
162
+ 821,
163
+ 304
164
+ ],
165
+ "page_idx": 2
166
+ },
167
+ {
168
+ "type": "text",
169
+ "text": "2 DIFFUSION MODELS & STRUCTURED GUIDANCE ",
170
+ "text_level": 1,
171
+ "bbox": [
172
+ 174,
173
+ 372,
174
+ 612,
175
+ 388
176
+ ],
177
+ "page_idx": 2
178
+ },
179
+ {
180
+ "type": "text",
181
+ "text": "In this section, we propose a simple yet effective approach incorporating structured language representations into the cross-attention layers. We briefly introduce the Stable Diffusion model and its critical components in Sec. 2.1. Then, we present our method in detail in Sec. 2.2. ",
182
+ "bbox": [
183
+ 174,
184
+ 405,
185
+ 825,
186
+ 446
187
+ ],
188
+ "page_idx": 2
189
+ },
190
+ {
191
+ "type": "text",
192
+ "text": "2.1 BACKGROUND ",
193
+ "text_level": 1,
194
+ "bbox": [
195
+ 174,
196
+ 465,
197
+ 315,
198
+ 481
199
+ ],
200
+ "page_idx": 2
201
+ },
202
+ {
203
+ "type": "text",
204
+ "text": "Stable Diffusion We implement our approach and experiments on the state-of-the-art T2I model, Stable Diffusion (Rombach et al., 2022). It is a two-stage method that consists of an autoencoder and a diffusion model. The pre-trained autoencoder encodes images as lower-resolution latent maps for diffusion training. During inference, it decodes generated outputs from the diffusion model into images. The diffusion model generates lower-resolution latent maps based on a random Gaussian noise input $z ^ { T }$ . Given $z ^ { T }$ , it outputs a noise estimation $\\epsilon$ at each step $t$ and subtracts it from $z ^ { t }$ . The final noise-free latent map prediction $z ^ { 0 }$ is fed into the autoencoder to generate images. Stable Diffusion adopts a modified UNet (Ronneberger et al., 2015) for noise estimation and a frozen CLIP text encoder (Radford et al., 2021) to encode text inputs as embedding sequences. The interactions between the image space and the textual embeddings are achieved through multiple cross-attention layers in both downsampling and upsampling blocks. ",
205
+ "bbox": [
206
+ 173,
207
+ 492,
208
+ 826,
209
+ 647
210
+ ],
211
+ "page_idx": 2
212
+ },
213
+ {
214
+ "type": "text",
215
+ "text": "CLIP Text Encoder Given an input prompt $\\mathcal { P }$ , the CLIP encoder encodes it as a sequence of embeddings ${ \\mathcal { W } } _ { \\mathrm { p } } = \\mathbf { C } \\mathbf { L I P } _ { \\mathrm { t e x t } } ( \\mathcal { P } )$ where $c _ { \\mathrm { p } }$ is the embedding dimension and $l$ is the sequence length. Our key observation is that the contextualization of CLIP embeddings is a potential cause of incorrect attribute binding. Due to the causal attention masks, tokens in the later part of a sequence are blended with the token semantics before them. For example, When the user indicates some rare color for the second object (e.g. “a yellow apple and red bananas”), Stable Diffusion tends to generate “banana” in “yellow”, as the embeddings of “yellow” is attended by token “banana”. ",
216
+ "bbox": [
217
+ 173,
218
+ 662,
219
+ 825,
220
+ 761
221
+ ],
222
+ "page_idx": 2
223
+ },
224
+ {
225
+ "type": "text",
226
+ "text": "Cross Attention Layers The cross-attention layers take the embedding sequences from the CLIP text encoder and fuse them with latent feature maps to achieve classifier-free guidance. Denote a 2D feature map $\\mathcal { X } ^ { t }$ , it is projected into queries by a linear layer $f _ { Q } ( \\cdot )$ and reshaped as $Q ^ { t } \\in R ^ { ( n , h \\times w , d ) }$ where $n$ denotes the number of attention heads, $d$ is the feature dimension. Similarly ${ \\mathcal W } _ { \\mathfrak p }$ is projected as keys and values $K _ { \\mathfrak { p } } , V _ { \\mathfrak { p } } \\in R ^ { ( n , l , d ) }$ by linear layers $f _ { K } ( \\cdot ) , f _ { V } ( \\cdot )$ . The attention maps refer to the product between queries and keys, denoted as a function $f _ { M } ( \\cdot )$ ",
227
+ "bbox": [
228
+ 174,
229
+ 779,
230
+ 825,
231
+ 867
232
+ ],
233
+ "page_idx": 2
234
+ },
235
+ {
236
+ "type": "equation",
237
+ "img_path": "images/dbad0639bef74ec13696b28a5736eed0f1d8fbb8ce1193600a40bbca688f7a5c.jpg",
238
+ "text": "$$\nM ^ { t } = f _ { M } ( Q ^ { t } , K _ { p } ) = \\mathrm { S o f t m a x } ( \\frac { Q ^ { t } K _ { \\mathrm { p } } ^ { T } } { \\sqrt { d } } ) , M ^ { t } \\in R ^ { ( n , h \\times w , l ) } .\n$$",
239
+ "text_format": "latex",
240
+ "bbox": [
241
+ 299,
242
+ 875,
243
+ 699,
244
+ 911
245
+ ],
246
+ "page_idx": 2
247
+ },
248
+ {
249
+ "type": "image",
250
+ "img_path": "images/a4f20aec4802f8a65ee210c0541bcc6905c7389daea131d1a009bc1e10573207.jpg",
251
+ "image_caption": [
252
+ "Figure 3: An illustration of our cross-attention design with structured representations. We unflatten the query and attention maps and omit the feature dimension $d$ of all query, key, and value tensors for demonstration purposes. Note that noun phrases at multiple hierarchies are extracted and encoded through the frozen CLIP text encoder and projected to value vectors. "
253
+ ],
254
+ "image_footnote": [],
255
+ "bbox": [
256
+ 199,
257
+ 102,
258
+ 808,
259
+ 325
260
+ ],
261
+ "page_idx": 3
262
+ },
263
+ {
264
+ "type": "text",
265
+ "text": "Cross Attention Controls Hertz et al. (2022) observes that the spatial layouts depend on the cross attention maps in Imagen Saharia et al. (2022). These maps control the layout and structure of generated images, while the values contain rich semantics mapped into attended regions. Therefore, we assume that the image layout and content can be disentangled by controlling attention maps and values separately. ",
266
+ "bbox": [
267
+ 174,
268
+ 420,
269
+ 826,
270
+ 491
271
+ ],
272
+ "page_idx": 3
273
+ },
274
+ {
275
+ "type": "text",
276
+ "text": "2.2 STRUCTURED DIFFUSION GUIDANCE ",
277
+ "text_level": 1,
278
+ "bbox": [
279
+ 178,
280
+ 507,
281
+ 470,
282
+ 521
283
+ ],
284
+ "page_idx": 3
285
+ },
286
+ {
287
+ "type": "text",
288
+ "text": "Given the challenging prompts in Fig. 1, the attribute-object pairs are available for free1 in many structured representations, such as a constituency tree or a scene graph. We seek an implicit way of combining language structures with the cross-attention layers. As is shown in Fig. 3, we can extract multiple noun phrases (NPs) and map their semantics into corresponding regions. Since $M _ { t }$ provides natural token-region associations (see Fig. 2), we can apply it to multiple values from different NPs to achieve region-wise semantic guidance. ",
289
+ "bbox": [
290
+ 174,
291
+ 532,
292
+ 825,
293
+ 617
294
+ ],
295
+ "page_idx": 3
296
+ },
297
+ {
298
+ "type": "text",
299
+ "text": "Specifically, given a parser $\\xi ( \\cdot )$ , we first extract a collection of concepts from all hierarchical levels as $\\mathcal { C } = \\{ c _ { 1 } , c _ { 2 } , \\ldots , c _ { k } \\}$ . For constituency parsing, we extract all NPs from the tree structure (see Fig.3 left). For the scene graphs, we extract objects and their relations with another object as text segments. We encode each NP separately: ",
300
+ "bbox": [
301
+ 173,
302
+ 623,
303
+ 825,
304
+ 680
305
+ ],
306
+ "page_idx": 3
307
+ },
308
+ {
309
+ "type": "equation",
310
+ "img_path": "images/77e28f45441ca9a1d8d56a707d6bdaa8b7e1df8613b506bd80d75eaef538a6af.jpg",
311
+ "text": "$$\n\\mathbb { W } = [ \\mathcal { W } _ { \\mathrm { p } } , \\mathcal { W } _ { 1 } , \\mathcal { W } _ { 2 } , \\ldots , \\mathcal { W } _ { k } ] , \\mathcal { W } _ { i } = \\mathbf { C } \\mathbf { L } \\mathbf { I } \\mathbf { P } _ { \\mathrm { t e x t } } ( c _ { i } ) , i = 1 , \\ldots k .\n$$",
312
+ "text_format": "latex",
313
+ "bbox": [
314
+ 290,
315
+ 688,
316
+ 707,
317
+ 707
318
+ ],
319
+ "page_idx": 3
320
+ },
321
+ {
322
+ "type": "text",
323
+ "text": "The embedding sequence $\\mathcal { W } _ { i }$ is realigned with $\\mathcal { W } _ { p }$ as shown in the middle of Fig. 3. Embeddings between $\\left. \\mathbf { b o s } \\right.$ and $\\langle \\mathrm { p a d } \\rangle$ are inserted into $\\mathcal { W } _ { p }$ to create a new sequence, denoted as $\\overline { { \\mathcal { W } } } _ { i }$ . We use $\\overline { { \\mathcal { W } } } _ { \\mathrm { p } }$ to obtain $K _ { \\mathfrak { p } }$ and $M ^ { t }$ as in Eq. 1, assuming that the full-prompt key is able to generate layouts without missing objects. We obtain a set of values from $\\mathbb { W }$ and multiply each with ${ \\bf { \\bar { \\boldsymbol { M } } } } ^ { t }$ to achieve a conjunction of $k$ NPs in $\\mathcal { C }$ : ",
324
+ "bbox": [
325
+ 174,
326
+ 714,
327
+ 825,
328
+ 790
329
+ ],
330
+ "page_idx": 3
331
+ },
332
+ {
333
+ "type": "equation",
334
+ "img_path": "images/43cd8d33fb320be7e98c97b79b3bb75f8831ac171d3a50931c712f437aabe5e4.jpg",
335
+ "text": "$$\n\\begin{array} { c } { \\mathbb { V } = [ f _ { V } ( \\mathcal { W } _ { \\mathrm { p } } ) , f _ { V } ( \\overline { { \\mathcal { W } } } _ { 1 } ) , \\ldots , f _ { V } ( \\overline { { \\mathcal { W } } } _ { k } ) ] = [ V _ { \\mathrm { p } } , V _ { 1 } , \\ldots , V _ { k } ] . } \\\\ { O ^ { t } = \\displaystyle \\frac { 1 } { ( k + 1 ) } \\sum _ { i } ( M ^ { t } V _ { i } ) , i = \\mathrm { p } , 1 , 2 , \\ldots , k . } \\end{array}\n$$",
336
+ "text_format": "latex",
337
+ "bbox": [
338
+ 303,
339
+ 795,
340
+ 692,
341
+ 858
342
+ ],
343
+ "page_idx": 3
344
+ },
345
+ {
346
+ "type": "text",
347
+ "text": "Compared to using $f _ { V } ( \\mathscr { W } _ { p } )$ only, Eq. 4 does not modify the image layout or composition since $M ^ { t }$ is still calculated from $Q ^ { t } , K _ { p }$ . Empirically, we justify the claim by a series of visualizations of $M _ { t }$ ",
348
+ "bbox": [
349
+ 174,
350
+ 869,
351
+ 821,
352
+ 898
353
+ ],
354
+ "page_idx": 3
355
+ },
356
+ {
357
+ "type": "text",
358
+ "text": "Algorithm 1 StructureDiffusion Guidance. ",
359
+ "text_level": 1,
360
+ "bbox": [
361
+ 178,
362
+ 103,
363
+ 455,
364
+ 117
365
+ ],
366
+ "page_idx": 4
367
+ },
368
+ {
369
+ "type": "text",
370
+ "text": "Require: ",
371
+ "text_level": 1,
372
+ "bbox": [
373
+ 174,
374
+ 123,
375
+ 236,
376
+ 137
377
+ ],
378
+ "page_idx": 4
379
+ },
380
+ {
381
+ "type": "text",
382
+ "text": "Input: Prompt $\\mathcal { P }$ , Parser $\\xi$ , decoder $\\psi$ , trained diffusion model $\\phi$ . \nOutput: Generated image $x$ . \n1: Retrieve concept set ${ \\mathcal { C } } = [ c _ { 1 } , \\ldots , c _ { k } ]$ by traversing $\\xi ( \\mathcal { P } )$ ; \n2: $\\mathcal { W } _ { \\mathrm { p } } \\mathrm { C L I P } _ { \\mathrm { t e x t } } ( \\mathcal { P } ) .$ , ${ \\mathcal { W } } _ { i } \\gets \\mathbf { C } \\mathbf { L I P _ { \\mathrm { t e x t } } } ( c _ { i } )$ ; $i = 1 , \\ldots , k$ \n3: for $t = T , T - 1 , \\dots , 1$ do \n4: for each cross attention layer in $\\phi$ do \n5: Obtain previous layer’s output $\\mathcal { X } ^ { t }$ . \n6: $Q ^ { t } \\gets \\hat { f } _ { Q } ( \\mathcal { X } ^ { t } ) , \\ \\dot { K _ { \\mathrm { p } } } \\gets \\boldsymbol { f } _ { K } \\mathsf { \\bar { ( } } \\mathcal { W _ { \\mathrm { p } } ) } , \\ V _ { i } \\gets f _ { V } ( \\overline { { \\mathcal { W } } } _ { i } ) ;$ $\\begin{array} { r } { i = { \\tt p } , 1 , \\ldots , k } \\\\ { \\{ { \\tt E q . ~ } 1 \\} } \\\\ { \\{ { \\tt E q . ~ } 4 \\} } \\end{array}$ \n7: Obtain attention maps $M ^ { t }$ from $Q ^ { t } , K _ { \\mathrm { p } }$ ; \n8: Obtain $O ^ { t }$ from $M ^ { t }$ , $\\{ V _ { i } \\}$ , and feed to following layers; \n9: end for \n10: end for \n11: Feed $z ^ { 0 }$ to decoder $\\psi ( \\cdot )$ to generate $\\mathbf { X }$ . ",
383
+ "bbox": [
384
+ 178,
385
+ 135,
386
+ 825,
387
+ 321
388
+ ],
389
+ "page_idx": 4
390
+ },
391
+ {
392
+ "type": "text",
393
+ "text": "(see Appendix C). However, Stable Diffusion tends to omit objects in generated images (Fig. 1), especially for concept conjunctions that connect two objects with the word “and”. We devise a variant of our method that computes a set of attention maps $\\ddot { \\mathbb { M } } = \\{ M _ { p } ^ { t } , M _ { 1 } ^ { t } , \\dots \\}$ from $\\mathcal { C }$ and multiply them to $\\mathbb { V }$ : ",
394
+ "bbox": [
395
+ 176,
396
+ 345,
397
+ 825,
398
+ 400
399
+ ],
400
+ "page_idx": 4
401
+ },
402
+ {
403
+ "type": "equation",
404
+ "img_path": "images/c767994a3fda118a2d6ccea8934090e68fe5e616eaa672a127b710fa13a54a98.jpg",
405
+ "text": "$$\n\\begin{array} { c } { { \\mathbb { K } = \\{ f _ { K } ( \\mathcal { W } _ { i } ) \\} , \\mathbb { M } ^ { t } = \\{ f _ { M } ( Q ^ { t } , K _ { i } ) \\} , i = \\mathrm { p } , 1 , 2 , \\ldots , k . } } \\\\ { { O ^ { t } = \\displaystyle \\frac { 1 } { ( k + 1 ) } \\sum _ { i } ( M _ { i } ^ { t } V _ { k } ) , i = \\mathrm { p } , 1 , 2 , \\ldots , k . } } \\end{array}\n$$",
406
+ "text_format": "latex",
407
+ "bbox": [
408
+ 303,
409
+ 398,
410
+ 694,
411
+ 454
412
+ ],
413
+ "page_idx": 4
414
+ },
415
+ {
416
+ "type": "text",
417
+ "text": "$O ^ { t }$ is the output of a certain cross-attention layer and the input into downstream layers to generate final image $x$ . Our algorithm can be summarized as 1, which requires no training or additional data. ",
418
+ "bbox": [
419
+ 174,
420
+ 455,
421
+ 823,
422
+ 484
423
+ ],
424
+ "page_idx": 4
425
+ },
426
+ {
427
+ "type": "text",
428
+ "text": "3 EXPERIMENT ",
429
+ "text_level": 1,
430
+ "bbox": [
431
+ 176,
432
+ 503,
433
+ 316,
434
+ 518
435
+ ],
436
+ "page_idx": 4
437
+ },
438
+ {
439
+ "type": "text",
440
+ "text": "3.1 EXPERIMENT SETTINGS ",
441
+ "text_level": 1,
442
+ "bbox": [
443
+ 176,
444
+ 534,
445
+ 382,
446
+ 549
447
+ ],
448
+ "page_idx": 4
449
+ },
450
+ {
451
+ "type": "text",
452
+ "text": "Datasets To address attribute binding and compositional generation, we propose a new benchmark, Attribute Binding Contrast set (ABC-6K). It consists of natural prompts from MSCOCO where each contains at least two color words modifying different objects. We also switch the position of two color words to create a contrast caption (Gardner et al., 2020). We end up with $6 . 4 \\mathrm { K }$ captions or 3.2K contrastive pairs. In addition to natural compositional prompts, we challenge our method with less detailed prompts that conjunct two concepts together. These prompts follow the sentence pattern of “a red apple and a yellow banana” and conjunct two objects with their attribute descriptions. We refer to this set of prompts as Concept Conjunction 500 (CC-500). We also evaluate our method on 10K randomly sampled captions from MSCOCO (Lin et al., 2014). We show that our method generalizes beyond attribute binding and introduces no quality degradation for general prompts. ",
453
+ "bbox": [
454
+ 173,
455
+ 560,
456
+ 825,
457
+ 699
458
+ ],
459
+ "page_idx": 4
460
+ },
461
+ {
462
+ "type": "text",
463
+ "text": "Evaluation Metrics We mainly rely on human evaluations for compositional prompts and concept conjunction (ABC-6K & CC-500). We ask annotators to compare two generated images, from Stable Diffusion and our method respectively, and indicate which image demonstrates better image-text alignment or image fidelity. For image fidelity, we ask the annotators “Regardless of the text, which image is more realistic and natural?”. We also investigate an automatic evaluation metric for image compositions, i.e., using a SOTA phrase grounding model GLIP (Li et al., 2022) to match phraseobject pairs. As for system-level evaluation, we follow previous work to utilize Inception Score (IS) (Salimans et al., 2016), Frechet Inception Distance (FID) (Heusel et al., 2017) and CLIP R-precision ´ (R-prec.) (Park et al., 2021). IS and FID mainly measure the image bank’s systematic quality and diversity, while R-prec measures image-level alignment. ",
464
+ "bbox": [
465
+ 174,
466
+ 713,
467
+ 825,
468
+ 853
469
+ ],
470
+ "page_idx": 4
471
+ },
472
+ {
473
+ "type": "text",
474
+ "text": "3.2 COMPOSITIONAL PROMPTS ",
475
+ "text_level": 1,
476
+ "bbox": [
477
+ 176,
478
+ 869,
479
+ 403,
480
+ 883
481
+ ],
482
+ "page_idx": 4
483
+ },
484
+ {
485
+ "type": "text",
486
+ "text": "Here we show the quantitative and qualitative evaluation results on ABC-6K. We observe that our method sometimes generates very similar images to Stable Diffusion. Hence, we first generate two images per prompt for our method and Stable Diffusion, involving around 12K image pairs to compare. Then, we filter out $20 \\%$ of the most similar pairs and then randomly sampled 1500 pairs for human evaluations. As shown in Table 1, annotators indicate around a $42 \\%$ chance of our method winning the comparison, $7 \\%$ higher than losing the comparison. There is still a $22 \\%$ of chance that our images are tied with images from Stable Diffusion. ",
487
+ "bbox": [
488
+ 174,
489
+ 895,
490
+ 823,
491
+ 924
492
+ ],
493
+ "page_idx": 4
494
+ },
495
+ {
496
+ "type": "table",
497
+ "img_path": "images/86f2f5b3874d91915911d0f79b795f8140a36efe891911187b5ee1b649a4af98.jpg",
498
+ "table_caption": [
499
+ "Table 1: Percentage of generated images of StructureDiffusion that are better than (win), tied with, or worse than (lose) the compared model in terms of text-image alignment and image fidelity. We filtered out $20 \\%$ most similar image pairs for comparison (See Sec. E). Composable Diffusion cannot be applied to ABC-6K as those prompts may not contain explicit “and” words that separate concepts. "
500
+ ],
501
+ "table_footnote": [],
502
+ "table_body": "<table><tr><td rowspan=\"2\">Benchmark</td><td rowspan=\"2\">StructureDiffusion (ours) v.s.</td><td colspan=\"3\">Alignment</td><td colspan=\"3\">Fidelity</td></tr><tr><td>Win (↑)</td><td>Lose (↓)</td><td>Tie</td><td>Win (↑)</td><td>Lose (↓)</td><td>Tie</td></tr><tr><td>ABC-6K</td><td>Stable Diffusion</td><td>42.2</td><td>35.6</td><td>22.2</td><td>48.3</td><td>39.1</td><td>12.6</td></tr><tr><td rowspan=\"2\">CC-500</td><td>Stable Diffusion</td><td>31.8</td><td>27.7</td><td>38.9</td><td>37.8</td><td>30.6</td><td>31.6</td></tr><tr><td>Composable Diffusion</td><td>46.5</td><td>30.1</td><td>22.8</td><td>61.4</td><td>19.8</td><td>18.8</td></tr></table>",
503
+ "bbox": [
504
+ 173,
505
+ 101,
506
+ 821,
507
+ 195
508
+ ],
509
+ "page_idx": 5
510
+ },
511
+ {
512
+ "type": "image",
513
+ "img_path": "images/cde95ccdebc9693de8c741688cd3b4fadc9ef5c3215551ed35f2b60c361cda4c.jpg",
514
+ "image_caption": [
515
+ "Figure 4: Qualitative results on ABC-6K. Our method improves both object-level and scene-level compositionality. "
516
+ ],
517
+ "image_footnote": [],
518
+ "bbox": [
519
+ 192,
520
+ 284,
521
+ 805,
522
+ 523
523
+ ],
524
+ "page_idx": 5
525
+ },
526
+ {
527
+ "type": "text",
528
+ "text": "",
529
+ "bbox": [
530
+ 174,
531
+ 599,
532
+ 825,
533
+ 669
534
+ ],
535
+ "page_idx": 5
536
+ },
537
+ {
538
+ "type": "text",
539
+ "text": "We show qualitative examples characterizing three different perspectives in Fig. 4. Our method fills in the correct color for different parts of an object or different objects, as shown in the first two examples. The third example demonstrates that our method can mitigate the issue of “missing objects”. Among the $42 \\%$ winning cases, there are $31 \\%$ for “fewer missing objects”, $1 4 . 1 \\%$ for “better-matched colors”, and $5 4 . 8 \\%$ for “other attributes or details” as indicated by annotators. The results certify that the improvement goes beyond colors to component completeness and fine-grained details. More qualitative examples characterizing all three aspects can be found in Fig. 14 in the Appendix. ",
540
+ "bbox": [
541
+ 173,
542
+ 676,
543
+ 825,
544
+ 787
545
+ ],
546
+ "page_idx": 5
547
+ },
548
+ {
549
+ "type": "text",
550
+ "text": "3.3 CONCEPT CONJUNCTION ",
551
+ "text_level": 1,
552
+ "bbox": [
553
+ 176,
554
+ 810,
555
+ 388,
556
+ 825
557
+ ],
558
+ "page_idx": 5
559
+ },
560
+ {
561
+ "type": "text",
562
+ "text": "Here we address challenging concept conjunction prompts and evaluate our method on CC-500. Apart from Stable Diffusion, we also compare to Composable Diffusion (Liu et al., 2022) implemented on top of Stable Diffusion. For Composable Diffusion, we separate the prompts into text segments by the keyword “and” and feed each span into an independent diffusion process. We generate three images per prompt and use all images for human evaluation for Stable Diffusion. We randomly sampled 600 images for comparison to Composable Diffusion. ",
563
+ "bbox": [
564
+ 174,
565
+ 840,
566
+ 825,
567
+ 924
568
+ ],
569
+ "page_idx": 5
570
+ },
571
+ {
572
+ "type": "table",
573
+ "img_path": "images/825a83d0f632061daf6fb88e161b5e3156d0b285af107e2b19768aef342833ae.jpg",
574
+ "table_caption": [],
575
+ "table_footnote": [],
576
+ "table_body": "<table><tr><td rowspan=\"2\"></td><td colspan=\"6\">CC-500 (Prompt format: “a [colorA] [objectA] and a [colorB] [objectB]&quot;)</td></tr><tr><td></td><td>Human Annotations</td><td></td><td>GLIP</td><td></td><td>Human-GLIP</td></tr><tr><td>Methods</td><td>Zero/One obj. ()</td><td>Two obj.</td><td>Two obj. w/ correct colors</td><td>Zero/One obj.(↓)</td><td>Two obj.</td><td>Consistency</td></tr><tr><td>Stable Diffusion</td><td>65.5</td><td>34.5</td><td>19.2</td><td>69.0</td><td>31.0</td><td>46.4</td></tr><tr><td>Composable Diffusion</td><td>69.7</td><td>30.3</td><td>20.6</td><td>74.2</td><td>25.8</td><td>48.9</td></tr><tr><td>StructureDiffusion (Ours)</td><td>62.0</td><td>38.0</td><td>22.7</td><td>68.8</td><td>31.2</td><td>47.6</td></tr></table>",
577
+ "bbox": [
578
+ 171,
579
+ 101,
580
+ 820,
581
+ 222
582
+ ],
583
+ "page_idx": 6
584
+ },
585
+ {
586
+ "type": "text",
587
+ "text": "Table 2: Fine-grained human and automatic evaluation results on CC-500. Recall that each prompt is a conjunction of two different objects with different colors. “Zero/One obj.” means that the model fails to generate all desired objects in the image. “Human-GLIP consistency” reflects the percentage of images where human annotations align with GLIP detection results. ",
588
+ "bbox": [
589
+ 173,
590
+ 232,
591
+ 825,
592
+ 287
593
+ ],
594
+ "page_idx": 6
595
+ },
596
+ {
597
+ "type": "image",
598
+ "img_path": "images/3902d5a9c111e4d4a12e67c65e27de1a9c2c07d74efa1fca4dfa19aefa3dbcb9.jpg",
599
+ "image_caption": [
600
+ "Figure 5: Qualitative results on CC-500 prompts that emphasize two aspects. (a) Color leakage: our method prevents the green color from invading the bird or apple. (b) Missing objects: our method completes the “blue bowl” and improves the quality of the “blue apple”. "
601
+ ],
602
+ "image_footnote": [],
603
+ "bbox": [
604
+ 205,
605
+ 303,
606
+ 802,
607
+ 537
608
+ ],
609
+ "page_idx": 6
610
+ },
611
+ {
612
+ "type": "text",
613
+ "text": "As shown in Table 1, our method outperforms Stable Diffusion by around $4 . 1 \\%$ and Composable Diffusion by $1 6 . 4 \\%$ in terms of image-text alignment. We also observe that our method enhances some fine-grained details in the generated images, leading to a $7 . 2 \\%$ improvement in image fidelity when compared with Stable Diffusion. We observe that images from composable diffusion can be oversaturated with unnatural visual textures and layouts, which could be the reason for StructureDiffusion to have high win rate in image fidelity. As shown in Fig. 5 and Fig. 13. Our approach prevents color bleeding (left), missing objects (right) and strengthens details (right). ",
614
+ "bbox": [
615
+ 174,
616
+ 622,
617
+ 825,
618
+ 720
619
+ ],
620
+ "page_idx": 6
621
+ },
622
+ {
623
+ "type": "text",
624
+ "text": "To further quantify the text-image alignment, we consider both human annotations and automatic evaluations. For each object mentioned in the prompt, we ask annotators whether the object exists in the image and whether it is in the correct color. We also apply a state-of-the-art detection model GLIP (Li et al., 2022) to ground each “a [color] [object]” phrase into bounding boxes. We report the percentage of images that contain incomplete objects / complete objects / complete objects with correct colors in Table 2. StructureDiffusion improves the compositionality by $3 . 5 \\%$ based on human annotations while only $0 . 2 \\%$ based on GLIP. We discover that humans disagree with GLIP for more than $50 \\%$ of the images, as entailed by the low consistency rate. Previous work also suggests the deficiency of large pre-trained models in compositional understanding (Thrush et al., 2022). ",
625
+ "bbox": [
626
+ 174,
627
+ 727,
628
+ 825,
629
+ 853
630
+ ],
631
+ "page_idx": 6
632
+ },
633
+ {
634
+ "type": "text",
635
+ "text": "3.4 OTHER PROMPTS ",
636
+ "text_level": 1,
637
+ "bbox": [
638
+ 176,
639
+ 869,
640
+ 333,
641
+ 883
642
+ ],
643
+ "page_idx": 6
644
+ },
645
+ {
646
+ "type": "text",
647
+ "text": "We show that our StructureDiffusion maintain the overall image quality and diversity on general prompts. We follow the standard evaluation process and generate 10,000 images from randomly ",
648
+ "bbox": [
649
+ 174,
650
+ 895,
651
+ 823,
652
+ 924
653
+ ],
654
+ "page_idx": 6
655
+ },
656
+ {
657
+ "type": "image",
658
+ "img_path": "images/e0cc7567ff201cd421e0f017febca9fe7cd7bc251c12c2c41f6a6f273c0b81cb.jpg",
659
+ "image_caption": [
660
+ "Figure 6: Qualitative results of using scene graph parser to generate structured representations. "
661
+ ],
662
+ "image_footnote": [],
663
+ "bbox": [
664
+ 173,
665
+ 102,
666
+ 821,
667
+ 198
668
+ ],
669
+ "page_idx": 7
670
+ },
671
+ {
672
+ "type": "image",
673
+ "img_path": "images/7dfce557e99a420d3ccd8d1cf8e3979db4bd6ad9b3761a1fd404947bf41071bb.jpg",
674
+ "image_caption": [
675
+ "Figure 7: Ablation study on the text sequence embeddings. We find that the padding embeddings are fully contextualized, representing the prompt’s high-level semantics. However, not all padding tokens are necessary to maintain a high-fidelity output from Stable Diffusion. "
676
+ ],
677
+ "image_footnote": [],
678
+ "bbox": [
679
+ 196,
680
+ 244,
681
+ 802,
682
+ 429
683
+ ],
684
+ "page_idx": 7
685
+ },
686
+ {
687
+ "type": "text",
688
+ "text": "sampled MSCOCO captions. Stable Diffusion obtains 39.9 IS, 18.0 FID and 72.2 R-Precision. Our method achieves 40.9 IS, 17.9 FID and $7 2 . 3 \\mathrm { R }$ -Precision. StructureDiffusion maintains the image fidelity and diversity as indicated in the comparable IS/FID/R-Prec scores. ",
689
+ "bbox": [
690
+ 176,
691
+ 513,
692
+ 825,
693
+ 555
694
+ ],
695
+ "page_idx": 7
696
+ },
697
+ {
698
+ "type": "text",
699
+ "text": "3.5 SCENE GRAPH INPUT ",
700
+ "text_level": 1,
701
+ "bbox": [
702
+ 176,
703
+ 577,
704
+ 362,
705
+ 590
706
+ ],
707
+ "page_idx": 7
708
+ },
709
+ {
710
+ "type": "text",
711
+ "text": "We show that our method is not limited to constituency parsing but can also be extended to other structured representations, such as scene graphs. As shown in Fig. 6, we first adopt the scene graph parser (Wu et al., 2019) and obtain a graph like the ones next to each image from the input prompt. The parser returns basic entities and their relations in between. We extract text spans of basic entities with their attributes attached and text spans that include two related entities. We provide examples in Appendix 3 and make comparison to the constituency parser. Similarly, we encode these spans separately and re-align each with the entire prompt encoding sequence. On MS-COCO, the scene graph parser setting maintains the image quality with 39.2 IS, 17.9 FID, and 72.0 R-Precision. When compared to Stable Diffusion on ABC-6K, the scene graph parser achieves $3 4 . 2 \\% - 3 2 . 9 \\% - 3 2 . 9 \\%$ Win-Lose-Tie in image-text alignment and $3 4 . 5 \\% - 3 2 . 5 \\% - 3 3 . 0 \\%$ Win-Lose-Tie in image fidelity. As for CC-500, the scene graph parser leads to the same output images due to the same text spans. We refer to Table 3 and Fig. 12 for more results and comparison. ",
712
+ "bbox": [
713
+ 173,
714
+ 603,
715
+ 825,
716
+ 770
717
+ ],
718
+ "page_idx": 7
719
+ },
720
+ {
721
+ "type": "text",
722
+ "text": "4 ABLATION STUDY ",
723
+ "text_level": 1,
724
+ "bbox": [
725
+ 176,
726
+ 792,
727
+ 356,
728
+ 809
729
+ ],
730
+ "page_idx": 7
731
+ },
732
+ {
733
+ "type": "text",
734
+ "text": "4.1 RE-ALIGNING SEQUENCE ",
735
+ "text_level": 1,
736
+ "bbox": [
737
+ 176,
738
+ 827,
739
+ 392,
740
+ 840
741
+ ],
742
+ "page_idx": 7
743
+ },
744
+ {
745
+ "type": "text",
746
+ "text": "In Section 2, we describe a method to realign the encoding of a text span back into the sequence of the full prompt. Since the noun-phrase text spans are shorter than the full sequence, re-alignment ensures that each token’s value vector corresponds to the correct attention map. On the other hand, naively expanding the span to the length of the full sequence degrades the image quality by ${ \\sim } 2 \\mathrm { I S } /$ FID (37.5 IS, 19.8 FID) compared to images with re-alignment or Stable Diffusion. ",
747
+ "bbox": [
748
+ 174,
749
+ 854,
750
+ 825,
751
+ 924
752
+ ],
753
+ "page_idx": 7
754
+ },
755
+ {
756
+ "type": "text",
757
+ "text": "4.2 CONTEXTUALIZED TEXT EMBEDDINGS ",
758
+ "text_level": 1,
759
+ "bbox": [
760
+ 176,
761
+ 103,
762
+ 486,
763
+ 118
764
+ ],
765
+ "page_idx": 8
766
+ },
767
+ {
768
+ "type": "text",
769
+ "text": "One limitation brought by our StructureDiffusion is that the cross-attention computation costs increase by the number of noun phrases. Yet we noticed that most of the attention maps are computed from padding embeddings, as Stable Diffusion adopts CLIP text encoders and automatically pads the sequence to 77 tokens. We conjecture that not all padding tokens are necessary for generating high-quality images. As is shown in Fig. 7, we study four different patterns of token embeddings. We discover that leaving the nearest padding embeddings maintains a similar IS / FID score as the full sequence. Further removing this padding embedding results in apparent degradation. While only using the nearest padding embedding results in the worst image quality, we find that the high-level image layout and semantics are preserved (see bottom right of Fig. 7). This phenomenon indicates that the padding embeddings are fully contextualized with the full prompt semantics. This also justifies our re-alignment operation that preserves padding embeddings of the main sequence ${ \\mathcal { W } } _ { \\mathrm { f u l l } }$ . ",
770
+ "bbox": [
771
+ 174,
772
+ 131,
773
+ 825,
774
+ 284
775
+ ],
776
+ "page_idx": 8
777
+ },
778
+ {
779
+ "type": "text",
780
+ "text": "5 RELATED WORK ",
781
+ "text_level": 1,
782
+ "bbox": [
783
+ 176,
784
+ 308,
785
+ 344,
786
+ 324
787
+ ],
788
+ "page_idx": 8
789
+ },
790
+ {
791
+ "type": "text",
792
+ "text": "Text-to-Image Synthesis The diffusion model is an emerging type of model that generate highquality images with a much more stable training process (Song & Ermon, 2019; Ho et al., 2020). Rombach et al. (2022) proposes to encode an image with an autoencoder and then leverage a diffusion model to generate continuous feature maps in the latent space. Stable Diffusion Rombach et al. (2022) adopts similar architecture but is trained on large-scale image-text datasets with fixed CLIP text encoder. Imagen (Saharia et al., 2022) addresses the importance of language understanding by using a frozen T5 encoder (Raffel et al., 2020), a dedicated large language model. We mainly focus on diffusion models and conduct our experiments on Stable Diffusion (Rombach et al., 2022), the SOTA open-sourced T2I model. ",
793
+ "bbox": [
794
+ 174,
795
+ 340,
796
+ 826,
797
+ 467
798
+ ],
799
+ "page_idx": 8
800
+ },
801
+ {
802
+ "type": "text",
803
+ "text": "Compositional Generation The compositional or controllable generation has been an essential direction for T2I models to understand and disentangle basic concepts in the generation process. As text inputs are relatively weak conditions, previous work leverage layout or scene graph to enhance compositionality (Johnson et al., 2018; Hong et al., 2018; Yang et al., 2022; Gafni et al., 2022). More recently, Liu et al. (2022) proposes an approach where the concept conjunctions are achieved by adding estimated scores from a parallel set of diffusion processes. In contrast, our method can be directly merged into the cross-attention layers with much less computational overhead. ",
804
+ "bbox": [
805
+ 174,
806
+ 484,
807
+ 825,
808
+ 583
809
+ ],
810
+ "page_idx": 8
811
+ },
812
+ {
813
+ "type": "text",
814
+ "text": "Diffusion Guidance Ho & Salimans (2022) develops classifier-free guidance where a single diffusion model is jointly trained under conditional and unconditional inputs. Most large-scale SOTA models, including autoregressive ones, adopt this technique for flexible and improved conditional synthesis results (Rombach et al., 2022; Ramesh et al., 2022; Gafni et al., 2022; Yu et al., 2022; Saharia et al., 2022). Hertz et al. (2022) discovers unique properties of cross attention maps on Imagen (Saharia et al., 2022) and achieves structure-preserving image editing by manipulating these maps. We observe similar properties in Stable Diffusion (Rombach et al., 2022) but propose a different algorithm for fine-grained, compositional text-to-image generation. ",
815
+ "bbox": [
816
+ 174,
817
+ 602,
818
+ 825,
819
+ 713
820
+ ],
821
+ "page_idx": 8
822
+ },
823
+ {
824
+ "type": "text",
825
+ "text": "6 CONCLUSION ",
826
+ "text_level": 1,
827
+ "bbox": [
828
+ 174,
829
+ 737,
830
+ 318,
831
+ 753
832
+ ],
833
+ "page_idx": 8
834
+ },
835
+ {
836
+ "type": "text",
837
+ "text": "In this work, we propose a training-free method for compositional text-to-image generation. First, we observe that existing large-scale T2I diffusion models can still struggle in compositional image synthesis. We address this challenge by explicitly focusing on binding objects with the correct attributes. Second, we propose structured diffusion guidance incorporating language structures into the cross-attention layers. We propose two simple techniques to align the structured encoding with the attention maps. Using our structured guidance on Stable Diffusion, attributes can be bound more accurately while maintaining the overall image quality and diversity. In addition, we justify our approach by conducting an in-depth analysis of the frozen language encoder and attention maps. Future work may explore explicit approaches to generate plausible image layouts without missing components. We hope that our approach accelerates the development of interpretable and efficient methods for diffusion-based text-to-image models. ",
838
+ "bbox": [
839
+ 174,
840
+ 770,
841
+ 825,
842
+ 924
843
+ ],
844
+ "page_idx": 8
845
+ },
846
+ {
847
+ "type": "text",
848
+ "text": "ACKNOWLEDGEMENT ",
849
+ "text_level": 1,
850
+ "bbox": [
851
+ 176,
852
+ 103,
853
+ 357,
854
+ 117
855
+ ],
856
+ "page_idx": 9
857
+ },
858
+ {
859
+ "type": "text",
860
+ "text": "We would like to thank the Robert N. Noyce Trust for their generous gift to the University of California via the Noyce Initiative. The work was also partially funded by an unrestricted gift from Google and by the National Science Foundation award #2048122. The writers’ opinions and conclusions in this publication are their own and should not be construed as representing the sponsors’ official policy, expressed or inferred. ",
861
+ "bbox": [
862
+ 174,
863
+ 133,
864
+ 825,
865
+ 204
866
+ ],
867
+ "page_idx": 9
868
+ },
869
+ {
870
+ "type": "text",
871
+ "text": "REPRODUCIBILITY STATEMENT ",
872
+ "text_level": 1,
873
+ "bbox": [
874
+ 176,
875
+ 224,
876
+ 437,
877
+ 241
878
+ ],
879
+ "page_idx": 9
880
+ },
881
+ {
882
+ "type": "text",
883
+ "text": "We release our core codebase containing the methodology implementation, settings, benchmarks containing compositional prompts under supplementary materials. ",
884
+ "bbox": [
885
+ 174,
886
+ 256,
887
+ 823,
888
+ 285
889
+ ],
890
+ "page_idx": 9
891
+ },
892
+ {
893
+ "type": "text",
894
+ "text": "ETHICAL STATEMENT ",
895
+ "text_level": 1,
896
+ "bbox": [
897
+ 176,
898
+ 305,
899
+ 356,
900
+ 321
901
+ ],
902
+ "page_idx": 9
903
+ },
904
+ {
905
+ "type": "text",
906
+ "text": "As for the data collection and verification, we use the Amazon Mechanical Turk platform and form the comparison task as batches of HITs. We select workers from English-speaking countries, including the US, CA, UK, AU, and NZ, since the task require understanding the English input prompt. Each HIT takes around 15-30 seconds on average to accomplish, and we pay each submitted HIT with 0.15 US dollars, resulting in an hourly payment of 18 US dollars. ",
907
+ "bbox": [
908
+ 174,
909
+ 337,
910
+ 825,
911
+ 406
912
+ ],
913
+ "page_idx": 9
914
+ },
915
+ {
916
+ "type": "text",
917
+ "text": "REFERENCES ",
918
+ "text_level": 1,
919
+ "bbox": [
920
+ 174,
921
+ 429,
922
+ 285,
923
+ 444
924
+ ],
925
+ "page_idx": 9
926
+ },
927
+ {
928
+ "type": "text",
929
+ "text": "Prafulla Dhariwal and Alexander Nichol. Diffusion models beat gans on image synthesis. Advances in Neural Information Processing Systems, 34:8780–8794, 2021. ",
930
+ "bbox": [
931
+ 173,
932
+ 452,
933
+ 823,
934
+ 481
935
+ ],
936
+ "page_idx": 9
937
+ },
938
+ {
939
+ "type": "text",
940
+ "text": "Ming Ding, Wendi Zheng, Wenyi Hong, and Jie Tang. Cogview2: Faster and better text-to-image generation via hierarchical transformers. arXiv preprint arXiv:2204.14217, 2022. ",
941
+ "bbox": [
942
+ 171,
943
+ 489,
944
+ 823,
945
+ 518
946
+ ],
947
+ "page_idx": 9
948
+ },
949
+ {
950
+ "type": "text",
951
+ "text": "Alaaeldin El-Nouby, Shikhar Sharma, Hannes Schulz, Devon Hjelm, Layla El Asri, Samira Ebrahimi Kahou, Yoshua Bengio, and Graham W.Taylor. Tell, Draw, and Repeat: Generating and Modifying Images Based on Continual Linguistic Instruction. In ICCV, 2019. ",
952
+ "bbox": [
953
+ 176,
954
+ 529,
955
+ 823,
956
+ 571
957
+ ],
958
+ "page_idx": 9
959
+ },
960
+ {
961
+ "type": "text",
962
+ "text": "Tsu-Jui Fu, Xin Eric Wang, Scott Grafton, Miguel Eckstein, and William Yang Wang. SSCR: Iterative Language-Based Image Editing via Self-Supervised Counterfactual Reasoning. In EMNLP, 2020. ",
963
+ "bbox": [
964
+ 171,
965
+ 580,
966
+ 825,
967
+ 609
968
+ ],
969
+ "page_idx": 9
970
+ },
971
+ {
972
+ "type": "text",
973
+ "text": "Oran Gafni, Adam Polyak, Oron Ashual, Shelly Sheynin, Devi Parikh, and Yaniv Taigman. Make-ascene: Scene-based text-to-image generation with human priors. arXiv preprint arXiv:2203.13131, 2022. ",
974
+ "bbox": [
975
+ 174,
976
+ 619,
977
+ 826,
978
+ 661
979
+ ],
980
+ "page_idx": 9
981
+ },
982
+ {
983
+ "type": "text",
984
+ "text": "Matt Gardner, Yoav Artzi, Victoria Basmov, Jonathan Berant, Ben Bogin, Sihao Chen, Pradeep Dasigi, Dheeru Dua, Yanai Elazar, Ananth Gottumukkala, et al. Evaluating models’ local decision boundaries via contrast sets. Findings of Empirical Methods in Natural Language Processing, 2020. ",
985
+ "bbox": [
986
+ 173,
987
+ 671,
988
+ 826,
989
+ 727
990
+ ],
991
+ "page_idx": 9
992
+ },
993
+ {
994
+ "type": "text",
995
+ "text": "Shuyang Gu, Dong Chen, Jianmin Bao, Fang Wen, Bo Zhang, Dongdong Chen, Lu Yuan, and Baining Guo. Vector quantized diffusion model for text-to-image synthesis. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 10696–10706, 2022a. ",
996
+ "bbox": [
997
+ 174,
998
+ 738,
999
+ 826,
1000
+ 780
1001
+ ],
1002
+ "page_idx": 9
1003
+ },
1004
+ {
1005
+ "type": "text",
1006
+ "text": "Shuyang Gu, Dong Chen, Jianmin Bao, Fang Wen, Bo Zhang, Dongdong Chen, Lu Yuan, and Baining Guo. Vector quantized diffusion model for text-to-image synthesis. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 10696–10706, 2022b. ",
1007
+ "bbox": [
1008
+ 174,
1009
+ 790,
1010
+ 825,
1011
+ 833
1012
+ ],
1013
+ "page_idx": 9
1014
+ },
1015
+ {
1016
+ "type": "text",
1017
+ "text": "Amir Hertz, Ron Mokady, Jay Tenenbaum, Kfir Aberman, Yael Pritch, and Daniel Cohen-Or. Promptto-prompt image editing with cross attention control. arXiv preprint arXiv:2208.01626, 2022. ",
1018
+ "bbox": [
1019
+ 171,
1020
+ 843,
1021
+ 825,
1022
+ 871
1023
+ ],
1024
+ "page_idx": 9
1025
+ },
1026
+ {
1027
+ "type": "text",
1028
+ "text": "Martin Heusel, Hubert Ramsauer, Thomas Unterthiner, Bernhard Nessler, and Sepp Hochreiter. Gans trained by a two time-scale update rule converge to a local nash equilibrium. Advances in neural information processing systems, 30, 2017. ",
1029
+ "bbox": [
1030
+ 176,
1031
+ 882,
1032
+ 825,
1033
+ 922
1034
+ ],
1035
+ "page_idx": 9
1036
+ },
1037
+ {
1038
+ "type": "text",
1039
+ "text": "Jonathan Ho and Tim Salimans. Classifier-free diffusion guidance. arXiv preprint arXiv:2207.12598, 2022. ",
1040
+ "bbox": [
1041
+ 171,
1042
+ 103,
1043
+ 825,
1044
+ 133
1045
+ ],
1046
+ "page_idx": 10
1047
+ },
1048
+ {
1049
+ "type": "text",
1050
+ "text": "Jonathan Ho, Ajay Jain, and Pieter Abbeel. Denoising diffusion probabilistic models. Advances in Neural Information Processing Systems, 33:6840–6851, 2020. ",
1051
+ "bbox": [
1052
+ 173,
1053
+ 140,
1054
+ 823,
1055
+ 169
1056
+ ],
1057
+ "page_idx": 10
1058
+ },
1059
+ {
1060
+ "type": "text",
1061
+ "text": "Seunghoon Hong, Dingdong Yang, Jongwook Choi, and Honglak Lee. Inferring semantic layout for hierarchical text-to-image synthesis. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 7986–7994, 2018. ",
1062
+ "bbox": [
1063
+ 176,
1064
+ 176,
1065
+ 823,
1066
+ 219
1067
+ ],
1068
+ "page_idx": 10
1069
+ },
1070
+ {
1071
+ "type": "text",
1072
+ "text": "Justin Johnson, Agrim Gupta, and Li Fei-Fei. Image generation from scene graphs. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 1219–1228, 2018. ",
1073
+ "bbox": [
1074
+ 171,
1075
+ 227,
1076
+ 823,
1077
+ 256
1078
+ ],
1079
+ "page_idx": 10
1080
+ },
1081
+ {
1082
+ "type": "text",
1083
+ "text": "Doyup Lee, Chiheon Kim, Saehoon Kim, Minsu Cho, and Wook-Shin Han. Autoregressive image generation using residual quantization. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 11523–11532, 2022. ",
1084
+ "bbox": [
1085
+ 174,
1086
+ 262,
1087
+ 823,
1088
+ 306
1089
+ ],
1090
+ "page_idx": 10
1091
+ },
1092
+ {
1093
+ "type": "text",
1094
+ "text": "Bowen Li, Xiaojuan Qi, Thomas Lukasiewicz, and Philip Torr. Controllable text-to-image generation. Advances in Neural Information Processing Systems, 32, 2019. ",
1095
+ "bbox": [
1096
+ 173,
1097
+ 313,
1098
+ 825,
1099
+ 343
1100
+ ],
1101
+ "page_idx": 10
1102
+ },
1103
+ {
1104
+ "type": "text",
1105
+ "text": "Liunian Harold Li, Pengchuan Zhang, Haotian Zhang, Jianwei Yang, Chunyuan Li, Yiwu Zhong, Lijuan Wang, Lu Yuan, Lei Zhang, Jenq-Neng Hwang, et al. Grounded language-image pre-training. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 10965–10975, 2022. ",
1106
+ "bbox": [
1107
+ 173,
1108
+ 349,
1109
+ 826,
1110
+ 406
1111
+ ],
1112
+ "page_idx": 10
1113
+ },
1114
+ {
1115
+ "type": "text",
1116
+ "text": "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. ",
1117
+ "bbox": [
1118
+ 176,
1119
+ 414,
1120
+ 825,
1121
+ 458
1122
+ ],
1123
+ "page_idx": 10
1124
+ },
1125
+ {
1126
+ "type": "text",
1127
+ "text": "Luping Liu, Yi Ren, Zhijie Lin, and Zhou Zhao. Pseudo numerical methods for diffusion models on manifolds. In International Conference on Learning Representations, 2021a. ",
1128
+ "bbox": [
1129
+ 169,
1130
+ 464,
1131
+ 823,
1132
+ 494
1133
+ ],
1134
+ "page_idx": 10
1135
+ },
1136
+ {
1137
+ "type": "text",
1138
+ "text": "Nan Liu, Shuang Li, Yilun Du, Antonio Torralba, and Joshua B Tenenbaum. Compositional visual generation with composable diffusion models. arXiv preprint arXiv:2206.01714, 2022. ",
1139
+ "bbox": [
1140
+ 171,
1141
+ 501,
1142
+ 823,
1143
+ 531
1144
+ ],
1145
+ "page_idx": 10
1146
+ },
1147
+ {
1148
+ "type": "text",
1149
+ "text": "Xihui Liu, Dong Huk Park, Samaneh Azadi, Gong Zhang, Arman Chopikyan, Yuxiao Hu, Humphrey Shi, Anna Rohrbach, and Trevor Darrell. More control for free! image synthesis with semantic diffusion guidance. arXiv preprint arXiv:2112.05744, 2021b. ",
1150
+ "bbox": [
1151
+ 176,
1152
+ 537,
1153
+ 823,
1154
+ 580
1155
+ ],
1156
+ "page_idx": 10
1157
+ },
1158
+ {
1159
+ "type": "text",
1160
+ "text": "Chao Lou, Wenjuan Han, Yuhuan Lin, and Zilong Zheng. Unsupervised vision-language parsing: Seamlessly bridging visual scene graphs with language structures via dependency relationships. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), pp. 15607–15616, June 2022. ",
1161
+ "bbox": [
1162
+ 174,
1163
+ 587,
1164
+ 826,
1165
+ 643
1166
+ ],
1167
+ "page_idx": 10
1168
+ },
1169
+ {
1170
+ "type": "text",
1171
+ "text": "Alex Nichol, Prafulla Dhariwal, Aditya Ramesh, Pranav Shyam, Pamela Mishkin, Bob McGrew, Ilya Sutskever, and Mark Chen. Glide: Towards photorealistic image generation and editing with text-guided diffusion models. ICML, 2021. ",
1172
+ "bbox": [
1173
+ 174,
1174
+ 651,
1175
+ 823,
1176
+ 695
1177
+ ],
1178
+ "page_idx": 10
1179
+ },
1180
+ {
1181
+ "type": "text",
1182
+ "text": "Dong Huk Park, Samaneh Azadi, Xihui Liu, Trevor Darrell, and Anna Rohrbach. Benchmark for compositional text-to-image synthesis. In Thirty-fifth Conference on Neural Information Processing Systems Datasets and Benchmarks Track (Round 1), 2021. ",
1183
+ "bbox": [
1184
+ 174,
1185
+ 702,
1186
+ 825,
1187
+ 746
1188
+ ],
1189
+ "page_idx": 10
1190
+ },
1191
+ {
1192
+ "type": "text",
1193
+ "text": "Peng Qi, Yuhao Zhang, Yuhui Zhang, Jason Bolton, and Christopher D. Manning. Stanza: A Python natural language processing toolkit for many human languages. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics: System Demonstrations, 2020. ",
1194
+ "bbox": [
1195
+ 174,
1196
+ 752,
1197
+ 825,
1198
+ 796
1199
+ ],
1200
+ "page_idx": 10
1201
+ },
1202
+ {
1203
+ "type": "text",
1204
+ "text": "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. ",
1205
+ "bbox": [
1206
+ 174,
1207
+ 803,
1208
+ 826,
1209
+ 859
1210
+ ],
1211
+ "page_idx": 10
1212
+ },
1213
+ {
1214
+ "type": "text",
1215
+ "text": "Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, and Peter J. Liu. Exploring the limits of transfer learning with a unified text-to-text transformer. Journal of Machine Learning Research, 21(140):1–67, 2020. URL http://jmlr.org/papers/v21/20-074.html. ",
1216
+ "bbox": [
1217
+ 174,
1218
+ 867,
1219
+ 825,
1220
+ 924
1221
+ ],
1222
+ "page_idx": 10
1223
+ },
1224
+ {
1225
+ "type": "text",
1226
+ "text": "Aditya Ramesh, Mikhail Pavlov, Gabriel Goh, Scott Gray, Chelsea Voss, Alec Radford, Mark Chen, and Ilya Sutskever. Zero-shot text-to-image generation. In International Conference on Machine Learning, pp. 8821–8831. PMLR, 2021. ",
1227
+ "bbox": [
1228
+ 174,
1229
+ 103,
1230
+ 823,
1231
+ 146
1232
+ ],
1233
+ "page_idx": 11
1234
+ },
1235
+ {
1236
+ "type": "text",
1237
+ "text": "Aditya Ramesh, Prafulla Dhariwal, Alex Nichol, Casey Chu, and Mark Chen. Hierarchical textconditional image generation with clip latents. arXiv preprint arXiv:2204.06125, 2022. ",
1238
+ "bbox": [
1239
+ 171,
1240
+ 154,
1241
+ 825,
1242
+ 184
1243
+ ],
1244
+ "page_idx": 11
1245
+ },
1246
+ {
1247
+ "type": "text",
1248
+ "text": "Robin Rombach, Andreas Blattmann, Dominik Lorenz, Patrick Esser, and Bjorn Ommer. High- ¨ resolution image synthesis with latent diffusion models. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 10684–10695, 2022. ",
1249
+ "bbox": [
1250
+ 174,
1251
+ 190,
1252
+ 825,
1253
+ 234
1254
+ ],
1255
+ "page_idx": 11
1256
+ },
1257
+ {
1258
+ "type": "text",
1259
+ "text": "Olaf Ronneberger, Philipp Fischer, and Thomas Brox. U-net: Convolutional networks for biomedical image segmentation. In International Conference on Medical image computing and computerassisted intervention, pp. 234–241. Springer, 2015. ",
1260
+ "bbox": [
1261
+ 176,
1262
+ 242,
1263
+ 825,
1264
+ 286
1265
+ ],
1266
+ "page_idx": 11
1267
+ },
1268
+ {
1269
+ "type": "text",
1270
+ "text": "Nataniel Ruiz, Yuanzhen Li, Varun Jampani, Yael Pritch, Michael Rubinstein, and Kfir Aberman. Dreambooth: Fine tuning text-to-image diffusion models for subject-driven generation. arXiv preprint arXiv:2208.12242, 2022. ",
1271
+ "bbox": [
1272
+ 176,
1273
+ 292,
1274
+ 825,
1275
+ 335
1276
+ ],
1277
+ "page_idx": 11
1278
+ },
1279
+ {
1280
+ "type": "text",
1281
+ "text": "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, et al. Photorealistic text-to-image diffusion models with deep language understanding. arXiv preprint arXiv:2205.11487, 2022. ",
1282
+ "bbox": [
1283
+ 173,
1284
+ 343,
1285
+ 826,
1286
+ 401
1287
+ ],
1288
+ "page_idx": 11
1289
+ },
1290
+ {
1291
+ "type": "text",
1292
+ "text": "Tim Salimans, Ian Goodfellow, Wojciech Zaremba, Vicki Cheung, Alec Radford, and Xi Chen. Improved techniques for training gans. Advances in neural information processing systems, 29, 2016. ",
1293
+ "bbox": [
1294
+ 174,
1295
+ 409,
1296
+ 826,
1297
+ 452
1298
+ ],
1299
+ "page_idx": 11
1300
+ },
1301
+ {
1302
+ "type": "text",
1303
+ "text": "Sebastian Schuster, Ranjay Krishna, Angel Chang, Li Fei-Fei, and Christopher D Manning. Generating semantically precise scene graphs from textual descriptions for improved image retrieval. In Proceedings of the fourth workshop on vision and language, pp. 70–80, 2015. ",
1304
+ "bbox": [
1305
+ 174,
1306
+ 459,
1307
+ 826,
1308
+ 503
1309
+ ],
1310
+ "page_idx": 11
1311
+ },
1312
+ {
1313
+ "type": "text",
1314
+ "text": "Yang Song and Stefano Ermon. Generative modeling by estimating gradients of the data distribution. Advances in Neural Information Processing Systems, 32, 2019. ",
1315
+ "bbox": [
1316
+ 174,
1317
+ 511,
1318
+ 823,
1319
+ 540
1320
+ ],
1321
+ "page_idx": 11
1322
+ },
1323
+ {
1324
+ "type": "text",
1325
+ "text": "Ming Tao, Hao Tang, Fei Wu, Xiao-Yuan Jing, Bing-Kun Bao, and Changsheng Xu. Df-gan: A simple and effective baseline for text-to-image synthesis. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 16515–16525, 2022. ",
1326
+ "bbox": [
1327
+ 174,
1328
+ 546,
1329
+ 826,
1330
+ 590
1331
+ ],
1332
+ "page_idx": 11
1333
+ },
1334
+ {
1335
+ "type": "text",
1336
+ "text": "Tristan Thrush, Ryan Jiang, Max Bartolo, Amanpreet Singh, Adina Williams, Douwe Kiela, and Candace Ross. Winoground: Probing vision and language models for visio-linguistic compositionality. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 5238–5248, 2022. ",
1337
+ "bbox": [
1338
+ 173,
1339
+ 598,
1340
+ 826,
1341
+ 656
1342
+ ],
1343
+ "page_idx": 11
1344
+ },
1345
+ {
1346
+ "type": "text",
1347
+ "text": "Bo Wan, Wenjuan Han, Zilong Zheng, and Tinne Tuytelaars. Unsupervised vision-language grammar induction with shared structure modeling. In International Conference on Learning Representations, 2021. ",
1348
+ "bbox": [
1349
+ 171,
1350
+ 662,
1351
+ 823,
1352
+ 707
1353
+ ],
1354
+ "page_idx": 11
1355
+ },
1356
+ {
1357
+ "type": "text",
1358
+ "text": "Hao Wu, Jiayuan Mao, Yufeng Zhang, Yuning Jiang, Lei Li, Weiwei Sun, and Wei-Ying Ma. Unified visual-semantic embeddings: Bridging vision and language with structured meaning representations. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 6609–6618, 2019. ",
1359
+ "bbox": [
1360
+ 173,
1361
+ 714,
1362
+ 826,
1363
+ 770
1364
+ ],
1365
+ "page_idx": 11
1366
+ },
1367
+ {
1368
+ "type": "text",
1369
+ "text": "Zuopeng Yang, Daqing Liu, Chaoyue Wang, Jie Yang, and Dacheng Tao. Modeling image composition for complex scene generation. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 7764–7773, 2022. ",
1370
+ "bbox": [
1371
+ 173,
1372
+ 779,
1373
+ 823,
1374
+ 821
1375
+ ],
1376
+ "page_idx": 11
1377
+ },
1378
+ {
1379
+ "type": "text",
1380
+ "text": "Jiahui Yu, Yuanzhong Xu, Jing Yu Koh, Thang Luong, Gunjan Baid, Zirui Wang, Vijay Vasudevan, Alexander Ku, Yinfei Yang, Burcu Karagol Ayan, et al. Scaling autoregressive models for contentrich text-to-image generation. arXiv preprint arXiv:2206.10789, 2022. ",
1381
+ "bbox": [
1382
+ 174,
1383
+ 830,
1384
+ 825,
1385
+ 873
1386
+ ],
1387
+ "page_idx": 11
1388
+ },
1389
+ {
1390
+ "type": "text",
1391
+ "text": "Han Zhang, Jing Yu Koh, Jason Baldridge, Honglak Lee, and Yinfei Yang. Cross-modal contrastive learning for text-to-image generation. In Proceedings of the IEEE/CVF conference on computer vision and pattern recognition, pp. 833–842, 2021. ",
1392
+ "bbox": [
1393
+ 174,
1394
+ 882,
1395
+ 825,
1396
+ 924
1397
+ ],
1398
+ "page_idx": 11
1399
+ },
1400
+ {
1401
+ "type": "text",
1402
+ "text": "Yiwu Zhong, Liwei Wang, Jianshu Chen, Dong Yu, and Yin Li. Comprehensive image captioning via scene graph decomposition. In European Conference on Computer Vision, pp. 211–229. Springer, 2020. ",
1403
+ "bbox": [
1404
+ 176,
1405
+ 103,
1406
+ 825,
1407
+ 145
1408
+ ],
1409
+ "page_idx": 12
1410
+ },
1411
+ {
1412
+ "type": "text",
1413
+ "text": "Yufan Zhou, Ruiyi Zhang, Changyou Chen, Chunyuan Li, Chris Tensmeyer, Tong Yu, Jiuxiang Gu, Jinhui Xu, and Tong Sun. Towards language-free training for text-to-image generation. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 17907–17917, 2022. ",
1414
+ "bbox": [
1415
+ 176,
1416
+ 154,
1417
+ 826,
1418
+ 210
1419
+ ],
1420
+ "page_idx": 12
1421
+ },
1422
+ {
1423
+ "type": "text",
1424
+ "text": "Minfeng Zhu, Pingbo Pan, Wei Chen, and Yi Yang. Dm-gan: Dynamic memory generative adversarial networks for text-to-image synthesis. In Proceedings of the IEEE/CVF conference on computer vision and pattern recognition, pp. 5802–5810, 2019. ",
1425
+ "bbox": [
1426
+ 174,
1427
+ 218,
1428
+ 825,
1429
+ 261
1430
+ ],
1431
+ "page_idx": 12
1432
+ },
1433
+ {
1434
+ "type": "text",
1435
+ "text": "A RELATED WORK ",
1436
+ "text_level": 1,
1437
+ "bbox": [
1438
+ 176,
1439
+ 286,
1440
+ 348,
1441
+ 303
1442
+ ],
1443
+ "page_idx": 12
1444
+ },
1445
+ {
1446
+ "type": "text",
1447
+ "text": "Text-to-Image Synthesis There are mainly three types of models for text-to-image synthesis: GAN-based (Tao et al., 2022; Zhu et al., 2019; Li et al., 2019; Fu et al., 2020; El-Nouby et al., 2019), autoregressive (Gu et al., 2022b; Lee et al., 2022; Ding et al., 2022) and diffusion models (Liu et al., 2021b; Nichol et al., 2021; Ruiz et al., 2022). Zhang et al. (2021) proposes XMC-GAN, a one-stage GAN that employs multiple contrastive losses between image-image, image-text, and region-token pairs. More recently, LAFITE (Zhou et al., 2022) enables language-free training by constructing pseudo image-text feature pairs using CLIP (Radford et al., 2021). As for autoregressive models, DALL-E adopts VQ-VAE to quantize image patches into tokens and then uses a transformer to generate discrete tokens sequentially (Ramesh et al., 2021). Parti (Yu et al., 2022) and Make-A-Scene (Gafni et al., 2022) both leverage classifier-free guidance to improve controllability. As for diffusion models, Gu et al. (2022a) concatenates VQ-VAE with the diffusion model and shows that the diffusion process can operate in discrete latent space. DALL-E 2 adopts the CLIP text encoder so that the diffusion process inverts the textual features into images (Ramesh et al., 2022). ",
1448
+ "bbox": [
1449
+ 174,
1450
+ 318,
1451
+ 825,
1452
+ 497
1453
+ ],
1454
+ "page_idx": 12
1455
+ },
1456
+ {
1457
+ "type": "text",
1458
+ "text": "Structured Representations for Vision and Language Inferring shared structures across language and vision has been a long-term pursuit in unifying these modalities (Schuster et al., 2015; Johnson et al., 2018; Zhong et al., 2020; Lou et al., 2022). Wu et al. (2019) utilizes the structure from semantic parsing in a visual-semantic embedding framework to facilitate embedding learning. Wan et al. (2021) proposes a new task in which the goal is to learn a joint structure between semantic parsing and image regions. To the best of our knowledge, our work is the first attempt in T2I to incorporate language structures into the image synthesizing process. ",
1459
+ "bbox": [
1460
+ 174,
1461
+ 513,
1462
+ 825,
1463
+ 611
1464
+ ],
1465
+ "page_idx": 12
1466
+ },
1467
+ {
1468
+ "type": "text",
1469
+ "text": "Diffusion Guidance To convert an unconditional diffusion model into a class-conditional one, Dhariwal & Nichol (2021) input the noisy image from each step into a classifier and calculate the classification loss. The loss can be back-propagated to the image space to provide a gradient that marginalizes the score estimation from the log of conditional probability. Similarly, in the T2I subdomain, Liu et al. (2021b) and Nichol et al. (2021) apply a noisy CLIP model to measure the cosine similarity between text prompts and noisy images. ",
1470
+ "bbox": [
1471
+ 174,
1472
+ 626,
1473
+ 825,
1474
+ 709
1475
+ ],
1476
+ "page_idx": 12
1477
+ },
1478
+ {
1479
+ "type": "text",
1480
+ "text": "B IMPLEMENTATION DETAILS ",
1481
+ "text_level": 1,
1482
+ "bbox": [
1483
+ 176,
1484
+ 729,
1485
+ 439,
1486
+ 744
1487
+ ],
1488
+ "page_idx": 12
1489
+ },
1490
+ {
1491
+ "type": "text",
1492
+ "text": "Throughout the experiments, we implement our method upon Stable Diffusion v1.4. For all comparisons between our method and Stable Diffusion, we fix the seed to generate the same initial Gaussian map and use 50 diffusion steps with PLMS sampling (Liu et al., 2021a). We fix the guidance scale to 7.5 and equally weight the key-value matrices in cross-attention layers if not otherwise specified. We do not add hand-crafted prompts such as “a photo of” to the text input. We use the Stanza Library (Qi et al., 2020) for constituency parsing and obtain noun phrases if not otherwise specified. ",
1493
+ "bbox": [
1494
+ 174,
1495
+ 760,
1496
+ 825,
1497
+ 844
1498
+ ],
1499
+ "page_idx": 12
1500
+ },
1501
+ {
1502
+ "type": "text",
1503
+ "text": "C VISUALIZATION OF ATTENTION MAPS ",
1504
+ "text_level": 1,
1505
+ "bbox": [
1506
+ 174,
1507
+ 864,
1508
+ 529,
1509
+ 880
1510
+ ],
1511
+ "page_idx": 12
1512
+ },
1513
+ {
1514
+ "type": "text",
1515
+ "text": "In this section, we demonstrate the visualization of cross-attention maps to support our assumptions and claims in Sec. 2. As is shown in Fig. 8, the attention maps of Stable Diffusion and our method have similar spatial distribution and highlights throughout the diffusion process. This phenomenon supports our assumption in Sec. 2.2 that the attention map $M _ { t }$ is unchanged even with multiple values in each cross-attention layer. We can observe a similar phenomenon in Fig. 9 except that our method accelerates the formation of interpretable attentions for both “green” and “clock” tokens. ",
1516
+ "bbox": [
1517
+ 173,
1518
+ 895,
1519
+ 823,
1520
+ 924
1521
+ ],
1522
+ "page_idx": 12
1523
+ },
1524
+ {
1525
+ "type": "image",
1526
+ "img_path": "images/e22e2d5e7ace9b5fbcfe4a7cc12e67be8180444f5dc3271034867469bdbfde5a.jpg",
1527
+ "image_caption": [
1528
+ "Figure 8: Visualization of cross attention maps of Stable Diffusion and our method. We compare maps of multiple tokens throughout the whole diffusion process with equal intervals. "
1529
+ ],
1530
+ "image_footnote": [],
1531
+ "bbox": [
1532
+ 176,
1533
+ 103,
1534
+ 820,
1535
+ 536
1536
+ ],
1537
+ "page_idx": 13
1538
+ },
1539
+ {
1540
+ "type": "text",
1541
+ "text": "",
1542
+ "bbox": [
1543
+ 174,
1544
+ 694,
1545
+ 825,
1546
+ 750
1547
+ ],
1548
+ "page_idx": 13
1549
+ },
1550
+ {
1551
+ "type": "text",
1552
+ "text": "Fig. 8, 9 also justify our claim that values represent rich textual semantics mapped to the image space as contents. For instance, our method parses the prompt in Fig. 8 into “A long narrow yellow kitchen” and “black and white floor tiles”, encodes and aligns them separately to form V. Empirically, these operations enhance the semantics of “yellow” and “black and white” separately and mitigate “yellow” being blended into “black and white”. This explains the disappearance of color leakage in our image compared to Stable Diffusion. Though one may attribute the leakage to incorrect attention distribution of the “yellow” token, we argue that this is not the critical reason. Despite the attention maps of “yellow” from our method slightly highlighting the “floor tile” regions, we cannot observe any yellow in our generated image. This proves that inaccurate attention distributions contribute little to the final image content. In addition, we also show in Fig. 10 that using multiple Keys is able to rectify the image layouts to mitigate missing object issues. The sheep-like attention maps in the third row verify the proposed variants of our method for concept conjunctions. ",
1553
+ "bbox": [
1554
+ 173,
1555
+ 757,
1556
+ 825,
1557
+ 924
1558
+ ],
1559
+ "page_idx": 13
1560
+ },
1561
+ {
1562
+ "type": "image",
1563
+ "img_path": "images/0be7b80d0f76ab47ff37221209affb8a234d6aaf76276fa61011c736050abb18.jpg",
1564
+ "image_caption": [
1565
+ "Figure 9: Visualization of cross attention maps corresponding to token “green” and “clock” across the full diffusion timestamps from step 50 to step 1 in equal intervals. Red boxes highlight steps where our method accelerates the formation of correct attention on the clock region. The evolution of the token “green” is also more interpretable in our method. Although the image composition is imperfect, the visualization still supports our assumptions and claims in Sec. 2.2. "
1566
+ ],
1567
+ "image_footnote": [],
1568
+ "bbox": [
1569
+ 179,
1570
+ 107,
1571
+ 812,
1572
+ 325
1573
+ ],
1574
+ "page_idx": 14
1575
+ },
1576
+ {
1577
+ "type": "image",
1578
+ "img_path": "images/6ce94909eda492a7e78221376ea5b39def302a7a1f5a92084ca40943ea3a1fda.jpg",
1579
+ "image_caption": [
1580
+ "Figure 10: Visualization of attention maps for token “sheep” of different methods. Our method with multiple Keys successfully rectify image layouts. "
1581
+ ],
1582
+ "image_footnote": [],
1583
+ "bbox": [
1584
+ 178,
1585
+ 433,
1586
+ 821,
1587
+ 734
1588
+ ],
1589
+ "page_idx": 14
1590
+ },
1591
+ {
1592
+ "type": "text",
1593
+ "text": "D ABLATION STUDY ",
1594
+ "text_level": 1,
1595
+ "bbox": [
1596
+ 174,
1597
+ 806,
1598
+ 361,
1599
+ 823
1600
+ ],
1601
+ "page_idx": 14
1602
+ },
1603
+ {
1604
+ "type": "text",
1605
+ "text": "D.1 A CASE STUDY OF ATTRIBUTE BINDING ",
1606
+ "text_level": 1,
1607
+ "bbox": [
1608
+ 174,
1609
+ 840,
1610
+ 491,
1611
+ 854
1612
+ ],
1613
+ "page_idx": 14
1614
+ },
1615
+ {
1616
+ "type": "text",
1617
+ "text": "Here, we present a case study to show evidence of two root causes of incorrect attribute binding. The first one is the contextualized token embeddings due to causal attention masks. As is shown on the left side of Fig. 11, we first encode two different prompts with a shared component, e.g. “a red apple” as the naive one and “a green bag and a red apple”. Using the encoding sequence of the naive prompt, we are able to get an image of red apple only. It is reasonable to assume that the yellow green regions are natural results of learning from authentic apple images. Then, we replace the tokens of the naive prompt with embeddings of the same token from the more complicated prompt. We use the same gaussian noise as initialization and generate an unnatural image with a solid green region (in the yellow bounding box). This result proves that the token “red” is contaminated with the semantics of “green” before it and explains some images with color leakage problems (e.g., Fig. 1). ",
1618
+ "bbox": [
1619
+ 174,
1620
+ 867,
1621
+ 826,
1622
+ 924
1623
+ ],
1624
+ "page_idx": 14
1625
+ },
1626
+ {
1627
+ "type": "image",
1628
+ "img_path": "images/3523608906863534f4a3e158ef3281942b6bb6822477164e5d40472b91acf880.jpg",
1629
+ "image_caption": [
1630
+ "Figure 11: Examples showing the potential root causes of incorrect attribute binding. Left: The large green regions in the second image prove that the hidden state’s output of token “red” is contextualized with token “green” before it. Right: Visualization of attention maps showing that the semantics from the token “bird” is mistakenly attended to the mouth region of the bear. The final image shows the unnatural beak-like shape of the bear. "
1631
+ ],
1632
+ "image_footnote": [],
1633
+ "bbox": [
1634
+ 179,
1635
+ 103,
1636
+ 818,
1637
+ 343
1638
+ ],
1639
+ "page_idx": 15
1640
+ },
1641
+ {
1642
+ "type": "text",
1643
+ "text": "",
1644
+ "bbox": [
1645
+ 174,
1646
+ 457,
1647
+ 825,
1648
+ 541
1649
+ ],
1650
+ "page_idx": 15
1651
+ },
1652
+ {
1653
+ "type": "text",
1654
+ "text": "The second reason attributes to inaccurate attention maps. In Fig. 11 (right), we visualize five crossattention maps (averaged across attention heads) from both downsample and upsampling blocks. The attention maps show the salient regions corresponding to the token “bird”. These maps demonstrate highlighted regions in the bottom left corner where the bird is located in the final image. Despite the interpretable structures, the maps also show saliency around the mouth region of the bear across all five layers. Thus, the inaccurate attention maps lead to a beak-like mouth of the bear in the image. ",
1655
+ "bbox": [
1656
+ 174,
1657
+ 547,
1658
+ 825,
1659
+ 631
1660
+ ],
1661
+ "page_idx": 15
1662
+ },
1663
+ {
1664
+ "type": "text",
1665
+ "text": "D.2 COMPARISON OF PARSERS ",
1666
+ "text_level": 1,
1667
+ "bbox": [
1668
+ 176,
1669
+ 648,
1670
+ 401,
1671
+ 662
1672
+ ],
1673
+ "page_idx": 15
1674
+ },
1675
+ {
1676
+ "type": "text",
1677
+ "text": "In this subsection, we compare the difference between using a constituency parser and a scene graph parser to obtain text spans and generate images. Table 3 compares the extracted text spans using constituency parser and scene graph parser. Example 0 shows that both parsers end up with the same results for CC-500 prompts. For Example 1-4, the scene graph parser generates more spans than the constituency parser. We notice that concepts in the middle of the sentence appear more often in these spans than other noun tokens, like “egg” or “red sauce” in Example 3. This imbalance potentially explains why the “egg” looks more highlighted in Fig. 12 (bottom left). On the other hand, “orange slices” appear more often in constituency parsing results, leading to better “orange” textures in the generated image. Similar observations can be made in Example 2, where “green pole” is emphasized more often by the constituency parser. ",
1678
+ "bbox": [
1679
+ 174,
1680
+ 675,
1681
+ 825,
1682
+ 815
1683
+ ],
1684
+ "page_idx": 15
1685
+ },
1686
+ {
1687
+ "type": "text",
1688
+ "text": "E LIMITATIONS & FUTURE WORK ",
1689
+ "text_level": 1,
1690
+ "bbox": [
1691
+ 176,
1692
+ 835,
1693
+ 472,
1694
+ 852
1695
+ ],
1696
+ "page_idx": 15
1697
+ },
1698
+ {
1699
+ "type": "text",
1700
+ "text": "There are several limitations of our work. First of all, our method depends on an external parsing function that may not be perfect. We adopt the commonly used Stanza Library Qi et al. (2020) for constituency parsing. The parsing function can be replaced with a more advanced learning-based method for improvement. Secondly, our method mainly focuses on compositional T2I neglecting any style descriptions. The parsing mechanism may categorize a style description, e.g. “in Van Gogh style” as a separate noun phrase that cannot be grounded in the image space. In addition, we discover that StructureDiffusion tends to generate similar images as Stable Diffusion. Thus we filtered out $20 \\%$ of most similar image pairs in Table 1, considering the efficiency of human evaluation. Therefore, the improvement could be compromised when evaluated on the full set of generated images. Future work may focus on devising explicit methods to associate attributes to objects using spatial information as input. For example, how to make a text-to-image synthesis model interpret coordinate information with limited fine-tuning or prompt tuning steps would be an appealing direction. ",
1701
+ "bbox": [
1702
+ 176,
1703
+ 867,
1704
+ 823,
1705
+ 924
1706
+ ],
1707
+ "page_idx": 15
1708
+ },
1709
+ {
1710
+ "type": "table",
1711
+ "img_path": "images/cf2ac2229777fca8ab753b0b0931fc8b755d2babbe943c720cb68e3f85f4a463.jpg",
1712
+ "table_caption": [
1713
+ "Table 3: Comparison between the constituency parser and scene graph parser. For CC-500 prompts, both parsers end up with the same results. As for general prompts, scene graph parser tends to generate more text spans with middle concepts appearing multiple times across different spans. "
1714
+ ],
1715
+ "table_footnote": [],
1716
+ "table_body": "<table><tr><td rowspan=1 colspan=1></td><td rowspan=1 colspan=1>Constituency Parser</td><td rowspan=1 colspan=1>Scene Graph Parser</td></tr><tr><td rowspan=2 colspan=1>Example 0</td><td rowspan=1 colspan=2>CC-500 Prompt: A white sheep and a red car</td></tr><tr><td rowspan=1 colspan=1>“A white sheep”,“a red car”</td><td rowspan=1 colspan=1>“A white sheep”,“a red car”</td></tr><tr><td rowspan=2 colspan=1>Example 1</td><td rowspan=1 colspan=2>Prompt: A silver car with a black cat sleeping on top of it</td></tr><tr><td rowspan=1 colspan=1>“A silver car”,“a black cat”,“A silver car with a black cat”</td><td rowspan=1 colspan=1>“A silver car”,&quot;a black cat”,“top of it”,“a black cat sleeping on top of it&quot;</td></tr><tr><td rowspan=2 colspan=1>Example 2</td><td rowspan=1 colspan=2>Prompt:A horse running in a white field next to a black and green pole</td></tr><tr><td rowspan=1 colspan=1>“Ahorse”,“a white feld&quot;,“a black and green pole&quot;,“a white field next to a black and green pole”</td><td rowspan=1 colspan=1>“Ahorse”,“a white field”,“a black and green pole”,“A horse running in a white field&quot;</td></tr><tr><td rowspan=2 colspan=1>Example 3</td><td rowspan=1 colspan=2>Prompt:Rice with red sauce with eggs over the top and orange slices on the side</td></tr><tr><td rowspan=1 colspan=1>“red sauce”,“the side”,“the top and orange slices”,“the top and orange slices on the side&quot;</td><td rowspan=1 colspan=1>“red sauce”,“the side”,“the top and orange slices”,“Rice with red sauce”,“red sauce with eggs”,“the top and orange slices on the side&quot;,“red sauce with eggs over the top and orange slices”</td></tr><tr><td rowspan=2 colspan=1>Example 4</td><td rowspan=1 colspan=2>Prompt:A pink scooter with a black seat next to a blue car</td></tr><tr><td rowspan=1 colspan=1>“A pink scooter”,“a black seat”,“a blue car”</td><td rowspan=1 colspan=1>“A pink scooter”,“a black seat”,“a blue car”,&quot;a pink scooter with a black seat&quot;,“a black seat next to a blue car”</td></tr></table>",
1717
+ "bbox": [
1718
+ 173,
1719
+ 102,
1720
+ 821,
1721
+ 400
1722
+ ],
1723
+ "page_idx": 16
1724
+ },
1725
+ {
1726
+ "type": "image",
1727
+ "img_path": "images/5505e9c9fabb63da9b36d9e776d538f607231efc48fb6c2f6bc627e1951a2d11.jpg",
1728
+ "image_caption": [
1729
+ "Figure 12: Synthesized images corresponding to prompts in Table 3. Yellow boxes annotate compositions that are improved using different parsers. "
1730
+ ],
1731
+ "image_footnote": [],
1732
+ "bbox": [
1733
+ 179,
1734
+ 468,
1735
+ 821,
1736
+ 696
1737
+ ],
1738
+ "page_idx": 16
1739
+ },
1740
+ {
1741
+ "type": "text",
1742
+ "text": "",
1743
+ "bbox": [
1744
+ 174,
1745
+ 766,
1746
+ 825,
1747
+ 878
1748
+ ],
1749
+ "page_idx": 16
1750
+ },
1751
+ {
1752
+ "type": "image",
1753
+ "img_path": "images/9a323a017b67c428078490d9067e77f606d8f54878028c43b59103d5e505fc9b.jpg",
1754
+ "image_caption": [
1755
+ "Figure 13: Qualitative results on CC-500 "
1756
+ ],
1757
+ "image_footnote": [],
1758
+ "bbox": [
1759
+ 179,
1760
+ 55,
1761
+ 820,
1762
+ 883
1763
+ ],
1764
+ "page_idx": 17
1765
+ },
1766
+ {
1767
+ "type": "text",
1768
+ "text": "Stable Diffusion ",
1769
+ "text_level": 1,
1770
+ "bbox": [
1771
+ 200,
1772
+ 164,
1773
+ 267,
1774
+ 193
1775
+ ],
1776
+ "page_idx": 18
1777
+ },
1778
+ {
1779
+ "type": "text",
1780
+ "text": "Ours ",
1781
+ "text_level": 1,
1782
+ "bbox": [
1783
+ 312,
1784
+ 171,
1785
+ 352,
1786
+ 184
1787
+ ],
1788
+ "page_idx": 18
1789
+ },
1790
+ {
1791
+ "type": "text",
1792
+ "text": "Stable Diffusion ",
1793
+ "text_level": 1,
1794
+ "bbox": [
1795
+ 416,
1796
+ 164,
1797
+ 483,
1798
+ 193
1799
+ ],
1800
+ "page_idx": 18
1801
+ },
1802
+ {
1803
+ "type": "text",
1804
+ "text": "Ours ",
1805
+ "text_level": 1,
1806
+ "bbox": [
1807
+ 529,
1808
+ 171,
1809
+ 568,
1810
+ 185
1811
+ ],
1812
+ "page_idx": 18
1813
+ },
1814
+ {
1815
+ "type": "text",
1816
+ "text": "Stable Diffusion ",
1817
+ "text_level": 1,
1818
+ "bbox": [
1819
+ 632,
1820
+ 164,
1821
+ 699,
1822
+ 193
1823
+ ],
1824
+ "page_idx": 18
1825
+ },
1826
+ {
1827
+ "type": "text",
1828
+ "text": "Ours ",
1829
+ "text_level": 1,
1830
+ "bbox": [
1831
+ 745,
1832
+ 171,
1833
+ 782,
1834
+ 184
1835
+ ],
1836
+ "page_idx": 18
1837
+ },
1838
+ {
1839
+ "type": "text",
1840
+ "text": "a purple cat with a orange hat on its head ",
1841
+ "bbox": [
1842
+ 189,
1843
+ 199,
1844
+ 379,
1845
+ 224
1846
+ ],
1847
+ "page_idx": 18
1848
+ },
1849
+ {
1850
+ "type": "text",
1851
+ "text": "A red cat sits on a rug with a black cord ",
1852
+ "bbox": [
1853
+ 410,
1854
+ 200,
1855
+ 588,
1856
+ 227
1857
+ ],
1858
+ "page_idx": 18
1859
+ },
1860
+ {
1861
+ "type": "text",
1862
+ "text": "A yellow cat is wearing a blue plastic baseball hat. ",
1863
+ "bbox": [
1864
+ 620,
1865
+ 199,
1866
+ 805,
1867
+ 226
1868
+ ],
1869
+ "page_idx": 18
1870
+ },
1871
+ {
1872
+ "type": "image",
1873
+ "img_path": "images/660bc275b91b59866cd20e3a88baefb5a552b3ad21116d920fca9476c0987944.jpg",
1874
+ "image_caption": [],
1875
+ "image_footnote": [],
1876
+ "bbox": [
1877
+ 400,
1878
+ 229,
1879
+ 598,
1880
+ 305
1881
+ ],
1882
+ "page_idx": 18
1883
+ },
1884
+ {
1885
+ "type": "image",
1886
+ "img_path": "images/44f8df4e6174cfaee77c876deda6de6350198075800255d17326b31cbf9a0166.jpg",
1887
+ "image_caption": [],
1888
+ "image_footnote": [],
1889
+ "bbox": [
1890
+ 614,
1891
+ 231,
1892
+ 810,
1893
+ 306
1894
+ ],
1895
+ "page_idx": 18
1896
+ },
1897
+ {
1898
+ "type": "image",
1899
+ "img_path": "images/26a9991969c15534788eae2f5acc0d8cda40c915d13508aea40a64234a837dfe.jpg",
1900
+ "image_caption": [
1901
+ "A red helmet is on a yellow toilet in the dirt "
1902
+ ],
1903
+ "image_footnote": [],
1904
+ "bbox": [
1905
+ 186,
1906
+ 229,
1907
+ 382,
1908
+ 305
1909
+ ],
1910
+ "page_idx": 18
1911
+ },
1912
+ {
1913
+ "type": "text",
1914
+ "text": "A red stop sign above a white walk across road sign ",
1915
+ "bbox": [
1916
+ 408,
1917
+ 327,
1918
+ 591,
1919
+ 353
1920
+ ],
1921
+ "page_idx": 18
1922
+ },
1923
+ {
1924
+ "type": "text",
1925
+ "text": "Two elephants walking by a green wall with tan palm trees painted on it ",
1926
+ "bbox": [
1927
+ 619,
1928
+ 318,
1929
+ 808,
1930
+ 357
1931
+ ],
1932
+ "page_idx": 18
1933
+ },
1934
+ {
1935
+ "type": "image",
1936
+ "img_path": "images/cfd38b6e692be180d8d214269d4b921af9c6ea51e92262d22844436ebebe2b8b.jpg",
1937
+ "image_caption": [],
1938
+ "image_footnote": [],
1939
+ "bbox": [
1940
+ 184,
1941
+ 359,
1942
+ 380,
1943
+ 435
1944
+ ],
1945
+ "page_idx": 18
1946
+ },
1947
+ {
1948
+ "type": "image",
1949
+ "img_path": "images/408e26c582eccff899a6069e2265d99daf61980c8cc47f66c6c8328d8054ffd6.jpg",
1950
+ "image_caption": [],
1951
+ "image_footnote": [],
1952
+ "bbox": [
1953
+ 401,
1954
+ 359,
1955
+ 598,
1956
+ 436
1957
+ ],
1958
+ "page_idx": 18
1959
+ },
1960
+ {
1961
+ "type": "image",
1962
+ "img_path": "images/7c5f1e143277e8913a928bce5fd0f6aacb27ceb05fed39986d71058a5a715923.jpg",
1963
+ "image_caption": [],
1964
+ "image_footnote": [],
1965
+ "bbox": [
1966
+ 616,
1967
+ 359,
1968
+ 810,
1969
+ 436
1970
+ ],
1971
+ "page_idx": 18
1972
+ },
1973
+ {
1974
+ "type": "text",
1975
+ "text": "A bathroom with red tile and a green shower curtain ",
1976
+ "text_level": 1,
1977
+ "bbox": [
1978
+ 186,
1979
+ 458,
1980
+ 379,
1981
+ 484
1982
+ ],
1983
+ "page_idx": 18
1984
+ },
1985
+ {
1986
+ "type": "text",
1987
+ "text": "A spacious kitchen has white walls , red countertops , and a large stove ",
1988
+ "bbox": [
1989
+ 406,
1990
+ 450,
1991
+ 593,
1992
+ 491
1993
+ ],
1994
+ "page_idx": 18
1995
+ },
1996
+ {
1997
+ "type": "text",
1998
+ "text": "A large white bed sitting in a hotel room next to a red couch ",
1999
+ "bbox": [
2000
+ 624,
2001
+ 450,
2002
+ 802,
2003
+ 491
2004
+ ],
2005
+ "page_idx": 18
2006
+ },
2007
+ {
2008
+ "type": "image",
2009
+ "img_path": "images/4a43f884cd58a3781a856b40d946e06aa95a3781630c49ecd2683d6082a67e4e.jpg",
2010
+ "image_caption": [],
2011
+ "image_footnote": [],
2012
+ "bbox": [
2013
+ 183,
2014
+ 492,
2015
+ 379,
2016
+ 568
2017
+ ],
2018
+ "page_idx": 18
2019
+ },
2020
+ {
2021
+ "type": "image",
2022
+ "img_path": "images/91f6e969166829de16eb4f631fbb73f19ef0d5390410d037d4a690f99df02786.jpg",
2023
+ "image_caption": [],
2024
+ "image_footnote": [],
2025
+ "bbox": [
2026
+ 401,
2027
+ 492,
2028
+ 598,
2029
+ 568
2030
+ ],
2031
+ "page_idx": 18
2032
+ },
2033
+ {
2034
+ "type": "image",
2035
+ "img_path": "images/c40deaf2eb3b4751d7c5816cee4083bcc77c9b78e322402b3ca26513daf3706d.jpg",
2036
+ "image_caption": [],
2037
+ "image_footnote": [],
2038
+ "bbox": [
2039
+ 616,
2040
+ 492,
2041
+ 812,
2042
+ 568
2043
+ ],
2044
+ "page_idx": 18
2045
+ },
2046
+ {
2047
+ "type": "text",
2048
+ "text": "A pink towel stands out greatly in the white bathroom ",
2049
+ "bbox": [
2050
+ 408,
2051
+ 588,
2052
+ 596,
2053
+ 616
2054
+ ],
2055
+ "page_idx": 18
2056
+ },
2057
+ {
2058
+ "type": "image",
2059
+ "img_path": "images/bacd240485e26a532174d993863ebd922208a129b432bdb6bcd36b94119a092b.jpg",
2060
+ "image_caption": [
2061
+ "A white toilet bowl with a purple rug in front "
2062
+ ],
2063
+ "image_footnote": [],
2064
+ "bbox": [
2065
+ 183,
2066
+ 621,
2067
+ 379,
2068
+ 695
2069
+ ],
2070
+ "page_idx": 18
2071
+ },
2072
+ {
2073
+ "type": "text",
2074
+ "text": "A large pizza on a white plate sitting on a blue table ",
2075
+ "text_level": 1,
2076
+ "bbox": [
2077
+ 622,
2078
+ 590,
2079
+ 805,
2080
+ 617
2081
+ ],
2082
+ "page_idx": 18
2083
+ },
2084
+ {
2085
+ "type": "image",
2086
+ "img_path": "images/fc3d8bd9df11cad37a11762b0e2c5fd1165c80053f07eca502b775632458b10e.jpg",
2087
+ "image_caption": [],
2088
+ "image_footnote": [],
2089
+ "bbox": [
2090
+ 401,
2091
+ 621,
2092
+ 599,
2093
+ 695
2094
+ ],
2095
+ "page_idx": 18
2096
+ },
2097
+ {
2098
+ "type": "image",
2099
+ "img_path": "images/48b52b815f2fadf7e93602f86d613241414c34c280fa91397edfec9c1c36a9c5.jpg",
2100
+ "image_caption": [],
2101
+ "image_footnote": [],
2102
+ "bbox": [
2103
+ 616,
2104
+ 621,
2105
+ 812,
2106
+ 695
2107
+ ],
2108
+ "page_idx": 18
2109
+ },
2110
+ {
2111
+ "type": "text",
2112
+ "text": "A spoon and bowl of red pea soup and green beans with onions ",
2113
+ "bbox": [
2114
+ 192,
2115
+ 718,
2116
+ 372,
2117
+ 757
2118
+ ],
2119
+ "page_idx": 18
2120
+ },
2121
+ {
2122
+ "type": "text",
2123
+ "text": "A cow standing outside of a white building with a blue entrance ",
2124
+ "bbox": [
2125
+ 413,
2126
+ 717,
2127
+ 584,
2128
+ 756
2129
+ ],
2130
+ "page_idx": 18
2131
+ },
2132
+ {
2133
+ "type": "text",
2134
+ "text": "A black and white curtain \nhanging in a room that is \ndecorated in black, white and \nred ",
2135
+ "bbox": [
2136
+ 620,
2137
+ 705,
2138
+ 807,
2139
+ 758
2140
+ ],
2141
+ "page_idx": 18
2142
+ },
2143
+ {
2144
+ "type": "image",
2145
+ "img_path": "images/b7fd1fb2b097479ee0c8daa0225ada709939a000e386f9227ee3d53632006091.jpg",
2146
+ "image_caption": [],
2147
+ "image_footnote": [],
2148
+ "bbox": [
2149
+ 401,
2150
+ 758,
2151
+ 599,
2152
+ 835
2153
+ ],
2154
+ "page_idx": 18
2155
+ },
2156
+ {
2157
+ "type": "image",
2158
+ "img_path": "images/6fd1de4853b4e135bbd29c014613e0ba1aebc6158a4201d581f5433d4629e15d.jpg",
2159
+ "image_caption": [],
2160
+ "image_footnote": [],
2161
+ "bbox": [
2162
+ 617,
2163
+ 758,
2164
+ 813,
2165
+ 835
2166
+ ],
2167
+ "page_idx": 18
2168
+ },
2169
+ {
2170
+ "type": "image",
2171
+ "img_path": "images/d5d8e5dbed72e828a9bba99342c7933385ffcda9b12e7d2758d88218380089c8.jpg",
2172
+ "image_caption": [
2173
+ "Figure 14: Qualitative results on ABC-6K "
2174
+ ],
2175
+ "image_footnote": [],
2176
+ "bbox": [
2177
+ 187,
2178
+ 758,
2179
+ 383,
2180
+ 835
2181
+ ],
2182
+ "page_idx": 18
2183
+ },
2184
+ {
2185
+ "type": "image",
2186
+ "img_path": "images/cfdda3c5e52b24145788d8db72809206b16643bae64a24cf322cb9114b08223e.jpg",
2187
+ "image_caption": [
2188
+ "Figure 15: Qualitative results characterizing attributes beyond colors, including shape, size and materials. "
2189
+ ],
2190
+ "image_footnote": [],
2191
+ "bbox": [
2192
+ 178,
2193
+ 171,
2194
+ 818,
2195
+ 797
2196
+ ],
2197
+ "page_idx": 19
2198
+ },
2199
+ {
2200
+ "type": "image",
2201
+ "img_path": "images/228590b790dbd98fc2e4f38e8af5d5b6c518ba667976fe594af7a5e67dfcd7e5.jpg",
2202
+ "image_caption": [
2203
+ "Figure 16: A prompt “an astronaut riding a horse” appended with different (combinations of) style descriptions. Our method has no negative effects on the image style. “base” refers to Stable Diffusion. "
2204
+ ],
2205
+ "image_footnote": [],
2206
+ "bbox": [
2207
+ 178,
2208
+ 107,
2209
+ 813,
2210
+ 852
2211
+ ],
2212
+ "page_idx": 20
2213
+ }
2214
+ ]
parse/dev/PUIqjT4rzq7/PUIqjT4rzq7_model.json ADDED
The diff for this file is too large to render. See raw diff
 
parse/dev/TrjbxzRcnf-/TrjbxzRcnf-.md ADDED
@@ -0,0 +1,447 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # MEMORIZING TRANSFORMERS
2
+
3
+ Yuhuai Wu, Markus N. Rabe, DeLesley Hutchins, Christian Szegedy
4
+
5
+ {yuhuai,mrabe,delesley,szegedy}@google.com
6
+
7
+ # ABSTRACT
8
+
9
+ Language models typically need to be trained or finetuned in order to acquire new knowledge, which involves updating their weights. We instead envision language models that can simply read and memorize new data at inference time, thus acquiring new knowledge immediately. In this work, we extend language models with the ability to memorize the internal representations of past inputs. We demonstrate that an approximate $k \mathbf { N N }$ lookup into a non-differentiable memory of recent (key, value) pairs improves language modeling across various benchmarks and tasks, including generic webtext (C4), math papers (arXiv), books (PG-19), code (Github), as well as formal theorems (Isabelle). We show that the performance steadily improves when we increase the size of memory up to 262K tokens. On benchmarks including code and mathematics, we find that the model is capable of making use of newly defined functions and theorems during test time.
10
+
11
+ # 1 INTRODUCTION
12
+
13
+ Transformers (Vaswani et al., 2017) have led to remarkable progress in natural language processing (Devlin et al., 2019; Brown et al., 2020), mathematical reasoning (Polu & Sutskever, 2020; Wang et al., 2020a; Rabe et al., 2021; Li et al., 2021; Hahn et al., 2021; Cobbe et al., 2021), and program synthesis (Austin et al., 2021; Chen et al., 2021; Li et al., 2022). However, transformer performance on many of these tasks is limited by the context length of attention, which is typically short. The ability to attend to far-away tokens is important in many situations. In novels, characters and events are referenced across multiple chapters. In source code, references to classes and functions may occur quite far from the places in which they are defined. In theorem proving, proofs make use of previously defined lemmas.
14
+
15
+ Attention over long sequences is also useful as a form of rapid learning. Facts and information which are stored in the form of weight matrices must be slowly trained over hundreds of thousands of training steps. By using attention, however, a model can simply memorize facts (e.g. function definitions) by storing them as (key, value) pairs in long-term memory, and then retrieve those facts later by creating a query that attends to them. In this case, attention acts as a form of information retrieval, allowing the model to look up facts that it has seen previously.
16
+
17
+ We demonstrate that a simple and effective way to increase the size of the attention context is to use approximate $k$ -nearest-neighbor $( k \mathsf { N N } )$ lookup, which is widely used in information retrieval. A number of extremely scalable implementations of $k \mathbf { N N }$ lookup are available, such as ScaNN (Guo et al., 2020) and Faiss (Johnson et al., 2021).
18
+
19
+ There are two things which distinguish our approach from previous work on long-range attention (c.f. Section 2). First, unlike some other approaches, $k \mathbf { N N }$ lookup does not do averaging or summarization of tokens at long distances, but retrieves exact values even from the distant context.
20
+
21
+ Second, gradients are not backpropagated into the external memory, which is critical to the scalability of our technique. The keys and values are a function of model parameters, so attempting to backpropagate gradients into external memory would necessarily involve computing all of the keys and values with the current model parameters on every training step. However, if the external memory is not differentiable, then we can instead instead reuse keys and values that were previously computed on prior training steps, which drastically reduces the amount of computation for large memories. With our technique, we are easily able to scale external memory up to sequence lengths of 131k or 262k tokens on a single TPU device, while maintaining a reasonable step time.
22
+
23
+ ![](images/c348262572039ee17a0180d1f12a1ab33318f7e59c45735bf4ae47b93ca7fd68.jpg)
24
+ Figure 1: Adding a memory of 8K tokens improves perplexity across different model sizes.
25
+
26
+ We show that model perplexity steadily improves with the size of external memory on a variety of language modelling tasks, including C4 (long documents only), Github code repositories, PG-19 books, formal proofs in Isabelle, and arXiv math papers. We further show that models can generalize to larger memory sizes than they were trained on: models trained with a small memory show gains from using a much larger memory at inference time. Finally, we show that our models are actually using memory in the way that we had hoped, e.g. by looking up the definitions of lemmas in a theorem proving corpus.
27
+
28
+ The simplicity of the changes to the Transformer architecture allows us to easily integrate this approach into existing code bases, including extremely large language models. We further show that the improvements to quality are maintained across models of increasing size, and that the model improvements gained from adding memory are even larger than increasing the size of the model by 5X or more as shown in Figure 1.
29
+
30
+ # 2 RELATED WORK
31
+
32
+ A great deal of work has been done on efficient long-range attention mechanisms; see Tay et al. (2020; 2021) recent surveys. Sliding windows (Beltagy et al., 2020) use a long sequence, but attend within a smaller window, thus reducing complexity to the window size, rather than total sequence length. Approximate mechanisms such as Linformer (Wang et al., 2020b), and Performer (Choromanski et al., 2021) refactor the attention matrix by using a different kernel than softmax to obtain $O ( N )$ complexity. Pooling strategies such as Hierarchical 1D attention (Zhu & Soricut, 2021), and Combiner (Ren et al., 2021) apply pooling or averaging over tokens at longer distances. Sparse strategies such as Big Bird (Zaheer et al., 2020) select only a subset of tokens to attend to; Routing Transformers (Roy et al., 2021) use clustering to select the subset, while Reformer (Kitaev et al., 2020) relies on hashing. Hierarchical mechanisms (Ainslie et al., 2020) combine multiple tokens into phrases or sentences to reduce sequence length. Expire-span (Sukhbaatar et al., 2021) prunes far-away tokens that it learns are “unimportant”. (Zemlyanskiy et al., 2021) process long sequences in two passes with different encoders. The second pass is given a lot of context by accessing summaries of the first pass.
33
+
34
+ Feedback transformers (Fan et al., 2020) use a recurrent architecture in which each token attends to the output of the final layer instead of the previous layer. Recurrence does not increase the size of the attention context itself, but it expands the receptive field at the cost of parallelism and training speed.
35
+
36
+ Truncated backpropagation through time (Williams & Peng, 1990) was originally introduced as a way of training recurrent neural networks (RNN) over very long sequences, when the entire sequence does not fit in memory. The sequence is chopped into segments, and after each training step, the final RNN state for the segment is saved in a non-differentiable cache, and used as the initial state on the next training step. Neural caches (Grave et al., 2017) extend the cache to contain a record of many prior hidden states, and attend over them. Transformer-XL (Dai et al., 2019) applies this technique to transformers; it caches the (key,value) pairs computed from the previous training step, and uses them as a prefix for the tokens on the next training step, which yields significant gains on long documents. Rae et al. (2020) improve over Transformer-XL by compressing the tokens before adding them to the cache. In contrast, we use a very large cache without compression, combined with an approximate $k \mathbf { N N }$ attention mechanism over it.
37
+
38
+ ![](images/93d8466b573b5325cd9a069c63eddcdd2572eb8799f9d4720b8a3dbfc7a46115.jpg)
39
+ Figure 2: We extend Transformers with access to (key, value) pairs of previously seen subsequences.
40
+
41
+ Sukhbaatar et al. (2019) make the observation that the feed-forward portion of a transformer layer functions very much like attention if one replaces the ReLU activation with softmax. They implement a combined attention over both tokens from the input sequence and a learned (and differentiable) “memory”. Lample et al. (2019) exploit this observation to replace the feed-forward layers (FFNs) with a fast $k \mathbf { N N }$ lookup over a much larger “memory”, and achieve large gains in model accuracy without significant computation overhead. (We use $k \mathbf { N N }$ lookup to approximate attention to previous tokens, not to replace the FFN.)
42
+
43
+ Non-differentiable external memory has been used in different ways by Khandelwal et al. (2020), who run a pre-trained model over an entire corpus, and construct a large table of (key, token) pairs. They then use that table to replace the final softmax layer for token selection in the model, which results in significant improvements in language modeling. Yogatama et al. (2021) extend this approach by a gating mechanism and a process to compress the context into keys for retrieval.
44
+
45
+ There are several works that combine retrieval with transformers. REALM (Guu et al., 2020), MARGE (Lewis et al., 2020a), RAG (Lewis et al., 2020b), and composite memory for dialog (Fan et al., 2021) retrieve documents from a knowledge base to improve question answering or dialogue. The knowledge base consists of text snippets and is static and typically separate from the inputs and outputs of the models. Instead, we focus on language modeling using a decoder-only model, and propose a simple model that unifies attention and retrieval.
46
+
47
+ $k$ -nearest-neighbor lookup is a general-purpose technique that is used for a wide variety of machine learning and retrieval tasks, and high-performance implementations are available for various architectures (Johnson et al., 2021; Guo et al., 2020). Memory-efficient Transformers (Gupta et al., 2021) replace dense attention with a $k \mathbf { N N }$ lookup to increase speed and reduce memory usage.
48
+
49
+ # 3 METHOD
50
+
51
+ The architecture of our $k \mathbf { N N }$ -augmented transformer is shown in Figure 2. The bulk of the model is a vanilla, decoder-only transformer (Vaswani et al., 2017). The input text is tokenized, and the tokens are embedded into vector space. The embedding vectors are passed through a series of transformer layers, each of which does dense self-attention, followed by a feed-forward network (FFN). Since this is a decoder-only language model, we use a causal attention mask and the token embeddings of the last layer are used to predict the next token.
52
+
53
+ Long documents are split into subsequences of 512 tokens, and each subsequence is used as the input for one training step. In contrast to standard practice, we do not shuffle the subsequences; instead, each long document is fed into the transformer sequentially, from beginning to end, as is done with Transformer-XL (Dai et al., 2019).
54
+
55
+ ![](images/81f98de49b0afcae04d1631ab7e72f49483236312e44999b1680cfebdad0dc90.jpg)
56
+ Figure 3: Our data pipeline splits documents into subsequences and packs subsequences into batches.
57
+
58
+ We also use a Transformer-XL style cache, which holds the keys and values from the previous training step. When doing self-attention, the cached keys and values are prepended to the current keys and values, and we use a sliding-window causal mask (Beltagy et al., 2020) so that each token has a local context that includes the previous 512 tokens.
59
+
60
+ # 3.1 $k$ NN-AUGMENTED ATTENTION LAYER
61
+
62
+ One of the transformer layers near the top of the stack is a kNN-augmented attention layer, which combines two forms of attention. Like all of the other layers, it uses standard dense self-attention on the local context, which is the input subsequence for the current training step. Unlike the other layers, however, it also does an approximate $k$ -nearest-neighbor search into the external memory.
63
+
64
+ The same queries are used for both the local context, and for the external memory. The keys and values also belong to the same distribution; after each training step, the (key, value) pairs in the local context are appended to the end of the external memory. If the document is very long, old (key, value) pairs will be dropped from the memory to make room for new ones. Thus, for each head, the external memory keeps a cache of the prior $M$ (key, value) pairs, where $M$ is the memory size.
65
+
66
+ The $k \mathbf { N N }$ lookup will return a set of retrieved memories, which consist of the top- $k$ (key, value) pairs that $k \mathbf { N N }$ search returns for each query (i.e. each token) in the input subsequence. As with standard dense attention, we first construct an attention matrix by computing the dot product of each query against the retrieved keys, then apply softmax, and finally return a weighted sum of the retrieved values. Unlike standard dense attention, the retrieved memories contain a different set of (key, value) pairs for each query.
67
+
68
+ Attention over the local context is performed in the usual way. The results of $k \mathbf { N N }$ -attention and local attention are then combined using a learned gate:
69
+
70
+ $$
71
+ \begin{array} { c } { { g = \sigma ( b _ { g } ) } } \\ { { V _ { a } = V _ { m } \odot g + V _ { c } \odot ( 1 - g ) } } \end{array}
72
+ $$
73
+
74
+ where $\sigma$ is the sigmoid function, and $\odot$ is element-wise multiplication. $V _ { a }$ is the combined result of attention, $V _ { m }$ is the result of attending to external memory, and $V _ { c }$ is the result of attending to the local context. The bias $b _ { g }$ is a learned per-head scalar parameter, which allows each head to choose between local and long-range attention. In our experiments, the value of the gate $g$ does not depend on the content of the token at each position, although that would be a trivial extension to implement. We did observe that over time, most heads learned to attend almost exclusively to external memory.
75
+
76
+ Position bias. For dense attention within the local context, we use the T5 relative position bias (Raffel et al., 2020). As noted by Dai et al. (2019), adding a global position encoding to each token does not work well when processing long documents. We don’t use a position bias for the retrieved memories. Experiments on the PG19 dataset (Sun et al., 2021) have shown that relative position does not appear to matter at long range, and the T5 relative bias puts all long-range tokens in the same bucket anyway.
77
+
78
+ Batching. Figure 3 illustrates how multiple long documents of different lengths are packed into a batch, and split into subsequences. Each subsequence in the batch comes from a different document, and thus requires a separate external memory, which is cleared at the start of each new document.
79
+
80
+ # 3.2 DISTRIBUTIONAL SHIFT
81
+
82
+ Because each long document is processed over multiple training steps, there is a distributional shift in the keys and values that are stored in external memory. The model parameters that produce the queries change over time, and will thus have shifted since the keys and values were stored. For very large memories, older records may become “stale.” Similar observations have been made for CrossBatch memory (Wang et al., 2020c) in the vision domain.
83
+
84
+ To reduce the effects of staleness, we normalize keys and queries (Henry et al., 2020). Normalization does not eliminate staleness, but it at least ensures that older keys and newer keys do not differ in magnitude. We also found that normalization helps stabilize training with the Transformer-XL cache.
85
+
86
+ In some of our experiments, we observed that training models from scratch with a large memory sometimes resulted in worse performance than pretraining the model with a small memory of size 8192, and then finetuning it on a larger memory. This training instability could be due to staleness. However, models seem to be able to cope with a limited degree of staleness (with the small memory) by adjusting their queries accordingly.
87
+
88
+ # 3.3 APPROXIMATE $k \mathbf { N N }$
89
+
90
+ We employ approximate $k \mathbf { N N }$ search rather than exact $k \mathbf { N N }$ search because it significantly improves the computational speed of our model. We use a simple approximation of $k \mathbf { N N }$ for TPUs, which has a recall of about $90 \%$ , i.e. $90 \%$ of the true top $k$ are returned in the approximate top $k$ . There are various other efficient approximate $k \mathbf { N N }$ algorithms available for CPU and GPU/TPU, for example through Faiss (Johnson et al., 2021) or ScaNN (Guo et al., 2020), which can scale into the billions.
91
+
92
+ # 4 EXPERIMENTS
93
+
94
+ We evaluate the effect of adding external memory on five language modeling tasks, all of which involve long-form text: English language books (PG-19), long web articles (C4), technical math papers (arXiv Math), source code (Github), and formal theorems (Isabelle). The results show significant improvements in the perplexity of the model with the addition of external memory. We experimented with various sizes of external memory, from 1536 to as high as 262K. On most of the datasets, there was an initial sharp gain from adding a small external memory, followed by smaller but steadily increasing gains as the size of the memory was increased.
95
+
96
+ # 4.1 DATASETS
97
+
98
+ arXiv Math For the arXiv dataset, we collected a corpus of papers by downloading them via the arXiv Bulk Data Access1. We filtered papers to include only articles labeled as “Mathematics” and whose $\mathrm { I A T } \mathrm { E } ^ { \mathrm { X } }$ source was available. The number of tokens per paper in this dataset is roughly comparable to the number of tokens per book in PG19, because $\mathrm { I A T } \mathrm { E } ^ { \mathrm { X } }$ source has many special characters and the tokenizer tends to output small subwords.
99
+
100
+ Github We used BigQuery2 to obtain a large corpus of Github repositories that are published with open-source licenses. We used file endings to filter for files in the languages C, $\mathrm { C } { + + }$ , Java, Python (including Jupyter notebooks), Go, and TypeScript. Individual source code files are often fairly short, and there are many dependencies and cross-references between files in the repository. To capture these dependencies, we created one long document for each Github repository by traversing the directory tree, and concatenating all of the files within it. The order in which files are traversed within the repository is random, but each subdirectory is processed as a unit, so that all the files within the subdirectory are close to each other in the resulting document. Source code is usually structured so that related files are all grouped together in the same subdirectory; this traversal preserves that structure, while still shuffling files and subdirectories in random order.
101
+
102
+ Formal Math – Isabelle The Isabelle corpus consists of formal mathematical proofs of theories. We collected all 627 theories available on The Archive of Formal Proofs3 (as of October 6, 2021) and an additional 57 theories from the Isabelle standard library4 to create a corpus of 684 theories. All theories have open-source licenses. Each theory is a self-contained mathematical object, on topics such as foundational logic, advanced analysis, algebra, or cryptography, and consists of multiple files containing proofs. As with the Github corpus, all files that make up a theory are concatenated together into one long document. Unlike the Github corpus, we order the files according to their import dependencies, so that later files use sub-theorems that are proved in earlier files.
103
+
104
+ Table 4: Average token-level perplexities of each model when trained for 500k steps.
105
+
106
+ <table><tr><td>Context</td><td>Memory</td><td>XL cache</td><td>arXiv</td><td>PG19</td><td>C4(4K+)</td><td>GitHub</td><td>Isabelle</td></tr><tr><td>512</td><td>None</td><td>None</td><td>3.29</td><td>13.71</td><td>17.20</td><td>3.05</td><td>3.09</td></tr><tr><td>2048</td><td>None</td><td>None</td><td>2.69</td><td>12.37</td><td>14.81</td><td>2.22</td><td>2.39</td></tr><tr><td>512</td><td>None</td><td>512</td><td>2.67</td><td>12.34</td><td>15.38</td><td>2.26</td><td>2.46</td></tr><tr><td>2048</td><td>None</td><td>2048</td><td>2.42</td><td>11.88</td><td>14.03</td><td>2.10</td><td>2.16</td></tr><tr><td>512</td><td>1536</td><td>None</td><td>2.61</td><td>12.50</td><td>14.97</td><td>2.20</td><td>2.33</td></tr><tr><td>512</td><td>8192</td><td>None</td><td>2.49</td><td>12.29</td><td>14.42</td><td>2.09</td><td>2.19</td></tr><tr><td>512</td><td>8192</td><td>512</td><td>2.37</td><td>11.93</td><td>14.04</td><td>2.03</td><td>2.08</td></tr><tr><td>512</td><td>65K</td><td>512</td><td>2.31</td><td>11.62</td><td>14.04</td><td>1.87</td><td>2.06</td></tr><tr><td>2048</td><td>8192</td><td>2048</td><td>2.33</td><td>11.84</td><td>13.80</td><td>1.98</td><td>2.06</td></tr><tr><td>2048</td><td>65K</td><td>2048</td><td>2.26</td><td>11.37</td><td>13.64</td><td>1.80</td><td>1.99</td></tr></table>
107
+
108
+ $\mathbf { C 4 } ( 4 \mathbf { K } + )$ C4, the colossal cleaned common crawl, is a very large collection of documents that have been scraped from the internet (Raffel et al., 2020). We filtered out all documents that have less than 4096 tokens to focus on documents where memory can have an impact.
109
+
110
+ PG-19 PG-19 is a large dataset of English-language books, published prior to 1919, which were retrieved from the Project Gutenberg archive (Rae et al., 2020; Sun et al., 2021). PG-19 is one of the few public datasets that only contains full-length books, and has become a benchmark for long-range natural language text modeling.
111
+
112
+ # 4.2 EXPERIMENTAL METHOD
113
+
114
+ We used a 12-layer decoder-only transformer (with and without Transformer-XL cache) with an embedding size of 1024, 8 attention heads of dimension 128, and an FFN hidden layer of size 4096. For all of our experiments, we used $k = 3 2$ . Unless specified otherwise, we use the 9th layer as the $k \mathbf { N N }$ augmented attention layer. We used a sentence-piece (Kudo & Richardson, 2018) tokenizer with a vocabulary size of 32K.
115
+
116
+ We used the Adafactor optimizer (Shazeer & Stern, 2018). In preliminary experiments, we conducted a hyperparameter search to determine the optimal learning rate among three choices ({3.0, 1.0, $3 \cdot { \bar { 1 0 } } ^ { - 1 } \}$ ), and found that 1.0 works best. We used a linear warmup schedule for the first 1000 steps, followed by square root decay. We trained the models from scratch for 500K steps on all the datasets, except for the Isabelle dataset. Isabelle is small, so we stopped training after 100K steps when the model began to overfit. We ran all of our experiments on 32 TPU cores. Our models were implemented in JAX (Bradbury et al., 2018) and Flax (Heek et al., 2020).
117
+
118
+ When comparing models with different context lengths, we adjusted the batch size (the number of documents in a batch) so that there are always $2 ^ { 1 7 }$ tokens in a batch. E.g., a model with a context length of 512 has a batch size of 256, while the 2048 model has a batch size of 64.
119
+
120
+ We experimented with multiple implementations of approximate $k \mathbf { N N }$ lookup with different tradeoffs between quality and computational cost. We did not observe a significant degradation of the model quality when switching to lower quality approximations of $k \mathbf { N N }$ , so the model appears to be quite robust with respect to the quality of $k \mathbf { N N }$ retrieval. For a model with around 200M trainable parameters the step time increased from 0.2s to $0 . 2 5 \mathrm { s }$ when we added a memory of size 8K, and to 0.6s when we added a memory of size 65K (measured on TPUv3).
121
+
122
+ # 4.3 EFFECT OF EXTERNAL MEMORY
123
+
124
+ Adding external memory results in substantial gains across datasets and architectures, as shown in Table 4. Across all five datasets, adding external memory to either the vanilla Transformer or the Transformer-XL architecture improves perplexity by a substantial amount. For example, on $\mathrm { C 4 } ( 4 \mathrm { K } + )$ dataset, adding memory of size 8192 improves the perplexity of the vanilla Transformer (with context size 512) from 17.20 to 14.42, and improves Transformer-XL from 15.38 to 14.04.
125
+
126
+ <table><tr><td>Context</td><td>Pretrain</td><td>Fine-tune</td><td>Perplexity</td></tr><tr><td>512</td><td>8192</td><td>None</td><td>2.37</td></tr><tr><td>512</td><td>65K</td><td>None</td><td>2.31</td></tr><tr><td>512</td><td>8192</td><td>65K</td><td>2.32</td></tr><tr><td>512</td><td>8192</td><td>131K</td><td>2.30</td></tr><tr><td>512</td><td>8192</td><td>262K</td><td>2.26</td></tr><tr><td>2048</td><td>8192</td><td>None</td><td>2.33</td></tr><tr><td>2048</td><td>65K</td><td>None</td><td>2.26</td></tr><tr><td>2048</td><td>65K</td><td>131K</td><td>2.23</td></tr><tr><td>2048</td><td>65K</td><td>262K</td><td>2.21</td></tr></table>
127
+
128
+ Table 5: Finetuning for 20K steps to make use of a larger memory on the arXiv data set.
129
+
130
+ Increasing the size of the memory increases the benefit of the memory. The best perplexities for all datasets and architectures were obtained with a memory size of 65K.
131
+
132
+ Note that Transformer-XL with context size 2048 already has a theoretical receptive field that is quite large. Each token in a higher layer can attend up to 2048 tokens away in the layer below, so the total receptive field is $2 0 4 8 \cdot 1 2$ (layers) $\sim 2 5 \mathrm { K }$ . Nevertheless, we still saw a substantial gain when adding an external memory of size 8192 to this model. $k \mathbf { N N }$ attention into memory would appear to be a more effective way to retrieve information from the distant past than the Transformer-XL cache.
133
+
134
+ On the other hand, we also saw improvements by adding XL cache to the large-memory (65K) models. In a vanilla (non-XL) Transformer, the first few tokens in a sequence have very little context, and thus have higher perplexity. The XL cache provides additional local short-range context at the start of a sequence, which complements the long-range context provided by external memory.
135
+
136
+ Interestingly, in a vanilla Transformer, using even a small external memory of size 1536 provides a gain in perplexity which is almost as good as using a local context of size 2048 but no memory (e.g. Table 4). This is surprising, because the external memory is not differentiable, and is added only to one layer of the Transformer, whereas increasing the context size is differentiable and affects all layers. We conclude that the lower layers of a Transformer don’t necessarily need long-range context, and having a differentiable memory is not as important as one might suspect.
137
+
138
+ # 4.4 SCALING TO LARGER MODELS
139
+
140
+ We scaled up the Transformer model to sizes of 1 and 8 billion parameters. For the 1 billion parameter model, we use 8 layers, 32 heads with head dimension 128, $d _ { - }$ model 2048, and $d _ { - }$ _ff 16384. For the 8 billion parameter model, we use 64 heads, 16 layers, $d$ _model 4096, and $d _ { - }$ _ff 32768. We used a context size of 2048, memory size of 8192, and no XL cache. We ran the comparisons to the vanilla Transformer on the arXiv math dataset. Scaling plots are shown in Figure 1.
141
+
142
+ External memory provides a consistent improvement to the model as it is scaled up. Remarkably, we found that the smaller Memorizing Transformer with just 8k tokens in memory can match the perplexity of a larger vanilla Transformer which has 5X more trainable parameters.
143
+
144
+ # 4.5 FINETUNING ON LARGER MEMORIES
145
+
146
+ Finetuning on a larger memory. In some cases, training was unstable when using large memories, possibly due to distributional shift early in the training (See Section 3.2). Thus, for memories of 131K or more tokens, we first pretrain the model with a memory size of 8192 or 65K for 500K steps, and then finetune it with the larger memory for an additional 20K steps. The results of finetuning on the arXiv Math data set are shown in Table 5. Increasing the size of external memory provided consistent gains up to a size of 262K. Note that 262K tokens is longer than almost all of the documents in arXiv, and thus we would not expect to see any gain past this point (see Appendix A).
147
+
148
+ ![](images/14d1bef481a2ec3931ed59a899d428ebe8a68caed797c0d03c05a6ce7c996ad0.jpg)
149
+ Figure 6: Finetuning a 1B vanilla Transformer model to use external memory of size 65K.
150
+
151
+ Finetuning a non-memory model to use memory Pretraining can be very costly both in time and computational resources. Thus, a natural question to ask is: can one fine-tune a pretrained Transformer to use external memory? The answer is yes!
152
+
153
+ We took a pre-trained 1B vanilla Transformer model, and fine-tuned it to use external memory (the 1B models used in Section 4.4). The fine-tuning result is shown in Figure 6. Notice that the model quickly learns to use external memory. Within 20K steps $4 \%$ of the pre-training time) the fine-tuned model has already closed $8 5 \%$ of the gap between it and the 1B Memorizing Transformer, and after $1 0 0 \mathrm { k }$ steps it has closed the gap entirely.
154
+
155
+ # 4.6 INFORMATION RETRIEVAL PATTERNS
156
+
157
+ We conducted a qualitative study of what the model was actually retrieving from external memory, by finding which tokens showed the biggest improvements in cross-entropy loss when the size of the memory was increased, and then examining the top- $k$ retrieved memories for those tokens. We found that the model gained the most when looking up rare words, such as proper names, references, citations, and function names, where the first use of a name is too far away from subsequent uses to fit in the local context. This result is in keeping with the prior analysis of long-context Transformers on PG19 (Sun et al., 2021), which found similar lookup patterns. For this experiment, we used a slightly older version of the architecture without the gating mechanism.
158
+
159
+ Which tokens show a benefit from memory? Figure 7 shows a visualization of which tokens show an improvement when the size of the external memory is increased. We selected a math paper at random, and plotted the difference in cross entropy loss for each token $x _ { i }$ in the paper, comparing two models with the same parameters, but with memories of different sizes. $\Delta _ { i } = \mathrm { c r o s s - e n t r o p y } _ { 8 1 9 2 } ( x _ { i } )$ $- \mathrm { c r o s s - e n t r o p y } _ { 3 2 \mathrm { K } } ( x _ { i } )$ . Positive values show an improvement in loss.
160
+
161
+ The $x$ -axis on the chart is the token number $i$ , while the $y$ -axis is $\Delta _ { i }$ . For the first 8192 tokens, the difference between the two models is zero, since the larger capacity of the 32K memory isn’t being used yet. However, after token 8193, we can see that the larger memory helps, on average, over the smaller memory. The benefit is not universal, since the predictions for some tokens become worse, possibly due to the fact that a relevant retrieved memory no longer makes it into the top- $k$ when the size of the external memory is increased. This figure also shows that the benefit of external memory is somewhat sparse. The improvement in perplexity seems to be mainly driven by a small percentage of tokens that obtain a large improvement in cross-entropy loss when using the larger memory.
162
+
163
+ What information is being looked up? Given that only a subset of tokens shows improvement from external memory, we did a further investigation into what, exactly, those tokens are using the memory for. We took those tokens which showed the largest improvement in cross-entropy loss, and for each of them tokens, we examined the top- $k$ retrieved memories. We studied arXiv math, Github and Isabelle corpus. For arXiv math and Github, we found the model retrieved function and variable names. See more details with examples in Appendix B.
164
+
165
+ ![](images/ac7dcbfadeffdce1e7c62204b4feff0227f84bf9079091c5be4d5700f286a668.jpg)
166
+ Figure 7: Difference in loss for each token in a randomly chosen paper, using the same model once with a memory size of 8K and once with 32K. Higher numbers mean the longer memory helped in comparison to the shorter memory. This paper is 22K tokens long.
167
+
168
+ Table 8: Examples of memory retrieval in the Isabelle dataset. The model is able to find the definition of a lemma from a reference to it. The retrieved surrounding context (highlighted) is the definition body of the mathematical object highlighted in the querying context.
169
+
170
+ <table><tr><td></td><td></td><td></td><td>Query indexInputTargetSurrounding context</td><td></td><td>Retrieved index Retrieved surrounding context</td></tr><tr><td>29721</td><td>mark</td><td>ov</td><td>rule prob_space. markov_inequality</td><td>8088</td><td>M.t\&lt;le&gt; X a} \&lt;le&gt; expectation X /t&quot;</td></tr><tr><td>40919</td><td>1</td><td>th</td><td>= ( subgraph_threshold Hn / p n)</td><td>27219</td><td>threshold H n = n powr (-(1 / max_density’</td></tr><tr><td>49699</td><td>S</td><td>W</td><td>assumes&#x27; orthonormal_system Sw&quot;</td><td>28050</td><td>definition orthonormal_system “</td></tr></table>
171
+
172
+ Retrieving mathematical definitions. Our case study on the Isabelle corpus provides one of the clearest illustrations of how a model can make good use of external memory. When predicting the name of a mathematical object or a lemma, the model looked up the definition from earlier in the proof. Examples of this behavior are shown in Table 8. In example 1, the model retrieves a definition within the body of a lemma, markov_inequality. In example 2, it retrieves the definition of a previously defined concept subgraph_threshold. In example 3, it retrieves the definition of orthonormal_system. We manually checked 10 examples where the model made a prediction of lemma names, and 8 out of 10 times model found the body of the lemma it needs to predict. In the other two cases, the model also looked up materials in the immediate vicinity. To the best of our knowledge, this is the first demonstration that attention is capable of looking up definitions and function bodies from a large corpus. The Isabelle case study used a model with two memory layers of size 32K.
173
+
174
+ # 5 CONCLUSION
175
+
176
+ We present a simple extension to the Transformer architecture, called kNN-augmented attention, which dramatically increases the length of the context that a language model can attend to by using $k$ -nearest-neighbor lookup into a large external memory. We demonstrate the effectiveness of external memory in a series of language modeling experiments over a variety of long-document datasets, including LaTeX documents, source code, formal proofs, and books.
177
+
178
+ The Memorizing Transformer shows large improvements in perplexity over the baseline for all of the data sets and architectures that we studied; it is comparable to a vanilla transformer that has 5 times the number of parameters. Perplexity continues to improve with increasing memory size, although there is a point of diminishing returns. Moreover, external memory continues to provide benefits even as the transformer is scaled up from 200M to 8B parameters. Perhaps most intriguingly, a Memorizing Transformer does not need to be pre-trained from scratch; it is possible obtain large gains from adding memory to an existing pre-trained model, and then fine-tuning it.
179
+
180
+ Unlike other forms of attention, $k \mathbf { N N }$ retrieval can be easily scaled up to huge memory sizes, and is thus potentially able to leverage vast knowledge bases or code repositories. How to make the best use of this capability is a topic for future work.
181
+
182
+ # ACKNOWLEDGMENTS
183
+
184
+ We want to thank Charles Staats for the many fruitful discussions and detailed comments, Henryk Michalewski for early version of of the memory implementation, Petros Maniatis for his help with our code datasets, Aitor Lewkowycz for his help with larger scale memorizing transformer experiments, Behnam Neyshabur for his comments on finetuning non-memory models, Imanol Schlag for his proofread and detailed comments, and Dennis Lee and Manzil Zaheer for discussions about large-scale attention and retrieval.
185
+
186
+ # ETHICS
187
+
188
+ The ability to memorize large databases of facts could have potential ramifications for society, especially if those databases include sensitive personal information or copyrighted works. However, one advantage of using an external memory is that the memory can be easily cleared of all such information, as we do at the end of each document that we train on. The same is not true of differentiable model parameters, which is what most existing architectures use to store facts and information that they are trained on.
189
+
190
+ # REPRODUCIBILITY
191
+
192
+ Details of our architecture and training hyperparameters are given in Section 4.2. The datasets for C4 and PG-19 are publicly available. Our additional datasets, Github, Isabelle, and ArXiv Math are derived from publicly available data buckets, which we link in the main part of the paper. Subsection 4.1 include details on how we constructed the datasets from those datasets. We plan to release our code as open source.
193
+
194
+ # REFERENCES
195
+
196
+ Joshua Ainslie, Santiago Ontañón, Chris Alberti, Vaclav Cvicek, Zachary Fisher, Philip Pham, Anirudh Ravula, Sumit Sanghai, Qifan Wang, and Li Yang. ETC: encoding long and structured inputs in transformers. In EMNLP, 2020.
197
+
198
+ Jacob Austin, Augustus Odena, Maxwell Nye, Maarten Bosma, Henryk Michalewski, David Dohan, Ellen Jiang, Carrie J. Cai, Michael Terry, Quoc V. Le, and Charles Sutton. Program synthesis with large language models. CoRR, abs/2108.07732, 2021. URL https://arxiv.org/abs/ 2108.07732.
199
+
200
+ Iz Beltagy, Matthew E. Peters, and Arman Cohan. Longformer: The long-document transformer. CoRR, abs/2004.05150, 2020. URL https://arxiv.org/abs/2004.05150.
201
+
202
+ James Bradbury, Roy Frostig, Peter Hawkins, Matthew James Johnson, Chris Leary, Dougal Maclaurin, George Necula, Adam Paszke, Jake VanderPlas, Skye Wanderman-Milne, and Qiao Zhang. JAX: composable transformations of Python+NumPy programs, 2018. URL http://github.com/google/jax.
203
+
204
+ Tom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah, Jared Kaplan, Prafulla Dhariwal, Arvind Neelakantan, Pranav Shyam, Girish Sastry, Amanda Askell, Sandhini Agarwal, Ariel Herbert-Voss, Gretchen Krueger, Tom Henighan, Rewon Child, Aditya Ramesh, Daniel M. Ziegler, Jeffrey Wu, Clemens Winter, Christopher Hesse, Mark Chen, Eric Sigler, Mateusz Litwin, Scott Gray, Benjamin Chess, Jack Clark, Christopher Berner, Sam McCandlish, Alec Radford, Ilya Sutskever, and Dario Amodei. Language models are few-shot learners. In NeurIPS, 2020.
205
+
206
+ Mark Chen, Jerry Tworek, Heewoo Jun, Qiming Yuan, Henrique Ponde de Oliveira Pinto, Jared Kaplan, Harrison Edwards, Yuri Burda, Nicholas Joseph, Greg Brockman, Alex Ray, Raul Puri, Gretchen Krueger, Michael Petrov, Heidy Khlaaf, Girish Sastry, Pamela Mishkin, Brooke Chan, Scott Gray, Nick Ryder, Mikhail Pavlov, Alethea Power, Lukasz Kaiser, Mohammad Bavarian, Clemens Winter, Philippe Tillet, Felipe Petroski Such, Dave Cummings, Matthias Plappert, Fotios Chantzis, Elizabeth Barnes, Ariel Herbert-Voss, William Hebgen Guss, Alex Nichol, Alex Paino, Nikolas Tezak, Jie Tang, Igor Babuschkin, Suchir Balaji, Shantanu Jain, William Saunders, Christopher Hesse, Andrew N. Carr, Jan Leike, Joshua Achiam, Vedant Misra, Evan Morikawa, Alec Radford, Matthew Knight, Miles Brundage, Mira Murati, Katie Mayer, Peter Welinder, Bob McGrew, Dario Amodei, Sam McCandlish, Ilya Sutskever, and Wojciech Zaremba. Evaluating large language models trained on code. CoRR, abs/2107.03374, 2021. URL https://arxiv. org/abs/2107.03374.
207
+
208
+ Krzysztof Marcin Choromanski, Valerii Likhosherstov, David Dohan, Xingyou Song, Andreea Gane, Tamás Sarlós, Peter Hawkins, Jared Quincy Davis, Afroz Mohiuddin, Lukasz Kaiser, David Benjamin Belanger, Lucy J. Colwell, and Adrian Weller. Rethinking attention with performers. In ICLR, 2021.
209
+
210
+ Karl Cobbe, Vineet Kosaraju, Mohammad Bavarian, Jacob Hilton, Reiichiro Nakano, Christopher Hesse, and John Schulman. Training verifiers to solve math word problems. CoRR, abs/2110.14168, 2021. URL https://arxiv.org/abs/2110.14168.
211
+
212
+ Zihang Dai, Zhilin Yang, Yiming Yang, Jaime G. Carbonell, Quoc Viet Le, and Ruslan Salakhutdinov. Transformer-XL: Attentive language models beyond a fixed-length context. In ACL, 2019.
213
+
214
+ Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. BERT: pre-training of deep bidirectional transformers for language understanding. In ACL, 2019.
215
+
216
+ Angela Fan, Thibaut Lavril, Edouard Grave, Armand Joulin, and Sainbayar Sukhbaatar. Addressing some limitations of transformers with feedback memory. arXiv preprint arXiv:2002.09402, 2020.
217
+
218
+ Angela Fan, Claire Gardent, Chloé Braud, and Antoine Bordes. Augmenting transformers with KNN-based composite memory for dialog. Transactions of the Association for Computational Linguistics, 9:82–99, 2021.
219
+
220
+ Edouard Grave, Armand Joulin, and Nicolas Usunier. Improving neural language models with a continuous cache. In ICLR, 2017.
221
+
222
+ Ruiqi Guo, Philip Sun, Erik Lindgren, Quan Geng, David Simcha, Felix Chern, and Sanjiv Kumar. Accelerating large-scale inference with anisotropic vector quantization. In ICML, 2020.
223
+
224
+ Ankit Gupta, Guy Dar, Shaya Goodman, David Ciprut, and Jonathan Berant. Memory-efficient transformers via top- $\mathbf { \nabla } \cdot \mathbf { k }$ attention. CoRR, abs/2106.06899, 2021. URL https://arxiv.org/ abs/2106.06899.
225
+
226
+ Kelvin Guu, Kenton Lee, Zora Tung, Panupong Pasupat, and Ming-Wei Chang. Retrieval augmented language model pre-training. In ICML, 2020.
227
+
228
+ Christopher Hahn, Frederik Schmitt, Jens U. Kreber, Markus Norman Rabe, and Bernd Finkbeiner. Teaching temporal logics to neural networks. In ICLR, 2021.
229
+
230
+ Jonathan Heek, Anselm Levskaya, Avital Oliver, Marvin Ritter, Bertrand Rondepierre, Andreas Steiner, and Marc van Zee. Flax: A neural network library and ecosystem for JAX, 2020. URL http://github.com/google/flax.
231
+
232
+ Alex Henry, Prudhvi Raj Dachapally, Shubham Shantaram Pawar, and Yuxuan Chen. Query-key normalization for transformers. In EMNLP, 2020.
233
+
234
+ Jeff Johnson, Matthijs Douze, and Hervé Jégou. Billion-scale similarity search with GPUs. IEEE Transactions on Big Data, 2021.
235
+
236
+ Urvashi Khandelwal, Omer Levy, Dan Jurafsky, Luke Zettlemoyer, and Mike Lewis. Generalization through memorization: Nearest neighbor language models. In ICLR, 2020.
237
+
238
+ Nikita Kitaev, Łukasz Kaiser, and Anselm Levskaya. Reformer: The efficient transformer. In ICLR, 2020.
239
+
240
+ Taku Kudo and John Richardson. Sentencepiece: A simple and language independent subword tokenizer and detokenizer for neural text processing. In EMNLP, 2018.
241
+
242
+ Guillaume Lample, Alexandre Sablayrolles, Marc’Aurelio Ranzato, Ludovic Denoyer, and Hervé Jégou. Large memory layers with product keys. In NeurIPS, 2019.
243
+
244
+ Mike Lewis, Marjan Ghazvininejad, Gargi Ghosh, Armen Aghajanyan, Sida Wang, and Luke Zettlemoyer. Pre-training via paraphrasing. In NeurIPS, 2020a.
245
+
246
+ Patrick Lewis, Ethan Perez, Aleksandra Piktus, Fabio Petroni, Vladimir Karpukhin, Naman Goyal, Heinrich Küttler, Mike Lewis, Wen-tau Yih, Tim Rocktäschel, et al. Retrieval-augmented generation for knowledge-intensive NLP tasks. In NeurIPS, 2020b.
247
+
248
+ Wenda Li, Lei Yu, Yuhuai Wu, and Lawrence C. Paulson. Isarstep: a benchmark for high-level mathematical reasoning. In ICLR, 2021.
249
+
250
+ Yujia Li, David 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, Po-Sen 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. Competition-level code generation with alphacode. DeepMind, 2022.
251
+
252
+ Stanislas Polu and Ilya Sutskever. Generative language modeling for automated theorem proving. CoRR, abs/2009.03393, 2020. URL https://arxiv.org/abs/2009.03393.
253
+
254
+ Markus Norman Rabe, Dennis Lee, Kshitij Bansal, and Christian Szegedy. Mathematical reasoning via self-supervised skip-tree training. In ICLR, 2021.
255
+
256
+ Jack W Rae, Anna Potapenko, Siddhant M Jayakumar, Chloe Hillier, and Timothy P Lillicrap. Compressive transformers for long-range sequence modelling. In ICLR, 2020.
257
+
258
+ Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, and Peter J. Liu. Exploring the limits of transfer learning with a unified text-to-text transformer. Journal of Machine Learning Research, 2020.
259
+
260
+ Hongyu Ren, Hanjun Dai, Zihang Dai, Mengjiao Yang, Jure Leskovec, Dale Schuurmans, and Bo Dai. Combiner: Full attention transformer with sparse computation cost. CoRR, abs/2107.05768, 2021. URL https://arxiv.org/abs/2107.05768.
261
+
262
+ Aurko Roy, Mohammad Saffar, Ashish Vaswani, and David Grangier. Efficient content-based sparse attention with routing transformers. Transactions of the Association for Computational Linguistics, 9:53–68, 2021.
263
+
264
+ Noam Shazeer and Mitchell Stern. Adafactor: Adaptive learning rates with sublinear memory cost. In ICML, 2018.
265
+
266
+ Sainbayar Sukhbaatar, Edouard Grave, Guillaume Lample, Herve Jegou, and Armand Joulin. Augmenting self-attention with persistent memory. arXiv preprint arXiv:1907.01470, 2019.
267
+
268
+ Sainbayar Sukhbaatar, Da Ju, Spencer Poff, Stephen Roller, Arthur Szlam, Jason Weston, and Angela Fan. Not all memories are created equal: Learning to forget by expiring. In ICML, 2021.
269
+
270
+ Simeng Sun, Kalpesh Krishna, Andrew Mattarella-Micke, and Mohit Iyyer. Do long-range language models actually use long-range context? In EMNLP, 2021.
271
+
272
+ Yi Tay, Mostafa Dehghani, Dara Bahri, and Donald Metzler. Efficient transformers: A survey. arXiv preprint arXiv:2009.06732, 2020.
273
+
274
+ Yi Tay, Mostafa Dehghani, Samira Abnar, Yikang Shen, Dara Bahri, Philip Pham, Jinfeng Rao, Liu Yang, Sebastian Ruder, and Donald Metzler. Long range arena: A benchmark for efficient transformers. In ICLR, 2021.
275
+
276
+ Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Łukasz Kaiser, and Illia Polosukhin. Attention is all you need. In NeurIPS, 2017.
277
+
278
+ Qingxiang Wang, Chad Brown, Cezary Kaliszyk, and Josef Urban. Exploration of neural machine translation in autoformalization of mathematics in mizar. In International Conference on Certified Programs and Proofs, 2020a.
279
+
280
+ Sinong Wang, Belinda Z Li, Madian Khabsa, Han Fang, and Hao Ma. Linformer: Self-attention with linear complexity. arXiv preprint arXiv:2006.04768, 2020b.
281
+
282
+ Xun Wang, Haozhi Zhang, Weilin Huang, and Matthew R. Scott. Cross-batch memory for embedding learning. In CVPR, 2020c.
283
+
284
+ Ronald J. Williams and Jing Peng. An efficient gradient-based algorithm for on-line training of recurrent network trajectories. Neural Computation, 1990.
285
+
286
+ Dani Yogatama, Cyprien de Masson d’Autume, and Lingpeng Kong. Adaptive semiparametric language models. ACL, 9:362–373, 2021.
287
+
288
+ Manzil Zaheer, Guru Guruganesh, Kumar Avinava Dubey, Joshua Ainslie, Chris Alberti, Santiago Ontañón, Philip Pham, Anirudh Ravula, Qifan Wang, Li Yang, and Amr Ahmed. Big bird: Transformers for longer sequences. In NeurIPS, 2020.
289
+
290
+ Yury Zemlyanskiy, Joshua Ainslie, Michiel de Jong, Philip Pham, Ilya Eckstein, and Fei Sha. Readtwice: Reading very large documents with memories. In ACL: Human Language Technologies, 2021.
291
+
292
+ Zhenhai Zhu and Radu Soricut. H-transformer-1d: Fast one-dimensional hierarchical attention for sequences. In ACL, 2021.
293
+
294
+ # A LENGTH OF INPUTS
295
+
296
+ ![](images/590dba826b536883dbd7b839ee67cfd0767b9162d302b75f3df6ce355c757fe0.jpg)
297
+
298
+ Figure 9: Histogram of the number of tokens in arXiv math papers dataset. We tuncated the histogram at 500k tokens. The maximum paper had almost 1.6M tokens.
299
+
300
+ ![](images/392ac5da3e6f25f1ea04b96cb84fa3eff4102cd04a0f0ce5ff97fef8be49ba65.jpg)
301
+
302
+ Figure 10: Histogram of the number of tokens in Github repositories dataset. We cut off the long tail of this plot. The repository with the maximum length has just over 9M tokens.
303
+
304
+ ![](images/869058a85d9ebbb8cb3aece05d5f6c75030dc1420ab9ed7ce7b5e7a8cff0cae2.jpg)
305
+ Figure 11: Histogram of the number of tokens in Isabelle proof scripts dataset.
306
+
307
+ ![](images/bdeca69f56f05a45e94288812872dd89cc33979dff117d6c86f428d2a5fc1362.jpg)
308
+ Figure 12: Histogram of the number of tokens in PG19 books dataset.
309
+
310
+ ![](images/049c1502062b0ef6c727e79a603400063a529317f7c6978f8199ef3811fadea6.jpg)
311
+ Figure 13: Histogram of the number of tokens in C4 documents filtered by documents that have less than 4096 tokens.
312
+
313
+ # A.1 ABLATION STUDIES
314
+
315
+ In the following section, we performed ablation studies to investigate the effects of various hyperparameters. Unless otherwise specified, we carried out these experiments with a memorizing transformer with context size 512, XL cache 512 with a memory size of 8192.
316
+
317
+ Multiple $k \mathbf { N N }$ layers. We experimented with using two $k \mathbf { N N }$ layers, rather than just one. However, we did not see further benefits brought by more than multiple retrieval layers.
318
+
319
+ $k \mathbf { N N }$ layer index We experimented with adding the external memory to layer 3, 6, 9 and 12 in a 12-layer transformer, with results shown in Table 14. We found that adding memory to the middle of the layer stack will obtain the best result, whereas adding memory to layers either too close to the input or to the output obtained less gains.
320
+
321
+ Table 14: Different layer index.
322
+
323
+ <table><tr><td>Layer index</td><td>Perplexity</td></tr><tr><td>3</td><td>2.40</td></tr><tr><td>6</td><td>2.36</td></tr><tr><td>9</td><td>2.37</td></tr><tr><td>12</td><td>2.43</td></tr></table>
324
+
325
+ Number of neighbors We studied the effects of the number of neighbors we retrieve from memory, with results shown in Table 15. We found that even with 32 number of neighbors, we can already obtain a comparable results with 128 or 256 neighbors.
326
+
327
+ Table 15: Number of neighbors.
328
+
329
+ <table><tr><td>Number of neighbors</td><td>Perplexity</td></tr><tr><td>32</td><td>2.38</td></tr><tr><td>128</td><td>2.37</td></tr><tr><td>256</td><td>2.37</td></tr></table>
330
+
331
+ Random seeds We measured the statistical significant of the results reported. We did 3 runs with 3 random seeds for Transformer XL of size 512, and also a memorizing transformer with memory size 8192. We measured the standard deviation of perplexities after 500K steps of training, shown in Table 16. We saw the standard deviation between different runs of the same experiment appears to be much smaller than the gap between different models.
332
+
333
+ Table 16: Random seeds.
334
+
335
+ <table><tr><td>Models</td><td>Perplexity</td></tr><tr><td>Transformer XL</td><td>2.67± 0.01</td></tr><tr><td>Memorizing Transformer</td><td>2.37 ± 0.005</td></tr></table>
336
+
337
+ B WHAT DOES THE MODEL RETRIEVE FROM MEMORY?
338
+
339
+ Retrieving citation names On arXiv math, several examples are shown in Table 17, which includes both the retrieved token and its surrounding context. We observe that many of the gains in crossentropy loss took place when trying to predict the name of bibitems, citations, or references, by looking up the references and citations used previously in the paper. Such lookups usually span over the entire paper, which is much longer than 8192 tokens, providing a plausible explanation for the gain beyond memory size of 8192.
340
+
341
+ Table 17: The table shows several examples of which tokens were retrieved during language modelling of arXiv math dataset. The model is retrieving names of the references from previous passages.
342
+
343
+ <table><tr><td>Query index1</td><td>Input</td><td></td><td>tTargetSurrounding context</td><td></td><td>Retrieved index Retrieved surrounding context</td></tr><tr><td>20389</td><td>Mon</td><td>thus</td><td>bibitem{ComtetMonthusYor</td><td>2208</td><td>Brownian motion \cite{ComtetMonthus Yor</td></tr><tr><td>16623</td><td>cha</td><td>kra</td><td>\cite{ chakrabarti)</td><td>4677</td><td>~1.2 of\cite{chakrabarti</td></tr><tr><td>14747</td><td>as</td><td>d</td><td>\eqref( asdfg ) }which</td><td>3365</td><td>begin{equation}\n \labelt asdfg</td></tr></table>
344
+
345
+ Retrieving function names from the codebase As with the arXiv papers, we also studied which tokens the model retrieved from memory. As might be expected, the model is often looking up the names of functions, and variables, as shown in Table 18.
346
+
347
+ Table 18: Examples of memory retrieval in the Github dataset. The model looks up how functions are used elsewhere in the repository.
348
+
349
+ <table><tr><td>Query index</td><td>Input</td><td></td><td>TargetSurrounding context</td><td></td><td>Retrieved indexRetrieved surrounding context</td></tr><tr><td>23837</td><td>Fo</td><td>nte</td><td>menu_play-&gt; setarFonte</td><td>14607</td><td>menu_load-&gt; setarFonte</td></tr><tr><td>23825</td><td>,</td><td>35</td><td>hscreen/2-50,50,200,35 );</td><td>14599</td><td>20, y+40,200,35)</td></tr><tr><td>14546</td><td>-&gt;</td><td>adi</td><td>panel-&gt; adicionaComponente</td><td>5205</td><td>panel-&gt; adicionaComponente</td></tr></table>
350
+
351
+ # B.1 MORE RETRIEVING EXAMPLES IN FORMAL THEOREM PROVING CORPU
352
+
353
+ # Example 1
354
+
355
+ • Input token index: 64604
356
+ • Input token: “_”
357
+ • Target token: “pair”
358
+ • Surrounding context: )) by (simp add: Fourier_sum_limit_pair [OF f, symmetric] Fourier’ • Name needs to be predicted: Fourier_sum_limit_pair
359
+ • Retrieved token: “Four”
360
+ • Retrieved token index: 64412
361
+ • Retrieved context: $2 ^ { \ast } { \mathfrak { n } }$ . Fourier_coefficient f k \* trigonometric_set k t)
362
+ • Definition of the name: lemma Fourier sum limit pair: assumes"f absolutely_integrable_on {-pi..pi}" shows"(入n. Ck<2 \*n. Fourier_coefficient f k \* trigonometric _set k t) 1 $\longleftrightarrow$ (入n. k<n.Fourier_coefficient f k \*trigonometric_setk t) 1" (is "?lhs $=$ ?rhs")
363
+
364
+ # Example 2
365
+
366
+ • Input token index: 46175
367
+ • Input token: “tri”’
368
+ • Target token: “gon”
369
+ • Surrounding context: <le>n. a k \* trigonometric_set k x) Name needs to be predicted: orthonormal_system_trigonometric_set Retrieved token: “gon”
370
+ • Retrieved token index: 35457
371
+ • Retrieved context: lemma orthonormal_system_trigonometric_set: $\backslash \mathrm { n }$ "orthonormal_system
372
+ • Definition of the name:
373
+
374
+ ![](images/83343cb6eed79c43cb0dd8e243d363d5ae700fb0872618464e56ae9135f177c1.jpg)
375
+ Figure 19: Definition of Fourier_sum_limit_pair.
376
+ Figure 20: Definition of orthonormal_system_trigonometric_set.
377
+
378
+ # Example 3
379
+
380
+ • Input token index: 49760
381
+ • Input token: “sum”’
382
+ • Target token: “m”
383
+ • Surrounding context: nusing Fourier_series_square_summable [OF assms, of’
384
+ • Name needs to be predicted: Fourier_series_square_summable
385
+ • Retrieved token: “sum”
386
+ • Retrieved token index: 35457
387
+ • Retrieved context: lemma Fourier_series_square_summable\n assumes:
388
+ • Definition of the name:
389
+
390
+ Lemma Fourier series square summable: assumes os: "orthonormal_system $\textsf { S w } ^ { * }$ and w: "∧i. (w i) square_integrable S" and f: "f square integrable S" shows "summable (confine (λi. (orthonormal_coeff S w f i) $\sim 2$ ) I)"
391
+
392
+ Figure 21: Definition of Fourier_series_square_summable.
393
+
394
+ # Example 4
395
+
396
+ • Input token index: 49697
397
+ • Input token: “_”’
398
+ • Target token: “system”
399
+ • Surrounding context: lemma Riemann_lebesgue_square_integrable: nassumes "orthonormal_system S w
400
+ • Name needs to be predicted: orthonormal_system
401
+ • Retrieved token: “system”
402
+ • Retrieved token index: 28052
403
+ • Retrieved context: definition orthonormal_system :: "\’a::euclidean’
404
+ • Definition of the name:
405
+
406
+ definition orthonormal_system :: "'a::euclidean_space ${ \mathsf { s e t } } \Rightarrow ( ^ { \mathrm { ~ \iota ~ } } \mathsf { b } \Rightarrow ^ { \mathrm { ~ \iota ~ } } \mathsf { a } \Rightarrow \mathsf { r e a l } ) \Rightarrow \mathsf { b o o l } ^ { \mathrm { ~ \iota ~ } }$ where"orthonormal_system ${ \sf S } \ w \equiv \forall \mathfrak { m } \ \mathfrak { n }$ .l2product S (wm)(wn) $=$ (if m = n then 1 else 0)"
407
+
408
+ # Example 5
409
+
410
+ • Input token index: 34817
411
+ • Input token: “.”’
412
+ • Target token: “b”
413
+ • Surrounding context: shows "integrable (lebesgue_on {a..b})
414
+ • Retrieved token 1: “.”
415
+ • Retrieved token index 1: 2416
416
+ • Retrieved context 1: lebesgue_on {a..b}) f i
417
+ • Retrieved token 2: “-”
418
+ • Retrieved token index 2: 2445
419
+ • Retrieved context 2: (lebesgue_on {a-c..b-c}) (
420
+ • Retrieved token 3: “-”
421
+ • Retreived token index 3: 6479
422
+ • Retrieved context 3: (lebesgue_on {-pi..pi}) (
423
+
424
+ # Example 6
425
+
426
+ • Input token index: 49759
427
+ • Input token: “_”’
428
+ • Target token: “sum”
429
+ • Surrounding context: $0 " \backslash \mathtt { n }$ using Fourier_series_square_summable [OF assms
430
+ • Retrieved token 1: “set”
431
+ • Retrieved token index 1: 35044
432
+ • Retrieved context 1: definition trigonometric_set :: "nat \<Rightarrow>
433
+ • Retrieved token 2: “ier”
434
+ • Retrieved token index 2: 47272
435
+ • Retrieved context 2: definition Fourier_coefficient\nwhere
436
+ • Retrieved token 3: “ine”
437
+ • Retrieved token index 3: 18160
438
+ • Retrieved context 3: lemma Schwartz_inequality_strong:\nassumes “f’
439
+ • Retrieved token 4: “system”
440
+ • Retrieved token index 4: 28052
441
+ • Retrieved context 4: definition orthonormal_system :: “\’a::euclidean’
442
+ • Retrieved token 5: “<”
443
+ • Retrieved token index 5: 47241
444
+ • Retrieved context 5: subsection\<open>Convergence wrt the L’
445
+ • Retrieved token 6: “n”
446
+ • Retrieved token index 6: 40835
447
+ • Retrieved context 6: \n subsection\<open>A bit of extra’
parse/dev/TrjbxzRcnf-/TrjbxzRcnf-_content_list.json ADDED
@@ -0,0 +1,2127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "type": "text",
4
+ "text": "MEMORIZING TRANSFORMERS ",
5
+ "text_level": 1,
6
+ "bbox": [
7
+ 312,
8
+ 113,
9
+ 684,
10
+ 135
11
+ ],
12
+ "page_idx": 0
13
+ },
14
+ {
15
+ "type": "text",
16
+ "text": "Yuhuai Wu, Markus N. Rabe, DeLesley Hutchins, Christian Szegedy ",
17
+ "bbox": [
18
+ 274,
19
+ 164,
20
+ 723,
21
+ 179
22
+ ],
23
+ "page_idx": 0
24
+ },
25
+ {
26
+ "type": "text",
27
+ "text": "{yuhuai,mrabe,delesley,szegedy}@google.com ",
28
+ "bbox": [
29
+ 294,
30
+ 193,
31
+ 704,
32
+ 205
33
+ ],
34
+ "page_idx": 0
35
+ },
36
+ {
37
+ "type": "text",
38
+ "text": "ABSTRACT ",
39
+ "text_level": 1,
40
+ "bbox": [
41
+ 454,
42
+ 246,
43
+ 544,
44
+ 262
45
+ ],
46
+ "page_idx": 0
47
+ },
48
+ {
49
+ "type": "text",
50
+ "text": "Language models typically need to be trained or finetuned in order to acquire new knowledge, which involves updating their weights. We instead envision language models that can simply read and memorize new data at inference time, thus acquiring new knowledge immediately. In this work, we extend language models with the ability to memorize the internal representations of past inputs. We demonstrate that an approximate $k \\mathbf { N N }$ lookup into a non-differentiable memory of recent (key, value) pairs improves language modeling across various benchmarks and tasks, including generic webtext (C4), math papers (arXiv), books (PG-19), code (Github), as well as formal theorems (Isabelle). We show that the performance steadily improves when we increase the size of memory up to 262K tokens. On benchmarks including code and mathematics, we find that the model is capable of making use of newly defined functions and theorems during test time. ",
51
+ "bbox": [
52
+ 233,
53
+ 279,
54
+ 766,
55
+ 445
56
+ ],
57
+ "page_idx": 0
58
+ },
59
+ {
60
+ "type": "text",
61
+ "text": "1 INTRODUCTION ",
62
+ "text_level": 1,
63
+ "bbox": [
64
+ 176,
65
+ 473,
66
+ 336,
67
+ 489
68
+ ],
69
+ "page_idx": 0
70
+ },
71
+ {
72
+ "type": "text",
73
+ "text": "Transformers (Vaswani et al., 2017) have led to remarkable progress in natural language processing (Devlin et al., 2019; Brown et al., 2020), mathematical reasoning (Polu & Sutskever, 2020; Wang et al., 2020a; Rabe et al., 2021; Li et al., 2021; Hahn et al., 2021; Cobbe et al., 2021), and program synthesis (Austin et al., 2021; Chen et al., 2021; Li et al., 2022). However, transformer performance on many of these tasks is limited by the context length of attention, which is typically short. The ability to attend to far-away tokens is important in many situations. In novels, characters and events are referenced across multiple chapters. In source code, references to classes and functions may occur quite far from the places in which they are defined. In theorem proving, proofs make use of previously defined lemmas. ",
74
+ "bbox": [
75
+ 174,
76
+ 505,
77
+ 825,
78
+ 631
79
+ ],
80
+ "page_idx": 0
81
+ },
82
+ {
83
+ "type": "text",
84
+ "text": "Attention over long sequences is also useful as a form of rapid learning. Facts and information which are stored in the form of weight matrices must be slowly trained over hundreds of thousands of training steps. By using attention, however, a model can simply memorize facts (e.g. function definitions) by storing them as (key, value) pairs in long-term memory, and then retrieve those facts later by creating a query that attends to them. In this case, attention acts as a form of information retrieval, allowing the model to look up facts that it has seen previously. ",
85
+ "bbox": [
86
+ 174,
87
+ 637,
88
+ 825,
89
+ 720
90
+ ],
91
+ "page_idx": 0
92
+ },
93
+ {
94
+ "type": "text",
95
+ "text": "We demonstrate that a simple and effective way to increase the size of the attention context is to use approximate $k$ -nearest-neighbor $( k \\mathsf { N N } )$ lookup, which is widely used in information retrieval. A number of extremely scalable implementations of $k \\mathbf { N N }$ lookup are available, such as ScaNN (Guo et al., 2020) and Faiss (Johnson et al., 2021). ",
96
+ "bbox": [
97
+ 174,
98
+ 728,
99
+ 825,
100
+ 784
101
+ ],
102
+ "page_idx": 0
103
+ },
104
+ {
105
+ "type": "text",
106
+ "text": "There are two things which distinguish our approach from previous work on long-range attention (c.f. Section 2). First, unlike some other approaches, $k \\mathbf { N N }$ lookup does not do averaging or summarization of tokens at long distances, but retrieves exact values even from the distant context. ",
107
+ "bbox": [
108
+ 176,
109
+ 791,
110
+ 823,
111
+ 833
112
+ ],
113
+ "page_idx": 0
114
+ },
115
+ {
116
+ "type": "text",
117
+ "text": "Second, gradients are not backpropagated into the external memory, which is critical to the scalability of our technique. The keys and values are a function of model parameters, so attempting to backpropagate gradients into external memory would necessarily involve computing all of the keys and values with the current model parameters on every training step. However, if the external memory is not differentiable, then we can instead instead reuse keys and values that were previously computed on prior training steps, which drastically reduces the amount of computation for large memories. With our technique, we are easily able to scale external memory up to sequence lengths of 131k or 262k tokens on a single TPU device, while maintaining a reasonable step time. ",
118
+ "bbox": [
119
+ 174,
120
+ 840,
121
+ 825,
122
+ 922
123
+ ],
124
+ "page_idx": 0
125
+ },
126
+ {
127
+ "type": "image",
128
+ "img_path": "images/c348262572039ee17a0180d1f12a1ab33318f7e59c45735bf4ae47b93ca7fd68.jpg",
129
+ "image_caption": [
130
+ "Figure 1: Adding a memory of 8K tokens improves perplexity across different model sizes. "
131
+ ],
132
+ "image_footnote": [],
133
+ "bbox": [
134
+ 346,
135
+ 103,
136
+ 648,
137
+ 247
138
+ ],
139
+ "page_idx": 1
140
+ },
141
+ {
142
+ "type": "text",
143
+ "text": "",
144
+ "bbox": [
145
+ 173,
146
+ 291,
147
+ 823,
148
+ 319
149
+ ],
150
+ "page_idx": 1
151
+ },
152
+ {
153
+ "type": "text",
154
+ "text": "We show that model perplexity steadily improves with the size of external memory on a variety of language modelling tasks, including C4 (long documents only), Github code repositories, PG-19 books, formal proofs in Isabelle, and arXiv math papers. We further show that models can generalize to larger memory sizes than they were trained on: models trained with a small memory show gains from using a much larger memory at inference time. Finally, we show that our models are actually using memory in the way that we had hoped, e.g. by looking up the definitions of lemmas in a theorem proving corpus. ",
155
+ "bbox": [
156
+ 174,
157
+ 325,
158
+ 825,
159
+ 424
160
+ ],
161
+ "page_idx": 1
162
+ },
163
+ {
164
+ "type": "text",
165
+ "text": "The simplicity of the changes to the Transformer architecture allows us to easily integrate this approach into existing code bases, including extremely large language models. We further show that the improvements to quality are maintained across models of increasing size, and that the model improvements gained from adding memory are even larger than increasing the size of the model by 5X or more as shown in Figure 1. ",
166
+ "bbox": [
167
+ 174,
168
+ 430,
169
+ 825,
170
+ 501
171
+ ],
172
+ "page_idx": 1
173
+ },
174
+ {
175
+ "type": "text",
176
+ "text": "2 RELATED WORK ",
177
+ "text_level": 1,
178
+ "bbox": [
179
+ 176,
180
+ 526,
181
+ 343,
182
+ 542
183
+ ],
184
+ "page_idx": 1
185
+ },
186
+ {
187
+ "type": "text",
188
+ "text": "A great deal of work has been done on efficient long-range attention mechanisms; see Tay et al. (2020; 2021) recent surveys. Sliding windows (Beltagy et al., 2020) use a long sequence, but attend within a smaller window, thus reducing complexity to the window size, rather than total sequence length. Approximate mechanisms such as Linformer (Wang et al., 2020b), and Performer (Choromanski et al., 2021) refactor the attention matrix by using a different kernel than softmax to obtain $O ( N )$ complexity. Pooling strategies such as Hierarchical 1D attention (Zhu & Soricut, 2021), and Combiner (Ren et al., 2021) apply pooling or averaging over tokens at longer distances. Sparse strategies such as Big Bird (Zaheer et al., 2020) select only a subset of tokens to attend to; Routing Transformers (Roy et al., 2021) use clustering to select the subset, while Reformer (Kitaev et al., 2020) relies on hashing. Hierarchical mechanisms (Ainslie et al., 2020) combine multiple tokens into phrases or sentences to reduce sequence length. Expire-span (Sukhbaatar et al., 2021) prunes far-away tokens that it learns are “unimportant”. (Zemlyanskiy et al., 2021) process long sequences in two passes with different encoders. The second pass is given a lot of context by accessing summaries of the first pass. ",
189
+ "bbox": [
190
+ 173,
191
+ 563,
192
+ 825,
193
+ 742
194
+ ],
195
+ "page_idx": 1
196
+ },
197
+ {
198
+ "type": "text",
199
+ "text": "Feedback transformers (Fan et al., 2020) use a recurrent architecture in which each token attends to the output of the final layer instead of the previous layer. Recurrence does not increase the size of the attention context itself, but it expands the receptive field at the cost of parallelism and training speed. ",
200
+ "bbox": [
201
+ 174,
202
+ 750,
203
+ 825,
204
+ 791
205
+ ],
206
+ "page_idx": 1
207
+ },
208
+ {
209
+ "type": "text",
210
+ "text": "Truncated backpropagation through time (Williams & Peng, 1990) was originally introduced as a way of training recurrent neural networks (RNN) over very long sequences, when the entire sequence does not fit in memory. The sequence is chopped into segments, and after each training step, the final RNN state for the segment is saved in a non-differentiable cache, and used as the initial state on the next training step. Neural caches (Grave et al., 2017) extend the cache to contain a record of many prior hidden states, and attend over them. Transformer-XL (Dai et al., 2019) applies this technique to transformers; it caches the (key,value) pairs computed from the previous training step, and uses them as a prefix for the tokens on the next training step, which yields significant gains on long documents. Rae et al. (2020) improve over Transformer-XL by compressing the tokens before adding them to the cache. In contrast, we use a very large cache without compression, combined with an approximate $k \\mathbf { N N }$ attention mechanism over it. ",
211
+ "bbox": [
212
+ 173,
213
+ 797,
214
+ 825,
215
+ 924
216
+ ],
217
+ "page_idx": 1
218
+ },
219
+ {
220
+ "type": "image",
221
+ "img_path": "images/93d8466b573b5325cd9a069c63eddcdd2572eb8799f9d4720b8a3dbfc7a46115.jpg",
222
+ "image_caption": [
223
+ "Figure 2: We extend Transformers with access to (key, value) pairs of previously seen subsequences. "
224
+ ],
225
+ "image_footnote": [],
226
+ "bbox": [
227
+ 245,
228
+ 94,
229
+ 735,
230
+ 330
231
+ ],
232
+ "page_idx": 2
233
+ },
234
+ {
235
+ "type": "text",
236
+ "text": "",
237
+ "bbox": [
238
+ 174,
239
+ 359,
240
+ 823,
241
+ 387
242
+ ],
243
+ "page_idx": 2
244
+ },
245
+ {
246
+ "type": "text",
247
+ "text": "Sukhbaatar et al. (2019) make the observation that the feed-forward portion of a transformer layer functions very much like attention if one replaces the ReLU activation with softmax. They implement a combined attention over both tokens from the input sequence and a learned (and differentiable) “memory”. Lample et al. (2019) exploit this observation to replace the feed-forward layers (FFNs) with a fast $k \\mathbf { N N }$ lookup over a much larger “memory”, and achieve large gains in model accuracy without significant computation overhead. (We use $k \\mathbf { N N }$ lookup to approximate attention to previous tokens, not to replace the FFN.) ",
248
+ "bbox": [
249
+ 173,
250
+ 395,
251
+ 825,
252
+ 492
253
+ ],
254
+ "page_idx": 2
255
+ },
256
+ {
257
+ "type": "text",
258
+ "text": "Non-differentiable external memory has been used in different ways by Khandelwal et al. (2020), who run a pre-trained model over an entire corpus, and construct a large table of (key, token) pairs. They then use that table to replace the final softmax layer for token selection in the model, which results in significant improvements in language modeling. Yogatama et al. (2021) extend this approach by a gating mechanism and a process to compress the context into keys for retrieval. ",
259
+ "bbox": [
260
+ 174,
261
+ 500,
262
+ 825,
263
+ 569
264
+ ],
265
+ "page_idx": 2
266
+ },
267
+ {
268
+ "type": "text",
269
+ "text": "There are several works that combine retrieval with transformers. REALM (Guu et al., 2020), MARGE (Lewis et al., 2020a), RAG (Lewis et al., 2020b), and composite memory for dialog (Fan et al., 2021) retrieve documents from a knowledge base to improve question answering or dialogue. The knowledge base consists of text snippets and is static and typically separate from the inputs and outputs of the models. Instead, we focus on language modeling using a decoder-only model, and propose a simple model that unifies attention and retrieval. ",
270
+ "bbox": [
271
+ 174,
272
+ 575,
273
+ 825,
274
+ 660
275
+ ],
276
+ "page_idx": 2
277
+ },
278
+ {
279
+ "type": "text",
280
+ "text": "$k$ -nearest-neighbor lookup is a general-purpose technique that is used for a wide variety of machine learning and retrieval tasks, and high-performance implementations are available for various architectures (Johnson et al., 2021; Guo et al., 2020). Memory-efficient Transformers (Gupta et al., 2021) replace dense attention with a $k \\mathbf { N N }$ lookup to increase speed and reduce memory usage. ",
281
+ "bbox": [
282
+ 174,
283
+ 666,
284
+ 825,
285
+ 723
286
+ ],
287
+ "page_idx": 2
288
+ },
289
+ {
290
+ "type": "text",
291
+ "text": "3 METHOD ",
292
+ "text_level": 1,
293
+ "bbox": [
294
+ 176,
295
+ 744,
296
+ 281,
297
+ 761
298
+ ],
299
+ "page_idx": 2
300
+ },
301
+ {
302
+ "type": "text",
303
+ "text": "The architecture of our $k \\mathbf { N N }$ -augmented transformer is shown in Figure 2. The bulk of the model is a vanilla, decoder-only transformer (Vaswani et al., 2017). The input text is tokenized, and the tokens are embedded into vector space. The embedding vectors are passed through a series of transformer layers, each of which does dense self-attention, followed by a feed-forward network (FFN). Since this is a decoder-only language model, we use a causal attention mask and the token embeddings of the last layer are used to predict the next token. ",
304
+ "bbox": [
305
+ 174,
306
+ 776,
307
+ 825,
308
+ 861
309
+ ],
310
+ "page_idx": 2
311
+ },
312
+ {
313
+ "type": "text",
314
+ "text": "Long documents are split into subsequences of 512 tokens, and each subsequence is used as the input for one training step. In contrast to standard practice, we do not shuffle the subsequences; instead, each long document is fed into the transformer sequentially, from beginning to end, as is done with Transformer-XL (Dai et al., 2019). ",
315
+ "bbox": [
316
+ 174,
317
+ 867,
318
+ 825,
319
+ 924
320
+ ],
321
+ "page_idx": 2
322
+ },
323
+ {
324
+ "type": "image",
325
+ "img_path": "images/81f98de49b0afcae04d1631ab7e72f49483236312e44999b1680cfebdad0dc90.jpg",
326
+ "image_caption": [
327
+ "Figure 3: Our data pipeline splits documents into subsequences and packs subsequences into batches. "
328
+ ],
329
+ "image_footnote": [],
330
+ "bbox": [
331
+ 267,
332
+ 92,
333
+ 710,
334
+ 150
335
+ ],
336
+ "page_idx": 3
337
+ },
338
+ {
339
+ "type": "text",
340
+ "text": "We also use a Transformer-XL style cache, which holds the keys and values from the previous training step. When doing self-attention, the cached keys and values are prepended to the current keys and values, and we use a sliding-window causal mask (Beltagy et al., 2020) so that each token has a local context that includes the previous 512 tokens. ",
341
+ "bbox": [
342
+ 174,
343
+ 178,
344
+ 825,
345
+ 234
346
+ ],
347
+ "page_idx": 3
348
+ },
349
+ {
350
+ "type": "text",
351
+ "text": "3.1 $k$ NN-AUGMENTED ATTENTION LAYER ",
352
+ "text_level": 1,
353
+ "bbox": [
354
+ 176,
355
+ 252,
356
+ 482,
357
+ 266
358
+ ],
359
+ "page_idx": 3
360
+ },
361
+ {
362
+ "type": "text",
363
+ "text": "One of the transformer layers near the top of the stack is a kNN-augmented attention layer, which combines two forms of attention. Like all of the other layers, it uses standard dense self-attention on the local context, which is the input subsequence for the current training step. Unlike the other layers, however, it also does an approximate $k$ -nearest-neighbor search into the external memory. ",
364
+ "bbox": [
365
+ 174,
366
+ 277,
367
+ 825,
368
+ 333
369
+ ],
370
+ "page_idx": 3
371
+ },
372
+ {
373
+ "type": "text",
374
+ "text": "The same queries are used for both the local context, and for the external memory. The keys and values also belong to the same distribution; after each training step, the (key, value) pairs in the local context are appended to the end of the external memory. If the document is very long, old (key, value) pairs will be dropped from the memory to make room for new ones. Thus, for each head, the external memory keeps a cache of the prior $M$ (key, value) pairs, where $M$ is the memory size. ",
375
+ "bbox": [
376
+ 174,
377
+ 340,
378
+ 825,
379
+ 411
380
+ ],
381
+ "page_idx": 3
382
+ },
383
+ {
384
+ "type": "text",
385
+ "text": "The $k \\mathbf { N N }$ lookup will return a set of retrieved memories, which consist of the top- $k$ (key, value) pairs that $k \\mathbf { N N }$ search returns for each query (i.e. each token) in the input subsequence. As with standard dense attention, we first construct an attention matrix by computing the dot product of each query against the retrieved keys, then apply softmax, and finally return a weighted sum of the retrieved values. Unlike standard dense attention, the retrieved memories contain a different set of (key, value) pairs for each query. ",
386
+ "bbox": [
387
+ 173,
388
+ 416,
389
+ 825,
390
+ 501
391
+ ],
392
+ "page_idx": 3
393
+ },
394
+ {
395
+ "type": "text",
396
+ "text": "Attention over the local context is performed in the usual way. The results of $k \\mathbf { N N }$ -attention and local attention are then combined using a learned gate: ",
397
+ "bbox": [
398
+ 176,
399
+ 507,
400
+ 820,
401
+ 536
402
+ ],
403
+ "page_idx": 3
404
+ },
405
+ {
406
+ "type": "equation",
407
+ "img_path": "images/bcc1a414349765bb66cda899232d5a3a652a7eeca3407bcadf71361b09e36cd0.jpg",
408
+ "text": "$$\n\\begin{array} { c } { { g = \\sigma ( b _ { g } ) } } \\\\ { { V _ { a } = V _ { m } \\odot g + V _ { c } \\odot ( 1 - g ) } } \\end{array}\n$$",
409
+ "text_format": "latex",
410
+ "bbox": [
411
+ 397,
412
+ 551,
413
+ 601,
414
+ 590
415
+ ],
416
+ "page_idx": 3
417
+ },
418
+ {
419
+ "type": "text",
420
+ "text": "where $\\sigma$ is the sigmoid function, and $\\odot$ is element-wise multiplication. $V _ { a }$ is the combined result of attention, $V _ { m }$ is the result of attending to external memory, and $V _ { c }$ is the result of attending to the local context. The bias $b _ { g }$ is a learned per-head scalar parameter, which allows each head to choose between local and long-range attention. In our experiments, the value of the gate $g$ does not depend on the content of the token at each position, although that would be a trivial extension to implement. We did observe that over time, most heads learned to attend almost exclusively to external memory. ",
421
+ "bbox": [
422
+ 173,
423
+ 601,
424
+ 825,
425
+ 685
426
+ ],
427
+ "page_idx": 3
428
+ },
429
+ {
430
+ "type": "text",
431
+ "text": "Position bias. For dense attention within the local context, we use the T5 relative position bias (Raffel et al., 2020). As noted by Dai et al. (2019), adding a global position encoding to each token does not work well when processing long documents. We don’t use a position bias for the retrieved memories. Experiments on the PG19 dataset (Sun et al., 2021) have shown that relative position does not appear to matter at long range, and the T5 relative bias puts all long-range tokens in the same bucket anyway. ",
432
+ "bbox": [
433
+ 174,
434
+ 691,
435
+ 825,
436
+ 762
437
+ ],
438
+ "page_idx": 3
439
+ },
440
+ {
441
+ "type": "text",
442
+ "text": "Batching. Figure 3 illustrates how multiple long documents of different lengths are packed into a batch, and split into subsequences. Each subsequence in the batch comes from a different document, and thus requires a separate external memory, which is cleared at the start of each new document. ",
443
+ "bbox": [
444
+ 174,
445
+ 768,
446
+ 825,
447
+ 810
448
+ ],
449
+ "page_idx": 3
450
+ },
451
+ {
452
+ "type": "text",
453
+ "text": "3.2 DISTRIBUTIONAL SHIFT ",
454
+ "text_level": 1,
455
+ "bbox": [
456
+ 176,
457
+ 828,
458
+ 382,
459
+ 843
460
+ ],
461
+ "page_idx": 3
462
+ },
463
+ {
464
+ "type": "text",
465
+ "text": "Because each long document is processed over multiple training steps, there is a distributional shift in the keys and values that are stored in external memory. The model parameters that produce the queries change over time, and will thus have shifted since the keys and values were stored. For very large memories, older records may become “stale.” Similar observations have been made for CrossBatch memory (Wang et al., 2020c) in the vision domain. ",
466
+ "bbox": [
467
+ 174,
468
+ 853,
469
+ 825,
470
+ 924
471
+ ],
472
+ "page_idx": 3
473
+ },
474
+ {
475
+ "type": "text",
476
+ "text": "To reduce the effects of staleness, we normalize keys and queries (Henry et al., 2020). Normalization does not eliminate staleness, but it at least ensures that older keys and newer keys do not differ in magnitude. We also found that normalization helps stabilize training with the Transformer-XL cache. ",
477
+ "bbox": [
478
+ 174,
479
+ 103,
480
+ 825,
481
+ 146
482
+ ],
483
+ "page_idx": 4
484
+ },
485
+ {
486
+ "type": "text",
487
+ "text": "In some of our experiments, we observed that training models from scratch with a large memory sometimes resulted in worse performance than pretraining the model with a small memory of size 8192, and then finetuning it on a larger memory. This training instability could be due to staleness. However, models seem to be able to cope with a limited degree of staleness (with the small memory) by adjusting their queries accordingly. ",
488
+ "bbox": [
489
+ 174,
490
+ 152,
491
+ 825,
492
+ 223
493
+ ],
494
+ "page_idx": 4
495
+ },
496
+ {
497
+ "type": "text",
498
+ "text": "3.3 APPROXIMATE $k \\mathbf { N N }$ ",
499
+ "text_level": 1,
500
+ "bbox": [
501
+ 176,
502
+ 241,
503
+ 354,
504
+ 255
505
+ ],
506
+ "page_idx": 4
507
+ },
508
+ {
509
+ "type": "text",
510
+ "text": "We employ approximate $k \\mathbf { N N }$ search rather than exact $k \\mathbf { N N }$ search because it significantly improves the computational speed of our model. We use a simple approximation of $k \\mathbf { N N }$ for TPUs, which has a recall of about $90 \\%$ , i.e. $90 \\%$ of the true top $k$ are returned in the approximate top $k$ . There are various other efficient approximate $k \\mathbf { N N }$ algorithms available for CPU and GPU/TPU, for example through Faiss (Johnson et al., 2021) or ScaNN (Guo et al., 2020), which can scale into the billions. ",
511
+ "bbox": [
512
+ 174,
513
+ 267,
514
+ 825,
515
+ 337
516
+ ],
517
+ "page_idx": 4
518
+ },
519
+ {
520
+ "type": "text",
521
+ "text": "4 EXPERIMENTS ",
522
+ "text_level": 1,
523
+ "bbox": [
524
+ 176,
525
+ 359,
526
+ 326,
527
+ 375
528
+ ],
529
+ "page_idx": 4
530
+ },
531
+ {
532
+ "type": "text",
533
+ "text": "We evaluate the effect of adding external memory on five language modeling tasks, all of which involve long-form text: English language books (PG-19), long web articles (C4), technical math papers (arXiv Math), source code (Github), and formal theorems (Isabelle). The results show significant improvements in the perplexity of the model with the addition of external memory. We experimented with various sizes of external memory, from 1536 to as high as 262K. On most of the datasets, there was an initial sharp gain from adding a small external memory, followed by smaller but steadily increasing gains as the size of the memory was increased. ",
534
+ "bbox": [
535
+ 174,
536
+ 391,
537
+ 825,
538
+ 488
539
+ ],
540
+ "page_idx": 4
541
+ },
542
+ {
543
+ "type": "text",
544
+ "text": "4.1 DATASETS ",
545
+ "text_level": 1,
546
+ "bbox": [
547
+ 174,
548
+ 506,
549
+ 287,
550
+ 521
551
+ ],
552
+ "page_idx": 4
553
+ },
554
+ {
555
+ "type": "text",
556
+ "text": "arXiv Math For the arXiv dataset, we collected a corpus of papers by downloading them via the arXiv Bulk Data Access1. We filtered papers to include only articles labeled as “Mathematics” and whose $\\mathrm { I A T } \\mathrm { E } ^ { \\mathrm { X } }$ source was available. The number of tokens per paper in this dataset is roughly comparable to the number of tokens per book in PG19, because $\\mathrm { I A T } \\mathrm { E } ^ { \\mathrm { X } }$ source has many special characters and the tokenizer tends to output small subwords. ",
557
+ "bbox": [
558
+ 174,
559
+ 532,
560
+ 825,
561
+ 603
562
+ ],
563
+ "page_idx": 4
564
+ },
565
+ {
566
+ "type": "text",
567
+ "text": "Github We used BigQuery2 to obtain a large corpus of Github repositories that are published with open-source licenses. We used file endings to filter for files in the languages C, $\\mathrm { C } { + + }$ , Java, Python (including Jupyter notebooks), Go, and TypeScript. Individual source code files are often fairly short, and there are many dependencies and cross-references between files in the repository. To capture these dependencies, we created one long document for each Github repository by traversing the directory tree, and concatenating all of the files within it. The order in which files are traversed within the repository is random, but each subdirectory is processed as a unit, so that all the files within the subdirectory are close to each other in the resulting document. Source code is usually structured so that related files are all grouped together in the same subdirectory; this traversal preserves that structure, while still shuffling files and subdirectories in random order. ",
568
+ "bbox": [
569
+ 174,
570
+ 618,
571
+ 825,
572
+ 758
573
+ ],
574
+ "page_idx": 4
575
+ },
576
+ {
577
+ "type": "text",
578
+ "text": "Formal Math – Isabelle The Isabelle corpus consists of formal mathematical proofs of theories. We collected all 627 theories available on The Archive of Formal Proofs3 (as of October 6, 2021) and an additional 57 theories from the Isabelle standard library4 to create a corpus of 684 theories. All theories have open-source licenses. Each theory is a self-contained mathematical object, on topics such as foundational logic, advanced analysis, algebra, or cryptography, and consists of multiple files containing proofs. As with the Github corpus, all files that make up a theory are concatenated together into one long document. Unlike the Github corpus, we order the files according to their import dependencies, so that later files use sub-theorems that are proved in earlier files. ",
579
+ "bbox": [
580
+ 176,
581
+ 775,
582
+ 823,
583
+ 859
584
+ ],
585
+ "page_idx": 4
586
+ },
587
+ {
588
+ "type": "table",
589
+ "img_path": "images/ba860c228ba1df8e0970d8053efe9bf7be4795e38980d72a5c422fe74f7d4358.jpg",
590
+ "table_caption": [
591
+ "Table 4: Average token-level perplexities of each model when trained for 500k steps. "
592
+ ],
593
+ "table_footnote": [],
594
+ "table_body": "<table><tr><td>Context</td><td>Memory</td><td>XL cache</td><td>arXiv</td><td>PG19</td><td>C4(4K+)</td><td>GitHub</td><td>Isabelle</td></tr><tr><td>512</td><td>None</td><td>None</td><td>3.29</td><td>13.71</td><td>17.20</td><td>3.05</td><td>3.09</td></tr><tr><td>2048</td><td>None</td><td>None</td><td>2.69</td><td>12.37</td><td>14.81</td><td>2.22</td><td>2.39</td></tr><tr><td>512</td><td>None</td><td>512</td><td>2.67</td><td>12.34</td><td>15.38</td><td>2.26</td><td>2.46</td></tr><tr><td>2048</td><td>None</td><td>2048</td><td>2.42</td><td>11.88</td><td>14.03</td><td>2.10</td><td>2.16</td></tr><tr><td>512</td><td>1536</td><td>None</td><td>2.61</td><td>12.50</td><td>14.97</td><td>2.20</td><td>2.33</td></tr><tr><td>512</td><td>8192</td><td>None</td><td>2.49</td><td>12.29</td><td>14.42</td><td>2.09</td><td>2.19</td></tr><tr><td>512</td><td>8192</td><td>512</td><td>2.37</td><td>11.93</td><td>14.04</td><td>2.03</td><td>2.08</td></tr><tr><td>512</td><td>65K</td><td>512</td><td>2.31</td><td>11.62</td><td>14.04</td><td>1.87</td><td>2.06</td></tr><tr><td>2048</td><td>8192</td><td>2048</td><td>2.33</td><td>11.84</td><td>13.80</td><td>1.98</td><td>2.06</td></tr><tr><td>2048</td><td>65K</td><td>2048</td><td>2.26</td><td>11.37</td><td>13.64</td><td>1.80</td><td>1.99</td></tr></table>",
595
+ "bbox": [
596
+ 240,
597
+ 101,
598
+ 756,
599
+ 276
600
+ ],
601
+ "page_idx": 5
602
+ },
603
+ {
604
+ "type": "text",
605
+ "text": "",
606
+ "bbox": [
607
+ 174,
608
+ 316,
609
+ 823,
610
+ 345
611
+ ],
612
+ "page_idx": 5
613
+ },
614
+ {
615
+ "type": "text",
616
+ "text": "$\\mathbf { C 4 } ( 4 \\mathbf { K } + )$ C4, the colossal cleaned common crawl, is a very large collection of documents that have been scraped from the internet (Raffel et al., 2020). We filtered out all documents that have less than 4096 tokens to focus on documents where memory can have an impact. ",
617
+ "bbox": [
618
+ 174,
619
+ 362,
620
+ 823,
621
+ 404
622
+ ],
623
+ "page_idx": 5
624
+ },
625
+ {
626
+ "type": "text",
627
+ "text": "PG-19 PG-19 is a large dataset of English-language books, published prior to 1919, which were retrieved from the Project Gutenberg archive (Rae et al., 2020; Sun et al., 2021). PG-19 is one of the few public datasets that only contains full-length books, and has become a benchmark for long-range natural language text modeling. ",
628
+ "bbox": [
629
+ 174,
630
+ 421,
631
+ 825,
632
+ 478
633
+ ],
634
+ "page_idx": 5
635
+ },
636
+ {
637
+ "type": "text",
638
+ "text": "4.2 EXPERIMENTAL METHOD ",
639
+ "text_level": 1,
640
+ "bbox": [
641
+ 174,
642
+ 496,
643
+ 393,
644
+ 510
645
+ ],
646
+ "page_idx": 5
647
+ },
648
+ {
649
+ "type": "text",
650
+ "text": "We used a 12-layer decoder-only transformer (with and without Transformer-XL cache) with an embedding size of 1024, 8 attention heads of dimension 128, and an FFN hidden layer of size 4096. For all of our experiments, we used $k = 3 2$ . Unless specified otherwise, we use the 9th layer as the $k \\mathbf { N N }$ augmented attention layer. We used a sentence-piece (Kudo & Richardson, 2018) tokenizer with a vocabulary size of 32K. ",
651
+ "bbox": [
652
+ 174,
653
+ 522,
654
+ 825,
655
+ 592
656
+ ],
657
+ "page_idx": 5
658
+ },
659
+ {
660
+ "type": "text",
661
+ "text": "We used the Adafactor optimizer (Shazeer & Stern, 2018). In preliminary experiments, we conducted a hyperparameter search to determine the optimal learning rate among three choices ({3.0, 1.0, $3 \\cdot { \\bar { 1 0 } } ^ { - 1 } \\}$ ), and found that 1.0 works best. We used a linear warmup schedule for the first 1000 steps, followed by square root decay. We trained the models from scratch for 500K steps on all the datasets, except for the Isabelle dataset. Isabelle is small, so we stopped training after 100K steps when the model began to overfit. We ran all of our experiments on 32 TPU cores. Our models were implemented in JAX (Bradbury et al., 2018) and Flax (Heek et al., 2020). ",
662
+ "bbox": [
663
+ 173,
664
+ 598,
665
+ 825,
666
+ 696
667
+ ],
668
+ "page_idx": 5
669
+ },
670
+ {
671
+ "type": "text",
672
+ "text": "When comparing models with different context lengths, we adjusted the batch size (the number of documents in a batch) so that there are always $2 ^ { 1 7 }$ tokens in a batch. E.g., a model with a context length of 512 has a batch size of 256, while the 2048 model has a batch size of 64. ",
673
+ "bbox": [
674
+ 176,
675
+ 704,
676
+ 821,
677
+ 746
678
+ ],
679
+ "page_idx": 5
680
+ },
681
+ {
682
+ "type": "text",
683
+ "text": "We experimented with multiple implementations of approximate $k \\mathbf { N N }$ lookup with different tradeoffs between quality and computational cost. We did not observe a significant degradation of the model quality when switching to lower quality approximations of $k \\mathbf { N N }$ , so the model appears to be quite robust with respect to the quality of $k \\mathbf { N N }$ retrieval. For a model with around 200M trainable parameters the step time increased from 0.2s to $0 . 2 5 \\mathrm { s }$ when we added a memory of size 8K, and to 0.6s when we added a memory of size 65K (measured on TPUv3). ",
684
+ "bbox": [
685
+ 174,
686
+ 752,
687
+ 825,
688
+ 837
689
+ ],
690
+ "page_idx": 5
691
+ },
692
+ {
693
+ "type": "text",
694
+ "text": "4.3 EFFECT OF EXTERNAL MEMORY ",
695
+ "text_level": 1,
696
+ "bbox": [
697
+ 176,
698
+ 854,
699
+ 434,
700
+ 869
701
+ ],
702
+ "page_idx": 5
703
+ },
704
+ {
705
+ "type": "text",
706
+ "text": "Adding external memory results in substantial gains across datasets and architectures, as shown in Table 4. Across all five datasets, adding external memory to either the vanilla Transformer or the Transformer-XL architecture improves perplexity by a substantial amount. For example, on $\\mathrm { C 4 } ( 4 \\mathrm { K } + )$ dataset, adding memory of size 8192 improves the perplexity of the vanilla Transformer (with context size 512) from 17.20 to 14.42, and improves Transformer-XL from 15.38 to 14.04. ",
707
+ "bbox": [
708
+ 176,
709
+ 882,
710
+ 825,
711
+ 924
712
+ ],
713
+ "page_idx": 5
714
+ },
715
+ {
716
+ "type": "table",
717
+ "img_path": "images/4782106695f92ea320beb22a6928adcb6fa0132108ecbecfc4a6af020e3ce2b3.jpg",
718
+ "table_caption": [],
719
+ "table_footnote": [
720
+ "Table 5: Finetuning for 20K steps to make use of a larger memory on the arXiv data set. "
721
+ ],
722
+ "table_body": "<table><tr><td>Context</td><td>Pretrain</td><td>Fine-tune</td><td>Perplexity</td></tr><tr><td>512</td><td>8192</td><td>None</td><td>2.37</td></tr><tr><td>512</td><td>65K</td><td>None</td><td>2.31</td></tr><tr><td>512</td><td>8192</td><td>65K</td><td>2.32</td></tr><tr><td>512</td><td>8192</td><td>131K</td><td>2.30</td></tr><tr><td>512</td><td>8192</td><td>262K</td><td>2.26</td></tr><tr><td>2048</td><td>8192</td><td>None</td><td>2.33</td></tr><tr><td>2048</td><td>65K</td><td>None</td><td>2.26</td></tr><tr><td>2048</td><td>65K</td><td>131K</td><td>2.23</td></tr><tr><td>2048</td><td>65K</td><td>262K</td><td>2.21</td></tr></table>",
723
+ "bbox": [
724
+ 341,
725
+ 99,
726
+ 655,
727
+ 262
728
+ ],
729
+ "page_idx": 6
730
+ },
731
+ {
732
+ "type": "text",
733
+ "text": "",
734
+ "bbox": [
735
+ 173,
736
+ 309,
737
+ 826,
738
+ 338
739
+ ],
740
+ "page_idx": 6
741
+ },
742
+ {
743
+ "type": "text",
744
+ "text": "Increasing the size of the memory increases the benefit of the memory. The best perplexities for all datasets and architectures were obtained with a memory size of 65K. ",
745
+ "bbox": [
746
+ 173,
747
+ 356,
748
+ 823,
749
+ 383
750
+ ],
751
+ "page_idx": 6
752
+ },
753
+ {
754
+ "type": "text",
755
+ "text": "Note that Transformer-XL with context size 2048 already has a theoretical receptive field that is quite large. Each token in a higher layer can attend up to 2048 tokens away in the layer below, so the total receptive field is $2 0 4 8 \\cdot 1 2$ (layers) $\\sim 2 5 \\mathrm { K }$ . Nevertheless, we still saw a substantial gain when adding an external memory of size 8192 to this model. $k \\mathbf { N N }$ attention into memory would appear to be a more effective way to retrieve information from the distant past than the Transformer-XL cache. ",
756
+ "bbox": [
757
+ 174,
758
+ 390,
759
+ 825,
760
+ 460
761
+ ],
762
+ "page_idx": 6
763
+ },
764
+ {
765
+ "type": "text",
766
+ "text": "On the other hand, we also saw improvements by adding XL cache to the large-memory (65K) models. In a vanilla (non-XL) Transformer, the first few tokens in a sequence have very little context, and thus have higher perplexity. The XL cache provides additional local short-range context at the start of a sequence, which complements the long-range context provided by external memory. ",
767
+ "bbox": [
768
+ 174,
769
+ 467,
770
+ 825,
771
+ 523
772
+ ],
773
+ "page_idx": 6
774
+ },
775
+ {
776
+ "type": "text",
777
+ "text": "Interestingly, in a vanilla Transformer, using even a small external memory of size 1536 provides a gain in perplexity which is almost as good as using a local context of size 2048 but no memory (e.g. Table 4). This is surprising, because the external memory is not differentiable, and is added only to one layer of the Transformer, whereas increasing the context size is differentiable and affects all layers. We conclude that the lower layers of a Transformer don’t necessarily need long-range context, and having a differentiable memory is not as important as one might suspect. ",
778
+ "bbox": [
779
+ 174,
780
+ 530,
781
+ 825,
782
+ 614
783
+ ],
784
+ "page_idx": 6
785
+ },
786
+ {
787
+ "type": "text",
788
+ "text": "4.4 SCALING TO LARGER MODELS ",
789
+ "text_level": 1,
790
+ "bbox": [
791
+ 176,
792
+ 633,
793
+ 423,
794
+ 647
795
+ ],
796
+ "page_idx": 6
797
+ },
798
+ {
799
+ "type": "text",
800
+ "text": "We scaled up the Transformer model to sizes of 1 and 8 billion parameters. For the 1 billion parameter model, we use 8 layers, 32 heads with head dimension 128, $d _ { - }$ model 2048, and $d _ { - }$ _ff 16384. For the 8 billion parameter model, we use 64 heads, 16 layers, $d$ _model 4096, and $d _ { - }$ _ff 32768. We used a context size of 2048, memory size of 8192, and no XL cache. We ran the comparisons to the vanilla Transformer on the arXiv math dataset. Scaling plots are shown in Figure 1. ",
801
+ "bbox": [
802
+ 174,
803
+ 660,
804
+ 825,
805
+ 731
806
+ ],
807
+ "page_idx": 6
808
+ },
809
+ {
810
+ "type": "text",
811
+ "text": "External memory provides a consistent improvement to the model as it is scaled up. Remarkably, we found that the smaller Memorizing Transformer with just 8k tokens in memory can match the perplexity of a larger vanilla Transformer which has 5X more trainable parameters. ",
812
+ "bbox": [
813
+ 176,
814
+ 737,
815
+ 825,
816
+ 780
817
+ ],
818
+ "page_idx": 6
819
+ },
820
+ {
821
+ "type": "text",
822
+ "text": "4.5 FINETUNING ON LARGER MEMORIES ",
823
+ "text_level": 1,
824
+ "bbox": [
825
+ 176,
826
+ 799,
827
+ 472,
828
+ 813
829
+ ],
830
+ "page_idx": 6
831
+ },
832
+ {
833
+ "type": "text",
834
+ "text": "Finetuning on a larger memory. In some cases, training was unstable when using large memories, possibly due to distributional shift early in the training (See Section 3.2). Thus, for memories of 131K or more tokens, we first pretrain the model with a memory size of 8192 or 65K for 500K steps, and then finetune it with the larger memory for an additional 20K steps. The results of finetuning on the arXiv Math data set are shown in Table 5. Increasing the size of external memory provided consistent gains up to a size of 262K. Note that 262K tokens is longer than almost all of the documents in arXiv, and thus we would not expect to see any gain past this point (see Appendix A). ",
835
+ "bbox": [
836
+ 174,
837
+ 827,
838
+ 825,
839
+ 924
840
+ ],
841
+ "page_idx": 6
842
+ },
843
+ {
844
+ "type": "image",
845
+ "img_path": "images/14d1bef481a2ec3931ed59a899d428ebe8a68caed797c0d03c05a6ce7c996ad0.jpg",
846
+ "image_caption": [
847
+ "Figure 6: Finetuning a 1B vanilla Transformer model to use external memory of size 65K. "
848
+ ],
849
+ "image_footnote": [],
850
+ "bbox": [
851
+ 348,
852
+ 104,
853
+ 647,
854
+ 273
855
+ ],
856
+ "page_idx": 7
857
+ },
858
+ {
859
+ "type": "text",
860
+ "text": "Finetuning a non-memory model to use memory Pretraining can be very costly both in time and computational resources. Thus, a natural question to ask is: can one fine-tune a pretrained Transformer to use external memory? The answer is yes! ",
861
+ "bbox": [
862
+ 176,
863
+ 328,
864
+ 823,
865
+ 369
866
+ ],
867
+ "page_idx": 7
868
+ },
869
+ {
870
+ "type": "text",
871
+ "text": "We took a pre-trained 1B vanilla Transformer model, and fine-tuned it to use external memory (the 1B models used in Section 4.4). The fine-tuning result is shown in Figure 6. Notice that the model quickly learns to use external memory. Within 20K steps $4 \\%$ of the pre-training time) the fine-tuned model has already closed $8 5 \\%$ of the gap between it and the 1B Memorizing Transformer, and after $1 0 0 \\mathrm { k }$ steps it has closed the gap entirely. ",
872
+ "bbox": [
873
+ 174,
874
+ 376,
875
+ 825,
876
+ 446
877
+ ],
878
+ "page_idx": 7
879
+ },
880
+ {
881
+ "type": "text",
882
+ "text": "4.6 INFORMATION RETRIEVAL PATTERNS ",
883
+ "text_level": 1,
884
+ "bbox": [
885
+ 176,
886
+ 469,
887
+ 473,
888
+ 483
889
+ ],
890
+ "page_idx": 7
891
+ },
892
+ {
893
+ "type": "text",
894
+ "text": "We conducted a qualitative study of what the model was actually retrieving from external memory, by finding which tokens showed the biggest improvements in cross-entropy loss when the size of the memory was increased, and then examining the top- $k$ retrieved memories for those tokens. We found that the model gained the most when looking up rare words, such as proper names, references, citations, and function names, where the first use of a name is too far away from subsequent uses to fit in the local context. This result is in keeping with the prior analysis of long-context Transformers on PG19 (Sun et al., 2021), which found similar lookup patterns. For this experiment, we used a slightly older version of the architecture without the gating mechanism. ",
895
+ "bbox": [
896
+ 174,
897
+ 497,
898
+ 825,
899
+ 609
900
+ ],
901
+ "page_idx": 7
902
+ },
903
+ {
904
+ "type": "text",
905
+ "text": "Which tokens show a benefit from memory? Figure 7 shows a visualization of which tokens show an improvement when the size of the external memory is increased. We selected a math paper at random, and plotted the difference in cross entropy loss for each token $x _ { i }$ in the paper, comparing two models with the same parameters, but with memories of different sizes. $\\Delta _ { i } = \\mathrm { c r o s s - e n t r o p y } _ { 8 1 9 2 } ( x _ { i } )$ $- \\mathrm { c r o s s - e n t r o p y } _ { 3 2 \\mathrm { K } } ( x _ { i } )$ . Positive values show an improvement in loss. ",
906
+ "bbox": [
907
+ 174,
908
+ 630,
909
+ 825,
910
+ 700
911
+ ],
912
+ "page_idx": 7
913
+ },
914
+ {
915
+ "type": "text",
916
+ "text": "The $x$ -axis on the chart is the token number $i$ , while the $y$ -axis is $\\Delta _ { i }$ . For the first 8192 tokens, the difference between the two models is zero, since the larger capacity of the 32K memory isn’t being used yet. However, after token 8193, we can see that the larger memory helps, on average, over the smaller memory. The benefit is not universal, since the predictions for some tokens become worse, possibly due to the fact that a relevant retrieved memory no longer makes it into the top- $k$ when the size of the external memory is increased. This figure also shows that the benefit of external memory is somewhat sparse. The improvement in perplexity seems to be mainly driven by a small percentage of tokens that obtain a large improvement in cross-entropy loss when using the larger memory. ",
917
+ "bbox": [
918
+ 174,
919
+ 707,
920
+ 825,
921
+ 819
922
+ ],
923
+ "page_idx": 7
924
+ },
925
+ {
926
+ "type": "text",
927
+ "text": "What information is being looked up? Given that only a subset of tokens shows improvement from external memory, we did a further investigation into what, exactly, those tokens are using the memory for. We took those tokens which showed the largest improvement in cross-entropy loss, and for each of them tokens, we examined the top- $k$ retrieved memories. We studied arXiv math, Github and Isabelle corpus. For arXiv math and Github, we found the model retrieved function and variable names. See more details with examples in Appendix B. ",
928
+ "bbox": [
929
+ 174,
930
+ 840,
931
+ 825,
932
+ 924
933
+ ],
934
+ "page_idx": 7
935
+ },
936
+ {
937
+ "type": "image",
938
+ "img_path": "images/ac7dcbfadeffdce1e7c62204b4feff0227f84bf9079091c5be4d5700f286a668.jpg",
939
+ "image_caption": [
940
+ "Figure 7: Difference in loss for each token in a randomly chosen paper, using the same model once with a memory size of 8K and once with 32K. Higher numbers mean the longer memory helped in comparison to the shorter memory. This paper is 22K tokens long. "
941
+ ],
942
+ "image_footnote": [],
943
+ "bbox": [
944
+ 207,
945
+ 92,
946
+ 792,
947
+ 161
948
+ ],
949
+ "page_idx": 8
950
+ },
951
+ {
952
+ "type": "table",
953
+ "img_path": "images/4cf585def3b67985c0413709b5970581b404b2a5f9e8e8dcb838c1acadc6ca0b.jpg",
954
+ "table_caption": [
955
+ "Table 8: Examples of memory retrieval in the Isabelle dataset. The model is able to find the definition of a lemma from a reference to it. The retrieved surrounding context (highlighted) is the definition body of the mathematical object highlighted in the querying context. "
956
+ ],
957
+ "table_footnote": [],
958
+ "table_body": "<table><tr><td></td><td></td><td></td><td>Query indexInputTargetSurrounding context</td><td></td><td>Retrieved index Retrieved surrounding context</td></tr><tr><td>29721</td><td>mark</td><td>ov</td><td>rule prob_space. markov_inequality</td><td>8088</td><td>M.t\\&lt;le&gt; X a} \\&lt;le&gt; expectation X /t&quot;</td></tr><tr><td>40919</td><td>1</td><td>th</td><td>= ( subgraph_threshold Hn / p n)</td><td>27219</td><td>threshold H n = n powr (-(1 / max_density’</td></tr><tr><td>49699</td><td>S</td><td>W</td><td>assumes&#x27; orthonormal_system Sw&quot;</td><td>28050</td><td>definition orthonormal_system “</td></tr></table>",
959
+ "bbox": [
960
+ 174,
961
+ 231,
962
+ 823,
963
+ 295
964
+ ],
965
+ "page_idx": 8
966
+ },
967
+ {
968
+ "type": "text",
969
+ "text": "Retrieving mathematical definitions. Our case study on the Isabelle corpus provides one of the clearest illustrations of how a model can make good use of external memory. When predicting the name of a mathematical object or a lemma, the model looked up the definition from earlier in the proof. Examples of this behavior are shown in Table 8. In example 1, the model retrieves a definition within the body of a lemma, markov_inequality. In example 2, it retrieves the definition of a previously defined concept subgraph_threshold. In example 3, it retrieves the definition of orthonormal_system. We manually checked 10 examples where the model made a prediction of lemma names, and 8 out of 10 times model found the body of the lemma it needs to predict. In the other two cases, the model also looked up materials in the immediate vicinity. To the best of our knowledge, this is the first demonstration that attention is capable of looking up definitions and function bodies from a large corpus. The Isabelle case study used a model with two memory layers of size 32K. ",
970
+ "bbox": [
971
+ 174,
972
+ 358,
973
+ 825,
974
+ 525
975
+ ],
976
+ "page_idx": 8
977
+ },
978
+ {
979
+ "type": "text",
980
+ "text": "5 CONCLUSION ",
981
+ "text_level": 1,
982
+ "bbox": [
983
+ 176,
984
+ 545,
985
+ 318,
986
+ 561
987
+ ],
988
+ "page_idx": 8
989
+ },
990
+ {
991
+ "type": "text",
992
+ "text": "We present a simple extension to the Transformer architecture, called kNN-augmented attention, which dramatically increases the length of the context that a language model can attend to by using $k$ -nearest-neighbor lookup into a large external memory. We demonstrate the effectiveness of external memory in a series of language modeling experiments over a variety of long-document datasets, including LaTeX documents, source code, formal proofs, and books. ",
993
+ "bbox": [
994
+ 174,
995
+ 577,
996
+ 825,
997
+ 647
998
+ ],
999
+ "page_idx": 8
1000
+ },
1001
+ {
1002
+ "type": "text",
1003
+ "text": "The Memorizing Transformer shows large improvements in perplexity over the baseline for all of the data sets and architectures that we studied; it is comparable to a vanilla transformer that has 5 times the number of parameters. Perplexity continues to improve with increasing memory size, although there is a point of diminishing returns. Moreover, external memory continues to provide benefits even as the transformer is scaled up from 200M to 8B parameters. Perhaps most intriguingly, a Memorizing Transformer does not need to be pre-trained from scratch; it is possible obtain large gains from adding memory to an existing pre-trained model, and then fine-tuning it. ",
1004
+ "bbox": [
1005
+ 174,
1006
+ 654,
1007
+ 825,
1008
+ 751
1009
+ ],
1010
+ "page_idx": 8
1011
+ },
1012
+ {
1013
+ "type": "text",
1014
+ "text": "Unlike other forms of attention, $k \\mathbf { N N }$ retrieval can be easily scaled up to huge memory sizes, and is thus potentially able to leverage vast knowledge bases or code repositories. How to make the best use of this capability is a topic for future work. ",
1015
+ "bbox": [
1016
+ 176,
1017
+ 758,
1018
+ 823,
1019
+ 800
1020
+ ],
1021
+ "page_idx": 8
1022
+ },
1023
+ {
1024
+ "type": "text",
1025
+ "text": "ACKNOWLEDGMENTS ",
1026
+ "text_level": 1,
1027
+ "bbox": [
1028
+ 176,
1029
+ 816,
1030
+ 326,
1031
+ 829
1032
+ ],
1033
+ "page_idx": 8
1034
+ },
1035
+ {
1036
+ "type": "text",
1037
+ "text": "We want to thank Charles Staats for the many fruitful discussions and detailed comments, Henryk Michalewski for early version of of the memory implementation, Petros Maniatis for his help with our code datasets, Aitor Lewkowycz for his help with larger scale memorizing transformer experiments, Behnam Neyshabur for his comments on finetuning non-memory models, Imanol Schlag for his proofread and detailed comments, and Dennis Lee and Manzil Zaheer for discussions about large-scale attention and retrieval. ",
1038
+ "bbox": [
1039
+ 174,
1040
+ 840,
1041
+ 825,
1042
+ 922
1043
+ ],
1044
+ "page_idx": 8
1045
+ },
1046
+ {
1047
+ "type": "text",
1048
+ "text": "ETHICS ",
1049
+ "text_level": 1,
1050
+ "bbox": [
1051
+ 176,
1052
+ 102,
1053
+ 238,
1054
+ 118
1055
+ ],
1056
+ "page_idx": 9
1057
+ },
1058
+ {
1059
+ "type": "text",
1060
+ "text": "The ability to memorize large databases of facts could have potential ramifications for society, especially if those databases include sensitive personal information or copyrighted works. However, one advantage of using an external memory is that the memory can be easily cleared of all such information, as we do at the end of each document that we train on. The same is not true of differentiable model parameters, which is what most existing architectures use to store facts and information that they are trained on. ",
1061
+ "bbox": [
1062
+ 174,
1063
+ 133,
1064
+ 825,
1065
+ 217
1066
+ ],
1067
+ "page_idx": 9
1068
+ },
1069
+ {
1070
+ "type": "text",
1071
+ "text": "REPRODUCIBILITY ",
1072
+ "text_level": 1,
1073
+ "bbox": [
1074
+ 176,
1075
+ 237,
1076
+ 331,
1077
+ 252
1078
+ ],
1079
+ "page_idx": 9
1080
+ },
1081
+ {
1082
+ "type": "text",
1083
+ "text": "Details of our architecture and training hyperparameters are given in Section 4.2. The datasets for C4 and PG-19 are publicly available. Our additional datasets, Github, Isabelle, and ArXiv Math are derived from publicly available data buckets, which we link in the main part of the paper. Subsection 4.1 include details on how we constructed the datasets from those datasets. We plan to release our code as open source. ",
1084
+ "bbox": [
1085
+ 174,
1086
+ 268,
1087
+ 825,
1088
+ 338
1089
+ ],
1090
+ "page_idx": 9
1091
+ },
1092
+ {
1093
+ "type": "text",
1094
+ "text": "REFERENCES ",
1095
+ "text_level": 1,
1096
+ "bbox": [
1097
+ 176,
1098
+ 359,
1099
+ 285,
1100
+ 375
1101
+ ],
1102
+ "page_idx": 9
1103
+ },
1104
+ {
1105
+ "type": "text",
1106
+ "text": "Joshua Ainslie, Santiago Ontañón, Chris Alberti, Vaclav Cvicek, Zachary Fisher, Philip Pham, Anirudh Ravula, Sumit Sanghai, Qifan Wang, and Li Yang. ETC: encoding long and structured inputs in transformers. In EMNLP, 2020. ",
1107
+ "bbox": [
1108
+ 174,
1109
+ 382,
1110
+ 826,
1111
+ 424
1112
+ ],
1113
+ "page_idx": 9
1114
+ },
1115
+ {
1116
+ "type": "text",
1117
+ "text": "Jacob Austin, Augustus Odena, Maxwell Nye, Maarten Bosma, Henryk Michalewski, David Dohan, Ellen Jiang, Carrie J. Cai, Michael Terry, Quoc V. Le, and Charles Sutton. Program synthesis with large language models. CoRR, abs/2108.07732, 2021. URL https://arxiv.org/abs/ 2108.07732. ",
1118
+ "bbox": [
1119
+ 174,
1120
+ 433,
1121
+ 826,
1122
+ 488
1123
+ ],
1124
+ "page_idx": 9
1125
+ },
1126
+ {
1127
+ "type": "text",
1128
+ "text": "Iz Beltagy, Matthew E. Peters, and Arman Cohan. Longformer: The long-document transformer. CoRR, abs/2004.05150, 2020. URL https://arxiv.org/abs/2004.05150. ",
1129
+ "bbox": [
1130
+ 176,
1131
+ 497,
1132
+ 825,
1133
+ 526
1134
+ ],
1135
+ "page_idx": 9
1136
+ },
1137
+ {
1138
+ "type": "text",
1139
+ "text": "James Bradbury, Roy Frostig, Peter Hawkins, Matthew James Johnson, Chris Leary, Dougal Maclaurin, George Necula, Adam Paszke, Jake VanderPlas, Skye Wanderman-Milne, and Qiao Zhang. JAX: composable transformations of Python+NumPy programs, 2018. URL http://github.com/google/jax. ",
1140
+ "bbox": [
1141
+ 173,
1142
+ 535,
1143
+ 826,
1144
+ 590
1145
+ ],
1146
+ "page_idx": 9
1147
+ },
1148
+ {
1149
+ "type": "text",
1150
+ "text": "Tom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah, Jared Kaplan, Prafulla Dhariwal, Arvind Neelakantan, Pranav Shyam, Girish Sastry, Amanda Askell, Sandhini Agarwal, Ariel Herbert-Voss, Gretchen Krueger, Tom Henighan, Rewon Child, Aditya Ramesh, Daniel M. Ziegler, Jeffrey Wu, Clemens Winter, Christopher Hesse, Mark Chen, Eric Sigler, Mateusz Litwin, Scott Gray, Benjamin Chess, Jack Clark, Christopher Berner, Sam McCandlish, Alec Radford, Ilya Sutskever, and Dario Amodei. Language models are few-shot learners. In NeurIPS, 2020. ",
1151
+ "bbox": [
1152
+ 174,
1153
+ 599,
1154
+ 826,
1155
+ 683
1156
+ ],
1157
+ "page_idx": 9
1158
+ },
1159
+ {
1160
+ "type": "text",
1161
+ "text": "Mark Chen, Jerry Tworek, Heewoo Jun, Qiming Yuan, Henrique Ponde de Oliveira Pinto, Jared Kaplan, Harrison Edwards, Yuri Burda, Nicholas Joseph, Greg Brockman, Alex Ray, Raul Puri, Gretchen Krueger, Michael Petrov, Heidy Khlaaf, Girish Sastry, Pamela Mishkin, Brooke Chan, Scott Gray, Nick Ryder, Mikhail Pavlov, Alethea Power, Lukasz Kaiser, Mohammad Bavarian, Clemens Winter, Philippe Tillet, Felipe Petroski Such, Dave Cummings, Matthias Plappert, Fotios Chantzis, Elizabeth Barnes, Ariel Herbert-Voss, William Hebgen Guss, Alex Nichol, Alex Paino, Nikolas Tezak, Jie Tang, Igor Babuschkin, Suchir Balaji, Shantanu Jain, William Saunders, Christopher Hesse, Andrew N. Carr, Jan Leike, Joshua Achiam, Vedant Misra, Evan Morikawa, Alec Radford, Matthew Knight, Miles Brundage, Mira Murati, Katie Mayer, Peter Welinder, Bob McGrew, Dario Amodei, Sam McCandlish, Ilya Sutskever, and Wojciech Zaremba. Evaluating large language models trained on code. CoRR, abs/2107.03374, 2021. URL https://arxiv. org/abs/2107.03374. ",
1162
+ "bbox": [
1163
+ 176,
1164
+ 691,
1165
+ 826,
1166
+ 858
1167
+ ],
1168
+ "page_idx": 9
1169
+ },
1170
+ {
1171
+ "type": "text",
1172
+ "text": "Krzysztof Marcin Choromanski, Valerii Likhosherstov, David Dohan, Xingyou Song, Andreea Gane, Tamás Sarlós, Peter Hawkins, Jared Quincy Davis, Afroz Mohiuddin, Lukasz Kaiser, David Benjamin Belanger, Lucy J. Colwell, and Adrian Weller. Rethinking attention with performers. In ICLR, 2021. ",
1173
+ "bbox": [
1174
+ 176,
1175
+ 867,
1176
+ 826,
1177
+ 922
1178
+ ],
1179
+ "page_idx": 9
1180
+ },
1181
+ {
1182
+ "type": "text",
1183
+ "text": "Karl Cobbe, Vineet Kosaraju, Mohammad Bavarian, Jacob Hilton, Reiichiro Nakano, Christopher Hesse, and John Schulman. Training verifiers to solve math word problems. CoRR, abs/2110.14168, 2021. URL https://arxiv.org/abs/2110.14168. ",
1184
+ "bbox": [
1185
+ 176,
1186
+ 103,
1187
+ 823,
1188
+ 146
1189
+ ],
1190
+ "page_idx": 10
1191
+ },
1192
+ {
1193
+ "type": "text",
1194
+ "text": "Zihang Dai, Zhilin Yang, Yiming Yang, Jaime G. Carbonell, Quoc Viet Le, and Ruslan Salakhutdinov. Transformer-XL: Attentive language models beyond a fixed-length context. In ACL, 2019. ",
1195
+ "bbox": [
1196
+ 173,
1197
+ 155,
1198
+ 825,
1199
+ 184
1200
+ ],
1201
+ "page_idx": 10
1202
+ },
1203
+ {
1204
+ "type": "text",
1205
+ "text": "Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. BERT: pre-training of deep bidirectional transformers for language understanding. In ACL, 2019. ",
1206
+ "bbox": [
1207
+ 171,
1208
+ 193,
1209
+ 823,
1210
+ 222
1211
+ ],
1212
+ "page_idx": 10
1213
+ },
1214
+ {
1215
+ "type": "text",
1216
+ "text": "Angela Fan, Thibaut Lavril, Edouard Grave, Armand Joulin, and Sainbayar Sukhbaatar. Addressing some limitations of transformers with feedback memory. arXiv preprint arXiv:2002.09402, 2020. ",
1217
+ "bbox": [
1218
+ 171,
1219
+ 231,
1220
+ 825,
1221
+ 261
1222
+ ],
1223
+ "page_idx": 10
1224
+ },
1225
+ {
1226
+ "type": "text",
1227
+ "text": "Angela Fan, Claire Gardent, Chloé Braud, and Antoine Bordes. Augmenting transformers with KNN-based composite memory for dialog. Transactions of the Association for Computational Linguistics, 9:82–99, 2021. ",
1228
+ "bbox": [
1229
+ 173,
1230
+ 268,
1231
+ 825,
1232
+ 313
1233
+ ],
1234
+ "page_idx": 10
1235
+ },
1236
+ {
1237
+ "type": "text",
1238
+ "text": "Edouard Grave, Armand Joulin, and Nicolas Usunier. Improving neural language models with a continuous cache. In ICLR, 2017. ",
1239
+ "bbox": [
1240
+ 173,
1241
+ 320,
1242
+ 823,
1243
+ 351
1244
+ ],
1245
+ "page_idx": 10
1246
+ },
1247
+ {
1248
+ "type": "text",
1249
+ "text": "Ruiqi Guo, Philip Sun, Erik Lindgren, Quan Geng, David Simcha, Felix Chern, and Sanjiv Kumar. Accelerating large-scale inference with anisotropic vector quantization. In ICML, 2020. ",
1250
+ "bbox": [
1251
+ 173,
1252
+ 358,
1253
+ 823,
1254
+ 388
1255
+ ],
1256
+ "page_idx": 10
1257
+ },
1258
+ {
1259
+ "type": "text",
1260
+ "text": "Ankit Gupta, Guy Dar, Shaya Goodman, David Ciprut, and Jonathan Berant. Memory-efficient transformers via top- $\\mathbf { \\nabla } \\cdot \\mathbf { k }$ attention. CoRR, abs/2106.06899, 2021. URL https://arxiv.org/ abs/2106.06899. ",
1261
+ "bbox": [
1262
+ 174,
1263
+ 397,
1264
+ 823,
1265
+ 439
1266
+ ],
1267
+ "page_idx": 10
1268
+ },
1269
+ {
1270
+ "type": "text",
1271
+ "text": "Kelvin Guu, Kenton Lee, Zora Tung, Panupong Pasupat, and Ming-Wei Chang. Retrieval augmented language model pre-training. In ICML, 2020. ",
1272
+ "bbox": [
1273
+ 174,
1274
+ 449,
1275
+ 823,
1276
+ 478
1277
+ ],
1278
+ "page_idx": 10
1279
+ },
1280
+ {
1281
+ "type": "text",
1282
+ "text": "Christopher Hahn, Frederik Schmitt, Jens U. Kreber, Markus Norman Rabe, and Bernd Finkbeiner. Teaching temporal logics to neural networks. In ICLR, 2021. ",
1283
+ "bbox": [
1284
+ 174,
1285
+ 486,
1286
+ 823,
1287
+ 516
1288
+ ],
1289
+ "page_idx": 10
1290
+ },
1291
+ {
1292
+ "type": "text",
1293
+ "text": "Jonathan Heek, Anselm Levskaya, Avital Oliver, Marvin Ritter, Bertrand Rondepierre, Andreas Steiner, and Marc van Zee. Flax: A neural network library and ecosystem for JAX, 2020. URL http://github.com/google/flax. ",
1294
+ "bbox": [
1295
+ 176,
1296
+ 525,
1297
+ 823,
1298
+ 568
1299
+ ],
1300
+ "page_idx": 10
1301
+ },
1302
+ {
1303
+ "type": "text",
1304
+ "text": "Alex Henry, Prudhvi Raj Dachapally, Shubham Shantaram Pawar, and Yuxuan Chen. Query-key normalization for transformers. In EMNLP, 2020. ",
1305
+ "bbox": [
1306
+ 171,
1307
+ 577,
1308
+ 823,
1309
+ 606
1310
+ ],
1311
+ "page_idx": 10
1312
+ },
1313
+ {
1314
+ "type": "text",
1315
+ "text": "Jeff Johnson, Matthijs Douze, and Hervé Jégou. Billion-scale similarity search with GPUs. IEEE Transactions on Big Data, 2021. ",
1316
+ "bbox": [
1317
+ 173,
1318
+ 614,
1319
+ 825,
1320
+ 645
1321
+ ],
1322
+ "page_idx": 10
1323
+ },
1324
+ {
1325
+ "type": "text",
1326
+ "text": "Urvashi Khandelwal, Omer Levy, Dan Jurafsky, Luke Zettlemoyer, and Mike Lewis. Generalization through memorization: Nearest neighbor language models. In ICLR, 2020. ",
1327
+ "bbox": [
1328
+ 173,
1329
+ 652,
1330
+ 823,
1331
+ 683
1332
+ ],
1333
+ "page_idx": 10
1334
+ },
1335
+ {
1336
+ "type": "text",
1337
+ "text": "Nikita Kitaev, Łukasz Kaiser, and Anselm Levskaya. Reformer: The efficient transformer. In ICLR, 2020. ",
1338
+ "bbox": [
1339
+ 173,
1340
+ 690,
1341
+ 825,
1342
+ 720
1343
+ ],
1344
+ "page_idx": 10
1345
+ },
1346
+ {
1347
+ "type": "text",
1348
+ "text": "Taku Kudo and John Richardson. Sentencepiece: A simple and language independent subword tokenizer and detokenizer for neural text processing. In EMNLP, 2018. ",
1349
+ "bbox": [
1350
+ 173,
1351
+ 729,
1352
+ 823,
1353
+ 758
1354
+ ],
1355
+ "page_idx": 10
1356
+ },
1357
+ {
1358
+ "type": "text",
1359
+ "text": "Guillaume Lample, Alexandre Sablayrolles, Marc’Aurelio Ranzato, Ludovic Denoyer, and Hervé Jégou. Large memory layers with product keys. In NeurIPS, 2019. ",
1360
+ "bbox": [
1361
+ 173,
1362
+ 767,
1363
+ 823,
1364
+ 796
1365
+ ],
1366
+ "page_idx": 10
1367
+ },
1368
+ {
1369
+ "type": "text",
1370
+ "text": "Mike Lewis, Marjan Ghazvininejad, Gargi Ghosh, Armen Aghajanyan, Sida Wang, and Luke Zettlemoyer. Pre-training via paraphrasing. In NeurIPS, 2020a. ",
1371
+ "bbox": [
1372
+ 173,
1373
+ 804,
1374
+ 823,
1375
+ 834
1376
+ ],
1377
+ "page_idx": 10
1378
+ },
1379
+ {
1380
+ "type": "text",
1381
+ "text": "Patrick Lewis, Ethan Perez, Aleksandra Piktus, Fabio Petroni, Vladimir Karpukhin, Naman Goyal, Heinrich Küttler, Mike Lewis, Wen-tau Yih, Tim Rocktäschel, et al. Retrieval-augmented generation for knowledge-intensive NLP tasks. In NeurIPS, 2020b. ",
1382
+ "bbox": [
1383
+ 174,
1384
+ 843,
1385
+ 823,
1386
+ 886
1387
+ ],
1388
+ "page_idx": 10
1389
+ },
1390
+ {
1391
+ "type": "text",
1392
+ "text": "Wenda Li, Lei Yu, Yuhuai Wu, and Lawrence C. Paulson. Isarstep: a benchmark for high-level mathematical reasoning. In ICLR, 2021. ",
1393
+ "bbox": [
1394
+ 174,
1395
+ 895,
1396
+ 820,
1397
+ 924
1398
+ ],
1399
+ "page_idx": 10
1400
+ },
1401
+ {
1402
+ "type": "text",
1403
+ "text": "Yujia Li, David 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, Po-Sen 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. Competition-level code generation with alphacode. DeepMind, 2022. ",
1404
+ "bbox": [
1405
+ 176,
1406
+ 103,
1407
+ 825,
1408
+ 188
1409
+ ],
1410
+ "page_idx": 11
1411
+ },
1412
+ {
1413
+ "type": "text",
1414
+ "text": "Stanislas Polu and Ilya Sutskever. Generative language modeling for automated theorem proving. CoRR, abs/2009.03393, 2020. URL https://arxiv.org/abs/2009.03393. ",
1415
+ "bbox": [
1416
+ 178,
1417
+ 195,
1418
+ 823,
1419
+ 224
1420
+ ],
1421
+ "page_idx": 11
1422
+ },
1423
+ {
1424
+ "type": "text",
1425
+ "text": "Markus Norman Rabe, Dennis Lee, Kshitij Bansal, and Christian Szegedy. Mathematical reasoning via self-supervised skip-tree training. In ICLR, 2021. ",
1426
+ "bbox": [
1427
+ 174,
1428
+ 233,
1429
+ 821,
1430
+ 262
1431
+ ],
1432
+ "page_idx": 11
1433
+ },
1434
+ {
1435
+ "type": "text",
1436
+ "text": "Jack W Rae, Anna Potapenko, Siddhant M Jayakumar, Chloe Hillier, and Timothy P Lillicrap. Compressive transformers for long-range sequence modelling. In ICLR, 2020. ",
1437
+ "bbox": [
1438
+ 174,
1439
+ 270,
1440
+ 820,
1441
+ 299
1442
+ ],
1443
+ "page_idx": 11
1444
+ },
1445
+ {
1446
+ "type": "text",
1447
+ "text": "Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, and Peter J. Liu. Exploring the limits of transfer learning with a unified text-to-text transformer. Journal of Machine Learning Research, 2020. ",
1448
+ "bbox": [
1449
+ 176,
1450
+ 306,
1451
+ 823,
1452
+ 349
1453
+ ],
1454
+ "page_idx": 11
1455
+ },
1456
+ {
1457
+ "type": "text",
1458
+ "text": "Hongyu Ren, Hanjun Dai, Zihang Dai, Mengjiao Yang, Jure Leskovec, Dale Schuurmans, and Bo Dai. Combiner: Full attention transformer with sparse computation cost. CoRR, abs/2107.05768, 2021. URL https://arxiv.org/abs/2107.05768. ",
1459
+ "bbox": [
1460
+ 174,
1461
+ 357,
1462
+ 826,
1463
+ 401
1464
+ ],
1465
+ "page_idx": 11
1466
+ },
1467
+ {
1468
+ "type": "text",
1469
+ "text": "Aurko Roy, Mohammad Saffar, Ashish Vaswani, and David Grangier. Efficient content-based sparse attention with routing transformers. Transactions of the Association for Computational Linguistics, 9:53–68, 2021. ",
1470
+ "bbox": [
1471
+ 174,
1472
+ 409,
1473
+ 826,
1474
+ 450
1475
+ ],
1476
+ "page_idx": 11
1477
+ },
1478
+ {
1479
+ "type": "text",
1480
+ "text": "Noam Shazeer and Mitchell Stern. Adafactor: Adaptive learning rates with sublinear memory cost. In ICML, 2018. ",
1481
+ "bbox": [
1482
+ 173,
1483
+ 459,
1484
+ 823,
1485
+ 488
1486
+ ],
1487
+ "page_idx": 11
1488
+ },
1489
+ {
1490
+ "type": "text",
1491
+ "text": "Sainbayar Sukhbaatar, Edouard Grave, Guillaume Lample, Herve Jegou, and Armand Joulin. Augmenting self-attention with persistent memory. arXiv preprint arXiv:1907.01470, 2019. ",
1492
+ "bbox": [
1493
+ 173,
1494
+ 496,
1495
+ 823,
1496
+ 526
1497
+ ],
1498
+ "page_idx": 11
1499
+ },
1500
+ {
1501
+ "type": "text",
1502
+ "text": "Sainbayar Sukhbaatar, Da Ju, Spencer Poff, Stephen Roller, Arthur Szlam, Jason Weston, and Angela Fan. Not all memories are created equal: Learning to forget by expiring. In ICML, 2021. ",
1503
+ "bbox": [
1504
+ 176,
1505
+ 534,
1506
+ 823,
1507
+ 563
1508
+ ],
1509
+ "page_idx": 11
1510
+ },
1511
+ {
1512
+ "type": "text",
1513
+ "text": "Simeng Sun, Kalpesh Krishna, Andrew Mattarella-Micke, and Mohit Iyyer. Do long-range language models actually use long-range context? In EMNLP, 2021. ",
1514
+ "bbox": [
1515
+ 173,
1516
+ 570,
1517
+ 821,
1518
+ 599
1519
+ ],
1520
+ "page_idx": 11
1521
+ },
1522
+ {
1523
+ "type": "text",
1524
+ "text": "Yi Tay, Mostafa Dehghani, Dara Bahri, and Donald Metzler. Efficient transformers: A survey. arXiv preprint arXiv:2009.06732, 2020. ",
1525
+ "bbox": [
1526
+ 176,
1527
+ 607,
1528
+ 821,
1529
+ 637
1530
+ ],
1531
+ "page_idx": 11
1532
+ },
1533
+ {
1534
+ "type": "text",
1535
+ "text": "Yi Tay, Mostafa Dehghani, Samira Abnar, Yikang Shen, Dara Bahri, Philip Pham, Jinfeng Rao, Liu Yang, Sebastian Ruder, and Donald Metzler. Long range arena: A benchmark for efficient transformers. In ICLR, 2021. ",
1536
+ "bbox": [
1537
+ 174,
1538
+ 645,
1539
+ 826,
1540
+ 688
1541
+ ],
1542
+ "page_idx": 11
1543
+ },
1544
+ {
1545
+ "type": "text",
1546
+ "text": "Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Łukasz Kaiser, and Illia Polosukhin. Attention is all you need. In NeurIPS, 2017. ",
1547
+ "bbox": [
1548
+ 171,
1549
+ 695,
1550
+ 823,
1551
+ 724
1552
+ ],
1553
+ "page_idx": 11
1554
+ },
1555
+ {
1556
+ "type": "text",
1557
+ "text": "Qingxiang Wang, Chad Brown, Cezary Kaliszyk, and Josef Urban. Exploration of neural machine translation in autoformalization of mathematics in mizar. In International Conference on Certified Programs and Proofs, 2020a. ",
1558
+ "bbox": [
1559
+ 173,
1560
+ 733,
1561
+ 825,
1562
+ 775
1563
+ ],
1564
+ "page_idx": 11
1565
+ },
1566
+ {
1567
+ "type": "text",
1568
+ "text": "Sinong Wang, Belinda Z Li, Madian Khabsa, Han Fang, and Hao Ma. Linformer: Self-attention with linear complexity. arXiv preprint arXiv:2006.04768, 2020b. ",
1569
+ "bbox": [
1570
+ 171,
1571
+ 784,
1572
+ 823,
1573
+ 813
1574
+ ],
1575
+ "page_idx": 11
1576
+ },
1577
+ {
1578
+ "type": "text",
1579
+ "text": "Xun Wang, Haozhi Zhang, Weilin Huang, and Matthew R. Scott. Cross-batch memory for embedding learning. In CVPR, 2020c. ",
1580
+ "bbox": [
1581
+ 173,
1582
+ 820,
1583
+ 823,
1584
+ 849
1585
+ ],
1586
+ "page_idx": 11
1587
+ },
1588
+ {
1589
+ "type": "text",
1590
+ "text": "Ronald J. Williams and Jing Peng. An efficient gradient-based algorithm for on-line training of recurrent network trajectories. Neural Computation, 1990. ",
1591
+ "bbox": [
1592
+ 173,
1593
+ 858,
1594
+ 821,
1595
+ 887
1596
+ ],
1597
+ "page_idx": 11
1598
+ },
1599
+ {
1600
+ "type": "text",
1601
+ "text": "Dani Yogatama, Cyprien de Masson d’Autume, and Lingpeng Kong. Adaptive semiparametric language models. ACL, 9:362–373, 2021. ",
1602
+ "bbox": [
1603
+ 174,
1604
+ 895,
1605
+ 821,
1606
+ 924
1607
+ ],
1608
+ "page_idx": 11
1609
+ },
1610
+ {
1611
+ "type": "text",
1612
+ "text": "Manzil Zaheer, Guru Guruganesh, Kumar Avinava Dubey, Joshua Ainslie, Chris Alberti, Santiago Ontañón, Philip Pham, Anirudh Ravula, Qifan Wang, Li Yang, and Amr Ahmed. Big bird: Transformers for longer sequences. In NeurIPS, 2020. ",
1613
+ "bbox": [
1614
+ 178,
1615
+ 103,
1616
+ 823,
1617
+ 146
1618
+ ],
1619
+ "page_idx": 12
1620
+ },
1621
+ {
1622
+ "type": "text",
1623
+ "text": "Yury Zemlyanskiy, Joshua Ainslie, Michiel de Jong, Philip Pham, Ilya Eckstein, and Fei Sha. Readtwice: Reading very large documents with memories. In ACL: Human Language Technologies, 2021. ",
1624
+ "bbox": [
1625
+ 174,
1626
+ 155,
1627
+ 823,
1628
+ 196
1629
+ ],
1630
+ "page_idx": 12
1631
+ },
1632
+ {
1633
+ "type": "text",
1634
+ "text": "Zhenhai Zhu and Radu Soricut. H-transformer-1d: Fast one-dimensional hierarchical attention for sequences. In ACL, 2021. ",
1635
+ "bbox": [
1636
+ 171,
1637
+ 207,
1638
+ 823,
1639
+ 234
1640
+ ],
1641
+ "page_idx": 12
1642
+ },
1643
+ {
1644
+ "type": "text",
1645
+ "text": "A LENGTH OF INPUTS ",
1646
+ "text_level": 1,
1647
+ "bbox": [
1648
+ 176,
1649
+ 102,
1650
+ 375,
1651
+ 118
1652
+ ],
1653
+ "page_idx": 13
1654
+ },
1655
+ {
1656
+ "type": "image",
1657
+ "img_path": "images/590dba826b536883dbd7b839ee67cfd0767b9162d302b75f3df6ce355c757fe0.jpg",
1658
+ "image_caption": [],
1659
+ "image_footnote": [],
1660
+ "bbox": [
1661
+ 176,
1662
+ 137,
1663
+ 820,
1664
+ 190
1665
+ ],
1666
+ "page_idx": 13
1667
+ },
1668
+ {
1669
+ "type": "text",
1670
+ "text": "Figure 9: Histogram of the number of tokens in arXiv math papers dataset. We tuncated the histogram at 500k tokens. The maximum paper had almost 1.6M tokens. ",
1671
+ "bbox": [
1672
+ 171,
1673
+ 203,
1674
+ 821,
1675
+ 232
1676
+ ],
1677
+ "page_idx": 13
1678
+ },
1679
+ {
1680
+ "type": "image",
1681
+ "img_path": "images/392ac5da3e6f25f1ea04b96cb84fa3eff4102cd04a0f0ce5ff97fef8be49ba65.jpg",
1682
+ "image_caption": [],
1683
+ "image_footnote": [],
1684
+ "bbox": [
1685
+ 176,
1686
+ 246,
1687
+ 821,
1688
+ 301
1689
+ ],
1690
+ "page_idx": 13
1691
+ },
1692
+ {
1693
+ "type": "text",
1694
+ "text": "Figure 10: Histogram of the number of tokens in Github repositories dataset. We cut off the long tail of this plot. The repository with the maximum length has just over 9M tokens. ",
1695
+ "bbox": [
1696
+ 171,
1697
+ 314,
1698
+ 823,
1699
+ 343
1700
+ ],
1701
+ "page_idx": 13
1702
+ },
1703
+ {
1704
+ "type": "image",
1705
+ "img_path": "images/869058a85d9ebbb8cb3aece05d5f6c75030dc1420ab9ed7ce7b5e7a8cff0cae2.jpg",
1706
+ "image_caption": [
1707
+ "Figure 11: Histogram of the number of tokens in Isabelle proof scripts dataset. "
1708
+ ],
1709
+ "image_footnote": [],
1710
+ "bbox": [
1711
+ 178,
1712
+ 358,
1713
+ 820,
1714
+ 412
1715
+ ],
1716
+ "page_idx": 13
1717
+ },
1718
+ {
1719
+ "type": "image",
1720
+ "img_path": "images/bdeca69f56f05a45e94288812872dd89cc33979dff117d6c86f428d2a5fc1362.jpg",
1721
+ "image_caption": [
1722
+ "Figure 12: Histogram of the number of tokens in PG19 books dataset. "
1723
+ ],
1724
+ "image_footnote": [],
1725
+ "bbox": [
1726
+ 178,
1727
+ 457,
1728
+ 820,
1729
+ 511
1730
+ ],
1731
+ "page_idx": 13
1732
+ },
1733
+ {
1734
+ "type": "image",
1735
+ "img_path": "images/049c1502062b0ef6c727e79a603400063a529317f7c6978f8199ef3811fadea6.jpg",
1736
+ "image_caption": [
1737
+ "Figure 13: Histogram of the number of tokens in C4 documents filtered by documents that have less than 4096 tokens. "
1738
+ ],
1739
+ "image_footnote": [],
1740
+ "bbox": [
1741
+ 178,
1742
+ 554,
1743
+ 820,
1744
+ 607
1745
+ ],
1746
+ "page_idx": 13
1747
+ },
1748
+ {
1749
+ "type": "text",
1750
+ "text": "A.1 ABLATION STUDIES ",
1751
+ "text_level": 1,
1752
+ "bbox": [
1753
+ 176,
1754
+ 103,
1755
+ 356,
1756
+ 117
1757
+ ],
1758
+ "page_idx": 14
1759
+ },
1760
+ {
1761
+ "type": "text",
1762
+ "text": "In the following section, we performed ablation studies to investigate the effects of various hyperparameters. Unless otherwise specified, we carried out these experiments with a memorizing transformer with context size 512, XL cache 512 with a memory size of 8192. ",
1763
+ "bbox": [
1764
+ 174,
1765
+ 128,
1766
+ 825,
1767
+ 171
1768
+ ],
1769
+ "page_idx": 14
1770
+ },
1771
+ {
1772
+ "type": "text",
1773
+ "text": "Multiple $k \\mathbf { N N }$ layers. We experimented with using two $k \\mathbf { N N }$ layers, rather than just one. However, we did not see further benefits brought by more than multiple retrieval layers. ",
1774
+ "bbox": [
1775
+ 174,
1776
+ 186,
1777
+ 823,
1778
+ 215
1779
+ ],
1780
+ "page_idx": 14
1781
+ },
1782
+ {
1783
+ "type": "text",
1784
+ "text": "$k \\mathbf { N N }$ layer index We experimented with adding the external memory to layer 3, 6, 9 and 12 in a 12-layer transformer, with results shown in Table 14. We found that adding memory to the middle of the layer stack will obtain the best result, whereas adding memory to layers either too close to the input or to the output obtained less gains. ",
1785
+ "bbox": [
1786
+ 174,
1787
+ 231,
1788
+ 825,
1789
+ 286
1790
+ ],
1791
+ "page_idx": 14
1792
+ },
1793
+ {
1794
+ "type": "table",
1795
+ "img_path": "images/70af44f82e22b7385bd6dbe298c52907b4c7a64f7f87918a633ee0be210798d2.jpg",
1796
+ "table_caption": [
1797
+ "Table 14: Different layer index. "
1798
+ ],
1799
+ "table_footnote": [],
1800
+ "table_body": "<table><tr><td>Layer index</td><td>Perplexity</td></tr><tr><td>3</td><td>2.40</td></tr><tr><td>6</td><td>2.36</td></tr><tr><td>9</td><td>2.37</td></tr><tr><td>12</td><td>2.43</td></tr></table>",
1801
+ "bbox": [
1802
+ 398,
1803
+ 335,
1804
+ 598,
1805
+ 426
1806
+ ],
1807
+ "page_idx": 14
1808
+ },
1809
+ {
1810
+ "type": "text",
1811
+ "text": "Number of neighbors We studied the effects of the number of neighbors we retrieve from memory, with results shown in Table 15. We found that even with 32 number of neighbors, we can already obtain a comparable results with 128 or 256 neighbors. ",
1812
+ "bbox": [
1813
+ 174,
1814
+ 450,
1815
+ 826,
1816
+ 493
1817
+ ],
1818
+ "page_idx": 14
1819
+ },
1820
+ {
1821
+ "type": "table",
1822
+ "img_path": "images/0d2009b64b5845b15ab5ce864c14f087c2773bbcadd1c93b710156037edf6b71.jpg",
1823
+ "table_caption": [
1824
+ "Table 15: Number of neighbors. "
1825
+ ],
1826
+ "table_footnote": [],
1827
+ "table_body": "<table><tr><td>Number of neighbors</td><td>Perplexity</td></tr><tr><td>32</td><td>2.38</td></tr><tr><td>128</td><td>2.37</td></tr><tr><td>256</td><td>2.37</td></tr></table>",
1828
+ "bbox": [
1829
+ 367,
1830
+ 541,
1831
+ 630,
1832
+ 618
1833
+ ],
1834
+ "page_idx": 14
1835
+ },
1836
+ {
1837
+ "type": "text",
1838
+ "text": "Random seeds We measured the statistical significant of the results reported. We did 3 runs with 3 random seeds for Transformer XL of size 512, and also a memorizing transformer with memory size 8192. We measured the standard deviation of perplexities after 500K steps of training, shown in Table 16. We saw the standard deviation between different runs of the same experiment appears to be much smaller than the gap between different models. ",
1839
+ "bbox": [
1840
+ 173,
1841
+ 642,
1842
+ 825,
1843
+ 712
1844
+ ],
1845
+ "page_idx": 14
1846
+ },
1847
+ {
1848
+ "type": "table",
1849
+ "img_path": "images/ac5365688e10dead3907cd7d2436c635a339a5c8ce323a9ee3f11d67937fc5ba.jpg",
1850
+ "table_caption": [
1851
+ "Table 16: Random seeds. "
1852
+ ],
1853
+ "table_footnote": [],
1854
+ "table_body": "<table><tr><td>Models</td><td>Perplexity</td></tr><tr><td>Transformer XL</td><td>2.67± 0.01</td></tr><tr><td>Memorizing Transformer</td><td>2.37 ± 0.005</td></tr></table>",
1855
+ "bbox": [
1856
+ 367,
1857
+ 761,
1858
+ 630,
1859
+ 814
1860
+ ],
1861
+ "page_idx": 14
1862
+ },
1863
+ {
1864
+ "type": "text",
1865
+ "text": "B WHAT DOES THE MODEL RETRIEVE FROM MEMORY? ",
1866
+ "bbox": [
1867
+ 174,
1868
+ 102,
1869
+ 645,
1870
+ 118
1871
+ ],
1872
+ "page_idx": 15
1873
+ },
1874
+ {
1875
+ "type": "text",
1876
+ "text": "Retrieving citation names On arXiv math, several examples are shown in Table 17, which includes both the retrieved token and its surrounding context. We observe that many of the gains in crossentropy loss took place when trying to predict the name of bibitems, citations, or references, by looking up the references and citations used previously in the paper. Such lookups usually span over the entire paper, which is much longer than 8192 tokens, providing a plausible explanation for the gain beyond memory size of 8192. ",
1877
+ "bbox": [
1878
+ 174,
1879
+ 133,
1880
+ 825,
1881
+ 217
1882
+ ],
1883
+ "page_idx": 15
1884
+ },
1885
+ {
1886
+ "type": "table",
1887
+ "img_path": "images/f0823719b76942ff54990140f592457ad251405b00ddeb20b85a6f2c4f05b204.jpg",
1888
+ "table_caption": [
1889
+ "Table 17: The table shows several examples of which tokens were retrieved during language modelling of arXiv math dataset. The model is retrieving names of the references from previous passages. "
1890
+ ],
1891
+ "table_footnote": [],
1892
+ "table_body": "<table><tr><td>Query index1</td><td>Input</td><td></td><td>tTargetSurrounding context</td><td></td><td>Retrieved index Retrieved surrounding context</td></tr><tr><td>20389</td><td>Mon</td><td>thus</td><td>bibitem{ComtetMonthusYor</td><td>2208</td><td>Brownian motion \\cite{ComtetMonthus Yor</td></tr><tr><td>16623</td><td>cha</td><td>kra</td><td>\\cite{ chakrabarti)</td><td>4677</td><td>~1.2 of\\cite{chakrabarti</td></tr><tr><td>14747</td><td>as</td><td>d</td><td>\\eqref( asdfg ) }which</td><td>3365</td><td>begin{equation}\\n \\labelt asdfg</td></tr></table>",
1893
+ "bbox": [
1894
+ 173,
1895
+ 256,
1896
+ 823,
1897
+ 316
1898
+ ],
1899
+ "page_idx": 15
1900
+ },
1901
+ {
1902
+ "type": "text",
1903
+ "text": "Retrieving function names from the codebase As with the arXiv papers, we also studied which tokens the model retrieved from memory. As might be expected, the model is often looking up the names of functions, and variables, as shown in Table 18. ",
1904
+ "bbox": [
1905
+ 174,
1906
+ 325,
1907
+ 825,
1908
+ 367
1909
+ ],
1910
+ "page_idx": 15
1911
+ },
1912
+ {
1913
+ "type": "table",
1914
+ "img_path": "images/9f34896ea4cb386413a8a8f9da6a94e95e5f6a1b3f29c08e898d3e2c626cfe15.jpg",
1915
+ "table_caption": [
1916
+ "Table 18: Examples of memory retrieval in the Github dataset. The model looks up how functions are used elsewhere in the repository. "
1917
+ ],
1918
+ "table_footnote": [],
1919
+ "table_body": "<table><tr><td>Query index</td><td>Input</td><td></td><td>TargetSurrounding context</td><td></td><td>Retrieved indexRetrieved surrounding context</td></tr><tr><td>23837</td><td>Fo</td><td>nte</td><td>menu_play-&gt; setarFonte</td><td>14607</td><td>menu_load-&gt; setarFonte</td></tr><tr><td>23825</td><td>,</td><td>35</td><td>hscreen/2-50,50,200,35 );</td><td>14599</td><td>20, y+40,200,35)</td></tr><tr><td>14546</td><td>-&gt;</td><td>adi</td><td>panel-&gt; adicionaComponente</td><td>5205</td><td>panel-&gt; adicionaComponente</td></tr></table>",
1920
+ "bbox": [
1921
+ 173,
1922
+ 421,
1923
+ 823,
1924
+ 491
1925
+ ],
1926
+ "page_idx": 15
1927
+ },
1928
+ {
1929
+ "type": "text",
1930
+ "text": "B.1 MORE RETRIEVING EXAMPLES IN FORMAL THEOREM PROVING CORPU",
1931
+ "text_level": 1,
1932
+ "bbox": [
1933
+ 181,
1934
+ 104,
1935
+ 705,
1936
+ 117
1937
+ ],
1938
+ "page_idx": 16
1939
+ },
1940
+ {
1941
+ "type": "text",
1942
+ "text": "Example 1 ",
1943
+ "text_level": 1,
1944
+ "bbox": [
1945
+ 173,
1946
+ 130,
1947
+ 250,
1948
+ 145
1949
+ ],
1950
+ "page_idx": 16
1951
+ },
1952
+ {
1953
+ "type": "text",
1954
+ "text": "• Input token index: 64604 \n• Input token: “_” \n• Target token: “pair” \n• Surrounding context: )) by (simp add: Fourier_sum_limit_pair [OF f, symmetric] Fourier’ • Name needs to be predicted: Fourier_sum_limit_pair \n• Retrieved token: “Four” \n• Retrieved token index: 64412 \n• Retrieved context: $2 ^ { \\ast } { \\mathfrak { n } }$ . Fourier_coefficient f k \\* trigonometric_set k t) \n• Definition of the name: lemma Fourier sum limit pair: assumes\"f absolutely_integrable_on {-pi..pi}\" shows\"(入n. Ck<2 \\*n. Fourier_coefficient f k \\* trigonometric _set k t) 1 $\\longleftrightarrow$ (入n. k<n.Fourier_coefficient f k \\*trigonometric_setk t) 1\" (is \"?lhs $=$ ?rhs\") ",
1955
+ "bbox": [
1956
+ 215,
1957
+ 156,
1958
+ 820,
1959
+ 387
1960
+ ],
1961
+ "page_idx": 16
1962
+ },
1963
+ {
1964
+ "type": "text",
1965
+ "text": "Example 2 ",
1966
+ "text_level": 1,
1967
+ "bbox": [
1968
+ 173,
1969
+ 435,
1970
+ 251,
1971
+ 449
1972
+ ],
1973
+ "page_idx": 16
1974
+ },
1975
+ {
1976
+ "type": "text",
1977
+ "text": "• Input token index: 46175 \n• Input token: “tri”’ \n• Target token: “gon” \n• Surrounding context: <le>n. a k \\* trigonometric_set k x) Name needs to be predicted: orthonormal_system_trigonometric_set Retrieved token: “gon” \n• Retrieved token index: 35457 \n• Retrieved context: lemma orthonormal_system_trigonometric_set: $\\backslash \\mathrm { n }$ \"orthonormal_system \n• Definition of the name: ",
1978
+ "bbox": [
1979
+ 215,
1980
+ 460,
1981
+ 815,
1982
+ 627
1983
+ ],
1984
+ "page_idx": 16
1985
+ },
1986
+ {
1987
+ "type": "image",
1988
+ "img_path": "images/83343cb6eed79c43cb0dd8e243d363d5ae700fb0872618464e56ae9135f177c1.jpg",
1989
+ "image_caption": [
1990
+ "Figure 19: Definition of Fourier_sum_limit_pair. ",
1991
+ "Figure 20: Definition of orthonormal_system_trigonometric_set. "
1992
+ ],
1993
+ "image_footnote": [],
1994
+ "bbox": [
1995
+ 272,
1996
+ 642,
1997
+ 718,
1998
+ 671
1999
+ ],
2000
+ "page_idx": 16
2001
+ },
2002
+ {
2003
+ "type": "text",
2004
+ "text": "Example 3 ",
2005
+ "text_level": 1,
2006
+ "bbox": [
2007
+ 173,
2008
+ 103,
2009
+ 251,
2010
+ 118
2011
+ ],
2012
+ "page_idx": 17
2013
+ },
2014
+ {
2015
+ "type": "text",
2016
+ "text": "• Input token index: 49760 \n• Input token: “sum”’ \n• Target token: “m” \n• Surrounding context: nusing Fourier_series_square_summable [OF assms, of’ \n• Name needs to be predicted: Fourier_series_square_summable \n• Retrieved token: “sum” \n• Retrieved token index: 35457 \n• Retrieved context: lemma Fourier_series_square_summable\\n assumes: \n• Definition of the name: ",
2017
+ "bbox": [
2018
+ 215,
2019
+ 130,
2020
+ 745,
2021
+ 295
2022
+ ],
2023
+ "page_idx": 17
2024
+ },
2025
+ {
2026
+ "type": "text",
2027
+ "text": "Lemma Fourier series square summable: assumes os: \"orthonormal_system $\\textsf { S w } ^ { * }$ and w: \"∧i. (w i) square_integrable S\" and f: \"f square integrable S\" shows \"summable (confine (λi. (orthonormal_coeff S w f i) $\\sim 2$ ) I)\" ",
2028
+ "bbox": [
2029
+ 272,
2030
+ 310,
2031
+ 723,
2032
+ 348
2033
+ ],
2034
+ "page_idx": 17
2035
+ },
2036
+ {
2037
+ "type": "text",
2038
+ "text": "Figure 21: Definition of Fourier_series_square_summable. ",
2039
+ "bbox": [
2040
+ 267,
2041
+ 363,
2042
+ 728,
2043
+ 377
2044
+ ],
2045
+ "page_idx": 17
2046
+ },
2047
+ {
2048
+ "type": "text",
2049
+ "text": "Example 4 ",
2050
+ "text_level": 1,
2051
+ "bbox": [
2052
+ 173,
2053
+ 396,
2054
+ 251,
2055
+ 410
2056
+ ],
2057
+ "page_idx": 17
2058
+ },
2059
+ {
2060
+ "type": "text",
2061
+ "text": "• Input token index: 49697 \n• Input token: “_”’ \n• Target token: “system” \n• Surrounding context: lemma Riemann_lebesgue_square_integrable: nassumes \"orthonormal_system S w \n• Name needs to be predicted: orthonormal_system \n• Retrieved token: “system” \n• Retrieved token index: 28052 \n• Retrieved context: definition orthonormal_system :: \"\\’a::euclidean’ \n• Definition of the name: ",
2062
+ "bbox": [
2063
+ 215,
2064
+ 422,
2065
+ 681,
2066
+ 602
2067
+ ],
2068
+ "page_idx": 17
2069
+ },
2070
+ {
2071
+ "type": "text",
2072
+ "text": "definition orthonormal_system :: \"'a::euclidean_space ${ \\mathsf { s e t } } \\Rightarrow ( ^ { \\mathrm { ~ \\iota ~ } } \\mathsf { b } \\Rightarrow ^ { \\mathrm { ~ \\iota ~ } } \\mathsf { a } \\Rightarrow \\mathsf { r e a l } ) \\Rightarrow \\mathsf { b o o l } ^ { \\mathrm { ~ \\iota ~ } }$ where\"orthonormal_system ${ \\sf S } \\ w \\equiv \\forall \\mathfrak { m } \\ \\mathfrak { n }$ .l2product S (wm)(wn) $=$ (if m = n then 1 else 0)\" ",
2073
+ "bbox": [
2074
+ 210,
2075
+ 616,
2076
+ 790,
2077
+ 637
2078
+ ],
2079
+ "page_idx": 17
2080
+ },
2081
+ {
2082
+ "type": "text",
2083
+ "text": "Example 5 ",
2084
+ "text_level": 1,
2085
+ "bbox": [
2086
+ 173,
2087
+ 103,
2088
+ 251,
2089
+ 118
2090
+ ],
2091
+ "page_idx": 18
2092
+ },
2093
+ {
2094
+ "type": "text",
2095
+ "text": "• Input token index: 34817 \n• Input token: “.”’ \n• Target token: “b” \n• Surrounding context: shows \"integrable (lebesgue_on {a..b}) \n• Retrieved token 1: “.” \n• Retrieved token index 1: 2416 \n• Retrieved context 1: lebesgue_on {a..b}) f i \n• Retrieved token 2: “-” \n• Retrieved token index 2: 2445 \n• Retrieved context 2: (lebesgue_on {a-c..b-c}) ( \n• Retrieved token 3: “-” \n• Retreived token index 3: 6479 \n• Retrieved context 3: (lebesgue_on {-pi..pi}) ( ",
2096
+ "bbox": [
2097
+ 215,
2098
+ 130,
2099
+ 635,
2100
+ 372
2101
+ ],
2102
+ "page_idx": 18
2103
+ },
2104
+ {
2105
+ "type": "text",
2106
+ "text": "Example 6 ",
2107
+ "text_level": 1,
2108
+ "bbox": [
2109
+ 173,
2110
+ 386,
2111
+ 251,
2112
+ 401
2113
+ ],
2114
+ "page_idx": 18
2115
+ },
2116
+ {
2117
+ "type": "text",
2118
+ "text": "• Input token index: 49759 \n• Input token: “_”’ \n• Target token: “sum” \n• Surrounding context: $0 \" \\backslash \\mathtt { n }$ using Fourier_series_square_summable [OF assms \n• Retrieved token 1: “set” \n• Retrieved token index 1: 35044 \n• Retrieved context 1: definition trigonometric_set :: \"nat \\<Rightarrow> \n• Retrieved token 2: “ier” \n• Retrieved token index 2: 47272 \n• Retrieved context 2: definition Fourier_coefficient\\nwhere \n• Retrieved token 3: “ine” \n• Retrieved token index 3: 18160 \n• Retrieved context 3: lemma Schwartz_inequality_strong:\\nassumes “f’ \n• Retrieved token 4: “system” \n• Retrieved token index 4: 28052 \n• Retrieved context 4: definition orthonormal_system :: “\\’a::euclidean’ \n• Retrieved token 5: “<” \n• Retrieved token index 5: 47241 \n• Retrieved context 5: subsection\\<open>Convergence wrt the L’ \n• Retrieved token 6: “n” \n• Retrieved token index 6: 40835 \n• Retrieved context 6: \\n subsection\\<open>A bit of extra’ ",
2119
+ "bbox": [
2120
+ 215,
2121
+ 414,
2122
+ 746,
2123
+ 827
2124
+ ],
2125
+ "page_idx": 18
2126
+ }
2127
+ ]
parse/dev/TrjbxzRcnf-/TrjbxzRcnf-_model.json ADDED
The diff for this file is too large to render. See raw diff
 
parse/dev/Yacmpz84TH/Yacmpz84TH.md ADDED
@@ -0,0 +1,281 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Toolformer: Language Models Can Teach Themselves to Use Tools
2
+
3
+ Timo Schick Jane Dwivedi-Yu Roberto Dessì† Roberta Raileanu Maria Lomeli Eric Hambro Luke Zettlemoyer Nicola Cancedda Thomas Scialom
4
+
5
+ FAIR, Meta †Universitat Pompeu Fabra
6
+
7
+ # Abstract
8
+
9
+ Language models (LMs) exhibit remarkable abilities to solve new tasks from just a few examples or textual instructions, especially at scale. They also, paradoxically, struggle with basic functionality, such as arithmetic or factual lookup, where much simpler and smaller specialized models excel. In this paper, we show that LMs can teach themselves to use external tools via simple APIs and achieve the best of both worlds. We introduce Toolformer, a model trained to decide which APIs to call, when to call them, what arguments to pass, and how to best incorporate the results into future token prediction. This is done in a self-supervised way, requiring nothing more than a handful of demonstrations for each API. We incorporate a range of tools, including a calculator, a Q&A system, a search engine, a translation system, and a calendar. Toolformer achieves substantially improved zero-shot performance across a variety of downstream tasks, often competitive with much larger models, without sacrificing its core language modeling abilities.
10
+
11
+ # 1 Introduction
12
+
13
+ Large language models achieve impressive zero and few-shot results on a variety of natural language processing tasks (Brown et al., 2020; Chowdhery et al., 2022, i.a.). However, these models have several inherent limitations that can at best be partially addressed by further scaling. These limitations include an inability to access up-to-date information on recent events (Komeili et al., 2022) and the related tendency to hallucinate facts (Maynez et al., 2020; Ji et al., 2022), difficulties in understanding low-resource languages (Lin et al., 2021), a lack of mathematical skills to perform precise calculations (Patel et al., 2021) and an unawareness of the progression of time (Dhingra et al., 2022).
14
+
15
+ A simple way to overcome the limitations of today’s language models is to give them the ability to use external tools such as search engines, calculators, or calendars. However, existing approaches either rely on large amounts of human annotations (Komeili et al., 2022; Thoppilan et al., 2022) or limit tool use to task-specific settings only (e.g., Gao et al., 2022; Parisi et al., 2022), hindering a more widespread adoption of tool use in LMs. Therefore, we propose Toolformer, a model that learns to use tools in a novel way, which fulfills the following desiderata:
16
+
17
+ • Tool use should be learned in a self-supervised way without large amounts of human annotations. This is important not only because of the costs associated with such annotations, but also because what humans find useful may be different from what a model finds useful. • The LM should not lose any of its generality and should be able to decide for itself when and how to use which tool. In contrast to existing approaches, this enables a much more comprehensive use of tools that is not tied to specific tasks.
18
+
19
+ Our approach for achieving these goals is based on the recent idea of using large LMs with in-context learning (Brown et al., 2020) to generate entire datasets from scratch (Schick and Schütze, 2021b;
20
+
21
+ ![](images/efd2dac35f6d1a63826328723565885e1aad2ceea0a3379b92e4c40bd9922f6b.jpg)
22
+ Figure 1: Exemplary predictions of Toolformer. The model autonomously decides to call different APIs (from top to bottom: a question answering system, a calculator, a machine translation system, and a Wikipedia search engine) to obtain information that is useful for completing a piece of text.
23
+
24
+ ![](images/5869d239001ffcca88eb10a98a653d9f154d0247150188f33783d20eda69ab5b.jpg)
25
+ Figure 2: Key steps in ourwe first sample a position pproach, illustrated for a question answe and corresponding API call candidates en an input text . We then execu $\mathbf { x }$ , $i$ $c _ { i } ^ { 1 } , c _ { i } ^ { 2 } , \ldots , c _ { i } ^ { k }$ these API calls and filter out all calls which do not reduce the loss $L _ { i }$ over the next tokens. All remaining API calls are interleaved with the original text, resulting in a new text $\mathbf { x } ^ { * }$ .
26
+
27
+ Honovich et al., 2022; Wang et al., 2022): Given just a handful of human-written examples of how an API can be used, we let a LM annotate a huge language modeling dataset with potential API calls. We then use a self-supervised loss to determine which of these API calls actually help the model in predicting future tokens. Finally, we finetune the LM itself on the API calls that it considers useful. As illustrated in Figure 1, through this simple approach, LMs can learn to control a variety of tools, and to choose for themselves which tool to use when and how.
28
+
29
+ As our approach is agnostic of the dataset being used, we can apply it to the exact same dataset that was used to pretrain a model in the first place. This ensures that the model does not lose any of its generality and language modeling abilities. We conduct experiments on a variety of different downstream tasks, demonstrating that after learning to use tools, Toolformer, which is based on a pretrained GPT-J model (Wang and Komatsuzaki, 2021) with 6.7B parameters, achieves much stronger zero-shot results, clearly outperforming a much larger GPT-3 model (Brown et al., 2020) and several other baselines on various tasks.
30
+
31
+ # 2 Approach
32
+
33
+ Our aim is to equip a language model $M$ with the ability to use different tools through API calls. We represent API calls as tuples $c = ( a _ { c } , i _ { c } )$ where $a _ { c }$ is the name of the API and $i _ { c }$ is the corresponding input. Given an API call $c$ with a corresponding result $r$ , we denote the linearized sequences of the API call not including and including its result, respectively, as:
34
+
35
+ $$
36
+ \begin{array} { r } { \mathsf { e } ( c ) = < \mathtt { A P I } > a _ { c } ( i _ { c } ) < / \mathtt { A P I } > \mathsf { e } ( c , r ) = < \mathtt { A P I } > a _ { c } ( i _ { c } ) \to r < / \mathtt { A P I } > } \end{array}
37
+ $$
38
+
39
+ where $ { \mathrm { ~ ~ \cdots ~ } } < \tt { A P I } > { \mathrm { ^ { \circ } } }$ , $ { \mathrm { ~ ~ \cdots ~ } } < / \tt A P I > { \mathrm { ^ { \circ } } }$ and $\ " \ "$ are special tokens.1 Some examples of linearized API calls inserted into text sequences are shown in Figure 1.
40
+
41
+ Your task is to add calls to a Question Answering API to a piece of text. The questions should help you get information required to complete the text. You can call the API by writing "[QA(question)]" where "question" is the question you want to ask. Here are some examples of API calls:
42
+
43
+ Input: Joe Biden was born in Scranton, Pennsylvania.
44
+ Output: Joe Biden was born in [QA("Where was Joe Biden born?")] Scranton, [QA("In which state is Scranton?")] Pennsylvania.
45
+
46
+ Input: Coca-Cola, or Coke, is a carbonated soft drink manufactured by the Coca-Cola Company. Output: Coca-Cola, or [QA("What other name is Coca-Cola known by?")] ${ \mathsf { C o k e } } ,$ , is a carbonated soft drink manufactured by [QA("Who manufactures Coca-Cola?")] the Coca-Cola Company.
47
+
48
+ Input: x Output:
49
+
50
+ Given a dataset $\mathcal { C } = \{ \mathbf { x } ^ { 1 } , \ldots , \mathbf { x } ^ { | \mathcal { C } | } \}$ of plain texts, we first convert this dataset into a dataset $\mathcal { C } ^ { * }$ augmented with API calls. This is done in three steps, illustrated in Figure 2: First, we exploit the in-context learning ability of $M$ to sample a large number of API calls. We then execute them and finally check whether the obtained responses are helpful for predicting future tokens; this is used as a filtering criterion. After filtering, we merge API calls for different tools, resulting in the augmented dataset $\mathcal { C } ^ { * }$ , and finetune $M$ itself on this dataset. Each step is described in more detail below.
51
+
52
+ Sampling API Calls For each API, we write a prompt $P ( \mathbf { x } )$ that encourages the LM to annotate an example $\mathbf { x } = x _ { 1 } , \ldots , x _ { n }$ with API calls. An example of such a prompt for a question answering tool is shown in Figure 3. Let $p _ { M } ( z _ { n + 1 } \mid z _ { 1 } , . . . , z _ { n } )$ be the probability that $M$ assigns to token $z _ { n + 1 }$ as a continuation for the sequence $z _ { 1 } , \ldots , z _ { n }$ . We first sample up to $k$ candidate positions for doing API calls by computing, for each $i \in \{ 1 , \ldots , n \}$ , the probability $p _ { i } = p _ { M } ( < _ { \tt A P I > } \mid P ( \mathbf { x } ) , x _ { 1 : i - 1 } )$ that $M$ assigns to starting an API call at position $i$ . Given a sampling threshold $\tau _ { s }$ , we keep all positions $I \stackrel { - } { = } \{ i | p _ { i } > \tau _ { s } \stackrel { - } { \} }$ ; if there are more than $k$ such positions, we only keep the top $k$ . For each position $i \in I$ , we then obtain up to $m$ API calls $c _ { i } ^ { 1 } , \ldots , c _ { i } ^ { m }$ by sampling from $M$ given the sequence $[ P ( \mathbf { x } ) , x _ { 1 } , \ldots , x _ { i - 1 } , < \mathtt { A P I } > ]$ as a prefix and ${ < } / { \tt A P I > }$ as an end-of-sequence token.
53
+
54
+ Executing API Calls As a next step, we execute all API calls generated by $M$ . How this is done depends entirely on the API itself – for example, it can involve calling another neural network, executing a Python script or using a retrieval system to perform search over a large corpus. The response for each API call $c _ { i }$ needs to be a single text sequence $r _ { i }$ .
55
+
56
+ Filtering API Calls Let $i$ be the position of the API call $c _ { i }$ in the sequence $\mathbf { x } = x _ { 1 } , \ldots , x _ { n }$ , and let $r _ { i }$ be the response from the API. Further, given a sequence $( w _ { i } \mid i \in \mathbb { N } )$ of weights, let
57
+
58
+ $$
59
+ L _ { i } ( \mathbf { z } ) = - \sum _ { j = i } ^ { n } w _ { j - i } \cdot \log p _ { M } ( x _ { j } \mid \mathbf { z } , x _ { 1 : j - 1 } )
60
+ $$
61
+
62
+ be the weighted cross entropy loss for $M$ over the tokens $x _ { i } , \ldots , x _ { n }$ if the model is prefixed with some text sequence $\mathbf { z }$ . We compare two different instantiations of this loss:
63
+
64
+ $$
65
+ L _ { i } ^ { + } = L _ { i } ( \mathbf { e } ( c _ { i } , r _ { i } ) ) \qquad L _ { i } ^ { - } = \operatorname* { m i n } \left( L _ { i } ( \varepsilon ) , L _ { i } ( \mathbf { e } ( c _ { i } , \varepsilon ) ) \right)
66
+ $$
67
+
68
+ where $\varepsilon$ denotes an empty sequence. The former is the weighted loss over all tokens $x _ { i } , \ldots , x _ { n }$ if the API call and its result are given to $M$ as a prefix;2 the latter is the minimum of the losses obtained from (i) doing no API call at all and (ii) doing an API call, but not providing the response. Intuitively, an API call is helpful to $M$ if providing it with both the input and the output of this call makes it easier for the model to predict future tokens, compared to not receiving the API call at all, or receiving only its input. Given a filtering threshold $\tau _ { f }$ , we thus only keep API calls for which $L _ { i } ^ { - } - L _ { i } ^ { + } \ge \tau _ { f }$ holds, i.e., adding the API call and its result reduces the loss by at least $\tau _ { f }$ , compared to not doing any API call or obtaining no result from it.
69
+
70
+ Table 1: Examples of inputs and outputs for all APIs used.
71
+
72
+ <table><tr><td>API Name</td><td>Example Input</td><td>Example Output</td></tr><tr><td>Question Answering</td><td>Where was the Knights of Columbus founded?</td><td>New Haven, Connecticut</td></tr><tr><td>Wikipedia Search</td><td>Fishing Reel Types</td><td>Spin fishing &gt; Spin fishing is distinguished between fly fishing and bait cast fishing by the type of rod and reel used. There are two types of reels used when spin fishing,</td></tr><tr><td>Calculator</td><td>27+4*2</td><td>the open faced reel and the closed faced reel. 35</td></tr><tr><td>Calendar</td><td>m</td><td>Today is Monday, January 30,2023.</td></tr><tr><td>Machine Translation</td><td>sureté nucléaire</td><td>nuclear safety</td></tr></table>
73
+
74
+ Model Finetuning After sampling and filtering calls for all APIs, we finally merge the remaining API calls and interleave them with the original inputs. That is, for an input text $\mathbf { x } = x _ { 1 } , \ldots , x _ { n }$ with a corresponding API call and result $( c _ { i } , r _ { i } )$ at position $i$ , we construct the new sequence $\mathbf { x } ^ { * } = x _ { 1 : i - 1 } , \mathbf { e } ( c _ { i } , r _ { i } ) , x _ { i : n }$ ; we proceed analogously for texts with multiple API calls. Doing this for all $\mathbf { x } \in { \mathcal { C } }$ results in the new dataset $\mathcal { C } ^ { * }$ augmented with API calls. We use $\mathcal { C } ^ { * }$ to finetune $M$ , using a standard language modeling objective. Crucially, apart from inserted API calls, $\mathcal { C } ^ { * }$ contains the exact same texts as $\mathcal { C }$ , the original dataset. As a consequence, finetuning $M$ on $\mathcal { C } ^ { * }$ exposes it to the same content as finetuning on $\mathcal { C }$ . Moreover, as API calls are inserted in exactly those positions and with exactly those inputs that help $M$ predict future tokens, finetuning on $\mathcal { C } ^ { * }$ enables the language model to decide when and how to use which tool, based purely on its own feedback.
75
+
76
+ Inference When generating text with $M$ after finetuning with our approach, we perform regular decoding until $M$ produces the $\ " \ "$ token, indicating that it next expects the response for an API call. At this point, we interrupt the decoding process, call the appropriate API to get a response, and continue the decoding process after inserting both the response and the ${ < } / \tt { A P I > }$ token.
77
+
78
+ # 3 Tools
79
+
80
+ We explore various tools to address different shortcomings of LMs. The only constraints we impose are that (i) their inputs and outputs can be represented as texts, and (ii) we can obtain a few demonstrations of their intended use. Concretely, we explore a question answering system, a Wikipedia search engine, a calculator, a calendar, and a machine translation system. Examples for the APIs associated with each of these tools are shown in Table 1. We briefly discuss all tools below.
81
+
82
+ Question Answering Our first tool is a question answering system based on another LM that can answer simple factoid questions. Specifically, we use Atlas (Izacard et al., 2022), a retrievalaugmented LM finetuned on Natural Questions (Kwiatkowski et al., 2019).
83
+
84
+ Calculator As a second tool, we use a calculator that can perform simple numeric calculations; we only support the four basic arithmetic operations. Results are always rounded to two decimal places.
85
+
86
+ Wikipedia Search Our third tool is a search engine that, given a search term, returns short text snippets from Wikipedia. Compared to our question answering tool, this search enables a model to get more comprehensive information on a subject, but requires it to extract the relevant parts by itself. As our search engine, we use a BM25 retriever (Robertson et al., 1995; Baeza-Yates et al., 1999) that indexes the Wikipedia dump from KILT (Petroni et al., 2021).
87
+
88
+ Machine Translation System Our fourth tool is a machine translation system based on a LM that can translate a phrase from any language into English. More concretely, we use the 600M parameter NLLB (Costa-jussà et al., 2022) as our multilingual machine translation model that works for 200 languages (including low-resource ones). The source language is automatically detected using the fastText classifier (Joulin et al., 2016), while the target language is always set to English.
89
+
90
+ Calendar Our final tool is a calendar API that, when queried, returns the current date without taking any input. This provides temporal context for predictions that require some awareness of time.
91
+
92
+ Table 2: Number of examples with API calls in $\mathcal { C } ^ { * }$ for different values of our filtering threshold $\tau _ { f }$
93
+
94
+ <table><tr><td></td><td colspan="3">Number of Examples</td></tr><tr><td>API</td><td>Tf = 0.5</td><td>Tf = 1.0</td><td>Tf = 2.0</td></tr><tr><td>Question Answering</td><td>51,987</td><td>18,526</td><td>5,135</td></tr><tr><td>Wikipedia Search</td><td>207,241</td><td>60,974</td><td>13,944</td></tr><tr><td>Calculator</td><td>3,680</td><td>994</td><td>138</td></tr><tr><td>Calendar</td><td>61,811</td><td>20,587</td><td>3,007</td></tr><tr><td>Machine Translation</td><td>3,156</td><td>1,034</td><td>229</td></tr></table>
95
+
96
+ # 4 Experiments
97
+
98
+ We investigate whether our approach enables a LM to use tools without any further supervision and to decide for itself when and how to call which tool. To test this, we select a variety of downstream tasks where we assume at least one of the considered tools to be useful, and evaluate performance in zero-shot settings (Section 4.2). Beyond that, we also ensure that our approach does not hurt the model’s core LM abilities; we verify this by looking at perplexity on two language modeling datasets (Section 4.3). Finally, we investigate how tool use is affected by model size (Section 4.4).
99
+
100
+ # 4.1 Experimental Setup
101
+
102
+ We use a subset of CCNet (Wenzek et al., 2020) as our dataset $\mathcal { C }$ and GPT-J (Wang and Komatsuzaki, 2021) as our language model $M$ . To reduce the computational cost of annotating $\mathcal { C }$ with API calls, we define heuristics for some APIs to get a subset of $\mathcal { C }$ for which API calls are more likely to be helpful than for an average text. For example, we only consider texts for the calculator tool if they contain at least three numbers. Details of the heuristics used are given in Appendix A. For obtaining $\mathcal { C } ^ { * }$ from $\mathcal { C }$ , we perform all steps described in Section 2 and additionally filter out all examples for which all API calls were eliminated in the filtering step.3 For the weighting function, we use
103
+
104
+ $$
105
+ w _ { t } = \frac { \tilde { w } _ { t } } { \sum _ { s \in \mathbb { N } } \tilde { w } _ { s } } \mathrm { ~ w i t h ~ } \tilde { w } _ { t } = \operatorname* { m a x } ( 0 , 1 - 0 . 2 \cdot t )
106
+ $$
107
+
108
+ to make sure that API calls happen close to where the information provided by the API is actually helpful for the model. The thresholds $\tau _ { s }$ and $\tau _ { f }$ are chosen individually for each tool to ensure a sufficient number of examples; see Appendix A for details. Table 2 shows relevant statistics of our final dataset augmented with API calls. We finetune $M$ on $\mathcal { C } ^ { * }$ using a batch size of 128 and a learning rate of $1 \cdot 1 0 ^ { - 5 }$ with linear warmup for the first $10 \%$ of training. Finetuning details are given in Appendix B. In our experiments, we mainly compare GPT-J and the following models:
109
+
110
+ • GPT- $\mathbf { J } + \mathbf { C } \mathbf { C }$ : GPT-J finetuned on $\mathcal { C }$ , our subset of CCNet without any API calls. • Toolformer: GPT-J finetuned on $\mathcal { C } ^ { * }$ , our subset of CCNet augmented with API calls. • Toolformer (disabled): The same model as Toolformer, but API calls are disabled during decoding. This is achieved by manually setting the probability of the ${ \tt { < A P I > } }$ token to 0.
111
+
112
+ We additionally compare to OPT (66B) (Zhang et al., 2022) and the original davinci variant of GPT-3 (175B) (Brown et al., 2020), two models that are about 10 and 25 times larger than GPT-J.
113
+
114
+ # 4.2 Downstream Tasks
115
+
116
+ We evaluate on various downstream tasks considering a prompted zero-shot setup: Models are instructed to solve each task in natural language (see Appendix C), but we provide no examples. This is in contrast to prior work on tool use (e.g., Gao et al., 2022; Parisi et al., 2022), where models are provided with dataset-specific examples of how a tool can be used to solve a concrete task. We choose this more challenging setup as we are interested in seeing whether Toolformer works in precisely those cases where a user does not specify in advance which tools should be used in which way.
117
+
118
+ Table 3: Results on subsets of LAMA and various benchmarks requiring mathematical reasoning. For LAMA, Toolformer uses the question answering tool for most examples, clearly outperforming all baselines of the same size and achieving results competitive with GPT-3. For the math benchmarks, Toolformer makes extensive use of the calculator tool, clearly outperforming OPT and GPT-3. Best results with a GPT-J based model are shown in bold, best results overall are underlined.
119
+
120
+ <table><tr><td></td><td colspan="3">LAMA</td><td colspan="3">Math Benchmarks</td></tr><tr><td>Model</td><td>SQuAD</td><td>Google-RE</td><td>T-REx</td><td>ASDiv</td><td>SVAMP</td><td>MAWPS</td></tr><tr><td>GPT-J</td><td>17.8</td><td>4.9</td><td>31.9</td><td>7.5</td><td>5.2</td><td>9.9</td></tr><tr><td>GPT-J + CC</td><td>19.2</td><td>5.6</td><td>33.2</td><td>9.6</td><td>5.0</td><td>9.3</td></tr><tr><td>Toolformer (disabled)</td><td>22.1</td><td>6.3</td><td>34.9</td><td>14.8</td><td>6.3</td><td>15.0</td></tr><tr><td>Toolformer</td><td>33.8</td><td>11.5</td><td>53.5</td><td>40.4</td><td>29.4</td><td>44.0</td></tr><tr><td>OPT (66B)</td><td>21.6</td><td>2.9</td><td>30.1</td><td>6.0</td><td>4.9</td><td>7.9</td></tr><tr><td>GPT-3 (175B)</td><td>26.8</td><td>7.0</td><td>39.8</td><td>14.0</td><td>10.0</td><td>19.8</td></tr></table>
121
+
122
+ We use greedy decoding, but with one modification for Toolformer: We let the model start an API call whenever ${ \tt { < A P I > } }$ is one of the $k$ most likely tokens. For $k = 1$ , this corresponds to regular greedy decoding; we instead use $k = 1 0$ to increase the disposition of our model to make use of APIs. At the same time, we allow at most one API call per input to make sure the model does not get stuck in a loop where it constantly calls APIs. The effect of these modifications is explored in Appendix E.
123
+
124
+ LAMA We evaluate our models on the SQuAD, Google-RE and T-REx subsets of the LAMA benchmark (Petroni et al., 2019). For each of these subsets, the task is to complete a short statement with a missing fact (e.g., a date or a place). As LAMA was originally designed to evaluate masked LMs (e.g., Devlin et al., 2019), we filter out examples where the mask token is not the final token, so that all examples can be processed in a left-to-right fashion. To account for different tokenizations and added complexity from not informing the model that a single word is required, for all models we use a slightly more lenient evaluation criterion than exact match and simply check whether the correct word is within the first five words predicted by the model. As LAMA is based on statements obtained directly from Wikipedia, we prevent Toolformer from using the Wikipedia Search API to avoid giving it an unfair advantage. As shown in Table 3 (left), all GPT-J models without tool use achieve similar performance. Crucially, Toolformer clearly outperforms these baseline models, improving upon the best baseline by 11.7, 5.2 and 18.6 points, respectively. It also clearly outperforms OPT (66B) and GPT-3 (175B), despite both models being much larger. This is achieved because the model independently decides to ask the question answering tool for the required information in almost all cases $( 9 8 . 1 \% )$ ; for only very few examples, it uses a different tool $( 0 . 7 \% )$ or no tool at all $( 1 . 2 \% )$ .
125
+
126
+ Math Benchmarks We test mathematical abilities on ASDiv (Miao et al., 2020), SVAMP (Patel et al., 2021) and the MAWPS benchmark (Koncel-Kedziorski et al., 2016). We again account for the fact that we test all models in a zero-shot setup by using a more lenient evaluation criterion: As the required output is always a number, we simply check for the first number predicted by the model.4 Results are shown in Table 3 (right). While GPT-J and GPT- $\mathbf { J } + \mathbf { C } \mathbf { C }$ perform about the same, Toolformer achieves stronger results even without API calls. We surmise that this is because the model is finetuned on many examples of API calls and their results, improving its own mathematical capabilities. Nonetheless, allowing the model to make API calls more than doubles performance for all tasks, and also clearly outperforms the much larger OPT and GPT-3. This is because across all benchmarks, for $9 7 . 9 \%$ of all examples the model decides to ask the calculator tool for help.
127
+
128
+ Question Answering We look at Web Questions (Berant et al., 2013), Natural Questions (Kwiatkowski et al., 2019) and TriviaQA (Joshi et al., 2017). For evaluation, we check whether the first 20 words predicted by a model contain the correct answer instead of requiring an exact match. For Toolformer, we disable the question answering tool as this would make solving the tasks trivial. Results are shown in Table 4 (left). Once again, Toolformer clearly outperforms all other models based on GPT-J, relying on the Wikipedia search API $( 9 9 . 3 \% )$ to find relevant information. However,
129
+
130
+ Table 4: Results for various question answering datasets and temporal datasets. Using the Wikipedia search tool for most examples, Toolformer clearly outperforms baselines of the same size, but falls short of GPT-3 (175B) for question answering tasks. For temporal datasets, Toolformer outperforms all baselines, but does not make use of the calendar tool for TEMPLAMA.
131
+
132
+ <table><tr><td></td><td colspan="3">LAMA</td><td colspan="2">Temporal Datasets</td></tr><tr><td>Model</td><td>WebQS</td><td>NQ</td><td>TriviaQA</td><td>TEMPLAMA</td><td>DATESET</td></tr><tr><td>GPT-J</td><td>18.5</td><td>12.8</td><td>43.9</td><td>13.7</td><td>3.9</td></tr><tr><td>GPT-J + CC</td><td>18.4</td><td>12.2</td><td>45.6</td><td>12.9</td><td>2.9</td></tr><tr><td>Toolformer (disabled)</td><td>18.9</td><td>12.6</td><td>46.7</td><td>12.7</td><td>5.9</td></tr><tr><td>Toolformer</td><td>26.3</td><td>17.7</td><td>48.8</td><td>16.3</td><td>27.3</td></tr><tr><td>OPT (66B)</td><td>18.6</td><td>11.4</td><td>45.7</td><td>14.5</td><td>1.3</td></tr><tr><td>GPT-3 (175B)</td><td>29.0</td><td>22.6</td><td>65.9</td><td>15.5</td><td>0.8</td></tr></table>
133
+
134
+ Table 5: Results on MLQA for Spanish (Es), German (De), Hindi $\mathrm { ( H i ) }$ , Vietnamese (Vi), Chinese (Zh) and Arabic (Ar). While using the MT tool to translate questions is helpful across all languages, further pretraining on CCNet deteriorates performance; thus, Toolformer does not consistently outperform GPT-J. The final rows correspond to models that are given contexts and questions in English.
135
+
136
+ <table><tr><td>Model</td><td>Es</td><td>De</td><td>Hi</td><td>Vi</td><td>Zh</td><td>Ar</td></tr><tr><td>GPT-J</td><td>15.2</td><td>16.5</td><td>1.3</td><td>8.2</td><td>18.2</td><td>8.2</td></tr><tr><td>GPT-J + CC</td><td>15.7</td><td>14.9</td><td>0.5</td><td>8.3</td><td>13.7</td><td>4.6</td></tr><tr><td>Toolformer (disabled)</td><td>19.8</td><td>11.9</td><td>1.2</td><td>10.1</td><td>15.0</td><td>3.1</td></tr><tr><td>Toolformer</td><td>20.6</td><td>13.5</td><td>1.4</td><td>10.6</td><td>16.8</td><td>3.7</td></tr><tr><td>OPT (66B)</td><td>0.3</td><td>0.1</td><td>1.1</td><td>0.2</td><td>0.7</td><td>0.1</td></tr><tr><td>GPT-3 (175B)</td><td>3.4</td><td>1.1</td><td>0.1</td><td>1.7</td><td>17.7</td><td>0.1</td></tr><tr><td>GPT-J (All En)</td><td>24.3</td><td>27.0</td><td>23.9</td><td>23.3</td><td>23.1</td><td>23.6</td></tr><tr><td>GPT-3 (All En)</td><td>24.7</td><td>27.2</td><td>26.1</td><td>24.9</td><td>23.6</td><td>24.0</td></tr></table>
137
+
138
+ Toolformer still lags behind the much larger GPT-3 (175B) model. This is likely due to both the simplicity of our search engine (in many cases, it returns results that are clearly not a good match for a given query) and the inability of Toolformer to interact with it, e.g., by reformulating its query if results are not helpful or by browsing through multiple of the top results.
139
+
140
+ Multilingual QA We evaluate all models on MLQA (Lewis et al., 2019), a multilingual QA benchmark. Context for each question is provided in English, while the question can be in Arabic, German, Spanish, Hindi, Vietnamese, or Simplified Chinese. Our evaluation metric is the percentage of times the model’s generation, capped at 10 words, contains the correct answer. Results are shown in Table 5. API calls improve Toolformer’s performance for all languages, suggesting that it has learned to make use of the machine translation tool. Depending on the language, this tool is used for $6 3 . 8 \%$ to $9 4 . 9 \%$ of all examples; the only exception is Hindi, for which it is used in only $7 . 3 \%$ of cases. However, Toolformer does not consistently outperform GPT-J as finetuning on CCNet deteriorates performance for some languages. OPT and GPT-3 perform surprisingly weak across all languages, mostly because they fail to provide an answer in English despite being instructed to do so. A potential reason for GPT-J not suffering from this problem is that it was trained on more multilingual data than both OPT and GPT-3, including EuroParl (Koehn, 2005). As an upper bound, we also evaluate GPT-J and GPT-3 on a variant of MLQA where both the context and the question are provided in English. In this setup, GPT-3 performs better than all other models, supporting our hypothesis that its subpar performance on MLQA is due to the task’s multilingual aspect.
141
+
142
+ Temporal Datasets We evaluate all models on TEMPLAMA (Dhingra et al., 2022) and a new dataset that we call DATESET. TEMPLAMA contains cloze queries about facts that change with time. DATESET, described in Appendix D, is generated through a series of templates, but populated using a combination of random dates/durations (e.g., “What day of the week was it 30 days ago?”). For both tasks, we use the same evaluation as for the original LAMA dataset. Results shown in Table 4 (right) illustrate that Toolformer outperforms all baselines for both TEMPLAMA and DATESET. However, closer inspection shows that improvements on TEMPLAMA can not be attributed to the calendar tool, which is only used for $0 . 2 \%$ of all examples, but mostly to the Wikipedia search and question answering tools.This makes sense given that entities in TEMPLAMA are often so specific and rare that even knowing the date alone would be of little help. The best course of action for this dataset – first querying the calendar API to get the current date, and then querying the QA system with this date – is not only prohibited by our restriction of using at most one API call, but also hard to learn for Toolformer given that all API calls in its training data are sampled independently. For DATESET, on the other hand, the considerable improvement of Toolformer compared to other models can be fully accredited to the calendar tool, which it makes use of for $5 4 . 8 \%$ of all examples.
143
+
144
+ ![](images/071c4fdbad1e77e8404f0631b4a51c5e303496f5cf70832da7e556306980604d.jpg)
145
+ Figure 4: Average performance on LAMA, our math benchmarks and our QA benchmarks for GPT-2 models of different sizes and GPT-J finetuned with our approach, both with and without API calls. While API calls are not helpful to the smallest models, larger models learn how to make good use of them. Even for bigger models, the gap between predictions with and without API calls remains high.
146
+
147
+ # 4.3 Language Modeling
148
+
149
+ We want to ensure that language modeling performance of Toolformer does not degrade through finetuning with API calls. To this end, we evaluate our models on two language modeling datasets: WikiText (Merity et al., 2017) and a subset of 10,000 randomly selected documents from CCNet (Wenzek et al., 2020) that were not used during training. Finetuning on CCNet leads to slightly improved performance on the CCNet evaluation subset (perplexity improves from 10.6 to 10.5), but slightly deteriorates performance on WikiText (9.9 to 10.3), presumably because the original pretraining data for GPT-J is more similar to WikiText than our subset of CCNet. Most importantly, however, training on $\mathcal { C } ^ { * }$ does not lead to an increase in perplexity compared to training on $\mathcal { C }$ when API calls are disabled at inference time, giving perplexities of 10.5 and 10.3, respectively.5
150
+
151
+ # 4.4 Scaling Laws
152
+
153
+ We investigate how the ability to ask external tools for help affects performance as we vary the size of our LM. To this end, we apply our approach not just to GPT-J, but also to four smaller models from the GPT-2 family (Radford et al., 2019), with 124M, 355M, 775M and 1.6B parameters, respectively. We do so using only a subset of three tools: the question answering system, the calculator, and the Wikipedia search engine. Apart from this, we follow the experimental setup described in Section 4.1. Figure 4 shows that the ability to leverage the provided tools only emerges at around 775M parameters: smaller models achieve similar performance both with and without tools. An exception to this is the Wikipedia search engine used mostly for QA benchmarks; we hypothesize that this is because the API is comparably easy to use. While models become better at solving tasks without API calls as they grow in size, their ability to make good use of the provided API improves at the same time. Thus, there remains a large gap between predictions with and without API calls even for our biggest model.
154
+
155
+ In Appendix G, we extend these investigations in scale to the LLaMA v1 7B model (Touvron et al., 2023) to see how tool-use scales with model capability instead of size. We find that the utility of weaker tools such as the WikiSearch tool vanish for these stronger base-models, and we demonstrate the value of generating and scoring with a strong model, compared to simply finetuning.
156
+
157
+ # 5 Related Work
158
+
159
+ Language Model Pretraining There are various approaches that augment LMs with some form of additional textual information during pretraining, including various forms of metadata (Keskar et al., 2019), HTML tags (Aghajanyan et al., 2021), Wikipedia markup (Schick et al., 2022), or related texts obtained from an information retrieval system (Guu et al., 2020; Borgeaud et al., 2021; Izacard et al., 2022). For all of these approaches, additional information is always provided, regardless of whether it is helpful or not. In contrast, Toolformer learns for itself to explicitly asks for the right information.
160
+
161
+ Tool Use Several approaches aim to equip LMs with the ability to use external tools such as search engines (Komeili et al., 2022; Thoppilan et al., 2022; Lazaridou et al., 2022; Shuster et al., 2022; Yao et al., 2022), web browsers (Nakano et al., 2021), calculators (Cobbe et al., 2021; Thoppilan et al., 2022), translation systems (Thoppilan et al., 2022) and Python interpreters (Gao et al., 2022). The way these models learn to use tools can roughly be divided into two approaches: Either they rely on large amounts of human supervision (Komeili et al., 2022; Nakano et al., 2021; Thoppilan et al., 2022) or they work by prompting the language model in a few-shot setup tailored towards a specific task where it is known a priori which tools needs to be used (Gao et al., 2022; Lazaridou et al., 2022; Yao et al., 2022). In contrast, the self-supervised nature of Toolformer enables it to learn how and when to use tools without requiring a specific prompt that shows task-specific examples of how a tool could be used. Perhaps most closely related to our work is TALM (Parisi et al., 2022), an approach that uses a similar self-supervised objective for teaching a model to use a calculator and a search engine, but explores this only in settings where a model is finetuned for downstream tasks.
162
+
163
+ Bootstrapping The idea of using self-training and bootstrapping techniques to improve models has been investigated in various contexts, ranging from word sense disambiguation (Yarowsky, 1995), relation extraction (Brin, 1999; Agichtein and Gravano, 2000), parsing (McClosky et al., 2006), sequence generation (He et al., 2020), few-shot text classification (Schick and Schütze, 2021a) and retrieval (Izacard and Grave, 2021) to reasoning (Zelikman et al., 2022). In a similar spirit, Toolformer is trained on its own predictions after applying a perplexity-based filtering step.
164
+
165
+ # 6 Limitations
166
+
167
+ While our approach enables LMs to learn how to use a variety of tools in a self-supervised way, there are some clear limitations to what can be achieved with our method in its current form. One such limitation is the inability of Toolformer to use tools in a chain (i.e., using the output of one tool as an input for another tool). This is due to the fact that API calls for each tool are generated independently; as a consequence, there are no examples of chained tool use in the finetuning dataset, since this would necessitate multiple API calls per example. Our current approach also does not allow the LM to use a tool in an interactive way – especially for tools such as search engines, that could potentially return hundreds of different results, enabling a LM to browse through these results or to refine its search query in a similar spirit to Nakano et al. (2021) can be crucial for certain applications. Beyond this, we found models trained with Toolformer to often be sensitive to the exact wording of their input when deciding whether or not to call an API; this is perhaps unsurprising given that LMs are known to be very sensitive to the prompt they are provided with in both zero- and few-shot settings (Jiang et al., 2020; Schick and Schütze, 2021a). Depending on the tool, our method is also very sample-inefficient; for example, processing more than a million documents results in only a few thousand examples of useful calls to the calculator API. A potential solution to this problem might be to iteratively apply our approach, similar to how this is done in related bootstrapping approaches (Schick and Schütze, 2021a; Izacard and Grave, 2021; Parisi et al., 2022). Finally, when deciding whether or not to make an API call, Toolformer currently does not take into account the tool-dependent, computational cost incurred from making an API call.
168
+
169
+ # 7 Conclusion
170
+
171
+ We have introduced Toolformer, a LM that learns in a self-supervised way how to use different tools such as search engines, calculators, and translation systems via simple API calls. This is done by finetuning on sampled API calls that are filtered based on whether they reduce perplexity on future tokens. Toolformer considerably improves zero-shot performance of a 6.7B parameter GPT-J model, enabling it to even outperform a much larger GPT-3 model on a range of different downstream tasks.
172
+
173
+ # References
174
+
175
+ Armen Aghajanyan, Dmytro Okhonko, Mike Lewis, Mandar Joshi, Hu Xu, Gargi Ghosh, and Luke Zettlemoyer. 2021. Htlm: Hyper-text pre-training and prompting of language models.
176
+
177
+ Eugene Agichtein and Luis Gravano. 2000. Snowball: Extracting relations from large plain-text collections. In Proceedings of the Fifth ACM Conference on Digital Libraries, DL ’00, page 85–94, New York, NY, USA. Association for Computing Machinery.
178
+
179
+ Ricardo Baeza-Yates, Berthier Ribeiro-Neto, et al. 1999. Modern information retrieval, volume 463. ACM press New York.
180
+
181
+ Jonathan Berant, Andrew Chou, Roy Frostig, and Percy Liang. 2013. Semantic parsing on Freebase from question-answer pairs. In Proceedings of the 2013 Conference on Empirical Methods in Natural Language Processing, pages 1533–1544, Seattle, Washington, USA. Association for Computational Linguistics.
182
+
183
+ Sebastian Borgeaud, Arthur Mensch, Jordan Hoffmann, Trevor Cai, Eliza Rutherford, Katie Millican, George van den Driessche, Jean-Baptiste Lespiau, Bogdan Damoc, Aidan Clark, Diego de Las Casas, Aurelia Guy, Jacob Menick, Roman Ring, Tom Hennigan, Saffron Huang, Loren Maggiore, Chris Jones, Albin Cassirer, Andy Brock, Michela Paganini, Geoffrey Irving, Oriol Vinyals, Simon Osindero, Karen Simonyan, Jack W. Rae, Erich Elsen, and Laurent Sifre. 2021. Improving language models by retrieving from trillions of tokens.
184
+
185
+ Sergey Brin. 1999. Extracting patterns and relations from the world wide web. In The World Wide Web and Databases, pages 172–183, Berlin, Heidelberg. Springer Berlin Heidelberg.
186
+
187
+ Tom Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah, Jared D Kaplan, Prafulla Dhariwal, Arvind Neelakantan, Pranav Shyam, Girish Sastry, Amanda Askell, Sandhini Agarwal, Ariel Herbert-Voss, Gretchen Krueger, Tom Henighan, Rewon Child, Aditya Ramesh, Daniel Ziegler, Jeffrey Wu, Clemens Winter, Chris Hesse, Mark Chen, Eric Sigler, Mateusz Litwin, Scott Gray, Benjamin Chess, Jack Clark, Christopher Berner, Sam McCandlish, Alec Radford, Ilya Sutskever, and Dario Amodei. 2020. Language models are few-shot learners. In Advances in Neural Information Processing Systems, volume 33, pages 1877–1901. Curran Associates, Inc.
188
+
189
+ Aakanksha Chowdhery, Sharan Narang, Jacob Devlin, Maarten Bosma, Gaurav Mishra, Adam Roberts, Paul Barham, Hyung Won Chung, Charles Sutton, Sebastian Gehrmann, Parker Schuh, Kensen Shi, Sasha Tsvyashchenko, Joshua Maynez, Abhishek Rao, Parker Barnes, Yi Tay, Noam Shazeer, Vinodkumar Prabhakaran, Emily Reif, Nan Du, Ben Hutchinson, Reiner Pope, James Bradbury, Jacob Austin, Michael Isard, Guy Gur-Ari, Pengcheng Yin, Toju Duke, Anselm Levskaya, Sanjay Ghemawat, Sunipa Dev, Henryk Michalewski, Xavier Garcia, Vedant Misra, Kevin Robinson, Liam Fedus, Denny Zhou, Daphne Ippolito, David Luan, Hyeontaek Lim, Barret Zoph, Alexander Spiridonov, Ryan Sepassi, David Dohan, Shivani Agrawal, Mark Omernick, Andrew M. Dai, Thanumalayan Sankaranarayana Pillai, Marie Pellat, Aitor Lewkowycz, Erica Moreira, Rewon Child, Oleksandr Polozov, Katherine Lee, Zongwei Zhou, Xuezhi Wang, Brennan Saeta, Mark Diaz, Orhan Firat, Michele Catasta, Jason Wei, Kathy Meier-Hellstern, Douglas Eck, Jeff Dean, Slav Petrov, and Noah Fiedel. 2022. Palm: Scaling language modeling with pathways.
190
+
191
+ Karl Cobbe, Vineet Kosaraju, Mohammad Bavarian, Mark Chen, Heewoo Jun, Lukasz Kaiser, Matthias Plappert, Jerry Tworek, Jacob Hilton, Reiichiro Nakano, et al. 2021. Training verifiers to solve math word problems. arXiv preprint arXiv:2110.14168.
192
+
193
+ Marta R Costa-jussà, James Cross, Onur Çelebi, Maha Elbayad, Kenneth Heafield, Kevin Heffernan, Elahe Kalbassi, Janice Lam, Daniel Licht, Jean Maillard, et al. 2022. No language left behind: Scaling human-centered machine translation. arXiv preprint arXiv:2207.04672.
194
+
195
+ 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, Volume 1 (Long and Short Papers), pages 4171–4186, Minneapolis, Minnesota. Association for Computational Linguistics.
196
+
197
+ Bhuwan Dhingra, Jeremy R. Cole, Julian Martin Eisenschlos, Daniel Gillick, Jacob Eisenstein, and William W. Cohen. 2022. Time-aware language models as temporal knowledge bases. Transactions of the Association for Computational Linguistics, 10:257–273.
198
+
199
+ Luyu Gao, Aman Madaan, Shuyan Zhou, Uri Alon, Pengfei Liu, Yiming Yang, Jamie Callan, and Graham Neubig. 2022. Pal: Program-aided language models.
200
+
201
+ Kelvin Guu, Kenton Lee, Zora Tung, Panupong Pasupat, and Ming-Wei Chang. 2020. Realm: Retrieval-augmented language model pre-training.
202
+
203
+ Junxian He, Jiatao Gu, Jiajun Shen, and Marc’Aurelio Ranzato. 2020. Revisiting self-training for neural sequence generation. In International Conference on Learning Representations.
204
+
205
+ Or Honovich, Thomas Scialom, Omer Levy, and Timo Schick. 2022. Unnatural instructions: Tuning language models with (almost) no human labor.
206
+
207
+ Gautier Izacard and Edouard Grave. 2021. Distilling knowledge from reader to retriever for question answering. In International Conference on Learning Representations.
208
+
209
+ Gautier Izacard, Patrick Lewis, Maria Lomeli, Lucas Hosseini, Fabio Petroni, Timo Schick, Jane Dwivedi-Yu, Armand Joulin, Sebastian Riedel, and Edouard Grave. 2022. Atlas: Few-shot learning with retrieval augmented language models.
210
+
211
+ Ziwei Ji, Nayeon Lee, Rita Frieske, Tiezheng Yu, Dan Su, Yan Xu, Etsuko Ishii, Yejin Bang, Andrea Madotto, and Pascale Fung. 2022. Survey of hallucination in natural language generation. ACM Computing Surveys.
212
+
213
+ Zhengbao Jiang, Frank F. Xu, Jun Araki, and Graham Neubig. 2020. How can we know what language models know? Transactions of the Association for Computational Linguistics, 8:423–438.
214
+
215
+ Mandar Joshi, Eunsol Choi, Daniel Weld, and Luke Zettlemoyer. 2017. TriviaQA: A large scale distantly supervised challenge dataset for reading comprehension. In Proceedings of the 55th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 1601–1611, Vancouver, Canada. Association for Computational Linguistics.
216
+
217
+ Armand Joulin, Edouard Grave, Piotr Bojanowski, Matthijs Douze, Hérve Jégou, and Tomas Mikolov. 2016. Fasttext. zip: Compressing text classification models. arXiv preprint arXiv:1612.03651.
218
+
219
+ Nitish Shirish Keskar, Bryan McCann, Lav R. Varshney, Caiming Xiong, and Richard Socher. 2019. Ctrl: A conditional transformer language model for controllable generation.
220
+
221
+ Philipp Koehn. 2005. Europarl: A parallel corpus for statistical machine translation. In Proceedings of machine translation summit x: papers, pages 79–86.
222
+
223
+ Mojtaba Komeili, Kurt Shuster, and Jason Weston. 2022. Internet-augmented dialogue generation. In Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 8460–8478, Dublin, Ireland. Association for Computational Linguistics.
224
+
225
+ Rik Koncel-Kedziorski, Subhro Roy, Aida Amini, Nate Kushman, and Hannaneh Hajishirzi. 2016. MAWPS: A math word problem repository. In Proceedings of the 2016 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, pages 1152–1157, San Diego, California. Association for Computational Linguistics.
226
+
227
+ 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. 2019. Natural questions: A benchmark for question answering research. Transactions of the Association for Computational Linguistics, 7:452–466.
228
+
229
+ Angeliki Lazaridou, Elena Gribovskaya, Wojciech Stokowiec, and Nikolai Grigorev. 2022. Internetaugmented language models through few-shot prompting for open-domain question answering. arXiv preprint arXiv:2203.05115.
230
+
231
+ Patrick Lewis, Barlas Oguz, Ruty Rinott, Sebastian Riedel, and Holger Schwenk. 2019. Mlqa:˘ Evaluating cross-lingual extractive question answering. arXiv preprint arXiv:1910.07475.
232
+
233
+ Xi Victoria Lin, Todor Mihaylov, Mikel Artetxe, Tianlu Wang, Shuohui Chen, Daniel Simig, Myle Ott, Naman Goyal, Shruti Bhosale, Jingfei Du, Ramakanth Pasunuru, Sam Shleifer, Punit Singh Koura, Vishrav Chaudhary, Brian O’Horo, Jeff Wang, Luke Zettlemoyer, Zornitsa Kozareva, Mona Diab, Veselin Stoyanov, and Xian Li. 2021. Few-shot learning with multilingual language models.
234
+
235
+ Joshua Maynez, Shashi Narayan, Bernd Bohnet, and Ryan McDonald. 2020. On faithfulness and factuality in abstractive summarization.
236
+
237
+ David McClosky, Eugene Charniak, and Mark Johnson. 2006. Effective self-training for parsing. In Proceedings of the Human Language Technology Conference of the NAACL, Main Conference, pages 152–159, New York City, USA. Association for Computational Linguistics.
238
+
239
+ Stephen Merity, Caiming Xiong, James Bradbury, and Richard Socher. 2017. Pointer sentinel mixture models. In International Conference on Learning Representations.
240
+
241
+ Shen-yun Miao, Chao-Chun Liang, and Keh-Yih Su. 2020. A diverse corpus for evaluating and developing English math word problem solvers. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics, pages 975–984, Online. Association for Computational Linguistics.
242
+
243
+ Reiichiro Nakano, Jacob Hilton, Suchir Balaji, Jeff Wu, Long Ouyang, Christina Kim, Christopher Hesse, Shantanu Jain, Vineet Kosaraju, William Saunders, Xu Jiang, Karl Cobbe, Tyna Eloundou, Gretchen Krueger, Kevin Button, Matthew Knight, Benjamin Chess, and John Schulman. 2021. Webgpt: Browser-assisted question-answering with human feedback.
244
+
245
+ Aaron Parisi, Yao Zhao, and Noah Fiedel. 2022. Talm: Tool augmented language models.
246
+
247
+ Arkil Patel, Satwik Bhattamishra, and Navin Goyal. 2021. Are NLP models really able to solve simple math word problems? In Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, pages 2080–2094, Online. Association for Computational Linguistics.
248
+
249
+ Fabio Petroni, Aleksandra Piktus, Angela Fan, Patrick Lewis, Majid Yazdani, Nicola De Cao, James Thorne, Yacine Jernite, Vladimir Karpukhin, Jean Maillard, Vassilis Plachouras, Tim Rocktäschel, and Sebastian Riedel. 2021. KILT: a benchmark for knowledge intensive language tasks. In Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, pages 2523–2544, Online. Association for Computational Linguistics.
250
+
251
+ Fabio Petroni, Tim Rocktäschel, Sebastian Riedel, Patrick Lewis, Anton Bakhtin, Yuxiang Wu, and Alexander Miller. 2019. Language models as knowledge bases? 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 2463–2473, Hong Kong, China. Association for Computational Linguistics.
252
+
253
+ 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.
254
+
255
+ Stephen E Robertson, Steve Walker, Susan Jones, Micheline M Hancock-Beaulieu, Mike Gatford, et al. 1995. Okapi at trec-3. Nist Special Publication Sp, 109:109.
256
+
257
+ Timo Schick, Jane Dwivedi-Yu, Zhengbao Jiang, Fabio Petroni, Patrick Lewis, Gautier Izacard, Qingfei You, Christoforos Nalmpantis, Edouard Grave, and Sebastian Riedel. 2022. Peer: A collaborative language model.
258
+
259
+ Timo Schick and Hinrich Schütze. 2021a. Exploiting cloze-questions for few-shot text classification and natural language inference. In Proceedings of the 16th Conference of the European Chapter of the Association for Computational Linguistics: Main Volume, pages 255–269, Online. Association for Computational Linguistics.
260
+
261
+ Timo Schick and Hinrich Schütze. 2021b. Generating datasets with pretrained language models. In Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing, pages 6943–6951, Online and Punta Cana, Dominican Republic. Association for Computational Linguistics.
262
+
263
+ Kurt Shuster, Jing Xu, Mojtaba Komeili, Da Ju, Eric Michael Smith, Stephen Roller, Megan Ung, Moya Chen, Kushal Arora, Joshua Lane, Morteza Behrooz, William Ngan, Spencer Poff, Naman Goyal, Arthur Szlam, Y-Lan Boureau, Melanie Kambadur, and Jason Weston. 2022. Blenderbot 3: a deployed conversational agent that continually learns to responsibly engage.
264
+
265
+ Romal Thoppilan, Daniel De Freitas, Jamie Hall, Noam Shazeer, Apoorv Kulshreshtha, Heng-Tze Cheng, Alicia Jin, Taylor Bos, Leslie Baker, Yu Du, YaGuang Li, Hongrae Lee, Huaixiu Steven Zheng, Amin Ghafouri, Marcelo Menegali, Yanping Huang, Maxim Krikun, Dmitry Lepikhin, James Qin, Dehao Chen, Yuanzhong Xu, Zhifeng Chen, Adam Roberts, Maarten Bosma, Vincent Zhao, Yanqi Zhou, Chung-Ching Chang, Igor Krivokon, Will Rusch, Marc Pickett, Pranesh Srinivasan, Laichee Man, Kathleen Meier-Hellstern, Meredith Ringel Morris, Tulsee Doshi, Renelito Delos Santos, Toju Duke, Johnny Soraker, Ben Zevenbergen, Vinodkumar Prabhakaran, Mark Diaz, Ben Hutchinson, Kristen Olson, Alejandra Molina, Erin Hoffman-John, Josh Lee, Lora Aroyo, Ravi Rajakumar, Alena Butryna, Matthew Lamm, Viktoriya Kuzmina, Joe Fenton, Aaron Cohen, Rachel Bernstein, Ray Kurzweil, Blaise Aguera-Arcas, Claire Cui, Marian Croak, Ed Chi, and Quoc Le. 2022. Lamda: Language models for dialog applications.
266
+
267
+ Hugo Touvron, Thibaut Lavril, Gautier Izacard, Xavier Martinet, Marie-Anne Lachaux, Timothée Lacroix, Baptiste Rozière, Naman Goyal, Eric Hambro, Faisal Azhar, Aurelien Rodriguez, Armand Joulin, Edouard Grave, and Guillaume Lample. 2023. Llama: Open and efficient foundation language models.
268
+
269
+ Ben Wang and Aran Komatsuzaki. 2021. GPT-J-6B: A 6 Billion Parameter Autoregressive Language Model. https://github.com/kingoflolz/mesh-transformer-jax.
270
+
271
+ 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.
272
+
273
+ Guillaume Wenzek, Marie-Anne Lachaux, Alexis Conneau, Vishrav Chaudhary, Francisco Guzmán, Armand Joulin, and Edouard Grave. 2020. CCNet: Extracting high quality monolingual datasets from web crawl data. In Proceedings of the Twelfth Language Resources and Evaluation Conference, pages 4003–4012, Marseille, France. European Language Resources Association.
274
+
275
+ Shunyu Yao, Jeffrey Zhao, Dian Yu, Nan Du, Izhak Shafran, Karthik Narasimhan, and Yuan Cao. 2022. React: Synergizing reasoning and acting in language models.
276
+
277
+ David Yarowsky. 1995. Unsupervised word sense disambiguation rivaling supervised methods. In 33rd Annual Meeting of the Association for Computational Linguistics, pages 189–196, Cambridge, Massachusetts, USA. Association for Computational Linguistics.
278
+
279
+ Eric Zelikman, Yuhuai Wu, Jesse Mu, and Noah D. Goodman. 2022. Star: Bootstrapping reasoning with reasoning.
280
+
281
+ Susan Zhang, Stephen Roller, Naman Goyal, Mikel Artetxe, Moya Chen, Shuohui Chen, Christopher Dewan, Mona Diab, Xian Li, Xi Victoria Lin, Todor Mihaylov, Myle Ott, Sam Shleifer, Kurt Shuster, Daniel Simig, Punit Singh Koura, Anjali Sridhar, Tianlu Wang, and Luke Zettlemoyer. 2022. Opt: Open pre-trained transformer language models.
parse/dev/Yacmpz84TH/Yacmpz84TH_content_list.json ADDED
@@ -0,0 +1,1502 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "type": "text",
4
+ "text": "Toolformer: Language Models Can Teach Themselves to Use Tools ",
5
+ "text_level": 1,
6
+ "bbox": [
7
+ 174,
8
+ 122,
9
+ 823,
10
+ 172
11
+ ],
12
+ "page_idx": 0
13
+ },
14
+ {
15
+ "type": "text",
16
+ "text": "Timo Schick Jane Dwivedi-Yu Roberto Dessì† Roberta Raileanu Maria Lomeli Eric Hambro Luke Zettlemoyer Nicola Cancedda Thomas Scialom ",
17
+ "bbox": [
18
+ 183,
19
+ 224,
20
+ 816,
21
+ 260
22
+ ],
23
+ "page_idx": 0
24
+ },
25
+ {
26
+ "type": "text",
27
+ "text": "FAIR, Meta †Universitat Pompeu Fabra ",
28
+ "bbox": [
29
+ 366,
30
+ 268,
31
+ 632,
32
+ 284
33
+ ],
34
+ "page_idx": 0
35
+ },
36
+ {
37
+ "type": "text",
38
+ "text": "Abstract ",
39
+ "text_level": 1,
40
+ "bbox": [
41
+ 462,
42
+ 319,
43
+ 535,
44
+ 337
45
+ ],
46
+ "page_idx": 0
47
+ },
48
+ {
49
+ "type": "text",
50
+ "text": "Language models (LMs) exhibit remarkable abilities to solve new tasks from just a few examples or textual instructions, especially at scale. They also, paradoxically, struggle with basic functionality, such as arithmetic or factual lookup, where much simpler and smaller specialized models excel. In this paper, we show that LMs can teach themselves to use external tools via simple APIs and achieve the best of both worlds. We introduce Toolformer, a model trained to decide which APIs to call, when to call them, what arguments to pass, and how to best incorporate the results into future token prediction. This is done in a self-supervised way, requiring nothing more than a handful of demonstrations for each API. We incorporate a range of tools, including a calculator, a Q&A system, a search engine, a translation system, and a calendar. Toolformer achieves substantially improved zero-shot performance across a variety of downstream tasks, often competitive with much larger models, without sacrificing its core language modeling abilities. ",
51
+ "bbox": [
52
+ 233,
53
+ 349,
54
+ 766,
55
+ 529
56
+ ],
57
+ "page_idx": 0
58
+ },
59
+ {
60
+ "type": "text",
61
+ "text": "1 Introduction ",
62
+ "text_level": 1,
63
+ "bbox": [
64
+ 174,
65
+ 551,
66
+ 310,
67
+ 569
68
+ ],
69
+ "page_idx": 0
70
+ },
71
+ {
72
+ "type": "text",
73
+ "text": "Large language models achieve impressive zero and few-shot results on a variety of natural language processing tasks (Brown et al., 2020; Chowdhery et al., 2022, i.a.). However, these models have several inherent limitations that can at best be partially addressed by further scaling. These limitations include an inability to access up-to-date information on recent events (Komeili et al., 2022) and the related tendency to hallucinate facts (Maynez et al., 2020; Ji et al., 2022), difficulties in understanding low-resource languages (Lin et al., 2021), a lack of mathematical skills to perform precise calculations (Patel et al., 2021) and an unawareness of the progression of time (Dhingra et al., 2022). ",
74
+ "bbox": [
75
+ 174,
76
+ 582,
77
+ 825,
78
+ 679
79
+ ],
80
+ "page_idx": 0
81
+ },
82
+ {
83
+ "type": "text",
84
+ "text": "A simple way to overcome the limitations of today’s language models is to give them the ability to use external tools such as search engines, calculators, or calendars. However, existing approaches either rely on large amounts of human annotations (Komeili et al., 2022; Thoppilan et al., 2022) or limit tool use to task-specific settings only (e.g., Gao et al., 2022; Parisi et al., 2022), hindering a more widespread adoption of tool use in LMs. Therefore, we propose Toolformer, a model that learns to use tools in a novel way, which fulfills the following desiderata: ",
85
+ "bbox": [
86
+ 176,
87
+ 685,
88
+ 825,
89
+ 768
90
+ ],
91
+ "page_idx": 0
92
+ },
93
+ {
94
+ "type": "text",
95
+ "text": "• Tool use should be learned in a self-supervised way without large amounts of human annotations. This is important not only because of the costs associated with such annotations, but also because what humans find useful may be different from what a model finds useful. • The LM should not lose any of its generality and should be able to decide for itself when and how to use which tool. In contrast to existing approaches, this enables a much more comprehensive use of tools that is not tied to specific tasks. ",
96
+ "bbox": [
97
+ 217,
98
+ 779,
99
+ 825,
100
+ 866
101
+ ],
102
+ "page_idx": 0
103
+ },
104
+ {
105
+ "type": "text",
106
+ "text": "Our approach for achieving these goals is based on the recent idea of using large LMs with in-context learning (Brown et al., 2020) to generate entire datasets from scratch (Schick and Schütze, 2021b; ",
107
+ "bbox": [
108
+ 173,
109
+ 876,
110
+ 823,
111
+ 904
112
+ ],
113
+ "page_idx": 0
114
+ },
115
+ {
116
+ "type": "image",
117
+ "img_path": "images/efd2dac35f6d1a63826328723565885e1aad2ceea0a3379b92e4c40bd9922f6b.jpg",
118
+ "image_caption": [
119
+ "Figure 1: Exemplary predictions of Toolformer. The model autonomously decides to call different APIs (from top to bottom: a question answering system, a calculator, a machine translation system, and a Wikipedia search engine) to obtain information that is useful for completing a piece of text. "
120
+ ],
121
+ "image_footnote": [],
122
+ "bbox": [
123
+ 176,
124
+ 92,
125
+ 823,
126
+ 231
127
+ ],
128
+ "page_idx": 1
129
+ },
130
+ {
131
+ "type": "image",
132
+ "img_path": "images/5869d239001ffcca88eb10a98a653d9f154d0247150188f33783d20eda69ab5b.jpg",
133
+ "image_caption": [
134
+ "Figure 2: Key steps in ourwe first sample a position pproach, illustrated for a question answe and corresponding API call candidates en an input text . We then execu $\\mathbf { x }$ , $i$ $c _ { i } ^ { 1 } , c _ { i } ^ { 2 } , \\ldots , c _ { i } ^ { k }$ these API calls and filter out all calls which do not reduce the loss $L _ { i }$ over the next tokens. All remaining API calls are interleaved with the original text, resulting in a new text $\\mathbf { x } ^ { * }$ . "
135
+ ],
136
+ "image_footnote": [],
137
+ "bbox": [
138
+ 173,
139
+ 304,
140
+ 825,
141
+ 406
142
+ ],
143
+ "page_idx": 1
144
+ },
145
+ {
146
+ "type": "text",
147
+ "text": "Honovich et al., 2022; Wang et al., 2022): Given just a handful of human-written examples of how an API can be used, we let a LM annotate a huge language modeling dataset with potential API calls. We then use a self-supervised loss to determine which of these API calls actually help the model in predicting future tokens. Finally, we finetune the LM itself on the API calls that it considers useful. As illustrated in Figure 1, through this simple approach, LMs can learn to control a variety of tools, and to choose for themselves which tool to use when and how. ",
148
+ "bbox": [
149
+ 173,
150
+ 497,
151
+ 826,
152
+ 582
153
+ ],
154
+ "page_idx": 1
155
+ },
156
+ {
157
+ "type": "text",
158
+ "text": "As our approach is agnostic of the dataset being used, we can apply it to the exact same dataset that was used to pretrain a model in the first place. This ensures that the model does not lose any of its generality and language modeling abilities. We conduct experiments on a variety of different downstream tasks, demonstrating that after learning to use tools, Toolformer, which is based on a pretrained GPT-J model (Wang and Komatsuzaki, 2021) with 6.7B parameters, achieves much stronger zero-shot results, clearly outperforming a much larger GPT-3 model (Brown et al., 2020) and several other baselines on various tasks. ",
159
+ "bbox": [
160
+ 174,
161
+ 588,
162
+ 825,
163
+ 685
164
+ ],
165
+ "page_idx": 1
166
+ },
167
+ {
168
+ "type": "text",
169
+ "text": "2 Approach ",
170
+ "text_level": 1,
171
+ "bbox": [
172
+ 174,
173
+ 707,
174
+ 289,
175
+ 724
176
+ ],
177
+ "page_idx": 1
178
+ },
179
+ {
180
+ "type": "text",
181
+ "text": "Our aim is to equip a language model $M$ with the ability to use different tools through API calls. We represent API calls as tuples $c = ( a _ { c } , i _ { c } )$ where $a _ { c }$ is the name of the API and $i _ { c }$ is the corresponding input. Given an API call $c$ with a corresponding result $r$ , we denote the linearized sequences of the API call not including and including its result, respectively, as: ",
182
+ "bbox": [
183
+ 173,
184
+ 739,
185
+ 825,
186
+ 795
187
+ ],
188
+ "page_idx": 1
189
+ },
190
+ {
191
+ "type": "equation",
192
+ "img_path": "images/1064527a7674ba25a1414da0a4003e59afc6210588e374a16176efe73e849733.jpg",
193
+ "text": "$$\n\\begin{array} { r } { \\mathsf { e } ( c ) = < \\mathtt { A P I } > a _ { c } ( i _ { c } ) < / \\mathtt { A P I } > \\mathsf { e } ( c , r ) = < \\mathtt { A P I } > a _ { c } ( i _ { c } ) \\to r < / \\mathtt { A P I } > } \\end{array}\n$$",
194
+ "text_format": "latex",
195
+ "bbox": [
196
+ 246,
197
+ 804,
198
+ 751,
199
+ 821
200
+ ],
201
+ "page_idx": 1
202
+ },
203
+ {
204
+ "type": "text",
205
+ "text": "where $ { \\mathrm { ~ ~ \\cdots ~ } } < \\tt { A P I } > { \\mathrm { ^ { \\circ } } }$ , $ { \\mathrm { ~ ~ \\cdots ~ } } < / \\tt A P I > { \\mathrm { ^ { \\circ } } }$ and $\\ \" \\ \"$ are special tokens.1 Some examples of linearized API calls inserted into text sequences are shown in Figure 1. ",
206
+ "bbox": [
207
+ 174,
208
+ 829,
209
+ 825,
210
+ 858
211
+ ],
212
+ "page_idx": 1
213
+ },
214
+ {
215
+ "type": "text",
216
+ "text": "Your task is to add calls to a Question Answering API to a piece of text. The questions should help you get information required to complete the text. You can call the API by writing \"[QA(question)]\" where \"question\" is the question you want to ask. Here are some examples of API calls: ",
217
+ "bbox": [
218
+ 183,
219
+ 95,
220
+ 812,
221
+ 135
222
+ ],
223
+ "page_idx": 2
224
+ },
225
+ {
226
+ "type": "text",
227
+ "text": "Input: Joe Biden was born in Scranton, Pennsylvania. \nOutput: Joe Biden was born in [QA(\"Where was Joe Biden born?\")] Scranton, [QA(\"In which state is Scranton?\")] Pennsylvania. ",
228
+ "bbox": [
229
+ 181,
230
+ 143,
231
+ 750,
232
+ 183
233
+ ],
234
+ "page_idx": 2
235
+ },
236
+ {
237
+ "type": "text",
238
+ "text": "Input: Coca-Cola, or Coke, is a carbonated soft drink manufactured by the Coca-Cola Company. Output: Coca-Cola, or [QA(\"What other name is Coca-Cola known by?\")] ${ \\mathsf { C o k e } } ,$ , is a carbonated soft drink manufactured by [QA(\"Who manufactures Coca-Cola?\")] the Coca-Cola Company. ",
239
+ "bbox": [
240
+ 184,
241
+ 193,
242
+ 802,
243
+ 232
244
+ ],
245
+ "page_idx": 2
246
+ },
247
+ {
248
+ "type": "text",
249
+ "text": "Input: x Output: ",
250
+ "bbox": [
251
+ 184,
252
+ 241,
253
+ 227,
254
+ 266
255
+ ],
256
+ "page_idx": 2
257
+ },
258
+ {
259
+ "type": "text",
260
+ "text": "Given a dataset $\\mathcal { C } = \\{ \\mathbf { x } ^ { 1 } , \\ldots , \\mathbf { x } ^ { | \\mathcal { C } | } \\}$ of plain texts, we first convert this dataset into a dataset $\\mathcal { C } ^ { * }$ augmented with API calls. This is done in three steps, illustrated in Figure 2: First, we exploit the in-context learning ability of $M$ to sample a large number of API calls. We then execute them and finally check whether the obtained responses are helpful for predicting future tokens; this is used as a filtering criterion. After filtering, we merge API calls for different tools, resulting in the augmented dataset $\\mathcal { C } ^ { * }$ , and finetune $M$ itself on this dataset. Each step is described in more detail below. ",
261
+ "bbox": [
262
+ 173,
263
+ 316,
264
+ 825,
265
+ 402
266
+ ],
267
+ "page_idx": 2
268
+ },
269
+ {
270
+ "type": "text",
271
+ "text": "Sampling API Calls For each API, we write a prompt $P ( \\mathbf { x } )$ that encourages the LM to annotate an example $\\mathbf { x } = x _ { 1 } , \\ldots , x _ { n }$ with API calls. An example of such a prompt for a question answering tool is shown in Figure 3. Let $p _ { M } ( z _ { n + 1 } \\mid z _ { 1 } , . . . , z _ { n } )$ be the probability that $M$ assigns to token $z _ { n + 1 }$ as a continuation for the sequence $z _ { 1 } , \\ldots , z _ { n }$ . We first sample up to $k$ candidate positions for doing API calls by computing, for each $i \\in \\{ 1 , \\ldots , n \\}$ , the probability $p _ { i } = p _ { M } ( < _ { \\tt A P I > } \\mid P ( \\mathbf { x } ) , x _ { 1 : i - 1 } )$ that $M$ assigns to starting an API call at position $i$ . Given a sampling threshold $\\tau _ { s }$ , we keep all positions $I \\stackrel { - } { = } \\{ i | p _ { i } > \\tau _ { s } \\stackrel { - } { \\} }$ ; if there are more than $k$ such positions, we only keep the top $k$ . For each position $i \\in I$ , we then obtain up to $m$ API calls $c _ { i } ^ { 1 } , \\ldots , c _ { i } ^ { m }$ by sampling from $M$ given the sequence $[ P ( \\mathbf { x } ) , x _ { 1 } , \\ldots , x _ { i - 1 } , < \\mathtt { A P I } > ]$ as a prefix and ${ < } / { \\tt A P I > }$ as an end-of-sequence token. ",
272
+ "bbox": [
273
+ 173,
274
+ 415,
275
+ 825,
276
+ 541
277
+ ],
278
+ "page_idx": 2
279
+ },
280
+ {
281
+ "type": "text",
282
+ "text": "Executing API Calls As a next step, we execute all API calls generated by $M$ . How this is done depends entirely on the API itself – for example, it can involve calling another neural network, executing a Python script or using a retrieval system to perform search over a large corpus. The response for each API call $c _ { i }$ needs to be a single text sequence $r _ { i }$ . ",
283
+ "bbox": [
284
+ 174,
285
+ 554,
286
+ 825,
287
+ 611
288
+ ],
289
+ "page_idx": 2
290
+ },
291
+ {
292
+ "type": "text",
293
+ "text": "Filtering API Calls Let $i$ be the position of the API call $c _ { i }$ in the sequence $\\mathbf { x } = x _ { 1 } , \\ldots , x _ { n }$ , and let $r _ { i }$ be the response from the API. Further, given a sequence $( w _ { i } \\mid i \\in \\mathbb { N } )$ of weights, let ",
294
+ "bbox": [
295
+ 174,
296
+ 623,
297
+ 823,
298
+ 654
299
+ ],
300
+ "page_idx": 2
301
+ },
302
+ {
303
+ "type": "equation",
304
+ "img_path": "images/33953fde96b6483fae55868512e0984f9f0c88054ed8aa8da92f9a5865ced994.jpg",
305
+ "text": "$$\nL _ { i } ( \\mathbf { z } ) = - \\sum _ { j = i } ^ { n } w _ { j - i } \\cdot \\log p _ { M } ( x _ { j } \\mid \\mathbf { z } , x _ { 1 : j - 1 } )\n$$",
306
+ "text_format": "latex",
307
+ "bbox": [
308
+ 349,
309
+ 656,
310
+ 648,
311
+ 699
312
+ ],
313
+ "page_idx": 2
314
+ },
315
+ {
316
+ "type": "text",
317
+ "text": "be the weighted cross entropy loss for $M$ over the tokens $x _ { i } , \\ldots , x _ { n }$ if the model is prefixed with some text sequence $\\mathbf { z }$ . We compare two different instantiations of this loss: ",
318
+ "bbox": [
319
+ 169,
320
+ 702,
321
+ 823,
322
+ 729
323
+ ],
324
+ "page_idx": 2
325
+ },
326
+ {
327
+ "type": "equation",
328
+ "img_path": "images/61abd2850c8d5910556db651b3401e55160ad88007a179cdad0a9c344439d1f2.jpg",
329
+ "text": "$$\nL _ { i } ^ { + } = L _ { i } ( \\mathbf { e } ( c _ { i } , r _ { i } ) ) \\qquad L _ { i } ^ { - } = \\operatorname* { m i n } \\left( L _ { i } ( \\varepsilon ) , L _ { i } ( \\mathbf { e } ( c _ { i } , \\varepsilon ) ) \\right)\n$$",
330
+ "text_format": "latex",
331
+ "bbox": [
332
+ 299,
333
+ 732,
334
+ 699,
335
+ 750
336
+ ],
337
+ "page_idx": 2
338
+ },
339
+ {
340
+ "type": "text",
341
+ "text": "where $\\varepsilon$ denotes an empty sequence. The former is the weighted loss over all tokens $x _ { i } , \\ldots , x _ { n }$ if the API call and its result are given to $M$ as a prefix;2 the latter is the minimum of the losses obtained from (i) doing no API call at all and (ii) doing an API call, but not providing the response. Intuitively, an API call is helpful to $M$ if providing it with both the input and the output of this call makes it easier for the model to predict future tokens, compared to not receiving the API call at all, or receiving only its input. Given a filtering threshold $\\tau _ { f }$ , we thus only keep API calls for which $L _ { i } ^ { - } - L _ { i } ^ { + } \\ge \\tau _ { f }$ holds, i.e., adding the API call and its result reduces the loss by at least $\\tau _ { f }$ , compared to not doing any API call or obtaining no result from it. ",
342
+ "bbox": [
343
+ 173,
344
+ 752,
345
+ 826,
346
+ 864
347
+ ],
348
+ "page_idx": 2
349
+ },
350
+ {
351
+ "type": "table",
352
+ "img_path": "images/cc2e355eee41244dc7e1460c8b1bc8ba42ead9d5d51d4666ba28b5eaec959037.jpg",
353
+ "table_caption": [
354
+ "Table 1: Examples of inputs and outputs for all APIs used. "
355
+ ],
356
+ "table_footnote": [],
357
+ "table_body": "<table><tr><td>API Name</td><td>Example Input</td><td>Example Output</td></tr><tr><td>Question Answering</td><td>Where was the Knights of Columbus founded?</td><td>New Haven, Connecticut</td></tr><tr><td>Wikipedia Search</td><td>Fishing Reel Types</td><td>Spin fishing &gt; Spin fishing is distinguished between fly fishing and bait cast fishing by the type of rod and reel used. There are two types of reels used when spin fishing,</td></tr><tr><td>Calculator</td><td>27+4*2</td><td>the open faced reel and the closed faced reel. 35</td></tr><tr><td>Calendar</td><td>m</td><td>Today is Monday, January 30,2023.</td></tr><tr><td>Machine Translation</td><td>sureté nucléaire</td><td>nuclear safety</td></tr></table>",
358
+ "bbox": [
359
+ 173,
360
+ 111,
361
+ 821,
362
+ 253
363
+ ],
364
+ "page_idx": 3
365
+ },
366
+ {
367
+ "type": "text",
368
+ "text": "Model Finetuning After sampling and filtering calls for all APIs, we finally merge the remaining API calls and interleave them with the original inputs. That is, for an input text $\\mathbf { x } = x _ { 1 } , \\ldots , x _ { n }$ with a corresponding API call and result $( c _ { i } , r _ { i } )$ at position $i$ , we construct the new sequence $\\mathbf { x } ^ { * } = x _ { 1 : i - 1 } , \\mathbf { e } ( c _ { i } , r _ { i } ) , x _ { i : n }$ ; we proceed analogously for texts with multiple API calls. Doing this for all $\\mathbf { x } \\in { \\mathcal { C } }$ results in the new dataset $\\mathcal { C } ^ { * }$ augmented with API calls. We use $\\mathcal { C } ^ { * }$ to finetune $M$ , using a standard language modeling objective. Crucially, apart from inserted API calls, $\\mathcal { C } ^ { * }$ contains the exact same texts as $\\mathcal { C }$ , the original dataset. As a consequence, finetuning $M$ on $\\mathcal { C } ^ { * }$ exposes it to the same content as finetuning on $\\mathcal { C }$ . Moreover, as API calls are inserted in exactly those positions and with exactly those inputs that help $M$ predict future tokens, finetuning on $\\mathcal { C } ^ { * }$ enables the language model to decide when and how to use which tool, based purely on its own feedback. ",
369
+ "bbox": [
370
+ 173,
371
+ 276,
372
+ 825,
373
+ 415
374
+ ],
375
+ "page_idx": 3
376
+ },
377
+ {
378
+ "type": "text",
379
+ "text": "Inference When generating text with $M$ after finetuning with our approach, we perform regular decoding until $M$ produces the $\\ \" \\ \"$ token, indicating that it next expects the response for an API call. At this point, we interrupt the decoding process, call the appropriate API to get a response, and continue the decoding process after inserting both the response and the ${ < } / \\tt { A P I > }$ token. ",
380
+ "bbox": [
381
+ 174,
382
+ 429,
383
+ 825,
384
+ 484
385
+ ],
386
+ "page_idx": 3
387
+ },
388
+ {
389
+ "type": "text",
390
+ "text": "3 Tools ",
391
+ "text_level": 1,
392
+ "bbox": [
393
+ 174,
394
+ 503,
395
+ 250,
396
+ 520
397
+ ],
398
+ "page_idx": 3
399
+ },
400
+ {
401
+ "type": "text",
402
+ "text": "We explore various tools to address different shortcomings of LMs. The only constraints we impose are that (i) their inputs and outputs can be represented as texts, and (ii) we can obtain a few demonstrations of their intended use. Concretely, we explore a question answering system, a Wikipedia search engine, a calculator, a calendar, and a machine translation system. Examples for the APIs associated with each of these tools are shown in Table 1. We briefly discuss all tools below. ",
403
+ "bbox": [
404
+ 174,
405
+ 534,
406
+ 825,
407
+ 603
408
+ ],
409
+ "page_idx": 3
410
+ },
411
+ {
412
+ "type": "text",
413
+ "text": "Question Answering Our first tool is a question answering system based on another LM that can answer simple factoid questions. Specifically, we use Atlas (Izacard et al., 2022), a retrievalaugmented LM finetuned on Natural Questions (Kwiatkowski et al., 2019). ",
414
+ "bbox": [
415
+ 176,
416
+ 617,
417
+ 823,
418
+ 659
419
+ ],
420
+ "page_idx": 3
421
+ },
422
+ {
423
+ "type": "text",
424
+ "text": "Calculator As a second tool, we use a calculator that can perform simple numeric calculations; we only support the four basic arithmetic operations. Results are always rounded to two decimal places. ",
425
+ "bbox": [
426
+ 176,
427
+ 674,
428
+ 823,
429
+ 702
430
+ ],
431
+ "page_idx": 3
432
+ },
433
+ {
434
+ "type": "text",
435
+ "text": "Wikipedia Search Our third tool is a search engine that, given a search term, returns short text snippets from Wikipedia. Compared to our question answering tool, this search enables a model to get more comprehensive information on a subject, but requires it to extract the relevant parts by itself. As our search engine, we use a BM25 retriever (Robertson et al., 1995; Baeza-Yates et al., 1999) that indexes the Wikipedia dump from KILT (Petroni et al., 2021). ",
436
+ "bbox": [
437
+ 174,
438
+ 715,
439
+ 825,
440
+ 785
441
+ ],
442
+ "page_idx": 3
443
+ },
444
+ {
445
+ "type": "text",
446
+ "text": "Machine Translation System Our fourth tool is a machine translation system based on a LM that can translate a phrase from any language into English. More concretely, we use the 600M parameter NLLB (Costa-jussà et al., 2022) as our multilingual machine translation model that works for 200 languages (including low-resource ones). The source language is automatically detected using the fastText classifier (Joulin et al., 2016), while the target language is always set to English. ",
447
+ "bbox": [
448
+ 174,
449
+ 799,
450
+ 825,
451
+ 869
452
+ ],
453
+ "page_idx": 3
454
+ },
455
+ {
456
+ "type": "text",
457
+ "text": "Calendar Our final tool is a calendar API that, when queried, returns the current date without taking any input. This provides temporal context for predictions that require some awareness of time. ",
458
+ "bbox": [
459
+ 173,
460
+ 883,
461
+ 823,
462
+ 911
463
+ ],
464
+ "page_idx": 3
465
+ },
466
+ {
467
+ "type": "table",
468
+ "img_path": "images/6ff4b55b4a07eedc3b46aca4392f355c7700e2c3c0ae697c3d7df3dcacc10adc.jpg",
469
+ "table_caption": [
470
+ "Table 2: Number of examples with API calls in $\\mathcal { C } ^ { * }$ for different values of our filtering threshold $\\tau _ { f }$ "
471
+ ],
472
+ "table_footnote": [],
473
+ "table_body": "<table><tr><td></td><td colspan=\"3\">Number of Examples</td></tr><tr><td>API</td><td>Tf = 0.5</td><td>Tf = 1.0</td><td>Tf = 2.0</td></tr><tr><td>Question Answering</td><td>51,987</td><td>18,526</td><td>5,135</td></tr><tr><td>Wikipedia Search</td><td>207,241</td><td>60,974</td><td>13,944</td></tr><tr><td>Calculator</td><td>3,680</td><td>994</td><td>138</td></tr><tr><td>Calendar</td><td>61,811</td><td>20,587</td><td>3,007</td></tr><tr><td>Machine Translation</td><td>3,156</td><td>1,034</td><td>229</td></tr></table>",
474
+ "bbox": [
475
+ 285,
476
+ 111,
477
+ 712,
478
+ 217
479
+ ],
480
+ "page_idx": 4
481
+ },
482
+ {
483
+ "type": "text",
484
+ "text": "4 Experiments ",
485
+ "text_level": 1,
486
+ "bbox": [
487
+ 174,
488
+ 238,
489
+ 312,
490
+ 256
491
+ ],
492
+ "page_idx": 4
493
+ },
494
+ {
495
+ "type": "text",
496
+ "text": "We investigate whether our approach enables a LM to use tools without any further supervision and to decide for itself when and how to call which tool. To test this, we select a variety of downstream tasks where we assume at least one of the considered tools to be useful, and evaluate performance in zero-shot settings (Section 4.2). Beyond that, we also ensure that our approach does not hurt the model’s core LM abilities; we verify this by looking at perplexity on two language modeling datasets (Section 4.3). Finally, we investigate how tool use is affected by model size (Section 4.4). ",
497
+ "bbox": [
498
+ 173,
499
+ 268,
500
+ 825,
501
+ 353
502
+ ],
503
+ "page_idx": 4
504
+ },
505
+ {
506
+ "type": "text",
507
+ "text": "4.1 Experimental Setup ",
508
+ "text_level": 1,
509
+ "bbox": [
510
+ 174,
511
+ 369,
512
+ 352,
513
+ 385
514
+ ],
515
+ "page_idx": 4
516
+ },
517
+ {
518
+ "type": "text",
519
+ "text": "We use a subset of CCNet (Wenzek et al., 2020) as our dataset $\\mathcal { C }$ and GPT-J (Wang and Komatsuzaki, 2021) as our language model $M$ . To reduce the computational cost of annotating $\\mathcal { C }$ with API calls, we define heuristics for some APIs to get a subset of $\\mathcal { C }$ for which API calls are more likely to be helpful than for an average text. For example, we only consider texts for the calculator tool if they contain at least three numbers. Details of the heuristics used are given in Appendix A. For obtaining $\\mathcal { C } ^ { * }$ from $\\mathcal { C }$ , we perform all steps described in Section 2 and additionally filter out all examples for which all API calls were eliminated in the filtering step.3 For the weighting function, we use ",
520
+ "bbox": [
521
+ 173,
522
+ 393,
523
+ 826,
524
+ 492
525
+ ],
526
+ "page_idx": 4
527
+ },
528
+ {
529
+ "type": "equation",
530
+ "img_path": "images/693c7b513b012950d4b380ba5c92ef3e8dbdb80d0fcf63a938802cc828f5b1e0.jpg",
531
+ "text": "$$\nw _ { t } = \\frac { \\tilde { w } _ { t } } { \\sum _ { s \\in \\mathbb { N } } \\tilde { w } _ { s } } \\mathrm { ~ w i t h ~ } \\tilde { w } _ { t } = \\operatorname* { m a x } ( 0 , 1 - 0 . 2 \\cdot t )\n$$",
532
+ "text_format": "latex",
533
+ "bbox": [
534
+ 343,
535
+ 497,
536
+ 653,
537
+ 531
538
+ ],
539
+ "page_idx": 4
540
+ },
541
+ {
542
+ "type": "text",
543
+ "text": "to make sure that API calls happen close to where the information provided by the API is actually helpful for the model. The thresholds $\\tau _ { s }$ and $\\tau _ { f }$ are chosen individually for each tool to ensure a sufficient number of examples; see Appendix A for details. Table 2 shows relevant statistics of our final dataset augmented with API calls. We finetune $M$ on $\\mathcal { C } ^ { * }$ using a batch size of 128 and a learning rate of $1 \\cdot 1 0 ^ { - 5 }$ with linear warmup for the first $10 \\%$ of training. Finetuning details are given in Appendix B. In our experiments, we mainly compare GPT-J and the following models: ",
544
+ "bbox": [
545
+ 174,
546
+ 536,
547
+ 825,
548
+ 621
549
+ ],
550
+ "page_idx": 4
551
+ },
552
+ {
553
+ "type": "text",
554
+ "text": "• GPT- $\\mathbf { J } + \\mathbf { C } \\mathbf { C }$ : GPT-J finetuned on $\\mathcal { C }$ , our subset of CCNet without any API calls. • Toolformer: GPT-J finetuned on $\\mathcal { C } ^ { * }$ , our subset of CCNet augmented with API calls. • Toolformer (disabled): The same model as Toolformer, but API calls are disabled during decoding. This is achieved by manually setting the probability of the ${ \\tt { < A P I > } }$ token to 0. ",
555
+ "bbox": [
556
+ 212,
557
+ 631,
558
+ 826,
559
+ 698
560
+ ],
561
+ "page_idx": 4
562
+ },
563
+ {
564
+ "type": "text",
565
+ "text": "We additionally compare to OPT (66B) (Zhang et al., 2022) and the original davinci variant of GPT-3 (175B) (Brown et al., 2020), two models that are about 10 and 25 times larger than GPT-J. ",
566
+ "bbox": [
567
+ 174,
568
+ 709,
569
+ 825,
570
+ 738
571
+ ],
572
+ "page_idx": 4
573
+ },
574
+ {
575
+ "type": "text",
576
+ "text": "4.2 Downstream Tasks ",
577
+ "text_level": 1,
578
+ "bbox": [
579
+ 174,
580
+ 753,
581
+ 344,
582
+ 768
583
+ ],
584
+ "page_idx": 4
585
+ },
586
+ {
587
+ "type": "text",
588
+ "text": "We evaluate on various downstream tasks considering a prompted zero-shot setup: Models are instructed to solve each task in natural language (see Appendix C), but we provide no examples. This is in contrast to prior work on tool use (e.g., Gao et al., 2022; Parisi et al., 2022), where models are provided with dataset-specific examples of how a tool can be used to solve a concrete task. We choose this more challenging setup as we are interested in seeing whether Toolformer works in precisely those cases where a user does not specify in advance which tools should be used in which way. ",
589
+ "bbox": [
590
+ 174,
591
+ 779,
592
+ 825,
593
+ 863
594
+ ],
595
+ "page_idx": 4
596
+ },
597
+ {
598
+ "type": "table",
599
+ "img_path": "images/1fef6447578dea8a84f5206305726e82e0779b81f1fad138b9cbcd028bedaee7.jpg",
600
+ "table_caption": [
601
+ "Table 3: Results on subsets of LAMA and various benchmarks requiring mathematical reasoning. For LAMA, Toolformer uses the question answering tool for most examples, clearly outperforming all baselines of the same size and achieving results competitive with GPT-3. For the math benchmarks, Toolformer makes extensive use of the calculator tool, clearly outperforming OPT and GPT-3. Best results with a GPT-J based model are shown in bold, best results overall are underlined. "
602
+ ],
603
+ "table_footnote": [],
604
+ "table_body": "<table><tr><td></td><td colspan=\"3\">LAMA</td><td colspan=\"3\">Math Benchmarks</td></tr><tr><td>Model</td><td>SQuAD</td><td>Google-RE</td><td>T-REx</td><td>ASDiv</td><td>SVAMP</td><td>MAWPS</td></tr><tr><td>GPT-J</td><td>17.8</td><td>4.9</td><td>31.9</td><td>7.5</td><td>5.2</td><td>9.9</td></tr><tr><td>GPT-J + CC</td><td>19.2</td><td>5.6</td><td>33.2</td><td>9.6</td><td>5.0</td><td>9.3</td></tr><tr><td>Toolformer (disabled)</td><td>22.1</td><td>6.3</td><td>34.9</td><td>14.8</td><td>6.3</td><td>15.0</td></tr><tr><td>Toolformer</td><td>33.8</td><td>11.5</td><td>53.5</td><td>40.4</td><td>29.4</td><td>44.0</td></tr><tr><td>OPT (66B)</td><td>21.6</td><td>2.9</td><td>30.1</td><td>6.0</td><td>4.9</td><td>7.9</td></tr><tr><td>GPT-3 (175B)</td><td>26.8</td><td>7.0</td><td>39.8</td><td>14.0</td><td>10.0</td><td>19.8</td></tr></table>",
605
+ "bbox": [
606
+ 173,
607
+ 165,
608
+ 825,
609
+ 296
610
+ ],
611
+ "page_idx": 5
612
+ },
613
+ {
614
+ "type": "text",
615
+ "text": "We use greedy decoding, but with one modification for Toolformer: We let the model start an API call whenever ${ \\tt { < A P I > } }$ is one of the $k$ most likely tokens. For $k = 1$ , this corresponds to regular greedy decoding; we instead use $k = 1 0$ to increase the disposition of our model to make use of APIs. At the same time, we allow at most one API call per input to make sure the model does not get stuck in a loop where it constantly calls APIs. The effect of these modifications is explored in Appendix E. ",
616
+ "bbox": [
617
+ 173,
618
+ 324,
619
+ 825,
620
+ 392
621
+ ],
622
+ "page_idx": 5
623
+ },
624
+ {
625
+ "type": "text",
626
+ "text": "LAMA We evaluate our models on the SQuAD, Google-RE and T-REx subsets of the LAMA benchmark (Petroni et al., 2019). For each of these subsets, the task is to complete a short statement with a missing fact (e.g., a date or a place). As LAMA was originally designed to evaluate masked LMs (e.g., Devlin et al., 2019), we filter out examples where the mask token is not the final token, so that all examples can be processed in a left-to-right fashion. To account for different tokenizations and added complexity from not informing the model that a single word is required, for all models we use a slightly more lenient evaluation criterion than exact match and simply check whether the correct word is within the first five words predicted by the model. As LAMA is based on statements obtained directly from Wikipedia, we prevent Toolformer from using the Wikipedia Search API to avoid giving it an unfair advantage. As shown in Table 3 (left), all GPT-J models without tool use achieve similar performance. Crucially, Toolformer clearly outperforms these baseline models, improving upon the best baseline by 11.7, 5.2 and 18.6 points, respectively. It also clearly outperforms OPT (66B) and GPT-3 (175B), despite both models being much larger. This is achieved because the model independently decides to ask the question answering tool for the required information in almost all cases $( 9 8 . 1 \\% )$ ; for only very few examples, it uses a different tool $( 0 . 7 \\% )$ or no tool at all $( 1 . 2 \\% )$ . ",
627
+ "bbox": [
628
+ 173,
629
+ 410,
630
+ 825,
631
+ 617
632
+ ],
633
+ "page_idx": 5
634
+ },
635
+ {
636
+ "type": "text",
637
+ "text": "Math Benchmarks We test mathematical abilities on ASDiv (Miao et al., 2020), SVAMP (Patel et al., 2021) and the MAWPS benchmark (Koncel-Kedziorski et al., 2016). We again account for the fact that we test all models in a zero-shot setup by using a more lenient evaluation criterion: As the required output is always a number, we simply check for the first number predicted by the model.4 Results are shown in Table 3 (right). While GPT-J and GPT- $\\mathbf { J } + \\mathbf { C } \\mathbf { C }$ perform about the same, Toolformer achieves stronger results even without API calls. We surmise that this is because the model is finetuned on many examples of API calls and their results, improving its own mathematical capabilities. Nonetheless, allowing the model to make API calls more than doubles performance for all tasks, and also clearly outperforms the much larger OPT and GPT-3. This is because across all benchmarks, for $9 7 . 9 \\%$ of all examples the model decides to ask the calculator tool for help. ",
638
+ "bbox": [
639
+ 173,
640
+ 633,
641
+ 825,
642
+ 772
643
+ ],
644
+ "page_idx": 5
645
+ },
646
+ {
647
+ "type": "text",
648
+ "text": "Question Answering We look at Web Questions (Berant et al., 2013), Natural Questions (Kwiatkowski et al., 2019) and TriviaQA (Joshi et al., 2017). For evaluation, we check whether the first 20 words predicted by a model contain the correct answer instead of requiring an exact match. For Toolformer, we disable the question answering tool as this would make solving the tasks trivial. Results are shown in Table 4 (left). Once again, Toolformer clearly outperforms all other models based on GPT-J, relying on the Wikipedia search API $( 9 9 . 3 \\% )$ to find relevant information. However, ",
649
+ "bbox": [
650
+ 173,
651
+ 787,
652
+ 825,
653
+ 872
654
+ ],
655
+ "page_idx": 5
656
+ },
657
+ {
658
+ "type": "table",
659
+ "img_path": "images/88955ebdedb1c7b1fb16844885f092bc7abdad8acfc0aff3dec93eecff42ad5b.jpg",
660
+ "table_caption": [
661
+ "Table 4: Results for various question answering datasets and temporal datasets. Using the Wikipedia search tool for most examples, Toolformer clearly outperforms baselines of the same size, but falls short of GPT-3 (175B) for question answering tasks. For temporal datasets, Toolformer outperforms all baselines, but does not make use of the calendar tool for TEMPLAMA. "
662
+ ],
663
+ "table_footnote": [],
664
+ "table_body": "<table><tr><td></td><td colspan=\"3\">LAMA</td><td colspan=\"2\">Temporal Datasets</td></tr><tr><td>Model</td><td>WebQS</td><td>NQ</td><td>TriviaQA</td><td>TEMPLAMA</td><td>DATESET</td></tr><tr><td>GPT-J</td><td>18.5</td><td>12.8</td><td>43.9</td><td>13.7</td><td>3.9</td></tr><tr><td>GPT-J + CC</td><td>18.4</td><td>12.2</td><td>45.6</td><td>12.9</td><td>2.9</td></tr><tr><td>Toolformer (disabled)</td><td>18.9</td><td>12.6</td><td>46.7</td><td>12.7</td><td>5.9</td></tr><tr><td>Toolformer</td><td>26.3</td><td>17.7</td><td>48.8</td><td>16.3</td><td>27.3</td></tr><tr><td>OPT (66B)</td><td>18.6</td><td>11.4</td><td>45.7</td><td>14.5</td><td>1.3</td></tr><tr><td>GPT-3 (175B)</td><td>29.0</td><td>22.6</td><td>65.9</td><td>15.5</td><td>0.8</td></tr></table>",
665
+ "bbox": [
666
+ 204,
667
+ 152,
668
+ 794,
669
+ 284
670
+ ],
671
+ "page_idx": 6
672
+ },
673
+ {
674
+ "type": "table",
675
+ "img_path": "images/8e2f305ae0827226a88158db7e15e5d91a20aa35a135b4771feca48d72e546b5.jpg",
676
+ "table_caption": [
677
+ "Table 5: Results on MLQA for Spanish (Es), German (De), Hindi $\\mathrm { ( H i ) }$ , Vietnamese (Vi), Chinese (Zh) and Arabic (Ar). While using the MT tool to translate questions is helpful across all languages, further pretraining on CCNet deteriorates performance; thus, Toolformer does not consistently outperform GPT-J. The final rows correspond to models that are given contexts and questions in English. "
678
+ ],
679
+ "table_footnote": [],
680
+ "table_body": "<table><tr><td>Model</td><td>Es</td><td>De</td><td>Hi</td><td>Vi</td><td>Zh</td><td>Ar</td></tr><tr><td>GPT-J</td><td>15.2</td><td>16.5</td><td>1.3</td><td>8.2</td><td>18.2</td><td>8.2</td></tr><tr><td>GPT-J + CC</td><td>15.7</td><td>14.9</td><td>0.5</td><td>8.3</td><td>13.7</td><td>4.6</td></tr><tr><td>Toolformer (disabled)</td><td>19.8</td><td>11.9</td><td>1.2</td><td>10.1</td><td>15.0</td><td>3.1</td></tr><tr><td>Toolformer</td><td>20.6</td><td>13.5</td><td>1.4</td><td>10.6</td><td>16.8</td><td>3.7</td></tr><tr><td>OPT (66B)</td><td>0.3</td><td>0.1</td><td>1.1</td><td>0.2</td><td>0.7</td><td>0.1</td></tr><tr><td>GPT-3 (175B)</td><td>3.4</td><td>1.1</td><td>0.1</td><td>1.7</td><td>17.7</td><td>0.1</td></tr><tr><td>GPT-J (All En)</td><td>24.3</td><td>27.0</td><td>23.9</td><td>23.3</td><td>23.1</td><td>23.6</td></tr><tr><td>GPT-3 (All En)</td><td>24.7</td><td>27.2</td><td>26.1</td><td>24.9</td><td>23.6</td><td>24.0</td></tr></table>",
681
+ "bbox": [
682
+ 269,
683
+ 361,
684
+ 728,
685
+ 505
686
+ ],
687
+ "page_idx": 6
688
+ },
689
+ {
690
+ "type": "text",
691
+ "text": "Toolformer still lags behind the much larger GPT-3 (175B) model. This is likely due to both the simplicity of our search engine (in many cases, it returns results that are clearly not a good match for a given query) and the inability of Toolformer to interact with it, e.g., by reformulating its query if results are not helpful or by browsing through multiple of the top results. ",
692
+ "bbox": [
693
+ 174,
694
+ 531,
695
+ 825,
696
+ 587
697
+ ],
698
+ "page_idx": 6
699
+ },
700
+ {
701
+ "type": "text",
702
+ "text": "Multilingual QA We evaluate all models on MLQA (Lewis et al., 2019), a multilingual QA benchmark. Context for each question is provided in English, while the question can be in Arabic, German, Spanish, Hindi, Vietnamese, or Simplified Chinese. Our evaluation metric is the percentage of times the model’s generation, capped at 10 words, contains the correct answer. Results are shown in Table 5. API calls improve Toolformer’s performance for all languages, suggesting that it has learned to make use of the machine translation tool. Depending on the language, this tool is used for $6 3 . 8 \\%$ to $9 4 . 9 \\%$ of all examples; the only exception is Hindi, for which it is used in only $7 . 3 \\%$ of cases. However, Toolformer does not consistently outperform GPT-J as finetuning on CCNet deteriorates performance for some languages. OPT and GPT-3 perform surprisingly weak across all languages, mostly because they fail to provide an answer in English despite being instructed to do so. A potential reason for GPT-J not suffering from this problem is that it was trained on more multilingual data than both OPT and GPT-3, including EuroParl (Koehn, 2005). As an upper bound, we also evaluate GPT-J and GPT-3 on a variant of MLQA where both the context and the question are provided in English. In this setup, GPT-3 performs better than all other models, supporting our hypothesis that its subpar performance on MLQA is due to the task’s multilingual aspect. ",
703
+ "bbox": [
704
+ 173,
705
+ 604,
706
+ 825,
707
+ 811
708
+ ],
709
+ "page_idx": 6
710
+ },
711
+ {
712
+ "type": "text",
713
+ "text": "Temporal Datasets We evaluate all models on TEMPLAMA (Dhingra et al., 2022) and a new dataset that we call DATESET. TEMPLAMA contains cloze queries about facts that change with time. DATESET, described in Appendix D, is generated through a series of templates, but populated using a combination of random dates/durations (e.g., “What day of the week was it 30 days ago?”). For both tasks, we use the same evaluation as for the original LAMA dataset. Results shown in Table 4 (right) illustrate that Toolformer outperforms all baselines for both TEMPLAMA and DATESET. However, closer inspection shows that improvements on TEMPLAMA can not be attributed to the calendar tool, which is only used for $0 . 2 \\%$ of all examples, but mostly to the Wikipedia search and question answering tools.This makes sense given that entities in TEMPLAMA are often so specific and rare that even knowing the date alone would be of little help. The best course of action for this dataset – first querying the calendar API to get the current date, and then querying the QA system with this date – is not only prohibited by our restriction of using at most one API call, but also hard to learn for Toolformer given that all API calls in its training data are sampled independently. For DATESET, on the other hand, the considerable improvement of Toolformer compared to other models can be fully accredited to the calendar tool, which it makes use of for $5 4 . 8 \\%$ of all examples. ",
714
+ "bbox": [
715
+ 174,
716
+ 827,
717
+ 825,
718
+ 911
719
+ ],
720
+ "page_idx": 6
721
+ },
722
+ {
723
+ "type": "image",
724
+ "img_path": "images/071c4fdbad1e77e8404f0631b4a51c5e303496f5cf70832da7e556306980604d.jpg",
725
+ "image_caption": [
726
+ "Figure 4: Average performance on LAMA, our math benchmarks and our QA benchmarks for GPT-2 models of different sizes and GPT-J finetuned with our approach, both with and without API calls. While API calls are not helpful to the smallest models, larger models learn how to make good use of them. Even for bigger models, the gap between predictions with and without API calls remains high. "
727
+ ],
728
+ "image_footnote": [],
729
+ "bbox": [
730
+ 173,
731
+ 90,
732
+ 808,
733
+ 281
734
+ ],
735
+ "page_idx": 7
736
+ },
737
+ {
738
+ "type": "text",
739
+ "text": "",
740
+ "bbox": [
741
+ 174,
742
+ 376,
743
+ 825,
744
+ 502
745
+ ],
746
+ "page_idx": 7
747
+ },
748
+ {
749
+ "type": "text",
750
+ "text": "4.3 Language Modeling ",
751
+ "text_level": 1,
752
+ "bbox": [
753
+ 174,
754
+ 518,
755
+ 352,
756
+ 532
757
+ ],
758
+ "page_idx": 7
759
+ },
760
+ {
761
+ "type": "text",
762
+ "text": "We want to ensure that language modeling performance of Toolformer does not degrade through finetuning with API calls. To this end, we evaluate our models on two language modeling datasets: WikiText (Merity et al., 2017) and a subset of 10,000 randomly selected documents from CCNet (Wenzek et al., 2020) that were not used during training. Finetuning on CCNet leads to slightly improved performance on the CCNet evaluation subset (perplexity improves from 10.6 to 10.5), but slightly deteriorates performance on WikiText (9.9 to 10.3), presumably because the original pretraining data for GPT-J is more similar to WikiText than our subset of CCNet. Most importantly, however, training on $\\mathcal { C } ^ { * }$ does not lead to an increase in perplexity compared to training on $\\mathcal { C }$ when API calls are disabled at inference time, giving perplexities of 10.5 and 10.3, respectively.5 ",
763
+ "bbox": [
764
+ 173,
765
+ 544,
766
+ 826,
767
+ 669
768
+ ],
769
+ "page_idx": 7
770
+ },
771
+ {
772
+ "type": "text",
773
+ "text": "4.4 Scaling Laws ",
774
+ "text_level": 1,
775
+ "bbox": [
776
+ 174,
777
+ 684,
778
+ 305,
779
+ 699
780
+ ],
781
+ "page_idx": 7
782
+ },
783
+ {
784
+ "type": "text",
785
+ "text": "We investigate how the ability to ask external tools for help affects performance as we vary the size of our LM. To this end, we apply our approach not just to GPT-J, but also to four smaller models from the GPT-2 family (Radford et al., 2019), with 124M, 355M, 775M and 1.6B parameters, respectively. We do so using only a subset of three tools: the question answering system, the calculator, and the Wikipedia search engine. Apart from this, we follow the experimental setup described in Section 4.1. Figure 4 shows that the ability to leverage the provided tools only emerges at around 775M parameters: smaller models achieve similar performance both with and without tools. An exception to this is the Wikipedia search engine used mostly for QA benchmarks; we hypothesize that this is because the API is comparably easy to use. While models become better at solving tasks without API calls as they grow in size, their ability to make good use of the provided API improves at the same time. Thus, there remains a large gap between predictions with and without API calls even for our biggest model. ",
786
+ "bbox": [
787
+ 174,
788
+ 710,
789
+ 825,
790
+ 862
791
+ ],
792
+ "page_idx": 7
793
+ },
794
+ {
795
+ "type": "text",
796
+ "text": "In Appendix G, we extend these investigations in scale to the LLaMA v1 7B model (Touvron et al., 2023) to see how tool-use scales with model capability instead of size. We find that the utility of weaker tools such as the WikiSearch tool vanish for these stronger base-models, and we demonstrate the value of generating and scoring with a strong model, compared to simply finetuning. ",
797
+ "bbox": [
798
+ 174,
799
+ 92,
800
+ 825,
801
+ 147
802
+ ],
803
+ "page_idx": 8
804
+ },
805
+ {
806
+ "type": "text",
807
+ "text": "5 Related Work ",
808
+ "text_level": 1,
809
+ "bbox": [
810
+ 174,
811
+ 170,
812
+ 321,
813
+ 188
814
+ ],
815
+ "page_idx": 8
816
+ },
817
+ {
818
+ "type": "text",
819
+ "text": "Language Model Pretraining There are various approaches that augment LMs with some form of additional textual information during pretraining, including various forms of metadata (Keskar et al., 2019), HTML tags (Aghajanyan et al., 2021), Wikipedia markup (Schick et al., 2022), or related texts obtained from an information retrieval system (Guu et al., 2020; Borgeaud et al., 2021; Izacard et al., 2022). For all of these approaches, additional information is always provided, regardless of whether it is helpful or not. In contrast, Toolformer learns for itself to explicitly asks for the right information. ",
820
+ "bbox": [
821
+ 174,
822
+ 205,
823
+ 826,
824
+ 289
825
+ ],
826
+ "page_idx": 8
827
+ },
828
+ {
829
+ "type": "text",
830
+ "text": "Tool Use Several approaches aim to equip LMs with the ability to use external tools such as search engines (Komeili et al., 2022; Thoppilan et al., 2022; Lazaridou et al., 2022; Shuster et al., 2022; Yao et al., 2022), web browsers (Nakano et al., 2021), calculators (Cobbe et al., 2021; Thoppilan et al., 2022), translation systems (Thoppilan et al., 2022) and Python interpreters (Gao et al., 2022). The way these models learn to use tools can roughly be divided into two approaches: Either they rely on large amounts of human supervision (Komeili et al., 2022; Nakano et al., 2021; Thoppilan et al., 2022) or they work by prompting the language model in a few-shot setup tailored towards a specific task where it is known a priori which tools needs to be used (Gao et al., 2022; Lazaridou et al., 2022; Yao et al., 2022). In contrast, the self-supervised nature of Toolformer enables it to learn how and when to use tools without requiring a specific prompt that shows task-specific examples of how a tool could be used. Perhaps most closely related to our work is TALM (Parisi et al., 2022), an approach that uses a similar self-supervised objective for teaching a model to use a calculator and a search engine, but explores this only in settings where a model is finetuned for downstream tasks. ",
831
+ "bbox": [
832
+ 174,
833
+ 308,
834
+ 825,
835
+ 488
836
+ ],
837
+ "page_idx": 8
838
+ },
839
+ {
840
+ "type": "text",
841
+ "text": "Bootstrapping The idea of using self-training and bootstrapping techniques to improve models has been investigated in various contexts, ranging from word sense disambiguation (Yarowsky, 1995), relation extraction (Brin, 1999; Agichtein and Gravano, 2000), parsing (McClosky et al., 2006), sequence generation (He et al., 2020), few-shot text classification (Schick and Schütze, 2021a) and retrieval (Izacard and Grave, 2021) to reasoning (Zelikman et al., 2022). In a similar spirit, Toolformer is trained on its own predictions after applying a perplexity-based filtering step. ",
842
+ "bbox": [
843
+ 174,
844
+ 507,
845
+ 825,
846
+ 592
847
+ ],
848
+ "page_idx": 8
849
+ },
850
+ {
851
+ "type": "text",
852
+ "text": "6 Limitations ",
853
+ "text_level": 1,
854
+ "bbox": [
855
+ 174,
856
+ 614,
857
+ 302,
858
+ 631
859
+ ],
860
+ "page_idx": 8
861
+ },
862
+ {
863
+ "type": "text",
864
+ "text": "While our approach enables LMs to learn how to use a variety of tools in a self-supervised way, there are some clear limitations to what can be achieved with our method in its current form. One such limitation is the inability of Toolformer to use tools in a chain (i.e., using the output of one tool as an input for another tool). This is due to the fact that API calls for each tool are generated independently; as a consequence, there are no examples of chained tool use in the finetuning dataset, since this would necessitate multiple API calls per example. Our current approach also does not allow the LM to use a tool in an interactive way – especially for tools such as search engines, that could potentially return hundreds of different results, enabling a LM to browse through these results or to refine its search query in a similar spirit to Nakano et al. (2021) can be crucial for certain applications. Beyond this, we found models trained with Toolformer to often be sensitive to the exact wording of their input when deciding whether or not to call an API; this is perhaps unsurprising given that LMs are known to be very sensitive to the prompt they are provided with in both zero- and few-shot settings (Jiang et al., 2020; Schick and Schütze, 2021a). Depending on the tool, our method is also very sample-inefficient; for example, processing more than a million documents results in only a few thousand examples of useful calls to the calculator API. A potential solution to this problem might be to iteratively apply our approach, similar to how this is done in related bootstrapping approaches (Schick and Schütze, 2021a; Izacard and Grave, 2021; Parisi et al., 2022). Finally, when deciding whether or not to make an API call, Toolformer currently does not take into account the tool-dependent, computational cost incurred from making an API call. ",
865
+ "bbox": [
866
+ 174,
867
+ 648,
868
+ 825,
869
+ 911
870
+ ],
871
+ "page_idx": 8
872
+ },
873
+ {
874
+ "type": "text",
875
+ "text": "7 Conclusion ",
876
+ "text_level": 1,
877
+ "bbox": [
878
+ 174,
879
+ 89,
880
+ 299,
881
+ 106
882
+ ],
883
+ "page_idx": 9
884
+ },
885
+ {
886
+ "type": "text",
887
+ "text": "We have introduced Toolformer, a LM that learns in a self-supervised way how to use different tools such as search engines, calculators, and translation systems via simple API calls. This is done by finetuning on sampled API calls that are filtered based on whether they reduce perplexity on future tokens. Toolformer considerably improves zero-shot performance of a 6.7B parameter GPT-J model, enabling it to even outperform a much larger GPT-3 model on a range of different downstream tasks. ",
888
+ "bbox": [
889
+ 174,
890
+ 121,
891
+ 825,
892
+ 191
893
+ ],
894
+ "page_idx": 9
895
+ },
896
+ {
897
+ "type": "text",
898
+ "text": "References ",
899
+ "text_level": 1,
900
+ "bbox": [
901
+ 174,
902
+ 213,
903
+ 266,
904
+ 229
905
+ ],
906
+ "page_idx": 9
907
+ },
908
+ {
909
+ "type": "text",
910
+ "text": "Armen Aghajanyan, Dmytro Okhonko, Mike Lewis, Mandar Joshi, Hu Xu, Gargi Ghosh, and Luke Zettlemoyer. 2021. Htlm: Hyper-text pre-training and prompting of language models. ",
911
+ "bbox": [
912
+ 176,
913
+ 237,
914
+ 825,
915
+ 266
916
+ ],
917
+ "page_idx": 9
918
+ },
919
+ {
920
+ "type": "text",
921
+ "text": "Eugene Agichtein and Luis Gravano. 2000. Snowball: Extracting relations from large plain-text collections. In Proceedings of the Fifth ACM Conference on Digital Libraries, DL ’00, page 85–94, New York, NY, USA. Association for Computing Machinery. ",
922
+ "bbox": [
923
+ 176,
924
+ 279,
925
+ 825,
926
+ 321
927
+ ],
928
+ "page_idx": 9
929
+ },
930
+ {
931
+ "type": "text",
932
+ "text": "Ricardo Baeza-Yates, Berthier Ribeiro-Neto, et al. 1999. Modern information retrieval, volume 463. ACM press New York. ",
933
+ "bbox": [
934
+ 173,
935
+ 333,
936
+ 823,
937
+ 361
938
+ ],
939
+ "page_idx": 9
940
+ },
941
+ {
942
+ "type": "text",
943
+ "text": "Jonathan Berant, Andrew Chou, Roy Frostig, and Percy Liang. 2013. Semantic parsing on Freebase from question-answer pairs. In Proceedings of the 2013 Conference on Empirical Methods in Natural Language Processing, pages 1533–1544, Seattle, Washington, USA. Association for Computational Linguistics. ",
944
+ "bbox": [
945
+ 173,
946
+ 375,
947
+ 825,
948
+ 430
949
+ ],
950
+ "page_idx": 9
951
+ },
952
+ {
953
+ "type": "text",
954
+ "text": "Sebastian Borgeaud, Arthur Mensch, Jordan Hoffmann, Trevor Cai, Eliza Rutherford, Katie Millican, George van den Driessche, Jean-Baptiste Lespiau, Bogdan Damoc, Aidan Clark, Diego de Las Casas, Aurelia Guy, Jacob Menick, Roman Ring, Tom Hennigan, Saffron Huang, Loren Maggiore, Chris Jones, Albin Cassirer, Andy Brock, Michela Paganini, Geoffrey Irving, Oriol Vinyals, Simon Osindero, Karen Simonyan, Jack W. Rae, Erich Elsen, and Laurent Sifre. 2021. Improving language models by retrieving from trillions of tokens. ",
955
+ "bbox": [
956
+ 174,
957
+ 443,
958
+ 825,
959
+ 526
960
+ ],
961
+ "page_idx": 9
962
+ },
963
+ {
964
+ "type": "text",
965
+ "text": "Sergey Brin. 1999. Extracting patterns and relations from the world wide web. In The World Wide Web and Databases, pages 172–183, Berlin, Heidelberg. Springer Berlin Heidelberg. ",
966
+ "bbox": [
967
+ 173,
968
+ 540,
969
+ 823,
970
+ 568
971
+ ],
972
+ "page_idx": 9
973
+ },
974
+ {
975
+ "type": "text",
976
+ "text": "Tom Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah, Jared D Kaplan, Prafulla Dhariwal, Arvind Neelakantan, Pranav Shyam, Girish Sastry, Amanda Askell, Sandhini Agarwal, Ariel Herbert-Voss, Gretchen Krueger, Tom Henighan, Rewon Child, Aditya Ramesh, Daniel Ziegler, Jeffrey Wu, Clemens Winter, Chris Hesse, Mark Chen, Eric Sigler, Mateusz Litwin, Scott Gray, Benjamin Chess, Jack Clark, Christopher Berner, Sam McCandlish, Alec Radford, Ilya Sutskever, and Dario Amodei. 2020. Language models are few-shot learners. In Advances in Neural Information Processing Systems, volume 33, pages 1877–1901. Curran Associates, Inc. ",
977
+ "bbox": [
978
+ 176,
979
+ 580,
980
+ 825,
981
+ 678
982
+ ],
983
+ "page_idx": 9
984
+ },
985
+ {
986
+ "type": "text",
987
+ "text": "Aakanksha Chowdhery, Sharan Narang, Jacob Devlin, Maarten Bosma, Gaurav Mishra, Adam Roberts, Paul Barham, Hyung Won Chung, Charles Sutton, Sebastian Gehrmann, Parker Schuh, Kensen Shi, Sasha Tsvyashchenko, Joshua Maynez, Abhishek Rao, Parker Barnes, Yi Tay, Noam Shazeer, Vinodkumar Prabhakaran, Emily Reif, Nan Du, Ben Hutchinson, Reiner Pope, James Bradbury, Jacob Austin, Michael Isard, Guy Gur-Ari, Pengcheng Yin, Toju Duke, Anselm Levskaya, Sanjay Ghemawat, Sunipa Dev, Henryk Michalewski, Xavier Garcia, Vedant Misra, Kevin Robinson, Liam Fedus, Denny Zhou, Daphne Ippolito, David Luan, Hyeontaek Lim, Barret Zoph, Alexander Spiridonov, Ryan Sepassi, David Dohan, Shivani Agrawal, Mark Omernick, Andrew M. Dai, Thanumalayan Sankaranarayana Pillai, Marie Pellat, Aitor Lewkowycz, Erica Moreira, Rewon Child, Oleksandr Polozov, Katherine Lee, Zongwei Zhou, Xuezhi Wang, Brennan Saeta, Mark Diaz, Orhan Firat, Michele Catasta, Jason Wei, Kathy Meier-Hellstern, Douglas Eck, Jeff Dean, Slav Petrov, and Noah Fiedel. 2022. Palm: Scaling language modeling with pathways. ",
988
+ "bbox": [
989
+ 176,
990
+ 690,
991
+ 826,
992
+ 856
993
+ ],
994
+ "page_idx": 9
995
+ },
996
+ {
997
+ "type": "text",
998
+ "text": "Karl Cobbe, Vineet Kosaraju, Mohammad Bavarian, Mark Chen, Heewoo Jun, Lukasz Kaiser, Matthias Plappert, Jerry Tworek, Jacob Hilton, Reiichiro Nakano, et al. 2021. Training verifiers to solve math word problems. arXiv preprint arXiv:2110.14168. ",
999
+ "bbox": [
1000
+ 176,
1001
+ 869,
1002
+ 825,
1003
+ 911
1004
+ ],
1005
+ "page_idx": 9
1006
+ },
1007
+ {
1008
+ "type": "text",
1009
+ "text": "Marta R Costa-jussà, James Cross, Onur Çelebi, Maha Elbayad, Kenneth Heafield, Kevin Heffernan, Elahe Kalbassi, Janice Lam, Daniel Licht, Jean Maillard, et al. 2022. No language left behind: Scaling human-centered machine translation. arXiv preprint arXiv:2207.04672. ",
1010
+ "bbox": [
1011
+ 178,
1012
+ 90,
1013
+ 823,
1014
+ 133
1015
+ ],
1016
+ "page_idx": 10
1017
+ },
1018
+ {
1019
+ "type": "text",
1020
+ "text": "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, Volume 1 (Long and Short Papers), pages 4171–4186, Minneapolis, Minnesota. Association for Computational Linguistics. ",
1021
+ "bbox": [
1022
+ 173,
1023
+ 143,
1024
+ 825,
1025
+ 213
1026
+ ],
1027
+ "page_idx": 10
1028
+ },
1029
+ {
1030
+ "type": "text",
1031
+ "text": "Bhuwan Dhingra, Jeremy R. Cole, Julian Martin Eisenschlos, Daniel Gillick, Jacob Eisenstein, and William W. Cohen. 2022. Time-aware language models as temporal knowledge bases. Transactions of the Association for Computational Linguistics, 10:257–273. ",
1032
+ "bbox": [
1033
+ 173,
1034
+ 224,
1035
+ 826,
1036
+ 267
1037
+ ],
1038
+ "page_idx": 10
1039
+ },
1040
+ {
1041
+ "type": "text",
1042
+ "text": "Luyu Gao, Aman Madaan, Shuyan Zhou, Uri Alon, Pengfei Liu, Yiming Yang, Jamie Callan, and Graham Neubig. 2022. Pal: Program-aided language models. ",
1043
+ "bbox": [
1044
+ 171,
1045
+ 276,
1046
+ 825,
1047
+ 306
1048
+ ],
1049
+ "page_idx": 10
1050
+ },
1051
+ {
1052
+ "type": "text",
1053
+ "text": "Kelvin Guu, Kenton Lee, Zora Tung, Panupong Pasupat, and Ming-Wei Chang. 2020. Realm: Retrieval-augmented language model pre-training. ",
1054
+ "bbox": [
1055
+ 173,
1056
+ 315,
1057
+ 825,
1058
+ 345
1059
+ ],
1060
+ "page_idx": 10
1061
+ },
1062
+ {
1063
+ "type": "text",
1064
+ "text": "Junxian He, Jiatao Gu, Jiajun Shen, and Marc’Aurelio Ranzato. 2020. Revisiting self-training for neural sequence generation. In International Conference on Learning Representations. ",
1065
+ "bbox": [
1066
+ 171,
1067
+ 354,
1068
+ 825,
1069
+ 385
1070
+ ],
1071
+ "page_idx": 10
1072
+ },
1073
+ {
1074
+ "type": "text",
1075
+ "text": "Or Honovich, Thomas Scialom, Omer Levy, and Timo Schick. 2022. Unnatural instructions: Tuning language models with (almost) no human labor. ",
1076
+ "bbox": [
1077
+ 174,
1078
+ 393,
1079
+ 823,
1080
+ 422
1081
+ ],
1082
+ "page_idx": 10
1083
+ },
1084
+ {
1085
+ "type": "text",
1086
+ "text": "Gautier Izacard and Edouard Grave. 2021. Distilling knowledge from reader to retriever for question answering. In International Conference on Learning Representations. ",
1087
+ "bbox": [
1088
+ 174,
1089
+ 433,
1090
+ 821,
1091
+ 463
1092
+ ],
1093
+ "page_idx": 10
1094
+ },
1095
+ {
1096
+ "type": "text",
1097
+ "text": "Gautier Izacard, Patrick Lewis, Maria Lomeli, Lucas Hosseini, Fabio Petroni, Timo Schick, Jane Dwivedi-Yu, Armand Joulin, Sebastian Riedel, and Edouard Grave. 2022. Atlas: Few-shot learning with retrieval augmented language models. ",
1098
+ "bbox": [
1099
+ 173,
1100
+ 472,
1101
+ 825,
1102
+ 515
1103
+ ],
1104
+ "page_idx": 10
1105
+ },
1106
+ {
1107
+ "type": "text",
1108
+ "text": "Ziwei Ji, Nayeon Lee, Rita Frieske, Tiezheng Yu, Dan Su, Yan Xu, Etsuko Ishii, Yejin Bang, Andrea Madotto, and Pascale Fung. 2022. Survey of hallucination in natural language generation. ACM Computing Surveys. ",
1109
+ "bbox": [
1110
+ 174,
1111
+ 525,
1112
+ 823,
1113
+ 569
1114
+ ],
1115
+ "page_idx": 10
1116
+ },
1117
+ {
1118
+ "type": "text",
1119
+ "text": "Zhengbao Jiang, Frank F. Xu, Jun Araki, and Graham Neubig. 2020. How can we know what language models know? Transactions of the Association for Computational Linguistics, 8:423–438. ",
1120
+ "bbox": [
1121
+ 171,
1122
+ 578,
1123
+ 823,
1124
+ 608
1125
+ ],
1126
+ "page_idx": 10
1127
+ },
1128
+ {
1129
+ "type": "text",
1130
+ "text": "Mandar Joshi, Eunsol Choi, Daniel Weld, and Luke Zettlemoyer. 2017. TriviaQA: A large scale distantly supervised challenge dataset for reading comprehension. In Proceedings of the 55th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 1601–1611, Vancouver, Canada. Association for Computational Linguistics. ",
1131
+ "bbox": [
1132
+ 173,
1133
+ 617,
1134
+ 825,
1135
+ 674
1136
+ ],
1137
+ "page_idx": 10
1138
+ },
1139
+ {
1140
+ "type": "text",
1141
+ "text": "Armand Joulin, Edouard Grave, Piotr Bojanowski, Matthijs Douze, Hérve Jégou, and Tomas Mikolov. 2016. Fasttext. zip: Compressing text classification models. arXiv preprint arXiv:1612.03651. ",
1142
+ "bbox": [
1143
+ 173,
1144
+ 684,
1145
+ 821,
1146
+ 713
1147
+ ],
1148
+ "page_idx": 10
1149
+ },
1150
+ {
1151
+ "type": "text",
1152
+ "text": "Nitish Shirish Keskar, Bryan McCann, Lav R. Varshney, Caiming Xiong, and Richard Socher. 2019. Ctrl: A conditional transformer language model for controllable generation. ",
1153
+ "bbox": [
1154
+ 173,
1155
+ 723,
1156
+ 823,
1157
+ 753
1158
+ ],
1159
+ "page_idx": 10
1160
+ },
1161
+ {
1162
+ "type": "text",
1163
+ "text": "Philipp Koehn. 2005. Europarl: A parallel corpus for statistical machine translation. In Proceedings of machine translation summit x: papers, pages 79–86. ",
1164
+ "bbox": [
1165
+ 171,
1166
+ 762,
1167
+ 825,
1168
+ 792
1169
+ ],
1170
+ "page_idx": 10
1171
+ },
1172
+ {
1173
+ "type": "text",
1174
+ "text": "Mojtaba Komeili, Kurt Shuster, and Jason Weston. 2022. Internet-augmented dialogue generation. In Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 8460–8478, Dublin, Ireland. Association for Computational Linguistics. ",
1175
+ "bbox": [
1176
+ 174,
1177
+ 801,
1178
+ 823,
1179
+ 844
1180
+ ],
1181
+ "page_idx": 10
1182
+ },
1183
+ {
1184
+ "type": "text",
1185
+ "text": "Rik Koncel-Kedziorski, Subhro Roy, Aida Amini, Nate Kushman, and Hannaneh Hajishirzi. 2016. MAWPS: A math word problem repository. In Proceedings of the 2016 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, pages 1152–1157, San Diego, California. Association for Computational Linguistics. ",
1186
+ "bbox": [
1187
+ 174,
1188
+ 854,
1189
+ 826,
1190
+ 911
1191
+ ],
1192
+ "page_idx": 10
1193
+ },
1194
+ {
1195
+ "type": "text",
1196
+ "text": "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. 2019. Natural questions: A benchmark for question answering research. Transactions of the Association for Computational Linguistics, 7:452–466. ",
1197
+ "bbox": [
1198
+ 176,
1199
+ 90,
1200
+ 826,
1201
+ 161
1202
+ ],
1203
+ "page_idx": 11
1204
+ },
1205
+ {
1206
+ "type": "text",
1207
+ "text": "Angeliki Lazaridou, Elena Gribovskaya, Wojciech Stokowiec, and Nikolai Grigorev. 2022. Internetaugmented language models through few-shot prompting for open-domain question answering. arXiv preprint arXiv:2203.05115. ",
1208
+ "bbox": [
1209
+ 174,
1210
+ 170,
1211
+ 826,
1212
+ 212
1213
+ ],
1214
+ "page_idx": 11
1215
+ },
1216
+ {
1217
+ "type": "text",
1218
+ "text": "Patrick Lewis, Barlas Oguz, Ruty Rinott, Sebastian Riedel, and Holger Schwenk. 2019. Mlqa:˘ Evaluating cross-lingual extractive question answering. arXiv preprint arXiv:1910.07475. ",
1219
+ "bbox": [
1220
+ 173,
1221
+ 222,
1222
+ 821,
1223
+ 251
1224
+ ],
1225
+ "page_idx": 11
1226
+ },
1227
+ {
1228
+ "type": "text",
1229
+ "text": "Xi Victoria Lin, Todor Mihaylov, Mikel Artetxe, Tianlu Wang, Shuohui Chen, Daniel Simig, Myle Ott, Naman Goyal, Shruti Bhosale, Jingfei Du, Ramakanth Pasunuru, Sam Shleifer, Punit Singh Koura, Vishrav Chaudhary, Brian O’Horo, Jeff Wang, Luke Zettlemoyer, Zornitsa Kozareva, Mona Diab, Veselin Stoyanov, and Xian Li. 2021. Few-shot learning with multilingual language models. ",
1230
+ "bbox": [
1231
+ 174,
1232
+ 258,
1233
+ 826,
1234
+ 315
1235
+ ],
1236
+ "page_idx": 11
1237
+ },
1238
+ {
1239
+ "type": "text",
1240
+ "text": "Joshua Maynez, Shashi Narayan, Bernd Bohnet, and Ryan McDonald. 2020. On faithfulness and factuality in abstractive summarization. ",
1241
+ "bbox": [
1242
+ 173,
1243
+ 325,
1244
+ 823,
1245
+ 353
1246
+ ],
1247
+ "page_idx": 11
1248
+ },
1249
+ {
1250
+ "type": "text",
1251
+ "text": "David McClosky, Eugene Charniak, and Mark Johnson. 2006. Effective self-training for parsing. In Proceedings of the Human Language Technology Conference of the NAACL, Main Conference, pages 152–159, New York City, USA. Association for Computational Linguistics. ",
1252
+ "bbox": [
1253
+ 173,
1254
+ 362,
1255
+ 825,
1256
+ 405
1257
+ ],
1258
+ "page_idx": 11
1259
+ },
1260
+ {
1261
+ "type": "text",
1262
+ "text": "Stephen Merity, Caiming Xiong, James Bradbury, and Richard Socher. 2017. Pointer sentinel mixture models. In International Conference on Learning Representations. ",
1263
+ "bbox": [
1264
+ 171,
1265
+ 414,
1266
+ 823,
1267
+ 444
1268
+ ],
1269
+ "page_idx": 11
1270
+ },
1271
+ {
1272
+ "type": "text",
1273
+ "text": "Shen-yun Miao, Chao-Chun Liang, and Keh-Yih Su. 2020. A diverse corpus for evaluating and developing English math word problem solvers. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics, pages 975–984, Online. Association for Computational Linguistics. ",
1274
+ "bbox": [
1275
+ 174,
1276
+ 452,
1277
+ 825,
1278
+ 508
1279
+ ],
1280
+ "page_idx": 11
1281
+ },
1282
+ {
1283
+ "type": "text",
1284
+ "text": "Reiichiro Nakano, Jacob Hilton, Suchir Balaji, Jeff Wu, Long Ouyang, Christina Kim, Christopher Hesse, Shantanu Jain, Vineet Kosaraju, William Saunders, Xu Jiang, Karl Cobbe, Tyna Eloundou, Gretchen Krueger, Kevin Button, Matthew Knight, Benjamin Chess, and John Schulman. 2021. Webgpt: Browser-assisted question-answering with human feedback. ",
1285
+ "bbox": [
1286
+ 174,
1287
+ 517,
1288
+ 826,
1289
+ 574
1290
+ ],
1291
+ "page_idx": 11
1292
+ },
1293
+ {
1294
+ "type": "text",
1295
+ "text": "Aaron Parisi, Yao Zhao, and Noah Fiedel. 2022. Talm: Tool augmented language models. ",
1296
+ "bbox": [
1297
+ 171,
1298
+ 583,
1299
+ 759,
1300
+ 598
1301
+ ],
1302
+ "page_idx": 11
1303
+ },
1304
+ {
1305
+ "type": "text",
1306
+ "text": "Arkil Patel, Satwik Bhattamishra, and Navin Goyal. 2021. Are NLP models really able to solve simple math word problems? In Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, pages 2080–2094, Online. Association for Computational Linguistics. ",
1307
+ "bbox": [
1308
+ 174,
1309
+ 607,
1310
+ 825,
1311
+ 664
1312
+ ],
1313
+ "page_idx": 11
1314
+ },
1315
+ {
1316
+ "type": "text",
1317
+ "text": "Fabio Petroni, Aleksandra Piktus, Angela Fan, Patrick Lewis, Majid Yazdani, Nicola De Cao, James Thorne, Yacine Jernite, Vladimir Karpukhin, Jean Maillard, Vassilis Plachouras, Tim Rocktäschel, and Sebastian Riedel. 2021. KILT: a benchmark for knowledge intensive language tasks. In Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, pages 2523–2544, Online. Association for Computational Linguistics. ",
1318
+ "bbox": [
1319
+ 174,
1320
+ 672,
1321
+ 825,
1322
+ 756
1323
+ ],
1324
+ "page_idx": 11
1325
+ },
1326
+ {
1327
+ "type": "text",
1328
+ "text": "Fabio Petroni, Tim Rocktäschel, Sebastian Riedel, Patrick Lewis, Anton Bakhtin, Yuxiang Wu, and Alexander Miller. 2019. Language models as knowledge bases? 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 2463–2473, Hong Kong, China. Association for Computational Linguistics. ",
1329
+ "bbox": [
1330
+ 174,
1331
+ 765,
1332
+ 825,
1333
+ 835
1334
+ ],
1335
+ "page_idx": 11
1336
+ },
1337
+ {
1338
+ "type": "text",
1339
+ "text": "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. ",
1340
+ "bbox": [
1341
+ 174,
1342
+ 844,
1343
+ 825,
1344
+ 873
1345
+ ],
1346
+ "page_idx": 11
1347
+ },
1348
+ {
1349
+ "type": "text",
1350
+ "text": "Stephen E Robertson, Steve Walker, Susan Jones, Micheline M Hancock-Beaulieu, Mike Gatford, et al. 1995. Okapi at trec-3. Nist Special Publication Sp, 109:109. ",
1351
+ "bbox": [
1352
+ 176,
1353
+ 882,
1354
+ 823,
1355
+ 911
1356
+ ],
1357
+ "page_idx": 11
1358
+ },
1359
+ {
1360
+ "type": "text",
1361
+ "text": "Timo Schick, Jane Dwivedi-Yu, Zhengbao Jiang, Fabio Petroni, Patrick Lewis, Gautier Izacard, Qingfei You, Christoforos Nalmpantis, Edouard Grave, and Sebastian Riedel. 2022. Peer: A collaborative language model. ",
1362
+ "bbox": [
1363
+ 176,
1364
+ 90,
1365
+ 823,
1366
+ 132
1367
+ ],
1368
+ "page_idx": 12
1369
+ },
1370
+ {
1371
+ "type": "text",
1372
+ "text": "Timo Schick and Hinrich Schütze. 2021a. Exploiting cloze-questions for few-shot text classification and natural language inference. In Proceedings of the 16th Conference of the European Chapter of the Association for Computational Linguistics: Main Volume, pages 255–269, Online. Association for Computational Linguistics. ",
1373
+ "bbox": [
1374
+ 174,
1375
+ 142,
1376
+ 826,
1377
+ 198
1378
+ ],
1379
+ "page_idx": 12
1380
+ },
1381
+ {
1382
+ "type": "text",
1383
+ "text": "Timo Schick and Hinrich Schütze. 2021b. Generating datasets with pretrained language models. In Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing, pages 6943–6951, Online and Punta Cana, Dominican Republic. Association for Computational Linguistics. ",
1384
+ "bbox": [
1385
+ 174,
1386
+ 207,
1387
+ 825,
1388
+ 263
1389
+ ],
1390
+ "page_idx": 12
1391
+ },
1392
+ {
1393
+ "type": "text",
1394
+ "text": "Kurt Shuster, Jing Xu, Mojtaba Komeili, Da Ju, Eric Michael Smith, Stephen Roller, Megan Ung, Moya Chen, Kushal Arora, Joshua Lane, Morteza Behrooz, William Ngan, Spencer Poff, Naman Goyal, Arthur Szlam, Y-Lan Boureau, Melanie Kambadur, and Jason Weston. 2022. Blenderbot 3: a deployed conversational agent that continually learns to responsibly engage. ",
1395
+ "bbox": [
1396
+ 174,
1397
+ 272,
1398
+ 826,
1399
+ 329
1400
+ ],
1401
+ "page_idx": 12
1402
+ },
1403
+ {
1404
+ "type": "text",
1405
+ "text": "Romal Thoppilan, Daniel De Freitas, Jamie Hall, Noam Shazeer, Apoorv Kulshreshtha, Heng-Tze Cheng, Alicia Jin, Taylor Bos, Leslie Baker, Yu Du, YaGuang Li, Hongrae Lee, Huaixiu Steven Zheng, Amin Ghafouri, Marcelo Menegali, Yanping Huang, Maxim Krikun, Dmitry Lepikhin, James Qin, Dehao Chen, Yuanzhong Xu, Zhifeng Chen, Adam Roberts, Maarten Bosma, Vincent Zhao, Yanqi Zhou, Chung-Ching Chang, Igor Krivokon, Will Rusch, Marc Pickett, Pranesh Srinivasan, Laichee Man, Kathleen Meier-Hellstern, Meredith Ringel Morris, Tulsee Doshi, Renelito Delos Santos, Toju Duke, Johnny Soraker, Ben Zevenbergen, Vinodkumar Prabhakaran, Mark Diaz, Ben Hutchinson, Kristen Olson, Alejandra Molina, Erin Hoffman-John, Josh Lee, Lora Aroyo, Ravi Rajakumar, Alena Butryna, Matthew Lamm, Viktoriya Kuzmina, Joe Fenton, Aaron Cohen, Rachel Bernstein, Ray Kurzweil, Blaise Aguera-Arcas, Claire Cui, Marian Croak, Ed Chi, and Quoc Le. 2022. Lamda: Language models for dialog applications. ",
1406
+ "bbox": [
1407
+ 174,
1408
+ 338,
1409
+ 826,
1410
+ 489
1411
+ ],
1412
+ "page_idx": 12
1413
+ },
1414
+ {
1415
+ "type": "text",
1416
+ "text": "Hugo Touvron, Thibaut Lavril, Gautier Izacard, Xavier Martinet, Marie-Anne Lachaux, Timothée Lacroix, Baptiste Rozière, Naman Goyal, Eric Hambro, Faisal Azhar, Aurelien Rodriguez, Armand Joulin, Edouard Grave, and Guillaume Lample. 2023. Llama: Open and efficient foundation language models. ",
1417
+ "bbox": [
1418
+ 173,
1419
+ 500,
1420
+ 825,
1421
+ 555
1422
+ ],
1423
+ "page_idx": 12
1424
+ },
1425
+ {
1426
+ "type": "text",
1427
+ "text": "Ben Wang and Aran Komatsuzaki. 2021. GPT-J-6B: A 6 Billion Parameter Autoregressive Language Model. https://github.com/kingoflolz/mesh-transformer-jax. ",
1428
+ "bbox": [
1429
+ 171,
1430
+ 564,
1431
+ 821,
1432
+ 593
1433
+ ],
1434
+ "page_idx": 12
1435
+ },
1436
+ {
1437
+ "type": "text",
1438
+ "text": "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. ",
1439
+ "bbox": [
1440
+ 176,
1441
+ 602,
1442
+ 823,
1443
+ 645
1444
+ ],
1445
+ "page_idx": 12
1446
+ },
1447
+ {
1448
+ "type": "text",
1449
+ "text": "Guillaume Wenzek, Marie-Anne Lachaux, Alexis Conneau, Vishrav Chaudhary, Francisco Guzmán, Armand Joulin, and Edouard Grave. 2020. CCNet: Extracting high quality monolingual datasets from web crawl data. In Proceedings of the Twelfth Language Resources and Evaluation Conference, pages 4003–4012, Marseille, France. European Language Resources Association. ",
1450
+ "bbox": [
1451
+ 174,
1452
+ 654,
1453
+ 826,
1454
+ 709
1455
+ ],
1456
+ "page_idx": 12
1457
+ },
1458
+ {
1459
+ "type": "text",
1460
+ "text": "Shunyu Yao, Jeffrey Zhao, Dian Yu, Nan Du, Izhak Shafran, Karthik Narasimhan, and Yuan Cao. 2022. React: Synergizing reasoning and acting in language models. ",
1461
+ "bbox": [
1462
+ 171,
1463
+ 718,
1464
+ 825,
1465
+ 747
1466
+ ],
1467
+ "page_idx": 12
1468
+ },
1469
+ {
1470
+ "type": "text",
1471
+ "text": "David Yarowsky. 1995. Unsupervised word sense disambiguation rivaling supervised methods. In 33rd Annual Meeting of the Association for Computational Linguistics, pages 189–196, Cambridge, Massachusetts, USA. Association for Computational Linguistics. ",
1472
+ "bbox": [
1473
+ 174,
1474
+ 756,
1475
+ 826,
1476
+ 799
1477
+ ],
1478
+ "page_idx": 12
1479
+ },
1480
+ {
1481
+ "type": "text",
1482
+ "text": "Eric Zelikman, Yuhuai Wu, Jesse Mu, and Noah D. Goodman. 2022. Star: Bootstrapping reasoning with reasoning. ",
1483
+ "bbox": [
1484
+ 174,
1485
+ 808,
1486
+ 821,
1487
+ 837
1488
+ ],
1489
+ "page_idx": 12
1490
+ },
1491
+ {
1492
+ "type": "text",
1493
+ "text": "Susan Zhang, Stephen Roller, Naman Goyal, Mikel Artetxe, Moya Chen, Shuohui Chen, Christopher Dewan, Mona Diab, Xian Li, Xi Victoria Lin, Todor Mihaylov, Myle Ott, Sam Shleifer, Kurt Shuster, Daniel Simig, Punit Singh Koura, Anjali Sridhar, Tianlu Wang, and Luke Zettlemoyer. 2022. Opt: Open pre-trained transformer language models. ",
1494
+ "bbox": [
1495
+ 174,
1496
+ 844,
1497
+ 825,
1498
+ 901
1499
+ ],
1500
+ "page_idx": 12
1501
+ }
1502
+ ]
parse/dev/Yacmpz84TH/Yacmpz84TH_middle.json ADDED
The diff for this file is too large to render. See raw diff
 
parse/dev/Yacmpz84TH/Yacmpz84TH_model.json ADDED
The diff for this file is too large to render. See raw diff
 
parse/dev/aUkOeKsGe2X/aUkOeKsGe2X.md ADDED
@@ -0,0 +1,345 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AUTOENCODER FOR SYNTHETIC TO REAL GENERAL-IZATION: FROM SIMPLE TO MORE COMPLEX SCENES
2
+
3
+ Anonymous authors Paper under double-blind review
4
+
5
+ # ABSTRACT
6
+
7
+ Learning on synthetic data and transferring the resulting properties to their real counterparts is an important challenge for reducing costs and increasing safety in machine learning. In this work, we focus on autoencoder architectures and aim at learning latent space representations that are invariant to inductive biases caused by the domain shift between simulated and real images showing the same scenario. We train on synthetic images only, present approaches to increase generalizability and improve the preservation of the semantics to real datasets of increasing visual complexity. We show that pre-trained feature extractors (e.g. VGG) can be sufficient for generalization on images of lower complexity, but additional improvements are required for visually more complex scenes. To this end, we demonstrate a new sampling technique, which matches semantically important parts of the image, while randomizing the other parts, leads to salient feature extraction and a neglection of unimportant parts. This helps the generalization to real data and we further show that our approach outperforms fine-tuned classification models.
8
+
9
+ # 1 INTRODUCTION
10
+
11
+ The generation of synthetic data constitutes a cost efficient way for acquiring machine learning training data together with exact and free annotations. Notwithstanding this obvious advantage, bridging the gap between synthetic and real data remains an open challenge, in particular for camera based applications. Learning from synthetic data is an important tool in robotics: Lee et al. (2020) introduced a method for training a quadrupedal robot on synthetic data by incorporating proprioceptive feedback. Akkaya et al. (2019) trained a robot hand to solve real Rubik’s cubes by learning the model in a simulation only. Zhang et al. (2019) made the robot feel at home by translating the real world input data into synthetic data for their reinforcement learning agent. In view of safety critical applications, synthetic data can provide the means to reduce costs related to acquiring samples for edge cases, or which are difficult to obtain because they are too dangerous, e.g. accidents. We focus on learning invariances empirically on synthetic data, which should transfer to real data, as opposed to constructing invariances as in equivariant neural networks (Romero & Hoogendoorn, 2020).
12
+
13
+ We investigate the case of single independent images for which consistency between frames and physical interactions cannot be taken advantage of. The latter is commonly used by reinforcement learning methods (Lee et al., 2020). We focus on training on synthetic data only and limit ourselves to autoencoder models which provide interesting properties due to their bottleneck design. The low-dimensional latent space of autoencoders can be subject to metric constraints (Hoffer & Ailon, 2015), allows for scene decomposition (Engelcke et al., 2020) and it is believed that latent factor disentanglement can be useful for downstream tasks (van Steenkiste et al., 2019). We assess to what extend we can generalize to real images and we highlight which design choices improve the autoencoder models performance with respect to accuracy and reconstruction quality. To this end, we first develop a method using features of pre-trained classifiers and show that we achieve better results on MPI3D (Gondal et al., 2019) to generalize from synthetic (toy or realistic) to real images compared to Autoencoder, Variational Autoencoder (VAE) (Kingma & Welling, 2014), $\beta$ - VAE (Higgins et al., 2017) and FactorVAE (Kim & Mnih, 2018). Although successful, we highlight that insights and design choices on a simple dataset do not necessarily transfer to real applications of higher visual complexity. To improve generalization, we propose to use the partially impossible reconstruction loss (PIRL) (Dias Da Cruz et al., 2021) (matching semantically important parts while randomizing the other parts) and we propose a novel variation thereof. We extensively show that our variation is the driving force for the improved generalization capacities. Additionally, we induce structure in the latent space by a triplet loss regularization. We evaluate and justify the benefits of the different design choices on an automotive application focusing on occupancy classification in the vehicle interior. The challenge of training in a single vehicle interior and transferring results between different vehicle interiors has been investigated by Dias Da Cruz et al. (2021). The latter and similar industrial applications suffer from the limited availability and variability of training data. A successful transfer from synthetic to real data would avoid the necessity of collecting real data for each vehicle interior: the invariances could be learned and improved on synthetic data only.
14
+
15
+ ![](images/40c198ac0999a1f43500c6b8d0cbde127e17c08caa224e39542524b626016d6a.jpg)
16
+ Figure 1: Impossible Instance Extractor Triplet Autoencoder (II-E-TAE) model architecture.
17
+
18
+ # 2 RELATED WORKS
19
+
20
+ There have been successful applications of reinforcement learning systems being trained in a simulated environment and deployed to a real one, for example by combining real and synthetic data during training (Kang et al., 2019; Rao et al., 2020; Fang et al., 2018; Bewley et al., 2019). However, these approaches can take into account temporal information and action-reaction causalities while in this work we use independent frames only. A good overview on reinforcement learning based simulation to real transferability is provided in (Zhao et al., 2020). Another line of research uses generative adversarial networks (GAN) to make synthetic images look like real images or vice versa (Ho et al., 2020; Carlson et al., 2019). This requires both synthetic and real images, whereas we focus on training on synthetic images only. Part of our methodology is related to domain randomization (Tremblay et al., 2018), where the environment is being randomized, but Tremblay et al. (2018) deployed this to object detection and the resulting model needs to be fine-tuned on real data. A similar idea of freezing the layers of a pre-trained model was investigated for object detection (Hinterstoisser et al., 2018), but neither with a dedicated sampling strategy nor in the context of autoencoders. While Tobin et al. (2017) focuses on localization and training on synthetic images only, the applicability is only tested on simple geometries. Although, we start our investigations on the simple dataset MPI3D, we increase the visual complexity by incorporating human models and child seats. Inoue et al. (2018) and Zhang et al. (2015) rely on the use of real images during training as well for the minimization of the synthetic to real gap for autoencoders. Recent advances on synthetic to real image segmentation (Chen et al., 2020; Yue et al., 2019; Pan et al., 2018) on the VisDA (Peng et al., 2017) dataset show a promising direction to overcome the gap between synthetic and real images, however, this cannot straightforwardly be compared against the investigation in this work, particularly, since we are focusing on autoencoder models and their generative nature. While our cost function variation is based on Dias Da Cruz et al. (2021), we show that our approach improves generalization while needing less demanding training data such that it can easily be applied to any commonly recorded dataset (i.e. no variations of the same scene are needed).
21
+
22
+ # 3 METHOD
23
+
24
+ Consider $N _ { s }$ sceneries and $N _ { v }$ variations of the same scenery, e.g. same scenery under different illuminations, with different backgrounds or under different data augmentation transformations. Let $\mathcal { X } = \{ X _ { i } ^ { j } | 1 \le i \le N _ { v } , 1 \le j \le N _ { s } \}$ denote the training data, where each $X _ { i } ^ { j } ~ \in ~ \mathbb { R } ^ { C \times H \times W }$ is the ith variation of scene $j$ consisting of $C$ channels and being of height $H$ and width $W$ . Let $X ^ { j } = \{ X _ { i } ^ { j } | 1 \leq i \leq N _ { v } \}$ be the set of all variations $i$ of scenery $j$ and $\mathcal { V } = \{ Y ^ { j } | 1 \le j \le N _ { s } \}$ be the corresponding target classes of the scenes of $\mathcal { X }$ . Notice that the classes remain constant for the variations $i$ of each scene $j$ . In the following, we will present the final model architecture as illustrated in Fig. 1 and we provide evidences for each design choice in Section 4.
25
+
26
+ ![](images/f525930f7109f4a5a7374812d496b8eb857a5292a06c680efe38c5ea117e6e5f.jpg)
27
+ Figure 2: Illustration of the different input-target pairs for the autoencoder reconstruction loss.
28
+
29
+ # 3.1 MODEL ARCHITECTURE: EXTRACTOR AUTOENCODER
30
+
31
+ By an abuse of terminology, we will refer to our method as a variation of vanilla autoencoders, although an encoder-decoder formulation would strictly speaking be more correct, because the goal will not be to reconstruct the input image exactly. We propose to apply ideas from transfer learning and use a pre-trained classification model to extract more general features from the input images. Instead of using the images itself, the extracted features are used as input. Our autoencoder consists of a summarization module which reduces the number of convolutional filters. This is fed to a simple MLP encoder which is then decoded by a transposed convolutional network. We refer to this model as extractor autoencoder (E-AE). Let $\mathrm { e } _ { \phi }$ be the encoder, $\mathrm { d } _ { \theta }$ the decoder and $\mathrm { e x t } _ { \omega }$ be a pre-trained classification model, referred to as extractor. For ease of notation, we define $\mathrm { e } _ { \phi } ( \mathrm { e x t } _ { \omega } ( \cdot ) ) = \mathrm { e e } _ { \phi , \omega } ( \cdot )$ . The model, using the vanilla reconstruction loss, can be formulated for a single input sample as
32
+
33
+ $$
34
+ \begin{array} { r } { \mathcal { L } _ { R } ( X _ { i } ^ { j } ; \theta , \phi ) = \mathrm { r } \left( \mathrm { d } _ { \theta } ( \mathrm { e x t } _ { \omega } ( X _ { i } ^ { j } ) ) ) , X _ { i } ^ { j } \right) = \mathrm { r } \left( \mathrm { d } _ { \theta } ( \mathrm { e e } _ { \phi , \omega } ( X _ { i } ^ { j } ) ) , X _ { i } ^ { j } \right) , } \end{array}
35
+ $$
36
+
37
+ where $\mathrm { r } ( \cdot , \cdot )$ computes the error loss between target and reconstruction. We use the structural similarity index measure (SSIM) (Bergmann et al., 2018) and binary cross entropy (BCE), but our method is not limited to them. Model details are provided in the appendix A.2.1.
38
+
39
+ # 3.2 SAMPLING STRATEGY: PARTIAL IMPOSSIBLE
40
+
41
+ An additional improvement to the autoencoder training approach is a dedicated sampling strategy for which we provide two variations. The first one is the partially impossible reconstruction loss (PIRL) as introduced by Dias Da Cruz et al. (2021) for illumination normalization. As our results will show, this also helps the transfer between synthetic and real images. For sampling the individual elements of a batch, we randomly select for each scene two images, one as input and the other one as target. This sampling strategy preserves the semantics while varying the unimportant features such that the model needs to focus on what remains constant. For random $a , b \in [ 0 , \mathsf { \bar { N } } _ { v } ]$ and $a \neq b$ :
42
+
43
+ $$
44
+ \begin{array} { r } { \mathcal { L } _ { R , I } ( X _ { a } ^ { j } ; \theta , \phi ) = \mathrm { r } \left( \mathrm { d } _ { \theta } \big ( \mathrm { e e } _ { \phi , \omega } ( X _ { a } ^ { j } ) \big ) , X _ { b } ^ { j } \right) . } \end{array}
45
+ $$
46
+
47
+ We refer to models using the PIRL by prepending an $I$ , e.g. I-E-AE.
48
+
49
+ # 3.3 SAMPLING STRATEGY: PARTIAL IMPOSSIBLE CLASS INSTANCE
50
+
51
+ We propose a novel variation to further improve this strategy by sampling a target image of a different scene, but of the same class. This should cause the model to learn invariances with respect to certain class variations which are not important for the task at hand, e.g. clothes, human poses, textures. This sampling variation would be reflected in the reconstruction loss as follows
52
+
53
+ $$
54
+ \begin{array} { r } { \mathcal { L } _ { R , I I } ( X _ { a } ^ { j } ; \theta , \phi ) = \mathrm { r } \left( \mathrm { d } _ { \theta } ( \mathrm e \varphi _ { \phi , \omega } ( X _ { a } ^ { j } ) ) , X _ { b } ^ { k } \right) , } \end{array}
55
+ $$
56
+
57
+ for random $a , b \in [ 0 , N _ { v } ]$ , $j \neq k$ and $Y ^ { j } = Y ^ { k }$ . We refer to this method as impossible class instance sampling marked by prepending $\boldsymbol { { I I } }$ , e.g. II-E-AE. It is important to notice that our novel variation can easily be applied to any common dataset. The sampling variations are visualized in Fig. 2.
58
+
59
+ # 3.4 STRUCTURE IN THE LATENT SPACE: TRIPLET LOSS
60
+
61
+ The final adjustment to our training strategy is the incorporation of the triplet loss regularization in the latent space (Hoffer & Ailon, 2015) to induce structure. This can be integrated by
62
+
63
+ $$
64
+ \mathcal { L } _ { T } ( X _ { a } ^ { j } ; \phi ) = \operatorname* { m a x } \left( 0 , \left. \mathrm { e e } _ { \phi , \omega } ( X _ { a } ^ { j } ) - \mathrm { e e } _ { \phi , \omega } ( X _ { b } ^ { k } ) \right. ^ { 2 } - \left. \mathrm { e e } _ { \phi , \omega } ( X _ { a } ^ { j } ) - \mathrm { e e } _ { \phi , \omega } ( X _ { c } ^ { l } ) \right. ^ { 2 } + 0 . 2 \right) ,
65
+ $$
66
+
67
+ for random $a , b , c \in [ 0 , N _ { v } ]$ , $j \neq k \neq l$ and $Y ^ { j } = Y ^ { k } \neq Y ^ { l }$ . We refer to this model as triplet autoencoder (TAE) either with or without using the PIRL. We can sample impossible target instances for the positive and negative triplet samples such that the total loss becomes (for some $\alpha$ and $\beta$ ):
68
+
69
+ $$
70
+ \begin{array} { r } { \mathcal { L } ( X _ { a } ^ { j } ; \theta , \phi ) = \alpha \mathcal { L } _ { T } ( X _ { a } ^ { j } ; \phi ) + \beta \left( \mathcal { L } _ { R , I I } ( X _ { a } ^ { j } ; \theta , \phi ) + \mathcal { L } _ { R , I I } ( X _ { b } ^ { k } ; \theta , \phi ) + \mathcal { L } _ { R , I I } ( X _ { c } ^ { l } ; \theta , \phi ) \right) . } \end{array}
71
+ $$
72
+
73
+ # 4 EXPERIMENTS
74
+
75
+ This section is organized in observations, formulated as subsections, which are built on one another and contain results highlighting the improvements. This provides explanations for the design choices leading to our final model architecture and cost function formulations presented in Section 3. Improvements regarding the transfer to real images when only being trained on synthetic images are assessed qualitatively based on reconstruction quality and latent space structure and quantitatively on classification accuracy. All experiments use the same hyperparameters whenever possible. Training details and additional results are provided in the appendix and in our implementation.
76
+
77
+ We perform a baseline evaluation on MPI3D (Gondal et al., 2019), which provides simple and realistic renderings and real counterparts. We reduced the dataset to contain only the large objects. For a higher visual complexity, we use as synthetic images the SVIRO (Dias Da Cruz et al., 2020) dataset. TICaM (Katrolia et al., 2021) is used to evaluate the performance on a real dataset of a similar application. The latter datasets are grayscale images from the vehicle interior and consider the task of classification (empty, infant, child or adult) for each seat position. The design choices made on MPI3D and the available synthetic images are not sufficient to obtain a good transferability to real images from the vehicle interior. Hence, we release an additional dataset, see Section 4.5 and A.1.4. We introduce step by step modifications to the autoencoder architecture leading to steady quantitative and qualitative improvements. MPI3D and the vehicle interior share interesting properties: they have almost identical backgrounds and the environment is more tractable than many computer vision datasets. The transfer from SVIRO to TICaM is further complicated by new unseen attributes, e.g. steering wheel. An additional ablation study shows that our novel variation of PIRL is the driving force for the improved generalization capacity. Finally, to be in line with common benchmark datasets, we show that our design choices also improve the transfer from training on MNIST (LeCun et al., 1998) to generalizing to real images of digits (De Campos et al., 2009).
78
+
79
+ # 4.1 AUTOENCODERS STRUGGLE ON REAL IMAGES WHEN TRAINED ON SYNTHETIC IMAGES
80
+
81
+ In the first, albeit na¨ıve experiment we assumed that due to the bottleneck of autoencoders, the latter should generalize to some extent to real images when trained on synthetic ones. We trained convolutional autoencoders (AE) on the toy and realistic MPI3D images, respectively, and evaluated the resulting models on the real recordings. The first row of Fig. 3b shows the reconstruction of real images when trained on the realistic synthetic images: the model preserves some of the semantics. The model fails to perform senseful reconstructions when trained on toy images, see Fig. 3c.
82
+
83
+ # 4.2 AUTOENCODERS OVERFIT TO THE SYNTHETIC DISTRIBUTION
84
+
85
+ An immediate consequence of the results of the previous section is the assumption that the autoencoder overfits to the synthetic distribution and takes into consideration some artefacts (e.g. rendering noise). We followed the idea of Gondal et al. (2019) and trained Variational Autoencoder (VAE) (Kingma & Welling, 2014), $\beta$ -VAE (Higgins et al., 2017) and FactorVAE (Kim & Mnih, 2018) on the same data as before using the BCE reconstruction loss. The results in the second $\beta$ -VAE with $\beta = 8$ ) and third (FactorVAE with $\gamma = 5 0$ ) row of Fig. 3b show that the models reconstruct real images better and more of the semantics are preserved. If trained on toy renderings, the representation gap is too large, causing the reconstruction of the real images to be bad: see Fig. 3c.
86
+
87
+ # 4.3 MORE GENERAL INPUT FEATURES IMPROVE AUTOENCODER RECONSTRUCTIONS
88
+
89
+ A small gap between the synthetic and real distribution can potentially be closed by a dedicated data augmentation approach to avoid overfitting to synthetic artefacts. Nevertheless, and while making sense, an abstraction from toy to real images cannot be achieved by means of simple data transformations or model constraints (e.g. denoising autoencoder). To this end we propose to use a (a) Synthetic realistic and toy training data as well as real data used as input after training (b) Reconstruction of real data when being trained on realistic data.
90
+
91
+ ![](images/db606ab564fb554bdc68096e90d37d57c729a2703f583ee9a2724ce27a15c9dd.jpg)
92
+
93
+ ![](images/b5c4273e246fb0d9bfe97bc6f85d6aa8e9268600bd6dc1f5d8f6bbf75c352d4d.jpg)
94
+
95
+ ![](images/74146757d8795cea08c1f93a2bbf952eea2c98a1572f0d43b12d006b0d909e8d.jpg)
96
+ (c) Reconstruction of real data when being trained on toy data.
97
+
98
+ ![](images/23c7452661ed37019e8f46d5d7f3b01bbbf06cb1b2d71dedb3b96b4800d72027.jpg)
99
+ Figure 3: Reconstruction of unseen real data for different autoencoders: Autoencoder (AE), $\beta$ Variational Autoencoder $\beta$ -VAE), FactorVAE (F-VAE) and Extractor Autoencoder (E-AE).
100
+ Figure 4: t-SNE projection of the 10 dimensional latent space representation of the realistic training (blue circle) together with the real (orange cross) images. Autoencoder (AE), $\beta$ Variational Autoencoder ( $\beta$ -VAE), FactorVAE and Extractor Autoencoder (E-AE). The extractor approach is the only method clustering both synthetic and real images together.
101
+
102
+ pre-trained feature extractor as presented in Section 3 and as defined by Eq. 1. In the following, we used the VGG-11 model pre-trained on Imagenet as the extractor if not stated otherwise.
103
+
104
+ The results from the fourth row of Fig. 3b and Fig. 3c, respectively, show that the proposed modifications enable the model to generalize to real images when trained on synthetic ones. Much more of the semantics are preserved even when the model was only trained on toy images. Our method produces semantically more correct and less noisy reconstructions compared to the VAE and FactorVAE baseline results. Additional qualitative improvements are highlighted by visualizing the latent space: both the 10-dimensional training (synthetic) and test (real) data latent spaces are projected together into a 2-dimensional representation using t-SNE. In Fig. 4 we can observe that VAE and FactorVAE improve the representation of real and synthetic images in the same region in the latent space, however, only partially, indicating a different representation for real and synthetic images. When using E-AE, real and synthetic images are represented more similarly in the latent space and the clusters are completely overlapping. Even when trained on the toy dataset, the latent space representation for synthetic and real images produced by E-AE overlaps partially as visualized in the appendix Fig. 8. Finally, we report in Table 1 a quantitative evaluation between the reconstructions of the real images against their synthetic training counterparts across all dataset images for different norms. We compute the same metrics between the real input images and their reconstruction to measure whether the semantics are being preserved : in all cases E-AE performs best. Additional results can be found in the appendix in Table 8 and reconstructions of synthetic input images in Fig 9. The latter shows that all models perform similarly well on the training data, hence the training was successful, but our proposed design choices generalize best to the real images.
105
+
106
+ Table 1: We report the L1, SSIM and LIPIPS (Zhang et al., 2018) norm between the reconstructions of the real images (unknown) and the corresponding synthetic (Synth.) training images (realistic or toy) or input images (Real). We report the mean of the norms across the dataset: for SSIM larger $\uparrow$ and for the others smaller $\downarrow$ is better. E-AE performs best.
107
+
108
+ <table><tr><td></td><td></td><td></td><td colspan="2">L1↓</td><td colspan="2">SSIM↑</td><td colspan="2">LPIPS↓</td></tr><tr><td>Trained on</td><td>Model</td><td>Variant</td><td>Synth.</td><td>Real</td><td>Synth.</td><td>Real</td><td>Synth.</td><td>Real</td></tr><tr><td>Toy</td><td>AE</td><td>SSIM</td><td>932</td><td>1763</td><td>0.56</td><td>0.42</td><td>0.35</td><td>0.40</td></tr><tr><td>Toy</td><td>VAE</td><td>BCE</td><td>659</td><td>1497</td><td>0.50</td><td>0.33</td><td>0.34</td><td>0.42</td></tr><tr><td>Toy</td><td>β-VAE</td><td>BCE,β=4</td><td>710</td><td>1542</td><td>0.53</td><td>0.38</td><td>0.31</td><td>0.44</td></tr><tr><td>Toy</td><td>β-VAE</td><td>BCE,β=8</td><td>406</td><td>1321</td><td>0.71</td><td>0.48</td><td>0.26</td><td>0.37</td></tr><tr><td>Toy</td><td>FactorVAE</td><td>BCE,= 10</td><td>521</td><td>1288</td><td>0.66</td><td>0.45</td><td>0.26</td><td>0.39</td></tr><tr><td>Toy</td><td>FactorVAE</td><td>BCE, = 50</td><td>430</td><td>1295</td><td>0.71</td><td>0.51</td><td>0.22</td><td>0.35</td></tr><tr><td>Toy</td><td>E-AE (ours)</td><td>SSIM</td><td>177</td><td>1165</td><td>0.90</td><td>0.58</td><td>0.10</td><td>0.28</td></tr><tr><td>Realistic</td><td>AE</td><td>SSIM</td><td>568</td><td>1133</td><td>0.83</td><td>0.62</td><td>0.20</td><td>0.24</td></tr><tr><td>Realistic</td><td>VAE</td><td>BCE</td><td>482</td><td>890</td><td>0.74</td><td>0.61</td><td>0.20</td><td>0.23</td></tr><tr><td>Realistic</td><td>β-VAE</td><td>BCE,β= 4</td><td>372</td><td>833</td><td>0.81</td><td>0.64</td><td>0.18</td><td>0.20</td></tr><tr><td>Realistic</td><td>β-VAE</td><td>BCE,β=8</td><td>384</td><td>854</td><td>0.79</td><td>0.64</td><td>0.19</td><td>0.21</td></tr><tr><td>Realistic</td><td>FactorVAE</td><td>BCE, = 10</td><td>218</td><td>734</td><td>0.88</td><td>0.68</td><td>0.15</td><td>0.19</td></tr><tr><td>Realistic</td><td>FactorVAE</td><td>BCE,= 50</td><td>391</td><td>830</td><td>0.78</td><td>0.64</td><td>0.16</td><td>0.18</td></tr><tr><td>Realistic</td><td>E-AE (ours)</td><td>SSIM</td><td>251</td><td>841</td><td>0.92</td><td>0.70</td><td>0.08</td><td>0.14</td></tr></table>
109
+
110
+ # 4.4 IT WORKS FOR VISUALLY SIMPLE IMAGES - MORE IS NEEDED ON MORE COMPLEX DATA
111
+
112
+ Since the method introduced in the previous section achieved good results, even when being trained on toy images, we were optimistic to apply it to images of higher visual complexity, e.g. a vehicle interior. We trained the same model architecture as in the previous section, but with a 64-dimensional latent space, on images from the Tesla vehicle from SVIRO and the Kodiaq vehicle from SVIROIllumination dataset, respectively, and evaluated the model on the real TICaM images. Examples of the resulting model’s reconstructions are plotted in Fig. 5 (b) and in the appendix Fig. 10. In both cases only blurry human models are being reconstructed, which is similar to the mode collapse in the first row of Fig. 3c. We concluded that more robust features are needed.
113
+
114
+ # 4.5 PARTIALLY IMPOSSIBLE RECONSTRUCTION LOSS HELPS GENERALIZATION
115
+
116
+ As defined by Eq. 2, a partially impossible reconstruction loss (PIRL) for autoencoders has proven to work well for image normalization (Dias Da Cruz et al., 2021). We hypothesized that the same approach could lead to a better generalization to real vehicle interiors. In a first approach, we applied this strategy to variations of the same scene under different illumination conditions, but realized that the learned invariances are not suitable for the transfer between synthetic and real. An example is provided in Fig. 5 (c) where we trained on the Kodiaq images from the SVIRO-Illumination dataset.
117
+
118
+ ![](images/4281065016928bbab651c5b624d62a1d31e928c2bf2d37618ea3d1b593ca8a77.jpg)
119
+ Figure 5: Reconstructions of unseen real data (a) from TICaM: (b) E-AE and (c) I-E-AE trained on Kodiaq SVIRO-Illumination, (d) E-AE, (e) I-E-AE, (f) II-E-AE and (g) II-E-TAE trained on our new dataset. A red (wrong) or green (correct) box highlights whether the classes are preserved.
120
+
121
+ We concluded that, for learning more general features by applying the PIRL, we needed input-target pairs where both images are of the same scene, but differ in the properties we want to become invariant to: the dominant background. To this end we created 5919 synthetic scenes where we placed humans, child and infant seats as if they would be sitting in a vehicle interior, but instead of a vehicle, the background was replaced by selecting randomly from a pool of available HDRI images. Each scene was rendered using 10 different backgrounds. Examples from the dataset are shown in Fig. 7 in the appendix. During training, we randomly select two images per scene and use one as input and the other as target, i.e. as defined in Eq. 2. When applied to real images, see Fig. 5 (e), the model better preserves the semantics of the real images: the model starts to reconstruct child seats and not people only, anymore. We also trained a model without the PIRL to show that the success is not due to the design choice of the dataset: in Fig. 5 (d) the model performs worse.
122
+
123
+ Finally, we extended this idea further with our novel PIRL loss formulation: instead of taking the same scene with a different background as target image, we randomly selected a different scene of the same class, e.g. if a person is sitting at the left seat position, we would take another image with a person on the left seat, potentially a different person with a different pose. This approach is formulated in Eq. 3. While this leads to a blurrier object reconstruction, which is expected because the autoencoder needs to learn an average class representation, the classes are preserved more robustly and the reconstructions look better than before, see Fig. 5 (f). Moreover, this additional randomization improves classification accuracy as discussed in Section 4.7 and in Section 5. A visualization of the different input-target pair combinations can be found in Fig. 2. The dataset can been downloaded from this link (Google Drive - Anonymous user) and it will be made publicly available.
124
+
125
+ # 4.6 STRUCTURE IN THE LATENT SPACE HELPS GENERALIZATION
126
+
127
+ The final improvement is based on the assumption that structure in the latent space should help the model performance. Class labels are included by formulating a triplet loss regularization to the latent space representation as defined by Eq. 4: images of the same class should be mapped closely together and images of different classes pushed away. The triplet loss induces a more meaningful $L ^ { \tilde { 2 } }$ -norm in the latent space (Dias Da Cruz et al., 2021) such that a k-nearest neighbor (KNN) classifier can be used in the next section. As the results of Fig. 5 (g) and in the appendix show, these final improvements, together with the previous changes, yield the semantically most correct reconstructions. In the appendix we show that due to the triplet loss the nearest neighbour of (g) makes sense and yields a clearer reconstruction. The triplet loss without the PIRL is not sufficient and in Section 5 we show that the II-PIRL loss is the driving force for the improved performance.
128
+
129
+ ![](images/d2e3018806e7aeb40bb69ac24c26fbfc65654d09fd618bd03a61176a143b76ff.jpg)
130
+ Figure 6: Comparison of the training performance distribution for each epoch over 250 epochs. II-E-TAE is compared against training the corresponding extractor from scratch or fine-tuning the layers after the features which are used by the extractor in our autoencoder approach.
131
+
132
+ # 4.7 KNN WITH TRIPLET LOSS OUT-PERFORMS FINE TUNED CLASSIFICATION MODELS
133
+
134
+ We investigated whether the qualitative improvements also transfer to a quantitative improvement. We took the most basic approach: we combined the E-TAE with a k-nearest neighbor classifier in the latent space and used our new dataset for training. We retrieve the latent space vectors for all flipped training images as well and used only a single image per scene (i.e. not all 10 variations).√ We choose $k \stackrel { - } { = } \sqrt { N } = 1 1 5$ , where $N$ is the size of the training data together with its flipped version (Jirina et al., 2011). The model should classify occupancy (empty, infant, child or adult) for each seat position and we used the same hyperparameters for all methods and variations thereof. We froze the same layers of the pre-trained models for fine-tuning the later layers in case of classification models or to train our autoencoder using it as an extractor. We evaluated the model performance after each epoch on the real TICaM images (normal and flipped images of the training and test splits) for both the autoencoder and the corresponding classification model. This provides a measure on the best possible result for each method, but is of course not a valid approach for model selection. We report in Fig. 6 the training results for seeds 1 to 10 and summarize the training performance by plotting the mean and standard deviation per epoch per method. Our approach converges more robustly and consistently to a better mean accuracy. For each experiment, we retrieve the best accuracy across all epochs and compute the mean, standard deviation and maximum of these values across all runs: these statistics are reported in Table 2. See the appendix for training from scratch and Densenet121 results. The model weights corresponding to the epochs selected by the previous heuristics were applied on the SVIRO dataset to verify whether the learned representations are universally applicable to other vehicle interiors. For SVIRO, we used the training images and excluded all images containing empty child seats or empty infant seats, treated everyday objects as background. The results show that our E-AE significantly outperforms the classification models across three different pre-trained models and across all datasets. A consistent improvement for the different modifications is achieved: I-E-TAE outperforms E-TAE and II-E-TAE outperforms I-E-TAE.
135
+
136
+ # 5 DISCUSSION AND LIMITATIONS
137
+
138
+ We want to highlight that most of the contribution to the success of our introduced model variations stems from the novel II variation of the PIRL loss. To this end we trained several types of classifiers in the latent space of different autoencoder model variations and report the results in Table 3. The II variation of the PIRL loss largely improves the classification accuracy compared to the I variation. Moreover, the performance is better compared to the triplet loss variation which uses the label information explcitily as a latent space constraints, compared to the implicit use by the II-PIRL.
139
+
140
+ Table 2: For each experiment, the best accuracy on real TICaM images across all epochs is taken and the mean, standard deviation and maximum of those values across all 10 runs is reported. The model weights achieving maximum performance per run on TiCAM are evaluated on SVIRO. Our approach outperforms the corresponding classification models significantly.
141
+
142
+ <table><tr><td></td><td></td><td colspan="2">TICaM</td><td colspan="2">SVIRO</td></tr><tr><td>Model</td><td>Variant</td><td>Mean</td><td>Max</td><td>Mean</td><td>Max</td></tr><tr><td>VGG-11</td><td>Pre-trained</td><td>75.5 ± 1.5</td><td>78.0</td><td>78.7± 2.9</td><td>84.0</td></tr><tr><td>Resnet-50</td><td>Pre-trained</td><td>78.1 ± 1.7</td><td>80.4</td><td>83.5 ± 2.7</td><td>88.1</td></tr><tr><td>VGG-11 Resnet-50</td><td>E-TAE E-TAE</td><td>76.7± 2.3 83.8 ± 1.3</td><td>81.5 86.0</td><td>78.6 ± 2.6 85.8± 2.4</td><td>82.3</td></tr><tr><td></td><td></td><td></td><td></td><td></td><td>89.1</td></tr><tr><td>VGG-11</td><td>I-E-TAE</td><td>79.7 ± 2.1</td><td>82.2</td><td>80.9 ± 4.0</td><td>85.6</td></tr><tr><td>Resnet-50</td><td>I-E-TAE</td><td>83.5 ± 1.3</td><td>85.6</td><td>89.2 ± 1.0</td><td>90.3</td></tr><tr><td>VGG-11</td><td>II-E-TAE</td><td>81.0± 0.6</td><td>82.0</td><td>79.1± 3.9</td><td>84.8</td></tr><tr><td>Resnet-50</td><td>II-E-TAE</td><td>83.7± 0.5</td><td>84.5</td><td>93.0± 0.8</td><td>94.1</td></tr></table>
143
+
144
+ Table 3: For each of the 10 experimental runs per method after 250 epochs (i.e. not the best model weights per training were selected) and using the VGG-11 extractor we trained different classifiers in the latent space: $\mathbf { k }$ -nearest neighbour (KNN), random forest (RForest) and support vector machine with a linear kernel (SVM). The results show that most of the contribution to the synthetic to real generalization is due to the novel II variation of the PIRL cost function.
145
+
146
+ <table><tr><td></td><td colspan="3">TICaM</td><td colspan="3">SVIRO</td></tr><tr><td>Variant</td><td>KNN</td><td>RForest</td><td>SVM</td><td>KNN</td><td>RForest</td><td>SVM</td></tr><tr><td>E-AE</td><td>17.1 ± 6.7</td><td>24.2 ± 4.1</td><td>40.6 ± 8.5</td><td>38.7 ± 2.9</td><td>58.2 ± 2.0</td><td>72.9 ± 2.3</td></tr><tr><td>I-E-AE</td><td>18.2 ± 7.3</td><td>42.4± 6.5</td><td>50.1± 3.7</td><td>61.0 ± 3.5</td><td>72.2 ± 2.5</td><td>73.8 ± 2.3</td></tr><tr><td>II-E-AE</td><td>73.2 ± 3.9</td><td>68.8 ± 5.7</td><td>66.9 ± 6.7</td><td>83.7 ±1.9</td><td>79.8± 2.7</td><td>81.4± 2.2</td></tr><tr><td>E-TAE</td><td>69.2 ± 3.4</td><td>66.4± 4.0</td><td>68.7 ± 2.2</td><td>76.2 ± 2.3</td><td>71.2 ± 2.5</td><td>75.3 ± 2.5</td></tr></table>
147
+
148
+ The II variation of the PIRL loss implicitly assumes that the classes are uni-modal, i.e. objects of the same class should be mapped onto a similar point in the latent space. This characteristic can either improve generalization or have a detrimental effect on the performance depending on the task to be solved. Under its current form there is no guarantee that, for example, facial landmarks or poses would be presereved. Nevertheless, we believe that extensions of our proposed loss, for example based on constraints (e.g. preservation of poses) could be an interesting direction for future work. It can be observed that our model is not perfect and sometimes struggles: e.g. in case an object (e.g. backpack) is located on the seat and for more complex human poses (e.g. people turning over). However, we believe that these problems are related to the training data: a more versatile synthetic dataset would probably improve the model performance on more challenging real images.
149
+
150
+ Finally, we show that improvements reported in this work are not limited to the application in the vehicle interior. To this end, we trained models using the same design choices on MNIST LeCun et al. (1998) and evaluate the generalization onto real digits De Campos et al. (2009) in Fig. 12 and Table 10 in the appendix: similar improvements by the different design choices can be observed.
151
+
152
+ # 6 CONCLUSION
153
+
154
+ We introduced an autoencoder model which uses a pre-trained classification model as a feature extractor. Our results showed that the resulting model produces superior reconstructions for synthetic to real generalization. However, we highlighted that design choices made on simple datasets do not necessarily transfer to visually more complex tasks. We performed a step-by-step investigation of additional model changes and showcased the improvements of each change. Although only a simple $\mathbf { k }$ -nearest neigbor classifier is being used in the latent space, our proposed autoencoder model outperforms consistently and more robustly all classification model counterparts.
155
+
156
+ # REPRODUCIBILITY STATEMENT
157
+
158
+ Reproducibility of our results is ensured by the code implementation provided in the supplementary material. Moreover, the model weights for all results reported in this work are available for download (anonymously): see the readme file in the supplementary material for download links. This readme file also explains how the code implementation can be used and how the results of the paper can be reproduced. The code implementation contains all the evaluation scripts necessary to get the results reported in this work. The appendix contains additional details about the training and models details as well as the datasets and data pre-processing part. For the latter, we also implemented preprocessing functions for all datasets used in our work together with links to the different datasets to download them. The datasets used in this work are all publicly available. The newly created dataset used in this work is also readily available for download. Lastly, the licenses of all datasets used are detailed in the readme file as well.
159
+
160
+ # CODE OF ETHICS
161
+
162
+ Our proposed improvements on reducing the performance gap between synthetic and real images could reduce the necessity for human labelling and improve privacy since fewer human subjects are needed for data recordings. It would reduce the financial investment and time investment of companies, institutions and individuals. The question arises whether the usage of a pre-trained extractor introduces biases in the sub-sequent model, whether better disentanglement properties can be achieved and how it is affected by the choice of the latter. The first part of this work investigates model design choices on a simpler dataset without human subjects. The second part investigates the application in the vehicle interior. According to the authors of the TICaM dataset, written consent of the human participants was obtained together with their signature. Regarding the application in the vehicle interior - insights and improvements for the transfer from synthetic to real could be used to cover important edge cases (e.g. accidents) by simulations such that security and safety could be improved. The licenses for all publicly available datasets used in this work is referenced as well.
163
+
164
+ # REFERENCES
165
+
166
+ Ilge Akkaya, Marcin Andrychowicz, Maciek Chociej, Mateusz Litwin, Bob McGrew, Arthur Petron, Alex Paino, Matthias Plappert, Glenn Powell, Raphael Ribas, et al. Solving rubik’s cube with a robot hand. arXiv preprint arXiv:1910.07113, 2019.
167
+
168
+ Vassileios Balntas, Edgar Riba, Daniel Ponsa, and Krystian Mikolajczyk. Learning local feature descriptors with triplets and shallow convolutional neural networks. In British Machine Vision Conference (BMVC), 2016.
169
+
170
+ Paul Bergmann, Sindy Lowe, Michael Fauser, David Sattlegger, and Carsten Steger. Improving un- ¨ supervised defect segmentation by applying structural similarity to autoencoders. arXiv preprint arXiv:1807.02011, 2018.
171
+
172
+ Alex Bewley, Jessica Rigley, Yuxuan Liu, Jeffrey Hawke, Richard Shen, Vinh-Dieu Lam, and Alex Kendall. Learning to drive from simulation without real world labels. In IEEE International Conference on Robotics and Automation (ICRA), 2019.
173
+
174
+ Alexandra Carlson, Katherine A Skinner, Ram Vasudevan, and Matthew Johnson-Roberson. Sensor transfer: Learning optimal sensor effect image augmentation for sim-to-real domain adaptation. IEEE Robotics and Automation Letters (RA-L), 2019.
175
+
176
+ Wuyang Chen, Zhiding Yu, Zhangyang Wang, and Animashree Anandkumar. Automated syntheticto-real generalization. In International Conference on Machine Learning (ICML, 2020.
177
+
178
+ Teofilo Em ´ ´ıdio De Campos, Bodla Rakesh Babu, Manik Varma, et al. Character recognition in natural images. Proceedings of the International Conference on Computer Vision Theory and Applications (VISAPP), 2009.
179
+
180
+ Steve Dias Da Cruz, Oliver Wasenmuller, Hans-Peter Beise, Thomas Stifter, and Didier Stricker. ¨ Sviro: Synthetic vehicle interior rear seat occupancy dataset and benchmark. In Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision (WACV), 2020.
181
+
182
+ Steve Dias Da Cruz, Bertram Taetz, Thomas Stifter, and Didier Stricker. Illumination normalization by partially impossible encoder-decoder cost function. In Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision (WACV), 2021.
183
+
184
+ Steve Dias Da Cruz, Bertram Taetz, Oliver Wasenmuller, Thomas Stifter, and Didier Stricker. Au- ¨ toencoder based inter-vehicle generalization for in-cabin occupant classification. In IEEE Intelligent Vehicles Symposium (IV), 2021.
185
+
186
+ Martin Engelcke, Adam R. Kosiorek, Oiwi Parker Jones, and Ingmar Posner. Genesis: Generative scene inference and sampling with object-centric latent representations. In International Conference on Learning Representations (ICLR), 2020.
187
+
188
+ Kuan Fang, Yunfei Bai, Stefan Hinterstoisser, Silvio Savarese, and Mrinal Kalakrishnan. Multi-task domain adaptation for deep learning of instance grasping from simulation. In IEEE International Conference on Robotics and Automation (ICRA), 2018.
189
+
190
+ Muhammad Waleed Gondal, Manuel Wuthrich, Djordje Miladinovic, Francesco Locatello, Martin Breidt, Valentin Volchkov, Joel Akpo, Olivier Bachem, Bernhard Scholkopf, and Stefan Bauer. ¨ On the transfer of inductive bias from simulation to the real world: a new disentanglement dataset. In Advances in Neural Information Processing Systems (NeurIPS), 2019.
191
+
192
+ Fang Gongfan. Pytorch ms-ssim. https://github.com/VainF/pytorch-msssim, 2019.
193
+
194
+ Irina Higgins, Loic Matthey, Arka Pal, Christopher Burgess, Xavier Glorot, Matthew Botvinick, Shakir Mohamed, and Alexander Lerchner. beta-vae: Learning basic visual concepts with a constrained variational framework. In International Conference on Learning Representations (ICLR), 2017.
195
+
196
+ Stefan Hinterstoisser, Vincent Lepetit, Paul Wohlhart, and Kurt Konolige. On pre-trained image features and synthetic images for deep learning. In Proceedings of the European Conference on Computer Vision (ECCV) Workshops, 2018.
197
+
198
+ Daniel Ho, Kanishka Rao, Zhuo Xu, Eric Jang, Mohi Khansari, and Yunfei Bai. Retinagan: An object-aware approach to sim-to-real transfer. arXiv preprint arXiv:2011.03148, 2020.
199
+
200
+ Elad Hoffer and Nir Ailon. Deep metric learning using triplet network. In International Workshop on Similarity-Based Pattern Recognition (SIMBAD), 2015.
201
+
202
+ Tadanobu Inoue, SLINEMOD ubhajit Choudhury, Giovanni De Magistris, and Sakyasingha Dasgupta. Transfer learning from synthetic to real images using variational autoencoders for precise position detection. In IEEE International Conference on Image Processing (ICIP), 2018.
203
+
204
+ Marcel Jirina, MJ Jirina, and K Funatsu. Classifiers based on inverted distances. In New fundamental technologies in data mining, volume 1, pp. 369–387. InTech, 2011.
205
+
206
+ Katie Kang, Suneel Belkhale, Gregory Kahn, Pieter Abbeel, and Sergey Levine. Generalization through simulation: Integrating simulated and real data into deep reinforcement learning for vision-based autonomous flight. In IEEE International Conference on Robotics and Automation (ICRA), 2019.
207
+
208
+ Jigyasa Singh Katrolia, Bruno Mirbach, Ahmed El-Sherif, Hartmut Feld, Jason Rambach, and Didier Stricker. Ticam: A time-of-flight in-car cabin monitoring dataset, 2021.
209
+
210
+ Hyunjik Kim and Andriy Mnih. Disentangling by factorising. In International Conference on Machine Learning (ICML), 2018.
211
+
212
+ Diederik P Kingma and Max Welling. Auto-encoding variational bayes. In International Conference on Learning Representations (ICLR), 2014.
213
+
214
+ Yann LeCun, Leon Bottou, Yoshua Bengio, and Patrick Haffner. Gradient-based learning applied to ´ document recognition. Proceedings of the IEEE, 1998.
215
+
216
+ Joonho Lee, Jemin Hwangbo, Lorenz Wellhausen, Vladlen Koltun, and Marco Hutter. Learning quadrupedal locomotion over challenging terrain. Science Robotics, 5(47), 2020.
217
+
218
+ Xingang Pan, Ping Luo, Jianping Shi, and Xiaoou Tang. Two at once: Enhancing learning and generalization capacities via ibn-net. In Proceedings of the European Conference on Computer Vision (ECCV), 2018.
219
+
220
+ Xingchao Peng, Ben Usman, Neela Kaushik, Judy Hoffman, Dequan Wang, and Kate Saenko. Visda: The visual domain adaptation challenge, 2017.
221
+
222
+ Kanishka Rao, Chris Harris, Alex Irpan, Sergey Levine, Julian Ibarz, and Mohi Khansari. Rlcyclegan: Reinforcement learning aware simulation-to-real. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), 2020.
223
+
224
+ David W. Romero and Mark Hoogendoorn. Co-attentive equivariant neural networks: Focusing equivariance on transformations co-occurring in data. In International Conference on Learning Representations (ICLR), 2020.
225
+
226
+ Josh Tobin, Rachel Fong, Alex Ray, Jonas Schneider, Wojciech Zaremba, and Pieter Abbeel. Domain randomization for transferring deep neural networks from simulation to the real world. In IEEE/RSJ International Conference on Intelligent Robots and Systems (IROS), 2017.
227
+
228
+ Jonathan Tremblay, Aayush Prakash, David Acuna, Mark Brophy, Varun Jampani, Cem Anil, Thang To, Eric Cameracci, Shaad Boochoon, and Stan Birchfield. Training deep networks with synthetic data: Bridging the reality gap by domain randomization. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR) Workshops, 2018.
229
+
230
+ Sjoerd van Steenkiste, Francesco Locatello, Jurgen Schmidhuber, and Olivier Bachem. Are disen- ¨ tangled representations helpful for abstract visual reasoning? In Advances in Neural Information Processing Systems (NeurIPS), 2019.
231
+
232
+ Xiangyu Yue, Yang Zhang, Sicheng Zhao, Alberto Sangiovanni-Vincentelli, Kurt Keutzer, and Boqing Gong. Domain randomization and pyramid consistency: Simulation-to-real generalization without accessing target domain data. In Proceedings of the IEEE/CVF International Conference on Computer Vision (ICCV), 2019.
233
+
234
+ Jingwei Zhang, Lei Tai, Peng Yun, Yufeng Xiong, Ming Liu, Joschka Boedecker, and Wolfram Burgard. Vr-goggles for robots: Real-to-sim domain adaptation for visual control. IEEE Robotics and Automation Letters (RA-L), 2019.
235
+
236
+ Richard Zhang, Phillip Isola, Alexei A Efros, Eli Shechtman, and Oliver Wang. The unreasonable effectiveness of deep features as a perceptual metric. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), 2018.
237
+
238
+ Xi Zhang, Yanwei Fu, Shanshan Jiang, Leonid Sigal, and Gady Agam. Learning from synthetic data using a stacked multichannel autoencoder. In IEEE International Conference on Machine Learning and Applications (ICMLA), 2015.
239
+
240
+ Wenshuai Zhao, Jorge Pena Queralta, and Tomi Westerlund. Sim-to-real transfer in deep reinforce- ˜ ment learning for robotics: a survey. In IEEE Symposium Series on Computational Intelligence (SSCI), 2020.
241
+
242
+ # A APPENDIX
243
+
244
+ # A.1 DATASET DETAILS
245
+
246
+ If not specified otherwise, all images have been centre cropped and resized to 128 pixels.
247
+
248
+ # A.1.1 MPI3D
249
+
250
+ We used the synthetic realistic and toy images as well as the real images, but we restricted the dataset to use only large objects, since even for humans the small objects cannot always be distinguished reliably. The dataset can be downloaded from Github.
251
+
252
+ # A.1.2 SVIRO
253
+
254
+ We only used the grayscale training images from the SVIRO dataset. We considered everyday objects as background and removed all images containing empty child and infant seats. For the classification evaluation we used all the images from all the different vehicles, but we used training images only. Occupancy classification is performed on the entire image such that all three seats need to be classified simultaneously. Since four classes are available per seat (empty, infant seat, child seat and adult) this results in a total of $4 ^ { 3 } = 6 4$ classes. The dataset can be downloaded from their website.
255
+
256
+ # A.1.3 SVIRO-ILLUMINATION
257
+
258
+ For the classification evaluation we used all the training and test images from all the different vehicles. We used all the variations per scenes, i.e. not just a single variation per illumination variation. The dataset can be downloaded from their website.
259
+
260
+ # A.1.4 OUR NEWLY RELEASED DATASET
261
+
262
+ We created 2938 training and 2981 test sceneries where each scenery is rendered with 10 different backgrounds out of a pool of 450 backgrounds. The background and the corresponding illumination conditions were defined using high dynamic range images (HDRI). The latter were downloaded from https://hdrihaven.com/. Human models, child seats and infant seats were randomly placed as if they were located inside a vehicle, but no vehicle is visible. There are four possible classes for each seat position (empty, infant seat, child seat and adult) leading to a total of $4 ^ { 3 } = 6 4$ classes for the whole image. We created randomly 172 adults using http://www.makehumancommunity.org/ and we used 6 child seats and 7 infant seats which were textured using randomly one out of five textures. Since the dataset is synthetic, there are no consent and privacy concerns. We will release the dataset under the license CC BY-NC-SA 4.0. At the moment, it can be downloaded from this link (Google Drive - Anonymous user). Examples are visualized in Fig. 7. We noticed that a larger number of different human models increases the transferability to real images.
263
+
264
+ # A.1.5 TICAM
265
+
266
+ We used all training and test images and also flipped the images for the classification evaluation. This was done, because otherwise the class variability is quite low and there is a strong bias towards people sitting on the right driver seat. Moreover, the steering wheel would always be placed at the same right position. We also needed to perform some pre-processing to make the real TICaM images compatible with the synthetic images. First, we adapted the labels: we extracted the labels for the left and right seat from the filename. The file name is split at the character after which the third (right seat) and ninth (left seat) part is responsible for the class definition. If the latter was a 0 or contained an $o$ , we kept it as a 0. If it contained a $p$ , it was changed into a 3. We changed the value to 2 if it was one of the child seats s03, $s 1 3$ , $s 0 4$ , $s 1 4$ or the variation $g 0 0$ for the child seats $s 0 1$ , s11, s02, s12. In all other cases, it was transformed to a 1, i.e. for the child seats s05, s15, s06, $s 1 6$ and variations $g 0 1 g 1 1 g 1 0$ for s01, s11, s02, $s 1 2$ . Second, the illumination of the images was normalized using a histogram equalization. After that the images were cropped at height position 120 with height 300 and left position 106 with width 300. Finally, the images were resized to 128 pixels. The dataset can be downloaded from their website.
267
+
268
+ ![](images/ede576ee3ab39f781ba6de61b1d1324447567584a451def95a31a8e122ad430d.jpg)
269
+ Figure 7: Examples of sceneries with different backgrounds from the newly generated dataset.
270
+
271
+ # A.2 TRAINING DETAILS
272
+
273
+ All our experiments were conducted using PyTorch 1.8. Pre-defined and models pre-trained on Imagenet were taken from torchvision 0.9.0.
274
+
275
+ We used the same hyperparameters for all training experiments and for all autoencoder and classification models respectively. We used the AdamW optimizer with a learning rate of $1 e - 4$ and weight decay of $1 e - 5$ . We used a batch size of 64 and the only augmentation performed was a random horizontal flip. All models were trained for 100 epochs on MPI3D and 250 epochs for the other datasets.
276
+
277
+ Both the extractor autoencoder and the classification models used the same layer for extracting the features from the pre-trained models. In both cases and for all pre-trained models we used layer level $- 3$ in our implementation: those features were used to fine-tune the rest of the pretrained classification model or to train from scratch our added autoencoder layers. In all cases, we interpolated the input images to be of size 224 and copied the single grayscale image channel twice along the channel dimension.
278
+
279
+ For the autoencoder training, we used the structural similarity index measure (SSIM) Bergmann et al. (2018) or the binary cross entropy (BCE) to measure the error between reconstruction and target image. We used PyTorch MS-SSIM Gongfan (2019) to compute the SSIM. In Eq. 5 we chose $\alpha = 1$ and $\beta = 1$ . We used a latent space dimension of 64 for all models trained on the vehicle interior and a latent space dimension of 10 for the MPI3D dataset. Further, we used the ReLU activation function. In case of a triplet loss, we used the swap parameter of Pytorch to make the negative mining more challenging Balntas et al. (2016). As a positive sample, we selected an image of a different scenery of the same class, i.e. the same objects are at the same seat position. For the negative sample we selected a scenery which differs in a single seat position and we did not allow sceneries with empty seats only. In case the partially impossible reconstruction loss was used, the target images for the positive and negative samples are chosen to be partially impossible as well.
280
+
281
+ # A.2.1 MODEL DETAILS
282
+
283
+ The autoencoder model architecture details are provided in Table 4, 6 and 7. Regarding the pretrained models, we used the output of the following layers to retrieve the extracted features. The notations is according to the torchvision model definitions:
284
+
285
+ VGG-11
286
+ (16): Conv2d(512, 512, kernel_size $=$ (3, 3), stride $=$ (1, 1), padding $=$ (1, 1))
287
+ (17): ReLU(inplace=True)
288
+
289
+ Resnet-50
290
+
291
+ (5): Bottleneck( (conv1): Conv2d(1024, 256, kernel_size $=$ (1, 1), stride $=$ (1, 1), bias=False) (bn1): BatchNorm2d(256, eps=1e-05, momentum $_ { 1 = 0 }$ .1, affine=True, track_running_stats=True) (conv2): Conv2d(256, 256, kernel_size $=$ (3, 3), stride $=$ (1, 1), padding $=$ (1, 1), bias=False) (bn2): BatchNorm2d(256, ep $\displaystyle { \cdot \mathsf { s } } = 1 \mathsf { e } - 0 5$ , momentum $_ { 1 = 0 }$ .1, affine $=$ True, track_running_stats=True) (conv3): Conv2d(256, 1024, kernel_size $=$ (1, 1), stride $=$ (1, 1), bias=False) (bn3): BatchNorm2d(1024, eps $= 1 \mathrm { e } - 0 5$ , momentum=0.1, affine $=$ True, track_running_stats $=$ True) (relu): ReLU(inplace $=$ True)
292
+ )
293
+
294
+ Densenet-121
295
+
296
+ (denselayer24): _DenseLayer( (norm1): BatchNorm2d(992, eps ${ } , = { }$ 1e-05, momentum $\iota { = } 0 \cdot 1$ , affine $: =$ True, track_running_stat ${ \tt S } =$ True) (relu1): ReLU(inplace $=$ True) (conv1): Conv2d(992, 128, kernel_size $=$ (1, 1), stride $=$ (1, 1), bias=False) (norm2): BatchNorm2d(128, eps=1e-05, momentum $\iota { = } 0 \cdot 1$ , affine=True, track_running_stats=True) (relu2): ReLU(inplace $=$ True) (conv2): Conv2d(128, 32, kernel_size $=$ (3, 3), strid $: =$ (1, 1), padding $\bf { \dot { \alpha } } =$ (1, 1), bias $=$ False)
297
+ )
298
+
299
+ Table 4: Model architecture for AE, VAE and $\beta$ -VAE on MPI3D
300
+
301
+ <table><tr><td>Encoder</td><td>Decoder</td></tr><tr><td>Input: 3 x 64 x 64</td><td>Input: 10</td></tr><tr><td>Conv, 4x4, 32, padding 1, stride 2 ReLU</td><td>FC,256, bias True ReLU</td></tr><tr><td>Conv, 4x4,32, padding 1, stride 2 ReLU</td><td>FC,1024,bias True ReLU</td></tr><tr><td>Conv, 4x4, 64, padding 1, stride 2 ReLU</td><td>ConvTranspose, 4x4,64, padding 1, stride 2 ReLU</td></tr><tr><td>Conv, 4x4, 64, padding 1, stride 2 ReLU</td><td>ConvTranspose, 4x4,32, padding 1, stride 2 ReLU</td></tr><tr><td>FC,256, bias True ReLU</td><td>ConvTranspose, 4x4, 32, padding 1, stride 2 ReLU</td></tr><tr><td>FC,10, bias True (twice in case of VAE)</td><td>ConvTranspose, 4x4, 3, padding 1, stride 2 Sigmoid</td></tr></table>
302
+
303
+ Table 5: Model architecture for FactorVAE on MPI3D. The model is exactly the same as the VAE model and uses the following discriminator.
304
+
305
+ <table><tr><td rowspan=1 colspan=1>Discriminator</td></tr><tr><td rowspan=1 colspan=1>Input: 10</td></tr><tr><td rowspan=1 colspan=1>FC,1000,bias TrueLeakyReLU(0.2)</td></tr><tr><td rowspan=1 colspan=1>FC,1000, bias TrueLeakyReLU(0.2)</td></tr><tr><td rowspan=1 colspan=1>FC,1000, bias TrueLeakyReLU(0.2)</td></tr><tr><td rowspan=1 colspan=1>FC,1000,bias TrueLeakyReLU(0.2)</td></tr><tr><td rowspan=1 colspan=1>FC,1000, bias TrueLeakyReLU(0.2)</td></tr><tr><td rowspan=1 colspan=1>FC, 2, bias True</td></tr></table>
306
+
307
+ Table 6: Model architecture for E-AE on MPI3D. The extractor is fixed during training.
308
+
309
+ <table><tr><td>Extractor + Summarizer + Encoder</td><td>Decoder</td></tr><tr><td>Input: 3 x 224 x 224</td><td>Input: 10</td></tr><tr><td>VGG-11 extractor after 7th Conv layer + ReLU Avgpool, 2x2, stride 2, padding 0</td><td>FC, 256, bias True ReLU</td></tr><tr><td>Conv, 4x4,256, padding 0, stride 1 ReLU</td><td>FC,1024,bias True ReLU</td></tr><tr><td>FC,256,bias True ReLU</td><td>ConvTranspose, 4x4, 64, padding 1, stride 2 ReLU</td></tr><tr><td>FC,10, bias True</td><td>ConvTranspose, 4x4,32, padding 1, stride 2 ReLU</td></tr><tr><td></td><td>ConvTranspose, 4x4, 32, padding 1, stride 2 ReLU</td></tr><tr><td></td><td>ConvTranspose,4x4,3, padding 1, stride 2 Sigmoid</td></tr></table>
310
+
311
+ Table 7: Model architecture for E-AE on SVIRO, SVIRO-Illumination and TICaM. C is the channel dimension which is 1 for all datasets. The extractor is fixed during training.
312
+
313
+ <table><tr><td>Extractor+ Summarizer+ Encoder</td><td>Decoder</td></tr><tr><td>Input: C x 224 x 224</td><td>Input: 64</td></tr><tr><td>VGG-11 extractor after 7th Conv layer + ReLU Avgpool, 2x2, stride 2, padding 0</td><td>FC, 256, bias True ReLU</td></tr><tr><td>Conv, 4x4, 256, padding 0, stride 1 ReLU</td><td>FC, 4096,bias True ReLU</td></tr><tr><td>FC,256, bias True ReLU</td><td>ConvTranspose, 4x4, 64, padding 1, stride 2 ReLU</td></tr><tr><td>FC, 64, bias True</td><td>ConvTranspose, 4x4,32, padding 1, stride 2 ReLU</td></tr><tr><td></td><td>ConvTranspose, 4x4,32,padding 1, stride 2 ReLU</td></tr><tr><td></td><td>ConvTranspose, 4x4, C, padding 1, stride 2 Sigmoid</td></tr></table>
314
+
315
+ ![](images/9924c84adc4ef9be81f96a01eaad42978a62bc60065cb4e59248401a47ada55f.jpg)
316
+ Figure 8: t-SNE projection of the 10 dimensional latent space representation of the toy training (blue circle) together with the real (orange cross) images. Autoencoder (AE), $\beta$ Variational Autoencoder ( $\beta$ -VAE), FactorVAE and Extractor Autoencoder (E-AE). When trained on toy images, our extractor approach performs still best although the synthetic-real distributions are not as overlapped as if trained on realistic images.
317
+
318
+ Table 8: We report the L1, SSIM and LIPIPS (Zhang et al., 2018) norm between the reconstructions of the real images (unknown) and the corresponding synthetic training images (realistic or toy). We report the mean of the norms across the entire reduced dataset: for SSIM larger $\uparrow$ and for the others smaller $\downarrow$ is better. E-AE performs best. Some models used SSIM, others BCE during training.
319
+
320
+ <table><tr><td>Trained on</td><td>Model</td><td>Variant</td><td>L1↓</td><td>SSIM↑</td><td>LPIPS↓</td></tr><tr><td>Toy</td><td>AE</td><td>BCE</td><td>768</td><td>0.559</td><td>0.412</td></tr><tr><td>Toy</td><td>AE</td><td>SSIM</td><td>932</td><td>0.558</td><td>0.347</td></tr><tr><td>Toy</td><td>E-AE (ours)</td><td>BCE</td><td>291</td><td>0.896</td><td>0.095</td></tr><tr><td>Toy</td><td>E-AE (ours)</td><td>SSIM</td><td>177</td><td>0.899</td><td>0.103</td></tr><tr><td>Toy</td><td>VAE</td><td>BCE</td><td>659</td><td>0.497</td><td>0.338</td></tr><tr><td>Toy</td><td>β-VAE</td><td>BCE,β= 4</td><td>710</td><td>0.527</td><td>0.311</td></tr><tr><td>Toy</td><td>β-VAE</td><td>BCE,β=8</td><td>406</td><td>0.709</td><td>0.258</td></tr><tr><td>Toy</td><td>FactorVAE</td><td>BCE,=10</td><td>521</td><td>0.660</td><td>0.262</td></tr><tr><td>Toy</td><td>FactorVAE</td><td>BCE, = 30</td><td>447</td><td>0.710</td><td>0.344</td></tr><tr><td>Toy</td><td>FactorVAE</td><td>BCE,γ = 50</td><td>430</td><td>0.712</td><td>0.221</td></tr><tr><td>Realistic</td><td>AE</td><td>BCE</td><td>373</td><td>0.841</td><td>0.211</td></tr><tr><td>Realistic</td><td>AE</td><td>SSIM</td><td>568</td><td>0.832</td><td>0.195</td></tr><tr><td>Realistic</td><td>E-AE (ours)</td><td>BCE</td><td>220</td><td>0.917</td><td></td></tr><tr><td>Realistic</td><td>E-AE (ours)</td><td>SSIM</td><td>251</td><td>0.921</td><td>0.071</td></tr><tr><td>Realistic</td><td>VAE</td><td>BCE</td><td>482</td><td>0.740</td><td>0.081</td></tr><tr><td>Realistic</td><td>β-VAE</td><td>BCE,β= 4</td><td>372</td><td>0.810</td><td>0.197</td></tr><tr><td>Realistic</td><td>β-VAE</td><td>BCE,β=8</td><td>384</td><td>0.794</td><td>0.176</td></tr><tr><td></td><td>FactorVAE</td><td>BCE,γ= 10</td><td>218</td><td>0.880</td><td>0.189</td></tr><tr><td>Realistic</td><td>FactorVAE</td><td>BCE, = 30</td><td>244</td><td>0.862</td><td>0.151</td></tr><tr><td>Realistic</td><td></td><td></td><td>391</td><td></td><td>0.161</td></tr><tr><td>Realistic</td><td>FactorVAE</td><td>BCE,γ = 50</td><td></td><td>0.779</td><td>0.164</td></tr></table>
321
+
322
+ ![](images/de052ac8418571befb4990a43a6c1c6ce17b9723fd012ea1b9a9278659938097.jpg)
323
+ (a) Reconstruction of training data when being trained on realistic data.
324
+
325
+ ![](images/8dc8fb9439a9eb337dec11411c741edb66a8f3da019bc395d49084f900c41b13.jpg)
326
+ Figure 9: Reconstruction of realistic and toy training data for different autoencoders: Autoencoder (AE), $\beta$ Variational Autoencoder ( $\beta$ -VAE), FactorVAE (F-VAE) and Extractor Autoencoder (E-AE).
327
+
328
+ (b) Reconstruction of training data when being trained on toy data.
329
+
330
+ Table 9: For each experiment, the best performance (in percentage) on real vehicle interior images (TICaM) across all epochs is taken and then the mean and maximum of those values across all 10 runs is reported. For the same backbone model extractor, our approach outperforms the vanilla classification models significantly. The model weights achieving the maximum performance per run are also evaluated on SVIRO where they perform better as well.
331
+
332
+ <table><tr><td></td><td>Dataset</td><td colspan="2">TICaM</td><td colspan="2">SVIRO</td></tr><tr><td></td><td>Dataset size</td><td>13356</td><td></td><td>11959</td><td></td></tr><tr><td>Model</td><td>Variant</td><td>Mean</td><td>Max</td><td>Mean</td><td>Max</td></tr><tr><td>VGG-11</td><td>Scratch</td><td>58.5 ± 4.0</td><td>64.6</td><td>65.6 ± 5.4</td><td>72.7</td></tr><tr><td>Resnet-50</td><td>Scratch</td><td>53.3 ± 3.5</td><td>60.4</td><td>56.4 ± 2.6</td><td>59.3</td></tr><tr><td>Densenet-121</td><td>Scratch</td><td>56.3 ± 5.5</td><td>62.1</td><td>68.8± 2.4</td><td>74.9</td></tr><tr><td>VGG-11</td><td>Pre-trained</td><td>75.5 ± 1.5</td><td>78.0</td><td>78.7± 2.9</td><td>84.0</td></tr><tr><td>Resnet-50</td><td>Pre-trained</td><td>78.1 ± 1.7</td><td>80.4</td><td>83.5 ± 2.7</td><td>88.1</td></tr><tr><td>Densenet-121</td><td>Pre-trained</td><td>72.2 ± 4.2</td><td>77.4</td><td>85.0 ± 2.3</td><td>88.0</td></tr><tr><td>VGG-11</td><td>E-TAE</td><td>76.7 ± 2.3</td><td>81.5</td><td>78.6 ± 2.6</td><td>82.3</td></tr><tr><td>Resnet-50</td><td>E-TAE</td><td>83.8 ± 1.3</td><td>86.0</td><td>85.8 ± 2.4</td><td>89.1</td></tr><tr><td>Densenet-121</td><td>E-TAE</td><td>78.5 ± 2.4</td><td>81.8</td><td>86.7 ± 1.3</td><td>88.2</td></tr><tr><td>VGG-11</td><td>I-E-TAE</td><td>79.7 ± 2.1</td><td>82.2</td><td>80.9 ± 4.0</td><td>85.6</td></tr><tr><td>Resnet-50</td><td>I-E-TAE</td><td>83.5 ± 1.3</td><td>85.6</td><td>89.2 ± 1.0</td><td>90.3</td></tr><tr><td>Densenet-121</td><td>I-E-TAE</td><td>77.2 ± 1.7</td><td>79.3</td><td>90.4 ± 1.3</td><td>92.1</td></tr><tr><td>VGG-11</td><td>II-E-TAE</td><td>81.0 ± 0.6</td><td>82.0</td><td>79.1 ± 3.9</td><td>84.8</td></tr><tr><td>Resnet-50</td><td>II-E-TAE</td><td>83.7 ± 0.5</td><td>84.5</td><td>93.0 ± 0.8</td><td>94.1</td></tr><tr><td>Densenet-121</td><td>II-E-TAE</td><td>79.3 ± 1.3</td><td>81.5</td><td>89.9 ± 1.8</td><td>92.3</td></tr></table>
333
+
334
+ ![](images/ad6b959581948049348901aa328ca18fa4ad72ebd2d1172c214851fcdfc96631.jpg)
335
+ Figure 10: Reconstruction results of unseen real data (a) from the TICaM dataset: (b) E-AE Trained on Tesla SVIRO, (c) E-AE Trained on Kodiaq SVIRO-Illumination , (d) I-E-AE Trained on Kodiaq SVIRO-Illumination , (e) E-AE, (f) I-E-AE, (g) II-E-AE, (h) E-TAE, (i) I-E-TAE, (j) II-E-TAE and (k) Nearest neighbour of (j). Examples (e)-(k) are all trained on our new dataset. A red (wrong) or green (correct) box highlights whether the semantics are preserved by the reconstruction.
336
+
337
+ Table 10: Different model architecture variations trained on MNIST. Then different classifiers were trained on the latent space representation of the training data and evaluated on real images of digits. Models were trained for 20 epochs using a latent dimension of 64 and MSE reconstruction loss. See Fig. 12 for the corresponding reconstruction results and input images.
338
+
339
+ <table><tr><td>Model</td><td>KNN</td><td>RForest</td><td>SVM</td></tr><tr><td>AE</td><td>15.7</td><td>12.5</td><td>11.6</td></tr><tr><td>TAE</td><td>11.1</td><td>11.6</td><td>8.4</td></tr><tr><td>II-AE II-TAE</td><td>27.8 21.8</td><td>20.2 17.9</td><td>23.6 23.9</td></tr><tr><td>E-AE E-TAE</td><td>27.3</td><td>23.1</td><td>26.5</td></tr><tr><td></td><td>26.1</td><td>19.1</td><td>23.3</td></tr><tr><td>II-E-AE</td><td>65.</td><td>61.9</td><td>65.6</td></tr><tr><td></td><td></td><td></td><td></td></tr><tr><td>II-E-TAE</td><td>64.1</td><td>63.7</td><td>63.7</td></tr></table>
340
+
341
+ ![](images/2fd75823d393d13fa0676f4e49df10819d578f94fac364788433f9a3f8ab6fa9.jpg)
342
+ Figure 11: Comparison of the training performance distribution for each epoch over 250 epochs. II-E-TAE is compared against training the corresponding extractor from scratch or fine-tuning the layers after the features which are used by the extractor in our autoencoder approach.
343
+
344
+ ![](images/65ab66f3264425dbc2e561d14109b514e805afe8278d6c69e65be9b64fb7b395.jpg)
345
+ Figure 12: Reconstruction of real input images of digits by models trained on MNIST. Similar to the vehicle interior, the II-PIRL loss provides the best class preserving reconstructions. The latter is supported by the quantiative results in Table 10.
parse/dev/aUkOeKsGe2X/aUkOeKsGe2X_content_list.json ADDED
The diff for this file is too large to render. See raw diff
 
parse/dev/dFbKQaRk15w/dFbKQaRk15w.md ADDED
The diff for this file is too large to render. See raw diff
 
parse/dev/dFbKQaRk15w/dFbKQaRk15w_content_list.json ADDED
The diff for this file is too large to render. See raw diff
 
parse/dev/dFbKQaRk15w/dFbKQaRk15w_model.json ADDED
The diff for this file is too large to render. See raw diff