\documentclass{beamer}

%\usepackage[table]{xcolor}
\mode<presentation> {
  \usetheme{Boadilla}
%  \usetheme{Pittsburgh}
%\usefonttheme[2]{sans}
\renewcommand{\familydefault}{cmss}
%\usepackage{lmodern}
%\usepackage[T1]{fontenc}
%\usepackage{palatino}
%\usepackage{cmbright}
  \setbeamercovered{transparent}
\useinnertheme{rectangles}
}
%\usepackage{normalem}{ulem}
%\usepackage{colortbl, textcomp}
\setbeamercolor{normal text}{fg=black}
\setbeamercolor{structure}{fg= black}
\definecolor{trial}{cmyk}{1,0,0, 0}
\definecolor{trial2}{cmyk}{0.00,0,1, 0}
\definecolor{darkgreen}{rgb}{0,.4, 0.1}
\usepackage{array}
\beamertemplatesolidbackgroundcolor{white}  \setbeamercolor{alerted
text}{fg=red}

\setbeamertemplate{caption}[numbered]\newcounter{mylastframe}

%\usepackage{color}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usepackage{colortbl}
%\usepackage[usenames, dvipsnames]{color}
%\setbeamertemplate{caption}[numbered]\newcounter{mylastframe}c
%\newcolumntype{Y}{\columncolor[cmyk]{0, 0, 1, 0}\raggedright}
%\newcolumntype{C}{\columncolor[cmyk]{1, 0, 0, 0}\raggedright}
%\newcolumntype{G}{\columncolor[rgb]{0, 1, 0}\raggedright}
%\newcolumntype{R}{\columncolor[rgb]{1, 0, 0}\raggedright}

%\begin{beamerboxesrounded}[upper=uppercol,lower=lowercol,shadow=true]{Block}
%$A = B$.
%\end{beamerboxesrounded}}
\renewcommand{\familydefault}{cmss}
%\usepackage[all]{xy}

