Skip to main content
QUICK REVIEW

[Paper Review] Focused Transformer: Contrastive Training for Context Scaling

Szymon Tworkowski, Konrad Staniszewski|arXiv (Cornell University)|Jul 6, 2023
Topic ModelingComputer Science13 citations
TL;DR

The paper introduces Focused Transformer (FoT), a contrastive-training method with memory attention to extend context length, enabling fine-tuned OpenLLaMA models (LongLLaMA) to handle up to 256k tokens and improve long-context tasks.

ABSTRACT

Large language models have an exceptional capability to incorporate new information in a contextual manner. However, the full potential of such an approach is often restrained due to a limitation in the effective context length. One solution to this issue is to endow an attention layer with access to an external memory, which comprises of (key, value) pairs. Yet, as the number of documents increases, the proportion of relevant keys to irrelevant ones decreases, leading the model to focus more on the irrelevant keys. We identify a significant challenge, dubbed the distraction issue, where keys linked to different semantic values might overlap, making them hard to distinguish. To tackle this problem, we introduce the Focused Transformer (FoT), a technique that employs a training process inspired by contrastive learning. This novel approach enhances the structure of the (key, value) space, enabling an extension of the context length. Our method allows for fine-tuning pre-existing, large-scale models to lengthen their effective context. This is demonstrated by our fine-tuning of $3B$ and $7B$ OpenLLaMA checkpoints. The resulting models, which we name LongLLaMA, exhibit advancements in tasks requiring a long context. We further illustrate that our LongLLaMA models adeptly manage a $256 k$ context length for passkey retrieval.

Motivation & Objective

  • Identify the distraction issue limiting context scaling in multi-document attention for LLMs.
  • Develop FoT to extend context length without retraining from scratch by shaping the (key, value) space.
  • Demonstrate practical fine-tuning of existing models (OpenLLaMA) to create LongLLaMA with longer context.
  • Empirically evaluate long-context capabilities on passkey retrieval, QA, and few-shot tasks; show extrapolation beyond training length.

Proposed method

  • Add memory attention layers that retrieve additional (key, value) context via kNN during inference.
  • Train with crossbatch procedure inspired by contrastive learning to expose memory attention to positives (current/previous context) and negatives (other documents).
  • Remove (except LongLLaMA) positional encodings in memory layers to enable extrapolation; use FAISS for exact kNN retrieval.
  • Fine-tune OpenLLaMA-3B and OpenLLaMA-7B with FoT to produce LongLLaMA models; evaluate on passkey retrieval, Qasper, TREC, WebQS, and long-context datasets (PG-19, arXiv, GitHub, Isabelle).
  • Demonstrate that FoT improves the structure of the key-value space, enabling attention to extended context without full-scale retraining.
  • Show that FoT-based models can extrapolate context length beyond training limits (e.g., 256k tokens in passkey retrieval).

Experimental results

Research questions

  • RQ1Can FoT mitigate the distraction issue when extending transformer context across many documents?
  • RQ2Can FoT enable extrapolation to much longer contexts without training on those lengths?
  • RQ3Do FoT-trained models maintain or improve perplexity and few-shot performance with longer contexts?
  • RQ4What are the practical gains on long-context tasks such as passkey retrieval and document QA?
  • RQ5How does FoT perform across different model sizes and datasets (PG-19, arXiv, GitHub, Isabelle, Qasper, TREC, WebQS)?

Key findings

  • FoT alleviates the distraction issue by shaping the key-value space via crossbatch contrastive training.
  • LongLLaMA-3B and LongLLaMA-7B extrapolate to 256k tokens, achieving 94.5% accuracy at 100k and 73% at 256k on passkey retrieval.
  • LongLLaMA models show accuracy gains on TREC and WebQS with longer contexts compared to baselines.
  • FoT enables extrapolation beyond training context length, unlike standard fine-tuning baselines.
  • Perplexity improves with longer context in FoT on PG-19, arXiv, GitHub, and Isabelle with gains up to 64k context (relative to baselines).
  • FoT is a simple plug-and-play extension that allows fine-tuning existing models to extend context without changing architecture.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.