---
title: "Overlooked Implications of the Reconstruction Loss for VAE Disentanglement"
authors:
  - "Nathan Michlo"
  - "Richard Klein"
  - "Steven James"
doi: "10.24963/ijcai.2023/453"
url: "https://ijcai.org/proceedings/2023/453"
pdf: "https://ijcai.org/proceedings/2023/0453.pdf"
venue: "Proceedings of the Thirty-Second International Joint Conference on Artificial Intelligence"
year: 2023
pages: "4073-4081"
track: "Main Track"
keywords:
  - "Machine Learning: ML: Representation learning"
  - "Machine Learning: ML: Explainable/Interpretable machine learning"
  - "Machine Learning: ML: Unsupervised learning"
  - "Machine Learning: ML: Autoencoders"
---

# Overlooked Implications of the Reconstruction Loss for VAE Disentanglement

Nathan Michlo, Richard Klein, Steven James

*Proceedings of the Thirty-Second International Joint Conference on Artificial Intelligence*, pages 4073-4081. DOI: [10.24963/ijcai.2023/453](https://doi.org/10.24963/ijcai.2023/453)

## Abstract

Learning disentangled representations with variational autoencoders (VAEs) is often attributed to the regularisation component of the loss. In this work, we highlight the interaction between data and the reconstruction term of the loss as the main contributor to disentanglement in VAEs. We show that standard benchmark datasets have unintended correlations between their subjective ground-truth factors and perceived axes in the data according to typical VAE reconstruction losses. Our work exploits this relationship to provide a theory for what constitutes an adversarial dataset under a given reconstruction loss. We verify this by constructing an example dataset that prevents disentanglement in state-of-the-art frameworks while maintaining human-intuitive ground-truth factors. Finally, we re-enable disentanglement by designing an example reconstruction loss that is once again able to perceive the ground-truth factors. Our findings demonstrate the subjective nature of disentanglement and the importance of considering the interaction between the ground-truth factors, data and notably, the reconstruction loss, which is under-recognised in the literature.

## Full text

## 1 Introduction

A fundamental challenge in machine learning is discovering useful representations from high-dimensional data that can be used to solve subsequent tasks effectively. Recently, deep learning approaches have showcased the ability of neural networks to extract meaningful features from high-dimensional inputs for tasks such as classification [Krizhevsky et al., 2012] and reinforcement learning [Mnih et al., 2015]. However, these learned representations are often not semantically meaningful, which can negatively impact interpretability, fairness [Locatello et al., 2019a], and downstream task performance [Locatello et al., 2019b].

Prior work has therefore argued that it is desirable to learn a representation that is disentangled [Bengio et al., 2013]. While there is no consensus on what constitutes a disentangled representation, it is generally agreed that it should be factorised so that each latent variable corresponds to a single explanatory variable responsible for generating the data [Burgess et al.,

2017]. For example, a single image from a video game may be represented by continuous latent variables governing the x and y positions of the player or enemies, as well as categorical variables governing their clothing or appearance.

A common approach to discovering these representations is variational autoencoders (VAEs) [Kingma and Welling, 2014], which are trained on unlabelled data to learn a lowerdimensional representation capable of reconstructing the input. However, it has been shown that unsupervised methods cannot reliably learn representations without the introduction of supervision or inductive biases [Locatello et al., 2019b]. The recently introduced Ada-GVAE framework partially overcame this problem by using a weakly supervised signal to discover underlying factors [Locatello et al., 2020], but there remains room for improvement.

Interestingly, VAEs do not have an explicit mechanism that encourages the learning of disentangled representations, but it is theorised that this behaviour is related to the regularisation term and the information bottleneck principle [Burgess et al., 2017; Mathieu et al., 2019; Rolinek et al., 2019]. However, despite this hypothesis, there is still no explicit reason for why the representations learnt by these frameworks should align with generative factors in the data. Nonetheless, these frameworks have been shown to produce disentangled representations when trained on synthetically generated data, as measured by appropriate metrics [Eastwood and Williams, 2018; Chen et al., 2018; Zaidi et al., 2020].

In this paper, we aim to understand why VAEs implicitly learn disentangled representations by investigating the interaction between the reconstruction loss of the VAE and the input data. We provide compelling evidence that disentanglement occurs not because of special algorithmic choices or the regularisation term, but because of how VAEs perceive distances between observations in the datasets themselves according to the reconstruction loss, and the fact that these distances accidentally correlate to the chosen ground-truth factors generating the data. In particular, we find that standardised benchmarks are constructed in such a way that they unintentionally encourage models to learn what appear to be disentangled representations.

The main, summarised contributions of this paper 1 are:

1 Our extended paper with factor importance results and full experiment details is available at: https://arxiv.org/abs/2202.13341

- (i) We introduce the concept of perceived distance, in terms of the VAE reconstruction loss, to measure overlap or similarity between dataset pairs. We demonstrate that perceived distances in existing datasets unintentionally correspond to the distances between ground-truth factors, and that VAEs learn these distances, explaining why learnt representations may appear disentangled.
- (ii) We provide a technique to visualise the correlation between perceived distances in the data and ground-truth factors generating the data. We use this understanding to provide a theory for what constitutes an adversarial dataset under a given reconstruction loss.
- (iii) We reveal the ineffectiveness of state-of-the-art models by using our theory to design a simple, example adversarial dataset with constant perceived distance between elements, over which VAE-based frameworks fail to learn disentangled representations.
- (iv) We provide an example solution to the adversarial dataset that modifies the reconstruction loss, and thus perceived distances across the dataset, so that VAE frameworks are again able to capture the ground-truth factors.
- (v) We contribute Disent, a general PyTorch [Paszke et al., 2017] disentanglement framework, with common models, metrics, and datasets. 2

## 2 Background

Assume a dataset X = {x(0) , ..., x(n)} is a set of independent and identically distributed (i.i.d) observations x ∈ RN, generated by some random process involving an unobserved random variable z ∈ RD of lower dimensionality D ≪ N. Additionally, the true prior distribution z ∼ p∗(z) and true conditional distribution x ∼ p∗(x|z) are unknown. Variational autoencoders (VAEs) aim to learn this generative process. Unlike autoencoders (AEs), which consist of an encoder fϕ(x) = z and decoder gθ(z) = ˆx with weights ϕ and θ, VAEs instead construct a probabilistic encoder by using the output from the encoder or inference model to parameterise approximate posterior distributions z ∼ qϕ(z|x). The approximate posterior is then sampled during training to obtain representations z, which are then decoded using the generative model to obtain reconstructions ˆx ∼ pθ(x|z).

A factorised Gaussian encoder [Kingma and Welling, 2014] is commonly used. The posterior is modelled using a multivariate Gaussian distribution with diagonal covariance z ∼ N(µϕ(x), σϕ(x)), and the prior is given by the multivariate normal distribution pθ(z) = N(0, I), with a mean of 0 and diagonal covariance I. To enable backpropagation, the reparameterisation trick in Equation (1) is used to sample from the posterior distribution by offsetting the distribution means by scaled noise values. 3

<!-- formula-not-decoded -->

VAEs maximise the evidence lower bound (ELBO) by minimising the loss given by Equation (4). VAE-based approaches often make slight modifications to this loss [Higgins et al., 2016; Zhao et al., 2017; Hou et al., 2017; Kumar et al., 2018; Chen et al., 2018; Kim and Mnih, 2018; Locatello et al., 2020], but the terms of these modified loss functions can usually still be grouped into reconstruction and regularisation components, given by Equations 2 and 3 respectively. The regularisation term affects the representations learnt by the encoder, while the reconstruction term improves the outputs from the decoder. These terms usually contradict in practice, with strong regularisation leading to worse reconstructions but often better disentanglement [Higgins et al., 2016; Burgess et al., 2017].

2 Disent framework repository: https://github.com/nmichlo/disent. Code is provided under the MIT license.

3 The notation ⊙ represents the element-wise product.

Figure 1: Nearby distributions in the latent space that correspond to different inputs. The VAE reconstructs a sample from the middle distributions. Left: weaker regularisation leads to few sampling mistakes, resembling a lookup table [Mathieu et al., 2019]. Right: strong regularisation leads to more reconstruction mistakes, where samples are attributed to nearby distributions, encouraging reorganisation.

![Image](https://ijcai.org/proceedings/2023/fulltext/453/image_000000_66b3318e9b47b63eabae59a327490d9a6cf9607238a5b1d5652abde992532e00.png)

<!-- formula-not-decoded -->

<!-- formula-not-decoded -->

<!-- formula-not-decoded -->

## 2.1 Random Sampling Reorganises VAE Embeddings

Disentanglement in VAEs is generally attributed to the regularisation term in Equation (3); however, we highlight that regularisation only enables the underlying disentanglement mechanism. Disentanglement arises rather as a result of VAEs reorganising the latent space to minimise reconstruction mistakes due to random sampling from the probabilistic encoder during training. Through this mechanism, a VAE will place similar observations according to the reconstruction loss in Equation (2) close together in the latent space [Burgess et al., 2017; Mathieu et al., 2019; Zietlow et al., 2021], as this action minimises sampling errors.

The regularisation term enables this interaction by controlling the overlap between latent distributions corresponding to different inputs. If these distributions overlap sufficiently, the decoder will often attribute a random sample to an incorrect input, see Figure 1. Thus, a mistake will be made during the decoding process, which encourages reorganisation to minimise the reconstruction error.

## 3 RelatedWork

The following works are the most applicable to our research, falling under three general categories: (i) explanations for disentanglement, (ii) the role of the reconstruction loss in disentanglement, and (iii) problems with disentanglement.

Firstly, Burgess et al.[2017] relate VAEs to the information bottleneck principle. Which explains that random sampling leads to a local minimisation of the reconstruction loss which reorganises the latent space so that points close in pixel space are close in the latent space. Mathieu et al.[2019] argue that VAEs do not explicitly encourage disentanglement through their design. Rather, they provide the explanation that the diagonal prior typically used in VAEs when combined with random sampling produces a similar effect to PCA. Our work takes inspiration from these ideas to develop the theory of perceived overlap in VAEs, which we use to analyse datasets and improve or hinder disentanglement.

Secondly, inspired by Burgess et al.[2017] most modern frameworks offer some way to balance the regularisation and reconstruction components of the loss, the ControlVAE automates this process [Shao et al., 2020]. Hou et al.[2017] instead swap out the reconstruction loss of VAEs for a perceptual loss function, which can improve the representations learnt by the model. Zietlow et al.[2021] extend the analysis of Mathieu et al.[2019]; However, emphasis is placed on constructing adversarial datasets that hinder disentanglement performance using a mild transformation, obtained from trained models which achieve poor disentanglement scores. Our work provides intuition by constructing an example adversarial dataset that targets a specific reconstruction loss, and then remedies this problem by adjusting the loss.

Finally, Locatello et al.[2019b] show that useful representations cannot be reliably learnt with unsupervised methods, unless inductive biases are introduced, and Gondal et al.[2019] show that representations learnt on synthetic data often do not transfer well to real-world data. Our work investigates the interplay between the reconstruction loss and data as the main bias in VAEs, standard choices accidentally disentangle synthetic data.

## 4 Existing Disentanglement Datasets

Consider the 3D Shapes dataset [Burgess and Kim, 2018] in Figure 2a, which contains observations of shapes fixed in the centre of the image with progressively changing attributes or factors such as size and colour. If, as humans, we are given unordered observations from a traversal along the size factor of 3D Shapes, it would be easy to order these observations using a perceived increase or decrease in the size of the shape. We might even say that the shapes in the images overlap by different amounts, considering shapes that are closer in size to possess more overlap, and thus also considering them as closer together in terms of distance. This idea naturally extends to VAEs ordering pairs of observations, and so we seek to investigate the correspondence between how these frameworks perceive distances over data points to reorganise the latent space and the ground-truth factors themselves.

## 4.1 Dataset Ground-truth Distance

Synthetic datasets [Burgess and Kim, 2018; LeCun et al., 2004; Matthey et al., 2017; Reed et al., 2015; Gondal et al., 2019] used for benchmarking disentanglement frameworks are all generated from F ∈ N+ ground-truth factors of variation. Each factor i ∈ [F] represents some property about the data that can be varied, 4 and has a dimensionality or size of fi &gt; 0

4 The bracket notation [F] gives the natural numbers set {1, ..., F}.

where fi ∈ N+. The set of all factors used for generating the dataset is written as Y = [f1] × ... × [fF]. The full dataset is generated from this set of factors using some ground-truth generative process X = {g∗(y) | y ∈ Y}. Examples of this generative process are given in Figure 2.

With this construction of synthetic datasets, it is fitting to describe the ground-truth distances between observations x(a) , x(b) ∈ X using the Manhattan or ℓ1 distance between their corresponding ground-truth factors y(a) , y(b) ∈ Y, 5 as in Equation (5). It is important to note that this choice may not be optimal for single factors; rather, ℓ1 distance naturally aligns with how the datasets are constructed.

<!-- formula-not-decoded -->

## 4.2 VAE Perceived Distance

With the idea of ground-truth distances between observations, we need a distance measure between observations as perceived by VAE frameworks. We derive the perceived distance between dataset elements from the noisy sampling procedure and the chosen reconstruction loss in a VAE framework.

Let z(b) ∼ qϕ(z|x(a) ) be a (possibly incorrect) sample from the posterior distribution corresponding to some input element x(a) ∈ X . Since the regularisation term encourages latent distributions to overlap, this sample z(b) may be incorrectly attributed by the decoder to a distribution corresponding to some other element from the dataset x(b) ∈ X , with reconstruction ˆx(b) ≈ x(b) . As the VAE objective consisting of the regularisation and reconstruction losses is jointly optimised, the decoder becomes better at reconstructing the inputs. In an ideal scenario, the inputs map to outputs (ˆx → x), and reconstructions are samples from our dataset: ˆx ∈ X . While this is not the case in practice due to the regularisation term, we derive the perceived distance in Equation (7) from this assumption that ˆx → x. This allows us to directly compare the elements x(a) , x(b) ∈ X within a dataset using the reconstruction loss as a distance function:

<!-- formula-not-decoded -->

<!-- formula-not-decoded -->

The perceived distance depends on the choice of reconstruction loss, which in literature is usually the pixel-wise Mean Squared Error (MSE) for data that is assumed to be normally distributed. We assume MSE is used throughout the rest of this work, unless specified. Note that analyses are similar for other pixel-wise losses, such as Binary Cross-Entropy (BCE).

## 4.3 Perceived Distances Correspond to Ground-Truth

In Section 4.1, all the ground-truth factors of a dataset are defined as the set Y = [f1] × . . . × [fF]. In Equation (9), we now define a factor traversal Y (a,i) ⊂ Y as the ordered set of all the coordinates along a factor i ∈ [F] such that the set passes through a point y(a) ∈ Y. The number of elements in the traversal is equal to the size of the chosen factor |Y (a,i) | = fi, and each element in the traversal generates the same traversal ∀y(b) ∈ Y (a,i) , Y (a,i) = Y (b,i) . Figure 2 gives examples of traversals.

5 When indexing y(a) , z(a) , x(a) , for convenience a may be an integer or a ground-truth factor a = y(a)

<!-- formula-not-decoded -->

<!-- formula-not-decoded -->

We compute the distance matrix ˜D(a,i) ∈ Rfi×fi , for some distance function d, between pairwise elements along a factor traversal Y (a,i) , written in Equation (10) using matrix notation.

<!-- formula-not-decoded -->

To examine the ground-truth factors within our datasets, we compute the average distance matrix D(i) = Ea∈Y[ ˜D(a,i) ] for each factor i ∈ [F]. We plot these results in Figure 3 for both the ground-truth distance dgt and perceived distance dpcv. It is immediately obvious from these plots that the groundtruth distances and the distances perceived by a VAE may accidentally correspond.

Finally, we relate our work to Burgess et al.[2017] by outlining a direct approach in our extended paper in Footnote 1 for computing relative factor importance using perceived distances. A factor is considered more important if a VAE prefers to learn it before another factor.

## 4.4 VAEs Learn Perceived Distances

We compute distance matrices over a trained β-VAE at various levels of the network, including the representation layer and reconstructions. At each level of the VAE, the learnt distances all correspond to the original perceived distances already present within the dataset, see Figure 4. Since VAEs reorganise the embedding space according to the perceived distances, and noting results from Section 4.3, VAEs may discover structures that are similar to the underlying ground-truth factors.

Our results in Figures 3 and 4 provide empirical evidence that VAEs mimic the distances already present in the dataset according to the reconstruction loss. To appear disentangled if the goal is factored representations, individual latent units will need to encode portions of the distances that correspond to factors within the data. However, it is known that VAEs with diagonal priors are rotationally invariant [Mathieu et al., 2019], thus the same distances between the means µ of latent distributions can be learnt for any arbitrary rotation of the latent space. This suggests that VAEs disentangle by accident, since ground-truth factors naturally correspond with distances in the dataset. If these perceived distances were to change such that they do not correspond to the ground-truth distances, VAEs might not be able to learn meaningful representations. This is highlighted by the fact that VAEs are already known to perform poorly on real-world data [Gondal et al., 2019].

## 5 Adversarial Datasets

In the previous section, we highlighted the striking similarity between the ground-truth distances and the perceived distances between observations in synthetic ground-truth datasets. This suggests that disentanglement occurs because latent distances accidentally correspond to ground-truth distances, when the latent space is reorganised to minimise reconstruction errors and perceived distances from the data space are captured.

Consider the example of a single chess piece moving across a chess board; there are no smooth transitions between grid points, since the piece is only valid when placed in the middle of squares. We describe such a dataset as having constant perceived distance. This property is adversarial in nature as it is impossible for a VAE to order these observations using pixel-wise perceived distance. It is tempting to think that a harder case is if the perceived distances do not correspond to ground-truth distances; however, an (incorrect) ordering can then still be found. Existing datasets such as Cars3D already satisfy this incorrect ordering, which may explain the generally worse disentanglement performance compared to other datasets, see Figure 3.

Formally, we say that a dataset has constant overlap when the pairwise distances over factor traversals are all equal. Let i ∈ [F] be a factor and y(a) ∈ Y be ground-truth coordinate vector. Then, for all elements over the factor traversal ∀y(b) ∈ Y (a,i) / {y(a)}, the corresponding perceived distance is constant such that dpcv(x(a) , x(b) ) = Cf with Cf ∈ R and Cf &gt; 0. Along factor traversals in such a dataset, no distinct ordering of elements can be found when a VAE tries to minimise the sampling error over the reconstruction loss. Going forward, we only consider the case where ∀f ∈ [F], Cf = C for some C &gt; 0.

## 5.1 Example XYSquares Adversarial Dataset

Taking inspiration from the chess piece example, we design a synthetic adversarial dataset called XYSquares (See Figure 5)

Figure 2: Common existing datasets used to benchmark disentanglement frameworks. These synthetic datasets are generated from ground-truth factors. Columns: represent a traversal along a single factor.

![Image](https://ijcai.org/proceedings/2023/fulltext/453/image_000001_4174b689aab122b489505d1929c01f692d1cb4bb82b28dfcdcb97efa5c76cf9c.png)

Figure 3: Distances in the ground-truth factor space naturally correspond to distances in the data space for current synthetic datasets. Top Row: Average ground-truth distance (ℓ1) matrices over factor traversals. Bottom Row: Average pixel-wise perceived distance (MSE) matrices over observations from the same factor traversals. Columns: Different ground-truth factors within each dataset.

![Image](https://ijcai.org/proceedings/2023/fulltext/453/image_000002_b295e61f413ba37f500cd6fb2d65c98bb22e8fe36c5d6607254c71e3767077ad.png)

Figure 4: β-VAEs learn similar distances between observations at all levels of the network depending on the reconstruction loss. Rows: Different factors of the Cars3D dataset (Top to bottom: elevation, azimuth, car type), Columns: Distance matrices computed over factor traversals (Left to right: ground-truth distances, perceived distances between observations, ℓ2 distances over latent distribution means, KL divergences between latent distributions, perceived distances between reconstructions).

![Image](https://ijcai.org/proceedings/2023/fulltext/453/image_000003_d82ddaa668884031ce0c9804f71045e23ec9329b591246941290e001db62c9ec.png)

that specifically targets VAEs that use a pixel-wise reconstruction loss such as MSE, resulting in constant perceived distances. The dataset consists of three 8 × 8 pixel squares in a world of size of 64 × 64. This leaves 8 grid positions along each axis without any pixel-wise overlap. The three squares are each assigned a colour according to R (1, 0, 0), G (0, 1, 0) and B (0, 0, 1) to avoid any channel-wise overlap. With 6 ground-truth factors (three squares moving along two axes), each with 8 possible values, this gives a total dataset size of 86 = 262144 observations. In the rightmost column of Figure 8, we validate that this leads to constant perceived distances between observation pairs in factor traversals.

Figure 5: Columns represent ground-truth factor traversals over our adversarial XYSquares dataset. Pixel-wise losses measure constant values along these traversals.

![Image](https://ijcai.org/proceedings/2023/fulltext/453/image_000004_862154ba23c33d33e5f53a8a5df3950ff41c0127ebcfd99e3665eb1bf01cb1e8.png)

## 5.2 Experimental Setup

We now investigate the performance of VAEs on our new dataset. In particular, we use the unsupervised β-VAE [Higgins et al., 2016] and the state-of-the-art weakly supervised Ada-GVAE [Locatello et al., 2020]. The β-VAE scales the VAE regularisation term with a coefficient β &gt; 0, while the Ada-GVAE breaks symmetry and encourages shared latent variables between pairs of observations. This is achieved by averaging together latent distributions between observation pairs that are estimated to remain unchanged when the KL divergence is below some threshold. We note that if the weakly supervised Ada-GVAE performs poorly, then it is highly likely that another unsupervised method will also perform poorly.

We use the same Adam [Kingma and Ba, 2015] optimiser and convolutional neural architecture as Burgess et al.[2017]. To evaluate disentangled representations, we use the MIG [Chen et al., 2018] (Mutual Information Gap) and DCI Disentanglement [Eastwood and Williams, 2018] scores. MIG measures the mutual information between the highest and second highest latent units for each factor, and DCI Disentanglement measures how much each latent unit captures a ground-truth factor using a predictive model.

Finally, we perform an extensive hyper-parameter grid search for existing frameworks and datasets before running our own experiments. Hyperparameters include the learning rate, size of the latent dimension, training steps, batch size and β values. See our extended paper in Footnote 1 for further details on all experiments conducted throughout the remainder of the paper.

## 5.3 Example Adversarial Dataset Results

Figure 6 shows that the disentanglement performance over XYSquares is extremely poor compared to existing datasets, even with the state-of-the-art Ada-GVAE. We are concerned only with the maximum score obtained for each model and dataset, as the graph is plotted over the hyper-parameter sweeps. This validates our adversarial dataset hypothesis in Section 5. Not only is the disentanglement performance poor, but much smaller values for β are needed when tuning the regularisation loss. Example latent traversals from a VAE trained over the adversarial dataset are given in Figure 7, results are far from disentangled and do not correspond in any way to the ground-truth factors in Figure 5.

## 5.4 Example of Varying Levels of Overlap

We have examined the effect of training on existing datasets with significant amounts of overlap, as well as our own adversarial dataset with constant perceived distances according to pixel-wise losses. However, we have not investigated increasing levels of overlap in datasets, or rather reducing perceived between observations that are also close in ground-truth factor space. To do so, we modify XYSquares by decreasing the spacing between grid points while keeping the number of grid points constant along each factor, ensuring the dataset size remains fixed at 86 = 262144 observations.

Figure 6: Densities over repeated runs for the attained MIG scores (left) and DCI Disentanglement scores (right) for the weaklysupervised Ada-GVAE (Left half of densities) and β-VAE (Right half of densities). XYSquares hurts the disentanglement performance significantly. Quartiles are marked with horizontal lines. We sweep over β values and latent dimension sizes. See our extended paper in Footnote 1 for details.

![Image](https://ijcai.org/proceedings/2023/fulltext/453/image_000005_b816cf1774f8612d26b96b640cb90b302148c257ca1bcc2ca07b18ef89046e69.png)

Figure 7: VAEs with pixel-wise losses fail to learn disentangled representations over the XYSquares dataset. Rows show latent traversals over a subset of latent units of a β-VAE. Varying one latent unit does not have an obvious effect or correspond to ground-truth factors.

![Image](https://ijcai.org/proceedings/2023/fulltext/453/image_000006_43b242cc9290cbccb0c73a1f01a671b0758ec89de936b548e37b1282fa67f0c4.png)

The original adversarial dataset, with a spacing of 8, has a constant distance value of dpcv(x(a) , x(b) ) = C8. As the spacing s decreases from 8 → 1 over the datasets, the probability increases that any two observations re-sampled along a single factor traversal overlap p(dpcv(x(a) , x(b) ) &lt; C8) and should thus be placed closer together in the latent space. More overlap leads to more unique distance values which in turn allows for easier ordering of data points. We visualise this concept using ground-truth and perceived distance matrices in Figure 8.

We verify our statements through the experimental results in Figure 9, where the β-VAE and Ada-GVAE are trained on these datasets. As the spacing decreases and overlap is introduced, the disentanglement performance improves, since it is easier for a VAE to introduce an ordering over representations. Even for the XYSquares dataset with 1 pixel of overlap between grid points, an ordering of elements along factor traversals can be induced. However, the probability of a VAE encountering these scenarios in the latent space due to random sampling is low, and thus it is still not always easy for the model to learn disentangled representations over such a dataset.

Figure 8: Ground-truth distance matrices (far left) and pixel-wise perceived distance matrices (left to right) over factor traversals. The spacing between grid-points of XYSquares decreases from 8px to 1px, which improves the correlation between perceived distances and ground-truth distances.

![Image](https://ijcai.org/proceedings/2023/fulltext/453/image_000007_25d5723af3d9175af3d3223f8c846d255f33b085f79973e9ffc8d93ca8cba985.png)

Figure 9: XYSquares spacing vs disentanglment score (MIG - left, DCI Disentanglement - right). Decreasing (left to right) levels of overlap leads to decreased disentanglement performance. Each experiment is repeated 5 times with previously tuned hyper-parameters. See our extended paper in Footnote 1 for further details.

![Image](https://ijcai.org/proceedings/2023/fulltext/453/image_000008_ae0774ba0cc1d602f0ead3b4b0f79d1ebd8aea4c45bf8e611480626f029d2e66.png)

## 6 Example of Introducing Overlap

The previous section focused on increasing overlap by changing the underlying dataset; however, this still does not solve the case for the original XYSquares dataset with constant pixel-wise perceived distance. Throughout this paper, we have provided evidence that VAEs disentangle based on their reconstruction loss, which happens to align with ground-truth factors of variation in common benchmark datasets. This correspondence is not optimal for all tasks and we propose that this leads to the poor disentanglement performance in these settings. Our solution is to choose a loss function that modifies perceived distances such that they also correspond to ground-truth distances.

The new loss function we choose cannot be a pixel-wise approach, as this does not capture the distances due to the spatial nature of the XYSquares dataset. For the sake of simplicity in this example, we convert the existing pixel-wise loss function into a spatially aware loss function by introducing a differentiable augmentation to its inputs. An appropriate augmentation for our dataset is a channel-wise box blur. The problem, however, is that the decoder needs to be able to reconstruct the data, and so purely replacing the pixel-wise loss with the augmented loss may not succeed. Rather, in Equation (11), we append the augmented term to the existing loss and scale it by a constant α &gt; 0.

<!-- formula-not-decoded -->

Figure 10: β-VAEs learn similar distances between observations. Top row: box blur augmented MSE. Bottom row: pixel-wise MSE loss. Columns: Distance matrices computed over factor traversals. All factors of XYSquares have the same statistics. This plot is constructed in a similar way to Figure 4.

![Image](https://ijcai.org/proceedings/2023/fulltext/453/image_000009_8bf6434bbc22da3f21f033317782a0f659c8cd42b54de3ef73228abeb9567914.png)

## 6.1 Example Augmented Loss Experiments

We choose a channel-wise box blur for our loss function with a radius of 31, or a total kernel size of 63 × 63. We efficiently implement large filters using the Fast Fourier Transform. The size of the filter ensures that if two observations have active pixels on opposite sides of the images, then overlap will still be introduced between them. We set α = 632 , while this appears large, a box blur kernel is normalised so that the sum of all its values is 1. We accordingly update our perceived distance measure and evaluate the new distances over the XYSquares dataset for each factor in Figure 10 after training and tuning β-VAEs.

Finally, in Figure 11, we compare the performance of the spatially-aware loss function to the original pixel-wise loss. Our new loss significantly improves the disentanglement performance over the adversarial dataset. This is because it allows our models to capture perceived distances between observations that align with the ground-truth factors.

While our choice of loss may not be optimal for disentanglement of these specific x and y factors from our adversarial dataset, disentanglement results are impressive. This is important because it provides the intuition that changing the loss function changes perceived distances and affects the ability of VAE frameworks to learn disentangled representations. We leave learning or identification of optimal reconstruction losses for different datasets, to improve disentanglement, as future work.

Figure 11: MIG and DCI scores for Ada-GVAE and β-VAE using the MSE loss and our modified loss function. Introducing a spatially aware loss function allows us to capture ground-truth distances between observations and allows the models to disentangle the adversarial XYSquares dataset.

![Image](https://ijcai.org/proceedings/2023/fulltext/453/image_000010_e0efaa492618968d8f03a8f0ef1ea9e3b0ab007a9489de40b7df7cc6285d9c0c.png)

## 7 Considerations for Disentanglement Research

We highlight the similarity between introducing overlap in Section 6 through the reconstruction loss function and varying levels of overlap in Section 5.4 through modifications to the construction of the dataset itself. Both methods aim to improve disentanglement by changing perceived distances to better correspond to the ground-truth factors, while keeping groundtruth factors fixed.

The problem is that ground-truth factors can indeed change, and this choice, while at the discretion of the researcher, is largely ignored in literature. For example, a researcher may choose RGB, HSV or categorical representations for colours, they may choose binary or continuous encodings for positions, or they may split or merge various factors together.

As our work shows, disentanglement is largely dependent on the chosen reconstruction loss and not special algorithmic choices. Obtaining improved disentanglement results under current VAE disentanglement frameworks will ultimately require supervision from the researcher to adjust perceived distances of the model to the task at hand. This contradicts the current notion that unsupervised and weakly supervised disentanglement methods can automatically uncover these human interpretable ground-truth factors [Higgins et al., 2016].

Ultimately, benchmarking against synthetic datasets with already subjective ground-truth factors will thus always remain problematic. There are infinitely many datasets with infinitely many choices as to what constitutes their ground-truth factors. Accurate disentanglement through future methods may need general world knowledge so that the methods can adapt to the task at hand.

## 8 Conclusion

In this paper, we demonstrated that there are fundamental characteristics of existing datasets that encourage VAEs to learn disentangled representations. Our work provides a theory for how VAEs perceive distances between pairs of observations in datasets. We used this theory to provide intuition by constructing an adversarial dataset for pixel-wise losses over-which state-of-the-art VAEs fail to learn disentangled representations. Finally, we re-enabled disentanglement over the example adversarial dataset by again adjusting perceived distances, instead through a change of the VAE reconstruction loss to capture the ground-truth factors of the dataset.

Our results highlight issues in current representation learning approaches. We find that the focus on regularisation for disentanglement is misplaced, rather, disentanglement is largely accidental, and careful choice of the reconstruction loss or data is needed to capture the ultimately subjective ground-truth factors. This is impractical in the real world, since perceived distances cannot be a prerequisite for true disentanglement. More advanced methods are therefore required that can uncover true meaning within the data.

## Acknowledgements

Computations were performed using the High Performance Computing infrastructure provided by the Mathematical Sciences Support unit at the University of the Witwatersrand.

## References

1. [Bengio et al., 2013] Yoshua Bengio, Aaron Courville, and Pascal Vincent. Representation learning: A review and new perspectives. IEEE Transactions on Pattern Analysis and Machine Intelligence, 35(8):1798-1828, 2013.
2. [Burgess and Kim, 2018] Christopher Burgess and Hyunjik Kim. 3D shapes dataset. https://github.com/deepmind/ 3dshapes-dataset, 2018. Accessed: 2023-01-01.
3. [Burgess et al., 2017] Christopher Burgess, Irina Higgins, Arka Pal, Loic Matthey, Nick Watters, Guillaume Des- jardins, and Alexander Lerchner. Understanding disentan- gling in β-VAE. In Workshop on Learning Disentangled Representations at the 31st Conference on Neural Informa- tion Processing Systems,, 2017.
4. [Chen et al., 2018] Ricky Chen, Xuechen Li, Roger Grosse, and David Duvenaud. Isolating sources of disentangle- ment in variational autoencoders. In Advances in Neural Information Processing Systems, pages 2615-2625, 2018.
5. [Eastwood and Williams, 2018] Cian Eastwood and Christo- pher Williams. A framework for the quantitative evaluation of disentangled representations. In International Confer- ence on Learning Representations, 2018.
6. [Gondal et al., 2019] Muhammad Waleed Gondal, Manuel Wuthrich, Djordje Miladinovic, Francesco Locatello, Mar- tin Breidt, Valentin Volchkov, Joel Akpo, Olivier Bachem, Bernhard Schölkopf, and Stefan Bauer. On the transfer of inductive bias from simulation to the real world: a new disentanglement dataset. Advances in Neural Information Processing Systems, 32:15740-15751, 2019.
7. [Higgins et al., 2016] Irina Higgins, Loic Matthey, Arka Pal, Christopher Burgess, Xavier Glorot, Matthew Botvinick, Shakir Mohamed, and Alexander Lerchner. beta-vae: Learning basic visual concepts with a constrained varia- tional framework. 2016.
8. [Hou et al., 2017] Xianxu Hou, Linlin Shen, Ke Sun, and Guoping Qiu. Deep feature consistent variational autoen- coder. In 2017 IEEE Winter Conference on Applications of Computer Vision, pages 1133-1141. IEEE, 2017.
9. [Kim and Mnih, 2018] Hyunjik Kim and Andriy Mnih. Dis- entangling by factorising. In International Conference on Machine Learning, pages 2649-2658. PMLR, 2018.
10. [Kingma and Ba, 2015] Diederik Kingma and Jimmy Ba. Adam: A method for stochastic optimization. In Inter- national Conference on Learning Representations, 2015.
11. [Kingma and Welling, 2014] Diederik Kingma and Max Welling. Auto-encoding variational bayes. In International Conference on Learning Representations, 2014.
12. [Krizhevsky et al., 2012] Alex Krizhevsky, Ilya Sutskever, and Geoffrey Hinton. Imagenet classification with deep convolutional neural networks. Advances in Neural Infor- mation Processing Systems, 25:1097-1105, 2012.
13. [Kumar et al., 2018] Abhishek Kumar, Prasanna Sattigeri, and Avinash Balakrishnan. Variational inference of disen- tangled latent concepts from unlabeled observations. In In- ternational Conference on Learning Representations, 2018.
14. [LeCun et al., 2004] Yann LeCun, Fu Jie Huang, and Leon Bottou. Learning methods for generic object recognition with invariance to pose and lighting. In IEEE Computer Society Conference on Computer Vision and Pattern Recog- nition, 2004.
15. [Locatello et al., 2019a] Francesco Locatello, Gabriele Ab- bati, Thomas Rainforth, Stefan Bauer, Bernhard Schölkopf, and Olivier Bachem. On the fairness of disentangled repre- sentations. In Advances in Neural Information Processing Systems, pages 14584-14597, 2019.
16. [Locatello et al., 2019b] Francesco Locatello, Stefan Bauer, Mario Lucic, Gunnar Raetsch, Sylvain Gelly, Bernhard Schölkopf, and Olivier Bachem. Challenging common assumptions in the unsupervised learning of disentangled representations. In International Conference on Machine Learning, pages 4114-4124. PMLR, 2019.
17. [Locatello et al., 2020] Francesco Locatello, Ben Poole, Gun- nar Rätsch, Bernhard Schölkopf, Olivier Bachem, and Michael Tschannen. Weakly-supervised disentanglement without compromises. In International Conference on Ma- chine Learning, pages 6348-6359. PMLR, 2020.
18. [Mathieu et al., 2019] Emile Mathieu, Tom Rainforth, Nana Siddharth, and Yee Whye Teh. Disentangling disentangle- ment in variational autoencoders. In International Con- ference on Machine Learning, pages 4402-4412. PMLR, 2019.
19. [Matthey et al., 2017] Loic Matthey, Irina Higgins, Demis Hassabis, and Alexander Lerchner. dSprites: Disentangle- ment testing sprites dataset. https://github.com/deepmind/ dsprites-dataset, 2017. Accessed: 2023-01-01.
20. [Mnih et al., 2015] Volodymyr Mnih, Koray Kavukcuoglu, David Silver, Andrei A Rusu, Joel Veness, Marc G Belle- mare, Alex Graves, Martin Riedmiller, Andreas K Fidje- land, Georg Ostrovski, et al. Human-level control through deep reinforcement learning. Nature, 518(7540):529-533, 2015.
21. [Paszke et al., 2017] Adam Paszke, Sam Gross, Soumith Chintala, Gregory Chanan, Edward Yang, Zachary DeVito, Zeming Lin, Alban Desmaison, Luca Antiga, and Adam Lerer. Automatic differentiation in PyTorch. 2017.
22. [Reed et al., 2015] Scott Reed, Yi Zhang, Yuting Zhang, and Honglak Lee. Deep visual analogy-making. Advances in Neural Information Processing Systems, 28:1252-1260, 2015.
23. [Rolinek et al., 2019] Michal Rolinek, Dominik Zietlow, and Georg Martius. Variational autoencoders pursue PCA di- rections (by accident). In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pages 12406-12415, 2019.
24. [Shao et al., 2020] Huajie Shao, Shuochao Yao, Dachun Sun, Aston Zhang, Shengzhong Liu, Dongxin Liu, Jun Wang, and Tarek Abdelzaher. Controlvae: Controllable varia- tional autoencoder. In International Conference on Ma- chine Learning, pages 8655-8664. PMLR, 2020.
25. [Zaidi et al., 2020] Julian Zaidi, Jonathan Boilard, Ghys- lain Gagnon, and Marc-André Carbonneau. Measuring disentanglement: A review of metrics. arXiv preprint arXiv:2012.09276, 2020.
26. [Zhao et al., 2017] Shengjia Zhao, Jiaming Song, and Ste- fano Ermon. InfoVAE: Information maximizing variational autoencoders. arXiv preprint arXiv:1706.02262, 2017.
27. [Zietlow et al., 2021] Dominik Zietlow, Michal Rolinek, and Georg Martius. Demystifying inductive biases for β-VAE based architectures. arXiv preprint arXiv:2102.06822, 2021.
