summaries: This paper presents conditions that are necessary for counterfactual invariant predictions under certain assumptions. They derive these from causal graphs and show the connection to worst-case domain generalization. Experiments on natural language datasets show that the proposed conditions do lead to a decrease in worst-domain error. In this paper, the authors study counterfactual invariance in machine learning models---intervening on “non causal” parts of the input should not change model predictions---and its relation to how models generalize out-of-domain. The authors show that counterfactually invariant predictors rely more on “causal” features as opposed to spurious correlations, thus generalizing to unseen distributions where these spurious correlations may not hold. The authors further propose two regularization schemes (one if the underlying data generation mechanism is represented by a causal model and another if it is an anticausal model) using which we can train counterfactually invariant predictors without access to counterfactual examples---as opposed to most prior work in which researchers often seek to either automatically construct or crowdsource counterfactual examples. They show that these strategies are heavily dependent on the underlying causal mechanisms, and that applying the regularization scheme designed for a causal model could lead to worse performance if the underlying data generation mechanism was anticausal and vice versa. The authors offer empirical evidence on text classification tasks (review helpfulness classification and natural language inference) to support their theoretical findings. I have some concerns about the paper (as discussed below) but overall I believe this paper builds on an exciting line of work and offers good theoretical and empirical contributions. The paper casts robustness to spurious correlations as a model's dependence on input data that is not stable under stress testing. Stress testing here corresponds to changing part of the input data that a practitioner believes should not change the prediction. The authors term this counterfactual invariance and consider two different causal structures that could've produced the data. Identifying distribution-level implications (as opposed to unit-level) of these causal structures, the authors propose regularization schemes to enforce when learning predictors to ensure that counterfactual-invariance holds (under certain assumptions). The effectiveness of these schemes is shown both theoretically and empirically. In this work, the authors focus on how to build models that are robust to spurious correlations. The focus of the paper is language datasets. The authors work with two types of DAGs -- a) association of the label with the invariant feature is anti-causal, and b) association of the label with invariant feature is causal. The authors propose a notion of invariance, which they call counterfactual invariance, that they require the predictor to satisfy. Under this notion, the prediction $f$ has to remain invariant under all the potential outcomes that $X$ can have under variations to the spurious feature $Z$. Since the notion of counterfactual invariance is hard to enforce as counterfactuals are not observed, the authors come up with necessary conditions that are then used as proxies to enforce counterfactual invariance. The necessary conditions are different in the two directions causal and anti-causal. Further, the authors analyze the relationship between best counterfactual invariant predictor on train domain and target domain (under appropriate notion of changes allowed in target domain). Finally, the authors establish conditions for min-max optimality of the predictor that is learned. 
abstractText: Informally, a ‘spurious correlation’ is the dependence of a model on some aspect of the input data that an analyst thinks shouldn’t matter. In machine learning, these have a know-it-when-you-see-it character; e.g., changing the gender of a sentence’s subject changes a sentiment predictor’s output. To check for spurious correlations, we can ‘stress test’ models by perturbing irrelevant parts of input data and seeing if model predictions change. In this paper, we study stress testing using the tools of causal inference. We introduce counterfactual invariance as a formalization of the requirement that changing irrelevant parts of the input shouldn’t change model predictions. We connect counterfactual invariance to outof-domain model performance, and provide practical schemes for learning (approximately) counterfactual invariant predictors (without access to counterfactual examples). It turns out that both the means and implications of counterfactual invariance depend fundamentally on the true underlying causal structure of the data—in particular, whether the label causes the features or the features cause the label. Distinct causal structures require distinct regularization schemes to induce counterfactual invariance. Similarly, counterfactual invariance implies different domain shift guarantees depending on the underlying causal structure. This theory is supported by empirical results on text classification.
authors.name: Victor Veitch
authors.name: Alexander D’Amour
authors.name: Steve Yadlowsky
authors.name: Jacob Eisenstein
references.authors: M. Arjovsky L. Bottou I. Gulrajani D. Lopez-Paz. Invariant Risk Minimization
references.title: 2020
references.venue: arXiv:
references.authors: M. Baktashmotlagh M.T. Harandi B.C. Lovell M. Salzmann
references.title: Unsupervised domain adaptation by domain invariant projection
references.venue: In: Proceedings of the 2013 IEEE International Conference on Computer Vision.
references.authors: M. Besserve A. Mehrjou R. Sun B. Schölkopf. Counterfactuals uncover the modular structure of deep generative models
references.title: 2019
references.venue: arXiv:
references.authors: J. Devlin M.-W. Chang K. Lee K. Toutanova
references.title: Bert: pre-training of deep bidirectional transformers for language understanding
references.venue: In: Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers).
references.authors: Y. Ganin E. Ustinova H. Ajakan P. Germain H. Larochelle F. Laviolette M. Marchand V. Lempitsky
references.title: Domain-adversarial training of neural networks
references.venue: J. Mach. Learn. Res
references.authors: S. Garg V. Perot N. Limtiaco A. Taly E.H. Chi A. Beutel
references.title: Counterfactual fairness in text classification through robustness
references.venue: In: Proceedings of the 2019 AAAI/ACM Conference on AI, Ethics, and Society.
references.authors: A. Gretton K.M. Borgwardt M.J. Rasch B. Schölkopf A. Smola
references.title: A kernel two-sample test
references.venue: The Journal of Machine Learning Research
references.authors: S. Gururangan S. Swayamdipta O. Levy R. Schwartz S. Bowman N.A. Smith
references.title: Annotation artifacts in natural language inference data
references.venue: In: Proceedings of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 2 (Short Papers).
references.authors: W. Huang H. Liu S.R. Bowman. Counterfactually-Augmented SNLI Training Data Does Not Yield Better Generalization Than Unaugmented Data
references.title: 2020
references.venue: arXiv:
references.authors: D. Kaushik E. Hovy Z.C. Lipton. Learning the Difference that Makes a Difference with Counterfactually-Augmented Data
references.title: 2020
references.venue: arXiv:
references.authors: D. Kaushik A. Setlur E. Hovy Z.C. Lipton. Explaining The Efficacy of Counterfactually Augmented Data
references.title: 2021
references.venue: arXiv:
references.authors: V. Kumar A. Choudhary E. Cho
references.title: Data augmentation using pre-trained transformer models
references.venue: In: Proceedings of the 2nd Workshop on Life-long Learning for Spoken Language Systems.
references.authors: M.J. Kusner J. Loftus C. Russell R. Silva
references.title: Counterfactual fairness
references.venue: In: Advances in Neural Information Processing Systems.
references.authors: F. Locatello B. Poole G. Raetsch B. Schölkopf O. Bachem M. Tschannen
references.title: Weakly-supervised disentanglement without compromises
references.venue: In: Proceedings of the 37th International Conference on Machine Learning.
references.authors: J. Manders T. van Laarhoven E. Marchiori. Adversarial Alignment of Class Prediction Uncertainties for Domain Adaptation
references.title: 2019
references.venue: arXiv:
references.authors: N. Mehrabi F. Morstatter N. Saxena K. Lerman A. Galstyan. A Survey on Bias Fairness in Machine Learning
references.title: 2019
references.venue: arXiv:
references.authors: N. Meinshausen
references.title: Causality from a distributional robustness point of view
references.venue: In: 2018 IEEE Data Science Workshop (DSW).
references.authors: J. Mitrovic B. McWilliams J. Walker L. Buesing C. Blundell. Representation Learning via Invariant Causal Mechanisms
references.title: 2020
references.venue: arXiv:
references.authors: K. Muandet D. Balduzzi B. Schölkopf
references.title: Domain generalization via invariant feature representation
references.venue: In: Proceedings of the 30th International Conference on Machine Learning.
references.authors: A. Naik A. Ravichander N. Sadeh C. Rose G. Neubig
references.title: Stress test evaluation for natural language inference
references.venue: In: Proceedings of the 27th International Conference on Computational Linguistics.
references.authors: J. Ni J. Li J. McAuley
references.title: Justifying recommendations using distantly-labeled reviews and fined-grained aspects
references.venue: Empirical Methods in Natural Language Processing (EMNLP)
references.authors: J. Peters P. Bühlmann N. Meinshausen
references.title: Causal inference by using invariant prediction: identification and confidence intervals
references.venue: Journal of the Royal Statistical Society. Series B (Statistical Methodology)
references.authors: M.T. Ribeiro T. Wu C. Guestrin S. Singh
references.title: Beyond accuracy: behavioral testing of nlp models with checklist
references.venue: In: Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics.
references.authors: A. Robey G.J. Pappas H. Hassani. Model-Based Domain Generalization
references.title: 2021
references.venue: arXiv:
references.authors: M. Rojas-Carulla B. Schölkopf R. Turner J. Peters
references.title: Invariant models for causal transfer learning
references.venue: Journal of Machine Learning Research
references.authors: S. Sagawa P.W. Koh T.B. Hashimoto P. Liang
references.title: Distributionally robust neural networks for group shifts: on the importance of regularization for worst-case generalization
references.venue: In: International Conference on Learning Representations.
references.authors: B. Schölkopf D. Janzing J. Peters E. Sgouritsa K. Zhang J. Mooij
references.title: On causal and anticausal learning
references.venue: In: Proceedings of the 29th International Coference on International Conference on Machine Learning.
references.authors: B. Schölkopf F. Locatello S. Bauer N.R. Ke N. Kalchbrenner A. Goyal Y. Bengio
references.title: Toward causal representation learning
references.venue: Proceedings of the IEEE
references.authors: A. Subbaswamy B. Chen S. Saria. A Universal Hierarchy of Shift-Stable Distributions the Tradeoff Between Stability Performance
references.title: 2019
references.venue: arXiv:
references.authors: A. Subbaswamy S. Saria
references.title: Counterfactual normalization: proactively addressing dataset shift and improving reliability using causal mechanisms
references.venue: In: Proceedings of the 34th Conference on Uncertainty in Artificial Intelligence (UAI), 2018.
references.authors: D. Teney E. Abbasnejad A. van den Hengel
references.title: Learning what makes a difference from counterfactual examples and gradient supervision
references.venue: In: CoRR (2020). arXiv:
references.authors: E. Tzeng J. Hoffman N. Zhang K. Saenko T. Darrell
references.title: Deep Domain Confusion: Maximizing for Domain Invariance
references.venue: 2014. arXiv:
references.authors: J. Wei K. Zou
references.title: EDA: easy data augmentation techniques for boosting performance on text classification tasks
references.venue: In: Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP).
references.authors: A. Williams N. Nangia S. Bowman
references.title: A broad-coverage challenge corpus for sentence understanding through inference
references.venue: In: Proceedings of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long Papers).
references.authors: T. Wu M.T. Ribeiro J. Heer D. Weld
references.title: Errudite: scalable
references.venue: reproducible, and testable error analysis”. In: Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics.
references.authors: T. Wu M.T. Ribeiro J. Heer D.S. Weld
references.title: Polyjuice: generating counterfactuals for explaining
references.venue: evaluating, and improving models”. In: Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics.
references.authors: H. Yan Y. Ding P. Li Q. Wang Y. Xu W. Zuo
references.title: Mind the Class Weight Bias: Weighted Maximum Mean Discrepancy for Unsupervised Domain Adaptation
references.venue: 2017. arXiv:
references.authors: K. Zhang B. Schölkopf K. Muandet Z. Wang
references.title: Domain adaptation under target and conditional shift
references.venue: In: Proceedings of the 30th International Conference on Machine Learning.
sections.heading: 1 Introduction
sections.text: Our focus in this paper is the sort of spurious correlations revealed by “poke it and see what happens” testing procedures for machine-learning models. For example, we might test a sentiment analysis tool by changing one proper noun for another (“tasty Mexican food” to “tasty Indian food”), with the expectation that the predicted sentiment should not change. This kind of perturbative stress testing is increasingly popular: it is straightforward to understand and offers a natural way to test the behavior of models against the expectations of practitioners [Rib+20; Wu+19; Nai+18].
  Intuitively, models that pass such stress tests are preferable to those that do not. However, fundamental questions about the use and meaning of perturbative stress tests remain open. For instance, what is the connection between passing stress tests and model performance on prediction? Eliminating predictor dependence on a spurious correlation should help with domain shifts that affect the spurious correlation—but how do we make this precise? And, how should we develop models that pass stress tests when our ability to generate perturbed examples is limited? For example, automatically perturbing the sentiment of a document in a general fashion is difficult.
  The ad hoc nature of stress testing makes it difficult to give general answers to such questions. In this paper, we will use the tools of causal inference to formalize what it means for models to pass stress tests, and use this formalization to answer the questions above. We will formalize passing stress tests as counterfactual invariance, a condition on how a predictor should behave when given
  35th Conference on Neural Information Processing Systems (NeurIPS 2021).
  certain (unobserved) counterfactual input data. We will then derive implications of counterfactual invariance that can be measured in the observed data. Regularizing predictors to satisfy these observable implications provides a means for achieving (partial) counterfactual invariance. Then, we will connect counterfactual invariance to robust prediction under certain domain shifts, with the aim of clarifying what counterfactual invariance buys and when it is desirable.
  An important insight that emerges from the formalization is that the true underlying causal structure of the data has fundamental implications for both model training and guarantees. Methods for handing ‘spurious correlations’ in data with a given causal structure need not perform well when blindly translated to another causal structure.
  Counterfactual Invariance Consider the problem of learning a predictor f that predicts a label Y from covariates X . In this paper, we’re interested in constructing predictors whose predictions are invariant to certain perturbations on X . Our first task is to formalize the invariance requirement.
  To that end, assume that there is an additional variable Z that captures information that should not influence predictions. However, Z may causally influence the covariates X . Using the potential outcomes notation, letX(z) to denote the counterfactualX we would have seen had Z been set to z, leaving all else fixed. Informally, we can understand perturbative stress tests as a way of producing particular realizations of counterfactual pairs X(z), X(z′) that differ by an intervention on z. Then, we formalize the requirement that an arbitrary change to z does not change predictions: Definition 1.1. A predictor f is counterfactually invariant to Z if f(X(z)) = f(X(z′)) almost everywhere, for all z, z′ in the sample space of Z. When Z is clear from context, we’ll just say the predictor is counterfactually invariant.
