Efficient Inference for Mul0nomial Mixed Membership Models - - PowerPoint PPT Presentation

efficient inference for mul0nomial mixed membership models
SMART_READER_LITE
LIVE PREVIEW

Efficient Inference for Mul0nomial Mixed Membership Models - - PowerPoint PPT Presentation

Efficient Inference for Mul0nomial Mixed Membership Models David Mimno UMass, Amherst Summary How fast can we make Gibbs sampling? How liGle memory can we use? Goal:


slide-1
SLIDE 1

Efficient ¡Inference ¡for Mul0nomial ¡Mixed ¡Membership Models

David ¡Mimno UMass, ¡Amherst

slide-2
SLIDE 2

Summary

  • How ¡fast ¡can ¡we ¡make ¡Gibbs ¡sampling?
  • How ¡liGle ¡memory ¡can ¡we ¡use?

Goal: ¡small ¡collec0ons ¡should ¡be ¡fast, large ¡collec0ons ¡should ¡be ¡possible

slide-3
SLIDE 3

Big ¡collec0ons! ¡ ¡Lots ¡of ¡topics!

  • 1000+ ¡topics
slide-4
SLIDE 4

Why ¡not ¡just ¡parallelize?

Big ¡computa0on Lots ¡of ¡smaller computa0ons

slide-5
SLIDE 5

Why ¡not ¡just ¡parallelize?

Small ¡computa0on Lots ¡of ¡really ¡small computa0ons

Be ¡smart, ¡then ¡parallelize

slide-6
SLIDE 6

Gibbs ¡Sampling ¡for ¡Topic ¡Models

dog cat feline hound dog dog horse equine 2 2 1 1 Doc ¡A Doc ¡B

slide-7
SLIDE 7

Document-­‑topic ¡sta0s0cs

dog cat feline hound dog dog horse equine

Nt|d

2 2 B 2 2 A 2 1

Doc ¡A Doc ¡B 2 2 1 1 docs topics

slide-8
SLIDE 8

Topic-­‑word ¡sta0s0cs

1 1 2 1 1 1 3 feline hound horse cat dog

Nw|t

dog cat feline hound dog dog horse equine Doc ¡A Doc ¡B 2 2 1 1 Word ¡types Topics

slide-9
SLIDE 9

score(t ¡| ¡Nt|d, ¡Nw|t) ¡=

slide-10
SLIDE 10

For ¡each ¡token,

dog cat feline hound dog dog horse equine Doc ¡A Doc ¡B

for ¡each ¡possible ¡topic ¡[0, ¡1, ¡2],

2 2 1 1

slide-11
SLIDE 11

For ¡each ¡token,

dog cat feline hound dog dog horse equine Doc ¡A Doc ¡B

for ¡each ¡possible ¡topic ¡[0, ¡1, ¡2], ¡ ¡compute

2 2 1 1

score(0 ¡| ¡N0|A, ¡Ndog|0)

slide-12
SLIDE 12

For ¡each ¡token,

dog cat feline hound dog dog horse equine Doc ¡A Doc ¡B

for ¡each ¡possible ¡topic ¡[0, ¡1, ¡2], ¡ ¡compute

2 2 1 1

score(0 ¡| ¡N0|A, ¡Ndog|0) score(1 ¡| ¡N1|A, ¡Ndog|1)

slide-13
SLIDE 13

For ¡each ¡token,

dog cat feline hound dog dog horse equine Doc ¡A Doc ¡B

for ¡each ¡possible ¡topic ¡[0, ¡1, ¡2], ¡ ¡compute

2 2 1 1

score(0 ¡| ¡N0|A, ¡Ndog|0) score(1 ¡| ¡N1|A, ¡Ndog|1) score(2 ¡| ¡N2|A, ¡Ndog|2)

slide-14
SLIDE 14

Add ¡up ¡the ¡scores

dog cat feline hound dog dog horse equine Doc ¡A Doc ¡B 2 2 1 1

score(0 ¡| ¡N0|A, ¡Ndog|0) + score(1 ¡| ¡N1|A, ¡Ndog|1) + score(2 ¡| ¡N2|A, ¡Ndog|2) Z ¡= ¡

