Computer Science
Computer Science-2021.gz:143245
Computer Science
eb71ca97e37968aaccea3fd85e3f304a92bb1f90
Supervising the Transfer of Reasoning Patterns in VQA

Methods for Visual Question Anwering (VQA) are notorious for leveraging dataset biases rather than performing reasoning, hindering generalization. It has been recently shown that better reasoning patterns emerge in attention layers of a state-of-the-art VQA model when they are trained on perfect (oracle) visual inputs. This provides evidence that deep neural networks can learn to reason when training conditions are favorable enough. However, transferring this learned knowledge to deployable models is a challenge, as much of it is lost during the transfer. We propose a method for knowledge transfer based on a regularization term in our loss function, supervising the sequence of required reasoning operations. We provide a theoretical analysis based on PAC-learning, showing that such program prediction can lead to decreased sample complexity under mild hypotheses. We also demonstrate the effectiveness of this approach experimentally on the GQA dataset and show its complementarity to BERT-like self-supervised pre-training.


Introduction
Reasoning over images is the main goal of Visual Question Anwering (VQA), a task where a model is asked to answer questions over images. This problem is a test bed for the creation of agents capable of high-level reasoning, as it involves multi-modal and high-dimensional data as well as complex decision functions requiring latent representations and multiple hops. State-of-the-art models are notorious for leveraging dataset biases and shortcuts in learning rather than performing reasoning, leading to lack of generalization, as evidenced by extensive recent work on bias oriented benchmarks for vision-and-language reasoning [1,22,23,37]. Even large-scale semi-supervised pre-training methods, which successfully managed to increase overall VQA performance, still struggle to address questions whose answers are rare given a context [22]. It has been recently shown that reasoning patterns emerge in attention layers of a SOTA VQA model when trained on perfect (oracle) visual inputs, which provides evidence that deep neural networks can learn to reason, when training conditions are favorable enough [23]. In particular, uncertainty and noise in visual inputs seems to be a major cause for shortcut learning in VQA. While this kind of methods provide strong empirical results and insights on the bottlenecks in problems involving learning to reason, they still suffer from significant loss in reasoning capabilities during the transfer phase, when the model is required to adapt from perfectly clean visual input to the noisy input it will encounter after deployment. We conjecture, that reasoning on noisy data involves additional functional components not necessary in the clean case due to different types of domain shifts: (1) a presence shift, caused by imperfect object detectors, leading to missing visual objects necessary for reasoning, or to multiple (duplicate) detections; (2) an appearance shift causing variations in object embeddings (descriptors) for the same class of objects due to different appearance.
In this paper, we propose a new method for transferring reasoning patterns from models learned on perfect visual input to models trained on noisy visual representations. Key to the success is a regularization term minimizing loss of the reasoning capabilities during transfer. In particular, we address this problem through program prediction as an additional auxiliary loss, i.e. supervision of the sequence of reasoning operations along with their textual and/or visual arguments. To maintain a strong link between the learned function and its objective during the knowledge transfer phase, when inputs are switched from clean oracle inputs to noisy input, the neural model is required to continue to predict complex reasoning programs from different types of inputs.
As a second justification, we claim that program supervision in itself leads to a simpler learning problem, as the underlying reasoning function is decomposed into a set of tasks, each of which is easier to learn individually than the full joint decision function. We backup this claim through a theoretical analysis showing decreased sample complexity under mild hypotheses.
In an experimental study, we demonstrate the effectiveness of this approach on the GQA dataset and show its complementarity when combined to BERT-like self-supervised pre-training [36,11].
As a summary, we present the following contributions: (i) we propose a new program supervision module added on top of vision-language transformer models; (ii) we provide a theoretical analysis of the benefit of supervising program prediction in VQA deriving bounds on sample complexity; (iii) we experimentally demonstrate the efficiency of program supervision and show that it increases VQA performance on both in-and out-of-distribution sets, even when combined with BERT-like pre-training [36,11], and that it improves the quality of oracle transfer initially proposed by [23].