\usepackage{tikz}
\usepackage{lipsum}

 \newenvironment{changemargin}[3]{%
 \begin{list}{}{%
 \setlength{\topsep}{0pt}%
 \setlength{\leftmargin}{#1}%
 \setlength{\rightmargin}{#2}%
 \setlength{\topmargin}{#3}%
 \setlength{\listparindent}{\parindent}%
 \setlength{\itemindent}{\parindent}%
 \setlength{\parsep}{\parskip}%
 }%
\item[]}{\end{list}}
\usetikzlibrary{arrows}
%\usepackage{palatino}
%\usepackage{eulervm}
\usecolortheme{lily}
%\usepackage[latin1]{inputenc}
\title[Text as Data] % (optional, nur bei langen Titeln nötig)
{Text as Data}

\author{Justin Grimmer}
\institute[Stanford University]{Associate Professor\\Department of Political Science \\  Stanford University}
\vspace{0.3in}


\date{September 23rd, 2014}%[Big Data Workshop] 
%\date{\today}



\begin{document}
\begin{frame}
\titlepage
\end{frame}

%%Introduction: who is in the class
%%what are they working on 


\begin{frame}
\frametitle{Text and Political Science}

A pre-2000's view of text in social science
\begin{itemize}
\item[-] Social interaction often occurs in texts \pause 
\invisible<1>{\item[-] Social Scientists avoided studying texts/speech} \pause 
\invisible<1-2>{\item[-] Why?} \pause 
\begin{itemize}
\invisible<1-3>{\item[-] Hard to find} \pause 
\invisible<1-4>{\item[-] Time Consuming} \pause 
\invisible<1-5>{\item[-]  Not generalizable (each new data set...new coding scheme)} \pause 
\invisible<1-6>{\item[-]  Difficult to store/search} \pause 
\invisible<1-7>{\item[-] Idiosyncratic to coders/researcher} \pause 
\invisible<1-8>{\item[-] Statistical methods/algorithms, computationally intensive} 
\end{itemize}
\end{itemize}

\end{frame}




\begin{frame}

A post-2000's view of text in social science: 
\vspace{0.25in}

\invisible<1>{ Massive collections of texts are increasingly used as a data source in social science: }


\begin{itemize}
\invisible<1-2>{\item[-] Congressional speeches, press releases, newsletters, ...}
\invisible<1-3>{\item[-]  Facebook posts, tweets, emails, cell phone records, ...} 
\invisible<1-4>{\item[-]  Newspapers, magazines, news broadcasts, ...  } 
\invisible<1-5>{\item[-] Foreign news sources, treaties, sermons, fatwas, ...}
\end{itemize}

\pause \pause \pause \pause \pause 


\end{frame}

\begin{frame}
%
\footnotesize
Why? \pause
\begin{itemize}
\invisible<1>{\item[-] Massive increase in availability of unstructured text (10 minutes of worldwide email = 1 LOC )} \pause 
\invisible<1-2>{\item[-] Cheap storage: 1956: \$10,000 megabyte.  2014: $<<<<<$ \$0.0001 per megabyte  (Unless you're sending an SMS)  } \pause 
\invisible<1-3>{\item[-] Explosion in methods and programs to analyze texts} \pause 
\begin{itemize}
\invisible<1-4>{\item[-] Generalizable:  one method can be used across many methods and to unify collections of texts} \pause 
\invisible<1-5>{\item[-] Systematic: parameters/statistics demonstrate how models make coding decisions} \pause 
\invisible<1-6>{\item[-] Cheap: easily applied to many new collections of texts, computing power is inexpensive} \pause 
\end{itemize}
\invisible<1-7>{\item[-] \alert{Unchanged Demand}: Social life (politics, economic exchanges, social interactions) occurs in \alert{texts} } \pause 
\begin{itemize}
\invisible<1-8>{\item[-] Laws} \pause 
\invisible<1-9>{\item[-] Treaties } \pause
\invisible<1-10>{\item[-] News media} \pause
\invisible<1-11>{\item[-] Campaigns} \pause
\invisible<1-12>{\item[-] Political pundits} \pause
\invisible<1-13>{\item[-] Petitions } \pause
\invisible<1-14>{\item[-] Press Releases} \pause
\invisible<1-15>{\item[-] ...} 
\end{itemize}
\end{itemize}
\end{frame}


\begin{frame}
\frametitle{What Can Text Methods Do?}

Haystack metaphor:\pause  \invisible<1>{\alert{ Improve Reading}} \pause 
\begin{itemize}
\invisible<1-2>{\item[-]  Interpreting the meaning of a sentence or phrase $\leadsto$ Analyzing a straw of hay} \pause 
\begin{itemize}
\invisible<1-3>{\item[-]Humans: amazing (Straussian political theory, analysis of English poetry) 
\item[-] Computers: struggle } \pause 
\end{itemize}
\invisible<1-4>{\item[-] Comparing, Organizing, and Classifying Texts$\leadsto$ Organizing hay stack} \pause 
\begin{itemize}
\invisible<1-5>{\item[-] Humans: terrible.  Tiny active memories
\item[-] Computers: amazing$\leadsto$ largely what we'll discuss today} \pause 
\end{itemize}
\end{itemize}
\invisible<1-6>{What automated text methods don't do:} \pause 
\begin{itemize}
\invisible<1-7>{\item[-] Develop a comprehensive statistical model of language
\item[-] Replace the need to read 
\item[-] Develop a single tool + evaluation for all tasks } 
\end{itemize}
\end{frame}


\begin{frame}
\frametitle{Texts are Deceptively Complex} 


{\tt We've got some difficult days ahead.  But it doesn't matter with me now. Because I've been to the mountaintop. And I don't mind. Like anybody, I would like to live a long life. Longevity has its place. But I'm not concerned about that now. } 

\pause 

\begin{itemize}
\invisible<1>{\item[-] Who is the {\tt I} ?} \pause 
\invisible<1-2>{\item[-] Who is the {\tt We}? } \pause 
\invisible<1-3>{\item[-] What is the {\tt mountaintop} (literal?)} \pause 
\end{itemize}

\invisible<1-4>{Texts$\leadsto$ high dimensional, not self contained}


\end{frame}


\begin{frame}
\frametitle{Texts are Surprisingly Simple}

(Lamar Alexander (R-TN) Feb 10, 2005)
\begin{table}
\begin{tabular}{ll}
\hline
 Word & No. Times Used in Press Release \\
 \hline
 department &     12\\
  grant  &      9 \\
  program &   7 \\
  firefight &  7 \\
  secure  &    5 \\
  homeland  &  4 \\
  fund   &    3 \\
 award  &    2 \\
 safety  &     2 \\
 service &    2 \\
 AFGP   &    2 \\
 support &   2 \\
equip  &    2 \\
applaud  &  2\\ 
 assist  &   2\\ 
prepared &  2 \\
\hline  
\end{tabular}
\end{table}



\end{frame}




\begin{frame}
\frametitle{Texts are Surprisingly Simple (?)}

{\tt US  Senators Bill Frist  (R-TN)  and Lamar Alexander (R-TN) today applauded the U S  Department of Homeland Security for awarding a \$8,190 grant to the Tracy City Volunteer Fire Department under the 2004 Assistance to Firefighters Grant Program's  (\alert{AFGP})  FirePrevention and Safety Program...}


\end{frame}



\begin{frame}
\frametitle{Not just for ``big data" }

\pause 

\invisible<1>{Manually develop categorization scheme for partitioning small (100) set of documents} \pause

  \begin{itemize}
\invisible<1-2>{ \item[-] Bell$(n) = $ number of ways of partitioning $n$ objects}
    \pause
   \invisible<1-3>{ \item[-] Bell$(2)=2$ (AB, A B)}\pause
  \invisible<1-4>{ \item[-] Bell$(3)=5$ (ABC, AB C, A BC, AC B, A B
   C)} \pause
   \invisible<1-5>{ \item[-] Bell$(5)=52$}\pause
   \invisible<1-6>{ \item[-] Bell(100)}\pause \invisible<1-7>{$\approx 4.75 \times
   10^{115}$ partitions} \pause
   \invisible<1-8>{\item[-] \alert{Big Number}:}\pause  \\
   \invisible<1-9>{7 Billion RAs} \pause  \\
   \invisible<1-10>{ Impossibly Fast (enumerate one clustering every millisecond)} \pause  \\
   \invisible<1-11>{ Working around the clock (24/7/365)}\pause  \\
        \invisible<1-12>{$\approx 1.54\times 10^{84} \times $} \invisible<1-13>{($14,000,000,000$)} \invisible<1-14>{years}
        \pause \pause\pause 
    \end{itemize}

\invisible<1-15>{\alert{Automated methods can help with even small problems}}

\end{frame}


\begin{frame}
\frametitle{What We'll Do:}


\alert{Statistical} and \alert{Computational} tools for working with texts

\end{frame}


\begin{frame}
\frametitle{Prerequisites}

Statistics:\pause 
\begin{itemize}
\invisible<1>{\item[-] Probability Theory/Univariate Inference (Old 350a)} \pause 
\invisible<1-2>{\item[-] Linear Regression (Old 350b)} \pause 
\invisible<1-3>{\item[-] (Ideally) Model Based Inference (Old 350c) 
\item[-] Willingness to learn new statistical models(!!)} \pause 
\end{itemize}

\invisible<1-4>{Computational:}\pause 

\begin{itemize}
\invisible<1-5>{\item[-] Familiarity with {\tt R} programming language} \pause 
\invisible<1-6>{\item[-] Experience with:} \pause 
\begin{itemize}
\invisible<1-7>{\item[-] Programming functions} \pause 
\invisible<1-8>{\item[-] Writing for loops} \pause 
\invisible<1-9>{\item[-] Using standard {\tt R} packages} \pause 
\invisible<1-10>{\item[-] Creating plots } \pause 
\end{itemize}
\invisible<1-11>{\item[-] Willingness to learn {\tt Python}} 
\end{itemize}



\end{frame}



\begin{frame}
\frametitle{Course Staff}

\begin{itemize}
\item[] \textbf{Me:} Justin Grimmer
\item[] \textbf{Office:} Encina West 414 (last door on left)
\item[] \textbf{Office Hours:} I'm usually in during business hours. Set up an appointment if you must meet with me
\item[] \textbf{Contact:} Gchat: justin.grimmer@gmail.com; Cell phone (617) 710-6803
\end{itemize}

\pause 

\invisible<1>{\alert{Programming TA}

\begin{itemize}
\item[] \textbf{Python/R/Programming}: Frances Zlotnick
\item[] \textbf{Office/Programming Section}: Encina Hall West, Room 417
\item[] \textbf{Office Hours}: 230-430 and by appointment
\item[] \textbf{Contact}: Zlotnick@stanford.edu
\end{itemize}
}


\end{frame}


\begin{frame}
\frametitle{Evaluation}

\alert{Homework}:

\begin{itemize}
\item[-] Weekly homework assignments
\item[-] Computational Component
\begin{itemize}
\item[-] Preprocessing texts
\item[-] Moving from texts$\leadsto$ data
\end{itemize}
\item[-] Statistical component
\begin{itemize}
\item[-] Applying algorithms, statistics to analyze texts
\end{itemize}
\end{itemize}

Our workspace
\begin{itemize}
\item[1)] {\tt RStudio} $\leadsto$ lowers startup costs of ${\tt R}$ 
\item[2)] {\tt R Markdown} $\leadsto$ integrates write up and code
\item[3)] {\tt Enthought Python Distribution} (academic license) $\leadsto$ python distribution that ships with most packages
\end{itemize}

Writeup can also occur in \LaTeX\ 


\end{frame}


\begin{frame}
\frametitle{Evaluation}

\alert{Homework}:

\begin{itemize}
\item[1)] Will be distributed on Tuesday
\item[2)] Due on Tuesday, 5pm 
\item[3)] {\tt Email:} Frannie and me
\end{itemize}

\alert{Collaborate}!
\begin{itemize}
\item[1)] Work together in groups
\item[2)] Individual write ups
\end{itemize}

\end{frame}


\begin{frame}
\frametitle{Evaluation}

\alert{Final Project}: \pause 

\begin{itemize}
\invisible<1>{\item[1)] An original research paper} \pause 
\begin{itemize}
\invisible<1-2>{\item[-] Part of a dissertation
\item[-] Field paper
\item[-] Paper for publication} \pause 
\end{itemize}
\invisible<1-3>{\item[2)] Contributing to ongoing research project} \pause 
\begin{itemize}
\invisible<1-4>{\item[1)] Michael Crespin (U of Oklahoma, Congressional Scholar): Categorizing floor speeches$\leadsto$ citations} \pause 
\invisible<1-5>{\item[2)] Alison McQueen (Stanford): Characterizing Hobbes' context$\leadsto$ political theory} \pause 
\invisible<1-6>{\item[3)] Robert Gulotty (Stanford$\leadsto$ U of Chicago) and Judith Goldstein (Stanford) Examine trade speeches in the 19th century Congress} \pause 
\end{itemize}
\end{itemize}
\invisible<1-7>{\alert{Talk to me about your ideas!}}


