Domain-Adaptive Variational Autoencoder

Machine Learning
Introduced by
Ilse, M.; Tomczak, J. M.; Louizos, C.; Welling, M.
Year
2020
Type
Generative model with domain adaptation
Family
Deep learning / NLP / CV

What does it do?

A Domain-Adaptive Variational Autoencoder (DA-VAE) is used here as a general name for variational autoencoders (VAEs) whose latent representation is split into parts for domain identity, class-relevant content and residual variation.

The aim is to let a model trained on labelled source-domain data be applied to a related domain. The reference instance on this page is DIVA (Ilse, Tomczak, Louizos and Welling, MIDL 2020). The experiments in that paper concern image data; use with text or sensor data is an extension that must be validated on your own data.

The intuition behind the method

Consider a classifier trained on images from one hospital and applied to images from another, where scanners and acquisition settings differ. A DA-VAE tries to keep the information that determines the label in one part of the latent code and the information that identifies the domain in another. If the class-relevant part is kept free of domain information, a downstream classifier built on it should be less sensitive to the shift. The decoder reconstructs the input from all parts together, which keeps the latent code tied to the data. Whether this separation succeeds in practice depends on how well the domain and class factors can be kept apart.

History

DA-VAE is used on this page as a general name for the approach, and DIVA (Ilse, Tomczak, Louizos and Welling, MIDL 2020, PMLR 121) is the reference instance. DIVA decomposes the latent space into domain, class and residual factors with auxiliary supervision, and its reported experiments are on image data. The variational autoencoder framework on which it rests is due to Kingma and Welling (2014).

When to use it

Choose DA-VAE when a large labelled dataset exists for a source domain, labels are scarce or absent in a related domain, and the shift is plausibly due to factors that do not determine the label, such as scanner type, staining protocol or writing style. The cited DIVA experiments concern images; use with text or sensor signals should be validated on your own data. Avoid it when the domains share little structure, since no shared latent content can then transfer. It is also a poor fit when the labelled dataset is very small, because the several loss terms need enough data to be fitted reliably, and when decision logic must be auditable, since the decomposed latent space adds structure that is hard to inspect.

Limitations and considerations

  • Several weights must be set (beta, the auxiliary classifier weights and any disentanglement or alignment penalty), and tuning is a substantial part of the work. Take starting values from the DIVA paper and confirm them by validation.
  • Training can become unstable when the reconstruction term pushes information into the domain or class codes that the disentanglement terms are trying to separate.
  • Disentanglement assumes that domain and class factors are statistically separable; when they are strongly correlated in the training data, the separation is less reliable.
  • The ELBO yields approximate posteriors, so the uncertainty they express depends on the variational family and is not guaranteed to be calibrated.
  • Heavier than fine-tuning a pretrained network, because it trains an encoder, a decoder and auxiliary heads jointly.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Combines representation learning, domain adaptation and, optionally, generation of samples under a different domain code within one probabilistic model.
  • Separate domain and class codes can be examined individually, whereas a single domain-invariant feature vector from adversarial training does not expose the domain factor. Whether this gives better transfer than adversarial methods depends on the dataset and must be tested empirically.
  • Unlabelled examples can contribute through the reconstruction term, which does not require labels; labelled data from additional domains can be added when available.
  • The decoder conditioned on the domain code supports reconstruction and cross-domain generation, which can be used to inspect what the domain factor changes.
  • Built on the standard VAE objective, so the reconstruction and KL terms can be examined with familiar diagnostics.

Applications

  • Medical image analysis across hospitals or scanner types (e.g. MRI from different manufacturers).
  • Cross-lingual text classification where a model trained on one language must transfer to another.
  • Cross-subject activity recognition from wearable sensors where inter-person variability acts as a domain shift.
  • Histopathology slide analysis across staining protocols or tissue preparation laboratories.
  • Remote-sensing image classification across different satellite sensors or acquisition conditions.
  • Sentiment analysis transfer across product categories or review platforms with different writing styles.

How it works

How it works

1

The encoder maps each input x to the parameters of a Gaussian approximate posterior, a mean and a variance, as in the formula for this step. In a DA-VAE the latent variable is partitioned into a domain code z_d, a class code z_y and a residual code z_x, and the posterior is factorised over these parts, each a Gaussian with its own mean and variance. The formula shown is written for a generic latent z and applies to each part in turn. The exact factorisation should be checked against the DIVA paper before implementation. Sampling uses the reparameterisation trick, which keeps training differentiable.