Related Work
Transformers in VQA -VQA as a task was introduced in various datasets [4,13,18], including GQA [17] which is automatically-generated from real-world images. This growing amount of diverse datasets has been accompanied by the development of more and more sophisticated VQA models. While their exhaustive survey is out of the scope of this paper, one can mention some foundational categories of approaches, e.g. those based on object-level attention [2] and tensor decomposition [6].
In this work, we focus on VQA models which are based on Transformers [40], due to their wide adoption and their impressive results in several tasks (including VQA). In particular, we rely on the combination of Transformers with a large-scale BERT [11]-like pretraining which was shown to be beneficial for VQA in recent works [21,36]. More recently, [23] focused on the study of so-called reasoning patterns in such Transformer-based VQA models. The authors analyzed how various VQA tasks are encoded in different attention heads, by applying an energy-based analysis inspired by [30]. The analysis was performed using a perfect-sighted oracle Transformer model (which is trained with near-to-perfect visual information, and thus, is much less prone to exploit dataset biases) in order to identify which patterns lead to better reasoning. Then, the authors showed that these reasoning patterns can be transferred from the oracle to a Transformer-based VQA model, thus improving both overall accuracy and accuracy on infrequent answers. In this work, we argue that using program prediction as an additional supervision signal is a catalyst for the transfer of these reasoning patterns.
Biases and shortcut learning in VQA -In addition to the popular VQA datasets mentioned above, other benchmarks were proposed to evaluate specific reasoning capabilities of VQA systems. In particular, they address the issue of shortcut learning [12] in deep learning, where models learn decision rules which are ineffective when tested on a domain or distribution different from the training one. For instance, VQA-CP [1] explicitly inverts the answer distribution between train and test splits.
To cope with recent criticisms regarding these evaluations [38,34], the GQA-OOD dataset [20] introduced a new split of GQA focusing on rare (Out-Of-Distribution / OOD) question-answer pairs, and showed that many VQA models strongly rely on dataset biases. Following this work, the VQA-CE dataset [9] introduced a new evaluation approach related to the VQA v2 dataset. By studying the multi-modal shortcuts in the training set and mining some trivial predictive rules (e.g. co-occurrences of words and visual objects), the evaluation set is generated using questions where these mined rules lead to incorrect answers. As for GQA-OOD, this dataset demonstrated that SOTA models do not perform well when they can't rely on shortcuts, even models which use bias-reduction techniques. Based on these benchmarks, several methods have been conceived to reduce shortcut learning in VQA (see [38,35] for a comprehensive study of the different techniques). However none of them achieve significant performance improvement on GQA-OOD [20] or VQA-CE [9].
Connections with symbolic VQA -Our work is also related to neuro-symbolic reasoning [42,29] and neural module networks (NMN) [3,15], which generally encode a set of pre-defined functions into unique neural modules, then dynamically compose them to execute question-related programs. Several improvements of standard NMNs have been proposed to make them end-to-end trainable through reinforcement learning [19] or, more recently, to enhance their scalability and generalizability [7]. However, the common point of all these works is that they are generally based on the prediction of reasoning programs whose elementary functions are learned jointly with program prediction itself, through program supervision. In contrast to this work, our approach uses program supervision to enrich its internal representations instead of inferring program's execution.
Measuring complexity of learning problems -and thus generalization, has been a goal of theoretical machine learning since the early days, with a large body of work based on PAC-Learning [39,33]. Traditionally, bounds have been provided ignoring data distributions and focusing uniquely on hypothesis classes (network structures in neural network language), e.g. as measured by VCdimension. Surprising experimental results on training networks on random samples have seemingly contradicted learning theory [44], in particular Rademacher Complexity. Recently, building on statistics of gradient descent, bounds have been proposed which take into account data distributions, notably [32]. Algorithmic alignment between neural network structures and the decomposition of underlying reasoning functions has been studied in [41], with a focus on algorithms based on dynamic programming. Our theoretical contribution in section 4 builds on the latter two methodologies and extends this type of analysis to intermediate supervision of reasoning programs.

