We address causal inference with text documents. For example, does adding atheorem to a paper affect its chance of acceptance? Does reporting the genderof a forum post author affect the popularity of the post? We estimate theseeffects from observational data, where they may be confounded by features ofthe text such as the subject or writing quality. Although the text suffices forcausal adjustment, it is prohibitively high-dimensional. The challenge is tofind a low-dimensional text representation that can be used in causalinference. A key insight is that causal adjustment requires only the aspects oftext that are predictive of both the treatment and outcome. Our proposed methodadapts deep language models to learn low-dimensional embeddings from text thatpredict these values well; these embeddings suffice for causal adjustment. Weestablish theoretical properties of this method. We study it empirically onsemi-simulated and real data on paper acceptance and forum post popularity.Code is available at https://github.com/blei-lab/causal-text-embeddings.
Quick Read (beta)
Using Text Embeddings for Causal Inference
We address causal inference with text documents. For example, does adding a theorem to a paper affect its chance of acceptance? Does reporting the gender of a forum post author affect the popularity of the post? We estimate these effects from observational data, where they may be confounded by features of the text such as the subject or writing quality. Although the text suffices for causal adjustment, it is prohibitively high-dimensional. The challenge is to find a low-dimensional text representation that can be used in causal inference. A key insight is that causal adjustment requires only the aspects of text that are predictive of both the treatment and outcome. Our proposed method adapts deep language models to learn low-dimensional embeddings from text that predict these values well; these embeddings suffice for causal adjustment. We establish theoretical properties of this method. We study it empirically on semi-simulated and real data on paper acceptance and forum post popularity. Code is available at github.com/blei-lab/causal-text-embeddings.
fontsize= \crefnamelemmalemmalemmas \CrefnamelemmaLemmaLemmas \crefnamethmtheoremtheorems \CrefnamethmTheoremTheorems \crefnameproppropositionpropositions \CrefnamepropPropositionPropositions \crefnameassumptionassumptionassumptions \crefnameassumptionAssumptionAssumptions \newbibmacro*journal \addbibresourcebibs/language,bibs/causality \crefformatequation(#2#1#3) \crefformatfigureFigure #2#1#3 \crefnameexampleExampleExamples \crefnamelemmaLemmaLemmas \crefnamecorCorollaryCorollaries \crefnametheoremTheoremTheorems \crefnameassumptionAssumptionAssumptions
We develop a method for causal inference from observed text documents. We consider a binary treatment, an outcome of interest, and a document of text. We assume that the text carries sufficient information to identify the causal effect; it is either an observed confounder or an observed mediator.
Consider a corpus of scientific papers submitted to a conference. Some have theorems; others do not. We want to infer the causal effect of including a theorem on paper acceptance. The effect is confounded by the subject of the paper—more technical topics demand theorems, but may have different rates of acceptance. The data does not explicitly list the subject, but it does include each paper’s abstract. We want to use the text to adjust for the subject and estimate the causal effect.
Consider comments from Reddit.com, an online forum. Each post has a popularity score and the author of the post may (optionally) list their gender. We want to know the direct effect of a ‘male’ label on the score of the post. However, the author’s gender may affect the text of the post, e.g., through tone, style, or topic choices, which also affects its score. Again, we want to use the text to accurately estimate the causal effect.
In these two examples, we assume that the text carries sufficient information to identify the causal effect. In theory, we can use classical methods of causal inference to adjust for the text of the document. But in practice we have finite data and the text is high dimensional, prohibiting efficient and accurate causal inference. The challenge is to reduce the text to a low-dimensional representation that both suffices for causal identification and that allows effective estimation with finite data.
Our strategy is to draw on text embedding methods to reduce the dimension of the text \citep[e.g.,]Mikolov:Chen:Corrado:Dean:2013,Mikolov:Sutskever:Chen:Corrado:2013,Devlin:Chang:Lee:Toutanova:2018,Peters:Neumann:Iyyer:Gardner:Clark:Lee:Zettlemoyer:2018. Informally, a text embedding method distills the text of each document to a real-valued vector, and these embeddings can be used as features for prediction problems. Black-box embedding methods are state-of-the-art for a range of natural language understanding tasks [Devlin:Chang:Lee:Toutanova:2018, Peters:Neumann:Iyyer:Gardner:Clark:Lee:Zettlemoyer:2018]. Here, we will adapt embedding methods in the service of causal inference.
The key insight is that to adjust for variables in causal inference, it suffices to use only the information relevant to the prediction of the treatment and outcome. Thus we harness modern embedding methods—BERT [Devlin:Chang:Lee:Toutanova:2018], in particular—to extract the information from the text required for this prediction problem . The learned embeddings capture information sufficient for causal identification and provide the necessary ingredients for various causal estimators.
Contribution. The main contribution of this paper is a method for adapting off-the-shelf text embedding methods to estimate treatment effects. We show that the method is theoretically sound, demonstrate its utility on semi-synthetic data, and apply it to real datasets for estimating causal effects of the properties of papers on acceptance and gender label on popularity.
2 Related work.
This paper connects to several areas of related work.
The first area is causal inference for text. \citetroberts2018adjusting also discuss how to estimate effects of treatments applied to text documents. They rely (in part) on topic modeling to reduce the dimension of the text. This strategy is reasonable if the learned topics reflect the confounding aspects of the text. In contrast, we replace the assumption that the topics capture confounding with the assumption that an embedding method can effectively extract predictive information. We compare to a topic-model based approach in creftype 5.
In other work, \citetegami2018make reduce raw text to interpretable outcomes; \citetwood2018challenges estimate treatment effects when confounders are observed, but missing or noisy treatments are inferred from text. In contrast, we are concerned with text as the confounder.
A second area of related work addresses causal inference with unobserved confounding when there is an observed proxy for the confounder [Kuroki:Miyakawa:1999, Pearl:2012, Kuroki:Pearl:2014, Miao:Geng:TchetgenTchetgen:2018, kallus2018causal]. This work usually assumes that the observed proxy variables are noisy realizations of the unobserved confounder, and then derives conditions under which causal identification is possible. One view of our problem is that each unit has a latent attribute (e.g., topic) such that observing it would suffice for causal identification, and the text is a proxy for this attribute. Unlike the proxy variable approach, however, we assume the text fully captures confounding. Our interest is in methods for finite-sample estimation rather than infinite-data identification.
Louizos:Shalit:Mooij:Sontag:Zemel:Welling:2017 also work with proxy variables, and consider the estimation problem. They fit a variational autoencoder using observed data and assume that it exactly recovers the true data generating distribution (including the latent confounder). We require weaker assumptions than the full recovery of the data generating distribution.
Work on causal inference with hidden confounding and many treatments is in the same vein [Wang:Blei:2018, Ranganath:Perotte:2018, damour:2019]. The idea is to use the treatments to infer the latent confounders. In contrast, we assume that the text suffices to adjust for confounding .
Finally, \citetVeitch:Wang:Blei:2019 also use the reduction of causal estimation to prediction. In their case, to address unobserved confounding in the presence of network data.
We begin by fixing notation and recalling some ideas from the estimation of causal effects. Each statistical unit is a document represented as a tuple , where is the outcome, is the treatment, and is the sequence of words. The observed dataset consists of observations drawn independently and identically at random from some distribution, .
We review estimation of the average treatment effect and the natural direct effect. For both, we assume that the words are sufficient for adjustment.
Average treatment effect. The average treatment effect (ATE) is defined as
The use of Pearl’s notation indicates that the effect of interest is causal: what happens if we intervene by adding a theorem to a paper? We assume that the words carry sufficient information to adjust for confounding (common causes) between and . creftypecap 1 on the left depicts this assumption. We define to be the part of which blocks all ‘backdoor paths’ between and . The causal effect is then identifiable from observational data as:
Our task is to estimate the ATE from a finite data sample. Define to be the conditional expected outcome and to be an estimate for . Following 3.1, a natural estimator is:
That is, is estimated by a two-stage procedure: First produce an estimate for through a predictive model; then plug into a pre-determined statistic to compute the estimate of the ATE.
The estimator creftype 3.2 is not the only possible choice. In principle, it is possible to do better by using estimators that also incorporate estimates of the propensity scores \citep[e.g.,]Robins:2000,vanderLaan:Rose:2011,Robins:Rotnitzky:Zhao:1994,Chernozhukov:Chetverikov:Demirer:Duflo:Hansen:Newey:Robins:2017. The general approach is a two-stage procedure. First fit a model for propensity scores and conditional outcomes; then plug the fitted model into a downstream estimator. What is important is that these estimators depend on only through and .
Natural direct effect. The direct effect is the expected change in outcome if we apply the treatment while holding fixed any mediating variables that are affected by the treatment and that affect the outcome. creftypecap 1 on the right depicts the text as mediator of the treatment and outcome. For the estimation of the direct effect, we take to be the parts of that mediate and . The natural direct effect of treatment is average difference in outcome induced by giving each unit the treatment, if the distribution of had been as though each unit received treatment. That is,
In the gender example, this is the expected difference in score between a post labeled as written by a man versus labeled as written by a woman, where the expectation is taken over the distribution of posts written by men.
Under minimal conditions, this quantity may be estimated from observational data [Pearl:2014]. The natural estimator is \citep[Ch. 8]vanderLaan:Rose:2011
As with the ATE, there are also more sophisticated estimators \citep[e.g.,][Ch. 8]vanderLaan:Rose:2011. Again, all such estimators rely on only through the estimated conditional outcomes and propensity scores.
4 Causal text embeddings
We first focus on estimation of the average treatment effect. Following the previous section, we want to produce estimates of the propensity score and the conditional expected outcome . We assume that some property of the text suffices for identification. The obstacle motivating this paper is that we do not directly observe the confounding features . Instead, we must work with the raw text.
A simple approach is to abandon altogether and learn models for the propensities and conditional outcomes directly from the words . Since contains all information about , the direct adjustment will also render the causal effect identifiable. Indeed, in an infinite-data setting this would be a sound approach. However, the dimensionality of the problem is prohibitive.
We require a reduction of the words to a feature that both contains sufficient information to render the causal effect identifiable, and that will allow us to effectively learn the propensity scores and conditional outcomes with a finite data sample. A key insight follows from \citep[Thm. 3]Rosenbaum:Rubin:1983. Recall and .
Suppose is some function of the words such that at least one of the following is -measurable:
If adjusting for suffices to render the average treatment effect identifiable then adjusting for only also suffices. That is, .
In words: the random variable carries the information about relevant to the prediction of both the propensity score and the conditional expected outcome. While will typically throw away much of the information in the words, creftype 4.1 says that adjusting for it suffices to estimate causal effects. Item 3 says that this holds even if we throw away information relevant to , so long as this information is not also relevant to (and vice versa). The utility of creftype 4.1 is that if we can find features of that suffice for the prediction problem, then adjusting for these features also suffices for the causal estimation problem.
Our strategy is to use the words of each document to produce an embedding vector that captures the confounding aspects of the text. These embeddings are satisfactory if we can use them to estimate the propensities and conditional outcomes required by the downstream effect estimator.
We will use embedding-based prediction models from the natural language processing literature. For our purposes, these models may viewed as black-boxes that take in words and produce a tuple , which contains an embedding and estimates of and that use that embedding. The idea is that such models provide an effective black-box tool for both distilling the words into the information relevant to prediction problems, and for solving those prediction problems.
Finally, to estimate the average treatment effect, we follow the general strategy of creftype 3. First, we fit the embedding-based prediction model to produce estimated embeddings , propensity scores and conditional outcomes . We then plug these values into a downstream estimator. We will see an explicit example below.
Validity. The next result gives conditions for this procedure to be valid.
Let be the conditional outcomes and propensities given . Suppose that is some consistent estimator for the average treatment effect . Further suppose that there is some function of the words such that
(identification) satisfies the condition of creftype 4.1.
(consistency) as , where is the estimated conditional outcome and propensity model.
(well-behaved estimator) for some constant ,
The requirement that the estimator behaves asymptotically as a sample mean is not an important restriction; most commonly used estimators have this property [Kennedy:2016]. The third condition is a technical requirement on the estimator. In the cases we consider, it suffices that the range of and are bounded and that is bounded away from 0 and 1. This later requirement is the common ‘overlap’ condition, and is anyway required for the estimation of the causal effects.
By creftype 4.1 and assumption 1, .
For brevity, we write . By Taylor’s theorem,
for some . By continuous mapping, it suffices to show that the second term goes to 0 in probability. By Cauchy-Schwarz and assumption 3,
By Markov’s inequality, for all . The result follows by assumption 2. ∎
As with all causal inference, the validity of the procedure relies on uncheckable assumptions that the practitioner must assess on a case-by-case basis. Particularly, we require that:
(properties of) the document text renders the effect identifiable,
the embedding method extracts text information relevant to the prediction of both and ,
the conditional outcome and propensity score models are consistent.
Only the second assumption is non-standard. In practice, we use the best possible embedding method and take the strong performance on (predictive) natural language tasks in many contexts as evidence that the method effectively extracts information relevant to prediction tasks. Implicitly, we are assuming that features that are useful for language understanding tasks are also useful for eliminating confounding. This is reasonable in settings where we expect the confounding to be aspects such as topic, writing quality, or sentiment. Informally, assumption 2 is satisfied if we use a good natural-language model, so we satisfy it by using the best available model.
Causal BERT. We modify BERT, a state-of-the-art language model \citepDevlin:Chang:Lee:Toutanova:2018. Each input to BERT is the document text, a sequence of word-piece tokens . The model is tasked with producing three kinds of outputs: 1) document-level embeddings, 2) a map from the embeddings to treatment probability, 3) a map from the embeddings to expected outcomes for the treated and untreated.
The model assigns an embedding to each word-piece . It then produces a document-level embedding for document text as for a particular function . The embeddings and global parameter are trained by minimizing an unsupervised objective, denoted as . Informally, random word-piece tokens are censored from each document and the model is tasked with predicting their identities.11 1 BERT also considers a ‘next sentence’ prediction task, which we do not use.
Following \citetDevlin:Chang:Lee:Toutanova:2018, we use a fine-tuning approach to solve the prediction problem. We add a logit-linear layer mapping and a 2-hidden layer neural net for each of and . We learn the parameters for the embedding model and the prediction model jointly. Intuitively, this adapts the embeddings to be useful for the downstream prediction task, i.e., for causal inference.
We write for the full collection of global parameters. The final model is trained as:
where the objective is designed to predict both the treatment and outcome. It is
Effect estimation. Computing causal effect estimates simply requires plugging in the propensity scores and expected outcomes that the trained model predicts on the held-out units. For example, using the plug-in estimator creftype 3.2,
The same procedure applies to other estimators as well.
Natural direct effect. We now discuss the analogous development for the natural direct effect. In this setting, the text serve as mediators between the treatment and the outcome. We are interested in understanding the causal effect of the treatment that does not go through the text.
The key result is the analogue of creftype 4.1. Namely, suppose is some function of the words such that carries all information relevant to both the prediction of the treatment and outcome. Then the natural direct effect is equal to
That is, adjusting for suffices to adjust for any mediating effect in the words. This result is essentially by definition: any mediator must be predictive of both the treatment and outcome, so it suffices to adjust only for the parts of that are predictive of both treatment and outcome.
The remaining development is identical to the average treatment effect case. We estimate embeddings, propensities, and conditional expected outcomes using Causal BERT, and then plug these estimates into a downstream direct effect estimator. For example,
The proof of validity is the same as creftype 4.2.
We now empirically study the quality of Causal BERT embeddings for causal estimation. The questions of interest are: 1) do the learned embeddings identify causal effects in realistic simulations? 2) what happens in the presence of unobserved confounding exogenous to the text? Additionally, we apply the proposed method to the two motivating examples in the introduction. We estimate causal effects on paper acceptance and post popularity on Reddit.com.22 2 Software and data at github.com/blei-lab/causal-text-embeddings.
We find: 1) The method is able to effectively adjust for confounding. And, 2) it is robust to exogenous confounding. Our application suggests that much of the apparent effect of the treatments we study is attributable to confounding in the text.
PeerRead. PeerRead is a corpus of computer-science papers [Kang:Ammar:Dalvi:vanZuylen:Kohlmeier:Hovy:Schwartz:2018]. We consider a subset of the corpus consisting of papers posted to the arXiv under cs.cl, cs.lg, or cs.ai between 2007 and 2017 inclusive. The data only includes papers which are not cross listed with any non-cs categories and are within a month of the submission deadline for a target conferences. The conferences are: ACL, EMNLP, NAACL, EACL, TACL, NeurIPS, ICML, ICLR and AAAI. A paper is marked as accepted if it appeared in one of the target venues. Otherwise, the paper is marked as rejected. The dataset includes 11,778 papers, of which 2,891 are accepted.
For each paper, we consider the text of abstract, the accept/reject decision, and two attributes:
buzzy: the title contains any of ‘deep’, ‘neural’, ‘embed’, or ‘adversarial net’.
theorem: the word ‘Theorem’ appears in the paper.
These attributes can be predicted from the abstract text.
Reddit. Reddit is an online forum divided into topic-specific subforums called ‘subreddits’. We consider three subreddits: keto, okcupid, and childfree. In these subreddits, we identify users whose username flair includes a gender label (usually ‘M’ or ‘F’). We collect all top-level comments from these users in 2018. We use each comment’s text and score, the number of likes minus dislikes from other users. The dataset includes 90k comments in the selected subreddits. We consider the direct effect of the labeled gender on posts’ scores.
Estimator. We use Causal BERT, explained in creftype 4. We truncate PeerRead abstracts to 250 word-piece tokens, and Reddit posts to 128 word-piece tokens. We begin with a BERT model pre-trained on a general English language corpus. We further pre-train a BERT model on each dataset, running training on the unsupervised objective until convergence. In all cases, we use a logit-linear layer to predict treatment from embeddings, and a 2 hidden layer neural network for the expected outcome predictor.
For each experiment, we consider two downstream estimators: The simple estimators creftypeplural 4.3\crefpairconjunction4.1, and ‘one-step’ TMLE estimators [vanderLaan:Gruber:2016]. The latter are more sophisticated estimators that combine estimated conditional outcomes and propensities to achieve asymptotic robustness and efficiency properties. For all estimators, we exclude units that have a predicted propensity score greater than 0.97 or less than 0.03.
Empirical evaluation of causal estimation procedures requires semi-synthetic data because ground truth causal effects are usually not available for real-world data. For such evaluations to be compelling, the semi-synthetic model must be reflective of real-world data. This is challenging for text data: there are no realistic generative models of text, so it is not possible to generate a confounder and then generate the text, treatment, and outcome on the basis of this confounder.
To circumvent this, we use real metadata—subreddit and title buzziness—as the confounders for the simulation. We simulate only the outcomes, using the treatment and the confounder. We compute the true propensity score as the proportion of units with in each strata of . Then, is simulated from the model:
Or, for binary outcomes,
The parameter controls the level of confounding; e.g., the bias of the unadjusted difference increases with . For PeerRead, we report estimates of the ATE for binary simulated outcomes. For Reddit, we compute the NDE for simulated real-valued outcomes.
Additionally, we compare against two baselines. The first is a two-stage procedure that uses LDA to estimate document-topic proportions and linear/logistic regression for and . The second fits linear/logistic regression for the expected outcomes and treatments using word counts directly without dimensionality reduction.
Results are summarized in creftypeplural 2\crefpairconjunction1. Compared to the unadjusted estimate, all methods for adjustment reduce confounding. However, causal BERT does substantially better for moderate to high confounding. This is even in a simulation setting favorable to LDA (the true confounding is topic, and has a simple relation to outcome). The benefits of dimensionality reduction on text are clear in PeerRead, where adjustment based on LDA is much better than using the words alone.
The effect of exogeneity.
We assume that the text carries all information about the confounding (or mediation) necessary to identify the causal effect. In many situations, this assumption may not be fully realistic. For example, in the simulations just discussed, it may not be possible to exactly recover the confounding from the text. We study the effect of violating this assumption by simulating both treatment and outcome from a confounder that consists of a part that can be fully inferred from the text and part that is wholly exogenous.
The challenge is finding a realistic confounder that can be exactly inferred from the text. Our approach is to (i) train BERT to predict the actual treatment of interest, producing propensity scores for each , and (ii) use as the inferrable part of the confounding. Precisely, we simulate propensity scores as , with . The outcome is simulated as above. When , the simulation is fully-inferrable and closely matches real data. Increasing allows us to study the effect of exogeneity; see creftype 2. As expected, the adjustment quality decays. Remarkably, the adjustment improves the naive estimate at all levels of exogeneity—the method is robust to violations of the theoretical assumptions.
Application We apply causal BERT to estimate the treatment effect of buzzy and theorem, and the effect of gender on log-score in each subreddit; see creftypeplural 4\crefpairconjunction3. Although unadjusted estimates suggest strong effects, our results show this is in large part explainable by confounding or mediating. On PeerRead, the TMLE estimate suggests a positive effect from including a theorem on paper acceptance, but the -only estimator does not. On Reddit, both estimates suggest a positive effect from labeling a post as female on its score in okcupid and childfree.