slide-15
SLIDE 15

Sample ¡a ¡new ¡topic

dog cat feline hound dog dog horse equine Doc ¡A Doc ¡B u ¡= ¡rand() ¡* ¡Z 2 2 1 1 Sample Return ¡t=0

slide-16
SLIDE 16

For ¡each ¡token,

dog cat feline hound dog dog horse equine Doc ¡A Doc ¡B

for ¡each ¡possible ¡topic ¡[0, ¡1, ¡2],

2 1 1

slide-17
SLIDE 17

Summary ¡so ¡far

  • For ¡every ¡token,

– For ¡each ¡possible ¡topic ¡t ¡calculate ¡score(t ¡| ¡…)

  • Add ¡up ¡scores ¡to ¡normalizing ¡constant

Z ¡= ¡∑t ¡score(t)

  • Sample ¡u ¡~ ¡U(0, ¡Z) ¡and ¡return ¡the

corresponding ¡topic ¡t.

Performance ¡is ¡dominated ¡by ¡calcula0on ¡of ¡Z

slide-18
SLIDE 18

The ¡normalizing ¡constant

slide-19
SLIDE 19

The ¡normalizing ¡constant

slide-20
SLIDE 20

The ¡normalizing ¡constant

slide-21
SLIDE 21

The ¡normalizing ¡constant

slide-22
SLIDE 22

The ¡normalizing ¡constant

Token-­‑specific Document-­‑specific Independent

  • f ¡word ¡and

document

slide-23
SLIDE 23

The ¡normalizing ¡constant

slide-24
SLIDE 24

Sta0s0cs ¡are ¡sparse

  • Nt|d ¡: ¡10-­‑20%
  • mostly ¡zeros
  • Nw|t ¡: ¡< ¡5%
  • almost ¡all ¡zeros
slide-25
SLIDE 25

Add ¡up ¡the ¡scores

dog cat feline hound dog dog horse equine Doc ¡A Doc ¡B 2 2 1 1

Z

slide-26
SLIDE 26

Add ¡up ¡the ¡scores, ¡in ¡blocks

dog cat feline hound dog dog horse equine Doc ¡A Doc ¡B t ¡: ¡Nw|t ¡> ¡0 t ¡: ¡Nt|d ¡> ¡0 ∀ t 2 2 1 1

slide-27
SLIDE 27

Add ¡up ¡the ¡scores, ¡in ¡blocks

dog cat feline hound dog dog horse equine Doc ¡A Doc ¡B Zword-­‑specific Zdocument-­‑specific Zsmoothing 2 2 1 1

slide-28
SLIDE 28

Add ¡up ¡some ¡blocks, ¡cache ¡others

dog cat feline hound dog dog horse equine Doc ¡A Doc ¡B The ¡size ¡of ¡this ¡block ¡is ¡almost ¡constant Recalculate ¡the ¡word-­‑specific block ¡for ¡every ¡token change ¡at ¡most ¡two from ¡each

  • f ¡these

2 2 1 1

slide-29
SLIDE 29

Add ¡up ¡some ¡blocks, ¡cache ¡others

dog cat feline hound dog dog horse equine Doc ¡A Doc ¡B 2 2 1 1

slide-30
SLIDE 30

Add ¡up ¡some ¡blocks, ¡cache ¡others

dog cat feline hound dog dog horse equine Doc ¡A Doc ¡B 2 2 1 1

slide-31
SLIDE 31

Add ¡up ¡some ¡blocks, ¡cache ¡others

dog cat feline hound dog dog horse equine Doc ¡A Doc ¡B Worst ¡case: ¡we ¡might ¡have ¡to ¡loop ¡over ¡all ¡topics 2 2 1 1

slide-32
SLIDE 32

Summary ¡so ¡far

  • We ¡can ¡store ¡most ¡of ¡the ¡computa0on ¡to

calculate ¡Z ¡from ¡token ¡to ¡token.

  • We ¡can ¡sample ¡exactly ¡from ¡the ¡same

