# Lecture 23: Bayesian non-parametrics (continued)

Overview of inference in Dirichlet processes, topic models and the hierarchical Dirichlet process, and infinite latent variable models.

## Recap

When using a mixture model, we need to answer the question: *How many components (mixtures) to use*?
One method of answering this question is through **Bayesian nonparametric mixture models**: define
a distribution over mixture models. Letting the number of mixture components go to infinity
*a priori* equips the model with flexibility to match the number of components required by the data.

The infinite component prior can be achieved through a **Dirichlet Process** (DP). The DP can
be intuitively defined through the Chinese Restaurant Process (CRP):

- Given a restaurant with an infinite number of tables (components) each with a potentially infinite number of seats (can account for unbounded number of data points).
- The first customer (data point) picks any table.
- The th customer (data point) enters the restaurant and
- Sits at an existing table (component) with probability , where is the number of people (data points) at table (component) .
- Starts a new table (instantiates new component) with probability .

The DP can be equivalently defined through the **stick-breaking** process.

- Given a stick of length 1.
- For
- Sample .
- Break of a fraction of the stick. This corresponds to the size of the th atom.
- Sample a random location for this atom from some base distribution .
- Recurse on the remaining stick.

We can define this sampling process as follows

Finally, we can also define the DP through the **Pólya** **urn** **scheme**:

- Suppose an urn contains black balls.
- For $n=1,2,…$, sample a ball from the urn at random.
- If the ball is black, add a ball of a previously unseen color, along with the black ball, back into the urn.
- If the ball is not black, add a new ball of the same color, along with the sampled ball, back into the urn.

## Inference in the Dirichlet Process Gibbs Samplers , Dirichlet Process Notes

Given a Dirichlet process mixture model and a dataset that presumably has been generated from the model, inference is the process of determining the component of the mixture model from which each of the data point came from. Let us consider a Dirichlet process mixture model:

where the data point $x_{n}$ is generated from the component $\phi_{n}$ of the mixture model $G$. We want to determine the component $\phi_{n}$ for each data point $x_{n}$.

### Collapsed Gibbs Sampler

The collapsed Gibbs Sampler integrates out $G$ to get a Chinese restaurant process (CRP). Since, samples in a CRP are exchangeable, we can always rearrange the ordering of data points so that any sampled data point $x_{n}$ is the last one. Let, $z_{n}$ be the cluster allocation of the $x_{n}$ and $K$ be the total number of instantiated clusters, then the probability of $x_{n}$ belonging to the $k^{th}$ cluster is given by:

Note that, there is always a non-zero probability of the data point $x_{n}$ not being associated to any of the $K$ existing clusters and leads to the instantiation of a new cluster.

However, there are a few problems with this approach:

- Updating only one data point at a time makes the algorithm infeasible for large datasets.
- In the case of two true clusters getting merged into a single cluster in the beginning (possibly due to bad initialization), it is unlikely that a single data point will break out and form a different cluster.
- Getting to the true distribution involves going through low probability states and mixing can often be very slow.
- Integrating out parameter for new features is difficult if the likelihood is not conjugate and requires approximation of the integration.

### Blocked Gibbs Sampler

In the Blocked Gibbs Sampler, we instantiate $G$ instead of integrating it out. Although $G$ is infinite-dimensional, we can simply approximate it with a truncated stick-breaking process:

Now, for any $x_{n}$, its assocation probability to the $k^{th}$ cluster can be computed as:

To estimate $\pi_{k}$ we follow the stick-breaking process which can also be thought of as a sequence of binary decisions. For example, we select $z_{n}=1$ with probability $b_{1}$. If $z_{n} \neq 1$, then we select $z_{n}=2$ with probability $b_{2}$ and so on. Formally,

Unlike the Collapsed Gibbs Sampler, where we instantiate a new cluster with some non-zero probability, here we fix the maximum number of clusters ($K$) in the beginning only. This fixed truncation introduces some error in the inference.

### Slice Sampler

In the Slice Sampler, we introduce random truncation in place of pre-determined fixed truncation as in Blocked Gibbs Sampler. By marginalizing out this random truncation, we recover our original Dirichlet process.

We introduce a random variable $u_{n}$ for each data point. The indicator $z_{n}$ is then sampled as follows:

where, $I\left(\pi_{k}>u_{n}\right)$ is an indicator function which will select only a finite number of possible clusters those with $\pi_{k} > u_{n}$. The conditional distribution for $u_{n}$ is a uniform distribution with range $0$ to $\pi_{z_{n}}$:

Conditioned on $u_{n}$ and cluster indicator $z_{n}$, $\pi_{k}$ can be sampled according to the Blocked Gibbs Sampler.

Here, we only need to represent a finite number of components $K$ such that

Slice sampler preserves the structure of blocked sampling, albeit the blocks are different for different points. Since, we do not have to integrate out $G$, it is much faster than Collapsed Gibbs Sampler.

## Hierarchical Dirichlet Process

### Motivation: Topic Models

As introduced in previous lectures, a topic model is a hierarchical graphical model for document description. Under a topic model,

- Each document is a distribution over topics;
- Each topic is a distribution over words;
- Each document is an unordered collection of words (bag-of-words) sampled from the topics;
- The topics are
*shared*among documents.

Latent Dirichlet Allocation (LDA)

However, a naive implementation of Dirichlet process will fail in the case of topic models, because it cannot ensure the topics are shared. To be more specific, for a DP with a *continuous* base measure, we have zero probability of sampling the same atoms twice. As a result, a new set of topics will be generated every time we try to sample a document, making the topic model useless. Thus, we want the base measure to be discrete, but we don’t want to pin down the number of possible topics as in the original LDA. In other words, we need an **infinite, discrete, random** base measure, which leads to the Hierarchical Dirichlet Process (HDP) model proposed by Teh et al.