Formula
q_{\phi}(z_d, z_y, z_x|x) = q_{\phi_d}(z_d|x)\, q_{\phi_y}(z_y|x)\, q_{\phi_x}(z_x|x), \quad q_{\phi_k}(z_k|x) = \mathcal{N}(\mu_{k}(x), \sigma^{2}_{k}(x))
2

Auxiliary classifiers are attached to the domain and class subspaces, so that the domain code is trained to predict the domain label and the class code to predict the class label. The intended effect is that the domain code carries little class information and the class code carries little domain information. No formula is given on this page for this step, and the specific form of the penalty or auxiliary loss should be taken from the DIVA paper.

3

The aim of this step is to make encodings from different domains comparable in the class and residual subspaces, for example by tying the latent distributions to a common prior. No formula is given on this page, and the exact alignment term should be taken from the original paper before implementation. Alignment is intended to make a classifier trained on source encodings usable on target encodings, but this transfer must be validated on held-out target data.

4

The decoder p(x|z_d, z_y, z_x) conditions on the domain, class and residual codes to reconstruct the input. Because the domain code is an explicit input, the decoder can in principle be given a different domain code to generate a translated sample. The formula shown does not include a separate translation objective.

Formula
p_{\theta}(x|z_{d}, z_{y}, z_{x})
5

The displayed formula is only the VAE part of the objective: an expected reconstruction term minus beta times the KL divergence between the approximate posterior and the prior. The beta coefficient sets the balance between reconstruction fidelity and closeness of the latent distribution to the prior. The full DA-VAE objective also contains supervised terms for the domain and class labels computed from their respective codes, each with its own weight. These terms are not shown in the formula, and their exact form and weights should be taken from the DIVA paper.

Formula
\mathcal{L} = \mathbb{E}[\log p_{\theta}(x|z)] - \beta \, D_{KL}(q_{\phi}(z|x) \| p(z))

Common pitfalls

  • Keeping a single latent code and calling the model domain-adaptive. The method relies on separating domain, class and residual parts; without that split the model is a plain VAE.
  • Validating only on the source domain. Source accuracy does not show how the model behaves under the shift, so held-out target-domain evaluation is needed.
  • Ignoring correlation between domain and class labels. When they co-vary, class information can leak into the domain code or the reverse; check this before training and interpret results cautiously.
  • Choosing beta too large, which weakens reconstruction, or too small, which leaves the latent space irregular and less transferable.
  • Tracking only reconstruction loss during development. Check that the domain code predicts the domain label while the class code does not, and measure downstream accuracy on target-domain labels.

Frequently asked questions

How is DA-VAE different from a standard domain-adversarial neural network (DANN)?

DANN uses a gradient-reversal layer to confuse a domain classifier, producing a single domain-invariant representation. DA-VAE instead decomposes the latent space into domain, class and residual subspaces within a generative framework, which allows generation under a different domain code and gives an approximate posterior over the latent factors. The cost is a more complex training objective. Which approach transfers better depends on the dataset.

Do I need labelled target-domain data?

Not necessarily in principle, since the reconstruction term does not require labels, but the extent to which unlabelled or sparsely labelled target data helps should be checked against the DIVA paper and validated on your own held-out data. Semi-supervised use beyond what that paper reports should be treated as an extension that has not been validated.

How do I choose the size of each latent subspace?

No universal rule is given. Choose sizes by validation on held-out data from the domains of interest, and check that the domain code predicts the domain label while the class code does not, and that the class code predicts the class label.

What happens if domain and class labels are correlated in my dataset?

Correlation between domain and class violates the independence assumption that disentanglement relies on. The model may encode class-relevant information in the domain subspace and vice versa. Check this correlation before training and interpret the results cautiously if it is strong.

Is there a standard implementation?

No canonical library is identified here. The model can be built from standard VAE components in common deep-learning frameworks, adding the auxiliary heads and penalties. Architectural details should be taken from the DIVA paper (Ilse et al., 2020) rather than assumed.

Related methods

Sources

  1. Ilse, M., Tomczak, J. M., Louizos, C., & Welling, M. (2020). DIVA: Domain Invariant Variational Autoencoders. Proceedings of the Third Conference on Medical Imaging with Deep Learning (MIDL 2020), PMLR 121, 322–348.

    Open publication reference
  2. Kingma, D. P., & Welling, M. (2014). Auto-Encoding Variational Bayes. Proceedings of the 2nd International Conference on Learning Representations (ICLR 2014).

    Open publication reference