27
Deep learning Deep learning Sum Product Networks Hamid Beigy Sharif university of technology December 25, 2018 Hamid Beigy | Sharif university of technology | December 25, 2018 1 / 24

Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning

Deep learningSum Product Networks

Hamid Beigy

Sharif university of technology

December 25, 2018

Hamid Beigy | Sharif university of technology | December 25, 2018 1 / 24

Page 2: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning

Table of contents

1 Introduction

2 Sum Product Networks

3 Applications

Hamid Beigy | Sharif university of technology | December 25, 2018 2 / 24

Page 3: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning | Introduction

Table of contents

1 Introduction

2 Sum Product Networks

3 Applications

Hamid Beigy | Sharif university of technology | December 25, 2018 2 / 24

Page 4: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning | Introduction

Introduction

1 We require to specify a high-dimensional distribution p(x1, . . . , xk) onthe data and possibly some latent variables.

2 The specific form of p will depend on some parameters w .

3 The basic operations will be to

specify the parametric/non-parametric form of p(x1, . . . , xk) (structurelearning)adjust p(x1, . . . , xk) to the data (learning )compute marginals and modes of p(x1, . . . , xk) (inference)

4 Working with fully flexible joint distributions is intractable!

5 We must work with structured or compact distributions.For example,distributions in which the random variables interactdirectly with only very few others in simple ways.

6 One solution is to use probabilistic graphical models.

Hamid Beigy | Sharif university of technology | December 25, 2018 3 / 24

Page 5: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning | Introduction

Bayesian Networks

1 A simple Bayesian network

p(G ,S ,R) = p(G |S ,R)p(S |R)p(R)

Hamid Beigy | Sharif university of technology | December 25, 2018 4 / 24

Page 6: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning | Introduction

Bayesian Networks

1 How calculate p(x1, . . . , xk) using Bayesian networks?

2 If a Bayesian network can be factorized, then we can write

p(x1, . . . , xk) =∏v∈V

p(xv |pa(v))

where pa(v) is the set of parents of v .

3 Cooper proved that exact inference in Bayesian networks is NP-hard.

Hamid Beigy | Sharif university of technology | December 25, 2018 5 / 24

Page 7: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning | Introduction

How to use word vectors?

1 A Markov network is a set of random variables having a Markovproperty described by an undirected graph.

2 Each edge represents dependency.

A depends on B and D.B depends on A and D.D depends on A, B, and E.E depends on D and C.C depends on E.

Hamid Beigy | Sharif university of technology | December 25, 2018 6 / 24

Page 8: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning | Introduction

Limitations of Graphical Models

1 Graphical models are limited in some aspects

Many compact distributions cannot be represented as a GM.The cost of exact inference in GM is exponential in the worst case(using approximate techniques).Because learning requires inference, learning GM will be difficult .Some distributions require GM with many layers of hidden variables tobe compactly encoded.

2 An alternative are sum product networks1

New deep model with many layers of hidden variables.Exact inference is tractable (linear in the size of the model).

1Poon, Hoifung and Pedro Domingos (2011). ”Sum-Product Networks: a New DeepArchitecture”. In: UAI 2011

Hamid Beigy | Sharif university of technology | December 25, 2018 7 / 24

Page 9: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning | Sum Product Networks

Table of contents

1 Introduction

2 Sum Product Networks

3 Applications

Hamid Beigy | Sharif university of technology | December 25, 2018 7 / 24

Page 10: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning | Sum Product Networks

Sum Product Networks

1 A SPN is rooted DAG whose leaves are x1, . . . , xn and x̄1, . . . , x̄n withinternal sum and product nodes , where each edge (i , j) emanatingfrom sum node i has a weight wij ≥ 0.

2 The value of a product node is the product of the value of its children.

3 The value of a sum node i is∑

j∈Ch(i) wijvj , where Ch(j) are thechildren of node i and vj is the value of node j

