# Generative model

In statistical classification, including machine learning, two main approaches are called the generative approach and the discriminative approach. These compute classifiers by different approaches, differing in the degree of statistical modelling. Terminology is inconsistent,[a] but three major types can be distinguished, following Jebara (2004):

The distinction between these last two classes is not consistently made;[2] Jebara (2004) refers to these three classes as generative learning, conditional learning, and discriminative learning, but Ng & Jordan (2002) only distinguish two classes, calling them generative classifiers (joint distribution) and discriminative classifiers (conditional distribution or no distribution), not distinguishing between the latter two classes.[3] Analogously, a classifier based on a generative model is a generative classifier, while a classifier based on a discriminative model is a discriminative classifier, though this term also refers to classifiers that are not based on a model.

Standard examples of each, all of which are linear classifiers, are:

In application to classification, one wishes to go from an observation x to a label y (or probability distribution on labels). One can compute this directly, without using a probability distribution (distribution-free classifier); one can estimate the probability of a label given an observation, ${\displaystyle P(Y|X=x)}$ (discriminative model), and base classification on that; or one can estimate the joint distribution ${\displaystyle P(X,Y)}$ (generative model), from that compute the conditional probability ${\displaystyle P(Y|X=x)}$, and then base classification on that. These are increasingly indirect, but increasingly probabilistic, allowing more domain knowledge and probability theory to be applied. In practice different approaches are used, depending on the particular problem, and hybrids can combine strengths of multiple approaches.

## Definition

An alternative division defines these symmetrically as:

• a generative model is a model of the conditional probability of the observable X, given a target y, symbolically, ${\displaystyle P(X|Y=y)}$ [4]
• a discriminative model is a model of the conditional probability of the target Y, given an observation x, symbolically, ${\displaystyle P(Y|X=x)}$ [5]

Regardless of precise definition, the terminology is constitutional because a generative model can be used to "generate" random instances (outcomes), either of an observation and target ${\displaystyle (x,y)}$ , or of an observation x given a target value y,[4] while a discriminative model or discriminative classifier (without a model) can be used to "discriminate" the value of the target variable Y, given an observation x.[5] The difference between "discriminate" (distinguish) and "classify" is subtle, and these are not consistently distinguished. (The term "discriminative classifier" becomes a pleonasm when "discrimination" is equivalent to "classification".)

The term "generative model" is also used to describe models that generate instances of output variables in a way that has no clear relationship to probability distributions over potential samples of input variables. Generative adversarial networks are examples of this class of generative models, and are judged primarily by the similarity of particular outputs to potential inputs. Such models are not classifiers.

### Relationships between models

In application to classification, the observable X is frequently a continuous variable, the target Y is generally a discrete variable consisting of a finite set of labels, and the conditional probability ${\displaystyle P(Y|X)}$  can also be interpreted as a (non-deterministic) target function ${\displaystyle f\colon X\to Y}$ , considering X as inputs and Y as outputs.

Given a finite set of labels, the two definitions of "generative model" are closely related. A model of the conditional distribution ${\displaystyle P(X|Y=y)}$  is a model of the distribution of each label, and a model of the joint distribution is equivalent to a model of the distribution of label values ${\displaystyle P(Y)}$ , together with the distribution of observations given a label, ${\displaystyle P(X|Y)}$ ; symbolically, ${\displaystyle P(X,Y)=P(X|Y)P(Y).}$  Thus, while a model of the joint probability distribution is more informative than a model of the distribution of label (but without their relative frequencies), it is a relatively small step, hence these are not always distinguished.

Given a model of the joint distribution, ${\displaystyle P(X,Y)}$ , the distribution of the individual variables can be computed as the marginal distributions ${\displaystyle P(X)=\sum _{y}P(X,Y=y)}$  and ${\displaystyle P(Y)=\int _{x}P(Y,X=x)}$  (considering X as continuous, hence integrating over it, and Y as discrete, hence summing over it), and either conditional distribution can be computed from the definition of conditional probability: ${\displaystyle P(X|Y)=P(X,Y)/P(Y)}$  and ${\displaystyle P(Y|X)=P(X,Y)/P(X)}$ .

