Learning Causal Semantic Representation for Out-of-Distribution Prediction

1 Introduction . 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 . 2 Related Work . 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 . 3 The Causal Semantic Generative Model . 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 .

Summary: 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.