Knowledge transfer and program supervision
We propose a method for transferring reasoning patterns from models learned on perfect visual inputs to models trained on noisy visual representations. In the lines of oracle transfer [23], we first pre-train a model on ground-truth visual data and then fine-tune on standard visual embeddings extracted with an object detector. The underlying hypothesis is that the noise and uncertainty in visual input prevents the model from learning to reason and leads to learning shortcuts. The decoder is fed with the VL-Transformer's penultimate embedding (just before the VQA classification head) and generates programs using a coarse-to-fine approach: a coarse program is generated using a GRU, consisting of a sequence of program operations embeddings {o i } i∈[0,n−1] . It is then re-fined by predicting the visual a v ij and textual a q ij arguments using an affinity score between operation and input embeddings. Not shown: prediction of the operation's dependencies.
To minimize the loss of reasoning capabilities during the transfer over the presence shift between oracle and noisy visual objects, we propose a regularization technique, which supervises the prediction of reasoning steps required to answer the question. We therefore assume the existence of the following ground truth annotation of reasoning programs. A given data sample consists of a sequence {q i } of input question word embeddings, a set {v i } of input visual objects, the ground truth answer class y * as well as the groundtruth reasoning program, which is structured as a tree involving operations and arguments. Operations {o * i } are elements of a predefined set {choose color, filter size, ...}. The arguments of these operations may be taken from (i) all question words, (ii) all visual objects, (iii) all operations -when an operation takes as argument the result of another operation. Hence, arguments are annotated as many-to-many relationships. In the question "Is there a motorbike or a plane?", for instance, the operation "or" depends on the result of the two operations checking the existence of a specific object in the image. This is denoted as a q * ij ∈{0, 1} where a q * ij =1 means that operation i is associated with question word j as argument and, similarly, a v * ij =1 indicating a visual argument and a d * ij =1 an operation result argument. We propose to apply the regularization on top of the VL-Transformer architecture proposed in [36], based on sequences of self-and cross-modality attention. For this purpose, we define a trainable module for program generation (program decoder), added to the output of the VL-Transformer model as shown in Fig. 2 -an adaptation to other architectures would be straightforward.
Program decoder -In the lines of [7], the program decoder has been designed in a coarse-to-fine fashion. It first generates a coarse sketch of the program consisting only of the operations, which are then refined by predicting textual and visual arguments and dependencies between operations.
Coarse: operation -this module only predicts the sequence of operations {o i } i∈[0,n−1] using a recurrent neural network (RNN / GRU) [8] variant, whose initial hidden state is initialized with the y CLS token embedding of the VQA transformer -the same embedding from which classically the final answer y is predicted, cf. Figure 2. Inference is stopped when the special "STOP" operation is predicted. At each GRU time step i, a new hidden state h i is computed, from which the operation o i is classified with a linear projection. It is supervised with a cross-entropy loss . Fine: input arguments -the coarse program is then refined by predicting the operations' arguments. We first deal with textual and visual arguments only. Affinity scores a q ij between each operation's hidden embedding h i and each token embedding q j are computed with a 2-layer feedforward network from concatenated embeddings. They represent the probability of the word q j to belong to the argument set of operation o i . Similar scores a v ij are computed for operations and visual objects. They are supervised with BCE losses L qarg = ij L BCE (a q ij , a q * ij ) and L varg = ij L BCE (a v ij , a v * ij ). Fine: op arguments -next the dependencies are predicted, i.e. arguments which correspond to results of other operations, and which structure the program into a tree. We deal with these arguments differently, and compute the set of dependency arguments for each operation o i with another GRU, whose hidden state is initialized with the hidden state h i of the operation. The argument index a d ij is a linear projection of the hidden state and supervised with BCE: . Program supervision -The coarse-to-fine program decoder is trained with the four additional losses weighted by hyperparameters α, β, γ, δ.
Ground truth programs -We use ground truth information from the GQA [17] dataset, whose questions have been automatically generated from real images. Each sample contains a program describing the operations and arguments required to derive the answer for each question. However, the GT programs have been created for GT visual arguments (GT objects), which do not exactly match the visual input of an object detector used during training and inference [2]. We therefore construct a soft target, by computing intersection-over-union (IoU) between GT and detected objects.
Oracle transfer -Our method uses program supervision to regularize knowledge transfer from a visual oracle to noisy input, as introduced in [23]. Oracle transfer consists in pretraining the VL-Transformer model on ground-truth one-hot visual inputs before performing BERT-like pre-training. It offers training conditions which are more favorable for learning reasoning capabilities. We perform the following steps: (1) Oracle pre-training on GT visual input on the GQA dataset; (2) (optionally) BERT-like pre-training on data from GQA unbalanced; (3) Finetuning on the final VQA-objective on the GQA dataset. Each one of these steps are regularized using program supervision.