distribu0on, ¡with ¡a ¡new ¡map ¡from ¡(0, ¡Z) ¡to topics. Fast ¡itera0on ¡over ¡{t ¡: ¡Nw|t ¡> ¡0} ¡is ¡cri.cal

slide-33
SLIDE 33

Topic-­‑word ¡sta0s0cs

1 1 2 1 1 1 3 feline hound horse cat dog

Nw|t

dog cat feline hound dog dog horse equine Doc ¡A Doc ¡B 2 2 1 1 Word ¡types Topics

slide-34
SLIDE 34

Word-­‑topic ¡sta0s0cs ¡transpose

Nw|t

dog cat feline hound dog dog horse equine Doc ¡A Doc ¡B

1 feline 1 hound 1 horse 1 cat 3 dog 2 1

2 2 1 1 Word ¡types Topics

slide-35
SLIDE 35

Representa0ons ¡of ¡Nw|t: ¡arrays

int[] typeTopicCounts = new int[T]; Topics ¡index ¡array ¡posi0ons.

2 1 3 3 1

Most ¡entries ¡are ¡zero.

slide-36
SLIDE 36

Integer ¡HashMaps

Faster, ¡but…

  • Complicated
  • Not ¡much ¡memory ¡improvement
  • Adds ¡dependencies ¡on ¡external

libraries ¡(trove, ¡fastu0l). TIntIntHashMap typeTopicCounts = new TIntIntHashMap(); (giant ¡black ¡box)

1 3 3

slide-37
SLIDE 37

Encoded ¡integer ¡arrays

int[] typeTopicCounts = new int[Nw]

(1, ¡3) (3, ¡0) 1

1 3 int32 count ¡bits topic ¡bits index ¡is ¡meaningless all ¡informa0on ¡is ¡in ¡array ¡values

Huge ¡speedup, ¡2x ¡faster ¡than ¡HashMaps

slide-38
SLIDE 38

Example

1 96 … … … … 9 24 3 “dog” … 83 15 8

100 ¡topics, ¡so ¡4x100 ¡bytes ¡= ¡400

slide-39
SLIDE 39

Example

1 96 … … … … 9 24 3 “dog” … 83 15 8 (1, ¡96) (3, ¡8) (9, ¡83) (24, ¡15) 3 2 1

4 ¡non-­‑zero ¡topics, ¡4 ¡x ¡4 ¡bytes ¡= ¡16!

slide-40
SLIDE 40

Example

1 96 … … … … 9 24 3 “dog” … 83 15 8 1<<7 ¡+ ¡96 3<<7 ¡+ ¡8 9<<7 ¡+ ¡83 24<<7 ¡+ ¡15 3 2 1

100 ¡topics, ¡27 ¡> ¡100

slide-41
SLIDE 41

Basic ¡Opera0ons: ¡itera0on

(1, ¡96) (3, ¡8) (9, ¡83) (24, ¡15) 3 2 1

t = v & 0x1111111 Nw|t = v >> 7

slide-42
SLIDE 42

Basic ¡Opera0ons: ¡itera0on

(1, ¡96) (3, ¡8) (9, ¡83) (24, ¡15) 3 2 1

Zword-­‑specific ¡=

slide-43
SLIDE 43

Basic ¡Opera0ons: ¡itera0on

(1, ¡96) (3, ¡8) (9, ¡83) (24, ¡15) 3 2 1

Zword-­‑specific ¡=

slide-44
SLIDE 44

Basic ¡Opera0ons: ¡itera0on

(1, ¡96) (3, ¡8) (9, ¡83) (24, ¡15) 3 2 1

Zword-­‑specific ¡=

slide-45
SLIDE 45

Basic ¡Opera0ons: ¡increment

(1, ¡96) (3, ¡8) (9, ¡83) (24, ¡15) 3 2 1

Nw|83++

slide-46
SLIDE 46

Basic ¡Opera0ons: ¡increment

(1, ¡96) (3, ¡8) (9, ¡83) (24, ¡15) 3 2 1

Nw|83++

v = (9+1)<<7 + 83

slide-47
SLIDE 47

Basic ¡Opera0ons: ¡increment

(1, ¡96) (3, ¡8) (10, ¡83) (24, ¡15) 3 2 1