4 The value of a SPN is the value of the root after a bottom upevaluation.

5 Layers of sum and product nodes alternate.

Hamid Beigy | Sharif university of technology | December 25, 2018 8 / 24

Page 11: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning | Sum Product Networks

Sum Product Networks (example)

1 An example of SPN

What is a Sum-Product Network?

• Poon and Domingos, UAI 2011

• Acyclic directed graphof sums and products

• Leaves can be indicatorvariables or univariate distributions

CS486/686 Lecture Slides (c) 2017 P. Poupart

Hamid Beigy | Sharif university of technology | December 25, 2018 9 / 24

Page 12: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning | Sum Product Networks

Probabilistic Inference

SPN represents a joint distribution over a set of random variables.

As an example considerp(x1 = true, x2 = false)

What is a Sum-Product Network?

• Poon and Domingos, UAI 2011

• Acyclic directed graphof sums and products

• Leaves can be indicatorvariables or univariate distributions

CS486/686 Lecture Slides (c) 2017 P. Poupart

Hamid Beigy | Sharif university of technology | December 25, 2018 10 / 24

Page 13: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning | Sum Product Networks

Marginal Inference

SPN represents a joint distribution over a set of random variables.

As an example considerp(x2 = false)

What is a Sum-Product Network?

• Poon and Domingos, UAI 2011

• Acyclic directed graphof sums and products

• Leaves can be indicatorvariables or univariate distributions

CS486/686 Lecture Slides (c) 2017 P. Poupart

Hamid Beigy | Sharif university of technology | December 25, 2018 11 / 24

Page 14: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning | Sum Product Networks

Conditional Inference

SPN represents a joint distribution over a set of random variables.

As an example consider

p(x1 = true|x2 = false) =p(x1 = true, x2 = false)

p(x2 = false)

Hence any inference query can be answered intwo bottom-up passes of the network (Lineartime complexity).

What is a Sum-Product Network?

• Poon and Domingos, UAI 2011

• Acyclic directed graphof sums and products

• Leaves can be indicatorvariables or univariate distributions

CS486/686 Lecture Slides (c) 2017 P. Poupart

Hamid Beigy | Sharif university of technology | December 25, 2018 12 / 24

Page 15: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning | Sum Product Networks

SPN Semantics

A valid SPN encodes a hierarchical mixture distribution.

Sum nodes: hidden variables(mixture)

Product nodes: factorization(independence)

What is a Sum-Product Network?

• Poon and Domingos, UAI 2011

• Acyclic directed graphof sums and products

• Leaves can be indicatorvariables or univariate distributions

CS486/686 Lecture Slides (c) 2017 P. Poupart

Hamid Beigy | Sharif university of technology | December 25, 2018 13 / 24

Page 16: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning | Sum Product Networks

Valid SPN

The scope of a node is the set of variables thatappear in the sub-SPN rooted at the node

An SPN is decomposable when each productnode has children with disjoint scopes.

An SPN is complete when each sum node haschildren with identical scopes

A decomposable and complete SPN is a validSPN.

What is a Sum-Product Network?

• Poon and Domingos, UAI 2011

• Acyclic directed graphof sums and products

• Leaves can be indicatorvariables or univariate distributions

CS486/686 Lecture Slides (c) 2017 P. Poupart

Hamid Beigy | Sharif university of technology | December 25, 2018 14 / 24

Page 17: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning | Sum Product Networks

Building and using an SPN

1 We must specify the structure of SPN (structure Estimation orstructure learning).

2 We must find the parameters of SPN (parameter learning).

3 We must answer queries (inference).

Hamid Beigy | Sharif university of technology | December 25, 2018 15 / 24

Page 18: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning | Sum Product Networks

Structure learning

1 What is SPN for univariate distribution?

2 → A univariate distribution is an SPN

3 What is SPN for product of disjoint random variables?

4 → A product of SPNs over disjoint variables is an SPN.

5 What is SPN for a mixture model?