\end{frame}


\begin{frame}
\frametitle{Evaluation}

\alert{Final Project:} \pause 

\begin{itemize}
\invisible<1>{\item[1)] Poster Session} \pause 
\begin{itemize}
\invisible<1-2>{\item[-] Opportunity to receive feedback on your projects} \pause 
\end{itemize}
\invisible<1-3>{\item[2)] Final paper} \pause 
\begin{itemize}
\invisible<1-4>{\item[-] Research length (25-30 pages)} \pause 
\invisible<1-5>{\item[-] Format appropriate for your field} \pause 
\end{itemize}
\invisible<1-6>{\item[-] Collaborative$\leadsto$ work in two-person teams} \pause 
\invisible<1-7>{\item[-] We will not adjudicate disputes (frankly, unimportant)} 
\end{itemize}



\end{frame}



\begin{frame}
\frametitle{Evaluation}


\alert{Participation:} \\ \pause 

\begin{itemize}
\invisible<1>{\item[-] Attend class} \pause 
\invisible<1-2>{\item[-] Ask questions (!!!)} \pause 
\invisible<1-3>{\item[-] Enroll in Piazza course site} \pause 
\begin{itemize}
\invisible<1-4>{\item[-] piazza.com/stanford/fall2014/polsci452} \pause 
\invisible<1-5>{\item[-] I'll post lecture slides there and readings (ensures auditors/guests have access)} \pause 
\invisible<1-6>{\item[-] Post Questions/Answer Questions/Course Announcements} 
\end{itemize}
\end{itemize}




\end{frame}






\begin{frame}
\frametitle{Plan for the Course}

\alert{Computational} and \alert{Statistical} tools \pause 

\begin{itemize}
\invisible<1>{\item[-] Acquiring and Preprocessing Text data} \pause 
\begin{itemize}
\invisible<1-2>{\item[-] Basics of webscraping
\item[-] Regular expressions
\item[-] Text $\leadsto$ Document Term Matrices} \pause 
\end{itemize}
\invisible<1-3>{\item[-] Dictionary Methods} \pause 
\begin{itemize}
\invisible<1-4>{\item[-] \alert{Assume}$\leadsto$ known categories
\item[-] \alert{Assume}$\leadsto$ known how words relate to groups
\item[-] Measure prevalence of categories} \pause 
\end{itemize}
\invisible<1-5>{\item[-] Discriminating Words} \pause 
\begin{itemize}
\invisible<1-6>{\item[-] \alert{Assume}$\leadsto$ known categories
\item[-] Statistical methods/algorithms to measure word discrimination} 
\end{itemize}
\end{itemize}


\end{frame}


\begin{frame}
\frametitle{Plan for the Course}
\begin{itemize}
\item[-] Geometry of Texts \pause 
\begin{itemize}
\invisible<1>{\item[-] \alert{Assume}$\leadsto$ relationship between texts
\item[-] Statistical methods/algorithms to \alert{project} (scale) texts in lower dimension} \pause 
\end{itemize}
\invisible<1-2>{\item[-] Clustering Methods (Unknown Groups, Unknown relationship of document characteristics to those groups)} \pause 
\begin{itemize}
\invisible<1-3>{\item[-] Fully Automated Clustering Methods} \pause 
\begin{itemize}
\invisible<1-4>{\item[-] \alert{Assume}$\leadsto$ Known distance
\item[-] \alert{Assume}$\leadsto$ Known objective
\item[-] \alert{Assume}$\leadsto$ Known method for optimization
\item[-] Statistical model to partition documents} \pause 
\end{itemize}
\invisible<1-5>{\item[-] Computer Assisted Clustering} \pause 
\begin{itemize}
\invisible<1-6>{\item[-] \alert{Assume}$\leadsto$ Method for organizing clusters
\item[-] Method for generating, organizing partitions for discovery} 
\end{itemize}
\end{itemize}
\end{itemize}

\end{frame}


\begin{frame}
\frametitle{Plan for the Course}

\begin{itemize}
\item[-] ``Vanilla" Latent Dirichlet Allocation (Topic Models) \pause 
\begin{itemize}
\invisible<1>{\item[-] Unknown categories
\item[-] \alert{Assume}$\leadsto$ documents are \alert{mixture} of topics
\item[-] Statistical method for measuring topics and document attention to topics} \pause 
\end{itemize}
\invisible<1-2>{\item[-] Structural Topic Models} \pause 
\begin{itemize}
\invisible<1-3>{\item[-] \alert{Assume}$\leadsto$ condition on characteristics 
\item[-] Measure topics, prevalence of topics across characteristics, distinctiveness of language} \pause 
\end{itemize}
\invisible<1-4>{\item[-] Supervised Methods} \pause 
\begin{itemize}
\invisible<1-5>{\item[-] \alert{Assume}$\leadsto$ Known categories (training documents)
\item[-] Statistical model: learn relationship between labels, words categorize remaining documents
\item[-] \alert{Ensembles of methods}} \pause 
\end{itemize}
\invisible<1-6>{\item[-] Ideological Scaling}\pause 
\begin{itemize}
\invisible<1-7>{\item[-] Application of methods, measuring political positions
\item[-] Supervised$\leadsto$ Wordscores
\item[-] Unsupervised $\leadsto$ Item Response Theory (IRT) Models} 
\end{itemize}
\end{itemize}

\end{frame}


\begin{frame}
\frametitle{Four Principles of Automated Text Analysis}

Principle 1: All Quantitative Models of Language are Wrong---But Some are Useful \pause 

\begin{itemize}
\invisible<1>{\item[-] Data generation process for text$\leadsto$ unknown} \pause 
\invisible<1-2>{\item[-] Complexity of language:} \pause 
\begin{itemize}
\invisible<1-3>{\item[-] Time flies like an arrow}\pause\invisible<1-4>{, fruit flies like a banana} \pause 
\invisible<1-5>{\item[-] Make peace, not war}\pause\invisible<1-6>{ , Make war not peace} \pause
\invisible<1-7>{\item[-] ``Years from now, you'll look back and you'll say that this was the moment, this was the place where America remembered what it means to hope. " } \pause 
\end{itemize}
\invisible<1-8>{\item[-] Models \alert{necessarily} fail to capture language$\leadsto$ useful for specific tasks}\pause
\invisible<1-9>{\item[-] \alert{Validation}$\leadsto$ demonstrate methods perform task } 
\end{itemize}




\end{frame}


\begin{frame}
\frametitle{Four Principles of Automated Text Analysis}

Principle 2: Quantitative Methods Augment Humans, Not Replace Them \pause 

\begin{itemize}
\invisible<1>{\item[-] \alert{Computer-Assisted} Reading} \pause 
\invisible<1-2>{\item[-] Quantitative methods organize, direct, and suggest} \pause 
\invisible<1-3>{\item[-] Humans: read and interpret } 
\end{itemize}


\end{frame}

\begin{frame}
\frametitle{Four Principles of Automated Text Analysis}

Principle 3: There is no Globally Best Method for Automated Text Analysis \pause 

\begin{itemize}
\invisible<1>{\item[-] Supervised methods$\leadsto$ known categories} \pause 
\invisible<1-2>{\item[-] Unsupervised methods$\leadsto$ discover categories} \pause 
\invisible<1-3>{\item[-] Debate$\leadsto$ acknowledge differences, resolved} 
\end{itemize}


\end{frame}


\begin{frame}
\frametitle{Four Principles of Automated Text Analysis}

Principle 4: Validate, Validate, Validate \pause 

\begin{itemize}
\invisible<1>{\item[-] Quantitative methods$\leadsto$ variable performance across tasks} \pause 
\invisible<1-2>{\item[-] \alert{Few theorems to guarantee performance}} \pause 
\invisible<1-3>{\item[-] Apply methods $\leadsto$ validate} \pause 
\invisible<1-4>{\item[-] \alert{Avoid}: blind application of methods} 
\end{itemize}


\end{frame}


\begin{frame}
\frametitle{Going Forward}


\begin{itemize}
\item[1)] Assignment distributed tonight
\item[2)] Install {\tt R} and {\tt Python}
\item[3)] Thursday: The Statistical/Computational Background for Text as Data!
\end{itemize}




\end{frame}




\end{document}



\begin{frame}
\frametitle{Conclusion}

Today: Introduction and where to get text\\
Next week: how to represent text quantitatively



\end{frame}




\end{document}