### Hierarchical Dirichlet Process

The key observation of Teh et al. *hierarchical* Dirichlet process, where

Here, $G_0$ is the global measure distributed as a Dirichlet process with concentration parameter $\gamma$ and base probability measure $H$. $G_j$ are the random measures which are conditionally independent given $G_0$, with distributions given by a Dirichlet process with base probability measure $G_0$. We can use $G_j$ to describe the distribution of topics for each document. Figure 2 shows a simple illustration of the sampling process of a HDP.

As in the case of DP, we can interpret HDP using the Chinese Restaurant Process analogy, where instead of a single restaurant, we now have a franchise of restaurants (documents). The restaurants share a common menu of dishes (topics). Each customer (word) picks a table in the restaurant and each table orders a dish (topic) according to the shared menu.

The following process desribes how to sample from a HDP-LDA. For more details, please refer to the paper

- Sample the global measure $G_0\sim\mathrm{DP}(\gamma,H)$ (e.g. using stick breaking).
- For each document $j$
- Sample a distribution over topics $G_j\sim\mathrm{DP}(\alpha_0,G_0)$.
- For $i=1,\ldots,N_j$
- Sample a topic $\phi_{ji}\sim G_j$.
- Sample a word $w_{ji}\sim P(\phi_{ji})$.

Figure 3 shows the perplexity score (i.e. negative log likelihood) of LDAs trained with different number of topics compared with HDP-LDA. It can be seen that HDP-LDA achieves the lowest possible perplexity by automatically selecting the “right” number of topics.

## Latent Variable Models

### Motivation

Latent class models introduced previously assume that classes are independent, which prevents the sharing of features across classes. However, in many applications it would be useful to share features across data points. For example,

- Images contain multiple objects which may have common features.
- Individuals in social networks may belong to multiple social groups.

Latent variable models introduce a latent feature space , from which the data can be constructed. For example, in Factor Analyis, the data is assumed to be a linear combination of the features

However, in general, it is not necessary for and to be combined linearly.

We are interested in answering the following two questions:

- Can we make the number of features (rows of , columns of ) unbounded?
- Can we do so in a manner that makes inference tractable?

We see that both of these properties can be achieved through the framework introduced
by the Indian Buffet Process (IBP)

### Sparse Latent Variable Models

We first consider the a large, but finite, sparse latent variable model. The sparsisty property is desirable so that as the number of features grows large, we can bound the expected number of non-zero features, which is a requirement for a tractable inference procedure.

The Chinese Restaurant Process discussed previously can be considered as a distribution over sparse finite bindary matrices, i.e. each customer (data point) is assigned to a single table (feature), leading to a matrix with a single non-zero entry per row.

Such a representation is excessively sparse, which motivates allowing multiple active features per row. In the restaurant analogy, this is equivalent to the customer sitting at multiple tables (or in IBP, get multiple dishes) - more on this later.

Let’s define our weight matrix as

where is a sparse binary matrix.

We are interested in defining a distribution , which is achieved
by placing a *beta-Bernoulli* prior over .

Using the fact that the columns (features) of are
*i.i.d.* and the rows are *i.i.d* when conditioned on , and
noting that the beta distribution is conjugate to the Bernoulli, the
distribution over is given by

where is the number of data points with active feature .

We can show that that this matrix is sparse by considering the expected number of non-zero entries

which is bounded above by .

### Infinite Sparse Latent Variable Models

Taking in the model above would result in a matrices with infinite numbers of
empty columns. To get arrow this, define an equivalence class of
*left-ordered* binary matrices given by the function .
Specifically, the matrices are sorted in order of decreasing binary number defined by
considering the rows of a single column as bits.

All matrices with the equivalence class have equal probability. The total probability of the class is then equal to , where is the number of matrices in the class. In order to compute , we introduce a few terms

- Let the
*history*of a feature $k$ be defined by the binary number equivalent of its rows, e.g. a 4 data point example with column has history 5. - Let $K_{h}$ denote the number of features with history $h$.
- Let $K_{+}$ denote the number of features with non-zero history.
- Let $K = K_{0} + K_{+}$, i.e. the sum of the zero history and non-zero history features.

For $N$ data points, we have a maximum history of $2^{N-1}$ (max N-bit binary number). Since columns are exchangeable, we note that any permutation of columns with history $h$ does not chage the matrix under equivalence.

The distribution over is then

We can evaluate this term by splitting into the terms for which and
(see eqn (13) in

Taking the limit as

where is the $N$th harmonic number. See Appendix A in

### Intuition: Indian Buffet Process

**Setup**: Buffet with infinite number of dishes. Customers can select any number of dishes.

**Procedure**:

- Customer enters restaurant and selects dishes.
- The th customer considers each previously selected dish and selects from it with probability .
- The th customer then selects new dishes.

We can show that this sequential process is *lof*-equivalent to the infinite *beta-Bernoulli* model defined
previously.

where is the number of new features in the th row. Accounting for the
cardinality of the *lof*-equivalence set gives the same result as the *beta-Bernoulli* case.

### Summary

The IBP enables reasoning about a potentially infinite number of features, which can be selected in a data-dependent
manner. The capacity of the model (in terms of # of features) does not need to be specified *a priori*, but can be
controlled through a prior distribution over the feature selection matrices.
Some properties of the IBP

- “Rich get richer” - popular dishes (features selected by many data points) become more popular (are assigned to more data).
- The number of dishes selected by a customer (non-zero entries in each data row) is distributed according to .
- The number of dishes selected by
**all**customers (number of non-zero entries) is distributed according to . - The number of dishes selected by
**any**customer (number of non-zero columns) is distributed according to . - The total number of dishes selected (number of non-zero entries) in expectation is bounded by .