sections.heading: 2 Causal Structure
sections.text: Counterfactual invariance is a condition on how the predicted label behaves under interventions on parts of the input data. However, intuitions about stress testing are based on how the true label behaves under interventions on parts of the input data. We will see that the true causal structure fundamentally affects both the implications of counterfactual invariance, and the techniques we use to achieve it. To study this phenomenon, we’ll use two causal structures that are commonly encountered in applications; see Figure 1.
sections.heading: 2.1 Prediction in the Causal Direction
sections.text: We begin with the case where X is a cause of Y . Example 2.1. We want to automatically classify the quality of product reviews. Each review has a number of “helpful” votes Y (from site users). We predict Y using the text of the product review X . However, we find interventions on the sentiment Z of the text change our prediction; changing “Great shoes!” to “Bad shoes!” changes the prediction.
  In the examples in this paper, the covariate X is text data. Usually, the causal relationship between the text and Y and Z will be complex— e.g., the relationships may depend on abstract, unlabeled, parts of the text such as topic, writing quality, or tone. In principle, we could enumerate all such latent variables, construct a causal graph capturing the relationships between these variables and Y, Z, and use this causal structure to study counterfactual invariance. For instance, if we think that topic causally influences the helpfulness Y , but is not influenced by sen-
  timent Z, then we could build a counterfactually invariant predictor by extracting the topic and
  predicting Y using topic alone. However, exhaustively articulating all possible such variables is a herculean task.
  Instead, notice that the only thing that’s relevant about these latent variables is their causal relationship with Y and Z. Accordingly, we’ll decompose the observed variable X into parts defined by their causal relationships with Y and Z. We remain agnostic to the semantic interpretation of these parts. Namely, we defineX⊥Z as the part ofX that is not causally influenced by Z (but may influence Y ), X⊥Y as the part that does not causally influence Y (but may be influenced by Z), and XY ∧Z is the remaining part that is both influenced by Z and that influences Y . The causal structure is shown in Figure 1a.
  We see there are two paths that lead to Y and Z being associated. The first is when Z affects XY ∧Z which, in turn, affects Y . For example, a very enthusiastic reviewer might write a longer, more detailed review, which will in turn be more helpful. The second is when a common cause or selection effect in the data generating process induces an association between Z and Y , which we denote with a dashed arrow. For example, if books tend to get more positive reviews, and also people who buy books are more likely to flag reviews as helpful, then the product type would be a common cause of sentiment and helpfulness.