6 → A weighted sum of SPNs over the same variables is an SPN.

A Weighted Sum of SPNs over the Same Variables

Is an SPN.

X Y X Y

w1 w2

Hamid Beigy | Sharif university of technology | December 25, 2018 16 / 24

Page 19: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning | Sum Product Networks

Structure learning

1 In a structure learning, one alternates betweenData Clustering: sum nodesVariable partitioning: product nodesStructure learning: LearnSPN

Cluster similar instances

Split variables on approximate independence

2 Some others use SVD decomposition2

2Adel, Tameem, David Balduzzi, and Ali Ghodsi (2015). ”Learning the Structure ofSum-Product Networks via an SVD-based Algorithm”. In UAI.

Hamid Beigy | Sharif university of technology | December 25, 2018 17 / 24

Page 20: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning | Sum Product Networks

Structure learning

1 Initialize the SPN using a dense valid SPN.

2 Learn the SPN weights using gradient descent or EM.

3 Add some penalty to the weights so that they tend to be zero.

4 Prune edges with zero weights at convergence.

Algorithm 1 LearnSPNInput: Set D of instances over variablesX .Output: An SPN with learned structure and parameters.S ← GenerateDenseSPN(X)InitializeWeights(S)repeatfor all d ∈ D doUpdateWeights(S, Inference(S, d))

end foruntil convergenceS ← PruneZeroWeights(S)return S

explicitly represent only the features, and require the sumsto be inefficiently computed by Gibbs sampling or oth-erwise approximated. Convolutional networks [15] alter-nate feature layers with pooling layers, where the pool-ing operation is typically max or average, and the fea-tures in each layer are over a subset of the input variables.Convolutional networks are not probabilistic, and are usu-ally viewed as a vision-specific architecture. SPNs can beviewed as probabilistic, general-purpose convolutional net-works, with average-pooling corresponding to marginal in-ference and max-pooling corresponding to MPE inference.Lee at al. [16] have proposed a probabilistic version ofmax-pooling, but in their architecture there is no corre-spondence between pooling and the sum or max operationsin probabilistic inference, as a result of which inference isgenerally intractable. SPNs can also be viewed as a prob-abilistic version of competitive learning [27] and sigma-pinetworks [25]. Like deep belief networks, SPNs can beused for nonlinear dimensionality reduction [14], and al-low objects to be reconstructed from the reduced represen-tation (in the case of SPNs, a choice of mixture componentat each sum node).

Probabilistic context-free grammars and statistical parsing[6] can be straightforwardly implemented as decomposableSPNs, with non-terminal nodes corresponding to sums (ormaxes) and productions corresponding to products (logi-cal conjunctions for standard PCFGs, and general productsfor head-driven PCFGs). Learning an SPN then amountsto directly learning a chart parser of bounded size. How-ever, SPNs are more general, and can represent unrestrictedprobabilistic grammars with bounded recursion. SPNs arealso well suited to implementing and learning grammaticalvision models (e.g., [10, 33]).

4 LEARNING SUM-PRODUCTNETWORKS

The structure and parameters of an SPN can be learnedtogether by starting with a densely connected architectureand learning the weights, as in multilayer perceptrons. Al-gorithm 1 shows a general learning scheme with onlinelearning; batch learning is similar.

First, the SPN is initialized with a generic architecture.The only requirement on this architecture is that it be valid(complete and consistent). Then each example is processedin turn by running inference on it and updating the weights.This is repeated until convergence. The final SPN is ob-tained by pruning edges with zero weight and recursivelyremoving non-root parentless nodes. Note that a weightededge must emanate from a sum node and pruning suchedges will not violate the validity of the SPN. Therefore,the learned SPN is guaranteed to be valid.

Completeness and consistency are general conditions thatleave room for a very flexible choice of architectures. Here,we propose a general scheme for producing the initial ar-chitecture: 1. Select a set of subsets of the variables. 2. Foreach subset R, create k sum nodes SR

