Learning Causal Semantic Representation for Out-of-Distribution Prediction

Abstract:
Conventional supervised learning methods, especially deep ones, are found to be sensitive to out-of-distribution (OOD) examples, largely because the learned representation mixes the semantic factor with the variation factor due to their domain-specific correlation, while only the semantic factor causes the output. To address the problem, we propose a Causal Semantic Generative model (CSG) based on a causal reasoning so that the two factors are modeled separately, and develop methods for OOD prediction from a single training domain, which is common and challenging. The methods are based on the causal invariance principle, with a novel design in variational Bayes for both efficient learning and easy prediction. Theoretically, we prove that under certain conditions, CSG can identify the semantic factor by fitting training data, and this semantic-identification guarantees the boundedness of OOD generalization error and the success of adaptation. Empirical study shows improved OOD performance over prevailing baselines.

heading: 1 Introduction
text: Deep learning has initiated a new era of artificial intelligence where the potential of machine learning models is greatly unleashed. Despite the great success, these methods heavily rely on the assumption that data from training and test domains follow the same distribution (i.e., the IID assumption), while in practice the test domain is often out-of-distribution (OOD), meaning that the test data distribute differently from the training data. Popular models for predicting the output (or label, response, outcome) y from the input (or covariate) x have been found erroneous when confronted with a distribution change, even from an essentially irrelevant perturbation like a position shift or background change for images [91, 6, 102, 41, 2, 27]. These phenomena pose serious concerns on the robustness and trustworthiness of machine learning methods and severely impede them from risk-sensitive scenarios.
Looking into the problem, although deep learning models allow extracting abstract representation for prediction with their powerful approximation capacity, the representation may unconsciously mix up semantic factors s (e.g., shape of an object) and variation factors v (e.g., background, object position) due to a correlation between them (e.g., desks often appear in a workspace background and beds in bedrooms), so the model also relies on the variation factors v for prediction via this correlation. However, this correlation tends to be superficial and spurious (e.g., a desk can also appear in a bedroom, but this does not make it a bed), and may change drastically in a new domain, making the effect from v misleading. So it is desired to learn a representation that identifies s against v.
Formally, the essence of this goal is to leverage causal relations for prediction, since the fundamental distinction between s and v is that only s is the cause of y. Causal relations better reflect basic ∗Correspondence to: Chang Liu <changliu@microsoft.com>. †Work done during an internship at Microsoft Research Asia.
35th Conference on Neural Information Processing Systems (NeurIPS 2021).
mechanisms of nature. They bring the merit to machine learning that they tend to be universal and invariant across domains [97, 87, 93, 77, 16, 96, 98], thus provide the most transferable and reliable information to unseen domains. This causal invariance has been shown to lead to proper domain adaptation [97, 123], lower adaptation cost and lighter catastrophic forgetting [87, 9, 56].
In this work, we propose a Causal Semantic Generative model (CSG) following a causal consideration to separately model the semantic (cause of prediction) and variation latent factors, and develop OOD prediction methods with theoretical guarantees on identifiability and the boundedness of OOD prediction error. Addressing the complaint that OOD prediction and causality methods often require multi-domain or intervention data, we focus on the most common and also challenging tasks where only one single training domain is available, including OOD generalization and domain adaptation, where in the latter, unsupervised test-domain data are additionally available for training. The methods and theory are based on the causal invariance principle, which suggests to share generative mechanisms across domains, while the latent factor distribution (i.e., the prior p(s, v)) changes. We argue that this causal invariance is more reliable than inference invariance in the other direction adopted by many existing methods [33, 101, 2, 66, 79]. For our method, we design novel and delicate reformulations of the ELBO objective so that we avoid the cost to build and learn two inference models. Theoretically, we prove that under certain conditions, CSG can identify the semantic factor on the single training domain, even in presence of an s-v correlation. We further prove the merits from this identification: prediction error is bounded for OOD generalization, and for domain adaptation, the test-domain prior is identifiable which leads to an accurate prediction. To sum up our contributions, • Up to our knowledge, we are the first to show a theoretical guarantee (under appropriate
conditions) to identify the latent cause of prediction (i.e., the semantic factor) on a single training domain, and also the first to show the theoretical benefits of this identification for OOD prediction. The results also contribute to generative representation learning for revealing what is learned. • We develop effective methods for OOD generalization and domain adaptation, and achieve
mostly better performance than prevailing methods on real-world image classification tasks.

