SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Sparse coding using the IP-OMP algorithm. In the discussion so far between the equivalence of OMP and IP-OMP, we swept the issue of recovering the sparse code under the rug. To remind the reader, the goal of sparse coding is to find a code  $\hat{\beta}_{\mathrm{IP - OMP}}$  such that  $x\approx D\hat{\beta}_{\mathrm{IP - OMP}}$ . However, the IP-OMP updates do not explicitly provide a way of doing so. However, by analyzing IP-OMP's prediction of the target  $\langle x,Z\rangle$  we can derive  $\hat{\beta}_{\mathrm{IP - OMP}}$ .
Recall from §2.1 that after termination, IP's prediction is the mode of the posterior distribution. Thus after termination IP-OMP's prediction would be given by
$$
\max  _ {Z} P \left(\langle x, Z \rangle \mid \mathcal {H} _ {1: \tau}\right) = \left\langle D _ {\tau} D _ {\tau} ^ {\dagger} x, z ^ {0} \right\rangle , \tag {7}
$$
where  $\tau$  is the number of iterations before IP-OMP terminated,  $D_{\tau}$  is the sub-matrix of  $D$  consisting of the atoms selected in the first  $\tau$  iterations,  $\dagger$  represents the pseudo-inverse, and  $z^0$  is the realization of  $Z$  that determines the outcomes of all the query answers and the target (which is  $\langle x,Z\rangle = \langle x,z^0\rangle$ ). Refer to Appendix §A.3 for a proof of equation 7. Next, notice that the query selection in IP-OMP is independent of the realization of  $Z$ , which implies that the sequence of queries selected in the first  $\tau$  iterations would depend solely on  $x$ . This implies the following lemma,
Lemma 2. For all  $z \in \mathbb{R}^m$ , IP-OMP's prediction of the target is given by  $\langle D_{\tau}D_{\tau}^{\dagger}x,z\rangle$
Refer to Appendix §A.4 for a proof. Taking  $z = e_i$ , the  $i^{\text{th}}$  canonical basis vector in  $\mathbb{R}^m$ , we observe that IP-OMP's prediction of the  $i^{\text{th}}$  component of  $x$ , denoted as  $x_i$ , is  $(D_{\tau}D_{\tau}^{\dagger}x)_i$ . Hence, we conclude
$$
x \approx D _ {\tau} D _ {\tau} ^ {\dagger} x = \overbrace {\left[ D _ {\tau} D _ {- \tau} \right]} ^ {D} \overbrace {\binom {D _ {\tau} ^ {\dagger} x} {0}} ^ {\hat {\beta} _ {\mathrm {I P - O M P}}} \Rightarrow \hat {\beta} _ {\mathrm {I P - O M P}} = \binom {D _ {\tau} ^ {\dagger} x} {0}, \tag {8}
$$
where  $D_{-\tau}$  is the matrix comprised of atoms of  $D$  not selected by IP-OMP in the first  $\tau$  iterations. Comparing with equation 3, we see that this is analogous to the sparse code estimate OMP obtains after  $\tau$  iterations, with the  $D_{\tau}$  matrix now replaced with the atoms selected by OMP.
IP-OMP  $\equiv$  OMP. Recall the only difference between IP-OMP and OMP is the normalization step after the dot product. We carry out synthetic experiments to investigate the effect of this normalization factor on the practical performance of IP-OMP vs. OMP in sparse code recovery. We first consider the noiseless case (equation 2) and later investigate the scenario where signals are corrupted by noise.
For the noiseless case, we conduct the following experiment. Fix  $n$ , the dimension of the sparse code,  $m$  the dimension of the observed signal, and  $s$  the sparsity level. Generate a large number of random dictionaries, where each atom (column) is sampled from the uniform distribution on the unit sphere in  $\mathbb{R}^m$ . For every dictionary, pick a subset of  $s$  (out of  $n$ ) atoms uniformly at random and simulate the coefficients for each of the selected atoms from the standard normal distribution. Set all the remaining coefficients to 0. These coefficients constitute the sampled sparse code. For each simulation, construct the observed signal  $x_o = D_o\beta_o$ , where  $D_o$  is the sampled random dictionary and  $\beta_o$  is the sampled sparse code. For every  $x_o$ , we carry out both OMP and IP-OMP and measure their performance in terms of the fraction of simulations in which the algorithm exactly recovered the sparse code  $\beta_o$ . We define exact recovery when the normalized mean-squared error (NMSE)
$$
\mathrm {N M S E} \left(\hat {\beta} _ {\mathrm {A l g .}}, \beta_ {o}\right) = \| \hat {\beta} _ {\mathrm {A l g .}} - \beta_ {o} \| _ {2} ^ {2} / \| \beta_ {o} \| _ {2} ^ {2} \tag {9}
$$
Figure 3: Performance of OMP (solid curves) and IP-OMP (overlaid circles) in the case where signals are corrupted by noise. On the  $y$ -axis we report the mean NMSE, as defined in equation 9, averaged over 1000 trials. On the  $x$ -axis, we report the number of measurements (signal dimension)  $m$ . Each sub-figure corresponds to a fixed number of dictionary atoms  $n$  and a fixed expected signal-to-noise ratio  $\mathbb{E}[\mathrm{SNR}]$ . The top row shows results for small  $n$  (256), while the bottom shows results for large  $n$  (1024).
is approximately zero  $(< 10^{-14})$ , where the subscript  $\mathrm{Alg.}$  indicates the algorithm (OMP or IP-OMP). This experimental setup was inspired by [24]. Further details of the experiment can be found in Appendix §B. Figure 2 reports these results which indicate that OMP and IP-OMP achieve almost the same exact recovery rate over a variety of different values of  $(m,n,s)$ . In particular, both IP-OMP and OMP degrade similarly when the sparsity rate  $\frac{s}{m} \to 1$  or the measurement rate  $\frac{m}{n} \to 0$ .
For the noisy case, we extend equation 2 with additive Gaussian noise. Specifically, we consider the measurement model  $\widetilde{x} = D_o\beta_o + e$ , where  $D_o$  and  $\beta_o$  are sampled as described in the previous paragraph,  $\widetilde{x}$  is the noisy observed signal and  $e \sim \mathcal{N}(0,\sigma^2 I)$ . The noise variance  $\sigma^2$  was set to achieve particular values of the expected signal-to-noise ratio (SNR)
$$
\mathbb {E} [ \mathrm {S N R} ] = \mathbb {E} _ {D _ {o}, \beta_ {o}, e} \left[ \frac {\| D _ {o} \beta_ {o} \| _ {2} ^ {2}}{\| e \| _ {2} ^ {2}} \right]. \tag {10}
$$
Details on this calculation are provided in Appendix §B.3. We measure the quality of the estimates produced by OMP and IP-OMP by reporting the mean NMSE of their estimates,  $\hat{\beta}_{\mathrm{Alg}}$ , (taken over all the trials). Further details can be found in Appendix §B. Figure 3 shows that the empirical equivalence between OMP and IP-OMP is maintained over different values of  $(m,n,s,\mathbb{E}[\mathrm{SNR}])$ .
More results can be found in Appendix §B. Figure 2 and Figure 3 show that despite the extra normalization, IP-OMP and OMP have practically the same sparse code recovery rates for random Gaussian dictionaries, which are commonly studied in compressed sensing (see, e.g., [22, Ch. 9]).
Connection to Orthogonal Least Squares (OLS). Interestingly, the IP-OMP selection criterion (equation IP-OMP) results in greedily selecting the atom that maximally reduces the residual error [32]. Specifically, let  $D_{k}$  indicate the set of atoms from  $D$  obtained after  $k$  iterations of IP-OMP. Then, the atom  $d^{*}$  solving the following optimization problem
$$
\left(d ^ {*}, \hat {\beta} ^ {*}\right) = \underset {d \in D, \hat {\beta} \in \mathbb {R} ^ {k + 1}} {\arg \min } \| x - \left[ D _ {k} d \right] \hat {\beta} \| _ {2} ^ {2}, \tag {11}
$$
is equal to the arg max of the IP-OMP objective at iteration  $k + 1$ . Using this insight, multiple authors have proposed to modify OMP by replacing its atom selection criterion with equation 11 and have re-discovered this algorithm under different names [33] with OLS being one of them. In this paper, we coin the name IP-OMP to emphasize its derivation from information-theoretic principles.
Our results on the empirical equivalence between IP-OMP and OMP are complemented by prior investigations into the OLS algorithm which report similar conclusions using random Gaussian dictionaries [34, 35]. Theoretically, Soussen et al. [13] showed that both the algorithms share the same exact recovery conditions. This is made precise in Theorem 2 (a restatement of results in [13]).
Theorem 2. Given a dictionary  $D$  and support  $S$ , define  $\mathcal{B} = \{\beta \in \mathbb{R}^n : \operatorname{supp}(\beta) \subseteq S\}$ . Then IP-OMP recovers all  $\beta \in \mathcal{B}$  in at most  $s = |\mathcal{S}|$  iterations if and only if the same holds for OMP.
These results further strengthen our claim that for practical scenarios, the normalization factor in IP-OMP does not have a significant impact. We note in passing that, for certain "special" dictionaries in which the dictionary atoms are strongly correlated with each other, IP-OMP has been reported to outperform OMP in its ability to recover the sparse code [13, 34].
4 IP-OMP for Explainable Predictions for Visual Classification Tasks
Inspired by the recent application of IP [5] and its variant V-IP [15] to explainable AI, here we propose a simple explainable AI algorithm for visual classification tasks which uses IP-OMP to ask queries about the image. In §4.1 we briefly describe the V-IP framework, propose our CLIP-IP-OMP algorithm, and discuss the differences with V-IP. Then, in §4.2 we present experiments showing that CLIP-IP-OMP is computationally much cheaper than V-IP, while achieving a similar classification accuracy. Refer to Appendix §C for a review of prior work on explainable AI.
4.1 The CLIP-IP-OMP Algorithm
The V-IP algorithm. In V-IP, a user first specifies a query set, which is comprised of interpretable functions of the input. For example, if the task is animal classification, the questions could be about various animal attributes. V-IP then adaptively generates short query-answer chains that are sufficient for prediction. This is done by learning a querier and a classifier network simultaneously from data. The querier learns to select the most informative query given the history of query-answer pairs obtained so far, while the classifier learns to make predictions based on the same history. However, the number of possible histories (subsets of query-answer pairs) the querier and classifier have to learn is exponential in the size of the query set, making the training process very slow. In this paper, we propose an alternative algorithm which is computationally much cheaper.
The CLIP-IP-OMP algorithm. Analogously to V-IP's interpretable query sets, we propose to use dictionaries of interpretable atoms. For example, every atom of the dictionary could correspond to a text embedding [36] of a semantic concept relevant for the classification task. This poses a challenge, since images and text embeddings live in very different spaces (pixel space vs. the latent space of some deep network). To address this mismatch, we leverage CLIP [17], which learns to encode images and text into a shared latent space such that the dot products of their respective embeddings are reflective of how well the text describes the image contents. We propose the following algorithm for making explainable predictions for visual classification tasks:
1. Given a set of semantic concepts relevant to the classification task, define each atom of the dictionary  $D$  as the CLIP embedding of one of the concepts obtained using CLIP's text encoder.
2. For a given input image, define the observed signal  $x$  as the CLIP embedding of the image.
3. Using IP-OMP as the querier, encode the image's CLIP embedding as a sparse combination of dictionary atoms with weights  $\hat{\beta}_{\mathrm{IP - OMP}}$ . While both OMP and IP-OMP recover the sparse code similarly well, we choose to use IP-OMP in our experiments due to its nice information-theoretic interpretation (§3).
4. Train a linear classifier to predict the class label from the sparse codes  $\hat{\beta}_{\mathrm{IP - OMP}}$ . This choice is made to enhance interpretability. By inspecting the weights of the linear layer, one can identify which concepts (atoms) are most important for the prediction.
For a given image, the linear network predicts the class label based on the sparse code. The explanation of the prediction, then, is given in terms of the non-zero coefficients of  $\hat{\beta}_{\mathrm{IP - OMP}}$  and their corresponding atoms. Because these atoms are text embeddings for concepts, they are semantically meaningful. This is in stark contrast to predictions made by deep networks trained on raw pixel data, where the reasoning behind network predictions is opaque.
Differences between CLIP-IP-OMP and V-IP. A significant difference between CLIP-IP-OMP and V-IP is the target variable in question. In V-IP, this is the class label  $Y$ , whereas in IP-OMP this is a projection of  $x$  (the observed image's CLIP embedding) onto a random direction  $Z$ . Moreover, the query answers in both algorithms are different. In V-IP, the image is considered a random variable and answers are functions of the image. In IP-OMP, the answers are simply dot products between a query (dictionary atom) and the random direction  $Z$ . Despite these differences, the label prediction in both V-IP and CLIP-IP-OMP is explained using a small set of concepts selected before termination. In V-IP, this is the set of query-answer pairs selected. In CLIP-IP-OMP, this is the sparse code  $\hat{\beta}_{\mathrm{IP - OMP}}$ , which encodes the set of selected concepts and their weights.
(b)
Figure 4: Explainable predictions using CLIP-IP-OMP. Two example runs of our algorithm on two images from the ImageNet test set, with number of iterations  $\tau = 9$ . For both images, our model predicted the correct class with  $68.73\%$  &  $72.21\%$  confidence resp. The weights of the linear classifier correspond to the weights for the predicted class. More examples in Appendix §E.6.
4.2 Experiments
Having described our algorithm, we now show its efficacy at generating explainable predictions on 5 different vision datasets: ImageNet [37], Places365 [38], CIFAR-{10, 100} [39], and CUB-200 [40]. Specific details about architecture and training protocols used can be found in Appendix §D.2. Our code is available at https://github.com/r-zip/ip-omp.
Semantic dictionaries. To get a set of semantically relevant concepts, we follow prior work [41], which uses GPT-3 [42] to extract relevant concepts for every class in the dataset by asking prompts like "List the most important features for recognizing something as a class". For more details, we direct the reader to [41]. In this work, we directly use their extracted concepts [43]. For each concept, we obtain their corresponding CLIP embedding by directly using the concept name as input to the text encoder. Some example concepts for Imagenet are shown in col. 2 of Figures 4a and 4b (y-axis).
Explainable predictions using CLIP-IP-OMP. We show example runs of the CLIP-IP-OMP algorithm on two images taken from the ImageNet dataset in Figure 4. In particular, given an image, we run IP-OMP on its CLIP embedding for a fixed number of iterations  $\tau$ , which is the desired explanation length. Then, we make a prediction using the linear classifier, which was trained to learn the mapping between sparse codes of sparsity level  $\tau$  (number of non-zero elements) and the class label. All of the CLIP embeddings (text and image) are  $\ell_2$ -normalized. The signed magnitude of the coefficient in the sparse code indicates how relevant the corresponding atom (text concept) is for the contents of the image. This claim is motivated by CLIP's training loss which incentivizes aligned image-text embedding pairs (that is, the text describes the image contents) to have a high dot product (closer to +1) and unaligned image-text embedding pairs (that is, the text does not correspond to the image contents) to have a small dot product (closer to -1). We also visualize the weights of the trained linear classifier for the predicted class. In Figure 4a, we see that the selected atoms with positive coefficients in the sparse code correspond to characteristics of a tiger like "black and white striped fur" and "prey animal". Similarly, atoms with negative coefficients correspond to concepts not found in a tiger like "salty flavor" and "witch". Although the image is not of a Savannah habitat, we suspect CLIP assigns a positive association between the text embedding for "a Savannah" and the image, since tigers are found in savannah habitats. Interestingly, the sign of the weights the linear classifier assigns to each of the concepts seems to be positively correlated with their sign in the sparse code. Similar observations are made for Figure 4b. Although the concept of "originated in Sussex, England" has a large coefficient in the sparse code, the linear classifier assigns a very low weight to it, indicating a diminished effect of that concept on the prediction "Aircraft Carrier".
Baseline comparisons. We compare our method with V-IP and Label-free Concept Bottleneck Models (Lf-CBM) [41], a recently proposed explainable AI algorithm which is similar in spirit to ours. Lf-CBM represents a given image in terms of a concept vector where every dimension
corresponds to a semantic concept and the corresponding feature is the dot product between CLIP's embedding of the image and the text concept. The final prediction is then made by training a sparse linear layer (using elastic net regularization) to map from concept features to labels. Note that their model is sparse in the network weights, whereas ours is sparse in the input features.
For a fair comparison, we use the same set of concepts for all methods. For V-IP, the query is CLIP's text embedding and the answer is its corresponding dot product with the CLIP embedding (since the dot product indicates whether the concept is present in the image). We compare all methods by examining the tradeoff between explanation length and classification accuracy. For V-IP, CLIP-IP-OMP, and Lf-CBM respectively, the explanation lengths are the number of queries selected, the number of dictionary atoms selected, and the number of non-zero
Figure 5: Trade-off between accuracy and explanation length for different methods (best viewed in colour).
weights in the linear classifier for the predicted class. For prediction accuracy, we use V-IP's learned classifier, whereas for our method, we train a separate linear classifier for every sparsity level (the number of iterations of IP-OMP before termination). Unlike CLIP-IP-OMP and V-IP, Lf-CBM does not have any sequential selection strategy. Hence, to compare, we report the average number of non-zero weights per class in the concepts-to-label linear mapping. The results are shown in Figure 5. On most datasets, CLIP-IP-OMP has a better trade-off (greater area-under-the-curve) than V-IP, except CIFAR-100 (where they are competitive) and CUB-200. Notice that for all datasets, in the initial iterations, atoms selected by CLIP-IP-OMP are more predictive for the class (higher test accuracy) than V-IP. This is because the atom selection in IP-OMP explicitly depends on the image content, whereas, the query selection in V-IP (equation 1) solely depends on the answers to the previous queries and the data distribution. On all datasets except CUB and ImageNet (where it is competitive), our method achieves similar accuracy to Lf-CBM, but with a much smaller explanation length (Lf-CBM's explanation length (accuracy) is indicated by the red star (red dashed line)).
Computational efficiency. Complementary to being performant at explaining prediction, we would like to stress the simplicity of our method compared to V-IP and Lf-CBM, two contemporary explainable AI methods. Both V-IP and Lf-CBM require costly optimization routines. In V-IP, this is training a querier network to learn what to ask next from data. In Lf-CBM, this is optimizing the sparse linear classifier using the elastic-net regularizer. Finding the right sparsity level (number of non-zero weights in the classifier) in Lf-CBM requires hyperparameter tuning by training multiple models. In comparison, our method uses IP-OMP, which requires no training, to select dictionary atoms. Moreover, the number of iterations of the algorithm controls the explanation lengths.
The main bottleneck of IP-OMP is in extracting the sparse codes since this involves computing projection matrices. For example, our implementation, based on Cholesky decomposition [44], takes  $\approx 40$  hours to extract sparse codes of support size 50 (the highest considered in our experiments) for all the 1.28 million images in the ImageNet training set on an NVIDIA RTX A5000 GPU. This will be much faster for smaller support sizes, for example at level 10, it takes  $\approx 6$  hours. For comparison, training Lf-CBM [43] on ImageNet for one set of hyperparameters takes about 50 hours on the same GPU. Similarly, training the V-IP framework [45] on ImageNet takes about 4 days!
In this work, we show that Orthogonal Matching Pursuit (OMP) is a particular case of Information Pursuit (IP) (modulo a normalization factor) with a suitably chosen set of queries and target variable. We call this IP-derived algorithm for sparse coding IP-OMP. We then present a simple algorithm, called CLIP-IP-OMP, which uses CLIP and IP-OMP to make explainable predictions for visual classification tasks. CLIP-IP-OMP has two limitations. First, its application is restricted to image datasets since it relies on CLIP to encode images and text concepts into a shared space. Second, the atom selection procedure using IP-OMP is independent of the class label; as a result an auxiliary classifier needs to be trained. Future work would aim to address these limitations.
This research was supported by the Army Research Office under the Multidisciplinary University Research Initiative contract W911NF-17-1-0304, and the NSF-Simons Research Collaboration on the Mathematical and Scientific Foundations of Deep Learning (NSF grant 2031985, Simons grant 814201). Moreover, the authors acknowledge Carolina Pacheco, Liangzu Peng, Jeremías Sulam and Darshan Thaker for their insightful feedback that helped improve the presentation of this work. Finally, we thank Kwan Ho Ryan Chan for helping us with implementing V-IP for baseline comparisons in Section §4.2.
[80] Tuomas Oikarinen and Tsui-Wei Weng. CLIP-Dissect: Automatic description of neuron representations in deep vision networks. arXiv preprint arXiv:2204.10965, 2022.
[81] Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Deep residual learning for image recognition. In IEEE Conference on Computer Vision and Pattern Recognition, pages 770-778, 2016.
[82] Mana Sezdi and Yavuz Üzcan. Clean room classification in the operating room. In Medical Technologies National Congress (TIPTEKNO), pages 1-4. IEEE, 2016.
Throughout, we will write  $\Pi_k = \Pi_{D_k}$  to ease the notation.
Proof. Assume that the atoms selected in  $D_{\mathcal{L}}$  are linearly independent (since linearly dependent atoms will not be selected by the equation IP-OMP algorithm—more on this in §A.2). The proof relies on Gaussian conditioning.
Notice that since  $Z$  is a standard normal distribution and the vector  $\zeta = (\langle x,Z\rangle ,Z^T D_{\mathcal{L}})^T$  is just a linear transformation of a standard normal, it is also a multivariate normal random variable. Its covariance is
$$
\operatorname {c o v} (\zeta) = \left( \begin{array}{l l} x ^ {T} x & x ^ {T} D _ {\mathcal {L}} \\ D _ {\mathcal {L}} ^ {T} x & D _ {\mathcal {L}} ^ {T} D _ {\mathcal {L}} \end{array} \right). \tag {12}
$$
Now there are two cases.
Case 1: The covariance matrix has full rank. In this case,
$$
P \left(\langle x, Z \rangle \mid \{Q = \left\langle d _ {Q}, z ^ {0} \right\rangle : Q \in \mathcal {L} \}\right) = \mathcal {N} \left(\left\langle D _ {\mathcal {L}} D _ {\mathcal {L}} ^ {\dagger} x, z ^ {0} \right\rangle , \| \Pi_ {D _ {\mathcal {L}}} ^ {\perp} x \| _ {2} ^ {2}\right). \tag {13}
$$
This result is obtained by observing that the conditioning event  $\{Q = \langle d_Q, z^0 \rangle : Q \in \mathcal{L}\}$  is exactly the event  $\{D_{\mathcal{L}}^T Z = D_{\mathcal{L}}^T z^0\}$ , since  $D_{\mathcal{L}}$  consists of atoms selected from  $D$  indexed by  $\mathcal{L}$ . Now, the result is obtained by using formulae for conditioning in multivariate Gaussian random variables [46, equation A.6]. Specifically, the mean is computed as