sections.heading: 2.2 Prediction in the Anti-Causal Direction
sections.text: We also consider the case where Y causes X .
  Example 2.2. We want to predict the star rating Y of movie reviews from the text X . However, we find that predictions are influenced by the movie genre Z; e.g., changing “Adam Sandler” (a comedy actor) to “Hugh Grant” (a romance actor) changes the predictions.
  Figure 1b shows the causal structure. Here, the observed X is influenced by both Y and Z. Again, we decompose X into parts defined by their causal relationship with Z and Y . Here, Z (and thus X⊥Y ) can be associated with Y through two paths. First, if XY ∧Z is non-trivial, then conditioning on it causes a dependence between Z and Y (because XY ∧Z is a collider). For example, if Adam Sandler tends to appear in good comedy movies but bad movies of other genres then seeing “Sandler” in the text induces a dependency between sentiment and genre. Second, Z and Y may be associated due to a common cause, or due to selection effects in the data collection protocol—this is represented by the dashed line between Z and Y . For example, fans of romantic comedies may tend to give higher reviews (to all films) than fans of horror movies.
sections.heading: 2.3 Non-Causal Associations
sections.text: Frequently, a predictor trained to predict Y from X will rely on X⊥Y , even though there is no causal connection between Y and X⊥Y , and therefore will fail counterfactual invariance. The reason is that X⊥Y serves as a proxy for Z, and Z is predictive of Y due to the non-causal (dashed line) association.
  There are two mechanisms that can induce such associations. First, Y and Z may be confounded: they are both influenced by an unobserved common causeU . For example, people who review books may be more upbeat than people who review clothing. This leads to positive sentiments and high helpfulness votes for books, creating an association between sentiment and helpfulness. Second, Y and Z may be subject to selection: there is some condition (event) S that depends on Y and Z, such that a data point from the population is included in the sample only if S = 1 holds. For example, our training data might only include movies with at least 100 reviews. If only excellent horror movies have so many reviews (but most rom-coms get that many), then this selection would induce an association between genre and score. Formally, the dashed-line causal graphs mean our sample is distributed according to P (X,Y, Z) = ∫ P(X,Y, Z, u | S = 1)dP(u) where Y,Z are caused by U and are causes of S, and (X,Y, Z) are causally related according to the graph.
  In addition to the non-causal dashed-line relationship, there is also dependency induced by between Y and Z by XY ∧Z . Whether or not each of these dependencies is “spurious” is a problem-specific judgement that must be made by each analyst based on their particular use case. E.g., using genre to predict sentiment may or may not be reasonable, depending on the actual application in mind. However, there is a special case that captures a common intuition for purely spurious association.
  Definition 2.3. We say that the association between Y and Z is purely spurious if Y ⊥ X |X⊥Z , Z.
  That is, if the dashed-line association did not exist (removed by conditioning on Z) then the part of X that is not influenced by Z would suffice to estimate Y .