heading: 2 Related Work
text: OOD generalization with causality. There are trials that ameliorate discriminative models towards a causal behavior. Bahadori et al. [4] introduce a regularizer that reweights input dimensions based on their approximated causal effects to the output, and Shen et al. [102] reweight training samples by amortizing causal effects among input samples. Their linear input-output assumption is then extended [4, 41] by learning a representation. Some recent works require identity data (finer than label) and enforce inference invariance via variance minimization [42], or leverage a strong domain knowledge to augment images as an independent intervention on variation factors [79]. These methods introduce no additional generative modeling efforts, at the cost of limited capacity for invariant causal mechanisms.
Domain adaptation/generalization with causality. There are methods developed under various causal assumptions [97, 123] or using learned causal relations [93, 77]. Zhang et al. [123], Gong et al. [35, 36] also consider certain ways of mechanism change. The considered causality is among directly observed variables, which may not well suit general data like image pixels where causality rather lies in the conceptual latent level [75, 10, 59].
To consider latent factors, there are domain adaptation [83, 5, 33, 73, 74] and generalization methods [80, 101, 113] that learn a representation with a domain-invariant marginal distribution. Remarkable results have been achieved. Nevertheless, it is found that this invariance is neither sufficient nor necessary to identify the true semantics or lower the adaptation error ([54, 125]; see also Appx. E). Moreover, these methods are based on inference invariance, which may not be as reliable as causal invariance (see Sec. 3.2).
There are also generative methods for domain adaptation/generalization that model latent factors. Cai et al. [18] and Ilse et al. [49] introduce a semantic factor and a domain-feature factor. They assume the two latent factors are independent in both generative and inference models, which is unrealistic. Correlated factors are then considered [3]. But all these works do not adapt the prior for domain change thus resort to inference invariance. Zhang et al. [121] consider a partially observed manipulation variable, while still assuming its independence from the output in both the joint and posterior, and the adaptation is inconsistent with causal invariance. The above methods also do not show guarantees to identify their latent factors. Teshima et al. [108] leverage causal invariance and
adapt the prior, yet also assume latent independence and do not separate the semantic factor. They require some supervised test-domain data, and their deterministic and invertible mechanism also indicates inference invariance. In addition, most domain generalization methods require multiple training domains, with exceptions [89] that still seek to augment domains. In contrast, CSG leverages causal invariance, and has guarantee to identify the semantic factor from a single training domain, even with a correlation to the variation factor.
Disentangled latent representations is also of interest in unsupervised learning. Despite empirical success [22, 43, 21], Locatello et al. [70] conclude that it is impossible to guarantee the disentanglement in unsupervised settings. Subsequent works then introduce ways of supervision like a few latent variable observations [71] or sample similarity [20, 72, 104]. Identifiable VAE [57] and extensions [58, 117] leverage the data of a cause variable of the latent variables and have established theoretical guarantees under a diversity condition. But the works do not depict domain change thus not suitable for OOD prediction. Instead of disentangling latent factors, we focus on identifying the semantic factor s (Sec. 5.1) and its benefit for OOD prediction. Appx. D shows more related work.

heading: 3 The Causal Semantic Generative Model
text: To develop the model soberly based on causality, we require its formal definition: two variables have a causal relation, denoted as “cause→ effect”, if intervening the cause (by changing external variables out of the considered system) may change the effect, but not vice versa [85, 88]. We follow this definition to build our model (Fig. 1a) by analyzing the example that an photographer takes a photo in a scene as x and labels it as y. Appx. C provides more explanations under other perspectives.
(1) It is likely that neither y → x (e.g., intervening the label with noise by distracting the photographer does not change the image) nor x→ y holds (e.g., intervening an image by breaking a camera sensor unit does not change how the photographer labels it), as also argued in [88, Sec. 1.4; 59]. So we introduce a latent variable z to capture factors with causal relations. Also for this reason, we need a generative model (vs. discriminative model that only learns x→ y). (2) The latent variable z as underlying generating factors (e.g., object shape and texture, background and illumination during imaging) is plausible to cause both x (e.g., changing object shape or background makes a different image, but breaking the camera does not change the shape or background) and y (e.g., the photographer would give a different label if the object shape had been different, but noise-corrupting the label does not change the shape). So we orient the edges in the generative direction z → (x, y), as also adopted in [78, 88, 108]. This is in contrast to prior works [18, 49, 48, 19] that treat y as the cause of a semantic factor, which, when y is also a noisy observation, makes unreasonable implications (e.g., adding noise to the labels in a dataset automatically changes object features and consequently the images, and changing the object features does not change the label). This difference is also discussed in [88, Sec. 1.4; 59].
(3) We attribute all x-y relation to the existence of some latent factor [68, “purely common cause”; 51] and exclude x-y edges. This can be achieved as long as z holds sufficient information of data (e.g., with shape, background etc. fixed, breaking the camera does not change the label, and noisecorrupting the label does not change the image). Promoting this structure reduces arbitrariness in explaining x-y relation thus helps identify (part of) z. This is in contrast to prior works [63, 121, 19] that treat y as a cause of x as no latent variable is introduced between.
(4) Not all latent factors are the causes of y (e.g., changing the shape may alter the label, while changing the background does not). We thus split the latent variable as z = (s, v) and remove the v → y edge, where s represents the semantic factor that causes y, and v describes the variation or diversity in generating x. This formalizes the intuition on the concepts in Introduction (Sec. 1).
(5) The two factors s and v often have a relation (e.g., a desk/bed shape tends to appear with a workspace/bedroom background), but it is usually a spurious correlation (e.g., putting a desk in a bedroom does not automatically change the room as a workspace, nor does it turn the desk into a bed). So we keep the undirected s-v edge. This is in contrast to prior works [18, 49, 121, 108, 79] which assume independent latent variables. Although v is not a cause of y, modeling it explicitly is worth the effort since otherwise it would still be implicitly mixed into s anyway through the s-v correlation. We summarize these conclusions in the following definition. Definition 1 (CSG). A Causal Semantic Generative Model (CSG), p := 〈p(s, v), p(x|s, v), p(y|s)〉, is a generative model on data variables x ∈ X ⊆ RdX and y ∈ Y with semantic s ∈ S ⊆ RdS and variation v ∈ V ⊆ RdV latent variables, following the graphical structure shown in Fig. 1a.

