Test-Time Training on Nearest Neighbors for Large Language Models

Moritz Hardt, Yu Sun
5/29/2023
cs.CLcs.LG

No official code found. Best implementation: socialfoundations/tttlm (50 stars, MIT, last commit 2024-04-18).

Abstract

Many recent efforts augment language models with retrieval, by adding retrieved data to the input context. For this approach to succeed, the retrieved data must be added at both training and test time. Moreover, as input length grows linearly with the size of retrieved data, cost in computation and memory grows quadratically for modern Transformers. To avoid these complications, we simply fine-tune the model on retrieved data at test time, using its standard training setup. We build a large-scale distributed index based on text embeddings of the Pile dataset. For each test input, our system retrieves its neighbors and fine-tunes the model on their text. Surprisingly, retrieving and training on as few as 20 neighbors, each for only one gradient iteration, drastically improves performance across more than 20 language modeling tasks in the Pile. For example, test-time training with nearest neighbors significantly narrows the performance gap between a small GPT-2 and a GPT-Neo model more than 10 times larger. Sufficient index quality and size, however, are necessary. Our work establishes a first baseline of test-time training for language modeling.

View on arXivView PDF

Code Implementations(1)

MIT

Test-time-training on nearest neighbors for large language models

505PythonMay 26, 20232 years agoMIT

Similar Papers

Cite this paper

@article{hardt2023testtime,
  title  = {Test-Time Training on Nearest Neighbors for Large Language Models},
  author = {Moritz Hardt and Yu Sun},
  year   = {2023},
  eprint = {2305.18466},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2305.18466v3},
  journal = {ICLR 2023 2023}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2305.18466.svg)](https://codeofpaper.com/paper/2305.18466)

Discussion