Sample complexity of program supervision
We provide a theoretical analysis indicating that the prediction and supervision of reasoning programs can improve learnability in vision and language reasoning under some assumptions. In what follows, we denote with g "true" (but unknown) underlying reasoning functions, and by f functions approximating them, implemented as neural networks. The goal is to learn a function g able to predict a distribution y over answer classes given an input question and an input image, see Fig 1a. While in the experimental part we use state-of-the-art tranformer based models, in this theoretical analysis, we consider a simplified model, which takes as input the two vectorial embeddings q and v corresponding to, respectively, the question and the visual information (image), for instance generated by a language model and a convolutional neural network, and produces answers y * = g(q, v).
We restrict this analysis to two-layer MLPs, as they are easier to handle theoretically than modern attention based models. The reasoning function g is approximated by neural network f parametrized by a vector θ and which predicts output answers y = f (q, v, θ).
Our analysis uses PAC-learning [39] and builds on recent results providing bounds on sample complexity taking into account the data distribution itself. We here briefly reproduce Theorem 3.5. from paper [41], which, as an extension of a result in [32], provides a bound for sample complexity of overparametrized MLPs with vectorial outputs, i.e. MLPs with sufficient capacity for learning a given task: Theorem 4.1 (Sample complexity for overparametrized MLPs). Let A be an overparametrized and randomly initialized two-layer MLP trained with gradient descent for a sufficient number of iterations.
We use the following Ansatz: since each possible input question requires a potentially different form of reasoning over the visual content, our analysis is based on the following assumption. Assumption 1. The unknown reasoning function g() is a mixture model which decomposes as follows where the different mixture components r correspond to different forms of reasoning related to different questions. The mixture components can reason on the visual input only, and the mixture weights are determined by the question q, i.e. the weights π depend on the question q, e.g. π = g π (q).
We call g π (.) the reasoning mode estimator. One hypothesis underlying this analysis is that learning to predict reasoning programs allows the model to more easily decompose into this form (3), i.e. that the network structure closely mimicks this decomposition, as information on the different reasoning modes r is likely to be available in the activations of intermediate layers, cf. Figure 1. This will be formalized in assumption 3 and justified further below.
Considering the supposed "true" reasoning function y * = g(q, v) and its decomposition given in (3), we suppose that each individual reasoning module g r can be approximated with a multi-variate polynomial, in particular each component h (i) r of the vector h r , as A trivial lower bound on the complexity of the reasoning mode estimator g π (.) is the complexity of the identity function, which is obtained in the highly unlikely case where the question embeddings q contain the 1-in-K encoding of the choice of reasoning mode r. We adopt a more realistic case as the following assumption. Assumption 2. The input question embeddings q are separated into clusters according to reasoning modes r, such that the underlying reasoning mode estimator g π can be realized as a NN classifier with dot-product similarity in this embedding space.
Under this assumption, the reasoning mode estimator can be expressed as a generalized linear model, i.e. a linear function followed by a soft-max σ, where the different γ r are the cluster centers of the different reasoning modes r in the question embedding space. As the softmax is a monotonic non-linear function, its removal will not decrease sample complexity 2 , and the complexity can be bounded by the logits π r = γ T r q. Plugging this into (3) we obtain that each component y * (i) of the answer is expressed as the following function: We can reparametrize this function by concatenating the question q and the visual input v into a single input vector x, which are then masked by two different binary masks, which can be subsumed into the parameters γ r and β (i) r,j , respectively, giving Extending Theorem 3.5. from [41], we can give our main theoretical result as the sample complexity of this function expressed as the following theorem. Theorem 4.2 (Sample complexity for multi-mode reasoning functions). Let A be an overparametrized and randomly initialized two-layer MLP trained with gradient descent for a sufficient number of iterations. Suppose g : r,j ∈ R, and p (i) r,j = 1 or p (i) r,j = 2l, l ∈ N + . The sample complexity C A (g, , δ) is The proof of this theorem is given in the supplementary material (Appendix A). Theorem 4.2 provides the sample complexity of the reasoning function g() under classical training. In the case of program supervision, our analysis is based on the following assumption (see also Fig.  1b): Assumption 3. Supervising reasoning programs encodes the choice of reasoning modes r into the hidden activations of the network f . Therefore, learning is separated into several different processes, (a) learning of the reasoning mode estimator g π () approximated as a network branch f π () connected to the program output; (b) learning of the the different reasoning modules g r () approximated as network branches f r () connected to the different answer classes y r ; each one of these modules is learned independently.
We justify Assumption 3.a through supervision directly, which separates g π () from the rest of the reasoning process. We justify Assumption 3.b by the fact, that different reasoning modes r will lead to different hidden activations of the network. Later layers will therefore see different inputs for different modes r, and selector neurons can identify responsible inputs for each branch f r (), effectively switching off irrelevant input.
We can see that these complexities are lower than the sample complexity of the full reasoning function given in theorem 4.2, since for a given combination of i, r, j, the term ||γ r || 2 ·||β r,j || p (i) r,j 2 dominates the corresponding term ||β r,j || p (i) r,j 2 . Let us recall that the different vectors γ correspond to the cluster centers of reasoning modes in language embedding space. Under the assumption that the language embeddings q have been created with batch normalization, a standard technique in neural vision and language models, each value γ (i) r follows a normal distribution N (0, 1). Dropping indices i, r, j to ease notation, we can then compare the expectation of the term ||γ|| 2 ·||β|| p 2 over the distribution of γ and derive the following relationship: where Γ is the Gamma special function and m is the dimension of the language embedding γ. We provide a proof for this equality in the supplementary material (Appendix A).
Discussion and validity of our claims -the difference in sample complexity is determined by the factor C in equation (8), which monotonically grows with the size of the embedding space m, which is typically in the hundreds. For the order of m=512 to m=768 used for state-of-the-art LXMERT models [36], complexity grows by a factor of around ∼20.
We would like to point out, that this analysis very probably under-estimates the difference in complexity, as the difference very much depends on the complexity of the reasoning estimator π, which we have simplified as a linear function in equation (5). Taking into account just the necessary soft-max alone would probably better appreciate the difference in complexity between the two methods, which we leave for future work. Our analysis is also based on several assumptions, among which is the simplified model (an over-parametrized MLP instead of an attention based network), as well as assumptions of Theorem 4.2 from [41] and [32], on which our analysis is based.
Lastly, we would like to comment on the fact that we compare two different bounds: (i) the bound on sample complexity for learning the full multi-modal reasoning given in Theorem 4.2, and (ii) the bound for learning a single reasoning mode given by Theorem 4.1. While comparing bounds does not provide definitive answers on the order of models, both bounds have been derived by the same algebraic manipulations and we claim that they are comparable.

