49
Text Mining for Economics and Finance Supervised Learning Stephen Hansen Text Mining Lecture 7 1 / 48

Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Embed Size (px)

Citation preview

Page 1: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Text Mining for Economics and FinanceSupervised Learning

Stephen Hansen

Text Mining Lecture 7 1 / 48

Page 2: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Introduction

Supervised learning is the problem of predicting a response variable (i.e.dependent variable) associated with documents using features of the text data.

For example, we may want to predict political party affiliation usingstate-of-the-union addresses.

Supervised learning has many commercial applications: predict which links avisitor to a website will click; which songs a listener will like; which emails arespam; and so on.

Supervised learning and econometrics share many of the same tools, but theemphasis is different.

Text Mining Lecture 7 2 / 48

Page 3: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Limitations of Prediction

The ability to predict response variables with a high degree of accuracy is notnecessarily useful for many of the goals of economic research:

1. In many cases, no specific behavioral model is being tested.

2. Often economists care about counter-factual analysis and policyexperiments, which the output of supervised learning algorithms does notoften facilitate. E.g. relationship between price and quantity.

3. No guidance as to why predictive relationships exist, which is problematicfor building forecasting models. E.g. Google Trends and flu outbreak.

4. Lucas critique. E.g. when consumers know firms set prices based on theirobserved behavior, consumers can strategically respond.

Text Mining Lecture 7 3 / 48

Page 4: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Application of Supervised Learning I

In some cases, we have some observations with a response variable and otherswithout.

We can use a predictive model to associate observation features with responses,and then apply the model to associate out-of-sample observations with labels.

Useful when we have a theory that requires measuring observations in terms oflabels, but which does not provide guidance about the relationship betweenfeatures and labels.

One advantage of supervised over unsupervised learning is that the output ismore interpretable since it is linked explicitly to labels.

Text Mining Lecture 7 4 / 48

Page 5: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Application of Supervised Learning II

Many empirical papers boil down to testing the significance of a singlecovariate’s relationship with a dependent variable while controlling for othercovariates.

Theory often motivates the relationship of interest, but not necessarily the set ofvariables to control for.

A typical approach is to run many different specifications to test how robust thepredicted relationship is.

Supervised learning can allow us to be more honest and simply include allcovariates and let the data decide which are the important ones.

Text Mining Lecture 7 5 / 48

Page 6: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Supervised Learning Problems

Supervised learning problems can be divided into two:

1. In classification problems, we place each document into one of a finitenumber of categories.

2. In regression problems, we use features of the document-term matrix topredict a continuous variable.

There is a strong connection between classification problems and latent variablemodels. Essentially, what are unobserved in the latter are observed in the former.

Text Mining Lecture 7 6 / 48

Page 7: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Rocchio Classification

Let each document d belong to one of C finite classes, and let Dc be the set ofdocuments in class c ∈ {1, . . . ,C}.

The centroid of the documents in class c is ~uc = 1|Dc |

∑d∈Dc

~xd .

We then assign out-of-sample documents to whichever class has the closestclass centroid.

This defines a linear classifier in which the decision boundary between twoclasses is a hyperplane.

Supervised analogue of k-means.

Text Mining Lecture 7 7 / 48

Page 8: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

K Nearest Neighbor Classification

In k nearest neighbor model (kNN), we have a set of labeled documents, andclassify new documents by looking at the labels of the k closest documents.

We assign the new document the label corresponding to the most frequent labelamong the neighbors.

This yields a locally linear, but globally non-linear classifier. More complexdecision rule than Rocchio, but potentially more accurate for inherentlynon-linear classification.

Text Mining Lecture 7 8 / 48

Page 9: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Discriminative Classification

We now discuss parametric models of the relationship between covariates xdand the dependent variable yd .

A discriminative classifier estimates the conditional distribution Pr [ yd | xd ].

Discriminative classifiers (logistic regression, support vector machines, etc.) canbe applied to text data without modification since we do not have to model thegeneration of documents.

Since we usually do not have many documents relative to vocabulary terms,fitting such models requires regularization.

Text Mining Lecture 7 9 / 48

Page 10: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Feature Selection

To apply a discriminative classifier, we need to choose how to represent thefeatures of our text.

Can use raw term counts (unigrams, bigrams, etc.); topic share representations;or even both together.

Can also use non-labeled texts along with labeled texts in topic modeling, sinceLDA uses no information from labels in estimation of topic shares.

Blei et. al. (2003) show that topic share representation is competitive with rawcounts in discriminative classification exercise.

Text Mining Lecture 7 10 / 48