heading: 3.1 The Causal Invariance Principle
text: Through the above process, we see that the s-v correlation embodied in the prior p(s, v) tends to change across domains. Under a causal view, this means that the domain change comes from a (soft) intervention on s or v or both, leading to a different prior. On the other hand, the generative processes are likely causal mechanisms, so they enjoy the celebrated Independent Causal Mechanisms principle [88, 98] indicating that they are unaffected under the intervention on prior. This leads to the following causal invariance principle for CSG. Principle 2 (causal invariance). The causal generative mechanisms p(x|s, v) and p(y|s) in CSG are invariant across domains, and the change of prior p(s, v) is the only source of domain change.
This invariance reflects the universality of basic laws of nature and is considered in some prior works [97, 88, 10, 16]. Other works instead introduce domain index [18, 49, 48, 19] or manipulation variables [121, 57, 58] to model distribution change explicitly. They then require multiple training domains or additional observations, while such changes can also be explained under causal invariance as long as the latent variables include all changing factors.
3.2 Comparison with Inference Invariance
Most domain adaptation and generalization methods (incl. domain-invariant-representation based [33, 101], invariantlatent-predictor based [2, 66, 79]) use a shared representation extractor across domains. This effectively assumes the invariance in the other direction, i.e. inferring latent factors z from observed data x. We note in its supportive examples (e.g., inferring object position from image, extracting the fundamental frequency from audio), the causal mechanism p(x|z) is nearly deterministic and invertible such that it preserves the information of z. Formally, for a given x, only one single z value achieves a positive p(x|z) while all other values lead to zero. The inferred representation given by the posterior via the Bayes rule p(z|x) ∝ p(z)p(x|z) then
concentrates on this z value, which is determined by the causal mechanism p(x|z) alone, regardless of the domain-specific prior p(z). Causal invariance then implies inference invariance.
In more general cases, the causal mechanism may be noisy or degenerate (Fig. 2), such that there are multiple z values that give a positive p(x|z), i.e. they all could generate the same x. Inference is then ambiguous, and the posterior relies on the prior to choose from these z values. Since the prior changes across domains (e.g., different labelers have different mindset), the inference rule then changes by nature and is not invariant,3 while the causal invariance is rather more fundamental and reliable. To leverage causal invariance, we use a different prior for the test domain (CSG-ind and CSG-DA), which gives a different and more reliable prediction than following inference invariance.
3Particularly, although Mitrovic et al. [79] consider a similar causal structure and promote the invariance of p(y|s), s actually depends on v for a given x, even when they are independent in the prior. So p(s|x) must depend on the domain-specific p(v), and a domain-invariant representation extractor does not exist.

heading: 4 Method
text: We now develop methods based on variational Bayes [55, 62] for OOD generalization and domain adaptation using CSG. Appx. F.1 shows all details.

