Datasets:
Tasks:
Question Answering
Modalities:
Image
Formats:
imagefolder
Languages:
English
Size:
100K - 1M
ArXiv:
License:
Add files using upload-large-folder tool
Browse filesFiles changed (50)
- md/train/B1lnzn0ctQ/B1lnzn0ctQ.mdAdded
- md/train/Bw7VC-DJUM/Bw7VC-DJUM.mdAdded+343
- md/train/XQQA6-So14/XQQA6-So14.mdAdded+530
- md/train/qmI0P1ZExUl/qmI0P1ZExUl.mdAdded+321
- md/train/rkEfPeZRb/rkEfPeZRb.mdAdded+233
- md/train/ry2YOrcge/ry2YOrcge.mdAdded+270
- md/train/vrhNQ7aYSdr/vrhNQ7aYSdr.mdAdded+274
- parse/test/4WnqRR915j/4WnqRR915j.mdAdded+539
- parse/test/4WnqRR915j/4WnqRR915j_content_list.jsonAdded
- parse/test/4WnqRR915j/4WnqRR915j_middle.jsonAdded
- parse/test/4WnqRR915j/4WnqRR915j_model.jsonAdded
- parse/test/8dkp41et6U/8dkp41et6U.mdAdded+378
- parse/test/8dkp41et6U/8dkp41et6U_content_list.jsonAdded
- parse/test/8dkp41et6U/8dkp41et6U_middle.jsonAdded
- parse/test/8dkp41et6U/8dkp41et6U_model.jsonAdded
- parse/test/AqN23oqraW/AqN23oqraW.mdAdded
- parse/test/AqN23oqraW/AqN23oqraW_content_list.jsonAdded
- parse/test/AqN23oqraW/AqN23oqraW_middle.jsonAdded
- parse/test/AqN23oqraW/AqN23oqraW_model.jsonAdded
- parse/test/FAO4VS9QRV/FAO4VS9QRV.mdAdded+352
- parse/test/FAO4VS9QRV/FAO4VS9QRV_content_list.jsonAdded+811
- parse/test/FAO4VS9QRV/FAO4VS9QRV_middle.jsonAdded
- parse/test/FAO4VS9QRV/FAO4VS9QRV_model.jsonAdded
- parse/test/QAwaaLJNCk/QAwaaLJNCk.mdAdded
- parse/test/QAwaaLJNCk/QAwaaLJNCk_content_list.jsonAdded
- parse/test/QAwaaLJNCk/QAwaaLJNCk_middle.jsonAdded
- parse/test/QAwaaLJNCk/QAwaaLJNCk_model.jsonAdded
- parse/test/VP20ZB6DHL/VP20ZB6DHL.mdAdded+352
- parse/test/VP20ZB6DHL/VP20ZB6DHL_content_list.jsonAdded+819
- parse/test/VP20ZB6DHL/VP20ZB6DHL_middle.jsonAdded
- parse/test/VP20ZB6DHL/VP20ZB6DHL_model.jsonAdded
- parse/test/WPZ2yPag4K/WPZ2yPag4K.mdAdded+241
- parse/test/WPZ2yPag4K/WPZ2yPag4K_content_list.jsonAdded+598
- parse/test/WPZ2yPag4K/WPZ2yPag4K_middle.jsonAdded
- parse/test/WPZ2yPag4K/WPZ2yPag4K_model.jsonAdded
- parse/test/aKkAwZB6JV/aKkAwZB6JV.mdAdded
- parse/test/aKkAwZB6JV/aKkAwZB6JV_content_list.jsonAdded
- parse/test/aKkAwZB6JV/aKkAwZB6JV_middle.jsonAdded
- parse/test/aKkAwZB6JV/aKkAwZB6JV_model.jsonAdded
- parse/test/b4tMhpN0JC/b4tMhpN0JC.mdAdded
- parse/test/b4tMhpN0JC/b4tMhpN0JC_content_list.jsonAdded
- parse/test/b4tMhpN0JC/b4tMhpN0JC_middle.jsonAdded
- parse/test/b4tMhpN0JC/b4tMhpN0JC_model.jsonAdded
- parse/test/hUgBU9wgSf/hUgBU9wgSf.mdAdded
- parse/test/hUgBU9wgSf/hUgBU9wgSf_content_list.jsonAdded
- parse/test/hUgBU9wgSf/hUgBU9wgSf_middle.jsonAdded
- parse/test/ttMwEuEPeB/ttMwEuEPeB.mdAdded
- parse/test/ttMwEuEPeB/ttMwEuEPeB_content_list.jsonAdded
- parse/test/ttMwEuEPeB/ttMwEuEPeB_middle.jsonAdded
- parse/test/ttMwEuEPeB/ttMwEuEPeB_model.jsonAdded
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343# LEARNING SPATIOTEMPORAL FEATURES VIA VIDEO AND TEXT PAIR DISCRIMINATION
Anonymous authors Paper under double-blind review
# ABSTRACT
Current video representations heavily rely on learning from manually annotated video datasets which are time-consuming and expensive to acquire. We observe videos are naturally accompanied by abundant text information such as YouTube titles and Instagram captions. In this paper, we leverage this visual-textual connection to learn spatiotemporal features in an efficient weakly-supervised manner. We present a general cross-modal pair discrimination (CPD) framework to capture this correlation between a video and its associated text. We train our CPD models on both standard video dataset (Kinetics-210k) and uncurated web video dataset (Instagram-300k) to demonstrate its effectiveness. Without further fine-tuning, the learnt models obtain competitive results for action classification on Kinetics under the linear classification protocol. Moreover, our visual model provides an effective initialization to fine-tune on downstream tasks, which yields a remarkable performance gain for action recognition on UCF101 and HMDB51, compared with the existing state-of-the-art self-supervised training methods. In addition, our CPD demonstrates that pre-training a relatively small dataset is able to yield a comparable performance to those methods of using order magnitude more data, which is meaningful and practicable for the scenarios with limited computational facilities.
# 1 INTRODUCTION
Deep learning has made a remarkable progress for visual recognition in both image and video domain (Krizhevsky et al., 2012; He et al., 2016; Carreira & Zisserman, 2017; Feichtenhofer et al., 2018) by training powerful neural networks on large-scale manually annotated datasets (e.g., ImageNet (Deng et al., 2009) and Kinetics (Kay et al., 2017)). More importantly, it is well-established that this supervised pre-training on large-scale datasets would benefit the downstream tasks (e.g., object detection (Ren et al., 2015), pose estimation (He et al., 2017), and temporal action detection (Zhao et al., 2017)), in particular when the target datasets are relatively small. Yet, annotating a large-scale dataset for training such deep neural networks is costly and time-consuming, and even more challenging for video due to its various temporal structure and complex semantics. As a result, the existing video datasets size is still smaller than ImageNet in terms of training samples and classes. On the other hand, videos typically contain richer structure with abundant side information such as motion (Diba et al., 2019; $\mathrm { N g }$ et al., 2018), audio (Arandjelovic & Zisserman, 2017; Korbar et al., 2018), and text (Miech et al., 2019; Sun et al., 2019b). So these expected these associated modalities are expected to provide useful cues to learn video representations in a more efficient way.
Language or text is probably the most natural and easy way to describe the semantic information of a video, and the associated textual information could be easily acquired when collecting video dataset (Rohrbach et al., 2017; Miech et al., 2019) from Internet or Movie. We argue that this correlation between a clip and its associated text could serve as an alternative supervision to learn video representation from scratch. This is different from some recent works (Sun et al., 2019b; Miech et al., 2019), in which these abundant textual information has been used to learn a high-level visual-text embedding applied to text-to-video retrieval or video captioning. Intuitively, it is more challenging to learn a general visual representation solely from text information without any human annotation, for reasons such as large numbers of noise in text, lacking careful initialization, and being hard to design an effective objective.
In this paper, we aim to learn effective video representation from noisy and diverse textual information, which could serves as the basis for a variety of downstream tasks. Basically, we learn a mapping of text and video into a shared embedding space and leverage their correlation as supervision signal. The technical difficulty is how to design an effective objective function, that is capable of modeling this complex visual-textual correlation and as well easily optimized by training from scratch on noisy datasets. Inspired by unsupervised feature learning in images (Wu et al., 2018; Tian et al., 2019), we present a cross-modal pair discrimination (CPD) framework, which tries to recognize each video and text pair into a class via a non-parametric classifier. To solve the computational issues imposed by the huge numbers of pair classes, we adapt noise-contrastive estimation technique (Gutmann & Hyvarinen, 2010) to approximate the original loss function. ¨
Specifically, we learn the CPD framework from web videos with the associated title or caption that could be directly crawled from web platforms such as YouTube (Kay et al., 2017) and Instagram (Duan et al., 2020). We utilize the off-the-shelf language models such as BERT (Devlin et al., 2019) or Word2vec (Mikolov et al., 2013) and devise a curriculum learning strategy to progressively train the video models. We first test the generalization ability of learned video representation by CPD on the Kinetics dataset (Kay et al., 2017) by using shallow classifiers such k-NN and linear classifier. It shows that our learned spatiotemporal features obtain promising results which are comparable to some supervised learning methods on the Kinetics dataset (Kay et al., 2017). Then, we investigate the generalization power of learned spatiotemporal features of CPD by fine-tuning on the Kinetics (Kay et al., 2017), UCF101 (Soomro et al., 2012) and HMDB51 (Kuehne et al., 2011) datasets, demonstrating that our method obtain superior performance to previous state-of-the-art self-supervised methods and comparable performance to the very recent methods of using orders of magnitude more videos (70M-100M vs. 0.3M).
# 2 RELATED WORK
Self/Weakly Supervised Representation Learning. Self supervised representation was popular in both image and video domains by designing various proxy tasks. In image domain, for instance, these tasks could be predicting the image context (Doersch et al., 2015), counting the objects (Noroozi et al., 2017), converting gray images to color one (Zhang et al., 2016), keeping global and local consistency (Hjelm et al., 2019). In video domain, typical examples include frame prediction (Diba et al., 2019; Vondrick et al., 2016), optical flow estimation $\mathrm { N g }$ et al., 2018; Zhou et al., 2017; Jayaraman & Grauman, 2017), instance tracking (Wang & Gupta, 2015; Wang et al., 2019b), temporal order or structure prediction (Misra et al., 2016; Fernando et al., 2017; Wei et al., 2018; Xu et al., 2019a). These learnt representations may capture some aspects of low-level image or video structures, but are generally outperformed by those using cross modal information.
Several cross-modal self-supervised tasks was proposed to enhance single-modality representation power and typical example is audio-visual representation learning (Aytar et al., 2016; Arandjelovic & Zisserman, 2017; Korbar et al., 2018). Meanwhile, some weakly-supervised methods were developed by utilizing web supervision obtained in an automatic way, such as query ID (Chen & Gupta, 2015; Ghadiyaram et al., 2019), and hashtag (Mahajan et al., 2018). Concurrent work (Miech et al., 2020) tried to learn video representations by using narration as supervision with instructional videos (e.g., HowTo100M (Miech et al., 2019)). However, they are limited by the video type. Our CPD is applicable to more general video type and we experiment with a much smaller dataset (0.3M vs. 100M) of both PGC and UGC videos, but achieves a similar performance on UCF101 and HMDB51. Concurrent work (Stroud et al., 2020) proposed a similar framework but required more training videos (0.3M vs. 70M) and richer textual information to obtain similar performance to ours.
Motion, Audio, and Text. Multi-modal information in videos provides natural cues for learning deep models. Motion or temporal information has been studied as to design proxy tasks to assist cross-modal learning, such as optical flow or tracking (Ng et al., 2018; Wang & Gupta, 2015), frame prediction (Diba et al., 2019; Vondrick et al., 2016), or high-level temporal structure (Wei et al., 2018; Xu et al., 2019a; Fernando et al., 2017). As most video contain synchronized audio and visual signals, audio information has served another common modality to supervised visual learning (Aytar et al., 2016; Arandjelovic & Zisserman, 2017; Korbar et al., 2018). However, both motion and audio information seem to be low-level signals and may lack high-level semantic for cross-modal learning.
Speech or text has been widely studied as another cross-modal setting in video learning (Sun et al., 2019b; Miech et al., 2019; Dong et al., 2019; Miech et al., 2018; Pan et al., 2016; Plummer et al., 2017). These works mainly aimed to learn a joint video-text embedding where visual and textual cues are adjacent if they are semantically. However, these works focused on learn high-level visualtextual embedding by using the off-the-shelf models as feature extractors. Instead, our proposed CPD framework addresses a different issue of video representation learning from scratch.
 Figure 1: The pipeline of our cross-modal pair discrimination (CPD) framework. First, the visual and text are fed into modality-specific networks for feature extraction. Then, the visual and textual features are mapped into a common 256-dimensional space. The cross-modal framework is learned via video and text pair discrimination, which tries to make corresponding pairs closer than other inconsistent pairs using a softmax criteria. The learnt spatiotemporal features could be deployed directly or fine-tuned for downstream tasks.
# 3 CROSS-MODAL PAIR DISCRIMINATION
In this section we provide an detailed description on our proposed cross-modal pair discrimination (CPD) for weakly supervised spatiotemporal feature learning. First, we present the whole framework and analyze its important properties. Then, we describe the training strategy of CPD framework. Finally, we introduce text and video feature extraction networks.
# 3.1 FRAMEWORK AND ANALYSIS
Our goal is to propose a weakly supervised representation learning method by exploiting the correlation between each video clip and its associated text information, which could be easily obtained from a variety of sources such as YouTube titles, Instagram captions and automatic speech recognition (ASR). It is generally assumed that these text information contains semantic information, but also might be noisy and irrelevant. Therefore, from technical perspective, we need to design an effective objective function and training strategy to capture this semantic correlation and as well also suppress the effect of noisy and irrelevant information. To this end, we devise a video-text pair discrimination objective and a curriculum learning strategy as follows.
More formally, as shown in Figure 1, we aim to learn a modality-specific embedding function $\mathcal { F } _ { v }$ and $\mathcal { F } _ { t }$ for the visual and textual information from a set of $N$ video clips and their associated textual information $\{ ( v _ { i } , t _ { i } ) _ { i = 1 } \} ^ { N }$ . Let $\mathbf { f } _ { i } ^ { v }$ and $\mathbf { f } _ { i } ^ { t }$ denote $\mathcal { F } _ { v } ( v _ { i } )$ and $\mathcal { F } _ { t } ( t _ { i } )$ , respectively. These embedding functions would map these two modality into a common space (i.e., $f _ { i } ^ { v } \in \mathbb { R } ^ { d }$ and $f _ { i } ^ { v } \in \mathbb { R } ^ { d } .$ ), and related visual and text information should be close to each other. The embedding functions could be implemented by neural networks which will be clarified in next section. We first focus on how to devise objective function to optimize these embedding functions. Inspired by the work of unsupervised learning in images (Wu et al., 2018), we design a cross-modal pair discrimination objective to learn these two embedding functions.
Self-instance discrimination. In the original instance-level discrimination framework ( $\mathrm { W u }$ et al., 2018), each image is treated as a distinct class and it would learn a classifier to categorize each image into its own class. This framework could be naturally extended into the setting of video and text pair by directly using feature concatenation, and we call this extension as self-instance discrimination. Formally, this video-text level instance discrimination objective could be implemented with the following softmax criterion:
$$p ( i | ( v , t ) ) = \frac { \exp ( \mathbf { w } _ { i } ^ { v T } \mathbf { f } ^ { v } + \mathbf { w } _ { i } ^ { t T } \mathbf { f } ^ { t } ) } { \sum _ { j = 1 } ^ { N } \exp ( \mathbf { w } _ { j } ^ { v T } \mathbf { f } ^ { v } + \mathbf { w } _ { j } ^ { t T } \mathbf { f } ^ { t } ) } ,$$
where the $i ^ { t h }$ video-text pair define a class $i$ , $( \mathbf { w } _ { i } ^ { v } , \mathbf { w } _ { i } ^ { t } )$ is a weight for class $i$ , and the class number is equal to training sample number $N$ . This class weight represent a class prototype for each video-text instance and is probably not easy to optimize as we only have a single sample for each class. Thus, the above parametric classifier could be refined with the following non-parametric variant:
$$p ( i | ( v , t ) ) = \frac { \exp ( \mathbf { f } _ { i } ^ { v T } \mathbf { f } ^ { v } / \tau + \mathbf { f } _ { i } ^ { t T } \mathbf { f } ^ { t } / \tau ) } { \sum _ { j = 1 } ^ { N } \exp ( \mathbf { f } _ { j } ^ { v T } \mathbf { f } ^ { v } / \tau + \mathbf { f } _ { j } ^ { t T } \mathbf { f } ^ { t } / \tau ) } ,$$
where $\tau$ is a temperature parameter to control the class concentration level and our training objective is to optimize the likelihood $\begin{array} { r } { \prod _ { i = 1 } ^ { N } p ( i | ( v _ { i } , t _ { i } ) ) } \end{array}$ . This straight forward extension shares the advantage of instance-level discrimination by directly modeling in the joint video-text space. Yet, in fact, the semantic information of text modality is higher than video pixels and we aims at learning video features with the supervision of textual information. To meet this requirement, we propose a refined objective function from the perspective of conditional distribution.
Cross-pair discrimination. According to the above analysis, we design the objective function by considering conditional distribution $p ( i _ { t } | v )$ and $p ( i _ { v } | t )$ rather than implicitly modeling distribution $p ( v , t )$ . Specifically, we design the following conditional distribution:
$$p ( i _ { t } | v ) = \frac { \exp ( \mathbf { f } _ { i } ^ { t T } \mathbf { f } ^ { v } / \tau ) } { \sum _ { j = 1 } ^ { N } \exp ( \mathbf { f } _ { j } ^ { t T } \mathbf { f } ^ { v } / \tau ) } ,$$
where $i ^ { t h }$ text define a text class $i _ { t }$ , and both $\mathbf { f } ^ { t }$ and $\mathbf { f } ^ { v }$ with unit-norm constraint. The conditional distribution $p ( i _ { v } | t )$ could be defined at the same way. We call this framework as cross-pair discrimination, and during training phase, the objective is to maximize the likelihood $\begin{array} { r } { \prod _ { i = 1 } ^ { N } p ( i _ { t } | v _ { i } ) \prod _ { i = 1 } ^ { N } p ( i _ { v } | t _ { i } ) } \end{array}$ . The key difference between Equation (2) and (3) is that we propose to use cross-correlation term $\mathbf { f } ^ { t T } \mathbf { f } ^ { v }$ to replace the self-correlation term $( \mathbf { f } ^ { v T } \mathbf { f } ^ { v } + \mathbf { f } ^ { t T } \mathbf { f } ^ { t } )$ . This cross correlation is more effective to capture the mutual information between visual and textual information, and thereby better at guiding the spatiotemporal feature learning from video with text information as supervision.
Ranking loss. There is some common ranking loss for cross-modal matching. To well study the effectiveness of proposed cross-modal pair discrimination objective, we also compare with a baseline of ranking loss, which is defined as follows:
$$\mathcal { L } ( v _ { i } , t _ { i } ) = \frac { 1 } { n - 1 } \sum _ { j \neq i } \operatorname* { m a x } ( 0 , \delta + \mathcal { S } ( \mathbf { f } _ { j } ^ { t } , \mathbf { f } _ { i } ^ { v } ) - \mathcal { S } ( \mathbf { f } _ { i } ^ { t } , \mathbf { f } _ { i } ^ { v } ) ) ,$$
where each video $v _ { i }$ has a associated text $t _ { i }$ and unrelated text $t _ { j }$ from current batch. ${ \cal { S } } ( \mathbf { f } _ { j } ^ { t } , \mathbf { f } _ { i } ^ { v } )$ is the cosine similarity, $n$ is the batch size and $\delta$ is a margin. We apply Equation (4) in both ways of video with its associated text and text with its video. In experiment, we empirically compare this ranking loss with our designed cross-pair discrimination objective.
# 3.2 TRAINING CPD
The training of CPD framework needs to address two technical issues: (1) large number of video-text pair classes; (2) optimization difficulty on noisy video-text datasets by training from scratch.
Noise-contrastive estimation. In training stage, we adopt noise-contrastive estimation technique (Gutmann & Hyvarinen, 2010) to approximate Equation (3) to solve the computational issues ¨ by the huge numbers of pairs. The basic idea is to transform the multi-class classification problem in Equation (3) into a set of binary classification problem. In the binary classification task, the task is to distinguish between data sample and noise sample. The approximate training objective is to minimize the following loss function:
$$\mathcal { L } = - \mathbb { E } _ { P ( v ) } \left\{ \mathbb { E } _ { P _ { d } ( i _ { t } | v ) } [ \log h ( i _ { t } , v ) ] + m \mathbb { E } _ { P _ { n } ( i _ { t } ^ { \prime } | v ) } [ \log \left( 1 - h ( i _ { t } ^ { \prime } , v ) \right) ] \right\} ,$$
where $\begin{array} { r } { h ( i _ { t } , v ) = \frac { p ( i _ { t } | v ) } { p ( i _ { t } | v ) + m p _ { n } ( i _ { t } | v ) } } \end{array}$ , $P _ { d } ( i _ { t } | v )$ is the actual data distribution and $P _ { n } ( i _ { t } ^ { \prime } | v )$ is the uniform distribution for noise, and $m$ denotes the noise frequency. To compute $p ( i _ { t } | v )$ efficiently and avoid large memory consumption, following $\mathbf { W } \mathbf { u }$ et al., 2018), we maintain a memory bank to store the visual and textual features for each training pair. The memory bank is updated dynamically during the training procedure.
Curriculum learning. To handle the optimization difficulty of directly training from scratch on noisy video-text dataset, we present a curriculum training strategy by resorting to the existing unsupervised pre-trained language models. To relieve the training difficulty, our curriculum learning strategy divides the training procedure into two stages. In the first stage, we fix the pre-trained language model and only update the parameters of visual model and embedding function. The motivation is that the language model is pre-trained well using corpus much larger than ours and the video model is totally trained from scratch. If we train both models simultaneously in the beginning, the random noise produced by video model will destroy the parameters of language model. In the second stage, after the good initialization of video model, we start to jointly train the visual-textual model with a smaller learning rate.
# 3.3 ARCHITECTURE DESIGN
Video architecture. For video representation, we use the 3D CNNs to extract spatiotemporal features from a video clip. Specifically, we randomly sample 8 frames from each video clip and sampling stride is 4. Following the implementation of slow stream in the recent SlowFast (Feichtenhofer et al., 2018), all filters from $c o n v _ { 1 }$ to $r e s _ { 3 }$ degenerate temporal convolutions into 2D convolution kernels and it only reserves 3D convolution kernels in $r e s _ { 4 }$ and $r e s _ { 5 }$ without temporal downsampling. We try two kinds of network architectures: (1) 3D ResNet34 trained on $1 1 2 \times 1 1 2 \times 8$ volumes and (2) 3D ResNet50 trained on $2 2 4 \times 2 2 4 \times 8$ volumes. The first tiny network is efficient for ablation study and then we transfer its optimal setting to the larger backbone and frame resolution. We also add a mapping layer to transform the visual features into 256-dimensional embedding space $\mathbf { f } ^ { v }$ and this 256-d vector is $\ell _ { 2 }$ -normalized.
Text architecture. Our textual stream subnetwork is based on the off-the-shelf language models. We choose Word2vec (Mikolov et al., 2013) and DistilBERT (Devlin et al., 2019; Sanh et al., 2019) as our textual encoders. Word2vec is an unsupervised word encoder, pre-trained by reconstructing the surrounding words of the continue sentences. We average word vectors which are 300 dimensional as textual encoder. BERT (Devlin et al., 2019) encodes long sentences by predicting the missing words given their bidirectional context, and DistilBERT achieves comparable performance with a faster and lighter model via knowledge distillation (Hinton et al., 2015). We average word embeddings of title generated by DistilBERT and obtain 768 dimensional text feature. Finally, two fully connected layers with ReLU and Batch Normalization (Ioffe & Szegedy, 2015) are added to our textual encoder to obtain textual feature $\mathbf { f } ^ { t }$ in the common embedding space, which is also $\ell _ { 2 }$ -normalized.
# 4 EXPERIMENTS
In this section, we present the experimental results of our proposed CPD framework. First, we describe the training and evaluation datasets with implementation details. Then, we conduct ablation study on our proposed CPD framework. Finally, we verify the effectiveness of CPD from two aspects: weakly-supervised representation learning and representation transfer.
# 4.1 DATASETS
In our experiment, we pre-train our CPD framework on two video-text datasets: Kinetics-210k (Kay et al., 2017) and Instagram-300k (Duan et al., 2020). Then, we fine-tune the video model on three human action datasets: Kinetics400 (Kay et al., 2017), UCF101 (Soomro et al., 2012) and HMDB51 (Kuehne et al., 2011).
Kinetics-210k. Following the recent self-supervised methods (Wang et al., $2 0 1 9 \mathrm { a }$ ; Korbar et al., 2018; Han et al., 2019), we utilize Kinetics (Kay et al., 2017) dataset for weakly-supervised pretraining of CPD. It is often called Kinetics400 since it has 400 action classes, but we count training video number as we do not use any class information for weakly-supervised representation learning. Due to invalid urls and data cleaning, the collected dataset contains around 210k video-text pairs, and thus we call this dataset as Kinetics-210k. To construct video-text pairs, we equip each clip with the video title directly crawled from YouTube, termed as Kinetics-title. As the original title may be very noisy, we pre-process the text information in two ways. First, we delete special symbols and characters such as non-English words and emoji, termed as Kinetics-title-clean. Second, we use StanfordNLP (Qi et al., 2018) to obtain the dependency tree of sentences in titles and only reserve verbs and nouns, named Kinetics-title-tree.
Instagram-300k. To avoid data bias in Kinetics caused by human annotation (i.e., trimmed videos with an action), we further verify the effectiveness our CPD model on an uncurated web video dataset (Duan et al., 2020). This new dataset is constructed from Instagram by searching action label of Kinetics-400 but without any manual filtering. Due to limited computation resource and also for fair comparison with pretraining on Kinetics-210k, we randomly sample 300k from the original web video dataset, termed as Instagram-300k.
An important difference is that the these videos are with User Generated Content (UGC) and accompanied by captions uploaded by users. Therefore, its video content distribution is much different with those in Profession Generated Content (PGC) in UCF101 and HMDB51, and the text noise is also much higher. So, it is more challenging to train a pre-trained CPD model on Instagram-300k.
UCF101 and HMDB51. We evaluate the generalization of our pre-trained models by fine-tuning on two small human action datasets: UCF101 (Soomro et al., 2012) and HMDB51 (Kuehne et al., 2011), which contain $1 3 \mathrm { k }$ videos of 101 classes and 7k video of 51 classes respectively. We report ablation study on the first split and report average performance over three splits for fair comparison.
# 4.2 IMPLEMENTATION DETAILS
Weakly supervised learning of CPD. We train our CPD model on video-text datasets and use video-text retrieval on 1k unseen video-text pairs as validation set duration training. Specifically, 8 frames are sampled from each video clip and the sampling stride is 4. We use SGD to optimize our objective and the training parameters include a momentum of 0.9 and 1e-4 for weight decay. We set temperature parameter $\tau = 0 . 0 7$ and noise frequency $m$ to 4096. In the beginning, we fix the pre-trained language model and the learning rate is set as 0.2. When the retrieval performance on validation set saturates (170 epochs for 3D ResNet34 and 110 epochs for 3D ResNet50), we start to update the language model with learning rate of 3e-5 and decrease the rest learning rate to 0.02. The maximize training number is 250 epochs. For input size of $1 1 2 \times 1 1 2 \times 8$ , the mini-batch size is 64 clips per GPUs and 16 clips per GPUs for input size of $2 2 4 \times 2 2 4 \times 8$ . We use 8 GPUs for training.
Evaluation on representation learning. We first verify our CPD learned representation by employing a shallow classifier on frozen features. Specifically, we utilize $\mathbf { k }$ -Nearest Neighbor (kNN) and linear classifier based on extracted features for classification. For video feature extraction, we sample 10 clips from each video and each clip contains 8 frames with 4 sampling stride. The 256- dimensional embedding feature and the output of global average pooling are extracted as features. The extracted features over 10 clips in a video are averaged as a video-level representation. We choose cosine distance as distance metric in kNN and set $k = 2 5$ . As for linear classifier, a fully connected layer after Batch Normalization is added with cross-entropy loss. We adopt Adam with learning rate of 1e-3 and reduce by a factor of 10 every 10 epochs, stopping at 30 epochs.
Evaluation on representation transfer. A main goal of representation learning is to transfer them to downstream tasks. We fine-tune the learned spatiotemporal representation on the UCF101, HMDB51 and a small fraction of Kinetics400. During fine-tuning, 16 frames with stride 4 are sampled as input. We simply replace the embedding layer of video model with a new fully-connected layer and multi-way softmax for action recognition. The classifier is trained using the SGD optimizer with an initial learning rate 1e-2 and weight decay 5e-4. Learning rate is decreased twice by a factor of 10 when the validation loss saturates. During testing, for each video, we uniformly sample 10 clips and each clip contains 3 crops, following the common practice (Feichtenhofer et al., 2018).
# 4.3 ABLATION STUDY
In this study, we pre-train our CPD models on Kinetics-210k dataset and choose the task of representation transfer by fine tuning on UCF101 split 1 for evaluation.
<table><tr><td>Trainingstrategy</td><td>Accuracy(%)</td></tr><tr><td>Random init.</td><td>50.0</td></tr><tr><td>Direct fine-tuning</td><td>81.3</td></tr><tr><td>Curr. learning1</td><td>82.2</td></tr><tr><td>Curr.learning2</td><td>84.2</td></tr></table>
(b) Study on training strategies.
<table><tr><td>Textual encoder</td><td>Data</td><td>Accuracy(%)</td></tr><tr><td>Random Init.</td><td>-</td><td>50.0</td></tr><tr><td>Word2vec</td><td>Tree</td><td>83.1</td></tr><tr><td>DistilBERT</td><td>Tree</td><td>82.1</td></tr><tr><td>Word2vec</td><td>Clean</td><td>82.5</td></tr><tr><td>DistilBERT</td><td>Clean</td><td>84.2</td></tr></table>
(c) Study on textual encoders.
Table 1: Ablation study on UCF101 by fine tuning a pre-trained CPD model from Kinetics-210k.
<table><tr><td>Objective function</td><td>Accuracy(%)</td></tr><tr><td>Random init.</td><td>50.0</td></tr><tr><td>Ranking loss</td><td>79.9</td></tr><tr><td>Self-instance Dis.</td><td>51.1</td></tr><tr><td>Cross-pair Dis.</td><td>82.2</td></tr></table>
(a) Study on loss functions.
Table 2: Evaluation on weakly-supervised representation learning without fine-tuning. Top-1 classification accuracy is reported on Kinetics-400 validation set.
<table><tr><td>Backbone</td><td>Pre-trained Sup.</td><td>Layer (Dim)</td><td>KNN</td><td>LC</td></tr><tr><td>3D-ConvNet (Kay et al.,2017)</td><td>Kinetics-400Label</td><td>-</td><td>-</td><td>56.1</td></tr><tr><td>3D ResNet34 (Hara et al., 2018) 3D ResNet50 (ours)</td><td>Kinetics-400 Label Kinetics-400 Label</td><td>-</td><td>-</td><td>60.1 73.2</td></tr><tr><td>ResNet50</td><td>ImageNet Label</td><td>-</td><td>- 42.8</td><td>56.1</td></tr><tr><td>3DResNet34</td><td></td><td>res5 (2048)</td><td></td><td></td></tr><tr><td></td><td>Instagram-300k Caption</td><td>emb (256)</td><td>34.5</td><td>37.3</td></tr><tr><td>3D ResNet34</td><td>Instagram-300k Caption</td><td>res5 (512)</td><td>36.1</td><td>44.6</td></tr><tr><td>3D ResNet50</td><td>Instagram-300k Caption</td><td>emb (256)</td><td>51.1</td><td>51.7</td></tr><tr><td>3DResNet50</td><td>Instagram-300k Caption</td><td>res5 (2048)</td><td>51.1</td><td>55.4</td></tr><tr><td>3DResNet34</td><td>Kinetics-210k Title</td><td>emb (256)</td><td>49.9</td><td>50.8</td></tr><tr><td>3D ResNet34</td><td>Kinetics-210k Title</td><td>res5 (512)</td><td>50.1</td><td>53.3</td></tr><tr><td>3DResNet50</td><td>Kinetics-210k Title</td><td>emb (256)</td><td>58.0</td><td>59.6</td></tr><tr><td>3DResNet50</td><td>Kinetics-210k Title</td><td>res5 (2048)</td><td>58.2</td><td>63.8</td></tr></table>
Objective function. We compare three objective functions for cross-modal pair discrimination described in Section 3.1. We pre-train models by utilizing DistilBERT as textual encoder without finetuning and the experimental results are reported in Table 1a. Self-instance discrimination almost has no contribution to learn effective representation as there is no cross-modal correlation modeling. Cross-pair discrimination gives a better performance than ranking loss as cross-pair discrimination can construct negative video-text pairs from entire dataset while ranking loss is only optimized by negative pairs from current batch. More theoretical analysis can be found in Section. A.1 of the Appendix.
Curriculum learning. We design different training strategies from noisy video-text datasets. The first strategy is to fine-tune the pre-trained textual encoder directly at the beginning. Then we compare with stage I and stage II of curriculum learning proposed in Section 3.2. All these strategies are pre-trained on Kinetics-title-clean. The numerical results are summarized in Table 1b. Fixing the pre-trained language model gives better performance than direct fine-tuning at the beginning $( + 0 . 9 \% )$ . We ascribe this to the fact that the random noise produced by video model destroy the well pre-trained textual encoder at the beginning. Also, fine-tuning the language model after the video model is well initialized further boost the accuracy by $2 . 0 \%$ .
Different textual information. In this experiment, we choose video-text pairs from Kinetics-titletree, Kinetics-title-clean datasets and utilize Word2vec and DistilBERT as a textual extractor. The experimental results are reported in Table 1c. For textual encoder, abundant and video-specific text information benefits to train our CPD model with stronger language model such as DistilBERT according to the performance difference between Kinetics-title-tree and Kinetics-title-clean $( 8 2 . 1 \%$ vs. $8 4 . 2 \%$ ). As for shallow textual encoder (e.g., Word2vec), simple text information from Kineticstitle-tree dataset gives better performance than abundant text information $( 8 3 . 1 \%$ vs. $8 2 . 5 \%$ ). From above observation, it can be concluded that Word2vec is more good at concise and accurate text while DistilBERT can handle more complex and noisy sentences which is close to realistic setting. Also, it is affordable to utilize strong language models due to our curriculum learning strategy and lightweight DistilBERT model.
# 4.4 EVALUATION ON REPRESENTATION LEARNING
To evaluate our learned representation, we report the classification performance on validation set of Kinetics via training shallow classifiers on frozen features as shown in Table 4.3. We perform kNN classifiers and linear classifiers (LC) on the embedding features or visual features from global average pooling after res5. In this shallow learning setting, we also compare with ImageNet pretraining representation (ResNet50) by using the same classifier. First, the representation learnt from
Table 3: Evaluation on representation transfer by fine-tuning. We compare our CPD model with other methods trained on different type of supervision.
<table><tr><td>Method</td><td>Supervision</td><td>Backbone</td><td>Pre-trained Dataset</td><td>UCF101</td><td>HMDB51</td></tr><tr><td>RandomInit. (Hara etal.,2018)</td><td></td><td>3DResNet18</td><td></td><td>42.4</td><td>17.1</td></tr><tr><td>Kinetics Pre-trained (Hara etal., 2018)</td><td>Action label</td><td>3DResNet50</td><td>Kinetics</td><td>89.3</td><td>61.0</td></tr><tr><td>Supervised SOTA (Xie et al.,2018)</td><td>Action label</td><td>S3D</td><td>Kinetics</td><td>96.8</td><td>75.9</td></tr><tr><td>Shuffle& Learn (Misra et al.,2016)</td><td>Order verification</td><td>CaffeNet</td><td>UCF101/HMDB51</td><td>50.2</td><td>18.1</td></tr><tr><td>OPN (Lee et al., 2017)</td><td>Sequence order</td><td>VGGNet</td><td>UCF101/HMDB51</td><td>59.8</td><td>23.8</td></tr><tr><td>CMC (Tian et al., 2019)</td><td>Optical flow</td><td>CaffeNet</td><td>UCF101</td><td>55.3</td><td>-</td></tr><tr><td>O3N (Fernando et al.,2017)</td><td>Odd-one-out</td><td>AlexNet</td><td>UCF101</td><td>60.3</td><td>32.5</td></tr><tr><td>MASN (Wang et al.,2019a)</td><td>Motion</td><td>C3D</td><td>Kinetics-400</td><td>61.2</td><td>33.4</td></tr><tr><td>COP (Xu et al.,2019b)</td><td>Clip order</td><td>3D ResNet10</td><td>UCF101</td><td>64.9</td><td>29.5</td></tr><tr><td>DPC (Han et al.,2019)</td><td>Prediction</td><td>3DResNet34</td><td>Kinetics-400</td><td>75.7</td><td>35.7</td></tr><tr><td>CBT(Sun et al.,2019a)</td><td>Audio(Text)/Context</td><td>S3D</td><td>Kinetics-600</td><td>79.5</td><td>44.6</td></tr><tr><td>AVTS (Korbar et al.,2018)</td><td>Audio</td><td>I3D</td><td>Kinetics-600</td><td>83.7</td><td>53.0</td></tr><tr><td>AVTS (Korbar et al., 2018)</td><td>Audio</td><td>MC3</td><td>Audioset-1.8M</td><td>89.0</td><td>61.6</td></tr><tr><td>XDC (Alwassel et al.,2019)</td><td>Audio</td><td>R(2+1)D</td><td>Kinetics-400</td><td>84.2</td><td>47.1</td></tr><tr><td>XDC (Alwassel et al.,2019)</td><td>Audio</td><td>R(2+1)D</td><td>IG-65M</td><td>91.5</td><td>63.1</td></tr><tr><td>MIL-NCE (Miech et al., 2020)</td><td>Audio(Text)</td><td>S3D</td><td>HT-100M</td><td>91.3</td><td>61.0</td></tr><tr><td>TWS (Stroud et al.,2020)</td><td>Text (Title,Des,Tag etc.)</td><td>S3D-G</td><td>WVT-70M</td><td>90.3</td><td>65.3</td></tr><tr><td>CPD (Ours)</td><td>Caption</td><td>3DResNet50</td><td>Instagram300k</td><td>89.9</td><td>63.8</td></tr><tr><td>CPD (Ours)</td><td>Title</td><td>3DResNet50</td><td>Kinetics210k</td><td>90.5</td><td>63.6</td></tr></table>
Kinetics-210k generally outperforms that of Instagram- $3 0 0 \mathrm { k }$ . The reason could be ascribed to the video distribution gap between UGC (Instagram) and PGC (Youtube), and also much noisier textual information in Instagram-300k. Second, we compare with ImageNet pretrained features, and our CPD representation is better under the same backbone. Finally, we compare with some end-toend trained representations with action labels, and there is still a performance gap between our representation and supervised end-to-end representation (e.g. $6 3 . 8 \%$ vs. $7 3 . 2 \%$ ).
# 4.5 EVALUATION ON REPRESENTATION TRANSFER
Transferring learned representation to downstream tasks is a main goal of representation learning. We transfer them to action recognition task on small datasets, namely UCF101 and HMDB51. We compare our CPD model pre-trained on Instagram-300k and Kinetics-210k with a randomly initialized network, self-supervised methods solely based on visual information, including Shuffle & Learn (Misra et al., 2016), CMC (Tian et al., 2019), MASN (Wang et al., 2019a), COP (Xu et al., 2019b), DPC (Han et al., 2019) and so on, and representation learning methods based on multimodal information (e.g., audio, text), including CBT (Sun et al., 2019a), AVTS (Korbar et al., 2018), XDC (Alwassel et al., 2019), MIL-NCE (Stroud et al., 2020), and TWS (Stroud et al., 2020).
As shown in Table 3, our CPD models generally outperform those self-supervised learning approaches of only using visual information $( \geq 1 0 \%$ on UCF101 and $\geq 2 0 \%$ on HMDB51), which indicates that cross-modal information is useful cue for visual representation learning. Meanwhile, our CPD representations obtain comparable performance to the concurrent works (i.e., MIL-NCE and TWS) of using text as weak supervision. However, our CPD uses a much smaller pre-training dataset of around 0.3M videos, while the other methods uses 70M-100M videos. Training a CPD model on a such large-scale dataset is almost impossible for a university lab with limited computational facilities. Our work demonstrates that pre-training a relatively small video-text dataset is also possible to match the SOTA performance, and this is quite meaningful and practicable for university lab. Finally, we notice that the gap of CPD models learned from Instagram- ${ 3 0 0 } \mathrm { k }$ and Kinetics- ${ \it 2 0 0 k }$ is very small, indicating that our CPD model can effectively handle high noise in text.
# 5 CONCLUSION
In this paper, we have presented a general cross-modal pair discrimination (CPD) framework to capture the correlation between a video clip and its associated text from real word and adopt noisecontrastive estimation to approximate the objective. Without fine-tuning, the learned models obtain competitive results for action classification on Kinetics dataset with a shallow classifier. Also, our visual models provide an effective initialization to fine-tune on the datasets of downstream task, and matches the state-of-the-art performance with a much smaller pre-training dataset.
# REFERENCES
Humam Alwassel, Dhruv Mahajan, Lorenzo Torresani, Bernard Ghanem, and Du Tran. Selfsupervised learning by cross-modal audio-video clustering. CoRR, abs/1911.12667, 2019. URL http://arxiv.org/abs/1911.12667.
Relja Arandjelovic and Andrew Zisserman. Look, listen and learn. In IEEE International Conference on Computer Vision, ICCV 2017, Venice, Italy, October 22-29, 2017, pp. 609–617, 2017.
Yusuf Aytar, Carl Vondrick, and Antonio Torralba. Soundnet: Learning sound representations from unlabeled video. In Advances in Neural Information Processing Systems 29: Annual Conference on Neural Information Processing Systems 2016, December 5-10, 2016, Barcelona, Spain, pp. 892–900, 2016.
Joao Carreira and Andrew Zisserman. Quo vadis, action recognition? A new model and the kinetics ˜ dataset. In 2017 IEEE Conference on Computer Vision and Pattern Recognition, CVPR 2017, Honolulu, HI, USA, July 21-26, 2017, pp. 4724–4733, 2017.
Xinlei Chen and Abhinav Gupta. Webly supervised learning of convolutional networks. In 2015 IEEE International Conference on Computer Vision, ICCV 2015, Santiago, Chile, December 7- 13, 2015, pp. 1431–1439, 2015.
Jia Deng, Wei Dong, Richard Socher, Li-Jia Li, Kai Li, and Fei-Fei Li. Imagenet: A large-scale hierarchical image database. In 2009 IEEE Computer Society Conference on Computer Vision and Pattern Recognition (CVPR 2009), 20-25 June 2009, Miami, Florida, USA, pp. 248–255, 2009.
Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. BERT: pre-training of deep bidirectional transformers for language understanding. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, NAACL-HLT 2019, Minneapolis, MN, USA, June 2-7, 2019, Volume 1 (Long and Short Papers), pp. 4171–4186, 2019.
Ali Diba, Vivek Sharma, Luc Van Gool, and Rainer Stiefelhagen. Dynamonet: Dynamic action and motion network. CoRR, abs/1904.11407, 2019.
Carl Doersch, Abhinav Gupta, and Alexei A. Efros. Unsupervised visual representation learning by context prediction. In 2015 IEEE International Conference on Computer Vision, ICCV 2015, Santiago, Chile, December 7-13, 2015, pp. 1422–1430, 2015.
Jianfeng Dong, Xirong Li, Chaoxi Xu, Shouling Ji, Yuan He, Gang Yang, and Xun Wang. Dual encoding for zero-example video retrieval. In IEEE Conference on Computer Vision and Pattern Recognition, CVPR 2019, Long Beach, CA, USA, June 16-20, 2019, pp. 9346–9355, 2019.
Haodong Duan, Yue Zhao, Yuanjun Xiong, Wentao Liu, and Dahua Lin. Omni-sourced weblysupervised learning for video recognition. CoRR, abs/2003.13042, 2020.
Christoph Feichtenhofer, Haoqi Fan, Jitendra Malik, and Kaiming He. Slowfast networks for video recognition. CoRR, abs/1812.03982, 2018.
Basura Fernando, Hakan Bilen, Efstratios Gavves, and Stephen Gould. Self-supervised video representation learning with odd-one-out networks. In 2017 IEEE Conference on Computer Vision and Pattern Recognition, CVPR 2017, Honolulu, HI, USA, July 21-26, 2017, pp. 5729–5738, 2017.
Deepti Ghadiyaram, Du Tran, and Dhruv Mahajan. Large-scale weakly-supervised pre-training for video action recognition. In IEEE Conference on Computer Vision and Pattern Recognition, CVPR 2019, Long Beach, CA, USA, June 16-20, 2019, pp. 12046–12055, 2019.
Michael Gutmann and Aapo Hyvarinen. Noise-contrastive estimation: A new estimation principle ¨ for unnormalized statistical models. In Proceedings of the Thirteenth International Conference on Artificial Intelligence and Statistics, AISTATS 2010, Chia Laguna Resort, Sardinia, Italy, May 13-15, 2010, pp. 297–304, 2010.
Tengda Han, Weidi Xie, and Andrew Zisserman. Video representation learning by dense predictive coding. CoRR, abs/1909.04656, 2019.
Kensho Hara, Hirokatsu Kataoka, and Yutaka Satoh. Can spatiotemporal 3d cnns retrace the history of 2d cnns and imagenet? In 2018 IEEE Conference on Computer Vision and Pattern Recognition, CVPR 2018, Salt Lake City, UT, USA, June 18-22, 2018, pp. 6546–6555, 2018.
Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Deep residual learning for image recognition. In 2016 IEEE Conference on Computer Vision and Pattern Recognition, CVPR 2016, Las Vegas, NV, USA, June 27-30, 2016, pp. 770–778, 2016.
Kaiming He, Georgia Gkioxari, Piotr Dollar, and Ross B. Girshick. Mask R-CNN. In ´ IEEE International Conference on Computer Vision, ICCV 2017, Venice, Italy, October 22-29, 2017, pp. 2980–2988, 2017.
Geoffrey E. Hinton, Oriol Vinyals, and Jeffrey Dean. Distilling the knowledge in a neural network. CoRR, abs/1503.02531, 2015.
R. Devon Hjelm, Alex Fedorov, Samuel Lavoie-Marchildon, Karan Grewal, Philip Bachman, Adam Trischler, and Yoshua Bengio. Learning deep representations by mutual information estimation and maximization. In 7th International Conference on Learning Representations, ICLR 2019, New Orleans, LA, USA, May 6-9, 2019, 2019.
Sergey Ioffe and Christian Szegedy. Batch normalization: Accelerating deep network training by reducing internal covariate shift. In Proceedings of the 32nd International Conference on Machine Learning, ICML 2015, Lille, France, 6-11 July 2015, pp. 448–456, 2015.
Dinesh Jayaraman and Kristen Grauman. Learning image representations tied to egomotion from unlabeled video. International Journal of Computer Vision, 125(1-3):136–161, 2017.
Will Kay, Joao Carreira, Karen Simonyan, Brian Zhang, Chloe Hillier, Sudheendra Vijaya- ˜ narasimhan, Fabio Viola, Tim Green, Trevor Back, Paul Natsev, Mustafa Suleyman, and Andrew Zisserman. The kinetics human action video dataset. CoRR, abs/1705.06950, 2017.
Bruno Korbar, Du Tran, and Lorenzo Torresani. Cooperative learning of audio and video models from self-supervised synchronization. In Advances in Neural Information Processing Systems 31: Annual Conference on Neural Information Processing Systems 2018, NeurIPS 2018, 3-8 December 2018, Montreal, Canada. ´ , pp. 7774–7785, 2018.
Alex Krizhevsky, Ilya Sutskever, and Geoffrey E. Hinton. Imagenet classification with deep convolutional neural networks. In Advances in Neural Information Processing Systems 25: 26th Annual Conference on Neural Information Processing Systems 2012. Proceedings of a meeting held December 3-6, 2012, Lake Tahoe, Nevada, United States., pp. 1106–1114, 2012.
Hildegard Kuehne, Hueihan Jhuang, Est´ıbaliz Garrote, Tomaso A. Poggio, and Thomas Serre. HMDB: A large video database for human motion recognition. In IEEE International Conference on Computer Vision, ICCV 2011, Barcelona, Spain, November 6-13, 2011, pp. 2556–2563, 2011.
Hsin-Ying Lee, Jia-Bin Huang, Maneesh Singh, and Ming-Hsuan Yang. Unsupervised representation learning by sorting sequences. In IEEE International Conference on Computer Vision, ICCV 2017, Venice, Italy, October 22-29, 2017, pp. 667–676, 2017.
Dhruv Mahajan, Ross B. Girshick, Vignesh Ramanathan, Kaiming He, Manohar Paluri, Yixuan Li, Ashwin Bharambe, and Laurens van der Maaten. Exploring the limits of weakly supervised pretraining. In Computer Vision - ECCV 2018 - 15th European Conference, Munich, Germany, September 8-14, 2018, Proceedings, Part II, pp. 185–201, 2018.
Pascal Mettes and Cees G. M. Snoek. Spatial-aware object embeddings for zero-shot localization and classification of actions. In The IEEE International Conference on Computer Vision (ICCV), Oct 2017.
Antoine Miech, Ivan Laptev, and Josef Sivic. Learning a text-video embedding from incomplete and heterogeneous data. CoRR, abs/1804.02516, 2018.
Antoine Miech, Dimitri Zhukov, Jean-Baptiste Alayrac, Makarand Tapaswi, Ivan Laptev, and Josef Sivic. Howto100m: Learning a text-video embedding by watching hundred million narrated video clips. CoRR, abs/1906.03327, 2019.
Antoine Miech, Jean-Baptiste Alayrac, Lucas Smaira, Ivan Laptev, Josef Sivic, and Andrew Zisserman. End-to-end learning of visual representations from uncurated instructional videos. In 2020 IEEE/CVF Conference on Computer Vision and Pattern Recognition, CVPR 2020, Seattle, WA, USA, June 13-19, 2020, pp. 9876–9886, 2020.
Tomas Mikolov, Kai Chen, Greg Corrado, and Jeffrey Dean. Efficient estimation of word representations in vector space. In Yoshua Bengio and Yann LeCun (eds.), 1st International Conference on Learning Representations, ICLR 2013, Scottsdale, Arizona, USA, May 2-4, 2013, Workshop Track Proceedings, 2013.
Ishan Misra, C. Lawrence Zitnick, and Martial Hebert. Shuffle and learn: Unsupervised learning using temporal order verification. In Computer Vision - ECCV 2016 - 14th European Conference, Amsterdam, The Netherlands, October 11-14, 2016, Proceedings, Part I, pp. 527–544, 2016.
Joe Yue-Hei Ng, Jonghyun Choi, Jan Neumann, and Larry S. Davis. Actionflownet: Learning motion representation for action recognition. In 2018 IEEE Winter Conference on Applications of Computer Vision, WACV 2018, Lake Tahoe, NV, USA, March 12-15, 2018, pp. 1616–1624, 2018.
Mehdi Noroozi, Hamed Pirsiavash, and Paolo Favaro. Representation learning by learning to count. In IEEE International Conference on Computer Vision, ICCV 2017, Venice, Italy, October 22-29, 2017, pp. 5899–5907, 2017.
Yingwei Pan, Tao Mei, Ting Yao, Houqiang Li, and Yong Rui. Jointly modeling embedding and translation to bridge video and language. In 2016 IEEE Conference on Computer Vision and Pattern Recognition, CVPR 2016, Las Vegas, NV, USA, June 27-30, 2016, pp. 4594–4602, 2016.
Bryan A. Plummer, Matthew Brown, and Svetlana Lazebnik. Enhancing video summarization via vision-language embedding. In 2017 IEEE Conference on Computer Vision and Pattern Recognition, CVPR 2017, Honolulu, HI, USA, July 21-26, 2017, pp. 1052–1060, 2017.
Peng Qi, Timothy Dozat, Yuhao Zhang, and Christopher D. Manning. Universal dependency parsing from scratch. In Proceedings of the CoNLL 2018 Shared Task: Multilingual Parsing from Raw Text to Universal Dependencies, pp. 160–170, Brussels, Belgium, October 2018. Association for Computational Linguistics.
Shaoqing Ren, Kaiming He, Ross B. Girshick, and Jian Sun. Faster R-CNN: towards real-time object detection with region proposal networks. In Advances in Neural Information Processing Systems 28: Annual Conference on Neural Information Processing Systems 2015, December 7-12, 2015, Montreal, Quebec, Canada, pp. 91–99, 2015.
Anna Rohrbach, Atousa Torabi, Marcus Rohrbach, Niket Tandon, Christopher Joseph Pal, Hugo Larochelle, Aaron C. Courville, and Bernt Schiele. Movie description. International Journal of Computer Vision, 123(1):94–120, 2017.
Victor Sanh, Lysandre Debut, Julien Chaumond, and Thomas Wolf. Distilbert, a distilled version of BERT: smaller, faster, cheaper and lighter. CoRR, abs/1910.01108, 2019.
Khurram Soomro, Amir Roshan Zamir, and Mubarak Shah. UCF101: A dataset of 101 human actions classes from videos in the wild. CoRR, abs/1212.0402, 2012.
Jonathan C. Stroud, David A. Ross, Chen Sun, Jia Deng, Rahul Sukthankar, and Cordelia Schmid. Learning video representations from textual web supervision. CoRR, abs/2007.14937, 2020. URL https://arxiv.org/abs/2007.14937.
Chen Sun, Fabien Baradel, Kevin Murphy, and Cordelia Schmid. Contrastive bidirectional transformer for temporal representation learning. CoRR, abs/1906.05743, 2019a.
Chen Sun, Austin Myers, Carl Vondrick, Kevin Murphy, and Cordelia Schmid. Videobert: A joint model for video and language representation learning. CoRR, abs/1904.01766, 2019b.
Yonglong Tian, Dilip Krishnan, and Phillip Isola. Contrastive multiview coding. CoRR, abs/1906.05849, 2019.
Carl Vondrick, Hamed Pirsiavash, and Antonio Torralba. Anticipating visual representations from unlabeled video. In 2016 IEEE Conference on Computer Vision and Pattern Recognition, CVPR 2016, Las Vegas, NV, USA, June 27-30, 2016, pp. 98–106, 2016.
Jiangliu Wang, Jianbo Jiao, Linchao Bao, Shengfeng He, Yunhui Liu, and Wei Liu. Self-supervised spatio-temporal representation learning for videos by predicting motion and appearance statistics. In The IEEE Conference on Computer Vision and Pattern Recognition (CVPR), June 2019a.
Xiaolong Wang and Abhinav Gupta. Unsupervised learning of visual representations using videos. In 2015 IEEE International Conference on Computer Vision, ICCV 2015, Santiago, Chile, December 7-13, 2015, pp. 2794–2802, 2015.
Xiaolong Wang, Allan Jabri, and Alexei A. Efros. Learning correspondence from the cycleconsistency of time. In IEEE Conference on Computer Vision and Pattern Recognition, CVPR 2019, Long Beach, CA, USA, June 16-20, 2019, pp. 2566–2576, 2019b.
Donglai Wei, Joseph J. Lim, Andrew Zisserman, and William T. Freeman. Learning and using the arrow of time. In 2018 IEEE Conference on Computer Vision and Pattern Recognition, CVPR 2018, Salt Lake City, UT, USA, June 18-22, 2018, pp. 8052–8060, 2018.
Zhirong Wu, Yuanjun Xiong, Stella X. Yu, and Dahua Lin. Unsupervised feature learning via nonparametric instance discrimination. In 2018 IEEE Conference on Computer Vision and Pattern Recognition, CVPR 2018, Salt Lake City, UT, USA, June 18-22, 2018, pp. 3733–3742, 2018.
Saining Xie, Chen Sun, Jonathan Huang, Zhuowen Tu, and Kevin Murphy. Rethinking spatiotemporal feature learning: Speed-accuracy trade-offs in video classification. In ECCV, pp. 318–335, 2018.
Dejing Xu, Jun Xiao, Zhou Zhao, Jian Shao, Di Xie, and Yueting Zhuang. Self-supervised spatiotemporal learning via video clip order prediction. In IEEE Conference on Computer Vision and Pattern Recognition, CVPR 2019, Long Beach, CA, USA, June 16-20, 2019, pp. 10334–10343, 2019a.
Dejing Xu, Jun Xiao, Zhou Zhao, Jian Shao, Di Xie, and Yueting Zhuang. Self-supervised spatiotemporal learning via video clip order prediction. In The IEEE Conference on Computer Vision and Pattern Recognition (CVPR), June 2019b.
Richard Zhang, Phillip Isola, and Alexei A. Efros. Colorful image colorization. In Computer Vision - ECCV 2016 - 14th European Conference, Amsterdam, The Netherlands, October 11-14, 2016, Proceedings, Part III, pp. 649–666, 2016.
Yue Zhao, Yuanjun Xiong, Limin Wang, Zhirong Wu, Xiaoou Tang, and Dahua Lin. Temporal action detection with structured segment networks. In IEEE International Conference on Computer Vision, ICCV 2017, Venice, Italy, October 22-29, 2017, pp. 2933–2942, 2017.
Tinghui Zhou, Matthew Brown, Noah Snavely, and David G. Lowe. Unsupervised learning of depth and ego-motion from video. In 2017 IEEE Conference on Computer Vision and Pattern Recognition, CVPR 2017, Honolulu, HI, USA, July 21-26, 2017, pp. 6612–6619, 2017.
# A TRAINING DETAILS OF CPD
we adopt noise-contrastive estimation technique (NCE) to approximate objective function in Equation (5) in our main paper. The purpose of NCE is to transform the multi-class classification problem into a set of binary classification problems by comparing data distribution against noise distribution. So $p _ { n }$ is noise distribution and we formalize it as a uniform distribution: $\begin{array} { r } { { p } _ { n } = \frac { 1 } { N } } \end{array}$ , where $N$ is the number of video-text pairs. $h ( i _ { t } , v )$ is the posterior probability of feature from the data distribution which means video and text are matched. $m$ is the number of negative pairs and we set it as 4096. For each video feature $\mathbf { f } ^ { v }$ , we take its related text feature $\mathbf { f } _ { i } ^ { t }$ and sample 4096 unrelated text features $\mathbf { f } _ { j } ^ { t }$ which are all from memory bank. The FPS of training videos are 30. The code of CPD will be released.
# A.1 ANALYSIS ON DIFFERENT LOSS FUNCTIONS
More insight about why our loss is better than ranking loss could be found from gradient backpropagation. Let $\mathbf { f } ^ { t + }$ and $\mathbf { f } ^ { t - }$ represent the associated and unrelated text feature. For ranking loss, the negative gradient w.r.t $\mathbf { f } ^ { v }$ is $\bar { \mathbf { f } ^ { t + } } - \mathbf { f } ^ { t - }$ if $\mathcal { L } > 0$ else 0. For CPD loss, it is $[ 1 - h ( i _ { t } ^ { + } , v ) ] / \bar { \bf \Delta } \bar { \bf f } ^ { t + } -$ $\sum h ( i _ { t } ^ { - } , v ) / \tau \mathbf { f } ^ { t - }$ . We observe our loss assign different weights to different examples based on their posterior probability $h$ , which helps learn from hard examples while the ranking loss treats them equally.
# B REPRESENTATION TRANSFER ON KINETICS
<table><tr><td rowspan="2">Method</td><td colspan="3">The Amount ofLabeled Data</td></tr><tr><td>1%</td><td>10%</td><td>20%</td></tr><tr><td>Fromscratch</td><td>0.3</td><td>10.7</td><td>33.3</td></tr><tr><td>ImageNet Inflation</td><td>12.8</td><td>36.8</td><td>45.7</td></tr><tr><td>Ours (Instagram-300k)</td><td>18.7</td><td>41.3</td><td>47.4</td></tr><tr><td>Ours (Kinetics-210k)</td><td>25.9</td><td>43.1</td><td>47.8</td></tr></table>
Table 4: Results of classification with small amount of labeled data on Kinetics-400 validation set (showing top-1 accuracy). We utilize 3D ResNet34 as backbone and pre-train it on Kinetics-210k and Instagram-210k.
Our weakly-supervised pre-trained representation can be an efficient initialization when training the model with only a small amount of labeled data. We randomly choose a small fraction of Kinetics400 training set as labeled data and fine-tune the pre-trained model on it. We report the performance of top-1 accuracy which is trained on labeled subset of $1 \%$ , $10 \%$ and $20 \%$ of the entire dataset in Table 4. We compare our method with training from scratch and ImageNet inflated model as baselines. Our method significantly surpasses the baselines on all present proportion of labeled subset especially when the amount of labeled data is extremely small. When only $1 \%$ of data is labeled, training from scratch can not learn anything yet our model achieves $1 8 . 7 \%$ and $2 5 . 9 \%$ top-1 accuracy. Both our CPD pre-trained models on Instagram and Kinetics outperform the ImageNet pre-trained models.
# C EVALUATION ON ZERO-SHOT CLASSIFICATION
We evaluate our visual-textual embedding of CPD model with zero-shot classification on UCF101 and Kinetics-400 without any fine-tuning in Table 5. We transform class labels and video clips into the same embedding space and recognize the video clip to its closest class with cosine distance. We compare our method with Mettes et al. (Mettes & Snoek, 2017) which realizes zero-shot localization and classification of human action in video via spatial-aware object embeddings on UCF101. Following (Mettes & Snoek, 2017), we select different classes for 10 times and average their accuracies for testing except the class number is 101. We outperform for every number of testing classes. For Kinetics-400, we achieve top-1 accuracy of $4 3 . 7 \%$ without fine-tuning and training label. In addition, top-1 accuracy of 20 random classes reaches to $7 4 . 4 \%$ , which shows the strong capability of our visual-textual embedding.
Table 5: Top-1 accuracy of zero-shot classification on UCF-101 and Kinetics-400. We outperform other methods without any extra labeled data and training procedure after pre-training on Kinetics210k.
<table><tr><td rowspan="2">Methods</td><td colspan="4">UCF-101</td><td colspan="4">Kinetics-400</td></tr><tr><td>Train</td><td>Test</td><td>Split</td><td>Acc.</td><td>Train</td><td>Test</td><td>Split</td><td>Acc.</td></tr><tr><td>Mettes (Mettes& Snoek,2017)</td><td>1</td><td>101</td><td>3</td><td>32.8</td><td>-</td><td>-</td><td>1</td><td>1</td></tr><tr><td>Ours(3D ResNet34)</td><td>=</td><td>101</td><td>3</td><td>40.6</td><td>=</td><td>400</td><td>1</td><td>38.2</td></tr><tr><td>Ours(3D ResNet50)</td><td>-</td><td>101</td><td>3</td><td>39.9</td><td>-</td><td>400</td><td>1</td><td>43.7</td></tr><tr><td>Mettes(Mettes& Snoek,2017)</td><td>-</td><td>50</td><td>10</td><td>40.4</td><td>-</td><td>1</td><td>1</td><td>1</td></tr><tr><td>Ours(3D ResNet34)</td><td></td><td>50</td><td>10</td><td>47.2</td><td>=</td><td>100</td><td>10</td><td>55.3</td></tr><tr><td>Ours(3D ResNet50)</td><td></td><td>50</td><td>10</td><td>44.8</td><td>=</td><td>100</td><td>10</td><td>57.4</td></tr><tr><td>Mettes (Mettes& Snoek,2017)</td><td></td><td>20</td><td>10</td><td>51.2</td><td>1</td><td>-</td><td>-</td><td>=</td></tr><tr><td>Ours(3D ResNet34)</td><td></td><td>20</td><td>10</td><td>54.4</td><td>=</td><td>20</td><td>10</td><td>73.1</td></tr><tr><td>Ours(3D ResNet50)</td><td></td><td>20</td><td>10</td><td>58.1</td><td>=</td><td>20</td><td>10</td><td>74.4</td></tr></table>
# D ANALYZE TEXT INFORMATION
# D.1 ANALYSIS ON KINETICS TITLE
Table 6: Analyze text information of Kinetics-210k datasets. At Least One: The proportion of text information that contains at least one word in action classes of Kinetics-400. All: The proportion of text information that contains the entire action class. $R e l$ : The proportion of word in text information that is relevant to action classes.
<table><tr><td>Datasets</td><td>At Least One(%)</td><td>A11(%)</td><td>Rel(%)</td></tr><tr><td>Kinetics-title-tree</td><td>90.5</td><td>44.3</td><td>46.3</td></tr><tr><td>Kinetics-title-clean</td><td>91.6</td><td>38.4</td><td>26.0</td></tr></table>
We provide an analysis of text information we used and the result in Table 6. First, there exists a large overlap between action class and text information (more than $90 \%$ for at least one word and more than $38 \%$ for complete action class). However, the titles also contain many other words and noisier information than action classes. Only $26 \%$ of words in Kinetics-title-clean are relevant to action classes.
 Figure 2: List of top 10 and bottom 10 kinetics classes sorted by the frequency of at least one word in label occurring in according title of Kinetics-title-clean dataset. Zoom in for more details. We also report the per-class accuracy of top 10 and bottom 10 classes sorted by word overlapping in Figure 2 and see that this accuracy is not positively correlated with word overlapping percentage. Finally, we provide some examples of videos and their titles from Kinetics-210k in Figure 3.
# D.2 VISUALIZATION OF INSTAGRAM CAPTION
Since videos from Instagram-300k are not annotated or filtered by human, both of their visual and textual information are very noisy. Figure 4 demonstrates some examples of videos and their associated captions. Figure 4a presents an example of high-quality video and relative accurate caption that both are about folding napkin. Many captions describe some useful information but also contain noisy text that is not related to video content (e.g., summerdays and gettingtattooed in Figure 4b and very long sentences in Figure 4d). In addition, there are some correct but not totally accurate descriptions. Figure 4c shows that the action in video is shot putting rather than spinning (appears in associated caption). Figure 4f illustrates that a person is climbing but its caption is mainly about high jumpping. Figure 4e shows that video content can also be noisy due to low video quality and shot transformation.
 Figure 3: Examples of video and title pairs from Kinetics-210k.
Bird of Paradise Napkin Fold #napkinfolding #napkinart #napkin #yellow #napkinfold #birdofparadise #kidscrafts #diy #video #tutorial #decoration #tablesetting
 Figure 4: Examples of videos and their associated captions from Instagram-300k.
#roadtrip from #britishcolumbia to #alberta. drivingallnight #mountains #trees #summer #summerdays #summerlovin #highway #music #playlist #carpoolkaraoke #notreallyasinger #butitry #gettingtattooed #buyingatruck #duoting
Day 1 of learning to spin $\circledast$ . A work in progress but having fun with it!
Good morning beautiful people of #god #grateful for another day he has given me #prayingfor #guidance and #protection in #Jesusname I #pray #amen Early #dinnersettings today #potroastbeef #bakechicken #vegetables WHAT #RICEANDPEAS WOULD YOU EAT WITH THIS? #pyjamachef #foodbloger #pyjamachef #healthyeating #alltypeoffood #lovecooking
My pets are unruly... Who wants them...??? #computerwork #selfishpets
High Jump Challenge Very funny $\textcircled { \dag }$ ?? #boulder #highjump #fitness #climbing #ninjawarrior #ninjawarriorswitzerland #challenge #funny123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530# NEURAL SPATIO-TEMPORAL POINT PROCESSES
Ricky T. Q. Chen∗ University of Toronto; Vector Institute rtqichen@cs.toronto.edu
Brandon Amos, Maximilian Nickel Facebook AI Research {bda,maxn}@fb.com
# ABSTRACT
We propose a new class of parameterizations for spatio-temporal point processes which leverage Neural ODEs as a computational method and enable flexible, highfidelity models of discrete events that are localized in continuous time and space. Central to our approach is a combination of continuous-time neural networks with two novel neural architectures, i.e., Jump and Attentive Continuous-time Normalizing Flows. This approach allows us to learn complex distributions for both the spatial and temporal domain and to condition non-trivially on the observed event history. We validate our models on data sets from a wide variety of contexts such as seismology, epidemiology, urban mobility, and neuroscience.
# 1 INTRODUCTION
Modeling discrete events that are localized in continuous time and space is an important task in many scientific fields and applications. Spatio-temporal point processes (STPPs) are a versatile and principled framework for modeling such event data and have, consequently, found many applications in a diverse range of fields. This includes, for instance, modeling earthquakes and aftershocks (Ogata, 1988; 1998), the occurrence and propagation of wildfires (Hering et al., 2009), epidemics and infectious diseases (Meyer et al., 2012; Schoenberg et al., 2019), urban mobility (Du et al., 2016), the spread of invasive species (Balderama et al., 2012), and brain activity (Tagliazucchi et al., 2012).
It is of great interest in all of these areas to learn high-fidelity models which can jointly capture spatial and temporal dependencies and their propagation effects. However, existing parameterizations of STPPs are strongly restricted in this regard due to computational considerations: In its general form, STPPs require solving multivariate integrals for computing likelihood values and thus have primarily been studied within the context of different approximations and model restrictions. This includes, for instance, restricting the model class to parameterizations with known closed-form solutions (e.g., exponential Hawkes processes (Ozaki, 1979)), to restrict dependencies between the spatial and temporal domain (e.g., independent and unpredictable marks (Daley & Vere-Jones, 2003)), or to discretize continuous time and space (Ogata, 1998). These restrictions and approximations—which can lead to mis-specified models and loss of information—motivated the development of neural temporal point processes such as Neural Hawkes Processes (Mei & Eisner, 2017) and Neural Jump SDEs (Jia & Benson, 2019). While these methods are more flexible, they can still require approximations such as Monte-Carlo sampling of the likelihood (Mei & Eisner, 2017; Nickel & Le, 2020) and, most importantly, only model restricted spatial distributions (Jia & Benson, 2019).
 Figure 1: Color is used to denote $p ( x | t )$ , which can be evaluated for Neural STPPs. After observing an event in one mode, the model is instantaneously updated as it strongly expects an event in the next mode. After a period of no observations, the model smoothly reverts back to the marginal distribution.
To overcome these issues, we propose a new class of parameterizations for spatio-temporal point processes which leverage Neural ODEs as a computational method and allows us to define flexible, high-fidelity models for spatio-temporal event data. We build upon ideas of Neural Jump SDEs (Jia & Benson, 2019) and Continuous-time Normalizing Flows (CNFs; Chen et al. 2018; Grathwohl et al. 2019; Mathieu & Nickel 2020) to learn parametric models of spatial (or mark1) distributions that are defined continuously in time. Normalizing flows are known to be flexible universal density estimators (e.g. Huang et al. 2018; 2020; Teshima et al. 2020; Kong & Chaudhuri 2020) while retaining computational tractability. As such, our approach allows the computation of exact likelihood values even for highly complex spatio-temporal distributions, and our models create smoothly changing spatial distributions that naturally benefits spatio-temporal modeling. Central to our approach, are two novel neural architectures based on CNFs—using either discontinuous jumps in distribution or self-attention—to condition spatial distributions on the event history. To the best of our knowledge, this is the first method that combines the flexibility of neural TPPs with the ability to learn high-fidelity models of continuous marks that can have complex dependencies on the event history. In addition to our modeling contributions, we also construct five new pre-processed data sets for benchmarking spatio-temporal event models.
# 2 BACKGROUND
In the following, we give a brief overview of two core frameworks which our method builds upon, i.e., spatio-temporal point processes and continuous-time normalizing flows.
Event Modeling with Point Processes Spatio-temporal point processes are concerned with modeling sequences of random events in continuous space and time (Moller & Waagepetersen, 2003; Baddeley et al., 2007). Let $\mathcal { H } = \{ ( t _ { i } , \pmb { x } _ { i } ) \} _ { i = 1 } ^ { n }$ denote the sequence of event times $t _ { i } \in \mathbb { R }$ and their associated locations $\pmb { x } _ { i } \in \mathbb { R } ^ { d }$ , the number of events $n$ being also random. Additionally, let $\mathcal { H } _ { t } = \{ ( t _ { i } , \pmb { x } _ { i } ) ~ | ~ t _ { i } < t , t _ { i } \in \mathcal { H } \}$ denote the history of events predating time $t$ . A spatio-temporal point process is then fully characterized by its conditional intensity function
$$\lambda ( t , \pmb { x } \mid \mathcal { H } _ { t } ) \triangleq \operatorname* { l i m } _ { \Delta t \downarrow 0 , \Delta \pmb { x } \downarrow 0 } \frac { \mathbb { P } \left( t _ { i } \in [ t , t + \Delta t ] , \pmb { x } _ { i } \in B ( \pmb { x } , \Delta \pmb { x } ) \mid \mathcal { H } _ { t } \right) } { | B ( \pmb { x } , \Delta \pmb { x } ) | \Delta t } .$$
where $B ( { \pmb x } , \Delta { \pmb x } )$ denotes a ball centered at $\pmb { x } \in \mathbb { R } ^ { d }$ and with radius $\Delta \mathbfit { x }$ . The only condition is that $\lambda ( t , \pmb { x } \mid \mathcal { H } _ { t } ) \geq 0$ and need not be normalized. Given $i - 1$ previous events, the conditional intensity function describes therefore the instantaneous probability of the $i$ -th event occurring at $t$ and location $_ { \textbf { \em x } }$ . In the following, we will use the common star superscript shorthand $\lambda ^ { * } ( t , \pmb { x } ) = \lambda ( t , \pmb { x } \mid \mathcal { H } _ { t } )$ to denote conditional dependence on the history. The joint log-likelihood of observing $\mathcal { H }$ within a time interval of $[ 0 , T ]$ is then given by (Daley $\&$ Vere-Jones, 2003, Proposition 7.3.III)
$$\log p \left( \mathcal { H } \right) = \sum _ { i = 1 } ^ { n } \log \lambda ^ { * } ( t _ { i } , \pmb { x } _ { i } ) - \int _ { 0 } ^ { T } \int _ { \mathbb { R } ^ { d } } \lambda ^ { * } ( \tau , \pmb { x } ) d \pmb { x } d \tau .$$
Training general STPPs with maximum likelihood is difficult as eq. (2) requires solving a multivariate integral. This need to compute integrals has driven research to focus around the use of kernel density estimators (KDE) with exponential kernels that have known anti-derivatives (Reinhart et al., 2018).
Continuous-time Normalizing Flows Normalizing flows (Dinh et al., 2014; 2016; Rezende & Mohamed, 2015) is a class of density models that describe flexible distributions by parameterizing an invertible transformation from a simpler base distribution, which enables exact computation of the probability of the transformed distribution, without any unknown normalization constants.
Given a random variable $\scriptstyle { \pmb x } _ { 0 }$ with known distribution $p ( \pmb { x } _ { 0 } )$ and an invertible transformation $F ( x )$ , the transformed variable $F ( \pmb { x } _ { 0 } )$ is a random variable with a probability distribution function that satisfies
$$\log p ( F ( { \pmb x } _ { 0 } ) ) = \log p ( { \pmb x } _ { 0 } ) - \log \left| \operatorname* { d e t } \frac { \partial F } { \partial { \pmb x } } ( { \pmb x } _ { 0 } ) \right| .$$
There have been many advances in parameterizing $F$ with flexible neural networks that also allow for cheap evaluations of eq. (3). We focus our attention on Continuous-time Normalizing Flows (CNFs), which parameterizes this transformation with a Neural ODE (Chen et al., 2018). CNFs define an infinite set of distributions on the real line that vary smoothly across time, and will be our core component for modeling events in the spatial domain.
Let $p ( \pmb { x } _ { 0 } )$ be the base distribution2. We then parameterize an instantaneous change in the form of an ordinary differential equation (ODE), $\begin{array} { r } { \frac { d { \pmb x } _ { t } } { d t } = f ( t , { \pmb x } _ { t } ) } \end{array}$ , where the subscript denotes dependence on $t$ . This function can be parameterized using any Lipschitz-continuous neural network. Conditioned on a sample $\scriptstyle { \mathbf { { \mathit { x } } } } _ { 0 }$ from the base distribution, let $\mathbf { \Delta } _ { \mathbf { \mathcal { X } } _ { t } }$ be the solution of the initial value problem 3 at time $t$ , i.e. it is from a trajectory that passes through $\scriptstyle { \pmb x } _ { 0 }$ at time 0 and satisfies the ODE $d { \pmb x } _ { t } / d t = f$ . We can express the value of the solution at time $t$ as
$${ \pmb x } _ { t } = { \pmb x } _ { 0 } + \int _ { 0 } ^ { t } f ( t , { \pmb x } _ { \tau } ) d \tau .$$
The distribution of $\mathbf { \Delta } _ { \mathbf { \mathcal { X } } _ { t } }$ then also continuously changes in $t$ through the following equation,
$$\log p ( { \pmb x } _ { t } | t ) = \log p ( { \pmb x } _ { 0 } ) - \int _ { 0 } ^ { t } \mathrm { t r } \left( \frac { \partial f } { \partial x } ( \tau , { \pmb x } _ { \tau } ) \right) ~ d \tau .$$
In practice, eq. (4) and eq. (5) are solved together from 0 to $t$ , as eq. (5) alone is not an ordinary differential equation but the combination of $\mathbf { \Delta } _ { \mathbf { \mathcal { X } } _ { t } }$ and $\log p ( { \pmb x } _ { t } )$ is. The trace of the Jacobian $\frac { \partial f } { \partial \boldsymbol { x } } ( \tau , \pmb { x } _ { \tau } )$ can be estimated using a Monte Carlo estimate of the identity (Skilling, 1989; Hutchinson, 1990), $\mathrm { t r } ( A ) = \mathbb { E } _ { v \sim \mathcal { N } ( 0 , 1 ) } [ v ^ { \top } A v ]$ . This estimator relies only on a vector-Jacobian product, which can be efficiently computed in modern automatic differentiation and deep learning frameworks. This has been used (Grathwohl et al., 2019) to scale CNFs to higher dimensions using a Monte Carlo estimate of the log likelihood objective,
$$\log p ( { \pmb x } _ { t } | t ) = \log p ( { \pmb x } _ { 0 } ) - \mathbb { E } _ { \pmb { v } \sim \mathcal { N } ( 0 , 1 ) } \left[ \int _ { 0 } ^ { t } v ^ { \top } \frac { \partial f } { \partial x } ( \tau , { \pmb x } _ { \tau } ) v \ d \tau \right] ,$$
which, even if only one sample of $v$ is used, is still amenable to training with stochastic gradient descent. Gradients with respect to any parameters in $f$ can be computed with constant memory by solving an adjoint ODE in reverse-time as described in Chen et al. (2018).
# 3 NEURAL SPATIO-TEMPORAL POINT PROCESSES
We are interested in modeling high-fidelity distributions in continuous time and space that can be updated based on new event information. For this purpose, we use the Neural ODE framework to parameterize a STPP by combining ideas from Neural Jump SDEs and Continuous Normalizing Flows to create highly flexible models that still allow exact likelihood computation.
We first (re-)introduce necessary notation. Let $\mathcal { H } = \{ ( t _ { i } , \pmb { x } _ { t _ { i } } ^ { ( i ) } ) \}$ denote a sequence of event times $t _ { i } \in [ 0 , T ]$ and locations $\pmb { x } _ { t _ { i } } ^ { ( i ) } \in \mathbb { R } ^ { d }$ i. The superscript indicates an association with the $i$ -th event, and the use of subscripting with $t _ { i }$ will be useful later in the continuous-time modeling framework. Following Daley & Vere-Jones (2003), we decompose the conditional intensity function as
$$\lambda ^ { * } ( t , { \pmb x } ) = \lambda ^ { * } ( t ) p ^ { * } ( { \pmb x } \mid t )$$
where $\lambda ^ { * } ( t )$ is the ground intensity of the temporal process and where $\boldsymbol { p } ^ { * } ( \boldsymbol { x } \mid t )$ is the conditional density of a mark $_ { \textbf { \em x } }$ at $t$ given $\mathcal { H } _ { t }$ . The star superscript is used as again shorthand to denote dependence on the history. Since $\textstyle \int _ { \mathbb { R } ^ { d } } p ^ { * } ( { \pmb { x } } \mid t ) = 1$ , eq. (7) allows us now to simplify the log-likelihood function of the joint process from eq. (2), such that
$$\log p ( \mathcal { H } ) = \underbrace { \sum _ { i = 1 } ^ { n } \log \lambda ^ { * } ( t _ { i } ) - \int _ { 0 } ^ { T } \lambda ^ { * } ( \tau ) ~ d \tau } _ { \mathrm { t e m p o r a l ~ l o g - l i k e l i h o o d } } + \underbrace { \sum _ { i = 1 } ^ { n } \log p ^ { * } ( \pmb { x } _ { t _ { i } } ^ { ( i ) } | t _ { i } ) } _ { \mathrm { s p a t i a l ~ l o g - l i k e l i h o o d } }$$
Furthermore, based on eq. (7), we can derive separate models for the ground intensity and conditional mark density which will be jointly conditioned on a continuous-time hidden state with jumps. In the following, we will first describe how we construct a latent dynamics model, which we use to compute the ground intensity $\lambda ^ { * } ( t )$ . We will then propose three novel CNF-based approaches for modeling the conditional mark density $p ^ { * } ( { \pmb x } | t )$ . We will first describe an unconditional model, which is already a strong baseline when spatial event distributions only follow temporal patterns and there is little to no correlation between the spatial observations. We then devise two new methods of conditioning on the event history $\mathcal { H }$ : one explicitly modeling instantaneous changes in distribution, and another that uses an attention mechanism which is more amenable to parallelism.
Latent Dynamics and Ground Intensity For the temporal variables $\{ t _ { i } \}$ , parameterize the intensity function using hidden state dynamics with jumps, similar to the work of Jia & Benson (2019). Specifically, we evolve a continuous-time hidden state $^ { h }$ and set
$$\lambda ^ { * } ( t ) = g _ { \lambda } ( h _ { t } ) \qquad \mathrm { ( G r o u n d i n t e n s i t y ) }$$
where $g _ { \lambda }$ is a neural network with a softplus nonlinearity applied to the output, to ensure the intensity is positive. We then capture conditional dependencies through the use of a continuously changing state $\boldsymbol { h } _ { t }$ with instantaneous updates when conditioned on an event.
The architecture is analogous to a recurrent neural network with a continuous-time hidden state (Mei & Eisner, 2017; Che et al., 2018; Rubanova et al., 2019) modeled by a Neural ODE. This provides us with a vector representation $\boldsymbol { h } _ { t }$ at every time value $t$ that acts as both a summary of the history of events and as a predictor of future behavior. Instantaneous updates to $\boldsymbol { h } _ { t }$ allow to incorporate abrupt changes to the hidden state that are triggered by observed events. This mechanism is important for modeling point processes and allows past events to influence future dynamics in a discontinuous way (e.g., modeling immediate shocks to a system).
We use $f _ { h }$ to model the continuous change in the form of an ODE and $g _ { h }$ to model instantaneous changes based on an observed event.
$${ \begin{array} { r l r l } & { h _ { t _ { 0 } } = h _ { 0 } } & & { ( { \mathrm { A n ~ i n i t i a l ~ h i d d e n ~ s t a t e } } ) } \\ & { { \frac { d h _ { t } } { d t } } = f _ { h } ( t , h _ { t } ) } & & { { \mathrm { b e t w e e n ~ e v e n t ~ t i m e s } } } & & { ( { \mathrm { C o n t i n u o u s ~ e v o l u t i o n } } ) } \\ & { \operatorname* { l i m } _ { \varepsilon \to 0 } h _ { t _ { i } + \varepsilon } = g _ { h } \left( t _ { i } , h _ { t _ { i } } , x _ { t _ { i } } ^ { ( i ) } \right) } & & { { \mathrm { a t ~ e v e n t ~ t i m e s ~ } } t _ { i } } & & { ( { \mathrm { I n s t a n t a n e o u s ~ u p d a t e s } } ) } \end{array} }$$
The use of $\varepsilon$ is to portray that $h _ { t }$ is a cagl \` ad\` function, i.e. left-continuous with right limits, with a discontinuous jump modeled by $g _ { h }$ .
The parameterization of continuous-time hidden states in the form of eqs. (10) to (12) has been used for time series modeling (Rubanova et al., 2019; De Brouwer et al., 2019) as well as TPPs (Jia & Benson, 2019). We parameterize $f _ { h }$ as a standard multi-layer fully connected neural network, and use the GRU update (Cho et al., 2014) to parameterize $g _ { h }$ , as was done in Rubanova et al. (2019).
Time-varying CNF The first model we consider is a straightforward application of the CNF to time-variable observations. Assuming that the spatial distribution is independent of prior events,
$$\log p ^ { * } ( \pmb { x } _ { t _ { i } } ^ { ( i ) } | t _ { i } ) = \log p ( \pmb { x } _ { t _ { i } } ^ { ( i ) } | t _ { i } ) = \log p ( \pmb { x } _ { 0 } ^ { ( i ) } ) - \int _ { 0 } ^ { t _ { i } } \mathrm { t r } \left( \frac { \partial f } { \partial x } ( \tau , \pmb { x } _ { \tau } ^ { ( i ) } ) \right) d \tau$$
where $\pmb { x } _ { \tau } ^ { ( i ) }$ ) is the solution of the ODE f with initial value x(i)t , the observed event location, at $\tau = t _ { i }$ the observed event time. The spatial distribution of an event modeled by a Time-varying CNF changes with respect to the time it occurs. Some spatio-temporal data sets exhibit mostly temporal patterns and little to no dependence on previous events in the spatial domain, which would make a time-varying CNF a good fit. Nevertheless, this model lacks the ability to capture spatial propagation effects, as it does not condition on previous event observations.
A major benefit of this model is the ability to evaluate the joint log-likelihood fully in parallel across events, since there are no dependencies between events. Most modern ODE solvers that we are aware of only allow a scalar terminal time. Thus, to solve all $n$ integrals in eq. (13) with a single call to an ODE solver, we can simply reparameterize all integrals with a consistent dummy variable and track the terminal time in the state (see Appendix $\mathrm { F }$ for detailed explanation). Intuitively, the idea is that we can reparameterize ODEs that are on $t \in [ 0 , t _ { i } ]$ into an ODE on $s \in [ 0 , 1 ]$ using the change of variables $\bar { s } = t / { { t } _ { i } }$ (or $t = s t _ { i }$ ) and scaling the output of $f$ by $t _ { i }$ . The joint ODE is then
$$\frac { d } { d s } \underbrace { \left[ \begin{array} { c } { x _ { s } ^ { ( 1 ) } } \\ { \vdots } \\ { x _ { s } ^ { ( n ) } } \end{array} \right] } _ { A _ { s } } = \underbrace { \left[ t _ { 1 } f ( s t _ { 1 } , x _ { s } ^ { ( 1 ) } ) \right] } _ { f ( s t _ { n } , z _ { s } ) } \quad \mathrm { ~ w h i c h ~ g i v e s ~ } \quad \underbrace { \left[ \begin{array} { c } { x _ { 0 } ^ { ( 1 ) } } \\ { \vdots } \\ { x _ { 0 } ^ { ( n ) } } \end{array} \right] } _ { A _ { 0 } } + \int _ { 0 } ^ { 1 } f ( s , A _ { s } ) d s = \underbrace { \left[ \begin{array} { c } { x _ { t _ { 1 } } ^ { ( 1 ) } } \\ { \vdots } \\ { x _ { t _ { n } } ^ { ( n ) } } \end{array} \right] } _ { A _ { 1 } } .$$
Thus the full trajectories between 0 to $t _ { i }$ for all events can be computed in parallel using this augmented ODE by simply integrating once from $s = 0$ to $s = 1$ .
$\mathbf { J u m p C N F }$ For the second model, we condition the dynamics defining the continuous normalizing flow on the hidden state $^ { h }$ , allowing the normalizing flow to update its distribution based on changes in $\mathcal { H }$ . For this purpose, we define continuous-time spatial distributions by making again use of two components: (i) a continuous-time normalizing flow that evolves the distribution continuously, and (ii) a standard (discrete-time) flow model that changes the distribution instantaneously after conditioning on new events. As normalizing flows parameterize distributions through transformations of the samples, these continuous- and discrete-time transformations are composable in a straightforward manner and are end-to-end differentiable.
The generative process of a single event in a Jump CNF is given by:
$$\begin{array} { r l r l } { x _ { 0 } \sim p ( x _ { 0 } ) } & { } & & { \mathrm { ( A n i n i t i a l ~ d i s t r i b u t i o n ) } } \\ { \displaystyle \frac { d x _ { t } } { d t } = f _ { x } ( t , x _ { t } , h _ { t } ) } & { \mathrm { ~ b e t w e e n ~ e v e n t ~ t i m e s ~ } } & & { \mathrm { ( C o n t i n u o u s ~ e v o l u t i o n ) } } \\ { \displaystyle \operatorname* { l i m } _ { \varepsilon 0 } x _ { t _ { i } + \varepsilon } = g _ { x } ( t _ { i } , x _ { t _ { i } } , h _ { t _ { i } } ) } & { \quad \mathrm { a t ~ e v e n t ~ t i m e s ~ } t _ { i } } & & { \mathrm { ( I n s t a n t a n e o u s ~ u p d a t e s ) } } \end{array}$$
The initial distribution can be parameterized by a normalizing flow. In practice, we set a base distribution at a negative time value and model $p ( \pmb { x } _ { 0 } )$ using the same CNF parameterized by $f _ { x }$ . The instantaneous updates (or jumps) describe conditional updates in distribution after each new event has been observed. This conditioning on $h _ { t _ { i } }$ is required for the continuous and instantaneous updates to depend on the history of observations. Otherwise, a Jump CNF would only be able to model the marginal distribution and behave similarly to a time-varying CNF. We solve for $h _ { t }$ alongside $\mathbf { \Delta } _ { \mathbf { \mathcal { X } } _ { t } }$ .
The final probability of an event $\mathbf { \Delta } _ { \mathbf { \mathcal { X } } _ { t } }$ at some $t > t _ { n }$ after observing $n$ events is given by the sum of changes according to the continuous- and discrete-time normalizing flows.
$$\begin{array} { r l } & { \log p ^ { * } ( { \boldsymbol x } _ { t } | t ) = \log p ( { \boldsymbol x } _ { 0 } ) } \\ & { \quad \quad + \underbrace { \displaystyle \sum _ { t _ { i } \in \mathcal { H } _ { t } } \left( - \int _ { t _ { i - 1 } } ^ { t _ { i } } { \mathrm { t r } \left( \frac { \partial f ( \tau , { \boldsymbol x } _ { \tau } , h _ { \tau } ) } { \partial { \boldsymbol x } } \right) d \tau } - \log \left| \operatorname* { d e t } \frac { \partial g _ { { \boldsymbol x } } ( t _ { i } , { \boldsymbol x } _ { t _ { i } } , h _ { t _ { i } } ) } { \partial { \boldsymbol x } } \right| \right) } _ { \mathrm { C h a p e ~ i n g ~ u p ~ t o ~ l a s t ~ v e n t } } } \\ & { \quad \quad + \underbrace { \displaystyle \int _ { t _ { n } } ^ { t } - { \mathrm { t r } \left( \frac { \partial f ( \tau , { \boldsymbol x } _ { \tau } , h _ { \tau } ) } { \partial { \boldsymbol x } } \right) d \tau } } _ { \mathrm { C h a p e ~ i n g e n ~ l a s t ~ v e n t ~ t o ~ } } } \end{array}$$
As the instantaneous updates must be applied sequentially in a Jump CNF, we can only compute the integrals in eq. (18) one at a time. As such, the number of initial value problems scales linearly with the number of events in the history because the ODE solver must be restarted between each instantaneous update to account for the discontinuous change to state. This incurs a substantial cost when the number of events is large.
Attentive CNF To design a spatial model with conditional dependencies that alleviates the computational issues of Jump CNFs and can be computed in parallel, we make use of efficient attention mechanisms based on the Transformer architecture (Vaswani et al., 2017). Denoting only the spatial variables for simplicity, each conditional distribution $\log p ( \pmb { x } _ { t _ { i } } \ | \ \mathcal { H } _ { t _ { i } } )$ can be modeled by a CNF that depends on the sample path of prior events. Specifically, we take the dummy-variable reparameterization of eq. (14) and modify it so that the $i$ -th event depends on all previous events using a Transformer architecture for $f$ ,
 Figure 2: Visualization of the sampling paths of Neural STPP models for a 1-D spatio-temporal data set where $\{ t _ { i } \} _ { i = 1 } ^ { 4 }$ are event times. The Jump CNF uses instantaneous jumps to update its distribution based on newly observed events while the Attentive CNF depends continuously on the sampling paths of prior events. We additionally visualize a second sequence for the Attentive CNF where the random base samples $\{ x _ { 0 } ^ { ( i ) } \} _ { i = 2 } ^ { 4 }$ are the same as in sequence 1. Even so, the sampling paths are different because the first event is different, effectively leading to different conditional spatial distributions. See Figure 9 for visualizations of the learned density.
$$\frac { d } { d s } \left[ \begin{array} { c } { x _ { s } ^ { ( 1 ) } } \\ { x _ { s } ^ { ( 2 ) } } \\ { \vdots } \\ { x _ { s } ^ { ( n ) } } \end{array} \right] = \left[ \begin{array} { c } { t _ { 1 } f \left( s t _ { 1 } , \{ x _ { s } ^ { ( i ) } \} _ { i = 1 } ^ { 1 } , \{ h _ { t _ { i } } \} _ { i = 1 } ^ { 1 } \right) } \\ { t _ { 2 } f \left( s t _ { 2 } , \{ x _ { s } ^ { ( i ) } \} _ { i = 1 } ^ { 2 } , \{ h _ { t _ { i } } \} _ { i = 1 } ^ { 2 } \right) } \\ { \vdots } \\ { t _ { n } f \left( s t _ { n } , \{ x _ { s } ^ { ( i ) } \} _ { i = 1 } ^ { n } , \{ h _ { t _ { i } } \} _ { i = 1 } ^ { n } \right) } \end{array} \right] : = f _ { \mathrm { A t t } } \mathrm { n } .$$
With this formulation, the trajectory of $\pmb { x } _ { \tau } ^ { ( i ) }$ depends continuously on the trajectory of $\pmb { x } _ { \tau } ^ { ( j ) }$ for all $j < i$ and the hidden states $^ { h }$ prior to the $i$ -th event. Similar to eq. (14), an Attention CNF can now solve for the trajectories of all events in parallel while simultaneously depending non-trivially on $\mathcal { H }$ .
To parameterize $f _ { \mathrm { A t t } \mathrm { n } }$ , we use an embedding layer followed by two multihead attention (MHA) blocks and an output layer to map back into the input space. We use the Lipschitz-continuous multihead attention from Kim et al. (2020) as they recently showed that the dot product multihead attention (Vaswani et al., 2017) is not Lipschitz-continuous and thus may be ill-suited for parameterizing ODEs.
Low-variance Log-likelihood Estimation The variance of the Hutchinson stochastic trace estimator in eq. (6) grows with the squared Frobenius norm of the Jacobian, $\sum _ { i j } \left[ \partial f / \partial x \right] _ { i j } ^ { 2 }$ (Hutchinson, 1990). For attentive CNFs, we can remove some of the non-diagonal elements of the Jacobian and achieve a lower variance estimator. The attention mechanism creates a blocktriangular Jacobian, where each block corresponds to one event, but the elements outside of the blockdiagonal are solely due to the multihead attention. By detaching the gradient connections between different events in the MHA blocks, we can create a surrogate
 Figure 3: Lower variance estimates of the loglikelihood allows training better Attentive CNFs.
Jacobian matrix that do not contain cross-event partial derivatives. This effectively allows us to apply Hutchinson’s estimator on a matrix that has the same diagonal elements as the Jacobian $\partial f / \partial x$ —and thus has the same expected value—but has zeros outside of the block-diagonal, leading to a lower variance trace estimator. The procedure consists of selectively removing partial derivatives and is straightforward but notationally cumbersome; the interested reader can find the details in Appendix E.
This is similar in spirit to Chen & Duvenaud (2019) but instead of constructing a neural network that specifically allows cheap removal of partial derivatives, we make use of the fact that multihead attention already allows cheap removal of (cross-event) partial derivatives.
An ablation experiment is shown in Figure 3 for training on the PINWHEEL data set, where the lower variance estimates (and gradients) ultimate led to faster convergence and better converged models.
# 4 RELATED WORK
Neural Temporal Point Processes Modeling real-world data using restricted models such as Exponential Hawkes Processes (Ozaki, 1979) may lead to poor results due to model mis-specification. While this has led to many works on improving the Hawkes process (e.g. Linderman & Adams 2014; Li & Zha 2014; Zhao et al. 2015; Farajtabar et al. 2017; Li & Ke 2020; Nickel & Le 2020), recent works have begun to explore neural network parameterizations of TPPs. A common approach is to use recurrent neural networks to accumulate the event history in a latent state from which the intensity value can then be derived. Models of this form include, for instance, Recurrent Marked Temporal Point Processes (RMTPPs; Du et al. 2016) and Neural Hawkes Processes (NHPs; Mei & Eisner 2017). In contrast to our approach, these methods can not compute the exact likelihood of the model and have to resort to Monte-Carlo sampling for its approximation. However, this approach is especially problematic for commonly occurring clustered and bursty event sequences as it either requires a very high sampling rate or ignores important temporal dependencies (Nickel & Le, 2020). To overcome this issue, Jia & Benson (2019) proposed Neural Jump SDEs which extend the Neural ODE framework and allow to compute the exact likelihood for neural TPPs, up to numerical errors. This method is closely related to our approach and we build on its ideas to compute the ground intensity of the STPP. However, current Neural Jump SDEs —as well as NHPs and RMTPPs—are not well-suited for modeling complex continuous mark distributions as they are restricted to methods such as Gaussian mixture models in the spatial domain. Finally, Shchur et al. (2019) and Mehrasa et al. (2019) considered combining TPPs with flexible likelihood-based models, however for different purposes as in our case, i.e., for intensity-free learning of only temporal point processes.
Continuous Normalizing Flows The ability to describe an infinite number of distributions with a Continuous Normalizing Flow has been used by a few recent works. Some works in computer graphics have used the interpolation effect of CNFs to model transformations of point clouds (Yang et al., 2019; Rempe et al., 2020; Li et al., 2020). CNFs have also been used in sequential latent variable models (Deng et al., 2020; Rempe et al., 2020). However, such works do not align the “time” axis of the CNF with the temporal axis of observations, and do not train on observations at more than one value of “time” in the CNF. In contrast, we align the time axis of the CNF with the time of the observations, directly using its ability to model distributions on a real-valued axis. A closely related application of CNFs to spatio-temporal data was done by Tong et al. (2020), who modeled the distribution of cells in a developing human embryo system at five fixed time values. In contrast to this, we extend to applications where observations are made at arbitrary time values, jointly modeling space and time within the spatio-temporal point process framework. Furthermore, Mathieu & Nickel (2020); Lou et al. (2020) recently proposed extensions of CNFs to Riemannian manifolds. For our proposed approach, this is especially interesting in the context of earth and climate science, as it allows us to model STPPs on the sphere simply by replacing the CNF with its Riemannian equivalent.
# 5 EXPERIMENTS
Data Sets Many collected data can be represented within the framework of spatio-temporal events. We pre-process data from open sources and make them suitable for spatio-temporal event modeling. Each sequence in these data sets can contain up to thousands of variables, all the while having a large variance in sequence lengths. Varying across a wide range of domains, the data sets we consider are: earthquakes, pandemic spread, consumer demand for a bike sharing app, and high-amplitude brain signals from fMRI scans. We briefly describe these data sets here; further details, pre-processing steps, and data set diagnostics can be found in Appendix C. Code for preprocessing and training are open sourced at https://github.com/facebookresearch/neural_stpp.
PINWHEEL This is a synthetic data set with multimodal and non-Gaussian spatial distributions designed to test the ability to capture drastic changes due to event history (see fig. 5). The data set consists of 10 clusters which form a pinwheel structure. Events are sampled from a multivariate Hawkes process such that events from one cluster will increase the probability of observing events in the next cluster in a clock-wise rotation. Number of events per sequences ranges between 4 to 108.
EARTHQUAKES For modeling earthquakes and aftershocks, we gathered location and time of all earthquakes in Japan from 1990 to 2020 with magnitude of at least 2.5 from the U.S. Geological Survey (2020). Number of events per sequences ranges between 18 to 543.
 Figure 5: Evolution of spatial densities on PINWHEEL data. top: Attentive CNF. bottom: Jump CNF. (a) Before observing any events at $\scriptstyle t = 0$ , the distribution is even across all clusters. (b-f) Each event increases the probability of observing a future event from the subsequent cluster in clock-wise ordering. (g-h) After a period of no new events, the distribution smoothly returns back to the initial distribution (a).
 Figure 7: Snapshots of conditional spatial distributions modeled by the Jump CNF (top) and a conditional kernel density estimator (KDE; bottom). (a) Distribution before any events at $\scriptstyle t = 0$ . (b-d) The Jump CNF’s distributions concentrate around tectonic plate boundaries where earthquakes and aftershocks gather, whereas the KDE must use a large variance in order to capture propagation of aftershocks in multiple directions.
COVID-19 CASES We use data released publicly by The New York Times (2020) on daily COVID-19 cases in New Jersey state. The data is aggregated at the county level, which we dequantize uniformly across the county. Number of events per sequences ranges between 3 to 323.
BOLD5000 This consists of fMRI scans as participants are given visual stimuli (Chang et al., 2019). We convert brain responses into spatio-temporal events following the z-score thresholding approach in Tagliazucchi et al. (2012; 2016). Number of events per sequences ranges between 6 to 1741.
In addition to these datasets, we also report in Appendix A results for CITIBIKE, a data set consisting of rental events from a bike sharing service in New York City.
Baselines To evaluate the capability of our proposed models, we compare against commonly-used baselines and state-of-the-art models. In some settings, ground intensity and conditional mark density are independent of each other and we can freely combine different baselines for the temporal and spatial domains. As temporal baselines, we use a homogeneous Poisson process, a self-correction process, a Hawkes process, and the Neural Hawkes Process, which were trained using their officially released code. As spatial baselines, we use a conditional kernel density estimator (KDE) with learned parameters, where $p ( { \pmb x } | t )$ is essentially modeled as a history-dependent Gaussian mixture model (see Appendix B), as well as the Time-varying CNF. In addition, we also compare to our implementation of Neural Jump SDEs (Jia & Benson, 2019) where the spatial distribution is a Gaussian mixture model. We use the same architecture as our GRU-based continuous-time hidden states for fair comparison, as we found the simpler parameterization in Jia & Benson (2019) to be numerically unstable for large number of events. Range of hyperparameter values are outlined in Appendix D.
<table><tr><td></td><td colspan="2">Pinwheel</td><td colspan="2">Earthquakes JP</td><td colspan="2">COVID-19 NJ</td><td colspan="2">BOLD5000</td></tr><tr><td>Model</td><td>Temporal</td><td>Spatial</td><td>Temporal</td><td>Spatial</td><td>Temporal</td><td>Spatial</td><td>Temporal</td><td>Spatial</td></tr><tr><td>Poisson Process</td><td>-0.784±0.001</td><td>1</td><td>-0.111±0.001</td><td>1</td><td>0.878±0.016</td><td>1</td><td>0.862±0.018</td><td>1</td></tr><tr><td>Self-correcting Process</td><td>-2.117±0.222</td><td></td><td>-7.051±0.780</td><td></td><td>-10.053±1.150</td><td></td><td>-6.470±0.827</td><td></td></tr><tr><td>Hawkes Process</td><td>-0.276±0.033</td><td></td><td>0.114±0.005</td><td></td><td>2.092±0.023</td><td></td><td>2.860±0.050</td><td></td></tr><tr><td>Neural Hawkes Process</td><td>-0.023±0.001</td><td></td><td>0.198±0.001</td><td></td><td>2.229±0.013</td><td></td><td>3.080±0.019</td><td></td></tr><tr><td>Conditional KDE</td><td></td><td>-2.958±0.000</td><td></td><td>-2.259±0.001</td><td></td><td>-2.583±0.000</td><td></td><td>-3.467±0.000</td></tr><tr><td>Time-varying CNF</td><td></td><td>-2.185±0.003</td><td></td><td>-1.459±0.016</td><td></td><td>-2.002±0.002</td><td>1</td><td>-1.846±0.019</td></tr><tr><td>Neural Jump SDE (GRU)</td><td>-0.006±0.042</td><td>-2.077±0.026</td><td>0.186±0.005 -1.652±0.012</td><td></td><td>2.251±0.004 -2.214±0.005</td><td></td><td>5.675±0.003</td><td>0.743±0.089</td></tr><tr><td>Jump CNF</td><td>0.027±0.002</td><td>-1.562±0.015</td><td>0.166±0.001</td><td>-1.007±0.050</td><td>2.242±0.002 -1.904±0.004</td><td></td><td>5.536±0.016</td><td>1.246±0.185</td></tr><tr><td>Attentive CNF</td><td>0.034±0.001 -1.572±0.002</td><td></td><td>0.204±0.001</td><td>-1.237±0.075</td><td>2.258±0.002 -1.864±0.001</td><td></td><td>5.842±0.005</td><td>1.252±0.026</td></tr></table>
Table 1: Log-likelihood per event on held-out test data (higher is better). Standard devs. estimated over 3 runs.
Results & Analyses The results of our evaluation are shown in table 1. We highlight all results where the intervals containing one standard deviation away from the mean overlap.
Across all data sets, the Time-varying CNF outperforms the conditional KDE baseline despite not being conditional on history. This suggests that the overall spatial distribution is rather complex. We also see from Figure 7 that Gaussian clusters tend to compensate for far-reaching events by learning a larger band-width whereas a flexible CNF can easily model multi-modal event propagation.
The Jump and Attentive CNF models achieve better log-likelihoods than the Time-varying CNF, suggesting prediction in these data sets benefit from modeling dependence on event history.
For COVID-19, the self-exciting Hawkes process is a strong baseline which aligns with similar results for other infectious diseases (Park et al., 2019), but Neural STPPs can achieve substantially better spatial likelihoods. Overall, NHP is competitive with the Neural Jump SDE; however, it tends to fall short of the Attentive CNF which jointly models spatial and temporal variables.
In a closer comparison to the temporal likelihood of Neural Jump SDEs (Jia & Benson, 2019), we find that overly-restricted spatial models can negatively affect the temporal model since both domains are tightly coupled. Since our realization of Neural Jump SDEs and our STPPs use the same underlying architecture to model the temporal domain, the temporal likelihood values are often close. However, there is still a statistically significant difference between our Neural STPP models and Neural Jump SDEs even for the temporal log-likelihood on all data sets.
Finally, we note that the results of the Jump and Attentive CNFs are typically close. The attentive model generally achieves better temporal log-likelihoods while maintaining competitive spatial log-likelihoods. This difference is likely due to the Attentive CNF’s ability to attend to all previous events, while the Jump CNF has to compress all history information inside the hidden state at the time of event. The Attentive CNF also enjoys substantially faster computations (see Appendix A).
# 6 CONCLUSION
To learn high-fidelity models of stochastic events occurring in continuous space and time, we have proposed a new class of parameterizations for spatio-temporal point processes. Our approach combines ideas of Neural Jump SDEs with Continuous Normalizing Flows and allows to retain the flexibility of neural temporal point processes while enabling highly expressive models of continuous marks. We leverage Neural ODEs as a computational method that allows computing, up to negligible numerical error, the likelihood of the joint model, and we show that our approach achieves state-ofthe-art performance on spatio-temporal datasets collected from a wide range of domains.
A promising area for future work are applications of our method in earth and climate science which often are concerned with modeling highly complex spatio-temporal data. In this context, the use of Riemannian CNFs (Mathieu & Nickel, 2020; Lou et al., 2020; Falorsi & Forre´, 2020) is especially interesting as it allows us to model Neural STPPs on manifolds (e.g. the earth’s surface) by simply replacing the CNF in our models with a Riemannian counterpart.
# ACKNOWLEDGMENTS
We acknowledge the Python community (Van Rossum & Drake Jr, 1995; Oliphant, 2007) for developing the core set of tools that enabled this work, including PyTorch (Paszke et al., 2019), torchdiffeq (Chen, 2018), fairseq (Ott et al., 2019), Jupyter (Kluyver et al., 2016), Matplotlib (Hunter, 2007), seaborn (Waskom et al., 2018), Cython (Behnel et al., 2011), numpy (Oliphant, 2006; Van Der Walt et al., 2011), pandas (McKinney, 2012), and SciPy (Jones et al., 2014).
# REFERENCES
Jimmy Lei Ba, Jamie Ryan Kiros, and Geoffrey E Hinton. Layer normalization. arXiv preprint arXiv:1607.06450, 2016.
Adrian Baddeley, Imre Bar´ any, and Rolf Schneider. Spatial point processes and their applications. ´ Stochastic Geometry: Lectures Given at the CIME Summer School Held in Martina Franca, Italy, September 13–18, 2004, pp. 1–75, 2007.
Earvin Balderama, Frederic Paik Schoenberg, Erin Murray, and Philip W Rundel. Application of branching models in the study of invasive species. Journal of the American Statistical Association, 107(498):467–476, 2012.
Stefan Behnel, Robert Bradshaw, Craig Citro, Lisandro Dalcin, Dag Sverre Seljebotn, and Kurt Smith. Cython: The best of both worlds. Computing in Science & Engineering, 13(2):31–39, 2011.
Nadine Chang, John A Pyles, Austin Marcus, Abhinav Gupta, Michael J Tarr, and Elissa M Aminoff. BOLD5000, a public fMRI dataset while viewing 5000 visual images. Scientific data, 6(1):1–18, 2019.
Zhengping Che, Sanjay Purushotham, Kyunghyun Cho, David Sontag, and Yan Liu. Recurrent neural networks for multivariate time series with missing values. Scientific reports, 8(1):1–12, 2018.
Ricky T. Q. Chen. torchdiffeq, 2018. URL https://github.com/rtqichen/ torchdiffeq.
Ricky T. Q. Chen, Yulia Rubanova, Jesse Bettencourt, and David K. Duvenaud. Neural ordinary differential equations. In Advances in neural information processing systems, pp. 6571–6583, 2018.
Ricky TQ Chen and David K Duvenaud. Neural networks with cheap differential operators. In Advances in Neural Information Processing Systems, pp. 9961–9971, 2019.
Kyunghyun Cho, Bart Van Merrienboer, Caglar Gulcehre, Dzmitry Bahdanau, Fethi Bougares, Holger ¨ Schwenk, and Yoshua Bengio. Learning phrase representations using RNN encoder-decoder for statistical machine translation. arXiv preprint arXiv:1406.1078, 2014.
Daryl J Daley and David Vere-Jones. An introduction to the theory of point processes, volume 1: Elementary theory and methods. Verlag New York Berlin Heidelberg: Springer, 2003.
Edward De Brouwer, Jaak Simm, Adam Arany, and Yves Moreau. GRU-ODE-Bayes: Continuous modeling of sporadically-observed time series. In Advances in Neural Information Processing Systems, pp. 7379–7390, 2019.
Ruizhi Deng, Bo Chang, Marcus A Brubaker, Greg Mori, and Andreas Lehrmann. Modeling continuous stochastic processes with dynamic normalizing flows. arXiv preprint arXiv:2002.10516, 2020.
Laurent Dinh, David Krueger, and Yoshua Bengio. Nice: Non-linear independent components estimation. arXiv preprint arXiv:1410.8516, 2014.
Laurent Dinh, Jascha Sohl-Dickstein, and Samy Bengio. Density estimation using real nvp. 2016.
Nan Du, Hanjun Dai, Rakshit Trivedi, Utkarsh Upadhyay, Manuel Gomez-Rodriguez, and Le Song. Recurrent marked temporal point processes: Embedding event history to vector. In Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, pp. 1555–1564, 2016.
Luca Falorsi and Patrick Forre. Neural ordinary differential equations on manifolds. ´ arXiv preprint arXiv:2006.06663, 2020.
Mehrdad Farajtabar, Jiachen Yang, Xiaojing Ye, Huan Xu, Rakshit Trivedi, Elias Khalil, Shuang Li, Le Song, and Hongyuan Zha. Fake news mitigation via point process based intervention. arXiv preprint arXiv:1703.07823, 2017.
Chris Finlay, Jorn-Henrik Jacobsen, Levon Nurbekyan, and Adam M Oberman. How to train your ¨ neural ode. arXiv preprint arXiv:2002.02798, 2020.
Will Grathwohl, Ricky T. Q. Chen, Jesse Bettencourt, and David Duvenaud. Scalable reversible generative models with free-form continuous dynamics. In International Conference on Learning Representations, 2019.
Amanda S Hering, Cynthia L Bell, and Marc G Genton. Modeling spatio-temporal wildfire ignition point patterns. Environmental and Ecological Statistics, 16(2):225–250, 2009.
Chin-Wei Huang, David Krueger, Alexandre Lacoste, and Aaron Courville. Neural autoregressive flows. In International Conference on Machine Learning, pp. 2078–2087, 2018.
Chin-Wei Huang, Laurent Dinh, and Aaron Courville. Solving ode with universal flows: Approximation theory for flow-based models. In ICLR 2020 Workshop on Integration of Deep Neural Models and Differential Equations, 2020.
John D Hunter. Matplotlib: A 2d graphics environment. Computing in science & engineering, 9(3): 90, 2007.
Michael F Hutchinson. A stochastic estimator of the trace of the influence matrix for Laplacian smoothing splines. Communications in Statistics-Simulation and Computation, 19(2):433–450, 1990.
Junteng Jia and Austin R Benson. Neural jump stochastic differential equations. In Advances in Neural Information Processing Systems, pp. 9847–9858, 2019.
Eric Jones, Travis Oliphant, and Pearu Peterson. {SciPy}: Open source scientific tools for $\{ { \mathrm { P y t h o n } } \}$ 2014.
Hyunjik Kim, George Papamakarios, and Andriy Mnih. The Lipschitz constant of self-attention. arXiv preprint arXiv:2006.04710, 2020.
Durk P Kingma and Prafulla Dhariwal. Glow: Generative flow with invertible 1x1 convolutions. In Advances in neural information processing systems, pp. 10215–10224, 2018.
Thomas Kluyver, Benjamin Ragan-Kelley, Fernando Perez, Brian E Granger, Matthias Bussonnier, ´ Jonathan Frederic, Kyle Kelley, Jessica B Hamrick, Jason Grout, Sylvain Corlay, et al. Jupyter notebooks-a publishing format for reproducible computational workflows. In ELPUB, pp. 87–90, 2016.
Zhifeng Kong and Kamalika Chaudhuri. The expressive power of a class of normalizing flow models. arXiv preprint arXiv:2006.00392, 2020.
Liangda Li and Hongyuan Zha. Learning parametric models for social infectivity in multi-dimensional hawkes processes. In Proceedings of the Twenty-Eighth AAAI Conference on Artificial Intelligence, pp. 101–107, 2014.
Tianbo Li and Yiping Ke. Tweedie-hawkes processes: Interpreting the phenomena of outbreaks. In Proceedings of the AAAI Conference on Artificial Intelligence, volume 34, pp. 4699–4706, 2020.
Yang Li, Haidong Yi, Christopher M Bender, Siyuan Shan, and Junier B Oliva. Exchangeable neural ode for set modeling. arXiv preprint arXiv:2008.02676, 2020.
Scott Linderman and Ryan Adams. Discovering latent network structure in point process data. In International Conference on Machine Learning, pp. 1413–1421, 2014.
Aaron Lou, Derek Lim, Isay Katsman, Leo Huang, Qingxuan Jiang, Ser-Nam Lim, and Christopher De Sa. Neural manifold ordinary differential equations. arXiv preprint arXiv:2006.10254, 2020.
Emile Mathieu and Maximilian Nickel. Riemannian continuous normalizing flows. arXiv preprint arXiv:2006.10605, 2020.
Wes McKinney. Python for data analysis: Data wrangling with Pandas, NumPy, and IPython. ” O’Reilly Media, Inc.”, 2012.
Nazanin Mehrasa, Ruizhi Deng, Mohamed Osama Ahmed, Bo Chang, Jiawei He, Thibaut Durand, Marcus Brubaker, and Greg Mori. Point process flows. arXiv preprint arXiv:1910.08281, 2019.
Hongyuan Mei and Jason Eisner. The Neural Hawkes Process: A neurally self-modulating multivariate point process. In Advances in Neural Information Processing Systems 30: Annual Conference on Neural Information Processing Systems 2017, 4-9 December 2017, Long Beach, CA, USA, pp. 6754–6764, 2017.
Sebastian Meyer, Johannes Elias, and Michael Hohle. A space–time conditional intensity model for ¨ invasive meningococcal disease occurrence. Biometrics, 68(2):607–616, 2012.
Jesper Moller and Rasmus Plenge Waagepetersen. Statistical inference and simulation for spatial point processes. CRC Press, 2003.
Maximilian Nickel and Matthew Le. Learning multivariate hawkes processes at scale. arXiv preprint arXiv:2002.12501, 2020.
Yosihiko Ogata. Statistical models for earthquake occurrences and residual analysis for point processes. Journal of the American Statistical association, 83(401):9–27, 1988.
Yosihiko Ogata. Space-time point-process models for earthquake occurrences. Annals of the Institute of Statistical Mathematics, 50(2):379–402, 1998.
Travis E Oliphant. A guide to NumPy, volume 1. Trelgol Publishing USA, 2006.
Travis E Oliphant. Python for scientific computing. Computing in Science & Engineering, 9(3): 10–20, 2007.
Myle Ott, Sergey Edunov, Alexei Baevski, Angela Fan, Sam Gross, Nathan Ng, David Grangier, and Michael Auli. fairseq: A fast, extensible toolkit for sequence modeling. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics (Demonstrations), pp. 48–53, Minneapolis, Minnesota, June 2019. Association for Computational Linguistics. doi: 10.18653/v1/N19-4009. URL https://www.aclweb.org/anthology/ N19-4009.
T. Ozaki. Maximum likelihood estimation of Hawkes’ self-exciting point processes. Annals of the Institute of Statistical Mathematics, 31(1):145–155, Dec 1979. ISSN 1572-9052. doi: 10.1007/ bf02480272.
Junhyung Park, Adam W Chaffee, Ryan J Harrigan, and Frederic Paik Schoenberg. A non-parametric Hawkes model of the spread of ebola in west africa. 2019.
Adam Paszke, Sam Gross, Francisco Massa, Adam Lerer, James Bradbury, Gregory Chanan, Trevor Killeen, Zeming Lin, Natalia Gimelshein, Luca Antiga, et al. Pytorch: An imperative style, high-performance deep learning library. In Advances in neural information processing systems, pp. 8026–8037, 2019.
Prajit Ramachandran, Barret Zoph, and Quoc V Le. Searching for activation functions. arXiv preprint arXiv:1710.05941, 2017.
Alex Reinhart et al. A review of self-exciting spatio-temporal point processes and their applications. Statistical Science, 33(3):299–318, 2018.
Davis Rempe, Tolga Birdal, Yongheng Zhao, Zan Gojcic, Srinath Sridhar, and Leonidas J Guibas. CaSPR: Learning canonical spatiotemporal point cloud representations. arXiv preprint arXiv:2008.02792, 2020. Danilo Rezende and Shakir Mohamed. Variational inference with normalizing flows. In International Conference on Machine Learning, pp. 1530–1538, 2015. Yulia Rubanova, Ricky T. Q. Chen, and David Duvenaud. Latent ODEs for irregularly-sampled time series. arXiv preprint arXiv:1907.03907, 2019. Frederic Paik Schoenberg, Marc Hoffmann, and Ryan J Harrigan. A recursive point process model for infectious diseases. Annals of the Institute of Statistical Mathematics, 71(5):1271–1287, 2019. Oleksandr Shchur, Marin Bilos, and Stephan G ˇ unnemann. Intensity-free learning of temporal point ¨ processes. arXiv preprint arXiv:1909.12127, 2019. John Skilling. The eigenvalues of mega-dimensional matrices. In Maximum Entropy and Bayesian Methods, pp. 455–466. Springer, 1989. Enzo Tagliazucchi, Pablo Balenzuela, Daniel Fraiman, and Dante R Chialvo. Criticality in large-scale brain fMRI dynamics unveiled by a novel point process analysis. Frontiers in physiology, 3:15, 2012. Enzo Tagliazucchi, Michael Siniatchkin, Helmut Laufs, and Dante R Chialvo. The voxel-wise functional connectome can be efficiently derived from co-activations in a sparse spatio-temporal point-process. Frontiers in neuroscience, 10:381, 2016. Takeshi Teshima, Isao Ishikawa, Koichi Tojo, Kenta Oono, Masahiro Ikeda, and Masashi Sugiyama. Coupling-based invertible neural networks are universal diffeomorphism approximators. arXiv preprint arXiv:2006.11469, 2020. The New York Times. Coronavirus (Covid-19) Data in the United States, 2020. URL https: //github.com/nytimes/covid-19-data. Alexander Tong, Jessie Huang, Guy Wolf, David van Dijk, and Smita Krishnaswamy. TrajectoryNet: A dynamic optimal transport network for modeling cellular dynamics. arXiv preprint arXiv:2002.04461, 2020. U.S. Geological Survey. Earthquake Catalogue (accessed August 21, 2020), 2020. URL https: //earthquake.usgs.gov/earthquakes/search/. Stefan Van Der Walt, S Chris Colbert, and Gael Varoquaux. The numpy array: a structure for efficient numerical computation. Computing in Science & Engineering, 13(2):22, 2011. Guido Van Rossum and Fred L Drake Jr. Python reference manual. Centrum voor Wiskunde en Informatica Amsterdam, 1995. 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. Michael Waskom, Olga Botvinnik, Drew O’Kane, Paul Hobson, Joel Ostblom, Saulius Lukauskas, David C Gemperline, Tom Augspurger, Yaroslav Halchenko, John B. Cole, Jordi Warmenhoven, Julian de Ruiter, Cameron Pye, Stephan Hoyer, Jake Vanderplas, Santi Villalba, Gero Kunter, Eric Quintero, Pete Bachant, Marcel Martin, Kyle Meyer, Alistair Miles, Yoav Ram, Thomas Brunner, Tal Yarkoni, Mike Lee Williams, Constantine Evans, Clark Fitzgerald, Brian, and Adel Qalieh. mwaskom/seaborn: v0.9.0 (july 2018), July 2018. URL https://doi.org/10. 5281/zenodo.1313201. Guandao Yang, Xun Huang, Zekun Hao, Ming-Yu Liu, Serge Belongie, and Bharath Hariharan. PointFlow: 3d point cloud generation with continuous normalizing flows. In Proceedings of the IEEE International Conference on Computer Vision, pp. 4541–4550, 2019. Qingyuan Zhao, Murat A Erdogdu, Hera Y He, Anand Rajaraman, and Jure Leskovec. Seismic: A self-exciting point process model for predicting tweet popularity. In Proceedings of the 21th ACM SIGKDD international conference on knowledge discovery and data mining, pp. 1513–1522, 2015.
# A ADDITIONAL RESULTS AND FIGURES
<table><tr><td></td><td colspan="2">Citibike NY</td></tr><tr><td>Model</td><td>Temporal</td><td>Spatial</td></tr><tr><td>Poisson Process</td><td>0.609±0.012</td><td></td></tr><tr><td>Self-correcting Process</td><td>-5.649±1.433</td><td></td></tr><tr><td>Hawkes Process</td><td>1.062±0.000</td><td></td></tr><tr><td>Neural Hawkes Process 1.030±0.015</td><td></td><td></td></tr><tr><td>Conditional KDE</td><td></td><td>-2.856±0.000</td></tr><tr><td>Time-varying CNF</td><td></td><td>-2.132±0.012</td></tr><tr><td>Neural Jump SDE</td><td>1.092±0.002</td><td>-2.731±0.001</td></tr><tr><td>Jump CNF</td><td>1.105±0.002</td><td>-2.155±0.015</td></tr><tr><td>Attentive CNF</td><td>1.112±0.002</td><td>-2.095±0.006</td></tr></table>
 Figure 8: Runtime comparison of Jump and Attentive CNF. Table 2: Log-likelihood values on held-out test data for an urban mobility data set.
 Figure 9: Both the Jump CNF and Attentive CNF are capable of modeling different the spatial distributions based on event history, so the appearance of a new event effectively shifts the distribution instantaneously. Shown on a synthetic 1-D data set similar to PINWHEEL, except we use a mixture of three Gaussians. Each event increases the likelihood of events for the cluster to the right.
 Figure 10: Learned attention weights for random event sequences.
# B BASELINE
Our self-excitation baseline uses a Hawkes process to model the temporal variable, then uses a Gaussian mixture model to describe the spatial distribution conditioned on history of events. This corresponds to the following likelihood decomposition
$$\log p ( t _ { 1 } , \dots , t _ { n } , x _ { 1 } , \dots , x _ { n } ) = \sum _ { i = 1 } ^ { n } \log p ( x _ { i } | t _ { i } , t _ { 1 } , \dots , t _ { i - 1 } , x _ { 1 } , \dots , x _ { i - 1 } ) + \sum _ { i = 1 } ^ { n } \log p ( t _ { i } | t _ { 1 } , \dots , t _ { i - 1 } )$$
Note that $t _ { i }$ does not depend on the spatial variables associated with previous events. This dependence structure allows the usage of simple temporal point processes to model $t _ { i }$ , e.g. a Hawkes process, since temporal variables do not depend on the spatial information. The spatial distribution conditions all past events as well as the current time of occurance.
Our baseline model assumes a simple Gaussian conditional model, that new events are likely to appear near previous events.
$$\log p ( x _ { i } | t _ { i } , t _ { 1 } , \dots , t _ { i - 1 } , x _ { 1 } , \dots , x _ { i - 1 } ) = \sum _ { j = 1 } ^ { i - 1 } \alpha _ { j } \mathcal { N } ( x _ { j } | \sigma ^ { 2 } ) , \quad \alpha _ { j } = \frac { \exp \{ ( t _ { j } - t _ { i } ) / \tau \} } { \sum _ { j ^ { \prime } = 1 } ^ { i - 1 } \exp \{ ( t _ { j ^ { \prime } } - t _ { i } ) / \tau \} }$$
This parameteric model has two learnable parameters: $\sigma ^ { 2 }$ and $\tau$ , which control the rate of decay in the spatial and temporal domains, respectively.
However, this Gaussian spatial model assumes events are propagated in all directions equally and can only model local self-excitation behavior. These assumptions are often used for simplifications but are generally incorrect for many spatio-temporal data. To name a few, earthquakes occur more frequently along boundaries of tectonic plates, epidemics propagate along traffic routes, taxi demands saturate locally and change as customers move around.
# C PRE-PROCESSING STEPS FOR EACH DATA SET
PINWHEEL We sample from a multivariate Hawkes process with 10 dimensions. We turn this into continuous spatial variables by assigning each dimension to a cluster from a “pinwheel” distribution, and sample from the corresponding cluster for each event. Number of events per sequences ranges between 4 to 108.
EARTHQUAKES For modeling earthquakes and aftershocks, we gathered location and time of all earthquakes in Japan from 1990 to 2020 with magnitude of at least 2.5 from the U.S. Geological Survey (2020). Starting from January 01, 1990, we created sequences with a gap of 7 days. Each sequence was of length 30 days. We ensured there was no contamination between train/val/test sets by removing intermediate sequences. We removed earthquakes from 2010 November to 2011 December, as these sequences were too long and only served as outliers in the data. This resulted in 950 training sequences, 50 validation sequences, and 50 test sequences. Number of events per sequence ranges between 18 to 543.
COVID-19 CASES We use data released publicly by The New York Times (2020) on daily COVID-19 cases in the New Jersey state, from March to July of 2020. The data is aggregated at the county level, which we dequantize uniformly across the county. We also dequantize the temporal axis by assigning new cases uniformly within the day. Starting at March 15, and every 3 days, we took a 7 day length sequence. For each sequence, we sampled each event with a probability of 0.01. This was done 50 times per sequence. We ensured there was no contamination between train/val/test sets by removing intermediate sequences. This resulted in 1450 training sequences, 100 validation sequences, and 100 test sequences. Number of events per sequence ranges between 3 to 323.
CITIBIKE Citibike is a bike sharing service in New York City. We treat the start of each trip as an event, and use the data from April to August of 2019. We split into sequences of length 1 day starting at $5 { : } 0 0 { \mathrm { a m } }$ of each day. For each sequence, we subsampled with a probability of 0.005 per event, 20 times. This resulted in 2440 training sequences, 300 validation sequences, and 320 test sequences. Number of events per sequence ranges between 9 to 231.
 Figure 11: Histograms of the number of events per sequence in each processed data set.
BOLD5000 This consists of fMRI scans of four participants as they are given visual stimuli (Chang et al., 2019). We use the sessions of a single patient and for each run, we split into 3 sequences, treated individually. We converted brain responses into spatio-temporal events following the $\mathbf { Z }$ -score thresholding approach in Tagliazucchi et al. 2016, Equation (2). We used a threshold of $\gamma = 6 . 0$ . We split the data into 1050 training sequences, 150 val sequences, 220 test sequences. Number of events per sequence ranges between 6 to 1741.
Each data set contains sequences with highly variable number of events, with varying degrees of dependence between events, making them difficult to model with traditional point process models. We plot histograms showing the number of events per sequence in Figure 11.
# D HYPERPARAMETERS CHOSEN AND TESTED
For the time-varying, jump, and attentive CNF models, we parameterized the CNF drift as a multilayer perceptron (MLP) with dimensions $[ d - 6 4 - 6 4 - 6 4 - d ]$ , where $d$ is the number of spatial variables. We swept over activation functions between using softplus or a time-dependent Swish (Ramachandran et al., 2017).
$$\mathrm { T i m e D e p e n d e n t S w i s h } ( t , z ) = h \sigma ( \beta ( t ) \odot z )$$
where $\sigma$ is the logistic sigmoid function, $\odot$ is the Hadamard (element-wise) product, and $\beta : \mathbb { R } \mathbb { R } _ { d _ { z } }$ is a MLP with widths $[ \bar { 1 } - 6 4 - d _ { z } ]$ where $d _ { z }$ is the dimension of $z$ , using the softplus activation function. We ultimately decided on using the time-dependent Swish for all experiments.
We swept over the MLP for defining $f _ { h }$ for the continuous-time hidden state in eq. (11) using hidden widths of $[ 8 - 2 0 ]$ , $[ 3 2 - 3 2 ]$ , $[ 6 4 - 6 4 ]$ , $\left[ 3 2 - 3 2 - 3 2 \right]$ , and $[ 6 4 - 6 4 - 6 4 ]$ . The majority of models used $3 2 - 3 2$ as it provided enough flexibility while remaining easy to solve. We used the softplus activation function. We tried MLP for parameterizing the instantaneous change in eq. (12); however, it was too unstable for long sequences. We therefore switched to the GRU parameterization, which takes an input (new event), the hidden state at the time of event, and outputs a new hidden state.
We regularized the $L _ { 2 }$ norm of the hidden state drift with a strength of 1e-4, chosen from $\{ 0$ , 1e-4, 1e-3, 1e- $\langle 2 \}$ . We optionally used optimal transport-inspired regularization from Finlay et al. (2020), which adds a Frobenius norm regularization to the gradient of the drift in addition to the $L _ { 2 }$ norm regularization, to the CNF models with a strength of $\{ 0 \}$ , 1e-4, 1e-3, 1e- $\cdot 2 \}$ . The Time-varying and Attentive CNF models did not require regularization and were mostly kept at 0, but the Jump CNF models benefited from some amount of regularization to avoid numerical instability.
To model a non-trivial spatial distribution for the entire data interval, we shift the data interval to start at $t = 2$ for all CNF models. Thus the interval used for parameterizing the CNF is $[ 2 , T + 2 ]$ . Generally, the “time” variable is a dummy one; we can place the base distribution at any time, and we can choose any interval on the real line to be the data interval; this does not limit the model in any way.
For the Jump CNF, we used a composition of 4 radial flows (Rezende & Mohamed, 2015) to parameterize the instantaneous updates in eq. (17). All parameters of the radial flows were parameterized to be the output of a MLP that takes as input the hidden state at the time of the event (before the hidden state is updated based on the current event). The radial flows were initialized in such a way that the log determinant is near zero.
For the Attentive CNF, the drift function consists of
Time-dependent $\mathrm { M L P } ( d - 6 4 - 6 4 ) 2 \times ]$ MultiheadAttention Time-dependent MLP(64 − 64 − d)
where the Time-dependent MLPs make use of the TimeDependentSwish. As was done in Vaswani et al. (2017), the multihead attention is used within a residual branch, except we swapped LayerNorm (Ba et al., 2016) with ActNorm (Kingma & Dhariwal, 2018) as LayerNorm has an unbounded Lipschitz and can be ill-suited for use in ODEs. We tested both standard multihead attention (Vaswani et al., 2017) and the Lipschitz multihead attention (Kim et al., 2020). The Lipschitz multihead attention typically produced similar validation NLL as the standard multihead attention but were more stable on multiple occassions. We therefore kept the Lipschitz multihead attention for all experiments. We additionally, use an auxiliary (non-attentive, simply with the two multihead attention layers removed) CNF to map from 0 (i.e. the time of base distribution) to the beginning of the data interval.
We initialized all Neural ODEs (for the hidden state and CNFs) with zero drift by initializing the weights and biases of the final layer to zero.
The log-likelihood values reported are after the spatial variables have been standardized using the empirical mean and standard deviation from the training set.
We train and test on log-likelihood (in nats) per event, which normalizes eq. (8) of each sequence by the number of events.
All integrals were solved using Chen (2018) to within a relative and absolute tolerance of 1E-4 or 1E-6, chosen based on preliminary testing for convergence and stability.
Our implementation of the Neural Jump SDE shares the same continuous-time hidden state parameterization but uses a mixture of Gaussians as the spatial model. We used 5 mixtures, and a MLP that maps from the hidden state to the parameters of this mixture of Gaussians (the means, log standard deviations, and mixture coefficients).
# E REMOVING CROSS-EVENT PARTIAL DERIVATIVES
This results in a lower-variance gradient estimator for training, and allows parallel computation of conditional log probabilities at test time.
We first summarily describe the attention mechanism. For an input $\boldsymbol { X } \in \mathbb { R } ^ { n \times d }$ representing the f $n$ variabled values $\{ x _ { s } ^ { ( 0 ) } , \ldots , x _ { s } ^ { ( n ) } \}$ . . . , x(n)s } at some valudependent on f , $s$ , this attention mechanism creates logitsch that the output is $P \in \mathbb { R } ^ { n \times n }$ $V \in R ^ { n \times d }$ $X$
$$O = \underbrace { \operatorname { s o f t m a x } ( P ) } _ { : = S } V .$$
where the softmax is taken over each row of $P$ . The output is then added to $X$ as a residual connection. The multihead attention computes $P$ in a way such that $P _ { i j }$ depends on $X _ { i }$ and $X _ { j }$ , and $V _ { i }$ depends on $X _ { i }$ . This is true for both the vanilla MHA (Vaswani et al., 2017) and the L2 MHA (Kim et al., 2020). For our use case, $P _ { i j }$ is set to −inf for $j > i$ as we don’t want to attend to future events.
We retain only the block-diagonal gradients where each block contains variables corresponding to one event. This is equivalent to removing all the cross-event dependencies.
$${ \frac { \partial { \cal O } _ { i } } { \partial X _ { i } } } = S _ { : , i } { \frac { \partial V _ { i } } { \partial X _ { i } } } + V ^ { \mathsf { T } } { \frac { \partial S } { \partial P _ { i } } } { \frac { \partial P _ { i } } { \partial X _ { i } } } + V ^ { \mathsf { T } } { \frac { \partial S } { \partial P _ { : , i } } } { \frac { \partial P _ { : , i } } { \partial X _ { i } } }$$
# F PARALLEL SOLVING OF MULTIPLE ODES WITH VARYING INTERVALS
Our numerical ODE solvers integrate a single ODE system $\begin{array} { r } { \frac { d x } { d t } = f ( t , x ) } \end{array}$ , where $x \in \mathbb { R } ^ { d }$ and $f : \mathbb { R } ^ { 1 + d } \mathbb { R } ^ { d }$ , on a single fixed interval $[ t _ { s t a r t } , t _ { e n d } ]$ . We can express the inputs and outputs of an ODE solver with
$$\odot \mathtt { D E S o l v e } ( x _ { 0 } , f , t _ { s t a r t } , t _ { e n d } ) \triangleq x _ { 0 } + \int _ { t _ { s t a r t } } ^ { t _ { e n d } } f ( t , x ( t ) ) d t = x ( t _ { e n d } ) .$$
where $x _ { 0 }$ is a vector containing the initial state at the initial time $t _ { 0 }$ .
Multiple ODEs Now suppose we have a set of that we would like to solve. If all systems had the $M$ systems (i.e. e initial time $\begin{array} { r } { { \frac { d x _ { m } } { d t } } = f _ { m } } \end{array}$ for outp $m = 1 , \ldots , M )$ $t _ { s t a r t }$ and $t _ { e n d }$ , we can readily create a joint system
$$\boldsymbol { x } _ { j o i n t } = \left[ \begin{array} { c } { x _ { 1 } } \\ { \vdots } \\ { x _ { M } } \end{array} \right] \qquad \mathrm { t h a t ~ f o l l o w s } \quad \frac { d x _ { j o i n t } } { d t } = \left[ \begin{array} { c } { f _ { 1 } ( t , x _ { 1 } ) } \\ { \vdots } \\ { f _ { M } ( t , x _ { M } ) } \end{array} \right]$$
Solving this joint system can be done in parallel with a single call to ODESolve:
$$x _ { j o i n t } ( t _ { 1 } ) = \mathsf { O D E S o l v e } ( x _ { 0 j o i n t } , f _ { j o i n t } , t _ { 0 } , t _ { 1 } )$$
which computes $x _ { m } ( t _ { 1 } )$ for all $m = 1 , \ldots , M$ . This is the standard method used for solving a batch of Neural ODEs.
Adding dependencies is straightforward Note that extending this further, the ODE systems do not need to be independent. They can depend on other variables at the same concurrent time value because the joint system is still an ordinary differential equation. For instance, we can have
$$\frac { d x _ { m } } { d t } = f _ { m } ( t , x _ { 1 } , \ldots , x _ { m } )$$
where $f _ { m } : \mathbb { R } ^ { 1 + M d } \mathbb { R } ^ { d }$ . Each system is now a partial differential equation, but the joint system $x _ { j o i n t }$ is still an ODE and can be solved with one call to ODESolve.
Varied time intervals Now suppose each system has a different time interval that we want to solve. Different initial times and different end times. Let’s denote the start and end time for the $m$ -th system as t start and $t _ { e n d } ^ { ( m ) }$ respectively. We can construct a dummy variable that always integrates from 0 to 1, and perform a change of variables (reparameterization) to transform every system to use this dummy variable.
As a concrete example of this reparameterzation procedure, consider just one system $x ( t )$ with drift function $f ( t , x )$ that we want to integrate from $t _ { s t a r t }$ to $t _ { e n d }$ with the initial value $x _ { 0 }$ . We can transform $x ( t )$ using the relation $\begin{array} { r } { s = \frac { t - \overline { { t } } _ { s t a r t } } { t _ { e n d } - t _ { s t a r t } } } \end{array}$ , or equivalently
$$t = s ( t _ { e n d } - t _ { s t a r t } ) + t _ { s t a r t } ,$$
into a solution $\tilde { { \boldsymbol { x } } } ( s )$ on the unit interval $[ 0 , 1 ]$ such that
$$\tilde { x } ( s ) = x ( s ( t _ { e n d } - t _ { s t a r t } ) + t _ { s t a r t } )$$
The drift function for $\tilde { x }$ then follows as
$$\begin{array} { l } { \displaystyle \tilde { f } ( s , \tilde { x } ( s ) ) \triangleq \frac { d \tilde { x } ( s ) } { d s } = \frac { d x ( t ) } { d t } \bigg \rvert _ { t = s ( t _ { e n d } - t _ { s t a r t } ) + t _ { s t a r t } } \frac { d t } { d s } } \\ { \displaystyle = f ( t , x ( t ) ) \bigg \rvert _ { t = s ( t _ { e n d } - t _ { s t a r t } ) + t _ { s t a r t } } ( t _ { e n d } - t _ { s t a r t } ) } \\ { \displaystyle = f \big ( s ( t _ { e n d } - t _ { s t a r t } ) + t _ { s t a r t } , \tilde { x } ( s ) \big ) \big ( t _ { e n d } - t _ { s t a r t } \big ) } \end{array}$$
Now since $\tilde { x } ( 0 ) = x ( t _ { s t a r t } )$ and $\tilde { x } ( 1 ) = x ( t _ { e n d } )$ , the following are equivalent
$$\boldsymbol { x } ( t _ { e n d } ) = \boldsymbol { \mathrm { O D E S O 1 v e } } ( x _ { 0 } , \tilde { f } , 0 , 1 ) = \boldsymbol { \mathrm { O D E S O 1 v e } } ( x _ { 0 } , f , t _ { s t a r t } , t _ { e n d } )$$
Putting it all together Let $\widetilde { x } _ { m } ( s )$ be the reparameterized solution for $x _ { m } ( t )$ such that
$$\tilde { x } _ { m } ( s ) = x _ { m } \left( s \left( t _ { e n d } ^ { ( m ) } - t _ { s t a r t } ^ { ( m ) } \right) + t _ { s t a r t } \right)$$
We can then solve for all $M$ systems, with different varying time intervals, using
$$\tilde { x } _ { j o i n t } = \left[ \begin{array} { l } { \tilde { x } _ { 1 } } \\ { \vdots } \\ { \tilde { x } _ { M } } \end{array} \right] \qquad \quad \mathrm { t h a t ~ f o l l o w s } \quad \frac { d \tilde { x } _ { j o i n t } } { d s } = \left[ \begin{array} { l } { \tilde { f } _ { 1 } ( s , \tilde { x } _ { 1 } ) } \\ { \vdots } \\ { \tilde { f } _ { M } ( s , \tilde { x } _ { M } ) } \end{array} \right] .$$
Solving this system to $s = 1$ yields $\tilde { x } _ { m } ( 1 ) = x _ { m } ( t _ { e n d } ^ { ( m ) } )$
Assuming $t _ { s t a r t } ^ { ( m ) } = 0$ for all $m = 1 , \ldots , M$ in order to reduce notational complexity, we can write this joint system in terms of the original systems as
$$\frac { d \tilde { x } _ { j o i n t } } { d s } = \left[ \begin{array} { c } { f _ { 1 } \left( s t _ { e n d } ^ { ( 1 ) } , \tilde { x } ( s ) \right) \ t _ { e n d } } \\ { \vdots } \\ { f _ { 1 } \left( s t _ { e n d } ^ { ( 1 ) } , \tilde { x } ( s ) \right) \ t _ { e n d } } \end{array} \right] .$$
This is the joint system written in equation 14. The joint system in equation 19 adds dependence between the $M$ systems but can still be solved with a single ODESolve.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321# ENCODING IN STYLE: A STYLEGAN ENCODER FOR IMAGE-TO-IMAGE TRANSLATION
Anonymous authors Paper under double-blind review
# ABSTRACT
We present a generic image-to-image translation framework, Pixel2Style2Pixel $( p S p )$ . Our pSp framework is based on a novel encoder network that directly generates a series of style vectors which are fed into a pretrained StyleGAN generator, forming the extended $\mathcal { W } +$ latent space. We first show that our encoder can directly embed real images into $\mathcal { W } +$ , with no additional optimization. We further introduce a dedicated identity loss which is shown to achieve improved performance in the reconstruction of an input image. We demonstrate pSp to be a simple architecture that, by leveraging a well-trained, fixed generator network, can be easily applied on a wide-range of image-to-image translation tasks. Solving these tasks through the style representation results in a global approach that does not rely on a local pixel-to-pixel correspondence and further supports multi-modal synthesis via the resampling of styles. Notably, we demonstrate that pSp can be trained to align a face image to a frontal pose with no labeled data and generate multi-modal results for ambiguous tasks such as conditional face generation from sketches and segmentation maps.
# 1 INTRODUCTION
In recent years, Generative Adversarial Networks (GANs) have significantly advanced image synthesis, particularly on face images. State-of-the-art image generation methods have achieved high visual quality and fidelity, and can now generate images with phenomenal realism. Most notably, StyleGAN (Karras et al., 2019; 2020) proposes a novel style-based generator architecture and attains state-of-the-art visual quality on high-resolution images. Moreover, it has been demonstrated that it has a disentangled latent space, $\mathcal { W }$ (Yang et al., 2019; Collins et al., 2020; Shen et al., 2020), which may offer control and editing capabilities.
Recently, numerous methods have shown competence in controlling StyleGAN’s latent space and performing meaningful manipulations in $\mathcal { W }$ (Jahanian et al., 2019; Shen et al., 2020; Tewari et al., 2020; Hark ¨ onen et al., 2020). To perform such edits on real images, one needs to invert the image ¨ into StyleGAN’s latent space, i.e., retrieve the latent code that reconstructs the image. However, it has been shown that inverting a real image into a 512-dimensional vector $\mathbf { w } \in \mathcal { W }$ does not lead to an accurate reconstruction. Motivated by this, it has become common practice (Abdal et al., 2019; 2020; Baylies, 2019; Zhu et al., 2020a; Adbal et al., 2020) to encode real images into an extended latent space, $\mathcal { W } +$ , defined by the concatenation of 18 different 512-dimensional w vectors, one for each input layer of StyleGAN. Nevertheless, many methods resort to using per-image optimization over $\mathcal { W } +$ , requiring several minutes for a single image. To accelerate this optimization process, some methods (Baylies, 2019; Zhu et al., 2020a) have trained an encoder to infer an approximate vector in $\mathcal { W } +$ which serves as a good initial point from which additional optimization is required. However, a fast, direct, and accurate learned inversion of real images into $\mathcal { W } +$ remains a challenge.
In this paper, we focus on the broader task of latent space embedding, which aims to retrieve the latent vector that generates a desired, not necessarily known, image. We do so by introducing a novel encoder architecture tasked with encoding an arbitrary image directly into $\mathcal { W } +$ . The encoder is based on a Feature Pyramid Network (Lin et al., 2017), where style feature vectors are extracted from different pyramid scales and inserted directly into a fixed, pretrained StyleGAN generator in correspondence to their spatial scales. Our encoder into $\mathcal { W } +$ , together with the StyleGAN decoder, form a generic encoder-decoder network that benefits many image-to-image translation tasks. Focusing on face images, we first demonstrate our method’s ability to successfully reconstruct a given image while preserving identity and other attributes. We then present numerous image-to-image translation applications. In a sense, our method performs Pixel2Style2Pixel translation, as every image is first encoded into style vectors and then into an image, and is therefore dubbed $p S p$ .
While many previous approaches to solving image-to-image translations tasks involve dedicated architectures specific for solving a single problem, we follow the spirit of pix2pix (Isola et al., 2017) and define a generic framework able to solve a wide range of tasks, all using the same architecture. Besides the simplification of the training process, as no adversary discriminator needs to be trained, using a pretrained StyleGAN generator offers several intriguing advantages over previous works. Many image-to-image architectures explicitly feed the generator with residual feature maps from the encoder (Isola et al., 2017; Wang et al., 2018), creating a strong locality bias (Richardson & Weiss, 2020). In contrast, our generator is governed only by the styles with no direct spatial input. The advantage of such a global approach is most evident in the task of Face Frontalization, where our encoder can be trained to align a given face image to a frontal pose with no labeled data. Another notable advantage of the intermediate style representation is the inherent support for multi-modal synthesis for ambiguous tasks such as face generation from sketches, segmentation maps, or lowresolution images. In such tasks, the generated styles can be resampled to create variations of the output image with no change to the architecture or training process.
The main contributions of this paper are: (i) a novel StyleGAN encoder able to directly encode real face images into the $\mathcal { W } +$ target latent domain; and (ii) a generic end-to-end framework for solving image-to-image translation tasks.
# 2 RELATED WORK
Latent Space Embedding With the rapid evolution of GANs, many works have tried to understand and control their latent space. A specific task that has received substantial attention is $G A N$ Inversion — where the latent vector from which a pretrained GAN most accurately reconstructs a given, known image, is sought. Motivated by its state-of-the-art image quality and latent space semantic richness, many recent works have used StyleGAN (Karras et al., 2019; 2020) for this task. Generally, inversion methods either directly optimize the latent vector to minimize the error for the given image (Lipton & Tripathi, 2017; Creswell & Bharath, 2018; Abdal et al., 2019; 2020), train an encoder to map the given image to the latent space (Perarnau et al., 2016; Creswell & Bharath, 2018; Pidhorskyi et al., 2020; Guan et al., 2020; Nitzan et al., 2020), or use a hybrid approach combining both (Baylies, 2019; Zhu et al., 2020a). Typically, methods performing optimization are superior in reconstruction quality to a learned encoder mapping, but require a substantially longer time. Unlike the above methods, our encoder can accurately and efficiently embed a given face image into the extended latent space $\mathcal { W } +$ of a fixed, pretrained StyleGAN generator, with no further optimization.
Image-to-Image Image-to-Image translation techniques aim at learning a conditional image generation function that maps an input image of a source domain to a corresponding image of a target domain. Isola et al. (2017) first introduced the use of conditional GANs to solve various imageto-image translation tasks. Since then, their work has been extended for many scenarios: highresolution synthesis (Wang et al., 2018), unsupervised learning (Liu et al., 2017; Zhu et al., 2017a; Katzir et al., 2019; Lira et al., 2020), multi-modal image synthesis (Zhu et al., 2017b; Huang et al., 2018; Choi et al., 2020), and conditional image synthesis (Park et al., 2019; Li et al., 2019; Liu et al., 2019b; Zhu et al., 2020b; Chen et al., 2020). The aforementioned works have constructed dedicated architectures, which require training the generator network.
Latent-Space Manipulation Recently, numerous papers have presented diverse methods to learn semantic edits of the latent code. A popular approach is finding linear directions that correspond to changes in a given binary labeled attribute, such as young $ \mathrm { o l d }$ , or no-smile smile (Shen et al., 2020; Goetschalckx et al., 2019; Denton et al., 2019; Adbal et al., 2020). Tewari et al. (2020) utilize a pretrained 3DMM to learn semantic face edits in the latent space. Jahanian et al. (2019) find latent space paths that correspond to a specific transformation, such as zoom or rotation, in a selfsupervised manner. Hark ¨ onen et al. (2020) find useful paths in an unsupervised manner by using the ¨ principal component axes (PCA) of an intermediate activation space. Finally, Collins et al. (2020) perform local semantic editing by manipulating corresponding components of the latent code.
 Figure 1: Our pSp architecture. Feature maps are first extracted using a standard feature pyramid over a ResNet backbone. For each of the 18 target styles, a small mapping network is trained to extract the learned styles from the corresponding feature map, where styles (0-2) are generated from the small feature map, (3-6) from the medium feature map, and (7-18) from the largest feature map. The mapping network, map2style, is a small fully convolutional network, which gradually reduces spatial size using a set of 2-strided convolutions followed by LeakyReLU activations. Each generated 512 vector, is fed into StyleGAN, starting from its matching affine transformation, $A$ .
# 3 THE PSP FRAMEWORK
Our pSp framework builds upon the representative power of a pretrained StyleGAN generator and the $\mathcal { W } +$ latent space. To utilize this representation one needs a strong encoder that is able to match each input image to an accurate encoding in the latent domain. A simple technique to embed into this domain is directly encoding a given input image into $\mathcal { W } +$ using a single 512-dimensional vector obtained from the last layer of the encoder network, thereby learning all 18 style vectors together. However, such an architecture presents a strong bottleneck making it difficult to fully represent the finer details of the original image and therefore limiting the reconstruction quality.
In StyleGAN, the authors have shown that the different style inputs correspond to different levels of detail, which are roughly divided into three groups — coarse, medium, and fine. Following this observation, in pSp we extend an encoder backbone with a feature pyramid (Lin et al., 2017), generating three levels of feature maps from which styles are extracted using a simple intermediate network — map2style — shown in Figure 1. The styles, aligned with the hierarchical representation, are then fed into the generator in correspondence to their scale to generate the output image, thus completing the translation from input pixels to output pixels, through the intermediate style representation. Therefore, our architecture, pSp, is an end-to-end image-to-image translation framework. The complete architecture is illustrated in Figure 1.
As in StyleGAN, we further define $\overline { { \mathbf { W } } }$ to be the average style vector of the pretrained generator. Given an input image, $\mathbf { X }$ , the output of our model is then defined as $p S p ( \mathbf { x } ) : = \mathbf { \bar { \boldsymbol { G } } } ( E ( \mathbf { \boldsymbol { x } } ) + \mathbf { \bar { \boldsymbol { w } } } )$ where $E ( \cdot )$ and $G ( \cdot )$ denote the encoder and StyleGAN generator, respectively. In this formulation, our encoder aims to learn the latent code with respect to the average style vector. We find that this results in better initialization.
# 3.1 LOSS FUNCTIONS
While the style-based translation is the core part of our framework, the choice of losses is also crucial. Our encoder is trained using a weighted combination of several objectives. First, we utilize the pixel-wise $\mathcal { L } _ { 2 }$ loss,
$$\mathcal { L } _ { 2 } \left( \mathbf { x } \right) = | | \mathbf { x } - p S p ( \mathbf { x } ) | | _ { 2 } .$$
In addition, to learn perceptual similarities, we utilize the LPIPS (Zhang et al., 2018) loss, which has been shown to better preserve image quality (Guan et al., 2020) compared to the more standard perceptual loss (Johnson et al., 2016):
$$\mathcal { L } _ { \mathrm { L P I P S } } \left( \mathbf { x } \right) = | | F ( \mathbf { x } ) - F ( p S p ( \mathbf { x } ) ) | | _ { 2 } ,$$
where $F ( \cdot )$ denotes the perceptual feature extractor.
To encourage the encoder to output latent style vectors closer to the average latent vector, we additionally define the following regularization loss:
$$\mathcal { L } _ { \mathrm { r e g } } \left( \mathbf { x } \right) = | | E ( \mathbf { x } ) - \overline { { \mathbf { w } } } | | _ { 2 } .$$
Similar to the truncation trick introduced in StyleGAN, we find that adding this regularization in the training of our encoder improves image quality without harming the fidelity of our outputs, especially in some of the more ambiguous tasks explored below.
The Identity Loss One of the main challenges of face generation tasks is the ability to preserve identity between the input and output images. Since identity preservation is a crucial part of face reconstruction tasks, it is important to integrate this objective into the overall loss function. Therefore, we incorporate a dedicated recognition loss measuring the cosine similarity between the output image and its source,
$$\mathcal { L } _ { \mathrm { I D } } \left( \mathbf { x } \right) = 1 - \left. R ( \mathbf { x } ) , R ( p S p ( \mathbf { x } ) ) \right. ,$$
where $R$ is a pretrained ArcFace (Deng et al., 2019) network for face recognition. The input, $\mathbf { X }$ , and output, $p S p ( \mathbf { x } )$ , are cropped around the face and resized to $1 1 2 \times 1 1 2$ before being fed into $R$ .
In summary, the total loss function is defined as
$$\begin{array} { r } { \mathcal { L } ( \mathbf { x } ) = \lambda _ { 1 } \mathcal { L } _ { 2 } ( \mathbf { x } ) + \lambda _ { 2 } \mathcal { L } _ { \mathrm { L P I P S } } ( \mathbf { x } ) + \lambda _ { 3 } \mathcal { L } _ { \mathrm { I D } } ( \mathbf { x } ) + \lambda _ { 4 } \mathcal { L } _ { \mathrm { r e g } } ( \mathbf { x } ) , } \end{array}$$
where $\lambda _ { 1 } , \lambda _ { 2 } , \lambda _ { 3 } , \lambda _ { 4 }$ are constants defining the loss weights. Constants and other implementation details can be found in Appendix A.1.
# 3.2 THE BENEFITS OF THE STYLEGAN DOMAIN
The translation between images through the style domain differentiates pSp from many standard image-to-image translation frameworks, as it makes our model operate globally instead of locally, without requiring pixel-to-pixel correspondence. This is a desired property as it has been shown that the locality bias limits current methods when handling non-local transformations (Richardson & Weiss, 2020). Moreover, previous works (Karras et al., 2019; Collins et al., 2020) have demonstrated that the disentanglement of semantic objects learned by StyleGAN is due to its layer-wise representation. This ability to independently manipulate semantic attributes leads to another desired property: the support for multi-modal synthesis. As some translation tasks are ambiguous, where a single input image may correspond to several outputs, it is desirable to be able to sample these possible outputs. While this requires specialized changes in standard image-to-image architectures (Zhu et al., 2017b; Huang et al., 2018), our framework inherently supports this by simply sampling style vectors. In practice, this is done by randomly sampling a vector $\mathbf { w } \in \mathbb { R } ^ { 5 1 2 }$ and generating a corresponding latent code in $\mathcal { W } +$ by replicating w. Style mixing is then performed by replacing select layers of the computed latent with those of the randomly generated latent, possibly with an $\alpha$ parameter for blending between the two styles. This is illustrated in Figure 7a in Appendix A. There, layers 1-7 are selected from the input latent while layers 8-18 are taken from the sampled vector allowing one to obtain outputs with similar coarse and medium features, but varying fine features.
# 4 APPLICATIONS AND EXPERIMENTS
To explore the effectiveness of our approach we evaluate our pSp framework on numerous imageto-image translation tasks.
# 4.1 STYLEGAN INVERSION
We start by evaluating the usage of the pSp framework for StyleGAN Inversion, that is, finding the latent code of real images in the latent domain. We compare our method to the ALAE encoder (Pidhorskyi et al., 2020) and to the encoder from IDInvert (In-Domain Invert) (Zhu et al., 2020a). The ALAE method proposes a StyleGAN-based autoencoder, where the encoder is trained alongside the generator to generate latent codes. In IDInvert, real images are embedded into the latent domain of a pretrained StyleGAN by first encoding the image into $\mathcal { W } +$ and then directly optimizing over the generated image to tune the latent. For a fair comparison with our method, we compare with IDInvert where no further optimization is performed after computing the encoding of a given image.
 Figure 2: Results of pSp for StyleGAN inversion compared to other approaches on CelebA-HQ.
 Figure 3: (a) Ablation of the pSp encoder over CelebA-HQ. (b) The importance of the identity loss.
Results Figure 2 shows a qualitative comparison between the methods. One can see that the ALAE method, operating in the $\mathcal { W }$ domain, cannot accurately reconstruct the input images. While IDInvert (Zhu et al., 2020a) better preserves the image attributes, it still fails to accurately preserve identity and the finer details of the input image. In contrast, our method is able to preserve identity while also reconstructing fine details such as lighting, hairstyle, and glasses.
Next, we conduct an ablation study to analyze the effectiveness of the pSp architecture. We compare our architecture to two simpler variations. First, we define an encoder generating a 512-dimensional style vector in the $\mathcal { W }$ latent domain, extracted from the last layer of the encoder network. We then expand this and define an encoder with an additional layer to transform the 512-dimensional feature vector to a full $1 8 \times 5 1 2 ~ { \textmu } { \bmod { } }$ vector. Figure 3a shows that while this simple extension into $\mathcal { W } +$ significantly improves the results, it still cannot preserve the finer details generated by our architecture. In Figure 3b we show the importance of the identity loss in the reconstruction task.
Finally, Table 4a presents a quantitative evaluation measuring the different encoders examined above. Our pSp model is able to better preserve the original images in terms of both perceptual similarity and identity. To make sure the similarity score is independent of our loss function, we utilize the Curricularface (Huang et al., 2020) method for evaluation.
Figure 4: (a) Quantitative results for image reconstruction on CelebA-HQ. (b) Results for Face Frontalization on the FEI Face Database split by rotation angle of the face in the input image.
<table><tr><td>Method</td><td colspan="4">↑ Similarity↓LPIPS↓MSERuntime</td></tr><tr><td>ALAE IDInvert</td><td>0.06 0.18</td><td>0.32 0.22</td><td>0.15 0.06</td><td>0.207 0.032</td></tr><tr><td>W Encoder Naive W+</td><td>0.35</td><td>0.23 0.19</td><td>0.06 0.04</td><td>0.064 0.064</td></tr><tr><td></td><td>0.49 0.56</td><td>0.17</td><td>0.03</td><td>0.105</td></tr><tr><td>pSp</td><td></td><td></td><td></td><td></td></tr><tr><td colspan="5">(a)</td></tr></table>
<table><tr><td>Method 90°</td><td>个 Similarity ↓Runtime 70° 50° 30°</td></tr><tr><td>R&R 0.34 0.56 0.66</td><td>0.7 1.5</td></tr><tr><td>pSp 0.32 0.52 0.60</td><td>0.63 0.1</td></tr><tr><td>(b)</td><td></td></tr></table>
 Figure 5: Comparison of face frontalization methods.
# 4.2 FACE FRONTALIZATION
Face frontalization is a challenging task for image-to-image translation frameworks due to the required non-local transformations and the lack of paired training data. RotateAndRender (R&R) (Zhou et al., 2020) overcome this challenge by incorporating a geometric 3D alignment process before the translation process. Alternatively, we show that our style-based translation mechanism is able overcome these challenges, even when trained with no labeled data.
Methodology and details For this task, training is the same as the encoder formulation with two important changes. First, we randomly flip the target image, thus creating inconsistencies in terms of pose compared to the input image. This guides the model towards generating a frontalized face, as the true target pose is unknown. While this may seem minor, without this augmentation the model would simply learn to encode the input image, matching its pose as well as identity. Next, in frontalization, as we are less interested in the background region compared to the face region and its identity, we also change the weights of the loss objective. In particular, we decrease the weights of the LPIPS and $L _ { 2 }$ loss functions, and give more weight to the losses computed on the inner part of the face, focusing the model on the inner region while reducing the importance of background preservation. As shown below, these changes to the training objective are enough for the model to generate realistic frontal faces, while also preserving identity.
Results Results are illustrated in Figure 5. When trained with the same data, pix2pixHD is unable to converge to satisfying results as it is much more dependent on the correspondence between the input and output pairs. Conversely, our method is able to handle the task successfully, generating realistic frontal faces, which are comparable to the more involved RotateAndRender approach. This shows the benefit of using a pretrained StyleGAN for image translation, as it allows us to achieve visually-pleasing results even with weak supervision. Table 4b provides a quantitative evaluation on the FEI Faces Database (Thomaz & Giraldi, 2010). While R&R outperforms pSp, our simple approach provides an elegant alternative, without requiring specialized alignment steps.
 Figure 6: (a) Comparison of sketches presented in DeepFaceDrawing. (b) Comparisons to other label-to-image methods on CelebAMask-HQ. (c) Multi-modal outputs using pSp with style-mixing. (d) Human evaluation results on CelebA-HQ for Conditional Image Synthesis tasks. Each cell denotes the percentage of users who favored pSp over the listed method.
# 4.3 CONDITIONAL IMAGE SYNTHESIS
Conditional image synthesis aims at generating photo-realistic images conditioned on certain input types. In this section, our pSp architecture is tested on two conditional image generation tasks: generating high-quality face images from sketches and semantic label maps. We demonstrate that, with only minimal changes, our encoder successfully utilizes the expressiveness of StyleGAN to generate high-quality and diverse outputs. Additionally, an ideal mapping framework should be able to generate multiple diverse outputs for a given input. To achieve this, we utilize the multi-modal synthesis approach described in Section 3.2.
Methodology and details The training of the two conditional generation tasks is identical to that of the encoder for StyleGAN inversion except for the omission of the identity loss and the addition of the regularization loss. To generate multiple images at inference time, we perform style-mixing, taking layers $( 1 - 7 )$ from the latent code of the input image and layers $( 8 - 1 8 )$ from a randomly drawn w vector.
# 4.3.1 FACE FROM SKETCH
Common approaches for sketch-to-image synthesis incorporate hard constraints that require pixelwise correspondence between the input sketch and generated image, making them ill-suited when given incomplete sketches. DeepFaceDrawing (Chen et al., 2020) address this using a set of dedicated mapping networks. We show that pSp provides a simple alternative to past approaches.
Dataset Construction As there are currently no publicly available datasets representative of handdrawn face sketches, we elect to construct our own dataset, which we describe in Appendix A.2.
Results Figure 6a compares the results of our method to those of pix2pixHD and DeepFaceDrawing. As no code release is available for DeepFaceDrawing, we compare directly with sketches and results published in their paper. Due to the hard constraints of pix2pixHD, they are unable to handle the abstract sketches and obtain poor visual results. While DeepFaceDrawing obtain more visually pleasing results compared to pix2pixHD, they are still limited in their diversity. Conversely, although our model is trained on a different dataset, we are still able to generalize well to their sketches. Notably, we observe our ability to obtain more diverse outputs that better retain finer details (e.g. facial hair). Another limitation of DeepFaceDrawing is its focus on frontal images. We therefore illustrate our model’s ability to generate high-fidelity outputs from non-frontal sketches in Figure 13. As we are unable to directly evaluate DeepFaceDrawing on our constructed dataset, we compare our results only to those of pix2pixHD, trained and evaluated with the same data.
# 4.3.2 FACE FROM SEGMENTATION MAP
Here, we evaluate using pSp for synthesizing face images from segmentation maps. In addition to pix2pixHD, we compare our approach to two additional state-of-the-art label-to-image methods: SPADE (Park et al., 2019), and CC FPSE (Liu et al., 2019b), both of which are based on pix2pixHD.
Results In Figure 6b we provide a visual comparison of the competing approaches on the CelebAMask-HQ dataset containing 19 semantic categories. As the competing methods are based on pix2pixHD, the results of all three are visually similar. Conversely, our approach is able to generate high-quality outputs across a wide range of inputs of various poses and expressions. Additionally, using our multi-modal technique, pSp can easily generate various possible outputs with the same pose and attributes but varying fine styles for a single input semantic map or sketch image. We provide examples in Figure 6c with additional examples in Appendix C.
# 4.3.3 HUMAN PERCEPTUAL STUDY
We additionally perform a human evaluation to compare the visual quality of each method presented above. Here, each worker is given two images synthesized by different methods on the same input and is given an unlimited time to select which output looks more realistic. Each of our three workers reviews approximately 2, 800 pairs for each task, resulting in over 8, 400 human judgements for each method. Table 6d shows that pSp significantly outperforms the other respective methods in both synthesis tasks.
# 5 DISCUSSION AND CONCLUSIONS
Although our suggested framework for image-to-image translation achieves compelling results in various applications, it has some inherent assumptions that should be considered. First, the highquality images that are generated by utilizing the pretrained StyleGAN come with a cost — the method is limited to images that can be generated by StyleGAN. Thus, generating faces which are not close to frontal, or have certain expressions may be challenging if such examples were not available when training the StyleGAN model. Also, the global approach of $\mathsf { p } \mathsf { S p }$ , although advantageous for many tasks, does introduce a challenge in preserving finer details of the input image, such as earrings or background details. This is especially significant in tasks such as inpainting or superresolution where standard image-to-image architectures can simply propagate local information. Figure 7b in Appendix A presents some examples of such reconstruction failures.
In this work, we proposed a novel encoder architecture that can be used to directly map a face image into the $\mathcal { W } +$ latent space with no optimization required. The encoder architecture, motivated by StyleGAN, consists of a hierarchy of three levels that correspond to the coarse, medium, and fine groupings of the 18 style vectors defining the input in the $\mathcal { W } +$ latent space. Styles are then extracted from the encoder in a hierarchical fashion and fed into the corresponding inputs of a fixed StyleGAN generator. Notably, our network is trained with an ID similarity loss, which encourages better preservation of identity compared to previous direct approaches. Combining our encoder with a StyleGAN decoder, we present a general framework for solving various image-to-image translation tasks. In contrast to previous methods, which tackle such tasks using a local ”pixel-topixel” approach, our framework takes a global approach, which we show can be used to solve a wide variety of image-to-image translation problems.
# REFERENCES
Rameen Abdal, Yipeng Qin, and Peter Wonka. Image2stylegan: How to embed images into the stylegan latent space? In Proceedings of the IEEE international conference on computer vision, pp. 4432–4441, 2019.
Rameen Abdal, Yipeng Qin, and Peter Wonka. Image2stylegan $^ { + + }$ : How to edit the embedded images? In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 8296–8305, 2020.
Rameen Adbal, Pie Zhu, Niloy J. Mitra, and Peter Wonka. Styleflow: Attribute-conditioned exploration of stylegan-generated images using conditional continuous normalizing flows. arXiv preprint arXiv:, 2020.
Baylies. stylegan-encoder. https://github.com/pbaylies/stylegan-encoder, 2019. Accessed: April 2020.
Shu-Yu Chen, Wanchao Su, Lin Gao, Shihong Xia, and Hongbo Fu. DeepFaceDrawing: Deep generation of face images from sketches. ACM Transactions on Graphics (Proceedings of ACM SIGGRAPH 2020), 39(4):72:1–72:16, 2020.
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.
Edo Collins, Raja Bala, Bob Price, and Sabine Susstrunk. Editing in style: Uncovering the local semantics of gans. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 5771–5780, 2020.
Antonia Creswell and Anil Anthony Bharath. Inverting the generator of a generative adversarial network. IEEE transactions on neural networks and learning systems, 30(7):1967–1974, 2018.
Jiankang Deng, Jia Guo, Niannan Xue, and Stefanos Zafeiriou. Arcface: Additive angular margin loss for deep face recognition. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pp. 4690–4699, 2019.
Emily Denton, Ben Hutchinson, Margaret Mitchell, and Timnit Gebru. Detecting bias with generative counterfactual face attribute augmentation. arXiv preprint arXiv:1906.06439, 2019.
Lore Goetschalckx, Alex Andonian, Aude Oliva, and Phillip Isola. Ganalyze: Toward visual definitions of cognitive image properties, 2019.
Shanyan Guan, Ying Tai, Bingbing Ni, Feida Zhu, Feiyue Huang, and Xiaokang Yang. Collaborative learning for faster stylegan embedding. arXiv preprint arXiv:2007.01758, 2020.
Erik Hark ¨ onen, Aaron Hertzmann, Jaakko Lehtinen, and Sylvain Paris. Ganspace: Discovering ¨ interpretable gan controls. arXiv preprint arXiv:2004.02546, 2020.
Xun Huang, Ming-Yu Liu, Serge Belongie, and Jan Kautz. Multimodal unsupervised image-toimage translation. In Proceedings of the European Conference on Computer Vision (ECCV), pp. 172–189, 2018.
Yuge Huang, Yuhan Wang, Ying Tai, Xiaoming Liu, Pengcheng Shen, Shaoxin Li, Jilin Li, and Feiyue Huang. Curricularface: adaptive curriculum learning loss for deep face recognition. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 5901–5910, 2020.
Phillip Isola, Jun-Yan Zhu, Tinghui Zhou, and Alexei A Efros. Image-to-image translation with conditional adversarial networks. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 1125–1134, 2017.
Ali Jahanian, Lucy Chai, and Phillip Isola. On the ”steerability” of generative adversarial networks. arXiv preprint arXiv:1907.07171, 2019.
Justin Johnson, Alexandre Alahi, and Li Fei-Fei. Perceptual losses for real-time style transfer and super-resolution. In European conference on computer vision, pp. 694–711. Springer, 2016.
Tero Karras, Timo Aila, Samuli Laine, and Jaakko Lehtinen. Progressive growing of GANs for improved quality, stability, and variation. In International Conference on Learning Representations, 2018. URL https://openreview.net/forum?id ${ . } = { }$ Hk99zCeAb.
Tero Karras, Samuli Laine, and Timo Aila. A style-based generator architecture for generative adversarial networks. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 4401–4410, 2019.
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.
Oren Katzir, Dani Lischinski, and Daniel Cohen-Or. Cross-domain cascaded deep feature translation. arXiv, pp. arXiv–1906, 2019.
Vuong Le, Jonathan Brandt, Zhe Lin, Lubomir Bourdev, and Thomas S. Huang. Interactive facial feature localization. In Andrew Fitzgibbon, Svetlana Lazebnik, Pietro Perona, Yoichi Sato, and Cordelia Schmid (eds.), Computer Vision – ECCV 2012, pp. 679–692, Berlin, Heidelberg, 2012. Springer Berlin Heidelberg. ISBN 978-3-642-33712-3.
Yuhang Li, Xuejin Chen, Feng Wu, and Zheng-Jun Zha. Linestofacephoto: Face photo generation from lines with conditional self-attention generative adversarial networks. In Proceedings of the 27th ACM International Conference on Multimedia, pp. 2323–2331, 2019.
Tsung-Yi Lin, Piotr Dollar, Ross Girshick, Kaiming He, Bharath Hariharan, and Serge Belongie.´ Feature pyramid networks for object detection. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 2117–2125, 2017.
Zachary C Lipton and Subarna Tripathi. Precise recovery of latent vectors from generative adversarial networks. arXiv preprint arXiv:1702.04782, 2017.
Wallace Lira, Johannes Merz, Daniel Ritchie, Daniel Cohen-Or, and Hao Zhang. Ganhopper: Multihop gan for unsupervised image-to-image translation. arXiv preprint arXiv:2002.10102, 2020.
Liyuan Liu, Haoming Jiang, Pengcheng He, Weizhu Chen, Xiaodong Liu, Jianfeng Gao, and Jiawei Han. On the variance of the adaptive learning rate and beyond. arXiv preprint arXiv:1908.03265, 2019a.
Ming-Yu Liu, Thomas Breuel, and Jan Kautz. Unsupervised image-to-image translation networks. In Advances in neural information processing systems, pp. 700–708, 2017.
Xihui Liu, Guojun Yin, Jing Shao, Xiaogang Wang, et al. Learning to predict layout-to-image conditional convolutions for semantic image synthesis. In Advances in Neural Information Processing Systems, pp. 570–580, 2019b.
Sachit Menon, Alexandru Damian, Shijia Hu, Nikhil Ravi, and Cynthia Rudin. Pulse: Selfsupervised photo upsampling via latent space exploration of generative models. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), June 2020.
Yotam Nitzan, Amit Bermano, Yangyan Li, and Daniel Cohen-Or. Disentangling in latent space by harnessing a pretrained generator. arXiv preprint arXiv:2005.07728, 2020.
Taesung Park, Ming-Yu Liu, Ting-Chun Wang, and Jun-Yan Zhu. Semantic image synthesis with spatially-adaptive normalization. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pp. 2337–2346, 2019.
Guim Perarnau, Joost Van De Weijer, Bogdan Raducanu, and Jose M Alvarez. Invertible conditional ´ gans for image editing. arXiv preprint arXiv:1611.06355, 2016.
Stanislav Pidhorskyi, Donald A Adjeroh, and Gianfranco Doretto. Adversarial latent autoencoders. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 14104–14113, 2020.
Eitan Richardson and Yair Weiss. The surprising effectiveness of linear unsupervised image-toimage translation. ArXiv, abs/2007.12568, 2020.
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.
Edgar Simo-Serra, Satoshi Iizuka, Kazuma Sasaki, and Hiroshi Ishikawa. Learning to simplify: fully convolutional networks for rough sketch cleanup. ACM Transactions on Graphics, 35:1–11, 07 2016. doi: 10.1145/2897824.2925972.
Ayush Tewari, Mohamed Elgharib, Gaurav Bharaj, Florian Bernard, Hans-Peter Seidel, Patrick Perez, Michael Zollh ´ ofer, and Christian Theobalt. Stylerig: Rigging stylegan for 3d control over ¨ portrait images. arXiv preprint arXiv:2004.00121, 2020.
Carlos Eduardo Thomaz and Gilson Antonio Giraldi. A new ranking method for principal components analysis and its application to face image analysis. Image and Vision Computing, 28(6):902 – 913, 2010. ISSN 0262-8856. doi: https://doi.org/10.1016/j.imavis.2009.11.005. URL http: //www.sciencedirect.com/science/article/pii/S0262885609002613.
Ting-Chun Wang, Ming-Yu Liu, Jun-Yan Zhu, Andrew Tao, Jan Kautz, and Bryan Catanzaro. Highresolution image synthesis and semantic manipulation with conditional gans. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 8798–8807, 2018.
Ceyuan Yang, Yujun Shen, and Bolei Zhou. Semantic hierarchy emerges in deep generative representations for scene synthesis, 2019.
Michael Zhang, James Lucas, Jimmy Ba, and Geoffrey E Hinton. Lookahead optimizer: k steps forward, 1 step back. In Advances in Neural Information Processing Systems, pp. 9597–9608, 2019.
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 conference on computer vision and pattern recognition, pp. 586–595, 2018.
Hang Zhou, Jihao Liu, Ziwei Liu, Yu Liu, and Xiaogang Wang. Rotate-and-render: Unsupervised photorealistic face rotation from single-view images. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 5911–5920, 2020.
Jiapeng Zhu, Yujun Shen, Deli Zhao, and Bolei Zhou. In-domain gan inversion for real image editing. arXiv preprint arXiv:2004.00049, 2020a.
Jun-Yan Zhu, Taesung Park, Phillip Isola, and Alexei A Efros. Unpaired image-to-image translation using cycle-consistent adversarial networks. In Proceedings of the IEEE international conference on computer vision, pp. 2223–2232, 2017a.
Jun-Yan Zhu, Richard Zhang, Deepak Pathak, Trevor Darrell, Alexei A Efros, Oliver Wang, and Eli Shechtman. Toward multimodal image-to-image translation. In Advances in neural information processing systems, pp. 465–476, 2017b.
Peihao Zhu, Rameen Abdal, Yipeng Qin, and Peter Wonka. Sean: Image synthesis with semantic region-adaptive normalization. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 5104–5113, 2020b.
 Figure 7: (a) To generate multiple outputs for a single input image, style-mixing is performed over pSp. (b) Challenging cases for StyleGAN Inversion.
A ADDITIONAL DETAILS
# A.1 IMPLEMENTATION DETAILS
Training Details For our backbone network we use the ResNet-IR architecture from (Deng et al., 2019) pretrained on face recognition, which accelerated convergence. We use a fixed StyleGAN2 generator trained on the FFHQ (Karras et al., 2019) dataset. That is, only the pSp encoder network is trained on the given image-to-image translation task. For all applications, the input image resolution is $2 5 6 \times 2 5 6$ , where the generated $1 0 2 4 \times 1 0 2 4$ output is resized before being fed into the loss functions. For training, we use the Ranger optimizer, a combination of Rectified Adam (Liu et al., 2019a) with the Lookahead technique (Zhang et al., 2019), with a constant learning rate of 0.001. Only horizontal flips are used as augmentations during training. All experiments are performed using a single NVIDIA Tesla P40 GPU.
For the StyleGAN inversion task, the $\lambda$ values are set as $\lambda _ { 1 } = 1$ , $\lambda _ { 2 } = 0 . 8$ , $\lambda _ { 3 } = 0 . 1$ . For face frontalization, we increase the weight of the identity loss, setting $\lambda _ { 3 } = 1$ , and decrease the LPIPS and $L _ { 2 }$ loss functions, setting $\lambda _ { 1 } = 0 . 0 1$ , $\lambda _ { 2 } = 0 . 8$ over the inner part of the face and $\lambda _ { 1 } = 0 . 0 0 1$ , $\lambda _ { 2 } = 0 . 0 8$ elsewhere. Additionally, the constants used in the conditional image synthesis tasks are identical to those used in the inversion task except for the omission of the identity loss (i.e. we set $\lambda _ { 3 } = 0$ ). Finally, $\lambda _ { 4 }$ is set to 0.005 in all applications except for the StyleGAN inversion task, which does not utilize the regularization loss.
# A.2 DATASETS
We conduct our experiments on the CelebA-HQ dataset (Karras et al., 2018), which contains 30,000 high quality images. We use a standard train-test split of the dataset, resulting in approximately 24,000 training images. The FFHQ dataset from (Karras et al., 2019), which contains 70,000 face images, is used for the StyleGAN inversion and face frontalization tasks.
For the generation of face images from sketches, we construct a dataset representative of handdrawn sketches using the CelebA-HQ dataset (Karras et al., 2018). Given an input image, we first apply a “pencil sketch” filter which retains most facial details of the original image while removing the remaining noise. We then apply the sketch-simplification method by Simo-Serra et al. (2016), resulting in images resembling hand-drawn sketches.
# B ADDITIONAL APPLICATIONS
# B.1 SUPER RESOLUTION
Here we show that our framework can be used to construct high-resolution (HR) facial images from corresponding low-resolution (LR) input images. PULSE (Menon et al., 2020) approaches this task in an unsupervised manner by traversing the HR image manifold in search of an image that downsamples to the input LR image. In this work we focus on applying pSp in a supervised manner as obtaining paired data is immediate. We show that our method achieves comparable results to PULSE and other previous works.
Methodology and details We train our model in a supervised fashion, where for each input we perform random bi-cubic down-sampling of $\times 1$ (i.e. no down-sampling), $\times 2 , \times 4 , \times 8$ , $\times 1 6$ , $\times 3 2$ and set the original, full resolution image as the target.
Results Figure 9 demonstrates the visual quality of the resulting images from our method along with those of the previous approaches. Although PULSE is able to achieve very high-quality results due to their usage of StyleGAN to generate images, they are unable to accurately retain identity even when performing down-sampling of $\times 8$ to a resolution of $3 2 \times 3 2$ . By learning a pixel-wise correspondence between the LR and HR images, pix2pixHD is able to obtain satisfying results even when down-sampled to a resolution of $1 6 \times 1 6$ (i.e. $\times 1 6$ down-sampling). However, visually, their results appear less photo-realistic. Contrary to these previous works, we are able to obtain highquality results even when down-sampling to resolutions of $1 6 \times 1 6$ and $8 \times 8$ . Finally, we generate multiple outputs for a given LR image using our multi-modal technique by perform style-mixing on layers (4-7) with an $\alpha$ value of 0.5 with a randomly sampled w vector, which alters medium-level styles that mainly control facial features. Figure 10 illustrates the results.
# B.2 EVEN MORE APPLICATIONS
To better show the flexibility of our pSp framework, We present three additional applications, which are summarized in Figure 8.
Local Editing Our framework allows for a simple approach to local image editing where altering specific attributes of an input sketch (e.g. eyes, smile) or segmentation map (e.g. hair) results in local edits of the generated images.
Face Interpolation Given two real images one can obtain their respective latent codes $w _ { 1 } , w _ { 2 } \in$ $\mathcal { W } +$ by feeding the images through our encoder. We can then naturally interpolate between the two images by computing their intermediate latent code $w ^ { \prime } = \lambda w _ { 1 } + ( 1 \bar { - \lambda } ) \bar { w } _ { 2 }$ for $0 \leq \lambda \leq 1$ and generate the corresponding image using the new code $w ^ { \prime }$ .
Inpainting Finally, we show the ability of our framework to reconstruct missing parts of an image using a simple, symmetric triangular mask. Our approach is able to accurately reconstruct the occluded areas while preserving the identity with respect to the original image.
 Figure 8: Additional applications for the pSp framework.
 Figure 9: Comparison of super-resolution approaches with (a) $\times 8$ down-sampling, (b) $\times 1 6$ downsampling, and (c) $\times 3 2$ down-sampling.
 Figure 10: Multi-modal synthesis for super-resolution using pSp with style-mixing.
# C ADDITIONAL RESULTS
 Figure 11: Additional StyleGAN inversion results using pSp on the CelebA-HQ (Karras et al., 2018) test set.
 Figure 12: Additional face frontalization results using pSp on the CelebA-HQ (Karras et al., 2018) test set.
 Figure 13: Even for challenging, non-frontal face sketches, pSp is able to obtain high-quality, diverse outputs.
 Figure 14: Additional results using pSp for the generation of face images from sketches constructed from the CelebA-HQ (Karras et al., 2018) test dataset.
 Figure 15: Additional results on the Helen Faces (Le et al., 2012) dataset using our proposed labelto-image method.
 Figure 16: Additional results on the CelebAMask-HQ (Karras et al., 2018) test set using our proposed label-to-image method.
 Figure 17: Conditional image synthesis results from sketches and segmentation maps displaying the multi-modal property of our approach.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233# VARIANCE-BASED GRADIENT COMPRESSION FOR EF-FICIENT DISTRIBUTED DEEP LEARNING
Anonymous authors Paper under double-blind review
# ABSTRACT
Due to the substantial computational cost, training state-of-the-art deep neural networks for large-scale datasets often requires distributed training using multiple computation workers. However, by nature, workers need to frequently communicate gradients, causing severe bottlenecks, especially on lower bandwidth connections. A few methods have been proposed to compress gradient for efficient communication, but they either suffer a low compression ratio or significantly harm the resulting model accuracy, particularly when applied to convolutional neural networks. To address these issues, we propose a method to reduce the communication overhead of distributed deep learning. Our key observation is that gradient updates can be delayed until an unambiguous (high amplitude, low variance) gradient has been calculated. We also present an efficient algorithm to compute the variance and prove that it can be obtained with negligible additional cost. We experimentally show that our method can achieve very high compression ratio while maintaining the result model accuracy. We also analyze the efficiency using computation and communication cost models and provide the evidence that this method enables distributed deep learning for many scenarios with commodity environments.
# 1 INTRODUCTION
Deep neural networks are attracting attention because of their outstanding prediction power in many application fields such as image recognition, natural language processing, and speech recognition. In addition, software frameworks are publicly available, making it easier to apply deep learning. However, their crucial drawback is the substantial computational cost on training. For example, it takes over a week to train ResNet-50 on the ImageNet dataset if using a single GPU. Such long training time limits the number of trials possible when creating models.
Therefore, we must conduct distributed training using multiple computation workers (e.g., multiple GPUs in different nodes). However, by nature, workers need to frequently communicate gradients, which yields a severe bottleneck for scalability, especially when using lower bandwidth connections. For example, when using 1000BASE-T Ethernet, communication takes at least ten times longer than forward and backward computation for ResNet-50, making multiple nodes impractical. High performance interconnections such as InfiniBand and Omni-Path are an order of magnitude more expensive than commodity interconnections, which limits research and development of deep learning using large-scale datasets to a small number of researchers.
Although several methods have been proposed to compress gradient for efficient communication, they either suffer a low compression ratio or significantly harm the resulting model accuracy, particularly when applied to convolutional neural networks. There are mainly two lines of research: quantization and sparsification. Quantization-based methods include 1-bit SGD (Seide et al., 2014) and TernGrad (Wen et al., 2017). Though they achieve small loss of accuracy by using at least one bit for each parameter, the compression ratio is limited. Sparsification-based methods include Strom (2015) and QSGD (Alistarh et al., 2017). While they can achieve high compression ratio, as we will see in our experiments, they harm the resulting model accuracy or suffer a low compression ratio, particularly when applied to convolutional neural networks.
To address these issues, we propose a new gradient compression algorithm to reduce the communication overhead of distributed deep learning. The proposed method belongs to the sparsification approaches. Our key observation is that the variance of the gradient for each parameter point over iterations is a useful signal for compression. As almost all previous approaches of both sparsification and quantization only look at the magnitude of gradient, we believe that we are opening a new door for this field. In addition, we also show that our method can be combined with previous compression methods to further boost performance. We also present an efficient algorithm to compute the variance and prove that it can be obtained with negligible additional cost.
We experimentally demonstrate that our method can achieve a high compression ratio while maintaining result model accuracy. We also analyze the efficiency using computation and communication cost models and provide evidence that our method enables distributed deep learning for many scenarios with commodity environments.
Organization. The remainder of this paper is organized as follows: Section 2 provides the definitions and notations used in this paper. Section 3 reviews related work in this field. Section 4 presents the proposed method. Section 5 analyzes performance. Section 6 shows our experimental results, and we conclude in Section 7.
# 2 PRELIMINARIES
In this section, we describe an overview of distributed deep learning and parameter updates with compressed gradients.
# 2.1 CHALLENGES IN DATA PARALLEL STOCHASTIC GRADIENT DESCENT
In data parallel distributed Stochastic Gradient Descent (SGD), all workers have identical copies of the same model and calculate gradients using different subsets of training data. Gradients are shared across all workers, and each worker updates its local model using the shared gradients.
There are two well-known approaches to communication of gradients: synchronous and asynchronous. Even though our method can be applied to both of them, we focus on the synchronous approach in this paper. Each worker computes gradients and shares them with other workers using a synchronized group communication routine in every single training iteration, typically using a communication routine known as allreduce.
The challenge is that the communication is possibly a severe bottleneck in a training process. Gradients typically consist of tens of millions of floating point values so the total size of exchanged data can be large. For example, the model size of ResNet-50 (He et al. (2016)) is over $1 1 0 \mathrm { M B }$ , and the size of gradients becomes large accordingly. Thus, the communication time has a significant effect on the total training time in environments equipped with a commodity interconnect hardware, such as 1Gb Ethernet. Also, in the synchronous approach, workers have to wait for completion of communication and their computing resources including GPUs are idle, which is a significant performance loss.
# 2.2 PROBLEM FORMULATION
In basic procedures of SGD, model parameters are updated as
$$\boldsymbol x _ { t + 1 } = \boldsymbol x _ { t } - \gamma \nabla f _ { t } ( \boldsymbol x _ { t } ) ,$$
where $x _ { t }$ and $\nabla f _ { t } ( x _ { t } )$ are model parameters and calculated gradients in time step $t$ , respectively. $f _ { t }$ is a loss function and it differs between samples used in a mini-batch. $\gamma$ is a step size.
To reduce an amount of data to be exchanged over a network, either quantization or sparsification or both are used as explained in Sec. 3.
# 3 RELATED WORK
There are two main approaches to gradient compression: quantization-based approaches and sparsification-based approaches. Quantization-based approaches reduce communication cost by expressing each gradient with fewer bits. If a baseline uses 32-bit floating points in communication, then it can reduce the amount of communication by up to 32 times. Seide et al. (2014) showed that neural networks can be trained using only one sign bit per parameter. There are two key techniques in their algorithm. First, they use different threshold to encode and decode gradient elements for each column of weight matrix. Second, quantization errors are added to the gradients calculated in the next step. Its effectiveness has been experimentally verified through speech models. Wen et al. (2017) proposed TernGrad to encode gradients with 2 bits per parameter. The algorithm is characterized by its theoretically-guaranteed convergence and reported that it can successfully train GoogLeNet (Szegedy et al., 2015) on ImageNet with an average loss of accuracy of less than $2 \%$ .
As a second approach, sparsification-based approaches reduce communication cost by sending only a small fraction of gradients. Even though they require sending not only the values of gradients but also parameters’ indexes, their strong sparsification reduces transmission requirements significantly. Strom (2015) proposed sending only gradients whose absolute values are greater than a user-defined threshold. The algorithm sends only sign bits and encoded indexes of parameters. Gradients are decoded up to the threshold and quantization errors are added to the gradients calculated in the next step as 1-bit stochastic gradients. Its effectiveness has also been experimentally verified on speech applications. Dryden et al. (2016) extended Strom’s method. They proposed to use an adaptive threshold instead of using a user-defined threshold. They also introduced repeated sparsification of gradients in order to combine the algorithm with an efficient communication algorithm. Alistarh et al. (2017) proposed QSGD. QSGD stochastically rounds gradients to linearly quantized values, which are calculated in the algorithm. Their work enjoys strong theoretical properties in convex optimizations. Furthermore, they can control the trade-off between accuracy and compression. On the other hand, Strom’s method does not work with small or large thresholds.
# 4 PROPOSED METHODS
In this section, we describe the proposed method. An efficient implementation and combination with other compression methods are also explained.
Our work belongs to the sparsification-based approaches. In this section, we explicitly denote a gradient vector $( \nabla \bar { f } ( x ) )$ and a gradient element $( \nabla _ { i } f ( x ) )$ for clarity. Previous works in this direction have focused on gradient elements with small magnitudes, and they rounded them to zero to sparsify. Our work diverges at this point. We propose using approximated variances of gradient elements instead of magnitudes. Our method do not transmit ambiguous elements until additional data reduce their ambiguity and significantly reduces communication while maintaining accuracy. This method enables shifting the balance between accuracy and compression, as necessary. Furthermore, we can combine our work with sparsity-promoting quantization like QSGD and Strom’s method. We show the way of combination with the Strom’s method later.
# 4.1 KEY CONCEPTS
The key idea of our method is delaying sending ambiguously estimated gradient elements. We consider a gradient element to be ambiguous when its amplitude is small compared to its variance over the data points. We extend the standard updating method to the following:
$$x _ { t + 1 } - \gamma r _ { t + 1 } = x _ { t } - \gamma ( \nabla f _ { t } ( x _ { t } ) + r _ { t } ) .$$
This extension follows Seide et al. (2014) and Strom (2015).
In previous works, the approximation errors are accumulated in $r _ { t }$ and used in future updates. In each step, parameters are updated only with approximated gradient elements represented by less number of bits. In our work, we interpret $r _ { t }$ as a delayed update, not approximation errors.
We send the gradient element corresponding to the $i$ -th parameter only when it satisfies the following criterion,
$$\frac { \alpha ^ { \prime } } { | B | } V _ { B } [ \nabla _ { i } f _ { z } ( x ) ] < ( \nabla _ { i } f _ { B } ( x ) ) ^ { 2 } ,$$
where $| B |$ is a size of the mini-batch and $\alpha ^ { \prime }$ is a hyper parameter representing required estimation accuracy. $z$ is a each sample and $B$ is a mini-batch, respectively and $f _ { z }$ and $f _ { B }$ are corresponding loss functions. $V _ { B } [ \nabla _ { i } f _ { z } ( x ) ]$ is the sample variance of the gradient element corresponding to the $i$ -th parameter over a mini-batch $B$ .
If we do not send some gradient elements, we add them to the next batch and recalculate (1) with increased batch size. For example, if we postpone sending a gradient element nine times consecutively, the criterion (1) is calculated as if ten times larger batch than usual mini-batch in the next step. Note that even though the criterion (1) is calculated as if we used a larger batch, what is used for an update is not the mean of the mini-batches across steps but the sum of them.
Following lemma supports our formulation.
Lemma 4.1. (De et al., 2017) A sufficient condition that a vector $- g$ is a descent direction is
$$\begin{array} { r } { \| g - \nabla f ( x ) \| _ { 2 } ^ { 2 } < \| g \| _ { 2 } ^ { 2 } . } \end{array}$$
We are interested in the case of $g = \nabla f _ { B } ( x )$ , the gradient vector of the loss function over $B$ . By the weak law of large numbers, when $| B | > 1$ , the left hand side of Eq. 2 with $g = \nabla f _ { B } ( x )$ can be estimated as follows:
$$E [ \| \nabla f _ { B } ( x ) - \nabla f ( x ) \| _ { 2 } ^ { 2 } ] \sim \frac { 1 } { | B | } V _ { B } [ \nabla f _ { z } ( x ) ] .$$
Thus our formulation with $\alpha ^ { \prime } \geq 1$ corresponds to an elementwise estimation of the sufficient condition (2) that a gradient vector decreases the loss function. Gradient elements become more likely to be sent as sample size increases. However, if once gradient elements are estimated with too high variances, it takes too long for the elements to be sent. Thus, we decay variance at every step. Details are described in subsection 4.4. In the combination with optimization methods like Momentum SGD, gradient elements not sent are assumed to be equal to zero.
# 4.2 QUANTIZATION AND PARAMETER ENCODING
To allow for comparison with other compression methods, we propose a basic quantization process. In this section, we refer to a gradient as an accumulated gradient. After deciding which gradient elements to send, each worker sends pairs of a value of a gradient element and its parameter index as Strom (2015) and Alistarh et al. (2017). We quantize each element to 4-bit so that we can represent each pair in 32-bit as per Strom (2015). The 4-bit consists of one sign bit and three exponent bits.
Our quantization except for the sign bit is as follows. For a weight matrix $W _ { k }$ (or a weight tensor in CNN), there is a group of gradient elements corresponding to the matrix. Let $M _ { k }$ be the maximum absolute value in the group. First, for each element $g _ { i }$ in the $k$ -th group, if $| g _ { i } |$ is larger than $2 ^ { \lfloor \log _ { 2 } M _ { k } \rfloor }$ truncate it to $2 ^ { \lfloor \log _ { 2 } { M _ { k } } \rfloor }$ , otherwise, round to the closer value of $2 ^ { \lfloor \log _ { 2 } \left. \dot { g } _ { i } \right. \rfloor }$ or $2 ^ { \lceil \bar { \log } _ { 2 } \lvert g _ { i } \rvert \rceil }$ . Let $g _ { i } ^ { \prime }$ be the preprocessed gradient element. Next, calculate a integer $d _ { i } : = \lfloor \log _ { 2 } M _ { k } \rfloor - \log _ { 2 } g _ { i } ^ { \prime }$ . If $d \sb i > 7$ then we do not send the value, otherwise, encode the integer from 0 to 7 using 3 bits. $\lfloor \log _ { 2 } M _ { k } \rfloor$ is also sent for every weight matrix. An efficient implementation is presented in subsection 4.4. We do not adopt stochastic rounding like Alistarh et al. (2017) nor accumulate rounding error $g _ { i } - g _ { i } ^ { \prime }$ for the next batch because this simple rounding does not harm accuracy empirically. Appendix B has a running example of this quantization.
Because the variance-based sparsification method described in subsection 4.1 is orthogonal to the quantization shown above, we can reduce communication cost further using sparsity promoting quantization methods such as QSGD instead. However, we used the quantization to show that enough level of sparsity is gained solely by our variance-based sparsification because the quantization rounds only a small fraction of gradient elements to zero. We show how to combine our method with a method in Strom (2015) later in this paper because the way of the combination is less obvious. We use a naive encoding for parameter indexes because the rest 28-bits are enough. We can further reduce the number of bits by compressing parameter indexes (Strom, 2015; Alistarh et al., 2017).
# 4.3 COMMUNICATION BETWEEN WORKERS
In distributed deep learning, the most important operation is to take the global mean of the gradient elements calculated in each worker. The operation is referred to as “allreduce.” It consists of three steps: (1) collects all local arrays in each worker, (2) reduce them using a given arithmetic operator, which is summation in this case, and (3) broadcast the result back to all workers so that all workers obtain the identical copies of the array.
Conventional data parallel deep learning applications can enjoy the benefit of highly optimized allreduce implementations thanks to the fact that only the sum of the values has to be kept during the communication. However, after applying the proposed method to the local gradient elements, they are converted to a sparse data structure so the allreduce operation can no longer apply.
Dryden et al. (2016) and Aji & Heafield (2017) proposed sparsifying gradient elements multiple times to utilize a kind of allreduce for sparsification-based compressions. However, the accuracy is possibly degraded when the elements are highly compressed through repetitive compressions. Instead, we adopt allgatherv for communication, where each worker just sends the calculated elements to other workers. We avoid to encode and decode elements multiple times by allgatherv. In allgatherv communication cost hardly increase from a kind of allreduce because index overlap, which is needed for summation, rarely occur if the compression ratio is sufficiently higher than the number of workers. Thanks to the high compression ratio possible with this algorithm and its combination with other compression methods, even large numbers of workers can be supported. Some optimization methods, such as ADAM (Ba & Kingma, 2015), require parameter updates and postprocessing. They are calculated locally after the communication.
# 4.4 EFFICIENT IMPLEMENTATION
We first describe the efficient computation of the criterion (1) and second how to quantize gradient elements without additional floating points operations. We can efficiently compare squared mean and variance in the criterion (1) by just comparing squared mean of gradient elements and sum of squared gradient elements. That is,
$$\left( \sum _ { z \in B } \frac { 1 } { | B | } \nabla _ { i } f _ { z } ( x ) \right) ^ { 2 } > \alpha \sum _ { z \in B } \left( \frac { 1 } { | B | } \nabla _ { i } f _ { z } ( x ) \right) ^ { 2 }$$
achieves our goal. Thus, we have to maintain only the sum of gradient elements and sum of squared gradient elements. Details are described in Appendix A. Decay of variance, described in subsection 4.1, is accomplished by multiplying hyperparameter $\zeta ( < 1 )$ to the sum of squared gradient elements at every step. Alpha in Eq. 3 controls how much unambiguity the algorithm require. The algorithm compress more aggressively with larger alpha. A range from one to two is good for alpha from its derivation. Fig. 1 shows the final algorithm.
The quantization of parameters described in subsection 4.2 can also be efficiently implemented with the standard binary floating point representation using only binary operations and integer arithmetic as follows. We can calculate $2 ^ { \lfloor \log _ { 2 } x \rfloor }$ by truncating the mantissa. We can also round values by adding one to the most significant bit of mantissa as if $x$ is an unsigned integer and then masking mantissa to 0.
# 4.5 HYBRID ALGORITHM
We describe the way to combine our method with Strom’s method. It becomes problematic how to modify variance when only parts of gradient elements are exchanged. We solve the issue simply by modifying $a ^ { 2 }$ to $( a - b ) ^ { 2 }$ . Let S be the value sent in a step (i.e. threshold, -threshold or 0). We correct squared gradient elements $\textstyle \sum ( \nabla _ { i } f ) ^ { 2 }$ to $\sum ( \nabla _ { i } f ) ^ { 2 } - 2 \bar { S } \sum ( \nabla _ { i } f ) + S ^ { 2 }$ . Fig. 2 shows the algorithm. We show the effictiveness of this combined algorithm by experiments in Sec. 6. Combinations with other works like QSGD and TernGrad are rather straightforward and we do not explore further in this paper.
# 5 PERFORMANCE ANALYSIS
Because common deep learning libraries do not currently support access to gradients of each sample, it is difficult to contrast practical performance of an efficient implementation in the commonly used software environment. In light of this, we estimate speedup of each iteration by gradient compression with a performance model of communication and computation. The total speed up of the whole training process is just the summation of each iteration because we adopt a synchronized approach.
Figure 1: Basic algorithm of our variancebased compression. $\zeta$ and $\alpha$ are hyperparameters. Recommended value for $\zeta$ is 0.999. $\alpha$ controls compression and accuracy. $\nabla _ { i } f _ { z }$ denotes a gradient element of parameter $i$ for each sample $z$ in mini-batch. CalcGrad() is backward and forward computaion. Encode() includes quantization and encoding of indexes. CommunicateAndUpdate() requires sharing gradient elements and decode, then update parameters.
<table><tr><td>Algorithm1:Basic</td></tr><tr><td>hyperparam:B = batch size, S,α</td></tr><tr><td>foreach parameters:</td></tr><tr><td>ri=0;</td></tr><tr><td>Ui = 0;</td></tr><tr><td>while not converged:</td></tr><tr><td>CalcGrad(;</td></tr><tr><td>foreach parameters: Vif; ri+=∑</td></tr><tr><td>Df)²; B</td></tr><tr><td>Ui+=∑( B</td></tr><tr><td>if r² >αui:</td></tr><tr><td>Encode(ri);</td></tr><tr><td>ri=0;</td></tr><tr><td>Ui=0;</td></tr><tr><td>else:</td></tr><tr><td>Ui *=;</td></tr><tr><td>CommunicateAndUpdate();</td></tr></table>
Figure 2: Hybrid algorithm of our variancebased compression and Strom’s method. $\tau$ is a user-defined threshold required in Strom’s method. Other parameters and notations are the same with Fig. 1.
<table><tr><td>Algorithm 2: Hybrid</td><td colspan="2"></td></tr><tr><td>hyperparam:B = batch size, S,α,T</td><td rowspan="3">if |ri| >T and r² > αvi: Encode(Sign(ri)); ri -= Sign(ri) T; max(Ui - 2|rilT + T²,0);</td></tr><tr><td>foreach parameters:</td></tr><tr><td>ri=0; Ui=0;</td></tr></table>
In the communication part, the pairs of the quantized values and the parameter indexes in each node are broadcast to all nodes. The $i$ -th node’s input data size $n _ { i } ( i = 1 , . . . , p )$ may be different among nodes, where $p$ denotes the number of nodes. An MPI function called allgatherv realizes such an operation. Because recent successful image recognition neural network models like VGG (Simonyan & Zisserman, 2015) or ResNet (He et al., 2016) have a large number of parameters, the latency term in communication cost can be ignored even if we achieve very high compression ratio such as $c > 1 , 0 0 0$ . In such cases, a type of collective communication algorithms called the ring algorithm is efficient (Thakur et al., 2005). Its bandwidth term is relatively small even though its latency term is proportional to $p$ . Although the naive ring allgatherv algorithm costs unacceptable $O ( \operatorname* { m a x } _ { i } n _ { i } \cdot p )$ time, Traff et al. ¨ (2008) proposed a method to mitigate it by dividing large input data, which is called pipelined ring algorithm. For example, an allgatherv implementation in MVAPICH adopts a pipelined ring algorithm for large input data.
The calculation of variance of gradients dominates in the additional cost for the computation part of the proposed method. The leading term of the number of multiply-add operations in it is $2 N | B |$ , where $N$ and $| B |$ are the number of parameters and the local batch size, respectively. Other terms such as determination of sent indexes and application of decay are at most $\bar { O } ( N )$ . Therefore hereafter we ignore the additional cost for the computation part and concentrate to the communication part.
We discuss the relationship between the compression ratio and the speedup of the communication part. As stated above, we ignore the latency term. The baseline is ring allreduce for uncompressed gradients. Its elapsed time is $T _ { r } = 2 ( p - \mathrm { i } ) N s \beta / p$ , where $s$ and $\beta$ are the bit size of each parameter and the transfer time per bit, respectively. On the other hand, elapsed time of pipelined ring allgatherv is $T _ { v } = \sum [ ( { n } _ { i } / m ) - 1 ) \bar { m \beta } ]$ , where $m$ is the block size of pipelining. Defining $c$ as the averaged compression ratio including change of the number of bits per parameter, $T _ { v }$ is evaluated as $\begin{array} { r } { T _ { v } \leq ( \sum n _ { i } + ( p - 1 ) m ) \beta = ( N s p / c + ( p - 1 ) m ) \beta . } \end{array}$ . If we set $m$ small enough, relative speedup is $T _ { r } / \overline { { T _ { v } } } \geq 2 ( p - 1 ) c / p ^ { 2 }$ . Therefore we expect linear speedup in $c > p / 2$ range.
# 6 EXPERIMENTS
In this section, we experimentally evaluate the proposed method. Specifically, we demonstrate that our method can significantly reduce the communication cost while maintaining test accuracy. We also show that it can reduce communication cost further when combined with other sparsification methods, and even improves test accuracy in some settings.
We used CIFAR-10 (Krizhevsky, 2009) and ImageNet (Russakovsky et al., 2015), the two most popular benchmark datasets of image classification. We fixed the hyperparameter $\zeta$ in Fig. 1 and Fig. 2 to 0.999 in all experiments. We evaluated gradient compression algorithms from the following two viewpoints: accuracy and compression ratio. The accuracy is defined as the test accuracy at the last epoch, and the compression ratio is defined as the number of the total parameters of networks divided by the average number of parameters sent. We do not consider the size of other non-essential information required for the communication, because they are negligible. In addition, we can ignore the number of bits to express each gradient because we assume that both a gradient and a parameter index are enclosed in a 32 bit word as Strom (2015) in all algorithms. Please note that, as all methods use allgatherv for communication, communication cost increases in proportion to the number of workers. Thus, high compression ratio is required to achieve sufficient speed up when using tens or hundreds of workers. We have visualization of results in Appendix C.
# 6.1 CIFAR-10
For experiments on CIFAR-10, we used a convolutional neural network similar to VGG (Simonyan & Zisserman, 2015). The details of the network architecture are described in Appendix D. We trained the network for 300 epochs with weight decay of 0.0005. A total number of workers was 8 and batch size was 64 for each worker. We applied no data augmentation to training images and center-cropped both training and test images into 32x32. We used two different optimization methods: Adam (Ba & Kingma, 2015) and momentum SGD (Sutskever et al., 2013). For Adam, we used Adam’s default parameter described in Ba & Kingma (2015). For momentum SGD, we set the initial learning rate to $0 . 0 5 \times 8$ and halved it at every 25 epochs. We used two’s complement in implementation of QSGD and ”bit” represents the number of bits used to represent each element of gradients. ”d” represents a bucket size. For each configuration, we report the median of the accuracy from five independent runs. Compression ratios are calculated based on the execution that achieved the reported accuracy.
Table 1 summarizes the results. Our method successfully trained the network with slight accuracy gain for the Adam setting and 2 to $3 \%$ of accuracy degradation for the Momentum SGD setting. Compression ratios were also sufficiently high, and our method reduced communication cost beyond quantization-based approaches described in section 3. The hybrid algorithm’s compression ratio is several orders higher than existing compression methods with a low reduction in accuracy. This indicates the algorithm can make computation with a large number of nodes feasible on commodity level infrastructure that would have previously required high-end interconnections. Even though QSGD achieved higher accuracy than our method, its compression power is limited and our algorithm can reduce communication cost more aggressively. On the other hand, Strom’s method caused significant accuracy degradation. Counter-intuitively, the hybrid algorithm improved its accuracy, in addition to the further reduction of communication.
Our hypothesis for this phenomena is as follows. In Strom’s algorithm, when a large positive gradient appears, it has no choice but send positive values for consequent steps even if calculated gradients in following mini-batches have negative values. On the other hand, in the hybrid algorithm, if following gradients have a different sign with a residual, the residual is not likely to be sent. We assume that this effect helped the training procedure and led to better accuracy. We also would like to mention the difficulty of hyperparameter tuning in Strom’s method. As Table 1 shows, using lower threshold does not necessarily always lead to higher accuracy. This is because the hyperparameter controls both its sparsification and quantization. Thus, users do not know whether to use a larger or smaller value as a threshold to maintain accuracy. We note that we observed unstable behaviors with other thresholds around 0.01. On the other hand, our algorithm are free from such problem. Moreover, when we know good threshold for Strom’s algorithm, we can just combine it with ours to get further compression.
Table 1: Training of a VGG-like network on CIFAR-10. $\tau$ denotes the threshold in Strom’s method. $\alpha$ is the hyperparameter of our method described in the criterion (3). The number of bits of QSGD refers the number of bits to express gradients except for the sign bits. For each configuration, the median of the accuracy from five independent runs is reported. The compression column lists the compression ratio defined at the beginning of Sec. 6.
<table><tr><td colspan="3">Adam</td><td colspan="2">Momentum SGD</td></tr><tr><td>Method</td><td>Accuracy</td><td>Compression</td><td>Accuracy</td><td>Compression</td></tr><tr><td>no compression</td><td>88.1</td><td>1</td><td>91.7</td><td>1</td></tr><tr><td>Strom, T = 0.001</td><td>62.8</td><td>88.5</td><td>84.8</td><td>6.5</td></tr><tr><td>Strom, T = :0.01</td><td>85.0</td><td>230.1</td><td>10.6</td><td>990.7</td></tr><tr><td>Strom, T = 0.1</td><td>88.0</td><td>6,942.8</td><td>71.6</td><td>8,485.0</td></tr><tr><td>our method,α = 1</td><td>88.9</td><td>120.7</td><td>90.3</td><td>52.4</td></tr><tr><td>our method,α = 1.5</td><td>88.9</td><td>453.3</td><td>89.6</td><td>169.2</td></tr><tr><td>our method,α = 2.0</td><td>88.9</td><td>913.4</td><td>88.4</td><td>383.6</td></tr><tr><td>hybrid, τ = 0.01,α = 2.0</td><td>85.0</td><td>1,942.2</td><td>87.6</td><td>983.9</td></tr><tr><td>hybrid, τ = 0.1,α = 2.0</td><td>88.2</td><td>12,822.4</td><td>87.1</td><td>12,396.8</td></tr><tr><td>QSGD (2bit, d = 128)</td><td>88.8</td><td>12.3</td><td>90.8</td><td>6.6</td></tr><tr><td>QSGD (3bit, d = 512)</td><td>87.4</td><td>14.4</td><td>91.4</td><td>7.0</td></tr><tr><td>QSGD (4bit, d = 512)</td><td>88.2</td><td>11.0</td><td>91.7</td><td>4.0</td></tr></table>
Table 2: Training ResNet50 on ImageNet. $\tau$ denotes a threshold in Strom’s method. $\alpha$ is the hyperparameter of our method described in the criterion (3). Accuracy is the test accuracy at the last epoch. Compression refers compression ratio defined in the beginning of Sec. 6.
<table><tr><td colspan="3">Adam</td><td colspan="2">Momentum SGD</td></tr><tr><td>Method</td><td>Accuracy</td><td>Compression</td><td> Accuracy</td><td>Compression</td></tr><tr><td>no compression</td><td>56.2</td><td>1</td><td>76.0</td><td>1</td></tr><tr><td>Strom, T = 0.001</td><td>28.6</td><td>38.6</td><td>75.2</td><td>2.1</td></tr><tr><td>Strom, T = 0.01</td><td>50.0</td><td>156.2</td><td>75.5</td><td>35.2</td></tr><tr><td>Strom, T = 0.1</td><td>48.1</td><td>6,969.0</td><td>75.5</td><td>2.002.2</td></tr><tr><td>our method,α = 1</td><td>55.3</td><td>1,542.8</td><td>74.7</td><td>103.8</td></tr><tr><td>our method, α = 1.5</td><td>57.4</td><td>2,953.1</td><td>75.5</td><td>400.7</td></tr><tr><td>our method,α = 2.0</td><td>57.8</td><td>5,173.8</td><td>75.1</td><td>990.7</td></tr><tr><td>hybrid, τ = 0.01,α = 2.0</td><td>52.2</td><td>2,374.2</td><td>75.0</td><td>470.9</td></tr><tr><td>hybrid, T = 0.1,α = 2.0</td><td>43.1</td><td>28,954.2</td><td>75.1</td><td>4,345.0</td></tr></table>
# 6.2 IMAGENET
As larger scale experiments, we trained ResNet-50 (He et al., 2016) on ImageNet. We followed training procedure of Goyal et al. (2017) including optimizer, hyperparameters and data augmentation. We also evaluated algorithms with replacing MomentumSGD and its learning rate scheduling to Adam with its default hyperparameter. We used batch size 32 for each worker and used 16 workers.
Table 2 summarizes the results. In this example as well as the previous CIFAR10 example, Variancebased Gradient Compression shows a significantly high compression ratio, with comparable accuracy. While in this case, Strom’s method’s accuracy was comparable with no compression, given the significant accuracy degradation with Strom’s method on CIFAR10, it appears Variance-based Gradient Compression provides a more robust solution. Note that the training configuration with MomentumSGD is highly optimized to training without any compression. For reference, the original paper of ResNet-50 reports its accuracy as $7 5 . 3 \%$ (He et al., 2016). Wen et al. (2017) reports that it caused up to $2 \%$ accuracy degradation in training with GoogLeNet (Szegedy et al., 2015) on ImageNet and our method causes no more degradation compared to quantization-based approaches.
# 7 CONCLUSION
We proposed a novel method for gradient compression. Our method can reduce communication cost significantly with no or only slight accuracy degradation. Contributions of our work can be summarized in the following three points. First, we proposed a novel measurement of ambiguity (high variance, low amplitude) to determine when a gradient update is required. Second, we showed the application of this measurement as a threshold for updates significantly reduces update requirements, while providing comparable accuracy. Third, we demonstrated this method can be combined with other efficient gradient compression approaches to further reduce communication cost.
# REFERENCES
A. F. Aji and K. Heafield. Sparse communication for distributed gradient descent. In Proceedings of the 2017 Conference on Empirical Methods in Natural Language Processing (EMNLP), pp. 440–445, 2017. D. Alistarh, D. Grubic, J. Li, R. Tomioka, and M. Vojnovic. Communication-efficient stochastic gradient descent, with applications to neural networks. In Advances in Neural Information Processing Systems 31 (NIPS), 2017. to appear. J. Ba and D. Kingma. Adam: A method for stochastic optimization. In 3rd International Conference on Learning Representations (ICLR), 2015. S. De, A. Yadav, D. Jacobs, and T. Goldstein. Automated inference with adaptive batches. In Proceedings of the 20th International Conference on Artificial Intelligence and Statistics (AISTATS), pp. 1504–1513, 2017. N. Dryden, S. A. Jacobs, T. Moon, and B. Van Essen. Communication quantization for data-parallel training of deep neural networks. In Proceedings of the Workshop on Machine Learning in High Performance Computing Environments (MLHPC ’16), pp. 1–8, 2016. P. Goyal, P. Dollar, R. B. Girshick, P. Noordhuis, L. Wesolowski, A. Kyrola, A. Tulloch, Y. Jia, and ´ K. He. Accurate, large minibatch SGD: training imagenet in 1 hour. arXiv:1706.02677, 2017. K. He, X. Zhang, S. Ren, and J. Sun. Deep residual learning for image recognition. In IEEE Conference on Computer Vision and Pattern Recognition (CVPR), pp. 770–778, 2016. A. Krizhevsky. Learning multiple layers of features from tiny images. 2009. O. Russakovsky, J. Deng, H. Su, J. Krause, S. Satheesh, S. Ma, Z. Huang, A. Karpathy, A. Khosla, M. Bernstein, A. C. Berg, and L. Fei-Fei. Imagenet large scale visual recognition challenge. International Journal of Computer Vision, 115(3):211–252, 2015. F. Seide, H. Fu, J. Droppo, G. Li, and D. Yu. 1-bit stochastic gradient descent and application to data-parallel distributed training of speech DNNs. In INTERSPEECH, pp. 1058–1062, 2014. K. Simonyan and A. Zisserman. Very deep convolutional networks for large-scale image recognition. In 3rd International Conference on Learning Representations (ICLR), 2015. N. Strom. Scalable distributed DNN training using commodity GPU cloud computing. In INTERSPEECH, pp. 1488–1492, 2015. I. Sutskever, J. Martens, G. Dahl, and G. Hinton. On the importance of initialization and momentum in deep learning. In Proceedings of the 30th International Conference on International Conference on Machine Learning (ICML), pp. 1139–1147, 2013. C. Szegedy, W. Liu, Y. Jia, P. Sermanet, S. Reed, D. Anguelov, D. Erhan, V. Vanhoucke, and A. Rabinovich. Going deeper with convolutions. In IEEE Conference on Computer Vision and Pattern Recognition (CVPR), pp. 1–9, 2015. R. Thakur, R. Rabenseifner, and W. Gropp. Optimization of collective communication operations in MPICH. The International Journal of High Performance Computing Applications, 19(1):49–66, 2005. S. Tokui, K. Oono, S. Hido, and J. Clayton. Chainer: a next-generation open source framework for deep learning. In Proceedings of Workshop on Machine Learning Systems (LearningSys) in The Twenty-ninth Annual Conference on Neural Information Processing Systems (NIPS), 2015. J. L. Traff, A. Ripke, C. Siebert, P. Balaji, R. Thakur, and W. Gropp. A simple, pipelined algorithm ¨ for large, irregular all-gather problems. In Recent Advances in Parallel Virtual Machine and Message Passing Interface: 15th European PVM/MPI Users’ Group Meeting, pp. 84–93, 2008. W. Wen, C. Xu, F. Yan, C. Wu, Y. Wang, Y. Chen, and H. Li. TernGrad: Ternary gradients to reduce communication in distributed deep learning. In Advances in Neural Information Processing Systems 31 (NIPS), 2017. to appear.
# A A SIMPLIFIED VIEW OF THE VARIANCE-BASED CRITERION
We derive that the criterion (3) corresponds to the criterion (1).
$$\begin{array} { r l } & { \quad ( \underset { s \in \boldsymbol { \kappa } _ { 1 } } { \sum } \frac { 1 } { B } \big | \nabla \gamma _ { s } f _ { s } ( z ) \big | ) ^ { \frac { 1 } { \gamma } } > \alpha \sum _ { \kappa \in \boldsymbol { \kappa } } ( \frac { 1 } { | B | } \nabla \gamma _ { s } f _ { s } ( z ) ) ^ { \theta ^ { \prime } } } \\ { \Leftrightarrow } & { \frac { | B | - \alpha } { | B | } ( \underset { s \in \boldsymbol { \kappa } _ { 1 } } { \sum } \frac { 1 } { B } \nabla \gamma _ { s } f _ { s } ( z ) ) ^ { 2 } > \alpha \frac { 1 } { | B | } ( \frac { 1 } { | B | } \underset { s \in \boldsymbol { \kappa } } { \sum } ( \nabla _ { s } f _ { s } ( z ) ) - \underset { s \neq n } { \sum } ( \frac { 1 } { | B | } \nabla _ { s } f _ { s } ( z ) ) ^ { 2 } ) } \\ { \Leftrightarrow } & { \frac { | B | - \alpha } { | B | } ( \underset { s \in \boldsymbol { \kappa } _ { 1 } } { \sum } | \nabla \gamma _ { s } f _ { s } ( z ) | ) ^ { 2 } > \alpha _ { | B | } \underset { s \in \boldsymbol { \kappa } } { \sum } | \nabla \gamma _ { s } f _ { s } ( z ) - \frac { 1 } { | B | } \sum _ { s \in \boldsymbol { \kappa } } ( \nabla \gamma _ { s } f _ { s } ( z ) ) ^ { 2 } | } \\ { \Leftrightarrow } & { \frac { | B | - \alpha } { | B | } ( \underset { s \in \boldsymbol { \kappa } _ { 1 } } { \sum } \frac { 1 } { B } \nabla \gamma _ { s } f _ { s } ( z ) ) ^ { 2 } > \alpha \frac { | B | - \frac { 1 } { | B | } } { | B | ^ { 2 } \cdot | B | } \sum _ { s = \boldsymbol { \kappa } } ( \nabla \gamma _ { s } f _ { s } ( z ) - \frac { 1 } { | B | } \sum _ { s = \boldsymbol { \kappa } } \gamma _ { s } ( z ) ) ^ { 2 } } \\ { \Leftrightarrow } & \frac { | B | - \alpha } { | B | } ( \underset { s \in \boldsymbol { \kappa } _ { 1 } } { \sum } \frac { 1 } { B } \gamma _ { s } f _ s \end{array}$$
$V _ { B } [ \nabla _ { i } f _ { z } ( x ) ] / | B |$ is an estimated variance of the means of gradients in mini-batches with size $| B |$ . For $\alpha = 1$ , the above criterion reduces to
$$\nabla f _ { B } ( x ) ^ { 2 } > \frac { 1 } { | B | } V _ { B } [ \nabla f _ { z } ( x ) ] ,$$
which is an estimated version of the sufficient condition (2). The term $( | B | - 1 ) / ( | B | - \alpha )$ is approximately 1 in most settings.
# B RUNNING EXAMPLE OF QUANTIZATION
Let $( 0 . 0 4 , 0 . 3 1 , - 6 . 2 5 , 2 2 . 2 5 , - 3 5 . 7 5 )$ be a part of gradient elements corresponding to a matrix. Sign bits are separately processed and we consider their absolute values here: $( 0 . 0 4 , 0 . 3 1 , 6 . 2 5 , 2 2 . 2 5 , 3 5 . 7 5 )$ . Now, $M _ { k }$ is the max of the elements: 35.75. $2 ^ { \lfloor \log _ { 2 } M _ { k } \rfloor }$ is 32. After rounding, $g _ { i ^ { \prime } }$ of each element become $0 . 0 3 1 2 5 , 0 . 2 5 , 8 , 1 6 , 3 2$ and $d _ { i }$ for each element become $1 0 , 7 , 2 , 1 , 0$ . Note that higher $d _ { i }$ corresponds to smaller $g _ { i } ^ { \prime }$ . We can use only 3 bits and thus we cannot represent 10 and it will not be sent, which means it will not be sent. Finally, we send them with $\lfloor \log _ { 2 } M _ { k } \rfloor$ , sign bits and index: $\left\{ \left\lfloor \log _ { 2 } M _ { k } \right\rfloor : 5 \right.$ , ( $( + 7$ , index : 1), (−2, index $: 2$ ), ( $+ 1$ , index : 2), $( - 0 , \mathrm { i n d e x : 3 } ) ) \}$ .
# C VISUAL REPRESENTATION OF EXPERIMENTAL RESULTS
 Figure 3 are scatter plots of Table 1 and 2. The upper right corner is desirable. The figures suggests superiority of our variance-based compression and hybrid algorithm. Figure 3: Scatter plots of relation between accuracy and compression ratio. The four plots correspond to the configurations on datasets and optimization methods as follows: (a) CIFAR-10 and Adam, (b) CIFAR-10 and MomentumSGD, (c) ImageNet and Adam, (d) ImageNet and MomentumSGD. No compression denotes the case where we do not use any compression methods. Variance is a method described in Sec. 4.1 and 4.2. Hybrid is a combination of variance based compression and Strom’s algorithm. Some outliers are not plotted. Upper right of these figures is desirable for all compression algorithms.
# D ARCHITECTURE OF VGG-LIKE NETWORK USED ON CIFAR-10
Table 3 shows the network architecture used for experiments on CIFAR-10. All convolutional layers are followed by batch normalization and ReLU activation. The code is available in examples of Chainer (Tokui et al., 2015) on GitHub.
Table 3: The network architecture for the CIFAR-10 classification task
<table><tr><td>input (3x32x32)</td></tr><tr><td>conv3-64 dropout(0.3) conv3-64</td></tr><tr><td>maxpool</td></tr><tr><td>conv3-128 dropout(0.4) conv3-128</td></tr><tr><td>maxpool</td></tr><tr><td>conv3-256 dropout(0.4) conv3-256 dropout(0.4)</td></tr><tr><td>conv3-256 maxpool</td></tr><tr><td>conv3-512 dropout(0.4) conv3-512 dropout(0.4)</td></tr><tr><td>conv3-512 maxpool</td></tr><tr><td>conv3-512 dropout(0.4) conv3-512 dropout(0.4)</td></tr><tr><td>conv3-512 maxpool</td></tr><tr><td>dropout(0.5) fully connected 512 bn relu</td></tr><tr><td>dropout(0.5) fully connected 10</td></tr><tr><td>softmax</td></tr></table>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270# LEARNING A NATURAL LANGUAGE INTERFACE WITH NEURAL PROGRAMMER
Arvind Neelakantan∗ University of Massachusetts Amherst arvind@cs.umass.edu
Quoc V. Le Google Brain qvl@google.com
Mart´ın Abadi Google Brain abadi@google.com
# Andrew McCallum∗
University of Massachusetts Amherst mccallum@cs.umass.edu
Dario Amodei∗ OpenAI damodei@openai.com
# ABSTRACT
Learning a natural language interface for database tables is a challenging task that involves deep language understanding and multi-step reasoning. The task is often approached by mapping natural language queries to logical forms or programs that provide the desired response when executed on the database. To our knowledge, this paper presents the first weakly supervised, end-to-end neural network model to induce such programs on a real-world dataset. We enhance the objective function of Neural Programmer, a neural network with built-in discrete operations, and apply it on WikiTableQuestions, a natural language question-answering dataset. The model is trained end-to-end with weak supervision of question-answer pairs, and does not require domain-specific grammars, rules, or annotations that are key elements in previous approaches to program induction. The main experimental result in this paper is that a single Neural Programmer model achieves $3 4 . 2 \%$ accuracy using only 10,000 examples with weak supervision. An ensemble of 15 models, with a trivial combination technique, achieves $3 7 . 7 \%$ accuracy, which is competitive to the current state-of-the-art accuracy of $3 7 . 1 \%$ obtained by a traditional natural language semantic parser.
# 1 BACKGROUND AND INTRODUCTION
Databases are a pervasive way to store and access knowledge. However, it is not straightforward for users to interact with databases since it often requires programming skills and knowledge about database schemas. Overcoming this difficulty by allowing users to communicate with databases via natural language is an active research area. The common approach to this task is by semantic parsing, which is the process of mapping natural language to symbolic representations of meaning. In this context, semantic parsing yields logical forms or programs that provide the desired response when executed on the databases (Zelle & Mooney, 1996). Semantic parsing is a challenging problem that involves deep language understanding and reasoning with discrete operations such as counting and row selection (Liang, 2016).
The first learning methods for semantic parsing require expensive annotation of question-program pairs (Zelle & Mooney, 1996; Zettlemoyer & Collins, 2005). This annotation process is no longer necessary in the current state-of-the-art semantic parsers that are trained using only question-answer pairs (Liang et al., 2011; Kwiatkowski et al., 2013; Krishnamurthy & Kollar, 2013; Pasupat & Liang, 2015). However, the performance of these methods still heavily depends on domain-specific grammar or pruning strategies to ease program search. For example, in a recent work on building semantic parsers for various domains, the authors hand-engineer a separate grammar for each domain (Wang et al., 2015).
Recently, many neural network models have been developed for program induction (Andreas et al., 2016; Jia & Liang, 2016; Reed & Freitas, 2016; Zaremba et al., 2016; Yin et al., 2015), despite the notorious difficulty of handling discrete operations in neural networks (Joulin & Mikolov, 2015; Kaiser & Sutskever, 2016). Most of these approaches rely on complete programs as supervision (Jia & Liang, 2016; Reed & Freitas, 2016) while others (Zaremba et al., 2016; Yin et al., 2015) have been tried only on synthetic tasks. The work that is most similar to ours is that of Andreas et al. (2016) on the dynamic neural module network. However, in their method, the neural network is employed only to search over a small set of candidate layouts provided by the syntactic parse of the question, and is trained using the REINFORCE algorithm (Williams, 1992). Hence, their method cannot recover from parser errors, and it is not trivial to adapt the parser to the task at hand. Additionally, all their modules or operations are parametrized by a neural network, so it is difficult to apply their method on tasks that require discrete arithmetic operations. Finally, their experiments concern a simpler dataset that requires fewer operations, and therefore a smaller search space, than WikiTableQuestions which we consider in our work. We discuss other related work in Section 4.
 Figure 1: Neural Programmer is a neural network augmented with a set of discrete operations. The model runs for a fixed number of time steps, selecting an operation and a column from the table at every time step. The induced program transfers information across timesteps using the row selector variable while the output of the model is stored in the scalar answer and lookup answer variables.
Neural Programmer (Neelakantan et al., 2016) is a neural network augmented with a set of discrete operations. It produces both a program, made up of those operations, and the result of running the program against a given table. The operations make use of three variables: row selector, scalar answer, and lookup answer, which are updated at every timestep. lookup answer and scalar answer store answers while row selector is used to propagate information across time steps. As input, a model receives a question along with a table (Figure 1). The model runs for a fixed number of time steps, selecting an operation and a column from the table as the argument to the operation at each time step. During training, soft selection (Bahdanau et al., 2014) is performed so that the model can be trained end-to-end using backpropagation. This approach allows Neural Programmer to explore the search space with better sample complexity than hard selection with the REINFORCE algorithm (Williams, 1992) would provide. All the parameters of the model are learned from a weak supervision signal that consists of only the final answer; the underlying program, which consists of a sequence of operations and of selected columns, is latent.
In this work, we develop an approach to semantic parsing based on Neural Programmer. We show how to learn a natural language interface for answering questions using database tables, thus integrating differentiable operations that are typical of neural networks with the declarative knowledge contained in the tables and with discrete operations on tables and entries. For this purpose, we make several improvements and adjustments to Neural Programmer, in particular adapting its objective function to make it more broadly applicable.
In earlier work, Neural Programmer is applied only on a synthetic dataset. In that dataset, when the expected answer is an entry in the given table, its position is explicitly marked in the table. However, real-world datasets certainly do not include those markers, and lead to many ambiguities (e.g., (Pasupat & Liang, 2015)). In particular, when the answer is a number that occurs literally in the table, it is not known, a priori, whether the answer should be generated by an operation or selected from the table. Similarly, when the answer is a natural language phrase that occurs in multiple positions in the table, it is not known which entry (or entries) in the table is actually responsible for the answer. We extend Neural Programmer to handle the weaker supervision signal by backpropagating through decisions that concern how the answer is generated when there is an ambiguity.
Our main experimental results concern WikiTableQuestions (Pasupat & Liang, 2015), a real-world question-answering dataset on database tables, with only 10,000 examples for weak supervision. This dataset is particularly challenging because of its small size and the lack of strong supervision, and also because the tables provided at test time are never seen during training, so learning requires adaptation at test time to unseen column names. A state-of-the-art, traditional semantic parser that relies on pruning strategies to ease program search achieves $3 7 . 1 \%$ accuracy. Standard neural network models like sequence-to-sequence and pointer networks do not appear to be promising for this dataset, as confirmed in our experiments below, which yield single-digit accuracies. In comparison, a single Neural Programmer model using minimal text pre-processing, and trained end-to-end, achieves $3 4 . 2 \%$ accuracy. This surprising result is enabled primarily by the sample efficiency of Neural Programmer, by the enhanced objective function, and by reducing overfitting via strong regularization with dropout (Srivastava et al., 2014; Iyyer et al., 2015; Gal & Ghahramani, 2016) and weight decay. An ensemble of 15 models, even with a trivial combination technique, achieves $3 7 . 7 \%$ accuracy.
# 2 NEURAL PROGRAMMER
In this section we describe in greater detail the Neural Programmer model and the modifications we made to the model. Neural Programmer is a neural network augmented with a set of discrete operations. The model consists of four modules:
• Question RNN that processes the question and converts the tokens to a distributed representation. We use an LSTM network (Hochreiter & Schmidhuber, 1997) as the question RNN. • A list of discrete operations such as counting and entry selection that are manually defined. Each operation is parameterized by a real-valued vector that is learned during training. • A selector module that induces two probability distributions at every time step, one over the set of operations and another over the set of columns. The input to the selector is obtained by concatenating the last hidden state of the question RNN, the hidden state of the history RNN from the current timestep, and the attention vector obtained by performing soft attention (Bahdanau et al., 2014) on the question using the history vector. Following Neelakantan et al. (2016), we employ hard selection at test time. History RNN modeled by a simple RNN (Werbos, 1990) with tanh activations which remembers the previous operations and columns selected by the model. The input to the history RNN at each timestep is the result of concatenating the weighted representations of operations and columns with their corresponding probability distributions produced by the selector at the previous timestep.
A more detailed description of the basic model can be found in Neelakantan et al. (2016). The model runs for fixed total of $T$ timesteps. The parameters of the operations, selector module, question and history RNNs are all learned with backpropagation using a weak supervision signal that consists of the final answer. Below, we discuss several modifications to the model to make it more broadly applicable, and easier to train.
# 2.1 OPERATIONS
We use 15 operations in the model that were chosen to closely match the set of operations used in the baseline model (Pasupat & Liang, 2015). All the operations except select and most frequent entry operate only on the set of selected rows which is given by the row selector variable. Before the first timestep, all the rows in the table are set to be selected. The built-in operations are:
• count returns the number of selected rows in row selector. • select and most frequent entry are operations which are computed only once for every question and output a boolean tensor with size same as the size of the input table. An entry in the output of the select operation is set to 1 if the entry matches some phrase in the question. The matched phrases in the question are anonymized to prevent overfitting. Similarly, for most frequent entry, it is set to 1 if the entry is the most frequently occurring one in its column. • argmax, argmin, greater than, less than, greater than or equal to, less than or equal to are all operations that output a tensor with size same as the size of the input table. • first, last, previous and next modify the row selector. • print operation assigns row selector on the selected column of lookup answer. • reset resets row selector to its initial value. This operation also serves as no-op when the model needs to induce programs whose complexity is less than $T$ .
All the operations are defined to work with soft selection so that the model can be trained with backpropagation. The operations along with their definitions are discussed in the Appendix.
# 2.2 OUTPUT AND ROW SELECTOR
Neural programmer makes use of three variables: row selector, scalar answer and lookup answer which are updated at every timestep. The variable lookup answer stores answers that are selected from the table while scalar answer stores numeric answers that are not provided in the table.1 The induced program transfers information across timesteps using the row selector variable which contains rows that are selected by the model.
Given an input table $\Pi$ , containing $M$ rows and $C$ columns ( $M$ and $C$ can vary across examples), the output variables at timestep $t$ are given by:
sc $\begin{array} { r l } & { \times a l a r \ a n s w e r _ { t } = \alpha _ { t } ^ { o p } ( c o u n t ) o u t p u t _ { t } ( c o u n t ) , } \\ & { o k u p \ a n s w e r _ { t } [ i ] [ j ] = \alpha _ { t } ^ { c o l } ( j ) \alpha _ { t } ^ { o p } ( p r i n t ) r o w \ s e l e c t _ { t - t } [ i ] , \forall ( i , j ) i = 1 , 2 , . . . , M , j = 1 , 2 , . . . , C } \end{array}$ lo where $\alpha _ { t } ^ { o p } ( o p )$ and $\alpha _ { t } ^ { c o l } ( j )$ are the probabilities assigned by the selector to operation $o p$ and column $j$ at timestep $t$ respectively and $o u t p u t _ { t } ( c o u n t )$ is the output of the count operation at timestep $t$ . The row selector variable at timestep $t$ is obtained by taking the weighted average of the outputs of the remaining operations and is discussed in the Appendix. lookup answerT $[ i ] [ j ]$ is the probability that the element $( i , j )$ in the input table is in the final answer predicted by the model.
# 2.3 TRAINING OBJECTIVE
We modify the training objective of Neural Programmer to handle the supervision signal available in real-world settings. In previous work, the position of the answers are explicitly marked in the table when the answer is an entry from the table. However, as discussed in Section 1, in real-world datasets (e.g., (Pasupat & Liang, 2015)) the answer is simply written down introducing two kinds of ambiguities. First, when the answer is a number and if the number is in the table, it is not known whether the loss should be computed using the scalar answer variable or the lookup answer variable. Second, when the answer is a natural language phrase and if the phrase occurs in multiple positions in the table, we again do not know which entry (or entries) in the table is actually responsible for generating the answer. We extend Neural Programmer to handle this weaker supervision signal during training by computing the loss only on the prediction that is closest to the desired response.
For scalar answers we compute the square loss:
$$L _ { s c a l a r } ( s c a l a r ~ a n s w e r _ { T } , y ) = \frac { 1 } { 2 } ( s c a l a r ~ a n s w e r _ { T } - y ) ^ { 2 }$$
where $y$ is the ground truth answer. We divide $L _ { s c a l a r }$ by the number of rows in the input table and do not backpropagate on examples for which the loss is greater than a threshold since it leads to instabilities in training.
When the answer is a list of items $y \ = \ ( a _ { 1 } , a _ { 2 } , . . . , a _ { N } )$ , for each element in the list $( a _ { i } , i { \ = }$ $1 , 2 , \ldots , N )$ we compute all the entries in the table that match that element, given by $S _ { i } ~ =$ $\{ ( r , c ) , \forall ( r , c ) \Pi [ r ] [ { \bar { c } } ] = a _ { i } \}$ . We tackle the ambiguity introduced when an answer item occurs at multiple entries in the table by computing the loss only on the entry which is assigned the highest probability by the model. We construct $g \in \{ 0 , 1 \} ^ { M \times C }$ , where $g [ i , j ]$ indicates whether the element $( i , j )$ in the input table is part of the output. We compute log-loss for each entry and the final loss is given by:
$$\begin{array} { l } { { \displaystyle { \cal L } _ { l o o k u p } ( l o o k u p ~ a n s w e r _ { T } , y ) = \sum _ { i = 1 } ^ { N } m i n _ { ( r , c ) \in S _ { i } } ( - \log ( l o o k u p ~ a n s w e r _ { T } [ r , c ] ) ) } \ ~ } \\ { { \displaystyle ~ - \ \frac { 1 } { M C } \sum _ { i = 1 } ^ { M } \sum _ { j = 1 } ^ { C } [ g [ i , j ] ~ = = \ 0 ] \log ( 1 - l o o k u p ~ a n s w e r _ { T } [ i , j ] ) } } \end{array}$$
where $[ c o n d ]$ is 1 when cond is True, and 0 otherwise.
We deal with the ambiguity that occurs when the ground truth is a number and if the number also occurs in the table, by computing the final loss as the soft minimum of $L _ { s c a l a r }$ and $L _ { l o o k u p }$ . Otherwise, the loss for an example is $L _ { s c a l a r }$ when the ground truth is a number and $L _ { l o o k u p }$ when the ground truth matches some entries in the table. The two loss functions $L _ { s c a l a r }$ and $L _ { l o o k u p }$ are in different scales, so we multiply $L _ { l o o k u p }$ by a constant factor which we set to 50.0 after a small exploration in our experiments.
Since we employ hard selection at test time, only one among scalar answer and lookup answer is modified at the last timestep. We use the variable that is set at the last timestep as the final output of the model.
# 3 EXPERIMENTS
We apply Neural Programmer on the WikiTableQuestions dataset (Pasupat & Liang, 2015) and compare it to different non-neural baselines including a natural language semantic parser developed by Pasupat & Liang (2015). Further, we also report results from training the sequence-tosequence model (Sutskever et al., 2014) and a modified version of the pointer networks (Vinyals et al., 2015). Our model is implemented in TensorFlow (Abadi et al., 2016) and the model takes approximately a day to train on a single Tesla K80 GPU. We use double-precision format to store the model parameters since the gradients become undefined values in single-precision format. Our code is available at https://github.com/tensorflow/models/tree/master/neural_ programmer.
# 3.1 DATA
We use the train, development, and test split given by Pasupat & Liang (2015). The dataset contains 11321, 2831, and 4344 examples for training, development, and testing respectively. We use their tokenization, number and date pre-processing. There are examples with answers that are neither number answers nor phrases selected from the table. We ignore these questions during training but the model is penalized during evaluation following Pasupat & Liang (2015). The tables provided in the test set are unseen at training, hence requiring the model to adapt to unseen column names at test time. We train only on examples for which the provided table has less than 100 rows since we run out of GPU memory otherwise, but consider all examples at test time.
Table 1: Performance of Neural Programmer compared to baselines from (Pasupat & Liang, 2015). The performance of an ensemble of 15 models is competitive to the current state-of-the-art natural language semantic parser.
<table><tr><td rowspan=1 colspan=1>Method</td><td rowspan=1 colspan=1>Dev Accuracy</td><td rowspan=1 colspan=1>Test Accuracy</td></tr><tr><td rowspan=1 colspan=3>Baselines from Pasupat & Liang (2015)</td></tr><tr><td rowspan=1 colspan=1>InformationRetrieval System</td><td rowspan=1 colspan=1>13.4</td><td rowspan=1 colspan=1>12.7</td></tr><tr><td rowspan=1 colspan=1>Simple Semantic Parser</td><td rowspan=1 colspan=1>23.6</td><td rowspan=1 colspan=1>24.3</td></tr><tr><td rowspan=1 colspan=1>Semantic Parser</td><td rowspan=1 colspan=1>37.0</td><td rowspan=1 colspan=1>37.1</td></tr><tr><td rowspan=1 colspan=3>Neural Programmer</td></tr><tr><td rowspan=1 colspan=1>Neural Programmer</td><td rowspan=1 colspan=1>34.1</td><td rowspan=1 colspan=1>34.2</td></tr><tr><td rowspan=1 colspan=1>Ensemble of 15 Neural Programmer models</td><td rowspan=1 colspan=1>37.5</td><td rowspan=1 colspan=1>37.7</td></tr><tr><td rowspan=1 colspan=1>Oracle Score with 15 Neural Programmer models</td><td rowspan=1 colspan=1>50.5</td><td rowspan=1 colspan=1>1</td></tr></table>
# 3.2 TRAINING DETAILS
We use $T = 4$ timesteps in our experiments. Words and operations are represented as 256 dimensional vectors, and the hidden vectors of the question and the history RNN are also 256 dimensional. The parameters are initialized uniformly randomly within the range [-0.1, 0.1]. We train the model using the Adam optimizer (Kingma & Ba, 2014) with mini-batches of size 20. The $\epsilon$ hyperparameter in Adam is set to 1e-6 while others are set to the default values. Since the training set is small compared to other datasets in which neural network models are usually applied, we rely on strong regularization:
• We clip the gradients to norm 1 and employ early-stopping. • The occurrences of words that appear less than 10 times in the training set are replaced by a single unknown word token. • We add a weight decay penalty with strength 0.0001. • We use dropout with a keep probability of 0.8 on input and output vectors of the RNN, and selector, operation and column name representations (Srivastava et al., 2014). We use dropout with keep probability of 0.9 on the recurrent connections of the question RNN and history RNN using the technique from Gal & Ghahramani (2016). We use word-dropout (Iyyer et al., 2015) with keep probability of 0.9. Here, words in the question are randomly replaced with the unknown word token while training.
We tune the dropout rates, regularization strength, and the $\epsilon$ hyperparameter using grid search on the development data, we fix the other hyperparameters after a small exploration during initial experiments.
# 3.3 RESULTS
Table 1 shows the performance of our model in comparison to baselines from Pasupat & Liang (2015). The best result from Neural Programmer is achieved by an ensemble of 15 models. The only difference among these models is that the parameters of each model is initialized with a different random seed. We combine the models by averaging the predicted softmax distributions of the models at every timestep. While it is generally believed that neural network models require a large number of training examples compared to simpler linear models to get good performance, our model
<table><tr><td rowspan=1 colspan=1>Method</td><td rowspan=1 colspan=1>Dev Accuracy</td></tr><tr><td rowspan=1 colspan=1>NeuralProgrammer</td><td rowspan=1 colspan=1>34.1</td></tr><tr><td rowspan=1 colspan=1>NeuralProgrammer-anonymization</td><td rowspan=1 colspan=1>33.7</td></tr><tr><td rowspan=1 colspan=1>Neural Programmer - match feature</td><td rowspan=1 colspan=1>31.1</td></tr><tr><td rowspan=1 colspan=1>Neural Programmer - {dropout,weight decay}</td><td rowspan=1 colspan=1>30.3</td></tr></table>
Table 2: Model ablation studies. We find that dropout and weight decay, along with the boolean feature indicating a matched table entry for column selection, have a significant effect on the performance of the model.
achieves competitive performance on this small dataset containing only 10,000 examples with weak supervision.
We did not get better results either by using pre-trained word vectors (Mikolov et al., 2013) or by pre-training the question RNN with a language modeling objective (Dai & Le, 2015). A possible explanation is that the word vectors obtained from unsupervised learning may not be suitable to the task under consideration. For example, the learned representations of words like maximum and minimum from unsupervised learning are usually close to each other but for our task it is counterproductive. We consider replacing soft selection with hard selection and training the model with the REINFORCE algorithm (Williams, 1992). The model fails to learn in this experiment, probably because the model has to search over millions of symbolic programs for every input question making it highly unlikely to find a program that gives a reward. Hence, the parameters of the model are not updated frequently enough.
# 3.3.1 NEURAL NETWORK BASELINES
To understand the difficulty of the task for neural network models, we experiment with two neural network baselines: the sequence-to-sequence model (Sutskever et al., 2014) and a modified version of the pointer networks (Vinyals et al., 2015). The input to the sequence-to-sequence model is a concatenation of the table and the question, and the decoder produces the output one token at a time. We consider only examples whose input length is less than 400 to make the running time reasonable. The resulting dataset has 8, 857 and 1, 623 training and development examples respectively. The accuracy of the best model on this development set after hyperparameter tuning is only $8 . 9 \%$ . Next, we experiment with pointer networks to select entries in the table as the final answer. We modify pointer networks to have two-attention heads: one to select the column and the other to select entries within a column. Additionally, the model performs multiple pondering steps on the table before returning the final answer. We train this model only on lookup questions, since the model does not have a decoder to generate answers. We consider only examples whose tables have less than 100 rows resulting in training and development set consisting of 7, 534 and 1, 829 examples respectively. The accuracy of the best model on this development set after hyperparameter tuning is only $4 . 0 \dot { \% }$ . These results confirm our intuition that discrete operations are hard to learn for neural networks particularly with small datasets in real-world settings.
# 3.4 ANALYSIS
# 3.4.1 MODEL ABLATION
Table 2 shows the impact of different model design choices on the final performance. While anonymizing phrases in the question that match some table entry seems to have a small positive effect, regularization has a much larger effect on the performance. Column selection is performed in Neelakantan et al. (2016) using only the name of a column; however, this selection procedure is insufficient in real-world settings. For example the column selected in question 3 in Table 3 does not have a corresponding phrase in the question. Hence, to select a column we additionally use a boolean feature that indicates whether an entry in that column matches some phrase in the question. Table 2 shows that the addition of this boolean feature has a significant effect on performance.
<table><tr><td rowspan=1 colspan=1>ID</td><td rowspan=1 colspan=1>Question</td><td rowspan=1 colspan=1></td><td rowspan=1 colspan=1>Step 1</td><td rowspan=1 colspan=1>Step 2</td><td rowspan=1 colspan=1>Step 3</td><td rowspan=1 colspan=1>Step 4</td></tr><tr><td rowspan=2 colspan=1>1</td><td rowspan=2 colspan=1>what is the total number ofteams?</td><td rowspan=1 colspan=1>Operation</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>count</td></tr><tr><td rowspan=1 colspan=1>Column</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>-</td></tr><tr><td rowspan=2 colspan=1>2</td><td rowspan=2 colspan=1>how many games had morethan 1,5oO in attendance?</td><td rowspan=1 colspan=1>Operation</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>>=</td><td rowspan=1 colspan=1>count</td></tr><tr><td rowspan=1 colspan=1>Column</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>=</td><td rowspan=1 colspan=1>attendance</td><td rowspan=1 colspan=1>-</td></tr><tr><td rowspan=1 colspan=1>3</td><td rowspan=2 colspan=1>what is the total numberof runner-ups listed on thechart?</td><td rowspan=1 colspan=1>Operation</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>=</td><td rowspan=1 colspan=1>select</td><td rowspan=1 colspan=1>count</td></tr><tr><td rowspan=1 colspan=1></td><td rowspan=1 colspan=1>Column</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1></td><td rowspan=1 colspan=1>outcome</td><td rowspan=1 colspan=1>1</td></tr><tr><td rowspan=2 colspan=1>4</td><td rowspan=2 colspan=1>which year held the mostcompetitions?</td><td rowspan=1 colspan=1>Operation</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>mfe</td><td rowspan=1 colspan=1>print</td></tr><tr><td rowspan=1 colspan=1>Column</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>-</td><td rowspan=1 colspan=1>year</td><td rowspan=1 colspan=1>year</td></tr><tr><td rowspan=2 colspan=1>5</td><td rowspan=2 colspan=1>what opponent is listed laston the table?</td><td rowspan=1 colspan=1>Operation</td><td rowspan=1 colspan=1>last</td><td rowspan=1 colspan=1>-</td><td rowspan=1 colspan=1>last</td><td rowspan=1 colspan=1>print</td></tr><tr><td rowspan=1 colspan=1>Column</td><td rowspan=1 colspan=1>-</td><td rowspan=1 colspan=1>-</td><td rowspan=1 colspan=1>-</td><td rowspan=1 colspan=1>opponent</td></tr><tr><td rowspan=2 colspan=1>6</td><td rowspan=2 colspan=1>which section is longest??</td><td rowspan=1 colspan=1>Operation</td><td rowspan=1 colspan=1>-</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>argmax</td><td rowspan=1 colspan=1>print</td></tr><tr><td rowspan=1 colspan=1>Column</td><td rowspan=1 colspan=1>-</td><td rowspan=1 colspan=1>-</td><td rowspan=1 colspan=1>kilometers</td><td rowspan=1 colspan=1>name</td></tr><tr><td rowspan=2 colspan=1>7</td><td rowspan=2 colspan=1>which engine(s) has the leastamount of power?</td><td rowspan=1 colspan=1>Operation</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>argmin</td><td rowspan=1 colspan=1>print</td></tr><tr><td rowspan=1 colspan=1>Column</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>-</td><td rowspan=1 colspan=1>power</td><td rowspan=1 colspan=1>engine</td></tr><tr><td rowspan=2 colspan=1>8</td><td rowspan=2 colspan=1>whatwas claudia roll'stime?</td><td rowspan=1 colspan=1>Operation</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>select</td><td rowspan=1 colspan=1>print</td></tr><tr><td rowspan=1 colspan=1>Column</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>swimmer</td><td rowspan=1 colspan=1>time</td></tr><tr><td rowspan=2 colspan=1>9</td><td rowspan=2 colspan=1>who had more silver medals,cuba or brazil?</td><td rowspan=1 colspan=1>Operation</td><td rowspan=1 colspan=1>argmax</td><td rowspan=1 colspan=1>select</td><td rowspan=1 colspan=1>argmax</td><td rowspan=1 colspan=1>print</td></tr><tr><td rowspan=1 colspan=1>Column</td><td rowspan=1 colspan=1>nation</td><td rowspan=1 colspan=1>nation</td><td rowspan=1 colspan=1>silver</td><td rowspan=1 colspan=1>nation</td></tr><tr><td rowspan=2 colspan=1>10</td><td rowspan=2 colspan=1>who was the next appointeddirector after lee p. brown?</td><td rowspan=1 colspan=1>Operation</td><td rowspan=1 colspan=1>select</td><td rowspan=1 colspan=1>next</td><td rowspan=1 colspan=1>last</td><td rowspan=1 colspan=1>print</td></tr><tr><td rowspan=1 colspan=1>Column</td><td rowspan=1 colspan=1>name</td><td rowspan=1 colspan=1>-</td><td rowspan=1 colspan=1>-</td><td rowspan=1 colspan=1>name</td></tr><tr><td rowspan=2 colspan=1>11</td><td rowspan=2 colspan=1>what team is listed previousto belgium?</td><td rowspan=1 colspan=1>Operation</td><td rowspan=1 colspan=1>select</td><td rowspan=1 colspan=1>previous</td><td rowspan=1 colspan=1>first</td><td rowspan=1 colspan=1>print</td></tr><tr><td rowspan=1 colspan=1>Column</td><td rowspan=1 colspan=1>team</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>team</td></tr></table>
Table 3: A few examples of programs induced by Neural Programmer that generate the correct answer in the development set. mfe is abbreviation for the operation most frequent entry. The model runs for 4 timesteps selecting an operation and a column at every step. The model employs hard selection during evaluation. The column name is displayed in the table only when the operation picked at that step takes in a column as input while the operation is displayed only when it is other than the reset operation. Programs that choose count as the final operation produce a number as the final answer while programs that select print as the final operation produce entries selected from the table as the final answer.
<table><tr><td rowspan=1 colspan=1>Operation</td><td rowspan=1 colspan=1>Program in Table 3Amount (%)</td><td rowspan=1 colspan=1>Amount (%)</td></tr><tr><td rowspan=1 colspan=3>Scalar Answer</td></tr><tr><td rowspan=1 colspan=1>Only Count</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>6.5</td></tr><tr><td rowspan=1 colspan=1>Comparison+ Count</td><td rowspan=1 colspan=1>2</td><td rowspan=1 colspan=1>2.1</td></tr><tr><td rowspan=1 colspan=1>Select + Count</td><td rowspan=1 colspan=1>3</td><td rowspan=1 colspan=1>22.1</td></tr><tr><td rowspan=1 colspan=1>Scalar Answer</td><td rowspan=1 colspan=1>1,2,3</td><td rowspan=1 colspan=1>30.7</td></tr><tr><td rowspan=1 colspan=3>Lookup Answer</td></tr><tr><td rowspan=1 colspan=1>Most Frequent Entry + Print</td><td rowspan=1 colspan=1>4</td><td rowspan=1 colspan=1>1.7</td></tr><tr><td rowspan=1 colspan=1>First/Last+Print</td><td rowspan=1 colspan=1>5</td><td rowspan=1 colspan=1>9.5</td></tr><tr><td rowspan=1 colspan=1>Superlative+Print</td><td rowspan=1 colspan=1>6.7</td><td rowspan=1 colspan=1>13.5</td></tr><tr><td rowspan=1 colspan=1>Select+Print</td><td rowspan=1 colspan=1>8</td><td rowspan=1 colspan=1>17.5</td></tr><tr><td rowspan=1 colspan=1>Select + {first, last, previous, next, superlative} + Print</td><td rowspan=1 colspan=1>9-11</td><td rowspan=1 colspan=1>27.1</td></tr><tr><td rowspan=1 colspan=1>Lookup Answer</td><td rowspan=1 colspan=1>4-11</td><td rowspan=1 colspan=1>69.3</td></tr></table>
Table 4: Statistics of the different sequence of operations among the examples answered correctly by the model in the development set. For each sequence of operations in the table, we also point to corresponding example programs in Table 3. Superlative operations include argmax and argmin, while comparison operations include greater than, less than, greater than or equal to and less than or equal to. The model induces a program that results in a scalar answer $3 0 . 7 \%$ of the time while the induced program is a table lookup for the remaining questions. print and select are the two most common operations used $6 9 . 3 \%$ and $6 6 . 7 \%$ of the time respectively.
# 3.4.2 INDUCED PROGRAMS
Table 3 shows few examples of programs induced by Neural Programmer that yield the correct answer in the development set. The programs given in Table 3 show a few characteristics of the learned model. First, our analysis indicates that the model can adapt to unseen column names at test time. For example in Question 3, the word outcome occurs only 8 times in the training set and is replaced with the unknown word token. Second, the model does not always induce the most efficient (with respect to number of operations other than the reset operation that are picked) program to solve a task. The last 3 questions in the table can be solved using simpler programs. Finally, the model does not always induce the correct program to get the ground truth answer. For example, the last 2 programs will not result in the correct response for all input database tables. The programs would produce the correct response only when the select operation matches one entry in the table.
# 3.4.3 CONTRIBUTION OF DIFFERENT OPERATIONS
Table 4 shows the contribution of the different operations. The model induces a program that results in a scalar answer $3 0 . 7 \%$ of the time while the induced program is a table lookup for the remaining questions. The two most commonly used operations by the model are print and select.
# 3.4.4 ERROR ANALYSIS
To conclude this section, we suggest ideas to potentially improve the performance of the model. First, the oracle performance with 15 Neural Programmer models is $5 0 . 5 \%$ on the development set while averaging achieves only $3 7 . 5 \%$ implying that there is still room for improvement. Next, the accuracy of a single model on the training set is $5 3 \%$ which is about $20 \%$ higher than the accuracy in both the development set and the test set. This difference in performance indicates that the model suffers from significant overfitting even after employing strong regularization. It also suggests that the performance of the model could be greatly improved by obtaining more training data. Nevertheless, there are limits to the performance improvements we may reasonably expect: in particular, as shown in previous work (Pasupat & Liang, 2015), $21 \%$ of questions on a random set of 200 examples in the considered dataset are not answerable because of various issues such as annotation errors and tables requiring advanced normalization.
# 4 OTHER RELATED WORK
While we discuss in detail various semantic parsing and neural program induction techniques in Section 1, here we briefly describe other relevant work. Recently, Kocisky et al. (2016) develop a semi-supervised semantic parsing method that uses question-program pairs as supervision. Concurrently to our work, Liang et al. (2016) propose neural symbolic machine, a model very similar to Neural Programmer but trained using the REINFORCE algorithm (Williams, 1992). They use only 2 discrete operations and run for a total of 3 timesteps, hence inducing programs that are much simpler than ours. Neural networks have also been applied on question-answering datasets that do not require much arithmetic reasoning (Bordes et al., 2014; Iyyer et al., 2014; Sukhbaatar et al., 2015; Peng et al., 2015; Hermann et al., 2015; Kumar et al., 2016). Wang & Jiang (2016) use a neural network model to get state-of-the-art results on a reading comprehension task (Rajpurkar et al., 2016).
# 5 CONCLUSION
In this paper, we enhance Neural Programmer to work with weaker supervision signals to make it more broadly applicable. Soft selection during training enables the model to actively explore the space of programs by backpropagation with superior sample complexity. In our experiments, we show that the model achieves performance comparable to a state-of-the-art traditional semantic parser even though the training set contains only 10,000 examples. To our knowledge, this is the first instance of a weakly supervised, end-to-end neural network model that induces programs on a real-world dataset.
Acknowledgements We are grateful to Panupong Pasupat for answering numerous questions about the dataset, and providing pre-processed version of the dataset and the output of the semantic parser. We thank David Belanger, Samy Bengio, Greg Corrado, Andrew Dai, Jeff Dean, Nando de Freitas, Shixiang Gu, Navdeep Jaitly, Rafal Jozefowicz, Ashish Vaswani, Luke Vilnis, Yuan Yu and Barret Zoph for their suggestions and the Google Brain team for the support. Arvind Neelakantan is supported by a Google PhD fellowship in machine learning.
# REFERENCES
Mart´ın Abadi, Ashish Agarwal, Paul Barham, Eugene Brevdo, Zhifeng Chen, Craig Citro, Gregory S. Corrado, Andy Davis, Jeffrey Dean, Matthieu Devin, Sanjay Ghemawat, Ian J. Goodfellow, Andrew Harp, Geoffrey Irving, Michael Isard, Yangqing Jia, Rafal Jozefowicz, Lukasz ´ Kaiser, Manjunath Kudlur, Josh Levenberg, Dan Mane, Rajat Monga, Sherry Moore, Derek Gor- ´ don Murray, Chris Olah, Mike Schuster, Jonathon Shlens, Benoit Steiner, Ilya Sutskever, Kunal Talwar, Paul A. Tucker, Vincent Vanhoucke, Vijay Vasudevan, Fernanda B. Viegas, Oriol Vinyals, ´ Pete Warden, Martin Wattenberg, Martin Wicke, Yuan Yu, and Xiaoqiang Zheng. Tensorflow: Large-scale machine learning on heterogeneous distributed systems. ArXiv, 2016.
Jacob Andreas, Marcus Rohrbach, Trevor Darrell, and Dan Klein. Learning to compose neural networks for question answering. NAACL, 2016.
Dzmitry Bahdanau, Kyunghyun Cho, and Yoshua Bengio. Neural machine translation by jointly learning to align and translate. ICLR, 2014.
Antoine Bordes, Sumit Chopra, and Jason Weston. Question answering with subgraph embeddings. EMNLP, 2014.
Andrew M Dai and Quoc V Le. Semi-supervised sequence learning. NIPS, 2015.
Yarin Gal and Zoubin Ghahramani. A theoretically grounded application of dropout in recurrent neural networks. NIPS, 2016.
Karl Moritz Hermann, Tomas Kocisk ´ y, Edward Grefenstette, Lasse Espeholt, Will Kay, Mustafa ´ Suleyman, and Phil Blunsom. Teaching machines to read and comprehend. NIPS, 2015.
Sepp Hochreiter and Jurgen Schmidhuber. Long short-term memory. ¨ Neural Computation, 1997.
Mohit Iyyer, Jordan L. Boyd-Graber, Leonardo Max Batista Claudino, Richard Socher, and Hal Daume III. A neural network for factoid question answering over paragraphs. ´ EMNLP, 2014.
Mohit Iyyer, Varun Manjunatha, Jordan Boyd-Graber, and Hal Daume III. Deep unordered compo- ´ sition rivals syntactic methods for text classification. ACL, 2015.
Robin Jia and Percy Liang. Data recombination for neural semantic parsing. ACL, 2016.
Armand Joulin and Tomas Mikolov. Inferring algorithmic patterns with stack-augmented recurrent nets. NIPS, 2015.
Lukasz Kaiser and Ilya Sutskever. Neural gpus learn algorithms. ICLR, 2016.
Diederik P. Kingma and Jimmy Ba. Adam: A method for stochastic optimization. ICLR, 2014.
Tomas Kocisky, Gabor Melis, Edward Grefenstette, Chris Dyer, Wang Ling, Phil Blunsom, and Karl Moritz Hermann. Semantic parsing with semi-supervised sequential autoencoders. ArXiv, 2016.
Jayant Krishnamurthy and Thomas Kollar. Jointly learning to parse and perceive: Connecting natural language to the physical world. TACL, 2013.
Ankit Kumar, Ozan Irsoy, Jonathan Su, James Bradbury, Robert English, Brian Pierce, Peter Ondruska, Ishaan Gulrajani, and Richard Socher. Ask me anything: Dynamic memory networks for natural language processing. ICML, 2016.
Tom Kwiatkowski, Eunsol Choi, Yoav Artzi, and Luke Zettlemoyer. Scaling semantic parsers with on-the-fly ontology matching. EMNLP, 2013.
Chen Liang, Jonathan Berant, Quoc Le, Kenneth Forbus, and Ni Lao. Neural symbolic machines: Learning semantic parsers on freebase with weak supervision. NAMPI Workshop, NIPS, 2016.
Percy Liang. Learning executable semantic parsers for natural language understanding. ACM, 2016.
Percy Liang, Michael I. Jordan, and Dan Klein. Learning dependency-based compositional semantics. ACL, 2011.
Tomas Mikolov, Kai Chen, Greg Corrado, and Jeffrey Dean. Efficient estimation of word representations in vector space. ArXiv, 2013.
Arvind Neelakantan, Quoc V. Le, and Ilya Sutskever. Neural programmer: Neural programmer: Inducing latent programs with gradient descent. ICLR, 2016.
Panupong Pasupat and Percy Liang. Compositional semantic parsing on semi-structured tables. ACL, 2015.
Baolin Peng, Zhengdong Lu, Hang Li, and Kam-Fai Wong. Towards neural network-based reasoning. ArXiv, 2015.
Pranav Rajpurkar, Jian Zhang, Konstantin Lopyrev, and Percy Liang. Squad: 100, $0 0 0 +$ questions for machine comprehension of text. ArXiv, 2016.
Scott Reed and Nando De Freitas. Neural programmer-interpreters. ICLR, 2016.
Nitish Srivastava, Geoffrey Hinton, Alex Krizhevsky, Ilya Sutskever, and Ruslan Salakhutdinov. Dropout: A simple way to prevent neural networks from overfitting. JMLR, 2014.
Sainbayar Sukhbaatar, Arthur Szlam, Jason Weston, and Rob Fergus. End-to-end memory networks. NIPS, 2015.
Ilya Sutskever, Oriol Vinyals, and Quoc V. Le. Sequence to sequence learning with neural networks. NIPS, 2014.
Oriol Vinyals, Meire Fortunato, and Navdeep Jaitly. Pointer networks. NIPS, 2015.
Shuohang Wang and Jing Jiang. Machine comprehension using match-lstm and answer pointer. ArXiv, 2016.
Yushi Wang, Jonathan Berant, and Percy Liang. Building a semantic parser overnight. ACL, 2015.
P. Werbos. Backpropagation through time: what does it do and how to do it. Proceedings of IEEE, 1990.
Ronald Williams. Simple statistical gradient-following algorithms for connectionist reinforcement learning. Machine Learning, 1992.
Pengcheng Yin, Zhengdong Lu, Hang Li, and Ben Kao. Neural enquirer: Learning to query tables with natural language. ArXiv, 2015.
Wojciech Zaremba, Tomas Mikolov, Armand Joulin, and Rob Fergus. Learning simple algorithms from examples. ICML, 2016.
John M. Zelle and Raymond J. Mooney. Learning to parse database queries using inductive logic programming. AAAI/IAAI, 1996.
Luke S. Zettlemoyer and Michael Collins. Learning to map sentences to logical form: Structured classification with probabilistic categorial grammars. UAI, 2005.
<table><tr><td rowspan=1 colspan=1>Type</td><td rowspan=1 colspan=1>Operation</td><td rowspan=1 colspan=3>Definition</td></tr><tr><td rowspan=1 colspan=1>Aggregate</td><td rowspan=1 colspan=1>count</td><td rowspan=1 colspan=3>Mcountt =∑ row_selectt-1[i]i=1</td></tr><tr><td rowspan=2 colspan=1>Superlative</td><td rowspan=1 colspan=1>argmax</td><td rowspan=1 colspan=3>maxt[i][j]=max(O.0,row_selectt-1[i]-C([[[i][]]<I[k][j]] × row_selectt-1[k])),i=1,...,M,j=1,...,C</td></tr><tr><td rowspan=1 colspan=1>argmin</td><td rowspan=1 colspan=3>mint[i][j]=max(O.0,row_selectt-1[i]-M([[i][j] > I[k][j]] × row_select-1[k])),i=1,...,M,j =1,...,C</td></tr><tr><td rowspan=4 colspan=1>Comparison</td><td rowspan=1 colspan=1>></td><td rowspan=1 colspan=1>gi][i]=II</td><td rowspan=1 colspan=1>illi</td><td rowspan=1 colspan=1>g[i][j]= I[i][] > pivotg,V(i,j),i= 1,...,M,j = 1,...,C</td></tr><tr><td rowspan=1 colspan=1><</td><td rowspan=1 colspan=1>[i][=II</td><td rowspan=1 colspan=1>i]i</td><td rowspan=1 colspan=1>li][j]=I[i][]< pivot,V(i,j),i =1,...,M,j=1,...,C</td></tr><tr><td rowspan=1 colspan=1>M</td><td rowspan=1 colspan=1>geii=II</td><td rowspan=1 colspan=1>il</td><td rowspan=1 colspan=1>geli]l]= I[𝑖]j]≥ pivotge,∀(i,j),i = 1,...,M,j = 1,...,C</td></tr><tr><td rowspan=1 colspan=1>≤</td><td rowspan=1 colspan=2>leij=Iij</td><td rowspan=1 colspan=1>le[i][j]=II[i][j]≤ pivote,V(i,j),i=1,...,M,j=1,...,C</td></tr><tr><td rowspan=6 colspan=1>Table Ops</td><td rowspan=1 colspan=1>select</td><td rowspan=1 colspan=3>s[i][j]= 1.O if II[i]lj] appears in question else 0.0,∀(i,j),i=1,...,M,j =1,...,C</td></tr><tr><td rowspan=1 colspan=1>mfe</td><td rowspan=1 colspan=3>mfe[i][j]=1.O if I[i]lj] is the most common entry in column j else 0.0,∀(i,j),i =1,...,M,j=1,.,C</td></tr><tr><td rowspan=1 colspan=1>first</td><td rowspan=1 colspan=3>i=1,...,M</td></tr><tr><td rowspan=1 colspan=1>last</td><td rowspan=1 colspan=3>i=1,...,M</td></tr><tr><td rowspan=1 colspan=1>previous</td><td rowspan=1 colspan=3>Pt[]= row_selectt-1[i+ 1],i=1,...,M-1;pt[M]=0</td></tr><tr><td rowspan=1 colspan=1>next</td><td rowspan=1 colspan=3>nt[i]=row_selectt-1[i-1],i=2,...,M;nt[1]=0</td></tr><tr><td rowspan=1 colspan=1>Print</td><td rowspan=1 colspan=1>print</td><td rowspan=1 colspan=3>lookup answert[il[i]= row_selectt-1[i],∀(i,j)i=1,...,M,j =1,...,C</td></tr><tr><td rowspan=1 colspan=1>Reset</td><td rowspan=1 colspan=1>reset</td><td rowspan=1 colspan=3>rt[]=1,Vi =1,2,...,M</td></tr></table>
Table 5: List of all operations provided to the model along with their definitions. mfe is abbreviation for the operation most frequent entry. [cond] is 1 when cond is True, and 0 otherwise. Comparison, select, reset and mfe operations are independent of the timestep while all the other operations are computed at every time step. Superlative operations and most frequent entry are computed within a column. The operations calculate the expected output with the respect to the membership probabilities given by the row selector so that they can work with probabilistic selection.
# APPENDIX
# OPERATIONS
Table 5 shows the list of operations built into the model along with their definitions.
ROW SELECTOR
As discussed in Section 2.3, the output variables scalar answer and lookup answer are calculated using the output of the count operations and print operation respectively. The row selector is computed using the output of the remaining operations and is given by,
$$\begin{array} { l } { { r o w ~ s e l e c t o r } [ \hat { l } ] = \displaystyle \sum _ { j = 1 } ^ { C } \{ \alpha _ { t } ^ { c o l } ( j ) \alpha _ { t } ^ { o p } ( > ) g [ \hat { l } ] [ j ] + \alpha _ { t } ^ { c o l } ( j ) \alpha _ { t } ^ { o p } ( < ) l [ \hat { l } ] [ j ] } \\ { ~ + ~ \alpha _ { t } ^ { c o l } ( j ) \alpha _ { t } ^ { o p } ( \ge ) g [ \hat { l } ] [ j ] + \alpha _ { t } ^ { c o l } ( j ) \alpha _ { t } ^ { o p } ( \le ) l [ \hat { l } ] [ j ] , } \\ { { ~ + ~ \alpha _ { t } ^ { c o l } ( j ) \alpha _ { t } ^ { o p } ( a r g m a x ) m a x [ \hat { l } ] j ] + \alpha _ { t } ^ { c o l } ( j ) \alpha _ { t } ^ { o p } ( a r g m i n _ { t } ) m i n [ \hat { l } ] [ j ] , } } \\ { { ~ + ~ \alpha _ { t } ^ { c o l } ( j ) \alpha _ { t } ^ { o p } ( s e l e c t ) s [ i ] [ j ] + \alpha _ { t } ^ { c o l } ( j ) \alpha _ { t } ^ { o p } ( m f e ) m f e [ \hat { l } ] [ j ] ] } } \\ { { ~ + ~ \alpha _ { t } ^ { c o l } ( j ) \alpha _ { t } ^ { o p } ( s e l e c t ) s [ i ] [ j ] + \alpha _ { t } ^ { c o l } ( j ) \alpha _ { t } ^ { o p } ( m f e ) m f e [ \hat { l } ] [ j ] ] } } \\ { { ~ + ~ \alpha _ { t } ^ { o p } ( p r e v i o u s ) p _ { t } [ \hat { l } ] + \alpha _ { t } ^ { o p } ( m e x t ) n _ { t } [ \hat { l } ] + \alpha _ { t } ^ { o p } ( r e s e t ) r _ { t } [ \hat { l } ] } } \\ { { ~ + ~ \alpha _ { t } ^ { e o p } ( f i r s t ) f [ \hat { l } ] + \alpha _ { t } ^ { o p } ( l a s t ) l a _ { t } [ \hat { l } ] } } \\ { { ~ \forall i , i = 1 , 2 , . . . , ~ M } } \end{array}$$
where $\alpha _ { t } ^ { o p } ( o p )$ and $\alpha _ { t } ^ { c o l } ( j )$ are the probabilities assigned by the selector to operation $o p$ and column $j$ at timestep $t$ respectively.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274# SubTab: Subsetting Features of Tabular Data for Self-Supervised Representation Learning
Talip Uçar, Ehsan Hajiramezanali, Lindsay Edwards
Respiratory and Immunology, R&D, AstraZeneca {talip.ucar, ehsan.hajiramezanali, lindsay.edwards}@astrazeneca.com
# Abstract
Self-supervised learning has been shown to be very effective in learning useful representations, and yet much of the success is achieved in data types such as images, audio, and text. The success is mainly enabled by taking advantage of spatial, temporal, or semantic structure in the data through augmentation. However, such structure may not exist in tabular datasets commonly used in fields such as healthcare, making it difficult to design an effective augmentation method, and hindering a similar progress in tabular data setting. In this paper, we introduce a new framework, Subsetting features of Tabular data (SubTab), that turns the task of learning from tabular data into a multi-view representation learning problem by dividing the input features to multiple subsets. We argue that reconstructing the data from the subset of its features rather than its corrupted version in an autoencoder setting can better capture its underlying latent representation. In this framework, the joint representation can be expressed as the aggregate of latent variables of the subsets at test time, which we refer to as collaborative inference. Our experiments show that the SubTab achieves the state of the art (SOTA) performance of $9 8 . 3 1 \%$ on MNIST in tabular setting, on par with CNN-based SOTA models, and surpasses existing baselines on three other real-world datasets by a significant margin.
# 1 Introduction
In recent years, the self-supervised learning has successfully been used to learn meaningful representations of the data in natural language processing [34, 41, 11, 28, 10, 21, 9]. A similar success has been achieved in image and audio domains [7, 15, 37, 5, 17, 13, 8]. This progress is mainly enabled by taking advantage of spatial, semantic, or temporal structure in the data through data augmentation [7] , pretext task generation [11] and using inductive biases through architectural choices (e.g. CNN for images). However, these methods can be less effective in the lack of such structures and biases in the tabular data commonly used in many fields such as healthcare, advertisement, finance, and law. And some augmentation methods such as cropping, rotation, color transformation etc. are domain specific, and not suitable for tabular setting. The difficulty in designing similarly effective methods tailored for tabular data is one of the reasons why self-supervised learning is under-studied in this domain $\lVert \overline { { 4 6 } } \rVert$ .
The most common approach in tabular data is to corrupt data through adding noise $\boxed { 4 3 }$ . An autoencoder maps corrupted examples of data to a latent space, from which it maps back to uncorrupted data. Through this process, it learns a representation robust to the noise in the input. This approach may not be as effective since it treats all features equally as if features are equally informative. However, perturbing uninformative features may not result in the intended goal of the corruption. A recent work takes advantage of self-supervised learning in tabular data setting by introducing a pretext task [46], in which a de-noising autoencoder with a classifier attached to representation layer is trained on corrupted data. The classifier’s task is to predict the location of corrupted features. However, this framework still relies on noisy data in the input. Additionally, training a classifier on an imbalanced binary mask for a high-dimensional data may not be ideal to learn meaningful representations.
 Figure 1: SubTab framework: i) Dividing the features into subsets (similar to feature bagging, or cropping images), ii) Reconstruction of either subsets of features $( \tilde { x } _ { 1 } , \tilde { x } _ { 2 } , \tilde { x } _ { 3 } )$ , or complete feature space $( \breve { \tilde { X } } _ { 1 } , \tilde { X } _ { 2 } , \tilde { X } _ { 3 } )$ , which are used to compute reconstruction loss. iii) Generating projections used to compute contrastive and distance loss. $E \equiv E n c o d e r .$ $D \equiv D e c o d e r$ , $G \equiv P r$ ojection.
In this work, we turn the problem of learning representation from a single-view of the data into the one learnt from its multiple views by dividing the features into subsets, akin to cropping in image domain or feature bagging in ensemble learning, to generate different views of the data. Each subset can be considered a different view. We show that reconstructing data from the subset of its features forces the encoder to learn better representation than the ones learned through the existing methods such as adding noise. We train our model in a self-supervised setting and evaluate it on downstream tasks such as classification, and clustering. We use five different datasets; MNIST in tabular format, the cancer genome atlas (TCGA) [42], human gut metagen-omic samples of obesity cohorts (Obesity) [36, 26], UCI adult income (Income) [24], and UCI BlogFeedback (Blog) [4].
SubTab can: i) construct a better representation by using the aggregate of the representation of the subsets, a process that we refer as collaborative inference ii) discover the regions of informative features by measuring predictive power of each subset, which is useful especially in high-dimensional data iii) do training and inference in the presence of missing features by ignoring corresponding subsets and iv) use smaller models by reducing input dimension, making it less prone to overfitting.
# 2 Method
The augmentation methods such as adding noise, rotation, cropping etc. are commonly used in image domain. Among them, the cropping is shown to be the most effective technique $\textcircled { 7 }$ . Inspired from this insight, we propose subsetting features of tabular data.
Figure 1 presents SubTab framework, in which we have an encoder (E), a decoder (D), and an optional projection (G). For the purpose of this paper, we will refer $^ { h }$ as latent, or representation, $_ { z }$ as projection, $\tilde { \pmb x }$ , and $\tilde { X }$ as the reconstruction of subset, and whole data respectively. Small letters are associated with subsets while capital latters are associated the whole set of features. Moreover, throughout this work, when we say that a representation is "good", we refer to its performance in a classification task using a linear model.
In SubTab framework, we divide tabular data to multiple subsets. Neighbouring subsets can have overlapping regions, defined as a percentage of a dimension of the subset. Each of the subsets is fed to the same encoder (i.e. parameter sharing) to get their corresponding latent representation. A shared decoder is used to reconstruct either the subset fed to the encoder, or full tabular data (i.e. reconstructing all features from the subset of features). We chose the latter in our experiments since it is more effective in learning good representations. We should also note that, in the latter case, the autoencoder cannot learn the identity, eliminating the constraint on the dimension of the bottleneck (i.e. representation). We compute one reconstruction loss term per subset.
 Figure 2: a) Push-Pull forces applied by each loss. PS / NS $:$ Positive/Negative sample; CL/RL/DL: Contrastive, Reconstruction, Distance losses b) Column or feature selection strategies for adding noise to each subset. Top: Selecting a block of neighbouring columns; Middle: Selecting columns randomly; Bottom: Selecting random features per row c) Latent variables from each subset is aggregated at test time. The mean (default), sum, max, or min aggregation can be used.
Moreover, we can optionally add contrastive loss to our objective by using all combination of pairs of projections from all subsets. For example, given three subsets as in Figure 1, there are three combinations of two: $\textstyle { { \binom { n } { k } } = { \binom { 3 } { 2 } } = { \frac { 3 ! } { 2 ! ( 1 ) ! } } = \dot { 3 } }$ . For four subsets, it would be 6 pairs of combination, and so on. We can add one more loss term, referred as distance loss, to reduce the distance between the pairs of projections of the subsets by using a loss function such as mean squared error (MSE). All three loss terms apply a pulling force on positive samples while contrastive loss also applies a push force between positive and negative samples as shown in Figure 2a.
Once the dataset is divided into subsets in data preparation step, a process that is similar to feature bagging in ensemble learning, their location is fixed. Thus, we don’t change the relative order of features in a subset during training since standard neural network architectures are not permutation invariant. This is to ensure that same features are fed to the same input units of neural network. However, our method can be extended to permutation invariant setting as a next step.
# 2.1 Strategies for adding noise
Our framework is complementary to other augmentation techniques used in tabular data setting. Thus, we experimented with adding noise to randomly selected entries in each subset by using three types of noise: i) adding Gaussian noise, ${ \mathcal { N } } ( 0 , \sigma ^ { 2 } )$ , ii) overwriting the value of a selected entry with another value randomly sampled from the same column, referred as swap-noise, iii) zeroing-out randomly selected entries, referred as zero-out noise.
Moreover, we use three different strategies when selecting the features to add noise to, as shown in Figure 2b: i) a random block of neighboring columns (NC), ii) random columns (RC) iii) random features per each sample (RF). To add noise, we create a binomial mask, $_ { \mathbf { \nabla } } \mathbf { m }$ , and a noise matrix, $\epsilon$ with same shape as the subset, in which the entries of the mask is assigned to 1 with probability $p$ and to 0 otherwise. The corrupted version, $\scriptstyle { \mathbf { \mathcal { x } } } _ { 1 c }$ , of subset $\mathbf { \mathbf { { x } _ { 1 } } }$ is generated as following:
$$x _ { 1 c } = ( 1 - m ) \odot x _ { 1 } + m \odot \epsilon$$
# 2.2 Training
Our objective function is:
$$\mathcal { L } _ { t } = \mathcal { L } _ { r } + \mathcal { L } _ { c } + \mathcal { L } _ { d } ,$$
where $\mathcal { L } _ { t } , \mathcal { L } _ { r }$ , $\mathcal { L } _ { c }$ and $\mathcal { L } _ { d }$ are total, reconstruction, contrastive, and distance losses, respectively.
i) Reconstruction loss: Given a subset, denoted by $\scriptstyle { \mathbf { 2 } } \mathbf { 4 }$ , we can reconstruct either the same subset, $\tilde { \mathbfit { x } } _ { k }$ or the entire feature space $\tilde { X } _ { k }$ . Then, we can compute the reconstruction loss for $k ^ { t h }$ subset by
computing mean squared error using either $( x _ { k } , \tilde { x } _ { k } )$ , or $( X , \tilde { X } _ { k } )$ pair as shown in Figure 1. We chose the latter since it was more effective. Overall reconstruction loss:
$$\mathcal { L } _ { r } = \frac { 1 } { K } \sum _ { k = 1 } ^ { K } s _ { k } , \mathrm { w h e r e } s _ { k } = \frac { 1 } { N } \sum _ { i = 1 } ^ { N } \left( X ^ { ( i ) } - \tilde { X } _ { k } ^ { ( i ) } \right) ^ { 2 }$$
where $K$ is the total number of subsets, $N$ is the size of the batch, $s _ { k }$ is the reconstruction loss for $k ^ { t h }$ subset, and $\mathcal { L } _ { r }$ is the average of reconstruction loss over all subsets.
ii) Contrastive loss: If the dataset is rich in the number of classes such that chances of sampling negative samples are high, we can use a projection network (G) to get projections, $z ^ { \prime } s$ , of representations, $\bar { \boldsymbol { h } } ^ { \prime } \boldsymbol { s }$ . Samples at the same rows of two subsets, ${ z } _ { 1 }$ and ${ z _ { 2 } }$ , can be considered as positive pairs while remaining rows in the subsets can be considered as negative to those samples.This allows us to compute the contrastive loss for each pair of projections using a loss function such as the normalized temperature-scaled cross entropy loss (NT-Xent) $\lVert \rVert$ . For three subsets, $\{ x _ { 1 } , x _ { 2 } , x _ { 3 } \}$ , we can compute such a loss for every pair $\{ z _ { a } , z _ { b } \}$ of total three pairs from the set $\bar { S } = \{ \{ z _ { 1 } , z _ { 2 } \} , \{ z _ { 1 } , z _ { 3 } \} , \{ z _ { 2 } , z _ { 3 } \} \}$ . Overall contrastive loss is:
$$\mathcal { L } _ { c } = \frac { 1 } { J } \sum _ { \{ z _ { a } , z _ { b } \} \in S } p ( z _ { a } , z _ { b } ) , \mathrm { ~ w h e r e ~ } p ( z _ { a } , z _ { b } ) = \frac { 1 } { 2 N } \sum _ { i = 1 } ^ { N } \Big [ l ( z _ { a } ( ^ { i } ) , z _ { b } ( ^ { i } ) ) + l ( z _ { b } ( ^ { i } ) , z _ { a } ( ^ { i } ) ) \Big ]$$
$$l ( z _ { \mathbf { a } } ^ { ( i ) } , z _ { b } ^ { ( i ) } ) = - \log \frac { \exp ( s i m ( z _ { \mathbf { a } } ^ { ( i ) } , z _ { b } ^ { ( i ) } ) / \tau ) } { \sum _ { k = 1 } ^ { N } \mathbb { 1 } _ { k \neq i } \exp ( s i m ( z _ { \mathbf { a } } ^ { ( i ) } , z _ { b } ^ { ( k ) } ) / \tau ) }$$
where $J$ is the total number of pairs in set $S$ , $p ( z _ { a } , z _ { b } )$ is total contrastive loss for a pair of projection $\{ z _ { a } , z _ { b } \}$ , $l \big ( z _ { a } ^ { \mathrm { ~ } } ^ { ( i ) } , z _ { b } ^ { \mathrm { ~ } ( i ) } \big )$ is the loss function for a corresponding positive pairs of examples $( z _ { a } { ^ { ( i ) } } , z _ { b } { ^ { ( i ) } } )$ in subsets $\{ z _ { a } , z _ { b } \}$ , and $\mathcal { L } _ { c }$ is the average of contrastive loss over all pairs.
iii) Distance loss: We can also add mean-squared error (MSE) loss for pairs of projections of subsets since the corresponding samples in subsets should be close to each other. Hence, we can compute an overall MSE loss as:
$${ \mathcal { L } } _ { d } = { \frac { 1 } { J } } \sum _ { \{ z _ { a } , z _ { b } \} \in S } p ( z _ { a } , z _ { b } ) , { \mathrm { ~ w h e r e ~ } } p ( z _ { a } , z _ { b } ) = { \frac { 1 } { N } } \sum _ { i = 1 } ^ { N } \left( z _ { a } ^ { ( i ) } - z _ { b } ^ { ( i ) } \right) ^ { 2 }$$
The pseudocode of algorithm can be found in Algorithm $\bigstar$ in the Appendix. We should note that both $\mathcal { L } _ { c }$ and $\mathcal { L } _ { d }$ in equation $^ { ( 2 ) }$ are optional, and we used them only in some experiments.
# 2.3 Test time
At test time, we feed the subsets of test set to the encoder, and get the aggregate of the representations of all available subsets as shown in Figure $2 \mathrm { c } .$ Please note that we can use mean, sum, min, max, or any other aggregation method to get joint representation, which is analogous to pooling in Computer Vision, or the aggregation of neighbouring nodes in graph convolutional networks $\pmb { \widetilde { \left. 2 3 \right. } }$ . We used mean aggregation in all our experiments, but did compare different aggregation methods in Appendix F.4. Our experiments show that we can use the representations of only one, or few subsets and still achieve a good performance at test time. For example, we could use only $h _ { 1 }$ , or aggregate of $\boldsymbol { h } _ { 1 }$ and $h _ { 2 }$ rather than aggregating over all subsets $( h _ { 1 } , h _ { 2 } , h _ { 3 } )$ in Figure $\boxed { 2 \mathrm { c } }$ This allows the model to infer from the data even in the presence of missing features, in which case we can ignore the subset with missing features. We can also design an aggregation function that computes weighted mean of the representations of subsets since some subsets might be more informative than others:
$$h = \frac { 1 } { Z } \sum _ { k = 1 } ^ { K } \eta _ { k } * h _ { k } , \mathrm { a n d } Z = \sum _ { k = 1 } ^ { K } \eta _ { k } ,$$
where $K$ is number of subsets, and $\eta _ { k }$ is the weight for $k _ { t h }$ subset. $\eta$ can be a learnable parameter in semi-supervised, or supervised setting by using an attention mechanism. We can also use 1D convolution in equation $\textcircled { 7 }$ by treating representations of subsets as separate channels during training. We left these ideas as future work and used the mean aggregation (i.e. $\eta _ { k } = 1 \mathrm { ~ }$ ) throughout our experiments, unless explicitly stated. A comparison of different aggregation methods can be found in Table $\underline { { \sqrt { \bf A } ^ { 3 } } } \mathrm { | i n }$ the Appendix.
# 3 Experiments
We conducted various experiments on diverse set of tabular datasets including MNIST $\pm \pm$ in tabular format, the cancer genome atlas (TCGA) $\pmb { \| 4 2 } \pmb { \| }$ , human gut metagen-omic samples of obesity cohorts (Obesity) [36, 26], UCI adult income (Income) $\pm \overbrace { | 2 4 | }$ , and UCI BlogFeedback (Blog) [4] to demonstrate the effectiveness of the SubTab framework. We compare our method to autoencoder baseline with and without dropout, other self-supervised methods such as VIME-self $\boxed { \boxed { 4 6 } }$ , Denoising Autoencoder (DAE) $\boxed { \boxplus 3 }$ , and Context Encoder (CAE) $\textcircled { 1 3 9 } \textcircled { 1 }$ as well as fully-supervised models such as logistic regression, random forest, and XGBoost $\textcircled { 6 }$ . For each dataset, once we decided on a particular autoencoder architecture, we used it for all models compared (i.e. VIME-self, DAE, CAE, and our model). We tried both ReLU and leakyReLU as activation functions for all, and both performed equally well. The code for SubTab is provided1. The summary of model architectures and hyperparameters are in Table $\boxed { \mathbf { A } 1 }$ in the Appendix. We should note that we ran more experiments using; i) Synthetic datasets and ii) OpenML-CC18 datasets $\lVert \rVert$ in Appendix G and H respectively.
# 3.1 Data
MNIST: We flattened $2 8 \mathbf { x } 2 8$ images, and scaled them by dividing all with 255 as it is done in [46]. We split training set into training and validation sets $( 9 0 - 1 0 \%$ split) when searching for hyper-parameters, and then used all of training set to train the final model. The test set is used only for final evaluation.
The Cancer Genome Atlas (TCGA): TCGA is a public cancer genomics dataset characterized over 20,000 primary cancer and matched normal samples that holds information over 38 cohorts. The task is to classify the cancer cohorts from the reverse phase protein array (RPPA) dataset. It includes 6671 samples with 122 features, which we divided to $8 0 { - } 1 0 { - } 1 0 \%$ train-validation-test sets. Once hyper-parameters is found, we trained the models on combined training and validation set.
Obesity: The dataset consists of publicly available human gut metagen-omic samples of obesity cohorts $\textcircled { 1 3 6 }$ . It is derived from whole-genome shotgun metagenomic studies. The dataset consists of 164 obese patients and 89 non-obese controls and has 425 features $\pmb { \left. 2 6 \right. }$ . We scaled the dataset by using min-max scaling. Since it is a small dataset, we evaluated the model by using 10 randomly drawn training-test $( 9 0 - 1 0 \% )$ splits, for each of which we used 10-fold cross-validation.
UCI Adult Income: It is a well-known public dataset extracted from the 1994 Census database $\pm$ It includes the details such as education level and demographics to predict whether the income of a person exceeds $\$ 508$ /yr. The data consists of six continuous and eight categorical features. After one-hot encoding of categorical features, there are total of 101 features. The pre-processing steps can be found in Section B.1 of Appendix.
UCI BlogFeedback: The data originates from blog posts, and is originally used for regression task of predicting the number of comments in the upcoming 24 hours. Similar to Yoon et al. $\check { \left| 4 6 \right| }$ , we turned it into a binary classification task of predicting whether there is a comment for a post or not.There are 280 integer and real valued features, and separate training and test datasets are provided. Further information can be found in Section B.2 of Appendix.
# 3.2 Evaluation
For self-supervised models, once the models are trained, we evaluate them by training a logistic regression model on the latent representations of training set, and testing it on the latent representation of the test set. For SubTab, the joint latent representation is obtained by using the mean aggregation of embeddings of the subsets for both training and test sets. We use the performance on a classification task as a measure of quality of the representation as it is usually done in the self-supervised learning. MNIST has 10, TCGA has 38, and the rest (i.e. Obesity, Income, and Blog) has 2 classes each.
# 3.3 Results
MNIST: We used a simple three-layer encoder architecture with dimensions of [512, 256, 128], referred as the base model, in which the last layer is a linear layer. During training of the base model, we used both reconstruction and contrastive losses. Additionally, we trained our model under three conditions: i) without any noise in the input data, ii) with noise in the input data and iii) same as (ii), but we also added distance loss computed for pairs of projections $\{ z _ { i } , z _ { j } , \ldots \}$ .
 Figure 3: a) Test accuracy on MNIST dataset over different number of subsets and varying levels of overlaps. b-c) t-SNE plots for training (b) and test (c) sets of MNIST for the case of using 4 subsets with $7 5 \%$ overlap between neighboring subsets.
 Figure 4: a) After training the base model (latent dimension ${ \boldsymbol { \mathbf { \rho } } } = 1 2 8$ ) on four subsets with $7 5 \%$ overlap, we test its performance using different number of subsets. The performance improves as we start increasing number of subsets involved in prediction. b) Comparing our model to CNN-based SOTA models trained on $2 8 \mathbf { x } 2 8$ MNIST in image format (please see Section 3.4 for details).
For SubTab, we trained our base model multiple times without noise at the input. For each training, we used different number of subsets with different levels of overlap between neighbouring subsets (Figure $\textcircled { 3 } \textcircled { \mu }$ . For small number of subsets (e.g. 2 or 3), the performance monotonically decreases when we increase the overlap between subsets. But, for higher number of subsets, the performance generally improves as we increase the number of shared features between the neighbouring subsets. In general, our results show that $K = 4$ with $7 5 \%$ overlap, and $K = 7$ with $50 \%$ overlap perform the best in MNIST dataset, where $K$ refers to the number of subsets. Figure $^ 3$ also shows t-SNE plots of training and test sets for $\mathrm { K } = 4$ with $7 5 \%$ overlap, which proves the high quality of clustering, while Table $\perp$ summarizes the classification accuracy of all models on the test set. Our base model without noise outperforms autoencoder baselines and other self-supervised models with the same architecture. We experimented with three noise types for all self-supervised models, and observed that adding swap-noise at the input pushes the performance higher. For SubTab, adding distance loss and increasing the dimensions of the last layer from 128 to 512 help improve the performance even further. Moreover, we conducted three additional experiments (details in Section $\dot { \mathbf { C } } . 3$ of Appendix):
In the first experiment, for the optimum case of $K = 4$ with $7 5 \%$ overlap, we trained and tested accuracy of a linear model by using the joint representations obtained from the varying number of subsets. Starting with a single subset of the data, we plot the training and test accuracy of the model (Figure $^ { 4 \mathrm { { a } } ) }$ . The linear model is able to achieve $8 7 . 5 \%$ test accuracy using the representation of a single subset. As we start adding latent representations of remaining subsets, both the training and test accuracy keep increasing, eventually achieving top accuracy when all subsets are used. The evolution of clusters corresponding to Figure $\textcircled { 4 } \textcircled { \scriptsize { \tt d } }$ can be seen in Figure $\mathbf { A } 7$ in Appendix. This experiment indicates that we can achieve a good performance using only small subset of features when we don’t have access to data on other features.
 Figure 5: a) The test accuracy using the mean aggregation of the latent representations of subsets, starting with the first subset, and keep adding new subsets sequentially. b) The test accuracy of individual subsets. c) Comparing the test accuracy by aggregating the representations of different set of subsets at test time for two versions of the model; untrained and the one trained on all subsets.
In the second experiment, we evaluated SubTab under the condition of missing features during training (Figure $5 \mathrm { a } )$ . To do so, we first sliced the unshuffled features of MNIST to seven subsets with no overlap (the case corresponding to the legend "7" at zero overlap in Figure $3 \mathrm { a } )$ . Each subset corresponds to four rows in a $2 8 \mathbf { x } 2 8$ image, starting from top four rows (subset 1) to the bottom ones (subset 7). Then, we trained the base model on five different sets of subsets; $\{ 4 \} , \{ 4 , 5 \} , \{ 3 , 4 , 5 \} , \{ 2 , 3 , 4 , 5 , 6 \}$ , and $\{ 1 , 2 , 3 , 4 , 5 , 6 , 7 \}$ , resulting in five different trained SubTab models. Please note that we selected the sets such that we expand out from the most informative middle regions of the image (i.e. subset 4) to the least informative top and bottom areas.
In order to compare the performance of five models, we followed the following steps for each trained model: 1) We first obtained the embeddings of all seven subsets for both training and test sets; 2) We then trained and evaluated a logistic regression model by using the joint embedding of each of the following seven sets: $\{ 1 \} , \{ 1 , \bar { 2 } \} , \{ 1 , \bar { 2 , } 3 \} , . . . , \{ 1 , 2 , 3 , 4 , 5 , 6 , \bar { 7 } \}$ i.e. starting from the first subset, we kept adding new subsets sequentially to increase the information content in the sets. For example, for the set $\{ 1 , 2 , 3 \}$ , we first trained a logistic regression model by using joint embedding of subset 1, 2 and 3 from training set, and evaluated it by using the joint embedding of same subsets from test set. The joint embedding of a set is obtained by using mean aggregation of embeddings of subsets in the set. In addition to five models, we initialized a sixth SubTab model, but kept it untrained and followed the same procedure described before to use it as a baseline. The results are shown in Figure 5a.
In this experiment, we observe that even when the model is trained on a single subset (subset 4, or the blue line in Figure $\textcircled { 5 } \textcircled { \scriptsize { \mathtt { h } } }$ , aggregating the representations of all seven subsets including the subsets not used in training does improve the results. This is because the encoder is able to map samples of different classes to different points in latent space even if it is not trained on them. Since we use the mean aggregation over different views (i.e. subsets) of the same class, we can still make each class in the data distinguishable from the rest in the latent space. We also note that when the model is trained on more and more subsets, its performance keeps improving. As a baseline, we also conducted the same test using untrained model (red line in the plot), and observed similar behaviour in which the test accuracy generally improves as we use more subsets when constructing the joint latent representation. Moreover, we measured the test accuracy of individual subsets to see how informative each subset is (Figure $\textcircled { 5 } \textcircled { > }$ . The result is as expected since we kept the features unshuffled in this experiment, and know that the subsets corresponding to the mid-region of the images (i.e. subsets 3, 4, and 5) should be more informative than the ones corresponding to the top and bottom regions (i.e. subsets 1, and 7). We repeated the same experiment using 28 subsets to get a higher resolution and added the result in Figure A8 in Appendix. From this experiment; i) we see that joint representation improves as we include more subsets (i.e. sub-views) at training and/or test time, ii) we can identify the informative subsets of features using SubTab framework.
In the third experiment, we evaluated SubTab on handling missing features at test time. Specifically, we used the model trained on all subsets, and compared it to the untrained model (i.e. our baseline). For each model, we obtained the joint embedding for training set by using mean aggregation over embeddings of all seven subsets, and then trained a linear model. The test accuracy of the linear model is measured by using; i) only subset 4, ii) aggregate of the most informative subsets {3,4,5}, iii) aggregate of {2,3,4,5,6} excluding the least informative subsets, and iv) all seven subsets of the test set (Figure 5c).
Table 1: Accuracy scores for all models for various datasets. The abbreviations in the table; NC: Neighbour columns used, RF: Random features used, G: Gaussian noise used, S: Swap noise used.
<table><tr><td>Type</td><td>Models</td><td>MNIST</td><td>Income</td><td>Blog</td><td>Obesity</td><td>TCGA</td></tr><tr><td rowspan="3">Supervised baseline</td><td>Logistic Regression</td><td>92.60±0.03</td><td>84.68±0.05</td><td>84.15±0.12</td><td>62.35±4.02</td><td>36.98± 1.25</td></tr><tr><td>Random Forest</td><td>96.96±0.06</td><td>84.62±0.07</td><td>83.61±0.15</td><td>67.45±2.23</td><td>61.62± 1.02</td></tr><tr><td>XGBoost</td><td>98.02±0.086</td><td>86.11±0.20</td><td>84.29±0.23</td><td>64.05±4.52</td><td>72.61±1.31</td></tr><tr><td rowspan="2">Autoencoder baseline</td><td>AE</td><td>92.77±0.32</td><td>84.67±0.07</td><td>84.06±0.24</td><td>61.96±3.28</td><td>55.16±0.75</td></tr><tr><td>AE w/Dropout (p=0.2)</td><td>94.31±0.28</td><td>85.00±0.10</td><td>84.18±0.20</td><td>62.74±4.38</td><td>56.87±2.26</td></tr><tr><td rowspan="9">Self- supervised</td><td>DAE (RF)</td><td>96.30±0.14 (S)</td><td>84.37±0.36 (G)</td><td>84.12±0.29 (G)</td><td>56.43±5.79 (G)</td><td>54.31±1.39 (G)</td></tr><tr><td>CAE (NC)</td><td>96.39±0.20 (S)</td><td>84.24±0.18 (G)</td><td>84.3±0.31 (G)</td><td>62.26±5.01 (G)</td><td>54.20±1.17(G)</td></tr><tr><td>VIME-self</td><td>95.23±0.17 (S)</td><td>84.43±0.08 (G)</td><td>84.11±0.27(G)</td><td>66.45±4.54(G)</td><td>55.11±1.37 (G)</td></tr><tr><td>SubTabwith:</td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>Base model (No noise)</td><td>97.26±0.2</td><td>85.31±0.08</td><td>84.29±0.26</td><td>68.01±3.07</td><td>57.02±1.50</td></tr><tr><td>+Noise</td><td>97.47±0.18 (S)</td><td>85.34±0.07 (G)</td><td>84.47±0.15 (G)</td><td>71.13±4.08 (G)</td><td>58.25±1.36 (G)</td></tr><tr><td>+Distance loss</td><td>97.52±0.14 (S)</td><td>85.35±0.06(G)</td><td>84.64±0.19 (G)</td><td>69.25±4.19 (G)</td><td>58.15±1.56 (G)</td></tr><tr><td>+LatentDim=512</td><td>97.86±0.07 (S)</td><td>=</td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td>=</td><td></td></tr></table>
The results indicate that SubTab can accommodate missing features at test time, and can still perform well. This might also indicate that working with subsets can give us a way to deal with uncertainty better when there are missing features at test time. As the model collects more information in the form of more features, its prediction improves (see Figure $\textcircled { 5 } \mathrm { { c } }$ ). We can also train the model when there are missing subsets during training, and it still performs well (e.g. see legend "4", corresponding to the model trained only on subset 4, in Figure $: 5 \mathrm { a } \big )$ . Our experiments simulate a practical scenario. For example, in healthcare, we might not have access to some features in one hospital while we might have them in another. So, our method would be beneficial in this type of cases.
Overall, we can make the following observations from our experiments: i) the less informative subsets can add value to the overall representation, or at least does not harm the performance (see the aggregate over {3,4,5} versus "All" in Figure $\textcircled { 5 } \mathrm { { c } }$ , ii) untrained model can be used to analyze which subsets can be potentially more informative, iii) once a model is trained on a subset, the performance of the individual subset does not change whether it is trained together with other subsets or not (for example, compare the performance of subset 3, 4, and 5 across all models in Figure $^ { 5 | { \scriptsize 5 } ) } _ { \cdot }$ , iv) general idea behind our framework works even for untrained model, and v) we may not need to impute data in our framework since we can simply ignore them as missing subsets, which is good since imputation generally distorts data, and the results.
TCGA: We used an encoder architecture with three layers [1024, 784, 784], where the third layer is linear. For VIME-self, DAE, CAE, and our model, we experimented with three noise types (Gaussian, swap, and zero-out noise) at the different $\%$ levels of masking ratio $p$ . We observed that $p = [ 0 . 1 5 , 0 . 3 ]$ range worked well for all models. For Gaussian noise, we used a distribution with zero mean, and different levels of standard deviation $( \sigma )$ . Among all three noise types, Gaussian noise with $\sigma = 0 . 1$ worked the best for all models. Please note that VIME-self uses swap-noise in its original implementation, but swap-noise does not work well on this dataset. For SubTab, similar to MNIST, we used four subsets with $7 5 \%$ overlap. SubTab performs better than other self-supervised models with a significant margin and almost doubles the performance of logistic regression model trained on raw data as shown in Table 1.
Obesity: We used a two-layer encoder with [1024, 1024] dimensions. Second layer is a linear layer. Gaussian noise $\mathcal { N } ( 0 , 0 . 3 )$ and masking ratio $p = 0 . 2$ works well across all models. Six subsets $K = 6$ ) with $0 \%$ overlap performed the best for the SubTab. We note that this dataset has 164 obese patients out of 253 total patients. So, the baseline accuracy is $1 6 4 / 2 5 3 = 6 4 . 8 2 \%$ . Based on this fact, we can say that all models, except ours, did not perform well on this dataset. Our model with added Gaussian noise results in accuracy of $7 1 . 1 3 \pm 4 . 0 8 \%$ , which is well above all models, including supervised ones. It means that our model was able to learn useful representation from the data. We should also note that the performance of our model is much better than what Oh and Zhang $\pmb { \mathbb { B } } 6 \mathbb { I }$ reported $( 6 6 \pm 3 . 2 \% )$ even though they trained a DAE on the same data, and reported their results using a random forest, a non-linear model, on the learned representations rather than a linear model.
UCI Adult Income & BlogFeedback: For these two datasets, we used the same architecture as in Obesity. For Income dataset, the best performance is obtained using 5 subsets with $25 \%$ overlap whereas we used 7 subsets with $7 5 \%$ overlap for Blog dataset. For the base model, we only used reconstruction loss. Adding Gaussian noise to the input and distance loss to the objective improves the performance for both datasets. SubTab outperforms other self-supervised models in both datasets.
The choice of hyper-parameters and other details for all experiments can be found in Table A1 in Section C.1 of Appendix.
# 3.4 Ablation study
We conducted a comprehensive ablation study using MNIST. Table 2 summarizes our experiments. The first thing to note is that the performance of the our base model is already good with only reconstruction loss. Hence, we can argue that the reconstruction of original feature space from a subset of features is a very effective way of learning representation. By adding noise to the input data, we can improve the performance. In the case of MNIST, swap-noise is very effective. Also, by adding additional losses such as contrastive, and distance losses as well as increasing the dimension of representation layer from 128 to 512, we can further improve the results. Moreover, we shuffled the features of MNIST to make sure that we don’t have any gains from unintentional spatial
Table 2: Ablation study using MNIST with 4 subsets with $7 5 \%$ overlap. Abbreviations are; RL: Reconstruction Loss, CL: Contrastive Loss, DL: Distance Loss, SF: Shuffled Features, LD: Latent Dim, Agg: Aggregating embeddings.
<table><tr><td rowspan=1 colspan=1>RL</td><td rowspan=1 colspan=1>CL</td><td rowspan=1 colspan=1>Noise</td><td rowspan=1 colspan=1>DL</td><td rowspan=1 colspan=1>SF</td><td rowspan=1 colspan=1>LD</td><td rowspan=1 colspan=1>Agg</td><td rowspan=1 colspan=1>Test Accuracy</td></tr><tr><td rowspan=2 colspan=1>+1</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>-</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>128</td><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1>97.13</td></tr><tr><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1></td><td rowspan=1 colspan=1>-</td><td rowspan=1 colspan=1>-</td><td rowspan=1 colspan=1>128</td><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1>97.11</td></tr><tr><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1></td><td rowspan=1 colspan=1>-</td><td rowspan=1 colspan=1>-</td><td rowspan=1 colspan=1>128</td><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1>97.26</td></tr><tr><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1>Zero-out</td><td rowspan=1 colspan=1>-</td><td rowspan=1 colspan=1>=</td><td rowspan=1 colspan=1>128</td><td rowspan=1 colspan=1>+</td><td rowspan=3 colspan=1>97.2597.2597.47</td></tr><tr><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1>Gaussian</td><td rowspan=1 colspan=1>-</td><td rowspan=1 colspan=1>-</td><td rowspan=1 colspan=1>128</td><td rowspan=1 colspan=1>+</td></tr><tr><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1>Swap</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>=</td><td rowspan=1 colspan=1>128</td><td rowspan=1 colspan=1>+</td></tr><tr><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1>Swap</td><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1>-</td><td rowspan=1 colspan=1>128</td><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1>97.52</td></tr><tr><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1>Swap</td><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1>128</td><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1>97.2</td></tr><tr><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1>Swap</td><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1>=</td><td rowspan=1 colspan=1>512</td><td rowspan=1 colspan=1>1</td><td rowspan=2 colspan=1>95.9297.86</td></tr><tr><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1>Swap</td><td rowspan=1 colspan=1>+</td><td rowspan=1 colspan=1>1</td><td rowspan=1 colspan=1>512</td><td rowspan=1 colspan=1>+</td></tr></table>
correlations between neighboring features. We kept all parameters and random seeds same for the comparison. As shown in the table, our model’s performance does not change much. We also tried concatenating latent variables of subsets rather than aggregating them when testing the performance. Comparing last two rows in the table, the aggregation is shown to work much better. Please note that we compared different aggregation functions in Appendix $\underline { { \overline { { \operatorname { F . 4 } } } } }$ showing that mean aggregation worked the best.
Finally, we compared the performance of SubTab on shallow and deep architecture choices. We trained and tested very shallow architectures for SubTab (referred as shallow SubTab), and compared them to relatively deeper SubTab models used in Table $^ 1$ (referred as deep SubTab). We used one-layer encoder and decoder with 784 dimension each for MNIST while using 1024 dimension for other datasets. Shallow SubTab is trained and evaluated under the same conditions as the deeper ones. As shown in Table $\textcircled { 3 }$ shallow SubTab significantly improves results in MNIST and TCGA, placing our model performance on par with CNN-based SOTA models $\pm 0 1 \big [ 1 9 \big ] \big [ 2 5 \big ] \big [ 2 2 \big ] \big [ 3 2 \big ]$ as shown in Figure 4b. Obesity is the only dataset which exploits the deeper architecture.
# 4 Related works
We refer the reader to the introduction section that lists some of the recent noticeable works in self-supervised learning. Since our work focuses on tabular data, we will review some of the recent work done in tabular data in self-supervised framework. The most recent work is mostly based on solving a pretext task. For example, Yoon et al. $\textcircled { 1 4 6 } |$ uses a de-noising autoencoder with a classifier attached to its representation layer. A random binary mask is generated to mask and overwrite a portion of entries in the tabular data, and the corrupted data is given as input to the encoder. The classifier is used to predict the mask while decoder is used to re-construct the uncorrupted original input similar to de-noising autoencoder $\boxed { 4 3 }$ . Although the proposed method is shown to work well in the experiments, there are couple drawbacks to this approach. Firstly, this approach might not work well in very high-dimensional, small and noisy data sets since the model might easily become over-parameterized and be prone to overfitting to the data. Secondly, training a classifier in this setting can be challenging since it needs to predict very high dimensional, sparse, and imbalanced binary mask, similar to the problems observed when training a model on imbalanced, binary dataset. In a similar way, TabNet [1] and TaBERT [45] also tries to recover original data from corrupted one.
Table 3: Comparing shallow and deep SubTab architectures.
<table><tr><td>Model</td><td>MNIST</td><td>Income</td><td>Blog</td><td>Obesity</td><td>TCGA</td></tr><tr><td>Deep SubTab</td><td>97.86±0.07</td><td>85.35±0.06</td><td>84.64±0.19</td><td>71.13±4.08</td><td>58.25± 1.36</td></tr><tr><td>Shallow SubTab</td><td>98.31±0.06</td><td>85.34±0.03</td><td>84.64±0.09</td><td>66.88±5.35</td><td>61.41±1.11</td></tr></table>
# 5 Conclusion
In this work, we show that a simple MLP-based autoencoder trained on MNIST in tabular format can perform on par with the CNN-based SOTA models trained on MNIST images in unsupervised/selfsupervised framework. SubTab achieves SOTA in MNIST dataset in tabular setting. We also tested our approach on other commonly used tabular datasets, and proved its benefits. In SubTab, the main performance gain comes from two parts of the model: i) reconstruction of all features from the subset of features, and ii) learning the joint representation by aggregating the embeddings of the subsets.
Using subsets of features may obviate the need for data imputation during training, and allows inference using subsets of features at test time. It might open the door to distributed training of high-dimensional data since the models can be trained on different subsets of features at the same time. We can also potentially take advantage of different datasets with common features by assigning those features to same subsets (i.e. transfer learning). We should note that the subsets shared the same autoencoder in our experiments although we could use separate autoencoders for different subsets if some of the features are drastically different than the rest.
SubTab is computationally scalable when we use only reconstruction loss during training. However, using contrastive, and/or distance losses requires the combinations of projections, which makes the computational complexity quadratic during training and limits the number of subsets we can use to divide the data. In this case, computational complexity is still linear at test time since we need to compute only the aggregate of the representations of the subsets. Also, when we divide the features into subsets, we keep the location of features in each subset same throughout training and test time since neural networks are not permutation invariant. As a possible solution, we can extend our work to permutation invariant architectures by treating collection of features as a set. We also showed that SubTab framework can be used to discover most informative subsets of features with limited resolution. A hierarchical version of SubTab might be used for identifying individual important features, but we leave it as a future work.
Finally, although the primary focus of this work is tabular data setting, SubTab can be extended to other domains such as images, audio, text and so on. We leave the extensions and applications of SubTab as a future work.
# 6 Broader Impact
Tabular data is a commonly used format in healthcare, finance, law and many other fields. Despite its broad usage, the most of the research in deep learning, especially with regards to unsupervised representation learning, has been on other data types such as images, text and audio. Our paper tries to close this gap by introducing a new framework to learn good representations from tabular data in unsupervised/self-supervised setting. The progress in this line of research will open doors to widespread applications of tabular data in other areas such as transfer learning, distributed learning, and multi-view learning, in which we can combine knowledge such as demographics and genomics from tabular data with those in images, text and audio. However, we should be aware of the shortcomings of such data integration in terms of biases and privacy issues that it might introduce.
# 7 Acknowledgements
We thank the anonymous reviewers for their helpful and constructive feedback on the paper. We would also like to thank the entire Respiratory and Immunology AI team and are grateful for general support from other organizations within AstraZeneca.
# References
[1] Sercan O Arik and Tomas Pfister. Tabnet: Attentive interpretable tabular learning. arXiv preprint arXiv:1908.07442, 2019.
[2] Bernd Bischl, Giuseppe Casalicchio, Matthias Feurer, Frank Hutter, Michel Lang, Rafael G Mantovani, Jan N van Rijn, and Joaquin Vanschoren. Openml benchmarking suites. arXiv preprint arXiv:1708.03731, 2017.
[3] James P Bridge, Sean B Holden, and Lawrence C Paulson. Machine learning for first-order theorem proving. Journal of automated reasoning, 53(2):141–172, 2014.
[4] Krisztian Buza. Feedback prediction for blogs. In Data analysis, machine learning and knowledge discovery, pages 145–152. Springer, 2014.
[5] Mathilde Caron, Ishan Misra, Julien Mairal, Priya Goyal, Piotr Bojanowski, and Armand Joulin. Unsupervised learning of visual features by contrasting cluster assignments. arXiv preprint arXiv:2006.09882, 2020.
[6] Tianqi Chen and Carlos Guestrin. XGBoost: A scalable tree boosting system. In Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, KDD ’16, pages 785–794, New York, NY, USA, 2016. ACM. ISBN 978-1-4503-4232-2. doi: 10.1145/2939672.2939785. URL http://doi.acm.org/10.1145/2939672.2939785.
[7] Ting Chen, Simon Kornblith, Mohammad Norouzi, and Geoffrey Hinton. A simple framework for contrastive learning of visual representations. In International conference on machine learning, pages 1597–1607. PMLR, 2020.
[8] Xinlei Chen, Haoqi Fan, Ross Girshick, and Kaiming He. Improved baselines with momentum contrastive learning. arXiv preprint arXiv:2003.04297, 2020.
[9] Ronan Collobert and Jason Weston. A unified architecture for natural language processing: Deep neural networks with multitask learning. In Proceedings of the 25th international conference on Machine learning, pages 160–167, 2008.
[10] Alexis Conneau, Kartikay Khandelwal, Naman Goyal, Vishrav Chaudhary, Guillaume Wenzek, Francisco Guzmán, Edouard Grave, Myle Ott, Luke Zettlemoyer, and Veselin Stoyanov. Unsupervised cross-lingual representation learning at scale. arXiv preprint arXiv:1911.02116, 2019.
[11] Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. Bert: Pre-training of deep bidirectional transformers for language understanding. arXiv preprint arXiv:1810.04805, 2018.
[12] Dheeru Dua and Casey Graff. UCI machine learning repository, 2017. URL http://archive. ics.uci.edu/ml.
[13] William Falcon and Kyunghyun Cho. A framework for contrastive self-supervised learning and designing a new approach. arXiv preprint arXiv:2009.00104, 2020.
[14] Ananda L Freire, Guilherme A Barreto, Marcus Veloso, and Antonio T Varela. Short-term memory mechanisms in neural network learning of robot navigation tasks: A case study. In 2009 6th Latin American Robotics Symposium (LARS 2009), pages 1–6. IEEE, 2009.
[15] Jean-Bastien Grill, Florian Strub, Florent Altché, Corentin Tallec, Pierre H Richemond, Elena Buchatskaya, Carl Doersch, Bernardo Avila Pires, Zhaohan Daniel Guo, Mohammad Gheshlaghi Azar, et al. Bootstrap your own latent: A new approach to self-supervised learning. arXiv preprint arXiv:2006.07733, 2020.
[16] Michael Harries and New South Wales. Splice-2 comparative evaluation: Electricity pricing. 1999.
[17] Kaiming He, Haoqi Fan, Yuxin Wu, Saining Xie, and Ross Girshick. Momentum contrast for unsupervised visual representation learning. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pages 9729–9738, 2020.
[18] Irwin Hersey. Textures: A photographic album for artists and designers by phil brodatz. Leonardo, 1(1):91–92, 1968. [19] Weihua Hu, Takeru Miyato, Seiya Tokui, Eiichi Matsumoto, and Masashi Sugiyama. Learning discrete representations via information maximizing self-augmented training. In International Conference on Machine Learning, pages 1558–1567. PMLR, 2017. [20] Xu Ji, João F Henriques, and Andrea Vedaldi. Invariant information clustering for unsupervised image classification and segmentation. In Proceedings of the IEEE/CVF International Conference on Computer Vision, pages 9865–9874, 2019. [21] Armand Joulin, Edouard Grave, Piotr Bojanowski, and Tomas Mikolov. Bag of tricks for efficient text classification. arXiv preprint arXiv:1607.01759, 2016. [22] Lyes Khacef, Laurent Rodriguez, and Benoit Miramond. Improving self-organizing maps with unsupervised feature extraction. In International Conference on Neural Information Processing, pages 474–486. Springer, 2020. [23] Thomas N Kipf and Max Welling. Semi-supervised classification with graph convolutional networks. arXiv preprint arXiv:1609.02907, 2016. [24] Ron Kohavi. Scaling up the accuracy of naive-bayes classifiers: A decision-tree hybrid. In Kdd, volume 96, pages 202–207, 1996. [25] Adam R Kosiorek, Sara Sabour, Yee Whye Teh, and Geoffrey E Hinton. Stacked capsule autoencoders. arXiv preprint arXiv:1906.06818, 2019. [26] Emmanuelle Le Chatelier, Trine Nielsen, Junjie Qin, Edi Prifti, Falk Hildebrand, Gwen Falony, Mathieu Almeida, Manimozhiyan Arumugam, Jean-Michel Batto, Sean Kennedy, et al. Richness of human gut microbiome correlates with metabolic markers. Nature, 500(7464):541–546, 2013. [27] Yann LeCun. The mnist database of handwritten digits. http://yann. lecun. com/exdb/mnist/, 1998. [28] Yinhan Liu, Myle Ott, Naman Goyal, Jingfei Du, Mandar Joshi, Danqi Chen, Omer Levy, Mike Lewis, Luke Zettlemoyer, and Veselin Stoyanov. Roberta: A robustly optimized bert pretraining approach. arXiv preprint arXiv:1907.11692, 2019. [29] Ilya Loshchilov and Frank Hutter. Decoupled weight decay regularization. arXiv preprint arXiv:1711.05101, 2017. [30] DD Lucas, R Klein, J Tannahill, D Ivanova, S Brandon, D Domyancic, and Y Zhang. Failure analysis of parameter-induced simulation crashes in climate models. Geoscientific Model Development, 6(4):1157–1171, 2013. [31] Renata CB Madeo, Clodoaldo AM Lima, and Sarajane M Peres. Gesture unit segmentation using support vector machines: segmenting gestures from rest positions. In Proceedings of the 28th Annual ACM Symposium on Applied Computing, pages 46–52, 2013. [32] Alireza Makhzani, Jonathon Shlens, Navdeep Jaitly, Ian Goodfellow, and Brendan Frey. Adversarial autoencoders. arXiv preprint arXiv:1511.05644, 2015. [33] C Merz and PM Murphy. Pima indians diabetes dataset. UCI Repository, 1996. [34] Tomas Mikolov, Kai Chen, Greg Corrado, and Jeffrey Dean. Efficient estimation of word representations in vector space. arXiv preprint arXiv:1301.3781, 2013. [35] Michiel O Noordewier, Geoffrey G Towell, and Jude W Shavlik. Training knowledge-based neural networks to recognize genes in dna sequences. In Advances in neural information processing systems, pages 530–536, 1991. [36] Min Oh and Liqing Zhang. Deepmicro: deep representation learning for disease prediction based on microbiome data. Scientific reports, 10(1):1–9, 2020.
[37] Aaron van den Oord, Yazhe Li, and Oriol Vinyals. Representation learning with contrastive predictive coding. arXiv preprint arXiv:1807.03748, 2018.
[38] Adam Paszke, Sam Gross, Francisco Massa, Adam Lerer, James Bradbury, Gregory Chanan, Trevor Killeen, Zeming Lin, Natalia Gimelshein, Luca Antiga, Alban Desmaison, Andreas Kopf, Edward Yang, Zachary DeVito, Martin Raison, Alykhan Tejani, Sasank Chilamkurthy, Benoit Steiner, Lu Fang, Junjie Bai, and Soumith Chintala. Pytorch: An imperative style, highperformance deep learning library. In H. Wallach, H. Larochelle, A. Beygelzimer, F. d'Alché- Buc, E. Fox, and R. Garnett, editors, Advances in Neural Information Processing Systems 32, pages 8024–8035. Curran Associates, Inc., 2019. URL http://papers.neurips.cc/paper/ 9015-pytorch-an-imperative-style-high-performance-deep-learning-library pdf.
[39] Deepak Pathak, Philipp Krahenbuhl, Jeff Donahue, Trevor Darrell, and Alexei A Efros. Context encoders: Feature learning by inpainting. In Proceedings of the IEEE conference on computer vision and pattern recognition, pages 2536–2544, 2016.
[40] F. Pedregosa, G. Varoquaux, A. Gramfort, V. Michel, B. Thirion, O. Grisel, M. Blondel, P. Prettenhofer, R. Weiss, V. Dubourg, J. Vanderplas, A. Passos, D. Cournapeau, M. Brucher, M. Perrot, and E. Duchesnay. Scikit-learn: Machine learning in Python. Journal of Machine Learning Research, 12:2825–2830, 2011.
[41] Jeffrey Pennington, Richard Socher, and Christopher D Manning. Glove: Global vectors for word representation. In Proceedings of the 2014 conference on empirical methods in natural language processing (EMNLP), pages 1532–1543, 2014.
[42] Katarzyna Tomczak, Patrycja Czerwinska, and Maciej Wiznerowicz. The cancer genome atlas ´ (tcga): an immeasurable source of knowledge. Contemporary oncology, 19(1A):A68, 2015.
[43] Pascal Vincent, Hugo Larochelle, Yoshua Bengio, and Pierre-Antoine Manzagol. Extracting and composing robust features with denoising autoencoders. In Proceedings of the 25th international conference on Machine learning, pages 1096–1103, 2008.
[44] I-Cheng Yeh, King-Jang Yang, and Tao-Ming Ting. Knowledge discovery on rfm model using bernoulli sequence. Expert Systems with Applications, 36(3):5866–5871, 2009.
[45] Pengcheng Yin, Graham Neubig, Wen-tau Yih, and Sebastian Riedel. Tabert: Pretraining for joint understanding of textual and tabular data. arXiv preprint arXiv:2005.08314, 2020.
[46] Jinsung Yoon, Yao Zhang, James Jordon, and Mihaela van der Schaar. Vime: Extending the success of self-and semi-supervised learning to tabular domain. Advances in Neural Information Processing Systems, 33, 2020.
[47] Kun Zhang and Wei Fan. Forecasting skewed biased stochastic ozone days: analyses, solutions and beyond. Knowledge and Information Systems, 14(3):299–326, 2008.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539# LLEMMA: AN OPEN LANGUAGE MODEL FOR MATHEMATICS
Zhangir Azerbayev 1,2 Hailey Schoelkopf 2 Keiran Paster 3,4 Marco Dos Santos 5 Stephen McAleer 6 Albert Q. Jiang 5 Jia Deng 1 Stella Biderman 2 Sean Welleck 6,7
1 Princeton University 2 EleutherAI 3 University of Toronto 4 Vector Institute 5 University of Cambridge 6 Carnegie Mellon University 7 University of Washington
# ABSTRACT
We present LLEMMA, a large language model for mathematics. We continue pretraining Code Llama on Proof-Pile-2, a mixture of scientific papers, web data containing mathematics, and mathematical code, yielding LLEMMA. On the MATH benchmark LLEMMA outperforms all known open base models, as well as the unreleased Minerva model suite on an equi-parameter basis. Moreover, LLEMMA is capable of tool use and formal theorem proving without any further finetuning. We openly release all artifacts, including 7 billion and 34 billion parameter models, the Proof-Pile-2, and code to replicate our experiments.1
# 1 INTRODUCTION
Language models trained on diverse mixtures of text display remarkably general language understanding and generation capabilities (Brown et al., 2020; Chowdhery et al., 2022), serving as base models that are adapted to a wide range of applications (Raffel et al., 2023). Applications such as open-ended dialogue (Thoppilan et al., 2022; Touvron et al., 2023) or instruction following (Ouyang et al., 2022; Wei et al., 2022) require balanced performance across the entire distribution of natural text, thus favoring generalist models. However, if we seek to maximize performance within one domain, such as medicine (Singhal et al., 2022; 2023), finance (Wu et al., 2023), or science (Taylor et al., 2022), a domain-specific language model may offer superior capabilities for a given computational cost, or lower computational cost for a given level of capability.
In this work, we train a domain-specific language model for mathematics. We have several motivations for doing so. First, solving mathematical problems requires pattern matching against a large body of specialized prior knowledge, thus serving as an ideal setting for domain adaptation. Second, mathematical reasoning is in itself a central AI task, its study dating back to at least Gelernter (1959) and Wang (1960) and continuing to today (Lu et al., 2023). Third, language models capable of strong mathematical reasoning are upstream of a number of research topics, such as reward modeling (Uesato et al., 2022; Lightman et al., 2023), reinforcement learning for reasoning (Polu et al., 2022; Lample et al., 2022), and algorithmic reasoning (Zhou et al., 2022; Zhang et al., 2023).
 Figure 1: Continued pretraining on ProofPile-2 yields LLEMMA, a base model with improved mathematical capabilities.
Although domain-specific models for mathematics have been trained in the past, they have either been closed access (Lewkowycz et al., 2022), limiting their ability to become a platform for further research, or have lagged far behind the closed access state-of-the-art (Azerbayev et al., 2023).
We present a recipe for adapting a language model to mathematics through continued pretraining (Lewkowycz et al., 2022; Rozière et al., 2023) on Proof-Pile-2, a diverse mixture of math-related text and code. Applying the recipe to Code Llama (Rozière et al., 2023) yields LLEMMA: 7 billion and 34 billion parameter base language models with substantially improved mathematical capabilities.
Specifically, our contributions are as follows:
1. We train and release the LLEMMA models: 7B and 34B parameter language models specialized for mathematics. The LLEMMA models are a new state-of-the-art for publicly released base models on MATH (Lewkowycz et al., 2022). 2. We release the AlgebraicStack, a dataset of 11B tokens of code specifically related to mathematics. 3. We demonstrate that LLEMMA is capable of using computational tools to solve mathematical problems, namely, the Python interpreter and formal theorem provers. 4. Unlike prior mathematics language models such as Minerva (Lewkowycz et al., 2022), the LLEMMA models are open access and we open source our training data and code. This allows LLEMMA to serve as a platform for future research in mathematical reasoning.
Our work builds on findings in Minerva (Lewkowycz et al., 2022), but differs in several ways: (1) LLEMMA’s training and evaluation covers a wider range of data and tasks, notably code data (e.g., the AlgebraicStack), tool use, and formal mathematics; (2) our work only depends on publicly accessible tools and data; (3) we provide new analyses related to the continued training data mixture, memorization, and additional supervised finetuning; (4) we make all artifacts publicly available.
# 2 APPROACH

LLEMMA models are 7 billion and 34 billion parameter language models specialized for mathematics. Our approach is to continue pretraining Code Llama (Rozière et al., 2023) on the Proof-Pile-2. Figure 2: Comparison of LLEMMA and Minerva training
<table><tr><td>Dataset</td><td>Tokens Open</td><td></td></tr><tr><td>Minerva Dataset</td><td>38.5B</td><td>X</td></tr><tr><td>Proof-Pile-2 (ours)</td><td>55B</td><td>√</td></tr><tr><td>Code (AlgebraicStack)</td><td>11B</td><td>√</td></tr><tr><td>OpenWebMath (Paster et al.,2023))</td><td>15B</td><td></td></tr><tr><td>ArXiv (Computer, 2023))</td><td>29B</td><td></td></tr></table>
# 2.1 DATA: Proof-Pile-2
We form the Proof-Pile-2, a 55B-token mixture of scientific papers, web data containing mathematics, and mathematical code. With the exception of the Lean proofsteps subset (see Appendix B), the Proof-Pile-2 has a knowledge cutoff of April 2023.
Code. Computational tools such as numerical simulations, computer algebra systems, and formal theorem provers are of ever increasing importance to mathematicians (Avigad, 2018). Motivated by this fact, we create AlgebraicStack, an 11B-token dataset of source code from 17 languages, spanning numerical, symbolic, and formal math. The dataset consists of filtered code from the Stack (Kocetkov et al., 2022), public GitHub repositories, and formal proofstep data. Table 9 shows the number of tokens by language in AlgebraicStack. See Appendix B.1 for further details on AlgebraicStack.
Web data. We use OpenWebMath (Paster et al., 2023), a 15B-token dataset of high-quality web pages filtered for mathematical content. OpenWebMath filters CommonCrawl web pages based on math-related keywords and a classifier-based math score, preserves mathematical formatting (e.g., LATEX, AsciiMath), and includes additional quality filters (e.g., perplexity, domain, length) and near-deduplication. Refer to Paster et al. (2023) for a full description of OpenWebMath.
Scientific papers. We use the ArXiv subset of RedPajama (Computer, 2023), an open-access reproduction of the LLaMA training dataset. The ArXiv subset contains 29B tokens.
General natural language and code data. Following Lewkowycz et al. (2022), our training mixture consists of a small amount of general domain data, which functions as a form of regularization. Since the pretraining dataset for LLaMA 2 is undisclosed, we use the Pile (Gao et al., 2020; Biderman et al., 2022) as a surrogate training dataset. We set $9 5 \%$ of our training mixture to be the Proof-Pile-2, $2 \%$ to be from the Pile (with ArXiv removed, as it is separately in Proof-Pile-2), and $3 \%$ to be the GitHub subset of RedPajama (Computer, 2023).
Further information on dataset composition and a datasheet are in Appendix B and Appendix E, respectively. We publicly release Proof-Pile-2 at hf.co/datasets/EleutherAI/proof-pile-2.
# 2.2 MODEL AND TRAINING
Each model is initialized from Code Llama (Rozière et al., 2023). Code Llama models are decoderonly transformer language models initialized from Llama 2 (Touvron et al., 2023) and further trained on 500B tokens of code. We continue training the Code Llama models on Proof-Pile-2 using a standard autoregressive language modeling objective. We train the 7B model for 200B tokens, and the 34B model for 50B tokens.
We train all models in bfloat16 mixed precision using the GPT-NeoX library (Andonian et al., 2023) across 256 A100 40GB GPUs. We use Tensor Parallelism (Shoeybi et al., 2019) with a world size of 2 for LLEMMA-7B , and a world size of 8 for LLEMMA-34B, alongside ZeRO Stage 1 sharded optimizer states (Rajbhandari et al., 2020) across Data Parallel (Goyal et al., 2017) replicas. We use Flash Attention 2 (Dao, 2023) to improve throughput and further reduce memory requirements.
LLEMMA 7B is trained for 42, 000 steps with a global batch size of 4 million tokens and a 4096 token context length. This corresponds to roughly 23, 000 A100-hours. The learning rate is warmed up to $1 \cdot 1 0 ^ { - 4 }$ over 500 steps, then set to cosine decay to $1 / 3 0 0 \mathrm { { t h } }$ of the maximum learning rate over 48, 000 steps. The reason for the discrepancy between the number of training steps and the scheduler length is that we planned to train for 48, 000 steps, but encountered NaN losses after step 42, 000, likely caused by unstable optimization or hardware failures (Elsen et al., 2023).
LLEMMA 34B is trained for 12, 000 steps with a global batch size of 4 million tokens and a 4096 context length. This corresponds to roughly 47, 000 A100-hours. The learning rate is warmed up to $5 \cdot 1 0 ^ { - 5 }$ over 500 steps, then decayed to 1/30th the peak learning rate.
Before training LLEMMA 7B, we contract the RoPE (Su et al., 2022) base period of the Code Llama 7B initialization from $\theta = 1 , 0 0 0 , 0 0 0$ to $\theta = 1 0 , 0 0 0$ . This is so that the long context finetuning procedure described in Peng et al. (2023)and Rozière et al. (2023) can be repeated on the trained LLEMMA 7B (we leave actually doing so to future work). Due to compute constraints, we were unable to verify that training LLEMMA 34B with a contracted RoPE base period did not come with a performance penalty, therefore for that model we preserved $\theta = 1 , 0 0 0 , 0 0 0$ .
# 3 EVALUATION
Our goal is to evaluate LLEMMA as a base model for mathematical text. To this end, we compare LLEMMA models using few-shot evaluation (Brown et al., 2020), and primarily focus on state-of-theart models that have not been finetuned on supervised examples for the task. First, we evaluate the model’s ability to solve mathematics problems using chain of thought reasoning (Wei et al., 2023) and majority voting (Wang et al., 2023). Our evaluations include MATH (Hendrycks et al., 2021b) and GSM8k (Cobbe et al., 2021), the de-facto standard benchmarks for evaluating quantitative reasoning in language models (Lewkowycz et al., 2022). Second, we explore few-shot tool use and formal theorem proving. Third, we study the effects of memorization and the data mixture. Appendix G contains a preliminary study of supervised finetuning with LLEMMA.
These tasks involve generating self-contained text solutions to problems expressed in $\mathrm { I A T _ { E } X }$ or natural language, without using external tools (Lewkowycz et al., 2022). We use the following evaluation:
• MATH (Hendrycks et al., 2021b), a dataset with $1 2 . 5 \mathrm { k }$ problems (5k evaluation) from high-school math competitions. Given a problem statement, the model generates a LATEXsolution and an answer that must match a reference answer. We follow a similar task implementation to Lewkowycz et al. (2022), using their four-example prompt and evaluating answers for exact string match or SymPy equivalence. • GSM8k (Cobbe et al., 2021), a dataset of middle-school level math word problems. We use the 8-shot prompt from Wei et al. (2023), as Lewkowycz et al. (2022) do not specify their evaluation prompt or number of few-shot examples. • OCWCourses (Lewkowycz et al., 2022), a collection of undergraduate-level STEM problems harvested from MIT’s OpenCourseWare. We use the four-example prompt provided by (Lewkowycz et al., 2022). • MMLU-STEM (Hendrycks et al., 2021a), a subset of 18 out of 57 subjects in the MMLU benchmark. We follow Lewkowycz et al. (2022) and use their provided four-example chain-ofthought prompt. • SAT, we create a dataset consisting of the 32 math questions that do not contain figures from the May 2023 College Board SAT examination, which is after our model’s knowledge cutoff.
# Input:
LLEMMA 34B solution: We have
$$\begin{array} { r l } { \displaystyle \sum _ { k = 2 } ^ { \infty } f ( k ) = \sum _ { k = 2 } ^ { \infty } \frac { 2 0 0 8 } { j \pi ^ { 2 } } \frac { 1 } { j ^ { k } } = \sum _ { j = 2 } ^ { 2 0 0 8 } \sum _ { k = 2 } ^ { \infty } \frac { 1 } { j ^ { k } } = \sum _ { j = 2 } ^ { 2 0 0 8 } \frac { 1 } { j ^ { 2 } } \sum _ { k = 0 } ^ { \infty } \frac { 1 } { j ^ { 3 } } = \sum _ { j = 2 } ^ { 2 0 0 8 } \frac { 1 } { j ^ { 2 } } \frac { 1 } { 1 - \frac { 1 } { j } } } & { } \\ { = \displaystyle \sum _ { j = 2 } ^ { 2 0 0 8 } \frac { 1 } { j ( j - 1 ) } = \sum _ { j = 2 } ^ { 2 0 0 8 } \left( \frac { 1 } { j - 1 } - \frac { 1 } { j } \right) } & { } \\ { = \left( \frac { 1 } { 1 } - \frac { 1 } { 2 } \right) + \left( \frac { 1 } { 2 } - \frac { 1 } { 3 } \right) + \cdots + \left( \frac { 1 } { 2 0 0 7 } - \frac { 1 } { 2 0 0 8 } \right) } & { } \\ { = 1 - \frac { 1 } { 2 0 0 8 } } & { } \\ { = \left[ \frac { 2 0 0 7 } { 2 0 0 8 } \right] } & { } \end{array}$$
Final Answer: The final answer is $\frac { 2 0 0 7 } { 2 0 0 8 }$ .
Figure 3: Example of a LLEMMA 34B solution to a MATH (Hendrycks et al., 2021a) problem. This problem is tagged with difficulty level 5, the highest in MATH. The model was conditioned on the 4-shot prompt described in subsection 3.1, and the solution was produced by greedy decoding. The model had to apply two nontrivial steps to solve this problem: (1) noticing that swapping the order of summation simplifies the problem, and (2) noticing that the resulting sum telescopes.
We compare with Minerva (Lewkowycz et al., 2022), which continued pretraining the PaLM language model on a dataset of technical content; Code Llama, the initialization of LLEMMA’s continued pretraining; and Llama 2, the initialization of Code Llama’s continued pretraining on code. For open access models, we report scores computed using our evaluation suite, which is implemented as a fork of the Language Model Evaluation Harness (Gao et al., 2021). For Minerva models, we report benchmark scores from Lewkowycz et al. (2022).
Results. LLEMMA’s continued pretraining on Proof-Pile-2 improves few-shot performance on the five mathematical benchmarks. LLEMMA 34B improves over Code Llama by 20 percentage points on GSM8k and 13 points on MATH, and LLEMMA 7B outperforms the proprietary Minerva model. Our approach also outperforms all open-weight language models at the time of writing. We conclude that continued pretraining on Proof-Pile-2 is effective for improving a pretrained model’s ability to perform mathematical problem solving.
LLEMMA is pretrained on a diverse distribution of mathematics-related data, and is not tuned for a particular task. Therefore, we expect that LLEMMA can adapt to many other tasks via task-specific finetuning and few-shot prompting.
Table 1: Results on our five chain-of-thought reasoning tasks with samples generated via greedy decoding. Minerva results are quoted from Lewkowycz et al. (2022). Note that CodeLlama 7B performs worse than random guessing $( 2 5 \% )$ on MMLU and SAT, largely due to failing to conclude its chain of thought with a valid answer.
<table><tr><td></td><td></td><td>GSM8k</td><td>OCW</td><td>MMLU-STEM</td><td>SAT</td><td>MATH</td></tr><tr><td>Llama 2</td><td>7B</td><td>11.8%</td><td>3.7%</td><td>29.9%</td><td>25.0%</td><td>3.2%</td></tr><tr><td>Code Llama</td><td>7B</td><td>10.5%</td><td>4.4%</td><td>25.1%</td><td>9.4%</td><td>4.5%</td></tr><tr><td>Minerva</td><td>8B</td><td>16.2%</td><td>7.7%</td><td>35.6%</td><td></td><td>14.1%</td></tr><tr><td>LLEMMA</td><td>7B</td><td>36.4%</td><td>7.7%</td><td>37.7%</td><td>53.1%</td><td>18.0%</td></tr><tr><td>Code Llama</td><td>34B</td><td>29.6%</td><td>7.0%</td><td>40.5%</td><td>40.6%</td><td>12.2%</td></tr><tr><td>LLEMMA</td><td>34B</td><td> 51.5%</td><td>11.8%</td><td>49.0%</td><td>71.9%</td><td>25.0%</td></tr><tr><td>Minerva</td><td>62B</td><td>52.4%</td><td>12.0%</td><td>53.9%</td><td></td><td>27.6%</td></tr><tr><td>Minerva</td><td>540B</td><td>58.8%</td><td>17.6%</td><td>63.9%</td><td>1</td><td>33.6%</td></tr></table>
Table 2: Majority voting results for LLEMMA and Minerva. Minerva results are quoted from Lewkowycz et al. (2022). Voting is done with $k = 2 5 6$ for MATH, $k = 1 0 0$ for GSM8k and OCW, and $k = 1 6$ for MMLU-STEM and SAT. We sample with temperature $T = 0 . 6$ for $k = 2 5 6$ and $k = 1 0 0$ and $T = 0 . 3$ for $k = 1 6$ , and use nucleus sampling with $p = 0 . 9 5$ (Holtzman et al., 2020). Due to compute constraints, we do not calculate majority voting scores for Llama 2 and Code Llama.
<table><tr><td></td><td></td><td>GSM8k maj@k</td><td>OCW maj@k</td><td>MMLU-STEM maj@k</td><td>SAT maj@k</td><td>MATH maj@k</td></tr><tr><td>Minerva</td><td>8B</td><td>28.4%</td><td>12.5%</td><td>43.4%</td><td></td><td>25.4%</td></tr><tr><td>LLEMMA</td><td>7B</td><td> 54.0%</td><td>14.3%</td><td>49.9%</td><td>78.1%</td><td>33.5%</td></tr><tr><td>LLEMMA</td><td>34B</td><td>69.3%</td><td>18.4%</td><td>59.7%</td><td>81.3%</td><td>43.1%</td></tr><tr><td>Minerva</td><td>62B</td><td>68.5%</td><td>23.5%</td><td>63.5%</td><td></td><td>43.4%</td></tr><tr><td>Minerva</td><td>540B</td><td>78.5%</td><td>30.8%</td><td>75.0%</td><td></td><td>50.3%</td></tr></table>
# 3.2 MATHEMATICAL PROBLEM SOLVING WITH TOOL USE
These tasks involve solving problems with access to computational tools. We evaluate the following:
• MATH+Python, the model is prompted to alternately describe a solution step in natural language, then execute that step with code. The final answer is a program that executes to a numeric type or a SymPy object. Our few-shot prompt includes examples that use built-in numeric operations, the math module, and SymPy. GSM8k $+$ Python, solving a GSM8k word problem by writing a Python program that executes to an integer answer. We use the prompt from Gao et al. (2023).
Results. As seen in Table 3, LLEMMA improves over Code Llama on both tasks. Its performance on MATH and GSM8k with tools is also higher than its performance on these datasets without tools.
Table 3: Mathematical problem solving with tool use.
<table><tr><td></td><td></td><td>GSM8k+Python pass@1</td><td>MATH+Python pass@1</td></tr><tr><td>Code Llama</td><td>7B</td><td>27.1%</td><td>17.2%</td></tr><tr><td>LLEMMA</td><td>7B</td><td>40.1%</td><td>21.5%</td></tr><tr><td>Code Llama</td><td>34B</td><td>52.7%</td><td>23.5%</td></tr><tr><td>LLEMMA</td><td>34B</td><td>62.6%</td><td>27.1%</td></tr></table>
# 3.3 FORMAL MATHEMATICS
Interactive proof assistants such as Lean (de Moura et al., 2015), Isabelle (Wenzel et al., 2008), and Coq (Paulin-Mohring, 1989a;b) express mathematics in programming languages that allow for verification. These languages are data scarce compared to mainstream languages, especially in the context of pretraining. For instance, the Stack dataset used to pretrain language models in the BigCode project (Allal et al., 2023) has over 700 gigabytes of Python, compared to 322 megabytes of Lean. Proof assistants also require models to leverage information that is not present in raw source code, such as goal states that contain information about each step of a proof.
 Figure 4: Example formal proofs from LLEMMA-7b. Left: The model is given a problem, informal proof, and formal statement, following Jiang et al. (2023). It generates a formal proof (starting with proof -) containing Isabelle code and calls to automation (shown as ${ < A T P > }$ ). Right: The model is given a proof state, visualized as a grey comment, and generates the subsequent step (e.g. rw [..).
Proof-Pile-2’s AlgebraicStack contains over 1.5 billion tokens of formal mathematics data, including proof states extracted from Lean and Isabelle formalizations. While a full investigation of formal math is outside the scope of this paper, we evaluate LLEMMA few-shot on two tasks:
• Informal-to-formal proving (Jiang et al., 2023), the task of generating a formal proof, given a formal statement, an informal LATEX statement, and an informal LATEX proof. The formal proof is checked by the proof assistant. We use the Isabelle proof assistant and evaluate on miniF2F (Zheng et al., 2021), a benchmark consisting of problem statements from Olympiads and undergraduate coursework. For the prompt, we use 11 (formal statement, informal statement, informal proof, formal proof) examples from Jiang et al. (2023), selecting 7 examples for number theory problems, and 6 examples for all others. We generate a single proof with greedy decoding.
• Formal-to-formal proving (e.g., Polu & Sutskever (2020)), the task of proving a formal statement by generating a sequence of proof steps (tactics). At each step, the input is a state $x _ { t }$ given by the proof assistant, and the language model’s task is to generate a proof step $y _ { t }$ (a sequence of code). The proof step is checked by the proof assistant, yielding a new state $x _ { t + 1 }$ or an error message. The process continues, stopping if a proof is completed or a timeout is reached. We prompt the model using three $( x _ { t } , y _ { t } )$ examples. We evaluate on miniF2F (Zheng et al., 2021) using the Lean 4 proof assistant, and use a standard best first search. See Appendix D for more details.
Results. As seen in Table 4, LLEMMA’s continued pretraining on Proof-Pile-2 improved few-shot performance on the two formal theorem proving tasks.
<table><tr><td>Method</td><td colspan="2">Informal-to-formal miniF2F-valid miniF2F-test</td></tr><tr><td>Sledgehammer</td><td>14.72%</td><td>20.49%</td></tr><tr><td>Code Llama 7b</td><td>16.31%</td><td>17.62%</td></tr><tr><td>Code Llama 34b</td><td>18.45%</td><td>18.03%</td></tr><tr><td>LLEMMA-7b</td><td>20.60%</td><td>22.13%</td></tr><tr><td>LLEMMA-34b</td><td>21.03%</td><td>21.31%</td></tr></table>
<table><tr><td>Method</td><td colspan="2">Formal-to-formal Search miniF2F-test</td></tr><tr><td>ReProver (fine-tuned)</td><td>1×64</td><td>26.50%</td></tr><tr><td>Code Llama 7b</td><td>1×32</td><td>20.49%</td></tr><tr><td>Code Llama 34b</td><td>1×32</td><td>22.13%</td></tr><tr><td>COPRA (GPT-4)</td><td></td><td>23.36%</td></tr><tr><td>LLEMMA-7b</td><td>1×32</td><td>26.23%</td></tr><tr><td>LLEMMA-34b</td><td>1×32</td><td>25.82%</td></tr></table>
Table 4: Formal theorem proving tasks. Left: Informal-to-formal proving in Isabelle, showing the percentage of proven theorems with greedy decoding. Right: Formal-to-formal proving in Lean, showing the percentage of proven theorems with the given number of attempts $\times$ generations-periteration of best first search, and a 10-minute timeout. Sledgehammer (Paulson & Nipkow, 2023) is built-in Isabelle automation. ReProver (Yang et al., 2023) is a supervised and retrieval-augmented model. COPRA (Thakur et al., 2023) is a retrieval-augmented GPT-4 based method. † COPRA does not use best first search, but instead samples from GPT-4 (OpenAI, 2023) a maximum of 60 times.
On informal-to-formal proving, LLEMMA-7b closes $2 2 . 1 \%$ of the theorems, improving upon its Code Llama initialization and the Sledgehammer prover. The theorems that LLEMMA proves are often complementary to those proved with Sledgehammer: taking the union of Sledgehammer and LLEMMA proofs results in 26 new validation proofs (an 11 percentage-point increase), and 17 new test proofs (a 7 point increase); see Appendix Table 11. Prior to our work, the only demonstration of few-shot proof autoformalization used the proprietary Codex model (Jiang et al., 2023).
On Lean 4 formal-to-formal proving, LLEMMA-7b improves upon its Code Llama initialization, and performs similar to ReProver (Yang et al., 2023), a retrieval-augmented language model finetuned for tactic prediction. LLEMMA adapts to the task using a 3 example prompt, which to our knowledge is the first demonstration of few-shot tactic prediction for theorem proving by an open model.
# 3.4 IMPACT OF DATA MIXTURE
When training a language model, it is common to upsample high-quality subsets of the training data according to mixture weights (Brown et al., 2020; Gao et al., 2020; Xie et al., 2023). We select mixture weights by doing short training runs on several hand-picked mixture weights, then choosing the one which minimizes perplexity on a set of high-quality held-out text (we use the MATH training set). Table 5 shows the MATH training set perplexity of models trained using different mixtures of arXiv to web to code. Based on these results, we trained LLEMMA with a ratio of $2 : 4 : 1$ . Note that our methodology uses the MATH training set to determine a training hyperparameter, though we expect that the effect is similar to that of related high-quality texts.
Table 5: MATH training set perplexity of Code Llama 7B models trained using different data mixtures for a reduced number of steps. Each mixture is represented by its arXiv:Web:Code ratio.
<table><tr><td>Mixture</td><td colspan="8">MATH training set perplexity</td></tr><tr><td></td><td>Overall</td><td>Prealgebra</td><td>Algebra</td><td>Numbrer</td><td>Countity</td><td>Geometry</td><td>Interedeate</td><td>Precalculus</td></tr><tr><td>2:4:1</td><td>1.478</td><td>1.495</td><td>1.515</td><td>1.552</td><td>1.475</td><td>1.519</td><td>1.439</td><td>1.331</td></tr><tr><td>2:4:2</td><td>1.482</td><td>1.500</td><td>1.519</td><td>1.556</td><td>1.477</td><td>1.524</td><td>1.443</td><td>1.334</td></tr><tr><td>4:2:1</td><td>1.487</td><td>1.505</td><td>1.524</td><td>1.561</td><td>1.481</td><td>1.534</td><td>1.447</td><td>1.338</td></tr><tr><td>4:2:2</td><td>1.489</td><td>1.508</td><td>1.527</td><td>1.562</td><td>1.483</td><td>1.538</td><td>1.447</td><td>1.339</td></tr><tr><td>4:4:1</td><td>1.487</td><td>1.506</td><td>1.525</td><td>1.561</td><td>1.482</td><td>1.529</td><td>1.446</td><td>1.335</td></tr><tr><td>4:4:2</td><td>1.485</td><td>1.503</td><td>1.523</td><td>1.559</td><td>1.480</td><td>1.529</td><td>1.444</td><td>1.334</td></tr></table>
# 3.5 DATASET OVERLAP AND MEMORIZATION
Do test problems or solutions appear in the corpus? We check whether any 30-gram in a test sequence (either an input problem or an output solution) occurs in any OpenWebMath or AlgebraicStack document. If so, we say that a hit occurred between the sequence and the document. Table 6 shows hits between sequences from MATH and documents from Proof-Pile-2. Using our methodology, around $7 \%$ of MATH test problem statements and $0 . 6 \%$ of MATH test solutions have hits. Note that our methodology gives a lower bound on the number of semantically equivalent sequences (e.g., it does not account for alternative phrasing).
We manually inspected 100 uniformly sampled hits between a test problem statement and an OpenWebMath document. 41 of the cases had no solution, which included websites with a list of problems, discussions, or hints. 49 had an alternative solution to the MATH ground-truth solution, but with the same answer. These include solutions that solve the problem differently than the ground-truth, solutions with missing details, and discussions that include the answer. 9 cases had a missing or incorrect answer, and 1 had the same solution as in the ground-truth. In summary, we find that solutions can appear in a corpus derived from web documents, particularly alternative solutions to those in the evaluation set. We repeated our analysis with 20-gram hits and our findings were similar, though with false positives; see Appendix Figure 6 for examples.
Table 6: Left: 30-gram hits between MATH test problems or solutions and Proof-Pile-2 documents. Example and Docs are the numbers of unique test examples and Proof-Pile-2 documents with a hit. Right: manual inspection of 100 hits between a problem statement and a Proof-Pile-2 document.
<table><tr><td>Proof-Pile-2</td><td>Test</td><td colspan="2"></td><td colspan="2">Example Docs Examputi Docs</td><td colspan="2">Same solution</td></tr><tr><td>OpenWebMath</td><td>MATH</td><td>348</td><td>717</td><td>34</td><td>46</td><td>Different solution, same answer</td><td>49</td></tr><tr><td>AlgebraicStack MATH</td><td></td><td>3</td><td>3</td><td>1</td><td>1</td><td>Different solution, different ans wer</td><td>9</td></tr><tr><td>OpenWebMath</td><td>GSM8k</td><td>2</td><td>3</td><td>0</td><td>0</td><td>No solution</td><td>41</td></tr><tr><td>AlgebraicStack GSM8k</td><td></td><td>0</td><td>0</td><td>0</td><td>0</td><td>Different problem</td><td>0</td></tr></table>
# How do problems in the corpus impact performance?
Next, we evaluate LLEMMA-34b on the test examples with a 30-gram hit, and the test examples without a 30- gram hit. Table 7 shows the accuracy partitioned by MATH difficulty level. The model’s accuracy remains low on difficult problems (e.g., $6 . 0 8 \%$ on Level 5 problems with a hit, versus $6 . 3 9 \%$ on problems without a hit), and we observe no clear relationship between 30-gram hits and accuracy across difficulty levels. We conclude that a nontrivial match between a test example and a training document did not imply that the model generated a memorized correct answer. We repeated the analysis with 20-grams and with the 7b model, and our findings were analogous. Figure 7 shows an example.
<table><tr><td>MATH Level</td><td>Hit Accuracy</td><td>Nonhit Accuracy</td><td>#Hits</td></tr><tr><td>Level 1</td><td>72.73</td><td>61.50</td><td>11</td></tr><tr><td>Level 2</td><td>35.71</td><td>40.18</td><td>28</td></tr><tr><td>Level 3</td><td>30.36</td><td>26.88</td><td>56</td></tr><tr><td>Level 4</td><td>14.89</td><td>16.61</td><td>94</td></tr><tr><td>Level 5</td><td>6.08</td><td>6.39</td><td>181</td></tr></table>
Table 7: LLEMMA-34b’s accuracy on hits (a 30-gram overlap between a problem or solution and a training sequence) and nonhits by MATH difficulty level.
Finally, we check 30-gram hits between LLEMMA’s MATH generations and OpenWebMath. There were 13 hits, which occurred when the model generated a common sequence of numbers (e.g., a list of Fibonacci numbers), plus one instance of factoring a polynomial. Appendix Figure 6 shows an example. We find all of these observations worthy of further study. Using LLEMMA and Proof-Pile-2 to better understand data, memorization, and performance is an interesting future direction. We include the code for our analysis in the LLEMMA repository.
# 4 RELATED WORK
Large-scale language modeling. Recent progress in large language models involves two connected threads: the increasing scale of models and data (Hoffmann et al., 2022; Kaplan et al., 2020; Chowdhery et al., 2022), and a progression toward more generalist models (Radford et al., 2019; Brown et al., 2020) which are capable of solving diverse problems and adapting quickly to novel tasks. A third thread relates to enabling open access to language models with these capabilities (Black et al., 2022; Biderman et al., 2023; Touvron et al., 2023; Rozière et al., 2023). Our work provides a recipe for specializing these language models to the domain of mathematics, providing a platform for further research and applications.
Domain adaptation. Language model applications typically require a general-domain pretraining step, followed by a shorter fine-tuning step. The finetuning step is often aimed at imbuing instructionfollowing ability (Sanh et al., 2022; Wei et al., 2022) or aligning a model’s outputs with human preferences (Ziegler et al., 2019; Ouyang et al., 2022; Bai et al., 2022). Other work explores adapting pretrained models to novel domains by continued training (Rozière et al., 2023; Beltagy et al., 2019), parameter-efficient finetuning methods (Yong et al., 2023), retrieval augmentation (Min et al., 2023; Asai et al., 2023), and other techniques. We provide an adaptation recipe involving continued training and targeted data collection.
Language models for mathematics. Applying large language models to problems in mathematics is an active subfield of machine learning, including benchmarking mathematical knowledge and reasoning at varying levels (Hendrycks et al., 2021b; Zheng et al., 2021; Welleck et al., 2022; Azerbayev et al., 2023). Although achieving strong mathematical reasoning is an important target, it is difficult to assess the correctness of models’ answers and processes, especially as models become more capable (Bowman et al., 2022; Uesato et al., 2022; Lightman et al., 2023; Cobbe et al., 2021).
A number of recent works focus on supervised finetuning on task-relevant (input, output) pairs (e.g.,Yu et al. (2023); Yue et al. (2023)). Doing so boosts performance on some common mathematical language modeling benchmarks, but trains the model for these specific tasks. In contrast, Lewkowycz et al. (2022) and our work seek to train a base language model as a platform for further development.
Language models for formal mathematics. An ongoing line of work explores integrating language models with interactive proof assistants in the context of mathematics. This includes synthesizing proofs via tactic prediction (Polu & Sutskever, 2020; Han et al., 2022; Lample et al., 2022; Jiang et al., 2022), autoformalization (Wu et al., 2022; Jiang et al., 2023), and integrated tools (Welleck & Saha, 2023). Due to high computational costs of search, language models applied to this domain have traditionally been small, but recent work has demonstrated promise in the use of larger models (First et al., 2023; Jiang et al., 2023). Our work provides a demonstration of few-shot proof autoformalization and tactic prediction, a large collection of formal mathematics data, along with an open access model for further exploring these directions.
# 5 CONCLUSION
We introduce LLEMMA and Proof-Pile-2, a novel base model and corpus for language modeling of mathematics. Our models, dataset, and code are openly available. We have shown that LLEMMA achieves state-of-the-art results for open-weights models on mathematical problem solving benchmarks, shown capabilities of using external tools via Python code, and demonstrated few-shot tactic prediction for theorem proving. We hope that LLEMMA and Proof-Pile-2 will be a useful base for future work on understanding language model generalization and dataset composition, investigating the limits of domain-specific language models, using language models as tools for mathematicians, and improving the mathematical capabilities of language models.
# ACKNOWLEDGEMENTS
We would like to thank Dragomir Radev, Arman Cohan, Jesse Michael Han, and the Deepmind Blueshift team for valuable guidance. We thank Jonah Philion for the model name. We thank Aviya Skowron for advising us on ethical considerations in the development and release of our models. We thank Jonathan Laurent and Leo Du for contributions to our open-source code.
We would also like to thank several parties for donating computing resources for this project: Stability AI (training the LLEMMA models), CoreWeave (evaluations and finetuning), the Province of Ontario and companies sponsoring the Vector Institute for Artificial Intelligence (www.vectorinstitute.ai/partners), and Brigham Young University (finetuning). KP is supported by an NSERC PGS-D award.
# REFERENCES
Loubna Ben Allal, Raymond Li, Denis Kocetkov, Chenghao Mou, Christopher Akiki, Carlos Munoz Ferrandis, Niklas Muennighoff, Mayank Mishra, Alex Gu, Manan Dey, Logesh Kumar Umapathi, Carolyn Jane Anderson, Yangtian Zi, Joel Lamy Poirier, Hailey Schoelkopf, Sergey Troshin, Dmitry Abulkhanov, Manuel Romero, Michael Lappert, Francesco De Toni, Bernardo García del Río, Qian Liu, Shamik Bose, Urvashi Bhattacharyya, Terry Yue Zhuo, Ian Yu, Paulo Villegas, Marco Zocca, Sourab Mangrulkar, David Lansky, Huu Nguyen, Danish Contractor, Luis Villa, Jia Li, Dzmitry Bahdanau, Yacine Jernite, Sean Hughes, Daniel Fried, Arjun Guha, Harm de Vries, and Leandro von Werra. Santacoder: don’t reach for the stars! In Deep Learning for Code (DL4C) Workshop, 2023. Alex Andonian, Quentin Anthony, Stella Biderman, Sid Black, Preetham Gali, Leo Gao, Eric Hallahan, Josh Levy-Kramer, Connor Leahy, Lucas Nestler, Kip Parker, Michael Pieler, Jason Phang, Shivanshu Purohit, Hailey Schoelkopf, Dashiell Stander, Tri Songz, Curt Tigges, Benjamin Thérien, Phil Wang, and Samuel Weinbach. GPT-NeoX: Large scale autoregressive language modeling in PyTorch. GitHub Repo, 9 2023. URL https://www.github.com/eleutherai/ gpt-neox. Akari Asai, Sewon Min, Zexuan Zhong, and Danqi Chen. Retrieval-based language models and applications. In Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 6: Tutorial Abstracts), pp. 41–46, Toronto, Canada, July 2023. Association for Computational Linguistics. doi: 10.18653/v1/2023.acl-tutorials.6. URL https: //aclanthology.org/2023.acl-tutorials.6. Jeremy Avigad. The mechanization of mathematics. Notices of the AMS, 65(6):681–90, 2018. Zhangir Azerbayev, Bartosz Piotrowski, Hailey Schoelkopf, Edward W. Ayers, Dragomir R. Radev, and Jeremy Avigad. Proofnet: Autoformalizing and formally proving undergraduate-level mathematics. ArXiv, abs/2302.12433, 2023. Yuntao Bai, Andy Jones, Kamal Ndousse, Amanda Askell, Anna Chen, Nova DasSarma, Dawn Drain, Stanislav Fort, Deep Ganguli, Tom Henighan, Nicholas Joseph, Saurav Kadavath, Jackson Kernion, Tom Conerly, Sheer El-Showk, Nelson Elhage, Zac Hatfield-Dodds, Danny Hernandez, Tristan Hume, Scott Johnston, Shauna Kravec, Liane Lovitt, Neel Nanda, Catherine Olsson, Dario Amodei, Tom Brown, Jack Clark, Sam McCandlish, Chris Olah, Ben Mann, and Jared Kaplan. Training a helpful and harmless assistant with reinforcement learning from human feedback. arXiv preprint arXiv:2204.05862, 2022. Iz Beltagy, Kyle Lo, and Arman Cohan. SciBERT: A pretrained language model for scientific text. 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), pp. 3615–3620, Hong Kong, China, November 2019. Association for Computational Linguistics. doi: 10.18653/v1/D19-1371. URL https://aclanthology.org/D19-1371. Stella Biderman, Hailey Schoelkopf, Quentin Gregory Anthony, Herbie Bradley, Kyle O’Brien, Eric Hallahan, Mohammad Aflah Khan, Shivanshu Purohit, USVSN Sai Prashanth, Edward Raff, et al. Pythia: A suite for analyzing large language models across training and scaling. In International Conference on Machine Learning, pp. 2397–2430. PMLR, 2023.
Stella Rose Biderman, Kieran Bicheno, and Leo Gao. Datasheet for the pile. ArXiv, abs/2201.07311, 2022.
Sidney Black, Stella Biderman, Eric Hallahan, Quentin Anthony, Leo Gao, Laurence Golding, Horace He, Connor Leahy, Kyle McDonell, Jason Phang, et al. Gpt-neox-20b: An open-source autoregressive language model. In Proceedings of BigScience Episode# 5–Workshop on Challenges & Perspectives in Creating Large Language Models, pp. 95–136, 2022. Samuel R. Bowman, Jeeyoon Hyun, Ethan Perez, Edwin Chen, Craig Pettit, Scott Heiner, Kamile˙ Lukošiut¯ e, Amanda Askell, Andy Jones, Anna Chen, Anna Goldie, Azalia Mirhoseini, Cameron ˙ McKinnon, Christopher Olah, Daniela Amodei, Dario Amodei, Dawn Drain, Dustin Li, Eli TranJohnson, Jackson Kernion, Jamie Kerr, Jared Mueller, Jeffrey Ladish, Joshua Landau, Kamal Ndousse, Liane Lovitt, Nelson Elhage, Nicholas Schiefer, Nicholas Joseph, Noemí Mercado, Nova DasSarma, Robin Larson, Sam McCandlish, Sandipan Kundu, Scott Johnston, Shauna Kravec, Sheer El Showk, Stanislav Fort, Timothy Telleen-Lawton, Tom Brown, Tom Henighan, Tristan Hume, Yuntao Bai, Zac Hatfield-Dodds, Ben Mann, and Jared Kaplan. Measuring progress on scalable oversight for large language models. arXiv preprint arXiv:2211.03540, 2022. 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, T. J. Henighan, Rewon Child, Aditya Ramesh, Daniel M. Ziegler, Jeff 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. ArXiv, abs/2005.14165, 2020. Aakanksha Chowdhery, Sharan Narang, Jacob Devlin, Maarten Bosma, Gaurav Mishra, Adam Roberts, Paul Barham, Hyung Won Chung, Charles Sutton, Sebastian Gehrmann, et al. Palm: Scaling language modeling with pathways. arXiv preprint arXiv:2204.02311, 2022. Karl Cobbe, Vineet Kosaraju, Mohammad Bavarian, Mark Chen, Heewoo Jun, Lukasz Kaiser, Matthias Plappert, Jerry Tworek, Jacob Hilton, Reiichiro Nakano, Christopher Hesse, and John Schulman. Training verifiers to solve math word problems. arXiv preprint arXiv:2110.14168, 2021. Katherine M. Collins, Albert Q. Jiang, Simon Frieder, Lionel Wong, Miri Zilka, Umang Bhatt, Thomas Lukasiewicz, Yuhuai Wu, Joshua B. Tenenbaum, William Hart, Timothy Gowers, Wenda Li, Adrian Weller, and Mateja Jamnik. Evaluating language models for mathematics through interactions. arXiv preprint arXiv:2306.01694, 2023. Together Computer. Redpajama: An open source recipe to reproduce llama training dataset, April 2023. URL https://github.com/togethercomputer/RedPajama-Data. Tri Dao. Flashattention-2: Faster attention with better parallelism and work partitioning. arXiv preprint arXiv:2307.08691, 2023. Leonardo de Moura, Soonho Kong, Jeremy Avigad, Floris Van Doorn, and Jakob von Raumer. The lean theorem prover (system description). In Automated Deduction-CADE-25: 25th International Conference on Automated Deduction, Berlin, Germany, August 1-7, 2015, Proceedings 25, pp. 378–388. Springer, 2015. Erich Elsen, Curtis Hawthorne, and Arushi Somani. The adventure of the errant hardware, 2023. URL https://www.adept.ai/blog/sherlock-sdc. Emily First, Markus N. Rabe, Talia Ringer, and Yuriy Brun. Baldur: Whole-proof generation and repair with large language models. arXiv preprint arXiv:2303.04910, 2023. Leo Gao, Stella Rose Biderman, Sid Black, Laurence Golding, Travis Hoppe, Charles Foster, Jason Phang, Horace He, Anish Thite, Noa Nabeshima, Shawn Presser, and Connor Leahy. The pile: An $8 0 0 \mathrm { g b }$ dataset of diverse text for language modeling. ArXiv, abs/2101.00027, 2020. Leo Gao, Jonathan Tow, Baber Abbasi, Stella Biderman, Sid Black, Anthony DiPofi, Charles Foster, Laurence Golding, Jeffrey Hsu, Alain Le Noac’h, Haonan Li, Kyle McDonell, Niklas Muennighoff, Jason Ociepa, Chris Phang, Laria Reynolds, Hailey Schoelkopf, Aviya Skowron, Lintang Sutawika, Eric Tang, Anish Thite, Ben Wang, Kevin Wang, and Andy Zou. A framework for few-shot language model evaluation, September 2021. URL https://doi.org/10.5281/zenodo. 5371628. Luyu Gao, Aman Madaan, Shuyan Zhou, Uri Alon, Pengfei Liu, Yiming Yang, Jamie Callan, and Graham Neubig. Pal: Program-aided language models. arXiv preprint arXiv:2211.10435, 2022. Luyu Gao, Aman Madaan, Shuyan Zhou, Uri Alon, Pengfei Liu, Yiming Yang, Jamie Callan, and Graham Neubig. Pal: Program-aided language models. arXiv preprint arXiv:2211.10435, 2023. Timnit Gebru, Jamie Morgenstern, Briana Vecchione, Jennifer Wortman Vaughan, Hanna Wallach, Hal Daumé III au2, and Kate Crawford. Datasheets for datasets, 2021. Herbert L. Gelernter. Realization of a geometry theorem proving machine. In IFIP Congress, 1959. URL https://api.semanticscholar.org/CorpusID:18484295. Priya Goyal, Piotr Dollár, Ross B. Girshick, Pieter Noordhuis, Lukasz Wesolowski, Aapo Kyrola, Andrew Tulloch, Yangqing Jia, and Kaiming He. Accurate, large minibatch SGD: training imagenet in 1 hour. CoRR, abs/1706.02677, 2017. URL http://arxiv.org/abs/1706.02677. Jesse Michael Han, Jason Rute, Yuhuai Wu, Edward Ayers, and Stanislas Polu. Proof artifact cotraining for theorem proving with language models. In International Conference on Learning Representations, 2022. URL https://openreview.net/forum?id $\underline { { \underline { { \mathbf { \Pi } } } } } =$ rpxJc9j04U. Dan Hendrycks, Collin Burns, Steven Basart, Andy Zou, Mantas Mazeika, Dawn Song, and Jacob Steinhardt. Measuring massive multitask language understanding. arXiv preprint arXiv:2009.03300, 2021a. Dan Hendrycks, Collin Burns, Saurav Kadavath, Akul Arora, Steven Basart, Eric Tang, Dawn Song, and Jacob Steinhardt. Measuring mathematical problem solving with the math dataset. NeurIPS, 2021b. Jordan Hoffmann, Sebastian Borgeaud, Arthur Mensch, Elena Buchatskaya, Trevor Cai, Eliza Rutherford, Diego de Las Casas, Lisa Anne Hendricks, Johannes Welbl, Aidan Clark, Tom Hennigan, Eric Noland, Katie Millican, George van den Driessche, Bogdan Damoc, Aurelia Guy, Simon Osindero, Karen Simonyan, Erich Elsen, Jack W. Rae, Oriol Vinyals, and L. Sifre. Training compute-optimal large language models. arXiv preprint arXiv:2203.15556, 2022. Ari Holtzman, Jan Buys, Li Du, Maxwell Forbes, and Yejin Choi. The curious case of neural text degeneration, 2020. Albert Q. Jiang, Wenda Li, Jesse Michael Han, and Yuhuai Wu. Lisa: Language models of isabelle proofs. 6th Conference on Artificial Intelligence and Theorem Proving, 2021. Albert Q. Jiang, Wenda Li, Szymon Tworkowski, Konrad Czechowski, Tomasz Odrzygó´zd´z, Piotr Miłos, Yuhuai Wu, and Mateja Jamnik. Thor: Wielding hammers to integrate language models ´ and automated theorem provers. arXiv preprint arXiv:2205.10893, 2022. Albert Qiaochu Jiang, Sean Welleck, Jin Peng Zhou, Timothee Lacroix, Jiacheng Liu, Wenda Li, Mateja Jamnik, Guillaume Lample, and Yuhuai Wu. Draft, sketch, and prove: Guiding formal theorem provers with informal proofs. In The Eleventh International Conference on Learning Representations, 2023. URL https://openreview.net/forum?id $\underline { { \underline { { \mathbf { \Pi } } } } } =$ SMa9EAovKMC. Jared Kaplan, Sam McCandlish, T. J. Henighan, Tom B. Brown, Benjamin Chess, Rewon Child, Scott Gray, Alec Radford, Jeff Wu, and Dario Amodei. Scaling laws for neural language models. arXiv preprint arXiv:2001.08361, 2020. Denis Kocetkov, Raymond Li, Loubna Ben Allal, Jia Li, Chenghao Mou, Carlos Muñoz Ferrandis, Yacine Jernite, Margaret Mitchell, Sean Hughes, Thomas Wolf, Dzmitry Bahdanau, Leandro von Werra, and Harm de Vries. The stack: 3 tb of permissively licensed source code. Preprint, 2022. Guillaume Lample, Marie-Anne Lachaux, Thibaut Lavril, Xavier Martinet, Amaury Hayat, Gabriel Ebner, Aurélien Rodriguez, and Timothée Lacroix. Hypertree proof search for neural theorem proving. arXiv preprint arXiv:2205.11491, 2022. Aitor Lewkowycz, Anders Johan Andreassen, David Dohan, Ethan Dyer, Henryk Michalewski, Vinay Venkatesh Ramasesh, Ambrose Slone, Cem Anil, Imanol Schlag, Theo Gutman-Solo, Yuhuai Wu, Behnam Neyshabur, Guy Gur-Ari, and Vedant Misra. Solving quantitative reasoning problems with language models. In Alice H. Oh, Alekh Agarwal, Danielle Belgrave, and Kyunghyun Cho (eds.), Advances in Neural Information Processing Systems, 2022. Hunter Lightman, Vineet Kosaraju, Yura Burda, Harri Edwards, Bowen Baker, Teddy Lee, Jan Leike, John Schulman, Ilya Sutskever, and Karl Cobbe. Let’s verify step by step. arXiv preprint arXiv:2305.20050, 2023. Pan Lu, Liang Qiu, Wenhao Yu, Sean Welleck, and Kai-Wei Chang. A survey of deep learning for mathematical reasoning. In Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pp. 14605–14631, Toronto, Canada, July 2023. Association for Computational Linguistics. doi: 10.18653/v1/2023.acl-long.817. URL https://aclanthology.org/2023.acl-long.817. Haipeng Luo, Qingfeng Sun, Can Xu, Pu Zhao, Jianguang Lou, Chongyang Tao, Xiubo Geng, Qingwei Lin, Shifeng Chen, and Dongmei Zhang. Wizardmath: Empowering mathematical reasoning for large language models via reinforced evol-instruct. arXiv preprint arXiv:2308.09583, 2023. The mathlib Community. The lean mathematical library. In Proceedings of the 9th ACM SIGPLAN International Conference on Certified Programs and Proofs, CPP 2020, pp. 367–381, New York, NY, USA, 2020. Association for Computing Machinery. ISBN 9781450370974. doi: 10.1145/ 3372885.3373824. URL https://doi.org/10.1145/3372885.3373824. Sewon Min, Suchin Gururangan, Eric Wallace, Hannaneh Hajishirzi, Noah A. Smith, and Luke Zettlemoyer. Silo language models: Isolating legal risk in a nonparametric datastore, 2023. Scott Morrison. lean-training-data. https://github.com/semorrison/ lean-training-data, 2023. OpenAI. Gpt-4 technical report, 2023. Long Ouyang, Jeff Wu, Xu Jiang, Diogo Almeida, Carroll L. Wainwright, Pamela Mishkin, Chong Zhang, Sandhini Agarwal, Katarina Slama, Alex Ray, John Schulman, Jacob Hilton, Fraser Kelton, Luke Miller, Maddie Simens, Amanda Askell, Peter Welinder, Paul Christiano, Jan Leike, and Ryan Lowe. Training language models to follow instructions with human feedback. arXiv preprint arXiv:2203.02155, 2022. Keiran Paster, Marco Dos Santos, Zhangir Azerbayev, and Jimmy Ba. Openwebmath: An open dataset of high-quality mathematical web text. CoRR, abs/2310.06786, 2023. doi: 10.48550/ ARXIV.2310.06786. URL https://doi.org/10.48550/arXiv.2310.06786. Christine Paulin-Mohring. Extracting $\omega$ ’s programs from proofs in the calculus of constructions. In Proceedings of the 16th ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pp. 89–104, 1989a. Christine Paulin-Mohring. Extraction de programmes dans le Calcul des Constructions. PhD thesis, Université Paris-Diderot-Paris VII, 1989b. Larry Paulson and Tobias Nipkow. The sledgehammer: Let automatic theorem provers write your isabelle scripts!, 2023. URL https://isabelle.in.tum.de/ website-Isabelle2009-1/sledgehammer.html. Bowen Peng, Jeffrey Quesnelle, Honglu Fan, and Enrico Shippole. Yarn: Efficient context window extension of large language models. arXiv preprint arXiv:2309.00071, 2023. Stanislas Polu and Ilya Sutskever. Generative language modeling for automated theorem proving. arXiv preprint arXiv:2009.03393, 2020. Stanislas Polu, Jesse Michael Han, Kunhao Zheng, Mantas Baksys, Igor Babuschkin, and Ilya Sutskever. Formal mathematics statement curriculum learning. arXiv preprint arXiv:2202.01344, 2022.
Alec Radford, Jeff Wu, Rewon Child, David Luan, Dario Amodei, and Ilya Sutskever. Language models are unsupervised multitask learners. OpenAI Blog, 2019.
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, 2023.
Samyam Rajbhandari, Jeff Rasley, Olatunji Ruwase, and Yuxiong He. ZeRO: Memory optimizations toward training trillion parameter models. In Proceedings of the International Conference for High Performance Computing, Networking, Storage and Analysis, SC ’20. IEEE Press, 2020. ISBN 9781728199986. doi: 10.5555/3433701.3433727. URL https://dl.acm.org/doi/10. 5555/3433701.3433727. Baptiste Rozière, Jonas Gehring, Fabian Gloeckle, Sten Sootla, Itai Gat, Xiaoqing Ellen Tan, Yossi Adi, Jingyu Liu, Tal Remez, Jérémy Rapin, Artyom Kozhevnikov, Ivan Evtimov, Joanna Bitton, Manish Bhatt, Cristian Canton Ferrer, Aaron Grattafiori, Wenhan Xiong, Alexandre Défossez, Jade Copet, Faisal Azhar, Hugo Touvron, Louis Martin, Nicolas Usunier, Thomas Scialom, and Gabriel Synnaeve. Code llama: Open foundation models for code. arXiv preprint arXiv:2308.12950, 2023. Victor Sanh, Albert Webson, Colin Raffel, Stephen H. Bach, Lintang Sutawika, Zaid Alyafeai, Antoine Chaffin, Arnaud Stiegler, Teven Le Scao, Arun Raja, Manan Dey, M Saiful Bari, Canwen Xu, Urmish Thakker, Shanya Sharma Sharma, Eliza Szczechla, Taewoon Kim, Gunjan Chhablani, Nihal Nayak, Debajyoti Datta, Jonathan Chang, Mike Tian-Jian Jiang, Han Wang, Matteo Manica, Sheng Shen, Zheng Xin Yong, Harshit Pandey, Rachel Bawden, Thomas Wang, Trishala Neeraj, Jos Rozen, Abheesht Sharma, Andrea Santilli, Thibault Fevry, Jason Alan Fries, Ryan Teehan, Tali Bers, Stella Biderman, Leo Gao, Thomas Wolf, and Alexander M. Rush. Multitask prompted training enables zero-shot task generalization. arXiv preprint arXiv:2110.08207, 2022. Mohammad Shoeybi, Mostofa Patwary, Raul Puri, Patrick LeGresley, Jared Casper, and Bryan Catanzaro. Megatron-LM: Training multi-billion parameter language models using model parallelism. Computing Research Repository, 2019. doi: 10.48550/arXiv.1909.08053. URL https://arxiv.org/abs/1909.08053v4. Version 4. Karan Singhal, Shekoofeh Azizi, Tao Tu, S. Sara Mahdavi, Jason Wei, Hyung Won Chung, Nathan Scales, Ajay Tanwani, Heather Cole-Lewis, Stephen Pfohl, Perry Payne, Martin Seneviratne, Paul Gamble, Chris Kelly, Nathaneal Scharli, Aakanksha Chowdhery, Philip Mansfield, Blaise Aguera y Arcas, Dale Webster, Greg S. Corrado, Yossi Matias, Katherine Chou, Juraj Gottweis, Nenad Tomasev, Yun Liu, Alvin Rajkomar, Joelle Barral, Christopher Semturs, Alan Karthikesalingam, and Vivek Natarajan. Large language models encode clinical knowledge, 2022. Karan Singhal, Tao Tu, Juraj Gottweis, Rory Sayres, Ellery Wulczyn, Le Hou, Kevin Clark, Stephen Pfohl, Heather Cole-Lewis, Darlene Neal, Mike Schaekermann, Amy Wang, Mohamed Amin, Sami Lachgar, Philip Mansfield, Sushant Prakash, Bradley Green, Ewa Dominowska, Blaise Aguera y Arcas, Nenad Tomasev, Yun Liu, Renee Wong, Christopher Semturs, S. Sara Mahdavi, Joelle Barral, Dale Webster, Greg S. Corrado, Yossi Matias, Shekoofeh Azizi, Alan Karthikesalingam, and Vivek Natarajan. Towards expert-level medical question answering with large language models, 2023. Jianlin Su, Yu Lu, Shengfeng Pan, Ahmed Murtadha, Bo Wen, and Yunfeng Liu. Roformer: Enhanced transformer with rotary position embedding. arXiv preprint arXiv:2104.09864, 2022. Ross Taylor, Marcin Kardas, Guillem Cucurull, Thomas Scialom, Anthony Hartshorn, Elvis Saravia, Andrew Poulton, Viktor Kerkez, and Robert Stojnic. Galactica: A large language model for science, 2022. Amitayush Thakur, Yeming Wen, and Swarat Chaudhuri. A language-agent approach to formal theorem-proving, 2023. 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. Lamda: Language models for dialog applications. arXiv preprint arXiv:2201.08239, 2022. Hugo Touvron, Louis Martin, Kevin Stone, Peter Albert, Amjad Almahairi, Yasmine Babaei, Nikolay Bashlykov, Soumya Batra, Prajjwal Bhargava, Shruti Bhosale, Dan Bikel, Lukas Blecher, Cristian Canton Ferrer, Moya Chen, Guillem Cucurull, David Esiobu, Jude Fernandes, Jeremy Fu, Wenyin Fu, Brian Fuller, Cynthia Gao, Vedanuj Goswami, Naman Goyal, Anthony Hartshorn, Saghar Hosseini, Rui Hou, Hakan Inan, Marcin Kardas, Viktor Kerkez, Madian Khabsa, Isabel Kloumann, Artem Korenev, Punit Singh Koura, Marie-Anne Lachaux, Thibaut Lavril, Jenya Lee, Diana Liskovich, Yinghai Lu, Yuning Mao, Xavier Martinet, Todor Mihaylov, Pushkar Mishra, Igor Molybog, Yixin Nie, Andrew Poulton, Jeremy Reizenstein, Rashi Rungta, Kalyan Saladi, Alan Schelten, Ruan Silva, Eric Michael Smith, Ranjan Subramanian, Xiaoqing Ellen Tan, Binh Tang, Ross Taylor, Adina Williams, Jian Xiang Kuan, Puxin Xu, Zheng Yan, Iliyan Zarov, Yuchen Zhang, Angela Fan, Melanie Kambadur, Sharan Narang, Aurelien Rodriguez, Robert Stojnic, Sergey Edunov, and Thomas Scialom. Llama 2: Open foundation and fine-tuned chat models. arXiv preprint arXiv:2307.09288, 2023. Jonathan Uesato, Nate Kushman, Ramana Kumar, Francis Song, Noah Siegel, Lisa Wang, Antonia Creswell, Geoffrey Irving, and Irina Higgins. Solving math word problems with process- and outcome-based feedback, 2022. H. Wang. Toward mechanical mathematics. IBM Journal of Research and Development, 4(1):2–22, 1960. doi: 10.1147/rd.41.0002. Xuezhi Wang, Jason Wei, Dale Schuurmans, Quoc V Le, Ed H. Chi, Sharan Narang, Aakanksha Chowdhery, and Denny Zhou. Self-consistency improves chain of thought reasoning in language models. In The Eleventh International Conference on Learning Representations, 2023. URL https://openreview.net/forum?id $\underline { { \underline { { \mathbf { \Pi } } } } } =$ 1PL1NIMMrw. Jason Wei, Maarten Bosma, Vincent Y. Zhao, Kelvin Guu, Adams Wei Yu, Brian Lester, Nan Du, Andrew M. Dai, and Quoc V. Le. Finetuned language models are zero-shot learners. arXiv preprint arXiv:2109.01652, 2022. Jason Wei, Xuezhi Wang, Dale Schuurmans, Maarten Bosma, Brian Ichter, Fei Xia, Ed Chi, Quoc Le, and Denny Zhou. Chain-of-thought prompting elicits reasoning in large language models, 2023. Sean Welleck. Neural theorem proving tutorial. https://github.com/wellecks/ ntptutorial, 2023. Sean Welleck and Rahul Saha. llmstep: Llm proofstep suggestions in lean. https://github. com/wellecks/llmstep, 2023. Sean Welleck, Jiacheng Liu, Ximing Lu, Hannaneh Hajishirzi, and Yejin Choi. Naturalprover: Grounded mathematical proof generation with language models. In Alice H. Oh, Alekh Agarwal, Danielle Belgrave, and Kyunghyun Cho (eds.), Advances in Neural Information Processing Systems, 2022. URL https://openreview.net/forum?id ${ . } = { }$ rhdfTOiXBng. Makarius Wenzel, Lawrence C Paulson, and Tobias Nipkow. The isabelle framework. In Theorem Proving in Higher Order Logics: 21st International Conference, TPHOLs 2008, Montreal, Canada, August 18-21, 2008. Proceedings 21, pp. 33–38. Springer, 2008. Shijie Wu, Ozan Irsoy, Steven Lu, Vadim Dabravolski, Mark Dredze, Sebastian Gehrmann, Prabhanjan Kambadur, David Rosenberg, and Gideon Mann. Bloomberggpt: A large language model for finance, 2023. Yuhuai Wu, Albert Qiaochu Jiang, Wenda Li, Markus Norman Rabe, Charles E Staats, Mateja Jamnik, and Christian Szegedy. Autoformalization with large language models. In Alice H. Oh, Alekh Agarwal, Danielle Belgrave, and Kyunghyun Cho (eds.), Advances in Neural Information Processing Systems, 2022. URL https://openreview.net/forum?id $=$ IUikebJ1Bf0. Sang Michael Xie, Hieu Pham, Xuanyi Dong, Nan Du, Hanxiao Liu, Yifeng Lu, Percy Liang, Quoc V. Le, Tengyu Ma, and Adams Wei Yu. Doremi: Optimizing data mixtures speeds up language model pretraining. arXiv preprint arXiv:2305.10429, 2023. Kaiyu Yang, Aidan Swope, Alex Gu, Rahul Chalamala, Peiyang Song, Shixing Yu, Saad Godil, Ryan Prenger, and Anima Anandkumar. LeanDojo: Theorem proving with retrieval-augmented language models. In Neural Information Processing Systems (NeurIPS), 2023. Zheng Xin Yong, Hailey Schoelkopf, Niklas Muennighoff, Alham Fikri Aji, David Ifeoluwa Adelani, Khalid Almubarak, M Saiful Bari, Lintang Sutawika, Jungo Kasai, Ahmed Baruwa, Genta Winata, Stella Biderman, Edward Raff, Dragomir Radev, and Vassilina Nikoulina. BLOOM $+ 1$ : Adding language support to BLOOM for zero-shot prompting. In Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pp. 11682–11703, Toronto, Canada, July 2023. Association for Computational Linguistics. doi: 10.18653/v1/2023. acl-long.653. URL https://aclanthology.org/2023.acl-long.653. Longhui Yu, Weisen Jiang, Han Shi, Jincheng Yu, Zhengying Liu, Yu Zhang, James T. Kwok, Zhenguo Li, Adrian Weller, and Weiyang Liu. Metamath: Bootstrap your own mathematical questions for large language models. arXiv preprint arXiv:2309.12284, 2023. Xiang Yue, Xingwei Qu, Ge Zhang, Yao Fu, Wenhao Huang, Huan Sun, Yu Su, and Wenhu Chen. Mammoth: Building math generalist models through hybrid instruction tuning. CoRR, abs/2309.05653, 2023. doi: 10.48550/arXiv.2309.05653. URL https://doi.org/10. 48550/arXiv.2309.05653. Shizhuo Dylan Zhang, Curt Tigges, Stella Biderman, Maxim Raginsky, and Talia Ringer. Can transformers learn to solve problems recursively?, 2023. Kunhao Zheng, Jesse Michael Han, and Stanislas Polu. Minif2f: a cross-system benchmark for formal olympiad-level mathematics. arXiv preprint arXiv:2109.00110, 2021. Hattie Zhou, Azade Nova, Hugo Larochelle, Aaron Courville, Behnam Neyshabur, and Hanie Sedghi. Teaching algorithmic reasoning via in-context learning, 2022. Daniel M Ziegler, Nisan Stiennon, Jeffrey Wu, Tom B Brown, Alec Radford, Dario Amodei, Paul Christiano, and Geoffrey Irving. Fine-tuning language models from human preferences. arXiv preprint arXiv:1909.08593, 2019.
# A AUTHOR CONTRIBUTIONS
Training Data. Zhangir Azerbayev, Keiran Paster, Marco Dos Santos, Sean Welleck. Model training. Zhangir Azerbayev, Hailey Schoelkopf, Keiran Paster. Evaluations. Zhangir Azerbayev, Hailey Schoelkopf, Keiran Paster, Marco Dos Santos, Stephen McAleer, Albert Q. Jiang, Sean Welleck. Formal math evaluations. Sean Welleck. Memorization analysis. Sean Welleck, Keiran Paster. Senior Authorship and Advising. Jia Deng, Stella Biderman, Sean Welleck.
B DATA: Proof-Pile-2
<table><tr><td>Data source</td><td>Tokens</td><td>Weight</td></tr><tr><td>Proof-Pile-2</td><td>55B</td><td>1</td></tr><tr><td>Code (AlgebraicStack)</td><td>11B</td><td>1.00</td></tr><tr><td>Web (OpenWebMath)</td><td>15B</td><td>4.00</td></tr><tr><td>Papers (ArXiv)</td><td>29B</td><td>2.00</td></tr><tr><td>General code (RedPajama)</td><td>59B</td><td>0.22</td></tr><tr><td>General language (Pile)</td><td>300B</td><td>0.15</td></tr></table>
Table 8: Proof-Pile-2 data sources (top), general language and code data included during training (bottom), and the mixture weights of each component during training.
# B.1 MATHEMATICAL CODE: AlgebraicStack
AlgebraicStack contains roughly 11B tokens of code related to mathematics. We describe its sources, filtering, and content below. Table 9 shows the number of tokens per language in AlgebraicStack.
<table><tr><td>Language</td><td>AlgebraicStack tokens</td><td>Language</td><td>AlgebraicStack tokens</td></tr><tr><td>Agda</td><td>35.2 M</td><td>Julia</td><td>531.0 M</td></tr><tr><td>C</td><td>25.1 M</td><td>Jupyter</td><td>199.1 M</td></tr><tr><td>C++</td><td>954.1 M</td><td>Lean</td><td>285.6 M</td></tr><tr><td>Coq</td><td>281.9 M</td><td>Maple</td><td>2.0M</td></tr><tr><td>Fortran</td><td>724.9 M</td><td>Matlab</td><td>65.8M</td></tr><tr><td>GAP</td><td>3.6 M</td><td>Python</td><td>6,098.8 M</td></tr><tr><td>Haskell</td><td>9.1 M</td><td>R</td><td>71.3 M</td></tr><tr><td>Idris</td><td>10.9 M</td><td>Tex</td><td>567.7 M</td></tr><tr><td>Isabelle</td><td>1,089.7 M</td><td>Total</td><td>10,955.7 M</td></tr></table>
Table 9: Tokens in AlgebraicStack, computed with the Llama tokenizer.
# B.1.1 GITHUB CODE
The following programming languages were either barely present in the Stack or consisted of largely incorrect filetypes, so we downloaded data for these languages directly via the Github Python API.
• Coq : We filter for files with the .v extension, and include Coq via including files that match a heuristic filter for the keywords "Theorem", "Proof", "Qed", "Inductive", "Definition", "Fixpoint" and exclude Verilog files via the keyword blacklist "pragma", "endmodule", "posedge", "negedge", "wire". We additionally exclude files noted as automatically generated.
• Isabelle : We filter for files with the .thy extension and include files matching the keyword whitelist "theorem ", "lemma We keep only isabelle-prover/mirror-afp-devel and discard all other older copies of the Archive of Formal Proofs. We further remove theorem statements and proofs that have a theorem name in the PISA (Jiang et al., 2021) test set. • Lean $:$ We filter for files with the .lean extension, using the keyword whitelist "theorem ", "lemma ", "example ". We remove all dependency files, and in order to avoid known benchmark contamination, we blacklist the ProofNet and MiniF2F repositories. We further remove theorems or lemmas that share a theorem name with the LeanDojo (Yang et al., 2023) val or test sets. • MATLAB $:$ We filter for files with the .m extension, using the keyword whitelist "#import", "interface", "implementation", "property", and blacklist C files via the keywords "#include" and the regex $\Sigma ^ { \prime }$ main\(.\*{\$’
We implemented a cutoff date for our Github API downloads, and used a cutoff date of April 1, 2023.
For all languages, unless otherwise stated, we additionally filtered out files with a filesize greater than 1048575 bytes or with a numerical density (ratio of digit characters to non-digit characters) of 0.5. We additionally perform document-level exact deduplication by removing documents which contain an overlapping 2048-character chunk as another document.
# B.1.2 LEAN PROOFSTEPS
We extract a dataset of (tactic state, next tactic) pairs from Mathlib 4 (mathlib Community, 2020) using the lean-training-data (Morrison, 2023) tool. We use Mathlib 4 commit c779bd5, which was created on August 20th 2023.
# B.1.3 ISABELLE PROOFSTEPS
We construct a dataset of Isabelle proofs, building upon the PISA dataset Jiang et al. (2021). Isabelle Proofsteps comprises proofs from the Archive of Formal Proofs and Isabelle Standard Library, scraped with PISA Jiang et al. (2021). Each entry in the dataset includes the theorem statement, the proof states and the proof steps, separated by specific tags. To maintain the integrity of evaluations using the PISA test set, we decontaminate Isabelle Proofsteps by removing theorems whose names overlap with those in the PISA test set. Although this approach results in a strict filtering – removing more than 10,000 theorems although there are only 3600 in the PISA test set – we consider it acceptable in order to mitigate data contamination. After filtering, Isabelle Proofsteps contains 251,000 theorems.
# B.1.4 STACK FILTERING
We source the following programming languages from the Stack (Kocetkov et al., 2022) dataset, and describe our filtering process and quality issues we chose to mitigate beyond our default quality heuristics:
• Agda: Only standard filters applied. • C : We include documents based on a keyword whitelist, namely: "#include <fftw.h>", "#include <fftw3.h>", "#include <rfftw.h>", "#include <gsl", "#include <cblas.h>", "#include <blas.h>", "#include <lapacke.h>", "#include <nlopt.h>", "#include <petsc.h>". • $\mathbf { C } + +$ : We include documents based on a keyword whitelist, namely: "#include <adept_arrays.h>", "#include <adept.h>", "#include <alglib>, "#include <boost", "#include <armadillo", "#include <blitz", "#include <Eigen", "#include <deal.II", "#include <dlib", "#include <NTL", "#include <mtl". • Fortran $:$ Only standard filters applied. • GAP $:$ Only standard filters applied. • Haskell : We filtered the data to only contain files with the following imports: Numeric.LinearAlgebra, Numeric.SpecFunctions, Numeric.Vector, Statistics, Data.Complex.
• Idris $:$ Only standard filters applied.
• Julia $:$ We filtered out mislabeled JSON lines files. We removed files larger than 10,000 characters long which both were not files containing tests and which had a lower numerical density than 0.5, and otherwise ignored numerical density. We additionally only accepted files within a specific keyword whitelist, to attempt to control relevance to scientific computing, namely: "LinearAlgebra", "DifferentialEquations", "Symbolics", "Distributions", "DataFrames", "DynamicalSystems", "Turing", "Gen", "JuMP", "sqrt", "abs", "zeros", "ones", "sin", "cos", "tan", "log", "exp", "integrate", "likelihood", "Matrix", $\pi$ , "pi", "rand", "grad". • Jupyter $:$ We found that many Jupyter notebook files were large due to containing long cell outputs, such as base64 images, long tracebacks, or other extra JSON cell metadata. We use nbconvert to convert notebooks to a markdown format, removing metadata. Maple $:$ We filtered out files with a size greater than 100, 000 bytes, and found that some files were XML. We filtered all files beginning with an XML declaration. • Python $:$ We filtered notebooks and JSON files out by excluding documents with beginning "{" characters, and included only files importing from a fixed list of libraries. • R : We excluded all files beginning with an XML declaration. We additionally filtered out all notebooks, and filtered all files containing MacOS "Resource Fork" files. • Tex : We used a max file size of 10,000,000 bytes. We excluded tex files found in directories named "latex/" because these were often auto-generated files, and excluded documents using gnuplot. We included only documents containing one of the keywords " \chapter{", "\chapter\*{", "\section{", "\section\*{", "\subsection{", "\subsection\*{", "\subsubsection{", "\subsubsection\*{", "\paragraph{", "\subparagraph{", and additionally only included documents identified as English by a classifier from the langid package.
For all languages we used within the Stack, unless otherwise stated, we additionally filtered out files with a filesize greater than 1048575 bytes or with a numerical density (ratio of digit characters to non-digit characters) of 0.5.
We used v1.2 of the near-deduplicated Stack as a base for processing.
# B.2 PAPERS: ARXIV
We use the entirety of ArXiv, as accessed by Computer (2023) in April 2023. For further information on preprocessing applied to ArXiv, see Computer (2023).
# B.3 WEB: OPENWEBMATH
For the web portion of our training dataset, we use OpenWebMath (Paster et al., 2023).
# C EVALUATION HARNESS
We implement a variety of math-related tasks and evaluation protocols into a public fork of the Language Model Evaluation Harness (Gao et al., 2021). The Harness provides a model-agnostic framework for standardized, reproducible evaluation of language models.
We add the following tasks for the evaluations in this paper:
• hendrycks_math_ppl: Perplexity evaluation on MATH (Hendrycks et al., 2021a) sub-tasks. • minif2f_isabelle: Proof autoformalization in Isabelle on the miniF2F benchmark based on Jiang et al. (2023), with a Portal-to-Isabelle (Jiang et al., 2021) proof checker. • minerva_math: The MATH benchmark with the prompt and Sympy evaluation from Minerva (Lewkowycz et al., 2022). • minerva-hendrycksTest: MMLU-STEM tasks following Lewkowycz et al. (2022). • ocw_courses: The OCW Courses task from Lewkowycz et al. (2022). • python_gsm8k: GSM8k with Python, based on Gao et al. (2022). • sympy_math: MATH with Sympy evaluation.
We include a link to the implementations for these tasks, including full prompts, in our public codebase.
# D EVALUATION: EXPERIMENT DETAILS
D.1 ISABELLE INFORMAL-TO-FORMAL THEOREM PROVING
We follow Jiang et al. (2023), allowing the model to issue a call to built-in Isabelle automation in the output proof by generating sledgehammer. This calls Sledgehammer (Paulson & Nipkow, 2023) and the list of heuristics listed in Jiang et al. (2023). Following Jiang et al. (2023), as a baseline we use Sledgehammer and the heuristics executed at the beginning of the proof (referred to as Sledgehammer in the main text for brevity). We use a 30-second timeout for Sledgehammer and implement proof checking via Portal-to-Isabelle (Jiang et al., 2021). Refer to the implementation in the Evaluation Harness for further details.
# D.2 LEAN THEOREM PROVING
Theorem proving via tactic prediction involves interacting with a proof assistant after each step of a proof. Implementing these interactions within the evaluation harness is outside the scope of this work. Therefore, for the Lean theorem proving task we use a separate evaluation setup based on an open-source implementation (Welleck, 2023). We include our evaluation code in our public codebase.
Setup. We evaluate on miniF2F (Zheng et al., 2021), which consists of 488 formalized statements from math competitions and undergraduate coursework. Given a formalized statement, the task is to generate a formal proof that is checked by Lean.
We use best first search, commonly used for neural tactic prediction models (e.g., Polu & Sutskever (2020)). Best first search is parameterized by the number of attempts $( \Nu )$ , generated tactics per iteration (S), and maximum iterations (T). We define the search budget to be the maximum number of generated tactics, $N \times S \times T$ . We set our search budget to $N \ = \ 1$ , $S ~ = ~ 3 2$ , and $T ~ = ~ 1 0 0$ , less than that of the baseline model. Following Yang et al. (2023), we generate tactics with beam search and use a 10 minute timeout. We adapt the proof search implementation from Welleck (2023), which uses LeanDojo v.1.1.2 (Yang et al., 2023) for interaction. We use Lean 4 miniF2F, using https://github.com/rah4927/lean-dojo-mew commit d00c776260c77de7e70125ef0cd119de6c0ff1de. Note that the ReProver baseline from (Yang et al., 2023) reports performance with Lean 3.
Prompt. We prompt the model with three (state, tactic) examples, shown in Figure 5.
"""Given the Lean 4 tactic state, suggest a next tactic.
 Figure 5: Prompt for the Lean theorem proving experiments.
# E DATASHEET
We provide a datasheet for Proof-Pile-2, following the framework in Gebru et al. (2021).
<table><tr><td colspan="2">MOTIVATION</td></tr><tr><td>For what purpose was the dataset cre- ated?</td><td>Proof-Pile-2 was created for the training or finetuning of domain-specific large lan- guage models for general mathematics</td></tr><tr><td>Who created the dataset and on behalf of which entity?</td><td>tasks. The dataset was created by the authors of this paper for the purposes of this research project.</td></tr><tr><td>Who funded the creation of the dataset?</td><td>The creation of the dataset was funded by the coauthors‘ grants and employers,as fur-</td></tr><tr><td> Any other comment?</td><td>ther described in section 5.</td></tr><tr><td colspan="2">COMPOSITION</td></tr><tr><td>What do the instances that comprise the dataset represent?</td><td>Instances are text-only documents.</td></tr><tr><td> How many instances are there in total?</td><td>We detail fine-grained token counts else- where in this paper.</td></tr><tr><td>Does the dataset contain all possible in- stances or is it a sample (not necessarily random) of instances from a larger set?</td><td>Our dataset is filtered based on our assess- ments of quality for the language modeling task. More detail on methodology can be</td></tr><tr><td>What data does each instance consist of?</td><td>found in Appendix B. Each instance is a text-only document, alongside metadata about its originating</td></tr><tr><td>Is there a label or target associated with each instance?</td><td>split and filename or location. No.</td></tr><tr><td>Is any information missing from individ- ual instances?</td><td>Yes,we filter undesired noise,such as base64-encoded images, from some doc-</td></tr><tr><td>Are relationships between individual in- stances made explicit?</td><td>uments. No.</td></tr><tr><td>Are there recommended data splits?</td><td>Yes, we release a canonical train, validation, and test split of the dataset, which we follow</td></tr><tr><td>Are there any errors, sources of noise,or redundancies in the dataset?</td><td>in this work. We make our best efforts to remove errors or sources of noise,but our dataset will naturally contain documents with errors or noise,and may contain near-duplicate doc-</td></tr><tr><td>Is the dataset self-contained, or does it link to or otherwise rely on external re- sources?</td><td>uments. The dataset is self-contained, but can also be reconstructed based on external publicly available data sources and datasets follow-</td></tr><tr><td>Does the dataset contain data that might be considered confidential?</td><td>ing our instructions. All documents in Proof-Pile-2 are publicly available online.</td></tr></table>
Does the dataset contain data that, if viewed directly, might be offensive, insulting, threatening, or might otherwise
We estimate toxic content to be less prevalent in our dataset than other more general web-based datasets, due to its technical fo
<table><tr><td>cause anxiety?</td><td>cus.However, it is likely to contain such content.</td></tr><tr><td colspan="2">COLLECTION</td></tr><tr><td>How was the data associated with each instance acquired?</td><td>Data was largely sourced from existing pub- lic subsets,such as the RedPajama dataset (Computer, 2023), OpenWebMath dataset (Paster et al., 2023),and via filtering the Stack (Kocetkov et al., 2022). Some data was collected using the Github API.</td></tr><tr><td>What mechanisms or procedures were used to collect the data?</td><td> See above.</td></tr><tr><td>If the dataset is a sample from a larger set, what was the sampling strategy?</td><td>We release the entirety of the dataset fol- lowing the application of our quality filters. We randomly held out validation and test splits from the dataset.</td></tr><tr><td>Who was involved in the data collec- tion process and how were they compen- sated?</td><td>The authors of this paper participated in lo- cating,retrieving,and filtering the dataset.</td></tr><tr><td>Over what timeframe was the data col- lected?</td><td>This data was collected in 2023,with a cut- off date of April 2023 for all subsets with the exception of our Lean proofstep data.</td></tr><tr><td>Were any ethical review processes con- ducted?</td><td>Yes, the authors conducted an informal eth- ical review internally.</td></tr><tr><td colspan="2">PREPROCESSING</td></tr><tr><td>Was any preprocessing/cleaning/labeling of the data done?</td><td>Yes,the authors extensively filtered the dataset subsets in keeping with our expec- tations for high-quality language modeling data in our domain. See Appendix B for further detail on filtering steps taken.</td></tr><tr><td>Was the“raw” data saved in addition to the preprocessed/cleaned/labeled data? Is the software that was used to prepro- cess/clean/label the data available?</td><td>Raw data can be accessed via reuse of our provided codebase. Yes. We release our codebase, which can be used to reproduce our dataset and its con- struction process,at https : //github. com/EleutherAI/math-lm.</td></tr><tr><td colspan="2">USES Has the dataset been used for any tasks</td></tr><tr><td>already?</td><td>Yes, this dataset has been used to train the LLEMMA language models as a domain adaptation and continued pretraining cor- pus.</td></tr><tr><td>Is there a repository that links to any or all papers or systems that use the dataset?</td><td>No.</td></tr><tr><td>What (other) tasks could the dataset be used for?</td><td>The dataset was specifically targeted as a high quality language modeling corpus for the mathematics domain, but may be useful for general-purpose language modeling or unforeseen other downstream uses.</td></tr></table>
Table 10: Datasheet for Proof-Pile-2, following the framework introduced by Gebru et al. (2021).
<table><tr><td>Is there anything about the composition of the dataset or the way it was col- lected and preprocessed/cleaned/labeled that might impact future uses?</td><td>We filtered the dataset with the intent of creating a model useful for mathematical tasks with solely English text.</td></tr><tr><td>Are there tasks for which the dataset should not be used?</td><td>The dataset should not be used with the intent to cause harm or for models intended for the purposes of harm.</td></tr><tr><td colspan="2">DISTRIBUTION</td></tr><tr><td>Will the dataset be distributed to third parties outside of the entity on behalf of which the dataset was created?</td><td>We make the dataset publicly available for reproducibility,analysis,and other further downstream uses.</td></tr><tr><td>How will the dataset will be distributed?</td><td>We provide code to replicate the dataset, and release it via the Huggingface Hub.</td></tr><tr><td>When will the dataset be distributed?</td><td>The dataset is available immediately.</td></tr><tr><td>Will the dataset be distributed under a copyright or other intellectual prop- erty (IP) license,and/or under applicable terms of use (ToU)?</td><td>We do not relicense the dataset's compo- nents,and do not impose our own use re- strictions.</td></tr><tr><td>Have any third parties imposed IP-based or other restrictions on the data associ- ated with the instances?</td><td>Not to our knowledge.</td></tr><tr><td>Do any export controls or other regula- tory restrictions apply to the dataset or to individual instances?</td><td>Not to our knowledge.</td></tr><tr><td>MAINTENANCE</td><td></td></tr><tr><td>Who will be supporting/hosting/main- taining the dataset?</td><td>The dataset will be hosted on the Hug- gingFace Hub and able to be recreated via code at https://github.com/ EleutherAI/math-lm. The dataset will not be updated post-release.</td></tr><tr><td>How can the owner/curator/manager of the dataset be contacted?</td><td> Via email at za2514@princeton.edu</td></tr><tr><td> Is there an erratum?</td><td>No.</td></tr><tr><td> Will the dataset be updated?</td><td>No.</td></tr><tr><td>If others want to extend/augment/build on/contribute to the dataset, is there a mechanism for them to do so?</td><td>No.</td></tr></table>
# F ADDITIONAL RESULTS
# F.1 PROOF AUTOFORMALIZATION
Table 11 shows additional results on Isabelle proof autoformalization, including the union of theorems closed by Sledgehammer and the given language model.
Table 11: Isabelle autoformalization. ∗We exclude the 11 examples used in the few-shot prompts. Pass $@ 1$ with greedy decoding.
<table><tr><td>Method</td><td>Autoformalization pass @1 miniF2F-valid*</td><td>miniF2F-test</td></tr><tr><td> Sledgehammer</td><td>14.72%</td><td>20.49%</td></tr><tr><td>Code Llama 7b</td><td>16.31%</td><td>17.62%</td></tr><tr><td>LLEMMA-7b</td><td>20.60%</td><td>22.13%</td></tr><tr><td>Code Llama 7b U Sledgehammer</td><td>20.17%</td><td>25.00%</td></tr><tr><td>LLEMMA-7b U Sledgehammer</td><td>25.97%</td><td>27.46%</td></tr></table>
# G SUPERVISED FINETUNING
A full exploration of finetuning applications for LLEMMA, such as instruction following (Ouyang et al., 2022; Wei et al., 2022), dialogue modeling (Thoppilan et al., 2022; Touvron et al., 2023; Collins et al., 2023), and reward modeling (Cobbe et al., 2021; Lightman et al., 2023) are outside the scope of this work. However, to establish that LLEMMA retains its advantage over other open models when finetuned, we conduct preliminary experiments finetuning LLEMMA-7B on MetaMathQA (Yu et al., 2023), a supervised dataset targeted at the MATH and GSM8k benchmarks. Results are shown in Table 12.
Table 12: Finetuning of various 7B base models on supervised mathematics datasets. All results with a Llama 2 initialization are copied from the literature (Luo et al., 2023; Yu et al., 2023). The LLEMMA 7B finetune is trained with identical hyperparameters to the models in Yu et al. (2023)
<table><tr><td>Initialization</td><td>Finetune Dataset</td><td>MATH</td><td>GSM8k</td></tr><tr><td>Llama 2 7B</td><td>WizardMath (Proprietary)</td><td>10.7%</td><td>54.9%</td></tr><tr><td>Llama 2 7B</td><td>MetaMathQA</td><td>19.4%</td><td>66.4%</td></tr><tr><td>LLEMMA 7B</td><td>MetaMathQA</td><td>25.2%</td><td>66.5%</td></tr><tr><td>Llama 2 70B</td><td>WizardMath (Proprietary)</td><td>22.7%</td><td>81.6%</td></tr><tr><td>Llama 2 70B</td><td>MetaMathQA</td><td>26.6%</td><td>82.3%</td></tr></table>
# H QUALITATIVE EXAMPLES
Dataset overlap. Figure 6 shows example false positives when checking $n$ -gram overlap with OpenWebMath documents for various $n$ . Figure 7 shows an example OpenWebMath document that has 30-gram overlap with a MATH problem, and LLEMMA-7b’s generated solution.
Task outputs. Figure 8 shows a generated proof in the informal2formal theorem proving task.
# OpenWebMath document
2D affine transformations can be better represented using 2 by 2 matrices, since they are simply linear combinations of 2 variables. The advantage of this is that the matrices are associative under multiplication Also, GPUs and modern toolkits are optimised to work with this representation. As a result, a scale matrix is \begin{bmatrix} s_x & 0 \\ 0 & s_y \end{bmatrix}, and a rotation matrix is \begin{bmatrix} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{bmatrix}.
A translation matrix is simply \begin{bmatrix} 1 & \frac{t_x}{y} \\ \frac{t_y}{x} & 1 ...
# MATH problem
A rotation centered at the origin takes $\binom { 1 3 } { 0 }$ to $\left( { \begin{array} { c } { 5 } \\ { - 1 2 } \end{array} } \right) .$ Which vector does the rotation take $\binom { 0 } { 1 }$ to?
#
The rotation matrix must be of the form $\left( \sin \theta \frac { \ l - \sin \theta } { \sin \theta } \right)$ . Thus,...
# Hit
\cos \theta & -\sin \theta \\ \sin \theta & \cos
# OpenWebMath document
# Basic Probability
A number is selected at random from 1 through 100, inclusive. What is the probability that the number is a divisor of 50? Express your answer as a common fraction.
Apr 24, 2019
There are a 100 integers between 1-100, inclusive. Since 50 is \$\$2\*5^2\$\$, it has \$\$(1+1) $( 1 + 2 ) = ( 2 )$ $( 3 ) = 6 5 5$ factors. Thus, the answer is \$\$\frac{6} $\{ 1 0 0 \} =$ \boxed{\frac{3}{50}}.\$\$
# MATH problem
A number is selected at random from 1 through 100, inclusive. What is the probability that the number is a perfect square?
# Hit
A number is selected at random from 1 through 100, inclusive. What is the probability that the number is a
# OpenWebMath document
Fig. 2.
Use values of the most used medicinal plants in the Safi Province (Morocco).
It is also important to note that for the abovementioned medicinal plants, many other folk uses have been reported in different regions of Morocco. Furthermore, literature-based proof revealed that these species have proven a wide variety of biological and pharmacological activities (Table 4, Ref. [14, 17, 19, 20, 21, 23, 24, 26, 28, 30, 31, 34, 35, 36, 38, 39, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116]), which may confirm the different popular applications of ...
# Generated solution (LLEMMA 7b):
The first 100 positive integers are 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, 21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49, 50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78, 79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100. We can see that...
Figure 6: Data overlap: Example false positives using 10-gram match between MATH solutions and OpenWebMath documents (top), 20-gram match between MATH problems and OpenWebMath documents (middle), and 30-gram match between LLEMMA-7b’s generated solutions and OpenWebMath documents (bottom).
# OpenWebMath document
A triangle is formed with edges along the line \$y=\frac{2}{3}x+5\$, the \$x\$-axis, and the line $\$ 123,456$ . If the area of the triangle is less than $\$ 205$ , find the sum of all possible integral values of \$k\$.
Feb 28, 2018
Look at the graph, here...two triangles are possible : https://www.desmos.com/calculator/m6wnjpgldq The height of the triangles at any point will be formed by
$$[ \begin{array} { l l l } { } & { ( 2 / 3 ) \textbf { x } + \textbf { 5 } } \end{array} ]$$
And the bases will be $[ \mathrm { ~ \bf ~ x ~ } - \mathrm { ~ \bf ~ ( ~ - ~ } 7 . 5 ) ] = [ \mathrm { ~ \bf ~ x ~ } + 7 . 5 ]$ ${ \begin{array} { r l } & { { \mathrm { S o \ldots \ldots \ldots } } { \mathrm { ~ w e ~ { \ w a n t } ~ t o ~ { \ s o \bot } v e ~ { \ t n } { \mathrm { ~ { \Sigma } } } } } } \\ & { ( 1 / 2 ) { \mathrm { ~ { \Sigma } ~ } } [ { \mathrm { ~ { \Sigma } } } ( 2 / 3 ) { \mathrm { ~ x ~ { \Sigma } ~ } } + { \mathrm { ~ { \Sigma } ~ } } 5 { \mathrm { ~ { \Sigma } ~ } } ] { \mathrm { ~ { \Sigma } ~ } } [ { \mathrm { ~ { \bf ~ x } ~ } } + { \mathrm { ~ { \Sigma } ~ } } 7 \cdot 5 { \mathrm { ~ { \Sigma } ~ } } ] = 2 0 } \\ & { [ { \mathrm { ~ { \Sigma } ~ } } ( 2 / 3 ) { \mathrm { ~ x ~ { \Sigma } ~ } } + { \mathrm { ~ { \Sigma } ~ } } 5 { \mathrm { ~ { \Sigma } ~ } } ] [ { \mathrm { ~ { \bf ~ x } ~ } } + { \mathrm { ~ { \Sigma } ~ } } 7 \cdot 5 ] = 4 0 } \\ & { ( 2 / 3 ) { \mathrm { ~ x \Sigma \mathrm { { \Sigma } } } } 2 + { \mathrm { ~ { \Sigma } } } { \mathrm { ~ { \Sigma } } } { \mathrm { ~ { \Sigma } } } + { \mathrm { ~ { \Sigma } } } { \mathrm { ~ { \Sigma } } } { \mathrm { ~ { \Sigma } } } + { \mathrm { ~ { \Sigma } } } 3 7 \ldots = 0 } \\ & { ( 2 / 3 ) { \mathrm { ~ x \widehat { \mathrm { \Sigma } } } } 2 + { \mathrm { ~ { \Sigma } ~ } } 1 0 { \bf x } - { \mathrm { ~ { \Sigma } ~ } } 2 . 5 = 0 { \mathrm { ~ { \Sigma } ~ } } 0 } \end{array} }$
Using a little technology.....the max x value for the triangle formed above the $_ \textrm { x }$ axis will be $=$ .246
And the min x value for the triangle formed below the x axis will be = -15.246
With the given boundaries, the integer sums of all possible $_ \textrm { x }$ values of k giving triangles with an area $< ~ 2 0$ units^2 $=$
[ (-15) + (-14 ) + (-13) + ...+ ( -2) + ( - 1 ) + 0 ] = (15) (16) / 2 = -120
Feb 28, 2018
MATH Problem: A triangle is formed with edges along the line $y = \textstyle { \frac { 2 } { 3 } } x + 5$ , the $x$ -axis, and the line $x = k$ . If the area of the triangle is less than 20, find the sum of all possible integral values of $k$ . Answer: -120
# Generated solution (LLEMMA $\mathbf { \Delta } ^ { 7 \mathbf { b } }$ ):
The triangle has vertices $( k , 0 )$ , $( 0 , 5 )$ , and $( k , \textstyle { \frac { 2 } { 3 } } k + 5 )$ . The base of the triangle has length $k$ , and the height of the triangle has length ${ \frac { 2 } { 3 } } k + 5$ . The area of the triangle is therefore
$$A = { \frac { 1 } { 2 } } b h = { \frac { 1 } { 2 } } k ( { \frac { 2 } { 3 } } k + 5 ) = { \frac { 1 } { 3 } } k ^ { 2 } + { \frac { 5 } { 2 } } k .$$
Since the area of the triangle is less than 20, we have
$$\frac { 1 } { 3 } k ^ { 2 } + \frac { 5 } { 2 } k < 2 0 \Rightarrow \frac { 1 } { 6 } k ^ { 2 } + \frac { 5 } { 4 } k - 1 0 < 0 .$$
This inequality is true if and only if with positive leading coefficient, it $\textstyle { \frac { 1 } { 6 } } k ^ { 2 } + { \frac { 5 } { 4 } } k - 1 0$ is positive. Since d only if its vertex $\textstyle { \frac { 1 } { 6 } } k ^ { 2 } + { \frac { 5 } { 4 } } k - 1 0$ is a quadratic The vertex of $\textstyle { \frac { 1 } { 6 } } k ^ { 2 } + { \frac { 5 } { 4 } } k - 1 0$ is $\bigl ( - { \frac { 1 0 } { 3 } } , - { \frac { 1 2 5 } { 1 8 } } \bigr )$ . Since $\begin{array} { l } { \displaystyle { - \frac { 1 0 } { 3 } < 0 } } \end{array}$ , we have that $\textstyle { \frac { 1 } { 6 } } k ^ { 2 } + { \frac { 5 } { 4 } } k - 1 0 > 0$ if and only if $k < - \frac { 1 0 } { 3 }$ . Therefore, the only possible integral values of $k$ are $k = 0 , 1 , 2 , 3 , 4$ . The sum of these values is $\boxed { 1 0 } .$ Final Answer: The final answer is 10.
Figure 7: Data overlap: Example OpenWebMath document that has a 30-gram overlap with the given MATH problem, and LLEMMA-7b’s generated solution.
 Figure 8: Informal-to-formal proving. The model is given the problem, informal proof, and formal statement, following Jiang et al. (2023). It generates a formal proof (starting with proof -) containing Isabelle code, comments $( \star \ldots \star )$ ) that align the informal and formal proofs, and calls to an automated prover (shown as ${ < A T P > }$ ). The proof is from LLEMMA-7b with greedy decoding.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378# LongLLMLingua: ACCELERATING AND ENHANCING LLMS IN LONG CONTEXT SCENARIOS VIA PROMPT COMPRESSION
Anonymous authors Paper under double-blind review
# ABSTRACT
In long context scenarios, large language models (LLMs) face three main challenges: higher computational/financial cost, longer latency, and inferior performance. Some studies reveal that the performance of LLMs depends on both the density and the position of the key information (question relevant) in the input prompt. Inspired by these findings, we propose LongLLMLingua for prompt compression towards improving LLMs’ perception of the key information to simultaneously address the three challenges. We conduct evaluation on a wide range of long context scenarios including single-/multi-document QA, few-shot learning, summarization, synthetic tasks, and code completion. Experimental results show that LongLLMLingua compressed prompt can derive higher performance with much lower cost. The latency of the end-to-end system is also reduced. For example, on NaturalQuestions benchmark, LongLLMLingua gains a performance boost of up to $1 7 . 1 \%$ over the original prompt with ${ \sim } 4 \mathbf { x }$ fewer tokens as input to GPT-3.5-Turbo. It can drive cost savings of $\$ 28.5$ and $\$ 27.4$ per 1,000 samples from the LongBench and ZeroScrolls benchmark, respectively. Additionally, when compressing prompts of ${ \sim } 1 0 \mathrm { k }$ tokens at a compression rate of $2 \mathbf { X } { - } 1 0 \mathbf { X }$ , LongLLMLingua can speed up the end-to-end latency by $1 . 4 \mathrm { X } \mathrm { - } 3 . 8 \mathrm { X }$ .
# 1 INTRODUCTION
ChatGPT and other large language models (LLMs) have revolutionized user-oriented language technologies and are serving as crucial components in more and more applications. Carefully designing prompts is necessary to achieve better performance in specific downstream tasks. The commonly used technologies such as In-Context Learning (ICL) (Dong et al., 2023), Retrieval Augment Generation (RAG) (Lewis et al., 2020), and Agent (Park et al., 2023) are driving prompts to be increasingly longer, even reaching thousands of tokens. Scenarios such as multi-document question answering, code completion, and document summarization also necessitate the processing of long contexts.
There are three main challenges when LLMs are used in long context scenarios: (1) The higher computational and financial cost required to run these models or to call APIs from companies providing LLM services. This can be a significant barrier for individuals or smaller organizations with limited resources. (2) The longer latency associated with LLMs, which can cause delays in generating responses or predictions and is particularly problematic in real-time scenarios where users expect quick and accurate responses. (3) The inferior performance caused by the extended window size of LLMs (Xiong et al., 2023), and the low density as well as the less sensitive position of the questionrelevant key information in the prompt. Figure 1a shows that LLMs’ performance in downstream tasks may decrease as the noisy information in the prompt increases (Shi et al., 2023). Moreover, the purple curve in Figure 1b indicates that LLMs’ ability to capture the relevant information depends on their positions in the prompt (Liu et al., 2023): they achieve the highest performance when relevant information occurs at the beginning or end of the input context, and significantly degrades if relevant information is located in the middle of long contexts.
Inspired by these observations, we propose LongLLMLingua to address the three challenges. Specifically, we use the advanced while efficient LLMLingua (Jiang et al., 2023a) as our backbone framework for prompt compression to address the first two challenges, i.e., reduce cost and latency. However, in the case of long contexts, the distribution of question-relevant key information in the prompt is generally sparse. Existing prompt compression methods like LLMLingua (Jiang et al., 2023a) and Selective-Context (Li, 2023) that do not consider the content of the question during compression may retain too much noisy information in the compressed results, leading to inferior performance. In this paper, LongLLMLingua is designed to enhance LLM’s perception of key information (relevant to the question) in the prompt, so that the third challenge of inferior performance in long context scenarios could be addressed. Figure 1b is an example. The underlying principle of LongLLMLingua is that small language models are inherently capable of capturing the distribution of key information relevant to a given question.
 Figure 1: (a) LLMs’ performance in downstream tasks may decrease as the noisy information in the prompt increases. In this case, we keep $k$ most relevant documents/paragraphs based on the ground truth or LongLLMLingua $r _ { k }$ . A larger $k$ implies more noise introduced into the prompt. To improve the key information density in the prompt, we present question-aware coarse-to-fine compression. (b) LLMs’ ability to capture the relevant information depends on their positions in the prompt. To reduce information loss in the middle, we introduce a document reordering mechanism.
Our main contributions are five-fold: (1) We propose a question-aware coarse-to-fine compression method to improve the key information density in the prompt (Sec. 4.1); (2) We introduce a document reordering mechanism to reduce information loss in the middle. (Sec. 4.2); (3) We present dynamic compression ratios to bridge the coarse-grained compression and fine-grained compression for adaptive granular control (Sec. 4.3); (4) We propose a post-compression subsequence recovery strategy to improve the integrity of the key information (4.4). (5) We evaluate LongLLMLingua on three benchmarks, i.e., NaturalQuestions (Liu et al., 2023), LongBench (Bai et al., 2023), and ZeroSCROLLS (Shaham et al., 2023). Experimental results demonstrate that compared with original prompts, LongLLMLingua compressed prompts can achieve higher performance with much lower costs. The latency of the end-to-end system is also reduced.
# 2 PROBLEM FORMULATION
Following LLMLingua (Jiang et al., 2023a), we use $\mathbf { x } = ( \mathbf { x } ^ { \mathrm { { i n s } } } , \mathbf { x } _ { 1 } ^ { \mathrm { { d o c } } } , \cdot \cdot \cdot , \mathbf { x } _ { K } ^ { \mathrm { { d o c } } } , \mathbf { x } ^ { \mathrm { { q u e } } } )$ to represent a prompt, which composed of the instruction $\mathbf { x } ^ { \mathrm { i n s } }$ , $K$ documents $\mathbf { x } _ { i } ^ { \mathrm { { d o c } } }$ , and the question $\mathbf { x } ^ { \mathrm { q u e } }$ . In fact, the prompt can be modified according to specific application scenarios. For example, $\mathbf { x } ^ { \mathrm { i n s } }$ at the beginning can be removed, $\mathbf { x } ^ { \mathrm { q u e } }$ can be any requirement specified by users, and $( \mathbf { x } _ { 1 } ^ { \mathrm { d o c } } , \cdot \cdot \cdot , \mathbf { x } _ { K } ^ { \mathrm { d o c } } )$ can be any additional materials that users append to the prompt to get a better response from LLMs for $\mathbf { x } ^ { \mathrm { q u e } }$ . The objective of a prompt compression system can be formulated as:
$$\operatorname* { m i n } _ { \widetilde { \mathbf { x } } } D \left( \mathbf { y } , \widetilde { \mathbf { y } } \right) + \lambda \| \widetilde { \mathbf { x } } \| _ { 0 } ,$$
where $\widetilde { \mathbf { x } }$ denotes the compressed prompt and is a token-level subsequence of $\mathbf { x }$ . $\mathbf { y }$ represents the eground-truth output texts with $\mathbf { x }$ as the input and $\widetilde { \mathbf { y } }$ represent the LLM-generated results derived by $\widetilde { \mathbf { x } }$ . $D$ eis a distance measure between two distributions, such as KL divergence. We expect the edistribution of $\mathbf { y }$ and $\widetilde { \mathbf { y } }$ to be as similar as possible. $\lambda$ is a trade-off hyper-parameter regarding the ecompression ratio. In this work, we additionally incorporate an operation space of permutation over the $K$ documents $( \mathbf { x } _ { 1 } ^ { \mathrm { d o c } } , \cdot \cdot \cdot , \mathbf { x } _ { K } ^ { \mathrm { d o c } } )$ for joint optimization.
 Figure 2: Framework of LongLLMLingua. Gray Italic content: As in LLMLingua.
# 3 PRELIMINARY: LLMLINGUA
LLMLingua (Jiang et al., 2023a) uses a small language model $\mathcal { M } _ { S }$ to calculate the perplexity of each token in the original prompt and then removes tokens with lower perplexities. The rationale behind this approach is that tokens with lower perplexities contribute less to the overall entropy gain of the language model, so removing them will have a relatively minor impact on the LLM’s comprehension of the context. LLMLiungua consists of three components: a budget controller, an iterative token-level prompt compression algorithm, and a distribution alignment mechanism, as shown by Italic texts in Figure 2. The budget controller allocates different compression ratios to the various components in the original prompt (i.e., instruction, demonstrations, question), and performs coarsegrained compression at the demonstration level. The intermediate results are divided into segments and the token-level compression is then performed segment by segment, with the perplexity of each token conditioned on previous compressed segments calculated by $\mathcal { M } _ { S }$ . For distribution alignment, it performs instruction tuning on $\mathcal { M } _ { S }$ with the data generated by the target LLM to narrow the gap between the distribution of LLM and that of $\mathcal { M } _ { S }$ used for prompt compression.
# 4 LONGLLMLINGUA
LongLLMLingua is developed upon the framework of LLMLingua towards prompt compression in long context scenarios. The primary challenge in long context scenarios is how to enhance LLM’s perception of key information relevant to the question in the prompt. LongLLMLingua addresses this challenge from three perspectives, and further applies a subsequence recovery strategy to improve the accuracy and reliability of the information provided to users. We elaborate on each component in this section.
# 4.1 HOW TO IMPROVE KEY INFORMATION DENSITY IN THE PROMPT?
out a metric Question-Aware Coarse-Grained Compression In coarse-grained compression, we aim to figure $r _ { k }$ to evaluate the importance of each document $\mathbf { x } _ { k } ^ { \mathrm { d o c } } = \{ x _ { k , i } ^ { \mathrm { { \bar { d o c } } } } \} _ { i = 1 } ^ { N _ { k } }$ , where $N _ { k }$ is the number of tokens in $\mathbf { x } _ { k } ^ { \mathrm { { d o c } } }$ . We only keep $\mathbf { x } _ { k } ^ { \mathrm { { d o c } } }$ with higher $r _ { k }$ as the intermediate compressed results.
LLMLingua uses document-level perplexity to represent the importance of documents: $r _ { k } = { }$ $1 / N _ { k } \textstyle \sum _ { i } ^ { \bar { N } _ { k } } p ( x _ { k , i } ^ { \mathrm { d o c } } ) \log p ( x _ { k , i } ^ { \mathrm { d o c } } ) , k \in \{ 1 , 2 , \cdots , K \}$ . Although the retained documents typically contain a lot of information, they are irrelevant to the question and instead become noise, reducing key information density in the compressed results and bringing difficulties for LLM to output correct answers. As shown in Figure 3a, the recall $@ 1 6$ of LLMLingua only reaches $50 \%$ , indicating its incompetence in retaining key information during compression.
Retrieval-based methods are also feasible here. We can use $\mathbf { x } ^ { \mathrm { q u e } }$ to retrieve the most relevant documents among $( \mathbf { x } _ { 1 } ^ { \mathrm { d o c } } , \cdot \cdot \cdot , \mathbf { x } _ { K } ^ { \mathrm { d o c } } )$ as the compressed results. However, these methods struggle to distinguish question-related fine-grained semantic information. Some documents with key information may be discarded during retrieval. As shown in Figure 3a, embedding-based methods such as Sentence BERT and OpenAI Embedding only achieve ${ \sim } 7 5 \%$ accuracy in recall $\textcircled { \alpha } 5$ , which implies that the final accuracy upper bound of LLMs with $4 \mathbf { x }$ compression is only $7 5 \%$ .
 Figure 3: (a) Comparison of recall on NaturalQuestions Multi-documemnt QA dataset. (b) Comparison between perplexities and contrastive perplexities of tokens in the prompt from Multi-documemnt QA dataset. The document with the ground truth is located on the left side of the dashed line.
One approach to improve key information density in the compressed results is to calculate documentlevel perplexity conditioned on the question $\mathbf { x } ^ { \mathrm { q u e } }$ . However, this method may not be effective because documents often contain a significant amount of irrelevant information. Even when conditioned on $\mathbf { x } ^ { \mathrm { q u e } }$ , the perplexity scores computed for entire documents may not be sufficiently distinct, rendering them an inadequate metric for document-level compression. Therefore, we propose to use the perplexity of the question $\mathbf { x } ^ { \mathrm { q u e } }$ conditioned on different contexts $\mathbf { x } _ { k } ^ { \mathrm { { d o c } } }$ to represent the association between them. We append a restrictive statement $\mathbf { x } ^ { \mathrm { r e s t r i c t { 1 } } }$ after $\mathbf { x } ^ { \mathrm { q u e } }$ to strengthen the interconnection of $\mathbf { x } ^ { \mathrm { q u e } }$ and $\mathbf { x } _ { k } ^ { \mathrm { { d o c } } }$ . It can be regarded as a regularization term that mitigates the impact of hallucinations. This can be formulated as:
$$r _ { k } = \frac { 1 } { N _ { c } } \sum _ { i } ^ { N _ { c } } p ( x _ { i } ^ { \mathrm { q u e , r e s t i c t } } | \mathbf { x } _ { k } ^ { \mathrm { d o c } } ) \log p ( x _ { i } ^ { \mathrm { q u e , r e s t r i c t } } | \mathbf { x } _ { k } ^ { \mathrm { d o c } } ) , k \in \{ 1 , 2 , \cdots , K \} ,$$
where $x _ { i } ^ { \mathrm { q u e , r e s t r i c t } }$ is the $i$ -th token in the concatenated sequence of $\mathbf { x } ^ { \mathrm { q u e } }$ and $\mathbf { x } ^ { \mathrm { r e s t r i c t } }$ and $N _ { c }$ in the number of tokens.
Figure 3a demonstrates that our coarse-level compression approach achieves the highest recall with different numbers of retained documents, suggesting that it preserves the most key information from the documents $( \mathbf { x } _ { 1 } ^ { \mathrm { d o c } } , \cdot \cdot \cdot , \mathbf { x } _ { K } ^ { \mathrm { d o c } } )$ in the compressed results.
Question-Aware Fine-Grained Compression In fine-grained compression, we assess the importance of each token in the instruction $\mathbf { x } ^ { \mathrm { i n s } }$ , the question $\mathbf { x } ^ { \mathrm { q u e } }$ , and $K ^ { \prime }$ documents $\{ \mathbf { x } _ { i } ^ { \mathrm { d o c } } \} _ { i = 1 } ^ { K ^ { \prime } }$ retained after coarse-grained compression. We incorporate the iterative compression mechanism following LLMLingua and directly calculate token perplexities to compress $\bar { \mathbf { x } } ^ { \mathrm { i n s } }$ and $\mathbf { x } ^ { \mathrm { q u e } }$ . In this section, we invesquestion e how to make the fine-grained token-level compression over , so that the compressed results could contain more question-r $\{ \mathbf { x } _ { k } ^ { \mathrm { d o c } } \} _ { k = 1 } ^ { K ^ { \prime } }$ aware of the information. $\mathbf { x } ^ { \mathrm { q u e } }$
A straightforward solution for the awareness of $\mathbf { x } ^ { \mathrm { q u e } }$ is to simply concatenate it at the beginning of the whole context. However, this will result in low perplexities of relevant tokens in the context following the condition, further reducing their differentiation from general tokens. In this paper, we propose contrastive perplexity, i.e., the distribution shift caused by the condition of the question, to represent the association between the token and the question. The contrastive perplexity based importance metric $s _ { i }$ for each token $x _ { i }$ in $\{ \mathbf { x } _ { k } ^ { \mathrm { d o c } } \} _ { k = 1 } ^ { K ^ { \prime } }$ can be formulated as:
$$s _ { i } = \mathrm { p e r p l e x i t y } ( x _ { i } | \boldsymbol { x } _ { < i } ) - \mathrm { p e r p l e x i t y } ( x _ { i } | \boldsymbol { x } ^ { \mathrm { q u e } } , \boldsymbol { x } _ { < i } ) .$$
Figure 3b illustrates the difference between perplexities and contrastive perplexities. We can see that tokens of high perplexities are widely distributed in all documents. However, tokens with high contrastive perplexities concentrate more on the left side of the dashed line, which corresponds to the document that contains the answer to the question. This suggests that the proposed contrastive perplexity can better distinguish tokens relevant to the question, thus improving the key information density in the compressed results.
# 4.2 HOW TO REDUCE INFORMATION LOSS IN THE MIDDLE?
As demonstrated in Figure 1b, LLM achieves the highest performance when relevant information occurs at the beginning and significantly degrades if relevant information is located in the middle of long contexts. After the coarse-grained compression, we have obtained a set of documents $\{ \mathbf { x } _ { k } ^ { \mathrm { d o c } } \} _ { k = 1 } ^ { K ^ { \prime } }$ with their corresponding importance scores $\{ r _ { k } \} _ { k = 1 } ^ { K ^ { \prime } }$ indicating their association with the question $\mathbf { x } ^ { \mathrm { q u e } }$ . Therefore, we reorder documents using their importance scores to better leverage LLMs’ information perception difference in positions:
$$( \mathbf { x } ^ { \mathrm { i n s } } , \mathbf { x } _ { 1 } ^ { \mathrm { d o c } } , \cdot \cdot \cdot , \mathbf { x } _ { K ^ { \prime } } ^ { \mathrm { d o c } } , \mathbf { x } ^ { \mathrm { q u e } } ) \xrightarrow { r _ { k } } ( \mathbf { x } ^ { \mathrm { i n s } } , \mathbf { x } _ { r 1 } ^ { \mathrm { d o c } } , \cdot \cdot \cdot , \mathbf { x } _ { r K ^ { \prime } } ^ { \mathrm { d o c } } , \mathbf { x } ^ { \mathrm { q u e } } )$$
# 4.3 HOW TO ACHIEVE ADAPTIVE GRANULAR CONTROL DURING COMPRESSION?
In fine-grained compression, LLMLingua applies the save compression ratio over all documents obtained from coarse-grained compression. However, the key information density of different documents is different. The more relevant to the question a document is, the more budget (i.e., lower compression ratio) we should allocate to it. Therefore, we bridge coarse-grained compression to fine-grained compression and use the importance scores $\{ r _ { k } \} _ { k = 1 } ^ { \bar { K ^ { \prime } } }$ obtained from coarse-grained compression to guide the budget allocation in fine-grained compression. In this way, we can achieve adaptive granular control on the whole.
Specifically, we first determine the initial budget for the retained documents $\tau ^ { \mathrm { d o c } }$ 2 using the budget controller of LLMLingua. During fine-grained compression, we follow the iterative token-level compression algorithm in LLMLingua but dynamically assign the compression budget $\cdot$ to each document $\mathbf { x } _ { k } ^ { \mathrm { { d o c } } }$ according to the ranking index $I ( r _ { k } )$ (e.g., 0, 1) of its importance score from the coarse-grained compression. In this paper, we employ a linear scheduler for the adaptive allocation. Budget of each token $x _ { i }$ can be formulated as:
$$\begin{array} { r l } & { \tau _ { i } = \tau _ { k } ^ { \mathrm { d o c } } , } \\ & { \tau _ { k } ^ { \mathrm { d o c } } = \operatorname* { m a x } ( \operatorname* { m i n } ( ( 1 - \frac { 2 I ( r _ { k } ) } { K ^ { \prime } } ) \delta \tau + \tau ^ { \mathrm { d o c } } , 0 ) , 1 ) , } \end{array}$$
where $i$ and $k$ is the index of token and document, $K ^ { \prime }$ denotes the number of documents, and $\delta \tau$ is a hyper-parameter that controls the overall budget for dynamic allocation.
# 4.4 HOW TO IMPROVE THE INTEGRITY OF KEY INFORMATION?
Certain tokens of key entities may be discarded during the fine-grained token-wise compression. For example, the time entity “2009” in the original prompt might be compressed to “209” and the name entity “Wilhelm Conrad Rontgen” might be compressed to “Wilhelmgen”. This can cause problems ¨ for fact-based tasks like document QA, where language models tend to replicate information from the prompt, as shown in Figure 4.
To improve the accuracy and reliability of the information provided to users, we propose a subsequence recovery method to restore the original content from LLMs’ responses. This method relies on the subsequence relationship among tokens in the original prompt, compressed prompt, and LLMs’ response. The overall procedure includes: i) Iterate through tokens $y _ { l }$ in LLMs’ response and select the longest substring $\bar { \tilde { y } } _ { \mathrm { k e y } , l } = \{ y _ { l } , y _ { l + 1 } , . . . , y _ { r } \}$ that appears in the compressed prompt $\widetilde { \pmb x }$ . ii) Find ethe maximum common shortest subsequence $\mathbf { \bar { \mathbf { x } } } _ { i , j } ~ { = } ~ \bar { \left\{ \mathbf { \bar { \mathbf { \Phi } } } ( { \bf { x } } _ { i } , { \bf { x } } _ { i + 1 } , . . . , { \bf { x } } _ { j } \right\} }$ ein the original prompt $_ { \textbf { \em x } }$ , corresponding to the representation $\widetilde { \boldsymbol { y } } _ { \mathrm { k e y } , l }$ in the original prompt (accelerated using prefix trees or esequence automata). iii) Replace the matched tokens $\widetilde { \boldsymbol { y } } _ { \mathrm { k e y } , l }$ in LLMs’ response with the corresponding subsequence $\boldsymbol { x } _ { i , j }$ efrom the original prompt. For more details, please refer to Algorithm 1.
<table><tr><td>Document [1](Title: List of Nobel laureates in Physics)The first Nobel Prize in Physics was awarded in 1901to{Wilhelm Conrad Rontgen}{Wilhelm Con rad Ro nt gen}, of Germany,... Original Prompt</td><td>Document [1](Title: List of Nobelates in Physics) The first Nobel1 {Wilhelmgen}{Wilhelm gen}, of, who received,.. Compressed Prompt</td><td>{Wilelmgen} {Wilhelm gen} LLMs' Response</td></tr></table>
# 5 EXPERIMENTS
Here, we investigate: (1) How effective is LongLLMLingua? (2) How efficient is LongLLMLingua?
Implementation details In this paper, we use GPT-3.5-Turbo- $. 0 6 1 3 ^ { 3 }$ and LongChat-13B-16k as the target LLMs, both accessible via OpenAI4 and HuggingFace5. To ensure stable and reproducible results, we employ greedy decoding and set the temperature to 0 in all experiments. For the small language models used for compression, we apply LLaMA-2-7B-Chat6, which has been aligned by supervised fine-tuning and RLHF. We implement our approach with PyTorch 1.13.1 and HuggingFace Transformers. We set up hyperparameters following LLMLingua except for the segment size used in iterative token-level compression set to 200 here. More details are provided in Appendix C.
Dataset & evaluation metric We use NaturalQuestions for the multi-document QA task, and use LongBench and ZeroSCROLLS for general long context scenarios. We also test on multi-hop QA tasks using MuSiQue dataset (Trivedi et al., 2022), and long dependency QA tasks using LooGLE benchmark (Li et al., 2023b). Please refer to Appendix D for more details on datasets.
(i) NaturalQuestions (Liu et al., 2023): This benchmark is similar to the retrieval-augmented generation setup in commercial search and question-answering scenarios like Bing Chat. Specifically, each question has 20 related documents in the original prompt. One of them contains the correct answer and there are five different ground truth document position settings in the prompt: 1st, 5th, 10th, 15th, and 20th. Following Liu et al. (2023), we use accuracy as the evaluation metric.
(ii) LongBench (Bai et al., 2023): This benchmark consists of six task types: single-document QA, multi-document QA, summarization, few-shot learning, code completion, and synthetic tasks. We used the English portion that covers 16 datasets for evaluation. We use the metrics and scripts provided along with the benchmark for evaluation.
(iii) ZeroSCROLLS (Shaham et al., 2023): This benchmark consists of four task types: summarization, QA, sentiment classification, and reordering, covering 10 datasets. We used the validation set for evaluation. We use the provided metrics and scripts for evaluation.
Baselines We include two sets of baselines in following experiments:
(i) Retrieval-based Methods. We measure the association between the question and the documents in the prompt using five SoTA retrieval methods: BM25, Gzip (Jiang et al., 2023b), SentenceBERT (Reimers & Gurevych, 2019), OpenAI Embedding, and the important metric $r _ { k }$ used in LongLLMLingua coarse-grained compression. We discard sentences or paragraphs with low association until the compression constraint is met while keeping the original document order unchanged.
Table 1: Performance of different methods with different compression ratios on NaturalQuestions (20 documents) (Liu et al., 2023). Reorder: we reorder the documents with relevance metrics of different baselines as our document reordering strategy described in Sec. 4.2. In the case of OpenAI, it corresponds to LongContextReorder in the LangChain framework (Chase, 2022). For results reported under 1st to 20th, we do not use the reordering strategy for all methods.
<table><tr><td rowspan="2">Methods</td><td rowspan="2"></td><td colspan="5">t</td><td></td><td colspan="3"></td><td></td><td colspan="2"></td><td colspan="2"></td></tr><tr><td>1st</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td colspan="10">2x constraint</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>Retrieval-based Methods</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>BM25</td><td></td><td>53.749.347.949.946.9</td><td></td><td></td><td>50.3</td><td></td><td>50.944.944.1 42.9 43.2</td><td></td><td></td><td></td><td>46.0</td><td>1,545</td><td>1.9x</td><td>2.1</td><td>1.9x</td></tr><tr><td>Gzip</td><td></td><td>64.663.8 60.5 58.3 57.3</td><td></td><td></td><td></td><td>64.4</td><td>61.9 55.752.7 50.8 50.9</td><td></td><td></td><td></td><td>59.3</td><td>1,567</td><td>1.9x</td><td>2.1</td><td>1.9x</td></tr><tr><td>SBERT</td><td></td><td>72.5 67.963.365.0 66.2</td><td></td><td></td><td></td><td>68.7</td><td>65.8 57.5 54.9 53.4 55.7</td><td></td><td></td><td></td><td>61.4</td><td>1,549</td><td>1.9x</td><td>2.2</td><td>1.9x</td></tr><tr><td>OpenAI</td><td></td><td>73.0 65.666.5 65.4 65.5</td><td></td><td></td><td></td><td>69.9</td><td>65.9 57.5 56.2 54.2 55.7</td><td></td><td></td><td></td><td>61.7</td><td>1,550</td><td>1.9x</td><td>4.9</td><td>0.8x</td></tr><tr><td>LongLLMLingua rk73.967.7 68.766.0 65.6</td><td></td><td></td><td></td><td></td><td></td><td>74.3</td><td>68.5 59.1 56.8 55.3 56.9</td><td></td><td></td><td></td><td>65.2</td><td>1,548</td><td>1.9x</td><td>2.3</td><td>1.8x</td></tr><tr><td colspan="10">Compression-based Methods</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>Selective-Context</td><td></td><td>45.4 39.0 33.833.5 41.5</td><td></td><td></td><td></td><td></td><td>53.2 26.325.424.2 33.3</td><td></td><td></td><td></td><td>1</td><td></td><td>1,4782.0x</td><td>7.4</td><td>0.6x</td></tr><tr><td>LLMLingua</td><td></td><td>39.739.540.437.1 42.3</td><td></td><td></td><td>41.5</td><td></td><td>38.7 37.3 35.7 34.1 37.5</td><td></td><td></td><td></td><td>37.1</td><td>1,410</td><td>2.1x</td><td>2.8</td><td>1.5x</td></tr><tr><td> LongLLMLingua</td><td></td><td></td><td></td><td></td><td></td><td>76.2</td><td></td><td></td><td></td><td></td><td>66.1</td><td>1,429</td><td>2.1x</td><td>2.9</td><td>1.4x</td></tr><tr><td colspan="10">77.2 72.9 70.8 70.5 70.6 68.7 59.4 57.3 55.9 58.4</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td colspan="10">4x constraint</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>Retrieval-based Methods BM25</td><td></td><td>40.638.6 38.2 37.4 36.6</td><td></td><td></td><td>36.3</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>2.7x</td></tr><tr><td>Gzip</td><td></td><td></td><td></td><td></td><td></td><td></td><td>39.537.5 36.8 36.4 35.5</td><td></td><td></td><td></td><td>37.7</td><td>798</td><td>3.7x</td><td>1.5</td><td>2.7x</td></tr><tr><td>SBERT</td><td></td><td>63.1 61.0 59.861.1 60.1</td><td></td><td></td><td></td><td>62.3</td><td>57.652.951.050.150.4</td><td></td><td></td><td></td><td>57.2</td><td>824</td><td>3.6x</td><td>1.5</td><td>2.5x</td></tr><tr><td>OpenAI</td><td></td><td>66.961.1 59.0 61.2 60.3</td><td></td><td></td><td></td><td>64.4 63.7</td><td>61.2 56.0 55.1 54.4 55.0</td><td>62.656.6 55.1 53.9 55.0</td><td></td><td></td><td>59.1</td><td>808</td><td>3.6x</td><td>1.6</td><td>1.0x</td></tr><tr><td></td><td></td><td>63.8 64.6 65.4 64.1 63.7</td><td></td><td></td><td></td><td>71.5</td><td>67.8 59.457.7 57.7 58.6</td><td></td><td></td><td></td><td>58.8 64.0</td><td>804 807</td><td>3.7x 3.7x</td><td>4.3 1.7</td><td>2.4x</td></tr><tr><td colspan="10">LongLLMLingua rk71.170.769.368.7 68.5</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>Compression-based Methods</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>Selective-Context LLMLingua</td><td>31.419.524.724.1 43.8</td><td></td><td></td><td></td><td></td><td>1 27.0</td><td>38.217.2 15.916.0 27.3 32.1 30.8 29.9 28.9 32.4</td><td></td><td></td><td></td><td>1 30.5</td><td>791 775</td><td>3.7x 3.8x</td><td>6.8 1.8</td><td>0.6x 2.2x</td></tr><tr><td> LongLLMLingua</td><td>25.527.523.526.530.0</td><td></td><td></td><td></td><td></td><td>75.5</td><td>68.7 60.5 59.3 58.3 61.3</td><td></td><td></td><td></td><td></td><td>748</td><td>3.9x</td><td>2.1</td><td>2.0x</td></tr><tr><td></td><td>75.0 71.8 71.2 71.2 74.7</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>66.7</td><td></td><td></td><td></td><td></td></tr><tr><td>Original Prompt Zero-shot</td><td>[75.7 57.3 54.1 55.4 63.1</td><td></td><td>56.1</td><td></td><td></td><td>1</td><td>68.657.4 55.352.5 55.0</td><td>35.0</td><td></td><td></td><td>-</td><td>2,946 15</td><td>1 196x |</td><td>4.1 1.1</td><td>- 3.7x</td></tr></table>
(ii) Compression-based Methods. We compare our approach with two state-of-art methods for prompt compression, i.e., Selective Context (Li, 2023) and LLMLingua (Jiang et al., 2023a). Both methods employ LLaMA-2-7B-Chat as the small language model for compression. In LLMLingua, a coarse-to-fine approach is used to handle constraints of compression ratio: the original prompt is first compressed to $k$ times the constraint at a coarse level, where $k$ is the granular control coefficient; token-level is then performed to reach the overall constraint. Our method follows the same coarse-to-fine logic to achieve the constraint.
Main results Table 1 and 2 present the performance of various methods under different compression constraints. There are multiple observations and conclusions: (1) Our LongLLMLingua achieves the best performance across different tasks and constraints of compression ratios. Compared to the original prompt, our compressed prompt can derive higher performance with much lower cost. For example, LongLLMLingua gains a performance boost of $1 7 . 1 \%$ on NaturalQuestions with the ground-truth document at the 10th position, while the number of tokens input to GPT3.5-Turbo is ${ \sim } 4 \mathbf { x }$ less. (2) Compression-based methods like Selective Context (Li, 2023) and LLMLingua (Jiang et al., 2023a) perform poorly on most tasks, especially those with abundant irrelevant information in the original prompt. This is due to their pure information entropy based compression mechanism, which includes too much noise in the compressed results and even leads to performance worse than the zero-shot setting, e.g., on NaturalQuestions. (3) Retrieval-based methods work well with low compression rates. However, their performance declines as the compression progresses, e.g., $2 x 4 x$ ; 3000 tokens $\to 2 0 0 0$ tokens. This may be caused by the decreased recall. Figure 3a is the illustration of cases on NaturalQuestions. (4) LongLLMLingua as well as our coarse-grained compression metric $r _ { k }$ only is much more robust than all other baselines under different tasks and compression constraints. With the increase of the compression rate, e.g., $2 x 4 x$ , LongLLMLingua even achieves a little performance gain. We mainly owe this to the question-aware coarse-to-fine compression, which can better figure out the key information and reach a higher key information density with a higher compression rate. (5) The proposed reordering method helps in not only our approach but also other baselines as shown in Table 1, well demonstrating its effectiveness.
Table 2: Performance of different methods under different compression ratios on LongBench (Bai et al., 2023) and ZeroSCROLLS (Shaham et al., 2023) using GPT-3.5-Turbo. Considering the dataset structure, we do not use the reordering strategy here.
<table><tr><td rowspan="2">Methods</td><td colspan="9">SinglDoc MuoSFeeesS</td><td rowspan="2"></td><td colspan="3"></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td colspan="10">3,000 tokens constraint</td><td></td><td></td><td></td><td></td></tr><tr><td>Retrieval-based Methods BM25</td><td>32.3</td><td>34.3</td><td>25.3</td><td>57.9</td><td>45.1</td><td>48.940.6</td><td>3,417</td><td>3x</td><td>7.5(2.1x)</td><td>19.8</td><td>3,379</td><td>3x</td><td>5.5(2.2x)</td></tr><tr><td>SBERT</td><td>35.3</td><td>37.4</td><td>26.7</td><td>63.4</td><td>51.0</td><td>34.541.4</td><td>3,399</td><td>3x</td><td>7.7(2.0x)</td><td>24.03,340</td><td></td><td>3x</td><td>5.9(2.1x)</td></tr><tr><td>OpenAI</td><td>34.5</td><td>38.6</td><td>26.8</td><td>63.4</td><td>49.6</td><td>37.641.7</td><td>3,421</td><td>3x</td><td>13.3(1.2x)</td><td>22.4</td><td>3.362</td><td>3x</td><td>11.7(1.0x)</td></tr><tr><td>LongLLMLingua rk</td><td>37.6</td><td>42.9</td><td>26.9</td><td>68.2</td><td>49.9</td><td>53.446.5</td><td>3,424</td><td>3x</td><td>8.2(1.9x)</td><td>29.3</td><td>3,350</td><td>3x</td><td>6.2(2.0x)</td></tr><tr><td colspan="10">Compression-basedMethods</td><td></td><td></td><td></td><td></td></tr><tr><td>Selective-Context</td><td>23.3</td><td>39.2</td><td>25.0</td><td>23.8</td><td>27.5</td><td>53.132.03,328</td><td></td><td></td><td>3x50.6(0.3x)|20.7</td><td></td><td>3,460</td><td>3x</td><td>54.2(0.2x)</td></tr><tr><td>LLMLingua</td><td>31.8</td><td>37.5</td><td>26.2</td><td>67.2</td><td>8.3</td><td></td><td>53.237.43,421</td><td>3x</td><td>9.2(1.7x)</td><td>30.7</td><td>3,366</td><td>3x</td><td>7.4(1.7x)</td></tr><tr><td> LongLLMLingua</td><td>40.7</td><td>46.2</td><td>27.2</td><td>70.6</td><td>53.0</td><td>55.2 48.8</td><td>3,283</td><td>3x</td><td>8.0(1.6x)32.83.412</td><td></td><td></td><td>3x</td><td>8.2(1.5x)</td></tr><tr><td colspan="10">2,000 tokens constraint</td><td colspan="7"></td></tr><tr><td colspan="10"></td><td colspan="7"></td></tr><tr><td>Retrieval-based Methods BM25</td><td>30.1</td><td>29.4</td><td>21.2</td><td>19.5</td><td>12.4</td><td>29.1 23.6</td><td>1,985</td><td>5x</td><td>4.6(3.4x)</td><td></td><td>20.1</td><td>1,799</td><td>5x</td><td>3.8(3.2x)</td></tr><tr><td>SBERT</td><td>33.8</td><td>35.9</td><td>25.9</td><td>23.5</td><td>18.0</td><td>17.825.8</td><td></td><td>1,947</td><td>5x</td><td>4.8(3.4x)</td><td>20.5</td><td>1,773</td><td>6x</td><td>4.1(3.0x)</td></tr><tr><td>OpenAI</td><td>34.3</td><td>36.3</td><td>24.7</td><td>32.4</td><td>26.3</td><td>24.829.8</td><td></td><td>1,991</td><td>5x</td><td>10.4(1.5x)</td><td>20.6</td><td>1,784</td><td>5x</td><td>9.9(1.2x)</td></tr><tr><td>LongLLMLingua rk</td><td>37.8</td><td>41.7</td><td>26.9</td><td>66.3</td><td>53.0</td><td>52.446.3</td><td></td><td>1,960</td><td>5x</td><td>4.7(3.3x)</td><td>24.9</td><td>1,771</td><td>6x</td><td>10.4(1.2x)</td></tr><tr><td colspan="10">Compression-based Methods</td><td colspan="7"></td></tr><tr><td>Selective-Context</td><td></td><td></td><td></td><td>15.7</td><td>8.4</td><td>49.224.8</td><td></td><td>1,925</td><td></td><td></td><td></td><td></td><td></td><td>47.5(0.3x)</td></tr><tr><td>LLMLingua</td><td>16.2 22.4</td><td>34.8 32.1</td><td>24.4 24.5</td><td>61.2</td><td>10.4</td><td>56.834.6</td><td></td><td>1,950</td><td>5x</td><td>5x47.1(0.3x)|19.4 5.9(2.6x)</td><td>27.2</td><td>1,865 1,862</td><td>5x 5x</td><td>4.8(2.5x)</td></tr><tr><td> LongLLMLingua</td><td>39.0</td><td>42.2</td><td>27.4</td><td>69.3</td><td>53.8</td><td>56.6 48.01,809</td><td></td><td></td><td>6x</td><td>6.1(2.6x)|32.5</td><td></td><td>1,753</td><td>6x</td><td>5.2(2.3x)</td></tr><tr><td>Original Prompt</td><td></td><td></td><td></td><td></td><td></td><td>54.244.0 10,295</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>Zero-shot</td><td>39.7 15.6</td><td>38.7 31.3</td><td>26.5 15.6</td><td>67.0 40.7</td><td>37.8 1.6</td><td>36.223.5</td><td></td><td>214</td><td>-</td><td>15.6 48x1.6(9.8x)</td><td>132.59,788 10.8</td><td>32</td><td>-</td><td>12.2 306x 1.0(12.2x)</td></tr></table>
Ablation study To evaluate the contributions of different components in LongLLMLingua, we introduce following variants of it for ablation study. (1) Variants about Question-aware Coarsegrained Compression, include: ours w/o Questionawareness, which calculates question-text relevance $r _ { k }$ using information entropy in LLMLingua, ours w/ SBERT, which employs SBERT to compute $r _ { k }$ , ours w/ $p ( \mathbf { x } _ { k } ^ { \mathrm { d o c } } | \boldsymbol { x } _ { i } ^ { \mathrm { q u e , r e s t r i c t } } )$ |xque,restricti ), which replace p(xque,restricti |x doc with $p ( \mathbf { x } _ { k } ^ { \mathrm { d o c } } | x _ { i } ^ { \mathrm { q u e , r e s t r 1 c t } } )$ in Eq. 2, and ours w/o restrict, which only calculates the conditional probability corresponding to $x ^ { \mathrm { q u e } }$ . (2) Ours w/o Question-aware Fine-grained, which disregards Eq. (3) and only applies Iterative Token-level Prompt Compression as LLMLingua. (3) Ours w/o Dynamic Compression Ratio, where all documents share the same compression ratio in fine-grained compression.
Table 3: Ablation study on NaturalQuestions with $2 \mathbf { x }$ constraint using GPT-3.5-Turbo.
<table><tr><td>1st 5th 10th 15th 20th</td></tr><tr><td>LongLLMLingua 77.2 72.9 70.8 70.5 70.6 Question-awareCoarse-grained - w/o Question-awareness 42.1 40.3 39.7 40.1 40.3</td></tr><tr><td>- W/SBERT 73.2 68.5 65.7 66.1 66.7 - w/p(xdoq| ,que,restrict 56.0 52.6 53.4 51.6 51.1 - w/o restrict 75.172.2 70.3 70.370.2 xi</td></tr><tr><td>- w/o Question-aware Fine-grained 75.8 71.0 68.9 68.4 69.3 - w/o Dynamic Compression Ratio 74.4 70.7 68.7 67.9 68.1 - w/o Subsequence Recovery 76.7 71.7 69.4 69.3 69.7</td></tr><tr><td>- w/ Document Reordering 76.2 76.2 76.2 76.2 76.2 - w/ GPT2-small 74.6 71.7 70.169.8 68.5</td></tr></table>
(4) Ours w/o and (5) LLMLingua w/ Subsequence Recovery, which either removes or adds the postprocessing subsequence recovery strategy. (6) Ours w/ GPT2-small, which uses the GPT2-small model as the small language model.
Table 3 shows the results of the ablation study. In summary, removing any component proposed for LongLLMLingua will lead to a performance drop regardless of the position of the ground-truth answer. This well validates the necessity and effectiveness of the proposed question-aware mechanism during coarse-to-fine compression, the dynamic compression ratio, and the subsequence recovery strategy. It also shows that applying SBERT for coarse-grained compression will result in inferior performance, which implies the superiority of our question-aware importance metric in Eq. 2 over SBERT. In addition, replacing $p ( x _ { i } ^ { \mathrm { q u e , r e s t r u c t } } | \mathbf { x } _ { k } ^ { \mathrm { d o c } } )$ with $p ( \mathbf { x } _ { k } ^ { \mathrm { d o c } } | x _ { i } ^ { \mathrm { q u e , r e s t r i c t } } )$ can greatly affect performance due to the large noise in calculating $p ( \mathbf { x } _ { k } ^ { \mathrm { { d o c } } } )$ since the perplexity of document depends on many other information besides the question. Removing the restrictive statement can increase the hallucination of small language models, leading to a decrease in performance. Moreover, our subsequence recovery strategy can also bring performance gains for LLMLingua. However, without our question-aware mechanism, results from LLMLingua are still less satisfactory. For more detailed cases, please go to Appendix F.
Latency evaluation We conducte end-to-end latency testing on a V100-32G, using the prompts from Multi-document QA, LongBench, and ZeroSCROLLS in the API call, and results are shown in Table 1 and 2. The latency includes the time cost for prompt compression and the request time for LLMs, with multiple measurements taken and averaged over. Results demonstrate that LongLLMLingua does indeed speed up the overall inference under different compression ratios and scenarios. Moreover, with the compression ratio increasing, the acceleration effect becomes more pronounced up to 2.6x. However, the OpenAI embedding and Selective-Context results in longer latency time, due to repeated API calls and the sequential entropy calculation of semantic units, respectively.
# 6 RELATED WORKS
Long context for LLMs. Recent research has focused on expanding the window size of LLMs. Main approaches include: (1) Staged pre-training (Nijkamp et al., 2023) which gradually increases the context window; (2) Modifying (Press et al., 2022) or interpolating position embeddings (Chen et al., 2023; Peng et al., 2023; Han et al., 2023); (3) Using linear or sparse attention mechanisms (Ding et al., 2023; Sun et al., 2023); (4) Utilizing external memory modules for context storage (Bertsch et al., 2023; Tworkowski et al., 2023). While these methods address context window expansion, their impact on downstream task performance has yet to be discussed.
Information distribution in prompt. Recent empirical experiments have shown that LLM performance decreases with less effective information in a prompt (Bai et al., 2023; Li et al., 2023a; Shi et al., 2023). Moreover, the position of relevant information in a prompt has a significant impact on performance(Wu et al., 2022). Liu et al. (2023) suggests that LLMs have more difficulty comprehending information located in the middle of a prompt compared to those at the edges.
Retrieval methods can be categorized as dense or sparse retrieval methods. Sparse retrieval methods, like BM25, determine the relevance between queries and documents based on n-gram information. Conversely, dense retrieval methods assess the relevance between queries and documents in latent space using dense vectors, such as SentenceBERT (Reimers & Gurevych, 2019) and OpenAI Embedding. Recently, Jiang et al. (2023b)) proposed an unsupervised dense retrieval method that leverages traditional compression algorithms, such as gzip, and k-nearest neighbors.
Prompt compression methods can be grouped into three main categories: (1) Token pruning (Goyal et al., 2020; Kim & Cho, 2021; Modarressi et al., 2022) and token merging (Bolya et al., 2023), which need model fine-tuning or intermediate results during inference and have been used with BERT-scale models. (2) Soft prompt tuning methods like GIST (Mu et al., 2023), AutoCompressor (Chevalier et al., 2023), and ICAE (Ge et al., 2023), which require LLMs’ parameter fine-tuning, making them suitable for specific domains but not directly applicable to black-box LLMs. (3) Information-entropy-based approaches such as Selective Context (Li, 2023) and LLMLingua (Jiang et al., 2023a), which use a small language model to calculate the self-information or perplexity of each token in the original prompt and then remove tokens with lower perplexities.
# 7 CONCLUSION
We propose LongLLMLingua to address the three challenges, i.e., higher computational/financial cost, longer system latency, and inferior performance for LLMs in long context scenarios. We develop LongLLMLingua from the perspective of efficient prompt compression, thus reducing both computational/financial cost and the system latency. We further design four components, i.e., a question-aware coarse-to-fine compression method, a document reordering mechanism, dynamic compression ratios, and a post-compression subsequence recovery strategy to improve LLMs’ perception of the key information, with which LongLLMLingua demonstrate superior performance. Experiments on one multi-document QA benchmark and two long context benchmarks demonstrate that LongLLMLingua compressed prompt can derive higher performance than original prompts while both API costs for inference and the end-to-end system latency are largely reduced.
REFERENCES Yushi Bai, Xin Lv, Jiajie Zhang, Hongchang Lyu, Jiankai Tang, Zhidian Huang, Zhengxiao Du, Xiao Liu, Aohan Zeng, Lei Hou, et al. Longbench: A bilingual, multitask benchmark for long context understanding. ArXiv preprint, abs/2308.14508, 2023. URL https://arxiv.org/ abs/2308.14508. Amanda Bertsch, Uri Alon, Graham Neubig, and Matthew R. Gormley. Unlimiformer: Long-range transformers with unlimited length input. In Thirty-seventh Conference on Neural Information Processing Systems, 2023. URL https://openreview.net/forum?id $\underline { { \underline { { \mathbf { \Pi } } } } } =$ lJWUJWLCJo. Daniel Bolya, Cheng-Yang Fu, Xiaoliang Dai, Peizhao Zhang, Christoph Feichtenhofer, and Judy Hoffman. Token merging: Your vit but faster. In The Eleventh International Conference on Learning Representations, 2023. URL https://openreview.net/forum?id $=$ JroZRaRw7Eu. Harrison Chase. LangChain, 2022. URL https://github.com/hwchase17/langchain. Shouyuan Chen, Sherman Wong, Liangjian Chen, and Yuandong Tian. Extending context window of large language models via positional interpolation. ArXiv preprint, abs/2306.15595, 2023. URL https://arxiv.org/abs/2306.15595. Alexis Chevalier, Alexander Wettig, Anirudh Ajith, and Danqi Chen. Adapting language models to compress contexts. ArXiv preprint, abs/2305.14788, 2023. URL https://arxiv.org/ abs/2305.14788. Jiayu Ding, Shuming Ma, Li Dong, Xingxing Zhang, Shaohan Huang, Wenhui Wang, and Furu Wei. Longnet: Scaling transformers to 1,000,000,000 tokens. ArXiv preprint, abs/2307.02486, 2023. URL https://arxiv.org/abs/2307.02486. Qingxiu Dong, Lei Li, Damai Dai, Ce Zheng, Zhiyong Wu, Baobao Chang, Xu Sun, Jingjing Xu, and Zhifang Sui. A survey for in-context learning. ArXiv preprint, abs/2301.00234, 2023. URL https://arxiv.org/abs/2301.00234. Tao Ge, Jing Hu, Xun Wang, Si-Qing Chen, and Furu Wei. In-context autoencoder for context compression in a large language model. ArXiv preprint, abs/2307.06945, 2023. URL https: //arxiv.org/abs/2307.06945. Saurabh Goyal, Anamitra Roy Choudhury, Saurabh Raje, Venkatesan T. Chakaravarthy, Yogish Sabharwal, and Ashish Verma. Power-bert: Accelerating BERT inference via progressive word-vector elimination. In Proceedings of the 37th International Conference on Machine Learning, ICML 2020, 13-18 July 2020, Virtual Event, volume 119 of Proceedings of Machine Learning Research, pp. 3690–3699. PMLR, 2020. URL http://proceedings.mlr.press/v119/ goyal20a.html. Chi Han, Qifan Wang, Wenhan Xiong, Yu Chen, Heng Ji, and Sinong Wang. Lm-infinite: Simple on-the-fly length generalization for large language models. ArXiv preprint, abs/2308.16137, 2023. URL https://arxiv.org/abs/2308.16137. Gautier Izacard, Mathilde Caron, Lucas Hosseini, Sebastian Riedel, Piotr Bojanowski, Armand Joulin, and Edouard Grave. Unsupervised dense information retrieval with contrastive learning. Transactions on Machine Learning Research, 2022. ISSN 2835-8856. URL https: //openreview.net/forum?id ${ . } = { }$ jKN1pXi7b0. Huiqiang Jiang, Qianhui Wu, Chin-Yew Lin, Yuqing Yang, and Lili Qiu. Llmlingua: Compressing prompts for accelerated inference of large language models. In Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing. Association for Computational Linguistics, December 2023a. URL https://arxiv.org/abs/2310.05736. Zhiying Jiang, Matthew Yang, Mikhail Tsirlin, Raphael Tang, Yiqin Dai, and Jimmy Lin. “lowresource” text classification: A parameter-free classification method with compressors. In Findings of the Association for Computational Linguistics: ACL 2023, pp. 6810–6828, Toronto, Canada, 2023b. Association for Computational Linguistics. doi: 10.18653/v1/2023.findings-acl. 426. URL https://aclanthology.org/2023.findings-acl.426. Gyuwan Kim and Kyunghyun Cho. Length-adaptive transformer: Train once with length drop, use anytime with search. In Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing (Volume 1: Long Papers), pp. 6501–6511, Online, 2021. Association for Computational Linguistics. doi: 10.18653/v1/2021.acl-long.508. URL https://aclanthology.org/2021. acl-long.508. Tom Kwiatkowski, Jennimaria Palomaki, Olivia Redfield, Michael Collins, Ankur Parikh, Chris Alberti, Danielle Epstein, Illia Polosukhin, Jacob Devlin, Kenton Lee, Kristina Toutanova, Llion Jones, Matthew Kelcey, Ming-Wei Chang, Andrew M. Dai, Jakob Uszkoreit, Quoc Le, and Slav Petrov. Natural questions: A benchmark for question answering research. Transactions of the Association for Computational Linguistics, 7:452–466, 2019. doi: 10.1162/tacl a 00276. URL https://aclanthology.org/Q19-1026. Patrick S. H. Lewis, Ethan Perez, Aleksandra Piktus, Fabio Petroni, Vladimir Karpukhin, Naman Goyal, Heinrich Kuttler, Mike Lewis, Wen-tau Yih, Tim Rockt ¨ aschel, Sebastian Riedel, ¨ and Douwe Kiela. Retrieval-augmented generation for knowledge-intensive NLP tasks. In Hugo Larochelle, Marc’Aurelio Ranzato, Raia Hadsell, Maria-Florina Balcan, and HsuanTien Lin (eds.), Advances in Neural Information Processing Systems 33: Annual Conference on Neural Information Processing Systems 2020, NeurIPS 2020, December 6-12, 2020, virtual, 2020. URL https://proceedings.neurips.cc/paper/2020/hash/ 6b493230205f780e1bc26945df7481e5-Abstract.html. Dacheng Li, Rulin Shao, Anze Xie, Ying Sheng, Lianmin Zheng, Joseph E. Gonzalez, Ion Stoica, Xuezhe Ma, and Hao Zhang. How long can open-source llms truly promise on context length?, 2023a. URL https://lmsys.org/blog/2023-06-29-longchat. Jiaqi Li, Mengmeng Wang, Zilong Zheng, and Muhan Zhang. Loogle: Can long-context language models understand long contexts? ArXiv preprint, abs/2311.04939, 2023b. URL https:// arxiv.org/abs/2311.04939. Yucheng Li. Unlocking context constraints of llms: Enhancing context efficiency of llms with self-information-based content filtering. ArXiv preprint, abs/2304.12102, 2023. URL https: //arxiv.org/abs/2304.12102. Nelson F Liu, Kevin Lin, John Hewitt, Ashwin Paranjape, Michele Bevilacqua, Fabio Petroni, and Percy Liang. Lost in the middle: How language models use long contexts. ArXiv preprint, abs/2307.03172, 2023. URL https://arxiv.org/abs/2307.03172. Ali Modarressi, Hosein Mohebbi, and Mohammad Taher Pilehvar. AdapLeR: Speeding up inference by adaptive length reduction. In Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pp. 1–15, Dublin, Ireland, 2022. Association for Computational Linguistics. doi: 10.18653/v1/2022.acl-long.1. URL https://aclanthology.org/2022.acl-long.1. Jesse Mu, Xiang Lisa Li, and Noah Goodman. Learning to compress prompts with gist tokens. In Thirty-seventh Conference on Neural Information Processing Systems, 2023. URL https: //openreview.net/forum?id $=$ 2DtxPCL3T5. Erik Nijkamp, Tian Xie, Hiroaki Hayashi, Bo Pang, Congying Xia, Chen Xing, Jesse Vig, Semih Yavuz, Philippe Laban, Ben Krause, Senthil Purushwalkam, Tong Niu, Wojciech Krysci ´ nski, ´ Lidiya Murakhovs’ka, Prafulla Kumar Choubey, Alex Fabbri, Ye Liu, Rui Meng, Lifu Tu, Meghana Bhat, Chien-Sheng Wu, Silvio Savarese, Yingbo Zhou, Shafiq Joty, and Caiming Xiong. Xgen-7b technical report. ArXiv preprint, abs/2309.03450, 2023. URL https: //arxiv.org/abs/2309.03450. Joon Sung Park, Joseph C O’Brien, Carrie J Cai, Meredith Ringel Morris, Percy Liang, and Michael S Bernstein. Generative agents: Interactive simulacra of human behavior. ArXiv preprint, abs/2304.03442, 2023. URL https://arxiv.org/abs/2304.03442. Bowen Peng, Jeffrey Quesnelle, Honglu Fan, and Enrico Shippole. Yarn: Efficient context window extension of large language models. ArXiv preprint, abs/2309.00071, 2023. URL https:// arxiv.org/abs/2309.00071. Ofir Press, Noah Smith, and Mike Lewis. Train short, test long: Attention with linear biases enables input length extrapolation. In International Conference on Learning Representations, 2022. URL https://openreview.net/forum?id $_ { \cdot } =$ R8sQPpGCv0. Nils Reimers and Iryna Gurevych. Sentence-BERT: Sentence embeddings using Siamese BERTnetworks. In Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLPIJCNLP), pp. 3982–3992, Hong Kong, China, 2019. Association for Computational Linguistics. doi: 10.18653/v1/D19-1410. URL https://aclanthology.org/D19-1410. Uri Shaham, Maor Ivgi, Avia Efrat, Jonathan Berant, and Omer Levy. Zeroscrolls: A zero-shot benchmark for long text understanding. ArXiv preprint, abs/2305.14196, 2023. URL https: //arxiv.org/abs/2305.14196. Freda Shi, Xinyun Chen, Kanishka Misra, Nathan Scales, David Dohan, Ed H Chi, Nathanael Scharli, and Denny Zhou. Large language models can be easily distracted by irrelevant context. ¨ In International Conference on Machine Learning, pp. 31210–31227. PMLR, 2023. Yutao Sun, Li Dong, Shaohan Huang, Shuming Ma, Yuqing Xia, Jilong Xue, Jianyong Wang, and Furu Wei. Retentive network: A successor to transformer for large language models. ArXiv preprint, abs/2307.08621, 2023. URL https://arxiv.org/abs/2307.08621. Harsh Trivedi, Niranjan Balasubramanian, Tushar Khot, and Ashish Sabharwal. MuSiQue: Multihop questions via single-hop question composition. Transactions of the Association for Computational Linguistics, 2022. Szymon Tworkowski, Konrad Staniszewski, Mikołaj Pacek, Yuhuai Wu, Henryk Michalewski, and Piotr Miłos. Focused transformer: Contrastive training for context scaling. ´ ArXiv preprint, abs/2307.03170, 2023. URL https://arxiv.org/abs/2307.03170. Zhiyong Wu, Yaoxiang Wang, Jiacheng Ye, and Lingpeng Kong. Self-adaptive in-context learning: An information compression perspective for in-context example selection and ordering. ArXiv preprint, abs/2212.10375, 2022. URL https://arxiv.org/abs/2212.10375. Wenhan Xiong, Jingyu Liu, Igor Molybog, Hejia Zhang, Prajjwal Bhargava, Rui Hou, Louis Martin, Rashi Rungta, Karthik Abinav Sankararaman, Barlas Oguz, Madian Khabsa, Han Fang, Yashar Mehdad, Sharan Narang, Kshitiz Malik, Angela Fan, Shruti Bhosale, Sergey Edunov, Mike Lewis, Sinong Wang, and Hao Ma. Effective long-context scaling of foundation models. ArXiv preprint, abs/2309.16039, 2023. URL https://arxiv.org/abs/2309.16039.
# A TOKEN-LEVEL SUBSQUENCE RECOVERY DETAILS
Algorithm 1 Pseudo code of Token-level Subsquence Recovery.
Input: The original prompt $_ { \pmb { x } }$ ; the compressed prompt $\widetilde { \pmb x }$ ; the generation response of LLMs $\textbf { { y } }$ . 1: Set the final response list $y _ { \mathrm { r e c } } = \phi$ , the left token index of subsquence $l$ to 0. 2: while $l < { \bf { y } } . l e n ( )$ do 3: if Substring $y _ { l } \in \widetilde { \pmb x }$ then 4: eFind the longer substring $\widetilde { \pmb { y } } _ { \mathrm { k e y } , l } = \left\{ y _ { l } , y _ { l + 1 } , . . . , y _ { r } \right\} \in \widetilde { \pmb { x } }$ . 5: eFind the maximum common shortest subsequence $\pmb { x } _ { i , j } = \{ x _ { i } , x _ { i + 1 } , . . . , x _ { j } \}$ in the original prompt $_ { \textbf { \em x } }$ . 6: Add the subsequence $\pmb { x } _ { i , j } = \{ x _ { i } , x _ { i + 1 } , . . . , x _ { j } \}$ to the response $\scriptstyle { \pmb { y } } _ { \mathrm { r e c } }$ . 7: Set the left index $l$ to $r + 1$ . 8: else 9: Add the token $y _ { l }$ to the response $\scriptstyle { \pmb { y } } _ { \mathrm { r e c } }$ . 10: Set the left index $l$ to $l + 1$ . 11: end if 12: end while Output: The final response list $\scriptstyle { \pmb { y } } _ { \mathrm { r e c } }$ .
# B DERIVATION OF QUESTION-AWARE FINE-GRAINED COMPRESSION
Based on the definition of Eq. 3, we can derive that,
$$\begin{array} { r l } & { s _ { i } = \mathrm { p e r p l e x i t y } ( x _ { i } | { x } _ { < i } ) - \mathrm { p e r p l e x i t y } ( x _ { i } | { x } ^ { \mathrm { q u e } } , { x } _ { < i } ) } \\ & { \quad = q ( x _ { i } ) \log p ( x _ { i } | { x } ^ { \mathrm { q u e } } , { x } _ { < i } ) - q ( x _ { i } ) \log p ( x _ { i } | { x } _ { < i } ) } \\ & { \quad = q ( x _ { i } ) \log \frac { p ( x _ { i } | { x } ^ { \mathrm { q u e } } , { x } _ { < i } ) } { p ( x _ { i } | { x } _ { < i } ) } } \end{array}$$
In the actual calculation of perplexity, a log operation is performed to avoid overflow, and $\cdot$ represents the probability distribution of the ground-truth.
At the same time, we can derive the following expanded expression based on Bayes’ theorem.
$$p ( x ^ { \mathfrak { q } \mathfrak { u e } } | x _ { i } , x _ { < i } ) = { \frac { p ( x _ { i } | x ^ { \mathfrak { q } \mathfrak { u e } } , x _ { < i } ) p ( x ^ { \mathfrak { q } \mathfrak { u e } } ) } { p ( x _ { i } | x _ { < i } ) } } = p ( x ^ { \mathfrak { q } \mathfrak { u e } } ) { \frac { p ( x _ { i } | x ^ { \mathfrak { q } \mathfrak { u e } } , x _ { < i } ) } { p ( x _ { i } | x _ { < i } ) } }$$
The probability distribution $\cdot$ of the question and the ground-truth distribution $q ( x _ { i } )$ of $\cdot$ are constants, hence $s _ { i }$ can be considered as the representation of Eq. 7.
$$s _ { i } \propto p ( x ^ { \mathrm { q u e } } | x _ { i } , x _ { < i } )$$
So we can utilize Eq. 3 to represent the probability distribution $\_$ , which represents the condition likelihood of generating $x ^ { \mathrm { q u e } }$ given the token $\cdot$ . Therefore, we can represent the token-level sensitive distribution for the question $x ^ { \mathrm { q u e } }$ using just a single inference. For tokens that are unrelated to $x ^ { \mathrm { q u e } }$ , such as the tokens on the right side of Figure 3b, their original amount of information may be high, but the contrastive perplexity remains at a relatively low level.
# C EXPERIMENT DETAILS
# C.1 DATASET DETAILS
NaturalQuestions multi-document QA A multi-document question-answering dataset, comprising 2,655 problems, was built by Liu et al. (2023) based on the NaturalQuestions dataset (Kwiatkowski et al., 2019). This dataset provides a realistic retrieval-augmented generation setup that closely resembles commercial search and question-answering applications (e.g., Bing Chat). Each example in the dataset contains a question and $\mathbf { k }$ related documents, utilizing the Contriever retrieval system (Izacard et al., 2022), one of which includes a document with the correct answer. To perform this task, the model must access the document containing the answer within its input context and use it to answer the question. The dataset’s data is sourced from the NaturalQuestions dataset, which contains historical queries issued to the Google search engine and human-annotated answers extracted from Wikipedia. The average prompt token length in this benchmark is 2,946. For our experiments, we used the version provided by Liu et al. (2023) that includes 20 documents7. The dataset comprises five different ground truth document position settings in the prompt: 1st, 5th, 10th, 15th, and 20th.
LongBench A multi-task long context benchmark consists of 3,750 problems in English and includes six categories with a total of 16 tasks. These tasks encompass key long-text application scenarios, such as single-document QA, multi-document QA, summarization, few-shot learning, synthetic tasks, and code completion. The average prompt token length in this benchmark is 10,289. For our experiments, we used the English dataset and evaluation scripts provided by Bai et al. (2023) for this benchmark8.
ZeroSCROLLS The multi-task long context benchmark consists of 4,378 problems, including four categories with a total of 10 tasks. These tasks cover summarization, question answering, aggregated sentiment classification, and information reordering. The average prompt token length in this benchmark is 9,788. For our experiments, we used the validation set and evaluation scripts provided by Shaham et al. (2023) for this dataset9.
MuSiQue The multi-hop question-answer dataset is composed of 39,876, 4,834, and 4,918 problems in the training, validation, and testing datasets, respectively. This dataset requires the language model to conduct multiple inferences based on the content of several documents and provide corresponding answers, thereby necessitating a certain capability for global information processing. The average token length for prompts in this dataset is 2,477. For our experiments, we utilized the validation set and evaluation scripts provided by Trivedi et al. (2022) for this dataset10.
LooGLE The multi-task long context benchmark comprises 6,448 problems, divided into three categories: summarization, short dependency question answering, and long dependency question answering. The average prompt token length in this benchmark stands at 24,005. For our experiments, we focused on the long dependency question answering subset, which includes four types of tasks: information retrieval, timeline reordering, computation, and comprehension. This subset contains 1,101 problems. We utilized the evaluation scripts provided by Li et al. (2023b) for this dataset11.
# C.2 OTHER IMPLEMENTATION DETAILS
All experiments were conducted using a Tesla V100 (32GB). We use tiktoken12 and GPT-3.5-Turbo model to count all the tokens. We set the granular control coefficient $k$ to 2. We use the pre-defined compression rates $\tau _ { \mathrm { i n s } } ~ = ~ 0 . 8 5$ and $\tau _ { \mathrm { q u e } } = 0 . 9$ for instructions and questions. The segment size used in the iterative token-level compression is set to 200. The $\delta \tau$ used in dynamic compression ratio is set to 0.25. For a fair comparison, we only used reordering in the NaturalQuestions Multidocument QA and noted this in Table 1. We use “We can get the answer to this question in the given documents.” as the guideline sentence in Equation (3).
For the baselines experiment, we use the currently recommended strongest model, all-mpnetbase- $. \mathbf { V } 2 ^ { 1 3 }$ , as the dense representation model for SentenceBERT. We use the recommended “textembedding-ada-002” as the embedding model for OpenAI Embedding14. We use the GPT2-dolly15 as the small language model in w/ GPT2-small ablation experiments.
D ADDITIONAL EXPERIMENTAL RESULTS
# D.1 DOCUMENT-LEVEL AVERAGE PERPLEXITY DISTRIBUTION
 Figure 5: The distribution of document-level average perplexity when the ground-truth document is in different positions.
Figure 5 shows the distribution of the document’s average perplexity when the ground-truth is located at different positions within the prompt. As can be observed, as the context length increases, the original perplexity curve remains relatively stable. In unrelated documents, a higher perplexity is still retained, making it easier to remove relevant tokens from the related documents in the prompt compression process, thereby damaging the corresponding semantic information. Contrarily, contrastive perplexity shows an increase in perplexity in documents related to the question. According to the theoretical derivation in Appendix B, it’s known that contrastive perplexity characterizes the conditional probability of tokens corresponding to the question. The higher the relevance, the higher the contrastive perplexity, thereby retaining key information in the prompt compression process.
# D.2 ZEROSCROLLS BREAKDOWNS
Table 4: Performance breakdown of different methods under different compression ratios on ZeroSCROLLS (Shaham et al., 2023) using GPT-3.5-Turbo.
<table><tr><td>Methods</td><td>GvRp SSFD QMsm SQAL QALT Nrtv Qspr MuSQ SpDg BkSS AVG|Tokens1/T</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td colspan="10">3,000 tokens constraint</td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>Retrieval-based Methods</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>BM25</td><td>9.7</td><td>3.4</td><td>11.7</td><td>14.3</td><td>57.1</td><td>5.9</td><td>25.7</td><td>11.2</td><td>29.6</td><td>29.6</td><td>19.8</td><td>3.379</td><td>3x</td></tr><tr><td>SBERT</td><td>16.5</td><td>9.8</td><td>12.3</td><td>15.2</td><td>60.0</td><td>14.623.4</td><td></td><td>12.1</td><td>39.4</td><td>36.4</td><td>24.0</td><td>3.340</td><td>3x</td></tr><tr><td>OpenAI</td><td>14.3</td><td>8.3</td><td>12.0</td><td>15.3</td><td>66.7</td><td>13.324.3</td><td></td><td>11.7</td><td>31.2</td><td>26.4</td><td>22.4</td><td>3,362</td><td>3x</td></tr><tr><td>LongLLMLingua rk</td><td>19.5</td><td>11.6</td><td>14.7</td><td>15.5</td><td>66.7</td><td>20.527.6</td><td></td><td>13.0</td><td>60.8</td><td>43.4</td><td>29.3</td><td>3,350</td><td>3x</td></tr><tr><td colspan="10">Compression-based Methods</td><td></td><td></td><td></td><td></td></tr><tr><td>Selective-Context</td><td>20.8</td><td>9.1</td><td>11.7</td><td>13.4</td><td>50.0</td><td>9.826.1</td><td></td><td>11.0</td><td>46.0</td><td>9.5</td><td>20.7</td><td>3,460</td><td>3x</td></tr><tr><td>LLMLingua</td><td>18.7</td><td>10.0</td><td>14.9</td><td>16.8</td><td>61.9</td><td>26.927.2</td><td></td><td>23.4</td><td>62.9</td><td>44.5</td><td>30.7</td><td>3.366</td><td>3x</td></tr><tr><td>LongLLMLingua </td><td>21.9</td><td>12.7</td><td>15.5</td><td>17.0</td><td>66.9</td><td>27.6 31.1</td><td></td><td>23.8</td><td>65.6</td><td>46.4</td><td>32.8</td><td>3.412</td><td>3x</td></tr><tr><td colspan="10">2,000 tokens constraint</td><td></td><td></td><td></td><td></td></tr><tr><td colspan="10">Retrieval-based Methods</td><td></td><td></td><td></td><td></td></tr><tr><td>BM25</td><td>8.8</td><td>2.5</td><td>11.1</td><td>13.5</td><td>60.0</td><td>7.0</td><td>4.9</td><td>20.3</td><td>39.9</td><td>32.9</td><td>20.1</td><td>1,799</td><td>5x</td></tr><tr><td>SBERT</td><td>10.2</td><td>7.9</td><td>13.7</td><td>13.2</td><td>60.0</td><td>8.1</td><td>10.8</td><td>1.7</td><td>37.2</td><td>42.8</td><td>20.5</td><td>1,773</td><td>6x</td></tr><tr><td>OpenAI</td><td>11.1</td><td>8.0</td><td>11.8</td><td>13.6</td><td>60.0</td><td>7.1</td><td>13.2</td><td>4.0</td><td>33.6</td><td>43.6</td><td>20.6</td><td>1,784</td><td>5x</td></tr><tr><td>LongLLMLingua rk</td><td>18.2</td><td>9.8</td><td>12.3</td><td>15.9</td><td>57.1</td><td>10.1 17.8</td><td></td><td>7.3</td><td>57.7</td><td>42.3</td><td>24.9</td><td>1,771</td><td>6x</td></tr><tr><td colspan="10">Compression-based Methods</td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>Selective-Context</td><td>19.0</td><td>8.4</td><td>9.7</td><td>12.4</td><td>47.0</td><td>12.5 21.6</td><td></td><td>11.5</td><td>41.2</td><td>11.0</td><td>19.4</td><td>1,865</td><td>5x</td></tr><tr><td>LLMLingua</td><td>19.4</td><td>11.9</td><td>13.1</td><td>16.0</td><td>62.1</td><td>23.724.0</td><td></td><td>22.4</td><td>33.9</td><td>44.9</td><td>27.2</td><td>1,862</td><td>5x</td></tr><tr><td>LongLLMLingua</td><td>19.9</td><td>12.3</td><td>14.7</td><td>16.5</td><td>64.9</td><td>27.4 30.6</td><td></td><td>23.5</td><td>68.3</td><td>47.1</td><td> 32.5</td><td>1,809</td><td>6x</td></tr><tr><td>Original Prompt</td><td>21.8</td><td>12.1</td><td>17.9</td><td>17.4</td><td>66.7</td><td>25.329.8</td><td></td><td>20.0</td><td>69.7</td><td>44.1</td><td>32.5</td><td>9.788</td><td>-</td></tr><tr><td>Zero-shot</td><td>9.4</td><td>3.0</td><td>8.6</td><td>11.4</td><td>42.9</td><td>10.612.4</td><td></td><td>5.5</td><td>4.2</td><td>0.0</td><td>12.8</td><td>32</td><td>306x</td></tr></table>
Table 4 presents a detailed performance breakdown on the ZeroSCROLLS benchmark. It can be observed that in the four summarization tasks - GvRp, SSFD, QMsm, SQAL, LongLLMLingua closely matches or slightly surpasses the original results under two compression constraints. Meanwhile, in the four long context QA tasks - Qsqr, Nrtv, QALT, MuSQ, there is a significant improvement. Notably, in the MuSiQue task, which is based on a question-answering dataset from books and movie scripts, there is a 2.1 point increase even under a 2,000 tokens constraint. It’s worth mentioning that MuSiQue is a multi-hop question-answering dataset that requires LLMs to utilize global information for long dependency QA. LongLLMLingua can also improve by 3.5 points under a 6x compression ratio. In the two ordering tasks, SpDg and BkSS, LongLLMLingua can better retain globally sensitive information, resulting in a 3.0 point improvement in BkSS after prompt compression.
It’s important to note that although the ZeroScrolls validation dataset is relatively small, it still demonstrates conclusions similar to previous experimental observations across various methods and tasks. Furthermore, this study conducted an in-depth analysis of the multi-hop QA task - MuSiQue, and another long context benchmark - LooGLE. The results can be found in Appendix D.3 and Appendix D.6.
# D.3 MUSIQUE
Table 5 presents the results from the MuSiQue multihop question-answer dataset. From the table, it can be observed that in the multi-hop QA task, requiring global information: 1) LongLLMLingua can reduce noise in the prompt by eliminating irrelevant information and putting more related information at the beginning or end of the prompt, thereby improving performance by 5.4 points. 2) The performance drop is more pronounced for retrievalbased methods, particularly for n-gram-based methods like BM25. Due to long dependencies, direct matching information is lost, resulting in less relevant information being recalled. 3) The performance of compression-based methods is slightly different. Selective-Context does not distinguish between different modules’ sensitivity, resulting in a loss of question and instruction-related information, thereby leading to poorer performance. However, LLMLingua can still retain relevant key information at around a $\cdot$ compression ratio. 4) The ablation experiments show that every module designed in LongLLMLingua plays a role in the multi-hop task. The removal of the question-aware coarse-grained and w/ $\cdot$ modules, which have difficulty in perceiving the importance distribution of corresponding questions, can cause a drop of up to 8 points. Removing the restrict prompt in the question-aware coarse module can also cause a 2-point drop due to the hallucination issue of small LLM. In addition, removing question-aware fine-grained, dynamic compression ratio, and document reordering can all cause a drop of 0.5-2.8 points. 5) Moreover, if the small language model in LongLLMLingua is replaced with GPT2-small, it can further improve the acceleration ratio and still achieve a result that is 2.6 points better than the original prompt.
Table 5: Performance of different methods and ablation study on MuSicQue (Trivedi et al., 2022) with 2x constraint using GPT3.5-Turbo.
<table><tr><td>Methods</td><td></td><td>F1 Tokens 1/T</td></tr><tr><td>Original Prompt</td><td>45.8 2,427</td><td></td></tr><tr><td>BM25</td><td></td><td>28.51,295 1.9x</td></tr><tr><td>SBERT</td><td></td><td>36.2 1,288 1.9x</td></tr><tr><td>LongLLMLingua rk</td><td>46.3 1,295 1.9x</td><td></td></tr><tr><td>Selective-Context LLMLingua</td><td>19.6 1,141 2.1x</td><td></td></tr><tr><td>LongLLMLingua</td><td>40.1 1,110 2.2x</td><td></td></tr><tr><td>Question-aware Coarse-grained</td><td></td><td>51.2 1,077 2.3x</td></tr><tr><td>- w/o Question-awareness</td><td></td><td>43.2 1,076 2.3x</td></tr><tr><td>- w/SBERT</td><td></td><td>47.31,070 2.3x</td></tr><tr><td>-w/ p(xe|a cxquersriet</td><td></td><td>44.0 1,066 2.3x</td></tr><tr><td>- w/o restrict</td><td></td><td>49.2 1,078 2.3x</td></tr><tr><td>- w/o Question-aware Fine-grained 48.4 1,118 2.2x - w/o Dynamic Compression Ratio 48.2 1,090 2.2x</td><td></td><td></td></tr><tr><td>- w/o Subsequence Recovery</td><td></td><td></td></tr><tr><td></td><td></td><td>50.7 1,077 2.3x</td></tr><tr><td>- w/o Document Reordering</td><td></td><td>49.2 1,077 2.3x</td></tr><tr><td>- w/ GPT2-small</td><td></td><td>48.4 1,095 2.2x</td></tr></table>
# D.4 ABLATION IN LONGBENCH
Table 6 presents the results from the ablation experiment in the LongBench long context benchmark. It can be observed that in various long context tasks: 1) Removing the question-aware coarsegrained, question-aware fine-grained, dynamic compression ratio, document reordering, and subsequence recovery proposed by LongLLMLingua all result in different degrees of performance drop. 2) Among these, question-aware coarse-grained is particularly important for document-based QA and synthetic tasks, with the maximum drop being 35.8 points; its impact on summarization and code tasks is relatively smaller. 3) The design of the conditional probability in the question-aware coarse-grained module improves the results in all tasks, including code completion, single-document question-answer, and synthetic tasks. Changing the order of conditional probabilities or removing the restrict prompt both lead to varying degrees of performance decline. 4) Removing questionaware fine-grained, dynamic compression ratio has a more significant impact on document-based QA and synthetic tasks. 5) The subsequence recovery module can enhance reference-based tasks, but its improvement on tasks like summarization, code, synthetic, etc., is relatively smaller. 6) Document reordering is effective for all types of tasks. Reordering at the document level does not affect LLMs’ understanding of context information, even for timeline-related tasks (see timeline reorder in LooGLE, Table 8). On the contrary, reordering can effectively alleviate the “lost in the middle” issue, thereby improving LLMs performance. 7) Using GPT2-small reduces the capture of effective tokens, but it can still achieve results close to or even slightly better than the original prompt.
Table 6: Ablation on LongBench (Bai et al., 2023) using GPT-3.5-Turbo.
<table><tr><td>Methods</td><td>|SingleDoc MultiDoc Summ.FewShot Synth. Code AVG Tokens1/T</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>LongLLMLingua</td><td>39.0</td><td>42.2</td><td>27.4</td><td>69.3</td><td>53.8</td><td>56.6</td><td>48.0</td><td>1,809</td><td>6x</td></tr><tr><td>Question-aware Coarse-grained</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>- w/o Question-awareness</td><td>27.1</td><td>38.7</td><td>25.4</td><td>62.0</td><td>18.0</td><td>53.3</td><td>37.4</td><td>1,945</td><td>5x</td></tr><tr><td>- w/ SBERT</td><td>34.0</td><td>38.7</td><td>24.1</td><td>57.9</td><td>32.5</td><td>31.1</td><td>36.4</td><td>1790</td><td>6x</td></tr><tr><td>-w/p(xget</td><td>22.5</td><td>28.9</td><td>23.2</td><td>53.0</td><td>22.5</td><td>33.3</td><td>30.6</td><td>1,794</td><td>6x</td></tr><tr><td>- w/o restrict</td><td>37.8</td><td>39.5</td><td>26.4</td><td>64.8</td><td>52.5</td><td>55.8</td><td>46.1</td><td>1,834</td><td>6x</td></tr><tr><td>- w/o Question-aware Fine-grained</td><td>35.7</td><td>41.1</td><td>26.4</td><td>62.9</td><td>44.5</td><td>54.8</td><td>44.2</td><td>1,807</td><td>6x</td></tr><tr><td>- w/o Dynamic Compression Ratio</td><td>36.1</td><td>40.6</td><td>26.9</td><td>67.2</td><td>48.0</td><td>55.8</td><td>45.7</td><td>1,851</td><td>6x</td></tr><tr><td>- w/o Subsequence Recovery</td><td>38.6</td><td>41.8</td><td>27.3</td><td>69.0</td><td>53.8</td><td>56.6</td><td>47.8</td><td>1,809</td><td>6x</td></tr><tr><td>- w/ Document Reordering</td><td>39.9</td><td>43.2</td><td>27.4</td><td>69.8</td><td>53.0</td><td>56.7</td><td>48.3</td><td>1,822</td><td>6x</td></tr><tr><td>- w/ GPT2-small</td><td>35.9</td><td>39.4</td><td>25.0</td><td>60.6</td><td>42.0</td><td>55.4</td><td>43.0</td><td>1,892</td><td>5x</td></tr></table>
# D.5 LONGBENCH USING LONGCHAT-13B-16K
Table 7: Performance of different methods under different compression ratios on LongBench (Bai et al., 2023) using LongChat-13b. Considering the dataset structure, we do not use the reordering strategy here.
<table><tr><td>Methods</td><td>| SingleDoc MultiDoc Summ. FewShot Synth. Code AVG Tokens 1/T</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>Original Prompt</td><td>27.4</td><td>30.3</td><td>20.3</td><td>49.9</td><td>12.5</td><td>42.5</td><td>30.5</td><td>10,295</td><td></td></tr><tr><td colspan="10">Retrieval-based Methods</td></tr><tr><td>BM25</td><td>2.4</td><td>2.6</td><td>16.4</td><td>8.7</td><td>0.0</td><td>44.7</td><td>12.5</td><td>1,985</td><td>5x</td></tr><tr><td>SBERT</td><td>11.6</td><td>13.7</td><td>21.1</td><td>16.2</td><td>7.5</td><td>30.0</td><td>16.7</td><td>1,947</td><td>5x</td></tr><tr><td>LongLLMLingua rk</td><td>30.3</td><td>32.4</td><td>24.5</td><td>41.0</td><td>27.5</td><td>38.1</td><td>32.3</td><td>1,960</td><td>5x</td></tr><tr><td colspan="10">Compression-based Methods</td></tr><tr><td>Selective-Context</td><td>16.1</td><td>23.5</td><td>21.8</td><td>21.4</td><td>2.5</td><td></td><td>35.920.2</td><td>1,925</td><td>5x</td></tr><tr><td>LLMLingua</td><td>20.6</td><td>22.3</td><td>22.4</td><td>35.6</td><td>0.0</td><td>35.4</td><td>22.7</td><td>1,950</td><td>5x</td></tr><tr><td>LongLLMLingua</td><td>31.1</td><td>34.1</td><td>24.5</td><td> 45.7</td><td>28.0</td><td>48.6</td><td>35.3</td><td>1,809</td><td>6x</td></tr></table>
Table 7 presents the experiment results in the LongBench long context benchmark using LongChat13b-16k. It can be seen that the compressed prompt can also achieve good results on other LLMs, such as LongChat-13b-16k. Specifically, 1) there is a maximum improvement of 15.5 points in synthetic tasks. Except for a slight drop in few-shot Learning, there is an improvement of 3-5 points in other tasks. 2) The performance trends of retrieval-based and compressed-based baselines are similar to the results in GPT-3.5-Turbo.
# D.6 LOOGLE
Table 8 presents the experiment results in the LooGLE long dependency benchmark, which features longer prompts $\cdot$ and more global dependencies. From the table, we can observe that: 1) LongLLMLingua can effectively improve the performance of long context tasks by compressing prompts, even for long dependency tasks. The results show that LongLLMLingua significantly improves performance in tasks such as retrieval, timeline reorder, and computation, with the maximum improvement reaching 15.9 points. 2) The document reorder in LongLLMLingua is effective in all types of tasks, even in tasks highly related to the timeline, it can effectively improve performance by alleviating the “lost in the middle” issue. 3) Retrieval-based methods tend to lose performance in tasks that have longer dependencies, such as computation and reasoning. 4) For compressionbased methods, due to the difficulty in perceiving question information, there tends to be a larger performance loss in retrieval tasks within long contexts.
Table 8: Performance of different methods on LooGLE (Li et al., 2023b) long dependency QA.
<table><tr><td>Methods</td><td></td><td>Retrieval Timeline Reorder Computation Reasoning AVG Tokens</td><td></td><td></td><td></td><td></td><td>1/T</td></tr><tr><td>Retrieval-based Methods</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>BM25</td><td>20.4</td><td>21.7</td><td>8.2</td><td>26.3</td><td>19.2</td><td>3,185</td><td>10x</td></tr><tr><td>SBERT</td><td>28.9</td><td>21.1</td><td>10.7</td><td>27.2</td><td>22.0</td><td>3,169</td><td>10x</td></tr><tr><td>LongLLMLingua rk</td><td>38.6</td><td>32.2</td><td>16.2</td><td>26.3</td><td>28.3</td><td>3,158</td><td>10x</td></tr><tr><td>Compression-based Methods</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>Selective-Context</td><td>16.7</td><td>5.0</td><td>2.3</td><td>17.6</td><td>10.4</td><td>3,710</td><td>8x</td></tr><tr><td>LLMLingua</td><td>10.0</td><td>25.0</td><td>13.3</td><td>21.1</td><td>17.3</td><td>3,404</td><td>9x</td></tr><tr><td>LongLLMLingua</td><td>40.0</td><td> 35.0</td><td>19.7</td><td>33.6</td><td> 32.1</td><td>3,121</td><td>10x</td></tr><tr><td> LongLLMLingua w/o Reorder</td><td>39.3</td><td>33.8</td><td>18.7</td><td>31.6</td><td>30.9</td><td>3,119</td><td>10x</td></tr><tr><td>Original Prompt</td><td>24.1</td><td>20.9</td><td>13.5</td><td>32.1</td><td></td><td>22.630.546</td><td>1</td></tr><tr><td>Zero-shot</td><td>8.7</td><td>6.3</td><td>1.2</td><td>14.5</td><td>7.7</td><td>43</td><td>710x</td></tr></table>
# E ECONOMIC COST
Table 9: The inference costs(per 1,000 samples $\$ 1$ ) for various datasets using GPT-3.5-Turbo.
<table><tr><td></td><td>Multi-document QA</td><td>LongBench</td><td>ZeroScolls</td><td>MuSicQue</td><td>LooGLE</td></tr><tr><td>Original</td><td>4.6</td><td>31.5</td><td>30.6</td><td>3.8</td><td>93.6</td></tr><tr><td>Ours</td><td>1.3</td><td>3.0</td><td>3.2</td><td>1.8</td><td>5.6</td></tr></table>
Table 9 presents the estimated per 1,000 samples inference costs for various datasets, encompassing input prompts and generated output text, based on GPT-3.5-Turbo pricing16. Our approach demonstrates substantial savings in computational resources and monetary expenses, particularly in long context situations. Cost reductions of $\$ 3.3$ , $\$ 28.5$ , $\$ 27.4$ , $\$ 2.0$ , and $\cdot$ per 1,000 samples are observed for Multi-document QA, LongBench, ZeroScrolls, MuSiQue, and LooGLE, respectively.
F ABLATION ANALYSIS G CASES STUDY
 Figure 6: Comparing the compressed prompt and LLMs’ response before and after using Questionaware Fine-grained Compression and Subsequence Recovery ${ \mathrm { 1 / } } \tau \mathrm { = } 3 0 \mathrm { x }$ , high compression ratio setting) from NaturalQuestions Multi-document QA (Liu et al., 2023) using GPT-3.5-Turbo.
# Original Prompt:
Document [1](Title: Dancing on Ice) It was confirmed on 25 January 2018, that Dancing on Ice had been recommissioned for an eleventh series to air in 2019.
Compressed Prompt: Write a high-quality answer for the given question using only the provided search results (some of which might be irrelevant). 1Title: Dancing on was confirmed on 2 January 2018 that Dancing on had been recommissioned for an eleventh series air in 209 . Document [2Title: Dan on) Dan on Ice Dancing on British presented by Phillip Schof alongside Holly Willough from 26 to 2011, and Christine Bleakley from 2012 to 204 The show consists of celebrit and professional partners figure skating in front of a panel of judges The, broadcast on ITV, started on January 2006 and ended on 9 March 2014 after showcontract not renewed by ITV On 4 September 2017, it was announced that rev series ´ would on I 7 January 201 Sch and Willby returning as a 5(: on ( on () The third series of a from January to168TV. The from Saturdays, with Holby present Kar,y Sliner Robin Cins returned to Panel”, with Ruth H joining the panel as replacement for Natalia Bestova. The commission of the was confirmed by at the07 announcedova depart the series Robinen Bar,ater and Jasoniner announced 7( on ( )) Dan 2 second of Dan on a from January to1207 ITV It presented Phillip Sch Holly Willough, and judged the ”I P consisting Nicky Slater, Nataliaian Karenres Jason Gardiner Karen Barber and Robin Cousins Jaynevill and Christopher Dean co and trained the contestants In this series, cele to ten in first series. The series was won former Kyran Bracken, with Mel Lambert the winner. It announced thatenresge Document []( on Ice on 08 on TV edition started 8 TV2 The Russian version ”анду) being on channel0, and renamed in8 to ” Ice” (). Its counterpart called ”Ice Age (, ”Stars on Ice on Channel Oneak IceHviezdyˇlJ. The Turkish version” is called Dans” (”ance on Document1 on Ice its, all,e () and Sje Chris de In series.2 edition ´ ](: on Ice world) Dan Ice is a made competition world format, and been subsequently Italy Chile where titled after series There have a, the show was broadcast on Channel 13 as a Document [17](Title: Dancing on Ice) the insight to the training of the celebrities over the last week. It was presented by television presenter Ben Shephard and former contestant and ”Loose Women” star Coleen Nolan. The show was broadcast from $8 ~ \mathrm { p m }$ to $8 . 3 0 \ \mathrm { p m }$ on Friday evenings on ITV throughout the duration of the main shows season. STV who broadcast the main show did not broadcast this on the Friday evening but after repeating the previous weeks main show on the following Saturday afternoon. Due to poor ratings, ´ ”Dancing on Ice Friday” was axed prior to the 2011 series. The show was based in the Question: when is dancing on ice on the tv Answer: LLMs’ Response: 209 LLMs’ Response after Subsquence Recovery: 2019 Ground Truth: 2019 Compressed Prompt: Please complete the code given below. public class MessageArchiveManagement private static final long MILLISECONDS_IN_DAY = 24 \* 00 \*0; public static final long_CUP $=$ MCON_DAY /.../ .("",.getStart add ifget() ${ > } 0$ Node end(" end.(" endNode.Value("", Util.getTimestamp(query.getEnd addNode } if (.withid null && contact null && !isference Node with(" .with .Value("valuewith .( // queryMessageive(connection, nextQuery final(connectionProtocol(), query synchronized (eries) // queries.add(nextQuery } } public boolean queryInProgress( contact, OnLoaded moreMessagesLoadedListener) ized (eries) (Query query : queries) if(query.getWith().equals(contact.getUserId())) if (query.onMoreMessagesLoaded $= =$ null &&MessagesListener null) query.setOnMoreMessagesLoaded(Listener} return true;}} return false;}} private void finalizeQuery(Protocol protocol, Query query) synchronized (queries) { .remove(query); } Contact contact $=$ null; if (query.getWith() ! $=$ null) { contact $=$ protocol.getItemByUID(query.getWith()); } if (contact ! $=$ null) { Next line of code:
contact.setLastMessageTransitted(query.getEnd());\n
# Ground Truth:
if (contact.setLastMessageTransmitted(query.getEnd()))
Zero-shot LLMs’ Response: contact.removeQuery(query);\n
Figure 8: Cases study on lcc code completion task in LongBench benchmark (Bai et al., 2023) in 2,000 constraint using GPT-3.5-Turbo.
# Compressed Prompt:
Please the of the question. questions are sometimes your cold but the of you isnt:ason: What food hasges:: Who the first coach the Clevelandns What arch the Placede: Other: Who created Harryime What Carbean cult didvey:: did Iraqi troops::ose cover is of an of Universal Import What the of Betty theest thectic:: Wh the founder and of The National Review:: was T Tims What the historicalals following the of Agra is whiteolate: of What the the: is a of everything:ase and:ose old London come- was : “y my sweet:: The major team in is called: Group or organization of: How dorow: M of: the name to ofese ?: Animal: is gymnia: of the between k and ch: of: the lawyer for Randy C:: the Francisco What year the in whereci became What country most is g the Who the to P What are the states the the name , Elino: What manmade waterways is1.76: Other of Z:ivalent of: of What was the:: How do ants have: of: the Dow first the high sound that hear in ear every then , but then it away ,:: didist control in:: How can I ofies ’ What did theramid-ers of Egypt eat:: How does Belle her inast: M of: When reading classs does EENTY :: Expression abbre: When was Florida:: manyelies were killed the: Whative on Punchl Hill and has1 What the Filenes the cookies in Internet: What word contains: Word with a special is Larry: a person: a Frenchist: of What American wrote : “ Goodors:: Where theiestk rail stations:: many people ofosis: the worsticane Whatbean is of was Jean: What the2 What caused Harryini What buildingately enough the the1d bill: Other location: many logmic there a rule:: the the word , JJ the average hours per months byOL:: How a cop of: many are of is Ch:: is Whatation does: the the Whatte is “ a whole new: Other: the Chyl nuclear: the first the: Invention, book and otherative What does “ Philebus-:: didoco painting: the between: is Po What. the lowest highestation 6:: How the inpy: an the “ What was General Douglasthur in was by Presidentuman: How isaster: an the forini:: was Dick:: Where can find on religion and health the and: Other Whatian the TV51 theBC show for How the is of What Englishrighted “ thee , so What song put James:ative piece What new school in Philadelphia: Whatwestern isbed is B: is What Asian was as The Little Brown theans What of thean meeting: is: much the91 ?:: On which isbor: Who first:: the:: How you a paint: an What then-der theterset ,:ivalent What is to hold the lens the the star: Why toason a for behavior , or that the accepted of:ivalent of Perg What religion What country you the What does V:: Where I a goodboard for:: buyies on the the the: areter cookiespped with cres: theoe thated ofasticitations , as ‘ the rules to “: the three What do for an:: CNN in:: is a:ose special bears was on17 the Who used Au an electionan: what book: is to the various ways can measure IT:chni and method is software What British minister and wereins: aic the to overcome fear What drink would the biggest:: the States do people longest:: which the the rare disease as : , andentizations , , and is of a is What Russian mastery What a perfect a: What c was Thomas in: Other: did the of What did What can feature the different:ques the-O the ons lips at What anetic did Victoria used her child: D What do: many from to of ofors , body: and is What causes get in: the G What is Other Who the1 century-stone who gained of Florence but endedake: of c: the oldest relationship sister with The the world of a to detectchni Whaty make:: Stuart
is first: is w What a character by Rs
Question: What is a fuel cell ? Type: LLMs’ Response: Definition of something LLMs’ Response after Subsquence Recovery: Definition of something
Ground Truth: Definition of something123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352# DELTA-LORA: FINE-TUNING HIGH-RANK PARAMETERS WITH THE DELTA OF LOW-RANK MATRICES
Anonymous authors Paper under double-blind review
# ABSTRACT
In this paper, we present Delta-LoRA, which is a novel parameter-efficient approach to fine-tune large language models (LLMs). In contrast to LoRA and other low-rank adaptation methods such as AdaLoRA, Delta-LoRA not only updates the low-rank matrices $\pmb { A }$ and $\textbf { { B } }$ , but also propagate the learning to the pre-trained weights $W$ via updates utilizing the delta of the product of two low-rank matrices $( \boldsymbol { A } ^ { ( \bar { t } + 1 ) } \boldsymbol { B } ^ { ( t + 1 ) } - \boldsymbol { A } ^ { ( t ) } \boldsymbol { B } ^ { ( t ) } )$ . Such a strategy effectively addresses the limitation that the incremental update of low-rank matrices is inadequate for learning representations capable for downstream tasks. Moreover, as the update of $W$ does not need to compute the gradients of $W$ and store their momentums, Delta-LoRA shares comparable memory requirements and computational costs with LoRA. Extensive experiments show that Delta-LoRA significantly outperforms existing low-rank adaptation methods. We further support these results with comprehensive analyses that underscore the effectiveness of Delta-LoRA.
# 1 INTRODUCTION
Large Language Models (LLMs) recently have attracted considerable attention due to their remarkable performance across a broad spectrum of downstream tasks. Diverging from conventional Transformers characterized by a scale of millions of parameters, modern LLMs typically scale up to billions of parameters, endowing them with notable advantages such as emergent capabilities and robust generalization as detailed in (Bubeck et al., 2023). Fine-tuning such highly capable LLMs on downstream tasks (Raffel et al., 2020; Devlin et al., 2019; Radford et al., 2019; He et al., 2021; Liu et al., 2019; Brown et al., 2020) has consequently become a mainstream paradigm to reduce the training time required for individual tasks, yet with superior performance compared with other methods (Lester et al., 2021; Li & Liang, 2021; Houlsby et al., 2019).
However, fine-tuning a LLM with all the learnable parameters (Full Fine-tuning) requires multiple GPUs with high memory demand (Dettmers et al., 2023; Hu et al., 2022), which is unattainable for many companies and research institutions. Full fine-tuning poses exceptional challenges to researchers: with massive parameter size, LLMs already demand more storage space than regular models; Further training exaggerates the GPU memory requirement because common optimizers such as AdamW (Loshchilov & Hutter, 2019) often maintain several copies of the model parameters, which is 2-3 times of memory overhead.
To this end, a series of methods have been proposed (Valipour et al., 2023; Zhang et al., 2022; Li & Liang, 2021; Liu et al., 2022a; Lv et al., 2023; Dettmers et al., 2023; Liu et al., 2022b; Zaken et al., 2021; Pfeiffer et al., 2021; Guo et al., 2021; Zhou et al., 2023; Zhang et al., 2023; Houlsby et al., 2019; Wang et al., 2022) to reduce memory overhead at the training stage. Some even accelerate the fine-tuning process with only less than $1 \%$ trainable parameters. Among these methods, LoRA (Hu et al., 2022) is the most attractive for its stable performance on broad downstream tasks (Ding et al., 2023), no observed overfitting, as well as no extra memory and computation cost at inference.
While LoRA and its successors (Zhang et al., 2022; Valipour et al., 2023) have indeed exhibited superior performance in comparison to alternative approaches within the realm of Parameter Efficient Fine-Tuning (PEFT), a substantial performance gap persists when compared to the full fine-tuning, as highlighted in most scenarios (Ding et al., 2023). This discrepancy is attributed to the inherent limitation of updating only a fraction of the model’s parameters, rendering it inadequate to fit the intricacies presented in the training data.
 Figure 1: An overview of the proposed Delta-LoRA structure, compared to LoRA, DyLoRA and AdaLoRA. Note that DyLoRA and LoRA basically share the same architecture. W is the pre-trained weight which is frozen (signified by blue) when performing efficient-parameter fine-tuning in (a) and (b). Orange trapezoids $\pmb { A }$ , $\textbf { { B } }$ and $\pmb { \cal E }$ denote the trainable parameters. In our proposed Delta-LoRA, the light orange rectangle means that pre-trained weights can be updated via the delta. Note that our proposed Delta-LoRA removes the Dropout layer to ensure reasonable delta for pre-trained matrix.
To bridge this gap, a reasonable strategy is to introduce more parameters into the optimization process. In this paper, we introduce Delta-LoRA as shown in Fig. 1, a novel PEFT approach that simultaneously updates the pre-trained matrix and two low-rank matrices while maintaining the same memory consumption as the original LoRA. Specifically, the pre-trained matrix $W$ is updated with the delta of the product of two low-rank matrices in two consecutive iterations $\triangle A B =$ $A ^ { ( t + 1 ) } B ^ { ( t + 1 ) } - A ^ { ( t ) } \bar { B } ^ { ( t ) } )$ , while two low-rank matrices are updated by the AdamW optimizer automatically. This is based on the mathematical property that $\begin{array} { r } { \frac { \partial \mathcal { L } ^ { \star } } { \partial W } = \frac { \partial \mathcal { L } } { \partial A B } . } \end{array}$ and $\triangle A B$ is a surrogate to direct the update of $W$ (see Sec. 4 for details). Since we neither store the gradient of $W$ nor use the optimizer to update the pre-trained matrix, the proposed method thus does not yield any extra memory overhead. This strategic integration effectively mitigates the sub-optimal representation learning stemming from only updating the two low-rank matrices. Moreover, our approach aligns the update direction of the pre-trained weights with that of the incremental update matrix. Furthermore, we discard the Dropout layer in low-rank branches to obtain a more reasonable delta for $W$ , in order to ensure $\begin{array} { r } { \frac { \partial \mathcal { L } } { \partial W } . = \frac { \partial \check { \mathcal { L } } } { \partial A B } } \end{array}$ . The advantages of our proposed method are conspicuous: including the pre-trained weights in the optimization process engenders a broader integration of parameters, thereby enhancing the potential for learning intricate representations.
The main contributions of this paper can be summarized as:
• We introduce Delta-LoRA, a novel PEFT method that simultaneously updates the full weight matrix and two low-rank matrices. Delta-LoRA leverages the delta of the product of $\pmb { A }$ and $\textbf { { B } }$ to update the pre-trained weights and thus prevent storing the first and the second-order momentums in the optimizer. • We analyze thbranch makes $\begin{array} { r } { \frac { \partial \Xi } { \partial W } \neq \frac { \partial \mathcal { L } } { \partial A B } } \end{array}$ ow of Delta-LoRA and show that the Dropout layer in the low-rank. Thus, we remove the Dropout layer in our proposed Delta-LoRA to get reasonable delta for $W$ . • We conduct comprehensive experiments to show that Delta-LoRA has consistent gains on a broad range of NLP tasks. Additionally, we provide thorough explanations to analyze its superiority and the value contributed by each component.
# 2 PRELIMINARIES
Transformer-based Models. Transformer (Vaswani et al., 2017) adopts the self-attention mechanism instead of recurrence and convolutions, achieving new state-of-the-art in machine translation. Dosovitskiy et al. (2021) later proposed the Vision-Transformer (ViT) architecture which exhibits versatility across various computer vision tasks. Nowadays, the Transformer-based models have become the most popular choice in both NLP and Computer Vision (Li et al., 2021; Carion et al., 2020; Zheng et al., 2021). Transformer typically consists of $L$ stacked blocks, each containing a multi-head attention (MHA) module and a feed-forward network (FFN) module. For an input sequence $\ b { X } \in \mathbb { R } ^ { n \times d }$ , the MHA module yields the output $\operatorname { M H A } ( X )$ , given by:
$$\begin{array} { r } { \mathrm { h e a d } _ { i } = \mathrm { s o f t m a x } ( \frac { X W _ { Q _ { i } } ( X W _ { K _ { i } } ) ^ { \top } } { \sqrt { d _ { k } } } ) X W _ { V _ { i } } } \\ { \mathrm { M H A } ( X ) = \mathrm { c o n c a t } ( \mathrm { h e a d } _ { 1 } , . . . , \mathrm { h e a d } _ { k } ) W _ { o } , } \end{array}$$
where $d _ { k }$ is the scaling factor and set to $d _ { k } = d / k$ . $W _ { K _ { i } }$ $W _ { Q _ { i } }$ , $W _ { V _ { i } }$ and $W _ { o }$ are weight matrices for computation of key, query, value and the output of MHA, respectively. Besides the MHA module, the FFN is also vital in the Transformer-based model. It stacks two fully connected (FC) layers with an activation function in between. FFN is defined as:
$$\mathrm { F F N } ( \pmb { x } ) = W _ { f _ { 2 } } \mathrm { R e L U } ( W _ { f _ { 1 } } \pmb { x } + b _ { 1 } ) + b _ { 2 } ,$$
where $\pmb { x } \in \mathbb { R } ^ { d }$ , $W _ { f _ { 1 } }$ and $W _ { f _ { 2 } }$ are two fully connected layers in FFN, $b _ { 1 }$ and $b _ { 2 }$ are bias terms.
Low Rank Adaptation. Given a pre-trained matrix $\boldsymbol { W } \in \mathbb { R } ^ { c \times d }$ , LoRA ( $\mathrm { H u }$ et al., 2022) learns an incremental update $\triangle \mathbf { { W } }$ and decomposes $\triangle W$ into a matrix multiplication between two lowrank matrices $\pmb { A }$ and $\textbf { { B } }$ , where $\pmb { A } \in \mathbb { R } ^ { c \times r }$ and $\boldsymbol { B } \in \mathbb { R } ^ { r \times d }$ , and $\triangle W = A B$ . Here, the rank $r \ll m i n ( d , c )$ . For an input $_ { \textbf { \em x } }$ and hidden state $^ { h }$ , LoRA has the following forward process:
$$\pmb { h } = \pmb { W } ^ { * } \pmb { x } = \pmb { W } \pmb { x } + \triangle \pmb { W } \pmb { x } = \pmb { W } \pmb { x } + \frac { \alpha } { r } \pmb { A } \pmb { B } \pmb { x }$$
At the beginning of the training stage, $\pmb { A }$ is randomly initialized via Kaiming initialization (He et al., 2015) and $\textbf { { B } }$ is initialized to zero matrix to make sure that the incremental update $A B = \mathbf { 0 }$ at initialization. Besides, LoRA uses hyper-parameters $\alpha$ and $r$ to scale ${ \pmb A } { \pmb B } { \pmb x }$ .
# 3 RELATED WORKS
With the ever-growing parameter scale in current Transformer-based models, fine-tuning such a large language model (LLM) requires considerable number of GPUs equipped with high memory capacity. This is mainly due to the fact that common optimizers such as AdamW (Loshchilov & Hutter, 2019) requires maintaining three times of extra parameter size (gradients, first-order and second-order momentums). To bridge this gap, a series of Parameter-Efficient Fine-Tuning (PEFT) methods have been proposed (Hu et al., 2022; Liu et al., 2022b; Shin et al., 2020; Houlsby et al., 2019). The Adapter (Houlsby et al., 2019) introduces lightweight trainable parameters between pre-trained layers while keeping the pre-trained weights fixed. Prompt-Tuning (Lester et al., 2021) aims to optimize the prompt to achieve comparable performance with fine-tuning for specific task, while Prefix-Tuning optimizes for trainable prefixes and prepends these trainable parameters to each hidden state (Li & Liang, 2021). Despite the notable performance achievements, these methods inevitably introduce extra overhead at the inference stage.
Hu et al. (2022) proposed LoRA to utilize the multiplication of two low-rank matrices to model the incremental update of a full-rank matrix. LoRA merges the incremental updates to pre-trained weights after training, thereby avoiding any extra computation overhead during inference. Furthermore, it stands out as one of the most effective PEFT techniques according to Ding et al. (2023)’s evaluation. Subsequent to its inception, a series of enhanced methods building upon LoRA was proposed. Notably, G-LoRA (Chavan et al., 2023) leverages a generalized prompt module to fine-tune pre-trained weights resulting in better representations for computer vision tasks. DyLoRA (Valipour et al., 2023) aims to adjust the rank of two lightweight matrices after the training stage. Differing from the conventional approach of maintaining a static rank during training, DyLoRA introduces rank variations to its blocks. AdaLoRA (Zhang et al., 2022) emphasizes the disparate importance attributed to distinct weight parameters. This technique intelligently allocates the parameter budget across weight matrices based on their respective importance scores. Additionally, Q-LoRA (Dettmers et al., 2023) was proposed to further reduce the average memory footprint by quantizing the pre-trained model with 4-bit NormalFloat. This quantization approach not only preserves the model’s efficacy but also effectively alleviates the resource-intensive nature of LLM training and addresses a pertinent concern.
 Figure 2: The framework of our proposed Delta-LoRA. The blue arrows represent forward pass while yellow dashed arrows denote backward propagation. The black solid arrows in (b) represent the process of updating the low-rank adaptation matrices $\pmb { A }$ and $\textbf { { B } }$ with normalized gradients $\widehat { \mathbf { g } } _ { A }$ and $\widehat { \pmb { g } } _ { B }$ multiplied by the learning rate $\eta$ , as well as updating the pre-trained weights $W$ bwith the delta bmatrix $\triangle A B$ multiplied by the update ratio $\lambda$ .
# 4 METHODOLOGY
This section introduces the novel fine-tuning approach termed as Delta-LoRA. Delta-LoRA encompasses two pivotal designs as shown in Figure 1 and Figure 2: (i) It simultaneously updates the full weight matrix $( W )$ alongside the two low-rank adaptation matrices $\mathbf { \delta A }$ and $\textbf { { B } }$ ), utilizing the delta $( \hat { A ^ { ( t + 1 ) } B ^ { ( t + 1 ) } } - A ^ { ( t ) } \hat { B } ^ { ( t ) } )$ resulting from incremental updates to refine the pre-trained weights $( W )$ ; (ii) The Dropout layer as originally integrated within the conventional LoRA module, is excluded in Delta-LoRA. This omission stems from the realization that its presence violates the required assumption $\begin{array} { r } { \frac { \partial \mathcal { L } } { \partial W } = \frac { \partial \mathcal { L } } { \partial A B } } \end{array}$ .
# 4.1 UPDATE THE DELTA OF LOW-RANK MATRICES ON PRE-TRAINED WEIGHTS
For an input $_ { \textbf { \em x } }$ and its corresponding hidden state $^ { h }$ , LoRA optimizes two low-rank matrices $\pmb { A }$ and $\textbf { { B } }$ to learn an incremental update $_ { A B }$ for the pre-trained and fixed weight matrix $W$ . Different from previous methods, we argue that $W$ also needs to be updated. In this way, we can introduce more learnable parameters to the optimization process for higher learning capability. However, acquiring the normalized gradients (i.e. the gradients after normalization in optimizer) to fine-tune the weight matrix $W$ is non-trivial, since the optimizer such as AdamW must maintain at least three extra copies of the parameters (i.e. gradients as well as the first-order and the second-order moments of gradients) in GPU memory. Intriguingly, we note that the gradients of the loss $\mathcal { L }$ with respect to matrices $_ { A B }$ and $W$ are precisely identical, under the presumption that the LoRA module exclusively retains matrices $\pmb { A }$ and $\textbf { { B } }$ , while disregarding the Dropout layer. This correspondence can be formally represented as:
$$\begin{array} { l } { g _ { W } = \displaystyle \frac { \partial \mathcal { L } } { \partial h _ { i + 1 } } \cdot \frac { \partial h _ { i + 1 } } { \partial W } ^ { \top } = \displaystyle \frac { \partial \mathcal { L } } { \partial h _ { i + 1 } } \cdot h _ { i } ^ { \top } , } \\ { g _ { A B } = \displaystyle \frac { \partial \mathcal { L } } { \partial h _ { i + 1 } } \cdot \frac { \partial h _ { i + 1 } } { \partial A B } ^ { \top } = \displaystyle \frac { \partial \mathcal { L } } { \partial h _ { i + 1 } } \cdot h _ { i } ^ { \top } , } \\ { \implies g _ { W } = g _ { A B } , } \end{array}$$
where $h _ { i + 1 } = W h _ { i } + A B h _ { i } .$ , $\boldsymbol { h } _ { i }$ and $\boldsymbol { h } _ { i + 1 }$ are the outputs of the $i$ -th layer and the $_ { i + 1 }$ -th layer respectively. $_ { A B }$ is the matrix product of the adaptation matrices $\pmb { A }$ and $\textbf { { B } }$ , $\mathcal { L }$ is the loss function, while $g _ { W + A B } , g _ { W }$ and $\mathbf { \sigma } _ { \mathbf { \sigma } _ { g _ { A B } } }$ denote the gradients of ∂L∂(W +AB) , ∂L∂W , and ∂ $\frac { \partial \mathcal { L } } { \partial A B }$ respectively.
Equation 4 inspires us to use $\mathbf { \sigma } _ { \mathbf { \sigma } _ { g _ { A B } } }$ to assimilate $\mathbf { \Delta } _ { g _ { W } }$ when learning the parameter updates for weight matrix $W$ . Unfortunately, we are only able to obtain the gradients $\mathbf { \pmb { g } } _ { \pmb { A } }$ and $\mathbf { \nabla } _ { \mathbf { \pmb { g } } \mathbf { \it { B } } }$ rather than $\mathbf { \Delta } _ { \mathbf { \mathcal { { g } } } \mathbf { \Delta } _ { W } }$ during the back-propagation process. Furthermore, the computation of the gradients for $_ { A B }$ is as expensive as for the matrix $W$ , since both matrices share the same dimensions of $d \times k$ , consequently entailing an equivalent GPU memory overhead.
Considering a typical optimization process, the model updates its parameters by applying the gradient descent: $\boldsymbol { W } ^ { ( t + 1 ) } = \boldsymbol { W } ^ { ( t ) } - \eta \boldsymbol { g } _ { \boldsymbol { W } }$ , with the parameter update denoted as $\triangle W = - \eta g _ { W }$ , using the learning rate $\eta$ . Similarly, we regard $- \triangle A B$ as the gradients for $_ { A B }$ and utilize this matrix as a substitute for $\mathbf { \Delta } _ { g _ { W } }$ according to Equation 4. Here, we can compute $\triangle A B$ as:
$$\triangle { \cal A } B = { \cal A } ^ { ( t + 1 ) } B ^ { ( t + 1 ) } - { \cal A } ^ { ( t ) } B ^ { ( t ) } = \eta { \cal A } ^ { ( t ) } g _ { B } + \eta g _ { A } B ^ { ( t ) } - \eta ^ { 2 } g _ { A } g _ { B } ,$$
where $A ^ { ( t ) }$ , $B ^ { ( t ) }$ and $\mathbf { \mathbf { } } W ^ { ( t ) }$ are the weights of $A , B$ and $W$ at the $t { \cdot }$ -th step respectively, $A ^ { ( t + 1 ) } =$ $A ^ { ( t ) } - \eta g _ { A }$ , $B ^ { ( t + 1 ) } = B ^ { ( t ) } - \eta \pmb { g } _ { B }$ and $\eta$ is the learning rate. To be precise, $- \triangle A B$ does not equate directly to $\mathbf { \sigma } _ { \mathbf { \sigma } _ { g _ { A B } } }$ and $\mathbf { \Delta } _ { \mathbf { \mathcal { { g } } } \mathbf { \Delta } _ { W } }$ as elaborated in Appendix A.4.2. Nonetheless, $\triangle A B$ has the capability to symbolize the genuine directions of update for the matrix $_ { A B }$ . Based on this assumption, it is reasonable to employ $- \triangle A B$ as the gradient for directing the update of $W$ .
Therefore, during the training phase we introduce the matrix $\triangle A B$ to update the pre-trained weights $W$ in the following manner:
$${ \bf W } ^ { ( t + 1 ) } = { \bf W } ^ { ( t ) } + \lambda \cdot \frac { \alpha } { r } \cdot \triangle A B , { \mathrm { w h e r e ~ } } \triangle A B = { \cal A } ^ { ( t + 1 ) } B ^ { ( t + 1 ) } - { \cal A } ^ { ( t ) } B ^ { ( t ) } ,$$
where $\lambda$ represents the hyper-parameter to trade off the update ratio of $_ { A B }$ and the pre-trained weights $W$ . The parameter updates for $W$ commence after $K$ training iterations. The procedural details of the algorithm are illustrated in Algorithm 1.
Discussion. The Delta-LoRA has some important modifications compared to LoRA. Here, we discuss and compare the difference:
<table><tr><td colspan="2">LoRA</td><td colspan="2">1 Delta-LoRA 1 1</td></tr><tr><td rowspan="2">(1) A(t+1) ← ∂L(χ;W,A(t),B(t))</td><td>1 1</td><td>aL(x;W(t),A(t),B(t)) (1) A(t+1) ←</td><td rowspan="2"></td></tr><tr><td>aA(t)</td><td>aA(t)</td></tr><tr><td rowspan="3">(2) B(t+1) ← ∂C(χ:W.A(t),B(t))</td><td></td><td>1 (2) B(t+1) ← 0L(ω:W(t),A(t),B(t))</td><td>aB(t)</td></tr><tr><td>∂B(t)</td><td></td><td></td></tr><tr><td></td><td></td><td>(3)W(t+1) ← A(t+1)B(t+1) - A(t)B(t)</td></tr></table>
It is obvious that LoRA only updates $\pmb { A }$ and $\textbf { { B } }$ , and keeps $W$ frozen, while Delta-LoRA updates $\pmb { A }$ and $\textbf { { B } }$ by the optimizer and $W$ with the delta of the product of $\pmb { A }$ and $\textbf { { B } }$ .
# 4.2 THE STRUCTURE OF OUR DELTA-LORA
Both LoRA and its successor AdaLoRA put a Dropout layer before two low-rank matrices $\pmb { A }$ and $\textbf { { B } }$ . However, this arrangement results in a disparity between the gradient matrices $\mathbf { \Delta } _ { g _ { W } }$ and $\mathbf { \sigma } _ { \mathbf { \sigma } _ { g _ { A B } } }$ (or the matrix $\mathbf { \_ { \_ { \_ { \delta A E B } } } }$ in the context of AdaLoRA). The derivation of this disparity can be shown as:
$$g _ { W } = { \frac { \partial { \mathcal { L } } } { \partial h _ { i + 1 } } } \cdot h _ { i } ^ { \top } \neq g _ { A B } = { \frac { \partial { \mathcal { L } } } { \partial h _ { i + 1 } } } \cdot \mathrm { D r o p } ( h _ { i } ) ^ { \top } ,$$
where $\mathrm { D r o p } ( \cdot )$ denotes the Dropout layer which leads to $g _ { W } \neq g _ { A B }$ . A reasonable choice is to remove the Dropout layer in the low-rank module and activate the Dropout layer between pre-trained layers if overfitting problem occurs. This modification also brings additional benefits: (1) it can alleviate under-fitting to some extent, thereby enhancing the learned representations of the networks. The rationale behind this improvement lies in the fact that LoRA and its successors formulate low-rank updates for pre-trained weights, involving less than $1 \%$ of the complete parameters. However, relying solely on such a small fraction of parameters may not bestow an adequate representation capacity in most cases; (2) This alteration also yields memory-saving benefits. By negating the requirement to store intermediate features, the model curtails the memory consumption. Consequently, there is a reduction in activation memory employed during the back-propagation process.
# 5 EXPERIMENTS
We evaluate our proposed model fine-tuning method Delta-LoRA with RoBERTa (Liu et al., 2019), GPT-2 (Radford et al., 2019) and BART (Lewis et al., 2019) on a broad set of datasets. Specifically, we train (1) RoBERTa on GLUE benchmark which consists of 8 NLP understanding tasks; (2) GPT-2 on E2E Challenge and WebNLG Challenge 2017 following the setting of Hu et al. (2022); and (3) BART on XSum dataset by using the setting provided by Zhang et al. (2022). See Appendix A.7 for more training details on the datasets. The setups and detailed introductions of baseline methods are shown in Appendix A.1. We use PyTorch to implement our experiments and download the pre-trained weights as well as configuration files from HuggingFace Wolf et al. (2019).
Table 1: The evaluation results of our proposed Delta-LoRA and other existing methods on E2E NLG Challenge dataset. $\dagger$ indicates fine-tuning all layers except embedding layer. $^ \ddag$ indicates only fine-tuning weights for query and value. $^ \mathparagraph$ means we choose different settings with AdaLoRA: we only tune $W _ { Q }$ and $W _ { V }$ instead of all layers. The best results of Fine-Tuning methods are underlined. The best results of PEFT methods are boldfaced.
Table 2: The evaluation results of our proposed Delta-LoRA and other existing methods on WebNLG Challenge 2017 dataset. $\dagger$ indicates fine-tuning all layers except embedding layer. $\ddagger$ indicates only fine-tuning weights for query and value. $^ \mathparagraph$ means we choose different settings with AdaLoRA: we only tune $W _ { Q }$ and $W _ { V }$ instead of all layers. The best results of Fine-Tuning methods are underlined. The best results of PEFT methods are boldfaced.
<table><tr><td>Method</td><td></td><td>Trainables|Exrupdale</td><td></td><td></td><td></td><td>BLEU NIST METEOR ROUGE-L CIDEr</td><td></td></tr><tr><td>Full Fine-Tuning</td><td>354.92M</td><td></td><td>69.58</td><td>8.75</td><td>46.34</td><td>71.66</td><td>2.47</td></tr><tr><td>Fine-Tuningt</td><td>305.84M</td><td></td><td>69.37</td><td>8.76</td><td>46.05</td><td>71.97</td><td>2.44</td></tr><tr><td>Fine-Tuningt</td><td>48M</td><td>×</td><td>69.77</td><td>8.84</td><td>46.29</td><td>71.96</td><td>2.49</td></tr><tr><td>LoRA (repr.)</td><td>0.375M</td><td>X</td><td>69.60</td><td>8.78</td><td>45.61</td><td>71.12</td><td>2.45</td></tr><tr><td>LoRA</td><td>0.35M</td><td></td><td>70.4</td><td>8.85</td><td>46.8</td><td>71.8</td><td>2.53</td></tr><tr><td>DyLoRA</td><td>0.375M</td><td></td><td>67.89</td><td>8.50</td><td>44.07</td><td>70.52</td><td>2.26</td></tr><tr><td>AdaLoRA</td><td>0.375M</td><td></td><td>68.16</td><td>8.58</td><td>44.10</td><td>70.66</td><td>2.35</td></tr><tr><td>Delta-LoRA (Ours)</td><td>0.375M</td><td>√48M</td><td>70.84</td><td>8.91</td><td>46.47</td><td>72.24</td><td>2.53</td></tr></table>
<table><tr><td>Method</td><td></td><td>PTrainables Exraupdatable</td><td>S BLEU↑</td><td>A</td><td>METEOR↑</td><td>S</td><td>TER</td><td>A</td></tr><tr><td>FullFine-Tuning</td><td>354.92M</td><td></td><td></td><td></td><td>61.38 45.11 54.480.44 0.38 0.410.36 0.53 0.44</td><td></td><td></td><td></td></tr><tr><td>Fine-Tuningt</td><td>305.84M</td><td>×</td><td></td><td></td><td>63.53 46.66 55.920.45 0.39 0.420.34 0.49 0.41</td><td></td><td></td><td></td></tr><tr><td>Fine-Tuningt</td><td>48M</td><td>×</td><td></td><td></td><td>64.55 48.06 57.080.46 0.39 0.430.33 0.47 0.40</td><td></td><td></td><td></td></tr><tr><td>LoRA (repr.)</td><td>0.375M</td><td>X</td><td>62.08 46.60 55.050.44 0.38 0.410.35 0.49 0.42</td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>LoRA</td><td>0.375M</td><td></td><td>62.1</td><td>46.7 55.3</td><td>0.440.380.41</td><td></td><td>0.330.460.39</td><td></td></tr><tr><td>DyLoRA</td><td>0.375M</td><td>×</td><td></td><td></td><td>58.39 46.02 52.77|0.42 0.37 0.40|0.38 0.49 0.43</td><td></td><td></td><td></td></tr><tr><td>AdaLoRA</td><td>0.375M</td><td>×</td><td>56.39 44.14 50.820.41 0.37 0.390.40 0.49 0.44</td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>Delta-LoRA (Ours)</td><td>0.375M</td><td>√48M</td><td></td><td></td><td></td><td></td><td>62.87 47.68 55.960.45 0.39 0.420.34 0.48 0.40</td><td></td></tr></table>
# 5.1 NATURAL LANGUAGE GENERATION
Models and Datasets. We use GPT2-Medium to verify the effectiveness of our Delta-LoRA on two datasets for data-to-text tasks, including the E2E NLG Challenge (Puzikov & Gurevych, 2018) and WebNLG Challenge 2017 (Gardent et al., 2017). The E2E NLG Challenge dataset comprises 42,000 samples for training, 4,600 for validation, and 4,600 for testing purposes. In contrast, the WebNLG Challenge 2017 consists of 21,855 training samples across nine categories, expanding to a total of 14 categories in the test set. For the text summarization task, we employed BART-Large (Lewis et al., 2019) to evaluate the efficacy of our method using the XSum dataset (Narayan et al., 2018). The XSum dataset is composed of 204,045 training samples, 11,332 validation samples, and 11,332 test samples. We also use LLaMA-7B(Touvron et al., 2023), a popular pre-trained large language model with 7 Billion parameters,to fine-tune on Alpaca dataset (Taori et al., 2023).
Implementation Details. In order to compare with LoRA and its successors fairly, we adopt the model setups from LoRA to implement our Delta-LoRA and three PEFT methods. We only learn the low-rank incremental update for $W _ { Q }$ and $W _ { V }$ in MHA module. For data-to-text datasets, we use the same training configurations as adopted by LoRA, including the number of training epochs, batch size and etc. We use update ratio $\lambda = 2$ and set start steps $K = 5 0 0$ for Delta-LoRA. More details about Delta-LoRA are listed in the Appendix A.7. For the text-summarization task, we use the implementation of AdaLoRA and adopt the same training configurations. We set the update ratio $\lambda = 0 . 5$ and the start steps $K = 1 0 0 0$ for Delta-LoRA.
Table 3: The evaluation results of Delta-LoRA with LLaMA-7B on the Instruction-Tuning dataset provided by Stanford Alpaca(Taori et al., 2023). We use GPT-4 to choose from a. LoRA, b. DeltaLoRA or c. Both LoRA and Delta-LoRA to decide the text from which method is better.
<table><tr><td>Both</td><td>LoRA</td><td>Delta-LoRA</td><td>Total</td></tr><tr><td>886</td><td>10</td><td>104</td><td>1,000</td></tr></table>
Experimental Results. Table 1 shows the results for E2E Challenge dataset on 5 evaluation metrics, demonstrating that our method achieves state-of-the-art performance over 3 baselines and a set of fine-tuning methods. For the BLEU and ROUGE-L metrics, our method obtains 1.24 and 1.13 performance gains compared with LoRA, with 0.13, 0.86 and 0.08 improvement on NIST, METEOR and CIDEr respectively. Table 2 demonstrates that Delta-LoRA outperforms baselines on BLEU score for WebNLG Challenge 2017 dataset, with 0.79, 1.08 and 0.91 improvement on Seen, Unseen and All test data, respectively. Additionally, for the METEOR and TER evaluation metrics, Delta-LoRA also achieves state-of-the-art performance, with 0.01 and 0.02 improvement over LoRA on all data. For the text-summarization task, the test results are shown in Table 4, which demonstrates that our method achieves state-of-the-art results across 3 parameter-efficient methods on 4 evaluation metrics. To fairly evaluate our method, we utilized LLaMA-7B and compared it with LoRA. We employed GPT-4 to generate 1,000 questions and presented these questions to the parameter-efficient fine-tuned LLaMA-7B. Subsequently, we leveraged GPT-4 to compare the texts generated by LoRA-tuned and Delta-LoRA-tuned LLMs. Additional details can be found in Appendix A.2. According to the findings in Table 3, Delta-LoRA establishes state-of-the-art performance in the evaluation of Language Models (LLMs). GPT-4 identified 104 samples generated by Delta-LoRA as superior to LoRA, while only 10 samples generated by LoRA exhibited higher quality than Delta-LoRA. This underscores Delta-LoRA’s effectiveness even when utilized within models containing billions of parameters.
Table 4: The evaluation results of our proposed Delta-LoRA and other existing methods on XSum dataset. $\dagger$ indicates fine-tuning all layers except the embedding layer. $^ \ddag$ indicates only fine-tuning weights for query and value. $\ P$ means we choose different settings with AdaLoRA: we only tune $W _ { Q }$ and $W _ { V }$ instead of all layers. The best results of Fine-Tuning methods are underlined. The best results of PEFT methods are boldfaced.
<table><tr><td>Method</td><td></td><td> PTrainablesExraUpdatable</td><td></td><td></td><td></td><td>Rouge-1 Rouge-2 Rouge-L Rouge-Sum</td></tr><tr><td>Full Fine-Tuning</td><td>387.5M</td><td></td><td>45.36</td><td>22.16</td><td>37.23</td><td>37.24</td></tr><tr><td>Fine-Tuningt</td><td>338.4M</td><td>xx</td><td>45.04</td><td>22.05</td><td>36.92</td><td>36.94</td></tr><tr><td>Fine-Tuningt</td><td>72M</td><td></td><td>44.95</td><td>21.43</td><td>36.35</td><td>36.37</td></tr><tr><td>LoRA</td><td>0.56M</td><td>X</td><td>43.27</td><td>20.13</td><td>35.12</td><td>35.12</td></tr><tr><td>DyLoRA</td><td>0.56M</td><td>×</td><td>41.84</td><td>18.76</td><td>33.56</td><td>33.57</td></tr><tr><td>AdaLoRAI</td><td>0.56M</td><td>X</td><td>42.91</td><td>19.76</td><td>34.71</td><td>34.72</td></tr><tr><td>Delta-LoRA (Ours)</td><td>0.56M</td><td>√72M</td><td>43.49</td><td>20.23</td><td>35.26</td><td>35.26</td></tr></table>
# 5.2 NATURAL LANGUAGE UNDERSTANDING
Models and Datasets. We use RoBERTa-baseLiu et al. (2019) to evaluate the performance of our proposed method, prior works and three fine-tuning methods. We choose the GLUE benchmark consisting of 8 datasets (Wang et al., 2019), including classification tasks, similarity and paraphrase tasks and natural language inference tasks.
Implementation Details. We use RoBERTa-base with 118M parameters to conduct our experiments and to compare our method with the baselines. We mostly adopt the same training configurations of
LoRA, more details can get from Appendix A.7. We set the rank to 8 and the target rank to 6 for AdaLoRA and choose the rest of hyper-parameters according to the characteristics of different tasks. For Delta-LoRA, we set the update ratio $\lambda$ to 0.5 and choose different start steps $K$ according to warmup steps used in individual tasks.
Table 5: The evaluation results of our proposed Delta-LoRA and other existing methods on GLUE benchmark. We report the overall (matched and mismatched) accuracy for MNLI, Matthew’s correlation for CoLA, Pearson correlation for STS-B, and accuracy for other tasks. $\dagger$ indicates fine-tuning all layers except the embedding layer. $\ddagger$ indicates only fine-tuning weights for query and value. $^ \mathparagraph$ means we choose different settings with AdaLoRA: we only tune $W _ { Q }$ and $W _ { V }$ instead of all layers. The best results of Fine-Tuning methods are underlined. The best results of PEFT methods are boldfaced.
<table><tr><td>Method</td><td></td><td></td><td>TraiableErUpdatablMNLISS-2 MRPC CoLA QNLIQP RTE STS-B AVG</td></tr><tr><td>Full Fine-Tuning</td><td>118.87M</td><td>X</td><td>87.51 94.26 88.23 64.57 92.73 91.96 84.11 90.56 86.74</td></tr><tr><td>Fine-Tuningt</td><td>82.05M</td><td>×</td><td>87.58 94.03 89.95 62.99 92.73 91.90 86.64 90.22 87.01</td></tr><tr><td>Fine-Tuningt</td><td>13.5M</td><td>×</td><td>87.48 95.06 89.21 61.07 92.76 91.19 84.83 89.85 86.43</td></tr><tr><td>LoRA</td><td>0.28M</td><td>X</td><td>87.40 94.61 89.95 63.17 93.02 90.67 86.64 91.54 87.12</td></tr><tr><td>DyLoRA</td><td>0.28M</td><td>X</td><td>86.33 94.26 89.46 61.12 92.22 90.17 84.47 91.06 86.14</td></tr><tr><td>AdaLoRA</td><td>0.28M</td><td>×</td><td>87.34 94.49 90.19 61.64 93.08 90.14 85.19 91.16 86.65</td></tr><tr><td>Delta-LoRA (Ours)</td><td>0.28M</td><td>√13.5M</td><td>87.50 95.06 90.19 63.82 93.09 90.87 87.00 91.57 87.38</td></tr></table>
Experimental Results. We compare our method with prior PEFT works. According to Table 5, our method outperforms existing methods on all 8 tasks in GLUE benchmark. Among these tasks, our method demonstrates significant improvement on SST-2, CoLA and RTE. This is mainly due to the fact that these datasets contain less training data, which hinders the model’s capacity to effectively acquire a robust representation when using prior fine-tuning methods. Delta-LoRA also achieves decent performance on the rest of the datasets, including MNLI, MRPC, QNLI as well STS-B, which proves that our method is stable and reliable across different settings.
# 5.3 COMPREHENSIVE UNDERSTANDING OF DELTA-LORA
Table 6: The ablation study of our proposed Delta-LoRA on E2E Challenge dataset demonstrates the importance of each component. The best results are boldfaced.
<table><tr><td>Method</td><td>Trainable Parameters</td><td>Parameters</td><td>Extra Updatable|BLEU NIST METEOR ROUGE-L CIDEr</td><td></td><td></td><td></td></tr><tr><td>LoRA (repr.)</td><td>0.375M</td><td></td><td>69.60 8.78</td><td>45.61</td><td>71.12</td><td>2.45</td></tr><tr><td>Delta-LoRA + LoRA Module</td><td>0.375M</td><td>√48M</td><td>70.29 8.88</td><td>46.38</td><td>71.88</td><td>2.51</td></tr><tr><td>Delta-LoRA</td><td>0.375M</td><td>√48M</td><td>70.84 8.91</td><td>46.47</td><td>72.24</td><td>2.53</td></tr></table>
Table 7: The ablation study of our proposed Delta-LoRA to eliminate the impact of hyper-parameter $\lambda$ on E2E Challenge dataset. The best results are boldfaced.
<table><tr><td>Method</td><td>Learming</td><td>入</td><td>BLEU NIST METEOR ROUGE-L CIDEr</td><td></td><td></td><td></td></tr><tr><td>LoRA (repr.)</td><td>2e-4</td><td>-</td><td>69.60</td><td>8.78 45.61</td><td>71.12</td><td>2.45</td></tr><tr><td>LoRA (repr.)</td><td>6e-4</td><td>1</td><td>69.63</td><td>8.79 45.70</td><td>71.55</td><td>2.39</td></tr><tr><td>Delta-LoRA</td><td>2e-4</td><td>2</td><td>70.84 8.91</td><td>46.47</td><td>72.24</td><td>2.53</td></tr></table>
The Extra Updatable Parameters. We introduce the concept of extra updatable parameters to point out the superiority of Delta-LoRA. For most PEFT methods, they can only adjust the low-rank adapters, such as AdapterHoulsby et al. (2019) and LoRAHu et al. (2022). Thus, they don’t have any extra parameters to update, which means their extra updatable parameters are 0. However, our Delta-LoRA can achieve the purpose of updating the W matrix without increasing the GPU memory consumption, which means its extra updatable parameters are the parameter number of $W$ .
Ablation study. To better understand the contribution of our modified LoRA module (i.e. DeltaLoRA module) and the effectiveness of our update algorithm, we conduct studies on E2E Challenge dataset with GPT2-medium. As shown in Table 6, only updating the pre-trained matrices with delta of low-rank update can indeed achieve performance improvement, while further discarding the dropout in Delta-LoRA module obtains the best performance. This observation confirms the indispensable role played by each component within our proposed methodology. We have devised an experiment to further differentiate whether the performance enhancement stems from the inherent characteristics of our method rather than solely from the substantial update magnitude. According to our algorithm, we update the parameters of both pre-trained and low-rank matrices, which can arose the doubt of whether the improvement is caused by updating larger $\triangle A B$ on the weights instead of introducing more parameters into the optimization process. To answer this question, we design an experiment with results shown in Table 7 to prove the effectiveness of our method. We scale the learning rate of LoRA from 2e-4 to 6e-4 making sure that $W + A B$ can be updated with $3 \times \triangle A B$ , which is equivalent to Delta-LoRA when $\lambda$ is set to 2. We find that even by updating with $3 \times \triangle A B$ on $_ { A B }$ , the performance is still not comparable with Delta-LoRA. This experiment further proves that introducing more parameters into the optimization process can force to learn better representation.
 Figure 3: The comparison of Fine-Tuning‡, LoRA as well as Delta-LoRA for the cosine similarity between the fine-tuned parameters and the original pre-trained parameters in each transformer block. Higher value means higher similarity.
The cosine similarity between fine-tuned and the pre-trained parameters to measure learning effects. We conduct a comparative analysis of three methods including Fine-Tuning‡, LoRA and Delta-LoRA, in order to elucidate the reasons behind Delta-LoRA’s superior performance. We use the last checkpoint trained on E2E Challenge dataset to give understanding. As depicted in Figure 3, it is evident that LoRA exhibits the highest similarity across the majority of transformer blocks. This observation suggests that LoRA primarily modifies the matrix $\pmb { W } ^ { * } = \pmb { W } + \pmb { A } \pmb { B }$ within a limited range. Nevertheless, Delta-LoRA showcases the lowest cosine similarity, underscoring that our approach induces the most significant modifications to the final matrix $W ^ { * }$ . Due to this property, our approach can effectively stimulate the model to acquire better representations, leading to state-of-the-art performance across all four PEFT methods. This observation further aligns with the evaluation results in Table 1: Delta-LoRA achieves the best performance among the three methods, whereas LoRA is slightly worse than Fine-Tuning‡.
# 6 CONCLUSION
In this paper, we have introduced Delta-LoRA, a novel method to simultaneously update the full weight matrix and two low-rank matrices. Delta-LoRA leverages the delta $( { \pmb A } ^ { ( t + 1 ) } { \pmb B } ^ { ( t + 1 ) } - { \pmb A } ^ { ( t ) } { \pmb B } ^ { ( t ) } )$ to update the pre-trained weights $( W )$ . In this way, we introduce more learnable parameters into the optimization process such that the model can learn a better representation with comparable memory cost as LoRA. Meanwhile, we identify the Dropout layer in the low-rank branch to be unnecessary according to the gradient flow. We also provide thorough analysis of our method to understand its effectiveness and robustness. Extensive experiments on a broad range of NLP tasks are conducted to empirically verify the effectiveness of our Delta-LoRA.
# REFERENCES
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.
Sébastien Bubeck, Varun Chandrasekaran, Ronen Eldan, Johannes Gehrke, Eric Horvitz, Ece Kamar, Peter Lee, Yin Tat Lee, Yuanzhi Li, Scott Lundberg, Harsha Nori, Hamid Palangi, Marco Tulio Ribeiro, and Yi Zhang. Sparks of artificial general intelligence: Early experiments with gpt-4, 2023. Nicolas Carion, Francisco Massa, Gabriel Synnaeve, Nicolas Usunier, Alexander Kirillov, and Sergey Zagoruyko. End-to-end object detection with transformers. In ECCV, 2020. Arnav Chavan, Zhuang Liu, Deepak Gupta, Eric Xing, and Zhiqiang Shen. One-for-all: Generalized lora for parameter-efficient fine-tuning. arXiv preprint arXiv:2306.07967, 2023. Tim Dettmers, Artidoro Pagnoni, Ari Holtzman, and Luke Zettlemoyer. Qlora: Efficient finetuning of quantized llms. arXiv preprint arXiv:2305.14314, 2023. Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. Bert: Pre-training of deep bidirectional transformers for language understanding. In NAACL, 2019. Ning Ding, Yujia Qin, Guang Yang, Fuchao Wei, Zonghan Yang, Yusheng Su, Shengding Hu, Yulin Chen, Chi-Min Chan, Weize Chen, Jing Yi, Weilin Zhao, Zhiyuan Liu, Hai-Tao Zheng, Jianfei Chen, Yang Liu, Jie Tang, Juanzi Li, and Maosong Sun. Parameter-efficient fine-tuning of large-scale pre-trained language models. Nature Machine Intelligence, 2023. Alexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn, Xiaohua Zhai, Thomas Unterthiner, Mostafa Dehghani, Matthias Minderer, Georg Heigold, Sylvain Gelly, et al. An image is worth 16x16 words: Transformers for image recognition at scale. In ICLR, 2021. Claire Gardent, Anastasia Shimorina, Shashi Narayan, and Laura Perez-Beltrachini. The WebNLG challenge: Generating text from RDF data. In Proceedings of the 10th International Conference on Natural Language Generation, 2017. Demi Guo, Alexander M Rush, and Yoon Kim. Parameter-efficient transfer learning with diff pruning. In ACL, 2021. Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Delving deep into rectifiers: Surpassing human-level performance on imagenet classification. In ICCV, 2015. Pengcheng He, Jianfeng Gao, and Weizhu Chen. Debertav3: Improving deberta using electra-style pre-training with gradient-disentangled embedding sharing. arXiv preprint arXiv:2111.09543, 2021. Neil Houlsby, Andrei Giurgiu, Stanislaw Jastrzebski, Bruna Morrone, Quentin De Laroussilhe, Andrea Gesmundo, Mona Attariyan, and Sylvain Gelly. Parameter-efficient transfer learning for nlp. In ICML, 2019. Edward J Hu, yelong shen, Phillip Wallis, Zeyuan Allen-Zhu, Yuanzhi Li, Shean Wang, Lu Wang, and Weizhu Chen. LoRA: Low-rank adaptation of large language models. In ICLR, 2022. Shaoyi Huang, Dongkuan Xu, Ian Yen, Yijue Wang, Sung-En Chang, Bingbing Li, Shiyang Chen, Mimi Xie, Sanguthevar Rajasekaran, Hang Liu, and Caiwen Ding. Sparse progressive distillation: Resolving overfitting under pretrain-and-finetune paradigm. In ACL, 2022. Brian Lester, Rami Al-Rfou, and Noah Constant. The power of scale for parameter-efficient prompt tuning. In EMNLP, 2021. Mike Lewis, Yinhan Liu, Naman Goyal, Marjan Ghazvininejad, Abdelrahman Mohamed, Omer Levy, Ves Stoyanov, and Luke Zettlemoyer. Bart: Denoising sequence-to-sequence pre-training for natural language generation, translation, and comprehension. arXiv preprint arXiv:1910.13461, 2019. Junnan Li, Ramprasaath Selvaraju, Akhilesh Gotmare, Shafiq Joty, Caiming Xiong, and Steven Chu Hong Hoi. Align before fuse: Vision and language representation learning with momentum distillation. 2021. Xiang Lisa Li and Percy Liang. Prefix-tuning: Optimizing continuous prompts for generation. In Chengqing Zong, Fei Xia, Wenjie Li, and Roberto Navigli (eds.), ACL, 2021. Haokun Liu, Derek Tam, Mohammed Muqeeth, Jay Mohta, Tenghao Huang, Mohit Bansal, and Colin A Raffel. Few-shot parameter-efficient fine-tuning is better and cheaper than in-context learning. In NeurIPS, 2022a. Xiao Liu, Kaixuan Ji, Yicheng Fu, Weng Tam, Zhengxiao Du, Zhilin Yang, and Jie Tang. P-tuning: Prompt tuning can be comparable to fine-tuning across scales and tasks. In ACL, 2022b. Yang Liu, Dan Iter, Yichong Xu, Shuohang Wang, Ruochen Xu, and Chenguang Zhu. Gpteval: Nlg evaluation using gpt-4 with better human alignment. arXiv preprint arXiv:2303.16634, 2023. Yinhan Liu, Myle Ott, Naman Goyal, Jingfei Du, Mandar Joshi, Danqi Chen, Omer Levy, Mike Lewis, Luke Zettlemoyer, and Veselin Stoyanov. Roberta: A robustly optimized bert pretraining approach. arXiv preprint arXiv:1907.11692, 2019. Ilya Loshchilov and Frank Hutter. Decoupled weight decay regularization. In ICLR, 2019. Kai Lv, Yuqing Yang, Tengxiao Liu, Qinghui Gao, Qipeng Guo, and Xipeng Qiu. Full parameter fine-tuning for large language models with limited resources. 2023. Shashi Narayan, Shay B Cohen, and Mirella Lapata. Don’t give me the details, just the summary! topic-aware convolutional neural networks for extreme summarization. arXiv preprint arXiv:1808.08745, 2018. Jonas Pfeiffer, Aishwarya Kamath, Andreas Rücklé, Kyunghyun Cho, and Iryna Gurevych. Adapterfusion: Non-destructive task composition for transfer learning. In EACL, 2021. Yevgeniy Puzikov and Iryna Gurevych. E2E NLG challenge: Neural models vs. templates. In Proceedings of the 11th International Conference on Natural Language Generation, 2018. Alec Radford, Jeffrey Wu, Rewon Child, David Luan, Dario Amodei, Ilya Sutskever, et al. Language models are unsupervised multitask learners. OpenAI blog, 1(8):9, 2019. Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, Peter J Liu, et al. Exploring the limits of transfer learning with a unified text-to-text transformer. JMLR, 21(140):1–67, 2020. Taylor Shin, Yasaman Razeghi, Robert L Logan IV, Eric Wallace, and Sameer Singh. Autoprompt: Eliciting knowledge from language models with automatically generated prompts. In EMNLP, 2020. Chuanqi Tan, Fuchun Sun, Tao Kong, Wenchang Zhang, Chao Yang, and Chunfang Liu. A survey on deep transfer learning. In ICANN, 2018. Rohan Taori, Ishaan Gulrajani, Tianyi Zhang, Yann Dubois, Xuechen Li, Carlos Guestrin, Percy Liang, and Tatsunori B. Hashimoto. Stanford alpaca: An instruction-following llama model. https://github.com/tatsu-lab/stanford_alpaca, 2023. Hugo Touvron, Thibaut Lavril, Gautier Izacard, Xavier Martinet, Marie-Anne Lachaux, Timothée Lacroix, Baptiste Rozière, Naman Goyal, Eric Hambro, Faisal Azhar, et al. Llama: Open and efficient foundation language models. arXiv preprint arXiv:2302.13971, 2023. Mojtaba Valipour, Mehdi Rezagholizadeh, Ivan Kobyzev, and Ali Ghodsi. Dylora: Parameter-efficient tuning of pre-trained models using dynamic search-free low-rank adaptation. In EACL, 2023. 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. Alex Wang, Amanpreet Singh, Julian Michael, Felix Hill, Omer Levy, and Samuel R. Bowman. GLUE: A multi-task benchmark and analysis platform for natural language understanding. In ICLR, 2019. Yaqing Wang, Subhabrata Mukherjee, Xiaodong Liu, Jing Gao, Ahmed Hassan Awadallah, and Jianfeng Gao. Adamix: Mixture-of-adapter for parameter-efficient tuning of large language models. In EMNLP, 2022. Thomas Wolf, Lysandre Debut, Victor Sanh, Julien Chaumond, Clement Delangue, Anthony Moi, Pierric Cistac, Tim Rault, Rémi Louf, Morgan Funtowicz, et al. Huggingface’s transformers: State-of-the-art natural language processing. arXiv preprint arXiv:1910.03771, 2019. Elad Ben Zaken, Shauli Ravfogel, and Yoav Goldberg. Bitfit: Simple parameter-efficient fine-tuning for transformer-based masked language-models. arXiv preprint arXiv:2106.10199, 2021. Longteng Zhang, Lin Zhang, Shaohuai Shi, Xiaowen Chu, and Bo Li. Lora-fa: Memory-efficient low-rank adaptation for large language models fine-tuning. arXiv preprint arXiv:2308.03303, 2023. Qingru Zhang, Minshuo Chen, Alexander Bukharin, Pengcheng He, Yu Cheng, Weizhu Chen, and Tuo Zhao. Adaptive budget allocation for parameter-efficient fine-tuning. In ICLR, 2022. Sixiao Zheng, Jiachen Lu, Hengshuang Zhao, Xiatian Zhu, Zekun Luo, Yabiao Wang, Yanwei Fu, Jianfeng Feng, Tao Xiang, Philip HS Torr, et al. Rethinking semantic segmentation from a sequence-to-sequence perspective with transformers. In CVPR, 2021. Han Zhou, Xingchen Wan, Ivan Vulic, and Anna Korhonen. Autopeft: Automatic configuration ´ search for parameter-efficient fine-tuning. arXiv preprint arXiv:2301.12132, 2023.
# A APPENDIX
# A.1 BASELINES
We compare our proposed method Delta-LoRA with Fine-Tuning and prior works of LoRA, AdaLoRA, and DyLoRA. For PEFT methods, we only train the incremental updates for $W _ { V }$ and $W _ { Q }$ , following the setup as used in LoRA’s paper. For Fine-Tuning methods, we use two extra training paradigms: (1) freeze the embedding and train all the other parameters as Fine-Tuning $\dagger$ ; (2) train $W _ { V }$ and $W _ { Q }$ only as Fine-Tuning‡.
Fine-Tuning. In the past few years, fine-tuning has become the mainstream paradigm for both NLP and CV tasks. However, fine-tuning full parameters is subject to potential drawbacks including overfitting and training instability (Huang et al., 2022). Therefore, freezing a subset of network layers and fine-tuning the rest has become a popular choice (Tan et al., 2018). In our experiments, we compare with full fine-tuning, fine-tuning with embedding layers frozen (Fine-tuning $\dagger .$ ) and fine-tuning query and value matrices only (Fine-tuning $\ddagger$ ).
LoRA (Hu et al., 2022) uses multiplication of two low-rank matrices to learn the incremental updates with reduced GPU memory cost. We follow their setups to reproduce experimental results for fair comparison.
DyLoRA (Valipour et al., 2023) randomly chooses a rank $r$ for LoRA modules during learning.
AdaLoRA (Zhang et al., 2022) focuses on the challenge of determining the optimal rank for incremental updates. It employs an adaptive approach to singular value pruning, tailoring the rank selection to the magnitude of each singular value. Consequently, distinct ranks are employed for different layers.
A.2 THE COMPARISON BETWEEN LORA AND DELTA-LORA WITH LLAMA-7B
# A.2.1 TRAINING AND INFERENCE ARGUMENTS USED IN OUR METHOD AND BASELINE
We choose LLaMA-7B to evaluate our method and LoRA. Here, we set the learning rate $\gamma = 1 \mathrm { e } { - } 4$ , batch size to 128, $r = 8$ , $\alpha = 1 6$ , and training epochs to 3 for both two methods. Following the LoRA’s paper, we only tune $W _ { Q }$ and $W _ { V }$ . For Delta-LoRA, we choose start steps $K = 1 0 0$ and $\lambda = 0 . 2 5$ . When inference, we set the no_repeat_ngram_size $= 1 0$ , temperature ${ } = 0$ and beam size $=$ 4 to get a certain answer.
# A.2.2 THE EVALUATION FOR OUR METHOD AND BASELINES
Current LLMs obtain the training data from the Internet, which may unintentionally cause data leakage. Therefore, using the mainstream NLP datasets to evaluate the effectiveness of Large Language Model is not reasonable and wisdom. Inspired by evaluation approach proposed by Liu et al. (2023), we decided to use GPT-4 to judge the text generated by which method is accurate. First, we ask GPT-4 to generate 1,000 different questions. Second, we use the LLaMA-7B trained by two methods to generate the texts. Finally, we ask GPT-4 to give decision to tell us which text is accurate. It can choose from three options: a. Choice 1 (LoRA generates accurate text), b. Choice 2 (Delta-LoRA generates accurate text) and c. Both Choice 1 and 2 (Both LoRA and Delta-LoRA generate accurate texts). The prompt we used for evaluation:
Help me to determine which text is accurate for the given instruction and question. The answer can be chosen from a. Choice 1 is accurate, b. Choice 2 is accurate or c. both Choice 1 and 2 are accurate. Give me a certain answer and this is a choice question. Please don’t give reasons and the answer must be shorter than 20 words.
Question: "" (Choice 1): "" (Choice 2): ""
# A.3 ALGORITHM OF DELTA-LORA
Our Delta-LoRA can be found in Algorithm 1. Compared to LoRA, we added a step to update the pre-trained $W$ without any extra GPU memory consumption.
Algorithm 1: Delta-LoRA
<table><tr><td>Input: Learning rate n; weight decay β; total training iterations T; low rank r; scale factor α; start steps K;update ratio 入. A is initialized by Kaiming Initialization, B= O and W is initialized with pre-trained weights. fort=0,..,T-1do Sample a mini-batch and compute gradients for {A,B} in each Delta-LoRA module.</td></tr><tr><td>Update the first and second moments maintained by the optimizer with the computed gradients,</td></tr><tr><td>and get the normalized gradients gA and gB . A(t+1) ← A(t)-ngA-nβA6) B(t+1)←B(t)-ngB-nβB(t)</td></tr><tr><td>ift>Kdo W(t+1) ←W(t) +λ··(A(t+1)B(t+1)-A(t)B(t))</td></tr><tr><td>end if end for</td></tr><tr><td>Output: the fine-tuned parameters {W(T),A(T), B(T) }</td></tr></table>
# A.4 A FURTHER UNDERSTANDING OF DELTA-LORA
A.4.1 THE DIFFERENCES BETWEEN LORA AND DELTA-LORA
There are some fundamental differences between LoRA and Delta-LoRA.
• Given $W + A B$ , $W$ is fixed in LoRA, but $W$ will be updated in our Delta-LoRA. This is the largest difference between LoRA and Delta-LoRA. This modification can yield more training differences between LoRA and Delta-LoRA in the next few training steps.
$\cdot$ $\mathrm { R a n k } ( \Delta W _ { D e l t a - L o R A } ) = \mathrm { R a n k } ( W ^ { ( T ) } - W ^ { ( 0 ) } + A B ) > \mathrm { R a n k } ( \Delta W _ { L o R A } ) = \mathrm { R a n k } ( A B ) .$ The rank of the learned incremental weight matrix in our Delta-LoRA is larger than that in the original LoRA.
$\bullet$ The gradient flow is different between LoRA and Delta-LoRA. Suppose that we have $\pmb { W } \in \mathbb { R } ^ { m \times n }$ , $\pmb { A } \in \mathbb { R } ^ { m \times r }$ and $\boldsymbol { B } \in \mathbb { R } ^ { r \times n }$ , where $r \leq \operatorname* { m i n } ( m , n )$ . For LoRA, it keeps $W$ frozen, so that $W ^ { * } =$ $\begin{array} { r } { { \cal W } ^ { ( 0 ) } + \frac { \alpha } { r } \cdot { \cal A } ^ { ( t ) } { \cal B } ^ { ( t ) } } \end{array}$ . For Delta-LoRA, it updates all matrices, and has $\begin{array} { r } { W ^ { * } = W ^ { ( t ) } + \frac { \alpha } { r } \cdot A ^ { ( t ) } B ^ { ( t ) } } \end{array}$ .
$$\frac \left[ \begin{array} { l l l l } { \displaystyle \frac { A ^ { h _ { i } } } { \eta } } & { \displaystyle + \frac { \eta } { \eta } } & { \displaystyle } & { \right] } \left[ \begin{array} { l l l l } { \displaystyle \frac { A ^ { h _ { i } } } { \eta } } & { \displaystyle + \frac { \eta } { \eta } } & { \displaystyle h _ { i + 1 } = h _ { i } A } & { h _ { i + 1 } \in \mathbb R ^ { h \times r } } \\ { \displaystyle \frac { A ^ { h } } { \eta } } & { \displaystyle \frac { A ^ { h } } { \eta } } & { h _ { i + 1 } } & { h _ { i + 2 } = h _ { i + 1 } B } & { h _ { i + 2 } \in \mathbb R ^ { h \times n } } \\ { \displaystyle \frac { \left[ \begin{array} { l l l l } { \displaystyle h _ { i + 3 } } & { \displaystyle - \frac { A ^ { h } } { \eta } } & { \displaystyle h _ { i + 2 } } & { \displaystyle h _ { i + 3 } = h _ { i } W } & { h _ { i + 3 } \in \mathbb R ^ { b \times n } } \\ { \displaystyle h _ { i + 4 } } & { \displaystyle } & { \displaystyle } & { } \end{array} \right] } { \le\right]ft[ \begin{array} { l } { \displaystyle h _ { i + 3 } } \\ { \displaystyle h _ { i + 4 } } \end{array} \right] } } \end{array} \end{array}$$
Figure 4: The backward propagation of Delta-LoRA.
So, we have the following equation according to Figure 4:
$$\begin{array} { r l } & { \frac { \partial \mathcal { L } } { \partial W ^ { ( t ) } } = ( \frac { \partial h _ { i + 3 } } { \partial W ^ { ( t ) } } ) ^ { \top } \frac { \partial \mathcal { L } } { \partial h _ { i + 4 } } = h _ { i } ^ { \top } \frac { \partial \mathcal { L } } { \partial h _ { i + 4 } } } \\ & { \frac { \partial \mathcal { L } } { \partial A ^ { ( t ) } } = ( \frac { \partial h _ { i + 1 } } { \partial A ^ { ( t ) } } ) ^ { \top } \frac { \partial \mathcal { L } } { \partial h _ { i + 4 } } \cdot \frac { \partial h _ { i + 4 } } { \partial h _ { i + 2 } } \cdot \frac { \partial h _ { i + 2 } } { \partial h _ { i + 1 } } = h _ { i } ^ { \top } \frac { \partial \mathcal { L } } { \partial h _ { i + 4 } } \frac { \partial h _ { i + 2 } } { \partial h _ { i + 1 } } = h _ { i } ^ { \top } \frac { \partial \mathcal { L } } { \partial h _ { i + 4 } } B ^ { ( t ) \top } = \frac { \partial \mathcal { L } } { \partial W ^ { ( t ) } } \cdot B ^ { ( t ) \top } } \end{array}$$
$\begin{array} { r } { \frac { \partial \mathcal { L } } { \partial B ^ { ( t ) } } = ( \frac { \partial h _ { i + 1 } } { \partial B ^ { ( t ) } } ) ^ { \top } \cdot \frac { \partial \mathcal { L } } { \partial h _ { i + 4 } } \cdot \frac { \partial h _ { i + 4 } } { \partial h _ { i + 2 } } = h _ { i + 2 } ^ { \top } \cdot \frac { \partial \mathcal { L } } { \partial h _ { i + 4 } } = ( A ^ { ( t ) } ) ^ { \top } \cdot h _ { i } ^ { \top } \cdot \frac { \partial \mathcal { L } } { \partial h _ { i + 4 } } = ( A ^ { ( t ) } ) ^ { \top } \cdot \frac { \partial \mathcal { L } } { \partial W ^ { ( t ) } } } \end{array}$ Here, we provide the back-propagation process of LoRA:
$$\begin{array} { r l } & { \frac { \partial \mathcal { L } } { \partial A ^ { ( t + 1 ) } } = \frac { \partial \mathcal { L } } { \partial W ^ { ( t + 1 ) } } \cdot ( B ^ { ( t + 1 ) } ) ^ { \top } = \frac { \partial \mathcal { L } } { \partial ( W ^ { ( 0 ) } + ( A ^ { ( t ) } + \Delta A ^ { ( t ) } ) ( B ^ { ( t ) } + \Delta B ^ { ( t ) } ) ) } \cdot ( B ^ { ( t ) } + \Delta B ^ { ( t ) } ) ^ { \top } } \\ & { \frac { \partial \mathcal { L } } { \partial B ^ { ( t + 1 ) } } = ( A ^ { ( t + 1 ) } ) ^ { \top } \cdot \frac { \partial \mathcal { L } } { \partial W ^ { ( t + 1 ) } } = ( A ^ { ( t ) } + \Delta A ^ { ( t ) } ) ^ { \top } \cdot \frac { \partial \mathcal { L } } { \partial ( W ^ { ( 0 ) } + ( A ^ { ( t ) } + \Delta A ^ { ( t ) } ) ( B ^ { ( t ) } + \Delta B ^ { ( t ) } ) ) } } \end{array}$$
This is the back-propagation process of Delta-LoRA:
$$\begin{array} { r l } & { \frac { \partial \mathcal { L } } { \partial A ^ { ( t + 1 ) } } = \frac { \partial \mathcal { L } } { \partial W ^ { ( t + 1 ) } } \cdot ( B ^ { ( t + 1 ) } ) ^ { \top } = \frac { \partial \mathcal { L } } { \partial ( ( W ^ { ( t ) } + \lambda \Delta A ^ { ( t ) } B ^ { ( t ) } ) + ( A ^ { ( t ) } + \Delta A ^ { ( t ) } ) ( B ^ { ( t ) } + \Delta B ^ { ( t ) } ) } \cdot ( B ^ { ( t ) } + \Delta B ^ { ( t ) } ) ^ { \top } } \\ & { \frac { \partial \mathcal { L } } { \partial B ^ { ( t + 1 ) } } = ( A ^ { ( t + 1 ) } ) ^ { \top } \cdot \frac { \partial \mathcal { L } } { \partial W ^ { ( t + 1 ) } } = ( A ^ { ( t ) } + \Delta A ^ { ( t ) } ) ^ { \top } \cdot \frac { \partial \mathcal { L } } { \partial ( ( W ^ { ( t ) } + \lambda \Delta A ^ { ( t ) } B ^ { ( t ) } ) + ( A ^ { ( t ) } + \Delta A ^ { ( t ) } ) ( B ^ { ( t ) } + \Delta B ^ { ( t ) } ) ) } } \end{array}$$
# A.4.2 THE EXPANSION OF $\triangle { A B }$
In the real training process, we need to consider a variety of training arguments, such as optimizer and the regularization for $\triangle A B$ . Suppose that we use the AdamW (Loshchilov & Hutter, 2019) and $L _ { 2 }$ regularization, the $\triangle A B$ can be expanded in the following equation:
$$\begin{array} { r l } & { \triangle A B = A ^ { ( t + 1 ) } B ^ { ( t + 1 ) } - A ^ { ( t ) } B ^ { ( t ) } } \\ & { \qquad = ( A ^ { ( t ) } - \eta \hat { g } _ { A } - \eta \beta A ^ { ( t ) } ) \cdot ( B ^ { ( t ) } - \eta \hat { g } _ { B } - \eta \beta B ^ { ( t ) } ) - A ^ { ( t ) } B ^ { ( t ) } } \\ & { \qquad = A ^ { ( t ) } B ^ { ( t ) } - \eta A ^ { ( t ) } \hat { g } _ { B } - \eta \beta A ^ { ( t ) } B ^ { ( t ) } - \eta \hat { g } _ { A } B ^ { ( t ) } + \eta ^ { 2 } \hat { g } _ { A } \hat { g } _ { B } + \eta ^ { 2 } \beta \hat { g } _ { A } B ^ { ( t ) } } \\ & { \qquad - \eta \beta A ^ { ( t ) } B ^ { ( t ) } + \eta ^ { 2 } \beta A ^ { ( t ) } \hat { g } _ { B } + \eta ^ { 2 } \beta ^ { 2 } A ^ { ( t ) } B ^ { ( t ) } - A ^ { ( t ) } B ^ { ( t ) } } \\ & { \qquad = - \eta A ^ { ( t ) } \hat { g } _ { B } - \eta \beta A ^ { ( t ) } B ^ { ( t ) } - \eta \hat { g } _ { A } B ^ { ( t ) } + \eta ^ { 2 } \hat { g } _ { A } \hat { g } _ { B } + \eta ^ { 2 } \beta \hat { g } _ { A } B ^ { ( t ) } } \\ & { \qquad - \eta \beta A ^ { ( t ) } B ^ { ( t ) } + \eta ^ { 2 } \beta A ^ { ( t ) } \hat { g } _ { B } + \eta ^ { 2 } \beta ^ { 2 } A ^ { ( t ) } B ^ { ( t ) } } \\ & { \qquad \approx - \eta A ^ { ( t ) } \hat { g } _ { B } - \eta \hat { g } _ { A } B ^ { ( t ) } } \end{array}$$
where $\eta$ is the learning rate, $\beta$ is weight decay. What’s more, for pre-trained weight $W , \triangle W =$ $\eta \widehat { g } _ { W } + \eta \beta W ^ { ( t ) }$ . As a consequence, $\triangle A B$ is not equal to $\triangle W$ in the training process.
A.5 CHANGE THE LEARNING RATE AND START STEPS TO SHOW BETTER PERFORMANCE.
We explored better hyper parameters of our Delta-LoRA by modifying the learning rate and trying more start steps and update ratio to prove the effectiveness of Delta-LoRA.
Table 8: The evaluation results of our proposed Delta-LoRA by using better hyper-parameters on GLUE benchmark.
<table><tr><td>Method</td><td>MNLI</td><td> SST-2</td><td>MRPC</td><td>CoLA</td><td>QNLI</td><td>QQP</td><td>RTE</td><td>STS-B</td><td>AVG</td></tr><tr><td>LoRA</td><td>87.40</td><td>94.61</td><td>89.95</td><td>63.17</td><td>93.02</td><td>90.67</td><td>86.64</td><td>91.54</td><td>87.12</td></tr><tr><td>DyLoRA</td><td>86.33</td><td>94.26</td><td>89.46</td><td>61.12</td><td>92.22</td><td>90.17</td><td>84.47</td><td>91.06</td><td>86.14</td></tr><tr><td>AdaLoRA</td><td>87.34</td><td>94.49</td><td>90.19</td><td>61.64</td><td>93.08</td><td>90.14</td><td>85.19</td><td>91.16</td><td>86.65</td></tr><tr><td>Delta-LoRA</td><td>87.62±0.21</td><td>95.29±0.23 90.60±0.14</td><td></td><td></td><td>64.64±0.86 93.09±0.15 91.01±0.06 87.00±0.36 91.61±0.04 87.60</td><td></td><td></td><td></td><td></td></tr></table>
Table 9: The better training hyper-parameters that we obtained of our proposed Delta-LoRA on GLUE benchmark.
<table><tr><td>Hyper-Parameter|MNLI SST-2 MRPC CoLA QNLI QQP RTE STS-B</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>Learning Raten|4e-4 5e-4 5e-4 6e-4 3e-4 6e-4 4e-4 4e-4</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>Start Steps K</td><td>2000400</td><td></td><td>10</td><td>200600400200200</td><td></td><td></td><td></td><td></td></tr><tr><td>Update Ratio入</td><td>0.5</td><td>0.5</td><td>0.5</td><td>1</td><td>1</td><td>0.50.5</td><td></td><td>0.5</td></tr></table>
# A.6 THE PARAMETER SENSITIVITY STUDY
Table 10: The parameter sensitivity study of update ratio $\lambda$ for our proposed Delta-LoRA on E2E Challenge dataset. The best results are boldfaced.
<table><tr><td>入</td><td>BLEU</td><td>NIST</td><td>METEOR</td><td>ROUGE-L</td><td>CIDEr</td></tr><tr><td>0</td><td>68.94</td><td>8.73</td><td>45.27</td><td>70.81</td><td>2.41</td></tr><tr><td>1</td><td>69.77</td><td>8.81</td><td>45.99</td><td>71.58</td><td>2.46</td></tr><tr><td>2</td><td>70.84</td><td>8.91</td><td>46.47</td><td>72.24</td><td>2.53</td></tr><tr><td>3</td><td>70.14</td><td>8.84</td><td>46.39</td><td>71.45</td><td>2.45</td></tr><tr><td>4</td><td>70.03</td><td>8.83</td><td>46.21</td><td>71.56</td><td>2.47</td></tr><tr><td>5</td><td>70.13</td><td>8.85</td><td>46.35</td><td>71.72</td><td>2.48</td></tr></table>
Parameter Sensitivity. Here, we explore the hyper-parameter $K$ in Algorithm 1 and $\lambda$ in Equation 6. For the hyper-parameter $K$ , we select it from 0 to 1000 with the interval of 100. From Table 11, we find that our Delta-LoRA could not bring in any improvement before $K = 4 0 0$ , and it will keep a relatively good performance when $K$ is larger than 500. What is more, we choose different numbers for $\lambda$ , ranging from 0 to 5. According to Table 10, the 5 metrics rise rapidly after $\lambda = 0$ and reach best at $\lambda = 2$ , while the performance has small drops on 5 evaluation scores if $\lambda$ is chosen from 3 to 5.
Table 11: The parameter sensitivity study of start steps $K$ for our proposed Delta-LoRA on E2E Challenge dataset. The best results are boldfaced.
<table><tr><td>K</td><td>BLEU</td><td>NIST</td><td>METEOR</td><td>ROUGE-L</td><td>CIDEr</td></tr><tr><td>0</td><td>69.10</td><td>8.75</td><td>45.54</td><td>71.31</td><td>2.41</td></tr><tr><td>100</td><td>69.97</td><td>8.84</td><td>46.07</td><td>71.40</td><td>2.46</td></tr><tr><td>200</td><td>69.72</td><td>8.83</td><td>45.82</td><td>71.41</td><td>2.43</td></tr><tr><td>300</td><td>69.73</td><td>8.86</td><td>45.98</td><td>71.09</td><td>2.46</td></tr><tr><td>400</td><td>70.18</td><td>8.89</td><td>46.30</td><td>71.66</td><td>2.49</td></tr><tr><td>500</td><td>70.84</td><td>8.91</td><td>46.47</td><td>72.24</td><td>2.53</td></tr><tr><td>600</td><td>70.38</td><td>8.86</td><td>46.38</td><td>71.70</td><td>2.47</td></tr><tr><td>700</td><td>70.61</td><td>8.89</td><td>46.43</td><td>72.13</td><td>2.51</td></tr><tr><td>800</td><td>70.70</td><td>8.89</td><td>46.30</td><td>71.97</td><td>2.51</td></tr><tr><td>900</td><td>71.00</td><td>8.92</td><td>46.47</td><td>72.04</td><td>2.52</td></tr><tr><td>1000</td><td>70.87</td><td>8.89</td><td>46.31</td><td>72.06</td><td>2.50</td></tr></table>
# A.7 HYPER-PARAMETER USED IN OUR EXPERIMENTS
We report the hyper-parameter that used in our experiments. Table 12 and Table 13 show the hyperparameter that we used for the training and evaluation on E2E Challenge and WebNLG Challenge 2017 dataset. The Table 14 and Table 15 are the training and evaluation hyper parameter for XSum dataset, and the Table 16 consists of hyper-parameters for 8 datasets in GLUE benchmark.
Table 12: The training hyper-parameter used for E2E Challenge and WebNLG Challenge 2017 dataset.
<table><tr><td>Hyper-Parameter</td><td>E2E Challenge</td><td>WebNLG Challenge 2017</td></tr><tr><td>Learning Rate n</td><td>2e-4</td><td>2e-4</td></tr><tr><td>Batch Size</td><td>8</td><td>8</td></tr><tr><td>Number of Epochs</td><td>5</td><td>5</td></tr><tr><td>Weight Decay β</td><td>0.01</td><td>0.01</td></tr><tr><td>Resid_pdrop</td><td>0</td><td>0.09</td></tr><tr><td>Attn_pdrop</td><td>0</td><td>0.09</td></tr><tr><td>Embd_pdrop</td><td>0</td><td>0</td></tr><tr><td>Label Smooth</td><td>0</td><td>0</td></tr><tr><td> Start Steps K</td><td>500</td><td>500</td></tr><tr><td>Update Ratio 入</td><td>2</td><td>5</td></tr><tr><td>Rank r</td><td>4</td><td>4</td></tr><tr><td>Alpha α</td><td>32</td><td>32</td></tr><tr><td>Trainable Matrices</td><td>Wq,Wv</td><td>Wq,Wv</td></tr><tr><td>LR Scheduler</td><td>Linear</td><td>Linear</td></tr><tr><td>Warmup Steps</td><td>500</td><td>500</td></tr></table>
Table 13: The hyper-parameter for evaluation used for E2E Challenge and WebNLG Challenge 2017 dataset.
<table><tr><td>Hyper-Parameter</td><td>E2E Challenge</td><td>WebNLG Challenge 2017</td></tr><tr><td>Beam Size</td><td>10</td><td>5</td></tr><tr><td>Penalty</td><td>0.8</td><td>1.0</td></tr><tr><td>No Repeat Ngram Size</td><td>4</td><td>4</td></tr></table>
Table 14: The training hyper-parameter used for XSum dataset.
<table><tr><td>Hyper-Parameter</td><td>Xsum</td></tr><tr><td>Learning Rate n</td><td>2e-4</td></tr><tr><td>Batch Size</td><td>64</td></tr><tr><td>Number of Epochs</td><td>25</td></tr><tr><td>Weight Decay β</td><td>0</td></tr><tr><td>Activation Dropout</td><td>0</td></tr><tr><td>Dropout Classifier Dropout</td><td>0</td></tr><tr><td>Start Steps K</td><td>0</td></tr><tr><td></td><td>1000</td></tr><tr><td>Update Ratio 入</td><td>0.5</td></tr><tr><td>Rank r</td><td>4</td></tr><tr><td>Alpha α Trainable Matrices</td><td>32</td></tr><tr><td>LR Scheduler</td><td>Wq, Wv Linear</td></tr><tr><td>Warmup Steps</td><td>3000</td></tr></table>
Table 15: The hyper-parameter for evaluation used for XSum dataset.
<table><tr><td>Hyper-Parameter</td><td>Xsum</td></tr><tr><td>Beam Size</td><td>8</td></tr><tr><td>Penalty</td><td>1.0</td></tr><tr><td>No Repeat N-gram Size</td><td>4</td></tr></table>
Table 16: The training hyper-parameters of our proposed Delta-LoRA on GLUE benchmark. We adopt the most of hyper-parameters in LoRA’s paper and implement our method based on the codes given by LoRA’s repository.
<table><tr><td>Hyper-Parameter</td><td>MNLI</td><td>SST-2</td><td>MRPC</td><td>CoLA</td><td>QNLI</td><td>QQP</td><td>RTE</td><td>STS-B</td></tr><tr><td>Learning Rate n</td><td>5e-4</td><td>5e-4</td><td>4e-4</td><td>4e-4</td><td>4e-4</td><td>4e-4</td><td>4e-4</td><td>4e-4</td></tr><tr><td>Batch Size</td><td>128</td><td>128</td><td>128</td><td>64</td><td>256</td><td>128</td><td>128</td><td>128</td></tr><tr><td>Number of Epochs</td><td>30</td><td>60</td><td>30</td><td>80</td><td>25</td><td>25</td><td>80</td><td>40</td></tr><tr><td>Weight Decay β</td><td>0.1</td><td>0.1</td><td>0.1</td><td>0.1</td><td>0.1</td><td>0.1</td><td>0.1</td><td>0.1</td></tr><tr><td>Max Sequence Length</td><td>256</td><td>256</td><td>256</td><td>256</td><td>256</td><td>256</td><td>512</td><td>256</td></tr><tr><td>Start Steps K</td><td>2000</td><td>400</td><td>10</td><td>100</td><td>800</td><td>400</td><td>200</td><td>200</td></tr><tr><td>Update Ratio 入</td><td>0.5</td><td>0.5</td><td>0.5</td><td>0.5</td><td>0.5</td><td>0.5</td><td>0.5</td><td>0.5</td></tr><tr><td>Rank r</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td></tr><tr><td>Alpha α</td><td>16</td><td>16</td><td>16</td><td>16</td><td>16</td><td>16</td><td>16</td><td>16</td></tr><tr><td>LR Scheduler</td><td>Linear</td><td>Linear</td><td>Linear</td><td>Linear</td><td>Linear</td><td>Linear</td><td>Linear</td><td>Linear</td></tr><tr><td>Trainable Matrices</td><td>WQ,Wv WQ.Wv WQ,Wv</td><td></td><td></td><td>Wq,Wv</td><td></td><td></td><td></td><td> WQ,Wv WQ,Wv WQ,Wv WQ.Wv</td></tr><tr><td>Warmup Ratio</td><td>0.06</td><td>0.06</td><td>0.06</td><td>0.06</td><td>0.06</td><td>0.06</td><td>0.06</td><td>0.06</td></tr><tr><td>Evaluation Metrics</td><td></td><td>Accuracy Accuracy Accuracy</td><td></td><td> Mthtion Accuracy Accuracy Accuracy</td><td></td><td></td><td></td><td>Pearson</td></tr></table>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811[ { "type": "text", "text": "DELTA-LORA: FINE-TUNING HIGH-RANK PARAMETERS WITH THE DELTA OF LOW-RANK MATRICES ", "text_level": 1, "page_idx": 0 }, { "type": "text", "text": "Anonymous authors Paper under double-blind review ", "page_idx": 0 }, { "type": "text", "text": "ABSTRACT ", "text_level": 1, "page_idx": 0 }, { "type": "text", "text": "In this paper, we present Delta-LoRA, which is a novel parameter-efficient approach to fine-tune large language models (LLMs). In contrast to LoRA and other low-rank adaptation methods such as AdaLoRA, Delta-LoRA not only updates the low-rank matrices $\\pmb { A }$ and $\\textbf { { B } }$ , but also propagate the learning to the pre-trained weights $W$ via updates utilizing the delta of the product of two low-rank matrices $( \\boldsymbol { A } ^ { ( \\bar { t } + 1 ) } \\boldsymbol { B } ^ { ( t + 1 ) } - \\boldsymbol { A } ^ { ( t ) } \\boldsymbol { B } ^ { ( t ) } )$ . Such a strategy effectively addresses the limitation that the incremental update of low-rank matrices is inadequate for learning representations capable for downstream tasks. Moreover, as the update of $W$ does not need to compute the gradients of $W$ and store their momentums, Delta-LoRA shares comparable memory requirements and computational costs with LoRA. Extensive experiments show that Delta-LoRA significantly outperforms existing low-rank adaptation methods. We further support these results with comprehensive analyses that underscore the effectiveness of Delta-LoRA. ", "page_idx": 0 }, { "type": "text", "text": "1 INTRODUCTION ", "text_level": 1, "page_idx": 0 }, { "type": "text", "text": "Large Language Models (LLMs) recently have attracted considerable attention due to their remarkable performance across a broad spectrum of downstream tasks. Diverging from conventional Transformers characterized by a scale of millions of parameters, modern LLMs typically scale up to billions of parameters, endowing them with notable advantages such as emergent capabilities and robust generalization as detailed in (Bubeck et al., 2023). Fine-tuning such highly capable LLMs on downstream tasks (Raffel et al., 2020; Devlin et al., 2019; Radford et al., 2019; He et al., 2021; Liu et al., 2019; Brown et al., 2020) has consequently become a mainstream paradigm to reduce the training time required for individual tasks, yet with superior performance compared with other methods (Lester et al., 2021; Li & Liang, 2021; Houlsby et al., 2019). ", "page_idx": 0 }, { "type": "text", "text": "However, fine-tuning a LLM with all the learnable parameters (Full Fine-tuning) requires multiple GPUs with high memory demand (Dettmers et al., 2023; Hu et al., 2022), which is unattainable for many companies and research institutions. Full fine-tuning poses exceptional challenges to researchers: with massive parameter size, LLMs already demand more storage space than regular models; Further training exaggerates the GPU memory requirement because common optimizers such as AdamW (Loshchilov & Hutter, 2019) often maintain several copies of the model parameters, which is 2-3 times of memory overhead. ", "page_idx": 0 }, { "type": "text", "text": "To this end, a series of methods have been proposed (Valipour et al., 2023; Zhang et al., 2022; Li & Liang, 2021; Liu et al., 2022a; Lv et al., 2023; Dettmers et al., 2023; Liu et al., 2022b; Zaken et al., 2021; Pfeiffer et al., 2021; Guo et al., 2021; Zhou et al., 2023; Zhang et al., 2023; Houlsby et al., 2019; Wang et al., 2022) to reduce memory overhead at the training stage. Some even accelerate the fine-tuning process with only less than $1 \\%$ trainable parameters. Among these methods, LoRA (Hu et al., 2022) is the most attractive for its stable performance on broad downstream tasks (Ding et al., 2023), no observed overfitting, as well as no extra memory and computation cost at inference. ", "page_idx": 0 }, { "type": "text", "text": "While LoRA and its successors (Zhang et al., 2022; Valipour et al., 2023) have indeed exhibited superior performance in comparison to alternative approaches within the realm of Parameter Efficient Fine-Tuning (PEFT), a substantial performance gap persists when compared to the full fine-tuning, as highlighted in most scenarios (Ding et al., 2023). This discrepancy is attributed to the inherent limitation of updating only a fraction of the model’s parameters, rendering it inadequate to fit the intricacies presented in the training data. ", "page_idx": 0 }, { "type": "image", "img_path": "images/1ca0c1ec6ae0bdfd3ed1798fc6e45918c8fd23932e69b68d64eae2d7c5c29b9a.jpg", "image_caption": [ "Figure 1: An overview of the proposed Delta-LoRA structure, compared to LoRA, DyLoRA and AdaLoRA. Note that DyLoRA and LoRA basically share the same architecture. W is the pre-trained weight which is frozen (signified by blue) when performing efficient-parameter fine-tuning in (a) and (b). Orange trapezoids $\\pmb { A }$ , $\\textbf { { B } }$ and $\\pmb { \\cal E }$ denote the trainable parameters. In our proposed Delta-LoRA, the light orange rectangle means that pre-trained weights can be updated via the delta. Note that our proposed Delta-LoRA removes the Dropout layer to ensure reasonable delta for pre-trained matrix. " ], "image_footnote": [], "page_idx": 1 }, { "type": "text", "text": "To bridge this gap, a reasonable strategy is to introduce more parameters into the optimization process. In this paper, we introduce Delta-LoRA as shown in Fig. 1, a novel PEFT approach that simultaneously updates the pre-trained matrix and two low-rank matrices while maintaining the same memory consumption as the original LoRA. Specifically, the pre-trained matrix $W$ is updated with the delta of the product of two low-rank matrices in two consecutive iterations $\\triangle A B =$ $A ^ { ( t + 1 ) } B ^ { ( t + 1 ) } - A ^ { ( t ) } \\bar { B } ^ { ( t ) } )$ , while two low-rank matrices are updated by the AdamW optimizer automatically. This is based on the mathematical property that $\\begin{array} { r } { \\frac { \\partial \\mathcal { L } ^ { \\star } } { \\partial W } = \\frac { \\partial \\mathcal { L } } { \\partial A B } . } \\end{array}$ and $\\triangle A B$ is a surrogate to direct the update of $W$ (see Sec. 4 for details). Since we neither store the gradient of $W$ nor use the optimizer to update the pre-trained matrix, the proposed method thus does not yield any extra memory overhead. This strategic integration effectively mitigates the sub-optimal representation learning stemming from only updating the two low-rank matrices. Moreover, our approach aligns the update direction of the pre-trained weights with that of the incremental update matrix. Furthermore, we discard the Dropout layer in low-rank branches to obtain a more reasonable delta for $W$ , in order to ensure $\\begin{array} { r } { \\frac { \\partial \\mathcal { L } } { \\partial W } . = \\frac { \\partial \\check { \\mathcal { L } } } { \\partial A B } } \\end{array}$ . The advantages of our proposed method are conspicuous: including the pre-trained weights in the optimization process engenders a broader integration of parameters, thereby enhancing the potential for learning intricate representations. ", "page_idx": 1 }, { "type": "text", "text": "The main contributions of this paper can be summarized as: ", "page_idx": 1 }, { "type": "text", "text": "• We introduce Delta-LoRA, a novel PEFT method that simultaneously updates the full weight matrix and two low-rank matrices. Delta-LoRA leverages the delta of the product of $\\pmb { A }$ and $\\textbf { { B } }$ to update the pre-trained weights and thus prevent storing the first and the second-order momentums in the optimizer. \n• We analyze thbranch makes $\\begin{array} { r } { \\frac { \\partial \\Xi } { \\partial W } \\neq \\frac { \\partial \\mathcal { L } } { \\partial A B } } \\end{array}$ ow of Delta-LoRA and show that the Dropout layer in the low-rank. Thus, we remove the Dropout layer in our proposed Delta-LoRA to get reasonable delta for $W$ . \n• We conduct comprehensive experiments to show that Delta-LoRA has consistent gains on a broad range of NLP tasks. Additionally, we provide thorough explanations to analyze its superiority and the value contributed by each component. ", "page_idx": 1 }, { "type": "text", "text": "2 PRELIMINARIES ", "text_level": 1, "page_idx": 1 }, { "type": "text", "text": "Transformer-based Models. Transformer (Vaswani et al., 2017) adopts the self-attention mechanism instead of recurrence and convolutions, achieving new state-of-the-art in machine translation. Dosovitskiy et al. (2021) later proposed the Vision-Transformer (ViT) architecture which exhibits versatility across various computer vision tasks. Nowadays, the Transformer-based models have become the most popular choice in both NLP and Computer Vision (Li et al., 2021; Carion et al., 2020; Zheng et al., 2021). Transformer typically consists of $L$ stacked blocks, each containing a multi-head attention (MHA) module and a feed-forward network (FFN) module. For an input sequence $\\ b { X } \\in \\mathbb { R } ^ { n \\times d }$ , the MHA module yields the output $\\operatorname { M H A } ( X )$ , given by: ", "page_idx": 1 }, { "type": "text", "text": "", "page_idx": 2 }, { "type": "equation", "img_path": "images/f55f34c702fd129ebb084cd19f22d2ecdeedfb3924df3b45f0eb1962af2d34b3.jpg", "text": "$$\n\\begin{array} { r } { \\mathrm { h e a d } _ { i } = \\mathrm { s o f t m a x } ( \\frac { X W _ { Q _ { i } } ( X W _ { K _ { i } } ) ^ { \\top } } { \\sqrt { d _ { k } } } ) X W _ { V _ { i } } } \\\\ { \\mathrm { M H A } ( X ) = \\mathrm { c o n c a t } ( \\mathrm { h e a d } _ { 1 } , . . . , \\mathrm { h e a d } _ { k } ) W _ { o } , } \\end{array}\n$$", "text_format": "latex", "page_idx": 2 }, { "type": "text", "text": "where $d _ { k }$ is the scaling factor and set to $d _ { k } = d / k$ . $W _ { K _ { i } }$ $W _ { Q _ { i } }$ , $W _ { V _ { i } }$ and $W _ { o }$ are weight matrices for computation of key, query, value and the output of MHA, respectively. Besides the MHA module, the FFN is also vital in the Transformer-based model. It stacks two fully connected (FC) layers with an activation function in between. FFN is defined as: ", "page_idx": 2 }, { "type": "equation", "img_path": "images/2644eb5c23196218ed1ebc4db68a8ed8c0811f2e16062fba503f09b1f8e3c151.jpg", "text": "$$\n\\mathrm { F F N } ( \\pmb { x } ) = W _ { f _ { 2 } } \\mathrm { R e L U } ( W _ { f _ { 1 } } \\pmb { x } + b _ { 1 } ) + b _ { 2 } ,\n$$", "text_format": "latex", "page_idx": 2 }, { "type": "text", "text": "where $\\pmb { x } \\in \\mathbb { R } ^ { d }$ , $W _ { f _ { 1 } }$ and $W _ { f _ { 2 } }$ are two fully connected layers in FFN, $b _ { 1 }$ and $b _ { 2 }$ are bias terms. ", "page_idx": 2 }, { "type": "text", "text": "Low Rank Adaptation. Given a pre-trained matrix $\\boldsymbol { W } \\in \\mathbb { R } ^ { c \\times d }$ , LoRA ( $\\mathrm { H u }$ et al., 2022) learns an incremental update $\\triangle \\mathbf { { W } }$ and decomposes $\\triangle W$ into a matrix multiplication between two lowrank matrices $\\pmb { A }$ and $\\textbf { { B } }$ , where $\\pmb { A } \\in \\mathbb { R } ^ { c \\times r }$ and $\\boldsymbol { B } \\in \\mathbb { R } ^ { r \\times d }$ , and $\\triangle W = A B$ . Here, the rank $r \\ll m i n ( d , c )$ . For an input $_ { \\textbf { \\em x } }$ and hidden state $^ { h }$ , LoRA has the following forward process: ", "page_idx": 2 }, { "type": "equation", "img_path": "images/70f75d17594911e264922372df18ed14984b7eb15c868ba1a1061ceb89af8a7d.jpg", "text": "$$\n\\pmb { h } = \\pmb { W } ^ { * } \\pmb { x } = \\pmb { W } \\pmb { x } + \\triangle \\pmb { W } \\pmb { x } = \\pmb { W } \\pmb { x } + \\frac { \\alpha } { r } \\pmb { A } \\pmb { B } \\pmb { x }\n$$", "text_format": "latex", "page_idx": 2 }, { "type": "text", "text": "At the beginning of the training stage, $\\pmb { A }$ is randomly initialized via Kaiming initialization (He et al., 2015) and $\\textbf { { B } }$ is initialized to zero matrix to make sure that the incremental update $A B = \\mathbf { 0 }$ at initialization. Besides, LoRA uses hyper-parameters $\\alpha$ and $r$ to scale ${ \\pmb A } { \\pmb B } { \\pmb x }$ . ", "page_idx": 2 }, { "type": "text", "text": "3 RELATED WORKS ", "text_level": 1, "page_idx": 2 }, { "type": "text", "text": "With the ever-growing parameter scale in current Transformer-based models, fine-tuning such a large language model (LLM) requires considerable number of GPUs equipped with high memory capacity. This is mainly due to the fact that common optimizers such as AdamW (Loshchilov & Hutter, 2019) requires maintaining three times of extra parameter size (gradients, first-order and second-order momentums). To bridge this gap, a series of Parameter-Efficient Fine-Tuning (PEFT) methods have been proposed (Hu et al., 2022; Liu et al., 2022b; Shin et al., 2020; Houlsby et al., 2019). The Adapter (Houlsby et al., 2019) introduces lightweight trainable parameters between pre-trained layers while keeping the pre-trained weights fixed. Prompt-Tuning (Lester et al., 2021) aims to optimize the prompt to achieve comparable performance with fine-tuning for specific task, while Prefix-Tuning optimizes for trainable prefixes and prepends these trainable parameters to each hidden state (Li & Liang, 2021). Despite the notable performance achievements, these methods inevitably introduce extra overhead at the inference stage. ", "page_idx": 2 }, { "type": "text", "text": "Hu et al. (2022) proposed LoRA to utilize the multiplication of two low-rank matrices to model the incremental update of a full-rank matrix. LoRA merges the incremental updates to pre-trained weights after training, thereby avoiding any extra computation overhead during inference. Furthermore, it stands out as one of the most effective PEFT techniques according to Ding et al. (2023)’s evaluation. Subsequent to its inception, a series of enhanced methods building upon LoRA was proposed. Notably, G-LoRA (Chavan et al., 2023) leverages a generalized prompt module to fine-tune pre-trained weights resulting in better representations for computer vision tasks. DyLoRA (Valipour et al., 2023) aims to adjust the rank of two lightweight matrices after the training stage. Differing from the conventional approach of maintaining a static rank during training, DyLoRA introduces rank variations to its blocks. AdaLoRA (Zhang et al., 2022) emphasizes the disparate importance attributed to distinct weight parameters. This technique intelligently allocates the parameter budget across weight matrices based on their respective importance scores. Additionally, Q-LoRA (Dettmers et al., 2023) was proposed to further reduce the average memory footprint by quantizing the pre-trained model with 4-bit NormalFloat. This quantization approach not only preserves the model’s efficacy but also effectively alleviates the resource-intensive nature of LLM training and addresses a pertinent concern. ", "page_idx": 2 }, { "type": "image", "img_path": "images/037ce7a0f1a42468cb0674307bfde62dc2055b5d13ea1eeaf17d413680783a56.jpg", "image_caption": [ "Figure 2: The framework of our proposed Delta-LoRA. The blue arrows represent forward pass while yellow dashed arrows denote backward propagation. The black solid arrows in (b) represent the process of updating the low-rank adaptation matrices $\\pmb { A }$ and $\\textbf { { B } }$ with normalized gradients $\\widehat { \\mathbf { g } } _ { A }$ and $\\widehat { \\pmb { g } } _ { B }$ multiplied by the learning rate $\\eta$ , as well as updating the pre-trained weights $W$ bwith the delta bmatrix $\\triangle A B$ multiplied by the update ratio $\\lambda$ . " ], "image_footnote": [], "page_idx": 3 }, { "type": "text", "text": "4 METHODOLOGY ", "text_level": 1, "page_idx": 3 }, { "type": "text", "text": "This section introduces the novel fine-tuning approach termed as Delta-LoRA. Delta-LoRA encompasses two pivotal designs as shown in Figure 1 and Figure 2: (i) It simultaneously updates the full weight matrix $( W )$ alongside the two low-rank adaptation matrices $\\mathbf { \\delta A }$ and $\\textbf { { B } }$ ), utilizing the delta $( \\hat { A ^ { ( t + 1 ) } B ^ { ( t + 1 ) } } - A ^ { ( t ) } \\hat { B } ^ { ( t ) } )$ resulting from incremental updates to refine the pre-trained weights $( W )$ ; (ii) The Dropout layer as originally integrated within the conventional LoRA module, is excluded in Delta-LoRA. This omission stems from the realization that its presence violates the required assumption $\\begin{array} { r } { \\frac { \\partial \\mathcal { L } } { \\partial W } = \\frac { \\partial \\mathcal { L } } { \\partial A B } } \\end{array}$ . ", "page_idx": 3 }, { "type": "text", "text": "4.1 UPDATE THE DELTA OF LOW-RANK MATRICES ON PRE-TRAINED WEIGHTS", "text_level": 1, "page_idx": 3 }, { "type": "text", "text": "For an input $_ { \\textbf { \\em x } }$ and its corresponding hidden state $^ { h }$ , LoRA optimizes two low-rank matrices $\\pmb { A }$ and $\\textbf { { B } }$ to learn an incremental update $_ { A B }$ for the pre-trained and fixed weight matrix $W$ . Different from previous methods, we argue that $W$ also needs to be updated. In this way, we can introduce more learnable parameters to the optimization process for higher learning capability. However, acquiring the normalized gradients (i.e. the gradients after normalization in optimizer) to fine-tune the weight matrix $W$ is non-trivial, since the optimizer such as AdamW must maintain at least three extra copies of the parameters (i.e. gradients as well as the first-order and the second-order moments of gradients) in GPU memory. Intriguingly, we note that the gradients of the loss $\\mathcal { L }$ with respect to matrices $_ { A B }$ and $W$ are precisely identical, under the presumption that the LoRA module exclusively retains matrices $\\pmb { A }$ and $\\textbf { { B } }$ , while disregarding the Dropout layer. This correspondence can be formally represented as: ", "page_idx": 3 }, { "type": "equation", "img_path": "images/95257cbf066bc719e602036a008c8a79b946d66fabd6a65178a95ca73e35ccb0.jpg", "text": "$$\n\\begin{array} { l } { g _ { W } = \\displaystyle \\frac { \\partial \\mathcal { L } } { \\partial h _ { i + 1 } } \\cdot \\frac { \\partial h _ { i + 1 } } { \\partial W } ^ { \\top } = \\displaystyle \\frac { \\partial \\mathcal { L } } { \\partial h _ { i + 1 } } \\cdot h _ { i } ^ { \\top } , } \\\\ { g _ { A B } = \\displaystyle \\frac { \\partial \\mathcal { L } } { \\partial h _ { i + 1 } } \\cdot \\frac { \\partial h _ { i + 1 } } { \\partial A B } ^ { \\top } = \\displaystyle \\frac { \\partial \\mathcal { L } } { \\partial h _ { i + 1 } } \\cdot h _ { i } ^ { \\top } , } \\\\ { \\implies g _ { W } = g _ { A B } , } \\end{array}\n$$", "text_format": "latex", "page_idx": 3 }, { "type": "text", "text": "where $h _ { i + 1 } = W h _ { i } + A B h _ { i } .$ , $\\boldsymbol { h } _ { i }$ and $\\boldsymbol { h } _ { i + 1 }$ are the outputs of the $i$ -th layer and the $_ { i + 1 }$ -th layer respectively. $_ { A B }$ is the matrix product of the adaptation matrices $\\pmb { A }$ and $\\textbf { { B } }$ , $\\mathcal { L }$ is the loss function, while $g _ { W + A B } , g _ { W }$ and $\\mathbf { \\sigma } _ { \\mathbf { \\sigma } _ { g _ { A B } } }$ denote the gradients of ∂L∂(W +AB) , ∂L∂W , and ∂ $\\frac { \\partial \\mathcal { L } } { \\partial A B }$ respectively. ", "page_idx": 3 }, { "type": "text", "text": "Equation 4 inspires us to use $\\mathbf { \\sigma } _ { \\mathbf { \\sigma } _ { g _ { A B } } }$ to assimilate $\\mathbf { \\Delta } _ { g _ { W } }$ when learning the parameter updates for weight matrix $W$ . Unfortunately, we are only able to obtain the gradients $\\mathbf { \\pmb { g } } _ { \\pmb { A } }$ and $\\mathbf { \\nabla } _ { \\mathbf { \\pmb { g } } \\mathbf { \\it { B } } }$ rather than $\\mathbf { \\Delta } _ { \\mathbf { \\mathcal { { g } } } \\mathbf { \\Delta } _ { W } }$ during the back-propagation process. Furthermore, the computation of the gradients for $_ { A B }$ is as expensive as for the matrix $W$ , since both matrices share the same dimensions of $d \\times k$ , consequently entailing an equivalent GPU memory overhead. ", "page_idx": 3 }, { "type": "text", "text": "", "page_idx": 4 }, { "type": "text", "text": "Considering a typical optimization process, the model updates its parameters by applying the gradient descent: $\\boldsymbol { W } ^ { ( t + 1 ) } = \\boldsymbol { W } ^ { ( t ) } - \\eta \\boldsymbol { g } _ { \\boldsymbol { W } }$ , with the parameter update denoted as $\\triangle W = - \\eta g _ { W }$ , using the learning rate $\\eta$ . Similarly, we regard $- \\triangle A B$ as the gradients for $_ { A B }$ and utilize this matrix as a substitute for $\\mathbf { \\Delta } _ { g _ { W } }$ according to Equation 4. Here, we can compute $\\triangle A B$ as: ", "page_idx": 4 }, { "type": "equation", "img_path": "images/d1113a3f92d45b5c22d6b134b15c5e12b757b82b7c1ac4d8f926ac787c51bf3b.jpg", "text": "$$\n\\triangle { \\cal A } B = { \\cal A } ^ { ( t + 1 ) } B ^ { ( t + 1 ) } - { \\cal A } ^ { ( t ) } B ^ { ( t ) } = \\eta { \\cal A } ^ { ( t ) } g _ { B } + \\eta g _ { A } B ^ { ( t ) } - \\eta ^ { 2 } g _ { A } g _ { B } ,\n$$", "text_format": "latex", "page_idx": 4 }, { "type": "text", "text": "where $A ^ { ( t ) }$ , $B ^ { ( t ) }$ and $\\mathbf { \\mathbf { } } W ^ { ( t ) }$ are the weights of $A , B$ and $W$ at the $t { \\cdot }$ -th step respectively, $A ^ { ( t + 1 ) } =$ $A ^ { ( t ) } - \\eta g _ { A }$ , $B ^ { ( t + 1 ) } = B ^ { ( t ) } - \\eta \\pmb { g } _ { B }$ and $\\eta$ is the learning rate. To be precise, $- \\triangle A B$ does not equate directly to $\\mathbf { \\sigma } _ { \\mathbf { \\sigma } _ { g _ { A B } } }$ and $\\mathbf { \\Delta } _ { \\mathbf { \\mathcal { { g } } } \\mathbf { \\Delta } _ { W } }$ as elaborated in Appendix A.4.2. Nonetheless, $\\triangle A B$ has the capability to symbolize the genuine directions of update for the matrix $_ { A B }$ . Based on this assumption, it is reasonable to employ $- \\triangle A B$ as the gradient for directing the update of $W$ . ", "page_idx": 4 }, { "type": "text", "text": "Therefore, during the training phase we introduce the matrix $\\triangle A B$ to update the pre-trained weights $W$ in the following manner: ", "page_idx": 4 }, { "type": "equation", "img_path": "images/9a3179d521c61ebb8ffb53739f6d4760bf3e7b00e49e537240a28bb15da1e09a.jpg", "text": "$$\n{ \\bf W } ^ { ( t + 1 ) } = { \\bf W } ^ { ( t ) } + \\lambda \\cdot \\frac { \\alpha } { r } \\cdot \\triangle A B , { \\mathrm { w h e r e ~ } } \\triangle A B = { \\cal A } ^ { ( t + 1 ) } B ^ { ( t + 1 ) } - { \\cal A } ^ { ( t ) } B ^ { ( t ) } ,\n$$", "text_format": "latex", "page_idx": 4 }, { "type": "text", "text": "where $\\lambda$ represents the hyper-parameter to trade off the update ratio of $_ { A B }$ and the pre-trained weights $W$ . The parameter updates for $W$ commence after $K$ training iterations. The procedural details of the algorithm are illustrated in Algorithm 1. ", "page_idx": 4 }, { "type": "text", "text": "Discussion. The Delta-LoRA has some important modifications compared to LoRA. Here, we discuss and compare the difference: ", "page_idx": 4 }, { "type": "table", "img_path": "images/9d9e25da4fca476561e29d0e85e617c5a6c515f2b89fb10a3194629d5c010bb5.jpg", "table_caption": [], "table_footnote": [], "table_body": "<table><tr><td colspan=\"2\">LoRA</td><td colspan=\"2\">1 Delta-LoRA 1 1</td></tr><tr><td rowspan=\"2\">(1) A(t+1) ← ∂L(χ;W,A(t),B(t))</td><td>1 1</td><td>aL(x;W(t),A(t),B(t)) (1) A(t+1) ←</td><td rowspan=\"2\"></td></tr><tr><td>aA(t)</td><td>aA(t)</td></tr><tr><td rowspan=\"3\">(2) B(t+1) ← ∂C(χ:W.A(t),B(t))</td><td></td><td>1 (2) B(t+1) ← 0L(ω:W(t),A(t),B(t))</td><td>aB(t)</td></tr><tr><td>∂B(t)</td><td></td><td></td></tr><tr><td></td><td></td><td>(3)W(t+1) ← A(t+1)B(t+1) - A(t)B(t)</td></tr></table>", "page_idx": 4 }, { "type": "text", "text": "It is obvious that LoRA only updates $\\pmb { A }$ and $\\textbf { { B } }$ , and keeps $W$ frozen, while Delta-LoRA updates $\\pmb { A }$ and $\\textbf { { B } }$ by the optimizer and $W$ with the delta of the product of $\\pmb { A }$ and $\\textbf { { B } }$ . ", "page_idx": 4 }, { "type": "text", "text": "4.2 THE STRUCTURE OF OUR DELTA-LORA ", "text_level": 1, "page_idx": 4 }, { "type": "text", "text": "Both LoRA and its successor AdaLoRA put a Dropout layer before two low-rank matrices $\\pmb { A }$ and $\\textbf { { B } }$ . However, this arrangement results in a disparity between the gradient matrices $\\mathbf { \\Delta } _ { g _ { W } }$ and $\\mathbf { \\sigma } _ { \\mathbf { \\sigma } _ { g _ { A B } } }$ (or the matrix $\\mathbf { \\_ { \\_ { \\_ { \\delta A E B } } } }$ in the context of AdaLoRA). The derivation of this disparity can be shown as: ", "page_idx": 4 }, { "type": "equation", "img_path": "images/d5e04b80286b8059cbc80569079c089a6c70080998409316587498e9b8b64858.jpg", "text": "$$\ng _ { W } = { \\frac { \\partial { \\mathcal { L } } } { \\partial h _ { i + 1 } } } \\cdot h _ { i } ^ { \\top } \\neq g _ { A B } = { \\frac { \\partial { \\mathcal { L } } } { \\partial h _ { i + 1 } } } \\cdot \\mathrm { D r o p } ( h _ { i } ) ^ { \\top } ,\n$$", "text_format": "latex", "page_idx": 4 }, { "type": "text", "text": "where $\\mathrm { D r o p } ( \\cdot )$ denotes the Dropout layer which leads to $g _ { W } \\neq g _ { A B }$ . A reasonable choice is to remove the Dropout layer in the low-rank module and activate the Dropout layer between pre-trained layers if overfitting problem occurs. This modification also brings additional benefits: (1) it can alleviate under-fitting to some extent, thereby enhancing the learned representations of the networks. The rationale behind this improvement lies in the fact that LoRA and its successors formulate low-rank updates for pre-trained weights, involving less than $1 \\%$ of the complete parameters. However, relying solely on such a small fraction of parameters may not bestow an adequate representation capacity in most cases; (2) This alteration also yields memory-saving benefits. By negating the requirement to store intermediate features, the model curtails the memory consumption. Consequently, there is a reduction in activation memory employed during the back-propagation process. ", "page_idx": 4 }, { "type": "text", "text": "5 EXPERIMENTS ", "text_level": 1, "page_idx": 4 }, { "type": "text", "text": "We evaluate our proposed model fine-tuning method Delta-LoRA with RoBERTa (Liu et al., 2019), GPT-2 (Radford et al., 2019) and BART (Lewis et al., 2019) on a broad set of datasets. Specifically, we train (1) RoBERTa on GLUE benchmark which consists of 8 NLP understanding tasks; (2) GPT-2 on E2E Challenge and WebNLG Challenge 2017 following the setting of Hu et al. (2022); and (3) BART on XSum dataset by using the setting provided by Zhang et al. (2022). See Appendix A.7 for more training details on the datasets. The setups and detailed introductions of baseline methods are shown in Appendix A.1. We use PyTorch to implement our experiments and download the pre-trained weights as well as configuration files from HuggingFace Wolf et al. (2019). ", "page_idx": 4 }, { "type": "text", "text": "", "page_idx": 5 }, { "type": "text", "text": "Table 1: The evaluation results of our proposed Delta-LoRA and other existing methods on E2E NLG Challenge dataset. $\\dagger$ indicates fine-tuning all layers except embedding layer. $^ \\ddag$ indicates only fine-tuning weights for query and value. $^ \\mathparagraph$ means we choose different settings with AdaLoRA: we only tune $W _ { Q }$ and $W _ { V }$ instead of all layers. The best results of Fine-Tuning methods are underlined. The best results of PEFT methods are boldfaced. ", "page_idx": 5 }, { "type": "table", "img_path": "images/5a4925a9663990b313825f10dd9729f95b01c4f4a88252897fdc395329f046c5.jpg", "table_caption": [ "Table 2: The evaluation results of our proposed Delta-LoRA and other existing methods on WebNLG Challenge 2017 dataset. $\\dagger$ indicates fine-tuning all layers except embedding layer. $\\ddagger$ indicates only fine-tuning weights for query and value. $^ \\mathparagraph$ means we choose different settings with AdaLoRA: we only tune $W _ { Q }$ and $W _ { V }$ instead of all layers. The best results of Fine-Tuning methods are underlined. The best results of PEFT methods are boldfaced. " ], "table_footnote": [], "table_body": "<table><tr><td>Method</td><td></td><td>Trainables|Exrupdale</td><td></td><td></td><td></td><td>BLEU NIST METEOR ROUGE-L CIDEr</td><td></td></tr><tr><td>Full Fine-Tuning</td><td>354.92M</td><td></td><td>69.58</td><td>8.75</td><td>46.34</td><td>71.66</td><td>2.47</td></tr><tr><td>Fine-Tuningt</td><td>305.84M</td><td></td><td>69.37</td><td>8.76</td><td>46.05</td><td>71.97</td><td>2.44</td></tr><tr><td>Fine-Tuningt</td><td>48M</td><td>×</td><td>69.77</td><td>8.84</td><td>46.29</td><td>71.96</td><td>2.49</td></tr><tr><td>LoRA (repr.)</td><td>0.375M</td><td>X</td><td>69.60</td><td>8.78</td><td>45.61</td><td>71.12</td><td>2.45</td></tr><tr><td>LoRA</td><td>0.35M</td><td></td><td>70.4</td><td>8.85</td><td>46.8</td><td>71.8</td><td>2.53</td></tr><tr><td>DyLoRA</td><td>0.375M</td><td></td><td>67.89</td><td>8.50</td><td>44.07</td><td>70.52</td><td>2.26</td></tr><tr><td>AdaLoRA</td><td>0.375M</td><td></td><td>68.16</td><td>8.58</td><td>44.10</td><td>70.66</td><td>2.35</td></tr><tr><td>Delta-LoRA (Ours)</td><td>0.375M</td><td>√48M</td><td>70.84</td><td>8.91</td><td>46.47</td><td>72.24</td><td>2.53</td></tr></table>", "page_idx": 5 }, { "type": "table", "img_path": "images/9a3abb0b5d99c654333e2c66bea506773b2613725539c0dd6ba47825643e39c7.jpg", "table_caption": [], "table_footnote": [], "table_body": "<table><tr><td>Method</td><td></td><td>PTrainables Exraupdatable</td><td>S BLEU↑</td><td>A</td><td>METEOR↑</td><td>S</td><td>TER</td><td>A</td></tr><tr><td>FullFine-Tuning</td><td>354.92M</td><td></td><td></td><td></td><td>61.38 45.11 54.480.44 0.38 0.410.36 0.53 0.44</td><td></td><td></td><td></td></tr><tr><td>Fine-Tuningt</td><td>305.84M</td><td>×</td><td></td><td></td><td>63.53 46.66 55.920.45 0.39 0.420.34 0.49 0.41</td><td></td><td></td><td></td></tr><tr><td>Fine-Tuningt</td><td>48M</td><td>×</td><td></td><td></td><td>64.55 48.06 57.080.46 0.39 0.430.33 0.47 0.40</td><td></td><td></td><td></td></tr><tr><td>LoRA (repr.)</td><td>0.375M</td><td>X</td><td>62.08 46.60 55.050.44 0.38 0.410.35 0.49 0.42</td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>LoRA</td><td>0.375M</td><td></td><td>62.1</td><td>46.7 55.3</td><td>0.440.380.41</td><td></td><td>0.330.460.39</td><td></td></tr><tr><td>DyLoRA</td><td>0.375M</td><td>×</td><td></td><td></td><td>58.39 46.02 52.77|0.42 0.37 0.40|0.38 0.49 0.43</td><td></td><td></td><td></td></tr><tr><td>AdaLoRA</td><td>0.375M</td><td>×</td><td>56.39 44.14 50.820.41 0.37 0.390.40 0.49 0.44</td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>Delta-LoRA (Ours)</td><td>0.375M</td><td>√48M</td><td></td><td></td><td></td><td></td><td>62.87 47.68 55.960.45 0.39 0.420.34 0.48 0.40</td><td></td></tr></table>", "page_idx": 5 }, { "type": "text", "text": "5.1 NATURAL LANGUAGE GENERATION ", "text_level": 1, "page_idx": 5 }, { "type": "text", "text": "Models and Datasets. We use GPT2-Medium to verify the effectiveness of our Delta-LoRA on two datasets for data-to-text tasks, including the E2E NLG Challenge (Puzikov & Gurevych, 2018) and WebNLG Challenge 2017 (Gardent et al., 2017). The E2E NLG Challenge dataset comprises 42,000 samples for training, 4,600 for validation, and 4,600 for testing purposes. In contrast, the WebNLG Challenge 2017 consists of 21,855 training samples across nine categories, expanding to a total of 14 categories in the test set. For the text summarization task, we employed BART-Large (Lewis et al., 2019) to evaluate the efficacy of our method using the XSum dataset (Narayan et al., 2018). The XSum dataset is composed of 204,045 training samples, 11,332 validation samples, and 11,332 test samples. We also use LLaMA-7B(Touvron et al., 2023), a popular pre-trained large language model with 7 Billion parameters,to fine-tune on Alpaca dataset (Taori et al., 2023). ", "page_idx": 5 }, { "type": "text", "text": "Implementation Details. In order to compare with LoRA and its successors fairly, we adopt the model setups from LoRA to implement our Delta-LoRA and three PEFT methods. We only learn the low-rank incremental update for $W _ { Q }$ and $W _ { V }$ in MHA module. For data-to-text datasets, we use the same training configurations as adopted by LoRA, including the number of training epochs, batch size and etc. We use update ratio $\\lambda = 2$ and set start steps $K = 5 0 0$ for Delta-LoRA. More details about Delta-LoRA are listed in the Appendix A.7. For the text-summarization task, we use the implementation of AdaLoRA and adopt the same training configurations. We set the update ratio $\\lambda = 0 . 5$ and the start steps $K = 1 0 0 0$ for Delta-LoRA. ", "page_idx": 5 }, { "type": "table", "img_path": "images/6d52a5ca410fa47ba56cca5b1ec9485c800c33be78d19dedd041b92d51c60422.jpg", "table_caption": [ "Table 3: The evaluation results of Delta-LoRA with LLaMA-7B on the Instruction-Tuning dataset provided by Stanford Alpaca(Taori et al., 2023). We use GPT-4 to choose from a. LoRA, b. DeltaLoRA or c. Both LoRA and Delta-LoRA to decide the text from which method is better. " ], "table_footnote": [], "table_body": "<table><tr><td>Both</td><td>LoRA</td><td>Delta-LoRA</td><td>Total</td></tr><tr><td>886</td><td>10</td><td>104</td><td>1,000</td></tr></table>", "page_idx": 6 }, { "type": "text", "text": "", "page_idx": 6 }, { "type": "text", "text": "Experimental Results. Table 1 shows the results for E2E Challenge dataset on 5 evaluation metrics, demonstrating that our method achieves state-of-the-art performance over 3 baselines and a set of fine-tuning methods. For the BLEU and ROUGE-L metrics, our method obtains 1.24 and 1.13 performance gains compared with LoRA, with 0.13, 0.86 and 0.08 improvement on NIST, METEOR and CIDEr respectively. Table 2 demonstrates that Delta-LoRA outperforms baselines on BLEU score for WebNLG Challenge 2017 dataset, with 0.79, 1.08 and 0.91 improvement on Seen, Unseen and All test data, respectively. Additionally, for the METEOR and TER evaluation metrics, Delta-LoRA also achieves state-of-the-art performance, with 0.01 and 0.02 improvement over LoRA on all data. For the text-summarization task, the test results are shown in Table 4, which demonstrates that our method achieves state-of-the-art results across 3 parameter-efficient methods on 4 evaluation metrics. To fairly evaluate our method, we utilized LLaMA-7B and compared it with LoRA. We employed GPT-4 to generate 1,000 questions and presented these questions to the parameter-efficient fine-tuned LLaMA-7B. Subsequently, we leveraged GPT-4 to compare the texts generated by LoRA-tuned and Delta-LoRA-tuned LLMs. Additional details can be found in Appendix A.2. According to the findings in Table 3, Delta-LoRA establishes state-of-the-art performance in the evaluation of Language Models (LLMs). GPT-4 identified 104 samples generated by Delta-LoRA as superior to LoRA, while only 10 samples generated by LoRA exhibited higher quality than Delta-LoRA. This underscores Delta-LoRA’s effectiveness even when utilized within models containing billions of parameters. ", "page_idx": 6 }, { "type": "table", "img_path": "images/18c5f81ef84d14b7664d2fa8b74d5de1ae903239dbbb236abfcfdb66aeae15c1.jpg", "table_caption": [ "Table 4: The evaluation results of our proposed Delta-LoRA and other existing methods on XSum dataset. $\\dagger$ indicates fine-tuning all layers except the embedding layer. $^ \\ddag$ indicates only fine-tuning weights for query and value. $\\ P$ means we choose different settings with AdaLoRA: we only tune $W _ { Q }$ and $W _ { V }$ instead of all layers. The best results of Fine-Tuning methods are underlined. The best results of PEFT methods are boldfaced. " ], "table_footnote": [], "table_body": "<table><tr><td>Method</td><td></td><td> PTrainablesExraUpdatable</td><td></td><td></td><td></td><td>Rouge-1 Rouge-2 Rouge-L Rouge-Sum</td></tr><tr><td>Full Fine-Tuning</td><td>387.5M</td><td></td><td>45.36</td><td>22.16</td><td>37.23</td><td>37.24</td></tr><tr><td>Fine-Tuningt</td><td>338.4M</td><td>xx</td><td>45.04</td><td>22.05</td><td>36.92</td><td>36.94</td></tr><tr><td>Fine-Tuningt</td><td>72M</td><td></td><td>44.95</td><td>21.43</td><td>36.35</td><td>36.37</td></tr><tr><td>LoRA</td><td>0.56M</td><td>X</td><td>43.27</td><td>20.13</td><td>35.12</td><td>35.12</td></tr><tr><td>DyLoRA</td><td>0.56M</td><td>×</td><td>41.84</td><td>18.76</td><td>33.56</td><td>33.57</td></tr><tr><td>AdaLoRAI</td><td>0.56M</td><td>X</td><td>42.91</td><td>19.76</td><td>34.71</td><td>34.72</td></tr><tr><td>Delta-LoRA (Ours)</td><td>0.56M</td><td>√72M</td><td>43.49</td><td>20.23</td><td>35.26</td><td>35.26</td></tr></table>", "page_idx": 6 }, { "type": "text", "text": "5.2 NATURAL LANGUAGE UNDERSTANDING ", "text_level": 1, "page_idx": 6 }, { "type": "text", "text": "Models and Datasets. We use RoBERTa-baseLiu et al. (2019) to evaluate the performance of our proposed method, prior works and three fine-tuning methods. We choose the GLUE benchmark consisting of 8 datasets (Wang et al., 2019), including classification tasks, similarity and paraphrase tasks and natural language inference tasks. ", "page_idx": 6 }, { "type": "text", "text": "Implementation Details. We use RoBERTa-base with 118M parameters to conduct our experiments and to compare our method with the baselines. We mostly adopt the same training configurations of ", "page_idx": 6 }, { "type": "text", "text": "LoRA, more details can get from Appendix A.7. We set the rank to 8 and the target rank to 6 for AdaLoRA and choose the rest of hyper-parameters according to the characteristics of different tasks. For Delta-LoRA, we set the update ratio $\\lambda$ to 0.5 and choose different start steps $K$ according to warmup steps used in individual tasks. ", "page_idx": 7 }, { "type": "table", "img_path": "images/e1db5f4642bf7cab3c6eef750a7a93687dc02950f4a45707f5b0dc5672a36528.jpg", "table_caption": [ "Table 5: The evaluation results of our proposed Delta-LoRA and other existing methods on GLUE benchmark. We report the overall (matched and mismatched) accuracy for MNLI, Matthew’s correlation for CoLA, Pearson correlation for STS-B, and accuracy for other tasks. $\\dagger$ indicates fine-tuning all layers except the embedding layer. $\\ddagger$ indicates only fine-tuning weights for query and value. $^ \\mathparagraph$ means we choose different settings with AdaLoRA: we only tune $W _ { Q }$ and $W _ { V }$ instead of all layers. The best results of Fine-Tuning methods are underlined. The best results of PEFT methods are boldfaced. " ], "table_footnote": [], "table_body": "<table><tr><td>Method</td><td></td><td></td><td>TraiableErUpdatablMNLISS-2 MRPC CoLA QNLIQP RTE STS-B AVG</td></tr><tr><td>Full Fine-Tuning</td><td>118.87M</td><td>X</td><td>87.51 94.26 88.23 64.57 92.73 91.96 84.11 90.56 86.74</td></tr><tr><td>Fine-Tuningt</td><td>82.05M</td><td>×</td><td>87.58 94.03 89.95 62.99 92.73 91.90 86.64 90.22 87.01</td></tr><tr><td>Fine-Tuningt</td><td>13.5M</td><td>×</td><td>87.48 95.06 89.21 61.07 92.76 91.19 84.83 89.85 86.43</td></tr><tr><td>LoRA</td><td>0.28M</td><td>X</td><td>87.40 94.61 89.95 63.17 93.02 90.67 86.64 91.54 87.12</td></tr><tr><td>DyLoRA</td><td>0.28M</td><td>X</td><td>86.33 94.26 89.46 61.12 92.22 90.17 84.47 91.06 86.14</td></tr><tr><td>AdaLoRA</td><td>0.28M</td><td>×</td><td>87.34 94.49 90.19 61.64 93.08 90.14 85.19 91.16 86.65</td></tr><tr><td>Delta-LoRA (Ours)</td><td>0.28M</td><td>√13.5M</td><td>87.50 95.06 90.19 63.82 93.09 90.87 87.00 91.57 87.38</td></tr></table>", "page_idx": 7 }, { "type": "text", "text": "Experimental Results. We compare our method with prior PEFT works. According to Table 5, our method outperforms existing methods on all 8 tasks in GLUE benchmark. Among these tasks, our method demonstrates significant improvement on SST-2, CoLA and RTE. This is mainly due to the fact that these datasets contain less training data, which hinders the model’s capacity to effectively acquire a robust representation when using prior fine-tuning methods. Delta-LoRA also achieves decent performance on the rest of the datasets, including MNLI, MRPC, QNLI as well STS-B, which proves that our method is stable and reliable across different settings. ", "page_idx": 7 }, { "type": "text", "text": "5.3 COMPREHENSIVE UNDERSTANDING OF DELTA-LORA ", "text_level": 1, "page_idx": 7 }, { "type": "table", "img_path": "images/dbdff6b48a80432c9339dd679b12aaee917a7aed12615c8693d3653c6b5537bd.jpg", "table_caption": [ "Table 6: The ablation study of our proposed Delta-LoRA on E2E Challenge dataset demonstrates the importance of each component. The best results are boldfaced. " ], "table_footnote": [], "table_body": "<table><tr><td>Method</td><td>Trainable Parameters</td><td>Parameters</td><td>Extra Updatable|BLEU NIST METEOR ROUGE-L CIDEr</td><td></td><td></td><td></td></tr><tr><td>LoRA (repr.)</td><td>0.375M</td><td></td><td>69.60 8.78</td><td>45.61</td><td>71.12</td><td>2.45</td></tr><tr><td>Delta-LoRA + LoRA Module</td><td>0.375M</td><td>√48M</td><td>70.29 8.88</td><td>46.38</td><td>71.88</td><td>2.51</td></tr><tr><td>Delta-LoRA</td><td>0.375M</td><td>√48M</td><td>70.84 8.91</td><td>46.47</td><td>72.24</td><td>2.53</td></tr></table>", "page_idx": 7 }, { "type": "table", "img_path": "images/41725e6c83c08bec0e98a3c0063d770c4211a61adb3e6eec6a080c2f03bc3a69.jpg", "table_caption": [ "Table 7: The ablation study of our proposed Delta-LoRA to eliminate the impact of hyper-parameter $\\lambda$ on E2E Challenge dataset. The best results are boldfaced. " ], "table_footnote": [], "table_body": "<table><tr><td>Method</td><td>Learming</td><td>入</td><td>BLEU NIST METEOR ROUGE-L CIDEr</td><td></td><td></td><td></td></tr><tr><td>LoRA (repr.)</td><td>2e-4</td><td>-</td><td>69.60</td><td>8.78 45.61</td><td>71.12</td><td>2.45</td></tr><tr><td>LoRA (repr.)</td><td>6e-4</td><td>1</td><td>69.63</td><td>8.79 45.70</td><td>71.55</td><td>2.39</td></tr><tr><td>Delta-LoRA</td><td>2e-4</td><td>2</td><td>70.84 8.91</td><td>46.47</td><td>72.24</td><td>2.53</td></tr></table>", "page_idx": 7 }, { "type": "text", "text": "The Extra Updatable Parameters. We introduce the concept of extra updatable parameters to point out the superiority of Delta-LoRA. For most PEFT methods, they can only adjust the low-rank adapters, such as AdapterHoulsby et al. (2019) and LoRAHu et al. (2022). Thus, they don’t have any extra parameters to update, which means their extra updatable parameters are 0. However, our Delta-LoRA can achieve the purpose of updating the W matrix without increasing the GPU memory consumption, which means its extra updatable parameters are the parameter number of $W$ . ", "page_idx": 7 }, { "type": "text", "text": "Ablation study. To better understand the contribution of our modified LoRA module (i.e. DeltaLoRA module) and the effectiveness of our update algorithm, we conduct studies on E2E Challenge dataset with GPT2-medium. As shown in Table 6, only updating the pre-trained matrices with delta of low-rank update can indeed achieve performance improvement, while further discarding the dropout in Delta-LoRA module obtains the best performance. This observation confirms the indispensable role played by each component within our proposed methodology. We have devised an experiment to further differentiate whether the performance enhancement stems from the inherent characteristics of our method rather than solely from the substantial update magnitude. According to our algorithm, we update the parameters of both pre-trained and low-rank matrices, which can arose the doubt of whether the improvement is caused by updating larger $\\triangle A B$ on the weights instead of introducing more parameters into the optimization process. To answer this question, we design an experiment with results shown in Table 7 to prove the effectiveness of our method. We scale the learning rate of LoRA from 2e-4 to 6e-4 making sure that $W + A B$ can be updated with $3 \\times \\triangle A B$ , which is equivalent to Delta-LoRA when $\\lambda$ is set to 2. We find that even by updating with $3 \\times \\triangle A B$ on $_ { A B }$ , the performance is still not comparable with Delta-LoRA. This experiment further proves that introducing more parameters into the optimization process can force to learn better representation. ", "page_idx": 7 }, { "type": "text", "text": "", "page_idx": 8 }, { "type": "image", "img_path": "images/9dcc54c551ff5c3ecbf10e382ac75f464784f07e54ba1c1d36ef9cdb8534030b.jpg", "image_caption": [ "Figure 3: The comparison of Fine-Tuning‡, LoRA as well as Delta-LoRA for the cosine similarity between the fine-tuned parameters and the original pre-trained parameters in each transformer block. Higher value means higher similarity. " ], "image_footnote": [], "page_idx": 8 }, { "type": "text", "text": "The cosine similarity between fine-tuned and the pre-trained parameters to measure learning effects. We conduct a comparative analysis of three methods including Fine-Tuning‡, LoRA and Delta-LoRA, in order to elucidate the reasons behind Delta-LoRA’s superior performance. We use the last checkpoint trained on E2E Challenge dataset to give understanding. As depicted in Figure 3, it is evident that LoRA exhibits the highest similarity across the majority of transformer blocks. This observation suggests that LoRA primarily modifies the matrix $\\pmb { W } ^ { * } = \\pmb { W } + \\pmb { A } \\pmb { B }$ within a limited range. Nevertheless, Delta-LoRA showcases the lowest cosine similarity, underscoring that our approach induces the most significant modifications to the final matrix $W ^ { * }$ . Due to this property, our approach can effectively stimulate the model to acquire better representations, leading to state-of-the-art performance across all four PEFT methods. This observation further aligns with the evaluation results in Table 1: Delta-LoRA achieves the best performance among the three methods, whereas LoRA is slightly worse than Fine-Tuning‡. ", "page_idx": 8 }, { "type": "text", "text": "6 CONCLUSION ", "text_level": 1, "page_idx": 8 }, { "type": "text", "text": "In this paper, we have introduced Delta-LoRA, a novel method to simultaneously update the full weight matrix and two low-rank matrices. Delta-LoRA leverages the delta $( { \\pmb A } ^ { ( t + 1 ) } { \\pmb B } ^ { ( t + 1 ) } - { \\pmb A } ^ { ( t ) } { \\pmb B } ^ { ( t ) } )$ to update the pre-trained weights $( W )$ . In this way, we introduce more learnable parameters into the optimization process such that the model can learn a better representation with comparable memory cost as LoRA. Meanwhile, we identify the Dropout layer in the low-rank branch to be unnecessary according to the gradient flow. We also provide thorough analysis of our method to understand its effectiveness and robustness. Extensive experiments on a broad range of NLP tasks are conducted to empirically verify the effectiveness of our Delta-LoRA. ", "page_idx": 8 }, { "type": "text", "text": "REFERENCES ", "text_level": 1, "page_idx": 9 }, { "type": "text", "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. ", "page_idx": 9 }, { "type": "text", "text": "Sébastien Bubeck, Varun Chandrasekaran, Ronen Eldan, Johannes Gehrke, Eric Horvitz, Ece Kamar, Peter Lee, Yin Tat Lee, Yuanzhi Li, Scott Lundberg, Harsha Nori, Hamid Palangi, Marco Tulio Ribeiro, and Yi Zhang. Sparks of artificial general intelligence: Early experiments with gpt-4, 2023. \nNicolas Carion, Francisco Massa, Gabriel Synnaeve, Nicolas Usunier, Alexander Kirillov, and Sergey Zagoruyko. End-to-end object detection with transformers. In ECCV, 2020. \nArnav Chavan, Zhuang Liu, Deepak Gupta, Eric Xing, and Zhiqiang Shen. One-for-all: Generalized lora for parameter-efficient fine-tuning. arXiv preprint arXiv:2306.07967, 2023. \nTim Dettmers, Artidoro Pagnoni, Ari Holtzman, and Luke Zettlemoyer. Qlora: Efficient finetuning of quantized llms. arXiv preprint arXiv:2305.14314, 2023. \nJacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. Bert: Pre-training of deep bidirectional transformers for language understanding. In NAACL, 2019. \nNing Ding, Yujia Qin, Guang Yang, Fuchao Wei, Zonghan Yang, Yusheng Su, Shengding Hu, Yulin Chen, Chi-Min Chan, Weize Chen, Jing Yi, Weilin Zhao, Zhiyuan Liu, Hai-Tao Zheng, Jianfei Chen, Yang Liu, Jie Tang, Juanzi Li, and Maosong Sun. Parameter-efficient fine-tuning of large-scale pre-trained language models. Nature Machine Intelligence, 2023. \nAlexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn, Xiaohua Zhai, Thomas Unterthiner, Mostafa Dehghani, Matthias Minderer, Georg Heigold, Sylvain Gelly, et al. An image is worth 16x16 words: Transformers for image recognition at scale. In ICLR, 2021. \nClaire Gardent, Anastasia Shimorina, Shashi Narayan, and Laura Perez-Beltrachini. The WebNLG challenge: Generating text from RDF data. In Proceedings of the 10th International Conference on Natural Language Generation, 2017. \nDemi Guo, Alexander M Rush, and Yoon Kim. Parameter-efficient transfer learning with diff pruning. In ACL, 2021. \nKaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Delving deep into rectifiers: Surpassing human-level performance on imagenet classification. In ICCV, 2015. \nPengcheng He, Jianfeng Gao, and Weizhu Chen. Debertav3: Improving deberta using electra-style pre-training with gradient-disentangled embedding sharing. arXiv preprint arXiv:2111.09543, 2021. \nNeil Houlsby, Andrei Giurgiu, Stanislaw Jastrzebski, Bruna Morrone, Quentin De Laroussilhe, Andrea Gesmundo, Mona Attariyan, and Sylvain Gelly. Parameter-efficient transfer learning for nlp. In ICML, 2019. \nEdward J Hu, yelong shen, Phillip Wallis, Zeyuan Allen-Zhu, Yuanzhi Li, Shean Wang, Lu Wang, and Weizhu Chen. LoRA: Low-rank adaptation of large language models. In ICLR, 2022. \nShaoyi Huang, Dongkuan Xu, Ian Yen, Yijue Wang, Sung-En Chang, Bingbing Li, Shiyang Chen, Mimi Xie, Sanguthevar Rajasekaran, Hang Liu, and Caiwen Ding. Sparse progressive distillation: Resolving overfitting under pretrain-and-finetune paradigm. In ACL, 2022. \nBrian Lester, Rami Al-Rfou, and Noah Constant. The power of scale for parameter-efficient prompt tuning. In EMNLP, 2021. \nMike Lewis, Yinhan Liu, Naman Goyal, Marjan Ghazvininejad, Abdelrahman Mohamed, Omer Levy, Ves Stoyanov, and Luke Zettlemoyer. Bart: Denoising sequence-to-sequence pre-training for natural language generation, translation, and comprehension. arXiv preprint arXiv:1910.13461, 2019. \nJunnan Li, Ramprasaath Selvaraju, Akhilesh Gotmare, Shafiq Joty, Caiming Xiong, and Steven Chu Hong Hoi. Align before fuse: Vision and language representation learning with momentum distillation. 2021. \nXiang Lisa Li and Percy Liang. Prefix-tuning: Optimizing continuous prompts for generation. In Chengqing Zong, Fei Xia, Wenjie Li, and Roberto Navigli (eds.), ACL, 2021. \nHaokun Liu, Derek Tam, Mohammed Muqeeth, Jay Mohta, Tenghao Huang, Mohit Bansal, and Colin A Raffel. Few-shot parameter-efficient fine-tuning is better and cheaper than in-context learning. In NeurIPS, 2022a. \nXiao Liu, Kaixuan Ji, Yicheng Fu, Weng Tam, Zhengxiao Du, Zhilin Yang, and Jie Tang. P-tuning: Prompt tuning can be comparable to fine-tuning across scales and tasks. In ACL, 2022b. \nYang Liu, Dan Iter, Yichong Xu, Shuohang Wang, Ruochen Xu, and Chenguang Zhu. Gpteval: Nlg evaluation using gpt-4 with better human alignment. arXiv preprint arXiv:2303.16634, 2023. \nYinhan Liu, Myle Ott, Naman Goyal, Jingfei Du, Mandar Joshi, Danqi Chen, Omer Levy, Mike Lewis, Luke Zettlemoyer, and Veselin Stoyanov. Roberta: A robustly optimized bert pretraining approach. arXiv preprint arXiv:1907.11692, 2019. \nIlya Loshchilov and Frank Hutter. Decoupled weight decay regularization. In ICLR, 2019. \nKai Lv, Yuqing Yang, Tengxiao Liu, Qinghui Gao, Qipeng Guo, and Xipeng Qiu. Full parameter fine-tuning for large language models with limited resources. 2023. \nShashi Narayan, Shay B Cohen, and Mirella Lapata. Don’t give me the details, just the summary! topic-aware convolutional neural networks for extreme summarization. arXiv preprint arXiv:1808.08745, 2018. \nJonas Pfeiffer, Aishwarya Kamath, Andreas Rücklé, Kyunghyun Cho, and Iryna Gurevych. Adapterfusion: Non-destructive task composition for transfer learning. In EACL, 2021. \nYevgeniy Puzikov and Iryna Gurevych. E2E NLG challenge: Neural models vs. templates. In Proceedings of the 11th International Conference on Natural Language Generation, 2018. \nAlec Radford, Jeffrey Wu, Rewon Child, David Luan, Dario Amodei, Ilya Sutskever, et al. Language models are unsupervised multitask learners. OpenAI blog, 1(8):9, 2019. \nColin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, Peter J Liu, et al. Exploring the limits of transfer learning with a unified text-to-text transformer. JMLR, 21(140):1–67, 2020. \nTaylor Shin, Yasaman Razeghi, Robert L Logan IV, Eric Wallace, and Sameer Singh. Autoprompt: Eliciting knowledge from language models with automatically generated prompts. In EMNLP, 2020. \nChuanqi Tan, Fuchun Sun, Tao Kong, Wenchang Zhang, Chao Yang, and Chunfang Liu. A survey on deep transfer learning. In ICANN, 2018. \nRohan Taori, Ishaan Gulrajani, Tianyi Zhang, Yann Dubois, Xuechen Li, Carlos Guestrin, Percy Liang, and Tatsunori B. Hashimoto. Stanford alpaca: An instruction-following llama model. https://github.com/tatsu-lab/stanford_alpaca, 2023. \nHugo Touvron, Thibaut Lavril, Gautier Izacard, Xavier Martinet, Marie-Anne Lachaux, Timothée Lacroix, Baptiste Rozière, Naman Goyal, Eric Hambro, Faisal Azhar, et al. Llama: Open and efficient foundation language models. arXiv preprint arXiv:2302.13971, 2023. \nMojtaba Valipour, Mehdi Rezagholizadeh, Ivan Kobyzev, and Ali Ghodsi. Dylora: Parameter-efficient tuning of pre-trained models using dynamic search-free low-rank adaptation. In EACL, 2023. \nAshish 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. \nAlex Wang, Amanpreet Singh, Julian Michael, Felix Hill, Omer Levy, and Samuel R. Bowman. GLUE: A multi-task benchmark and analysis platform for natural language understanding. In ICLR, 2019. \nYaqing Wang, Subhabrata Mukherjee, Xiaodong Liu, Jing Gao, Ahmed Hassan Awadallah, and Jianfeng Gao. Adamix: Mixture-of-adapter for parameter-efficient tuning of large language models. In EMNLP, 2022. \nThomas Wolf, Lysandre Debut, Victor Sanh, Julien Chaumond, Clement Delangue, Anthony Moi, Pierric Cistac, Tim Rault, Rémi Louf, Morgan Funtowicz, et al. Huggingface’s transformers: State-of-the-art natural language processing. arXiv preprint arXiv:1910.03771, 2019. \nElad Ben Zaken, Shauli Ravfogel, and Yoav Goldberg. Bitfit: Simple parameter-efficient fine-tuning for transformer-based masked language-models. arXiv preprint arXiv:2106.10199, 2021. \nLongteng Zhang, Lin Zhang, Shaohuai Shi, Xiaowen Chu, and Bo Li. Lora-fa: Memory-efficient low-rank adaptation for large language models fine-tuning. arXiv preprint arXiv:2308.03303, 2023. \nQingru Zhang, Minshuo Chen, Alexander Bukharin, Pengcheng He, Yu Cheng, Weizhu Chen, and Tuo Zhao. Adaptive budget allocation for parameter-efficient fine-tuning. In ICLR, 2022. \nSixiao Zheng, Jiachen Lu, Hengshuang Zhao, Xiatian Zhu, Zekun Luo, Yabiao Wang, Yanwei Fu, Jianfeng Feng, Tao Xiang, Philip HS Torr, et al. Rethinking semantic segmentation from a sequence-to-sequence perspective with transformers. In CVPR, 2021. \nHan Zhou, Xingchen Wan, Ivan Vulic, and Anna Korhonen. Autopeft: Automatic configuration ´ search for parameter-efficient fine-tuning. arXiv preprint arXiv:2301.12132, 2023. ", "page_idx": 9 }, { "type": "text", "text": "", "page_idx": 10 }, { "type": "text", "text": "", "page_idx": 11 }, { "type": "text", "text": "A APPENDIX ", "text_level": 1, "page_idx": 12 }, { "type": "text", "text": "A.1 BASELINES", "text_level": 1, "page_idx": 12 }, { "type": "text", "text": "We compare our proposed method Delta-LoRA with Fine-Tuning and prior works of LoRA, AdaLoRA, and DyLoRA. For PEFT methods, we only train the incremental updates for $W _ { V }$ and $W _ { Q }$ , following the setup as used in LoRA’s paper. For Fine-Tuning methods, we use two extra training paradigms: (1) freeze the embedding and train all the other parameters as Fine-Tuning $\\dagger$ ; (2) train $W _ { V }$ and $W _ { Q }$ only as Fine-Tuning‡. ", "page_idx": 12 }, { "type": "text", "text": "Fine-Tuning. In the past few years, fine-tuning has become the mainstream paradigm for both NLP and CV tasks. However, fine-tuning full parameters is subject to potential drawbacks including overfitting and training instability (Huang et al., 2022). Therefore, freezing a subset of network layers and fine-tuning the rest has become a popular choice (Tan et al., 2018). In our experiments, we compare with full fine-tuning, fine-tuning with embedding layers frozen (Fine-tuning $\\dagger .$ ) and fine-tuning query and value matrices only (Fine-tuning $\\ddagger$ ). ", "page_idx": 12 }, { "type": "text", "text": "LoRA (Hu et al., 2022) uses multiplication of two low-rank matrices to learn the incremental updates with reduced GPU memory cost. We follow their setups to reproduce experimental results for fair comparison. ", "page_idx": 12 }, { "type": "text", "text": "DyLoRA (Valipour et al., 2023) randomly chooses a rank $r$ for LoRA modules during learning. ", "page_idx": 12 }, { "type": "text", "text": "AdaLoRA (Zhang et al., 2022) focuses on the challenge of determining the optimal rank for incremental updates. It employs an adaptive approach to singular value pruning, tailoring the rank selection to the magnitude of each singular value. Consequently, distinct ranks are employed for different layers. ", "page_idx": 12 }, { "type": "text", "text": "A.2 THE COMPARISON BETWEEN LORA AND DELTA-LORA WITH LLAMA-7B ", "page_idx": 12 }, { "type": "text", "text": "A.2.1 TRAINING AND INFERENCE ARGUMENTS USED IN OUR METHOD AND BASELINE ", "text_level": 1, "page_idx": 12 }, { "type": "text", "text": "We choose LLaMA-7B to evaluate our method and LoRA. Here, we set the learning rate $\\gamma = 1 \\mathrm { e } { - } 4$ , batch size to 128, $r = 8$ , $\\alpha = 1 6$ , and training epochs to 3 for both two methods. Following the LoRA’s paper, we only tune $W _ { Q }$ and $W _ { V }$ . For Delta-LoRA, we choose start steps $K = 1 0 0$ and $\\lambda = 0 . 2 5$ . When inference, we set the no_repeat_ngram_size $= 1 0$ , temperature ${ } = 0$ and beam size $=$ 4 to get a certain answer. ", "page_idx": 12 }, { "type": "text", "text": "A.2.2 THE EVALUATION FOR OUR METHOD AND BASELINES ", "text_level": 1, "page_idx": 12 }, { "type": "text", "text": "Current LLMs obtain the training data from the Internet, which may unintentionally cause data leakage. Therefore, using the mainstream NLP datasets to evaluate the effectiveness of Large Language Model is not reasonable and wisdom. Inspired by evaluation approach proposed by Liu et al. (2023), we decided to use GPT-4 to judge the text generated by which method is accurate. First, we ask GPT-4 to generate 1,000 different questions. Second, we use the LLaMA-7B trained by two methods to generate the texts. Finally, we ask GPT-4 to give decision to tell us which text is accurate. It can choose from three options: a. Choice 1 (LoRA generates accurate text), b. Choice 2 (Delta-LoRA generates accurate text) and c. Both Choice 1 and 2 (Both LoRA and Delta-LoRA generate accurate texts). The prompt we used for evaluation: ", "page_idx": 12 }, { "type": "text", "text": "Help me to determine which text is accurate for the given instruction and question. The answer can be chosen from a. Choice 1 is accurate, b. Choice 2 is accurate or c. both Choice 1 and 2 are accurate. Give me a certain answer and this is a choice question. Please don’t give reasons and the answer must be shorter than 20 words. ", "page_idx": 12 }, { "type": "text", "text": "Question: \"\" (Choice 1): \"\" (Choice 2): \"\" ", "page_idx": 12 }, { "type": "text", "text": "A.3 ALGORITHM OF DELTA-LORA ", "text_level": 1, "page_idx": 12 }, { "type": "text", "text": "Our Delta-LoRA can be found in Algorithm 1. Compared to LoRA, we added a step to update the pre-trained $W$ without any extra GPU memory consumption. ", "page_idx": 12 }, { "type": "table", "img_path": "images/5262abc5271f04ac9464f3f9e2a946374e723b5fa0594edcad78709ac54a20b8.jpg", "table_caption": [ "Algorithm 1: Delta-LoRA " ], "table_footnote": [], "table_body": "<table><tr><td>Input: Learning rate n; weight decay β; total training iterations T; low rank r; scale factor α; start steps K;update ratio 入. A is initialized by Kaiming Initialization, B= O and W is initialized with pre-trained weights. fort=0,..,T-1do Sample a mini-batch and compute gradients for {A,B} in each Delta-LoRA module.</td></tr><tr><td>Update the first and second moments maintained by the optimizer with the computed gradients,</td></tr><tr><td>and get the normalized gradients gA and gB . A(t+1) ← A(t)-ngA-nβA6) B(t+1)←B(t)-ngB-nβB(t)</td></tr><tr><td>ift>Kdo W(t+1) ←W(t) +λ··(A(t+1)B(t+1)-A(t)B(t))</td></tr><tr><td>end if end for</td></tr><tr><td>Output: the fine-tuned parameters {W(T),A(T), B(T) }</td></tr></table>", "page_idx": 13 }, { "type": "text", "text": "A.4 A FURTHER UNDERSTANDING OF DELTA-LORA ", "text_level": 1, "page_idx": 13 }, { "type": "text", "text": "A.4.1 THE DIFFERENCES BETWEEN LORA AND DELTA-LORA ", "page_idx": 13 }, { "type": "text", "text": "There are some fundamental differences between LoRA and Delta-LoRA. ", "page_idx": 13 }, { "type": "text", "text": "• Given $W + A B$ , $W$ is fixed in LoRA, but $W$ will be updated in our Delta-LoRA. This is the largest difference between LoRA and Delta-LoRA. This modification can yield more training differences between LoRA and Delta-LoRA in the next few training steps. ", "page_idx": 13 }, { "type": "text", "text": "$\\cdot$ $\\mathrm { R a n k } ( \\Delta W _ { D e l t a - L o R A } ) = \\mathrm { R a n k } ( W ^ { ( T ) } - W ^ { ( 0 ) } + A B ) > \\mathrm { R a n k } ( \\Delta W _ { L o R A } ) = \\mathrm { R a n k } ( A B ) .$ The rank of the learned incremental weight matrix in our Delta-LoRA is larger than that in the original LoRA. ", "page_idx": 13 }, { "type": "text", "text": "$\\bullet$ The gradient flow is different between LoRA and Delta-LoRA. Suppose that we have $\\pmb { W } \\in \\mathbb { R } ^ { m \\times n }$ , $\\pmb { A } \\in \\mathbb { R } ^ { m \\times r }$ and $\\boldsymbol { B } \\in \\mathbb { R } ^ { r \\times n }$ , where $r \\leq \\operatorname* { m i n } ( m , n )$ . For LoRA, it keeps $W$ frozen, so that $W ^ { * } =$ $\\begin{array} { r } { { \\cal W } ^ { ( 0 ) } + \\frac { \\alpha } { r } \\cdot { \\cal A } ^ { ( t ) } { \\cal B } ^ { ( t ) } } \\end{array}$ . For Delta-LoRA, it updates all matrices, and has $\\begin{array} { r } { W ^ { * } = W ^ { ( t ) } + \\frac { \\alpha } { r } \\cdot A ^ { ( t ) } B ^ { ( t ) } } \\end{array}$ . ", "page_idx": 13 }, { "type": "equation", "img_path": "images/40cbd1fe3a3a13fdaa9a7f4d5f3f702cd283215648cba09f5f4187967ac98a40.jpg", "text": "$$\n\\frac \\left[ \\begin{array} { l l l l } { \\displaystyle \\frac { A ^ { h _ { i } } } { \\eta } } & { \\displaystyle + \\frac { \\eta } { \\eta } } & { \\displaystyle } & { \\right] } \\left[ \\begin{array} { l l l l } { \\displaystyle \\frac { A ^ { h _ { i } } } { \\eta } } & { \\displaystyle + \\frac { \\eta } { \\eta } } & { \\displaystyle h _ { i + 1 } = h _ { i } A } & { h _ { i + 1 } \\in \\mathbb R ^ { h \\times r } } \\\\ { \\displaystyle \\frac { A ^ { h } } { \\eta } } & { \\displaystyle \\frac { A ^ { h } } { \\eta } } & { h _ { i + 1 } } & { h _ { i + 2 } = h _ { i + 1 } B } & { h _ { i + 2 } \\in \\mathbb R ^ { h \\times n } } \\\\ { \\displaystyle \\frac { \\left[ \\begin{array} { l l l l } { \\displaystyle h _ { i + 3 } } & { \\displaystyle - \\frac { A ^ { h } } { \\eta } } & { \\displaystyle h _ { i + 2 } } & { \\displaystyle h _ { i + 3 } = h _ { i } W } & { h _ { i + 3 } \\in \\mathbb R ^ { b \\times n } } \\\\ { \\displaystyle h _ { i + 4 } } & { \\displaystyle } & { \\displaystyle } & { } \\end{array} \\right] } { \\le\\right]ft[ \\begin{array} { l } { \\displaystyle h _ { i + 3 } } \\\\ { \\displaystyle h _ { i + 4 } } \\end{array} \\right] } } \\end{array} \\end{array}\n$$", "text_format": "latex", "page_idx": 13 }, { "type": "image", "img_path": "", "image_caption": [ "Figure 4: The backward propagation of Delta-LoRA. " ], "image_footnote": [], "page_idx": 13 }, { "type": "text", "text": "So, we have the following equation according to Figure 4: ", "page_idx": 13 }, { "type": "equation", "img_path": "images/edfdef858b105f09097f1e38f896b04e419e7b327da9c28fa3a04647394e61cb.jpg", "text": "$$\n\\begin{array} { r l } & { \\frac { \\partial \\mathcal { L } } { \\partial W ^ { ( t ) } } = ( \\frac { \\partial h _ { i + 3 } } { \\partial W ^ { ( t ) } } ) ^ { \\top } \\frac { \\partial \\mathcal { L } } { \\partial h _ { i + 4 } } = h _ { i } ^ { \\top } \\frac { \\partial \\mathcal { L } } { \\partial h _ { i + 4 } } } \\\\ & { \\frac { \\partial \\mathcal { L } } { \\partial A ^ { ( t ) } } = ( \\frac { \\partial h _ { i + 1 } } { \\partial A ^ { ( t ) } } ) ^ { \\top } \\frac { \\partial \\mathcal { L } } { \\partial h _ { i + 4 } } \\cdot \\frac { \\partial h _ { i + 4 } } { \\partial h _ { i + 2 } } \\cdot \\frac { \\partial h _ { i + 2 } } { \\partial h _ { i + 1 } } = h _ { i } ^ { \\top } \\frac { \\partial \\mathcal { L } } { \\partial h _ { i + 4 } } \\frac { \\partial h _ { i + 2 } } { \\partial h _ { i + 1 } } = h _ { i } ^ { \\top } \\frac { \\partial \\mathcal { L } } { \\partial h _ { i + 4 } } B ^ { ( t ) \\top } = \\frac { \\partial \\mathcal { L } } { \\partial W ^ { ( t ) } } \\cdot B ^ { ( t ) \\top } } \\end{array}\n$$", "text_format": "latex", "page_idx": 13 }, { "type": "text", "text": "$\\begin{array} { r } { \\frac { \\partial \\mathcal { L } } { \\partial B ^ { ( t ) } } = ( \\frac { \\partial h _ { i + 1 } } { \\partial B ^ { ( t ) } } ) ^ { \\top } \\cdot \\frac { \\partial \\mathcal { L } } { \\partial h _ { i + 4 } } \\cdot \\frac { \\partial h _ { i + 4 } } { \\partial h _ { i + 2 } } = h _ { i + 2 } ^ { \\top } \\cdot \\frac { \\partial \\mathcal { L } } { \\partial h _ { i + 4 } } = ( A ^ { ( t ) } ) ^ { \\top } \\cdot h _ { i } ^ { \\top } \\cdot \\frac { \\partial \\mathcal { L } } { \\partial h _ { i + 4 } } = ( A ^ { ( t ) } ) ^ { \\top } \\cdot \\frac { \\partial \\mathcal { L } } { \\partial W ^ { ( t ) } } } \\end{array}$ Here, we provide the back-propagation process of LoRA: ", "page_idx": 14 }, { "type": "equation", "img_path": "images/2364d19b8d1ba5aec70389e1f20e817d272eaa9ea61d444cb2d404ea8cc6b06b.jpg", "text": "$$\n\\begin{array} { r l } & { \\frac { \\partial \\mathcal { L } } { \\partial A ^ { ( t + 1 ) } } = \\frac { \\partial \\mathcal { L } } { \\partial W ^ { ( t + 1 ) } } \\cdot ( B ^ { ( t + 1 ) } ) ^ { \\top } = \\frac { \\partial \\mathcal { L } } { \\partial ( W ^ { ( 0 ) } + ( A ^ { ( t ) } + \\Delta A ^ { ( t ) } ) ( B ^ { ( t ) } + \\Delta B ^ { ( t ) } ) ) } \\cdot ( B ^ { ( t ) } + \\Delta B ^ { ( t ) } ) ^ { \\top } } \\\\ & { \\frac { \\partial \\mathcal { L } } { \\partial B ^ { ( t + 1 ) } } = ( A ^ { ( t + 1 ) } ) ^ { \\top } \\cdot \\frac { \\partial \\mathcal { L } } { \\partial W ^ { ( t + 1 ) } } = ( A ^ { ( t ) } + \\Delta A ^ { ( t ) } ) ^ { \\top } \\cdot \\frac { \\partial \\mathcal { L } } { \\partial ( W ^ { ( 0 ) } + ( A ^ { ( t ) } + \\Delta A ^ { ( t ) } ) ( B ^ { ( t ) } + \\Delta B ^ { ( t ) } ) ) } } \\end{array}\n$$", "text_format": "latex", "page_idx": 14 }, { "type": "text", "text": "This is the back-propagation process of Delta-LoRA: ", "page_idx": 14 }, { "type": "equation", "img_path": "images/3e89350f054224cd724921bb5543388056b7cfd48920d6dbb5253990dbbc928e.jpg", "text": "$$\n\\begin{array} { r l } & { \\frac { \\partial \\mathcal { L } } { \\partial A ^ { ( t + 1 ) } } = \\frac { \\partial \\mathcal { L } } { \\partial W ^ { ( t + 1 ) } } \\cdot ( B ^ { ( t + 1 ) } ) ^ { \\top } = \\frac { \\partial \\mathcal { L } } { \\partial ( ( W ^ { ( t ) } + \\lambda \\Delta A ^ { ( t ) } B ^ { ( t ) } ) + ( A ^ { ( t ) } + \\Delta A ^ { ( t ) } ) ( B ^ { ( t ) } + \\Delta B ^ { ( t ) } ) } \\cdot ( B ^ { ( t ) } + \\Delta B ^ { ( t ) } ) ^ { \\top } } \\\\ & { \\frac { \\partial \\mathcal { L } } { \\partial B ^ { ( t + 1 ) } } = ( A ^ { ( t + 1 ) } ) ^ { \\top } \\cdot \\frac { \\partial \\mathcal { L } } { \\partial W ^ { ( t + 1 ) } } = ( A ^ { ( t ) } + \\Delta A ^ { ( t ) } ) ^ { \\top } \\cdot \\frac { \\partial \\mathcal { L } } { \\partial ( ( W ^ { ( t ) } + \\lambda \\Delta A ^ { ( t ) } B ^ { ( t ) } ) + ( A ^ { ( t ) } + \\Delta A ^ { ( t ) } ) ( B ^ { ( t ) } + \\Delta B ^ { ( t ) } ) ) } } \\end{array}\n$$", "text_format": "latex", "page_idx": 14 }, { "type": "text", "text": "A.4.2 THE EXPANSION OF $\\triangle { A B }$ ", "text_level": 1, "page_idx": 14 }, { "type": "text", "text": "In the real training process, we need to consider a variety of training arguments, such as optimizer and the regularization for $\\triangle A B$ . Suppose that we use the AdamW (Loshchilov & Hutter, 2019) and $L _ { 2 }$ regularization, the $\\triangle A B$ can be expanded in the following equation: ", "page_idx": 14 }, { "type": "equation", "img_path": "images/84763fe0b18426f41e0f77128271433035c57c76a6a3e5cdbdb242e2ca6d2f51.jpg", "text": "$$\n\\begin{array} { r l } & { \\triangle A B = A ^ { ( t + 1 ) } B ^ { ( t + 1 ) } - A ^ { ( t ) } B ^ { ( t ) } } \\\\ & { \\qquad = ( A ^ { ( t ) } - \\eta \\hat { g } _ { A } - \\eta \\beta A ^ { ( t ) } ) \\cdot ( B ^ { ( t ) } - \\eta \\hat { g } _ { B } - \\eta \\beta B ^ { ( t ) } ) - A ^ { ( t ) } B ^ { ( t ) } } \\\\ & { \\qquad = A ^ { ( t ) } B ^ { ( t ) } - \\eta A ^ { ( t ) } \\hat { g } _ { B } - \\eta \\beta A ^ { ( t ) } B ^ { ( t ) } - \\eta \\hat { g } _ { A } B ^ { ( t ) } + \\eta ^ { 2 } \\hat { g } _ { A } \\hat { g } _ { B } + \\eta ^ { 2 } \\beta \\hat { g } _ { A } B ^ { ( t ) } } \\\\ & { \\qquad - \\eta \\beta A ^ { ( t ) } B ^ { ( t ) } + \\eta ^ { 2 } \\beta A ^ { ( t ) } \\hat { g } _ { B } + \\eta ^ { 2 } \\beta ^ { 2 } A ^ { ( t ) } B ^ { ( t ) } - A ^ { ( t ) } B ^ { ( t ) } } \\\\ & { \\qquad = - \\eta A ^ { ( t ) } \\hat { g } _ { B } - \\eta \\beta A ^ { ( t ) } B ^ { ( t ) } - \\eta \\hat { g } _ { A } B ^ { ( t ) } + \\eta ^ { 2 } \\hat { g } _ { A } \\hat { g } _ { B } + \\eta ^ { 2 } \\beta \\hat { g } _ { A } B ^ { ( t ) } } \\\\ & { \\qquad - \\eta \\beta A ^ { ( t ) } B ^ { ( t ) } + \\eta ^ { 2 } \\beta A ^ { ( t ) } \\hat { g } _ { B } + \\eta ^ { 2 } \\beta ^ { 2 } A ^ { ( t ) } B ^ { ( t ) } } \\\\ & { \\qquad \\approx - \\eta A ^ { ( t ) } \\hat { g } _ { B } - \\eta \\hat { g } _ { A } B ^ { ( t ) } } \\end{array}\n$$", "text_format": "latex", "page_idx": 14 }, { "type": "text", "text": "where $\\eta$ is the learning rate, $\\beta$ is weight decay. What’s more, for pre-trained weight $W , \\triangle W =$ $\\eta \\widehat { g } _ { W } + \\eta \\beta W ^ { ( t ) }$ . As a consequence, $\\triangle A B$ is not equal to $\\triangle W$ in the training process. ", "page_idx": 14 }, { "type": "text", "text": "A.5 CHANGE THE LEARNING RATE AND START STEPS TO SHOW BETTER PERFORMANCE. ", "page_idx": 14 }, { "type": "text", "text": "We explored better hyper parameters of our Delta-LoRA by modifying the learning rate and trying more start steps and update ratio to prove the effectiveness of Delta-LoRA. ", "page_idx": 14 }, { "type": "table", "img_path": "images/9f7e6cf447bcf509eb53e72b21d9ee4416a1ffc0fa59bb0dd7c5545e6c3f559a.jpg", "table_caption": [ "Table 8: The evaluation results of our proposed Delta-LoRA by using better hyper-parameters on GLUE benchmark. " ], "table_footnote": [], "table_body": "<table><tr><td>Method</td><td>MNLI</td><td> SST-2</td><td>MRPC</td><td>CoLA</td><td>QNLI</td><td>QQP</td><td>RTE</td><td>STS-B</td><td>AVG</td></tr><tr><td>LoRA</td><td>87.40</td><td>94.61</td><td>89.95</td><td>63.17</td><td>93.02</td><td>90.67</td><td>86.64</td><td>91.54</td><td>87.12</td></tr><tr><td>DyLoRA</td><td>86.33</td><td>94.26</td><td>89.46</td><td>61.12</td><td>92.22</td><td>90.17</td><td>84.47</td><td>91.06</td><td>86.14</td></tr><tr><td>AdaLoRA</td><td>87.34</td><td>94.49</td><td>90.19</td><td>61.64</td><td>93.08</td><td>90.14</td><td>85.19</td><td>91.16</td><td>86.65</td></tr><tr><td>Delta-LoRA</td><td>87.62±0.21</td><td>95.29±0.23 90.60±0.14</td><td></td><td></td><td>64.64±0.86 93.09±0.15 91.01±0.06 87.00±0.36 91.61±0.04 87.60</td><td></td><td></td><td></td><td></td></tr></table>", "page_idx": 14 }, { "type": "table", "img_path": "images/be9bc167a7ce7fb872dfcd51215057f1e05bb04fbab23f643f7ad85c512cea0e.jpg", "table_caption": [ "Table 9: The better training hyper-parameters that we obtained of our proposed Delta-LoRA on GLUE benchmark. " ], "table_footnote": [], "table_body": "<table><tr><td>Hyper-Parameter|MNLI SST-2 MRPC CoLA QNLI QQP RTE STS-B</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>Learning Raten|4e-4 5e-4 5e-4 6e-4 3e-4 6e-4 4e-4 4e-4</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>Start Steps K</td><td>2000400</td><td></td><td>10</td><td>200600400200200</td><td></td><td></td><td></td><td></td></tr><tr><td>Update Ratio入</td><td>0.5</td><td>0.5</td><td>0.5</td><td>1</td><td>1</td><td>0.50.5</td><td></td><td>0.5</td></tr></table>", "page_idx": 14 }, { "type": "text", "text": "A.6 THE PARAMETER SENSITIVITY STUDY ", "text_level": 1, "page_idx": 15 }, { "type": "table", "img_path": "images/d510e93eac06d4c47b958d15e47a554885fb0542771f49fb06300c494f88a060.jpg", "table_caption": [ "Table 10: The parameter sensitivity study of update ratio $\\lambda$ for our proposed Delta-LoRA on E2E Challenge dataset. The best results are boldfaced. " ], "table_footnote": [], "table_body": "<table><tr><td>入</td><td>BLEU</td><td>NIST</td><td>METEOR</td><td>ROUGE-L</td><td>CIDEr</td></tr><tr><td>0</td><td>68.94</td><td>8.73</td><td>45.27</td><td>70.81</td><td>2.41</td></tr><tr><td>1</td><td>69.77</td><td>8.81</td><td>45.99</td><td>71.58</td><td>2.46</td></tr><tr><td>2</td><td>70.84</td><td>8.91</td><td>46.47</td><td>72.24</td><td>2.53</td></tr><tr><td>3</td><td>70.14</td><td>8.84</td><td>46.39</td><td>71.45</td><td>2.45</td></tr><tr><td>4</td><td>70.03</td><td>8.83</td><td>46.21</td><td>71.56</td><td>2.47</td></tr><tr><td>5</td><td>70.13</td><td>8.85</td><td>46.35</td><td>71.72</td><td>2.48</td></tr></table>", "page_idx": 15 }, { "type": "text", "text": "Parameter Sensitivity. Here, we explore the hyper-parameter $K$ in Algorithm 1 and $\\lambda$ in Equation 6. For the hyper-parameter $K$ , we select it from 0 to 1000 with the interval of 100. From Table 11, we find that our Delta-LoRA could not bring in any improvement before $K = 4 0 0$ , and it will keep a relatively good performance when $K$ is larger than 500. What is more, we choose different numbers for $\\lambda$ , ranging from 0 to 5. According to Table 10, the 5 metrics rise rapidly after $\\lambda = 0$ and reach best at $\\lambda = 2$ , while the performance has small drops on 5 evaluation scores if $\\lambda$ is chosen from 3 to 5. ", "page_idx": 15 }, { "type": "table", "img_path": "images/c68055072a7b99eea319779d30509405785852a01512ac369f315dfc697e8c28.jpg", "table_caption": [ "Table 11: The parameter sensitivity study of start steps $K$ for our proposed Delta-LoRA on E2E Challenge dataset. The best results are boldfaced. " ], "table_footnote": [], "table_body": "<table><tr><td>K</td><td>BLEU</td><td>NIST</td><td>METEOR</td><td>ROUGE-L</td><td>CIDEr</td></tr><tr><td>0</td><td>69.10</td><td>8.75</td><td>45.54</td><td>71.31</td><td>2.41</td></tr><tr><td>100</td><td>69.97</td><td>8.84</td><td>46.07</td><td>71.40</td><td>2.46</td></tr><tr><td>200</td><td>69.72</td><td>8.83</td><td>45.82</td><td>71.41</td><td>2.43</td></tr><tr><td>300</td><td>69.73</td><td>8.86</td><td>45.98</td><td>71.09</td><td>2.46</td></tr><tr><td>400</td><td>70.18</td><td>8.89</td><td>46.30</td><td>71.66</td><td>2.49</td></tr><tr><td>500</td><td>70.84</td><td>8.91</td><td>46.47</td><td>72.24</td><td>2.53</td></tr><tr><td>600</td><td>70.38</td><td>8.86</td><td>46.38</td><td>71.70</td><td>2.47</td></tr><tr><td>700</td><td>70.61</td><td>8.89</td><td>46.43</td><td>72.13</td><td>2.51</td></tr><tr><td>800</td><td>70.70</td><td>8.89</td><td>46.30</td><td>71.97</td><td>2.51</td></tr><tr><td>900</td><td>71.00</td><td>8.92</td><td>46.47</td><td>72.04</td><td>2.52</td></tr><tr><td>1000</td><td>70.87</td><td>8.89</td><td>46.31</td><td>72.06</td><td>2.50</td></tr></table>", "page_idx": 15 }, { "type": "text", "text": "A.7 HYPER-PARAMETER USED IN OUR EXPERIMENTS ", "text_level": 1, "page_idx": 15 }, { "type": "text", "text": "We report the hyper-parameter that used in our experiments. Table 12 and Table 13 show the hyperparameter that we used for the training and evaluation on E2E Challenge and WebNLG Challenge 2017 dataset. The Table 14 and Table 15 are the training and evaluation hyper parameter for XSum dataset, and the Table 16 consists of hyper-parameters for 8 datasets in GLUE benchmark. ", "page_idx": 15 }, { "type": "table", "img_path": "images/162a2f0cf25716d299d0270805fc6cfd10e9a8b6111f99c84cf0248d66b3ba46.jpg", "table_caption": [ "Table 12: The training hyper-parameter used for E2E Challenge and WebNLG Challenge 2017 dataset. " ], "table_footnote": [], "table_body": "<table><tr><td>Hyper-Parameter</td><td>E2E Challenge</td><td>WebNLG Challenge 2017</td></tr><tr><td>Learning Rate n</td><td>2e-4</td><td>2e-4</td></tr><tr><td>Batch Size</td><td>8</td><td>8</td></tr><tr><td>Number of Epochs</td><td>5</td><td>5</td></tr><tr><td>Weight Decay β</td><td>0.01</td><td>0.01</td></tr><tr><td>Resid_pdrop</td><td>0</td><td>0.09</td></tr><tr><td>Attn_pdrop</td><td>0</td><td>0.09</td></tr><tr><td>Embd_pdrop</td><td>0</td><td>0</td></tr><tr><td>Label Smooth</td><td>0</td><td>0</td></tr><tr><td> Start Steps K</td><td>500</td><td>500</td></tr><tr><td>Update Ratio 入</td><td>2</td><td>5</td></tr><tr><td>Rank r</td><td>4</td><td>4</td></tr><tr><td>Alpha α</td><td>32</td><td>32</td></tr><tr><td>Trainable Matrices</td><td>Wq,Wv</td><td>Wq,Wv</td></tr><tr><td>LR Scheduler</td><td>Linear</td><td>Linear</td></tr><tr><td>Warmup Steps</td><td>500</td><td>500</td></tr></table>", "page_idx": 16 }, { "type": "table", "img_path": "images/9156124cb481f5a13eae2a0ebb71fddd843320c9ea724ce309e0bbabab36da5c.jpg", "table_caption": [ "Table 13: The hyper-parameter for evaluation used for E2E Challenge and WebNLG Challenge 2017 dataset. " ], "table_footnote": [], "table_body": "<table><tr><td>Hyper-Parameter</td><td>E2E Challenge</td><td>WebNLG Challenge 2017</td></tr><tr><td>Beam Size</td><td>10</td><td>5</td></tr><tr><td>Penalty</td><td>0.8</td><td>1.0</td></tr><tr><td>No Repeat Ngram Size</td><td>4</td><td>4</td></tr></table>", "page_idx": 16 }, { "type": "table", "img_path": "images/da597f8730d96119464796a7e05ffe09dc8d5545a3946f3b9f0260e204e982bc.jpg", "table_caption": [ "Table 14: The training hyper-parameter used for XSum dataset. " ], "table_footnote": [], "table_body": "<table><tr><td>Hyper-Parameter</td><td>Xsum</td></tr><tr><td>Learning Rate n</td><td>2e-4</td></tr><tr><td>Batch Size</td><td>64</td></tr><tr><td>Number of Epochs</td><td>25</td></tr><tr><td>Weight Decay β</td><td>0</td></tr><tr><td>Activation Dropout</td><td>0</td></tr><tr><td>Dropout Classifier Dropout</td><td>0</td></tr><tr><td>Start Steps K</td><td>0</td></tr><tr><td></td><td>1000</td></tr><tr><td>Update Ratio 入</td><td>0.5</td></tr><tr><td>Rank r</td><td>4</td></tr><tr><td>Alpha α Trainable Matrices</td><td>32</td></tr><tr><td>LR Scheduler</td><td>Wq, Wv Linear</td></tr><tr><td>Warmup Steps</td><td>3000</td></tr></table>", "page_idx": 16 }, { "type": "table", "img_path": "images/ea1a27b206db1a4acf10682468033577f4bd671ad95239a35794dfb8d4249ed8.jpg", "table_caption": [ "Table 15: The hyper-parameter for evaluation used for XSum dataset. " ], "table_footnote": [], "table_body": "<table><tr><td>Hyper-Parameter</td><td>Xsum</td></tr><tr><td>Beam Size</td><td>8</td></tr><tr><td>Penalty</td><td>1.0</td></tr><tr><td>No Repeat N-gram Size</td><td>4</td></tr></table>", "page_idx": 16 }, { "type": "table", "img_path": "images/76f5df35a6ae5876bd32fcbbe28738001e834c3e0e3f6cf36558012b07abb44b.jpg", "table_caption": [ "Table 16: The training hyper-parameters of our proposed Delta-LoRA on GLUE benchmark. We adopt the most of hyper-parameters in LoRA’s paper and implement our method based on the codes given by LoRA’s repository. " ], "table_footnote": [], "table_body": "<table><tr><td>Hyper-Parameter</td><td>MNLI</td><td>SST-2</td><td>MRPC</td><td>CoLA</td><td>QNLI</td><td>QQP</td><td>RTE</td><td>STS-B</td></tr><tr><td>Learning Rate n</td><td>5e-4</td><td>5e-4</td><td>4e-4</td><td>4e-4</td><td>4e-4</td><td>4e-4</td><td>4e-4</td><td>4e-4</td></tr><tr><td>Batch Size</td><td>128</td><td>128</td><td>128</td><td>64</td><td>256</td><td>128</td><td>128</td><td>128</td></tr><tr><td>Number of Epochs</td><td>30</td><td>60</td><td>30</td><td>80</td><td>25</td><td>25</td><td>80</td><td>40</td></tr><tr><td>Weight Decay β</td><td>0.1</td><td>0.1</td><td>0.1</td><td>0.1</td><td>0.1</td><td>0.1</td><td>0.1</td><td>0.1</td></tr><tr><td>Max Sequence Length</td><td>256</td><td>256</td><td>256</td><td>256</td><td>256</td><td>256</td><td>512</td><td>256</td></tr><tr><td>Start Steps K</td><td>2000</td><td>400</td><td>10</td><td>100</td><td>800</td><td>400</td><td>200</td><td>200</td></tr><tr><td>Update Ratio 入</td><td>0.5</td><td>0.5</td><td>0.5</td><td>0.5</td><td>0.5</td><td>0.5</td><td>0.5</td><td>0.5</td></tr><tr><td>Rank r</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td></tr><tr><td>Alpha α</td><td>16</td><td>16</td><td>16</td><td>16</td><td>16</td><td>16</td><td>16</td><td>16</td></tr><tr><td>LR Scheduler</td><td>Linear</td><td>Linear</td><td>Linear</td><td>Linear</td><td>Linear</td><td>Linear</td><td>Linear</td><td>Linear</td></tr><tr><td>Trainable Matrices</td><td>WQ,Wv WQ.Wv WQ,Wv</td><td></td><td></td><td>Wq,Wv</td><td></td><td></td><td></td><td> WQ,Wv WQ,Wv WQ,Wv WQ.Wv</td></tr><tr><td>Warmup Ratio</td><td>0.06</td><td>0.06</td><td>0.06</td><td>0.06</td><td>0.06</td><td>0.06</td><td>0.06</td><td>0.06</td></tr><tr><td>Evaluation Metrics</td><td></td><td>Accuracy Accuracy Accuracy</td><td></td><td> Mthtion Accuracy Accuracy Accuracy</td><td></td><td></td><td></td><td>Pearson</td></tr></table>", "page_idx": 17 }]123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352# CHAIN-OF-VERIFICATION REDUCES HALLUCINATION IN LARGE LANGUAGE MODELS
Anonymous authors Paper under double-blind review
# ABSTRACT
Generation of plausible yet incorrect factual information, termed hallucination, is an unsolved issue in large language models. We study the ability of language models to deliberate on the responses they give in order to correct their mistakes. We develop the Chain-of-Verification (COVE) method whereby the model first (i) drafts an initial response; then (ii) plans verification questions to fact-check its draft; (iii) answers those questions independently so the answers are not biased by other responses; and (iv) generates its final verified response. In experiments, we show COVE decreases hallucinations across a variety of tasks, from list-based questions from Wikidata, closed book MultiSpanQA and longform text generation.
# 1 INTRODUCTION
Large Language Models (LLMs) are trained on huge corpora of text documents with billions of tokens of text. It has been shown that as the number of model parameters is increased, performance at tasks such as closed book QA improve in accuracy, and larger models can generate more correct factual statements (Radford et al., 2019; Petroni et al., 2019). However, even the largest models can still fail, particularly on lesser known torso and tail distribution facts (Sun et al., 2023a), i.e. those that occur relatively rarely in the training corpora. In those cases where the model is incorrect, they instead generate an alternative response which is typically plausible looking (e.g., a similar entity, but an incorrect one). These factually incorrect generations are referred to as hallucinations (Maynez et al., 2020). Further, in longform tasks consisting of generating multiple sentences or paragraphs, the hallucination problem can be exacerbated due to the issue of exposure bias (Wang & Sennrich, 2020).
The current wave of language modeling research goes beyond next word prediction, and has focused on their ability to reason. Improved performance in reasoning tasks can be gained by encouraging language models to first generate internal thoughts or reasoning chains before responding (Wei et al., 2022; Adolphs et al., 2021; Wang et al., 2022; Lanchantin et al., 2023), as well as updating their initial response through self-critique (Press et al., 2022; Madaan et al., 2023). In this work we follow this line of research to study how and when language-model-based reasoning can be used to reduce hallucinations. We develop an approach, called Chain-of-Verification (CoVe) which, given an initial draft response, first plans verification questions to check its work, and then systematically answers those questions in order to finally produce an improved revised response. We find that independent verification questions tend to provide more accurate facts than those in the original longform answer, and hence improve the correctness of the overall response. We study variations on this recipe across a range of tasks: from list-based questions, closed booked QA and longform text generation. We first propose a joint approach for generating the entire verification chain left-to-right, which improves performance and decreases hallucinations compared to the baseline language model. However, models that attend to existing hallucinations in the context from their own generations tend to repeat the hallucinations. Hence we also introduce further improvements with factored variants which separate out the verification chain steps, in terms of which context is attended to. We show how these factored variants give further performance gains across all three tasks considered.
# 2 RELATED WORK
Hallucination is a general problem in language model generations that appears across many tasks, from summarization (Maynez et al., 2020) to open-domain dialogue (Roller et al., 2020), and has not
# Query
Name some politicians who were born in NY, New York.
# 1. Baseline Response
Here are some politicians who were born in NY, New York: 1. Hillary Clinton - former secretary of state and former Democratic presidential nominee 2. Donald Trump - former president of the United States 3. Michael Bloomberg - former Mayor of New York City and former Democratic presidential candidate … <list continues..>
# 2. Plan Verifications
3. Execute Verifications
Hillary Clinton was born in Chicago, Illinois, United States on October 26, 1947.
- Where was Hillary Clinton born? - Where was Donald Trump born? - Where was Michael Bloomberg born? … <questions continue..>
Donald Trump was born on June 14, 1946, in Queens, New York City, New York, United States
Michael Bloomberg was born on February 14, 1942, in Boston, Massachusetts, United States.
# 4. Final Verified Response
Here are some politicians who were born in NY, New York: 1. Donald Trump - former president of the United States 2. Alexandria Ocasio-Cortez - Democratic member of the U.S. House of Representatives … <list continues..>
Figure 1: Chain-of-Verification (CoVe) method. Given a user query, a large language model generates a baseline response that may contain inaccuracies, e.g. factual hallucinations. We show a query here which failed for ChatGPT (see section 12 for more details). To improve this, CoVe first generates a plan of a set of verification questions to ask, and then executes that plan by answering them and hence checking for agreement. We find that individual verification questions are typically answered with higher accuracy than the original accuracy of the facts in the original longform generation. Finally, the revised response takes into account the verifications. The factored version of CoVe answers verification questions such that they cannot condition on the original response, avoiding repetition and improving performance.
been resolved by simply scaling up training data or model size (Zhang et al., 2023). For a survey of the hallucination issue, see Ji et al. (2023) and Ye et al. (2023). A majority of the methods for reducing hallucination can be divided into roughly three categories: training-time correction, generation-time correction and via augmentation (tool-use).
In training-time correction methods, an attempt is made to improve the raw left-to-right generations of an encoder-decoder or decoder-only language model by either training or otherwise adjusting the model weights to decrease the probability of hallucinated generations. This includes using reinforcement learning (Roit et al., 2023; Wu et al., 2023), constrastive learning (Chern et al., 2023b; Sun et al., 2023b) and other methods (Li et al., 2023; Narayan et al., 2023).
In generation-time correction, a common theme is to make reasoning decisions “on top of” the base LLM in order to make them more reliable. For example, by considering the probabilities of the generated tokens (Mielke et al., 2022; Kadavath et al., 2022). In Manakul et al. (2023) multiple samples are drawn from the model to detect hallucinations. In Varshney et al. (2023) hallucinations are identified using low confidence scores, and their correctness is checked through a validation procedure, mitigated, and then the generation is continued. An alternative to using the confidence scores is to leverage inconsistencies in the LLMs output to detect hallucination. Cohen et al. (2023) show that using inconsistencies for QA tasks can outperform using confidence scores for hallucination detection. Cohen et al. (2023) simulate an interactive multi-agent LM vs. LM debate setup to detect hallucinations for factoid QA, Agrawal et al. (2023) check for hallucinated references, while Mundler ¨ et al. (2023) extract relational triples from generations and verify them against another LLM. COVE also uses a related self-consistency approach but we show our approach can correct hallucinated facts in longform generations by generating and answering verification questions by solely using the same LLM.
A third approach is to use external tools to help mitigate hallucinations, rather than relying solely on the abilities of the language model itself. For example, retrieval-augmented generation can decrease hallucinations by using factual documents for grounding (Shuster et al., 2021; Jiang et al., 2023b; Yu et al., 2023) or chain-of-thought verification (Zhao et al., 2023). Other approaches include using tools for fact-checking (Chern et al., 2023a; Galitsky, 2023; Peng et al., 2023), or linking to external documents with attribution (Menick et al., 2022; Rashkin et al., 2023; Gao et al., 2023).
There are also a number of related works in improving reasoning for logical and mathematical tasks, even if they do not address reducing hallucination explicitly. Several approaches have been shown to improve results with extended reasoning steps by the system, such as chain-of-thought (Wei et al., 2022), deductive verification (Ling et al., 2023), and self-verification (Miao et al., 2023; Jiang et al., 2023a; Weng et al., 2022). The latter tries to predict the (masked) question given the answer for math problems, and use that as evidence that this is the correct solution.
# 3 CHAIN-OF-VERIFICATION
Our approach assumes access to a base LLM that – despite potentially being prone to hallucination – is capable of being prompted with general instructions in either a few-shot or zero-shot fashion. A key assumption of our method is that this language model, when suitably prompted, can both generate and execute a plan of how to verify itself in order to check its own work, and finally incorporate this analysis into an improved response.
Our overall process, which we call Chain-of-Verification (CoVe), thus performs four core steps:
1. Generate Baseline Response: Given a query, generate the response using the LLM. 2. Plan Verifications: Given both query and baseline response, generate a list of verification questions that could help to self-analyze if there are any mistakes in the original response. 3. Execute Verifications: Answer each verification question in turn, and hence check the answer against the original response to check for inconsistencies or mistakes. 4. Generate Final Verified Response: Given the discovered inconsistencies (if any), generate a revised response incorporating the verification results.
Each of these steps is performed by prompting the same LLM in different ways to obtain the desired response. While steps (1), (2) and (4) all can be invoked with a single prompt, we investigate variations of step (3) including joint, 2-step and factored versions. These variants either involve a single prompt, two prompts or else independent prompts per question, where more sophisticated decomposition can yield improved results.
We describe these steps in more detail below. An overview of the approach is illustrated in Figure 1, and in the Appendix in Figure 3.
# 3.1 BASELINE RESPONSE
Given a query, we generate left-to-right as usual using the LLM, with no special tricks. While this is the first step in the CoVe pipeline, it also serves as the baseline we wish to improve in our experiments (i.e., we will directly compare this baseline response with the final verified response from our overall method).
Given such baseline generations are typically prone to hallucination, CoVe attempts to identify these hallucinations, and correct them, in the following steps.
# 3.2 PLAN VERIFICATIONS
Conditioned on the original query and the baseline response, the model is prompted to generate a series of verification questions that test the factual claims in the original baseline response. For example if part of a longform model response contains the statement “The Mexican–American War was an armed conflict between the United States and Mexico from 1846 to 1848”, then one possible verification question to check those dates could be “When did the Mexican American war start and end?”. We note that verification questions are not templated and the language model is free to phrase these in any form it wants, and they also do not have to closely match the phrasing of the original text.
In our experiments, we perform such verification planning by providing a few-shot prompt of (response, verification) demonstrations to our LLM. See section 11 for the few-shot prompts we will use in our experiments. We note it is also possible with a sufficiently performant instruction-following LLM that this could be performed zero-shot.
# 3.3 EXECUTE VERIFICATIONS
Given the planned verification questions, the next step is to answer them in order to assess if any hallucinations exist. While techniques such as retrieval-augmentation could be used in this process, such as verification via search engine, in this work we do not explore tool-use. Instead, we consider only using the LLM itself in all steps of CoVe, hence the model is used to check its own work. We investigate several variants of verification execution, called joint, 2-Step, factored and factor+revise.
Joint In the joint method, the planning and execution (steps 2 and 3) are accomplished by using a single LLM prompt, whereby the few-shot demonstrations include both verification questions and their answers immediately after the questions. In this approach separate prompts are not needed.
2-Step A potential disadvantage of the joint method is that because the verification questions must condition on the baseline response in the LLM context, and the method is joint, the verification answers have to condition on the initial response as well. This may increase the likelihood of repetition, another known issue of modern LLMs (Holtzman et al., 2019). This means the verification questions might hallucinate similarly to the original baseline response, which defeats the purpose. We hence instead separate the planning and execution into separate steps, both with their own LLM prompt. The planning prompt conditions on the baseline response in the first step. The verification questions generated from planning are answered in the second step, where crucially the context given to the LLM prompt only contains the questions, and not the original baseline response and hence cannot repeat those answers directly.
Factored Another, more sophisticated approach, is to answer all questions independently as separate prompts. Again, crucially, those prompts do not contain the original baseline response and are hence not prone to simply copying or repeating it. The factored approach has the further advantage of removing any potential interference not only from the baseline response, but also between answer contexts, and is somewhat related to the recent (concurrent) work of Radhakrishnan et al. (2023) for subquestion answering by factored decomposition, hence we adopt their naming. It can also potentially handle more verification questions by virtue of them not all having to fit with the same single context. While this is potentially more computationally expensive, requiring the execution of many more LLM prompts, they can be run in parallel, and hence be batched. In order to do this, we first have to take the set of generated questions from subsection 3.2 and parse them into separate questions, which is a relatively easy task as the few-shot demonstrations we provide indicate they should be generated as a comma-separated list. We can then split them out into separate LLM prompts.
Factor+Revise After answering the verification questions, the overall CoVe pipeline then has to either implicitly or explicitly cross-check whether those answers indicate an inconsistency with the original responses. In the factor+revise approach, we execute this as a deliberate step via an extra LLM prompt, which may make it easier for the final system to reason about this step explicitly. Differently to answering the verification questions, the cross-checking phase needs to condition on both the baseline response and the verification question and answer. We thus execute this as separate LLM prompts, one “cross-check” prompt for each question, with again a set of few-shot demonstrations showing the desired output. For example if the original baseline response contained the phrase “It followed in the wake of the 1845 U.S. annexation of Texas. . . ” and CoVe generated a verification question When did Texas secede from Mexico? which was answered with 1836 then an inconsistency should be detected by this step.
# 3.4 FINAL VERIFIED RESPONSE
Finally, the improved response that takes verification into account is generated. This is executed by a final few-shot prompt where the context takes into account all of the previous reasoning steps, the baseline response and verification question answer pairs, so that the corrections can take place. If the Factor+Revise approach is used from subsection 3.3 then the output of the cross-check inconsistency detection is provided as well.
# 4 EXPERIMENTS
We use various experimental benchmarks to measure the efficacy of CoVe in reducing hallucination, comparing against a number of baselines.
# 4.1 TASKS
The benchmarks we use range from list-based questions where the required answer is a set of entities, to where the answer is a longform generation of multiple freeform sentences.
# 4.1.1 WIKIDATA
We start by testing CoVe on a set of automatically generated questions using the Wikidata $\mathsf { A P I } ^ { 1 }$ . We create list questions of the form: “Who are some [Profession]s who were born in [City]?”. For example, “Who are some politicians who were born in Boston?”. The answer to these questions is a set of entities, where the gold list is obtained from the Wikidata knowledge base. This results in a dataset of 56 test questions, each typically containing ${ \sim } 6 0 0$ known gold entities, but typically an LLM will produce a much shorter list. We then use the precision metric (micro-averaged) to measure performance, in addition to reporting the averaged number of positive and negative entities produced.
# 4.1.2 WIKI-CATEGORY LIST
We then proceed to a harder set-generation task. We use the QUEST (Malaviya et al., 2023) dataset that was created using Wikipedia Category lists. We convert these category names to questions by simply prepending a “Name some”. Owing to the varied questions such as Name some Mexican animated horror films or Name some Endemic orchids of Vietnam we believe this task can pose a greater challenge. We collate all examples in the dataset that do not require logical operations to create a set of 55 test questions each having 8 answers. Similar to the Wikidata task, we measure ˜ precision (micro-averaged) to measure performance, in addition to reporting the averaged number of positive and negative entities produced.
# 4.1.3 MULTISPANQA
We next test our approach on an reading comprehension benchmark, MultiSpanQA (Li et al., 2022). MultiSpanQA comprises of questions that have multiple independent answers (derived from a series of multiple discontiguous spans in the text, with questions originally from the Natural Questions dataset). We consider a closed-book setting, where we do not provide supporting documents, and hence consider a subset of questions which are factoid-based, so that our base LLM is more likely to be able to answer them. We thus use a test set of 418 questions with shorter answers per span (up to 3 tokens per item). For example, Q: Who invented the first printing press and in what year?, A: Johannes Gutenberg, 1450.
Table 1: Test Precision and average number of positive and negative (hallucination) entities for list-based questions on the Wikidata and Wiki-Category list tasks.
<table><tr><td></td><td colspan="2">Wikidata (Easier)</td><td></td><td colspan="4">Wiki-Category list (Harder)</td></tr><tr><td>LLM</td><td>Method</td><td>Prec. (↑)</td><td>Pos.</td><td>Neg.</td><td>Prec.(↑)</td><td>Pos.</td><td>Neg.</td></tr><tr><td>Llama 2 70B Chat</td><td>Zero-shot</td><td>0.12</td><td>0.55</td><td>3.93</td><td>0.05</td><td>0.35</td><td>6.85</td></tr><tr><td>Llama 2 70B Chat</td><td>CoT</td><td>0.08</td><td>0.75</td><td>8.92</td><td>0.03</td><td>0.30</td><td>11.1</td></tr><tr><td>Llama 65B</td><td>Few-shot</td><td>0.17</td><td>0.59</td><td>2.95</td><td>0.12</td><td>0.55</td><td>4.05</td></tr><tr><td>Llama 65B</td><td>CoVe (joint)</td><td>0.29</td><td>0.41</td><td>0.98</td><td>0.15</td><td>0.30</td><td>1.69</td></tr><tr><td>Llama 65B</td><td>CoVe (two-step)</td><td>0.36</td><td>0.38</td><td>0.68</td><td>0.21</td><td>0.50</td><td>0.52</td></tr><tr><td>Llama 65B</td><td>CoVe (factored)</td><td>0.32</td><td>0.38</td><td>0.79</td><td>0.22</td><td>0.52</td><td>1.52</td></tr></table>
# 4.1.4 LONGFORM GENERATION OF BIOGRAPHIES
We next validate the performance of CoVe on longform text generation. In this setting, we evaluate our method on generating biographies, adopting the benchmark proposed in by Min et al. (2023). Here the model is simply prompted to generate a biography of a selected entity using the prompt: “Tell me a bio of <entity>”. We evaluate the efficacy of our approach using the FACTSCORE metric (Min et al., 2023) developed in that work, which uses a retrieval-augmented language model to fact-check the response (Instruct-Llama, “Llama $^ +$ Retrieval $+ \mathrm { N P ^ { , } }$ ), which they showed correlates well with human judgments.
# 4.2 BASELINES
We use Llama 65B, a strong open model as our base LLM (Touvron et al., 2023a), and use greedy decoding for all models. As Llama 65B is not instruction fine-tuned, we employ few-shot examples particular to each task for measuring performance on each of our benchmarks. This serves as our main baseline which CoVe tries to improve upon. CoVe uses the same Llama 65B base, but includes, for the same few-shot examples, demonstrations of verification questions and final verified responses, following Figure 1 and section 3. Thus, we measure the ability to improve over the original baseline response for the same LLM. For CoVe, we compare different variants, particularly the joint and factored versions on all tasks.
We also compare to Llama instruction fine-tuned models, for which we use Llama 2 (Touvron et al., 2023b). We measure both zero-shot performance on the task, or zero-shot with chain-of-thought by adding “Let’s think step by step” to the zero-shot prompt. We find that the instruction fine-tuned models tend to generate extraneous content when queried. This can especially be a problem for the list-based tasks. To deal with this we add an extra line to our prompt: “List only the answers separated by a comma”. We also add another layer of post-processing to extract the answers by using an off-the-shelf NER model to further avoid this issue as this helped. However, we still expect few-shot to improve over this, especially for tasks like Multi-Span-QA where the answers are not all named entities, and the few-shot examples effectively show the domain of the task.
For the longform generation of biographies we also compare to several existing model results reported in Min et al. (2023), in particular InstructGPT (Ouyang et al., 2022), ChatGPT 2 and PerplexityAI 3.
# 4.3 RESULTS
We are interested in empirically answering the following research questions:
RQ1 Can COVE effectively reduce the rate of hallucinatory content produced by the LLM? RQ2 Can COVE be used to fix or remove incorrect generations without decreasing the amount of correct content?
Table 2: Closed book MultiSpanQA test performance, comparing CoVe with various baselines.
<table><tr><td>LLM</td><td>Method</td><td>F1(1)</td><td>Prec.</td><td>Rec.</td></tr><tr><td>Llama 2 70B Chat</td><td>Zero-shot</td><td>0.20</td><td>0.13</td><td>0.40</td></tr><tr><td>Llama 2 70B Chat</td><td>CoT</td><td>0.17</td><td>0.11</td><td>0.37</td></tr><tr><td>Llama 65B</td><td>Few-shot</td><td>0.39</td><td>0.40</td><td>0.38</td></tr><tr><td>Llama 65B</td><td>CoVe (joint)</td><td>0.46</td><td>0.50</td><td>0.42</td></tr><tr><td>Llama 65B</td><td>CoVe (factored)</td><td>0.48</td><td>0.50</td><td>0.46</td></tr></table>
Table 3: Longform generation of biographies with metrics defined from Min et al. (2023). Models marked with $^ *$ are reported from previous work. FACTSCORE automatically computed using “InstructLlama” ( Retrieve $ \mathrm { L M } + \mathrm { N P }$ ), the best open-access model.
<table><tr><td>LLM</td><td>Method</td><td>FACTSCORE. (↑)</td><td>Avg. # facts</td></tr><tr><td>InstructGPT*</td><td>Zero-shot</td><td>41.1</td><td>26.3</td></tr><tr><td>ChatGPT*</td><td>Zero-shot</td><td>58.7</td><td>34.7</td></tr><tr><td>PerplexityAI*</td><td>Retrieval-based</td><td>61.6</td><td>40.8</td></tr><tr><td>Llama 2 70B Chat</td><td>Zero-shot</td><td>41.3</td><td>64.9</td></tr><tr><td>Llama 2 70B Chat</td><td>CoT</td><td>41.1</td><td>49.0</td></tr><tr><td>Llama 65B</td><td>Few-shot</td><td>55.9</td><td>16.6</td></tr><tr><td>Llama 65B</td><td>CoVe (joint)</td><td>60.8</td><td>12.8</td></tr><tr><td>Llama 65B</td><td>CoVe (factored)</td><td>63.7</td><td>11.7</td></tr><tr><td>Llama 65B</td><td>CoVe (factor+revise)</td><td>71.4</td><td>12.3</td></tr><tr><td>GPT-3</td><td>Few-shot</td><td>45.3</td><td>15.6</td></tr><tr><td>GPT-3 + ChatGPT</td><td>ChatProtect Muindler et al. (2023)</td><td>48.5</td><td>14.6</td></tr><tr><td>GPT-3 + InstructGPT</td><td>SCG-LL Manakul et al. (2023)</td><td>60.6</td><td>6.0</td></tr><tr><td>GPT-3+DeBERTA</td><td>SCG-NLI Manakul et al. (2023)</td><td>61.7</td><td>6.3</td></tr><tr><td>GPT-3 + InstructGPT</td><td>CoVe (factor+revise)</td><td>68.6</td><td>9.0</td></tr></table>
 Figure 2: FACTSCORE performance distribution across head, torso and tail facts for CoVe variants and various baselines on longform generation of biographies.
Our main results across the four benchmark tasks are given in Table 1, Table 2 and Table 3, and our main findings are as follows.
CoVe improves precision on list-based answer tasks We find that CoVe provides large gains in precision on the list-based tasks, e.g. more than doubles the precision from the Llama 65B few-shot baseline for the Wikidata task (from 0.17 to 0.36). We find from the positive and negative breakdown that there is a large reduction in the number of hallucinated answers (negatives: $2 . 9 5 0 . 6 8 )$ while only a relatively small reduction in the number of non-hallucinations (positives: $0 . 5 9 0 . 3 8$ ).
CoVe improves performance on closed book QA We also find that CoVe brings improvements in general QA problems, as measured on MultiSpanQA. We observe a $23 \%$ improvement in F1 over the few-shot baseline $( 0 . 3 9 0 . 4 8 )$ ), where the improvements come from gains in both precision and recall.
CoVe improves precision on longform generation These results also extend to longform generation, where we actually see larger gains than in the QA setting. FACTSCORE increases $28 \%$ $5 5 . 9 $ 71.4) from the few-shot baseline, with again only a relatively small reduction in average number of facts provided $1 6 . 6 1 2 . 3$ ). We also show the breakdown of improvements across facts in Figure 2, where one can see CoVe improves results for both rare and more frequent facts.
Instruction-tuning and CoT do not reduce hallucinations We find that the few-shot baseline that employs a pre-trained Llama model outperforms Llama-2-Chat, an instruction tuned model, across all the tasks. The few-shot examples lead the model to give outputs in line with those expected for the task, whereas general instruction tuning produces more hallucinations or incorrect outputs. Zero-shot chain-of-thought (CoT) prompting also fails to improve the results for these tasks.
Factored and 2-step CoVe improve performance We observe a consistent performance improvement across all tasks from applying the factored CoVe approach compared to joint CoVe. For example improvement from $6 0 . 8 6 3 . 7$ in FACTSCORE in longform generation. Similarly, the 2-step approach also outperforms the joint approach, as tested on the Wikidata and Wiki-Category list tasks, with 2-step giving the best results for Wikidata, and factored the best for Wiki-Category. All these results support our hypothesis that verifying questions should not attend to the original baseline response as they may be prone to repeating it (as the joint method can do).
Further explicit reasoning helps remove hallucinations In the longform generation task we also explore more sophisticated reasoning steps in the CoVe “factor+revise” method, which explicitly cross-checks whether verification answers indicate an inconsistency. We see large gains in the FACTSCORE metric from this further explicit reasoning from 63.7 (factored) $ 7 1 . 4$ (factor+revise). This gives further indication that appropriate and explicit reasoning in LLMs can bring improvements in mitigating hallucinations.
CoVe-based Llama outperforms InstructGPT, ChatGPT and PerplexityAI On the longform generation task, our baseline few-shot Llama 65B is outperformed by the ChatGPT and PerplexityAI models in terms of the FACTSCORE metric. However, applying CoVe to Llama 65B lifts its performance above ChatGPT and InstructGPT, as well as PerplexityAI. This is particularly impressive compared to PerplexityAI considering that is a model that can support its facts with retrieval-augmentation, whereas CoVe uses only the base language model itself with improved reasoning via deliberation (verification). However, Figure 2 shows PerplexityAI still outperforms CoVe for very rare facts where retrieval is essential, but CoVe outperforms PerplexityAI for frequent facts.
CoVe outperforms existing hallucination mitigation baselines We compare CoVe to three recently released longform hallucination mitigation approaches — NLI and LLM, the two bestperforming variants of SelfCheckGPT (Manakul et al., 2023) and ChatProtect Mundler et al. (2023). ¨ Our results in Table 3 show that COVE outperforms all these baselines. More details on our implementations of the baselines can be found in section 9. For SelfCheckGPT we experiment with different thresholds (in Table 6) and choose a threshold that results in a high FACTSCORE without removing a lot of facts. We note that some models produce fewer overall facts than others, however, the FACTSCORE metric is normalized and hence comparable across models. We verified this experimentally by clipping Llama-2-70B chat’s output to present fewer facts (as it contains the largest number in its output out of all models), but this did not change its FACTSCORE substantially, e.g. clipping to 10 sentences increased its score from $4 1 . 3 4 2 . 7$ . We note the length of the generations of the few-shot-based models is essentially governed by the few-shot examples, which in turn are constrained by the context length.
Shortform verification questions are more accurately answered than longform queries In a longform response, LLMs are prone to generate a number of hallucinations. However, it can often be the case that the LLM itself would know these hallucinations are wrong if queried specifically for that individual fact, independent of the rest of the longform generation, see Figure 1, Figure 3, and section 12. This can be seen quantitatively on the Wikidata task, where only ${ \sim } 1 7 \%$ of the Llama few-shot baseline answer entities are correct in list-based questions. However, when querying each individual entity via a verification question, we find ${ \sim } 7 0 \%$ are correctly answered.
Open LLM-based verification questions outperform yes/no-based and rule-based verification questions In our method, CoVe, the verification questions generated by the LLM expect answers that are true facts. Another alternative type of verification questions would be templated verification questions, which can be generated cheaply, and binary questions. We first compare to heuristically constructed questions by replacing the LLM questions with templated yes/no questions of the form “Does $X$ answer the question” for list-based questions with elements $X$ in the answer. Results on the Wiki-Category task, given in Table 4, show a reduced precision with rule-based verification questions. We then move on to binary questions where we include the fact as part of the verification question and ask it in a yes/no answer format. We evaluate this difference in Table 4, and find that yes/no type questions perform worse for the factored version of CoVe. Some anecdotal examples are included in Appendix section 12 for ChatGPT where we find the model tends to agree with facts in a yes/no question format whether they are right or wrong. We believe this difference would be larger for longform generation where the types of required verification questions can be more diverse, and LLM-based verification becomes even more necesary.
Inference overhead Approaches that detect hallucinations via inconsistencies require repeated prompts to the LLM. COVE essentially requires 1 LLM call for generating the baseline response, 1 LLM call for each sentence to plan the verifications, 1 LLM call to verify each fact and 1 LLM call for each fact to generate the consistent response. We also note that the LLM calls for verification for each fact can be parallelized. This is comparable and in certain cases fewer LLM calls compared to other approaches for hallucination mitigation. We provide a more in-depth analysis in section 8.
# 5 CONCLUSION
We introduced Chain-of-Verification $\mathrm { ( C o V e ) }$ , an approach to reduce hallucinations in a large language model by deliberating on its own responses and self-correcting them. In particular, we showed that models are able to answer verification questions with higher accuracy than when answering the original query by breaking down the verification into a set of simpler questions. Secondly, when answering the set of verification questions, we showed that controlling the attention of the model so that it cannot attend to its previous answers (factored CoVe) helps alleviate copying the same hallucinations. Overall, our method provides substantial performance gains over the original language model response just by asking the same model to deliberate on (verify) its answer. An obvious extension to our work is to equip CoVe with tool-use, e.g., to use retrieval augmentation in the verification execution step which would likely bring further gains.
# 6 LIMITATIONS
While our Chain-of-Verification (CoVe) method seeks to reduce hallucinations, it does not remove them completely from generations. This means that CoVe can still generate incorrect or misleading information for a given query, even if it improves over the baseline. We also note that in our experiments we have only addressed hallucinations in the form of directly stated factual inaccuracies. However, hallucinations could come in other forms, such as during incorrect reasoning steps, as part of opinions, etc. We also note that the generations CoVe produces come with verifications which, if viewed by the user, add more interpretability to its decisions, but come at the cost of increased computational expense due to generating more tokens in the output, similar to other reasoning methods such as Chain-of-Thought.
Our method seeks to make a large language model produce improved responses by spending more time deliberating to identify its own mistakes. While we have shown this gives clear improvements, the upper bound to the improvement is clearly limited by the overall capabilities of the model, e.g. in identifying and knowing what it knows. In this regard, an orthogonal line of research, as discussed in section 2 is the use of external tools by language models, to gain further information beyond what is stored in its weights. While we do not explore that avenue in this work those techniques would likely be fruitful to combine with the findings here.
# REFERENCES
Leonard Adolphs, Kurt Shuster, Jack Urbanek, Arthur Szlam, and Jason Weston. Reason first, then respond: Modular generation for knowledge-infused dialogue. arXiv preprint arXiv:2111.05204, 2021. Ayush Agrawal, Lester Mackey, and Adam Tauman Kalai. Do language models know when they’re hallucinating references? arXiv preprint arXiv:2305.18248, 2023. I Chern, Steffi Chern, Shiqi Chen, Weizhe Yuan, Kehua Feng, Chunting Zhou, Junxian He, Graham Neubig, Pengfei Liu, et al. Factool: Factuality detection in generative ai–a tool augmented framework for multi-task and multi-domain scenarios. arXiv preprint arXiv:2307.13528, 2023a. I-Chun Chern, Zhiruo Wang, Sanjan Das, Bhavuk Sharma, Pengfei Liu, Graham Neubig, et al. Improving factuality of abstractive summarization via contrastive reward learning. arXiv preprint arXiv:2307.04507, 2023b. Roi Cohen, May Hamri, Mor Geva, and Amir Globerson. Lm vs lm: Detecting factual errors via cross examination. arXiv preprint arXiv:2305.13281, 2023. Boris A Galitsky. Truth-o-meter: Collaborating with llm in fighting its hallucinations. 2023. Luyu Gao, Zhuyun Dai, Panupong Pasupat, Anthony Chen, Arun Tejasvi Chaganty, Yicheng Fan, Vincent Zhao, Ni Lao, Hongrae Lee, Da-Cheng Juan, et al. Rarr: Researching and revising what language models say, using language models. In Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pp. 16477–16508, 2023. Ari Holtzman, Jan Buys, Li Du, Maxwell Forbes, and Yejin Choi. The curious case of neural text degeneration. arXiv preprint arXiv:1904.09751, 2019. Ziwei Ji, Nayeon Lee, Rita Frieske, Tiezheng Yu, Dan Su, Yan Xu, Etsuko Ishii, Ye Jin Bang, Andrea Madotto, and Pascale Fung. Survey of hallucination in natural language generation. ACM Computing Surveys, 55(12):1–38, 2023. Weisen Jiang, Han Shi, Longhui Yu, Zhengying Liu, Yu Zhang, Zhenguo Li, and James T Kwok. Backward reasoning in large language models for verification. arXiv preprint arXiv:2308.07758, 2023a. Zhengbao Jiang, Frank F Xu, Luyu Gao, Zhiqing Sun, Qian Liu, Jane Dwivedi-Yu, Yiming Yang, Jamie Callan, and Graham Neubig. Active retrieval augmented generation. arXiv preprint arXiv:2305.06983, 2023b. Saurav Kadavath, Tom Conerly, Amanda Askell, Tom Henighan, Dawn Drain, Ethan Perez, Nicholas Schiefer, Zac Hatfield-Dodds, Nova DasSarma, Eli Tran-Johnson, et al. Language models (mostly) know what they know. arXiv preprint arXiv:2207.05221, 2022. Jack Lanchantin, Shubham Toshniwal, Jason Weston, Arthur Szlam, and Sainbayar Sukhbaatar. Learning to reason and memorize with self-notes. arXiv preprint arXiv:2305.00833, 2023. Haonan Li, Martin Tomko, Maria Vasardani, and Timothy Baldwin. Multispanqa: A dataset for multi-span question answering. In Proceedings of the 2022 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, pp. 1250–1260, 2022. Kenneth Li, Oam Patel, Fernanda Viegas, Hanspeter Pfister, and Martin Wattenberg. Inference-time ´ intervention: Eliciting truthful answers from a language model. arXiv preprint arXiv:2306.03341, 2023. Zhan Ling, Yunhao Fang, Xuanlin Li, Zhiao Huang, Mingu Lee, Roland Memisevic, and Hao Su. Deductive verification of chain-of-thought reasoning. arXiv preprint arXiv:2306.03872, 2023. Aman Madaan, Niket Tandon, Prakhar Gupta, Skyler Hallinan, Luyu Gao, Sarah Wiegreffe, Uri Alon, Nouha Dziri, Shrimai Prabhumoye, Yiming Yang, et al. Self-refine: Iterative refinement with self-feedback. arXiv preprint arXiv:2303.17651, 2023. Chaitanya Malaviya, Peter Shaw, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. Quest: A retrieval dataset of entity-seeking queries with implicit set operations. arXiv preprint arXiv:2305.11694, 2023. Potsawee Manakul, Adian Liusie, and Mark JF Gales. Selfcheckgpt: Zero-resource black-box hallucination detection for generative large language models. arXiv preprint arXiv:2303.08896, 2023. Joshua Maynez, Shashi Narayan, Bernd Bohnet, and Ryan McDonald. On faithfulness and factuality in abstractive summarization. arXiv preprint arXiv:2005.00661, 2020. Jacob Menick, Maja Trebacz, Vladimir Mikulik, John Aslanides, Francis Song, Martin Chadwick, Mia Glaese, Susannah Young, Lucy Campbell-Gillingham, Geoffrey Irving, et al. Teaching language models to support answers with verified quotes. arXiv preprint arXiv:2203.11147, 2022. Ning Miao, Yee Whye Teh, and Tom Rainforth. Selfcheck: Using llms to zero-shot check their own step-by-step reasoning. arXiv preprint arXiv:2308.00436, 2023. Sabrina J Mielke, Arthur Szlam, Emily Dinan, and Y-Lan Boureau. Reducing conversational agents’ overconfidence through linguistic calibration. Transactions of the Association for Computational Linguistics, 10:857–872, 2022. Sewon Min, Kalpesh Krishna, Xinxi Lyu, Mike Lewis, Wen-tau Yih, Pang Wei Koh, Mohit Iyyer, Luke Zettlemoyer, and Hannaneh Hajishirzi. Factscore: Fine-grained atomic evaluation of factual precision in long form text generation. arXiv preprint arXiv:2305.14251, 2023. Niels Mundler, Jingxuan He, Slobodan Jenko, and Martin Vechev. Self-contradictory hallucinations ¨ of large language models: Evaluation, detection and mitigation. arXiv preprint arXiv:2305.15852, 2023. Shashi Narayan, Joshua Maynez, Reinald Kim Amplayo, Kuzman Ganchev, Annie Louis, Fantine Huot, Anders Sandholm, Dipanjan Das, and Mirella Lapata. Conditional generation with a question-answering blueprint. Transactions of the Association for Computational Linguistics, 11: 974–996, 2023. Long Ouyang, Jeffrey Wu, Xu Jiang, Diogo Almeida, Carroll Wainwright, Pamela Mishkin, Chong Zhang, Sandhini Agarwal, Katarina Slama, Alex Ray, et al. Training language models to follow instructions with human feedback. Advances in Neural Information Processing Systems, 35: 27730–27744, 2022. Baolin Peng, Michel Galley, Pengcheng He, Hao Cheng, Yujia Xie, Yu Hu, Qiuyuan Huang, Lars Liden, Zhou Yu, Weizhu Chen, et al. Check your facts and try again: Improving large language models with external knowledge and automated feedback. arXiv preprint arXiv:2302.12813, 2023. Fabio Petroni, Tim Rocktaschel, Patrick Lewis, Anton Bakhtin, Yuxiang Wu, Alexander H Miller, ¨ and Sebastian Riedel. Language models as knowledge bases? arXiv preprint arXiv:1909.01066, 2019. Ofir Press, Muru Zhang, Sewon Min, Ludwig Schmidt, Noah A Smith, and Mike Lewis. Measuring and narrowing the compositionality gap in language models. arXiv preprint arXiv:2210.03350, 2022. Alec Radford, Jeffrey Wu, Rewon Child, David Luan, Dario Amodei, Ilya Sutskever, et al. Language models are unsupervised multitask learners. OpenAI blog, 1(8):9, 2019. Ansh Radhakrishnan, Karina Nguyen, Anna Chen, Carol Chen, Carson Denison, Danny Hernandez, Esin Durmus, Evan Hubinger, Jackson Kernion, Kamile Luko ˙ siˇ ut¯ e, et al. Question decomposition ˙ improves the faithfulness of model-generated reasoning. arXiv preprint arXiv:2307.11768, 2023. Hannah Rashkin, Vitaly Nikolaev, Matthew Lamm, Lora Aroyo, Michael Collins, Dipanjan Das, Slav Petrov, Gaurav Singh Tomar, Iulia Turc, and David Reitter. Measuring attribution in natural language generation models. Computational Linguistics, pp. 1–66, 2023. Paul Roit, Johan Ferret, Lior Shani, Roee Aharoni, Geoffrey Cideron, Robert Dadashi, Matthieu Geist, Sertan Girgin, Leonard Hussenot, Orgad Keller, et al. Factually consistent summarization ´ via reinforcement learning with textual entailment feedback. arXiv preprint arXiv:2306.00186, 2023. Stephen Roller, Emily Dinan, Naman Goyal, Da Ju, Mary Williamson, Yinhan Liu, Jing Xu, Myle Ott, Kurt Shuster, Eric M Smith, et al. Recipes for building an open-domain chatbot. arXiv preprint arXiv:2004.13637, 2020. Kurt Shuster, Spencer Poff, Moya Chen, Douwe Kiela, and Jason Weston. Retrieval augmentation reduces hallucination in conversation. arXiv preprint arXiv:2104.07567, 2021. Kai Sun, Yifan Ethan Xu, Hanwen Zha, Yue Liu, and Xin Luna Dong. Head-to-tail: How knowledgeable are large language models (llm)? aka will llms replace knowledge graphs? arXiv preprint arXiv:2308.10168, 2023a. Weiwei Sun, Zhengliang Shi, Shen Gao, Pengjie Ren, Maarten de Rijke, and Zhaochun Ren. Contrastive learning reduces hallucination in conversations. In Proceedings of the AAAI Conference on Artificial Intelligence, volume 37, pp. 13618–13626, 2023b. Hugo Touvron, Thibaut Lavril, Gautier Izacard, Xavier Martinet, Marie-Anne Lachaux, Timothee´ Lacroix, Baptiste Roziere, Naman Goyal, Eric Hambro, Faisal Azhar, et al. Llama: Open and \` efficient foundation language models. arXiv preprint arXiv:2302.13971, 2023a. Hugo Touvron, Louis Martin, Kevin Stone, Peter Albert, Amjad Almahairi, Yasmine Babaei, Nikolay Bashlykov, Soumya Batra, Prajjwal Bhargava, Shruti Bhosale, Dan Bikel, Lukas Blecher, Cristian Canton Ferrer, Moya Chen, Guillem Cucurull, David Esiobu, Jude Fernandes, Jeremy Fu, Wenyin Fu, Brian Fuller, Cynthia Gao, Vedanuj Goswami, Naman Goyal, Anthony Hartshorn, Saghar Hosseini, Rui Hou, Hakan Inan, Marcin Kardas, Viktor Kerkez, Madian Khabsa, Isabel Kloumann, Artem Korenev, Punit Singh Koura, Marie-Anne Lachaux, Thibaut Lavril, Jenya Lee, Diana Liskovich, Yinghai Lu, Yuning Mao, Xavier Martinet, Todor Mihaylov, Pushkar Mishra, Igor Molybog, Yixin Nie, Andrew Poulton, Jeremy Reizenstein, Rashi Rungta, Kalyan Saladi, Alan Schelten, Ruan Silva, Eric Michael Smith, Ranjan Subramanian, Xiaoqing Ellen Tan, Binh Tang, Ross Taylor, Adina Williams, Jian Xiang Kuan, Puxin Xu, Zheng Yan, Iliyan Zarov, Yuchen Zhang, Angela Fan, Melanie Kambadur, Sharan Narang, Aurelien Rodriguez, Robert Stojnic, Sergey Edunov, and Thomas Scialom. Llama 2: Open foundation and fine-tuned chat models, 2023b.
Neeraj Varshney, Wenlin Yao, Hongming Zhang, Jianshu Chen, and Dong Yu. A stitch in time saves nine: Detecting and mitigating hallucinations of llms by validating low-confidence generation. arXiv preprint arXiv:2307.03987, 2023.
Chaojun Wang and Rico Sennrich. On exposure bias, hallucination and domain shift in neural machine translation. arXiv preprint arXiv:2005.03642, 2020.
Xuezhi Wang, Jason Wei, Dale Schuurmans, Quoc Le, Ed Chi, Sharan Narang, Aakanksha Chowdhery, and Denny Zhou. Self-consistency improves chain of thought reasoning in language models. arXiv preprint arXiv:2203.11171, 2022.
Jason Wei, Xuezhi Wang, Dale Schuurmans, Maarten Bosma, Fei Xia, Ed Chi, Quoc V Le, Denny Zhou, et al. Chain-of-thought prompting elicits reasoning in large language models. Advances in Neural Information Processing Systems, 35:24824–24837, 2022.
Yixuan Weng, Minjun Zhu, Shizhu He, Kang Liu, and Jun Zhao. Large language models are reasoners with self-verification. arXiv preprint arXiv:2212.09561, 2022.
Zeqiu Wu, Yushi Hu, Weijia Shi, Nouha Dziri, Alane Suhr, Prithviraj Ammanabrolu, Noah A Smith, Mari Ostendorf, and Hannaneh Hajishirzi. Fine-grained human feedback gives better rewards for language model training. arXiv preprint arXiv:2306.01693, 2023.
Hongbin Ye, Tong Liu, Aijia Zhang, Wei Hua, and Weiqiang Jia. Cognitive mirage: A review of hallucinations in large language models. arXiv preprint arXiv:2309.06794, 2023.
Wenhao Yu, Zhihan Zhang, Zhenwen Liang, Meng Jiang, and Ashish Sabharwal. Improving language models via plug-and-play retrieval feedback. arXiv preprint arXiv:2305.14002, 2023. Muru Zhang, Ofir Press, William Merrill, Alisa Liu, and Noah A Smith. How language model hallucinations can snowball. arXiv preprint arXiv:2305.13534, 2023. Ruochen Zhao, Xingxuan Li, Shafiq Joty, Chengwei Qin, and Lidong Bing. Verify-and-edit: A knowledge-enhanced chain-of-thought framework. arXiv preprint arXiv:2305.03268, 2023.
# 7 RULE-BASED VS BINARY VS GENERAL QUESTIONS
Table 4: Comparison of various COVE verification plan strategies (rows) and verification execution techniques (columns) on the WikiCategory task.
<table><tr><td></td><td colspan="2">Verification Execution</td></tr><tr><td></td><td>CoVe (joint)</td><td>CoVe (factored)</td></tr><tr><td>Verification Plan</td><td>Prec.</td><td>Prec.</td></tr><tr><td>Rule-based questions Generated by model:</td><td>0.13</td><td>0.16</td></tr><tr><td>yes/no questions</td><td>0.15</td><td>0.19</td></tr><tr><td>general questions</td><td>0.15</td><td>0.22</td></tr></table>
# 8 INFERENCE OVERHEAD
$N : =$ Number of text samples, 4 in our experiments $k : =$ Number of repeated mitigations, 3 in our experiments $s : =$ Number of sentences in the generated passage $f : =$ Number of facts in the generated passage
<table><tr><td>Method</td><td>#LLM prompts</td></tr><tr><td>Few-shot</td><td>1</td></tr><tr><td>ChatProtect Mundler et al. (2023)</td><td>1+s×k × (3)</td></tr><tr><td>SCG-LLM Manakul et al. (2023)</td><td>n+1+s×n</td></tr><tr><td>CoVe (factor+revise)</td><td>1+s+2×f</td></tr></table>
Table 5: Worst-case LLM prompts used by each hallucination mitigation approach in the worst case
Based on the current implementations we find the COVE induces a similar inference overhead to other longform hallucination mitigation approaches.
# 9 IMPLEMENTATION OF BASELINES
We use the existing models provided by Manakul et al. (2023) for the NLI model. For the LLM model we prompt GPT-3.5-turbo-instruction with the following instruction (as described in Manakul et al. (2023).
Context: {} Sentence: {} Is the sentence supported by the context above? Answer Yes or No:
Table 6: Different threshold results for SelfCheckGPT
<table><tr><td colspan="3">NLI</td><td colspan="2">LLM</td></tr><tr><td>Threshold</td><td>FS</td><td>Facts</td><td>FS</td><td>Facts</td></tr><tr><td>High</td><td>76.5</td><td>3.0</td><td>61.7</td><td>6.3</td></tr><tr><td>Med</td><td>60.6</td><td>6.0</td><td>56.8</td><td>8.4</td></tr><tr><td>Low</td><td>53.0</td><td>8.0</td><td>53.0</td><td>10</td></tr></table>
# 10 COVE - FURTHER DETAILS
Query
What was the primary cause of the Mexican-American war?
1. Baseline Response
The Mexican–American War was an armed conflict between the United States and Mexico from 1846 to 1848. It followed in the wake of the 1845 U.S. annexation of Texas, which Mexico considered part of its territory in spite of its de facto secession in the 1835 Texas Revolution.

# 4. Final Verified Response
The Mexican–American War was an armed conflict between the United States and Mexico from 1846 to 1848. It followed in the wake of the 1845 U.S. annexation of Texas.
Figure 3: For longform generation, the Chain-of-Verification (CoVe) Factor $^ +$ Revise method is the most effective in our longform generation experiments. CoVe Factor $^ +$ Revise has the model independently identify (cross-check) which facts are consistent with its executed verifications (indicated by tickmark and crosses in the figure). With this extra step we aim to disregard the inconsistent facts and use the consistent facts to regenerate the response.
# 11 PROMPT TEMPLATES
We provide prompt templates for the longform generation of biographies task below for the different steps and variants of CoVe (see section 3). Templates for the other tasks are similar, but using few-shot examples from those tasks instead.
# 11.1 GENERATE BASELINE RESPONSE

Table 7: Few-shot prompting with 3 few-shot examples for the longform generation of biographies task. Other tasks use the same standard few-shot setup as well (with 3 examples from that particular task).
# 11.2 PLAN VERIFICATIONS

Table 8: Step (2) of CoVe involves planning the verification questions. In the biography task case we split the longform generation into its individual passages (e.g. sentences in the biography case, this was done due to excessive context length, which we don’t need to do for the other tasks). The model then generates a verification question for each fact it observes in each passage (a passage may have multiple facts).
# 11.3 EXECUTE VERIFICATIONS
<table><tr><td>A:Answer</td><td>Q:Verification Question</td></tr><tr><td>A:Answer</td><td>Q:Verification Question</td></tr><tr><td></td><td>Q:Verification Question</td></tr><tr><td>A:Answer</td><td></td></tr><tr><td>A:</td><td>Q:Verification Question</td></tr></table>
Table 9: In step (3) of CoVe, the model then generates an answer for each of the verification questions. Again we use 3 few-shot examples.

Table 10: In step (4) of CoVe (factored) the model is then presented with its original generation (split into passages, e.g. sentences, in the biography case, due to excessive context length which we do not need to do for the other tasks) along with its own verification step results. The model is told that this information comes from “another source”. The model is required to synthesize a new final answer based on facts that are consistent between the two sources.
11.5 FACTOR $^ +$ REVISE: IDENTIFY WHICH FACTS ARE CONSISTENT
Context: <Original Fact>. From another source, <output of execute verification step: ${ \mathsf { \Omega } } + { \mathsf { \Omega } } { \mathsf { A } } { \mathsf { \Sigma } } ^ { } $ Response: CONSISTENT. <Consistent fact> Context: <Original Fact>. From another source, <output of execute verification step: ${ \mathsf { \Omega } } + { \mathsf { \Omega } } { \mathsf { A } } { \mathsf { \Sigma } } ^ { } $ Response: INCONSISTENT. Context: <Original Fact>. From another source, <output of execute verification step: ${ \mathsf { \Omega } } + { \mathsf { \Omega } } { \mathsf { A } } { \mathsf { \Sigma } } ^ { } $ Response: PARTIALLY CONSISTENT. <Consistent part>
Table 11: In the CoVe (Factor $^ +$ Revise) variant, as part of step (3) after subsection 11.3, the model is made to explicitly identify which facts are consistent between the two sources. The consistent facts can then be spliced together.
# 12 CHATGPT EXAMPLE SCREENSHOTS
 Figure 4: ChatGPT generates several hallucinations for this question, e.g. Hillary Clinton and Michael Bloomberg.
 Figure 5: Even when the longform answer is provided for a rewritten query (see query from Figure 4), while giving a slightly different answer, ChatGPT still generates several hallucinations for this question, e.g. Hillary Clinton and Michael Bloomberg.
 Figure 6: Shortform questions (which could be verification questions) appear to be answered more factually than the longform answers in Figure 4 and Figure 5.
 Figure 7: Another example of hallucinations for a different query, e.g., John F. Kennedy Jr was born in Washington D.C.
 Figure 8: Examples where questions asking for a fact are answered correctly, but verifying via a yes/no question is incorrect (the model tends to agree with the way the question is stated, even if it was stated incorrectly).123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819[ { "type": "text", "text": "CHAIN-OF-VERIFICATION REDUCES HALLUCINATION IN LARGE LANGUAGE MODELS ", "text_level": 1, "page_idx": 0 }, { "type": "text", "text": "Anonymous authors Paper under double-blind review ", "page_idx": 0 }, { "type": "text", "text": "ABSTRACT ", "text_level": 1, "page_idx": 0 }, { "type": "text", "text": "Generation of plausible yet incorrect factual information, termed hallucination, is an unsolved issue in large language models. We study the ability of language models to deliberate on the responses they give in order to correct their mistakes. We develop the Chain-of-Verification (COVE) method whereby the model first (i) drafts an initial response; then (ii) plans verification questions to fact-check its draft; (iii) answers those questions independently so the answers are not biased by other responses; and (iv) generates its final verified response. In experiments, we show COVE decreases hallucinations across a variety of tasks, from list-based questions from Wikidata, closed book MultiSpanQA and longform text generation. ", "page_idx": 0 }, { "type": "text", "text": "1 INTRODUCTION ", "text_level": 1, "page_idx": 0 }, { "type": "text", "text": "Large Language Models (LLMs) are trained on huge corpora of text documents with billions of tokens of text. It has been shown that as the number of model parameters is increased, performance at tasks such as closed book QA improve in accuracy, and larger models can generate more correct factual statements (Radford et al., 2019; Petroni et al., 2019). However, even the largest models can still fail, particularly on lesser known torso and tail distribution facts (Sun et al., 2023a), i.e. those that occur relatively rarely in the training corpora. In those cases where the model is incorrect, they instead generate an alternative response which is typically plausible looking (e.g., a similar entity, but an incorrect one). These factually incorrect generations are referred to as hallucinations (Maynez et al., 2020). Further, in longform tasks consisting of generating multiple sentences or paragraphs, the hallucination problem can be exacerbated due to the issue of exposure bias (Wang & Sennrich, 2020). ", "page_idx": 0 }, { "type": "text", "text": "The current wave of language modeling research goes beyond next word prediction, and has focused on their ability to reason. Improved performance in reasoning tasks can be gained by encouraging language models to first generate internal thoughts or reasoning chains before responding (Wei et al., 2022; Adolphs et al., 2021; Wang et al., 2022; Lanchantin et al., 2023), as well as updating their initial response through self-critique (Press et al., 2022; Madaan et al., 2023). In this work we follow this line of research to study how and when language-model-based reasoning can be used to reduce hallucinations. We develop an approach, called Chain-of-Verification (CoVe) which, given an initial draft response, first plans verification questions to check its work, and then systematically answers those questions in order to finally produce an improved revised response. We find that independent verification questions tend to provide more accurate facts than those in the original longform answer, and hence improve the correctness of the overall response. We study variations on this recipe across a range of tasks: from list-based questions, closed booked QA and longform text generation. We first propose a joint approach for generating the entire verification chain left-to-right, which improves performance and decreases hallucinations compared to the baseline language model. However, models that attend to existing hallucinations in the context from their own generations tend to repeat the hallucinations. Hence we also introduce further improvements with factored variants which separate out the verification chain steps, in terms of which context is attended to. We show how these factored variants give further performance gains across all three tasks considered. ", "page_idx": 0 }, { "type": "text", "text": "2 RELATED WORK ", "text_level": 1, "page_idx": 0 }, { "type": "text", "text": "Hallucination is a general problem in language model generations that appears across many tasks, from summarization (Maynez et al., 2020) to open-domain dialogue (Roller et al., 2020), and has not ", "page_idx": 0 }, { "type": "text", "text": "Query ", "text_level": 1, "page_idx": 1 }, { "type": "text", "text": "Name some politicians who were born in NY, New York. ", "page_idx": 1 }, { "type": "text", "text": "1. Baseline Response ", "text_level": 1, "page_idx": 1 }, { "type": "text", "text": "Here are some politicians who were born in NY, New York: \n1. Hillary Clinton - former secretary of state and former Democratic presidential nominee \n2. Donald Trump - former president of the United States \n3. Michael Bloomberg - former Mayor of New York City and former Democratic presidential candidate … <list continues..> ", "page_idx": 1 }, { "type": "text", "text": "2. Plan Verifications ", "text_level": 1, "page_idx": 1 }, { "type": "text", "text": "3. Execute Verifications ", "page_idx": 1 }, { "type": "text", "text": "Hillary Clinton was born in Chicago, Illinois, United States on October 26, 1947. ", "page_idx": 1 }, { "type": "text", "text": "- Where was Hillary Clinton born? - Where was Donald Trump born? - Where was Michael Bloomberg born? … <questions continue..> ", "page_idx": 1 }, { "type": "text", "text": "Donald Trump was born on June 14, 1946, in Queens, New York City, New York, United States ", "page_idx": 1 }, { "type": "text", "text": "Michael Bloomberg was born on February 14, 1942, in Boston, Massachusetts, United States. ", "page_idx": 1 }, { "type": "text", "text": "4. Final Verified Response ", "text_level": 1, "page_idx": 1 }, { "type": "text", "text": "Here are some politicians who were born in NY, New York: \n1. Donald Trump - former president of the United States \n2. Alexandria Ocasio-Cortez - Democratic member of the U.S. House of Representatives … <list continues..> ", "page_idx": 1 }, { "type": "text", "text": "Figure 1: Chain-of-Verification (CoVe) method. Given a user query, a large language model generates a baseline response that may contain inaccuracies, e.g. factual hallucinations. We show a query here which failed for ChatGPT (see section 12 for more details). To improve this, CoVe first generates a plan of a set of verification questions to ask, and then executes that plan by answering them and hence checking for agreement. We find that individual verification questions are typically answered with higher accuracy than the original accuracy of the facts in the original longform generation. Finally, the revised response takes into account the verifications. The factored version of CoVe answers verification questions such that they cannot condition on the original response, avoiding repetition and improving performance. ", "page_idx": 1 }, { "type": "text", "text": "been resolved by simply scaling up training data or model size (Zhang et al., 2023). For a survey of the hallucination issue, see Ji et al. (2023) and Ye et al. (2023). A majority of the methods for reducing hallucination can be divided into roughly three categories: training-time correction, generation-time correction and via augmentation (tool-use). ", "page_idx": 1 }, { "type": "text", "text": "In training-time correction methods, an attempt is made to improve the raw left-to-right generations of an encoder-decoder or decoder-only language model by either training or otherwise adjusting the model weights to decrease the probability of hallucinated generations. This includes using reinforcement learning (Roit et al., 2023; Wu et al., 2023), constrastive learning (Chern et al., 2023b; Sun et al., 2023b) and other methods (Li et al., 2023; Narayan et al., 2023). ", "page_idx": 1 }, { "type": "text", "text": "In generation-time correction, a common theme is to make reasoning decisions “on top of” the base LLM in order to make them more reliable. For example, by considering the probabilities of the generated tokens (Mielke et al., 2022; Kadavath et al., 2022). In Manakul et al. (2023) multiple samples are drawn from the model to detect hallucinations. In Varshney et al. (2023) hallucinations are identified using low confidence scores, and their correctness is checked through a validation procedure, mitigated, and then the generation is continued. An alternative to using the confidence scores is to leverage inconsistencies in the LLMs output to detect hallucination. Cohen et al. (2023) show that using inconsistencies for QA tasks can outperform using confidence scores for hallucination detection. Cohen et al. (2023) simulate an interactive multi-agent LM vs. LM debate setup to detect hallucinations for factoid QA, Agrawal et al. (2023) check for hallucinated references, while Mundler ¨ et al. (2023) extract relational triples from generations and verify them against another LLM. COVE also uses a related self-consistency approach but we show our approach can correct hallucinated facts in longform generations by generating and answering verification questions by solely using the same LLM. ", "page_idx": 1 }, { "type": "text", "text": "", "page_idx": 2 }, { "type": "text", "text": "A third approach is to use external tools to help mitigate hallucinations, rather than relying solely on the abilities of the language model itself. For example, retrieval-augmented generation can decrease hallucinations by using factual documents for grounding (Shuster et al., 2021; Jiang et al., 2023b; Yu et al., 2023) or chain-of-thought verification (Zhao et al., 2023). Other approaches include using tools for fact-checking (Chern et al., 2023a; Galitsky, 2023; Peng et al., 2023), or linking to external documents with attribution (Menick et al., 2022; Rashkin et al., 2023; Gao et al., 2023). ", "page_idx": 2 }, { "type": "text", "text": "There are also a number of related works in improving reasoning for logical and mathematical tasks, even if they do not address reducing hallucination explicitly. Several approaches have been shown to improve results with extended reasoning steps by the system, such as chain-of-thought (Wei et al., 2022), deductive verification (Ling et al., 2023), and self-verification (Miao et al., 2023; Jiang et al., 2023a; Weng et al., 2022). The latter tries to predict the (masked) question given the answer for math problems, and use that as evidence that this is the correct solution. ", "page_idx": 2 }, { "type": "text", "text": "3 CHAIN-OF-VERIFICATION ", "text_level": 1, "page_idx": 2 }, { "type": "text", "text": "Our approach assumes access to a base LLM that – despite potentially being prone to hallucination – is capable of being prompted with general instructions in either a few-shot or zero-shot fashion. A key assumption of our method is that this language model, when suitably prompted, can both generate and execute a plan of how to verify itself in order to check its own work, and finally incorporate this analysis into an improved response. ", "page_idx": 2 }, { "type": "text", "text": "Our overall process, which we call Chain-of-Verification (CoVe), thus performs four core steps: ", "page_idx": 2 }, { "type": "text", "text": "1. Generate Baseline Response: Given a query, generate the response using the LLM. 2. Plan Verifications: Given both query and baseline response, generate a list of verification questions that could help to self-analyze if there are any mistakes in the original response. 3. Execute Verifications: Answer each verification question in turn, and hence check the answer against the original response to check for inconsistencies or mistakes. 4. Generate Final Verified Response: Given the discovered inconsistencies (if any), generate a revised response incorporating the verification results. ", "page_idx": 2 }, { "type": "text", "text": "Each of these steps is performed by prompting the same LLM in different ways to obtain the desired response. While steps (1), (2) and (4) all can be invoked with a single prompt, we investigate variations of step (3) including joint, 2-step and factored versions. These variants either involve a single prompt, two prompts or else independent prompts per question, where more sophisticated decomposition can yield improved results. ", "page_idx": 2 }, { "type": "text", "text": "We describe these steps in more detail below. An overview of the approach is illustrated in Figure 1, and in the Appendix in Figure 3. ", "page_idx": 2 }, { "type": "text", "text": "3.1 BASELINE RESPONSE", "text_level": 1, "page_idx": 2 }, { "type": "text", "text": "Given a query, we generate left-to-right as usual using the LLM, with no special tricks. While this is the first step in the CoVe pipeline, it also serves as the baseline we wish to improve in our experiments (i.e., we will directly compare this baseline response with the final verified response from our overall method). ", "page_idx": 2 }, { "type": "text", "text": "Given such baseline generations are typically prone to hallucination, CoVe attempts to identify these hallucinations, and correct them, in the following steps. ", "page_idx": 2 }, { "type": "text", "text": "3.2 PLAN VERIFICATIONS ", "text_level": 1, "page_idx": 3 }, { "type": "text", "text": "Conditioned on the original query and the baseline response, the model is prompted to generate a series of verification questions that test the factual claims in the original baseline response. For example if part of a longform model response contains the statement “The Mexican–American War was an armed conflict between the United States and Mexico from 1846 to 1848”, then one possible verification question to check those dates could be “When did the Mexican American war start and end?”. We note that verification questions are not templated and the language model is free to phrase these in any form it wants, and they also do not have to closely match the phrasing of the original text. ", "page_idx": 3 }, { "type": "text", "text": "In our experiments, we perform such verification planning by providing a few-shot prompt of (response, verification) demonstrations to our LLM. See section 11 for the few-shot prompts we will use in our experiments. We note it is also possible with a sufficiently performant instruction-following LLM that this could be performed zero-shot. ", "page_idx": 3 }, { "type": "text", "text": "3.3 EXECUTE VERIFICATIONS ", "text_level": 1, "page_idx": 3 }, { "type": "text", "text": "Given the planned verification questions, the next step is to answer them in order to assess if any hallucinations exist. While techniques such as retrieval-augmentation could be used in this process, such as verification via search engine, in this work we do not explore tool-use. Instead, we consider only using the LLM itself in all steps of CoVe, hence the model is used to check its own work. We investigate several variants of verification execution, called joint, 2-Step, factored and factor+revise. ", "page_idx": 3 }, { "type": "text", "text": "Joint In the joint method, the planning and execution (steps 2 and 3) are accomplished by using a single LLM prompt, whereby the few-shot demonstrations include both verification questions and their answers immediately after the questions. In this approach separate prompts are not needed. ", "page_idx": 3 }, { "type": "text", "text": "2-Step A potential disadvantage of the joint method is that because the verification questions must condition on the baseline response in the LLM context, and the method is joint, the verification answers have to condition on the initial response as well. This may increase the likelihood of repetition, another known issue of modern LLMs (Holtzman et al., 2019). This means the verification questions might hallucinate similarly to the original baseline response, which defeats the purpose. We hence instead separate the planning and execution into separate steps, both with their own LLM prompt. The planning prompt conditions on the baseline response in the first step. The verification questions generated from planning are answered in the second step, where crucially the context given to the LLM prompt only contains the questions, and not the original baseline response and hence cannot repeat those answers directly. ", "page_idx": 3 }, { "type": "text", "text": "Factored Another, more sophisticated approach, is to answer all questions independently as separate prompts. Again, crucially, those prompts do not contain the original baseline response and are hence not prone to simply copying or repeating it. The factored approach has the further advantage of removing any potential interference not only from the baseline response, but also between answer contexts, and is somewhat related to the recent (concurrent) work of Radhakrishnan et al. (2023) for subquestion answering by factored decomposition, hence we adopt their naming. It can also potentially handle more verification questions by virtue of them not all having to fit with the same single context. While this is potentially more computationally expensive, requiring the execution of many more LLM prompts, they can be run in parallel, and hence be batched. In order to do this, we first have to take the set of generated questions from subsection 3.2 and parse them into separate questions, which is a relatively easy task as the few-shot demonstrations we provide indicate they should be generated as a comma-separated list. We can then split them out into separate LLM prompts. ", "page_idx": 3 }, { "type": "text", "text": "Factor+Revise After answering the verification questions, the overall CoVe pipeline then has to either implicitly or explicitly cross-check whether those answers indicate an inconsistency with the original responses. In the factor+revise approach, we execute this as a deliberate step via an extra LLM prompt, which may make it easier for the final system to reason about this step explicitly. Differently to answering the verification questions, the cross-checking phase needs to condition on both the baseline response and the verification question and answer. We thus execute this as separate LLM prompts, one “cross-check” prompt for each question, with again a set of few-shot demonstrations showing the desired output. For example if the original baseline response contained the phrase “It followed in the wake of the 1845 U.S. annexation of Texas. . . ” and CoVe generated a verification question When did Texas secede from Mexico? which was answered with 1836 then an inconsistency should be detected by this step. ", "page_idx": 3 }, { "type": "text", "text": "", "page_idx": 4 }, { "type": "text", "text": "3.4 FINAL VERIFIED RESPONSE ", "text_level": 1, "page_idx": 4 }, { "type": "text", "text": "Finally, the improved response that takes verification into account is generated. This is executed by a final few-shot prompt where the context takes into account all of the previous reasoning steps, the baseline response and verification question answer pairs, so that the corrections can take place. If the Factor+Revise approach is used from subsection 3.3 then the output of the cross-check inconsistency detection is provided as well. ", "page_idx": 4 }, { "type": "text", "text": "4 EXPERIMENTS ", "text_level": 1, "page_idx": 4 }, { "type": "text", "text": "We use various experimental benchmarks to measure the efficacy of CoVe in reducing hallucination, comparing against a number of baselines. ", "page_idx": 4 }, { "type": "text", "text": "4.1 TASKS ", "text_level": 1, "page_idx": 4 }, { "type": "text", "text": "The benchmarks we use range from list-based questions where the required answer is a set of entities, to where the answer is a longform generation of multiple freeform sentences. ", "page_idx": 4 }, { "type": "text", "text": "4.1.1 WIKIDATA ", "text_level": 1, "page_idx": 4 }, { "type": "text", "text": "We start by testing CoVe on a set of automatically generated questions using the Wikidata $\\mathsf { A P I } ^ { 1 }$ . We create list questions of the form: “Who are some [Profession]s who were born in [City]?”. For example, “Who are some politicians who were born in Boston?”. The answer to these questions is a set of entities, where the gold list is obtained from the Wikidata knowledge base. This results in a dataset of 56 test questions, each typically containing ${ \\sim } 6 0 0$ known gold entities, but typically an LLM will produce a much shorter list. We then use the precision metric (micro-averaged) to measure performance, in addition to reporting the averaged number of positive and negative entities produced. ", "page_idx": 4 }, { "type": "text", "text": "4.1.2 WIKI-CATEGORY LIST ", "text_level": 1, "page_idx": 4 }, { "type": "text", "text": "We then proceed to a harder set-generation task. We use the QUEST (Malaviya et al., 2023) dataset that was created using Wikipedia Category lists. We convert these category names to questions by simply prepending a “Name some”. Owing to the varied questions such as Name some Mexican animated horror films or Name some Endemic orchids of Vietnam we believe this task can pose a greater challenge. We collate all examples in the dataset that do not require logical operations to create a set of 55 test questions each having 8 answers. Similar to the Wikidata task, we measure ˜ precision (micro-averaged) to measure performance, in addition to reporting the averaged number of positive and negative entities produced. ", "page_idx": 4 }, { "type": "text", "text": "4.1.3 MULTISPANQA ", "text_level": 1, "page_idx": 4 }, { "type": "text", "text": "We next test our approach on an reading comprehension benchmark, MultiSpanQA (Li et al., 2022). MultiSpanQA comprises of questions that have multiple independent answers (derived from a series of multiple discontiguous spans in the text, with questions originally from the Natural Questions dataset). We consider a closed-book setting, where we do not provide supporting documents, and hence consider a subset of questions which are factoid-based, so that our base LLM is more likely to be able to answer them. We thus use a test set of 418 questions with shorter answers per span (up to 3 tokens per item). For example, Q: Who invented the first printing press and in what year?, A: Johannes Gutenberg, 1450. ", "page_idx": 4 }, { "type": "table", "img_path": "images/a2ec61b6cb20568209957c9ee841e0852634fb138381546fd4be17509cc01c08.jpg", "table_caption": [ "Table 1: Test Precision and average number of positive and negative (hallucination) entities for list-based questions on the Wikidata and Wiki-Category list tasks. " ], "table_footnote": [], "table_body": "<table><tr><td></td><td colspan=\"2\">Wikidata (Easier)</td><td></td><td colspan=\"4\">Wiki-Category list (Harder)</td></tr><tr><td>LLM</td><td>Method</td><td>Prec. (↑)</td><td>Pos.</td><td>Neg.</td><td>Prec.(↑)</td><td>Pos.</td><td>Neg.</td></tr><tr><td>Llama 2 70B Chat</td><td>Zero-shot</td><td>0.12</td><td>0.55</td><td>3.93</td><td>0.05</td><td>0.35</td><td>6.85</td></tr><tr><td>Llama 2 70B Chat</td><td>CoT</td><td>0.08</td><td>0.75</td><td>8.92</td><td>0.03</td><td>0.30</td><td>11.1</td></tr><tr><td>Llama 65B</td><td>Few-shot</td><td>0.17</td><td>0.59</td><td>2.95</td><td>0.12</td><td>0.55</td><td>4.05</td></tr><tr><td>Llama 65B</td><td>CoVe (joint)</td><td>0.29</td><td>0.41</td><td>0.98</td><td>0.15</td><td>0.30</td><td>1.69</td></tr><tr><td>Llama 65B</td><td>CoVe (two-step)</td><td>0.36</td><td>0.38</td><td>0.68</td><td>0.21</td><td>0.50</td><td>0.52</td></tr><tr><td>Llama 65B</td><td>CoVe (factored)</td><td>0.32</td><td>0.38</td><td>0.79</td><td>0.22</td><td>0.52</td><td>1.52</td></tr></table>", "page_idx": 5 }, { "type": "text", "text": "4.1.4 LONGFORM GENERATION OF BIOGRAPHIES ", "text_level": 1, "page_idx": 5 }, { "type": "text", "text": "We next validate the performance of CoVe on longform text generation. In this setting, we evaluate our method on generating biographies, adopting the benchmark proposed in by Min et al. (2023). Here the model is simply prompted to generate a biography of a selected entity using the prompt: “Tell me a bio of <entity>”. We evaluate the efficacy of our approach using the FACTSCORE metric (Min et al., 2023) developed in that work, which uses a retrieval-augmented language model to fact-check the response (Instruct-Llama, “Llama $^ +$ Retrieval $+ \\mathrm { N P ^ { , } }$ ), which they showed correlates well with human judgments. ", "page_idx": 5 }, { "type": "text", "text": "4.2 BASELINES", "text_level": 1, "page_idx": 5 }, { "type": "text", "text": "We use Llama 65B, a strong open model as our base LLM (Touvron et al., 2023a), and use greedy decoding for all models. As Llama 65B is not instruction fine-tuned, we employ few-shot examples particular to each task for measuring performance on each of our benchmarks. This serves as our main baseline which CoVe tries to improve upon. CoVe uses the same Llama 65B base, but includes, for the same few-shot examples, demonstrations of verification questions and final verified responses, following Figure 1 and section 3. Thus, we measure the ability to improve over the original baseline response for the same LLM. For CoVe, we compare different variants, particularly the joint and factored versions on all tasks. ", "page_idx": 5 }, { "type": "text", "text": "We also compare to Llama instruction fine-tuned models, for which we use Llama 2 (Touvron et al., 2023b). We measure both zero-shot performance on the task, or zero-shot with chain-of-thought by adding “Let’s think step by step” to the zero-shot prompt. We find that the instruction fine-tuned models tend to generate extraneous content when queried. This can especially be a problem for the list-based tasks. To deal with this we add an extra line to our prompt: “List only the answers separated by a comma”. We also add another layer of post-processing to extract the answers by using an off-the-shelf NER model to further avoid this issue as this helped. However, we still expect few-shot to improve over this, especially for tasks like Multi-Span-QA where the answers are not all named entities, and the few-shot examples effectively show the domain of the task. ", "page_idx": 5 }, { "type": "text", "text": "For the longform generation of biographies we also compare to several existing model results reported in Min et al. (2023), in particular InstructGPT (Ouyang et al., 2022), ChatGPT 2 and PerplexityAI 3. ", "page_idx": 5 }, { "type": "text", "text": "4.3 RESULTS ", "text_level": 1, "page_idx": 5 }, { "type": "text", "text": "We are interested in empirically answering the following research questions: ", "page_idx": 5 }, { "type": "text", "text": "RQ1 Can COVE effectively reduce the rate of hallucinatory content produced by the LLM? RQ2 Can COVE be used to fix or remove incorrect generations without decreasing the amount of correct content? ", "page_idx": 5 }, { "type": "table", "img_path": "images/c71f45bc27d7cbb0c4c9c85d8bb79727c0478a49222f498771c21338a0442adb.jpg", "table_caption": [ "Table 2: Closed book MultiSpanQA test performance, comparing CoVe with various baselines. " ], "table_footnote": [], "table_body": "<table><tr><td>LLM</td><td>Method</td><td>F1(1)</td><td>Prec.</td><td>Rec.</td></tr><tr><td>Llama 2 70B Chat</td><td>Zero-shot</td><td>0.20</td><td>0.13</td><td>0.40</td></tr><tr><td>Llama 2 70B Chat</td><td>CoT</td><td>0.17</td><td>0.11</td><td>0.37</td></tr><tr><td>Llama 65B</td><td>Few-shot</td><td>0.39</td><td>0.40</td><td>0.38</td></tr><tr><td>Llama 65B</td><td>CoVe (joint)</td><td>0.46</td><td>0.50</td><td>0.42</td></tr><tr><td>Llama 65B</td><td>CoVe (factored)</td><td>0.48</td><td>0.50</td><td>0.46</td></tr></table>", "page_idx": 6 }, { "type": "table", "img_path": "images/1502ab975c354313e5a95ec265dd59c4d0e37ee5df2d6fb1a7b5b326edb0cfac.jpg", "table_caption": [ "Table 3: Longform generation of biographies with metrics defined from Min et al. (2023). Models marked with $^ *$ are reported from previous work. FACTSCORE automatically computed using “InstructLlama” ( Retrieve $ \\mathrm { L M } + \\mathrm { N P }$ ), the best open-access model. " ], "table_footnote": [], "table_body": "<table><tr><td>LLM</td><td>Method</td><td>FACTSCORE. (↑)</td><td>Avg. # facts</td></tr><tr><td>InstructGPT*</td><td>Zero-shot</td><td>41.1</td><td>26.3</td></tr><tr><td>ChatGPT*</td><td>Zero-shot</td><td>58.7</td><td>34.7</td></tr><tr><td>PerplexityAI*</td><td>Retrieval-based</td><td>61.6</td><td>40.8</td></tr><tr><td>Llama 2 70B Chat</td><td>Zero-shot</td><td>41.3</td><td>64.9</td></tr><tr><td>Llama 2 70B Chat</td><td>CoT</td><td>41.1</td><td>49.0</td></tr><tr><td>Llama 65B</td><td>Few-shot</td><td>55.9</td><td>16.6</td></tr><tr><td>Llama 65B</td><td>CoVe (joint)</td><td>60.8</td><td>12.8</td></tr><tr><td>Llama 65B</td><td>CoVe (factored)</td><td>63.7</td><td>11.7</td></tr><tr><td>Llama 65B</td><td>CoVe (factor+revise)</td><td>71.4</td><td>12.3</td></tr><tr><td>GPT-3</td><td>Few-shot</td><td>45.3</td><td>15.6</td></tr><tr><td>GPT-3 + ChatGPT</td><td>ChatProtect Muindler et al. (2023)</td><td>48.5</td><td>14.6</td></tr><tr><td>GPT-3 + InstructGPT</td><td>SCG-LL Manakul et al. (2023)</td><td>60.6</td><td>6.0</td></tr><tr><td>GPT-3+DeBERTA</td><td>SCG-NLI Manakul et al. (2023)</td><td>61.7</td><td>6.3</td></tr><tr><td>GPT-3 + InstructGPT</td><td>CoVe (factor+revise)</td><td>68.6</td><td>9.0</td></tr></table>", "page_idx": 6 }, { "type": "image", "img_path": "images/2a6ac1cda2f821ac1aa01184f19b3fcaf962289ecad5c965bc0573e103f15b60.jpg", "image_caption": [ "Figure 2: FACTSCORE performance distribution across head, torso and tail facts for CoVe variants and various baselines on longform generation of biographies. " ], "image_footnote": [], "page_idx": 6 }, { "type": "text", "text": "Our main results across the four benchmark tasks are given in Table 1, Table 2 and Table 3, and our main findings are as follows. ", "page_idx": 6 }, { "type": "text", "text": "CoVe improves precision on list-based answer tasks We find that CoVe provides large gains in precision on the list-based tasks, e.g. more than doubles the precision from the Llama 65B few-shot baseline for the Wikidata task (from 0.17 to 0.36). We find from the positive and negative breakdown that there is a large reduction in the number of hallucinated answers (negatives: $2 . 9 5 0 . 6 8 )$ while only a relatively small reduction in the number of non-hallucinations (positives: $0 . 5 9 0 . 3 8$ ). ", "page_idx": 6 }, { "type": "text", "text": "CoVe improves performance on closed book QA We also find that CoVe brings improvements in general QA problems, as measured on MultiSpanQA. We observe a $23 \\%$ improvement in F1 over the few-shot baseline $( 0 . 3 9 0 . 4 8 )$ ), where the improvements come from gains in both precision and recall. ", "page_idx": 7 }, { "type": "text", "text": "CoVe improves precision on longform generation These results also extend to longform generation, where we actually see larger gains than in the QA setting. FACTSCORE increases $28 \\%$ $5 5 . 9 $ 71.4) from the few-shot baseline, with again only a relatively small reduction in average number of facts provided $1 6 . 6 1 2 . 3$ ). We also show the breakdown of improvements across facts in Figure 2, where one can see CoVe improves results for both rare and more frequent facts. ", "page_idx": 7 }, { "type": "text", "text": "Instruction-tuning and CoT do not reduce hallucinations We find that the few-shot baseline that employs a pre-trained Llama model outperforms Llama-2-Chat, an instruction tuned model, across all the tasks. The few-shot examples lead the model to give outputs in line with those expected for the task, whereas general instruction tuning produces more hallucinations or incorrect outputs. Zero-shot chain-of-thought (CoT) prompting also fails to improve the results for these tasks. ", "page_idx": 7 }, { "type": "text", "text": "Factored and 2-step CoVe improve performance We observe a consistent performance improvement across all tasks from applying the factored CoVe approach compared to joint CoVe. For example improvement from $6 0 . 8 6 3 . 7$ in FACTSCORE in longform generation. Similarly, the 2-step approach also outperforms the joint approach, as tested on the Wikidata and Wiki-Category list tasks, with 2-step giving the best results for Wikidata, and factored the best for Wiki-Category. All these results support our hypothesis that verifying questions should not attend to the original baseline response as they may be prone to repeating it (as the joint method can do). ", "page_idx": 7 }, { "type": "text", "text": "Further explicit reasoning helps remove hallucinations In the longform generation task we also explore more sophisticated reasoning steps in the CoVe “factor+revise” method, which explicitly cross-checks whether verification answers indicate an inconsistency. We see large gains in the FACTSCORE metric from this further explicit reasoning from 63.7 (factored) $ 7 1 . 4$ (factor+revise). This gives further indication that appropriate and explicit reasoning in LLMs can bring improvements in mitigating hallucinations. ", "page_idx": 7 }, { "type": "text", "text": "CoVe-based Llama outperforms InstructGPT, ChatGPT and PerplexityAI On the longform generation task, our baseline few-shot Llama 65B is outperformed by the ChatGPT and PerplexityAI models in terms of the FACTSCORE metric. However, applying CoVe to Llama 65B lifts its performance above ChatGPT and InstructGPT, as well as PerplexityAI. This is particularly impressive compared to PerplexityAI considering that is a model that can support its facts with retrieval-augmentation, whereas CoVe uses only the base language model itself with improved reasoning via deliberation (verification). However, Figure 2 shows PerplexityAI still outperforms CoVe for very rare facts where retrieval is essential, but CoVe outperforms PerplexityAI for frequent facts. ", "page_idx": 7 }, { "type": "text", "text": "CoVe outperforms existing hallucination mitigation baselines We compare CoVe to three recently released longform hallucination mitigation approaches — NLI and LLM, the two bestperforming variants of SelfCheckGPT (Manakul et al., 2023) and ChatProtect Mundler et al. (2023). ¨ Our results in Table 3 show that COVE outperforms all these baselines. More details on our implementations of the baselines can be found in section 9. For SelfCheckGPT we experiment with different thresholds (in Table 6) and choose a threshold that results in a high FACTSCORE without removing a lot of facts. We note that some models produce fewer overall facts than others, however, the FACTSCORE metric is normalized and hence comparable across models. We verified this experimentally by clipping Llama-2-70B chat’s output to present fewer facts (as it contains the largest number in its output out of all models), but this did not change its FACTSCORE substantially, e.g. clipping to 10 sentences increased its score from $4 1 . 3 4 2 . 7$ . We note the length of the generations of the few-shot-based models is essentially governed by the few-shot examples, which in turn are constrained by the context length. ", "page_idx": 7 }, { "type": "text", "text": "Shortform verification questions are more accurately answered than longform queries In a longform response, LLMs are prone to generate a number of hallucinations. However, it can often be the case that the LLM itself would know these hallucinations are wrong if queried specifically for that individual fact, independent of the rest of the longform generation, see Figure 1, Figure 3, and section 12. This can be seen quantitatively on the Wikidata task, where only ${ \\sim } 1 7 \\%$ of the Llama few-shot baseline answer entities are correct in list-based questions. However, when querying each individual entity via a verification question, we find ${ \\sim } 7 0 \\%$ are correctly answered. ", "page_idx": 7 }, { "type": "text", "text": "", "page_idx": 8 }, { "type": "text", "text": "Open LLM-based verification questions outperform yes/no-based and rule-based verification questions In our method, CoVe, the verification questions generated by the LLM expect answers that are true facts. Another alternative type of verification questions would be templated verification questions, which can be generated cheaply, and binary questions. We first compare to heuristically constructed questions by replacing the LLM questions with templated yes/no questions of the form “Does $X$ answer the question” for list-based questions with elements $X$ in the answer. Results on the Wiki-Category task, given in Table 4, show a reduced precision with rule-based verification questions. We then move on to binary questions where we include the fact as part of the verification question and ask it in a yes/no answer format. We evaluate this difference in Table 4, and find that yes/no type questions perform worse for the factored version of CoVe. Some anecdotal examples are included in Appendix section 12 for ChatGPT where we find the model tends to agree with facts in a yes/no question format whether they are right or wrong. We believe this difference would be larger for longform generation where the types of required verification questions can be more diverse, and LLM-based verification becomes even more necesary. ", "page_idx": 8 }, { "type": "text", "text": "Inference overhead Approaches that detect hallucinations via inconsistencies require repeated prompts to the LLM. COVE essentially requires 1 LLM call for generating the baseline response, 1 LLM call for each sentence to plan the verifications, 1 LLM call to verify each fact and 1 LLM call for each fact to generate the consistent response. We also note that the LLM calls for verification for each fact can be parallelized. This is comparable and in certain cases fewer LLM calls compared to other approaches for hallucination mitigation. We provide a more in-depth analysis in section 8. ", "page_idx": 8 }, { "type": "text", "text": "5 CONCLUSION ", "text_level": 1, "page_idx": 8 }, { "type": "text", "text": "We introduced Chain-of-Verification $\\mathrm { ( C o V e ) }$ , an approach to reduce hallucinations in a large language model by deliberating on its own responses and self-correcting them. In particular, we showed that models are able to answer verification questions with higher accuracy than when answering the original query by breaking down the verification into a set of simpler questions. Secondly, when answering the set of verification questions, we showed that controlling the attention of the model so that it cannot attend to its previous answers (factored CoVe) helps alleviate copying the same hallucinations. Overall, our method provides substantial performance gains over the original language model response just by asking the same model to deliberate on (verify) its answer. An obvious extension to our work is to equip CoVe with tool-use, e.g., to use retrieval augmentation in the verification execution step which would likely bring further gains. ", "page_idx": 8 }, { "type": "text", "text": "6 LIMITATIONS ", "text_level": 1, "page_idx": 8 }, { "type": "text", "text": "While our Chain-of-Verification (CoVe) method seeks to reduce hallucinations, it does not remove them completely from generations. This means that CoVe can still generate incorrect or misleading information for a given query, even if it improves over the baseline. We also note that in our experiments we have only addressed hallucinations in the form of directly stated factual inaccuracies. However, hallucinations could come in other forms, such as during incorrect reasoning steps, as part of opinions, etc. We also note that the generations CoVe produces come with verifications which, if viewed by the user, add more interpretability to its decisions, but come at the cost of increased computational expense due to generating more tokens in the output, similar to other reasoning methods such as Chain-of-Thought. ", "page_idx": 8 }, { "type": "text", "text": "Our method seeks to make a large language model produce improved responses by spending more time deliberating to identify its own mistakes. While we have shown this gives clear improvements, the upper bound to the improvement is clearly limited by the overall capabilities of the model, e.g. in identifying and knowing what it knows. In this regard, an orthogonal line of research, as discussed in section 2 is the use of external tools by language models, to gain further information beyond what is stored in its weights. While we do not explore that avenue in this work those techniques would likely be fruitful to combine with the findings here. ", "page_idx": 8 }, { "type": "text", "text": "REFERENCES ", "text_level": 1, "page_idx": 9 }, { "type": "text", "text": "Leonard Adolphs, Kurt Shuster, Jack Urbanek, Arthur Szlam, and Jason Weston. Reason first, then respond: Modular generation for knowledge-infused dialogue. arXiv preprint arXiv:2111.05204, 2021. \nAyush Agrawal, Lester Mackey, and Adam Tauman Kalai. Do language models know when they’re hallucinating references? arXiv preprint arXiv:2305.18248, 2023. \nI Chern, Steffi Chern, Shiqi Chen, Weizhe Yuan, Kehua Feng, Chunting Zhou, Junxian He, Graham Neubig, Pengfei Liu, et al. Factool: Factuality detection in generative ai–a tool augmented framework for multi-task and multi-domain scenarios. arXiv preprint arXiv:2307.13528, 2023a. \nI-Chun Chern, Zhiruo Wang, Sanjan Das, Bhavuk Sharma, Pengfei Liu, Graham Neubig, et al. Improving factuality of abstractive summarization via contrastive reward learning. arXiv preprint arXiv:2307.04507, 2023b. \nRoi Cohen, May Hamri, Mor Geva, and Amir Globerson. Lm vs lm: Detecting factual errors via cross examination. arXiv preprint arXiv:2305.13281, 2023. \nBoris A Galitsky. Truth-o-meter: Collaborating with llm in fighting its hallucinations. 2023. \nLuyu Gao, Zhuyun Dai, Panupong Pasupat, Anthony Chen, Arun Tejasvi Chaganty, Yicheng Fan, Vincent Zhao, Ni Lao, Hongrae Lee, Da-Cheng Juan, et al. Rarr: Researching and revising what language models say, using language models. In Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pp. 16477–16508, 2023. \nAri Holtzman, Jan Buys, Li Du, Maxwell Forbes, and Yejin Choi. The curious case of neural text degeneration. arXiv preprint arXiv:1904.09751, 2019. \nZiwei Ji, Nayeon Lee, Rita Frieske, Tiezheng Yu, Dan Su, Yan Xu, Etsuko Ishii, Ye Jin Bang, Andrea Madotto, and Pascale Fung. Survey of hallucination in natural language generation. ACM Computing Surveys, 55(12):1–38, 2023. \nWeisen Jiang, Han Shi, Longhui Yu, Zhengying Liu, Yu Zhang, Zhenguo Li, and James T Kwok. Backward reasoning in large language models for verification. arXiv preprint arXiv:2308.07758, 2023a. \nZhengbao Jiang, Frank F Xu, Luyu Gao, Zhiqing Sun, Qian Liu, Jane Dwivedi-Yu, Yiming Yang, Jamie Callan, and Graham Neubig. Active retrieval augmented generation. arXiv preprint arXiv:2305.06983, 2023b. \nSaurav Kadavath, Tom Conerly, Amanda Askell, Tom Henighan, Dawn Drain, Ethan Perez, Nicholas Schiefer, Zac Hatfield-Dodds, Nova DasSarma, Eli Tran-Johnson, et al. Language models (mostly) know what they know. arXiv preprint arXiv:2207.05221, 2022. \nJack Lanchantin, Shubham Toshniwal, Jason Weston, Arthur Szlam, and Sainbayar Sukhbaatar. Learning to reason and memorize with self-notes. arXiv preprint arXiv:2305.00833, 2023. \nHaonan Li, Martin Tomko, Maria Vasardani, and Timothy Baldwin. Multispanqa: A dataset for multi-span question answering. In Proceedings of the 2022 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, pp. 1250–1260, 2022. \nKenneth Li, Oam Patel, Fernanda Viegas, Hanspeter Pfister, and Martin Wattenberg. Inference-time ´ intervention: Eliciting truthful answers from a language model. arXiv preprint arXiv:2306.03341, 2023. \nZhan Ling, Yunhao Fang, Xuanlin Li, Zhiao Huang, Mingu Lee, Roland Memisevic, and Hao Su. Deductive verification of chain-of-thought reasoning. arXiv preprint arXiv:2306.03872, 2023. \nAman Madaan, Niket Tandon, Prakhar Gupta, Skyler Hallinan, Luyu Gao, Sarah Wiegreffe, Uri Alon, Nouha Dziri, Shrimai Prabhumoye, Yiming Yang, et al. Self-refine: Iterative refinement with self-feedback. arXiv preprint arXiv:2303.17651, 2023. \nChaitanya Malaviya, Peter Shaw, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. Quest: A retrieval dataset of entity-seeking queries with implicit set operations. arXiv preprint arXiv:2305.11694, 2023. \nPotsawee Manakul, Adian Liusie, and Mark JF Gales. Selfcheckgpt: Zero-resource black-box hallucination detection for generative large language models. arXiv preprint arXiv:2303.08896, 2023. \nJoshua Maynez, Shashi Narayan, Bernd Bohnet, and Ryan McDonald. On faithfulness and factuality in abstractive summarization. arXiv preprint arXiv:2005.00661, 2020. \nJacob Menick, Maja Trebacz, Vladimir Mikulik, John Aslanides, Francis Song, Martin Chadwick, Mia Glaese, Susannah Young, Lucy Campbell-Gillingham, Geoffrey Irving, et al. Teaching language models to support answers with verified quotes. arXiv preprint arXiv:2203.11147, 2022. \nNing Miao, Yee Whye Teh, and Tom Rainforth. Selfcheck: Using llms to zero-shot check their own step-by-step reasoning. arXiv preprint arXiv:2308.00436, 2023. \nSabrina J Mielke, Arthur Szlam, Emily Dinan, and Y-Lan Boureau. Reducing conversational agents’ overconfidence through linguistic calibration. Transactions of the Association for Computational Linguistics, 10:857–872, 2022. \nSewon Min, Kalpesh Krishna, Xinxi Lyu, Mike Lewis, Wen-tau Yih, Pang Wei Koh, Mohit Iyyer, Luke Zettlemoyer, and Hannaneh Hajishirzi. Factscore: Fine-grained atomic evaluation of factual precision in long form text generation. arXiv preprint arXiv:2305.14251, 2023. \nNiels Mundler, Jingxuan He, Slobodan Jenko, and Martin Vechev. Self-contradictory hallucinations ¨ of large language models: Evaluation, detection and mitigation. arXiv preprint arXiv:2305.15852, 2023. \nShashi Narayan, Joshua Maynez, Reinald Kim Amplayo, Kuzman Ganchev, Annie Louis, Fantine Huot, Anders Sandholm, Dipanjan Das, and Mirella Lapata. Conditional generation with a question-answering blueprint. Transactions of the Association for Computational Linguistics, 11: 974–996, 2023. \nLong Ouyang, Jeffrey Wu, Xu Jiang, Diogo Almeida, Carroll Wainwright, Pamela Mishkin, Chong Zhang, Sandhini Agarwal, Katarina Slama, Alex Ray, et al. Training language models to follow instructions with human feedback. Advances in Neural Information Processing Systems, 35: 27730–27744, 2022. \nBaolin Peng, Michel Galley, Pengcheng He, Hao Cheng, Yujia Xie, Yu Hu, Qiuyuan Huang, Lars Liden, Zhou Yu, Weizhu Chen, et al. Check your facts and try again: Improving large language models with external knowledge and automated feedback. arXiv preprint arXiv:2302.12813, 2023. \nFabio Petroni, Tim Rocktaschel, Patrick Lewis, Anton Bakhtin, Yuxiang Wu, Alexander H Miller, ¨ and Sebastian Riedel. Language models as knowledge bases? arXiv preprint arXiv:1909.01066, 2019. \nOfir Press, Muru Zhang, Sewon Min, Ludwig Schmidt, Noah A Smith, and Mike Lewis. Measuring and narrowing the compositionality gap in language models. arXiv preprint arXiv:2210.03350, 2022. \nAlec Radford, Jeffrey Wu, Rewon Child, David Luan, Dario Amodei, Ilya Sutskever, et al. Language models are unsupervised multitask learners. OpenAI blog, 1(8):9, 2019. \nAnsh Radhakrishnan, Karina Nguyen, Anna Chen, Carol Chen, Carson Denison, Danny Hernandez, Esin Durmus, Evan Hubinger, Jackson Kernion, Kamile Luko ˙ siˇ ut¯ e, et al. Question decomposition ˙ improves the faithfulness of model-generated reasoning. arXiv preprint arXiv:2307.11768, 2023. \nHannah Rashkin, Vitaly Nikolaev, Matthew Lamm, Lora Aroyo, Michael Collins, Dipanjan Das, Slav Petrov, Gaurav Singh Tomar, Iulia Turc, and David Reitter. Measuring attribution in natural language generation models. Computational Linguistics, pp. 1–66, 2023. \nPaul Roit, Johan Ferret, Lior Shani, Roee Aharoni, Geoffrey Cideron, Robert Dadashi, Matthieu Geist, Sertan Girgin, Leonard Hussenot, Orgad Keller, et al. Factually consistent summarization ´ via reinforcement learning with textual entailment feedback. arXiv preprint arXiv:2306.00186, 2023. \nStephen Roller, Emily Dinan, Naman Goyal, Da Ju, Mary Williamson, Yinhan Liu, Jing Xu, Myle Ott, Kurt Shuster, Eric M Smith, et al. Recipes for building an open-domain chatbot. arXiv preprint arXiv:2004.13637, 2020. \nKurt Shuster, Spencer Poff, Moya Chen, Douwe Kiela, and Jason Weston. Retrieval augmentation reduces hallucination in conversation. arXiv preprint arXiv:2104.07567, 2021. \nKai Sun, Yifan Ethan Xu, Hanwen Zha, Yue Liu, and Xin Luna Dong. Head-to-tail: How knowledgeable are large language models (llm)? aka will llms replace knowledge graphs? arXiv preprint arXiv:2308.10168, 2023a. \nWeiwei Sun, Zhengliang Shi, Shen Gao, Pengjie Ren, Maarten de Rijke, and Zhaochun Ren. Contrastive learning reduces hallucination in conversations. In Proceedings of the AAAI Conference on Artificial Intelligence, volume 37, pp. 13618–13626, 2023b. \nHugo Touvron, Thibaut Lavril, Gautier Izacard, Xavier Martinet, Marie-Anne Lachaux, Timothee´ Lacroix, Baptiste Roziere, Naman Goyal, Eric Hambro, Faisal Azhar, et al. Llama: Open and \\` efficient foundation language models. arXiv preprint arXiv:2302.13971, 2023a. \nHugo Touvron, Louis Martin, Kevin Stone, Peter Albert, Amjad Almahairi, Yasmine Babaei, Nikolay Bashlykov, Soumya Batra, Prajjwal Bhargava, Shruti Bhosale, Dan Bikel, Lukas Blecher, Cristian Canton Ferrer, Moya Chen, Guillem Cucurull, David Esiobu, Jude Fernandes, Jeremy Fu, Wenyin Fu, Brian Fuller, Cynthia Gao, Vedanuj Goswami, Naman Goyal, Anthony Hartshorn, Saghar Hosseini, Rui Hou, Hakan Inan, Marcin Kardas, Viktor Kerkez, Madian Khabsa, Isabel Kloumann, Artem Korenev, Punit Singh Koura, Marie-Anne Lachaux, Thibaut Lavril, Jenya Lee, Diana Liskovich, Yinghai Lu, Yuning Mao, Xavier Martinet, Todor Mihaylov, Pushkar Mishra, Igor Molybog, Yixin Nie, Andrew Poulton, Jeremy Reizenstein, Rashi Rungta, Kalyan Saladi, Alan Schelten, Ruan Silva, Eric Michael Smith, Ranjan Subramanian, Xiaoqing Ellen Tan, Binh Tang, Ross Taylor, Adina Williams, Jian Xiang Kuan, Puxin Xu, Zheng Yan, Iliyan Zarov, Yuchen Zhang, Angela Fan, Melanie Kambadur, Sharan Narang, Aurelien Rodriguez, Robert Stojnic, Sergey Edunov, and Thomas Scialom. Llama 2: Open foundation and fine-tuned chat models, 2023b. ", "page_idx": 9 }, { "type": "text", "text": "", "page_idx": 10 }, { "type": "text", "text": "", "page_idx": 11 }, { "type": "text", "text": "Neeraj Varshney, Wenlin Yao, Hongming Zhang, Jianshu Chen, and Dong Yu. A stitch in time saves nine: Detecting and mitigating hallucinations of llms by validating low-confidence generation. arXiv preprint arXiv:2307.03987, 2023. ", "page_idx": 11 }, { "type": "text", "text": "Chaojun Wang and Rico Sennrich. On exposure bias, hallucination and domain shift in neural machine translation. arXiv preprint arXiv:2005.03642, 2020. ", "page_idx": 11 }, { "type": "text", "text": "Xuezhi Wang, Jason Wei, Dale Schuurmans, Quoc Le, Ed Chi, Sharan Narang, Aakanksha Chowdhery, and Denny Zhou. Self-consistency improves chain of thought reasoning in language models. arXiv preprint arXiv:2203.11171, 2022. ", "page_idx": 11 }, { "type": "text", "text": "Jason Wei, Xuezhi Wang, Dale Schuurmans, Maarten Bosma, Fei Xia, Ed Chi, Quoc V Le, Denny Zhou, et al. Chain-of-thought prompting elicits reasoning in large language models. Advances in Neural Information Processing Systems, 35:24824–24837, 2022. ", "page_idx": 11 }, { "type": "text", "text": "Yixuan Weng, Minjun Zhu, Shizhu He, Kang Liu, and Jun Zhao. Large language models are reasoners with self-verification. arXiv preprint arXiv:2212.09561, 2022. ", "page_idx": 11 }, { "type": "text", "text": "Zeqiu Wu, Yushi Hu, Weijia Shi, Nouha Dziri, Alane Suhr, Prithviraj Ammanabrolu, Noah A Smith, Mari Ostendorf, and Hannaneh Hajishirzi. Fine-grained human feedback gives better rewards for language model training. arXiv preprint arXiv:2306.01693, 2023. ", "page_idx": 11 }, { "type": "text", "text": "Hongbin Ye, Tong Liu, Aijia Zhang, Wei Hua, and Weiqiang Jia. Cognitive mirage: A review of hallucinations in large language models. arXiv preprint arXiv:2309.06794, 2023. ", "page_idx": 11 }, { "type": "text", "text": "Wenhao Yu, Zhihan Zhang, Zhenwen Liang, Meng Jiang, and Ashish Sabharwal. Improving language models via plug-and-play retrieval feedback. arXiv preprint arXiv:2305.14002, 2023. Muru Zhang, Ofir Press, William Merrill, Alisa Liu, and Noah A Smith. How language model hallucinations can snowball. arXiv preprint arXiv:2305.13534, 2023. Ruochen Zhao, Xingxuan Li, Shafiq Joty, Chengwei Qin, and Lidong Bing. Verify-and-edit: A knowledge-enhanced chain-of-thought framework. arXiv preprint arXiv:2305.03268, 2023. ", "page_idx": 12 }, { "type": "text", "text": "7 RULE-BASED VS BINARY VS GENERAL QUESTIONS ", "text_level": 1, "page_idx": 13 }, { "type": "table", "img_path": "images/1b404a4d4c4ba13aa87d99eb9854727bb962c60ec3af0d295032f76132ee1e78.jpg", "table_caption": [ "Table 4: Comparison of various COVE verification plan strategies (rows) and verification execution techniques (columns) on the WikiCategory task. " ], "table_footnote": [], "table_body": "<table><tr><td></td><td colspan=\"2\">Verification Execution</td></tr><tr><td></td><td>CoVe (joint)</td><td>CoVe (factored)</td></tr><tr><td>Verification Plan</td><td>Prec.</td><td>Prec.</td></tr><tr><td>Rule-based questions Generated by model:</td><td>0.13</td><td>0.16</td></tr><tr><td>yes/no questions</td><td>0.15</td><td>0.19</td></tr><tr><td>general questions</td><td>0.15</td><td>0.22</td></tr></table>", "page_idx": 13 }, { "type": "text", "text": "8 INFERENCE OVERHEAD ", "text_level": 1, "page_idx": 13 }, { "type": "text", "text": "$N : =$ Number of text samples, 4 in our experiments $k : =$ Number of repeated mitigations, 3 in our experiments $s : =$ Number of sentences in the generated passage $f : =$ Number of facts in the generated passage ", "page_idx": 13 }, { "type": "table", "img_path": "images/a80cba59d69d61bd4a6cc7ffc8a7467065d71dcfe4632e9bac4232b296d17317.jpg", "table_caption": [], "table_footnote": [], "table_body": "<table><tr><td>Method</td><td>#LLM prompts</td></tr><tr><td>Few-shot</td><td>1</td></tr><tr><td>ChatProtect Mundler et al. (2023)</td><td>1+s×k × (3)</td></tr><tr><td>SCG-LLM Manakul et al. (2023)</td><td>n+1+s×n</td></tr><tr><td>CoVe (factor+revise)</td><td>1+s+2×f</td></tr></table>", "page_idx": 13 }, { "type": "text", "text": "Table 5: Worst-case LLM prompts used by each hallucination mitigation approach in the worst case ", "page_idx": 13 }, { "type": "text", "text": "Based on the current implementations we find the COVE induces a similar inference overhead to other longform hallucination mitigation approaches. ", "page_idx": 13 }, { "type": "text", "text": "9 IMPLEMENTATION OF BASELINES ", "text_level": 1, "page_idx": 13 }, { "type": "text", "text": "We use the existing models provided by Manakul et al. (2023) for the NLI model. For the LLM model we prompt GPT-3.5-turbo-instruction with the following instruction (as described in Manakul et al. (2023). ", "page_idx": 13 }, { "type": "text", "text": "Context: {} \nSentence: {} \nIs the sentence supported by the context above? \nAnswer Yes or No: ", "page_idx": 13 }, { "type": "table", "img_path": "images/cd42f37186065d23769aea7a2509293b9796b99ecfa654da425731f8332fa6b1.jpg", "table_caption": [ "Table 6: Different threshold results for SelfCheckGPT " ], "table_footnote": [], "table_body": "<table><tr><td colspan=\"3\">NLI</td><td colspan=\"2\">LLM</td></tr><tr><td>Threshold</td><td>FS</td><td>Facts</td><td>FS</td><td>Facts</td></tr><tr><td>High</td><td>76.5</td><td>3.0</td><td>61.7</td><td>6.3</td></tr><tr><td>Med</td><td>60.6</td><td>6.0</td><td>56.8</td><td>8.4</td></tr><tr><td>Low</td><td>53.0</td><td>8.0</td><td>53.0</td><td>10</td></tr></table>", "page_idx": 14 }, { "type": "text", "text": "10 COVE - FURTHER DETAILS ", "text_level": 1, "page_idx": 14 }, { "type": "text", "text": "Query ", "page_idx": 14 }, { "type": "text", "text": "What was the primary cause of the Mexican-American war? ", "page_idx": 14 }, { "type": "text", "text": "1. Baseline Response ", "page_idx": 14 }, { "type": "text", "text": "The Mexican–American War was an armed conflict between the United States and Mexico from 1846 to 1848. It followed in the wake of the 1845 U.S. annexation of Texas, which Mexico considered part of its territory in spite of its de facto secession in the 1835 Texas Revolution. ", "page_idx": 14 }, { "type": "image", "img_path": "images/94709e778b23d5c18849470472ac402c7e9407a4ccadc313485b8a453c3cd60c.jpg", "image_caption": [], "image_footnote": [], "page_idx": 14 }, { "type": "text", "text": "4. Final Verified Response ", "text_level": 1, "page_idx": 14 }, { "type": "text", "text": "The Mexican–American War was an armed conflict between the United States and Mexico from 1846 to 1848. It followed in the wake of the 1845 U.S. annexation of Texas. ", "page_idx": 14 }, { "type": "text", "text": "Figure 3: For longform generation, the Chain-of-Verification (CoVe) Factor $^ +$ Revise method is the most effective in our longform generation experiments. CoVe Factor $^ +$ Revise has the model independently identify (cross-check) which facts are consistent with its executed verifications (indicated by tickmark and crosses in the figure). With this extra step we aim to disregard the inconsistent facts and use the consistent facts to regenerate the response. ", "page_idx": 14 }, { "type": "text", "text": "11 PROMPT TEMPLATES ", "text_level": 1, "page_idx": 15 }, { "type": "text", "text": "We provide prompt templates for the longform generation of biographies task below for the different steps and variants of CoVe (see section 3). Templates for the other tasks are similar, but using few-shot examples from those tasks instead. ", "page_idx": 15 }, { "type": "text", "text": "11.1 GENERATE BASELINE RESPONSE", "text_level": 1, "page_idx": 15 }, { "type": "image", "img_path": "images/0fe7b3d2b41a0144a2c0181c7d4152dcb93519e51be0121a5a244181b0cf9570.jpg", "image_caption": [], "image_footnote": [], "page_idx": 15 }, { "type": "text", "text": "Table 7: Few-shot prompting with 3 few-shot examples for the longform generation of biographies task. Other tasks use the same standard few-shot setup as well (with 3 examples from that particular task). ", "page_idx": 15 }, { "type": "text", "text": "11.2 PLAN VERIFICATIONS ", "text_level": 1, "page_idx": 15 }, { "type": "image", "img_path": "images/13a898dcb1cd0226f5f767f829a20fca5547e701fb0d28e03510b5bc7cd8b2df.jpg", "image_caption": [], "image_footnote": [], "page_idx": 15 }, { "type": "text", "text": "Table 8: Step (2) of CoVe involves planning the verification questions. In the biography task case we split the longform generation into its individual passages (e.g. sentences in the biography case, this was done due to excessive context length, which we don’t need to do for the other tasks). The model then generates a verification question for each fact it observes in each passage (a passage may have multiple facts). ", "page_idx": 15 }, { "type": "text", "text": "11.3 EXECUTE VERIFICATIONS ", "text_level": 1, "page_idx": 16 }, { "type": "table", "img_path": "images/c24433d94aab360c77c0965746a6cfff8479e46f076233877555ed30ceacb696.jpg", "table_caption": [], "table_footnote": [], "table_body": "<table><tr><td>A:Answer</td><td>Q:Verification Question</td></tr><tr><td>A:Answer</td><td>Q:Verification Question</td></tr><tr><td></td><td>Q:Verification Question</td></tr><tr><td>A:Answer</td><td></td></tr><tr><td>A:</td><td>Q:Verification Question</td></tr></table>", "page_idx": 16 }, { "type": "text", "text": "Table 9: In step (3) of CoVe, the model then generates an answer for each of the verification questions. \nAgain we use 3 few-shot examples. ", "page_idx": 16 }, { "type": "image", "img_path": "images/ace96e9e92daafa958b6f1a880fbf19309271761f99ac9dec0e094b0dd11f67c.jpg", "image_caption": [], "image_footnote": [], "page_idx": 16 }, { "type": "text", "text": "Table 10: In step (4) of CoVe (factored) the model is then presented with its original generation (split into passages, e.g. sentences, in the biography case, due to excessive context length which we do not need to do for the other tasks) along with its own verification step results. The model is told that this information comes from “another source”. The model is required to synthesize a new final answer based on facts that are consistent between the two sources. ", "page_idx": 16 }, { "type": "text", "text": "11.5 FACTOR $^ +$ REVISE: IDENTIFY WHICH FACTS ARE CONSISTENT ", "page_idx": 17 }, { "type": "text", "text": "Context: <Original Fact>. \nFrom another source, \n<output of execute verification step: ${ \\mathsf { \\Omega } } + { \\mathsf { \\Omega } } { \\mathsf { A } } { \\mathsf { \\Sigma } } ^ { } $ \nResponse: CONSISTENT. <Consistent fact> \nContext: <Original Fact>. \nFrom another source, \n<output of execute verification step: ${ \\mathsf { \\Omega } } + { \\mathsf { \\Omega } } { \\mathsf { A } } { \\mathsf { \\Sigma } } ^ { } $ \nResponse: INCONSISTENT. \nContext: <Original Fact>. \nFrom another source, \n<output of execute verification step: ${ \\mathsf { \\Omega } } + { \\mathsf { \\Omega } } { \\mathsf { A } } { \\mathsf { \\Sigma } } ^ { } $ \nResponse: PARTIALLY CONSISTENT. <Consistent part> ", "page_idx": 17 }, { "type": "text", "text": "Table 11: In the CoVe (Factor $^ +$ Revise) variant, as part of step (3) after subsection 11.3, the model is made to explicitly identify which facts are consistent between the two sources. The consistent facts can then be spliced together. ", "page_idx": 17 }, { "type": "text", "text": "12 CHATGPT EXAMPLE SCREENSHOTS ", "text_level": 1, "page_idx": 18 }, { "type": "image", "img_path": "images/a0ac0be4610c73ae36b0490ec9f086a325d33f878a872c442c779f33d65a5874.jpg", "image_caption": [ "Figure 4: ChatGPT generates several hallucinations for this question, e.g. Hillary Clinton and Michael Bloomberg. " ], "image_footnote": [], "page_idx": 18 }, { "type": "image", "img_path": "images/81ab370438350ed63c748edfeb9c58714679c87057809dcd84e149b5cfee97a4.jpg", "image_caption": [ "Figure 5: Even when the longform answer is provided for a rewritten query (see query from Figure 4), while giving a slightly different answer, ChatGPT still generates several hallucinations for this question, e.g. Hillary Clinton and Michael Bloomberg. " ], "image_footnote": [], "page_idx": 18 }, { "type": "image", "img_path": "images/9f8d2dbbfaa853e00d3fc3adfa55c24c1c0502c17e543fa748123cd0e8a97b90.jpg", "image_caption": [ "Figure 6: Shortform questions (which could be verification questions) appear to be answered more factually than the longform answers in Figure 4 and Figure 5. " ], "image_footnote": [], "page_idx": 19 }, { "type": "image", "img_path": "images/7f1208d6d3f6c8164bbd03eeea1030b9a2275742dd85a5054d7115d1fa54cfbc.jpg", "image_caption": [ "Figure 7: Another example of hallucinations for a different query, e.g., John F. Kennedy Jr was born in Washington D.C. " ], "image_footnote": [], "page_idx": 19 }, { "type": "image", "img_path": "images/ef441d4c071149f8a7e5c6aae7dad6cac0beb4d516e8512712a32b3a3366428b.jpg", "image_caption": [ "Figure 8: Examples where questions asking for a fact are answered correctly, but verifying via a yes/no question is incorrect (the model tends to agree with the way the question is stated, even if it was stated incorrectly). " ], "image_footnote": [], "page_idx": 20 }]123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241# FINE-TUNING LANGUAGE MODELS FOR FACTUALITY
Katherine Tian\*†, Eric Mitchell\*†, Huaxiu Yao†§, Christopher D. Manning†, Chelsea Finn† †Stanford University §UNC Chapel Hill {kattian,eric.mitchell}@cs.stanford.edu
# ABSTRACT
The fluency and creativity of large pre-trained language models (LLMs) have led to their widespread use, sometimes even as a replacement for traditional search engines. Yet language models are prone to making convincing but factually inaccurate claims, often referred to as ‘hallucinations.’ These errors can inadvertently spread misinformation or harmfully perpetuate misconceptions. Further, manual fact-checking of model responses is a time-consuming process, making human factuality labels expensive to acquire. In this work, we fine-tune language models to be more factual, without human labeling and targeting more open-ended generation settings than past work. We leverage two key recent innovations in NLP to do so. First, several recent works have proposed methods for judging the factuality of open-ended text by measuring consistency with an external knowledge base or simply a large model’s confidence scores. Second, the Direct Preference Optimization algorithm enables straightforward finetuning of language models on objectives other than supervised imitation, using a preference ranking over possible model responses. We show that learning from automatically generated factuality preference rankings, generated either through existing retrieval systems or our novel retrieval-free approach, significantly improves the factuality (percent of generated claims that are correct) of Llama-2 on held-out topics compared with RLHF or decoding strategies targeted at factuality. At 7B scale, compared to Llama-2-Chat, we observe $53 \%$ and $50 \%$ reduction in factual error rate when generating biographies and answering medical questions, respectively. A reference implementation can be found at https://github.com/kttian/llm_factuality_tuning.
# 1 INTRODUCTION
Recent developments in training large language models (LLMs), particularly methods that learn from rankings over responses such as reinforcement learning from human feedback (RLHF) (Christiano et al., 2017; Ziegler et al., 2020; Ouyang et al., 2022), have enabled the development of powerful, engaging dialogue agents. State-of-the-art LLMs are pre-trained on a vast amount of knowledge in large datasets (Touvron et al., 2023a;b) and further fine-tuned to apply this knowledge to follow diverse instructions or complete more specific tasks (Chung et al., 2022; Chen et al., 2021). However, despite these large language models’ exposure to diverse datasets, they are prone to confidently generating incorrect claims. One recent study shows that GPT-3.5 (ChatGPT) produces false citations more often than not when asked to provide the authors of a given study (Agrawal et al., 2023). Nonetheless, other research has demonstrated that in simple question-answering settings, large language models do exhibit systematic markers of uncertainty that indicate their factually unreliable statements (Kadavath et al., 2022; Tian et al., 2023). These results suggest that language models internally represent the limits of their knowledge, leading us to ask: Can language models be fine-tuned to leverage this internal awareness, to avoid making untrue statements in the first place?
A key source of difficulty in training factual models comes in specifying an objective that adequately captures factuality. As an example, maximum likelihood, the most common objective for pre-training language models, does not always encourage factual predictions. Consider the question “Where was Yo-Yo Ma born?” A model that continues by near-deterministically producing the text “idk, probably Paris?” is nearly always correct, but receives extremely high loss if the pre-training data contains any other response to the question. On the other hand, a model that hedges probability mass over many possible phrasings and many possible locations (including incorrect ones, like Antarctica) will likely receive much lower loss, as any response observed in the training data will be assigned at least some non-trivial probability. Because the pre-training objective may reward ‘smearing’ probability mass over many possible responses, language models may generate incorrect statements if they underfit the training data or if asked questions that require knowledge not contained in the pre-training data.
 Figure 1: Our approach aims to improve the factuality of language models, specifically focusing on longform generation (e.g. writing a biography). We develop two different approaches for estimating factuality of a passage (center), each of which allows us to generate a preference dataset (right). We then fine-tune the language model to optimize these factuality preferences (far right).
In principle, reinforcement learning-based objectives can avoid the failures of existing pre-training objectives through the appropriate choice of a reward function that penalizes factually incorrect statements. However, accurately computing such a reward function can be expensive. Obtaining human labels of factuality is time-consuming and costly; Min et al. (2023) report that professional fact-checkers took approximately 9 minutes to fact-check a single model-generated biography of a well-known individual; it cost about $\$ 2,000$ to annotate 505 biographies.
In light of these challenges, we leverage recent advances in estimating truthfulness without human intervention: a) reference-based automated fact-checking methods that evaluate the extent to which an external knowledge base supports the claims in a piece of text (Min et al., 2023; Chern et al., 2023) and b) reference-free truthfulness evaluations that use a model’s own confidence as a proxy for truthfulness, inspired by Kuhn et al. (2023). Using these truthfulness measures and a dataset of unlabeled prompts (e.g., “Write a biography of Yo-Yo Ma.”), we sample pairs of completions from a pre-trained model and annotate them with a preference label denoting which has a lower rate of factual errors. Using the recently proposed Direct Preference Optimization (Rafailov et al., 2023) algorithm, we can stably and efficiently learn from such data. Ultimately, this pipeline enables us to fine-tune off-the-shelf language models to produce factual errors less often (with or without a reference knowledge base). See Figure 1 for an overview of our factuality tuning pipeline.
Our primary contribution is a straightforward approach to optimizing language models for factuality in long-form text generation without human annotation. We validate this approach on two benchmark datasets for evaluating factuality, targeted at generating biographies of popular figures and answering open-ended questions about medical conditions. We find that fine-tuning for factuality outperforms conventional RLHF and produces complementary benefits to LLM decoding strategies that aim to increase factuality. Further, we find qualitative differences in the result of learning from preference pairs scored with reference-based and reference-free truthfulness estimation. Overall, we find that learning factuality from automatically constructed preference pairs is a cost-effective way to increase model factuality without human intervention, reducing the error count for claims generated by Llama models by around $50 \%$ or more for biographies and over $2 5 \%$ for medical questions.
# 2 PRELIMINARIES
Our approach to fine-tuning directly for improved factuality uses the framework of reinforcement learning from preferences over candidate actions or responses. In this section, we provide an overview of reinforcement learning in the context of language models, as well as the specific algorithm we use for preference-based RL, direct preference optimization (Rafailov et al., 2023).
Fine-tuning language models with reinforcement learning. Reinforcement learning (RL) has proven to be an effective approach to fine-tuning language models to extract complex, useful behaviors from their pre-trained weights. In the context of RL, a language model policy $\pi _ { \theta }$ (typically an autoregressive Transformer) produces a conditional distribution $\pi _ { \theta } ( y \mid x )$ over responses $y$ given an input query $x$ (both $x$ and $y$ are text sequences). The goal of reinforcement learning is to maximize the average reward of outputs generated by the policy, where a reward function $\bar { r } ( x , y )$ assigns a scalar score to an input-output pair that determines its desirability. However, past works have observed that fine-tuning language models with an objective of unconstrained reward maximization can lead to overoptimization (Gao et al., 2022), that is, a policy that achieves high reward through exploitation of the idiosyncrasies of the reward function that are not aligned with the intended behavior. The most commonly-used objective in practice therefore combines reward maximization with a KL-divergence penalty between the language model and its initialization:
$$\mathop { \operatorname* { m a x } } _ { \pi _ { \theta } } \mathbb { E } _ { x \sim \mathcal { D } _ { p } , y \sim \pi _ { \theta } ( y | x ) } \left[ r ( x , y ) - \beta \log \frac { \pi _ { \theta } ( y \mid x ) } { \pi _ { \mathrm { r e f } } ( y \mid x ) } \right]$$
where $\mathcal { D } _ { p }$ is some dataset of prompts, $\pi _ { \mathrm { r e f } }$ is the reference model, usually the result of performing some supervised fine-tuning on a pre-trained model using demonstration data, and $\beta$ is a coefficient that controls the trade-off between reward and divergence (Ouyang et al., 2022; Bai et al., 2022; Stiennon et al., 2020). Optimizing this objective aligns the model with the reward function without deviating too far from the pre-trained reference model, reducing overoptimization. In practice, the most common algorithm used to optimize this objective for language models is proximal policy optimization (PPO; Schulman et al. (2017)), although some variants exist (Ramamurthy et al., 2022; Lu et al., 2022). However, these algorithms are quite complex to implement and tune (Zheng et al., 2023) and require online sampling during training, substantially increasing training time.
RL from preferences with direct preference optimization (DPO). Most large language models fine-tuned with Eq. 1 optimize a reward function that is learned from a dataset of preference rankings over possible model outputs. The DPO algorithm simplifies $\mathrm { R L }$ on language models for this special case (Rafailov et al., 2023), using a dataset of preference pairs $\mathcal { D } = \{ x ^ { ( i ) } , y _ { w } ^ { ( i ) } , y _ { l } ^ { ( i ) } \} _ { i = 1 } ^ { N }$ of prompts $x$ and candidate responses $y _ { w }$ and $y _ { l }$ (typically sampled from $\pi _ { \mathrm { r e f } } )$ , where $y _ { w }$ is preferred over $y _ { l }$ (denoted $y _ { w } \succ y _ { l } ,$ . The probability of observing a particular preference pair is assumed to follow a Bradley-Terry model (Bradley & Terry, 1952):
$$p ( y _ { w } \succ y _ { l } ) = \sigma ( r ( x , y _ { w } ) - r ( x , y _ { l } ) )$$
where $\sigma$ is the sigmoid function and $r ( x , y )$ is an unobserved reward or scoring function. Rafailov et al. (2023) show that the optimal policy $\pi ^ { * }$ for the problem in Eq. 1 can be found by optimizing a simple classification loss computed directly on the preference data:
$$\begin{array} { r } { \mathcal { L } _ { \mathrm { D P O } } ( \pi _ { \theta } ; \pi _ { \mathrm { r e f } } ) = - \mathbb { E } _ { ( x , y _ { w } , y _ { l } ) \sim \mathcal { D } } \left[ \log \sigma \left( \beta \log \frac { \pi _ { \theta } ( y _ { w } \mid x ) } { \pi _ { \mathrm { r e f } } ( y _ { w } \mid x ) } - \beta \log \frac { \pi _ { \theta } ( y _ { l } \mid x ) } { \pi _ { \mathrm { r e f } } ( y _ { l } \mid x ) } \right) \right] } \end{array}$$
DPO enables learning $\pi _ { \theta }$ from a fixed dataset of preferences, without fitting an explicit reward function or sampling from the policy in the loop of training. These advantages make DPO an attractive choice for fine-tuning language models for objectives other than imitation. However, a challenge remains in constructing preference pairs that encourage greater factuality.
# 3 CONSTRUCTING PREFERENCES ENCOURAGING FACTUALITY INLONG-FORM TEXT
While existing preference learning algorithms like DPO enable efficient, stable learning from objectives other than maximum likelihood, they require data in the form of preferences over possible responses to a prompt. In this section, we propose two classes of approaches to generating such preferences without human labeling effort. One class leverages existing methods to determine consistency with external reference texts as a measure of truthfulness; we propose another, which leverages calibrated model probabilities themselves as a proxy for truthfulness. For both approaches, we are computing an estimated truthfulness score over the claims in each generated response; the response with higher average truthfulness is taken as the preferred response. See Figure 2 for an overview of both procedures for truthfulness scoring. Note that truthfulness scoring is needed only at training time; at test time, we can sample from the model in the normal manner.
# 3.1 REFERENCE-BASED TRUTHFULNESS ESTIMATION
An intuitive approach to estimating truthfulness is by estimating the consistency of a given piece of text with a reliable reference text or knowledge base. Several recent works have introduced such evaluation criteria; for example, FactScore (Min et al., 2023) uses Wikipedia as reference knowledge, and FacTool (Chern et al., 2023) uses Google Search Results. These measures show high agreement with human judgments of factuality, making them attractive sources of truth for preference data construction. Due to the relatively consistent and high quality of Wikipedia articles, we elect to use FactScore as a representative method of reference-based truthfulness scoring.
 Figure 2: We estimate the factuality of a generation by first extracting claims (left) and then evaluating each claims’ truthfulness (right). For the latter, we consider: a reference-based (top right) method that uses a finetuned Llama model to check if the fact is supported by Wikipedia (Min et al., 2023) and a reference-free (bottom right) method that uses the model’s confidence in its most likely answer to estimate its truthfulness.
To evaluate a piece of text, FactScore first extracts a list of the atomic claims present in the text using GPT-3.5.1 For each atomic claim, a smaller, more efficient model such as a Llama-1-7b model (Touvron et al., 2023a) that has been fine-tuned for fact-checking is then used to perform natural language inference (MacCartney & Manning, 2008) to determine if a claim is supported by the reference text. The passage’s truthfulness score is the fraction of the extracted atomic claims that are estimated to be supported by the reference text.
We note that reference-based truthfulness has the key limitation that it requires access to relevant, high-quality reference texts against which to measure consistency. Such a requirement may limit applicability to domains where ground truth documents are not known and accurate retrieval is difficult, such as in niche domains or less-structured tasks. Further, reference-based truthfulness estimation requires a reliable model to determine if an atomic claim is supported by the article. In light of these limitations, we propose a reference-free approach to estimating truthfulness of open-ended text, which avoids the need for retrieving external knowledge and checking consistency.
# 3.2 REFERENCE-FREE CONFIDENCE-BASED TRUTHFULNESS ESTIMATION
To eliminate the need for external knowledge, we leverage the fact that large language models are well-calibrated (Kadavath et al., 2022; Tian et al., 2023). That is, if a large language model assigns a fixed confidence $p$ to each claim in a set of claims, the fraction of these claims that is correct is $p$ . In other words, in expectation over many claims, a perfectly-calibrated model’s confidence in a claim corresponds to the probability it is correct. To use this notion of calibration, we interpret a model generation (e.g., a biography of Yo-Yo Ma) as a collection of claims, each resulting from a query to the model’s knowledge (e.g., “When was Yo-Yo Ma born?” or “How many siblings does Yo-Yo Ma have?”). Our goal is to encourage the model to produce responses containing queries to its knowledge likely to lead to correct claims. Therefore, we parse a complete model generation into its constituent queries to the model’s knowledge. For each query to the model’s knowledge present in the generation, we can estimate the likelihood it will lead to a correct claim by simply estimating the average confidence of the model’s answer to this query. If a model assigns probability 0.7 to ‘1955’ and probability 0.3 to ‘1953’ for the query “When was Yo-Yo Ma born?”, then the probability this query will lead to a correct claim (again, in expectation over queries) is $0 . 7 ^ { 2 } + 0 . { \dot { 3 } } ^ { 2 } = 0 . 5 { \dot { 8 } }$ . The model used for computing confidence scores essentially takes the place of the reference text datastore. We evaluate this Expected Confidence approach as well as a Max Confidence approach, which simply takes the max over the answer confidences for a given query (i.e., we assume the model produces answers greedily rather than sampling).
 Figure 3: Factuality tuning using FactScore truthfulness scoring (FactTune-FS) produces by far the greatest improvement in factuality for the biography generation and medical question-answering problems. Factuality tuning with expected model confidence truthfulness scoring provides the next strongest performance, on average. For MedicalQA, only factuality tuning provides a strict improvement in factuality (more correct statements and fewer incorrect statements) compared to the SFT model.
More concretely, we first extract atomic claims from the text using GPT-3.5. We then use GPT-3.5 to convert each claim to a query (question) testing knowledge of the particular fact. Careful rephrasing is necessary to ensure that the rephrased question is unambiguous; for example, the claim “Yo-Yo Ma plays the cello” should be converted to the question “What instrument does Yo-Yo Ma play?” rather than just “What does Yo-Yo Ma play?” as the latter question admits answers of the wrong type. If we were to use the second prompt, a model might assign $50 \%$ of its probability on “cello” and $50 \%$ of its probability on “basketball.” However, the model’s low confidence is caused by the ambiguity of the question, not low confidence in the instrument that Yo-Yo Ma plays. We detail the prompts used for question generation in Appendix A.2.
After each claim is converted to a minimally ambiguous question, we resample an answer 20 times from the base model (e.g. Llama-1-7b) that is fine-tuned to estimate the model’s uncertainty over the answer. We use a few-shot prompt to encourage well-formed answers. We bin these answers by equivalence, using either heuristic string matching of the responses or using GPT-3.5 to assess if the answers are semantically equivalent, inspired by Kuhn et al. (2023). Our heuristic string match checks whether the words in the answer, excluding stop words, are the same. We compare these choices in Section 4.4. The score for each claim is either the expected or maximum confidence of the model’s response; we finally average this score over all claims in a given model generation.
# 3.3 FACTUALITY TUNING: PUTTING IT ALL TOGETHER
Given a choice of truthfulness estimator, we can now construct a preference dataset for factuality tuning a given language model from a set of unlabeled prompts. First, we sample $n$ multiple candidate responses for each prompt from the model with simple temperature sampling with temperature 1.0 (using few-shot prompting for models that have not been fine-tuned). For each response, we then compute the truthfulness score with the chosen estimator (reference-based or reference-free). Finally, for all $\binom { n } { 2 }$ pairs of responses to each prompt, we simply choose the response with the higher truthfulness score as the preferred response. For a set of $m$ prompts, we ultimately generate $m { \binom { n } { 2 } } - k$ preference pairs, where $k$ is the number of pairs with equal scores. Finally, we fine-tune the model using the DPO pipeline, using all model responses as targets for the SFT stage.
# 4 EXPERIMENTS
Our experiments evaluate the extent to which factuality can be learned through preference-based reinforcement learning, using the fully automated preference-generation pipeline described in Section
Table 1: Dataset statistics and examples. In biographies, entities are individuals; in MedicalQA, entities are medical conditions. We include 6 questions for each entity in MedicalQA and adjust the number of responses per prompt to keep the total number of pairs in the two datasets roughly similar.
<table><tr><td>Dataset</td><td>Entities [train, val, test]</td><td>Prompts per Entity</td><td>Responses per Prompt</td><td>Example prompt</td></tr><tr><td>Biographies</td><td>463[288,50,125]</td><td>16</td><td>10</td><td>Write me a paragraph biography of Mary Wolstonecraft.</td></tr><tr><td>Medical QA</td><td>295[150,45,100]</td><td></td><td>6</td><td>What are the common symptoms of a stroke?</td></tr></table>
3. We call the model fine-tuned with our reference-based metric FactTune-FS and the model finetuned with our model confidence-based score, which is completely reference-free, FactTune-MC. For all of our experiments, samples for model confidence are taken from Llama-1-7b.
Datasets. We conduct our experiments on two tasks: generating biographies and medical questionanswering. For biographies, we generated a dataset consisting of 463 diverse well-known individuals (288 train, 50 val, 125 test) with 10 short-paragraph biographies each. For medical question answering, we used a dataset of 295 diverse common medical conditions (150 train, 45 val, 100 test) with 6 questions about each condition and 6 short-paragraph answers per question. The test set just uses 1 question per condition. The prompts were generated with GPT-3.5, and the answers were sampled from Llama-1-7b using a few-shot prompt for each dataset. We found that our procedure consistently resulted in well-formed and informative responses, albeit with possible factual errors. Because FactScore uses retrieval against a given Wikipedia article, we generate data based on individuals and medical conditions that have Wikipedia pages. See Table 1 for the summary stats and examples from our datasets.
Baselines. We compare factuality tuning with inference-time intervention (Li et al., 2023, ITI) and decoding by contrasting layers (Chuang et al., 2023, DOLA), applied to the SFT model for each task. For ITI, we supervise the training of the linear probes with FactScore labels: we take batches of atomic facts extracted from the training samples and bias the models’ activations from the incorrect to correct atomic facts to determine the direction of the intervention. In the case of Llama-2, we also compare against ‘standard’ RLHF with human preference labels (Touvron et al., 2023b).
Evaluation. To evaluate each generated response, we follow the FactScore procedure to extract the number of correct and incorrect facts. Then, to check that the model responses are still relevant and helpful after actuality fine-tuning, we also use GPT-3.5 to determine whether each fact is relevant to the question or not (using the prompt in Appendix A.2). For biographies, we observed that essentially $100 \%$ of facts were relevant to the individual, so we skip the relevance computation to save costs. For each dataset, we report the number of correct and relevant facts (# Correct), the number of inaccuracies (# Incorrect), and the proportion of correct relevant facts out of the total number of extracted facts ( $\%$ Correct). Note that the total number of facts may vary between generations. We validate our evaluation metrics in Sec. A.1.
# 4.1 FINE-TUNING FOR FACTUALITY ACROSS DOMAINS
In this section, we apply our methodology for learning factuality to Llama-1-7b and Llama-2-7b in multiple domains. We show the results in Table 2. Learning from reference-based factualityscored pairs (FactTune-FS) consistently improves factual accuracy compared to RLHF models and decoding-based factuality baselines by at least $11 \%$ on biographies and $13 \%$ on medical questionanswering. FactTune-FS reduces the number of factual errors and maintains no more than a slight decrease, if not increase, in the amount of correct information generated. Factuality tuning from model-confidence scores (FactTune-MC, FactTune-EC) also reduces error rate and improves the factuality of RLHF models on both datasets, without any external reference information.
# 4.2 FINE-TUNING CHAT MODELS FOR FACTUALITY
Most widely used practical chatbots today are LMs trained with RLHF to follow diverse instructions in a way that is helpful to users. In this section, we investigate the ability of our human-free factuality tuning method to improve the factuality of RLHF chat models. Using Llama-2-7b-Chat, we find that fine-tuning an RLHF LM with both factuality and semantic entropy-based rewards can further improve its factuality without significantly decreasing the total number of facts, as shown in Table 3.
Table 2: Factuality tuning from reference-based factuality-scored pairs (FactTune-FS) improves factual accuracy compared to RLHF models and decoding-based factuality baselines, consistently reducing the number of errors and often increasing the number of correct facts generated. Factuality tuning from model confidence scored pairs (FactTune-MC, FactTune-EC) also outperforms RLHF models, providing a strong reference-free alternative for improving factuality and reducing error.
<table><tr><td></td><td></td><td colspan="3">Biographies</td><td colspan="3">Medical QA</td></tr><tr><td>Base Model</td><td>Method</td><td># Correct</td><td># Incorrect</td><td>% Correct</td><td># Correct</td><td># Incorrect</td><td>% Correct</td></tr><tr><td rowspan="6">Llama-1</td><td>ITI</td><td>13.68</td><td>5.24</td><td>0.730</td><td>10.25</td><td>7.96</td><td>0.538</td></tr><tr><td>DOLA</td><td>12.44</td><td>4.74</td><td>0.737</td><td>9.22</td><td>5.58</td><td>0.640</td></tr><tr><td>SFT</td><td>13.54</td><td>6.54</td><td>0.696</td><td>9.96</td><td>6.86</td><td>0.600</td></tr><tr><td>FactTune-FS (Ours)</td><td>14.51</td><td>3.74</td><td>0.812</td><td>12.60</td><td>4.18</td><td>0.746</td></tr><tr><td>FactTune-MC (Ours)</td><td>9.74</td><td>2.42</td><td>0.819</td><td>11.51</td><td>5.56</td><td>0.668</td></tr><tr><td>FactTune-EC (Ours)</td><td>10.84</td><td>3.28</td><td>0.790</td><td>11.52</td><td>6.56</td><td>0.641</td></tr><tr><td rowspan="7">Llama-2</td><td>ITI</td><td>13.30</td><td>5.56</td><td>0.712</td><td>9.40</td><td>4.25</td><td>0.690</td></tr><tr><td>DOLA</td><td>13.25</td><td>6.50</td><td>0.684</td><td>9.87</td><td>6.06</td><td>0.627</td></tr><tr><td>Chat</td><td>21.41</td><td>6.30</td><td>0.774</td><td>9.61</td><td>6.69</td><td>0.619</td></tr><tr><td>SFT</td><td>13.47</td><td>6.49</td><td>0.687</td><td>10.68</td><td>6.22</td><td>0.627</td></tr><tr><td>FactTune-FS (Ours)</td><td>19.32</td><td>2.76</td><td>0.880</td><td>13.29</td><td>2.97</td><td>0.809</td></tr><tr><td>FactTune-MC (Ours)</td><td>11.74</td><td>3.51</td><td>0.783</td><td>12.94</td><td>5.26</td><td>0.706</td></tr><tr><td>FactTune-EC (Ours)</td><td>12.68</td><td>3.69</td><td>0.797</td><td>12.80</td><td>5.19</td><td>0.710</td></tr></table>
<table><tr><td></td><td></td><td colspan="3">Biographies</td><td colspan="3">Medical QA</td></tr><tr><td>Base Model</td><td>Method</td><td># Correct</td><td># Incorrect</td><td>% Correct</td><td># Correct</td><td># Incorrect</td><td>% Correct</td></tr><tr><td></td><td></td><td>21.41</td><td>6.30</td><td>0.774</td><td>9.61</td><td>6.69</td><td>0.619</td></tr><tr><td></td><td>DOLA</td><td>22.25</td><td>5.81</td><td>0.793</td><td>11.45</td><td>6.74</td><td>0.624</td></tr><tr><td>Llama-2-Chat</td><td>FactTune-FS (Ours)</td><td>20.02</td><td>4.38</td><td>0.821</td><td>11.94</td><td>6.21</td><td>0.667</td></tr><tr><td></td><td>FactTune-MC (Ours)</td><td>19.12</td><td>4.97</td><td>0.795</td><td>12.61</td><td>7.21</td><td>0.627</td></tr><tr><td></td><td>FactTune-EC (Ours)</td><td>18.77</td><td>5.13</td><td>0.784</td><td>11.51</td><td>6.40</td><td>0.639</td></tr><tr><td></td><td>OOD FactTune-FS (ours)</td><td>21.06</td><td>5.45</td><td>0.796</td><td>11.56</td><td>6.66</td><td>0.635</td></tr></table>
Table 3: Factuality tuning a dialogue model (Llama-2-Chat) with FactScore, model confidence-based truthfulness estimation, and FactScore-based preferences from a different dataset (FactTune-FS, FactTune-MC, OOD FactTune-FS) further improves its factual accuracy more than a baseline method for factuality, DOLA.
# In other words, factuality tuning can be composed with RLHF to further improve the factuality of chat models.
While our quantitative metrics demonstrate a clear increase in factual accuracy, we also investigate how factuality fine-tuning impacts other aspects of model performance and generalizes. Using GPT4 as a judge, we find that FactTune-MC and FactTune-EC can improve both factuality and fluency compared to the SFT model (examples in Appendix Table 8). GPT-4 chooses FactTuneEC as more fluent than SFT on $80 \%$ of samples, FactTune-MC on $7 5 \%$ of samples, ITI on $57 \%$ of samples, FactTune-FS on $33 \%$ of samples, and DOLA on $16 \%$ of samples $\scriptstyle ( \mathrm { n = 1 0 0 }$ ).
Lastly, we find that fine-tuning for factuality generalizes across datasets. Fine-tuning Llama-2- 7b-Chat on biographies to evaluate on MedicalQA and vice versa (OOD FactTune-FS) improves the factuality more than RLHF (Table 3).
4.3 COMPLEMENTARY BENEFITS OF FACTUALITY TUNING AND DECODING-TIME FACTUALITY INTERVENTIONS
Besides fine-tuning for factuality, multiple existing works aim to improve LLM factuality through inference time interventions to either the decoding process or the model parameters themselves. We explore the possibility of applying both of these types of methods together, i.e., using factualityboosting decoding methods on a model fine-tuned with our factuality tuning procedure. In Table 4 we present the results of stacking both approaches. We find that in most cases, DOLA can even further increase the accuracy of factuality fine-tuned models, with one exception for Llama-2 on the biography task. While not a comprehensive evaluation of combining methods for improving factuality, this result suggests that different approaches to enhancing factuality may operate through complementary mechanisms.
Table 4: DOLA factuality decoding frequently composes with factuality fine-tuning, providing an increase in average correctness for the majority of combinations of model and dataset.
<table><tr><td></td><td></td><td colspan="3">Biographies</td><td colspan="3">Medical QA</td></tr><tr><td>Base Model</td><td>Method</td><td>#Correct</td><td>#Incorrect</td><td>%Correct</td><td>#Correct</td><td>#Incorrect</td><td>%Correct</td></tr><tr><td rowspan="2">Llama-1</td><td></td><td></td><td>3.74</td><td></td><td>12.0</td><td>418</td><td>0.746</td></tr><tr><td>FactTune-FS + DOLA</td><td>1451</td><td></td><td>0.812</td><td></td><td></td><td></td></tr><tr><td rowspan="2">Llama-2</td><td></td><td>19.32</td><td>2.76</td><td>0.880</td><td>13.29</td><td></td><td></td></tr><tr><td>FactTune-FS + DOLA</td><td></td><td></td><td></td><td></td><td>2.7</td><td>0.89</td></tr></table>
<table><tr><td></td><td></td><td></td><td colspan="3">Biographies</td><td colspan="3">Medical QA</td></tr><tr><td>Fact Ext.</td><td>Equiv</td><td>Metric</td><td>#Correct</td><td>#Incorrect</td><td>%Correct</td><td>#Correct</td><td>#Incorrect</td><td>%Correct</td></tr><tr><td rowspan="2">Atomic</td><td rowspan="2">Heuristic</td><td>Max Con Conf</td><td>9.74</td><td>22</td><td></td><td></td><td>5.56</td><td>0.668</td></tr><tr><td></td><td></td><td></td><td>0.819</td><td>11.51</td><td></td><td></td></tr><tr><td rowspan="2">Entity</td><td rowspan="2">Heuristic</td><td></td><td>12.2</td><td></td><td>0.74</td><td>10.3</td><td></td><td></td></tr><tr><td>Mx Co Conf</td><td></td><td>4.74</td><td></td><td></td><td>64</td><td>0.603</td></tr></table>
Table 5: On Llama-1, model confidence-based preference construction with atomic question extraction outperforms the version with entity extraction.
# 4.4 IMPACT OF DESIGN DECISIONS OF OPEN-ENDED MODEL CONFIDENCE SCORING
This section discusses the impacts of different design choices for the steps of our reference-free truthfulness score construction for factuality tuning: how to perform fact extraction and what confidence metric to use.
The first step is to extract the individual facts from the long-form response and re-sample each fact from the base model to assess the model’s confidence in the fact. For the fact-extraction and resampling procedure, one approach (Atomic) is to convert each extracted atomic fact into a corresponding ‘atomic question’ with a few-shot prompt query to GPT-3.5, then sample answers to each question from the base LLM. Another approach (Entity) extracts entities from the response via nltk and re-samples the extracted entity in-line. Atomic question extraction has the potential to be more comprehensive and precise, while named entity extraction is a less expensive proxy that doesn’t use closed models. In Table 5, we observe that atomic question extraction outperforms named entity extraction, although the difference in accuracy is smaller on Medical QA than on Biographies.
After re-sampling the fact, we study the choice of confidence metric between taking the model’s confidence based on the most common sample (Max Conf) or the confidence of the fact from the original response (Expected Conf). To compute Max Conf for both atomic and entity extraction, we bin the samples into equivalence classes of distinct responses using a string matching heuristic described in Section 3.2 and take the proportion of samples in the largest bin. For computing Expected Confidence, we first perform the same answer binning procedure as for Max Confidence, resulting in $k$ bins and confidences $p _ { 1 } , \ldots , p _ { k }$ , and take $\textstyle E C = \sum _ { i = 1 } ^ { k } p _ { i } ^ { 2 }$ . The results in Table 5 show that the performance of Max Conf versus Expected Conf varies but are quite similar.
# 5 RELATED WORK
Many works have identified reducing factual errors (sometimes called ‘hallucinations’) as a key challenge for building more reliable language models (Lewis et al., 2020; Kadavath et al., 2022; Zhang et al., 2023), even for the most powerful language models (Bubeck et al., 2023). Other use of the term ‘hallucination’ refers to summarization or translation system outputs not supported by the reference text (Maynez et al., 2020; Zhang et al., 2020) even if they are factual (Cao et al., 2022). Other work uses ‘hallucination’ to describe vision-language models producing outputs not grounded in a visual input, e.g., a captioning system describing an object that doesn’t exist in the image (Rohrbach et al., 2018). In our case, we focus on statements that are factually incorrect (or, inconsistent with a set of ‘authoritative’ texts, such as Wikipedia).
Several works describe methods for detecting likely factual errors through sensitivity to perturbations in the prompt (Xu et al., 2023), high diversity of responses under resampling (Kadavath et al., 2022; Mundler et al. ¨ , 2023; Kuhn et al., 2023; Manakul et al., 2023), or inconsistency with external knowledge sources (Min et al., 2023; Chern et al., 2023), or properties of internal activations (Azaria & Mitchell, 2023). Others go beyond detecting errors, correcting them after they have been generated (Peng et al., 2023; Gao et al., 2023; Dhuliawala et al., 2023). These approaches typically rely on retrieving relevant data from a trusted knowledge base and use another LLM to verify consistency; however, retrieval-based methods face key challenges, namely reliable resolution of conflicts between parametric and retrieved knowledge (Longpre et al., 2022; Chen et al., 2022) as well as maintaining improvements in factuality as model size increases (Mallen et al., 2023). Further, retrieval-based methods add significant system complexity; the most common open-source consumer language models thus use purely parametric models (Touvron et al., 2023a). The FactScore variant of our approach uses retrieval only during training, avoiding inference time complexity. In principle, any existing criterion could be used to generate preferences (see ;¸ we aim to show that even choosing relatively simple criteria leads to substantial improvements in factuality.
Most similar to ours, some approaches attempt to prevent the generation of factual errors in the first place, using prompting strategies (Si et al., 2023) or perturbing the internal representations of the model (Chuang et al., 2023; Li et al., 2023). Unlike using a fixed heuristic for identifying an internal ‘factuality’ dimension, we optimize directly for the end goal of generating factual statements, which we find shows a greater improvement in factuality. Finally, while most past work has focused on short-form NLG tasks like short-form question-answering (Kadavath et al., 2022), we explore ways to measure model confidence over factual information in long-form, unstructured text and estimate truthfulness in a reference-free manner (i.e., don’t require any external knowledge base or annotations).
# 6 CONCLUSION
In this paper, we show a practical, effective strategy to improve a language model’s ability to generate factual content, specifically focusing on long-form generations. We develop and study two different approaches to estimating the truthfulness of long-form text and optimize for these criteria using preference-based learning. In addition to existing reference-based truthfulness estimators that leverage external knowledge to establish the truth of a particular statement, we introduce a novel reference-free procedure for estimating truthfulness that uses the language model’s own uncertainty as an indication of factuality. Our experiments show that fine-tuning a language model with either criterion reliably reduces the number of incorrect facts (i.e. hallucinations) that the model generates. Reference-free approaches like the one we introduced provide a scalable self-supervision strategy to improve factuality, eliminating the need for a reference corpus of ‘gold’ texts.
The experimental results suggest a number of avenues for future work. First, because of the limited research and thus the limited benchmarks on the factuality of long-form language model generations, we proposed two new tasks to benchmark our approach. These tasks are representative of but do not fully cover the range of scenarios where we would hope to improve factuality. Furthermore, our experiments provide evidence for improving the factuality of dialogue models that are already finetuned with RLHF, but still leave open the question of how best to combine typical RLHF rewards and approaches with factuality rankings. Similarly, exploring additional ways to combine factuality tuning with existing methods for improving factuality, such as in our factuality tuning $+ { \mathrm { ~ D O L A } }$ experiment, may be a fruitful direction for future research. Further, future work might explore alternative approaches to constructing factuality preferences, such as using self-correction (Pan et al., 2023). Finally, we explore only 7B models in this work. Scaling up our factuality tuning recipe to larger models (and larger preference datasets) may reduce hallucinations even further.
# ACKNOWLEDGEMENTS
EM gratefully acknowledges funding from a Knight-Hennessy graduate fellowship and a Stanford Accelerator for Generative AI and Education grant. CF and CDM are CIFAR Fellows.
Reproducibility Statement. We explain the steps of our fine-tuning method in Section 3. In Section 4.1, we provide details on the dataset (dataset statistics, how it was generated, and examples), as well as how the evaluation is completed and how we implemented the baselines. In the experiment subsections and captions, we provide additional implementation or reporting details. In the appendix, we provide the exact GPT-3.5 prompts used for the extraction steps of our reference-free scoring method. A codebase with instructions for factuality scoring, training, and evaluation can be found here: https://github.com/kttian/llm_factuality_tuning.
# REFERENCES
Ayush Agrawal, Mirac Suzgun, Lester Mackey, and Adam Tauman Kalai. Do language models know when they’re hallucinating references?, 2023. arXiv preprint arxiv:2305.18248. 1
Amos Azaria and Tom Mitchell. The internal state of an LLM knows when its lying, 2023. arXiv preprint arxiv:2304.13734. 9
Yuntao Bai, Andy Jones, Kamal Ndousse, Amanda Askell, Anna Chen, Nova DasSarma, Dawn Drain, Stanislav Fort, Deep Ganguli, Tom Henighan, Nicholas Joseph, Saurav Kadavath, Jackson Kernion, Tom Conerly, Sheer El-Showk, Nelson Elhage, Zac Hatfield-Dodds, Danny Hernandez, Tristan Hume, Scott Johnston, Shauna Kravec, Liane Lovitt, Neel Nanda, Catherine Olsson, Dario Amodei, Tom Brown, Jack Clark, Sam McCandlish, Chris Olah, Ben Mann, and Jared Kaplan. Training a helpful and harmless assistant with reinforcement learning from human feedback, 2022. arXiv preprint arxiv:2204.05862. 3
Ralph Allan Bradley and Milton E Terry. Rank analysis of incomplete block designs: I. the method of paired comparisons. Biometrika, 39(3/4):324–345, 1952. 3
Sebastien Bubeck, Varun Chandrasekaran, Ronen Eldan, Johannes Gehrke, Eric Horvitz, Ece ´ Kamar, Peter Lee, Yin Tat Lee, Yuanzhi Li, Scott Lundberg, Harsha Nori, Hamid Palangi, Marco Tulio Ribeiro, and Yi Zhang. Sparks of artificial general intelligence: Early experiments with GPT-4, 2023. arXiv preprint arxiv:2303.12712. 8
Meng Cao, Yue Dong, and Jackie Cheung. Hallucinated but factual! inspecting the factuality of hallucinations in abstractive summarization. In Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pp. 3340–3354, Dublin, Ireland, May 2022. Association for Computational Linguistics. doi: 10.18653/v1/2022.acl-long. 236. URL https://aclanthology.org/2022.acl-long.236. 8
Hung-Ting Chen, Michael Zhang, and Eunsol Choi. Rich knowledge sources bring complex knowledge conflicts: Recalibrating models to reflect conflicting evidence. In Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing, pp. 2292–2307, Abu Dhabi, United Arab Emirates, December 2022. Association for Computational Linguistics. doi: 10.18653/v1/2022.emnlp-main.146. URL https://aclanthology.org/2022. emnlp-main.146. 9
Mark Chen, Jerry Tworek, Heewoo Jun, Qiming Yuan, Henrique Ponde, Jared Kaplan, Harrison Edwards, Yura 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, David W. Cummings, Matthias Plappert, Fotios Chantzis, Elizabeth Barnes, Ariel Herbert-Voss, William H. Guss, Alex Nichol, Igor Babuschkin, S. Arun Balaji, Shantanu Jain, Andrew Carr, Jan Leike, Joshua Achiam, Vedant Misra, Evan Morikawa, Alec Radford, Matthew M. 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. ArXiv, abs/2107.03374, 2021. URL https://api.semanticscholar.org/CorpusID:235755472. 1
I-Chun Chern, Steffi Chern, Shiqi Chen, Weizhe Yuan, Kehua Feng, Chunting Zhou, Junxian He, Graham Neubig, and Pengfei Liu. FacTool: Factuality detection in generative ai – a tool augmented framework for multi-task and multi-domain scenarios, 2023. arXiv preprint arxiv:2307.13528. 2, 4, 9
Paul F Christiano, Jan Leike, Tom Brown, Miljan Martic, Shane Legg, and Dario Amodei. Deep reinforcement learning from human preferences. In I. Guyon, U. Von Luxburg, S. Bengio, H. Wallach, R. Fergus, S. Vishwanathan, and R. Garnett (eds.), Advances in Neural Information Processing Systems, volume 30. Curran Associates, Inc., 2017. URL https://proceedings.neurips.cc/paper_files/paper/2017/ file/d5e2c0adad503c91f91df240d0cd4e49-Paper.pdf. 1
Yung-Sung Chuang, Yujia Xie, Hongyin Luo, Yoon Kim, James Glass, and Pengcheng He. DoLa: Decoding by contrasting layers improves factuality in large language models, 2023. arXiv preprint arxiv:2309.03883. 6, 9
Hyung Won Chung, Le Hou, Shayne Longpre, Barret Zoph, Yi Tay, William Fedus, Yunxuan Li, Xuezhi Wang, Mostafa Dehghani, Siddhartha Brahma, Albert Webson, Shixiang Shane Gu, Zhuyun Dai, Mirac Suzgun, Xinyun Chen, Aakanksha Chowdhery, Alex Castro-Ros, Marie Pellat, Kevin Robinson, Dasha Valter, Sharan Narang, Gaurav Mishra, Adams Yu, Vincent Zhao, Yanping Huang, Andrew Dai, Hongkun Yu, Slav Petrov, Ed H. Chi, Jeff Dean, Jacob Devlin, Adam Roberts, Denny Zhou, Quoc V. Le, and Jason Wei. Scaling instruction-finetuned language models, 2022. 1 Shehzaad Dhuliawala, Mojtaba Komeili, Jing Xu, Roberta Raileanu, Xian Li, Asli Celikyilmaz, and Jason Weston. Chain-of-verification reduces hallucination in large language models, 2023. 9 Leo Gao, John Schulman, and Jacob Hilton. Scaling laws for reward model overoptimization, 2022. 3, 14 Luyu Gao, Zhuyun Dai, Panupong Pasupat, Anthony Chen, Arun Tejasvi Chaganty, Yicheng Fan, Vincent Y. Zhao, Ni Lao, Hongrae Lee, Da-Cheng Juan, and Kelvin Guu. Rarr: Researching and revising what language models say, using language models, 2023. 9 Saurav Kadavath, Tom Conerly, Amanda Askell, Tom Henighan, Dawn Drain, Ethan Perez, Nicholas Schiefer, Zac Hatfield-Dodds, Nova DasSarma, Eli Tran-Johnson, Scott Johnston, Sheer El-Showk, Andy Jones, Nelson Elhage, Tristan Hume, Anna Chen, Yuntao Bai, Sam Bowman, Stanislav Fort, Deep Ganguli, Danny Hernandez, Josh Jacobson, Jackson Kernion, Shauna Kravec, Liane Lovitt, Kamal Ndousse, Catherine Olsson, Sam Ringer, Dario Amodei, Tom Brown, Jack Clark, Nicholas Joseph, Ben Mann, Sam McCandlish, Chris Olah, and Jared Kaplan. Language models (mostly) know what they know, 2022. URL http://arxiv.org/ abs/2207.05221. Arxiv arxiv:2207.05221. 1, 4, 8, 9 Lorenz Kuhn, Yarin Gal, and Sebastian Farquhar. Semantic uncertainty: Linguistic invariances for uncertainty estimation in natural language generation, 2023. 2, 5, 8 Patrick Lewis, Ethan Perez, Aleksandra Piktus, Fabio Petroni, Vladimir Karpukhin, Naman Goyal, Heinrich Kuttler, Mike Lewis, Wen-tau Yih, Tim Rockt ¨ aschel, Sebastian Riedel, ¨ and Douwe Kiela. Retrieval-augmented generation for knowledge-intensive NLP tasks. In H. Larochelle, M. Ranzato, R. Hadsell, M.F. Balcan, and H. Lin (eds.), Advances in Neural Information Processing Systems, volume 33, pp. 9459–9474. Curran Associates, Inc., 2020. URL https://proceedings.neurips.cc/paper_files/paper/2020/ file/6b493230205f780e1bc26945df7481e5-Paper.pdf. 8 Kenneth Li, Oam Patel, Fernanda Viegas, Hanspeter Pfister, and Martin Wattenberg. Inference-time ´ intervention: Eliciting truthful answers from a language model, 2023. 6, 9 Shayne Longpre, Kartik Perisetla, Anthony Chen, Nikhil Ramesh, Chris DuBois, and Sameer Singh. Entity-based knowledge conflicts in question answering, 2022. 9 Ximing Lu, Sean Welleck, Jack Hessel, Liwei Jiang, Lianhui Qin, Peter West, Prithviraj Ammanabrolu, and Yejin Choi. QUARK: Controllable text generation with reinforced unlearning. In Alice H. Oh, Alekh Agarwal, Danielle Belgrave, and Kyunghyun Cho (eds.), Advances in Neural Information Processing Systems, 2022. URL https://openreview.net/forum?id= 5HaIds3ux5O. 3 Bill MacCartney and Christopher D. Manning. Modeling semantic containment and exclusion in natural language inference. In Proceedings of the 22nd International Conference on Computational Linguistics (Coling 2008), pp. 521–528, Manchester, UK, August 2008. Coling 2008 Organizing Committee. URL http://www.aclweb.org/anthology/C08-1066. 4 Alex Mallen, Akari Asai, Victor Zhong, Rajarshi Das, Daniel Khashabi, and Hannaneh Hajishirzi. When not to trust language models: Investigating effectiveness of parametric and non-parametric memories. In Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pp. 9802–9822, Toronto, Canada, July 2023. Association for Computational Linguistics. doi: 10.18653/v1/2023.acl-long.546. URL https://aclanthology.org/2023.acl-long.546. 9 Potsawee Manakul, Adian Liusie, and Mark J. F. Gales. Selfcheckgpt: Zero-resource black-box hallucination detection for generative large language models, 2023. 8 Joshua Maynez, Shashi Narayan, Bernd Bohnet, and Ryan McDonald. On faithfulness and factuality in abstractive summarization. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics, pp. 1906–1919, Online, July 2020. Association for Computational Linguistics. doi: 10.18653/v1/2020.acl-main.173. URL https://aclanthology.org/ 2020.acl-main.173. 8 Sewon Min, Kalpesh Krishna, Xinxi Lyu, Mike Lewis, Wen tau Yih, Pang Wei Koh, Mohit Iyyer, Luke Zettlemoyer, and Hannaneh Hajishirzi. Factscore: Fine-grained atomic evaluation of factual precision in long form text generation, 2023. 2, 4, 9, 14 Niels Mundler, Jingxuan He, Slobodan Jenko, and Martin Vechev. Self-contradictory hallucinations ¨ of large language models: Evaluation, detection and mitigation, 2023. 8 Long Ouyang, Jeff Wu, Xu Jiang, Diogo Almeida, Carroll L. Wainwright, Pamela Mishkin, Chong Zhang, Sandhini Agarwal, Katarina Slama, Alex Ray, John Schulman, Jacob Hilton, Fraser Kelton, Luke Miller, Maddie Simens, Amanda Askell, Peter Welinder, Paul Christiano, Jan Leike, and Ryan Lowe. Training language models to follow instructions with human feedback, 2022. 1, 3 Liangming Pan, Michael Saxon, Wenda Xu, Deepak Nathani, Xinyi Wang, and William Yang Wang. Automatically correcting large language models: Surveying the landscape of diverse selfcorrection strategies, 2023. 9 Baolin Peng, Michel Galley, Pengcheng He, Hao Cheng, Yujia Xie, Yu Hu, Qiuyuan Huang, Lars Liden, Zhou Yu, Weizhu Chen, and Jianfeng Gao. Check your facts and try again: Improving large language models with external knowledge and automated feedback, 2023. 9 Rafael Rafailov, Archit Sharma, Eric Mitchell, Stefano Ermon, Christopher D. Manning, and Chelsea Finn. Direct preference optimization: Your language model is secretly a reward model, 2023. 2, 3 Rajkumar Ramamurthy, Prithviraj Ammanabrolu, Kiante Brantley, Jack Hessel, Rafet Sifa, Chris- ´ tian Bauckhage, Hannaneh Hajishirzi, and Yejin Choi. Is reinforcement learning (not) for natural language processing: Benchmarks, baselines, and building blocks for natural language policy optimization. In International Conference on Learning Representations (ICLR 2023), 2022. URL https://arxiv.org/abs/2210.01241. 3 Anna Rohrbach, Lisa Anne Hendricks, Kaylee Burns, Trevor Darrell, and Kate Saenko. Object hallucination in image captioning. In Ellen Riloff, David Chiang, Julia Hockenmaier, and Jun’ichi Tsujii (eds.), Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing, pp. 4035–4045, Brussels, Belgium, October-November 2018. Association for Computational Linguistics. doi: 10.18653/v1/D18-1437. URL https://aclanthology.org/ D18-1437. 8 John Schulman, Filip Wolski, Prafulla Dhariwal, Alec Radford, and Oleg Klimov. Proximal policy optimization algorithms, 2017. 3 Chenglei Si, Zhe Gan, Zhengyuan Yang, Shuohang Wang, Jianfeng Wang, Jordan Boyd-Graber, and Lijuan Wang. Prompting gpt-3 to be reliable, 2023. 9 Nisan Stiennon, Long Ouyang, Jeff Wu, Daniel M. Ziegler, Ryan Lowe, Chelsea Voss, Alec Radford, Dario Amodei, and Paul Christiano. Learning to summarize from human feedback. Neural Information Processing Systems, 18, 2020. 3 Katherine Tian, Eric Mitchell, Allan Zhou, Archit Sharma, Rafael Rafailov, Huaxiu Yao, Chelsea Finn, and Christopher D. Manning. Just ask for calibration: Strategies for eliciting calibrated confidence scores from language models fine-tuned with human feedback, 2023. 1, 4 Hugo Touvron, Thibaut Lavril, Gautier Izacard, Xavier Martinet, Marie-Anne Lachaux, Timothee´ Lacroix, Baptiste Roziere, Naman Goyal, Eric Hambro, Faisal Azhar, Aurelien Rodriguez, Ar- \` mand Joulin, Edouard Grave, and Guillaume Lample. Llama: Open and efficient foundation language models, 2023a. 1, 4, 9 Hugo Touvron, Louis Martin, Kevin Stone, Peter Albert, Amjad Almahairi, Yasmine Babaei, Nikolay Bashlykov, Soumya Batra, Prajjwal Bhargava, Shruti Bhosale, Dan Bikel, Lukas Blecher, Cristian Canton Ferrer, Moya Chen, Guillem Cucurull, David Esiobu, Jude Fernandes, Jeremy Fu, Wenyin Fu, Brian Fuller, Cynthia Gao, Vedanuj Goswami, Naman Goyal, Anthony Hartshorn, Saghar Hosseini, Rui Hou, Hakan Inan, Marcin Kardas, Viktor Kerkez, Madian Khabsa, Isabel Kloumann, Artem Korenev, Punit Singh Koura, Marie-Anne Lachaux, Thibaut Lavril, Jenya Lee, Diana Liskovich, Yinghai Lu, Yuning Mao, Xavier Martinet, Todor Mihaylov, Pushkar Mishra, Igor Molybog, Yixin Nie, Andrew Poulton, Jeremy Reizenstein, Rashi Rungta, Kalyan Saladi, Alan Schelten, Ruan Silva, Eric Michael Smith, Ranjan Subramanian, Xiaoqing Ellen Tan, Binh Tang, Ross Taylor, Adina Williams, Jian Xiang Kuan, Puxin Xu, Zheng Yan, Iliyan Zarov, Yuchen Zhang, Angela Fan, Melanie Kambadur, Sharan Narang, Aurelien Rodriguez, Robert Stojnic, Sergey Edunov, and Thomas Scialom. Llama 2: Open foundation and fine-tuned chat models, 2023b. 1, 6 Weijia Xu, Sweta Agrawal, Eleftheria Briakou, Marianna J. Martindale, and Marine Carpuat. Understanding and Detecting Hallucinations in Neural Machine Translation via Model Introspection. Transactions of the Association for Computational Linguistics, 11:546–564, 06 2023. ISSN 2307- 387X. doi: 10.1162/tacl a 00563. URL https://doi.org/10.1162/tacl_a_00563. 8 Muru Zhang, Ofir Press, William Merrill, Alisa Liu, and Noah A Smith. How language model hallucinations can snowball. arXiv preprint arXiv:2305.13534, 2023. 8 Yuhao Zhang, Derek Merck, Emily Tsai, Christopher D Manning, and Curtis Langlotz. Optimizing the factual correctness of a summary: A study of summarizing radiology reports. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics (ACL), 2020. URL https://arxiv.org/pdf/1911.02541.pdf. 8 Rui Zheng, Shihan Dou, Songyang Gao, Yuan Hua, Wei Shen, Binghai Wang, Yan Liu, Senjie Jin, Qin Liu, Yuhao Zhou, Limao Xiong, Lu Chen, Zhiheng Xi, Nuo Xu, Wenbin Lai, Minghao Zhu, Cheng Chang, Zhangyue Yin, Rongxiang Weng, Wensen Cheng, Haoran Huang, Tianxiang Sun, Hang Yan, Tao Gui, Qi Zhang, Xipeng Qiu, and Xuanjing Huang. Secrets of RLHF in large language models part I: PPO, 2023. 3 Daniel M. Ziegler, Nisan Stiennon, Jeffrey Wu, Tom B. Brown, Alec Radford, Dario Amodei, Paul Christiano, and Geoffrey Irving. Fine-tuning language models from human preferences, 2020. 1
<table><tr><td>Dataset</td><td>Evaluation</td><td>SFT</td><td>FactTune-FS</td></tr><tr><td>Biographies</td><td>Human</td><td>0.582</td><td>0.846</td></tr><tr><td>Biographies</td><td>FactScore</td><td>0.669</td><td>0.921</td></tr><tr><td>MedQA</td><td>Human</td><td>0.662</td><td>0.838</td></tr><tr><td>MedQA</td><td>FactScore</td><td>0.534</td><td>0.806</td></tr></table>
Table 6: To validate that our models do not suffer from extreme reward overoptimization, we conduct a human evaluation of the Llama-1-7b SFT and FactTune-FS models and find that an increase in FactScore also corresponds to a large increase in human-annotated accuracy. This study is computed on a subset of 25 generations per model.
 Figure 4: Average FactScore error counts and GPT-4 error counts are highly correlated, suggesting that the resulting models do not suffer from extreme reward overoptimization (Gao et al., 2022). We plot average FactScore error count v.s. average GPT-4 error count, scaling each dataset by the max GPT-4 error count in that dataset.
# A APPENDIX
# A.1 VALIDATING METRICS FOR FACTUALITY
Our experiments primarily use counts of correct and incorrect facts computed by FactScore as the main evaluation metrics, as FactScore is automated and has been shown to exhibit good agreement with human fact-checkers (Min et al., 2023). Nonetheless, we aim to verify that our results are not specific or overfit to the FactScore criterion. In this section, we provide an evaluation with (1) human evaluators hired through Prolific.co2 and (2) GPT-4.
To acquire human fact-checking results, we provide each human evaluator with a prompt, a generated response, and the title of the Wikipedia article they should use for fact-checking the response. We ask the human study participants to count the total number of facts and the number of incorrect facts in the response, and we divide these to obtain the human-rated accuracy. We provide the results in Table 6, where on average humans rated our FactTune-FS model for both datasets significantly higher than the SFT model.
Further, we ask GPT-4 to evaluate the factuality of a given response by counting the number of factual errors. We observe that the GPT-4 model ratings and FactScore model ratings are highly correlated, and GPT-4 provides another evaluation metric that demonstrates that FactTune-FS significantly reduces average error compared to the SFT models on both datasets (see Figure 4). Taken together, these results suggest that the improvements in factuality are not the result of exploitation of our evaluation protocol.
# A.2 PROMPTS
Table 7 contains the prompts used with GPT-3.5 to convert statements into questions for model confidence-based truthfulness estimation.
# A.3 SAMPLE MODEL GENERATIONS
See Table 8 for samples generated by several different models. After factuality tuning, the model does produce somewhat terser responses.
Table 7: GPT-3.5 prompts used to convert atomic facts into questions.
<table><tr><td>Biography Atomic Fact to Question the key fact in the statement. For example: Statement: LeBron James is a professional basketball player. Question: What is LeBron James’profession? Statement: He is one of the best in the NBA. Question: Where does LeBron James rank among NBA players? Statement: James was born in Akron.</td><td>I will provide a statement containing one atomic fact related to Hillry Clinton or people around her. Please rephrase the following statement into a specific question testing knowledge of the key fact in the statement. For example: Statement:Hillary Clinton was born in 1947. Question: In what year was Hillary Clinton born? Statement: Hillary attended the Wellesley College. Question: What college did Hillary Clinton attend? Statement: She married Bill Clinton. Question: Who did Hillary Clinton marry? I will provide a statement containing one atomic fact related to LeBron James or people around him. Please rephrase the following statement into a specific question that testing knowledge of</td></tr><tr><td>Atomic Fact to Question derarm. the breast or underarm? the breast?</td><td>MedicalQA I will provide a statement containing one atomic fact about the medical condition menopause. Please rephrase the following statement into a specific question testing knowledge of the key fact in the statement.For example: Statement: Menopause is a time in a woman's life. Question: Menopause is a time in whose life? Statement: Menopause is the time when a woman no longer has menstrual periods. Question: Menopause is the time when a woman no longer has what? Statement: There is a decline in the ovarian hormone estrogen. Question: During menopause there is a decline in what? I will provide a statement containing one atomic fact about the medical condition breast cancer. Please rephrase the following statement into a specific question testing knowledge of the key fact in the statement. For example: Statement: The signs and symptoms include a lump or thickening in or near the breast or un- Question: Do the signs and symptoms of breast cancer include a lump or thickening in or near Statement: The signs and symptoms include a change in the size or shape of the breast. Question: Do the signs and symptoms of breast cancer include a change in the size or shape of I will provide a statement containing one atomic fact about the medical condition varicose veins. Please rephrase the following statement into a specific question testing knowledge of the key fact in the statement.For example:</td></tr></table>
<table><tr><td>SFT</td><td>Greta Gerwig is an American actress and filmmaker. She was born in and raised in Sacramento, California. Gerwig became interested in the film industry in 2OO2,when she attended the San Francisco Art Institute. She got her start in 2OO6,when she starred in the film‘The Off Hours'. Her other films include Frances Ha,Mistress America,and 2Oth Century Women. In 2018, Gerwig directed Lady Bird,and received wide acclaim,a Golden Globe and Tony nomination for directing,and Oscar and BAFTA nominations for the film.</td></tr><tr><td>FactTune-FS</td><td>Greta Gerwig is an American actress and filmmaker. Born in Sacramento, California in 1983, Gerwig started acting at a young age. She is best known for starring in films such as ‘Frances Ha’ and ‘Mistress America.’Gerwig was nominated for an Oscar for Best Actress for her per- formance in ‘Lady Bird.' Gerwig has writen and directed a number of acclaimed independent films,such as‘FrancesHa’and ‘Mistress America.'</td></tr><tr><td>FactTune-MC</td><td>Greta Gerwig is an American actress and flmmaker. She was born in 1983 in Sacramento, California,and raised in Stanford, California and New York City. Gerwig has appeared in such movies as Greenberg,Frances Ha,and Jackie.She also portrayed the title role in the 2013 film of Jackie Kennedy. Her directorial debut is the 2O12 movie,Lady Bird,which was nominated for the Academy Award for Best Picture.</td></tr></table>
Table 8: Samples for writing a biography of Greta Gerwig under the SFT, FactTune-FS, FactTune-MC Llama1-7b models.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598[ { "type": "text", "text": "FINE-TUNING LANGUAGE MODELS FOR FACTUALITY ", "text_level": 1, "page_idx": 0 }, { "type": "text", "text": "Katherine Tian\\*†, Eric Mitchell\\*†, Huaxiu Yao†§, Christopher D. Manning†, Chelsea Finn† \n†Stanford University §UNC Chapel Hill \n{kattian,eric.mitchell}@cs.stanford.edu ", "page_idx": 0 }, { "type": "text", "text": "ABSTRACT ", "text_level": 1, "page_idx": 0 }, { "type": "text", "text": "The fluency and creativity of large pre-trained language models (LLMs) have led to their widespread use, sometimes even as a replacement for traditional search engines. Yet language models are prone to making convincing but factually inaccurate claims, often referred to as ‘hallucinations.’ These errors can inadvertently spread misinformation or harmfully perpetuate misconceptions. Further, manual fact-checking of model responses is a time-consuming process, making human factuality labels expensive to acquire. In this work, we fine-tune language models to be more factual, without human labeling and targeting more open-ended generation settings than past work. We leverage two key recent innovations in NLP to do so. First, several recent works have proposed methods for judging the factuality of open-ended text by measuring consistency with an external knowledge base or simply a large model’s confidence scores. Second, the Direct Preference Optimization algorithm enables straightforward finetuning of language models on objectives other than supervised imitation, using a preference ranking over possible model responses. We show that learning from automatically generated factuality preference rankings, generated either through existing retrieval systems or our novel retrieval-free approach, significantly improves the factuality (percent of generated claims that are correct) of Llama-2 on held-out topics compared with RLHF or decoding strategies targeted at factuality. At 7B scale, compared to Llama-2-Chat, we observe $53 \\%$ and $50 \\%$ reduction in factual error rate when generating biographies and answering medical questions, respectively. A reference implementation can be found at https://github.com/kttian/llm_factuality_tuning. ", "page_idx": 0 }, { "type": "text", "text": "1 INTRODUCTION ", "text_level": 1, "page_idx": 0 }, { "type": "text", "text": "Recent developments in training large language models (LLMs), particularly methods that learn from rankings over responses such as reinforcement learning from human feedback (RLHF) (Christiano et al., 2017; Ziegler et al., 2020; Ouyang et al., 2022), have enabled the development of powerful, engaging dialogue agents. State-of-the-art LLMs are pre-trained on a vast amount of knowledge in large datasets (Touvron et al., 2023a;b) and further fine-tuned to apply this knowledge to follow diverse instructions or complete more specific tasks (Chung et al., 2022; Chen et al., 2021). However, despite these large language models’ exposure to diverse datasets, they are prone to confidently generating incorrect claims. One recent study shows that GPT-3.5 (ChatGPT) produces false citations more often than not when asked to provide the authors of a given study (Agrawal et al., 2023). Nonetheless, other research has demonstrated that in simple question-answering settings, large language models do exhibit systematic markers of uncertainty that indicate their factually unreliable statements (Kadavath et al., 2022; Tian et al., 2023). These results suggest that language models internally represent the limits of their knowledge, leading us to ask: Can language models be fine-tuned to leverage this internal awareness, to avoid making untrue statements in the first place? ", "page_idx": 0 }, { "type": "text", "text": "A key source of difficulty in training factual models comes in specifying an objective that adequately captures factuality. As an example, maximum likelihood, the most common objective for pre-training language models, does not always encourage factual predictions. Consider the question “Where was Yo-Yo Ma born?” A model that continues by near-deterministically producing the text “idk, probably Paris?” is nearly always correct, but receives extremely high loss if the pre-training data contains any other response to the question. On the other hand, a model that hedges probability mass over many possible phrasings and many possible locations (including incorrect ones, like Antarctica) will likely receive much lower loss, as any response observed in the training data will be assigned at least some non-trivial probability. Because the pre-training objective may reward ‘smearing’ probability mass over many possible responses, language models may generate incorrect statements if they underfit the training data or if asked questions that require knowledge not contained in the pre-training data. ", "page_idx": 0 }, { "type": "image", "img_path": "images/5410068e804224bc887b843d58dc7804a3e0d70426741c655e4faffc98599a7b.jpg", "image_caption": [ "Figure 1: Our approach aims to improve the factuality of language models, specifically focusing on longform generation (e.g. writing a biography). We develop two different approaches for estimating factuality of a passage (center), each of which allows us to generate a preference dataset (right). We then fine-tune the language model to optimize these factuality preferences (far right). " ], "image_footnote": [], "page_idx": 1 }, { "type": "text", "text": "", "page_idx": 1 }, { "type": "text", "text": "In principle, reinforcement learning-based objectives can avoid the failures of existing pre-training objectives through the appropriate choice of a reward function that penalizes factually incorrect statements. However, accurately computing such a reward function can be expensive. Obtaining human labels of factuality is time-consuming and costly; Min et al. (2023) report that professional fact-checkers took approximately 9 minutes to fact-check a single model-generated biography of a well-known individual; it cost about $\\$ 2,000$ to annotate 505 biographies. ", "page_idx": 1 }, { "type": "text", "text": "In light of these challenges, we leverage recent advances in estimating truthfulness without human intervention: a) reference-based automated fact-checking methods that evaluate the extent to which an external knowledge base supports the claims in a piece of text (Min et al., 2023; Chern et al., 2023) and b) reference-free truthfulness evaluations that use a model’s own confidence as a proxy for truthfulness, inspired by Kuhn et al. (2023). Using these truthfulness measures and a dataset of unlabeled prompts (e.g., “Write a biography of Yo-Yo Ma.”), we sample pairs of completions from a pre-trained model and annotate them with a preference label denoting which has a lower rate of factual errors. Using the recently proposed Direct Preference Optimization (Rafailov et al., 2023) algorithm, we can stably and efficiently learn from such data. Ultimately, this pipeline enables us to fine-tune off-the-shelf language models to produce factual errors less often (with or without a reference knowledge base). See Figure 1 for an overview of our factuality tuning pipeline. ", "page_idx": 1 }, { "type": "text", "text": "Our primary contribution is a straightforward approach to optimizing language models for factuality in long-form text generation without human annotation. We validate this approach on two benchmark datasets for evaluating factuality, targeted at generating biographies of popular figures and answering open-ended questions about medical conditions. We find that fine-tuning for factuality outperforms conventional RLHF and produces complementary benefits to LLM decoding strategies that aim to increase factuality. Further, we find qualitative differences in the result of learning from preference pairs scored with reference-based and reference-free truthfulness estimation. Overall, we find that learning factuality from automatically constructed preference pairs is a cost-effective way to increase model factuality without human intervention, reducing the error count for claims generated by Llama models by around $50 \\%$ or more for biographies and over $2 5 \\%$ for medical questions. ", "page_idx": 1 }, { "type": "text", "text": "2 PRELIMINARIES ", "text_level": 1, "page_idx": 1 }, { "type": "text", "text": "Our approach to fine-tuning directly for improved factuality uses the framework of reinforcement learning from preferences over candidate actions or responses. In this section, we provide an overview of reinforcement learning in the context of language models, as well as the specific algorithm we use for preference-based RL, direct preference optimization (Rafailov et al., 2023). ", "page_idx": 1 }, { "type": "text", "text": "Fine-tuning language models with reinforcement learning. Reinforcement learning (RL) has proven to be an effective approach to fine-tuning language models to extract complex, useful behaviors from their pre-trained weights. In the context of RL, a language model policy $\\pi _ { \\theta }$ (typically an autoregressive Transformer) produces a conditional distribution $\\pi _ { \\theta } ( y \\mid x )$ over responses $y$ given an input query $x$ (both $x$ and $y$ are text sequences). The goal of reinforcement learning is to maximize the average reward of outputs generated by the policy, where a reward function $\\bar { r } ( x , y )$ assigns a scalar score to an input-output pair that determines its desirability. However, past works have observed that fine-tuning language models with an objective of unconstrained reward maximization can lead to overoptimization (Gao et al., 2022), that is, a policy that achieves high reward through exploitation of the idiosyncrasies of the reward function that are not aligned with the intended behavior. The most commonly-used objective in practice therefore combines reward maximization with a KL-divergence penalty between the language model and its initialization: ", "page_idx": 1 }, { "type": "text", "text": "", "page_idx": 2 }, { "type": "equation", "img_path": "images/6f95c544d4907ac4818f63eec3614cae9b5aa16fc1a0231048b4a99a9fb915ce.jpg", "text": "$$\n\\mathop { \\operatorname* { m a x } } _ { \\pi _ { \\theta } } \\mathbb { E } _ { x \\sim \\mathcal { D } _ { p } , y \\sim \\pi _ { \\theta } ( y | x ) } \\left[ r ( x , y ) - \\beta \\log \\frac { \\pi _ { \\theta } ( y \\mid x ) } { \\pi _ { \\mathrm { r e f } } ( y \\mid x ) } \\right]\n$$", "text_format": "latex", "page_idx": 2 }, { "type": "text", "text": "where $\\mathcal { D } _ { p }$ is some dataset of prompts, $\\pi _ { \\mathrm { r e f } }$ is the reference model, usually the result of performing some supervised fine-tuning on a pre-trained model using demonstration data, and $\\beta$ is a coefficient that controls the trade-off between reward and divergence (Ouyang et al., 2022; Bai et al., 2022; Stiennon et al., 2020). Optimizing this objective aligns the model with the reward function without deviating too far from the pre-trained reference model, reducing overoptimization. In practice, the most common algorithm used to optimize this objective for language models is proximal policy optimization (PPO; Schulman et al. (2017)), although some variants exist (Ramamurthy et al., 2022; Lu et al., 2022). However, these algorithms are quite complex to implement and tune (Zheng et al., 2023) and require online sampling during training, substantially increasing training time. ", "page_idx": 2 }, { "type": "text", "text": "RL from preferences with direct preference optimization (DPO). Most large language models fine-tuned with Eq. 1 optimize a reward function that is learned from a dataset of preference rankings over possible model outputs. The DPO algorithm simplifies $\\mathrm { R L }$ on language models for this special case (Rafailov et al., 2023), using a dataset of preference pairs $\\mathcal { D } = \\{ x ^ { ( i ) } , y _ { w } ^ { ( i ) } , y _ { l } ^ { ( i ) } \\} _ { i = 1 } ^ { N }$ of prompts $x$ and candidate responses $y _ { w }$ and $y _ { l }$ (typically sampled from $\\pi _ { \\mathrm { r e f } } )$ , where $y _ { w }$ is preferred over $y _ { l }$ (denoted $y _ { w } \\succ y _ { l } ,$ . The probability of observing a particular preference pair is assumed to follow a Bradley-Terry model (Bradley & Terry, 1952): ", "page_idx": 2 }, { "type": "equation", "img_path": "images/0524f69ee68c26727795f3ad82bff32c54f592904d88989823a50149df9fd709.jpg", "text": "$$\np ( y _ { w } \\succ y _ { l } ) = \\sigma ( r ( x , y _ { w } ) - r ( x , y _ { l } ) )\n$$", "text_format": "latex", "page_idx": 2 }, { "type": "text", "text": "where $\\sigma$ is the sigmoid function and $r ( x , y )$ is an unobserved reward or scoring function. Rafailov et al. (2023) show that the optimal policy $\\pi ^ { * }$ for the problem in Eq. 1 can be found by optimizing a simple classification loss computed directly on the preference data: ", "page_idx": 2 }, { "type": "equation", "img_path": "images/586b762edeeeaee503fe2560937f5bf596fe94fbb3d38070ee513203dd19ce27.jpg", "text": "$$\n\\begin{array} { r } { \\mathcal { L } _ { \\mathrm { D P O } } ( \\pi _ { \\theta } ; \\pi _ { \\mathrm { r e f } } ) = - \\mathbb { E } _ { ( x , y _ { w } , y _ { l } ) \\sim \\mathcal { D } } \\left[ \\log \\sigma \\left( \\beta \\log \\frac { \\pi _ { \\theta } ( y _ { w } \\mid x ) } { \\pi _ { \\mathrm { r e f } } ( y _ { w } \\mid x ) } - \\beta \\log \\frac { \\pi _ { \\theta } ( y _ { l } \\mid x ) } { \\pi _ { \\mathrm { r e f } } ( y _ { l } \\mid x ) } \\right) \\right] } \\end{array}\n$$", "text_format": "latex", "page_idx": 2 }, { "type": "text", "text": "DPO enables learning $\\pi _ { \\theta }$ from a fixed dataset of preferences, without fitting an explicit reward function or sampling from the policy in the loop of training. These advantages make DPO an attractive choice for fine-tuning language models for objectives other than imitation. However, a challenge remains in constructing preference pairs that encourage greater factuality. ", "page_idx": 2 }, { "type": "text", "text": "3 CONSTRUCTING PREFERENCES ENCOURAGING FACTUALITY INLONG-FORM TEXT", "text_level": 1, "page_idx": 2 }, { "type": "text", "text": "While existing preference learning algorithms like DPO enable efficient, stable learning from objectives other than maximum likelihood, they require data in the form of preferences over possible responses to a prompt. In this section, we propose two classes of approaches to generating such preferences without human labeling effort. One class leverages existing methods to determine consistency with external reference texts as a measure of truthfulness; we propose another, which leverages calibrated model probabilities themselves as a proxy for truthfulness. For both approaches, we are computing an estimated truthfulness score over the claims in each generated response; the response with higher average truthfulness is taken as the preferred response. See Figure 2 for an overview of both procedures for truthfulness scoring. Note that truthfulness scoring is needed only at training time; at test time, we can sample from the model in the normal manner. ", "page_idx": 2 }, { "type": "text", "text": "3.1 REFERENCE-BASED TRUTHFULNESS ESTIMATION ", "text_level": 1, "page_idx": 2 }, { "type": "text", "text": "An intuitive approach to estimating truthfulness is by estimating the consistency of a given piece of text with a reliable reference text or knowledge base. Several recent works have introduced such evaluation criteria; for example, FactScore (Min et al., 2023) uses Wikipedia as reference knowledge, and FacTool (Chern et al., 2023) uses Google Search Results. These measures show high agreement with human judgments of factuality, making them attractive sources of truth for preference data construction. Due to the relatively consistent and high quality of Wikipedia articles, we elect to use FactScore as a representative method of reference-based truthfulness scoring. ", "page_idx": 2 }, { "type": "image", "img_path": "images/ccc4d832b1e3b7e4429c9496f3b841873bdb56aa91bc7cebb8d67fb54a96253c.jpg", "image_caption": [ "Figure 2: We estimate the factuality of a generation by first extracting claims (left) and then evaluating each claims’ truthfulness (right). For the latter, we consider: a reference-based (top right) method that uses a finetuned Llama model to check if the fact is supported by Wikipedia (Min et al., 2023) and a reference-free (bottom right) method that uses the model’s confidence in its most likely answer to estimate its truthfulness. " ], "image_footnote": [], "page_idx": 3 }, { "type": "text", "text": "", "page_idx": 3 }, { "type": "text", "text": "To evaluate a piece of text, FactScore first extracts a list of the atomic claims present in the text using GPT-3.5.1 For each atomic claim, a smaller, more efficient model such as a Llama-1-7b model (Touvron et al., 2023a) that has been fine-tuned for fact-checking is then used to perform natural language inference (MacCartney & Manning, 2008) to determine if a claim is supported by the reference text. The passage’s truthfulness score is the fraction of the extracted atomic claims that are estimated to be supported by the reference text. ", "page_idx": 3 }, { "type": "text", "text": "We note that reference-based truthfulness has the key limitation that it requires access to relevant, high-quality reference texts against which to measure consistency. Such a requirement may limit applicability to domains where ground truth documents are not known and accurate retrieval is difficult, such as in niche domains or less-structured tasks. Further, reference-based truthfulness estimation requires a reliable model to determine if an atomic claim is supported by the article. In light of these limitations, we propose a reference-free approach to estimating truthfulness of open-ended text, which avoids the need for retrieving external knowledge and checking consistency. ", "page_idx": 3 }, { "type": "text", "text": "3.2 REFERENCE-FREE CONFIDENCE-BASED TRUTHFULNESS ESTIMATION ", "text_level": 1, "page_idx": 3 }, { "type": "text", "text": "To eliminate the need for external knowledge, we leverage the fact that large language models are well-calibrated (Kadavath et al., 2022; Tian et al., 2023). That is, if a large language model assigns a fixed confidence $p$ to each claim in a set of claims, the fraction of these claims that is correct is $p$ . In other words, in expectation over many claims, a perfectly-calibrated model’s confidence in a claim corresponds to the probability it is correct. To use this notion of calibration, we interpret a model generation (e.g., a biography of Yo-Yo Ma) as a collection of claims, each resulting from a query to the model’s knowledge (e.g., “When was Yo-Yo Ma born?” or “How many siblings does Yo-Yo Ma have?”). Our goal is to encourage the model to produce responses containing queries to its knowledge likely to lead to correct claims. Therefore, we parse a complete model generation into its constituent queries to the model’s knowledge. For each query to the model’s knowledge present in the generation, we can estimate the likelihood it will lead to a correct claim by simply estimating the average confidence of the model’s answer to this query. If a model assigns probability 0.7 to ‘1955’ and probability 0.3 to ‘1953’ for the query “When was Yo-Yo Ma born?”, then the probability this query will lead to a correct claim (again, in expectation over queries) is $0 . 7 ^ { 2 } + 0 . { \\dot { 3 } } ^ { 2 } = 0 . 5 { \\dot { 8 } }$ . The model used for computing confidence scores essentially takes the place of the reference text datastore. We evaluate this Expected Confidence approach as well as a Max Confidence approach, which simply takes the max over the answer confidences for a given query (i.e., we assume the model produces answers greedily rather than sampling). ", "page_idx": 3 }, { "type": "image", "img_path": "images/2dbe894e5993a9be7efccd8d24b194797acb848da2022e87116b3a4649747261.jpg", "image_caption": [ "Figure 3: Factuality tuning using FactScore truthfulness scoring (FactTune-FS) produces by far the greatest improvement in factuality for the biography generation and medical question-answering problems. Factuality tuning with expected model confidence truthfulness scoring provides the next strongest performance, on average. For MedicalQA, only factuality tuning provides a strict improvement in factuality (more correct statements and fewer incorrect statements) compared to the SFT model. " ], "image_footnote": [], "page_idx": 4 }, { "type": "text", "text": "", "page_idx": 4 }, { "type": "text", "text": "More concretely, we first extract atomic claims from the text using GPT-3.5. We then use GPT-3.5 to convert each claim to a query (question) testing knowledge of the particular fact. Careful rephrasing is necessary to ensure that the rephrased question is unambiguous; for example, the claim “Yo-Yo Ma plays the cello” should be converted to the question “What instrument does Yo-Yo Ma play?” rather than just “What does Yo-Yo Ma play?” as the latter question admits answers of the wrong type. If we were to use the second prompt, a model might assign $50 \\%$ of its probability on “cello” and $50 \\%$ of its probability on “basketball.” However, the model’s low confidence is caused by the ambiguity of the question, not low confidence in the instrument that Yo-Yo Ma plays. We detail the prompts used for question generation in Appendix A.2. ", "page_idx": 4 }, { "type": "text", "text": "After each claim is converted to a minimally ambiguous question, we resample an answer 20 times from the base model (e.g. Llama-1-7b) that is fine-tuned to estimate the model’s uncertainty over the answer. We use a few-shot prompt to encourage well-formed answers. We bin these answers by equivalence, using either heuristic string matching of the responses or using GPT-3.5 to assess if the answers are semantically equivalent, inspired by Kuhn et al. (2023). Our heuristic string match checks whether the words in the answer, excluding stop words, are the same. We compare these choices in Section 4.4. The score for each claim is either the expected or maximum confidence of the model’s response; we finally average this score over all claims in a given model generation. ", "page_idx": 4 }, { "type": "text", "text": "3.3 FACTUALITY TUNING: PUTTING IT ALL TOGETHER ", "text_level": 1, "page_idx": 4 }, { "type": "text", "text": "Given a choice of truthfulness estimator, we can now construct a preference dataset for factuality tuning a given language model from a set of unlabeled prompts. First, we sample $n$ multiple candidate responses for each prompt from the model with simple temperature sampling with temperature 1.0 (using few-shot prompting for models that have not been fine-tuned). For each response, we then compute the truthfulness score with the chosen estimator (reference-based or reference-free). Finally, for all $\\binom { n } { 2 }$ pairs of responses to each prompt, we simply choose the response with the higher truthfulness score as the preferred response. For a set of $m$ prompts, we ultimately generate $m { \\binom { n } { 2 } } - k$ preference pairs, where $k$ is the number of pairs with equal scores. Finally, we fine-tune the model using the DPO pipeline, using all model responses as targets for the SFT stage. ", "page_idx": 4 }, { "type": "text", "text": "4 EXPERIMENTS ", "text_level": 1, "page_idx": 4 }, { "type": "text", "text": "Our experiments evaluate the extent to which factuality can be learned through preference-based reinforcement learning, using the fully automated preference-generation pipeline described in Section ", "page_idx": 4 }, { "type": "table", "img_path": "images/6b7f980ac2fae80a5980c1368a8cb2ab99e23e9dd734738249eb85072711e416.jpg", "table_caption": [ "Table 1: Dataset statistics and examples. In biographies, entities are individuals; in MedicalQA, entities are medical conditions. We include 6 questions for each entity in MedicalQA and adjust the number of responses per prompt to keep the total number of pairs in the two datasets roughly similar. " ], "table_footnote": [], "table_body": "<table><tr><td>Dataset</td><td>Entities [train, val, test]</td><td>Prompts per Entity</td><td>Responses per Prompt</td><td>Example prompt</td></tr><tr><td>Biographies</td><td>463[288,50,125]</td><td>16</td><td>10</td><td>Write me a paragraph biography of Mary Wolstonecraft.</td></tr><tr><td>Medical QA</td><td>295[150,45,100]</td><td></td><td>6</td><td>What are the common symptoms of a stroke?</td></tr></table>", "page_idx": 5 }, { "type": "text", "text": "3. We call the model fine-tuned with our reference-based metric FactTune-FS and the model finetuned with our model confidence-based score, which is completely reference-free, FactTune-MC. For all of our experiments, samples for model confidence are taken from Llama-1-7b. ", "page_idx": 5 }, { "type": "text", "text": "Datasets. We conduct our experiments on two tasks: generating biographies and medical questionanswering. For biographies, we generated a dataset consisting of 463 diverse well-known individuals (288 train, 50 val, 125 test) with 10 short-paragraph biographies each. For medical question answering, we used a dataset of 295 diverse common medical conditions (150 train, 45 val, 100 test) with 6 questions about each condition and 6 short-paragraph answers per question. The test set just uses 1 question per condition. The prompts were generated with GPT-3.5, and the answers were sampled from Llama-1-7b using a few-shot prompt for each dataset. We found that our procedure consistently resulted in well-formed and informative responses, albeit with possible factual errors. Because FactScore uses retrieval against a given Wikipedia article, we generate data based on individuals and medical conditions that have Wikipedia pages. See Table 1 for the summary stats and examples from our datasets. ", "page_idx": 5 }, { "type": "text", "text": "Baselines. We compare factuality tuning with inference-time intervention (Li et al., 2023, ITI) and decoding by contrasting layers (Chuang et al., 2023, DOLA), applied to the SFT model for each task. For ITI, we supervise the training of the linear probes with FactScore labels: we take batches of atomic facts extracted from the training samples and bias the models’ activations from the incorrect to correct atomic facts to determine the direction of the intervention. In the case of Llama-2, we also compare against ‘standard’ RLHF with human preference labels (Touvron et al., 2023b). ", "page_idx": 5 }, { "type": "text", "text": "Evaluation. To evaluate each generated response, we follow the FactScore procedure to extract the number of correct and incorrect facts. Then, to check that the model responses are still relevant and helpful after actuality fine-tuning, we also use GPT-3.5 to determine whether each fact is relevant to the question or not (using the prompt in Appendix A.2). For biographies, we observed that essentially $100 \\%$ of facts were relevant to the individual, so we skip the relevance computation to save costs. For each dataset, we report the number of correct and relevant facts (# Correct), the number of inaccuracies (# Incorrect), and the proportion of correct relevant facts out of the total number of extracted facts ( $\\%$ Correct). Note that the total number of facts may vary between generations. We validate our evaluation metrics in Sec. A.1. ", "page_idx": 5 }, { "type": "text", "text": "4.1 FINE-TUNING FOR FACTUALITY ACROSS DOMAINS ", "text_level": 1, "page_idx": 5 }, { "type": "text", "text": "In this section, we apply our methodology for learning factuality to Llama-1-7b and Llama-2-7b in multiple domains. We show the results in Table 2. Learning from reference-based factualityscored pairs (FactTune-FS) consistently improves factual accuracy compared to RLHF models and decoding-based factuality baselines by at least $11 \\%$ on biographies and $13 \\%$ on medical questionanswering. FactTune-FS reduces the number of factual errors and maintains no more than a slight decrease, if not increase, in the amount of correct information generated. Factuality tuning from model-confidence scores (FactTune-MC, FactTune-EC) also reduces error rate and improves the factuality of RLHF models on both datasets, without any external reference information. ", "page_idx": 5 }, { "type": "text", "text": "4.2 FINE-TUNING CHAT MODELS FOR FACTUALITY ", "text_level": 1, "page_idx": 5 }, { "type": "text", "text": "Most widely used practical chatbots today are LMs trained with RLHF to follow diverse instructions in a way that is helpful to users. In this section, we investigate the ability of our human-free factuality tuning method to improve the factuality of RLHF chat models. Using Llama-2-7b-Chat, we find that fine-tuning an RLHF LM with both factuality and semantic entropy-based rewards can further improve its factuality without significantly decreasing the total number of facts, as shown in Table 3. ", "page_idx": 5 }, { "type": "table", "img_path": "images/f5e36c05b40d0e0c4b846676e520c0e727eb64bac8228a0b104e1f9c34763325.jpg", "table_caption": [ "Table 2: Factuality tuning from reference-based factuality-scored pairs (FactTune-FS) improves factual accuracy compared to RLHF models and decoding-based factuality baselines, consistently reducing the number of errors and often increasing the number of correct facts generated. Factuality tuning from model confidence scored pairs (FactTune-MC, FactTune-EC) also outperforms RLHF models, providing a strong reference-free alternative for improving factuality and reducing error. " ], "table_footnote": [], "table_body": "<table><tr><td></td><td></td><td colspan=\"3\">Biographies</td><td colspan=\"3\">Medical QA</td></tr><tr><td>Base Model</td><td>Method</td><td># Correct</td><td># Incorrect</td><td>% Correct</td><td># Correct</td><td># Incorrect</td><td>% Correct</td></tr><tr><td rowspan=\"6\">Llama-1</td><td>ITI</td><td>13.68</td><td>5.24</td><td>0.730</td><td>10.25</td><td>7.96</td><td>0.538</td></tr><tr><td>DOLA</td><td>12.44</td><td>4.74</td><td>0.737</td><td>9.22</td><td>5.58</td><td>0.640</td></tr><tr><td>SFT</td><td>13.54</td><td>6.54</td><td>0.696</td><td>9.96</td><td>6.86</td><td>0.600</td></tr><tr><td>FactTune-FS (Ours)</td><td>14.51</td><td>3.74</td><td>0.812</td><td>12.60</td><td>4.18</td><td>0.746</td></tr><tr><td>FactTune-MC (Ours)</td><td>9.74</td><td>2.42</td><td>0.819</td><td>11.51</td><td>5.56</td><td>0.668</td></tr><tr><td>FactTune-EC (Ours)</td><td>10.84</td><td>3.28</td><td>0.790</td><td>11.52</td><td>6.56</td><td>0.641</td></tr><tr><td rowspan=\"7\">Llama-2</td><td>ITI</td><td>13.30</td><td>5.56</td><td>0.712</td><td>9.40</td><td>4.25</td><td>0.690</td></tr><tr><td>DOLA</td><td>13.25</td><td>6.50</td><td>0.684</td><td>9.87</td><td>6.06</td><td>0.627</td></tr><tr><td>Chat</td><td>21.41</td><td>6.30</td><td>0.774</td><td>9.61</td><td>6.69</td><td>0.619</td></tr><tr><td>SFT</td><td>13.47</td><td>6.49</td><td>0.687</td><td>10.68</td><td>6.22</td><td>0.627</td></tr><tr><td>FactTune-FS (Ours)</td><td>19.32</td><td>2.76</td><td>0.880</td><td>13.29</td><td>2.97</td><td>0.809</td></tr><tr><td>FactTune-MC (Ours)</td><td>11.74</td><td>3.51</td><td>0.783</td><td>12.94</td><td>5.26</td><td>0.706</td></tr><tr><td>FactTune-EC (Ours)</td><td>12.68</td><td>3.69</td><td>0.797</td><td>12.80</td><td>5.19</td><td>0.710</td></tr></table>", "page_idx": 6 }, { "type": "table", "img_path": "images/9ac1e349973f0b03c90bdc9d19558eda934e0b6813998b2a344faba0cb247eed.jpg", "table_caption": [], "table_footnote": [ "Table 3: Factuality tuning a dialogue model (Llama-2-Chat) with FactScore, model confidence-based truthfulness estimation, and FactScore-based preferences from a different dataset (FactTune-FS, FactTune-MC, OOD FactTune-FS) further improves its factual accuracy more than a baseline method for factuality, DOLA. " ], "table_body": "<table><tr><td></td><td></td><td colspan=\"3\">Biographies</td><td colspan=\"3\">Medical QA</td></tr><tr><td>Base Model</td><td>Method</td><td># Correct</td><td># Incorrect</td><td>% Correct</td><td># Correct</td><td># Incorrect</td><td>% Correct</td></tr><tr><td></td><td></td><td>21.41</td><td>6.30</td><td>0.774</td><td>9.61</td><td>6.69</td><td>0.619</td></tr><tr><td></td><td>DOLA</td><td>22.25</td><td>5.81</td><td>0.793</td><td>11.45</td><td>6.74</td><td>0.624</td></tr><tr><td>Llama-2-Chat</td><td>FactTune-FS (Ours)</td><td>20.02</td><td>4.38</td><td>0.821</td><td>11.94</td><td>6.21</td><td>0.667</td></tr><tr><td></td><td>FactTune-MC (Ours)</td><td>19.12</td><td>4.97</td><td>0.795</td><td>12.61</td><td>7.21</td><td>0.627</td></tr><tr><td></td><td>FactTune-EC (Ours)</td><td>18.77</td><td>5.13</td><td>0.784</td><td>11.51</td><td>6.40</td><td>0.639</td></tr><tr><td></td><td>OOD FactTune-FS (ours)</td><td>21.06</td><td>5.45</td><td>0.796</td><td>11.56</td><td>6.66</td><td>0.635</td></tr></table>", "page_idx": 6 }, { "type": "text", "text": "In other words, factuality tuning can be composed with RLHF to further improve the factuality of chat models. ", "text_level": 1, "page_idx": 6 }, { "type": "text", "text": "While our quantitative metrics demonstrate a clear increase in factual accuracy, we also investigate how factuality fine-tuning impacts other aspects of model performance and generalizes. Using GPT4 as a judge, we find that FactTune-MC and FactTune-EC can improve both factuality and fluency compared to the SFT model (examples in Appendix Table 8). GPT-4 chooses FactTuneEC as more fluent than SFT on $80 \\%$ of samples, FactTune-MC on $7 5 \\%$ of samples, ITI on $57 \\%$ of samples, FactTune-FS on $33 \\%$ of samples, and DOLA on $16 \\%$ of samples $\\scriptstyle ( \\mathrm { n = 1 0 0 }$ ). ", "page_idx": 6 }, { "type": "text", "text": "Lastly, we find that fine-tuning for factuality generalizes across datasets. Fine-tuning Llama-2- 7b-Chat on biographies to evaluate on MedicalQA and vice versa (OOD FactTune-FS) improves the factuality more than RLHF (Table 3). ", "page_idx": 6 }, { "type": "text", "text": "4.3 COMPLEMENTARY BENEFITS OF FACTUALITY TUNING AND DECODING-TIME FACTUALITY INTERVENTIONS ", "page_idx": 6 }, { "type": "text", "text": "Besides fine-tuning for factuality, multiple existing works aim to improve LLM factuality through inference time interventions to either the decoding process or the model parameters themselves. We explore the possibility of applying both of these types of methods together, i.e., using factualityboosting decoding methods on a model fine-tuned with our factuality tuning procedure. In Table 4 we present the results of stacking both approaches. We find that in most cases, DOLA can even further increase the accuracy of factuality fine-tuned models, with one exception for Llama-2 on the biography task. While not a comprehensive evaluation of combining methods for improving factuality, this result suggests that different approaches to enhancing factuality may operate through complementary mechanisms. ", "page_idx": 6 }, { "type": "table", "img_path": "images/fe22d6772f7ba1cecd755a13a9152870d08ea92a57ab203edc7a47962387600a.jpg", "table_caption": [ "Table 4: DOLA factuality decoding frequently composes with factuality fine-tuning, providing an increase in average correctness for the majority of combinations of model and dataset. " ], "table_footnote": [], "table_body": "<table><tr><td></td><td></td><td colspan=\"3\">Biographies</td><td colspan=\"3\">Medical QA</td></tr><tr><td>Base Model</td><td>Method</td><td>#Correct</td><td>#Incorrect</td><td>%Correct</td><td>#Correct</td><td>#Incorrect</td><td>%Correct</td></tr><tr><td rowspan=\"2\">Llama-1</td><td></td><td></td><td>3.74</td><td></td><td>12.0</td><td>418</td><td>0.746</td></tr><tr><td>FactTune-FS + DOLA</td><td>1451</td><td></td><td>0.812</td><td></td><td></td><td></td></tr><tr><td rowspan=\"2\">Llama-2</td><td></td><td>19.32</td><td>2.76</td><td>0.880</td><td>13.29</td><td></td><td></td></tr><tr><td>FactTune-FS + DOLA</td><td></td><td></td><td></td><td></td><td>2.7</td><td>0.89</td></tr></table>", "page_idx": 7 }, { "type": "table", "img_path": "images/cdbf6180dd0ff7791cd494f6d64df452297fbc4839b262618a12abea7d09ba38.jpg", "table_caption": [], "table_footnote": [ "Table 5: On Llama-1, model confidence-based preference construction with atomic question extraction outperforms the version with entity extraction. " ], "table_body": "<table><tr><td></td><td></td><td></td><td colspan=\"3\">Biographies</td><td colspan=\"3\">Medical QA</td></tr><tr><td>Fact Ext.</td><td>Equiv</td><td>Metric</td><td>#Correct</td><td>#Incorrect</td><td>%Correct</td><td>#Correct</td><td>#Incorrect</td><td>%Correct</td></tr><tr><td rowspan=\"2\">Atomic</td><td rowspan=\"2\">Heuristic</td><td>Max Con Conf</td><td>9.74</td><td>22</td><td></td><td></td><td>5.56</td><td>0.668</td></tr><tr><td></td><td></td><td></td><td>0.819</td><td>11.51</td><td></td><td></td></tr><tr><td rowspan=\"2\">Entity</td><td rowspan=\"2\">Heuristic</td><td></td><td>12.2</td><td></td><td>0.74</td><td>10.3</td><td></td><td></td></tr><tr><td>Mx Co Conf</td><td></td><td>4.74</td><td></td><td></td><td>64</td><td>0.603</td></tr></table>", "page_idx": 7 }, { "type": "text", "text": "4.4 IMPACT OF DESIGN DECISIONS OF OPEN-ENDED MODEL CONFIDENCE SCORING ", "text_level": 1, "page_idx": 7 }, { "type": "text", "text": "This section discusses the impacts of different design choices for the steps of our reference-free truthfulness score construction for factuality tuning: how to perform fact extraction and what confidence metric to use. ", "page_idx": 7 }, { "type": "text", "text": "The first step is to extract the individual facts from the long-form response and re-sample each fact from the base model to assess the model’s confidence in the fact. For the fact-extraction and resampling procedure, one approach (Atomic) is to convert each extracted atomic fact into a corresponding ‘atomic question’ with a few-shot prompt query to GPT-3.5, then sample answers to each question from the base LLM. Another approach (Entity) extracts entities from the response via nltk and re-samples the extracted entity in-line. Atomic question extraction has the potential to be more comprehensive and precise, while named entity extraction is a less expensive proxy that doesn’t use closed models. In Table 5, we observe that atomic question extraction outperforms named entity extraction, although the difference in accuracy is smaller on Medical QA than on Biographies. ", "page_idx": 7 }, { "type": "text", "text": "After re-sampling the fact, we study the choice of confidence metric between taking the model’s confidence based on the most common sample (Max Conf) or the confidence of the fact from the original response (Expected Conf). To compute Max Conf for both atomic and entity extraction, we bin the samples into equivalence classes of distinct responses using a string matching heuristic described in Section 3.2 and take the proportion of samples in the largest bin. For computing Expected Confidence, we first perform the same answer binning procedure as for Max Confidence, resulting in $k$ bins and confidences $p _ { 1 } , \\ldots , p _ { k }$ , and take $\\textstyle E C = \\sum _ { i = 1 } ^ { k } p _ { i } ^ { 2 }$ . The results in Table 5 show that the performance of Max Conf versus Expected Conf varies but are quite similar. ", "page_idx": 7 }, { "type": "text", "text": "5 RELATED WORK ", "text_level": 1, "page_idx": 7 }, { "type": "text", "text": "Many works have identified reducing factual errors (sometimes called ‘hallucinations’) as a key challenge for building more reliable language models (Lewis et al., 2020; Kadavath et al., 2022; Zhang et al., 2023), even for the most powerful language models (Bubeck et al., 2023). Other use of the term ‘hallucination’ refers to summarization or translation system outputs not supported by the reference text (Maynez et al., 2020; Zhang et al., 2020) even if they are factual (Cao et al., 2022). Other work uses ‘hallucination’ to describe vision-language models producing outputs not grounded in a visual input, e.g., a captioning system describing an object that doesn’t exist in the image (Rohrbach et al., 2018). In our case, we focus on statements that are factually incorrect (or, inconsistent with a set of ‘authoritative’ texts, such as Wikipedia). ", "page_idx": 7 }, { "type": "text", "text": "Several works describe methods for detecting likely factual errors through sensitivity to perturbations in the prompt (Xu et al., 2023), high diversity of responses under resampling (Kadavath et al., 2022; Mundler et al. ¨ , 2023; Kuhn et al., 2023; Manakul et al., 2023), or inconsistency with external knowledge sources (Min et al., 2023; Chern et al., 2023), or properties of internal activations (Azaria & Mitchell, 2023). Others go beyond detecting errors, correcting them after they have been generated (Peng et al., 2023; Gao et al., 2023; Dhuliawala et al., 2023). These approaches typically rely on retrieving relevant data from a trusted knowledge base and use another LLM to verify consistency; however, retrieval-based methods face key challenges, namely reliable resolution of conflicts between parametric and retrieved knowledge (Longpre et al., 2022; Chen et al., 2022) as well as maintaining improvements in factuality as model size increases (Mallen et al., 2023). Further, retrieval-based methods add significant system complexity; the most common open-source consumer language models thus use purely parametric models (Touvron et al., 2023a). The FactScore variant of our approach uses retrieval only during training, avoiding inference time complexity. In principle, any existing criterion could be used to generate preferences (see ;¸ we aim to show that even choosing relatively simple criteria leads to substantial improvements in factuality. ", "page_idx": 7 }, { "type": "text", "text": "", "page_idx": 8 }, { "type": "text", "text": "Most similar to ours, some approaches attempt to prevent the generation of factual errors in the first place, using prompting strategies (Si et al., 2023) or perturbing the internal representations of the model (Chuang et al., 2023; Li et al., 2023). Unlike using a fixed heuristic for identifying an internal ‘factuality’ dimension, we optimize directly for the end goal of generating factual statements, which we find shows a greater improvement in factuality. Finally, while most past work has focused on short-form NLG tasks like short-form question-answering (Kadavath et al., 2022), we explore ways to measure model confidence over factual information in long-form, unstructured text and estimate truthfulness in a reference-free manner (i.e., don’t require any external knowledge base or annotations). ", "page_idx": 8 }, { "type": "text", "text": "6 CONCLUSION ", "text_level": 1, "page_idx": 8 }, { "type": "text", "text": "In this paper, we show a practical, effective strategy to improve a language model’s ability to generate factual content, specifically focusing on long-form generations. We develop and study two different approaches to estimating the truthfulness of long-form text and optimize for these criteria using preference-based learning. In addition to existing reference-based truthfulness estimators that leverage external knowledge to establish the truth of a particular statement, we introduce a novel reference-free procedure for estimating truthfulness that uses the language model’s own uncertainty as an indication of factuality. Our experiments show that fine-tuning a language model with either criterion reliably reduces the number of incorrect facts (i.e. hallucinations) that the model generates. Reference-free approaches like the one we introduced provide a scalable self-supervision strategy to improve factuality, eliminating the need for a reference corpus of ‘gold’ texts. ", "page_idx": 8 }, { "type": "text", "text": "The experimental results suggest a number of avenues for future work. First, because of the limited research and thus the limited benchmarks on the factuality of long-form language model generations, we proposed two new tasks to benchmark our approach. These tasks are representative of but do not fully cover the range of scenarios where we would hope to improve factuality. Furthermore, our experiments provide evidence for improving the factuality of dialogue models that are already finetuned with RLHF, but still leave open the question of how best to combine typical RLHF rewards and approaches with factuality rankings. Similarly, exploring additional ways to combine factuality tuning with existing methods for improving factuality, such as in our factuality tuning $+ { \\mathrm { ~ D O L A } }$ experiment, may be a fruitful direction for future research. Further, future work might explore alternative approaches to constructing factuality preferences, such as using self-correction (Pan et al., 2023). Finally, we explore only 7B models in this work. Scaling up our factuality tuning recipe to larger models (and larger preference datasets) may reduce hallucinations even further. ", "page_idx": 8 }, { "type": "text", "text": "ACKNOWLEDGEMENTS ", "text_level": 1, "page_idx": 8 }, { "type": "text", "text": "EM gratefully acknowledges funding from a Knight-Hennessy graduate fellowship and a Stanford Accelerator for Generative AI and Education grant. CF and CDM are CIFAR Fellows. ", "page_idx": 8 }, { "type": "text", "text": "Reproducibility Statement. We explain the steps of our fine-tuning method in Section 3. In Section 4.1, we provide details on the dataset (dataset statistics, how it was generated, and examples), as well as how the evaluation is completed and how we implemented the baselines. In the experiment subsections and captions, we provide additional implementation or reporting details. In the appendix, we provide the exact GPT-3.5 prompts used for the extraction steps of our reference-free scoring method. A codebase with instructions for factuality scoring, training, and evaluation can be found here: https://github.com/kttian/llm_factuality_tuning. ", "page_idx": 8 }, { "type": "text", "text": "REFERENCES ", "text_level": 1, "page_idx": 9 }, { "type": "text", "text": "Ayush Agrawal, Mirac Suzgun, Lester Mackey, and Adam Tauman Kalai. Do language models know when they’re hallucinating references?, 2023. arXiv preprint arxiv:2305.18248. 1 ", "page_idx": 9 }, { "type": "text", "text": "Amos Azaria and Tom Mitchell. The internal state of an LLM knows when its lying, 2023. arXiv preprint arxiv:2304.13734. 9 ", "page_idx": 9 }, { "type": "text", "text": "Yuntao Bai, Andy Jones, Kamal Ndousse, Amanda Askell, Anna Chen, Nova DasSarma, Dawn Drain, Stanislav Fort, Deep Ganguli, Tom Henighan, Nicholas Joseph, Saurav Kadavath, Jackson Kernion, Tom Conerly, Sheer El-Showk, Nelson Elhage, Zac Hatfield-Dodds, Danny Hernandez, Tristan Hume, Scott Johnston, Shauna Kravec, Liane Lovitt, Neel Nanda, Catherine Olsson, Dario Amodei, Tom Brown, Jack Clark, Sam McCandlish, Chris Olah, Ben Mann, and Jared Kaplan. Training a helpful and harmless assistant with reinforcement learning from human feedback, 2022. arXiv preprint arxiv:2204.05862. 3 ", "page_idx": 9 }, { "type": "text", "text": "Ralph Allan Bradley and Milton E Terry. Rank analysis of incomplete block designs: I. the method of paired comparisons. Biometrika, 39(3/4):324–345, 1952. 3 ", "page_idx": 9 }, { "type": "text", "text": "Sebastien Bubeck, Varun Chandrasekaran, Ronen Eldan, Johannes Gehrke, Eric Horvitz, Ece ´ Kamar, Peter Lee, Yin Tat Lee, Yuanzhi Li, Scott Lundberg, Harsha Nori, Hamid Palangi, Marco Tulio Ribeiro, and Yi Zhang. Sparks of artificial general intelligence: Early experiments with GPT-4, 2023. arXiv preprint arxiv:2303.12712. 8 ", "page_idx": 9 }, { "type": "text", "text": "Meng Cao, Yue Dong, and Jackie Cheung. Hallucinated but factual! inspecting the factuality of hallucinations in abstractive summarization. In Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pp. 3340–3354, Dublin, Ireland, May 2022. Association for Computational Linguistics. doi: 10.18653/v1/2022.acl-long. 236. URL https://aclanthology.org/2022.acl-long.236. 8 ", "page_idx": 9 }, { "type": "text", "text": "Hung-Ting Chen, Michael Zhang, and Eunsol Choi. Rich knowledge sources bring complex knowledge conflicts: Recalibrating models to reflect conflicting evidence. In Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing, pp. 2292–2307, Abu Dhabi, United Arab Emirates, December 2022. Association for Computational Linguistics. doi: 10.18653/v1/2022.emnlp-main.146. URL https://aclanthology.org/2022. emnlp-main.146. 9 ", "page_idx": 9 }, { "type": "text", "text": "Mark Chen, Jerry Tworek, Heewoo Jun, Qiming Yuan, Henrique Ponde, Jared Kaplan, Harrison Edwards, Yura 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, David W. Cummings, Matthias Plappert, Fotios Chantzis, Elizabeth Barnes, Ariel Herbert-Voss, William H. Guss, Alex Nichol, Igor Babuschkin, S. Arun Balaji, Shantanu Jain, Andrew Carr, Jan Leike, Joshua Achiam, Vedant Misra, Evan Morikawa, Alec Radford, Matthew M. 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. ArXiv, abs/2107.03374, 2021. URL https://api.semanticscholar.org/CorpusID:235755472. 1 ", "page_idx": 9 }, { "type": "text", "text": "I-Chun Chern, Steffi Chern, Shiqi Chen, Weizhe Yuan, Kehua Feng, Chunting Zhou, Junxian He, Graham Neubig, and Pengfei Liu. FacTool: Factuality detection in generative ai – a tool augmented framework for multi-task and multi-domain scenarios, 2023. arXiv preprint arxiv:2307.13528. 2, 4, 9 ", "page_idx": 9 }, { "type": "text", "text": "Paul F Christiano, Jan Leike, Tom Brown, Miljan Martic, Shane Legg, and Dario Amodei. Deep reinforcement learning from human preferences. In I. Guyon, U. Von Luxburg, S. Bengio, H. Wallach, R. Fergus, S. Vishwanathan, and R. Garnett (eds.), Advances in Neural Information Processing Systems, volume 30. Curran Associates, Inc., 2017. URL https://proceedings.neurips.cc/paper_files/paper/2017/ file/d5e2c0adad503c91f91df240d0cd4e49-Paper.pdf. 1 ", "page_idx": 9 }, { "type": "text", "text": "Yung-Sung Chuang, Yujia Xie, Hongyin Luo, Yoon Kim, James Glass, and Pengcheng He. DoLa: Decoding by contrasting layers improves factuality in large language models, 2023. arXiv preprint arxiv:2309.03883. 6, 9 ", "page_idx": 10 }, { "type": "text", "text": "Hyung Won Chung, Le Hou, Shayne Longpre, Barret Zoph, Yi Tay, William Fedus, Yunxuan Li, Xuezhi Wang, Mostafa Dehghani, Siddhartha Brahma, Albert Webson, Shixiang Shane Gu, Zhuyun Dai, Mirac Suzgun, Xinyun Chen, Aakanksha Chowdhery, Alex Castro-Ros, Marie Pellat, Kevin Robinson, Dasha Valter, Sharan Narang, Gaurav Mishra, Adams Yu, Vincent Zhao, Yanping Huang, Andrew Dai, Hongkun Yu, Slav Petrov, Ed H. Chi, Jeff Dean, Jacob Devlin, Adam Roberts, Denny Zhou, Quoc V. Le, and Jason Wei. Scaling instruction-finetuned language models, 2022. 1 Shehzaad Dhuliawala, Mojtaba Komeili, Jing Xu, Roberta Raileanu, Xian Li, Asli Celikyilmaz, and Jason Weston. Chain-of-verification reduces hallucination in large language models, 2023. 9 Leo Gao, John Schulman, and Jacob Hilton. Scaling laws for reward model overoptimization, 2022. \n3, 14 Luyu Gao, Zhuyun Dai, Panupong Pasupat, Anthony Chen, Arun Tejasvi Chaganty, Yicheng Fan, Vincent Y. Zhao, Ni Lao, Hongrae Lee, Da-Cheng Juan, and Kelvin Guu. Rarr: Researching and revising what language models say, using language models, 2023. 9 Saurav Kadavath, Tom Conerly, Amanda Askell, Tom Henighan, Dawn Drain, Ethan Perez, Nicholas Schiefer, Zac Hatfield-Dodds, Nova DasSarma, Eli Tran-Johnson, Scott Johnston, Sheer El-Showk, Andy Jones, Nelson Elhage, Tristan Hume, Anna Chen, Yuntao Bai, Sam Bowman, Stanislav Fort, Deep Ganguli, Danny Hernandez, Josh Jacobson, Jackson Kernion, Shauna Kravec, Liane Lovitt, Kamal Ndousse, Catherine Olsson, Sam Ringer, Dario Amodei, Tom Brown, Jack Clark, Nicholas Joseph, Ben Mann, Sam McCandlish, Chris Olah, and Jared Kaplan. Language models (mostly) know what they know, 2022. URL http://arxiv.org/ abs/2207.05221. Arxiv arxiv:2207.05221. 1, 4, 8, 9 Lorenz Kuhn, Yarin Gal, and Sebastian Farquhar. Semantic uncertainty: Linguistic invariances for uncertainty estimation in natural language generation, 2023. 2, 5, 8 Patrick Lewis, Ethan Perez, Aleksandra Piktus, Fabio Petroni, Vladimir Karpukhin, Naman Goyal, Heinrich Kuttler, Mike Lewis, Wen-tau Yih, Tim Rockt ¨ aschel, Sebastian Riedel, ¨ and Douwe Kiela. Retrieval-augmented generation for knowledge-intensive NLP tasks. In H. Larochelle, M. Ranzato, R. Hadsell, M.F. Balcan, and H. Lin (eds.), Advances in Neural Information Processing Systems, volume 33, pp. 9459–9474. Curran Associates, Inc., \n2020. URL https://proceedings.neurips.cc/paper_files/paper/2020/ file/6b493230205f780e1bc26945df7481e5-Paper.pdf. 8 Kenneth Li, Oam Patel, Fernanda Viegas, Hanspeter Pfister, and Martin Wattenberg. Inference-time ´ intervention: Eliciting truthful answers from a language model, 2023. 6, 9 Shayne Longpre, Kartik Perisetla, Anthony Chen, Nikhil Ramesh, Chris DuBois, and Sameer Singh. Entity-based knowledge conflicts in question answering, 2022. 9 Ximing Lu, Sean Welleck, Jack Hessel, Liwei Jiang, Lianhui Qin, Peter West, Prithviraj Ammanabrolu, and Yejin Choi. QUARK: Controllable text generation with reinforced unlearning. In Alice H. Oh, Alekh Agarwal, Danielle Belgrave, and Kyunghyun Cho (eds.), Advances in Neural Information Processing Systems, 2022. URL https://openreview.net/forum?id= \n5HaIds3ux5O. 3 Bill MacCartney and Christopher D. Manning. Modeling semantic containment and exclusion in natural language inference. In Proceedings of the 22nd International Conference on Computational Linguistics (Coling 2008), pp. 521–528, Manchester, UK, August 2008. Coling 2008 Organizing Committee. URL http://www.aclweb.org/anthology/C08-1066. 4 Alex Mallen, Akari Asai, Victor Zhong, Rajarshi Das, Daniel Khashabi, and Hannaneh Hajishirzi. When not to trust language models: Investigating effectiveness of parametric and non-parametric memories. In Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pp. 9802–9822, Toronto, Canada, July 2023. Association for Computational Linguistics. doi: 10.18653/v1/2023.acl-long.546. URL https://aclanthology.org/2023.acl-long.546. 9 \nPotsawee Manakul, Adian Liusie, and Mark J. F. Gales. Selfcheckgpt: Zero-resource black-box hallucination detection for generative large language models, 2023. 8 \nJoshua Maynez, Shashi Narayan, Bernd Bohnet, and Ryan McDonald. On faithfulness and factuality in abstractive summarization. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics, pp. 1906–1919, Online, July 2020. Association for Computational Linguistics. doi: 10.18653/v1/2020.acl-main.173. URL https://aclanthology.org/ 2020.acl-main.173. 8 \nSewon Min, Kalpesh Krishna, Xinxi Lyu, Mike Lewis, Wen tau Yih, Pang Wei Koh, Mohit Iyyer, Luke Zettlemoyer, and Hannaneh Hajishirzi. Factscore: Fine-grained atomic evaluation of factual precision in long form text generation, 2023. 2, 4, 9, 14 \nNiels Mundler, Jingxuan He, Slobodan Jenko, and Martin Vechev. Self-contradictory hallucinations ¨ of large language models: Evaluation, detection and mitigation, 2023. 8 \nLong Ouyang, Jeff Wu, Xu Jiang, Diogo Almeida, Carroll L. Wainwright, Pamela Mishkin, Chong Zhang, Sandhini Agarwal, Katarina Slama, Alex Ray, John Schulman, Jacob Hilton, Fraser Kelton, Luke Miller, Maddie Simens, Amanda Askell, Peter Welinder, Paul Christiano, Jan Leike, and Ryan Lowe. Training language models to follow instructions with human feedback, 2022. 1, 3 \nLiangming Pan, Michael Saxon, Wenda Xu, Deepak Nathani, Xinyi Wang, and William Yang Wang. Automatically correcting large language models: Surveying the landscape of diverse selfcorrection strategies, 2023. 9 \nBaolin Peng, Michel Galley, Pengcheng He, Hao Cheng, Yujia Xie, Yu Hu, Qiuyuan Huang, Lars Liden, Zhou Yu, Weizhu Chen, and Jianfeng Gao. Check your facts and try again: Improving large language models with external knowledge and automated feedback, 2023. 9 \nRafael Rafailov, Archit Sharma, Eric Mitchell, Stefano Ermon, Christopher D. Manning, and Chelsea Finn. Direct preference optimization: Your language model is secretly a reward model, 2023. 2, 3 \nRajkumar Ramamurthy, Prithviraj Ammanabrolu, Kiante Brantley, Jack Hessel, Rafet Sifa, Chris- ´ tian Bauckhage, Hannaneh Hajishirzi, and Yejin Choi. Is reinforcement learning (not) for natural language processing: Benchmarks, baselines, and building blocks for natural language policy optimization. In International Conference on Learning Representations (ICLR 2023), 2022. URL https://arxiv.org/abs/2210.01241. 3 \nAnna Rohrbach, Lisa Anne Hendricks, Kaylee Burns, Trevor Darrell, and Kate Saenko. Object hallucination in image captioning. In Ellen Riloff, David Chiang, Julia Hockenmaier, and Jun’ichi Tsujii (eds.), Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing, pp. 4035–4045, Brussels, Belgium, October-November 2018. Association for Computational Linguistics. doi: 10.18653/v1/D18-1437. URL https://aclanthology.org/ D18-1437. 8 \nJohn Schulman, Filip Wolski, Prafulla Dhariwal, Alec Radford, and Oleg Klimov. Proximal policy optimization algorithms, 2017. 3 \nChenglei Si, Zhe Gan, Zhengyuan Yang, Shuohang Wang, Jianfeng Wang, Jordan Boyd-Graber, and Lijuan Wang. Prompting gpt-3 to be reliable, 2023. 9 \nNisan Stiennon, Long Ouyang, Jeff Wu, Daniel M. Ziegler, Ryan Lowe, Chelsea Voss, Alec Radford, Dario Amodei, and Paul Christiano. Learning to summarize from human feedback. Neural Information Processing Systems, 18, 2020. 3 \nKatherine Tian, Eric Mitchell, Allan Zhou, Archit Sharma, Rafael Rafailov, Huaxiu Yao, Chelsea Finn, and Christopher D. Manning. Just ask for calibration: Strategies for eliciting calibrated confidence scores from language models fine-tuned with human feedback, 2023. 1, 4 \nHugo Touvron, Thibaut Lavril, Gautier Izacard, Xavier Martinet, Marie-Anne Lachaux, Timothee´ Lacroix, Baptiste Roziere, Naman Goyal, Eric Hambro, Faisal Azhar, Aurelien Rodriguez, Ar- \\` mand Joulin, Edouard Grave, and Guillaume Lample. Llama: Open and efficient foundation language models, 2023a. 1, 4, 9 \nHugo Touvron, Louis Martin, Kevin Stone, Peter Albert, Amjad Almahairi, Yasmine Babaei, Nikolay Bashlykov, Soumya Batra, Prajjwal Bhargava, Shruti Bhosale, Dan Bikel, Lukas Blecher, Cristian Canton Ferrer, Moya Chen, Guillem Cucurull, David Esiobu, Jude Fernandes, Jeremy Fu, Wenyin Fu, Brian Fuller, Cynthia Gao, Vedanuj Goswami, Naman Goyal, Anthony Hartshorn, Saghar Hosseini, Rui Hou, Hakan Inan, Marcin Kardas, Viktor Kerkez, Madian Khabsa, Isabel Kloumann, Artem Korenev, Punit Singh Koura, Marie-Anne Lachaux, Thibaut Lavril, Jenya Lee, Diana Liskovich, Yinghai Lu, Yuning Mao, Xavier Martinet, Todor Mihaylov, Pushkar Mishra, Igor Molybog, Yixin Nie, Andrew Poulton, Jeremy Reizenstein, Rashi Rungta, Kalyan Saladi, Alan Schelten, Ruan Silva, Eric Michael Smith, Ranjan Subramanian, Xiaoqing Ellen Tan, Binh Tang, Ross Taylor, Adina Williams, Jian Xiang Kuan, Puxin Xu, Zheng Yan, Iliyan Zarov, Yuchen Zhang, Angela Fan, Melanie Kambadur, Sharan Narang, Aurelien Rodriguez, Robert Stojnic, Sergey Edunov, and Thomas Scialom. Llama 2: Open foundation and fine-tuned chat models, 2023b. 1, 6 \nWeijia Xu, Sweta Agrawal, Eleftheria Briakou, Marianna J. Martindale, and Marine Carpuat. Understanding and Detecting Hallucinations in Neural Machine Translation via Model Introspection. Transactions of the Association for Computational Linguistics, 11:546–564, 06 2023. ISSN 2307- 387X. doi: 10.1162/tacl a 00563. URL https://doi.org/10.1162/tacl_a_00563. 8 \nMuru Zhang, Ofir Press, William Merrill, Alisa Liu, and Noah A Smith. How language model hallucinations can snowball. arXiv preprint arXiv:2305.13534, 2023. 8 \nYuhao Zhang, Derek Merck, Emily Tsai, Christopher D Manning, and Curtis Langlotz. Optimizing the factual correctness of a summary: A study of summarizing radiology reports. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics (ACL), 2020. URL https://arxiv.org/pdf/1911.02541.pdf. 8 \nRui Zheng, Shihan Dou, Songyang Gao, Yuan Hua, Wei Shen, Binghai Wang, Yan Liu, Senjie Jin, Qin Liu, Yuhao Zhou, Limao Xiong, Lu Chen, Zhiheng Xi, Nuo Xu, Wenbin Lai, Minghao Zhu, Cheng Chang, Zhangyue Yin, Rongxiang Weng, Wensen Cheng, Haoran Huang, Tianxiang Sun, Hang Yan, Tao Gui, Qi Zhang, Xipeng Qiu, and Xuanjing Huang. Secrets of RLHF in large language models part I: PPO, 2023. 3 \nDaniel M. Ziegler, Nisan Stiennon, Jeffrey Wu, Tom B. Brown, Alec Radford, Dario Amodei, Paul Christiano, and Geoffrey Irving. Fine-tuning language models from human preferences, 2020. 1 ", "page_idx": 10 }, { "type": "text", "text": "", "page_idx": 11 }, { "type": "text", "text": "", "page_idx": 12 }, { "type": "table", "img_path": "images/033e71e49af60b2f755d88d1da18a6336988e2e905d459e9a90dfbcf980ba8c3.jpg", "table_caption": [], "table_footnote": [], "table_body": "<table><tr><td>Dataset</td><td>Evaluation</td><td>SFT</td><td>FactTune-FS</td></tr><tr><td>Biographies</td><td>Human</td><td>0.582</td><td>0.846</td></tr><tr><td>Biographies</td><td>FactScore</td><td>0.669</td><td>0.921</td></tr><tr><td>MedQA</td><td>Human</td><td>0.662</td><td>0.838</td></tr><tr><td>MedQA</td><td>FactScore</td><td>0.534</td><td>0.806</td></tr></table>", "page_idx": 13 }, { "type": "text", "text": "Table 6: To validate that our models do not suffer from extreme reward overoptimization, we conduct a human evaluation of the Llama-1-7b SFT and FactTune-FS models and find that an increase in FactScore also corresponds to a large increase in human-annotated accuracy. This study is computed on a subset of 25 generations per model. ", "page_idx": 13 }, { "type": "image", "img_path": "images/c728e2c9dbd4acc21848512c38d03b6c6ddf3a6c6a95ab7ba5c3ff9b16cbe034.jpg", "image_caption": [ "Figure 4: Average FactScore error counts and GPT-4 error counts are highly correlated, suggesting that the resulting models do not suffer from extreme reward overoptimization (Gao et al., 2022). We plot average FactScore error count v.s. average GPT-4 error count, scaling each dataset by the max GPT-4 error count in that dataset. " ], "image_footnote": [], "page_idx": 13 }, { "type": "text", "text": "A APPENDIX ", "text_level": 1, "page_idx": 13 }, { "type": "text", "text": "A.1 VALIDATING METRICS FOR FACTUALITY ", "text_level": 1, "page_idx": 13 }, { "type": "text", "text": "Our experiments primarily use counts of correct and incorrect facts computed by FactScore as the main evaluation metrics, as FactScore is automated and has been shown to exhibit good agreement with human fact-checkers (Min et al., 2023). Nonetheless, we aim to verify that our results are not specific or overfit to the FactScore criterion. In this section, we provide an evaluation with (1) human evaluators hired through Prolific.co2 and (2) GPT-4. ", "page_idx": 13 }, { "type": "text", "text": "To acquire human fact-checking results, we provide each human evaluator with a prompt, a generated response, and the title of the Wikipedia article they should use for fact-checking the response. We ask the human study participants to count the total number of facts and the number of incorrect facts in the response, and we divide these to obtain the human-rated accuracy. We provide the results in Table 6, where on average humans rated our FactTune-FS model for both datasets significantly higher than the SFT model. ", "page_idx": 13 }, { "type": "text", "text": "Further, we ask GPT-4 to evaluate the factuality of a given response by counting the number of factual errors. We observe that the GPT-4 model ratings and FactScore model ratings are highly correlated, and GPT-4 provides another evaluation metric that demonstrates that FactTune-FS significantly reduces average error compared to the SFT models on both datasets (see Figure 4). Taken together, these results suggest that the improvements in factuality are not the result of exploitation of our evaluation protocol. ", "page_idx": 13 }, { "type": "text", "text": "A.2 PROMPTS ", "text_level": 1, "page_idx": 13 }, { "type": "text", "text": "Table 7 contains the prompts used with GPT-3.5 to convert statements into questions for model confidence-based truthfulness estimation. ", "page_idx": 13 }, { "type": "text", "text": "A.3 SAMPLE MODEL GENERATIONS ", "text_level": 1, "page_idx": 13 }, { "type": "text", "text": "See Table 8 for samples generated by several different models. After factuality tuning, the model does produce somewhat terser responses. ", "page_idx": 13 }, { "type": "table", "img_path": "images/533195afd2d8583338f72fc010025755314e81b1a400e06e15b1db5fc29068c5.jpg", "table_caption": [ "Table 7: GPT-3.5 prompts used to convert atomic facts into questions. " ], "table_footnote": [], "table_body": "<table><tr><td>Biography Atomic Fact to Question the key fact in the statement. For example: Statement: LeBron James is a professional basketball player. Question: What is LeBron James’profession? Statement: He is one of the best in the NBA. Question: Where does LeBron James rank among NBA players? Statement: James was born in Akron.</td><td>I will provide a statement containing one atomic fact related to Hillry Clinton or people around her. Please rephrase the following statement into a specific question testing knowledge of the key fact in the statement. For example: Statement:Hillary Clinton was born in 1947. Question: In what year was Hillary Clinton born? Statement: Hillary attended the Wellesley College. Question: What college did Hillary Clinton attend? Statement: She married Bill Clinton. Question: Who did Hillary Clinton marry? I will provide a statement containing one atomic fact related to LeBron James or people around him. Please rephrase the following statement into a specific question that testing knowledge of</td></tr><tr><td>Atomic Fact to Question derarm. the breast or underarm? the breast?</td><td>MedicalQA I will provide a statement containing one atomic fact about the medical condition menopause. Please rephrase the following statement into a specific question testing knowledge of the key fact in the statement.For example: Statement: Menopause is a time in a woman's life. Question: Menopause is a time in whose life? Statement: Menopause is the time when a woman no longer has menstrual periods. Question: Menopause is the time when a woman no longer has what? Statement: There is a decline in the ovarian hormone estrogen. Question: During menopause there is a decline in what? I will provide a statement containing one atomic fact about the medical condition breast cancer. Please rephrase the following statement into a specific question testing knowledge of the key fact in the statement. For example: Statement: The signs and symptoms include a lump or thickening in or near the breast or un- Question: Do the signs and symptoms of breast cancer include a lump or thickening in or near Statement: The signs and symptoms include a change in the size or shape of the breast. Question: Do the signs and symptoms of breast cancer include a change in the size or shape of I will provide a statement containing one atomic fact about the medical condition varicose veins. Please rephrase the following statement into a specific question testing knowledge of the key fact in the statement.For example:</td></tr></table>", "page_idx": 14 }, { "type": "table", "img_path": "images/981861a167d235b6cfd0335a15d05423d179436df3b84c4e4f82eca8b10fb529.jpg", "table_caption": [], "table_footnote": [ "Table 8: Samples for writing a biography of Greta Gerwig under the SFT, FactTune-FS, FactTune-MC Llama1-7b models. " ], "table_body": "<table><tr><td>SFT</td><td>Greta Gerwig is an American actress and filmmaker. She was born in and raised in Sacramento, California. Gerwig became interested in the film industry in 2OO2,when she attended the San Francisco Art Institute. She got her start in 2OO6,when she starred in the film‘The Off Hours'. Her other films include Frances Ha,Mistress America,and 2Oth Century Women. In 2018, Gerwig directed Lady Bird,and received wide acclaim,a Golden Globe and Tony nomination for directing,and Oscar and BAFTA nominations for the film.</td></tr><tr><td>FactTune-FS</td><td>Greta Gerwig is an American actress and filmmaker. Born in Sacramento, California in 1983, Gerwig started acting at a young age. She is best known for starring in films such as ‘Frances Ha’ and ‘Mistress America.’Gerwig was nominated for an Oscar for Best Actress for her per- formance in ‘Lady Bird.' Gerwig has writen and directed a number of acclaimed independent films,such as‘FrancesHa’and ‘Mistress America.'</td></tr><tr><td>FactTune-MC</td><td>Greta Gerwig is an American actress and flmmaker. She was born in 1983 in Sacramento, California,and raised in Stanford, California and New York City. Gerwig has appeared in such movies as Greenberg,Frances Ha,and Jackie.She also portrayed the title role in the 2013 film of Jackie Kennedy. Her directorial debut is the 2O12 movie,Lady Bird,which was nominated for the Academy Award for Best Picture.</td></tr></table>", "page_idx": 15 }]md/train/B1lnzn0ctQ/B1lnzn0ctQ.mdAdded
md/train/Bw7VC-DJUM/Bw7VC-DJUM.mdAdded+343
md/train/XQQA6-So14/XQQA6-So14.mdAdded+530
md/train/qmI0P1ZExUl/qmI0P1ZExUl.mdAdded+321
md/train/rkEfPeZRb/rkEfPeZRb.mdAdded+233
md/train/ry2YOrcge/ry2YOrcge.mdAdded+270
md/train/vrhNQ7aYSdr/vrhNQ7aYSdr.mdAdded+274
parse/test/4WnqRR915j/4WnqRR915j.mdAdded+539
parse/test/4WnqRR915j/4WnqRR915j_content_list.jsonAdded
parse/test/4WnqRR915j/4WnqRR915j_middle.jsonAdded
parse/test/4WnqRR915j/4WnqRR915j_model.jsonAdded
parse/test/8dkp41et6U/8dkp41et6U.mdAdded+378
parse/test/8dkp41et6U/8dkp41et6U_content_list.jsonAdded
parse/test/8dkp41et6U/8dkp41et6U_middle.jsonAdded
parse/test/8dkp41et6U/8dkp41et6U_model.jsonAdded
parse/test/AqN23oqraW/AqN23oqraW.mdAdded
parse/test/AqN23oqraW/AqN23oqraW_content_list.jsonAdded
parse/test/AqN23oqraW/AqN23oqraW_middle.jsonAdded
parse/test/AqN23oqraW/AqN23oqraW_model.jsonAdded
parse/test/FAO4VS9QRV/FAO4VS9QRV.mdAdded+352
parse/test/FAO4VS9QRV/FAO4VS9QRV_content_list.jsonAdded+811
parse/test/FAO4VS9QRV/FAO4VS9QRV_middle.jsonAdded
parse/test/FAO4VS9QRV/FAO4VS9QRV_model.jsonAdded
parse/test/QAwaaLJNCk/QAwaaLJNCk.mdAdded
parse/test/QAwaaLJNCk/QAwaaLJNCk_content_list.jsonAdded
parse/test/QAwaaLJNCk/QAwaaLJNCk_middle.jsonAdded
parse/test/QAwaaLJNCk/QAwaaLJNCk_model.jsonAdded
parse/test/VP20ZB6DHL/VP20ZB6DHL.mdAdded+352
parse/test/VP20ZB6DHL/VP20ZB6DHL_content_list.jsonAdded+819
parse/test/VP20ZB6DHL/VP20ZB6DHL_middle.jsonAdded
parse/test/VP20ZB6DHL/VP20ZB6DHL_model.jsonAdded
parse/test/WPZ2yPag4K/WPZ2yPag4K.mdAdded+241
parse/test/WPZ2yPag4K/WPZ2yPag4K_content_list.jsonAdded+598
parse/test/WPZ2yPag4K/WPZ2yPag4K_middle.jsonAdded
parse/test/WPZ2yPag4K/WPZ2yPag4K_model.jsonAdded
parse/test/aKkAwZB6JV/aKkAwZB6JV.mdAdded
parse/test/aKkAwZB6JV/aKkAwZB6JV_content_list.jsonAdded
parse/test/aKkAwZB6JV/aKkAwZB6JV_middle.jsonAdded
parse/test/aKkAwZB6JV/aKkAwZB6JV_model.jsonAdded
parse/test/b4tMhpN0JC/b4tMhpN0JC.mdAdded
parse/test/b4tMhpN0JC/b4tMhpN0JC_content_list.jsonAdded
parse/test/b4tMhpN0JC/b4tMhpN0JC_middle.jsonAdded
parse/test/b4tMhpN0JC/b4tMhpN0JC_model.jsonAdded
parse/test/hUgBU9wgSf/hUgBU9wgSf.mdAdded
parse/test/hUgBU9wgSf/hUgBU9wgSf_content_list.jsonAdded
parse/test/hUgBU9wgSf/hUgBU9wgSf_middle.jsonAdded
parse/test/ttMwEuEPeB/ttMwEuEPeB.mdAdded
parse/test/ttMwEuEPeB/ttMwEuEPeB_content_list.jsonAdded
parse/test/ttMwEuEPeB/ttMwEuEPeB_middle.jsonAdded
parse/test/ttMwEuEPeB/ttMwEuEPeB_model.jsonAdded