C ONTRASTIVE ESTIMATION REVEALS TOPIC POSTERIOR INFORMATION TO LINEAR MODELS
Anonymous authors
Paper under double-blind review
A BSTRACT
Contrastive learning is an approach to representation learning that utilizes naturally occurring similar and dissimilar pairs of data points to ﬁnd useful embeddings of data.
In the context of document classiﬁcation under topic modeling assumptions, we prove that contrastive learning is capable of recovering a representation of documents that reveals their underlying topic posterior information to linear models.
We apply this procedure in a semi-supervised setup and demonstrate empirically that linear classiﬁers with these representations perform well in document classiﬁcation tasks with very few training examples
I NTRODUCTION
Using unlabeled data to ﬁnd useful embeddings is a central challenge in representation learning.
Classical approaches to this task often start by ﬁtting some type of structure to the unlabeled data, such as a generative model or a dictionary, and then embed future data via inference with the ﬁtted structure (Blei et al., 2003; Raina et al., 2007).
While principled, this approach is not without its drawbacks.
One issue is that learning structures and performing inference is often hard in general (Sontag & Roy, 2011; Arora et al., 2012).
Another issue is that we must a priori choose a structure and method for ﬁtting the unlabeled data, and unsupervised methods for learning these structures can be sensitive to model misspeciﬁcation (Kulesza et al., 2014).
Contrastive learning (also called noise contrastive estimation, or NCE) is an alternative representation learning approach that tries to capture the latent structure in unlabeled data implicitly.
At a high level, these methods formulate a classiﬁcation problem in which the goal is to distinguish examples that naturally occur in pairs, called positive samples, from randomly paired examples, called negative samples.
The particular choice of positive samples depends on the setting.
In image representation problems, for example, patches from the same image or neighboring frames from videos may serve as positive examples (Wang & Gupta, 2015; Hjelm et al., 2018).
In text modeling, the positive samples may be neighboring sentences (Logeswaran & Lee, 2018; Devlin et al., 2018).
The idea is that in the course of learning to distinguish between semantically similar positive examples and randomly chosen negative examples, we will capture some of the latent semantic information.
In this work, we look “under the hood” of contrastive learning and consider its application to document modeling, where the goal is to construct useful vector representations of text documents in a corpus.
In this setting, there is a natural source of positive and negative examples: a positive example is simply a document from the corpus, and a negative example is one formed by pasting together the ﬁrst half of one document and the second half of another (independently chosen) document.
We prove that when the corpus is generated by a topic model, learning to distinguish between these two types of documents yields representations that are closely related to their underlying latent variables.
One potential application of contrastive learning is in a semi-supervised setting, where there is a small amount of labeled data as well as a much larger collection of unlabeled data.
In these situations, purely supervised methods that ﬁt complicated models may have poor performance due to the limited amount of labeled data.
On the other hand, when the labels are well-approximated by some function of the latent structure, our results show that an effective strategy is to ﬁt linear functions, which may be learned with relatively little labeled data, on top of contrastive representations.
In our experiments, we verify empirically that this approach produces reasonable results.
Contributions.
The primary goal of this work is to shed light on what contrastive learning techniques uncover in the presence of latent structure.
To this end, we focus on the setting of document modeling where latent structure is induced by a topic model.
Here, our contrastive learning objective is to distinguish true documents from ‘fake’ documents that are composed by randomly pasting together two document halves from the corpus.
We consider two types of architectures or functional forms of solutions for this problem, both trained with logistic loss.
The ﬁrst architecture, on which our theoretical analysis will focus, consists of general functions of the form f ( · , · ) .
Here, we have trained f so that f ( x, x (cid:48) ) indicates the conﬁdence of the model that x and x (cid:48) are two halves of the same document.
To embed a new document x using f , we propose a landmark embedding procedure: ﬁx documents l 1 , . . .
, l M (our so-called landmarks) and create the embedding φ ( x ) using a function of the predictions f ( x, l 1 ) , . . . ,
f ( x, l M ) .
In Section 4, we show that the embedding φ ( x ) is a linear transformation of the underlying topic posterior moments of x .
Moreover, under certain conditions this linear relationship is invertible, so that linear functions of φ ( x ) correspond to polynomial functions of the topic posterior of document x .
In Section 5, we show that errors in f on the contrastive learning objective transfer smoothly to errors in φ ( x ) as a linear transformation of the topic posterior of x .
Thus, as the quality of f improves, linear functions of φ ( x ) more closely approximate polynomial functions of the topic posterior of document x .
Unfortunately, the landmark embedding can require quite a few landmarks before our theoretical results kick in.
Moreover, embedding a document requires M evaluations of f , which can be expensive.
To circumvent this, in Section 7 we introduce a direct embedding procedure that more closely matches what is done in practice.
We use an architecture of the form f 1 ( x ) T f 2 ( x (cid:48) ) where f 1 , f 2 are functions with d -dimensional outputs, and we train this architecture on the same contrastive learning task as before.
To embed a document x , we simply use the evaluation f 1 ( x ) .
In Section 7, we evaluate this embedding on a semi-supervised learning task, and we show that it has reasonable performance.
Indeed, the direct embedding method outperforms the landmark embedding method, which raises the question of whether or not anything can be theoretically proven about the direct embedding method.
We leave this question to future work.
Related work.
Reducing an unsupervised problem to a synthetically-generated supervised problem is a well-studied technique.
In dynamical systems modeling, Langford et al.
(2009) showed that the solutions to a few forward prediction problems can be used to track the underlying state of a nonlinear dynamical system.
For linear dynamics, the idea is also seen in autoregressive models (Yule, 1927).
In anomaly/outlier detection, a useful technique is to learn a classiﬁer that distinguishes between true samples from a distribution and fake samples from some synthetic distribution (Steinwart et al., 2005;
Abe et al., 2006).
Similarly, estimating the parameters of a probabilistic model can be reduced to learning to classify between true data and randomly generated noise (Gutmann &
Hyv ¨ arinen, 2010).
In the context of natural language processing, methods such as skip-gram and continuous bag-ofwords turn the problem of ﬁnding word embeddings into a prediction problem (Mikolov et al., 2013a;b).
Modern language representation training algorithms such as BERT and QT also use naturally occurring classiﬁcation tasks such as predicting randomly masked elements of a sentence or discriminating whether or not two sentences are adjacent (Devlin et al., 2018; Logeswaran & Lee, 2018).
Training these models often employs a technique called negative sampling, in which softmax prediction probabilities are estimated by randomly sampling examples; this bears close resemblance to the way that negative examples are produced in contrastive learning.
Most relevant to the current paper, Arora et al.
(2019) gave a theoretical analysis of contrastive learning.
They considered the speciﬁc setting of trying to minimize the contrastive loss
[Equation]
where ( x, x + ) is a positive pair and ( x, x − ) is a negative pair.
They showed that if there is an underlying collection of latent classes and positive examples are generated by draws from the same class, then minimizing the contrastive loss over embedding functions f yields good representations for the classiﬁcation task of distinguishing latent classes.
The main difference between our work and that of Arora et al.
(2019) is that we adopt a generative modeling perspective and induce the contrastive distribution naturally, while they do not make generative assumptions but assume the contrastive distribution is directly induced by the downstream Input Corpus for i n do Sample from
; S ← S
(cid:40) { ( x (1) , x (2) , 1) } w.p. 1 /{ ( x (1) , ˜ x (2) , 0) } w.p. 1 /end for Solve the optimization problem [Equation]
Select classiﬁcation task.
In particular, our contrastive distribution and supervised learning problem are only indirectly related through the latent variables in the generative model, while Arora et al.
assume an explicit connection.
The focus of our work is therefore complementary to theirs: we study the types of functions that can be succinctly expressed with the contrastive representation in our generative modeling setup.
In addition, our results apply to semi-supervised regression, but it is unclear how to deﬁne their contrastive distribution in this setting; this makes it difﬁcult to apply their results here.
Finally, Arora et al.
point out the method they study has limitations that arise when the number of latent classes is small and the probability of negative samples having the same class is high.
In our setting, class collisions turn out not to be a problem since our embeddings explicitly utilize conditional probability information from the solution to our contrastive learning objective.
S ETUP
Let V denote a ﬁnite vocabulary.
A topic is a distribution over V .
We will assume that we have K such topics, and denote the corresponding distributions as O ( · | k ) for k = 1 , . . .
, K .
To generate a length m document x , one ﬁrst draws a vector w from ∆ K , the K -dimensional probability simplex, and then samples each of the m words x 1 , . . .
, x m by ﬁrst sampling the latent variable z i ∼ w and drawing x i ∼ O ( · | z i ) .
We note that documents are allowed to take different lengths.
We will also be interested in the case where each document has an associated label (cid:96) ∈ R .
One natural restriction to make on a label is that it is conditionally independent of the document given the topic distribution of the document.
Thus, we will assume that there is a joint distribution D of triples ( x, w, (cid:96) ) , where ( x, w ) are generated according to the topic model described above, and then (cid:96) is drawn from some distribution conditioned on w .
One of the goals of this paper is to characterize the functional forms of this conditional distribution that are most suited to contrastive learning.
In the representation learning approach to the semi-supervised setting, we are given a large collection
U of documents with no labels, and a small collection L of labeled documents.
Using U , we learn a feature map ˆ φ that will form the basis of our predictions.
Then, using L , we learn a simple predictor based on ˆ φ , such as a linear function, to predict the label (cid:96) given ˆ φ ( x ) .
C ONTRASTIVE LEARNING ALGORITHM
In contrastive learning, examples come in the form of similar and dissimilar pairs of points, where the exact deﬁnition of similar/dissimilar depends on the task at hand.
Our construction of similar pairs will take the form of randomly splitting a document into two documents, and our dissimilar pairs will consist of subsampled documents from two randomly chosen documents.
In the generative modeling setup, since the words are i.i.d.
conditional on the topic distribution, a natural way to split a document x into two is to call the ﬁrst half of the words x (1) and the second half x (2) .
In our experiments, we split the documents by applying a random permutation to the word tokens and partitioning in half, thus effectively ignoring the word ordering (as is common in topic models).
The contrastive representation learning procedure is displayed in Algorithm 1.
It uses a ﬁnite-sample approximation to the contrastive distribution D contrast described as follows: (a) sample a document x and partition it into ( x (1) , x (2) ) , (b) with probability 1 / 2 output ( x (1) , x (2) , 1) , (c) with probability 1 / 2 , sample a second document (˜ x (1) , ˜ x (2) ) and output ( x (1) , ˜ x
For ( x, x (cid:48) , y ) ∼ D contrast , the parts x and x (cid:48) are the two halves of a (possibly synthetic) document, and y is the binary label.
Our contrastive learning objective is to minimize the binary cross-entropy loss of discriminating between positive and negative examples:
[Equation]
In our algorithm, we approximate this expectation via sampling and optimize the empirical objective, which yields an approximate minimizer ˆ f (chosen from some function class F ).
To see why optimizing this contrastive learning objective is so useful, let f (cid:63) be the global minimizer of Eq.
By Bayes’ theorem we have that g (cid:63) :=
exp( f (cid:63) ) satisﬁes the following:
[Equation]
Thus, g (cid:63) ( x, x (cid:48) ) captures the ratio of the probability of x and x (cid:48) co-occurring as the ﬁrst and second halves of the same document and the product of their marginal probabilities.
In Eq.
(1), we have not imposed any constraints on the functions over which we are optimizing.
Thus, we seek to extract a useful embedding from g (cid:63) using only black box access to g (cid:63) .
Our approach to this problem is to select some set of ﬁxed documents, which we call landmarks , and to embed by utilizing the predictions of g (cid:63) on these landmarks.
Formally, we select documents l 1 , . . .
, l M and represent document x as
[Equation]
This yields the ﬁnal document-level representation, which can be used for downstream tasks.
As we shall see in Section 4, when the documents have an underlying topic structure, φ (cid:63) ( x ) is related to the posterior information of the topics by a linear transformation and this linear transformation is invertible whenever the landmarks l 1 , . . .
, l M are sufﬁciently diverse.
In practice, we only have access to an approximate minimizer ˆ f of Eq.
Thus, our embedding in practice will be given by
[Equation]
In Section 5 we will see that, under some mild assumptions, our claims about φ (cid:63) also hold true for ˆ φ up to some small errors.
Finally, we point out that there is nothing special about the binary cross-entropy loss.
We may replace this loss in Eq.
(1) with any proper scoring rule (Shuford et al., 1966; Buja et al., 2005), so long as the appropriate non-linear transformation is applied to the resulting predictions.
R ECOVERING TOPIC STRUCTURE
In this section, we focus on expressivity of the contrastive representation, showing that polynomial functions of the topic posterior can be represented as linear functions of the representation.
To do so, we ignore statistical issues and assume that we have access to the oracle representations g (cid:63) ( x, · ) .
In Section 5, we address statistical issues.
Recall the generative topic model process for a document x .
We ﬁrst draw a topic vector w ∈ ∆ K .
Then for each word i = 1 , . .
. , length ( x ) , we draw z
i ∼ Categorical ( w ) and x i ∼ O ( · | z i ) .
We will show that when documents are generated according to the above model, the embedding of a document x in Eq.
(2) is closely related its underlying topic vector w .
4. T HE SINGLE TOPIC CASE
To build intuition for the embedding in Eq.
(2), we ﬁrst consider the case where each document’s probability vector w is supported on a single topic, i.e., w ∈ { e 1 , . .
, e K } where e i is the i th standard basis element.
Then we have the following lemma.
Lemma 1.
For any documents x, x (cid:48) , we can write g (cid:63) ( x, x (cid:48) )
=
η ( x ) T ψ ( x (cid:48) ) , where η ( x ) k := P ( w = e k | x (1) = x ) is the topic posterior distribution and ψ ( x ) k :
= P ( x (2) = x | w = e k ) / P ( x (2) =
x (cid:48) ) .
Due to space constraints, all proofs are deferred to Appendix C and Appendix D.
The characterization from Lemma 1 shows that g (cid:63) contains information about the posterior topic distribution η ( · ) .
To recover it, we must make sure that the ψ ( · ) vectors for our landmark documents span R K .
Formally, if l 1 , . .
, l M are the landmarks, and we deﬁne the matrix L ∈ R K × M by
[Equation]
then our representation satisﬁes φ (cid:63) ( x ) =
L T η ( x ) .
If our landmarks are chosen so that L has rank
K , then L † φ (cid:63) ( x ) =
η ( x ) , where † denotes the matrix pseudo-inverse.
Thus, there is a linear transformation of φ (cid:63) ( x ) that recovers the posterior distribution of w given x .
There are two observations to be made here.
The ﬁrst is that this argument naturally generalizes beyond the single topic setting to any setting where w can take values in a ﬁnite set S , which may include some mixtures of multiple topics, though the number of landmarks needed would grow at least linearly with | S | .
The second is that we have made no use of the structure of x (1) and x (2) , except for that they are independent conditioned on w .
Thus, this argument applies to more exotic ways of partitioning a document beyond the bag-of-words approach.
4. T HE GENERAL SETTING
In the general setting, we allow document vectors to be any probability vector in ∆ K , and we do not hope to recover the full posterior distribution over ∆ K .
However, the intuition from the single topic case largely carries over, and we will show that we can still recover the posterior moments.
Let m max be the length of the longest landmark document.
Let S Km :
= { α ∈ Z K + : (cid:80) k
α k = m } denote the set of non-negative integer vectors that sum to m and let S K ≤ m max
=
S K 0 ∪ · · · ∪ S Km max .
Let π ( w ) denote the degree- m max monomial vector in w : π ( w ) :
= ( w α 1 1 · · · w α k k : α ∈ S K ≤ m max ) .
For a positive integer m and a vector α ∈ S Km , we let (cid:0) [ m ] α (cid:1) :
= { z ∈ [ K ] m : (cid:80) mi
=1 1 I [ z i = k ] =
α k ∀ k ∈ [ K ] } .
For a document x of length m , the degree- m polynomial vector ψ m is deﬁned by
[Equation]
and let ψ d ( x ) = (cid:126)
for all d (cid:54) = m .
The cumulative polynomial vector ψ is given by
[Equation]
Given these deﬁnitions, we have the following general case analogue of Lemma 1.
Lemma 2.
For any documents x, x (cid:48) , we may write g (cid:63) ( x, x (cid:48) )
=
η ( x ) T ψ ( x (cid:48) )
where η ( x ) :=
E [ π ( w ) | x (1) =
x ] and ψ is deﬁned in Eq (4) .
Thus, we again have φ (cid:63) ( x ) =
L T η ( x ) , but the columns of L are now vectors ψ ( l i ) from Eq.
Our analysis, so far, shows that if we choose the landmarks such that LL T is invertible, then our representation captures all moments of the topic posterior up to degree m max .
As the next theorem shows, we can ensure that LL T is invertible whenever each topic has an associated anchor word (Arora et al., 2012), i.e., a word that occurs with positive probability only within that topic.
In this case, there is a set of landmarks l 1 , . . .
, l M such that any polynomial of η ( x ) can be expressed as a linear function of φ (cid:63) ( x ) .
Theorem 3.
Suppose that (i) each topic has an associated anchor word, and (ii) the marginal distribution of w has positive probability on the interior of ∆ K .
For any d o ≥ 1 , there is a collection of M =
O ( K d o ) landmark documents l 1 , . . .
, l M such that if Q ( w ) is a degree- d o polynomial in w , then there is a vector θ ∈ R M such that (cid:104) θ, φ (cid:63) ( x ) (cid:105) =
E [ Q ( w ) | x (1) =
x ] for all documents x .
Coupling Theorem 3 with the Stone-Weierstrass theorem (Stone, 1948) shows that, in principle, the posterior mean of any continuous function of w can be approximated using our representation.
E RROR ANALYSIS
Given a ﬁnite amount of data, we cannot hope to solve Eq.
(1) exactly.
Thus, our solution ˆ f will only be an approximation to f (cid:63) .
Since ˆ f is the basis of our representation, one may worry that errors incurred in this approximation will cascade and cause the approximate representation φ ( x ) to differ so wildly from φ (cid:63) ( x ) that the results of Section 4 do not even approximately hold.
In this section, we will show that, under certain conditions, such fears are unfounded.
Speciﬁcally, we will show that there is an error transformation from the approximation error of ˆ f to the approximation error of linear functions in ˆ φ .
That is, if the target function is η ( x ) T θ (cid:63) , then we will show that the best mean squared error achievable using our approximate representation ˆ φ , given by
[Equation]
is bounded in terms of the approximation quality of ˆ f as well as some other terms.
Here, µ (1) is the marginal distribution over ﬁrst halves of documents drawn from D .
Thus, for the speciﬁc setting of semi-supervised learning, an approximate solution to Eq.
(1) is good enough.
There are a number of reasonable ways to choose landmark documents.
Here we consider a simple method: randomly sample them from the marginal distribution µ (2) of x (2) .
We will assume that this distribution satisﬁes certain regularity properties.
Assumption 1.
There is a constant σ min > 0 such that for any δ ∈ (0 , 1) , there is a number M 0 such that for an i.i.d.
sample l 1 , . . .
, l M from µ (2) , with M ≥ M 0 , with probability 1 − δ , the matrix L in
Eq.
(3) (with ψ as deﬁned in Lemma 1 or Eq.
(4) ) has minimum singular value at least σ min √ M .
Note that the smallest non-zero singular value of 1 √ M L is the square-root of the smallest eigenvalue of a certain empirical second-moment matrix.
Hence, Assumption 1 holds under appropriate conditions on the landmark distribution, for instance via tail bounds for sums of random matrices (Tropp, 2012) combined with matrix perturbation analysis (e.g., Weyl’s inequality).
In the single topic setting with anchor words, it can be shown that for long enough documents, σ min is lower-bounded by a constant when M 0 grows polynomially with K .
We defer a detailed proof of this to Appendix D.
We will also assume that the predictions of ˆ f and f (cid:63) bounded above by some constant.
Assumption 2.
There exists some g max > 0 such that ˆ f ( x, l i ) , f (cid:63) ( x, l i ) ≤ log g max for all documents x and landmarks l i .
Note that if Assumption 2 holds for f (cid:63) , then it can be made to hold for ˆ f by clipping.
Moreover, it holds for f (cid:63) whenever the vocabulary and document sizes are constants:
[Equation]
Since landmarks are sampled, and the number of possible documents is ﬁnite, there exists a constant p min > 0 such that P ( x (2) = l ) ≥ p min .
Thus, Assumption 2 holds for g max ≤ 1 /p min .
Given these assumptions, we have the following error transformation guarantee.
Theorem 4.
Fix any δ ∈ (0 , 1) , and suppose Assumption 1 and Assumption 2 hold (with M 0 , σ min , and f max ).
Let ˆ f be the function returned by the contrastive learning algorithm, and let ε : =
L contrast ( ˆ f ) − L contrast ( f (cid:63) ) denote its excess contrastive loss.
If M ≥ M 0 , then with probability [Figure] least
[Equation]
We make a few observations here.
First, (cid:107) θ
(cid:63) (cid:107) 22 is a measure of the complexity of the target function.
Thus, if the target function is some reasonable function (e.g., low-degree polynomial) of the posterior document vector, then we can expect (cid:107) θ (cid:63) (cid:107) 22 to be small.
Second, the dependence on g max is probably not very tight and can likely be improved.
Third, note that M can grow and ε can shrink with the number of unlabeled documents; indeed, none of the terms in Theorem 4 deal with labeled data.
Finally, it is possible to establish guarantees in a semi-supervised setting using our analysis.
If we have n L i.i.d.
labeled examples, and we learn a linear predictor ˆ v with the representation ˆ φ using
ERM (say), then the bias-variance decomposition grants
[Equation]
where v ∗ is the minimizer of mse( · ) .
The ﬁnal term E x ∼ µ (1) (ˆ φ ( x ) T ( v ∗ − ˆ v )) 2 is the excess risk in linear regression, which goes to zero as n L → ∞ .
T OPIC MODELING SIMULATIONS
To test our theory, we ran simulation experiments with a single-topic generative model where K = 20 topics are sampled from a symmetric Dirichlet ( α ) distribution over a vocabulary of size 5k.
The Dirichlet parameter α governs the sparsity of the topic distributions, effectively determining the similarity of the topics: as α increases the prior concentrates on the interior of the simplex, forcing the topic distributions to be more similar.
This is visualized in the left panel of Figure 1.
In the experiments, we generate a dataset and solve the contrastive optimization problem, and then we construct the landmark embeddings φ ( x ) for each document x using 1k landmark documents, following Section 4.
Using the true likelihood matrix L for the landmarks, we infer the MAP topic estimate and measure accuracy as the fraction of test documents for which this prediction matches the generating topic.
See Appendix A for additional details.
The results are displayed in the center and right panel of Figure 1 where we vary the network architecture and the amount of training data.
The experiment identiﬁes several interesting properties of the contrastive learning approach.
First, as a sanity check, the algorithm does accurately predict the latent topics of the test documents in most experimental conditions and the accuracy is quite high when the problem is relatively easy (e.g., α is small).
Second, the performance degrades as α increases, but this can be mitigated by increasing the model capacity (size of the network) or the resampling rate (which exposes the model to more unlabeled data).
Speciﬁcally, we consistently see that for a ﬁxed model and α , increasing the resampling rate improves accuracy.
A similar trend emerges when we ﬁx α and rate and increase model capacity.
These ﬁndings suggest that latent topics can be recovered by the contrastive learning approach, provided we have an expressive enough model and enough unlabeled data. [Figure]
S EMI - SUPERVISED EXPERIMENTS
We also conducted experiments with our document-level contrastive representations in a semisupervised setting.
The goal of these experiments is to demonstrate that the contrastive representations yield non-trivial performance, as consistent with the theory.
Note that our intention is not to show state-of-the-art performance using contrastive learning; that is beyond the scope of the paper.
We discuss the main ﬁndings here, with experimental details deferred to Appendix B.
A closely related representation.
In the worst-case, the guarantees from Section 4 and Sectionrequire the number of landmarks to be quite large.
To develop a more practical representation, and to more closely mirror what is done in practice, we consider training models of the form f 1 , f 2 :
X → R d where ( x, x (cid:48) )
(cid:55)→ f 1 ( x ) T f 2 ( x (cid:48) ) .
Plugging this into Eq (1), we solve the following bivariate optimization problem:
[Equation]
Given f 1 , f 2 , we can embed a document x according to f 1 ( x ) .
We call the resulting scheme the direct embedding approach to distinguish it from the landmark embedding approach from Section 3.
Methodology.
We used the AG news topic classiﬁcation dataset (Zhang et al., 2015), which has 4 classes and 30k training examples per class.
We reserve 1k examples per class as labeled training data and use the remaining examples for representation learning.
For all methods, we use (cid:96) 2regularized logistic regression to ﬁt a linear classiﬁer on the labeled data.
We compared the representations Landmark-NCE and Direct-NCE against the following baselines: (1) standard bag-of-words ( BOW ), (2) bag-of-words with dimensionality reduction ( BOW+SVD ), (3) representations from LDA ( LDA ), and (4) skip-gram word embeddings (Mikolov et al., 2013b) ( word2vec ).
For the NCE methods, we experiment with different neural network architectures and numbers of landmarks but use standard settings for other training parameters.
See
Appendix B for details.
We note that all of these methods all of these methods ignore word order in the ﬁnal document-level representation, and all of them (with the exception of word2vec ) ignore word order in their training.
In all line plots in Figure 2, the training examples axis refers to the number of randomly selected labeled examples used to train the linear classiﬁer.
The shaded regions denote 95% conﬁdence intervals computed over 10 replicates of this random selection procedure.
Baseline comparison.
In the left panel of Figure 2, we visualize the semi-supervised perfomance of NCE and the baselines.
Direct-NCE outperforms all the other methods, with dramatic improve- ments over all except word2vec in the low labeled data regime.
BOW is quite competitive when there is an abundance of labeled data, but as the dimensionality of this representation is quite large, it performs poorly with limited samples.
However, unsupervised dimensionality reduction on this representation appears to be unhelpful and actually degrades performance uniformly.
Finally, we point out that word embedding representations ( word2vec ) perform quite well, but our documentlevel Direct-NCE procedure is slightly better, particularly when there are few labeled examples.
This may reﬂect some advantage in learning document-level non-linear representations, as opposed to averaging word-level ones.
Visualizing embeddings.
For a qualitative perspective, we visualize the embeddings from NCE using t-SNE with the default scikit-learn parameters (van der Maaten & Hinton, 2008; Pedregosa et al., 2011).
To compare, we also used t-SNE to visualize the document-averaged word2vec embeddings.
The right panels of Figure 2 shows these visualizations on the 7,600 test documents colored according to their true label.
While qualitiative, the visualization of the Direct-NCE embeddings appear to be more clearly separated into label-homogeneous regions than that of word2vec .
Other results.
We investigated the effect of the number of landmarks on the performance of
Landmark-NCE by embedding with 500, 1k, 4k, 8k, and 16k landmarks.
The bottom left panel of Figure 2 displays the results, which suggest that a larger number of landmarks is helpful, with diminishing returns at the higher end of the scale.
We also looked into the effect of depth on the performance of Direct-NCE by training networks with one, two, and three hidden layers.
In each case, the ﬁrst hidden layer has 300 nodes and the rest have 256 nodes.
The top center panel of Figure 2 displays the results, which suggest that using deeper models for representation learning may improve downstream performance.
We also tracked the contrastive loss of the model on a holdout validation contrastive dataset.
The bottom center panel of Figure 2 plots how this loss evolves over training epochs.
Along with this contrastive loss, we checkpoint the model, train a linear classiﬁer, and evaluate the supervised test accuracy.
We see that test accuracy steadily improves as contrastive loss decreases, suggesting that in these settings, contrastive loss (which we can measure using an unlabeled validation set) is a good surrogate for downstream performance (which may not be measurable until we have a task at hand).
A T OPIC MODELING SIMULATIONS
The results of Section 4 show that if a model is trained to minimize the contrastive learning objective, then that model must also recover certain topic posterior information in the corpus.
However, there are a few practical questions that remain: can we train such a model, how much capacity should it have, and how much data is needed in order to train it?
Our topic modeling simulations are designed to study these questions.
Simulation setup.
We considered a single-topic generative model where the topics θ 1 , . . .
, θ K are sampled from a symmetric Dirichlet ( α/K ) distribution over ∆ |V| and for each document, its length is drawn from a Poisson( λ ) and its topic is sampled uniformly from [ K ] .
This model can be thought of as a limiting case of the LDA model (Blei et al., 2003; Grifﬁths & Steyvers, 2004) when the document-level topic distribution is symmetric Dirichlet ( β ) with β (cid:28) 1 .
In our experiments, we set
K = 20 , |V| = 5000 , and λ = 30 , and we varied α from 1 to 10.
Notice that as α increases, the
Dirichlet prior becomes more concentrated around the uniform distribution, so the topic distributions are more likely to be similar.
Thus, we expect the contrastive learning problem to be more difﬁcult with larger values of α .
We used contrastive models of the same form as Section 7, namely models of the form f 1 , f 2 where the ﬁnal prediction is f 1 ( x ) T f 2 ( x (cid:48) ) and f 1 and f 2 are fully-connected neural networks with three hidden layers.
To measure the effect of model capacity, we trained two models – a smaller model with 256 nodes per hidden layer and a larger model with 512 nodes per hidden layer.
Both models were trained for 100 epochs.
We used all of the same optimization parameters as in Section 7 with the exception of dropout, which we did not use.
To study the effect of training data, we varied the rate r at which we resampled our entire contrastive training set from the ground truth topic model.
Speciﬁcally, after every 1 /r -th training epoch, we resampled 60,000 new documents and constructed a contrastive dataset from these documents.
We varied the resampling rate r from 0.1 to 1.0, where larger values of r imply more training data.
The total amount of training data varies from 600K documents to 6M documents.
Using the results from Section 4, we constructed the embedding φ ( x ) of a new document x using 1000 landmark documents, each sampled from the same generative model.
We constructed the true likelihood matrix L of the landmark documents using the underlying topic model and recovered the model-based posterior L † φ ( x ) .
We measured accuracy as the fraction of testing documents for which the MAP topic under the model-based posterior matched the generating topic.
We usedtesting documents and performed 5 replicates for each setting of parameters.
B S EMI - SUPERVISED EXPERIMENT DETAILS
Methodology.
We conducted semi-supervised experiments on the AG news topic classiﬁcation dataset as compiled by Zhang et al.
This dataset contains news articles that belong to one of four categories: world, sports, business, and sci/tech.
There are 30,000 examples from each class in the training set, and 1,900 examples from each class in the testing set.
We minimally preprocessed the dataset by removing punctuation and words that occurred in fewer than 10 documents, resulting in a vocabulary of approximately 16,700 words.
We randomly selected 1,000 examples from each class to remain as our labeled training dataset, and we used the remaining 116,000 examples as our unlabeled dataset for learning representations.
After computing representations on the unlabeled dataset, we ﬁt a linear classiﬁer on the labeled training set using logistic regression with cross validation to choose the (cid:96) 2 regularization parameter ( n folds = 3 ).
We compared our representations, Landmark-NCE and Direct-NCE , against several representation baselines.
• BOW – The standard bag-of-words representation.
• BOW+SVD – A bag of words representation with dimensionality reduction.
We ﬁrst perform SVD on the bag-of-words representation using the unsupervised dataset to compute
a low dimensional subspace, and train a linear classiﬁer on the projected bag-of-words representations with the labeled dataset.
• LDA – A representation derived from LDA.
We ﬁt LDA on the unsupervised dataset using online variational Bayes (Hoffman et al., 2010), and our representation is the inferred posterior distribution over topics given training document.
• word2vec – Skip-gram word embeddings (Mikolov et al., 2013b).
We ﬁt the skip-gram word embeddings model on the unsupervised dataset and then averaged the word embeddings in each of the training documents to get their representation.
For our representation, to solve the optimization problem in Eq.
(5), we considered neural network architectures of various depths.
We used fully-connected layers with between 250 and 300 nodes per hidden layer.
We used ReLU nonlinearities, dropout probability 1/2, batch normalization, and the default PyTorch initialization (Paszke et al., 2019).
We optimized using RMSProp with momentum value 0.009 and weight decay 0.0001 as in Radhakrishnan et al.
We started with learning rate 10 − 4 which we halved after 250 epochs, and we trained for 600 epochs.
Unless otherwise stated, Landmark-NCE and Direct-NCE use a three-layer architecture, and Landmark-NCE uses 8000 landmarks.
To sample a contrastive dataset, we ﬁrst randomly partitioned each unlabeled document in half to create the positive pairs.
To create the negative pairs, we again randomly partitioned each unlabeled document in half, randomly permuted one set of half documents, and discarded collisions.
This results in a contrastive dataset whose size is roughly twice the number of unlabeled documents.
In the course of training our models for the contrastive task, we resampled a contrastive dataset every 3 epochs to prevent overﬁtting on any one particular dataset.
Additional discussions.
In the left panel of Figure 2, we additionally remark that LDA performs quite poorly.
This could be for several reasons, including that ﬁtting a topic model directly could be challenging on the relatively short documents in the corpus or that the document category is not well-expressed by a linear function of the topic proportions.
C P ROOFS FROM S ECTIONC. P ROOF OF SINGLE TOPIC REPRESENTATION LEMMA
Proof of Lemma 1.
Conditioned on the topic vector w , x (1) and x (2) are independent.
Thus,
[Equation]
where the third equality follows from Bayes’ rule.
C. P ROOF OF GENERAL REPRESENTATION LEMMA
Proof of Lemma 2.
Fix a document x of length m and a document probability vector w .
Conditioned on the assignment of each word in the document to a topic, probability of a document factorizes as
P ( x | w ) = (cid:88)
z ∈ [ K ] m m (cid:89) i =
[Equation]
|
[Equation]
z
[Equation]
[ K ] m   m (cid:89) i = w z
[Equation]

   m (cid:89)
i
[Equation]
O ( x i | z i ) 
 =
π ( w ) T ψ ( x ) , where the last line follows from collecting like terms.
Using the form of g (cid:63) from above, we have
[Equation]
C. P ROOF OF POLYNOMIAL REPRESENTATION THEOREM
Proof of Theorem 3.
By assumption (i), there exists an anchor word a k for each topic k = 1 , . . .
, K .
By deﬁnition this means that O ( a k | j ) >
if and only if j = k .
For each vector α ∈ Z K + such that (cid:80) α k ≤ d o , create a landmark document consisting of α k copies of a k for k = 1 , . .
, K .
This will result in (cid:0) K + d o d o (cid:1) landmark documents.
Moreover, from assumption (ii), we can see that each of these landmark documents has positive probability of occurring under the marginal distribution of x (2) for ( x (1) , x (2) , y ) ∼ D contrast , which implies g (cid:63) ( x, l ) is well-deﬁned for all our landmark documents l .
Let l denote one of our landmark documents and let α ∈ Z K + be its associated vector.
Since l only contains anchor words, ψ ( l ) β > 0 if and only if α = β .
To see this, note that
[Equation]
On the other hand, if β (cid:54) =
α but (cid:80) k β k = (cid:80) k
α k , then there exists an index k
such that β k ≥ α k +1 .
Thus, for any z ∈ (cid:0) [ m ] β (cid:1) , there will be more than α k words in l assigned to topic k .
Since every word in l is an anchor word and at most α k of them correspond to topic k , we will have
[Equation]
Rebinding ψ ( l ) =
( ψ 0 ( l ) , . . .
, ψ d 0 ( l )) and forming the matrix L using this deﬁnition, we see that
L T can be diagonalized and inverted.
For any target degree- d o polynomial Q ( w ) , there exists a vector v such that Q ( w ) = (cid:104) v, π d 0 ( w ) (cid:105) , where π d 0 ( w ) denotes the degree- d 0 monomial vector.
Thus, we may take θ =
L − 1 v and get that for any document x :
[Equation]
D P ROOFS FROM S ECTIOND. P ROOF OF ERROR TRANSFORMATION GUARANTEE
We ﬁrst recall and setup some notations.
For ( x (1) , x (2) , y ) ∼ D contrast (our contrastive distribution deﬁned in Section 3), we let µ i denote the marginal distribution of x ( i ) .
Furthermore, recall the
contrastive loss, conditional probability, odds ratio, and oracle representation functions:
[Equation]
where l 1 , . . . , l M are landmark documents.
The learned approximation to f (cid:63) is ˆ f
[Equation]
and from it we derive
[Equation]
Let η ( x ) , ψ ( x ) denote the posterior/likelihood vectors from Lemma 1 or the posterior/likelihood polynomial vectors from Lemma 2.
Say the length of this vector is N ≥ 1 .
Our goal is to show that linear functions in the representation ˆ φ ( x ) can provide a good approximation to the target function
[Equation]
x )
[Equation]
θ
[Equation]
where θ (cid:63) ∈ R N is some ﬁxed vector.
To this end, deﬁne
[Equation]
which is the best mean squared error achievable using the representation ˆ φ .
By Lemma 1 or Lemma 2, we know that for any x, x (cid:48)
we have
[Equation]
Recall the matrix
[Equation]
This matrix is in R N × M .
If L has full row rank, then
[Equation]
where
[Equation]
and v (cid:63) =
L † θ (cid:63) .
Thus, R ( φ (cid:63) ) = 0 .
We will show that R (ˆ φ ) can be bounded as well.
Theorem 5 (Restatement of Theorem 4) .
Suppose the following assumptions hold.
(1) There is a constant σ min > 0 such that for any δ ∈ (0 , 1) , there is a number M
( δ ) such that for an i.i.d.
sample l 1 , . . .
, l M with M ≥ M 0 ( δ ) , with probability 1 − δ , the matrix
[Equation]
has minimum singular value at least σ min √ M .
(2) There exists a value g max > 0 such that for all documents x and landmarks l i
[Equation]
Let ˆ f be the function returned by the contrastive learning algorithm, and let
[Equation]
denote its excess contrastive loss.
For any δ ∈ (0 , 1) , if M ≥ M 0 ( δ/ 2) , then with probability at least 1 − δ over the random draw of l 1 , . . . , l M , we have
[Equation]
Proof.
We ﬁrst condition on two events based on the sample l 1 , . . .
, l M .
The ﬁrst is the event that
L has full row rank and smallest non-zero singular value at least √ Mσ min > 0 ; this event has probability at least 1 − δ/ 2 .
The second is the event that
[Equation]
where we make the deﬁnitions
[Equation]
By Hoeffding’s inequality and the fact that ˆ p and p (cid:63) have range [0 , 1] , this event also has probability at least 1 − δ/ 2 .
By the union bound, both events hold simultaneously with probability at least 1 − δ .
We henceforth condition on these two events for the remainder of the proof.
Since L has full row rank, via Cauchy-Schwarz, we have
[Equation]
We analyze the two factors on the right-hand side separately.
Analysis of v (cid:63) .
For v (cid:63) , we have
[Equation]
where we have used the fact that L has smallest non-zero singular value at least √ Mσ min .
Analysis of φ (cid:63) − ˆ φ .
For the other term, we ﬁrst note that
[Equation]
Thus, we have
[Equation]
where KL ( p, p (cid:48) ) denotes the KL-divergence between two Bernoulli distributions with biases p and p (cid:48) , respectively.
Pinkser’s inequality tells us that KL ( p, p (cid:48) ) ≥ 2( p − p (cid:48) ) 2 .
Combining this with the fact that D contrast is a mixture distribution that places half its probability mass in µ (1) ⊗ µ (2) implies
[Equation]
[Table]
Combining the above with Eq.
(6) and the deﬁnitions of ˆ p, p (cid:63) , we have
[Equation]
Wrapping up.
To conclude, we have
[Equation]
D. S ATISFYING A SSUMPTION
Suppose we are in the single topic case where w ∈ { e 1 , . .
, e K } .
Assume that min k Pr( w = e k ) ≥ w min .
Further assumes that each topic k has an anchor word a k , satisfying O ( a k | z = e k ) ≥ a min .
Then we will show that when M and m are large enough, the matrix L whose columns are ψ ( x ) / P ( x ) will have large singular values.
First note that if document x contains a k then ψ ( x ) is one sparse, and satisﬁes if a k
[Equation]
[Equation]
Therefore, the second moment matrix satisﬁes
[Equation]
Now, if the number of words per document is m ≥ 1 /a min then
[Equation]
Finally, using the fact that P ( w = e k ) ≤ 1 , we see that the second moment matrix satisﬁes
[Equation]
For the empirical matrix, we perform a crude analysis and apply the Matrix-Hoeffding inequality (Tropp, 2012).
We have (cid:13)(cid:13) ψ ( x ) ψ ( x ) T (cid:13)(cid:13) 2 ≤ Kw − 2min
and so with probability at least 1 − δ , we have
[Equation]
If we take M ≥ Ω( K log( K/δ ) /w 2min ) then we will have that the minimum eigenvalue of the empirical second moment matrix will be at least 1 / 2 .