1 , . . . , SRk , and select

a set of ways to decompose R into other selected subsetsR1, . . . , Rl. 3. For each of these decompositions, and forall 1 ≤ i1, . . . , il ≤ k, create a product node with par-ents SR

j and children SR1

i1, . . . , SRl

il. We require that only a

polynomial number of subsets is selected and for each sub-set only a polynomial number of decompositions is cho-sen. This ensures that the initial SPN is of polynomial sizeand guarantees efficient inference during learning and forthe final SPN. For domains with inherent local structure,there are usually intuitive choices for subsets and decom-positions; we give an example in Section 5 for image data.Alternatively, subsets and decompositions can be selectedrandomly, as in random forests [4]. Domain knowledge(e.g., affine invariances or symmetries) can also be incor-porated into the architecture, although we do not pursuethis in this paper.

Weight updating in Algorithm 1 can be done by gradientdescent or EM. We consider each of these in turn.

SPNs lend themselves naturally to efficient computationof the likelihood gradient by backpropagation [26]. Letnj be a child of sum node ni. Then ∂S(x)/∂wij =(∂S(x)/∂Si(x))Sj(x) and can be computed along with∂S(x)/∂Si(x) using the marginal inference algorithm de-scribed in Section 2. The weights can then be updated bya gradient step. (Also, if batch learning is used instead,quasi-Newton and conjugate gradient methods can be ap-plied without the difficulties introduced by approximate in-ference.) We ensure that S(∗) = 1 throughout by renormal-izing the weights at each step, i.e., projecting the gradientonto the S(∗) = 1 constraint surface. Alternatively, we canlet Z = S(∗) vary and optimize S(X)/S(∗).

SPNs can also be learned using EM [20] by viewing eachsum node i as the result of summing out a correspond-ing hidden variable Yi, as described in Section 2. Nowthe inference in Algorithm 1 is the E step, computing themarginals of the Yi’s, and the weight update is the M step,adding each Yi’s marginal to its sum from the previous it-erations and renormalizing to obtain the new weights.

Hamid Beigy | Sharif university of technology | December 25, 2018 18 / 24

Page 21: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning | Applications

Table of contents

1 Introduction

2 Sum Product Networks

3 Applications

Hamid Beigy | Sharif university of technology | December 25, 2018 18 / 24

Page 22: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning | Applications

Image completion

1 Main evaluation: Caltech-101

101 categories, e.g., faces, cars, elephantsEach category: 30 800 images

2 Also, Olivetti [Samaria & Harter, 1994] (400 faces)

3 Each category: Last third for test

4 Test images: Unseen objects

Hamid Beigy | Sharif university of technology | December 25, 2018 19 / 24

Page 23: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning | Applications

Image completionCool applications: Face completion

Poon & Domingos 2011Hamid Beigy | Sharif university of technology | December 25, 2018 20 / 24

Page 24: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning | Applications

Language modeling

1 Fixed structure SPN encoding the conditional probabilityp(wi |wi−1 . . . ,wi−n) as an nth order language model3.

Applications IV: language modelingFixed structure SPN encoding the conditional probability p(wi|wi−1, . . . , wi−n)

as an n-th order language model.

Figure 2: SPN for language modeling.

probability as

P (Y=y|X=x) =

� (Y=y|X=x)Py0 � (Y=y0|X=x)

=

Ph � (Y=y,H=h|X=x)P

y0,h � (Y=y0,H=h|X=x)

where � (Y = y|X = x) is an unnormalized probability. Thusthe partial derivative of the conditional log-likelihood with re-spect to a weight w in an SPN is given by:

@@w

logP (y|x)= @@w

log

X

h

� (y,h|x)� @@w

log

X

y0,h

�y0,h|x

(1)To train an SPN, we first specify its architecture, i.e., its

