Large language models (LMs) are currently trained to predict tokens given document prefixes, enabling them to directly perform long-form generation and prompting-style tasks which can be reduced to document completion. Existing pretraining pipelines train LMs by concatenating random sets of short documents to create input contexts but the prior documents provide no signal for predicting the next document. We instead present In-Context Pretraining, a new approach where language models are pretrained on a sequence of related documents, thereby explicitly encouraging them to read and reason across document boundaries. We can do In-Context Pretraining by simply changing the document ordering so that each context contains related documents, and directly applying existing pretraining pipelines. However, this document sorting problem is challenging. There are billions of documents and we would like the sort to maximize contextual similarity for every document without repeating any data. To do this, we introduce approximate algorithms for finding related documents with efficient nearest neighbor search and constructing coherent input contexts with a graph traversal algorithm. Our experiments show In-Context Pretraining offers a simple and scalable approach to significantly enhance LMs'performance: we see notable improvements in tasks that require more complex contextual reasoning, including in-context learning (+8%), reading comprehension (+15%), faithfulness to previous contexts (+16%), long-context reasoning (+5%), and retrieval augmentation (+9%).
翻译:大型语言模型(LMs)当前通过给定文档前缀来预测词元进行训练,使其能够直接执行可简化为文档补全的长文本生成和提示式任务。现有预训练流程通过拼接随机选取的短文档集来创建输入上下文,但前置文档对预测后续文档不提供任何信号。我们提出一种新方法——上下文预训练,将语言模型在相关文档序列上进行预训练,从而明确鼓励它们跨越文档边界进行阅读和推理。我们仅需改变文档排序使每个上下文包含相关文档,并直接应用现有预训练流程即可实现上下文预训练。然而,这种文档排序问题极具挑战性:面对数十亿级文档,我们希望在无数据重复的前提下最大化每个文档的上下文相似性。为此,我们引入近似算法:通过高效近邻搜索寻找相关文档,并采用图遍历算法构建连贯的输入上下文。实验表明,上下文预训练提供了一种简单可扩展的方法来显著提升语言模型性能:在需要复杂上下文推理的任务中,我们观察到显著改进——上下文学习(+8%)、阅读理解(+15%)、对先前上下文的忠实度(+16%)、长上下文推理(+5%)以及检索增强(+9%)。