Towards Better Understanding of Self-Supervised Representations
Abstract
Self-supervised learning methods have shown impressive results in downstream classification tasks.
However, there is limited work in understanding and interpreting their learned representations.
In this paper, we study the representation space of several state-of-the-art self-supervised models including SimCLR, SwaV, MoCo V2 and
BYOL.
Without the use of class label information, we first discover discriminative features that are highly active for various subsets of samples and correspond to unique physical attributes in images.
We show that, using such discriminative features, one can compress the representation space of self-supervised models up to 50% without affecting downstream linear classification significantly.
Next, we propose a sample-wise
Self-Supervised Representation Quality Score (or,
Q-Score) that can be computed without access to any label information.
Q-Score, utilizes discriminative features to reliably predict if a given sample is likely to be mis-classified in the downstream classification task achieving AUPRC of 0 .
91 on SimCLR and BYOL trained on ImageNet100.
Q-Score can also be used as a regularization term to remedy low-quality representations leading up to 8% relative improvement in accuracy on all 4 self-supervised baselines on ImageNet-100,
CIFAR-10, CIFAR-100 and STL-10.
Moreover, through heatmap analysis, we show that Q-Score regularization enhances discriminative features and reduces feature noise, thus improving model interpretability.
1. Introduction
Self-supervised models learn to extract useful representations from data without relying on human supervision.
These models (Chen et al., 2020a; Caron et al., 2020; Chen et al., 2020b; Grill et al., 2020; Chen & He, 2021; Caron et al., 2018; Khosla et al., 2020) have shown comparable results to supervised models in downstream classification tasks.
By means of data augmentation, these models are trained to encode semantically relevant information from images while ignoring nuisance aspects.
Therefore, the representations ultimately learned should only contain the information required to define a given sample.
However, in practice, learned representations are often quite noisy and not interpretable, causing difficulties in understanding and debugging their failure modes (Jing et al., 2022;
Huang et al., 2021; Ericsson et al., 2021).
In this paper, our goal is to study the representation space of self-supervised models such as SimCLR (Chen et al., 2020a), SwaV (Caron et al., 2020), MoCo (Chen et al., 2020b) and BYOL (Grill et al., 2020) and discover their informative features in an unsupervised manner.
This can help us debug models better, improve their representation spaces and make them more interpretable.
Understanding these learned representations is relatively less explored.
(Jing et al., 2022), observes that self-supervised representations collapse to a lower dimensional space instead of the entire embedding space.
Other methods (von K ¨ ugelgen* et al., 2021; Xiao et al., 2021), propose to separate the representation space into variant and invariant information so that augmentations are not task-specific.
(Grigg et al., 2021), observe representations across layers of the encoder and compare it to supervised setups.
In this work, we focus more on thoroughly studying the representation space of SSL methods and their properties.
We investigate the connections between the unsupervised properties in the representation space and mis-classifications when the representations are used in downstream classification tasks.
We summarize our contributions as follows:
• We study the representation space of self-supervised models and discover discriminative features , in an unsupervised fashion.
• We show that discriminative features often have unique physical meanings and although are discovered without any label information (given that SSL models are trained without labels), show strong correlation to class labels.
Moreover, with discriminative features, representations can be compressed by up to 50% reliably.
• We introduce Self-Supervised Quality Score (QScore) to measure the quality of each learned representation.
We empirically observe that the higher the Q-Score, the more likely that the sample will be correctly classified, achieving an AUPRC of up to 0 .
• We apply Q-Score as a regularizer to the selfsupervised loss and show that, by improving the quality of low-score samples, we can improve downstream classification accuracy by 8% .
Moreover, we show that using the Q-Score regularization improves the interpretability of self-supervised representations by removing noise and highlighting useful information.
2. Self-Supervised Representations
Let us consider a SimCLR model with a ResNet (He et al., 2016) base encoder f ( . ) and an MLP projection head g ( . ) .
We define x i ∈ R n and ˜ x i ∈ R n as two transformed views of the i th sample in a given input dataset containing N samples.
Our setup is identical to SimCLR.
We apply data transformations, random crop , random horizontal flip , random color distortion and random Gaussian blur .
We pass the input samples through the base encoder to get selfsupervised representations denoted by f ( x i )
=
h
i ∈ R r and f (˜ x i ) =
˜ h
i ∈
R r where r is the size of the representation space.
For contrastive training, we use the output of the projection head g ( h i ) =
z i ∈ R p and g (˜ h i ) =
˜
z i ∈ R p where p is the size of the projection space.
The SimCLR optimization for the set of model parameters θ , is as follows,
[Equation]
where sim ( z i , z j ) =
1 τ
[Equation]
In Figure 1, we visualize the representations of SimCLR pretrained on ImageNet-100 (Russakovsky et al., 2015).
Each row denotes the latent vector ( h i ) of a random sample at index i of the ImageNet-100 test set.
There are 512 columns corresponding to the representation size of a ResNet-18 (He et al., 2016) encoder.
First, we study properties of sample representations ( h i ).
We observe that each representation is nearly sparse, i.e., most feature values are close to zero (Jing et al., 2022).
However, there exists a select few features that are strongly deviated from the remaining features in any given representation.
For ease of visualization, we have highlighted 4 different representations (in black), which show at least one dominant feature.
For the i th sample whose latent representation is h i ∈
R r , let µ i denote the mean of h i and
σ i denote the standard deviation of h i .
We formally define the set of dominant features for the i th sample as, L i :=
{ j : h ij > µ i + ϵσ i } .
where ϵ is a hyperparameter that is empirically selected.
In practice, we find that ϵ = 4 works best for our experiments.
We observe that dominant features of a sample may be unique to that particular representation or may be shared with other samples in the population.
For example, in Figure 1, features 11 and 301 (highlighted in red) are strongly activated for a single sample, whereas, features 27 andare strongly activated for more than one sample.
In Figure 1, we plot all the samples where the given feature is strongly activated (i.e., dominant) and group them by their class labels (note that the selection of dominant features are done without using the label information).
If we take feature 11, 27, 301 and 333, we observe that they are dominant for over 80% of a particular class and significantly higher than the remaining classes.
The gradient heatmaps also correspond to informative visual attributes necessary for identifying these objects.
We will refer to these features as discriminative features defined formally in the next section.
On the other hand, some dominant features may be strongly activated for a large number of samples in the population.
For example, in Figure 1, we illustrate the range of classes that feature 175 is dominant for, varying from birds, animals, vegetables, household items etc.
If we examine the gradient heatmaps of this feature across various classes, we observe that this feature does not have a clear physical interpretation.
[Figure]
3. Selecting Discriminative Features
In Figure 2 (left), we plot the number of samples where a given feature at index j is part of the set of dominant features (i.e., j ∈ L i ).
Intuitively, this is the number of times a given feature is strongly activated for the samples in the population.
The features are visualized in the ascending order of the number of strong activations in the population (containing 5000 samples).
We define three broad categories of dominant features: (i)
Features that are strongly activated across a very small fraction of the population, corresponding to the lower tail features in Figure 2.
These features are image-specific and are unlikely to have class-relevance.
(ii) Features dominant across a large number of samples in the population i.e, the upper tail features in Figure 2.
Like feature 175 in Figure 1), such features are likely to encode very broad and general characteristics (like texture, color etc.)
common to most samples and therefore, are not class-discriminative.
The third category includes, (iii) features that are active across a moderate number of samples in the population (i.e. the middle parts in Figure 2).
These features are most likely to encode unique physical attributes associated with particular classes, similar to those illustrated in the top panel in Figure 1.
We refer to this subset of dominant features as discriminative features (denoted by the dotted lines in Figure 2).
We emphasize that these discriminative features are selected without the use of any label information.
We justify the described method of selection in Figure(right), where we plot the top-1 accuracy of a linear classifier on ImageNet-100 using subsets of discriminative features of varying sizes.
We also plot the top-1 accuracy when random subsets of features are selected.
We observe that discriminative features perform significantly better than randomly features and can reduce the representation size up to 50% , with minimal reduction in performance.
See Appendix Figures
A.1 and A.2 for results on other self-supervised models.
4. Interpreting Representations
In this section, we study some properties of the latent space that drive representations to be correctly classified by a downstream linear classifier.
In Figure 3, we visualize the discriminative features selected in an unsupervised manner using the approach outlined in Section 3 for several
ImageNet-100 classes.
Each row corresponds to the class
As we can see, in Figure 3, in the first panel, there is a clear difference between representations of correctly and incorrectly classified examples.
Both correct and mis-classified representations are nearly sparse, however, the discriminative features are strongly deviated only in correct classifications.
This is especially interesting because the label information has not been used in the selection of discriminative features.
In Figure 1, we observe that discriminative features show strong correlation to ground truth, which suggests that their presence may be useful in correctly classifying representations.
In Figure 3, our claim is confirmed as we observe that mis-classified representations do not show high activation on discriminative features.
For every representation, apart from the discriminative features, there are a large number of features that have very low activation (close to zero).
We name such features as noisy features for each representation.
Correctly classified representations contain few noisy features and are more sparse while mis-classified representations are often more noisy.
Our visual observations hint that we can potentially classify representations in an unsupervised manner by leveraging these structural properties of representations.
We observe that the heatmaps of discriminative features (in
Figure 4) of any given class, capture relevant and defining characteristics of the images, therefore are highly correlated with the ground-truth.
The physical attribute associated with a discriminative feature is consistent between the correct and incorrect classifications.
Noisy features lead to noisy heatmaps which focus on aspects of the inputs that are uninformative (See Section A.10).
For any given sample, having a large number of noisy features and low activations on discriminative features are strong signals indicating its potential mis-classification in the downstream task.
We would like to emphasize that our results only indicate an association between these structural properties and classification accuracy and we do not claim any causal relationship between the two.
5. Self-Supervised Q-Score
Our study of learned representation patterns help us discover discriminative features in an unsupervised manner.
We combine our observations to design a sample-wise quality score for self-supervised representations.
Let us define D , such that | D | < r , as the set of discriminative features for a given self-supervised model trained on a given dataset.
For the i th sample, we have h i ∈ R r (representation), µ i (mean of h i ), σ i (standard deviation of h i ) and the set of dominant features L i =
{ j : h ij > µ i + ϵσ i } , | L i | < r .
We define our Self-Supervised Quality
Score for sample i as,
[Equation]
where, L i ∩ D is the set of discriminative features specific to the i th sample.
We also use the L 1 norm ∥ h i ∥ 1 to promote sparsity in representations consequently ensuring that noisy features are penalized.
Intuitively, higher Q i implies that the representation is sparse with strongly activated discriminative features.
It combines two favorable properties of representations i.e., sparsity (or feature noise, computed by the Lnorm) and strongly activated discriminative features.
Our objective with this metric is to compute a sample-specific score in an unsupervised manner indicating the quality of its representations.
Ideally, we would like to argue that samples with higher Q-score have improved representations and thus are more likely to be classified correctly in the downstream task.
We confirm this in Section A.3.
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
We can also use Q-Score as an intervention by further training state-of-the-art self-supervised models with Q-Score regularization.
For example, we can apply this regularizer to the SimCLR optimization as follows,
[Equation]
where, α is a threshold with which we select the samples whose Q-Scores should be maximized and λ is the regularization coefficient.
In other words the goal of this regularization is to improve low-quality representations, similar to the ones shown in Figure 3, by maximizing their Q-Score to improve their quality for downstream classification.
As shown in in Table 1, Q-Score regularization improves the top-1 accuracy on each dataset on all of the self-supervised state-of-the-art models.
On ImageNet-100 we observe up to an 8% relative improvement in accuracy, most significant on MoCo.
In addition to top-1 accuracy, Q-Score also shows significant improvement in representation quality and interpretability.
In Figure 3, we compare the representation space before and after Q-Score regularization.
We observe that discriminative features become more enhanced after Q-Score regularization on both correct and mis-classified representations.
Our regularization also greatly reduces noisy features and produces cleaner representations with clear discriminative features that are easier to classify (See Section A.4).
There- fore, we attribute the improvement in performance to improved representation quality.
Our motivation is to produce better quality representations that are more distinguishable across classes and therefore, easier to classify.
Although
Q-Score improves accuracy, it does not entirely prevent mis-classifications as mis-classifications may occur due to a variety of reasons such as, hardness of samples, encoder capacity, dataset imbalance etc.
A. Appendix
Features N u m b e r o f S t r o n g A c t i v a t i o n s SimCLR Discriminative Features Features
N u m b e r o f S t r o n g A c t i v a t i o n s
SwaV Discriminative Features
Features
N u m b e r o f S t r o n g A c t i v a t i o n s MoCo Discriminative Features Features N u m b e r o f S t r o n g A c t i v a t i o n s
BYOL Discriminative Features
A.1. Discussion
In this paper we studied the representation space of self-supervised models in downstream classification tasks and discovered discriminative features.
Discriminative features are a subset of features that show strong activations in smaller but sizable sets of samples, wherever relevant, and correspond to unique physical attributes.
With discriminative features, we can reduce the representation size by 50% without affecting linear accuracy.
We also observe significant differences in representations between correctly and incorrectly classified samples.
Building on these observations, we define Self-Supervised Quality
Score (Q-Score) that is effective in determining how likely samples are to be correctly or incorrectly classified.
Our proposed score can be computed per sample in an unsupervised manner (without label information).
With the help of Q-Score regularization, we remedied these low-quality samples by improving their Q-Scores, thereby, improving the overall accuracy of state-of-the-art self-supervised models by up to 8% .
We also observed that regularization improves model interpretability by enhancing discriminative features and reducing feature noise.
Our paper poses important questions for future studies such as: 1) why do self-supervised models trained without any labels, produce axis-aligned, sparse representations, 2) what are the causes of mis-classifications, apart from representation quality, 3) how can we utilize the better representations space for other tasks besides classification.
A.2. Experimental Setup
Our setup consists of pre-trained self-supervised encoders ( f ( . ) )
SimCLR (Chen et al., 2020a), SwaV (Caron et al., 2020), MoCo (Chen et al., 2020b) and BYOL (Grill et al., 2020) on ImageNet-100 (Russakovsky et al., 2015), CIFAR-
(Krizhevsky et al., a), CIFAR-100 (Krizhevsky et al., b) and STL-10 (Coates et al.).
We maintain the same encoder optimization, training parameters and optimizers as the respective papers.
We train the pre-trained encoders on their self-supervised objectives with our Q-Score regularizer on the latent representations.
We train with λ = 0 .
1 for 100 epochs until convergence on a single NVIDIA RTX A4000 GPU.
A.3. ROC Plots of Q-Score
We measure how effective our score is in differentiating between correctly and incorrectly classified representations in an unsupervised manner.
In Figure A.3, we plot the Precision-Recall (PR) curve and the Receiver Operating Characteristic (ROC) curve of Q-Score for SimCLR, SwaV, MoCo and BYOL, for the validation set of ImageNet-100 containingsamples.
We also compute the AUROC (area under receiver operating characteristic curve) and AUPRC (area under precision-recall curve) in differentiating between correct and incorrect classifications.
We observe up to 0 .
91 AUPRC and 0 .
74 AUROC among our baselines.
Based on these results we can conclude that, Q-Score is a reliable metric in assessing the quality and representations with lower Q-Score (quality), are more likely to be mis-classified.
A.4. Gradient Heatmaps after Q-Score Regularization
In Figure A.4, we visualize heatmaps of several samples of 4 classes in the Q-Score regularized model.
The discriminative features under each class, activate relevant attributes for each example within that class.
The noisy features, in contrast
[Figure]
[Figure] [Figure]
to Figure 4, are now not activated for the majority of the examples.
Strongly activated discriminative features, sparse representations (Figure 3) and reduced noise in heatmaps (Figure A.4), are indicators that Q-Score regularized representations are more interpretable for downstream classification.
A.5. Linear Head
In Figure A.5, we plot the magnitude of linear head weights of the top classes for each feature.
We observe that the linear head weight at the given feature index is strongly correlated with a particular class.
The class mappings are identical to those observed in Figure 1.
This indicates that the linear head implicitly learns to assign higher weights for discriminative features at their respective classes.
A.6. Selecting Discriminative Features
In Figure 2, we select features based on the number of times they are dominant in the population.
Discriminative features are selected in the middle portion, illustrated by dotted black lines.
In this section, we discuss the performance when the selection range is either to the left or the right of the curve.
In Figure A.6, we add two additional baselines on top of Figure A.2. The red curve shows the top-1 accuracy of features selected from the lower tail (left) of Figure 2.
The purple curve shows the top-1 accuracy of features selected from the upper tail (right) of Figure 2.
We observe that discriminative features outperform all baselines, indicating that selecting discriminative features from the middle portion in Figure 2 is optimal for best linear evaluation performance.
A.7. Deconstructing Self-Supervised Q-Score
The self-supervised Q-Score contains two components - 1)
The mean of the discriminative features within a representation and 2)
The L1-norm of the representation.
In Figure A.8, we visualize the AUC curves for each component separately to study their effectiveness in discriminating between correct and mis-classified representations.
We observe that the AUPRC and AUROC values, for each individual component is significantly lower compared to Q-Score in Figure A.3, for each self-supervised model baseline.
Combining both the components allows us to promote the magnitude of discriminative features, and at the same time ensure that representations remain sparse.
The improved AUC numbers in Figure A.3, confirm that combining both properties in Q-Score is more effective in distinguishing between correct and incorrect classifications.
In Figure A.7, we also visualize histograms of Q-Score between correct and mis-classified samples for 4 self-supervised models.
We observe that mis-classified representations are clearly shifted in their Q-Score distribution on each model.
This confirms that Q-Score, without the use of any label information, can predict the likelihood of being correctly classified for any given representation.
A.8. Class-wise Accuracy and Sparsity
In Figure A.9, we plot the class-wise accuracy of ImageNet-100 classes before and after Q-Score regularization.
We observe that Q-Score regularization, maintains or improves that performance of 83 classes and does not significantly degrade the performance of any class.
In Figure A.10, we plot the sparsity of the representations in ImageNet-100 before and after regularization.
Due to the use of L1-norm, we observe a significant increase in sparsity.
A.9. Transfer Performance of Q-Score Regularization
In Table A.1, we tabulate the transfer learning performance (linear evaluation) of various unseen datasets (Krizhevsky et al.
, a;b; Coates et al.
; Maji et al., 2013; Nilsback & Zisserman, 2008; Bossard et al., 2014; Krause et al., 2013; Cimpoi et al., 2014) on 4 self-supervised models trained on ImageNet-100 with Q-Score regularization.
We observe that the average accuracy of unseen datasets improves on all setups, especially on SwaV and BYOL.
We would like to mention that these d un g _ b ee t l e c h
i m e f oo t b a ll _
h e l m e t
j e a n b o tt l e c a p
D u t c h _ o v e n m il k _ c a n
M e x i c a n _ h a i r l e ss c o m p u t e r _ k e
y b
o a r d 0.0 0.
L i n e a r H e a d W e i g h t
Featurer o b i n t
o y _ t e rr i e r p a p ill o n l a p t o p
A m e r
i c a n _ c oo t t u b c a r _ w h ee l b a ss i n e t h a r e 0.
L i n e a r H e a d W e i g h t
Featurem il k _ c a n i r o n c h
i m e
D u t c h _ o v e n r e d _ f o x c a r b o n a r a r o t i ss e
r
i e t u b c
i n e m a 0.
L i n e a r H e a d W e i g h t
Featurec a u li f l o w e r c
a r _ w h ee l p
i c k u p p
i n e a pp l e m i x i n g _ b o w l r ee l c i n e m a m o p e d t r i p o d 0.
L i n e a r H e a d [Figure] e i g h t
[Figure] [Figure]
self-supervised models use ResNet-18 and are pre-trained on ImageNet-100 due to limited resource constraints, therefore, the accuracy numbers may be lower than those reported in the baselines.
In Figure A. [Figure] we visualize the gradient heatmaps of the discriminative features discovered on SimCLR on ImageNeton both ImageNet-100 and unseen datasets, Aircraft (Maji et al., 2013), Food (Bossard et al., 2014) and Cars (Krause et al., 2013).
We observe that the physical meaning associated with each discriminative feature is consistent between both the training and unseen data.
The heatmaps also correspond to informative features, strongly correlated with the ground truth.
These gradients indicate that discriminative features are transferable across unseen datasets, which support the improvement we observe in Table A.1.
We also visualize the representations of correct and incorrect classifications of the Flowers (Nilsback & Zisserman, 2008) dataset in Figure A.12.
We use SimCLR pre-trained on ImageNet-100 (top panel) and with Q-Score regularization (bottom panel).
We observe that the same properties as Figure 3 on ImageNet-100 (train dataset) transfer at test time to Flowers, an unseen dataset.
Before regularization, representations, especially the mis-classified ones are more noisy.
We observe dominant features on each sample which get more enhanced after Q-Score regularization.
The representations also become more sparse with reduced noise leading to improved top-1 accuracy as shown in Table A.1.
A.10. More Gradient Heatmaps of SimCLR
In Figures A.13, A.14, A.15 and A.16, we plot more heatmaps of discriminative and noisy features of SimCLR.
We observe that discriminative features are highly correlated with the ground truth, whereas, noisy features, map to spurious portions that do not contribute to useful information.
[Figure]
[Figure]
[Figure]
[Figure]
E n g li s h
_ f o x h o un d
G r e a t _ D a n e
A m e r
i c a n _ S t a ff o r d
s h
i r e _ t e
rr
i e r t o y _ t e rr i e r s a f e t y _ p i n
C h
e s a p e a k e _ B a y _ r e t
r
i e v e r v
i
z
s l a r ee l C h
i hu a hu a r o c k
c r a b f i dd l e r _ c r a b p e d e s t a l m il k _ c a n l a n g u r s t r e t c h e r
M e x i c a n _ h a i r l e ss m o d e m
W a l k e r _ h o un d
D o b e r m a n p u r
s
e
i r o n h
o n e y c
o m b s a r o n g b o
nn e t b o tt l e c a p r o c k i n g _ c h a i r b o x e r l a m p s h a d e t r i p o
d v a c uu m c a r _ w h ee l c h i m e R o tt w e il e r S a l u k i
j e a n c o y
o t e t u b m o r t
a r b o a r d c h
o c o l a t e _ s a u c e
b
o r z
o i s li
d e _ r u l e w i n d o w _
s c r ee n h o g n o s e _ s n a k
e m ee r k a t
r e d _ f o x k u v a s z l a p t o p
D u t c h _ o v e n g r ee n _ m a m b a c o c k t a il _ s h a k e r g a s m
a s k o b e li s k h a r m o n i c a
G il a _ m o n s t e r h e a d _ c a bb a g e t h r o n e p a r k _ b e n c h c o m p u t e r _
k e y b
o a r d g i bb o n c i n e m a
s k i _
m a s k r o t
i ss e
r
i e s t a n d a r d _ p oo d l e w a l k i n g _ s t i c k
A m e r
i c a n _ l o b s t e r b a ss i n e t m o u s e t r a p d un g _ b ee t l e s t i n k h
o r n t il e _ r oo f t h e a t e r _ c u r t
a
i n A m e r
i c a n _ c oo t S h
i h - T
z
u h a r e p i
c k u p t a bb y g a r t
e r _ s n a k e p a p ill o n g oo s e b a nn i s t e r h a r d _ d
i s c r o b i n c a r b o n a r a m o p e
d w il d _ b o a r m i x i n g _ b o w l f oo t b a ll _ h e l m e t k o m o n d
o r a m b u l a n c e l o r
i
k
ee t w i n g c a u li f l o w e r p
i n e a pp l e p i r a t e l e a f h
o
pp e
r b
o a t
h
o u s e li tt l e _
b l u e _
h e r o n g a r d e n _
s p
i
d e r g
y
r
o m i t
r a
A f r i c a n _ hun t
i n g _ d o g
[Figure]
[Figure] i n r e p r [Figure] e
[Figure]
[Table]
CIFAR
[Table]
[Table] [Table] [Table]
[Table] [Table] [Table]
[Table] [Table]
Aircraft
[Table] [Table]
[Table] [Table]
Flowers
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]