sections.heading: 3 Observable Signatures of Counterfactually Invariant Predictors
sections.text: We now consider the question of how to achieve counterfactual invariance in practice. The challenge is that counterfactual invariance is defined by the behavior of the predictor on counterfactual data that is never actually observed. This makes checking counterfactual invariance impossible. Instead, we’ll derive a signature of counterfactual invariance that actually can be measured—and enforced— using ordinary datasets where Z (or a proxy) is measured. For example, the star rating of a review as a proxy for sentiment, or genre labels in the movie review case.
  Intuitively, a predictor f is counterfactually invariant if it depends only on X⊥Z , the part of X that is not affected by Z. To formalize this, we need to show that such a X⊥Z is well defined: Lemma 3.1. LetX⊥Z be aX-measurable random variable such that, for all measurable functions f , we have that f is counterfactually invariant if and only if f(X) is X⊥Z -measurable. If Z is discrete 1 then such a X⊥Z exists.
  Accordingly, we’d like to construct a predictor that is a function ofX⊥Z only (i.e., isX ⊥ Z measurable). The key insight is that we can use the causal graphs to read off a set of conditional independence relationships that are satisfied by Z,X⊥Z , Y . Critically, these conditional independence relationships are testable from the observed data. Thus, they provide a signature of counterfactual invariance: Theorem 3.2. If f is a counterfactually invariant predictor:
  1. Under the anti-causal graph, f(X) ⊥ Z | Y . 2. Under the causal-direction graph, if Y and Z are not subject to selection (but possibly
  confounded), f(X) ⊥ Z. 3. Under the causal-direction graph, if the association is purely spurious, Y ⊥ X | X⊥Z , Z,
  and Y and Z are not confounded (but possibly selected), f(X) ⊥ Z | Y . Remark 3.3 (Connection to Fairness). This result has an interesting interpretation when Z is a protected attribute (e.g., sex or race) that we’d like to be fair with respect to. There are many ways of formalizing fairness, which are usually mutually incompatible. In the fairness setting, counterfactual invariance is equivalent to counterfactual fairness [Kus+17; Gar+19], the condition f(X) ⊥ Z is equivalent to demographic parity, and the condition f(X) ⊥ Z | Y is equivalent to equalized odds [Meh+19]. Theorem 3.2 then says that counterfactual fairness implies either demographic parity or equalized odds, depending on the true underlying causal structure of the problem. Hence, the relationship between disparate fairness notions is clarified by taking the underlying causal structure into account. This also suggests we can take counterfactual fairness as the fundamental notion, then use demographic parity in the causal-confounding case and equalized odds otherwise. However, we leave the (ethical) question of whether this is a sound strategy to future work.
  Causal Regularization Without access to counterfactual examples, we cannot directly enforce counterfactual invariance. However, we can require a trained model to satisfy the counterfactual invariance signature of Theorem 3.2. The hope is that enforcing the signature will lead the model to be counterfactually invariant. To do this, we regularize the model to satisfy the appropriate conditional independence condition. For simplicity of exposition, we restrict to binary Y and Z. The (infinite data) regularization terms are
  marginal regularization = MMD(P(f(X) | Z = 0),P(f(X) | Z = 1)) (3.1) conditional regularization = MMD(P(f(X) | Z = 0, Y = 0),P(f(X) | Z = 1, Y = 0)) (3.2)
  +MMD(P(f(X) | Z = 0, Y = 1),P(f(X) | Z = 1, Y = 1)). Maximum mean discrepancy (MMD) is a metric on probability measures.2 The marginal independence condition is equivalent to (3.1) equal 0, and the conditional independence is equivalent to (3.2)
  1In fact, it suffices that all potential outcomes {Y (z)}z are jointly measurable with respect to a single well-behaved sigma algebra; discrete Z is sufficient but not necessary.
  2The choice of regularization by MMD is for concreteness. Any technique for enforcing the independence signatures would do in principle—e.g., adversarial methods borrowed from the fairness literature. The key point here is the observation that different causal structures imply different independence signatures.
  equal 0. In practice, we can estimate the MMD with finite data samples [Gre+12]. When training with stochastic gradient descent, we compute the penalty on each minibatch.
  The procedure is then: if the data has causal-direction structure and the Y ↔ Z association is due to confounding, add the marginal regularization term to the the training objective. If the data has anti-causal structure, or the association is due to selection, add the conditional regularization term instead. In this way, we regularize towards models that satisfy the counterfactual invariance signature.
  A key point is that the regularizer we must use depends on the true causal structure. The conditional and marginal independence conditions are generally incompatible. Enforcing the condition that is mismatched to the true underlying causal structure may fail to encourage counterfactual invariance, or may throw away more information than is required.
  Gap to Counterfactual Invariance The conditional independence signature of Theorem 3.2 is necessary but not sufficient for counterfactual invariance. This is for two reasons. First, counterfactual invariance applies to individual datapoint realizations, but the signature is distributional. In particular, the invariance P(f(X) | do(Z = z)) = P(f(X) | do(Z = z′)) for all z, z′ would also imply the conditional independence signature. But, this invariance is weaker than counterfactual invariance, since it doesn’t require access to counterfactual realizations. Second, f(X) ⊥ Z does not imply, in general, that Z is not a cause of f(X). This (unusual) behavior can happen if, e.g., there are levels of Z that we do not observe in the training data, or there are variables omitted from the causal graph that are a common cause of Z and X .
  Unfortunately, the gap between the signature and counterfactual invariance is a fundamental restriction of using observational data. The conditional independence signature is in some sense the closest proxy for counterfactual invariance we can hope for. In section 5, we’ll see that enforcing the signature does a good job of enforcing counterfactual invariance in practice.