sum and product nodes, and the connections between them.Then we learn the weights of the sum nodes via gradient de-scent to maximize the conditional log-likelihood of a trainingset of (x,y) examples. The gradient of each weight (Equa-tion 1) is computed via backpropagation. The first summationon the right-hand side of Equation 1 can be computed tractablyin a single upward pass through the SPN by setting all hid-den variables to 1, and the second summation can be computedsimilarly by setting both hidden and query variables to 1. Thepartial derivatives are passed from parent to child according tothe chain rule as described by [14]. Each weight is changedby multiplying a learning rate parameter ⌘ to Equation 1, i.e.,�w = ⌘ @

@w

logP (y|x). To speed up training, we could esti-mate the gradient by computing it with a subset (mini-batch) ofexamples from the training set, rather than using all examples.

3. SPN Architecture

Figure 2 shows the architecture of our discriminative SPN forlanguage modeling1. To predict a word (a query variable), we

1https://github.com/stakok/lmspn/blob/master/faq.md containsmore details about the architecture.

use its previous N words as evidence in our SPN. Each previousword is represented by a K-dimensional vector where K is thenumber of words in a vocabulary. Each vector has exactly one1 at the index corresponding to the word it represents, and 0’severywhere else. When we predict the ith word, we have avector v

i�j

(1 j N ) at the bottommost layer for each ofthe previous N words.

Above the bottommost layer, we have a (hidden) layer ofsum nodes. There are D sum nodes H

j1 . . . HjD

for each vec-tor v

i�j

. Each sum node Hjl

has an edge connecting it to everyentry in v

i�j

. Let the mth entry in vi�j

be denoted by vm

i�j

,and the weight of the edge from H

jl

to vm

i�j

be denoted byw

lm

. We constrain each weight wlm

to be the same for eachpair of H

jl

and vm

i�j

(1 j N ). This layer of sum nodescan be interpreted as compressing each K-dimensional vectorsvi�j

into a smaller continuous-valued D-dimensional featurevector (thus gaining the same advantages of [5] as described inSection 1). Because the weights w

lm

’s are constrained to bethe same between each pair of K-dimensional input vector andD-dimensional feature vector, we ensure that the weights areposition independent, i.e., the same word will be compressedinto the same feature vector regardless of its position. Thisalso makes it easier to train the SPN by reducing the numberof weights to be learned.

Above the Hjl

layer, we have another layer of sum nodes.In this layer, each node M

k

(1 k K) is connected to everyH

jl

node. Moving up, we have a layer of product nodes. EachG

k

product node is connected via two edges to an Mk

node.Each G

k

node transforms the output from its child Mk

node bysquaring it. This helps to capture more complicated dependencyamong the input words.

Moving up, we have another layer of sum nodes. Each Bk

node in this layer is connected to an Mk

node and a Gk

node inthe lower layers. Above this, there is a layer of S

k

nodes, eachof which is connected to a B

k

node and an indicator variable yk

representing a value in our categorical query variable (i.e., theith word which we are predicting). y

k

= 1 if the query variableis the kth word, and y

k

= 0 otherwise. Intuitively, the indicatorvariables select which part of the SPN below an S

k

node gets“activated”. Finally, we have an S node which connects to allSk

nodes. When we normalize the weights between S and theSk

nodes to sum to 1, S’s output is the conditional probabilityof the ith word given its previous N words.

4. Experiments

4.1. Dataset

We performed our experiments on the commonly used PennTreebank corpus [15], and adhered to the experimental setupused in previous work [6, 9]. We used sections 0-20, sections21-22, and sections 23-24 respectively as training, validationand test sets. These sections contain segments of news re-ports from the Wall Street Journal. We treated punctuation aswords, and used the 10,000 most frequent words in the cor-pus to create a vocabulary. All other words are regarded asunknown and mapped to the token <unk>. The percentagesof out-of-vocabulary (<unk>) tokens in them are about 5.91%,6.96% and 6.63% respectively. Thus only a small fraction ofthe dataset consists of unknown words.

4.2. Methodology

