Few-shot Learning for Topic Modeling

Tomoharu IwataarXiv 2021

Abstract

Topic models have been successfully used for analyzing text documents. However, with existing topic models, many documents are required for training. In this paper, we propose a neural network-based few-shot learning method that can learn a topic model from just a few documents. The neural networks in our model take a small number of documents as inputs, and output topic model priors. The proposed method trains the neural networks such that the expected test likelihood is improved when topic model parameters are estimated by maximizing the posterior probability using the priors based on the EM algorithm. Since each step in the EM algorithm is differentiable, the proposed method can backpropagate the loss through the EM algorithm to train the neural networks. The expected test likelihood is maximized by a stochastic gradient descent method using a set of multiple text corpora with an episodic training framework. In our experiments, we demonstrate that the proposed method achieves better perplexity than existing methods using three real-world text document sets.

1. Introduction

Topic modeling is a fundamental tool in Natural Language Processing (NLP) for uncovering latent thematic structures within document collections. Traditional approaches, such as Latent Dirichlet Allocation (LDA), rely heavily on statistical regularities that only manifest in large-scale datasets. Consequently, these models often fail when applied to small document sets—a common scenario in specialized research fields, niche document archives, or personalized AI assistants.

While few-shot learning has seen significant success in supervised tasks like image classification, its application to the unsupervised world of topic modeling remains a challenge. This paper addresses this gap by proposing a framework that can extract coherent topics from as few as three documents by treating the optimization process itself as a learnable component of a neural network.

2. Methodology

The core of the proposed method is a neural-network-based generator that outputs the parameters for a topic model. The architecture is designed to handle the sparsity of few-shot data through a multi-stage pipeline that integrates traditional probabilistic modeling with deep learning.

2.1 Episodic Training Framework

To enable few-shot capabilities, the model is trained using a meta-learning approach known as episodic training. During training, the model is presented with thousands of "episodes." In each episode, it receives a small "support set" of documents from a specific corpus, estimates the topic parameters, and is then evaluated on its ability to predict words in a separate "query set" from the same corpus.

The episodic training framework (a) and test phase (b) of the proposed few-shot topic model.

2.2 Differentiable EM Layers

The most innovative aspect of this work is the treatment of the Expectation-Maximization (EM) algorithm as a series of differentiable layers. The process follows these steps:

  1. Corpus Representation: A permutation-invariant neural network (based on the "Deep Sets" architecture) compresses the support documents into a single vector ($r$) representing the corpus essence.
  2. Generating Priors: This representation is used to predict Dirichlet parameters ($\alpha$ and $\beta$), which act as the initial priors for document-topic and topic-word distributions.
  3. Optimization: These priors are passed into an EM algorithm. Because each E-step and M-step is mathematically differentiable, the model can backpropagate the loss through the entire optimization process to refine how it initializes these priors.
Internal architecture showing the generation of priors and the differentiable EM steps.

3. Experimental Evaluation

The model was evaluated on three well-known text datasets: 20News, Digg, and NeurIPS. In the experiments, the "target corpus" for the few-shot task consisted of only three documents ($N=3$).

3.1 Key Results

The proposed method was compared against 11 baselines, including standard LDA and MAML-based neural approaches.

  • Perplexity: The proposed model achieved the lowest (best) perplexity across all datasets. On 20News, it reached a perplexity of 2785.8, significantly outperforming standard LDA (3239.1) and the best non-EM neural baseline (2831.7).
  • Refinement: Increasing the number of EM steps ($T$) within the neural network consistently lowered perplexity, proving that the differentiable layers effectively refine topic estimates.
  • Qualitative Coherence: Even with only three documents, the model extracted highly relevant keywords. For instance, in a "sci.space" corpus, it correctly identified clusters around "mission/orbit" and "spacecraft/solar."

4. Conclusion

By making the EM algorithm differentiable, this research demonstrates that topic models can be effectively trained in few-shot scenarios. This approach allows the model to learn how to initialize an optimization process so that it reaches a high-quality solution in just a few steps. While the training phase is computationally intensive due to episodic sampling, the resulting model is highly efficient at test time. Future work may extend this differentiable optimization logic to other latent variable models, such as Gaussian Mixture Models or Non-negative Matrix Factorization (NMF).

Summary updated

BibTeX
@misc{iwata2021few,
  author = {Tomoharu Iwata},
  title = {{Few-shot Learning for Topic Modeling}},
  year = {2021},
  eprint = {2104.09011},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2104.09011},
}
Figure