Nw|83++

v = (9+1)<<7 + 83

slide-48
SLIDE 48

Basic ¡Opera0ons: ¡increment

(1, ¡96) (1, ¡83) (1, ¡15) 3 2 1

Nw|83++

v = (1+1)<<7 + 83

slide-49
SLIDE 49

Basic ¡Opera0ons: ¡increment

(1, ¡96) (1, ¡83) (1, ¡15) 3 2 1

Nw|83++

v = (1+1)<<7 + 83

slide-50
SLIDE 50

Basic ¡Opera0ons: ¡increment

(1, ¡96) (2, ¡83) (1, ¡15) 3 2 1

Nw|83++

slide-51
SLIDE 51

Basic ¡Opera0ons: ¡increment

(1, ¡96) (1, ¡15) (2, ¡83) 3 2 1

Nw|83++

slide-52
SLIDE 52

Basic ¡Opera0ons: ¡decrement

(1, ¡96) (1, ¡83) (1, ¡15) 3 2 1

Nw|83-­‑-­‑

v = (1-1)<<7 + 83

slide-53
SLIDE 53

Basic ¡Opera0ons: ¡decrement

(1, ¡96) (1, ¡15) 3 2 1

Nw|83-­‑-­‑

v = (1-1)<<7 + 83

slide-54
SLIDE 54

Basic ¡Opera0ons: ¡decrement

(1, ¡96) (1, ¡15) 3 2 1

Nw|83-­‑-­‑

slide-55
SLIDE 55

Basic ¡Opera0ons

  • Iterate:

– linear ¡in ¡number ¡of ¡non-­‑zero ¡topics

  • Increment ¡and ¡decrement:

– theore0cally ¡the ¡same ¡as ¡iterate, ¡but ¡usually constant

slide-56
SLIDE 56

Memory ¡alloca0on

  • Conserva0ve:

– Count ¡total ¡occurrences ¡of ¡each ¡word ¡type: ¡Nw – For ¡each ¡word ¡type, ¡allocate ¡int[min(T, Nw)]

  • More ¡savings:

– For ¡each ¡type ¡allocate ¡int[min(T, Nw)/k], increase ¡memory ¡as ¡needed ¡(or ¡not)

slide-57
SLIDE 57

Standard ¡alloca0on

“dog” “the” “llama” … Topics

slide-58
SLIDE 58

Conserva0ve ¡alloca0on

“dog” “the” “llama” … Topics “llama” ¡occurs ¡only ¡twice ¡in ¡corpus, ¡so at ¡most ¡two ¡topics

slide-59
SLIDE 59

Huge ¡savings: ¡0me ¡and ¡memory

slide-60
SLIDE 60

Huge ¡savings: ¡0me ¡and ¡memory

slide-61
SLIDE 61

Large-­‑scale ¡Polylingual ¡Topics

  • Wikipedias ¡in ¡40 ¡languages ¡(AR ¡to ¡ZH)

(Ar0cles ¡linking ¡to ¡same ¡English ¡page ¡share ¡P(t|d) ¡)

  • 1,200,000 ¡English ¡headwords
  • 7,000,000 ¡ar0cles
  • 300,000,000 ¡tokens
  • 4,000,000 ¡dis0nct ¡word ¡types

– Drop ¡rare ¡words ¡(< ¡5 ¡tokens) – Drop ¡common ¡words ¡(> ¡5% ¡of ¡docs)

  • 500 ¡topics

One ¡(1) ¡CPU

slide-62
SLIDE 62

Thanks!

  • Paper:

Efficient ¡Methods ¡for ¡Topic ¡Model ¡Inference ¡on ¡Streaming Document ¡Collec.ons. ¡Limin ¡Yao, ¡David ¡Mimno, Andrew ¡McCallum. ¡KDD ¡2009. ¡(See ¡sec0on ¡3.4)

  • Code:

hGp://mallet.cs.umass.edu (Implemented ¡in ¡cc.mallet.topics.WorkerRunnable)

  • 40 ¡language ¡Wikipedia ¡model:

hGp://christo.cs.umass.edu/wiki40