heading: 4.1 Method for OOD Generalization
text: For OOD generalization, one only has supervised data from the underlying data distribution p∗(x, y) on the training domain. Fitting a CSG p := 〈p(s, v), p(x|s, v), p(y|s)〉 to data by maximizing likelihood Ep∗(x,y)[log p(x, y)] is intractable, since p(x, y) := ∫ p(s, v, x, y) dsdv where p(s, v, x, y) := p(s, v)p(x|s, v)p(y|s), is hard to estimate. The Evidence Lower BOund (ELBO) Lp, qs,v|x,y (x, y) := Eq(s,v|x,y)[log p(s,v,x,y) q(s,v|x,y) ] [55, 112] is a tractable surrogate with the help of an inference model q(s, v|x, y) that enjoys easy sampling and density evaluation. It is known that maxqs,v|x,y Lp, qs,v|x,y (x, y) drives q(s, v|x, y) towards the posterior p(s, v|x, y) := p(s,v,x,y) p(x,y) , meanwhile makes Lp, qs,v|x,y (x, y) a tighter lower bound of log p(x, y) for optimizing CSG p. However, the subtlety with supervised learning is that prediction is still hard, as the introduced model q(s, v|x, y) does not help estimate p(y|x). To address this, we propose to employ an auxiliary model q(s, v, y|x) targeting p(s, v, y|x). It allows easy sampling of y given x for prediction, and can also serve as the required inference model: q(s, v|x, y) = q(s,v,y|x)q(y|x) , where q(y|x) := ∫ q(s, v, y|x) dsdv is also determined by q(s, v, y|x). The ELBO objective Ep∗(x,y)[Lp, qs,v|x,y (x, y)] then becomes:
Ep∗(x)Ep∗(y|x)[log q(y|x)] + Ep∗(x)Eq(s,v,y|x) [p∗(y|x) q(y|x) log p(s, v, x, y) q(s, v, y|x) ] . (1)
As a functional of q(s, v, y|x) (instead of q(s, v|x, y)) and the CSG p, this objective also drives them towards their targets: the first term is the negative of the standard cross entropy (CE) loss which drives q(y|x) towards p∗(y|x), and once this is achieved, the second term becomes the expected ELBO Ep∗(x)[Lp, qs,v,y|x(x)] that drives q(s, v, y|x) towards p(s, v, y|x) and p(x) towards p∗(x). Furthermore, as the target of q(s, v, y|x) factorizes as p(s, v, y|x) = p(s, v|x)p(y|s) (due to Fig. 1a) where p(y|s) is already known (part of the CSG), we can instead employ a lighter inference model q(s, v|x) for the minimally intractable component p(s, v|x) therein, and use q(s, v|x)p(y|s) as q(s, v, y|x). This turns the objective Eq. (1) to:
max p, qs,v|x
Ep∗(x,y) [
log q(y|x) + 1 q(y|x)
Eq(s,v|x) [ p(y|s) log p(s, v)p(x|s, v)
q(s, v|x)
]] , (2)
where q(y|x) := Eq(s,v|x)[p(y|s)]. The expectations can be estimated by Monte Carlo after applying the reparameterization trick [62]. This is the basic CSG method.
CSG-ind To actively improve OOD generalization performance, we consider using an independent prior p⊥(s, v) := p(s)p(v) for prediction in the test domain (Fig. 1b), where p(s) and p(v) are the marginals of the training-domain prior p(s, v). Intuitively, p⊥(s, v) discards the spurious correlation between s and v on the training domain (e.g., the “desk-workspace”, “bed-bedroom” association), and promotes a cautious neutral belief on the unknown test-domain correlation in defence against all possibilities (e.g., a “desk-bedroom”, “bed-workspace” association). Formally, p⊥(s, v) has a larger entropy than p(s, v) [24, Thm. 2.6.6], so it reduces training-domain-specific information and encourages reliance on the causal mechanisms for better generalization. It also amounts to applying the do-operator [85] to Fig. 1a, representing a randomized experiment by independently soft-intervening s or v. In this way, causal invariance is properly leveraged, making a different and more reliable prediction than following inference invariance. Our theory below also shows that p⊥(s, v) leads to a smaller generalization error bound (Thm. 6 Remark).
Methodologically, we need the test-domain inference model q⊥(s, v|x) for prediction p⊥(y|x) ≈ Eq⊥(s,v|x)[p(y|s)], but also need q(s, v|x) for learning on the training domain. To save the cost of building and learning two inference models, we propose to use q⊥(s, v|x) to represent q(s, v|x). Noting that their targets are related by p(s, v|x) = p(s,v)
p⊥(s,v) p⊥(x) p(x) p ⊥(s, v|x), we formulate q(s, v|x) = p(s,v) p⊥(s,v) p⊥(x) p(x) q ⊥(s, v|x) accordingly, so that this q(s, v|x) achieves its target if and only if q⊥(s, v|x)
does. The objective Eq. (1) then becomes:
max p, q⊥
s,v|x
Ep∗(x,y) [
log π(y|x) + 1 π(y|x) Eq⊥(s,v|x) [ p(s, v) p⊥(s, v) p(y|s) log p ⊥(s, v)p(x|s, v) q⊥(s, v|x) ]] , (3)
where π(y|x) := Eq⊥(s,v|x) [ p(s,v) p⊥(s,v) p(y|s) ] . (Note p⊥(s, v) is determined by p(s, v) in the CSG p.)