Using the training set, we learned the weights of all sumnodes in our SPN described in Section 3. To evaluate

One-hot encoding of word vocabulary.Windowed representation of size

First embedding layer with sizeD,sharing word weights across differentmixtures (position invariance).

State-of-the-art perplexity on PennTreeBank even for low orders (n = 4).

Cheng et al., “Language modeling with Sum-Product Networks”, 2014

3Cheng et al.,”Language Sum-Product Networks”, InterSpeech, 2014

Hamid Beigy | Sharif university of technology | December 25, 2018 21 / 24

Page 25: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning | Applications

Language modeling

1 Perplexity scores (PPL) of different language modelsits performance on the test set, we used the standard(per-word) perplexity measure. The perplexity (PPL)on a sequence of words w1, w2, . . . , wM

is given by

PPL =

M

vuutMY

i=1

1

P (wi

|w1, ..., wi�1).

We estimated the probability P (wi

|w1, ..., wi�1) in PPL asP (w

i

|wi�1, ..., wi�N

) that is given by our SPN.We used a learning rate of ⌘=0.1, a mini-batch size of 100,

randomly initialized the weights to a value between 0 and 1, andimposed an L2 penalty of 10�5 on all weights. With referenceto Figure 2, We used K=10000, feature vectors with D=100

dimensions, and N =3 and N =4 previous words. We denotean SPN that uses N previous words as SPN-N . We stoppedtraining our SPN when its performance on the validation setstops improving at two consecutive evaluation points, or whenit has run for 40 hours, whichever occurred first. (It turned outthat both SPN-3 and SPN-4 ran for the maximum of 40 hours.)We parallelized our SPN code2 to run on a GPU, and ran ourexperiments on a machine with a 2.4 GHz CPU and an NVIDIATesla C2075 GPU (448 CUDA cores, 5GB of device memory).

We compared our SPNs to an interpolated 5-gram modelwith modified Kneser-Ney smoothing and no count cutoffs(KN5) [3], the log-bilinear model [4], feedforward neural net-works [5], syntactical neural networks [8], recurrent neural net-works (RNN) [6], and LDA-augmented RNN [9], all of whichare described in Section 1.

4.3. Results

Table 1 shows the results of our experiments. The scores ofcomparison systems are obtained from [9]. The “IndividualPPL” column shows the perplexity score of the respectivesystems. The “+KN5” column shows the perplexity score af-ter taking a weighted average of a system’s predictions andKN5’s predictions (both equally weighted). ‘TrainingSetFre-quency’ refers to a system that sets the probability of a tokento its frequency of occurrence in the training set. This base-line is outperformed by all other models, suggesting that theyare capturing some form of dependency among words whenmaking their predictions. As the table shows, both SPN-3 andSPN-4 outperform all other systems. Note that even thoughLDA-augmented RNN uses additional information from latentDirichlet allocation (LDA; which is not used by our SPNs),SPN-3 and SPN-4 still do better by 8.4% and 5.4% respectivelyon “Individual PPL”, and by 16.6% and 16.2% respectively on“+KN5”. They have more pronounced improvements over thenext best comparison system, RNN (which is a fairer compari-son because it does not use information beyond what is availableto our SPNs). SPN-3 and SPN-4 outperform RNN by 16.4%and 13.7% respectively on “Individual PPL”, and by 22.4%and 22.0% respectively on “+KN5”.

We were initially surprised by SPN-3’s better performanceover SPN-4 (because the latter uses more information and thusshould make better predictions). Upon inspecting their perplex-ity scores on the training set, we found that SPN-4 consistentlyhad lower perplexity than SPN-3 during the later stages of train-ing. This suggests that SPN-4 is overfitting the data. (From Fig-ure 2, we see that SPN-4 has D⇥K+D⇥K = 2⇥10

6 moreparameters than SPN-3, and hence is more likely to overfit.)

2Our implementation is publicly available athttps://github.com/stakok/lmspn.

