Semi-supervised Learning by Latent Space Energy-Based Model of Symbol-Vector Coupling
Abstract
This paper proposes a latent space energy-based prior model for semi-supervised learning.
The model stands on a generator network that maps a latent vector to the observed example.
The energy term of the prior model couples the latent vector and a symbolic one-hot vector, so that classiﬁcation can be based on the latent vector inferred from the observed example.
In our learning method, the symbol-vector coupling, the generator network and the inference network are learned jointly.
Our method is applicable to semi-supervised learning in various data domains such as image, text, and tabular data.
Our experiments demonstrate that our method performs well on semi-supervised learning tasks.
Introduction
Generative modeling and likelihood-based learning is a principled framework for unsupervised and semi-supervised learning.
The energy-based model (EBM) [29], being a generative version of a discriminator, is particularly convenient for semi-supervised learning.
A notable recent paper is Grathwohl et al.
[13] which proposed the joint energy-based model (JEM) and applied it to classiﬁcation.
In an extension [46] it was applied to semi-supervised learning.
Earlier papers that touch on the relationship between modern EBM and classiﬁer parametrized by deep networks [28, 25] include [6, 43, 19, 27].
Recently, Pang et al.
[36] proposed to learn EBM in latent space, where the EBM serves as a prior model for the latent vector of a generator model that maps the latent vector to the observed example.
Both the EBM prior and the generator network can be learned jointly by maximum likelihood or its approximate or variational variants.
The latent space EBM has been applied to image modeling, text modeling, and more recently molecule generation [37].
See also the more recent developments [2, 42].
Moving EBM from data space to latent space allows the EBM to stand on an already expressive generator model, and the EBM prior can be considered a correction of the non-informative uniform or isotropic Gaussian prior of the generator model.
Due to the low dimensionality of the latent space, the EBM can be parametrized by a very small network, and yet it can capture regularities and rules in the data effectively (and implicitly).
In this paper, we move the formulation of JEM [13] to latent space, so that the latent space EBM prior becomes an associative memory that couples the dense latent vector for generation and the one-hot symbolic vector for classiﬁcation.
Given the inferred latent vector, the conditional distribution of the one-hot vector is a regular softmax classiﬁer based on the latent vector.
We learn the symbol-vector coupling, the generator network, and the inference network jointly.
Our method is applicable to semisupervised learning in various data domains such as image, text, and tabular data.
In experiments, our method demonstrates either competitive or improved performance compared to previous methods.
The symbol-vector coupling in the latent space is of independent interest in terms of the interaction between symbolic reasoning and distributed representation.
We also provide a general theoretical framework in appendix for learning latent EBM in general, where our learning method is a special case.
Model and learning 2.1 Model: symbol-vector coupling
Let x ∈ R D be the observed example.
Let z ∈ R
d be the latent vector.
Let y be the symbolic one-hot vector for classiﬁcation of K categories.
y is K -dimensional.
Our model is deﬁned by
[Equation]
where p α ( y, z ) is the prior model with parameters α , p β ( x | z ) is the top-down generation model with parameters β , and θ =
( α, β ) .
Given z , y and x are independent, i.e., z is sufﬁcient for y .
After inferring z from x , the inference of y is based on z , i.e., z is the information bottleneck [41].
The prior model p α ( y, z ) is formulated as an energy-based model,
[Equation]
where p
( z ) is a reference distribution, assumed to be isotropic Gaussian (or uniform) prior of the conventional generator model.
f α ( z ) ∈ R K is parameterized by a small multi-layer perceptron.
Z α is the normalizing constant or partition function.
The energy term (cid:104) y, f α ( z ) (cid:105) in (2) forms an associative memory that couples the symbol y and the dense vector z .
Given z ,
[Equation]
i.e., a softmax classiﬁer, where f α ( z ) provides the K logit scores for the K categories.
Marginally,
[Equation]
where the marginal energy term
[Equation]
i.e., the so-called log-sum-exponential form.
The summation can be easily computed because we only need to sum over K different values of the one-hot y .
The above prior model p α ( y, z ) stands on a generation model p β ( x | z ) , which is assumed to be the same as the top-down network in VAE [23].
In particular, x = g β ( z ) + (cid:15) , where (cid:15) ∼ N(0 , σ 2 I D ) , so that p β ( x | z ) ∼ N( g β ( z ) , σ 2 I D ) .
As in VAE, σ 2 takes an assumed value.
2.2 Prior and posterior sampling
symbol-aware continuous vector
computation
Sampling from the prior p α ( z ) and the posterior p θ ( z | x ) can be accomplished by Langevin dynamics.
For prior sampling from p α ( z ) , Langevin dynamics iterates z t +1 =
z t + s 2 ∇ z log p
α
( z t ) / 2 +
N(0 , s 2 I d ) , where s is the step size, and the gradient is computed by
[Equation]
(6) where the gradient computation involves averaging ∇ z f α ( z ) over the softmax classiﬁcation p α
( y | z ) in (3).
Thus the sampling of the continuous dense vector z is aware of the symbolic y .
Posterior sampling from p θ ( z | x ) follows a similar scheme, where
[Equation]
When the dynamics is reasoning about x by sampling the dense continuous vector z from p θ ( z | x ) , it is aware of the symbolic y via the softmax p
α
( y | z ) .
Thus ( y, z ) forms a duality between symbol and dense vector, i.e., they are two sides of a single “sym-vec coin.”
The entropy of p α
( y | z ) may determine whether the symbolic interpretation will pop out from z .
Pang et al.
[36] proposed to use prior and posterior sampling for maximum likelihood learning.
Due to the low-dimensionality of the latent space, MCMC sampling is affordable and mixes well.
Comparing prior and posterior sampling, prior sampling is particularly affordable, because f α ( z ) is a small network.
In comparison, ∇ z log p β ( x | z ) in the posterior sampling requires back-propagation through the generator network, which can be more expensive.
Therefore we shall amortize the posterior sampling from p β ( x | z ) by an inference network, as detailed in the next subsection.
2.3 Amortizing posterior sampling and variational learning
Similar to VAE [23], we recruit an inference network q φ ( z | x ) to approximate the true posterior p θ ( z | x ) , in order to amortize posterior sampling.
Following VAE, we learn the inference model q φ ( z | x ) and the top-down model p θ ( z, x ) jointly.
For unlabeled x , the log-likelihood log p θ ( x ) is lower bounded by the evidence lower bound (ELBO),
[Equation] [Equation]
where D KL denotes the Kullback-Leibler divergence.
For the prior model, the learning gradient is
[Equation]
(10) where F α ( z ) is deﬁned by (5), E q φ ( z | x ) is approximated by samples from the inference network, and
E p
α
( z ) is approximated by persistent MCMC samples from the prior.
Let ψ = { β, φ } collect the parameters of the inference (encoder) and generator (decoder) models.
The learning gradients for the two models are
[Equation]
where D KL ( q φ ( z | x ) (cid:107) p 0 ( z )) is tractable and the expectations in the other two terms are approximated by samples from the inference network q φ ( z | x ) with reparametrization trick [23].
VAE is employed for training latent space EBM in recent work [2, 42].
In our work, we train the inference network jointly with the latent space EBM.
We only need to include the extra F α ( z ) term, and log Z α is a constant that can be discarded.
This expands the scope of VAE where the top-down model is a latent EBM.
As mentioned above, we shall not amortize the prior sampling from p α ( z ) due to its simplicity, and due to the fact that sampling p α ( z ) is only needed in the training stage, but is not required in the testing stage.
In general, we can also amortize the sampling of p α ( z ) by a ﬂow-based model [9, 10].
See appendix for a general theoretical formulation.
2.4 Labeled data
For a labeled example ( x, y ) , the log-likelihood can be decomposed into log p θ ( x, y )
= log p θ ( x ) + log p θ ( y | x ) .
The gradient of log p θ ( x ) can be computed in the same way as the unlabeled data, and
[Equation]
(12) where p θ ( y | z ) is the softmax classiﬁer deﬁned by (3), and q φ ( z | x ) is the learned inference network.
Thus ∇ θ log p θ ( y | x ) ≈ ∇ θ log E q φ ( z | x ) [ p θ ( y | z )] .
The gradients backpropagate to both the EBM prior and the inference network.
For semi-supervised learning, we can combine the learning gradients from both unlabeled and labeled data.
2.5 Algorithm
The learning and sampling algorithm is described in Algorithm 1.
Algorithm
Posterior
the
network and
trick.
Unsupervised learning of
[Equation]
Unsupervised learning of inference and generator models :
[Equation]
Supervised
of prior and inference model
[Equation]
Related work
Discriminative models.
Recent semi-supervised learning (SSL) methods based on discriminative models have achieved substantial progress.
Most of these methods rely on data augmentation strategies which heavily exploit class-invariance properties of images [3, 40].
Invariance properties for text and tabular data are however less clear.
One successful method, virtual adversarial training (VAT) [31], does not depend on image-domain-speciﬁc properties.
Instead, it ﬁnds an adversarial augmentation to x within an (cid:15) -ball of x with respect to l p norm such that the distance between the class distribution conditional on x and that conditional on the augmentation is maximized.
This approach is applicable to continuous data beyond images like tabular data.
It nevertheless still has the limitation on discrete data since the adversarial augmentation requires the data space to be differentiable.
GANs.
Generative models in the GAN family have also been applied to SSL and exhibited promising results.
Salimans et al.
[39] changed the discriminator in GAN to be a classiﬁer with an extra "generated" class, which is thus able to simultaneously distinguish real and generated samples and to predict class labels.
To avoid the incompatible roles of the classiﬁer and discriminator, Li et al.
[5] proposed to keep the discriminator in the original GAN and add a classiﬁer for class prediction.
Dai et al.
[7] argued that a preferred generator for SSL should be a complement generator in the sense that it should assign high densities for data points with low densities in the data distribution.
These
GAN-based SSL methods generally perform well on images, competitive with discriminative models.
However, GANs are highly tuned to image data.
The adversarial generative training relies on the differentibility of data generation and applying it to discrete data like text with does not exhibit much gain if no harm is caused [4].
Energy-based model.
Recently EBMs have also been applied to SSL.
Grathwohl et al.
[13] proposed
Joint Energy-based Model (JEM) on top of a regular discriminative classiﬁer by re-interpreting the logits.
Zhao et al.
[46] extended JEM to SSL and obtained reasonable performance.
With a similar formulation, Gao et al.
[11] adversarially trained the EBM with a pretrained GLOW [21] and obtained performance competitive with GAN-based and discriminative models, especially after it is combined with VAT.
Our model shares similarities with these models in that our model has a latent space EBM and it is constructed through re-using the logits of a discriminative classiﬁer in the latent space.
Our
EBM in the latent space however has a much lower dimension and smoother landscape, which renders fast sampling and mixing.
The learning also does not require expensive pretraining of GLOW like in
Also, it is not easy to apply data space EBM to discrete data since its training requires either the data space or the generation process of the auxiliary generator (e.g., GLOW) to be differentiable.
Likelihood-based models.
In a seminal work [22], Kingma et al. adopted VAE for SSL where a discrete latent variable, y , representing the class labels is introduced in addition to the usual continuous vector, z .
In [30], adversarial training was applied to force y and z to capture disentangled semantics.
In our model, the continuous vector is coupled with the discrete variable or symbol to form a latent space EBM prior.
More recently, Izmailov et al.
[18] proposed a ﬂow-based model,
FlowGMM, where the data distribution is mapped to a Gaussian mixture in the latent space with invertible ﬂow.
Our model is similar in the sense that it uses an inference network to map the data distribution to an latent space EBM.
But our model does not have the restriction of invertibility.
FlowGMM is aimed for broad applicability and demonstrate promising results on text and tabular data, sharing the goal of our work.
Experiments
We evaluate our model on a wide variety of datasets to demonstrate the broad applicability of our model.
We begin the evaluation with image data which most SSL research works have been focused on.
Next we consider text data in both continuous and discrete situations.
Finally, our model is assessed on tabular data.
Two recent works applied their methods, FlowGMM [18] and JEM [46], beyond image data and these two models are closely related to ours.
They thus serve as important baselines of our model.
For image experiments, the inference network is implemented with a standard Wide ResNet [44], widely used in image SSL works [35].
The generator network is a 4-layer deconvoluational network, similar to the generator in DCGAN [38].
The inference and generator networks in text and tabular experiments are all a 3-layer MLP.
The latent EBM prior in all experiments is also a small 3-layer
MLP with a hidden dimension of 200.
All model parameters are initialized with Xavier normal [12].
Adam [20] is adopted for all model optimization.
The models are trained until convergence (taking approximately 400,000 parameter updates for image models, 100,000 updates for text models without pretrained embeddings, 3,000 updates for text models with pretrained embeddings, 4, updates for tabular models).
We run 20 steps of persistent chains with step size 0 .
6 to obtain MCMC samples used in learning the latent space EBM prior (i.e., Step 4 in Algorithm 1).
Notice that MCMC sampling only needs to compute the gradients of the small latent space EBM and does not need to backpropagate through the larger generator.
4.1 Image
Standard image SSL benchmarks, SVHN [32], with 1,000 labeled data and 64,932 unlabeled data, and CIFAR-10 [24], with 4,000 labeled data and 41,000 unlabeled data, are adopted to assess our model on image classiﬁcation.
The results are summarized in Tabel 1.
Besides FlowGMM [18] and JEM [46], we also compare our model to other likelihood-based models, VAE M1+M
AAE [30], in addition to representative GAN-based models, TripleGAN [5], BadGAN [7] and discriminative models, Π -Model [26] and VAT [31].
Our model outperforms FlowGMM and JEM and other likelihood-based models.
The improvement is especially clear on SVHN (with almost 10% absolute improvement compared to FlowGMM).
We however observe a performance gap between our model and GAN-based and discriminative methods which highly tuned for images.
4.2 Text
We evaluate our model on text with a widely used text classiﬁcation dataset, AGNews [45], in two settings.
The ﬁrst one follows the evaluation protocol used in FlowGMM [18].
Text data are ﬁrst embedded by a pretrained language model, BERT [8], and the SSL model is constructed on the embedding space.
We use the preprocesed data provided by [18] which contains 200 labeled data and 120,000 unlabled data are used in training.
AGNews has 4 classes.
Our model is compared to
FlowGMM [18], RBF Label Spreading (a graph-based label spreading method) [47], and Π -Model [26].
Table 2 displays the results.
Our model exhibits competitive performance with FlowGMM and outperforms other baselines.
[Table]
The second setting where a large pretrained language model is not available follows the setup used in
Gururangan et al.
[14] where they proposed VAMPIRE.
While the huge amount of text data required for large transformer-based language model pretraining is available for some languages, such as
English, this scale of data is not available for all languages.
We use the preprocessed data provided by [14] and it contains 200 labeled data and 114,600 unlabeled documents for training.
Follow [14], a document is modeled by the unigram of its words.
Thus, each document is a vector of vocabulary size, V ( V = 30 , 000 for AGNews), and each element represents a word’s occurring frequency in the document, modeled by a multinominal distribution.
Notice that most popular SSL methods, such as
GAN-based models, data space EBM, and VAT, cannot be easily applied in this case since the data space is discrete.
We compare our model to VAMPIRE using unigram representation, self-training, and supervised training with Glove word embeddings pretrained on in-domain and out-domain data (see [14] for detailed descriptions of these baselines).
The results are summarized in Table 3.
Our model clearly outperforms these baselines.
It is worth pointing that FlowGMM is also applicable in this setting.
We attempted to apply FlowGMM to this task but achieved low accuracy.
[Table] [Table]
4.3 Tabular data
We use three tabular datasets from the UCI repository.
Hepmass and Miniboone were utilized in [18] for SSL and Protein was used in [46].
Protein has a continuous target variable and we follow [46] to bin the targets into 10 equally weighted buckets.
We use the same experimental settings as in the two prior works.
The number of labeled / unlabeled data for Hepmass, Miniboone
[Table]
and Protein are 20/140,000, 20/65,000, 100/41,057 respectively.
Hepmass and Miniboone have 2 classes, while
Protein has 10 classes.
We compare our model to RBF Label Spreading, JEM, FlowGMM, Π -Model, and VAT.
Tabel 4 summarizes the results.
Our model outperforms all baselines across the three tabular datasets.
[Table]
Conclusion
Semi-supervised learning based on latent space EBM prior with symbol-vector coupling is very natural.
For unlabeled data, the marginal EBM prior is in the form of sum of exponentials.
For labeled data, the conditional distribution of label given the inferred latent vector is a regular softmax classiﬁer.
The semi-supervised learning can be based on a principled likelihood-based framework, with inference computation being amortized by a variational inference network.
Our model may be interpreted as a generative classiﬁer, where the latent vector used for classiﬁcation is inferred based on a top-down generative model.
The top-down model and the posterior inference captures the concept of information bottleneck [41] more naturally than bottom-up classiﬁer.
The posterior inference of a top-down model may be more robust to adversarial perturbations than a classiﬁer deﬁned on the input directly, because the posterior inference can explain away the adversarial perturbations via the top-down model.
The inference of the latent vector is aware of the underlying symbol, and the symbol-vector coupling in our prior model may shed light on the interaction between symbolic reasoning and continuous computation.
We may consider a multi-layer top-down model where each layer consists of dense sub-vectors coupled with symbolic one-hot sub-vectors, so that continuous computation based on dense sub-vectors is aware of the corresponding symbols.
Our experiments show that our semi-supervised learning method outperforms existing methods on text and tabular data.
We shall continue to improve our method on image data.
To rephrase the title of this workshop, we cannot believe our principled model-based semi-supervised learning method does not work better than existing methods on image data. Acknowledgement
We thank the reviewers for their insightful comments and suggestions.
The work is supported by NSF
DMS-2015577.
Appendix: learning latent EBM with divergence perturbation formulation
This section provides a theoretical formulation for learning latent EBM in general, where our model is a special case.
We can embed our learning method within this general formulation.
The latent EBM is of the following form:
[Equation]
Marginally, p θ ( x ) = (cid:82) p θ ( z, x ) dz , and the posterior is p θ ( z | x ) =
p θ ( z, x ) /p
θ ( x ) .
Let p data ( x ) be the data distribution that generates x .
Maximum likelihood estimation (MLE) minimizes D KL ( p data ( x ) (cid:107) p θ ( x )) , where expectation with respect to p data can be approximated by averaging over observed examples.
Learning of latent EBM can be based on the following divergence perturbation (see [15, 16] for related formulations), [Equation]
[Equation]
which is a perturbation of the divergence D KL ( p data ( x ) (cid:107) p θ ( x )) that underlies MLE.
q
+ ( z | x ) is the positive phase sampler, and q − ( z, x ) is the negative phase sampler.
They correspond to the positive phase and negative phase of MLE learning of latent EBM such as Boltzmann machine [1].
For two distributions q ( z | x ) and p ( z | x ) , we deﬁne D KL ( q ( z | x ) (cid:107) p ( z | x )) =
[Equation] [Equation] ( q ( z | x ) /p
( z | x )] , with an outer expectation with respect to p data .
The divergence D KL ( p data ( x ) (cid:107) p θ ( x )) for MLE is perturbed by the positive phase divergence D KL ( q + ( z | x ) (cid:107) p θ ( z | x )) and the negative phase divergence D
KL ( q − ( z, x ) (cid:107) p θ ( z, x )) .
For latent space EBM prior, we have the factorization p
θ ( z, x ) =
p α ( z ) p β ( x | z ) , and q − ( z, x ) =
q − ( z ) p β ( x | z ) , so that the negative phase D KL in (14) becomes D KL ( q − ( z ) (cid:107) p
α ( z )) , i.e., the KL divergence between the priors.
The above formulation has the following features.
[Equation] ) Gradient of divergence perturbation ∆ can be calculated explicitly without intractable integrations in p θ ( x ) and log Z θ , because p θ ( x ) is merged with p θ ( z | x ) to become p θ ( z, x ) due to the positive phase D KL term, and the log Z θ is canceled by the negative phase D KL term.
(2) For MLE learning, at iteration t , let θ t be the current estimate of θ .
We let q
+ ( z | x ) =
p θ t ( z | x ) and q − ( z, x ) =
p θ t ( z, x ) .
In this case, the positive phase D KL ( q + ( z | x ) (cid:107) p θ ( z | x )) achieves its minimum 0 at θ t , so that its gradient at θ t is 0.
Similarly the negative phase D KL ( q − ( z, x ) (cid:107) p θ ( z, x )) achieves its minimum 0 at θ t too, so that its gradient at θ t is also 0.
Thus the gradient of the divergence perturbation ∆ in (14) is the same as the MLE gradient of the ﬁrst KL term D KL ( p data ( x ) (cid:107) p θ ( x )) .
(3) For amortized computation, q + ( z | x )
=
q φ + ( z | x ) is an inference network, and q − ( z, x ) =
q φ − ( z, x ) is a synthesis network, with parameters φ + and φ − respectively, that are independent of the model parameter θ .
The learning can be based on min θ min φ + max φ − ∆ .
The positive phase D
KL leads to variational learning.
The negative phase D KL leads to a generalized form of contrastive divergence [17], as well as adversarial interpretation due to the negative sign and max φ − .
For latent space EBM prior, we only need a synthesis network q φ − ( z ) to approximate the prior model p α ( z ) .
We may consider using a ﬂow-based model [9, 10] for q φ − ( z ) .
In our current work, we employ an inference network for q φ + ( z | x ) , but we leave q − ( z ) to MCMC sampling, because p α ( z ) is very simple, and sampling of p α ( z ) does not require back-propagation through the generator network.
Moreover, sampling p α ( z ) is not needed in the testing stage.
In between (2) and (3), both q + ( z | x ) and q − ( z, x ) can be sampled by short-run MCMC for inference and synthesis [33, 34].
The short-run MCMC runs a ﬁxed number of MCMC iterations from a ﬁxed initial distribution, so that both q + ( z | x ) and q − ( z, x ) are well deﬁned.
The gradient of ∆ in (14) based on short-run MCMC is a perturbation of the MLE learning gradient.
The MLE learning gradient is impractical because it requires convergence of MCMC.
Learning algorithm based on short-run MCMC converges to the solution of an estimating equation which is a perturbation of the MLE estimating equation.
The learning algorithm of Pang et al.
[36] works within this scheme.
The above formulation encompasses many generative models and associated learning algorithms.
It helps us understand the model and learning algorithm proposed in this paper.
It will also help us develop new models and algorithms.