heading: 4.2 Method for Domain Adaptation
text: In domain adaptation, one also has unsupervised data from the underlying data distribution p̃∗(x) on the test domain. We can leverage them for better prediction. According to the causal invariance principle (2), we only need a new prior p̃(s, v) for the test-domain CSG p̃ := 〈p̃(s, v), p(x|s, v), p(y|s)〉 (Fig. 1c). Fitting test-domain data can be done through the standard ELBO objective with the test-domain inference model q̃(s, v|x):
max p̃, q̃s,v|x
Ep̃∗(x)[Lp̃, q̃s,v|x(x)],where Lp̃, q̃s,v|x(x) = Eq̃(s,v|x) [ log p̃(s, v)p(x|s, v) q̃(s, v|x) ] . (4)
Prediction is given by p̃(y|x) ≈ Eq̃(s,v|x)[p(y|s)]. Similar to the CSG-ind case, we still need q(s, v|x) for fitting training-domain data, and we can also avoid a separate q(s, v|x) model by representing it using q̃(s, v|x). Following the same relation between their targets, we let q(s, v|x) = p̃(x) p(x) p(s,v) p̃(s,v) q̃(s, v|x), which reformulates the same training-domain objective Eq. (1) as:
max p, q̃s,v|x
Ep∗(x,y) [
log π(y|x) + 1 π(y|x) Eq̃(s,v|x) [p(s, v) p̃(s, v) p(y|s) log p̃(s, v)p(x|s, v) q̃(s, v|x) ]] , (5)
where π(y|x) := Eq̃(s,v|x) [p(s,v) p̃(s,v)p(y|s) ] . The resulting method, termed CSG-DA, solves both optimization problems Eqs. (4, 5) simultaneously.

heading: 4.3 Implementation and Model Selection
text: To implement the three CSG methods, we only need one inference model in each. Appx. F.2 shows its construction from a general discriminative model (e.g., how to select its hidden nodes as s and v). In practice x often has a much larger dimension than y, making the first supervision term overwhelmed by the second unsupervised term in Eqs. (2,3,5). So we downscale the second term.
As recently emphasized [39], an OOD method should include a model selection method, since it is nontrivial and significantly affects performance [95, 120]. For our methods, we use a validation set from the training domain for model selection. This complies with the OOD setup, and is also suggested by our theory below which gives guarantees based on a good fit to the training-domain data distribution. For CSG-ind/DA, the learned predictor targets the test domain, so we do not use it directly for evaluating validation accuracy, but by normalizing π(y|x). Appx. F.3 shows details.

heading: 5 Theory
text: We now establish theory for the identification of the semantic factor (cause of prediction) and subsequent merits for OOD generalization and domain adaptation. We focus on the distribution-level generalization instead of from finite samples to unseen samples under the same distribution, so we only consider the infinite-data regime. Appx. A shows all the proofs and auxiliary theory.
Latent variable identification is hard [65, 81, 116, 70] as it is beyond observational relations [51, 88]. Assumptions are thus required to draw definite conclusions.
Assumption 3. (Additive noise) There exist nonlinear functions f and g with bounded derivatives up to the third-order, and independent random variables µ and ν, such that p(x|s, v) = pµ(x− f(s, v)), and p(y|s) = pν(y − g(s)) for continuous y or p(y|s) = Cat(y|g(s)) for categorical y. (Bijectivity) Assume f is bijective and g is injective.
The additive noise assumption is widely adopted in causal discovery [51, 17]. It disables expressing the same joint in the other direction [122, Thm. 8; 86, Prop. 23] so that CSG unnecessarily indicates inference invariance. For this reason, we exclude GAN [37] and flow-based [61] implementations. Bijectivity is a common assumption for identifiability [51, 100, 57, 68]. It is sufficient [86, Prop. 17; 88, Prop. 7.4] for the more fundamental [86, Prop. 7; 88, p.109] requirement of causal minimality [86, p.2012; 88, Def. 6.33]. Particularly, s and v may otherwise have dummy dimensions that f and g simply ignore, raising another ambiguity against identifiability. On the other hand, according to the
commonly acknowledged manifold hypothesis [115, 31], we can take X as the lower-dimensional data manifold and such a bijection exists as a coordinate map, which is an injection to the original data space and also allows dS + dV < dX .