Table 1: Perplexity scores (PPL) of different language models.

Model Individual PPL +KN5TrainingSetFrequency 528.4KN5 [3] 141.2Log-bilinear model [4] 144.5 115.2Feedforward neural network [5] 140.2 116.7Syntactical neural network [8] 131.3 110.0RNN [6] 124.7 105.7LDA-augmented RNN [9] 113.7 98.3SPN-3 104.2 82.0

SPN-4 107.6 82.4

SPN-4’ 100.0 80.6

To ameliorate this problem, we used the weights of the smallerSPN to guide the weight learning in the larger SPN. We trainedan SPN-(N�1) for 10 hours, and used its weights to initializethe corresponding weights in an SPN-N (all other weights areinitialized to zero) before training the SPN-N for another 10hours. We repeated this process for N = 2, 3, 4. The final SPNthus obtained uses 4 previous words and is denoted SPN-4’. AsTable 1 shows, SPN-4’ is the best performing system3.

Running a test example on our SPNs is typically very fast(sub-second). Our SPNs took less time to train than RNN. Toattain the level of KN5’s perplexity score, RNN4 and SPN-4took about 10 hours and 4 hours to train respectively.

To demonstrate that our SPN can scale to larger data, wetrained an SPN-4 for 40 hours on the Brown Laboratory forLinguistic Information Processing 1987-89 WSJ corpus, whichis about 40 times larger than Penn Treebank (PTB). We testedthis SPN-4 on the same test set (section 23-24 of PTB) and ob-tained a perplexity of 93.0 (an improvement of 13.6% over theSPN-4 trained on the smaller PTB dataset). This suggests thatour model can scale, and can perform better with more data.

To show that our trained SPN is encapsulating useful in-formation, we “seeded” it with some random initial words, andused it to generate a sequence of words. Some examples of thegenerated word sequences are shown below. These sentenceshave the “flavor” of news reports, and qualitatively suggest thatour SPN is capturing meaningful information from the data.

• IT COULD BE SIMPLY EARNINGS FOR MANY IN-VESTOR IN THE WATERS FEDERAL CAPITAL

• BUSINESS REGULATORY SAID IT EXPECTS TOARGUE OWN ’S THREE MEDICAL INVESTMENTIN <unk>

5. Conclusion and Future Work

We presented the first SPN that is used for language model-ing. Our proposed SPN is able to contain multiple hidden layersto capture rich dependencies among words, while maintainingtractable inference and training times. Our empirical compar-isons with six previous language models on the standard PennTreebank corpus demonstrate the effectiveness of our SPN.

As future work, we want to combine our SPN languagemodel with an SPN for acoustic modeling to create an integratedspeech recognition system. We also want to create a “recurrent”SPN to capture long range dependencies in word sequences.

Acknowledgements. This work is supported by DSO grantDSOCL13083.

3Note that the total training time for SPN-4’ is also 40 hours, so itsbetter performance is not due to longer training times.

4We used the RNNLM Toolkit athttp://www.fit.vutbr.cz/ imikolov/rnnlm.

Hamid Beigy | Sharif university of technology | December 25, 2018 22 / 24

Page 26: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning | Applications

Other applications

1 Image completion

2 Image classification

3 Activity recognition

4 Click-through logs

5 Nucleic acid sequences

6 Collaborative filtering

Hamid Beigy | Sharif university of technology | December 25, 2018 23 / 24

Page 27: Deep learning - Sum Product Networksce.sharif.edu/courses/97-98/1/ce959-1/resources/root/slides/Lect-22.pdf · Deep learning j Introduction Introduction 1 We require to specify a

Deep learning | Applications

Advantages of SPNs

1 Unlike graphical models, SPNs are tractable over high treewidthmodels.

2 SPNs are a deep architecture with full probabilistic semantics

3 SPNs can incorporate features into an expressive model withoutrequiring approximate inference.

Hamid Beigy | Sharif university of technology | December 25, 2018 24 / 24