Page 11: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Linear Regression

We are all familiar with one discriminative classifier: the linear regression modelin which Pr [ y | β, x ] = N (y | β · x, σ2).

The log-likelihood function is

`(β) =N∑i=1

Pr [ yi | β, xi ] =N∑i=1

log

[(1

2πσ2

)1/2

exp(− 12σ2 (yi − β · xi )2

)]=

− 12σ2 RSS(β)− N

2log(2πσ2).

where RSS(β) is the residual sum of squares.

So the OLS coefficients minimize RSS(β), which yields β = (X′X)−1X′y.

Text Mining Lecture 7 11 / 48

Page 12: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

OLS and Overfitting

Especially with many covariates, or high-degree polynomials, OLS is at risk ofoverfitting.

One popular solution is to punish model complexity through introducingpenalization terms into the objective function.

These can be statistically founded by introducing priors on the regressioncoefficients that encourage them to be smaller in magnitude.

Text Mining Lecture 7 12 / 48

Page 13: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Ridge Regression

Suppose we draw each regression coefficient βi from a normal prior N (0, τ2).Lower values of τ are associated with smaller values of the coefficients.

The posterior distribution over β is then proportional to Pr [ y | β, x ]Pr [β ].

Finding the β at which the posterior is highest is called maximum a posteriori(MAP) estimation.

The objection function for MAP estimation can be written

RSS(β) + λ∑j

β2j

which is called the ridge regression model.

Solution is βR = (λID + X′X)−1X′y. The higher is λ, the smaller are thecoefficients. Shrinkage but not sparsity.

Text Mining Lecture 7 13 / 48

Page 14: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

LASSO

Now suppose we draw each regression coefficient βj from a Laplace prior so thatPr [βi | λ ] ∝ exp(−λ|βj |).

Unlike the normal distribution, the Laplace distribution has a spike at 0 whichpromotes sparsity.

The objection function for MAP estimation can be written

RSS(β) + λ∑j

|βj |

which is called the LASSO.

One reason for the popularity of LASSO for variable selection is that it is aconvex optimization problem and can be solved with extremely efficientalgorithms.

Text Mining Lecture 7 14 / 48

Page 15: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

LASSO and Causal Inference

A typical goal in econometrics is to identify the effect of a (low-dimensional)treatment variable on an outcome of interest.

There are typically also a high-dimensional set of controls whose dimensionalityis reduced through ad hoc decisions.

These controls may include text data, e.g. effect of identity of author on readeropinions requires controlling for content of text.

Increasing interest in using variable selection techniques to aid in causalinference.

Belloni et. al. (2014) provide an overview of current research on this topic ineconometrics.

Text Mining Lecture 7 15 / 48

Page 16: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Instrumental Variables Model

yi = αdi + εi

di = z ′i Π + ri + νi

where E[ εi | zi ] = E[ νi | zi , ri ] = 0, but E[ εiνi ] = 0.

This is the standard instrumental variables model in econometrics, but whatabout when there are many instruments?

Under an assumption of approximate sparsity in the relationship between di andthe instruments, performing LASSO as part of a two-stage procedure allows forvalid inference on α.

Intuitively, selection mistakes in the first stage have only mild effects since thetrue coefficient of any omitted instruments will be small.

Text Mining Lecture 7 16 / 48

Page 17: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Model with Treatment and Controls

yi = αdi + x ′i θy + ryi + ψi

where E[ψi | di , xi , ryi ] = 0.

Suppose that di is low-dimensional; that xi is high-dimensional; and that themodel satisfies approximate sparsity.

A naive procedure for selection of controls is to estimate a LASSO thatpenalizes the controls but not the treatments.

The problem is that the procedure will omit controls that are highly correlatedwith di since they are penalized while di is not.

This creates an omitted-variable bias whenever the relationship between theomitted variables and the outcome is moderately sized.

Text Mining Lecture 7 17 / 48

Page 18: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Double Selection

The proposed solution is to run LASSO twice:

1. Regress outcome variable on controls, select set P1.

2. Regression treatment variable on controls, select set P2.

Perform OLS with outcome as dependent variable, and treatment + P1 + P2 asindependent variables.

This guards against excluding controls that are either highly correlated with thetreatment and moderately correlated with the outcome, or moderatelycorrelated with the treatment and highly correlated with the outcome.

Inference on α using double selection is valid even if we allow selection mistakes.

Text Mining Lecture 7 18 / 48

Page 19: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Simulation Results

Text Mining Lecture 7 19 / 48

Page 20: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Post-Selection Inference on SelectedVariables

The previous model emphasized inference about a non-selected treatment effectby tuning the selection of controls.

However at times we wish to perform inference on the selected variablesthemselves.

This is problematic because even if random relationships exist in the data,LASSO will find some covariates that correlate with the dependent variable.

Cross-validation can mitigate the problem, but few guarantees exist about theestimated coefficients—one can prove (Meinshausen and Bühlmann 2006) thatcross validation selects too many variables.

Bottom line: LASSO was designed for prediction problems, and research intoparameter inference is an ongoing and unresovled issue.

Text Mining Lecture 7 20 / 48

Page 21: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Solutions

More robust approach is to explicitly compute model inclusion probabilties in aBayesian framework.

A simpler solution (Bach 2008, Meinshausen and Bühlmann 2010) is based onbootstrapping.

We can repeatedly resample the observations, fit LASSO for each draw, andrecord whether every variable was selected or not.

The fraction of times that each variable appears across the samples then acts asan approximation of posterior inclusion probabilities in a Bayesian model.

Selecting variables that appear more than a fixed fraction of times produces asparser estimator than cross validation.

Text Mining Lecture 7 21 / 48

Page 22: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Example

In recent work with Michael McMahon and Matthew Tong, we study the impactof the release of the Bank of England’s Inflation Report on bond price changesat different maturities.

IR contains forecast variables we use as controls: (i) mode, variance, andskewness of inflation and GDP forecasts; (ii) their difference from the previousforecast.

To represent text, we estimate a 30-topic model and represent each IR in termsof (i) topic shares and (ii) evolution of topic shares from previous IR.

First step in the analysis is to partial out the forecast variables from bond pricemoves and topic shares by constructing residuals.

We are then left with 69 bond price moves (number of IRs in the data) and 60text features.

Text Mining Lecture 7 22 / 48

Page 23: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Results of Hold-One-Out CV

Gilt1yspot Gilt3y Gilt5yλmin .0000204 .0000306 .0000244Features selected 54 57 55

No guidance on what the key dimensions of variation in the text are.

Text Mining Lecture 7 23 / 48

Page 24: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Results of Boostrapping

For each maturity, we constructed 100 boostrap draws and kept text featurespresent in two-thirds or more.

Gilt1yspot Gilt3y Gilt5yFeatures selected 5 4 5

Text Mining Lecture 7 24 / 48

Page 25: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Gilt1yspot: T1 and T5

Text Mining Lecture 7 25 / 48

Page 26: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Gilt3y and Gilt5y: D6 and D15

Text Mining Lecture 7 26 / 48

Page 27: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Generative Modeling

A generative classifier estimates the full joint distribution Pr [ y , xd ].

Discriminative models have lower asymptotic error, but generative models:

1. May approach their asymptotic error faster (Ng and Jordan 2001).

2. Allow one to generate new data.

In practice, we estimate models of the form Pr [ xd | y ], a relationship we thenneed to invert for classifying out-of-sample documents.

Text Mining Lecture 7 27 / 48

Page 28: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Naive Bayes Classifier

A simple generative model is the Naive Bayes classifier.

The “naive” assumption is that the elements of xd are independent within aclass. This is equivalent to the unigram model we discussed earlier.

Let xc,v be the count of term v among all documents in class c , and |Dc | thenumber of documents in class c . Then the joint log-likelihood is∑

c

|Dc | log(ρc) +∑c

∑v

xc,v log(βc,v )

with MLE estimates

ρc =|Dc |D

and βc,v =xc,v∑v xc,v

(=

xc,v + 1∑v xc,v + V

with smoothing).

This is like the multinomial mixture model but with observed rather than latentclass labels.

Text Mining Lecture 7 28 / 48

Page 29: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Classification

We can obtain Pr [ cd | xd ] ∝ Pr [ xd | cd ]Pr [ cd ] from Bayes’ rule, where theprobabilities on the RHS are already estimated.

To assign a class-label cd to an out-of sample document we can use MAPestimation:

cd = argmaxc

log(ρc) +∑v

xd,v log(βc,v ).

While the probabilities themselves are not generally accurate, classificationdecisions can be surprisingly so.

Text Mining Lecture 7 29 / 48

Page 30: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Generative Classification with LDA

To build a generative classifier with LDA, one can estimate separate models foreach class labels, and thereby obtain αc and β1,c , . . . ,βK ,c for each class label.

For an out-of-sample document d , one can then obtain an estimate of θd,cgiven the class-label-specific parameters, for example by querying according tothe procedure in the previous lecture slides.

Finally, one can assign the document to whichever class has a highestprobability, which is easily computed—the probability of observing term v inclass c is

∑k θd,c,k βk,c,v .

Text Mining Lecture 7 30 / 48

Page 31: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Inverse Regression

Modeling and inverting the relationship Pr [ xd | y ] is more difficult when y iscontinuous and/or multidimensional.

Well-known example of this inverse regression problem is Gentzkow and Shapiro(2010).

Drawing on this paper as motivation, Taddy (2013) and Taddy (2015) haveproposed fully generative models for inverse regression.

Text Mining Lecture 7 31 / 48

Page 32: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Measuring Media Slant

Gentzkow and Shapiro (2010) explore the determinants of newspapers’ideological slant.

The key measurement problem is that we observe the text of newspaper articles,but not their location on a political ideology scale.

Their solution is to determine the relationship between bigram and trigramfrequencies used in US Congressional speeches and political party affiliation, andthen to use these estimates to predict the ideology of newspaper.

The theory relies on observing newspapers’ ideologies, but the relationshipbetween words and ideology is left completely open ex ante.

Text Mining Lecture 7 32 / 48

Page 33: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Text Data

2005 Congressional Record, which contains all speeches made by any member ofUS Congress during official deliberations. (Full text).

After stopword removal and stemming, compute all bigrams and trigrams in thedata. Millions in total.

Consider all English language daily newspapers available in either ProQuest orNewsLibrary for a total sample of 433 newspapers. (Access to phrase searches).

Consider only bigrams and trigrams that appear in not too few and not toomany headlines.

Text Mining Lecture 7 33 / 48

Page 34: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Text Data

2005 Congressional Record, which contains all speeches made by any member ofUS Congress during official deliberations. (Full text).

After stopword removal and stemming, compute all bigrams and trigrams in thedata. Millions in total.

Consider all English language daily newspapers available in either ProQuest orNewsLibrary for a total sample of 433 newspapers. (Access to phrase searches).

Consider only bigrams and trigrams that appear in not too few and not toomany headlines.

Text Mining Lecture 7 33 / 48

Page 35: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Identifying Partisan Phrases

Let xvD and xvR denote the total counts of term v among Democratic andRepublican speeches, respectively.

Let x−vD and x−vR denote the total counts of all terms besides term v .

One can then compute Pearson’s χ2 statistic for each term v as

χ2v =

(xvRx−vD − x−vRxvD)

(xvR + xvD)(xvR + x−vD)(x−vR + xvD)(x−vR + x−vD).

Identify the 500 bigrams and 500 trigrams with the highest test statistic.

Text Mining Lecture 7 34 / 48

Page 36: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Democratic Phrases

Text Mining Lecture 7 35 / 48

Page 37: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Republican Phrases

Text Mining Lecture 7 36 / 48

Page 38: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Constructing Newspaper Ideology

For each member of Congress i compute relative term frequenciesfiv = xiv/

∑v xiv ; for each newspaper n compute similar measure fnv .

1. For each term v regress fiv on the share of votes won by George W Bush ini ’s constituency in the 2004 Presidential election → slope and interceptparameters av and bv . Provides mapping from ideology to language.

2. For each newspaper n, regress fnv − av on bv , yielding slope estimateyn =

∑v bv (fnv − av )/

∑v b

2v . Measures how the partisanship of term v

affects language of newspaper n.

If fnv = av + bvyn + εnv with E[ εnv | bv ] = 0, then E[ yn ] = yn.

Use yn as a measure of n’s ideology in econometric work.

Text Mining Lecture 7 37 / 48

Page 39: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Taddy (2013)

“Multinomial Inverse Regression for Text Analysis” proposes a more formalstatistical model in the spirit of Gentzkow and Shapiro.

Let xy =∑

d :yd=y xd and Ny =∑

d :yd=y Nd .

Then we can model

xy ∼ MN(qy ,Ny ) where qy ,v =exp(av + bvy)∑v exp(av + bvy)

.

This is a generalized linear model with a (multinomial) logistic link function.

Text Mining Lecture 7 38 / 48

Page 40: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Gamma-Lasso

The prior distribution for the bv coefficients is Laplace with a term-specificGamma hyperprior:

p(bv , λv ) =λv2

exp(−λv |bv |)r s

Γ(s)λs−1v exp(−rλv ).

This is a departure from the typical lasso model in which all coefficients sharethe same λv . This allows for heterogeneous coefficient penalization, whichincreases robustness in the presence of many spurious regressors.

Taddy proposes a simple inference procedure that maximizes penalizedlikelihood (implemented in ‘textir’ package in R).

Text Mining Lecture 7 39 / 48

Page 41: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Sufficient Reduction Projection

There remains the issues of how to use the estimated model for classification.

Let zd = b · fd be the sufficient reduction projection for document d , wherefd = xd/Nd and b is the vector of estimated coefficients.

The sufficient reduction projection is sufficient for yd in the sense thatyd ⊥ xd ,Nd | zd .

This can be seen as an alternative dimensionality reduction technique (specificto the label of interest): all the information contained in the high-dimensionalfrequency counts relevant for predicting yd can be summarized in the SRprojection.

Text Mining Lecture 7 40 / 48

Page 42: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Classification

For classification, one can use the SR projections to build a forward regressionthat regresses yd on some function of the zd : OLS; logistic; with or withoutnon-linear terms in zd , etc.

To classify a document d in the test data:

1. Form zd given the estimated b coefficients in the training data.

2. Use the estimated forward regression to generate a predicted value for yd .

Taddy shows that MNIR outperforms other classifiers (LASSO, LDA, sLDA,etc.).

Text Mining Lecture 7 41 / 48

Page 43: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Taddy (2015)

Taddy (2015) constructs an algorithm for fitting MNIR with yd itself havingmultiple dimensions, i.e. yd = (yd,1, . . . , yd,M).

The SR projection idea extends to this environment in the sense thatyd,m ⊥ xd ,Nd | zd,m where zd,m = fd · bm.

Prediction application. Suppose some yd,m is only observed for a subset ofdocuments while yd,−m is observed for all documents. We can build a forwardregression in the training data that relates yd.m to yd,−m and zd,m which can beapplied to test data.

Treatment effect application. Suppose we want to estimate the treatment effectof yd,m on yd,1 but want to also control for xd , which is high dimensional.(Similar problem to Belloni et. al.) The SR result implies that yd,m, yd,1 ⊥ xdgiven zd,m, zd,1, Nd , and controls other than m. We can then perform a forwardregression with just the SR projections.

Text Mining Lecture 7 42 / 48

Page 44: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Supervised LDA (Blei and McAuliffe)

1. Draw θd independently for d = 1, . . . ,D from Dirichlet(α).

2. Each word wd,n in document d is generated from a two-step process:

2.1 Draw topic assignment zd,n from θd .

2.2 Draw wd,n from βzd,n .

3. Draw yd from N (zd · φ, σ2) where zd = (n1,d/Nd , . . . , nK ,d/Nd).

Essentially plain LDA with a linear regression linking topic allocations withobserved variables.

Text Mining Lecture 7 43 / 48

Page 45: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

sLDA Plate Diagram

DNd

α

θd

zd ,n yd

wd ,n

βk

K

φ, σ2

η

Text Mining Lecture 7 44 / 48

Page 46: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Joint Likelihood

Applying the factorization formula for Bayesian networks to sLDA yields(∏d

Pr [θd | α ]

)(∏k

Pr [βk | η ]

)×(∏

d

∏n

Pr [ zd,n | θd ]

)×(∏

d

∏n

Pr [wd,n | zd,n,B ]

)×(∏

d

Pr[yd∣∣ zd ,φ, σ2 ])

Text Mining Lecture 7 45 / 48

Page 47: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Inference

One can apply a stochastic EM algorithm. The sampling equation for the topicallocations becomes

Pr[zd,n = k

∣∣ z−(d,n),w, α, η ] ∝m−k,vd,n + η∑v m−k,v + ηV

(n−d,k + α

)exp[−(yd − φ · zd)2] ∝

m−k,vd,n + η∑v m−k,v + ηV

(n−d,k + α

)exp[2φk/Nd(yd − φ · z−d )− (φk/Nd)2].

Alternate between drawing samples for topic allocations (E-step), and updatingthe estimated coefficients φ through standard OLS (M-step).

Text Mining Lecture 7 46 / 48

Page 48: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Movie Review Example

Text Mining Lecture 7 47 / 48

Page 49: Text Mining for Economics and Finance Supervised Learning · Text Mining for Economics and Finance Supervised Learning StephenHansen Text Mining Lecture 7 1/48

Conclusion

We have seen numerous discriminative and generative models for supervisedlearning.

Text regression is essentially a particular instance of a more general model inmachine learning, which brings along the same qualifications and caveats.

Generative models take seriously the count nature of text in building a likelihoodfunction, and are recommended with there are relatively few documents.

A new possibility which you should explore is word embeddings, a neural networkapproach for representing vocabulary terms and documents in a latent space.

Text Mining Lecture 7 48 / 48