heading: 5.1 Identifiability Theory
text: We first formalize the goal of identifying the semantic factor.
Definition 4 (semantic-identification). We say a learned CSG p is semantic-identified, if there exists a homeomorphism4 Φ on S ×V , such that (i) its output dimensions in S is constant of v: ΦS(s, v) = ΦS(s, v′),∀v, v′ ∈ V (hence denote ΦS(s, v) as ΦS(s)), and (ii) it is a reparameterization of the ground-truth CSG p∗: Φ#[p∗s,v] = ps,v , p ∗(x|s, v) = p(x|Φ(s, v)) and p∗(y|s) = p(y|ΦS(s)).
Here, Φ#[p∗s,v] denotes the pushed-forward distribution 5 of p∗s,v by Φ, i.e. the distribution of Φ(s, v) when (s, v) ∼ p∗s,v. As the ground-truth CSG could at most provide its information via the data distribution p∗(x, y), a well-learned CSG that achieves p(x, y) = p∗(x, y) still has the degree of freedom in parameterizing (s, v). This is described by this reparameterization Φ (Appx. Lemma 9). At the heart of the definition, the v-constancy of ΦS implies that Φ is semantic-preserving: the learned model does not mix the ground-truth v into its s, so that the learned s holds equivalent information to the ground-truth s. The definition can thus be seen as the semantic equivalence (Appx. Def. 10, Prop. 14) to the ground-truth CSG p∗.
For related concepts, this identification cannot be characterized by the statistical independence between s and v (vs. [18, 49, 121]), which is not sufficient [70] nor necessary (due to the existence of spurious correlation). It is also weaker than disentanglement [44, 11], which additionally requires the learned v to be constant of the ground-truth s. The following theorem shows that semanticidentification can be achieved on a single domain under certain conditions.
Theorem 5 (semantic-identifiability). With Assumption 3, a CSG p is semantic-identified, if it is well-learned such that p(x, y) = p∗(x, y), under the conditions that log p(s, v) and log p∗(s, v) are bounded up to the second-order, and that6 (i) 1/σ2µ → ∞ where σ2µ := E[µ>µ], or (ii) pµ (e.g., a Gaussian) has an a.e. non-zero characteristic function.
Remarks. (1) (Condition and Intuition) Compared with the multi-domain case [87, 93, 2], identifiability on a single training domain comes at a cost and requires certain conditions. One may imagine that in some extreme cases e.g., all desks appear in workspace and all beds in bedrooms, it is impossible to distinguish whether y labels the object or the background (unlearnable OOD problem [119]). The theorem finds an appropriate condition that excludes such cases: when log p∗(s, v) is bounded, deterministic s-v relations are not allowed as they concentrate p∗(s, v) on a lower-dimensional subspace in S × V thus make it unbounded. It also leads to the intuition of identifiability: a bounded log p∗(s, v) indicates a stochastic s-v relation, so mixing the ground-truth v into the learned smakes the inference of smore noisy due to the intrinsic diversity/uncertainty of this v. As prediction is made via the inferred s, this worsens prediction accuracy thus violates the “well-learned” requirement. Compared with discriminative models, CSG makes more faithful inference, and its causal structure leads to a proper description of domain change.
(2) In condition (i), 1/σ2µ measures the intensity of the causal mechanism p(x|s, v). When it is large, the “strong” p(x|s, v) helps disambiguating values of (s, v) in generating a given x. The formal version in Appx. Thm. 5’ shows a quantitative reference for large enough intensity, and Appx. B gives a non-asymptotic extension showing how the intensity trades-off the tolerance of equalities in Def. 4. Condition (ii) goes beyond inference invariance. It roughly implies that different (s, v) values a.s. produce different p(x|s, v), so their roles in generating x become clear which helps identification. (3) The theorem does not contradict the impossibility result by Locatello et al. [70], which considers disentangling each latent dimension with an unconstrained (s, v)→ (x, y), while we only identify s as a whole, with the v → y edge removed which breaks the s-v symmetry.
4A transformation is a homeomorphism if it is a continuous bijection with continuous inverse. 5The definition of Φ#[p∗s,v] requires Φ to be measurable. This is satisfied by the continuity of Φ as a homeomorphism (as long as the Borel σ-field is considered) [13, Thm. 13.2]. 6To be precise, the conclusions are that the equalities in Def. 4 hold asymptotically in the limit 1/σ2µ →∞ for condition (i), and hold a.e. for condition (ii).

heading: 5.2 OOD Generalization Theory
text: Now we show the benefit of semantic-identification for OOD generalization that the prediction error is bounded. Note the optimal predictor Ẽ ∗ [y|x] 7 on the test domain is defined by the corresponding ground-truth CSG p̃∗, which differs from p∗ only in the test-domain prior p̃∗(s, v) (Principle 2). Theorem 6 (OOD generalization error). 8 With Assumption 3, for a semantic-identified CSG p on the training domain with semantic-preserving reparameterization Φ, we have up to O(σ4µ),
Ep̃∗(x)‖E[y|x]− Ẽ ∗ [y|x]‖22 6 σ4µB′4f−1B ′2 g Ep̃s,v ∥∥∇ log(p̃s,v/ps,v)∥∥22, (6) where B′f−1 and B ′ g bound the 2-norms
9 of the Jacobians of f−1 and g, respectively, and p̃s,v := Φ#[p̃ ∗ s,v] is the test-domain prior under the parameterization of the CSG p.
In the bound, the term Ep̃s,v ∥∥∇ log(p̃s,v/ps,v)∥∥22 is the Fisher divergence measuring the difference between the two priors. As the prior change is the only source of domain change, this term also measures the “OODness” in terms of the effect on prediction. The bound also shows that when the causal mechanism p(x|s, v) is strong (small σµ), it dominates prediction over the prior change, as the generalization error becomes small. Compared with other methods, using a CSG enforces causal invariance, so the boundedness of OOD generalization error becomes more plausible in practice.
Remark. The bound also shows the advantage of CSG-ind (Sec. 4.1). The Fisher divergence is revealed [28] to have a similar behavior as the forward KL divergence ps,v 7→ KL(p̃s,v‖ps,v) that it is very sensitive to the insufficient coverage of ps,v on the support of p̃s,v [46, 109], since log(p̃s,v/ps,v) is infinitely large on the uncovered region. As the independent prior p⊥s,v has a larger support than ps,v, it is less likely to miss the support of p̃s,v, so it induces a generally smaller Fisher divergence. CSG-ind thus generally has a smaller OOD generalization error bound than CSG.

