Abstract
The development of Long-Context Large Language Models (LLMs) has markedly advanced natural language processing by facilitating the process of textual data across long documents and multiple corpora. However, Long-Context LLMs still face two critical challenges: The lost in the middle phenomenon, where crucial middle-context information is likely to be missed, and the distraction issue that the models lose focus due to overly extended contexts. To address these challenges, we propose the Context Filtering Language Model (FltLM), a novel integrated Long-Context LLM which enhances the ability of the model on multi-document question-answering (QA) tasks. Specifically, FltLM innovatively incorporates a context filter with a soft mask mechanism, identifying and dynamically excluding irrelevant content to concentrate on pertinent information for better comprehension and reasoning. Our approach not only mitigates these two challenges, but also enables the model to operate conveniently in a single forward pass. Experimental results demonstrate that FltLM significantly outperforms supervised fine-tuning and retrieval-based methods in complex QA scenarios, suggesting a promising solution for more accurate and reliable long-context natural language understanding applications.
Introduction
As Large Language Models (LLMs) evolve to process tens of thousands of tokens, they encounter significant hurdles in maintaining comprehension accuracy. Two primary issues persist: Lost in the Middle, where models struggle to retrieve information buried in the center of a prompt, and the Distraction Issue, where the attention mechanism's focus is dispersed across irrelevant "noise" documents. Traditional retrieval-augmented systems attempt to solve this by pre-filtering documents, but they often fail if the retriever's precision is low, still overwhelming the LLM with distractors. FltLM addresses these challenges by integrating filtering and reasoning within a single architecture.
Methodology
FltLM is built upon a 2N-layer Long-Context LLM (utilizing a ChatGLM3-6B base). The architecture is bifurcated into two functional stages:
- The Context Filter (First N layers): The model employs a strategy of appending a special token (
</doc_i>) to every document. The hidden states of these tokens are used to compute relevance scores for each document in the context. - The Soft Mask Mechanism (Remaining N layers): Based on the relevance scores, FltLM applies a learnable soft mask to the attention matrix in the subsequent layers. Unlike a "hard" filter that deletes tokens, the soft mask dynamically reduces the influence of irrelevant information, allowing the model to remain end-to-end trainable and robust to filter uncertainty.
The model is optimized via a joint loss function: $L = L_{lm} + \lambda L_{flt}$. The filter loss ($L_{flt}$) is a modified InfoNCE loss that incorporates an absolute threshold and margin, ensuring the model can distinguish relevant content regardless of the total document count.
Experimental Evaluation
The authors trained FltLM on approximately 85,000 samples derived from multi-hop QA datasets (HotpotQA, 2WikiMultiHopQA, and MuSiQue), simulating a 32k-token context by replacing snippets with full Wikipedia articles. Evaluation was conducted using the LongBench English multi-document QA datasets (HQA, 2WIKI, and MSQ).
Key Results and Insights
FltLM achieved an average F1 score of 67.58% on LongBench tasks, outperforming standard Supervised Fine-Tuning (65.24%) and traditional retrieval pipelines.
Superior Retrieval Performance: When evaluated as a retriever, FltLM's internal filter outperformed dedicated state-of-the-art models such as BGE-m3 and E5-Mistral, achieving higher recall with fewer documents.
Reciprocal Enhancement: A key finding was that the QA and filtering tasks mutually benefit each other. Training with the combined loss made the context filter more accurate than training it in isolation, as feedback from the reasoning task helps the filter learn better semantic features.
Robustness to Positioning: By scoring every document independently, FltLM effectively solves the "Lost in the Middle" problem. Performance remained stable even when relevant documents were moved to the center of the prompt, unlike traditional fine-tuned models.
Conclusion
FltLM offers a streamlined, "one-stop-shop" solution for long-context processing by integrating filtering directly into the forward pass. While currently focused on multi-hop QA, future work will explore its generalization to other long-form tasks and its scalability to even larger context windows using more efficient attention mechanisms.
Summary updated