38
Topic models for corpora and for graphs

Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Topic  models  for  corpora  and  for  graphs

Page 2: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Announcement – [c. Jan 27]!•  Paper presentations: 3/3 and 3/5!•  Projects: !

•  see “project info” on wiki!•  1-2 page writeup of your idea: 2/17!•  Response to my feedback: 3/5!•  Option for 605 students to collaborate:!

•  Proposals will be posted; proposers can advertise slots for collaborators, who can be 605 students (1-2 per project max)!

•  “Pay”: 1 less assignment, no exam!

•  http://curtis.ml.cmu.edu/w/courses/index.php/Machine_Learning_with_Large_Datasets_10-605_in_Spring_2015#Grading_Policies updated!

Page 3: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Announcement!•  Quiz:

https://qna-app.appspot.com/view.html?aglzfnFuYS1hcHByGQsSDFF1ZXN0aW9uTGlzdBiAgICAyvPFCgw !

Page 4: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Motivation

•  Social  graphs  seem  to  have   –  some  aspects  of  randomness

•  small  diameter,  giant  connected  components,.. –  some  structure

•  homophily,  scale-­‐free  degree  dist?

Page 5: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

More  terms

•  “Stochastic  block  model”,  aka  “Block-­‐stochastic  matrix”: – Draw  ni  nodes  in  block  i – With  probability  pij,  connect  pairs  (u,v)  where  u  is  in  block  i,  v  is  in  block  j

–  Special,  simple  case:  pii=qi,  and  pij=s  for  all  i≠j

•  Question:  can  you  Jit  this  model  to  a  graph? –  Jind  each  pij  and  latent  nodeàblock  mapping

Page 6: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Not? football

Page 7: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Not? books

Page 8: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Outline

•  Stochastic  block  models  &  inference  question •  Review  of  text  models

–  Mixture  of  multinomials  &  EM –  LDA  and  Gibbs  (or  variational  EM)

•  Block  models  and  inference •  Mixed-­‐membership  block  models •  Multinomial  block  models  and  inference  w/  Gibbs

Page 9: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Review  –  supervised  Naïve  Bayes •  Naïve  Bayes  Model:  Compact  representation

C

W1 W2 W3 ….. WN

C

W

N

π

M

M

π

β

β

Page 10: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Review  –  supervised  Naïve  Bayes

•  Multinomial  Naïve  Bayes

C

W1 W2 W3 ….. WN

π

M

β

•  For each document d = 1,!, M

•  Generate Cd ~ Mult( | π)

•  For each position n = 1,!, Nd

•  Generate wn ~ Mult( |β,Cd)

Page 11: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Review  –  supervised  Naïve  Bayes

•  Multinomial  naïve  Bayes:  Learning – Maximize  the  log-­‐likelihood  of  observed  variables  w.r.t.  the  parameters:

•  Convex  function:  global  optimum •  Solution:  

Page 12: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Review  –  unsupervised  Naïve  Bayes

•  Mixture  model:  unsupervised  naïve  Bayes  model

C

W

NM

π

β

•  Joint probability of words and classes:

•  But classes are not visible: Z

Page 13: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

LDA

Page 14: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Review  -­‐  LDA

•  Motivation

w

M

θ

N

Assumptions: 1) documents are i.i.d 2) within a document, words are i.i.d. (bag of words)

• For each document d = 1,!,M

•  Generate θd ~ D1(…)

•  For each word n = 1,!, Nd

• generate wn ~ D2( | θdn)

Now pick your favorite distributions for D1, D2

Page 15: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

•  Latent  Dirichlet  Allocation

z

w

β

M

θ

N

α •  For each document d = 1,!,M

•  Generate θd ~ Dir( | α)

•  For each position n = 1,!, Nd

•  generate zn ~ Mult( | θd)

•  generate wn ~ Mult( | βzn)

“Mixed membership” kk

jjk nn

nnnnjz

αα

αα

+++

+==