heading: 5.3 Domain Adaptation Theory
text: CSG-DA (Sec. 4.2) learns a new prior p̃s,v by fitting unsupervised test-domain data, with causal mechanisms shared. If the mechanisms are semantic-identified, the ground-truth test-domain prior p̃∗s,v can also be identified under the learned parameterization, and prediction is made precise. Theorem 7 (domain adaptation error). With conditions of Thm. 5, for a semantic-identified CSG p on the training domain with semantic-preserving reparameterization Φ, if its new prior p̃s,v is welllearned such that p̃(x) = p̃∗(x), then p̃s,v = Φ#[p̃ ∗ s,v], and Ẽ[y|x] = Ẽ ∗ [y|x] for any x ∈ supp(p̃∗x).
Different from existing domain adaptation bounds (Appx. E), Theorems 6,7 allow different inference models in the two domains, thus go beyond inference invariance.

heading: 6 Experiments
text: For OOD generalization baselines, there is not much choice beyond the standard CE loss optimization, as domain adaptation methods require test-domain data and most domain generalization methods degenerate to CE with one training domain. The exception within our scope is a causal discriminative method CNBB [41]. For domain adaptation, we consider well-acknowledged methods DANN [33], DAN [73], CDAN [74] and recent compelling methods MDD [124] and BNM [25] (shown in Appx. Tables 2,3). Appx. G shows more details, results, and discussions. 10
Shifted-MNIST. We first consider an OOD prediction task on MNIST to classify digits “0”s and “1”s. To make a spurious correlation, in the training data, we horizontally shift each “0” at random by δ0 ∼ N (−5, 12) pixels, while each “1” by δ1 ∼ N (5, 12) pixels. We consider two test domains with different digit-position distributions: each digit is not moved δ0 = δ1 = 0 in the first, and is shifted at random by δ0, δ1 ∼ N (0, 22) pixels in the second. We implement all methods using a multilayer perceptron which is not naturally shift invariant. We use a larger architecture for non-generative methods to compensate the additional generative component of generative methods.
The performance is shown in Table 1(top 2 rows). For OOD generalization, CE is misled by the more noticeable position factor due to the spurious correlation to digits, and resorts to random guess (even
7For categorical y, the expectation of y is taken under the one-hot representation. 8See Appx. Thm. 6’ for the formal version. 9As the induced operator norm for matrices (not the Frobenius norm).
10Codes are available at https://github.com/changliu00/causal-semantic-generative-model.
worse) when position is not informative for prediction. CNBB ameliorates the position confusion, but not as thoroughly without modeling causal mechanisms. In contrast, our CSG gives more genuine predictions in unseen domains, thanks to the identification of the semantic factor. CSG-ind performs even better, justifying the merit of using an independent prior for prediction. For domain adaptation, CSG-DA achieves the best results. Existing adaptation methods even worsen the result (negative transfer), as the misleading position representation gets strengthened on the unsupervised test data. CSG is benefited from adaptation in a proper way that identifies the semantic factor.
ImageCLEF-DA is a standard benchmark for domain adaptation [1]. It has 12 classes and three domains of real-world images: Caltech-256, ImageNet, Pascal VOC 2012. We select four OOD prediction tasks C↔P, I↔P that have not seen good enough results. We adopt the same setup as [74]. As shown in Table 1(middle 4 rows), CSG-ind again achieves the best OOD generalization results, and even outperforms some domain adaptation methods. Our CSG also outperforms the baselines mostly. For domain adaptation, CSG-DA is the best in most cases and on par with the best in others.
PACS is a more recent benchmark dataset [69]. It has 7 classes and is named after its four domains: Photo, Art, Cartoon, Sketch; each contains images of a certain style. We follow the same setup as [39]; particularly, we pool together all domains but the test one as the single training domain. Results in Table 1(bottom 4 rows) show the same trend. CSG-DA even outperforms most domain generalization methods reported in [39], which are fed with more information. Appx. Tables 2,3 also show the results on an even larger dataset VLCS [30], which present a similar observation.
Visualization. Appx. Fig. 5 visualizes the learned models using LIME [91]. The results show our methods focus more on the semantic regions and shapes, indicating a causal representation is learned.
Dataset analysis. The results indicate our methods are more powerful on shifted-MNIST and PACS (and VLCS) than ImageCLEF-DA. This meets the intuition of identifiability (Thm. 5 Remark (1)): the random position or pooled training domain shows a diverse v for each s (while with a misleading spurious correlation), so identification is better guaranteed to overcome the spurious correlation.
Ablation study. To show the benefit of modeling s and v separately, we compare with a counterpart of CSG that treats s and v as a whole (equivalently, v → y is kept; see Appx. F.1.4 for method details). Appx. Tables 2,3 show that our methods outperform this baseline in all cases. This shows the separate modeling makes CSG consciously drive semantic representation into the dedicated variable s.