Given a model of one conditional probability, and estimated probability distributions for the variables X and Y, denoted ${\displaystyle P(X)}$  and ${\displaystyle P(Y)}$ , one can estimate the opposite conditional probability using Bayes' rule:

${\displaystyle P(X|Y)P(Y)=P(Y|X)P(X).}$

For example, given a generative model for ${\displaystyle P(X|Y)}$ , one can estimate:

${\displaystyle P(Y|X)=P(X|Y)P(Y)/P(X),}$

and given a discriminative model for ${\displaystyle P(Y|X)}$ , one can estimate:

${\displaystyle P(X|Y)=P(Y|X)P(X)/P(Y).}$

Note that Bayes' rule (computing one conditional probability in terms of the other) and the definition of conditional probability (computing conditional probability in terms of the joint distribution) are frequently conflated as well.

## Contrast with discriminative classifiers

A generative algorithm models how the data was generated in order to categorize a signal. It asks the question: based on my generation assumptions, which category is most likely to generate this signal? A discriminative algorithm does not care about how the data was generated, it simply categorizes a given signal. So, discriminative algorithms try to learn ${\displaystyle p(y|x)}$  directly from the data and then try to classify data. On the other hand, generative algorithms try to learn ${\displaystyle p(x,y)}$  which can be transformed into ${\displaystyle p(y|x)}$  later to classify the data. One of the advantages of generative algorithms is that you can use ${\displaystyle p(x,y)}$  to generate new data similar to existing data. On the other hand, discriminative algorithms generally give better performance in classification tasks.[6]

Despite the fact that discriminative models do not need to model the distribution of the observed variables, they cannot generally express complex relationships between the observed and target variables. They don't necessarily perform better than generative models at classification and regression tasks. The two classes are seen as complementary or as different views of the same procedure.[7]

## Deep Generative Models

With the rise of deep learning, a new family of methods, called deep generative models (DGMs)[8][9], is formed through the combination of generative models and deep neural networks. The trick of DGMs is that the neural networks we use as generative models have a number of parameters significantly smaller than the amount of data we train them on, so the models are forced to discover and efficiently internalize the essence of the data in order to generate it.

Popular DGMs include Variational Autoencoder (VAE), Generative Adversarial Networks (GANs) and auto-regressive models. There is a trend to build large deep generative models.[8] For example, GPT-3, and its precursor GPT-2,[10] for auto-regressive neural language models, BigGAN[11] and VQ-VAE[12] for image generation, Optimus[13] as the largest VAE language model, jukebox as the largest VAE model for music generation[14]

DGMs have many short-term applications. But in the long run, they hold the potential to automatically learn the natural features of a dataset, whether categories or dimensions or something else entirely.[9]

## Types

### Generative models

Types of generative models are:

If the observed data are truly sampled from the generative model, then fitting the parameters of the generative model to maximize the data likelihood is a common method. However, since most statistical models are only approximations to the true distribution, if the model's application is to infer about a subset of variables conditional on known values of others, then it can be argued that the approximation makes more assumptions than are necessary to solve the problem at hand. In such cases, it can be more accurate to model the conditional density functions directly using a discriminative model (see below), although application-specific details will ultimately dictate which approach is most suitable in any particular case.

## Examples

### Simple example

Suppose the input data is ${\displaystyle x\in \{1,2\}}$ , the set of labels for ${\displaystyle x}$  is ${\displaystyle y\in \{0,1\}}$ , and there are the following 4 data points: ${\displaystyle (x,y)=\{(1,0),(1,0),(2,0),(2,1)\}}$

For the above data, estimating the joint probability distribution ${\displaystyle p(x,y)}$  from the empirical measure will be the following:

${\displaystyle y=0}$  ${\displaystyle y=1}$
${\displaystyle x=1}$  ${\displaystyle 1/2}$  ${\displaystyle 0}$
${\displaystyle x=2}$  ${\displaystyle 1/4}$  ${\displaystyle 1/4}$

while ${\displaystyle p(y|x)}$  will be following:

${\displaystyle y=0}$  ${\displaystyle y=1}$
${\displaystyle x=1}$  ${\displaystyle 1}$  ${\displaystyle 0}$
${\displaystyle x=2}$  ${\displaystyle 1/2}$  ${\displaystyle 1/2}$

### Text generation

Shannon (1948) gives an example in which a table of frequencies of English word pairs is used to generate a sentence beginning with "representing and speedily is an good"; which is not proper English but which will increasingly approximate it as the table is moved from word pairs to word triplets etc.

## Notes

1. ^ Three leading sources, Ng & Jordan 2002, Jebara 2004, and Mitchell 2015, give different divisions and definitions.

## References

1. ^ Ng & Jordan (2002): "Generative classifiers learn a model of the joint probability, ${\displaystyle p(x,y)}$ , of the inputs x and the label y, and make their predictions by using Bayes rules to calculate ${\displaystyle p(y|x)}$ , and then picking the most likely label y.
2. ^ Jebara 2004, 2.4 Discriminative Learning: "This distinction between conditional learning and discriminative learning is not currently a well established convention in the field."
3. ^ Ng & Jordan 2002: "Discriminative classifiers model the posterior ${\displaystyle p(y|x)}$  directly, or learn a direct map from inputs x to the class labels."
4. ^ a b Mitchell 2015: "We can use Bayes rule as the basis for designing learning algorithms (function approximators), as follows: Given that we wish to learn some target function ${\displaystyle f\colon X\to Y}$ , or equivalently, ${\displaystyle P(Y|X)}$ , we use the training data to learn estimates of ${\displaystyle P(X|Y)}$  and ${\displaystyle P(Y)}$ . New X examples can then be classified using these estimated probability distributions, plus Bayes rule. This type of classifier is called a generative classifier, because we can view the distribution ${\displaystyle P(X|Y)}$  as describing how to generate random instances X conditioned on the target attribute Y.
5. ^ a b Mitchell 2015: "Logistic Regression is a function approximation algorithm that uses training data to directly estimate ${\displaystyle P(Y|X)}$ , in contrast to Naive Bayes. In this sense, Logistic Regression is often referred to as a discriminative classifier because we can view the distribution ${\displaystyle P(Y|X)}$  as directly discriminating the value of the target value Y for any given instance X
6. ^ Ng & Jordan 2002
7. ^ Bishop, C. M.; Lasserre, J. (24 September 2007), "Generative or Discriminative? getting the best of both worlds", in Bernardo, J. M. (ed.), Bayesian statistics 8: proceedings of the eighth Valencia International Meeting, June 2-6, 2006, Oxford University Press, pp. 3–23, ISBN 978-0-19-921465-5
8. ^ a b
9. ^ a b "Generative Models". OpenAI. June 16, 2016.
10. ^ "Better Language Models and Their Implications". OpenAI. February 14, 2019.
11. ^ Brock, Andrew; Donahue, Jeff; Simonyan, Karen (2018). "Large Scale GAN Training for High Fidelity Natural Image Synthesis". arXiv:1809.11096 [cs.LG].
12. ^ Razavi, Ali; Aaron van den Oord; Vinyals, Oriol (2019). "Generating Diverse High-Fidelity Images with VQ-VAE-2". arXiv:1906.00446 [cs.LG].
13. ^ Li, Chunyuan; Gao, Xiang; Li, Yuan; Li, Xiujun; Peng, Baolin; Zhang, Yizhe; Gao, Jianfeng (2020). "Optimus: Organizing Sentences via Pre-trained Modeling of a Latent Space". arXiv:2004.04092 [cs.CL].
14. ^ "Jukebox". OpenAI. April 30, 2020.