SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Visual theme subspaces Whilst successfully preventing the visual imitation of many famous artists, applying the adjective subspace projection to every text prompt's CLIP representation can restrict the ability to use adjectives to specify visual appearance. We find a further effective strategy is to build additional subspaces for more specific visual appearances (e.g. artists' painting styles). Concretely,
Figure 4: Killing the CLIP representations' component in the adjective subspace provides a way to block the imitation of artists' styles in CLIP-based text-to-image models.
we embed 830 artists' names and surnames in a new matrix  $\mathbf{X}_{i'}$  and solve Equation (1) using all PoS classes in the negative summation to prevent the destruction of existing concepts. In contrast to the adjective space, projection onto the orthogonal complement of this 'artist subspace' preserves adjective-based visual descriptions whilst also successfully preventing style imitation (Figure 5a). Crucially, we highlight that for the example shown in Figure 5a, the artist's name Qi Baishi is not present in the 'training' list of example artists, suggesting the subspace has learnt a more general notion of an artist rather than simply the variation for only those artists whose names are provided as supervision.
We suggest more generally that subspaces learnt from a collection of words describing specific themes (whilst retaining variation in the PoS data through the main objective) could be useful for erasing entire visual concepts (such as NSFW imagery) from the CLIP representations. An additional example of another such custom subspace is shown in Figure 5b for removing only gory/bloody visual appearances. Not only does this offer a way to erase specific appearances in CLIP-based text-to-image models, but might also offer application in discriminative tasks, such as being able to block CLIP-based retrieval of images of sensitive nature. Please see the supplementary material for additional details, results, and visualisation of failure cases.
3.2 Quantitative results
Here we show quantitatively how the PoS-grounded subspaces can isolate the variation in the CLIP representation of either an image or text prompt. We validate this in two ways: through a class invariance metric in Section 3.2.1 and through zero-shot classification in Section 3.2.2.
(a) A custom subspace for 'artistic style'.
(b) A custom subspace for gory/bloody visual themes.
Figure 5: Projecting onto the orthogonal complement of custom visual theme subspaces erases specific appearances from CLIP-based text-to-image models' images.
(a) [25] PGA for PoS of interest.
(b) Ours  $(\lambda \coloneqq 0.5)$ .
(c) [25]  $\mathrm{PGA}^{\perp}$  for nuisance PoS.
Figure 6: Subspace class invariance: The norm of the ViT-B-32 CLIP text representations of 5k words from each PoS, in each of the subspaces. Results on baseline methods are shown in (a) and (c).
3.2.1 Class invariance
We first aim to quantify the extent to which our method results in subspaces that capture variation solely in the desired part of speech. We quantify this by a class invariance metric to measure how much each class' data points are retained in the subspaces. Concretely, we compute the Frobenius norm  $\frac{1}{n_j} ||\tilde{\mathbf{W}}_i^\top \mathbf{Y}_j||_F^2$  where each column  $\mathbf{y}_{jn} = \mathrm{Log}_{\mu}(\mathbf{x}_{jn})$  contains the CLIP embeddings in the columns of  $\mathbf{X}_j$  mapped to the tangent space, and  $n_j$  is the number of data points in class  $j$ .
We compare the proposed method to two other component analyses performed in the tangent spaces. In Figure 6a we project onto a subspace learnt from only the data of the specific PoS of interest (e.g. the first row's subspace learnt through principal geodesic analysis [26]–maximising the variance for just the noun PoS data points), whilst in Figure 6c the subspace is learnt by simply minimizing the variance in the projections for the nuisance PoS classes (e.g. the first row's subspace minimizing the variance for the remaining adjective, verb, and adverbs' data points). We show the results of the proposed method with  $\lambda = 0.5$  in Figure 6b for all combinations of parts of speech.
This quantity should be as close as possible to 0 in each of Figure 6's subfigures' off-diagonals  $i \neq j$  and as close as possible to 1 along the figures' diagonals  $i = j$  (if the subspaces capture visual variation that is unique to a particular word class). The learnt subspaces in Figure 6b evidently exhibit this pattern of disentanglement better than the baselines; the vectors have a large norm in their labelled class and a much smaller norm in the subspaces of the other categories.
3.2.2 Zero-shot subspace classification
In this subsection, our goal is to further validate quantitatively how well our noun subspace can isolate the representations relating to the content in an image by studying the task of zero-shot image
Table 1: Top-1 ZS classification accuracy with CLIP ViT-B-32.
ImageNET	MIT-states	UT Zap.	DomainNET	StanfordCars	Caltech101	Food101	CIFAR10	CIFAR100	OxfordPets	Flowers102	Caltech256	STL10	MNIST	FER2013
[1] CLIP	56.50	45.30	82.20	50.60	58.50	80.00	75.20	87.50	60.40	73.80	62.50	80.10	96.10	29.10	37.80
[32] PoS PCA	56.50	45.40	81.80	50.60	58.30	80.10	75.20	87.50	60.40	73.80	62.50	80.10	96.10	29.10	37.60
[25] PoS PCA	56.70	45.20	84.40	50.40	56.20	80.00	75.20	86.10	60.20	75.10	60.20	80.50	95.80	29.40	38.00
Noun Submanifold	57.80	45.50	87.70	50.80	58.60	81.90	76.30	87.90	61.40	75.20	61.00	81.50	96.30	29.80	44.70
Figure 7: Ablation study on the zero-shot accuracy for the subspaces vs the submanifolds with CLIP ViT-B-32; the submanifold outperforms the subspaces on almost all datasets considered.
classification $^3$ , given this is a very common application of CLIP in practice [1]. Importantly, these experiments serve as an additional way of measuring the subspaces' ability to isolate task-relevant modes of variation in the CLIP representations. With this in mind, we consider the baseline zero-shot setting [1] which computes the cosine similarity between all images in the training sets' and names of the class labels' CLIP representations. In our case, rather than computing the cosine similarity of the CLIP representations with  $S(\mathbf{z}_I, \mathbf{z}_T)$  we measure instead the similarity in the noun subspace with  $S\left(\Pi_N(\mathbf{z}_I), \mathbf{z}_T\right)$ . We hypothesise that if the noun subspace indeed better isolates the object of an image-invariant to the particular style of the image—we should expect to see improvement to the baseline image classification.
We show the Top-1 accuracies for a large variety of datasets in Table 1. We find the noun submanifold projection to lead to improved zero-shot classification on  $14 / 15$  of the datasets considered with CLIP ViT-B-32, and include a comparison to the Euclidean subspaces in Figure 7 to further illustrate the benefit of the geometry-aware variant. This is without needing any prompt engineering or domain knowledge about each dataset separately, confirming that the subspaces serve the intended role of being able to isolate the visual modalities of interest automatically. For all results in this subsection, we project onto a relatively large  $k\coloneqq 500$  dimensional subspace for PCA, PGA, and the proposed method. Please see the supplementary material for results on 2 more alternative CLIP architectures.
Vision-language representations There has been much interest in studying the properties of the VL representations in large-scale models such as CLIP. In particular, Goh et al. [12] show that there exist neurons that fire in response to both visual representations of a concept as well as to text relating to the concept. Viewing this as a form of entanglement, Materzynska et al. [31] address this by learning a linear subspace in which written text is disentangled from its visual component. Whilst we also wish to disentangle visual concepts, we do not focus on disentangling written words from visual representations, but rather visual modalities more generally. Further, our solution is instead given in closed form and has far fewer hyperparameters to tune. In addition to disentangling written/visual concepts, a number of works explore other forms of disentanglement in multimodal models. For example, to better perform image captioning [35, 36], generation [37, 38, 39, 40, 41], or discovering compositional representations or structure [37, 38, 39, 42].
Another popular approach to learning more useful VL representations is fine-tuning; Ilharco et al. [43] use fine-tuning in combination with weight interpolation to improve results on specific tasks without affecting existing performance, whilst many other works fine-tune CLIP for specific domains such as action recognition [11], video recognition [10], image captioning [7], and more [9]. Despite the success of fine-tuning, this comes with the restrictive requirement of task-specific labels. The method of 'prompting' [44, 17, 18, 13] is one alternative approach. At a high level, this technique learns a set of parameters (either in the form of 'words' in a prompt [17, 44] or as pixels appended to an input image [18, 13]) to steer the input to produce more useful representations for specific downstream tasks. In contrast, our method disentangles the modes of variation directly in the joint
For example, the colour in which a digit is drawn [33, 34] is not relevant information for the task of classifying which number it is.
vision-language representation space—this facilitates the ability to separate semantic information in both image and text representations. Consequently, the proposed method has direct application for both discriminative tasks and CLIP text-driven generative tasks.
Component analysis Let the matrices  $\mathbf{X}_1, \mathbf{X}_2 \in \mathbb{R}^{d \times n}$  contain  $n$  data points of two classes in their columns. The Principal Component Analysis (PCA) [32, 45] computes the low-dimensional subspace of maximum variance as the leading eigenvectors of the empirical covariance matrix of all data points. One pertinent drawback of PCA is its unsupervised nature in disregarding the labels of the data points. Whilst one can learn class-specific subspaces via PCA on the relevant subset of data (i.e. the eigenvectors of zero-mean  $\frac{1}{n} \mathbf{X}_1 \mathbf{X}_1^\top$ ), there is nothing to prevent the remaining 'nuisance' class(es) from also having large variance in this learnt subspace. One method that provides a way to jointly maximise the variance in one class' projected embeddings whilst minimizing that of another class is the Fukunaga-Koontz transform [46, 47] (FKT). FKT learns a class 1-specific subspace spanned by the columns of  $\mathbf{W}_1 \in \mathbb{R}^{d \times k}$  as the leading eigenvectors of  $\left(\mathbf{UD}^{-\frac{1}{2}}\right)^\top \mathbf{X}_1 \mathbf{X}_1^\top\left(\mathbf{UD}^{-\frac{1}{2}}\right)$ , where  $\mathbf{U}, \mathbf{D}$  are the eigenvectors (stacked column-wise) and eigenvalues (along the diagonal) respectively of the matrix  $(\mathbf{X}_1 \mathbf{X}_1^\top + \mathbf{X}_2 \mathbf{X}_2^\top)$ . Whilst FKT also learns a subspace in which solely the target class' points have a large coefficient, the FKT operates on just two classes of interest and is more computationally expensive than the proposed method in requiring two eigendecompositions (rather than one). Another related supervised decomposition is the Fisher Discriminant Analysis (FDA) [48] which learns a subspace in which classes can be easily discriminated. Despite FDA's objective involving a similar trace maximisation form to Equation (4), the goals of FDA and the proposed objective are very different. FDA aims to minimise intra-class variation, whilst the proposed objective maximises the norm of vectors of the target class in the learnt subspaces, whilst minimising those of the remaining classes. Additionally, the proposed objective does not suffer from the same restrictively small upper bound on the dimensionality of the learnt subspace as FDA does through the low-rank of the between-scatter matrix. A comparison to the subspaces learnt with FDA, FKT, and the proposed objective is shown in the supplementary material to illustrate the differences visually.
In this paper, we have proposed a method for learning geometry-aware subspaces in CLIP's vision-language space that disentangle the modes of visual variation in representations of both images and text. To achieve this, we used the semantic relationship between parts of speech in natural language and specific visual modes of variation. We demonstrated the disentanglement qualitatively with a text-to-image model, showcasing the model's ability to remove visual imitation of artists' styles from synthetic images. Class invariance metrics and zero-shot classification results further validated the disentanglement quantitatively.
Limitations A common drawback of subspace learning approaches is choosing a good number of dimensions  $k$ . Our method inherits this limitation, and one must choose the appropriate value for the specific task. Despite this, the closed-form eigensolution means only a single fast computation is needed, and any desired number of eigenvectors can be used at test-time. Although the recovered subspaces show wide applicability in downstream tasks, they are not able to perfectly separate the modes of variation for every possible image and text prompt. Additionally, the PoS supervision can not help address polysemy within a particular part of speech (such as disambiguating between the bird/machine meanings of the word 'crane'). This further alludes to the promise of the custom subspaces in being able to target more specific visual concepts. Finally, often even minor changes to text-to-image models' text input or its representation produces very different output images [49]. As can be seen from our results, the subspace projection of the entire text representation similarly does not guarantee the preservation of the structure of the images generated from the 'original' prompts.
This research was partially supported by the EU's Horizon 2020 programme H2020-951911 AI4Media project, a grant from The Cyprus Institute on Cyclone, and by project MIS 5154714 of the National Recovery and Resilience Plan Greece 2.0 funded by the European Union under the NextGenerationEU Program.
[42] Tian Yun, Usha Bhalla, Ellie Pavlick, and Chen Sun. Do vision-language pretrained models learn composable primitive concepts? Transactions on Machine Learning Research, 2023. ISSN 2835-8856.
[43] Gabriel Ilharco, Mitchell Wortsman, Samir Yitzhak Gadre, Shuran Song, Hannaneh Hajishirzi, Simon Kornblith, Ali Farhadi, and Ludwig Schmidt. Patching open-vocabulary models by interpolating weights. NeurIPS, 2022.
[44] Kaiyang Zhou, Jingkang Yang, Chen Change Loy, and Ziwei Liu. Learning to prompt for vision-language models. IJCV, 130(9):2337-2348, 2022.
[45] Karl Pearson. Liii. on lines and planes of closest fit to systems of points in space. The London, Edinburgh, and Dublin philosophical magazine and journal of science, 2(11):559-572, 1901.
[46] Keinosuke Fukunaga. Introduction to statistical pattern recognition. Elsevier, 2013.
[47] Sheng Zhang and Terence Sim. Discriminant subspace analysis: A fukunaga-koontz approach. IEEE Transactions on Pattern Analysis and Machine Intelligence, 29, 2007.
[48] R. A. Fisher. The use of multiple measurements in taxonomic problems. Annals of Eugenics, 7 (2):179-188, 1936.
[49] Amir Hertz, Ron Mokady, Jay Tenenbaum, Kfir Aberman, Yael Pritch, and Daniel Cohen-Or. Prompt-to-prompt image editing with cross attention control, 2022.
[50] Mehdi Cherti, Romain Beaumont, Ross Wightman, Mitchell Wortsman, Gabriel Ilharco, Cade Gordon, Christoph Schuhmann, Ludwig Schmidt, and Jenia Jitsev. Reproducible scaling laws for contrastive language-image learning, 2022.
[51] 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. NeurIPS, 35:27730-27744, 2022.
[52] Rohit Gandikota, Joanna Materzynska, Jaden Fiotto-Kaufman, and David Bau. Erasing concepts from diffusion models. arXiv preprint arXiv:2303.07345, 2023.
[53] Nupur Kumari, Bingliang Zhang, Sheng-Yu Wang, Eli Shechtman, Richard Zhang, and Jun-Yan Zhu. Ablating concepts in text-to-image diffusion models. arXiv preprint arXiv:2303.13516, 2023.
A Definitions and derivations
A.1 Closed-form solution
Detailed steps for the expansion of the original objective into the trace maximisation form of the main objective are given as follows:
$$
\begin{array}{l} (1 - \lambda) \| \mathbf {W} _ {i} ^ {\top} \mathbf {X} _ {i} \| _ {F} ^ {2} - \sum_ {j \in \mathcal {C} \backslash \{i \}} \lambda \| \mathbf {W} _ {i} ^ {\top} \mathbf {X} _ {j} \| _ {F} ^ {2} (6) \\ = (1 - \lambda) \operatorname {t r} \left(\left(\mathbf {W} _ {i} ^ {\top} \mathbf {X} _ {i}\right) ^ {\top} \left(\mathbf {W} _ {i} ^ {\top} \mathbf {X} _ {i}\right)\right) - \sum_ {j \in \mathcal {C} \backslash \{i \}} \lambda \operatorname {t r} \left(\left(\mathbf {W} _ {i} ^ {\top} \mathbf {X} _ {j}\right) ^ {\top} \left(\mathbf {W} _ {i} ^ {\top} \mathbf {X} _ {j}\right)\right) (7) \\ = \operatorname {t r} \left((1 - \lambda) \mathbf {X} _ {i} ^ {\top} \mathbf {W} _ {i} \mathbf {W} _ {i} ^ {\top} \mathbf {X} _ {i} - \sum_ {j \in \mathcal {C} \backslash \{i \}} \lambda \mathbf {X} _ {j} ^ {\top} \mathbf {W} _ {i} \mathbf {W} _ {i} ^ {\top} \mathbf {X} _ {j}\right) (8) \\ = \operatorname {t r} \left((1 - \lambda) \mathbf {W} _ {i} ^ {\top} \mathbf {X} _ {i} \mathbf {X} _ {i} ^ {\top} \mathbf {W} _ {i} - \sum_ {j \in \mathcal {C} \backslash \{i \}} \lambda \mathbf {W} _ {i} ^ {\top} \mathbf {X} _ {j} \mathbf {X} _ {j} ^ {\top} \mathbf {W} _ {i}\right) (9) \\ = \operatorname {t r} \left(\mathbf {W} _ {i} ^ {\top} \left((1 - \lambda) \mathbf {X} _ {i} \mathbf {X} _ {i} ^ {\top} - \sum_ {j \in \mathcal {C} \backslash \{i \}} \lambda \mathbf {X} _ {j} \mathbf {X} _ {j} ^ {\top}\right) \mathbf {W} _ {i}\right) (10) \\ = \operatorname {t r} \left(\mathbf {W} _ {i} ^ {\top} \mathbf {C} _ {i} \mathbf {W} _ {i}\right), (11) \\ \end{array}
$$
where  $\mathbf{C}_i = \left((1 - \lambda)\mathbf{X}_i\mathbf{X}_i^\top -\sum_{j\in \mathcal{C}\setminus \{i\}}\lambda \mathbf{X}_j\mathbf{X}_j^\top\right)$ . Here we have used  $||\mathbf{X}||_F^2 = \operatorname {tr}\left(\mathbf{X}^\top \mathbf{X}\right)$  and the linearity and cyclic properties of the trace.
A.2 The Logarithmic and Exponential Maps
For mapping to the hypersphere's tangent space at a reference point in the main paper, we use well-known explicit formulas. Concretely, the Logarithmic Map  $\operatorname{Log}_{\mathbf{p}}: \mathbb{S}^{d-1} \to \mathcal{T}_{\mathbf{p}}\mathbb{S}^{d-1}$ , which maps points on the sphere to the tangent space at a reference point  $\mathbf{p} \in \mathbb{S}^{d-1}$  is defined as
$$
\operatorname {L o g} _ {\mathbf {p}} (\mathbf {z}) = \operatorname {a r c c o s} \left(\mathbf {z} ^ {\top} \mathbf {p}\right) \frac {\left(\mathbf {I} _ {d} - \mathbf {p p} ^ {\top}\right) \left(\mathbf {z} - \mathbf {p}\right)}{\left| \left(\mathbf {I} _ {d} - \mathbf {p p} ^ {\top}\right) \left(\mathbf {z} - \mathbf {p}\right) \right| | _ {2}}. \tag {12}
$$
Its inverse, the Exponential Map  $\mathrm{Exp}_{\mathbf{p}}: \mathcal{T}_{\mathbf{p}}^{\mathbb{S}^{d-1}} \to \mathbb{S}^{d-1}$  mapping points back onto the sphere is given by
$$
\operatorname {E x p} _ {\mathbf {p}} (\mathbf {z}) = \cos \left(\left| \left| \mathbf {z} \right| \right| _ {2}\right) \mathbf {p} + \sin \left(\left| \left| \mathbf {z} \right| \right| _ {2}\right) \frac {\mathbf {z}}{\left| \left| \mathbf {z} \right| \right| _ {2}}. \tag {13}
$$
B.1 Qualitative results
Visual disentanglement Firstly, we include many more examples of the visual disentanglement with the 'adjective' and 'noun' PoS subspaces and TTIM of Rampas et al. [15] in Figures 8 and 9.
Figure 8: Additional results for visual disentanglement of text prompts using the learnt PoS subspaces.
Figure 9: Additional results for visual disentanglement of text prompts using the learnt PoS subspaces.
Visual theme removal As shown in the main paper, the adjective subspace works remarkably well for preventing the imitation of artists' styles in the CLIP-based text-to-image model Paella. However, as stated in the main paper, the adjective subspace orthogonal projection for the task of 'style blocking' is overly restrictive in also preventing the description of visual appearance with adjectives. We provide in Figure 10 some examples of this--for example, the 'stormy' and 'red' visual appearances are removed in Figure 10 after projection. On the other hand, the custom visual theme subspaces can target specific visual appearances more precisely--two examples are shown in Figure 11 (following the experimental setup outlined in Appendix D).
Prompt: "A photo of a shiba inu outside in stormy weather"
Prompt: "A photo of a house in the forest with red walls"
Figure 10: 'Style blocking' with the adjective subspace is overly restrictive (here blocking 'stormy' and 'red' visual appearances).
Prompt: "A photo of a man covered in blood"
Prompt: "A photo of a gruesome death metal album cover"
Prompt:"AshibaInu in the style of Van Gogh"
Prompt: "A portrait painting of a man in the style of Picasso"
Figure 11: Additional results for the two custom visual theme orthogonal complement subspace projection for 'gore' and artists' styles.
Figure 12: Projecting onto a custom subspace (given by 2758 names of animals) and its orthogonal complement learnt using the proposed objective. Such custom visual subspaces show promise in helping disambiguate between polysemous nouns.
Polysemy within a single part-of-speech As described in the limitations, the PoS subspaces cannot disambiguate between polysemous phrases within one particular PoS. We show in Figure 12 a proof-of-concept result suggesting that the custom visual subspaces can be a means of addressing this. In particular, we learn a custom "animal" subspace following the same protocol in Sect. 3.1.2 of the main paper. When projecting CLIP representations of "a photo of a crane" onto this subspace, we produce photos of the bird, rather than of machinery. Conversely, projecting the CLIP representation of "A photo of a bass" onto this subspace's orthogonal complement removes the representation of "bass" as a fish, synthesizing instead just images of bass guitars.
B.2 Quantitative results
Visual theme subspace invariance Here we show quantitative results for the visual theme-specific subspaces. We have evaluated this visually via text-to-image models in Figure 11, however here we wish to demonstrate that large variation in the CLIP representations directly is captured for only the themes of interest. Concretely, in Figure 13 we compute the same class invariance metric for 200 random WordNET words and random theme-specific words in the learnt custom theme subspaces through  $\frac{1}{200} ||(\hat{\mathbf{W}}_i^\top \mathbf{Y})||_F^2$ . Here,  $\mathbf{Y} \in \mathbb{R}^{d \times 200}$  contains in its columns the CLIP word embedding mapped to the tangent space, and  $i$  denotes the specific custom visual theme of interest for a particular subfigure. As can be seen from the high magnitude in the orange bars and low magnitude of the blue bars in Figure 13, these subspaces map the 200 random other words much closer to the zero vector than the theme-specific words. This indicates the variance in just the words of interest has indeed been captured.
Figure 13:  $\frac{1}{200} ||(\hat{\mathbf{W}}_i^\top \mathbf{Y})||_F^2$  of CLIP representations (of both 200 random words and 200 words from the 'training' set describing the theme of interest) projected onto theme  $i$ -specific subspaces.