heading: 7 Conclusion and Discussion
text: We propose a Causal Semantic Generative model for single-domain OOD prediction tasks, which builds upon a causal reasoning, and models the semantic (cause of prediction) and variation factors separately. By the causal invariance principle, we develop novel and efficient learning and prediction methods, and prove the semantic-identifiability and the subsequent bounded generalization error and the success of adaptation. Experiments show the improved performance over prevailing baselines.
Notably, we answered the questions in the recent farseeing paper [98] on causal representation learning: we found an appropriate condition under which “causal variables can be recovered”, and provided “compelling evidence on the advantages (of causal modeling) in terms of generalization”. Also, separating semantics from variation extends to broader examples. Neural nets are found to
change their prediction under a different texture [34, 15]. Adversarial vulnerability [107, 38, 67] extends variation factors to human-imperceptible features, i.e. adversarial noise, which is found to have a strong correlation to the semantics [50]. The separation also matters for fairness when a sensitive variation factor may affect prediction. This work also inspires the dual connection between causal representation learning (“fill in the blanks” given a graph) and causal discovery (“link the nodes” given observed variables). Our theory shows the identifiability condition for causal discovery (the additive noise assumption) also makes causal representation identifiable. Studying the general connection between the two tasks is an interesting future work.

Review summaries:
The paper addresses the problem of out-of-distribution prediction by proposing a causal model which captures the underlying data generation process. The causal model consists of a latent variable which generates both the input images and the associated output labels. The novelty of the paper stems from the fact that the authors split the latent variable into two parts. The first part (s) captures the semantics of the generation process and the second part (v) captures the spurious domain specific variations. Since maximizing the likelihood of the data under this model is intractable, the authors propose an approximate and efficient training and inference mechanism. The authors show theoretically that their model will learn semantic features which are responsible for the final prediction. The claims are backed by a collection of experiments on simple datasets.   

This paper proposes a Causal Semantic Generative model (CSG) for out-of-distribution (OOD) generalization. It assumes a semantic latent variable $s$ and a variation latent variable $v$, following the causal graph that $s,v$ are the causes of the input $x$ and $s$ is the only cause of the label $y$. The prior $p(s,v)$ is domain-specific, but the causal mechanisms $p(x|s,v)$ and $p(y|s)$ are invariant across domains. To learn the model, the authors adopt variational inference by introducing $q(s,v|x)$ and training with ELBO. The authors consider single-domain OOD prediction and domain adaptation. For single-domain, they advocate to use an independent prior p(s)p(v) to eliminate spurious correlation. For domain adaptation, a new prior is learned on the target domain.  The authors provide theoretical analysis, showing that under additive noise assumption, the ground-truth CSG is identifiable, and subsequently the OOD generalization error and domain adaptation error are bounded. Experiments are conducted on Shifted MNIST, ImageCLEF-DA and PACS datasets. The proposed model achieves superior performance compared to CNBB in single domain and DANN, DAN, CDAN in domain adaptation.

The authors propose a specific graphical model, Causal Semantic Generative model, which is based on the principles of casual reasoning. The graphical model attempts to explicitly distinguish between meaningful semantic factors of variation and spurious correlations. The design of the model is targeted at out-of-domain generalization and domain adaptation performance. The authors describe an approach for training such a model using variational inference, and demonstrate theoretically and experimentally that their approach gives superior OOD generalization and domain adaptation performance compared to relevant baselines.

This paper focuses on addressing the domain generalization problem through the lens of causality. Instead of learning environment-invariant representation/inference p(z|x) like [31,97], the paper proposes to learn the other direction p(x|z). The paper proposes a novel graph, where it assumes the latent semantic-object representation (s) and domain-specific representation (v) cause the image. The generative mechanism works (s,v) -> x, while the prior p(s, v) can be prone to environment change at test time.   Therefore, the model proposes a CSG-ELBO to maximize the likelihood of E_{p(x, y)}[log p(x,y)], and further derive a CSG-ind to disentangle v from s. The paper conducts three experiments on different datasets for both OOD generalization and domain adaptation to show the advantage of their proposed model.