Experimental results
Setup + architecture: -we perform our experiments with a compact version of the Vision-Language (VL)-Tansformer used in [36] (cf. Fig. 2 Table 3: We study the impact of the program supervision posistion: after uni-modal layers or after cross-modal layers (standard configuration). The supervision is more efficient when used after cross-modal interactions. Setting=oracle transfer, no lxmert balanced GQA [17] training set (∼1M question-answer pairs). However, LXMERT pretraining is done on the unbalanced training set (∼15M question-answer pairs). The latter contains more questions and programs, but the same number of images (∼100K images). Evaluation: is performed on GQA [17] and GQA-OOD [20] test sets. GQA is a dataset with question-answer pairs automatically generated from real images, and is particularly well suited for evaluating a large variety of reasoning skills. GQA-OOD is a benchmark dedicated to the out-of-domain VQA evaluation, and gives information on the generalization capabilities of the model. Hyper-parameters are selected either on the testdev (for GQA) or validation (for GQA-OOD) sets. When specified (with ±) we provide the average accuracy and standard deviation computed on three runs with different random seeds. Visual input: following [2], we use bottom-up visual features extracted using a pre-trained object detector (we keep its parameters frozen during the training). If not specified, we use faster-RCNN [31] with 36 objects per-images. In addition to that, we experiment with designed objects, and also with the VinVL [45] features which (unlike faster-RCNN ones) are conceived specifically for vision-language tasks.
Program supervision improves visual reasoning -Tab. 1 reports the effectiveness of program prediction when combined with oracle and BERT-like pretraining on the GQA dataset and corroborates the results found in the theoretical analysis. In addition, when using both program supervision and LXMERT [36] but without oracle transfer, we achieve an accuracy of 58.8 on the testdev set of GQA. This is lower than oracle transfer's accuracy, demonstrating the complementary of the two methods. We note that the majority of the gain is achieved on the more challenging open questions. In addition, results on GQA-OOD (acc-tail and acc-head) suggest that the gains are obtained in, both, out-and in-distribution settings. However, as already observed in [23], LXMERT pre-training tends to decrease the acc-tail gains brought by oracle transfer plus program supervision. We evaluate the program prediction performance by measuring the area under the ROC curve (AUC) on the visual argument prediction with an IoU treshold of 2 3 =0.66. Models (c) and (e) achieve, respectively, 97.1 and 96.4 AUC scores, demonstrating the effectiveness of the program decoder.
Visual arguments are the key -We study the impact of different types of program supervision in Tab. 2. We can see the importance of supervising arguments, in (4) and (5). The supervision of visual arguments (5) contributes most to the gain in performance, again corroborating that visual uncertainty is the main bottleneck for reasoning on the GQA dataset.
Program supervision enhances cross-modal interactions -In Tab. 3, we study how the inputs of the program prediction module influence the VQA accuracy. In particular, we test two settings: (   uni-modal, where the programs are predicted from the vision and language embeddings right after the uni-modal layers (language and vision only in Fig. 2); and (8) cross-modal, where the programs are predicted after the cross-modal layers (as shown in Fig. 2). We observe that, contrary to the latter, the former does not improve the baseline ((7) vs (6) in Tab. 3). This highlights the fact that the program supervision mainly impacts the operations in the cross modal layers, where the most complex reasoning operations are performed.
Program supervision allows to take advantage of the improved visual inputs -We analyse the impact of using our method with a better input image representation. Increasing the number of objects from 36 to 100 per image ((g) and (h) in Tab. 4), allows to further increase the gains brought by our method. On the contrary, the score of the baseline model remains unchanged, showing that the program supervision allows to take advantage of a bigger number of object proposals. Similarly, replacing the faster-RCNN features by the more recent and more accurate VinVL ones ((i)-(l) in Tab. 4) results in better performances.
Comparison with SOTA -We report in Tab. 5 the results obtained by our approach compared to the current SOTA on the GQA and GQA-OOD datasets. In order to ensure a fair comparison, we also provide, for each method, information regarding the amount of data (images and sentences) used during training. As shown in Tab. 5, our approach compares favourably with SOTA since it obtains the second best accuracy (with a 0.2 points gap) on the GQA test-std set among the approaches which not use extra training data. The results also remain competitive when comparing to the OSCAR+VinVL [45], while being trained with 50 times less images. On GQA-OOD, our approach obtains the second best acc-tail score (and the best acc-head one) with a much less complex architecture than current SOTA (26M vs 212M trainable parameters compared to LXMERT [36]).

Conclusion
We have demonstrated that it is possible to improve the reasoning abilities of VQA models when providing additional supervision of program annotations. In particular, our method is designed to improve the transfer of reasoning patterns from models learned on perfect visual input to models trained on noisy visual representations. Our experiments are supported by a theoretical analysis, demonstrating that program supervision can decrease sample complexity under reasonable hypothesis. The proposed method relies on the availability of reasoning program annotations, which are costly to annotate, especially when dealing with human generated questions. Recent work has already managed to gather such kind of annotations [10]. The next step will be to extend the method to configurations where the program annotation is rare or incomplete.
Broader Impact -Beyond the exciting scientific reasons for exploring work on visual reasoning, we welcome the potentially high interest for society in VQA systems targeting increased accessibility.
As an example, we have tools in mind, which allow the visually impaired to query their environment based on visual information from a wearable camera. We are currently not aware of existing applications abusing VQA systems for unethical goals. Potential future unethical abuse, generally and beyond our contribution, could involve their use to automatic solving of Captchas (automatic Turing tests), and the creation of false dialogs and discussions in online forums ("troll farms") requiring the examination of posted text as well as accompanying images. The latter is a risk inherent to any powerful system capable of predicting text, but for the moment does not realistically apply to VQA, where very short answers are predicted through classification over the full answer dictionary (even though our contribution is independent of the chosen VQA model).

Supplementary Material A Proofs of Section 4
A.1 Proof of theorem 4.2 For the unfamiliar reader, we here briefly recall the notion of sample complexity, in the context of PAC-learning [39], which characterizes the minimum amount (=M ) of samples necessary to learn a function with sufficiently low (= ) error with sufficiently high (= δ) probability: Definition A.1 (Sample complexity). Given an error threshold >0; a threshold on error probability δ; a training set S = {x i , y i } of M i.i.d. training samples from D, generated from some underlying true function y i = g(x i ), and a learning algorithm A, which generates a function f from training data, e.g. f = A(S); Then g is (M, , δ)-learnable by A if The case of scalar outputs In the lines of [32], we first define the case for a single component y (i) of the vector y and define the following Corollary: Corollary 0.1 (Sample complexity for multi-mode reasoning functions with a single scalar component). Let A be an overparametrized and randomly initialized two-layer MLP trained with gradient descent for a sufficient number of iterations. Suppose g : and p r,j = 1 or p r,j = 2l, l ∈ N + . The sample complexity C A (g, , δ) is Proof of Corollary 0.1: Using Theorem 5.1 from [32], we know that sums of learnable functions are learnable, and can thus focus on a single term where we dropped indices r and j and the superscript (i) for convenience.
We proceed in the lines of the proof of Theorem 5.1 in [32]. Given a set of i.i.d data samples S = {(x s , y s )} n s=1 = (X, y) from the underlying function g(x), let w be the weights of the first layer of two layer network with ReLu activations; let H ∞ ∈ R n,n be a Gram matrix defined as follows, with elements To provide bounds on the sample complexity of g(x), using Theorem 5.1 of [32], it suffices to show that the following bound holds for a bound M g independent of the number of samples n. From the proof of Theorem 5.1 in [32], we also know that where K = X T X, and X is the data matrix of all row vectors x i .
Let us consider the case of p = 1. Reformulating equation (10), we get: Now, taking the full set of input vectors x i arranged into the full data matrix X, we can perform similar algebraic operations to get Plugging (15) and (16) into (11), we need to show that the following expression is smaller than a constant M g : where we made use of ||a⊗b|| 2 2 = ||a|| 2 2 ||b|| 2 2 for two vectors a and b and an integer n. This finishes the proof for the case p = 1.
This finishes the proof for the case p = 2l+1.
The case of vectorial outputs In the lines of [41], we consider each component of the output vector independent and apply an union bound to Corollary 0.1. If the individual components y (i) fail to learn with probability δ 0 , then the full output of dimension m fails with probability mδ 0 and with an error of at most m 0 . A change of variables from ( 0 , δ 0 ) to ( , δ) gives a complexity for the model with vectorial output of This ends the proof of Theorem 4.2.
A.2 Proof of the inequality in Eq. (8) Let us denote by p(x) the density of normal distribution. And to make the notation more succinct and to avoid confusion between different usages of superscripts, in this proof we will change γ i r to γ i , i.e. the i th component of the vector γ, not to be confused with γ r , a vector corresponding to the embedding of the r th reasoning mode. Then, We now perform a change of variables and introduce a new random variable Since each individual γ i is distributed normal, z is distributed according to a χ 2 distribution with m degrees of freedom, and we get The expectation now corresponds to 1 2 th centered moment of the χ 2 distribution with m degrees of freedom, whose k th moments are given as This ends the proof of the equality.

B Program decoder
We provide more details on the program decoder architecture. The hidden size is set to 128 (same as in the VL-Transformer). We use GeLU [14] as non linearity, along with layernorm [5].
Operations The maximum number of operations in one program is set to N maxop = 9. The total number of operation's labels is N op = 212. We use a one layer GRU [8] with hidden size equals to 128, to infer the operation's hidden embedding h i . It is followed by a two layers MLP (128 → 64 → N op , projecting h i into a one-hot vector o i . Arguments Affinity scores a q ij between each operation's hidden embedding h i and each token embedding q j (or v j ) are computed with a 2-layer feed-forward network (256 → 64 → 1) from concatenated embeddings. The op arguments are predicted from h i using another one layer GRU with hidden size equals to 128 followed by a nonlinear projection (128 → N maxop ). Hyper-parameters are set to α = 1, β = 1, γ = 1 and δ = 100.

C Training details
Architecture: Our VQA architecture is a compact version of the VL-Transformer introduced in [36] 3 . In particular, it has 9 language only layers, 5 vision only layers, and 5 cross modal layers. The hidden size is set to 128. In total, this compact version has 26M parameters, allowing to reduce computation time and memory overhead.
Optimizer: All models were trained with the Adam optimizer [25], a learning rate of 10 −4 with warm starting and learning rate decay.
Oracle transfer: is performed following [23]. First, the oracle model is trained during at most 40 epochs on the GQA balanced training set with ground-truth image representation. Then we continue the training during 10 epochs, with visual features extracted using an object detector. We use a batch size equals to 196 (96 when using VinVL features).
BERT/LXMERT [36] pretraining is performed during 20 epochs with a batch size of 320 (256 when using VinVL features). All pretraining losses are added from the beginning, including the VQA one. Note that LXMERT [36] is originally pre-trained on a corpus gathering images and sentences from MSCOCO [28] and VisualGenome [26]. In this work, we only train on the GQA [17] unbalanced set, with VisualGenome images. After pre-trainning, we finetune on the GQA [17] balanced set during 4 epochs, with a batch size of 32 and a learning rate equal to 10 −5 .

D Computing resources
Training and evaluation has been performed on several compute infrastructures, which include an Nvidia DGX-A100 with 8× A100 GPUs and a cluster with P100 and RTX 2080 GPUs. After design and development, the final training and evaluation runs have been performed on Geforce RTX 2080 GPUs. We provide an estimate for the amount of compute in Table 6 -the number of GPUs and approximate execution times for different models and experimental settings (train, validation and test).

C02 Emission
The RTX infrastructure has a carbon efficiency of 0.035 kgCO 2 eq/kWh. A cumulative of 6500 hours of computation was performed on hardware of type RTX 2080 (TDP of 215W). Total emissions are estimated to be 48.9 kgCO 2 eq . Estimations were conducted using the https://mlco2.github.io/impact#compute presented in [27].

E Visualisation of predictions
We provide example of program prediction in Fig. 3 and 4. In Fig. 3, the question is 'does the boat to the left of the flag look small or large?'. The program decoder successfully infers the correct program. It first predicts the coarse operationsselect, relate, choose size -, then adds the arguments taken from the image or the question -boat, flag, small, large -. Finally, the VQA model predicts the correct answer 'small'. In Fig. 4, the question is 'who is wearing goggles?'. Similarly to the first example, the program decoder generates coarse operationsselect, relate, query name -and visual/textual arguments -woman, who, goggles, wearing-. In these two examples, the decoder correctly predicts that the programs are chains of operations (special case of a tree). At contrary, a question like 'are there nuts or vegetables?' is a not a chain because of the presence of exist and or operations.
(  Table 7: Comparison with the random prog baseline, where we randomly replace the ground truth program with a program picked from another question (compact model, no LXMERT/BERT pretraining, no Oracle), on GQA val.

F Sanity check
As a sanity check, and to avoid the unfortunate result pinpointed in [34], we compare our model with a random baseline random prog. in Tab. 7. In random prog., we randomly replace the ground truth program with a program picked from another question, during the training. As expected, this random baseline achieves low performances.