[Paper Review] Large Language Models Are Latent Variable Models: Explaining and Finding Good Demonstrations for In-Context Learning
The paper proposes a Bayesian latent-variable framework for in-context learning, learning task concepts with a small LM and selecting demonstrations to transfer to larger LLMs, validated across eight NLP datasets and GSM8K.
In recent years, pre-trained large language models (LLMs) have demonstrated remarkable efficiency in achieving an inference-time few-shot learning capability known as in-context learning. However, existing literature has highlighted the sensitivity of this capability to the selection of few-shot demonstrations. Current understandings of the underlying mechanisms by which this capability arises from regular language model pretraining objectives remain disconnected from the real-world LLMs. This study aims to examine the in-context learning phenomenon through a Bayesian lens, viewing real-world LLMs as latent variable models. On this premise, we propose an algorithm to select optimal demonstrations from a set of annotated data with a small LM, and then directly generalize the selected demonstrations to larger LMs. We demonstrate significant improvement over baselines, averaged over eight GPT models on eight real-world text classification datasets. We also demonstrate the real-world usefulness of our algorithm on GSM8K, a math word problem dataset. Our empirical findings support our hypothesis that LLMs implicitly infer a latent variable containing task information.
Motivation & Objective
- Motivate in-context learning as inference over a latent task/concept variable within real-world LLMs.
- Propose a practical two-step algorithm: latent concept learning with a small LM and demonstration selection for larger LLMs.
- Theoretically justify demonstration selection under a Bayes-optimal framework and empirically validate on multiple datasets and models.
- Demonstrate transferability of learned concept tokens and demonstrations across different large language models.
Proposed method
- Model text generation with a latent variable theta that encodes task and format information.
- Introduce c new concept tokens per task to represent theta and fine-tune only their embeddings while freezing the rest of the model.
- Formulate demonstration selection to maximize the posterior probability P(theta | demonstrations, test input) and approximate with a tractable objective.
- Train concept tokens via prompt-tuning to minimize the cross-entropy loss aligning P(Y|theta,X) with the data.
- Select k demonstrations by computing and ranking top candidates according to their inferred theta probability, then use the same demonstrations across larger LLMs.
- Demonstrations are learned/tuned with a small LM (e.g., GPT2-large) and transferred to larger LMs without further tuning.
Experimental results
Research questions
- RQ1Can a latent variable theta capturing task and format information explain in-context learning in real-world LLMs?
- RQ2Does learning task-specific concept tokens with a small LM enable effective demonstration selection that transfers to larger LLMs?
- RQ3How does demonstration selection based on inferred theta compare to uniform or similarity-based baselines across diverse tasks?
- RQ4Is the proposed method robust across model sizes and task domains, including complex tasks like GSM8K?
Key findings
- Demonstration selection based on learned latent concepts significantly improves in-context learning across eight NLP datasets and multiple GPT-family models.
- Learning task concept tokens with a small LM enables transfer of demonstrations to much larger LLMs without re-training the large models.
- The proposed method outperforms uniform and similarity-based baselines in 8 datasets, showing an average relative improvement (reported as 12.5% in the paper) over baselines.
- The approach also yields strong results on GSM8K, with larger models benefiting more when demonstrations are learned from the latent concepts.
- Demonstrations learned with GPT2-large generalize well to other models including GPT-3 variants, LLaMA, OPT, and others, indicating cross-model transferability.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.