sections.heading: 4 Performance Out of Domain
sections.text: Counterfactual invariance is an intuitively desirable property for a predictor to have. However, it’s not immediately clear how it relates to model performance as measured by, e.g., accuracy. Intuitively, eliminating predictor dependence on a spurious Z may help with domain shift, where the data distribution in the target domain differs from the distribution of the training data. We now turn to formalizing this idea.
  First, we must articulate the set of domain shifts to be considered. In our setting, the natural thing is to hold the causal relationships fixed across domains, but to allow the non-causal (“spurious”) dependence between Y and Z to vary. Demanding that the causal relationships stay fixed reflects the requirement that the causal structure describes the dynamics of an underlying real-world process— e.g., the author’s sentiment is always a cause (not an effect) of the text in all domains. On the other hand, the dependency between Y and Z induced by either confounding or selection can vary without changing the underlying causal structure. For confounding, the distribution of the confounder may differ between domains—e.g., books are rare in training, but common in deployment. For selection, the selection criterion may differ between domains—e.g., we include only frequently reviewed movies in training, but make predictions for all movies in deployment.
  We want to capture spurious domain shifts by considering domain shifts induced by selection or confounding. However, there is an additional nuance. Changes to the marginal distribution of Y will affect the risk of a predictor, even in the absence of any spurious association between Y and Z. Therefore, we restrict to shifts that preserve the marginal distribution of Y . Definition 4.1. We say that distributions P,Q are causally compatible if both obey the same causal graph, P (Y ) = Q(Y ), and there is a confounder U and/or selection conditions S, S̃ such that P = ∫ P(X,Y, Z | U, S=1)dP̃ (U) and Q= ∫ P(X,Y, Z | U, S̃=1)dQ̃(U) for some P̃ (U), Q̃(U).
  We can now connect counterfactual invariance and robustness to domain shift. Theorem 4.2. Let F invar be the set of all counterfactually invariant predictors. Let L be either square error or cross entropy loss. And, let f∗ := argminf∈F invar EP [L(Y, f(X))] be the counterfactually invariant risk minimizer. Suppose that the target distributionQ is causally compatible with the training distribution P . Suppose that any of the following conditions hold:
  1. the data obeys the anti-causal graph 2. the data obeys the causal-direction graph, there is no confounding (but possibly selection),
  and the association is purely spurious, Y ⊥ X | X⊥Z , Z, or 3. the data obeys the causal-direction graph, there is no selection (but possibly confounding),
  the association is purely spurious and the causal effect of X⊥Z on Y is additive, i.e., the true data generating process is
  Y ← g(X⊥Z ) + g̃(U) + ξ where E[ξ | X⊥Z ] = 0, (4.1)
  for some functions g, g̃.
  Then, the training domain counterfactually invariant risk minimizer is also the target domain counterfactually invariant risk minimizer, f∗ = argminf∈F invar EQ[L(Y, f(X))]. Remark 4.3. The causal case with confounding requires an additional assumption (additive structure) because, e.g., an interaction between confounder and X⊥Z can yield a case where X ⊥ Z and Y have a different relationship in each domain (whence, out-of-domain learning is impossible).
  This result gives a recipe for finding a good predictor in the target domain even without access to any target domain examples at training time. Namely, find the counterfactually invariant risk minimizer in the training domain. In practice, we can use the regularization scheme of section 3 to (approximately) achieve this. We’ll see in section 5 that this works well in practice.
  Optimality Theorem 4.2 begs the question: if the only thing we know about the target setting is that it’s causally compatible with the training data, is the best predictor the counterfactually invariant predictor with lowest training risk? A natural way to formalize this question is to study the predictor with the best performance in the worst case target distribution. We define Q = {Q : Q causally compatible with P} and the Q-minimax predictor f∗minimax = argminf∈F maxQ∈Q EQ[L(Y, f(X)]. The question is then: what’s the relationship between the counterfactually invariant risk minimizer and the minimax predictor? Theorem 4.4. The counterfactually invariant risk minimizer is notQ-minimax in general. However, under the conditions of Theorem 4.2, if the association is purely spurious, XY ∧Z ⊥ Y |X⊥Z , Z, and P(Z, Y ) satisfies overlap, then the two predictors are the same. By overlap we mean that P(Z, Y ) is a discrete distribution such that for all (z, y), if P(z, y) > 0 then there is some y′ 6= y such that also P(z, y′) > 0.
  Conceptually, Theorem 4.4 just says that the counterfactually invariant predictor excludes XY ∧Z , even when this information is useful in every domain. In the purely spurious case, XY ∧Z carries no useful information, so counterfactual invariance is optimal.
sections.heading: 5 Experiments
sections.text: The main claims of the paper are:
  1. Stress test violations can be reduced by suitable conditional independence regularization. 2. This reduction will improve out-of-domain prediction performance. 3. To get the full effect, the imposed penalty must match the causal structure of the data.
  Setup To assess these claims, we’ll examine the behavior of predictors trained with the marginal or conditinal regularization on multiple text datasets that have either causal or anti-causal structure. We expect to see that marginal regularization improves stress test and out-of-domain performance on data with causal-confounded structure, and conditional regularization improves these on data with anti-causal structure.
  For each experiment, we use BERT [Dev+19] finetuned to predict a label Y from the text as our base model. We train multiple causally-regularized models on the each dataset. The training varies by whether we use the conditional or marginal penalty, and by the strength of the regularization term. That is, we train identical architectures using CrossEntropy+λ ·Regularizer as the objective function, where we vary λ and take Regularizer as either the marginal penalty, (3.1), or conditional penalty, (3.2). We compare these models’ predictions on data with causal and anti-causal structure.
  See supplement for experimental details.
sections.heading: 5.1 Robustness to Stress Tests
sections.text: First, we examine whether enforcing the causal regularization actually helps to enforce counterfactual invariance. We create counterfactual (stress test) examples by perturbing the input data and compare the prediction on these. We build the experimental datasets using Amazon reviews from the product category “Clothing, Shoes, and Jewelry” [NLM19].
  Synthetic To study the relationship between counterfactual invariance and the distributional signature of Theorem 3.2, we construct a synthetic confound. For each review, we draw a Bernoulli random Z, and then perturb the text X so that the common words “the” and “a” carry information about Z: for example, we replace “the” with the token “thexxxxx” when Z = 1. We take Y to be the review score, and subsample so Y is balanced. This data has anti-causal structure: the text X is written to explain the score Y . Further, we expect that the Y,Z association is purely spurious, because “the” and “a” carry little information about the label.
  We train the models on data where P(Y = Z) = 0.3. We then create perturbed stress-test datasets by changing each example Xi(z) to the counterfactual Xi(1 − z) (using the synthetic model). By measuring the performance of each model on the perturbed data, we can test whether the distributional properties enforced by the regularizers result in counterfactual invariance at the instance level. Figure 2 shows that conditional regularization (matching the anti-causal structure) reduces checklist failures, as measured by the frequency that the predicted label changes due to perturbation as well as the mean absolute difference in predictive probabilities that is induced by perturbation.
  Natural To study the relationship in real data, we use the review data in a different way. We now take Z to be the score, binarized as Z ∈ {1 or 2 stars, 4 or 5 stars}. We use this Z as a proxy for sentiment, and consider problems where sentiment should (plausibly) not have a causal effect on Y . For the causal prediction problem, we take Y to be the helpfulness score of the review (binarized as described below). This is causal because readers decide whether the review is helpful based on the text. For the anti-causal prediction problem, we take Y to be whether “Clothing” is included as a category tag for the product under review (e.g., boots typically do not have this tag). This is
  anti-causal because the product category affects the text.
  We control the strength of the spurious association between Y and Z. In the anti-causal case, this is done by selection: we randomly subset the data to enforce a target level of dependence between Y and Z. The causal-direction case with confounding is more complicated. To manipulate confounding strength, we binarize the number of helpfulness votes V in a manner determined by
  the target level of association. We take Y = 1[V > TZ ] where TZ is a Z-dependent threshold, chosen to induce a target association. We choose P(Y = 0 | Z = 0) = P(Y = 1 | Z = 1) = 0.3. We balance Z by subsampling, which also balances Y .
  Now, we create stress test perturbations of these datasets by randomly changing adjectives in the examples. Using predefined lists of postive sentiment adjectives and negative sentiment adjectives, we swap any adjective that shows up on a list with a randomly sampled adjective from the other list. This preserves basic sentence structure, and thus creates a limited set of counterfactual pairs that differ on sentiment.
  Results for differences in predicted probabilities between original and perturbed data are shown in Figure 3. Each point is a trained model, which vary in measured MMD on the test data and on sensitivity to perturbations. Recall that the conditional independence signature of Theorem 3.2 are necessary but not sufficient for counterfactual invariance, so it’s not certain that regularizing to reduce the MMD will reduce perturbation sensitivity. Happily, we see that regularizing to reduce the MMD that matches the causal structure does indeed reduce sensitivity to perturbations.
  Notice that regularizing the causally mismatched MMD can have strange effects. Regularizing marginal MMD in the anti-causal case actually makes the model more sensitive to perturbations!
sections.heading: 5.2 Domain Shift
sections.text: Next, we study the effect of causal regularization on model performance under domain shift.
  The plots show out-of-domain accuracy for models trained on the (natural) review data. In each row, the left figure shows out-of-domain accuracies (lines are models), with the X-axis showing the level of spurious correlation in the test data (0.3 is the training condition); the right figure shows worst out-of-domain accuracy versus in-domain test accuracy (dots are models).
  Natural Product Review We again use the natural Amazon review data described above. For both the causal and anticausal data, we create multiple test sets with variable spurious correlation strength. This is done in the manner described above, varying P(Y = 0 | Z = 0) = P(Y = 1 | Z = 1) = γ. Here, γ is the strength of spurious association. The test sets are out-of-domain samples. By design, Y is balanced in each dataset, so these samples are causally compatible with the training data. For both the causal and anti-causal datasets, the training data has P(Y = 0 | Z = 0) = P(Y = 1 | Z = 1) = 0.3. We train a classifier for each regularization type and regularization strength, and measure the accuracy on each test domain. The results are shown in Figure 4.
  First, the unregularized predictors do indeed learn to rely on the spurious association between sentiment and the label. The accuracy of these predictors decays dramatically as the spurious assocation moves from negative (0.3) to positive—in the causal case, the unregularized predictor is worse than chance in the 0.8 domain.
  Following section 3, the regularization that matches the underlying causal structure should yield a predictor that is (approximately) counterfactually invariant. Following Theorem 4.2, we expect that good performance of a counterfactually-invariant predictor in the training domain should imply good performance in each of the other domains. Indeed, we see that this is so. Models that are regularized to have small values of the appropriate MMD do indeed have better out-of-domain performance.
  Such models have somewhat worse in-domain performance, because they no longer exploit the spurious correlation.
  MNLI Data For an additional test on naturally-occurring confounds, we use the multigenre natural language inference (MNLI) dataset [WNB18]. Instances are concatenations of two sentences, and the label describes the semantic relationship between them, Y ∈ {contradiction, entailment, neutral}. There is a well-known confound in this dataset: examples where the second sentence contain a negation word (e.g., “not”) are much more likely to be labeled as contradictions [Gur+18]. Following Sagawa et al. [Sag+20], we set Z to indicate whether one of a small set of negation words is present. Although Z is derived from the text X , it can be viewed as a proxy for a latent variable indicating whether the author intended to use negation in the text. This is an anti-causal prediction problem: the annotators were instructed to write text to reflect the desired label [WNB18].
  Following Sagawa et al. [Sag+20], we divide the MNLI data into groups by (Y, Z) and compute the “worst group accuracy” across all such groups. Because this is an anti-causal problem, we predict that the conditional MMD is a more appropriate penalty than the marginal MMD. As shown in Figure 5, this prediction holds: conditional MMD regularization dramatically improves performance on the worst group, while only lightly impacting the overall accuracy across groups.
sections.heading: 6 Related work
sections.text: Several papers draw a connection between causality and domain shifts [SS18; SCS19; Arj+20; Mei18; PBM16; RC+18; Zha+13; Sch+12]. Typically, this work considers a prediction setting where the covariates X include both causes and effects of Y , and it is unknown which is which. The goal is to learn to predict Y using only its causal parents. Zhang et al. [Zha+13] considers anti-causal domain shift induced by changing P (Y ) and proposes a data reweighting scheme. By contrast, counterfactual invariance is an example-wise notion of invariance, not an invariance across environments. In particular, learning a counterfactually invariant predictor only requires access to data from a single environment. Theorem 4.2 establishes that counterfactual invariance does imply a certain domain generalization guarantee over causally-compatible domains. Note though that the notion of causal compatibility is not generally the same as class of domain shifts previously considered. For example, we have invariant performance in the anti-causal setting, but this is ruled out by Arjovsky et al. [Arj+20].
  A related body of work focuses on “causal representation learning” [Bes+19; Loc+20; Sch+21; Arj+20]. Our approach follows this tradition, but focuses on splittingX into components defined by their causal relationships with the label Y and an additional covariate Z. Rather than attempting to infer the causal relationship between X and Y , we show that domain knowledge of this relationship is essential for obtaining counterfactually-invariant predictors. The role of causal vs anti-causal data generation in semi-supervised learning and transfer learning has also been studied [Sch+21; Sch+12]. In this paper we focus on a different implication of the causal vs anti-causal distinction.
  Another line of work considers the case where either the counterfactuals X(z), X(z′) are observed for at least some data points, or where it’s assumed that there’s enough structural knowledge to (learn to) generate counterfactual examples [RPH21; Wu+21; Gar+19; Mit+20; WZ19; KCC20; KHL20; TAH20]. Kusner et al. [Kus+17] and Garg et al. [Gar+19] in particular examine a notion of
  counterfactual fairness that can be seen as equivalent to counterfactual invariance. In these papers, approximate counterfactuals are produced by direct manipulation of the features (e.g., change male to female names), generative models (e.g., style transfer of images), or crowdsourcing. Then, these counterfactuals can either be used as additional training data or the predictor can be regularized such that it cannot distinguish between Xi(z) and Xi(z′). This strategy can be viewed as enforcing counterfactual invariance directly; an advantage is that it avoids the necessary-but-not-sufficient nuance of Theorem 3.2. However, counterfactual examples can be difficult to obtain for language data in many realistic problem domains, and it may be difficult to learn to generalize from such examples [HLB20].
  The marginal and conditional independencies of Theorem 3.2 have appeared in other contexts. As discussed in remark 3.3, if we think of Z as a protected attribute and f as a ‘fair’ classifier, then counterfactual invariance is counterfactual fairness, the marginal independence is demographic parity, and the conditional independence is equalized odds [Meh+19]. In another setting, one approach to domain adaptation is to seek representations φ such that either φ(X) [e.g., MBS13; Bak+13; Gan+16; Tze+14] or φ(X) | Y [e.g., MLM19; Yan+17] have the same distribution in each environment. The connection here is subtler; it is inappropriate to interpret Z as a domain label (we only have access to one domain at train time, and all values of Z are present in each domain). To clarify the connection, consider introducing an extra variable E that labels the domain. For concreteness, consider the anti-causal case where the spurious association between Y and Z is due to an observed confounder U . Now, suppose that E is a cause of U . Then, E labels the distribution of the unobserved confounder, and thus different values of E correspond to different causally compatible domains. Now, if we draw the causal graph we can read off that X⊥z E|Y . That is, we arrive at the same conditional independence criterion. However, it’s essentially a coincidence that this matches the criterion we’d use if we’d observed Z—the two variables have totally different causal meanings and interpretations. For example, in the review data case, we might take Z to be review score and E to be the website the review is collected from. The review quality doesn’t need to be counterfactually invariant to the website, and indeed we wouldn’t expect it to be!
  Finally, this work can be viewed as part of a recent line of work using counterfactuals to examine the connection between example-wise robustness (stress testing) and distributional-level robustness (domain shift) [e.g., TAH20; RPH21; Kau+21]. Teney et al. [TAH20] use near counterfactuals with different labels in a modified training objective, and show improved performance out-of-domain empirically. Robey et al. [RPH21] use image models to generate counterfactuals, and incorporate the model into training, showing out-of-domain improvement. They assume a somewhat different causal structure—articulating the precise connection is an interesting future direction. Kaushik et al. [Kau+21] study a linear-Gaussian model and argue that out-of-domain performance can be used as a signal to distinguish ‘causal’ and ‘spurious’ features.
sections.heading: 7 Discussion
sections.text: We used the tools of causal inference to formalize and study perturbative stress tests. A main insight of the paper is that counterfactual desiderata can be linked to observationally-testable conditional independence criteria. This requires consideration of the true underlying causal structure of the data. Done correctly, the link yields a simple procedure for enforcing the counterfactual desiderata, and mitigating the effects of domain shift.
  The main limitation of the paper is the restrictive causal structures we consider. In particular, we require that X⊥Z , the part of X not causally affected by Z, is also statistically independent of Z in the observed data. However, in practice these may be dependent due to a common cause. In this case, the procedure here will be overly conservative, throwing away more information than required. Additionally, it is not obvious how to apply the ideas described here to more complicated causal situations, which can occur in structured prediction (e.g., question answering). Extending the ideas to handle richer causal structures is an important direction for future work. The work described here can provide a template for this research program.
sections.heading: 8 Acknowledgements
sections.text: Thanks to Kevin Murphy, Been Kim, Molly Roberts, Justin Grimmer, and Brandon Stewart for feedback on an earlier version.
sections.heading: 9 Funding Transparency
sections.text: This paper was not supported by any third party funding, and the authors have no competing interests to declare.
title: Counterfactual Invariance to Spurious Correlations: Why and How to Pass Stress Tests