...),...,,|Pr(

11,21

K

Page 16: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

•  vs  Naïve  Bayes…

z

w

β

M

θ

N

α

K

Page 17: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

•  LDA’s  view  of  a  document

Page 18: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

•  LDA  topics

Page 19: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Review  -­‐  LDA

•  Latent  Dirichlet  Allocation – Parameter  learning:

• Variational  EM –  Numerical  approximation  using  lower-­‐bounds –  Results  in  biased  solutions –  Convergence  has  numerical  guarantees

• Gibbs  Sampling   –  Stochastic  simulation –  unbiased  solutions –  Stochastic  convergence

Page 20: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Review  -­‐  LDA

•  Gibbs  sampling –  Applicable  when  joint  distribution  is  hard  to  evaluate  but  conditional  distribution  is  known

–  Sequence  of  samples  comprises  a  Markov  Chain –  Stationary  distribution  of  the  chain  is  the  joint  distribution

Key capability: estimate distribution of one latent variables given the other latent variables and observed variables.

Page 21: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Why  does  Gibbs  sampling  work?

• What’s  the  Jixed  point? –  Stationary  distribution  of  the  chain  is  the  joint  distribution

• When  will  it  converge  (in  the  limit)? – Graph  deJined  by  the  chain  is  connected

•  How  long  will  it  take  to  converge? – Depends  on  second  eigenvector  of  that  graph

Page 22: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…
Page 23: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Called “collapsed Gibbs sampling” since you’ve marginalized away some variables

Fr: Parameter estimation for text analysis - Gregor Heinrich

Page 24: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Review  -­‐  LDA

•  Latent  Dirichlet  Allocation

z

w

β

M

θ

N

α •  Randomly initialize each zm,n

•  Repeat for t=1,….

•  For each doc m, word n

•  Find Pr(zmn=k|other z’s)

•  Sample zmn according to that distr.

“Mixed membership”

Page 25: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Outline

•  Stochastic  block  models  &  inference  question •  Review  of  text  models

–  Mixture  of  multinomials  &  EM –  LDA  and  Gibbs  (or  variational  EM)

•  Block  models  and  inference •  Mixed-­‐membership  block  models •  Multinomial  block  models  and  inference  w/  Gibbs •  Beastiary  of  other  probabilistic  graph  models

–  Latent-­‐space  models,  exchangeable  graphs,  p1,  ERGM

Page 26: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Review  -­‐  LDA

•  Motivation

w

M

θ

N

Assumptions: 1) documents are i.i.d 2) within a document, words are i.i.d. (bag of words)

• For each document d = 1,!,M

•  Generate θd ~ D1(…)

•  For each word n = 1,!, Nd

• generate wn ~ D2( | θdn)

Docs and words are exchangeable.

Page 27: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Stochastic  Block  models:  �assume  1)  nodes  w/in  a  block  z  and  �2)  edges  between  blocks  zp,zq  are  exchangeable

zp zq

apq

N2

zp  

N

α

p  

β

Page 28: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Stochastic  Block  models:  �assume  1)  nodes  w/in  a  block  z  and  �2)  edges  between  blocks  zp,zq  are  exchangeable

zp zq

apq

N2

zp  

N

α

p  

β Gibbs sampling:

•  Randomly initialize zp for each node p.

•  For t = 1…

•  For each node p

•  Compute zp given other z’s

•  Sample zp

See: Snijders & Nowicki, 1997, Estimation and Prediction for Stochastic Blockmodels for Groups with Latent Graph Structure

Page 29: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Mixed  Membership  Stochastic  Block  models�

θp   θq  

zp!. z.!q

apq

N2

θp  

N

α

p  

β

Airoldi et al, JMLR 2008

Page 30: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Parkkinen  et  al  paper

Page 31: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Another  mixed  membership  block  model

Page 32: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Another  mixed  membership  block  model z=(zi,zj) is a pair of block ids

nz = #pairs z

qz1,i = #links to i from block z1

qz1,. = #outlinks in block z1

δ  =  indicator  for  diagonal  

M  =  #nodes  

Page 33: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Another  mixed  membership  block  model

Page 34: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Experiments  

Balasubramanyan, Lin, Cohen, NIPS w/s 2010

+ lots of synthetic data

Page 35: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…
Page 36: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…
Page 37: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Experiments  

Balasubramanyan, Lin, Cohen, NIPS w/s 2010

Page 38: Topic&models&for&corpora&and&for&graphswcohen/10-605/topic-models-intro.pdf• Latent&Dirichlet&Allocation z w β M θ N α • Randomly initialize each z m,n • Repeat for t=1,…

Experiments  

Balasubramanyan, Lin, Cohen, NIPS w/s 2010