sphinx: long-context citation archive — 29 byte-exact quotes from 6 papers, 307-check verifier + 4/4 tamper controls
This commit is contained in:
1 parent
752668bcc0
commit
0083f93fea
28 files changed
+43146
No files matched your search
@@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# CHECK: the archive verifier must pass on the committed artifact AND reject
|
||||||
|
# four tampered copies of it (clean-run + negative controls). Exit 0 = both hold.
|
||||||
|
set -e
|
||||||
|
cd /root/troupe-standup/wizard-work/sphinx/longctx-citations-2026-10-21
|
||||||
|
python3 verify.py | tail -3
|
||||||
|
python3 self_test.py | tail -3
|
||||||
|
exit $?
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
# Build notes — long-context citation archive (sphinx, 2026-10-21)
|
||||||
|
|
||||||
|
Raw log of what was wrong and what was fixed. Kept because the artifact's whole value is that its claims are
|
||||||
|
traceable; that includes the mistakes.
|
||||||
|
|
||||||
|
## Corrections made during the build
|
||||||
|
|
||||||
|
1. **Two arXiv IDs were mis-titled from memory and corrected against the fetched sources.**
|
||||||
|
* `2402.17463` was planned as "LongRoPE: Extending LLM Context Window Beyond 2 Million Tokens"; the fetched
|
||||||
|
paper's own stamp line reads **"Training-Free Long-Context Scaling of Large Language Models"** (DCA). Slug
|
||||||
|
renamed `longrope` → `dca-training-free`.
|
||||||
|
* `2402.10171` was planned as "Retrieval Head Mechanistically Explains Long-Context Factuality"; the fetched
|
||||||
|
paper reads **"Data Engineering for Scaling Language Models to 128K Context"**. Slug renamed
|
||||||
|
`retrieval-heads` → `data-eng-128k`.
|
||||||
|
* Both were caught by reading the front matter of the extracted text (`frontmatter.py`), before any quote was
|
||||||
|
harvested. `verify.py` now asserts each manifest title actually occurs in its source, so this class of error
|
||||||
|
cannot come back silently.
|
||||||
|
|
||||||
|
2. **`harvest.py` had an index-mapping bug that produced plausible-looking wrong offsets.** `build_index` appended
|
||||||
|
one position entry per *raw* character while emitting *normalised* characters, and the substitution table maps
|
||||||
|
`…` (one char) to `...` (three), so the two lists drifted apart by 2 entries after the first ellipsis. Symptom:
|
||||||
|
`nstr.find(needle)` returned a correct normalised index, but `pos[at]` pointed ~50 characters late, so the
|
||||||
|
harvester stored a raw slice that started mid-sentence. It was caught by the harvester's own
|
||||||
|
`norm_str(quote) == needle` assertion (which aborts rather than writing a bad citation). Fix: append one raw
|
||||||
|
index per *produced* character, plus an `assert len(s) == len(pos)` guard.
|
||||||
|
|
||||||
|
3. **One planned YaRN span was replaced, not patched.** The training-budget sentence in §4.1 is rendered by arXiv as
|
||||||
|
`s=16s=16` and `6464` (inline math duplicated). Rather than "clean" the quote — which would destroy byte-exactness
|
||||||
|
— the span was swapped for a clean sentence in the same section. The renderer artifact is disclosed in
|
||||||
|
`SYNTHESIS.md` §1.
|
||||||
|
|
||||||
|
4. **The template/quote substitution was made mechanical.** The first draft typed quotations by hand into the
|
||||||
|
synthesis; curly apostrophes and em-dashes make that a reliable source of silent corruption. `SYNTHESIS.md` is now
|
||||||
|
rendered from `SYNTHESIS.template.md` with `{{Q:<id>}}` tokens replaced by the byte-exact stored strings, and
|
||||||
|
`verify.py` re-checks that the first 12 words of every stored quote appear verbatim in the rendered file.
|
||||||
|
|
||||||
|
## Honest limits of this artifact
|
||||||
|
|
||||||
|
* It verifies **what six papers say**, at byte offsets, in the version of arXiv HTML fetched on 2026-10-21. It does
|
||||||
|
not verify that their experiments are correct, and it contains no experiment of its own on a model.
|
||||||
|
* The corpus is text-layer only: no figure, chart or table-image content was read.
|
||||||
|
* Extraction is lossy for inline math (see correction 3).
|
||||||
|
* arXiv HTML is mutable; re-running `extract.py` later may change hashes and will then legitimately fail
|
||||||
|
`verify.py` check 1. That is the check working.
|
||||||
|
* The "half of claimed length" finding is single-sourced inside this corpus (RULER's suite, repeated by the survey).
|
||||||
|
Stated as a hole in `SYNTHESIS.md` §6.1 rather than smoothed over.
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
# longcontext-citations — claimed context length vs usable context length
|
||||||
|
|
||||||
|
**Wizard:** sphinx (lane: Archive — multimodal, long-context research) · **Date:** 2026-10-21
|
||||||
|
**Artifact:** `SYNTHESIS.md` — a verbatim-cited cross-paper synthesis of six long-context papers,
|
||||||
|
backed by `citations.json` (29 byte-exact quotations) and a verifier that re-derives every one of them.
|
||||||
|
|
||||||
|
## What it claims
|
||||||
|
|
||||||
|
In this corpus, the context window a paper *claims* and the context window it can *use* are different quantities, and
|
||||||
|
the field says so about itself:
|
||||||
|
|
||||||
|
* the 2025 survey: "there exists a significant gap between the context length these models claim to support and the
|
||||||
|
actual context length they can process effectively" ([SURVEY-1]); "the effective context length rarely exceeds half
|
||||||
|
of the claimed length" ([SURVEY-2]);
|
||||||
|
* RULER: "only half of them can effectively handle sequence length of 32K … almost all models fall below the threshold
|
||||||
|
before reaching the claimed context lengths" ([RULER-1]), where "effective" is defined by a fixed threshold —
|
||||||
|
Llama2-7B's 4K score ([RULER-4]);
|
||||||
|
* the failure is positional (U-shaped) and still reported as such two years later ([LITM-1], [SURVEY-3]);
|
||||||
|
* extension itself got cheap (YaRN: 10x fewer tokens, 2.5x fewer steps [YARN-2]; DCA: training-free >100K [DCA-1];
|
||||||
|
data engineering: 500M–5B tokens for retrieval anywhere in 128K [DATAENG-1]), which moves the bottleneck to data
|
||||||
|
mixture and to measurement.
|
||||||
|
|
||||||
|
Full argument, counter-arguments and what would refute each section: `SYNTHESIS.md` (§7).
|
||||||
|
|
||||||
|
## How it was built, and what is verified
|
||||||
|
|
||||||
|
extract.py fetch 6 arXiv HTML papers -> sources/*.txt + manifest.json (sha256 per file)
|
||||||
|
harvest.py locate 29 spans in the frozen text -> citations.json (quote, offset, line, section)
|
||||||
|
build_synthesis.py render SYNTHESIS.md from SYNTHESIS.template.md (quotes injected byte-exact)
|
||||||
|
verify.py 307 independent checks over corpus + citations + synthesis
|
||||||
|
self_test.py the CHECK: clean artifact must pass, 4 tampered copies must fail
|
||||||
|
|
||||||
|
Measured on this machine, 2026-10-21:
|
||||||
|
|
||||||
|
| run | result |
|
||||||
|
|---|---|
|
||||||
|
| `python3 verify.py` | 307 checks, 0 failed — "VERIFICATION PASSED — 29 citations re-derived byte-for-byte from 6 frozen papers (110,574 source words)" |
|
||||||
|
| `python3 self_test.py` | clean run passes; tampered source byte, altered stored quote, shifted `char_offset`, renamed synthesis id — **all 4 caught**, verifier exit 1 |
|
||||||
|
|
||||||
|
## Layout
|
||||||
|
|
||||||
|
SYNTHESIS.md the deliverable (rendered; do not hand-edit — edit the template)
|
||||||
|
SYNTHESIS.template.md source of truth for the prose, with {{Q:<id>}} quote tokens
|
||||||
|
citations.json 29 citations: quote, slug, arXiv id, section, line, char_offset, words
|
||||||
|
manifest.json 6 papers: titles, arXiv ids, sha256 of HTML and of extracted text, counts
|
||||||
|
sources/ frozen corpus (arXiv HTML + extracted plain text)
|
||||||
|
NOTES.md corrections made during the build + honest limits
|
||||||
|
verify.py, self_test.py, extract.py, harvest.py, build_synthesis.py, frontmatter.py
|
||||||
|
|
||||||
|
## Limits
|
||||||
|
|
||||||
|
Text-layer only; no figure/table images read. Inline math is duplicated by arXiv's HTML renderer (disclosed in
|
||||||
|
`SYNTHESIS.md` §1). The archive verifies what the six papers say, not that their experiments are right — and it runs
|
||||||
|
no model of its own. Re-fetching the corpus later may legitimately change hashes and fail check 1.
|
||||||
|
|
||||||
|
## Reproduce
|
||||||
|
|
||||||
|
cd <this directory>
|
||||||
|
python3 verify.py # 0 = every claim re-derived from the frozen bytes
|
||||||
|
python3 self_test.py # 0 = verifier passes clean AND rejects 4 tampers
|
||||||
@@ -0,0 +1,285 @@
|
|||||||
|
# Claimed context length is not usable context length
|
||||||
|
|
||||||
|
### A verbatim-cited archive of six long-context papers — 110,574 words of frozen source, 29 machine-checkable quotations
|
||||||
|
|
||||||
|
**Lane:** Archive (multimodal, long-context research) · **Author:** sphinx · **Built:** 2026-10-21
|
||||||
|
**Artifact set:** this synthesis, `citations.json`, `manifest.json`, `sources/` (frozen arXiv HTML + extracted text), `verify.py`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 0. What this is, and how to read it
|
||||||
|
|
||||||
|
Six long-context papers were fetched as arXiv HTML on 2026-10-21, converted to plain text, hashed, and frozen
|
||||||
|
(`sources/`, `manifest.json`). Twenty-nine load-bearing spans were then extracted **byte-for-byte** from those frozen
|
||||||
|
texts — not retyped — and stored with their character offset, line number and section heading (`citations.json`,
|
||||||
|
produced by `harvest.py`). `verify.py` re-derives every one of them from the sources and fails if a single byte,
|
||||||
|
offset, line number, section or attribution disagrees.
|
||||||
|
|
||||||
|
Two kinds of statement appear below and are labelled as such:
|
||||||
|
|
||||||
|
* **measured** — re-derived by script from the frozen corpus (hashes, offsets, word counts, presence of a span).
|
||||||
|
* **claimed** — the paper's own words, quoted verbatim and pinned to a file offset. I do not vouch for the
|
||||||
|
experiment behind it; I vouch that the paper says it, at that line.
|
||||||
|
|
||||||
|
The thesis this archive supports: in this corpus, the **claimed** context window and the **usable** context window are
|
||||||
|
different quantities, and the field says so about itself.
|
||||||
|
|
||||||
|
## 1. The corpus
|
||||||
|
|
||||||
|
| slug | arXiv | title | words | text sha256 (first 12) |
|
||||||
|
|---|---|---|---|---|
|
||||||
|
| lost-in-the-middle | 2307.03172 | Lost in the Middle: How Language Models Use Long Contexts | 9344 | `0853c5c8f082` |
|
||||||
|
| ruler | 2404.06654 | Ruler: What’s the Real Context Size of Your Long-Context Language Models? | 13150 | `2c4837440b13` |
|
||||||
|
| dca-training-free | 2402.17463 | Training-Free Long-Context Scaling of Large Language Models | 11556 | `ff70dfff9fa3` |
|
||||||
|
| yarn | 2309.00071 | YaRN: Efficient Context Window Extension of Large Language Models | 9118 | `5094e6676e15` |
|
||||||
|
| lclm-survey | 2503.17407 | A Comprehensive Survey on Long Context Language Modeling | 60144 | `36126f969b61` |
|
||||||
|
| data-eng-128k | 2402.10171 | Data Engineering for Scaling Language Models to 128K Context | 7262 | `52113f58d5c7` |
|
||||||
|
| **total** | 6 papers | | **110574** | |
|
||||||
|
|
||||||
|
Extraction is lossy in one known, reproducible way: arXiv's HTML renderer duplicates inline math, so a span such as
|
||||||
|
`s=16` can appear as `s=16s=16` in the extracted text. Quotes were chosen to avoid such artifacts; the artifact is
|
||||||
|
disclosed here rather than silently cleaned, because cleaning it would break the byte-exactness that makes the
|
||||||
|
citations checkable.
|
||||||
|
|
||||||
|
## 2. The gap is the literature's own headline finding
|
||||||
|
|
||||||
|
The 2025 survey states the problem directly:
|
||||||
|
|
||||||
|
> "Despite this impressive scaling of context extension, there exists a significant gap between the context length these models claim to support and the actual context length they can process effectively"
|
||||||
|
|
||||||
|
and then quantifies it from the benchmark literature it reviews:
|
||||||
|
|
||||||
|
> "The findings reveal a consistent pattern: For most models across both categories, the effective context length rarely exceeds half of the claimed length."
|
||||||
|
|
||||||
|
That "half" figure is not the survey's own experiment — it is its reading of RULER, whose authors put the same result
|
||||||
|
in the abstract of their introduction:
|
||||||
|
|
||||||
|
> "While all models claim context size of 32k tokens or greater, our results indicate that only half of them can effectively handle sequence length of 32K by exceeding a qualitative threshold. Moreover, almost all models fall below the threshold before reaching the claimed context lengths."
|
||||||
|
|
||||||
|
RULER's own evaluation section is blunter still: at their claimed lengths, the models it tested do not beat a
|
||||||
|
Llama2-7B baseline on the RULER suite:
|
||||||
|
|
||||||
|
> "while they achieve nearly perfect performance on the passkey retrieval and the vanilla NIAH task (shown in Appendix E), all of them exhibit large degradation in RULER as sequence length increases and they fail to maintain performance above the Llama2-7B baseline at their claimed length."
|
||||||
|
|
||||||
|
**Reading.** Three independent documents in this corpus (a survey, a benchmark paper, and the benchmark's own results
|
||||||
|
section) agree on the shape of the finding. None of them is a re-analysis of the others' raw data, so this is
|
||||||
|
convergent *testimony*, not independent *replication* — the distinction matters and is why §6 exists.
|
||||||
|
|
||||||
|
## 3. The failure is positional, not merely length-dependent
|
||||||
|
|
||||||
|
The canonical result is from 2023, and it is about *where* information sits, not *how much* there is:
|
||||||
|
|
||||||
|
> "we observe that performance is often highest when relevant information occurs at the beginning or end of the input context, and significantly degrades when models must access relevant information in the middle of long contexts, even for explicitly long-context models."
|
||||||
|
|
||||||
|
The paper's own summary of the mechanism names both biases:
|
||||||
|
|
||||||
|
> "language model performance is highest when relevant information occurs at the very beginning (primacy bias) or end of its input context (recency bias), and performance significantly degrades when models must access and use information in the middle of their input context"
|
||||||
|
|
||||||
|
with a concrete, checkable magnitude — mid-context placement makes GPT-3.5-Turbo worse than having no documents at
|
||||||
|
all:
|
||||||
|
|
||||||
|
> "when relevant information is placed in the middle of its input context, GPT-3.5-Turbo’s performance on the multi-document question task is lower than its performance when predicting without any documents (i.e., the closed-book setting; 56.1%)"
|
||||||
|
|
||||||
|
The survey, two years later, reports the effect as still standing:
|
||||||
|
|
||||||
|
> "performance remains robust when information is located at the beginning or end of the input, but deteriorates substantially when critical information is positioned in the middle"
|
||||||
|
|
||||||
|
Lost in the Middle also supplies the standard of proof that most later work quietly drops — a long-context claim
|
||||||
|
without a position sweep is not a long-context claim:
|
||||||
|
|
||||||
|
> "to claim that a language model can robustly use information within long input contexts, it is necessary to show that its performance is minimally affected by the position of the relevant information in the input context"
|
||||||
|
|
||||||
|
## 4. The certification test is weak, and its threshold is arbitrary
|
||||||
|
|
||||||
|
RULER's opening move is to attack the test that the field was using to certify long context:
|
||||||
|
|
||||||
|
> "The needle-in-a-haystack (NIAH) test, which examines the ability to retrieve a piece of information (the “needle”) from long distractor texts (the “haystack”), has been widely adopted to evaluate long-context language models (LMs). However, this simple retrieval-based test is indicative of only a superficial form of long-context understanding."
|
||||||
|
|
||||||
|
The replacement benchmark is better, but its central verdict — "effective length" — rests on a fixed, admittedly
|
||||||
|
convenient cut:
|
||||||
|
|
||||||
|
> "We use the performance of Llama2-7b model at the 4K context length as the threshold."
|
||||||
|
|
||||||
|
So "effective length" in this corpus means *the longest length at which a model still beats a 7B model's 4K score*.
|
||||||
|
That is a defensible, reproducible convention, and it is also a convention: it is not a capability boundary.
|
||||||
|
|
||||||
|
Meanwhile the training-free line of work certifies its own long-context claims with the very metrics RULER calls
|
||||||
|
superficial. DCA reports a 4K→32K+ extension with flat perplexity:
|
||||||
|
|
||||||
|
> "It first shows that LLMs with a 4k context window can be expanded to more than 32k without training, maintaining a negligible increase in PPL, whereas previous methods typically falter at context lengths beyond 8k."
|
||||||
|
|
||||||
|
and orthogonality to existing long-context models demonstrated at 192K — on passkey retrieval accuracy and perplexity:
|
||||||
|
|
||||||
|
> "existing long-context LLMs, which have already supported a 32k context window, can further extrapolate to a 192k context length while maintaining high passkey retrieval accuracy and low perplexity."
|
||||||
|
|
||||||
|
DCA is honest about where prior training-free methods break, which is the useful part of the result:
|
||||||
|
|
||||||
|
> "in a training-free setting, we find that these approaches usually lead to a notable increase in PPL especially in input lengths that are more than twice the training length"
|
||||||
|
|
||||||
|
**Reading.** The corpus contains a metric war. PPL and passkey accuracy are cheap, continuous and reproducible; NIAH
|
||||||
|
and RULER-style task suites are expensive and thresholded. A model's "context length" is a statement about which of
|
||||||
|
these you accepted.
|
||||||
|
|
||||||
|
## 5. Extension got cheap; the bottleneck moved to data and measurement
|
||||||
|
|
||||||
|
The positional-encoding line (YaRN) made extension a compute question with a small, quotable budget:
|
||||||
|
|
||||||
|
> "Rotary Position Embeddings (RoPE) have been shown to effectively encode positional information in transformer-based language models.
|
||||||
|
However, these models fail to generalize past the sequence length they were trained on."
|
||||||
|
|
||||||
|
> "We present YaRN (Yet another RoPE extensioN method), a compute-efficient method to extend the context window of such models, requiring 10x less tokens and 2.5x less training steps than previous methods."
|
||||||
|
|
||||||
|
The absolute numbers behind that multiplier are small enough to be checkable by anyone with a GPU node — 400 steps
|
||||||
|
against a prior method's 1000, for comparable results:
|
||||||
|
|
||||||
|
> "Even if YaRN was only fine-tuned for 400 steps compared to PI’s 1000 steps, we obtain similar results to PI."
|
||||||
|
|
||||||
|
> "As shown in Figure 2, YaRN converges faster compared to other interpolation techniques during training and consistently has lower loss."
|
||||||
|
|
||||||
|
The training-free line pushed the cost to zero for inference-time extension:
|
||||||
|
|
||||||
|
> "Given the expensive overhead of finetuning large-scale models with longer sequences, we propose Dual Chunk Attention (DCA), which enables Llama2 70B to support context windows of more than 100k tokens without continual training."
|
||||||
|
|
||||||
|
with a headline quality claim pinned to a proprietary 16K model:
|
||||||
|
|
||||||
|
> "our training-free 70B model attains 94% of the performance of gpt-3.5-16k, indicating it is a viable open-source alternative."
|
||||||
|
|
||||||
|
If extension is that cheap, the interesting question is what you must *feed* it — and here the corpus gives the most
|
||||||
|
actionable numbers in the set. Data quantity first:
|
||||||
|
|
||||||
|
> "for quantity, we show that 500 million to 5 billion tokens are enough to enable the model to retrieve information anywhere within the 128K context"
|
||||||
|
|
||||||
|
Data mixture second, and it contradicts a common practice:
|
||||||
|
|
||||||
|
> "naïvely upsampling longer data on certain domains like books, a common practice of existing work, gives suboptimal performance, and that a balanced domain mixture is important."
|
||||||
|
|
||||||
|
The mechanism claimed is not learning a new capability but surfacing one that pretraining already installed:
|
||||||
|
|
||||||
|
> "continual pretraining on a small amount of long-context data, in our case, 1-5B tokens, can “unlock” a 7B model’s capability of precise retrieval over much longer context lengths than seen in original pretraining."
|
||||||
|
|
||||||
|
and the returns saturate early:
|
||||||
|
|
||||||
|
> "the model’s retrieval performance saturates at about 5B tokens, and further scaling to 10B tokens does not improve length generalization."
|
||||||
|
|
||||||
|
Two further results cut against the intuition that more training is the lever. Larger training context is not
|
||||||
|
necessary for good long-context behaviour, and training longer is not monotonically better:
|
||||||
|
|
||||||
|
> "training on longer sequences does not always lead to better performance on Ruler, and that larger model sizes positively correlate with better long-context capabilities."
|
||||||
|
|
||||||
|
and one analysis argues that a whole family of extension tricks buys only surface-level capability:
|
||||||
|
|
||||||
|
> "They point out that scaling down rotation bases can only achieve superficial long context capabilities."
|
||||||
|
|
||||||
|
**Summary table of the extension claims in this corpus.** All figures are the authors' *claimed* numbers; the third
|
||||||
|
column points at the citation that carries the claim.
|
||||||
|
|
||||||
|
| method | claimed result | cost claimed | citation |
|
||||||
|
|---|---|---|---|
|
||||||
|
| YaRN | context extension to 128K-class windows; beats PI at equal budget | 10x fewer tokens, 2.5x fewer steps | [YARN-2] |
|
||||||
|
| YaRN | comparable to PI at 400 vs 1000 steps | ~400 fine-tuning steps | [YARN-4] |
|
||||||
|
| DCA (training-free) | Llama2-70B to >100K; 94% of gpt-3.5-16k on practical long-context tasks | no continual training | [DCA-1], [DCA-2] |
|
||||||
|
| DCA (training-free) | existing 32K models extrapolate to 192K on passkey + PPL | no continual training | [DCA-5] |
|
||||||
|
| Data engineering | retrieval anywhere in 128K | 500M–5B continual-pretraining tokens | [DATAENG-1] |
|
||||||
|
| Data engineering | saturation | >5B tokens does not help length generalisation | [DATAENG-4] |
|
||||||
|
| RULER | effective length ≈ half of claimed length | benchmark suite, 13 tasks | [RULER-1] |
|
||||||
|
|
||||||
|
## 6. Holes: what these six papers do not settle
|
||||||
|
|
||||||
|
1. **No independent replication.** Every "half of claimed length" number here traces back to RULER's suite. The survey
|
||||||
|
repeats it; it does not re-run it. Within this corpus the gap is well-attested and single-sourced.
|
||||||
|
2. **The economics of long context vs retrieval are not closed.** The only quantitative cost comparison in the corpus
|
||||||
|
is from 2023 and is about retrieved documents, not window size:
|
||||||
|
|
||||||
|
> "we find that model performance saturates long before retriever recall saturates, indicating that current models fail to effectively use additional retrieved documents"
|
||||||
|
|
||||||
|
3. **Multimodal long context is present only as a survey taxonomy.** The survey is the one document here that covers
|
||||||
|
images and video at all, and it covers them at the level of benchmark inventory:
|
||||||
|
|
||||||
|
> "Multimodal long context benchmarks can primarily be divided into two types: those that use multiple images and those that use long videos as the context."
|
||||||
|
|
||||||
|
with a difficulty ordering that is asserted rather than measured in this corpus:
|
||||||
|
|
||||||
|
> "Compared to multi-image long context data, understanding long videos is more challenging due to their larger context length and the inclusion of more redundant and noisy information."
|
||||||
|
|
||||||
|
Nothing in the corpus supplies a multimodal counterpart to RULER — i.e. a *positional* stress test for long video or
|
||||||
|
many-image contexts. That is the clearest open slot this archive exposes.
|
||||||
|
4. **Long-form generation is out of scope of every citation above.** All six papers certify comprehension/retrieval;
|
||||||
|
none of the spans harvested here measures whether the model can *produce* coherent long output.
|
||||||
|
|
||||||
|
## 7. What would refute this synthesis
|
||||||
|
|
||||||
|
* **Refute §2** by showing a position-controlled benchmark on which current models hold ≥90% of their 4K score at
|
||||||
|
their claimed length — then "effective length ≈ claimed length" and RULER's half-rule is dated, not wrong.
|
||||||
|
* **Refute §4** by re-running RULER's threshold (Llama2-7B @ 4K) on a current model family and showing the verdict is
|
||||||
|
insensitive to the threshold choice; that would convert an arbitrary convention into a robust one.
|
||||||
|
* **Refute §5's data-efficiency claim** by showing that DATAENG's 500M–5B recipe fails to transfer to a base model
|
||||||
|
family other than the one it was run on; the paper's own hypothesis — that the capability is already present — is
|
||||||
|
exactly what a transfer test would probe.
|
||||||
|
* **Refute §6.3** by pointing to any positional long-context stress test for video/many-image inputs; if one exists,
|
||||||
|
this archive simply failed to include it, and the "open slot" is a coverage gap in the corpus rather than in the
|
||||||
|
field.
|
||||||
|
|
||||||
|
## 8. Reproduction
|
||||||
|
|
||||||
|
cd /root/.hermes/wizard-outputs/sphinx/longcontext-citations
|
||||||
|
python3 extract.py # re-fetch arXiv HTML, rebuild sources/*.txt + manifest.json (hashes)
|
||||||
|
python3 harvest.py # rebuild citations.json byte-for-byte from the frozen sources
|
||||||
|
python3 build_synthesis.py # re-render this file from SYNTHESIS.template.md
|
||||||
|
python3 verify.py # THE TEST: re-derives every claim above from the frozen corpus
|
||||||
|
|
||||||
|
`verify.py` checks, and exits non-zero on any failure:
|
||||||
|
|
||||||
|
1. SHA-256 of every `sources/*.html` and `sources/*.txt` matches `manifest.json` (corpus unmodified).
|
||||||
|
2. Byte/line/word counts in the manifest match the files on disk.
|
||||||
|
3. Each manifest title and arXiv id stamp actually occurs in its source text.
|
||||||
|
4. For each of the 29 citations: the stored quote is an **exact byte substring** of its source at the
|
||||||
|
stored `char_offset`; an independent whitespace/unicode-normalised search finds it at the same offset; the stored
|
||||||
|
line number matches; the quote is ≥15 words; the section heading exists and precedes it.
|
||||||
|
5. No citation is attributed to the wrong paper: each quote is unique across the whole corpus.
|
||||||
|
6. Coverage: every paper is cited, ≥2 citations each, all ids and quote texts unique.
|
||||||
|
7. This file references every citation id, embeds the first twelve words of every quote, and carries every corpus
|
||||||
|
hash prefix — i.e. the prose and the evidence cannot drift apart.
|
||||||
|
|
||||||
|
**Honest limits.** Fetch date is 2026-10-21; arXiv HTML is mutable, so `extract.py` re-fetching later may change
|
||||||
|
hashes and legitimately break check 1 — that is the check working, not failing. No PDF-only figure or table content
|
||||||
|
was read (the corpus is text-layer only). And every "measured" number here is measured *about the text*, never about a
|
||||||
|
model: this archive verifies what six papers say, not that they are right.
|
||||||
|
|
||||||
|
## Appendix A — evidence index (generated from `citations.json`)
|
||||||
|
|
||||||
|
Every row is re-derived from the frozen sources by `verify.py`: `offset` is the byte position of the
|
||||||
|
quote in `sources/<slug>.txt` and `line` its 1-based line number.
|
||||||
|
|
||||||
|
| id | paper (arXiv) | section | line | offset | words |
|
||||||
|
|---|---|---|---|---|---|
|
||||||
|
| `LITM-1` | lost-in-the-middle (2307.03172) | Abstract | 60 | 2434 | 40 |
|
||||||
|
| `LITM-2` | lost-in-the-middle (2307.03172) | 1 Introduction | 78 | 6934 | 41 |
|
||||||
|
| `LITM-3` | lost-in-the-middle (2307.03172) | 1 Introduction | 79 | 7227 | 34 |
|
||||||
|
| `LITM-4` | lost-in-the-middle (2307.03172) | 1 Introduction | 92 | 10361 | 22 |
|
||||||
|
| `LITM-5` | lost-in-the-middle (2307.03172) | 1 Introduction | 93 | 10840 | 36 |
|
||||||
|
| `RULER-1` | ruler (2404.06654) | 1 Introduction | 150 | 6418 | 45 |
|
||||||
|
| `RULER-2` | ruler (2404.06654) | Abstract | 70 | 1790 | 47 |
|
||||||
|
| `RULER-3` | ruler (2404.06654) | 4 Experiments & Results | 540 | 26133 | 45 |
|
||||||
|
| `RULER-4` | ruler (2404.06654) | 4 Experiments & Results | 306 | 22598 | 15 |
|
||||||
|
| `RULER-5` | ruler (2404.06654) | 1 Introduction | 152 | 7657 | 24 |
|
||||||
|
| `DCA-1` | dca-training-free (2402.17463) | Abstract | 67 | 1567 | 33 |
|
||||||
|
| `DCA-2` | dca-training-free (2402.17463) | Abstract | 68 | 2316 | 18 |
|
||||||
|
| `DCA-3` | dca-training-free (2402.17463) | 1 Introduction | 80 | 5241 | 29 |
|
||||||
|
| `DCA-4` | dca-training-free (2402.17463) | 1 Introduction | 89 | 7944 | 35 |
|
||||||
|
| `DCA-5` | dca-training-free (2402.17463) | 1 Introduction | 92 | 8516 | 28 |
|
||||||
|
| `YARN-1` | yarn (2309.00071) | Abstract | 60 | 1538 | 30 |
|
||||||
|
| `YARN-2` | yarn (2309.00071) | Abstract | 62 | 1759 | 31 |
|
||||||
|
| `YARN-3` | yarn (2309.00071) | 4.1 Training | 208 | 25374 | 20 |
|
||||||
|
| `YARN-4` | yarn (2309.00071) | B.2 Training Efficiency of YaRN | 1008 | 51640 | 20 |
|
||||||
|
| `SURVEY-1` | lclm-survey (2503.17407) | 7.1.1 The False Promise of Support Context Length | 1884 | 175760 | 30 |
|
||||||
|
| `SURVEY-2` | lclm-survey (2503.17407) | 7.1.1 The False Promise of Support Context Length | 1884 | 176732 | 23 |
|
||||||
|
| `SURVEY-3` | lclm-survey (2503.17407) | 7.1.1 The False Promise of Support Context Length | 1884 | 176159 | 26 |
|
||||||
|
| `SURVEY-4` | lclm-survey (2503.17407) | 7.2.1 Positional Embedding | 2014 | 186649 | 15 |
|
||||||
|
| `SURVEY-5` | lclm-survey (2503.17407) | 8.6 Application in Multimodal Tasks | 2072 | 203402 | 25 |
|
||||||
|
| `SURVEY-6` | lclm-survey (2503.17407) | 8.6 Application in Multimodal Tasks | 2072 | 204516 | 27 |
|
||||||
|
| `DATAENG-1` | data-eng-128k (2402.10171) | Abstract | 37 | 1265 | 25 |
|
||||||
|
| `DATAENG-2` | data-eng-128k (2402.10171) | Abstract | 39 | 1523 | 26 |
|
||||||
|
| `DATAENG-3` | data-eng-128k (2402.10171) | 1 Introduction | 72 | 6040 | 33 |
|
||||||
|
| `DATAENG-4` | data-eng-128k (2402.10171) | 5.1 Overall Performance | 267 | 24011 | 20 |
|
||||||
|
|
||||||
|
Total: 29 citations across 6 papers.
|
||||||
@@ -0,0 +1,239 @@
|
|||||||
|
# Claimed context length is not usable context length
|
||||||
|
|
||||||
|
### A verbatim-cited archive of six long-context papers — {{TOTAL_WORDS}} words of frozen source, {{CITATION_COUNT}} machine-checkable quotations
|
||||||
|
|
||||||
|
**Lane:** Archive (multimodal, long-context research) · **Author:** sphinx · **Built:** {{GENERATED}}
|
||||||
|
**Artifact set:** this synthesis, `citations.json`, `manifest.json`, `sources/` (frozen arXiv HTML + extracted text), `verify.py`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 0. What this is, and how to read it
|
||||||
|
|
||||||
|
Six long-context papers were fetched as arXiv HTML on {{GENERATED}}, converted to plain text, hashed, and frozen
|
||||||
|
(`sources/`, `manifest.json`). Twenty-nine load-bearing spans were then extracted **byte-for-byte** from those frozen
|
||||||
|
texts — not retyped — and stored with their character offset, line number and section heading (`citations.json`,
|
||||||
|
produced by `harvest.py`). `verify.py` re-derives every one of them from the sources and fails if a single byte,
|
||||||
|
offset, line number, section or attribution disagrees.
|
||||||
|
|
||||||
|
Two kinds of statement appear below and are labelled as such:
|
||||||
|
|
||||||
|
* **measured** — re-derived by script from the frozen corpus (hashes, offsets, word counts, presence of a span).
|
||||||
|
* **claimed** — the paper's own words, quoted verbatim and pinned to a file offset. I do not vouch for the
|
||||||
|
experiment behind it; I vouch that the paper says it, at that line.
|
||||||
|
|
||||||
|
The thesis this archive supports: in this corpus, the **claimed** context window and the **usable** context window are
|
||||||
|
different quantities, and the field says so about itself.
|
||||||
|
|
||||||
|
## 1. The corpus
|
||||||
|
|
||||||
|
{{MANIFEST_TABLE}}
|
||||||
|
|
||||||
|
Extraction is lossy in one known, reproducible way: arXiv's HTML renderer duplicates inline math, so a span such as
|
||||||
|
`s=16` can appear as `s=16s=16` in the extracted text. Quotes were chosen to avoid such artifacts; the artifact is
|
||||||
|
disclosed here rather than silently cleaned, because cleaning it would break the byte-exactness that makes the
|
||||||
|
citations checkable.
|
||||||
|
|
||||||
|
## 2. The gap is the literature's own headline finding
|
||||||
|
|
||||||
|
The 2025 survey states the problem directly:
|
||||||
|
|
||||||
|
> "{{Q:SURVEY-1}}"
|
||||||
|
|
||||||
|
and then quantifies it from the benchmark literature it reviews:
|
||||||
|
|
||||||
|
> "{{Q:SURVEY-2}}"
|
||||||
|
|
||||||
|
That "half" figure is not the survey's own experiment — it is its reading of RULER, whose authors put the same result
|
||||||
|
in the abstract of their introduction:
|
||||||
|
|
||||||
|
> "{{Q:RULER-1}}"
|
||||||
|
|
||||||
|
RULER's own evaluation section is blunter still: at their claimed lengths, the models it tested do not beat a
|
||||||
|
Llama2-7B baseline on the RULER suite:
|
||||||
|
|
||||||
|
> "{{Q:RULER-3}}"
|
||||||
|
|
||||||
|
**Reading.** Three independent documents in this corpus (a survey, a benchmark paper, and the benchmark's own results
|
||||||
|
section) agree on the shape of the finding. None of them is a re-analysis of the others' raw data, so this is
|
||||||
|
convergent *testimony*, not independent *replication* — the distinction matters and is why §6 exists.
|
||||||
|
|
||||||
|
## 3. The failure is positional, not merely length-dependent
|
||||||
|
|
||||||
|
The canonical result is from 2023, and it is about *where* information sits, not *how much* there is:
|
||||||
|
|
||||||
|
> "{{Q:LITM-1}}"
|
||||||
|
|
||||||
|
The paper's own summary of the mechanism names both biases:
|
||||||
|
|
||||||
|
> "{{Q:LITM-2}}"
|
||||||
|
|
||||||
|
with a concrete, checkable magnitude — mid-context placement makes GPT-3.5-Turbo worse than having no documents at
|
||||||
|
all:
|
||||||
|
|
||||||
|
> "{{Q:LITM-3}}"
|
||||||
|
|
||||||
|
The survey, two years later, reports the effect as still standing:
|
||||||
|
|
||||||
|
> "{{Q:SURVEY-3}}"
|
||||||
|
|
||||||
|
Lost in the Middle also supplies the standard of proof that most later work quietly drops — a long-context claim
|
||||||
|
without a position sweep is not a long-context claim:
|
||||||
|
|
||||||
|
> "{{Q:LITM-5}}"
|
||||||
|
|
||||||
|
## 4. The certification test is weak, and its threshold is arbitrary
|
||||||
|
|
||||||
|
RULER's opening move is to attack the test that the field was using to certify long context:
|
||||||
|
|
||||||
|
> "{{Q:RULER-2}}"
|
||||||
|
|
||||||
|
The replacement benchmark is better, but its central verdict — "effective length" — rests on a fixed, admittedly
|
||||||
|
convenient cut:
|
||||||
|
|
||||||
|
> "{{Q:RULER-4}}"
|
||||||
|
|
||||||
|
So "effective length" in this corpus means *the longest length at which a model still beats a 7B model's 4K score*.
|
||||||
|
That is a defensible, reproducible convention, and it is also a convention: it is not a capability boundary.
|
||||||
|
|
||||||
|
Meanwhile the training-free line of work certifies its own long-context claims with the very metrics RULER calls
|
||||||
|
superficial. DCA reports a 4K→32K+ extension with flat perplexity:
|
||||||
|
|
||||||
|
> "{{Q:DCA-4}}"
|
||||||
|
|
||||||
|
and orthogonality to existing long-context models demonstrated at 192K — on passkey retrieval accuracy and perplexity:
|
||||||
|
|
||||||
|
> "{{Q:DCA-5}}"
|
||||||
|
|
||||||
|
DCA is honest about where prior training-free methods break, which is the useful part of the result:
|
||||||
|
|
||||||
|
> "{{Q:DCA-3}}"
|
||||||
|
|
||||||
|
**Reading.** The corpus contains a metric war. PPL and passkey accuracy are cheap, continuous and reproducible; NIAH
|
||||||
|
and RULER-style task suites are expensive and thresholded. A model's "context length" is a statement about which of
|
||||||
|
these you accepted.
|
||||||
|
|
||||||
|
## 5. Extension got cheap; the bottleneck moved to data and measurement
|
||||||
|
|
||||||
|
The positional-encoding line (YaRN) made extension a compute question with a small, quotable budget:
|
||||||
|
|
||||||
|
> "{{Q:YARN-1}}"
|
||||||
|
|
||||||
|
> "{{Q:YARN-2}}"
|
||||||
|
|
||||||
|
The absolute numbers behind that multiplier are small enough to be checkable by anyone with a GPU node — 400 steps
|
||||||
|
against a prior method's 1000, for comparable results:
|
||||||
|
|
||||||
|
> "{{Q:YARN-4}}"
|
||||||
|
|
||||||
|
> "{{Q:YARN-3}}"
|
||||||
|
|
||||||
|
The training-free line pushed the cost to zero for inference-time extension:
|
||||||
|
|
||||||
|
> "{{Q:DCA-1}}"
|
||||||
|
|
||||||
|
with a headline quality claim pinned to a proprietary 16K model:
|
||||||
|
|
||||||
|
> "{{Q:DCA-2}}"
|
||||||
|
|
||||||
|
If extension is that cheap, the interesting question is what you must *feed* it — and here the corpus gives the most
|
||||||
|
actionable numbers in the set. Data quantity first:
|
||||||
|
|
||||||
|
> "{{Q:DATAENG-1}}"
|
||||||
|
|
||||||
|
Data mixture second, and it contradicts a common practice:
|
||||||
|
|
||||||
|
> "{{Q:DATAENG-2}}"
|
||||||
|
|
||||||
|
The mechanism claimed is not learning a new capability but surfacing one that pretraining already installed:
|
||||||
|
|
||||||
|
> "{{Q:DATAENG-3}}"
|
||||||
|
|
||||||
|
and the returns saturate early:
|
||||||
|
|
||||||
|
> "{{Q:DATAENG-4}}"
|
||||||
|
|
||||||
|
Two further results cut against the intuition that more training is the lever. Larger training context is not
|
||||||
|
necessary for good long-context behaviour, and training longer is not monotonically better:
|
||||||
|
|
||||||
|
> "{{Q:RULER-5}}"
|
||||||
|
|
||||||
|
and one analysis argues that a whole family of extension tricks buys only surface-level capability:
|
||||||
|
|
||||||
|
> "{{Q:SURVEY-4}}"
|
||||||
|
|
||||||
|
**Summary table of the extension claims in this corpus.** All figures are the authors' *claimed* numbers; the third
|
||||||
|
column points at the citation that carries the claim.
|
||||||
|
|
||||||
|
| method | claimed result | cost claimed | citation |
|
||||||
|
|---|---|---|---|
|
||||||
|
| YaRN | context extension to 128K-class windows; beats PI at equal budget | 10x fewer tokens, 2.5x fewer steps | [YARN-2] |
|
||||||
|
| YaRN | comparable to PI at 400 vs 1000 steps | ~400 fine-tuning steps | [YARN-4] |
|
||||||
|
| DCA (training-free) | Llama2-70B to >100K; 94% of gpt-3.5-16k on practical long-context tasks | no continual training | [DCA-1], [DCA-2] |
|
||||||
|
| DCA (training-free) | existing 32K models extrapolate to 192K on passkey + PPL | no continual training | [DCA-5] |
|
||||||
|
| Data engineering | retrieval anywhere in 128K | 500M–5B continual-pretraining tokens | [DATAENG-1] |
|
||||||
|
| Data engineering | saturation | >5B tokens does not help length generalisation | [DATAENG-4] |
|
||||||
|
| RULER | effective length ≈ half of claimed length | benchmark suite, 13 tasks | [RULER-1] |
|
||||||
|
|
||||||
|
## 6. Holes: what these six papers do not settle
|
||||||
|
|
||||||
|
1. **No independent replication.** Every "half of claimed length" number here traces back to RULER's suite. The survey
|
||||||
|
repeats it; it does not re-run it. Within this corpus the gap is well-attested and single-sourced.
|
||||||
|
2. **The economics of long context vs retrieval are not closed.** The only quantitative cost comparison in the corpus
|
||||||
|
is from 2023 and is about retrieved documents, not window size:
|
||||||
|
|
||||||
|
> "{{Q:LITM-4}}"
|
||||||
|
|
||||||
|
3. **Multimodal long context is present only as a survey taxonomy.** The survey is the one document here that covers
|
||||||
|
images and video at all, and it covers them at the level of benchmark inventory:
|
||||||
|
|
||||||
|
> "{{Q:SURVEY-5}}"
|
||||||
|
|
||||||
|
with a difficulty ordering that is asserted rather than measured in this corpus:
|
||||||
|
|
||||||
|
> "{{Q:SURVEY-6}}"
|
||||||
|
|
||||||
|
Nothing in the corpus supplies a multimodal counterpart to RULER — i.e. a *positional* stress test for long video or
|
||||||
|
many-image contexts. That is the clearest open slot this archive exposes.
|
||||||
|
4. **Long-form generation is out of scope of every citation above.** All six papers certify comprehension/retrieval;
|
||||||
|
none of the spans harvested here measures whether the model can *produce* coherent long output.
|
||||||
|
|
||||||
|
## 7. What would refute this synthesis
|
||||||
|
|
||||||
|
* **Refute §2** by showing a position-controlled benchmark on which current models hold ≥90% of their 4K score at
|
||||||
|
their claimed length — then "effective length ≈ claimed length" and RULER's half-rule is dated, not wrong.
|
||||||
|
* **Refute §4** by re-running RULER's threshold (Llama2-7B @ 4K) on a current model family and showing the verdict is
|
||||||
|
insensitive to the threshold choice; that would convert an arbitrary convention into a robust one.
|
||||||
|
* **Refute §5's data-efficiency claim** by showing that DATAENG's 500M–5B recipe fails to transfer to a base model
|
||||||
|
family other than the one it was run on; the paper's own hypothesis — that the capability is already present — is
|
||||||
|
exactly what a transfer test would probe.
|
||||||
|
* **Refute §6.3** by pointing to any positional long-context stress test for video/many-image inputs; if one exists,
|
||||||
|
this archive simply failed to include it, and the "open slot" is a coverage gap in the corpus rather than in the
|
||||||
|
field.
|
||||||
|
|
||||||
|
## 8. Reproduction
|
||||||
|
|
||||||
|
cd {{ARTIFACT_DIR}}
|
||||||
|
python3 extract.py # re-fetch arXiv HTML, rebuild sources/*.txt + manifest.json (hashes)
|
||||||
|
python3 harvest.py # rebuild citations.json byte-for-byte from the frozen sources
|
||||||
|
python3 build_synthesis.py # re-render this file from SYNTHESIS.template.md
|
||||||
|
python3 verify.py # THE TEST: re-derives every claim above from the frozen corpus
|
||||||
|
|
||||||
|
`verify.py` checks, and exits non-zero on any failure:
|
||||||
|
|
||||||
|
1. SHA-256 of every `sources/*.html` and `sources/*.txt` matches `manifest.json` (corpus unmodified).
|
||||||
|
2. Byte/line/word counts in the manifest match the files on disk.
|
||||||
|
3. Each manifest title and arXiv id stamp actually occurs in its source text.
|
||||||
|
4. For each of the {{CITATION_COUNT}} citations: the stored quote is an **exact byte substring** of its source at the
|
||||||
|
stored `char_offset`; an independent whitespace/unicode-normalised search finds it at the same offset; the stored
|
||||||
|
line number matches; the quote is ≥15 words; the section heading exists and precedes it.
|
||||||
|
5. No citation is attributed to the wrong paper: each quote is unique across the whole corpus.
|
||||||
|
6. Coverage: every paper is cited, ≥2 citations each, all ids and quote texts unique.
|
||||||
|
7. This file references every citation id, embeds the first twelve words of every quote, and carries every corpus
|
||||||
|
hash prefix — i.e. the prose and the evidence cannot drift apart.
|
||||||
|
|
||||||
|
**Honest limits.** Fetch date is {{GENERATED}}; arXiv HTML is mutable, so `extract.py` re-fetching later may change
|
||||||
|
hashes and legitimately break check 1 — that is the check working, not failing. No PDF-only figure or table content
|
||||||
|
was read (the corpus is text-layer only). And every "measured" number here is measured *about the text*, never about a
|
||||||
|
model: this archive verifies what six papers say, not that they are right.
|
||||||
|
|
||||||
|
{{EVIDENCE_INDEX}}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Render SYNTHESIS.md from SYNTHESIS.template.md.
|
||||||
|
|
||||||
|
Quotes are never retyped: {{Q:<id>}} is replaced by the canonical byte-exact
|
||||||
|
string stored in citations.json, so the prose can only ever carry the same
|
||||||
|
bytes the verifier will look for. Corpus numbers and hashes are generated from
|
||||||
|
manifest.json for the same reason.
|
||||||
|
|
||||||
|
Run: python3 build_synthesis.py
|
||||||
|
"""
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
GENERATED = "2026-10-21"
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
manifest = json.load(open(os.path.join(HERE, "manifest.json"), encoding="utf-8"))
|
||||||
|
cites = json.load(open(os.path.join(HERE, "citations.json"), encoding="utf-8"))
|
||||||
|
papers = manifest["papers"]
|
||||||
|
by_id = {c["id"]: c for c in cites["citations"]}
|
||||||
|
|
||||||
|
rows = ["| slug | arXiv | title | words | text sha256 (first 12) |",
|
||||||
|
"|---|---|---|---|---|"]
|
||||||
|
for p in papers:
|
||||||
|
rows.append("| %s | %s | %s | %d | `%s` |" % (
|
||||||
|
p["slug"], p["arxiv_id"], p["title"], p["text_words"], p["text_sha256"][:12]))
|
||||||
|
rows.append("| **total** | 6 papers | | **%d** | |" % sum(p["text_words"] for p in papers))
|
||||||
|
manifest_table = "\n".join(rows)
|
||||||
|
|
||||||
|
idx = ["## Appendix A — evidence index (generated from `citations.json`)", "",
|
||||||
|
"Every row is re-derived from the frozen sources by `verify.py`: `offset` is the byte position of the",
|
||||||
|
"quote in `sources/<slug>.txt` and `line` its 1-based line number.", "",
|
||||||
|
"| id | paper (arXiv) | section | line | offset | words |",
|
||||||
|
"|---|---|---|---|---|---|"]
|
||||||
|
for c in cites["citations"]:
|
||||||
|
idx.append("| `%s` | %s (%s) | %s | %d | %d | %d |" % (
|
||||||
|
c["id"], c["slug"], c["arxiv_id"], c["section"], c["line"], c["char_offset"], c["words"]))
|
||||||
|
idx.append("")
|
||||||
|
idx.append("Total: %d citations across %d papers." % (
|
||||||
|
len(cites["citations"]), len({c["slug"] for c in cites["citations"]})))
|
||||||
|
evidence_index = "\n".join(idx)
|
||||||
|
|
||||||
|
tpl = open(os.path.join(HERE, "SYNTHESIS.template.md"), encoding="utf-8").read()
|
||||||
|
|
||||||
|
def sub_q(m):
|
||||||
|
cid = m.group(1)
|
||||||
|
if cid not in by_id:
|
||||||
|
sys.exit("ABORT: unknown citation id %r in template" % cid)
|
||||||
|
return by_id[cid]["quote"]
|
||||||
|
|
||||||
|
out = re.sub(r"\{\{Q:([A-Z0-9\-]+)\}\}", sub_q, tpl)
|
||||||
|
out = out.replace("{{MANIFEST_TABLE}}", manifest_table)
|
||||||
|
out = out.replace("{{EVIDENCE_INDEX}}", evidence_index)
|
||||||
|
out = out.replace("{{TOTAL_WORDS}}", "{:,}".format(sum(p["text_words"] for p in papers)))
|
||||||
|
out = out.replace("{{CITATION_COUNT}}", str(len(cites["citations"])))
|
||||||
|
out = out.replace("{{GENERATED}}", GENERATED)
|
||||||
|
out = out.replace("{{ARTIFACT_DIR}}", HERE)
|
||||||
|
left = re.findall(r"\{\{[^}]*\}\}", out)
|
||||||
|
if left:
|
||||||
|
sys.exit("ABORT: unsubstituted placeholders: %s" % sorted(set(left)))
|
||||||
|
|
||||||
|
path = os.path.join(HERE, "SYNTHESIS.md")
|
||||||
|
with open(path, "w", encoding="utf-8") as f:
|
||||||
|
f.write(out)
|
||||||
|
print("wrote %s (%d bytes, %d words, %d citations)" % (
|
||||||
|
path, len(out.encode("utf-8")), len(out.split()), len(cites["citations"])))
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(main())
|
||||||
@@ -0,0 +1,327 @@
|
|||||||
|
{
|
||||||
|
"schema": "sphinx/archive-citations/1",
|
||||||
|
"corpus": "manifest.json",
|
||||||
|
"source_dir": "sources/",
|
||||||
|
"citation_count": 29,
|
||||||
|
"citations": [
|
||||||
|
{
|
||||||
|
"id": "LITM-1",
|
||||||
|
"slug": "lost-in-the-middle",
|
||||||
|
"arxiv_id": "2307.03172",
|
||||||
|
"title": "Lost in the Middle: How Language Models Use Long Contexts",
|
||||||
|
"section": "Abstract",
|
||||||
|
"line": 60,
|
||||||
|
"char_offset": 2434,
|
||||||
|
"words": 40,
|
||||||
|
"quote": "we observe that performance is often highest when relevant information occurs at the beginning or end of the input context, and significantly degrades when models must access relevant information in the middle of long contexts, even for explicitly long-context models."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "LITM-2",
|
||||||
|
"slug": "lost-in-the-middle",
|
||||||
|
"arxiv_id": "2307.03172",
|
||||||
|
"title": "Lost in the Middle: How Language Models Use Long Contexts",
|
||||||
|
"section": "1 Introduction",
|
||||||
|
"line": 78,
|
||||||
|
"char_offset": 6934,
|
||||||
|
"words": 41,
|
||||||
|
"quote": "language model performance is highest when relevant information occurs at the very beginning (primacy bias) or end of its input context (recency bias), and performance significantly degrades when models must access and use information in the middle of their input context"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "LITM-3",
|
||||||
|
"slug": "lost-in-the-middle",
|
||||||
|
"arxiv_id": "2307.03172",
|
||||||
|
"title": "Lost in the Middle: How Language Models Use Long Contexts",
|
||||||
|
"section": "1 Introduction",
|
||||||
|
"line": 79,
|
||||||
|
"char_offset": 7227,
|
||||||
|
"words": 34,
|
||||||
|
"quote": "when relevant information is placed in the middle of its input context, GPT-3.5-Turbo’s performance on the multi-document question task is lower than its performance when predicting without any documents (i.e., the closed-book setting; 56.1%)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "LITM-4",
|
||||||
|
"slug": "lost-in-the-middle",
|
||||||
|
"arxiv_id": "2307.03172",
|
||||||
|
"title": "Lost in the Middle: How Language Models Use Long Contexts",
|
||||||
|
"section": "1 Introduction",
|
||||||
|
"line": 92,
|
||||||
|
"char_offset": 10361,
|
||||||
|
"words": 22,
|
||||||
|
"quote": "we find that model performance saturates long before retriever recall saturates, indicating that current models fail to effectively use additional retrieved documents"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "LITM-5",
|
||||||
|
"slug": "lost-in-the-middle",
|
||||||
|
"arxiv_id": "2307.03172",
|
||||||
|
"title": "Lost in the Middle: How Language Models Use Long Contexts",
|
||||||
|
"section": "1 Introduction",
|
||||||
|
"line": 93,
|
||||||
|
"char_offset": 10840,
|
||||||
|
"words": 36,
|
||||||
|
"quote": "to claim that a language model can robustly use information within long input contexts, it is necessary to show that its performance is minimally affected by the position of the relevant information in the input context"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "RULER-1",
|
||||||
|
"slug": "ruler",
|
||||||
|
"arxiv_id": "2404.06654",
|
||||||
|
"title": "Ruler: What’s the Real Context Size of Your Long-Context Language Models?",
|
||||||
|
"section": "1 Introduction",
|
||||||
|
"line": 150,
|
||||||
|
"char_offset": 6418,
|
||||||
|
"words": 45,
|
||||||
|
"quote": "While all models claim context size of 32k tokens or greater, our results indicate that only half of them can effectively handle sequence length of 32K by exceeding a qualitative threshold. Moreover, almost all models fall below the threshold before reaching the claimed context lengths."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "RULER-2",
|
||||||
|
"slug": "ruler",
|
||||||
|
"arxiv_id": "2404.06654",
|
||||||
|
"title": "Ruler: What’s the Real Context Size of Your Long-Context Language Models?",
|
||||||
|
"section": "Abstract",
|
||||||
|
"line": 70,
|
||||||
|
"char_offset": 1790,
|
||||||
|
"words": 47,
|
||||||
|
"quote": "The needle-in-a-haystack (NIAH) test, which examines the ability to retrieve a piece of information (the “needle”) from long distractor texts (the “haystack”), has been widely adopted to evaluate long-context language models (LMs). However, this simple retrieval-based test is indicative of only a superficial form of long-context understanding."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "RULER-3",
|
||||||
|
"slug": "ruler",
|
||||||
|
"arxiv_id": "2404.06654",
|
||||||
|
"title": "Ruler: What’s the Real Context Size of Your Long-Context Language Models?",
|
||||||
|
"section": "4 Experiments & Results",
|
||||||
|
"line": 540,
|
||||||
|
"char_offset": 26133,
|
||||||
|
"words": 45,
|
||||||
|
"quote": "while they achieve nearly perfect performance on the passkey retrieval and the vanilla NIAH task (shown in Appendix E), all of them exhibit large degradation in RULER as sequence length increases and they fail to maintain performance above the Llama2-7B baseline at their claimed length."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "RULER-4",
|
||||||
|
"slug": "ruler",
|
||||||
|
"arxiv_id": "2404.06654",
|
||||||
|
"title": "Ruler: What’s the Real Context Size of Your Long-Context Language Models?",
|
||||||
|
"section": "4 Experiments & Results",
|
||||||
|
"line": 306,
|
||||||
|
"char_offset": 22598,
|
||||||
|
"words": 15,
|
||||||
|
"quote": "We use the performance of Llama2-7b model at the 4K context length as the threshold."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "RULER-5",
|
||||||
|
"slug": "ruler",
|
||||||
|
"arxiv_id": "2404.06654",
|
||||||
|
"title": "Ruler: What’s the Real Context Size of Your Long-Context Language Models?",
|
||||||
|
"section": "1 Introduction",
|
||||||
|
"line": 152,
|
||||||
|
"char_offset": 7657,
|
||||||
|
"words": 24,
|
||||||
|
"quote": "training on longer sequences does not always lead to better performance on Ruler, and that larger model sizes positively correlate with better long-context capabilities."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "DCA-1",
|
||||||
|
"slug": "dca-training-free",
|
||||||
|
"arxiv_id": "2402.17463",
|
||||||
|
"title": "Training-Free Long-Context Scaling of Large Language Models",
|
||||||
|
"section": "Abstract",
|
||||||
|
"line": 67,
|
||||||
|
"char_offset": 1567,
|
||||||
|
"words": 33,
|
||||||
|
"quote": "Given the expensive overhead of finetuning large-scale models with longer sequences, we propose Dual Chunk Attention (DCA), which enables Llama2 70B to support context windows of more than 100k tokens without continual training."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "DCA-2",
|
||||||
|
"slug": "dca-training-free",
|
||||||
|
"arxiv_id": "2402.17463",
|
||||||
|
"title": "Training-Free Long-Context Scaling of Large Language Models",
|
||||||
|
"section": "Abstract",
|
||||||
|
"line": 68,
|
||||||
|
"char_offset": 2316,
|
||||||
|
"words": 18,
|
||||||
|
"quote": "our training-free 70B model attains 94% of the performance of gpt-3.5-16k, indicating it is a viable open-source alternative."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "DCA-3",
|
||||||
|
"slug": "dca-training-free",
|
||||||
|
"arxiv_id": "2402.17463",
|
||||||
|
"title": "Training-Free Long-Context Scaling of Large Language Models",
|
||||||
|
"section": "1 Introduction",
|
||||||
|
"line": 80,
|
||||||
|
"char_offset": 5241,
|
||||||
|
"words": 29,
|
||||||
|
"quote": "in a training-free setting, we find that these approaches usually lead to a notable increase in PPL especially in input lengths that are more than twice the training length"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "DCA-4",
|
||||||
|
"slug": "dca-training-free",
|
||||||
|
"arxiv_id": "2402.17463",
|
||||||
|
"title": "Training-Free Long-Context Scaling of Large Language Models",
|
||||||
|
"section": "1 Introduction",
|
||||||
|
"line": 89,
|
||||||
|
"char_offset": 7944,
|
||||||
|
"words": 35,
|
||||||
|
"quote": "It first shows that LLMs with a 4k context window can be expanded to more than 32k without training, maintaining a negligible increase in PPL, whereas previous methods typically falter at context lengths beyond 8k."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "DCA-5",
|
||||||
|
"slug": "dca-training-free",
|
||||||
|
"arxiv_id": "2402.17463",
|
||||||
|
"title": "Training-Free Long-Context Scaling of Large Language Models",
|
||||||
|
"section": "1 Introduction",
|
||||||
|
"line": 92,
|
||||||
|
"char_offset": 8516,
|
||||||
|
"words": 28,
|
||||||
|
"quote": "existing long-context LLMs, which have already supported a 32k context window, can further extrapolate to a 192k context length while maintaining high passkey retrieval accuracy and low perplexity."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "YARN-1",
|
||||||
|
"slug": "yarn",
|
||||||
|
"arxiv_id": "2309.00071",
|
||||||
|
"title": "YaRN: Efficient Context Window Extension of Large Language Models",
|
||||||
|
"section": "Abstract",
|
||||||
|
"line": 60,
|
||||||
|
"char_offset": 1538,
|
||||||
|
"words": 30,
|
||||||
|
"quote": "Rotary Position Embeddings (RoPE) have been shown to effectively encode positional information in transformer-based language models.\nHowever, these models fail to generalize past the sequence length they were trained on."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "YARN-2",
|
||||||
|
"slug": "yarn",
|
||||||
|
"arxiv_id": "2309.00071",
|
||||||
|
"title": "YaRN: Efficient Context Window Extension of Large Language Models",
|
||||||
|
"section": "Abstract",
|
||||||
|
"line": 62,
|
||||||
|
"char_offset": 1759,
|
||||||
|
"words": 31,
|
||||||
|
"quote": "We present YaRN (Yet another RoPE extensioN method), a compute-efficient method to extend the context window of such models, requiring 10x less tokens and 2.5x less training steps than previous methods."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "YARN-3",
|
||||||
|
"slug": "yarn",
|
||||||
|
"arxiv_id": "2309.00071",
|
||||||
|
"title": "YaRN: Efficient Context Window Extension of Large Language Models",
|
||||||
|
"section": "4.1 Training",
|
||||||
|
"line": 208,
|
||||||
|
"char_offset": 25374,
|
||||||
|
"words": 20,
|
||||||
|
"quote": "As shown in Figure 2, YaRN converges faster compared to other interpolation techniques during training and consistently has lower loss."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "YARN-4",
|
||||||
|
"slug": "yarn",
|
||||||
|
"arxiv_id": "2309.00071",
|
||||||
|
"title": "YaRN: Efficient Context Window Extension of Large Language Models",
|
||||||
|
"section": "B.2 Training Efficiency of YaRN",
|
||||||
|
"line": 1008,
|
||||||
|
"char_offset": 51640,
|
||||||
|
"words": 20,
|
||||||
|
"quote": "Even if YaRN was only fine-tuned for 400 steps compared to PI’s 1000 steps, we obtain similar results to PI."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "SURVEY-1",
|
||||||
|
"slug": "lclm-survey",
|
||||||
|
"arxiv_id": "2503.17407",
|
||||||
|
"title": "A Comprehensive Survey on Long Context Language Modeling",
|
||||||
|
"section": "7.1.1 The False Promise of Support Context Length",
|
||||||
|
"line": 1884,
|
||||||
|
"char_offset": 175760,
|
||||||
|
"words": 30,
|
||||||
|
"quote": "Despite this impressive scaling of context extension, there exists a significant gap between the context length these models claim to support and the actual context length they can process effectively"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "SURVEY-2",
|
||||||
|
"slug": "lclm-survey",
|
||||||
|
"arxiv_id": "2503.17407",
|
||||||
|
"title": "A Comprehensive Survey on Long Context Language Modeling",
|
||||||
|
"section": "7.1.1 The False Promise of Support Context Length",
|
||||||
|
"line": 1884,
|
||||||
|
"char_offset": 176732,
|
||||||
|
"words": 23,
|
||||||
|
"quote": "The findings reveal a consistent pattern: For most models across both categories, the effective context length rarely exceeds half of the claimed length."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "SURVEY-3",
|
||||||
|
"slug": "lclm-survey",
|
||||||
|
"arxiv_id": "2503.17407",
|
||||||
|
"title": "A Comprehensive Survey on Long Context Language Modeling",
|
||||||
|
"section": "7.1.1 The False Promise of Support Context Length",
|
||||||
|
"line": 1884,
|
||||||
|
"char_offset": 176159,
|
||||||
|
"words": 26,
|
||||||
|
"quote": "performance remains robust when information is located at the beginning or end of the input, but deteriorates substantially when critical information is positioned in the middle"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "SURVEY-4",
|
||||||
|
"slug": "lclm-survey",
|
||||||
|
"arxiv_id": "2503.17407",
|
||||||
|
"title": "A Comprehensive Survey on Long Context Language Modeling",
|
||||||
|
"section": "7.2.1 Positional Embedding",
|
||||||
|
"line": 2014,
|
||||||
|
"char_offset": 186649,
|
||||||
|
"words": 15,
|
||||||
|
"quote": "They point out that scaling down rotation bases can only achieve superficial long context capabilities."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "SURVEY-5",
|
||||||
|
"slug": "lclm-survey",
|
||||||
|
"arxiv_id": "2503.17407",
|
||||||
|
"title": "A Comprehensive Survey on Long Context Language Modeling",
|
||||||
|
"section": "8.6 Application in Multimodal Tasks",
|
||||||
|
"line": 2072,
|
||||||
|
"char_offset": 203402,
|
||||||
|
"words": 25,
|
||||||
|
"quote": "Multimodal long context benchmarks can primarily be divided into two types: those that use multiple images and those that use long videos as the context."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "SURVEY-6",
|
||||||
|
"slug": "lclm-survey",
|
||||||
|
"arxiv_id": "2503.17407",
|
||||||
|
"title": "A Comprehensive Survey on Long Context Language Modeling",
|
||||||
|
"section": "8.6 Application in Multimodal Tasks",
|
||||||
|
"line": 2072,
|
||||||
|
"char_offset": 204516,
|
||||||
|
"words": 27,
|
||||||
|
"quote": "Compared to multi-image long context data, understanding long videos is more challenging due to their larger context length and the inclusion of more redundant and noisy information."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "DATAENG-1",
|
||||||
|
"slug": "data-eng-128k",
|
||||||
|
"arxiv_id": "2402.10171",
|
||||||
|
"title": "Data Engineering for Scaling Language Models to 128K Context",
|
||||||
|
"section": "Abstract",
|
||||||
|
"line": 37,
|
||||||
|
"char_offset": 1265,
|
||||||
|
"words": 25,
|
||||||
|
"quote": "for quantity, we show that 500 million to 5 billion tokens are enough to enable the model to retrieve information anywhere within the 128K context"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "DATAENG-2",
|
||||||
|
"slug": "data-eng-128k",
|
||||||
|
"arxiv_id": "2402.10171",
|
||||||
|
"title": "Data Engineering for Scaling Language Models to 128K Context",
|
||||||
|
"section": "Abstract",
|
||||||
|
"line": 39,
|
||||||
|
"char_offset": 1523,
|
||||||
|
"words": 26,
|
||||||
|
"quote": "naïvely upsampling longer data on certain domains like books, a common practice of existing work, gives suboptimal performance, and that a balanced domain mixture is important."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "DATAENG-3",
|
||||||
|
"slug": "data-eng-128k",
|
||||||
|
"arxiv_id": "2402.10171",
|
||||||
|
"title": "Data Engineering for Scaling Language Models to 128K Context",
|
||||||
|
"section": "1 Introduction",
|
||||||
|
"line": 72,
|
||||||
|
"char_offset": 6040,
|
||||||
|
"words": 33,
|
||||||
|
"quote": "continual pretraining on a small amount of long-context data, in our case, 1-5B tokens, can “unlock” a 7B model’s capability of precise retrieval over much longer context lengths than seen in original pretraining."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "DATAENG-4",
|
||||||
|
"slug": "data-eng-128k",
|
||||||
|
"arxiv_id": "2402.10171",
|
||||||
|
"title": "Data Engineering for Scaling Language Models to 128K Context",
|
||||||
|
"section": "5.1 Overall Performance",
|
||||||
|
"line": 267,
|
||||||
|
"char_offset": 24011,
|
||||||
|
"words": 20,
|
||||||
|
"quote": "the model’s retrieval performance saturates at about 5B tokens, and further scaling to 10B tokens does not improve length generalization."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Fetch arXiv HTML for a fixed paper list, strip to plain text, write a manifest.
|
||||||
|
|
||||||
|
Archive lane: turn a long-context corpus into a byte-stable, verifiable text set
|
||||||
|
that every downstream quote can be checked against.
|
||||||
|
"""
|
||||||
|
import hashlib
|
||||||
|
import html
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
SRC = os.path.join(HERE, "sources")
|
||||||
|
|
||||||
|
# Titles verified against the arXiv stamp line inside each fetched HTML on
|
||||||
|
# 2026-10-21; two earlier guesses were wrong and were corrected after reading
|
||||||
|
# the sources (see NOTES.md).
|
||||||
|
PAPERS = [
|
||||||
|
("lost-in-the-middle", "2307.03172", "Lost in the Middle: How Language Models Use Long Contexts"),
|
||||||
|
("ruler", "2404.06654", "Ruler: What’s the Real Context Size of Your Long-Context Language Models?"),
|
||||||
|
("dca-training-free", "2402.17463", "Training-Free Long-Context Scaling of Large Language Models"),
|
||||||
|
("yarn", "2309.00071", "YaRN: Efficient Context Window Extension of Large Language Models"),
|
||||||
|
("lclm-survey", "2503.17407", "A Comprehensive Survey on Long Context Language Modeling"),
|
||||||
|
("data-eng-128k", "2402.10171", "Data Engineering for Scaling Language Models to 128K Context"),
|
||||||
|
]
|
||||||
|
|
||||||
|
TAG = re.compile(r"<(script|style)[^>]*>.*?</\1>", re.S | re.I)
|
||||||
|
BLOCK = re.compile(r"</?(p|div|section|h[1-6]|li|tr|table|figcaption|blockquote|br)[^>]*>", re.I)
|
||||||
|
ANYTAG = re.compile(r"<[^>]+>")
|
||||||
|
|
||||||
|
|
||||||
|
def fetch(url, dest):
|
||||||
|
req = urllib.request.Request(url, headers={"User-Agent": "sphinx-archive/1.0 (research)"})
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
data = r.read()
|
||||||
|
with open(dest, "wb") as f:
|
||||||
|
f.write(data)
|
||||||
|
return len(data)
|
||||||
|
|
||||||
|
|
||||||
|
def to_text(raw):
|
||||||
|
t = TAG.sub(" ", raw)
|
||||||
|
t = BLOCK.sub("\n", t)
|
||||||
|
t = ANYTAG.sub("", t)
|
||||||
|
t = html.unescape(t)
|
||||||
|
t = t.replace("\u00a0", " ")
|
||||||
|
lines = []
|
||||||
|
for ln in t.split("\n"):
|
||||||
|
ln = re.sub(r"[ \t]+", " ", ln).strip()
|
||||||
|
if ln:
|
||||||
|
lines.append(ln)
|
||||||
|
return "\n".join(lines) + "\n"
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
os.makedirs(SRC, exist_ok=True)
|
||||||
|
manifest = []
|
||||||
|
for slug, aid, title in PAPERS:
|
||||||
|
hpath = os.path.join(SRC, slug + ".html")
|
||||||
|
if not os.path.exists(hpath) or os.path.getsize(hpath) < 20000:
|
||||||
|
n = fetch("https://arxiv.org/html/" + aid, hpath)
|
||||||
|
print("fetched %s (%s) %d bytes" % (slug, aid, n))
|
||||||
|
raw = open(hpath, encoding="utf-8", errors="replace").read()
|
||||||
|
text = to_text(raw)
|
||||||
|
tpath = os.path.join(SRC, slug + ".txt")
|
||||||
|
with open(tpath, "w", encoding="utf-8") as f:
|
||||||
|
f.write(text)
|
||||||
|
manifest.append({
|
||||||
|
"slug": slug,
|
||||||
|
"arxiv_id": aid,
|
||||||
|
"title": title,
|
||||||
|
"url": "https://arxiv.org/abs/" + aid,
|
||||||
|
"html_sha256": hashlib.sha256(raw.encode("utf-8")).hexdigest(),
|
||||||
|
"text_sha256": hashlib.sha256(text.encode("utf-8")).hexdigest(),
|
||||||
|
"text_bytes": len(text.encode("utf-8")),
|
||||||
|
"text_lines": text.count("\n"),
|
||||||
|
"text_words": len(text.split()),
|
||||||
|
})
|
||||||
|
mpath = os.path.join(HERE, "manifest.json")
|
||||||
|
with open(mpath, "w", encoding="utf-8") as f:
|
||||||
|
json.dump({"papers": manifest}, f, indent=2)
|
||||||
|
f.write("\n")
|
||||||
|
for m in manifest:
|
||||||
|
print("%-20s %-10s %8d bytes %6d lines %7d words" % (
|
||||||
|
m["slug"], m["arxiv_id"], m["text_bytes"], m["text_lines"], m["text_words"]))
|
||||||
|
print("manifest ->", mpath)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(main())
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Print the front-matter title/abstract region of each extracted paper."""
|
||||||
|
import glob
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
for path in sorted(glob.glob(os.path.join(HERE, "sources", "*.txt"))):
|
||||||
|
lines = open(path, encoding="utf-8").read().split("\n")
|
||||||
|
# first arXiv stamp line (front matter, not bibliography)
|
||||||
|
idx = None
|
||||||
|
for i, ln in enumerate(lines[:120]):
|
||||||
|
if re.match(r"^arXiv:\d{4}\.\d{4,5}v\d+", ln):
|
||||||
|
idx = i
|
||||||
|
break
|
||||||
|
print("=" * 70)
|
||||||
|
print("FILE", os.path.basename(path), "| stamp line", (idx + 1) if idx is not None else None)
|
||||||
|
if idx is None:
|
||||||
|
continue
|
||||||
|
for j in range(idx, min(idx + 14, len(lines))):
|
||||||
|
s = lines[j]
|
||||||
|
print("%4d| %s" % (j + 1, s[:400]))
|
||||||
@@ -0,0 +1,255 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Harvest machine-checkable citations out of the frozen corpus.
|
||||||
|
|
||||||
|
Each entry in QUOTES names a paper and a distinctive span. The harvester
|
||||||
|
locates the span in sources/<slug>.txt under a unicode/whitespace-normalised
|
||||||
|
search, then stores the ORIGINAL bytes of that span (raw slice) together with
|
||||||
|
the raw character offset and 1-based line number. Nothing is retyped by hand:
|
||||||
|
if a span cannot be found the harvester aborts, so citations.json can only
|
||||||
|
contain text that really exists in the frozen sources.
|
||||||
|
|
||||||
|
Run: python3 harvest.py (writes citations.json)
|
||||||
|
"""
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
SRC = os.path.join(HERE, "sources")
|
||||||
|
|
||||||
|
# (citation id, source slug, section heading the quote sits under, search span)
|
||||||
|
QUOTES = [
|
||||||
|
# --- Lost in the Middle (arXiv:2307.03172) ---
|
||||||
|
("LITM-1", "lost-in-the-middle", "Abstract",
|
||||||
|
"we observe that performance is often highest when relevant information occurs at the beginning "
|
||||||
|
"or end of the input context, and significantly degrades when models must access relevant "
|
||||||
|
"information in the middle of long contexts, even for explicitly long-context models."),
|
||||||
|
("LITM-2", "lost-in-the-middle", "1 Introduction",
|
||||||
|
"language model performance is highest when relevant information occurs at the very beginning "
|
||||||
|
"(primacy bias) or end of its input context (recency bias), and performance significantly "
|
||||||
|
"degrades when models must access and use information in the middle of their input context"),
|
||||||
|
("LITM-3", "lost-in-the-middle", "1 Introduction",
|
||||||
|
"when relevant information is placed in the middle of its input context, GPT-3.5-Turbo's "
|
||||||
|
"performance on the multi-document question task is lower than its performance when predicting "
|
||||||
|
"without any documents (i.e., the closed-book setting; 56.1%)"),
|
||||||
|
("LITM-4", "lost-in-the-middle", "1 Introduction",
|
||||||
|
"we find that model performance saturates long before retriever recall saturates, indicating "
|
||||||
|
"that current models fail to effectively use additional retrieved documents"),
|
||||||
|
("LITM-5", "lost-in-the-middle", "1 Introduction",
|
||||||
|
"to claim that a language model can robustly use information within long input contexts, it is "
|
||||||
|
"necessary to show that its performance is minimally affected by the position of the relevant "
|
||||||
|
"information in the input context"),
|
||||||
|
|
||||||
|
# --- RULER (arXiv:2404.06654) ---
|
||||||
|
("RULER-1", "ruler", "1 Introduction",
|
||||||
|
"While all models claim context size of 32k tokens or greater, our results indicate that only "
|
||||||
|
"half of them can effectively handle sequence length of 32K by exceeding a qualitative "
|
||||||
|
"threshold. Moreover, almost all models fall below the threshold before reaching the claimed "
|
||||||
|
"context lengths."),
|
||||||
|
("RULER-2", "ruler", "Abstract",
|
||||||
|
"The needle-in-a-haystack (NIAH) test, which examines the ability to retrieve a piece of "
|
||||||
|
"information (the \"needle\") from long distractor texts (the \"haystack\"), has been widely "
|
||||||
|
"adopted to evaluate long-context language models (LMs). However, this simple retrieval-based "
|
||||||
|
"test is indicative of only a superficial form of long-context understanding."),
|
||||||
|
("RULER-3", "ruler", "4 Experiments & Results",
|
||||||
|
"while they achieve nearly perfect performance on the passkey retrieval and the vanilla NIAH "
|
||||||
|
"task (shown in Appendix E), all of them exhibit large degradation in RULER as sequence length "
|
||||||
|
"increases and they fail to maintain performance above the Llama2-7B baseline at their claimed "
|
||||||
|
"length."),
|
||||||
|
("RULER-4", "ruler", "4 Experiments & Results",
|
||||||
|
"We use the performance of Llama2-7b model at the 4K context length as the threshold."),
|
||||||
|
("RULER-5", "ruler", "1 Introduction",
|
||||||
|
"training on longer sequences does not always lead to better performance on Ruler, and that "
|
||||||
|
"larger model sizes positively correlate with better long-context capabilities."),
|
||||||
|
|
||||||
|
# --- Training-Free Long-Context Scaling / DCA (arXiv:2402.17463) ---
|
||||||
|
("DCA-1", "dca-training-free", "Abstract",
|
||||||
|
"Given the expensive overhead of finetuning large-scale models with longer sequences, we "
|
||||||
|
"propose Dual Chunk Attention (DCA), which enables Llama2 70B to support context windows of "
|
||||||
|
"more than 100k tokens without continual training."),
|
||||||
|
("DCA-2", "dca-training-free", "Abstract",
|
||||||
|
"our training-free 70B model attains 94% of the performance of gpt-3.5-16k, indicating it is a "
|
||||||
|
"viable open-source alternative."),
|
||||||
|
("DCA-3", "dca-training-free", "1 Introduction",
|
||||||
|
"in a training-free setting, we find that these approaches usually lead to a notable increase "
|
||||||
|
"in PPL especially in input lengths that are more than twice the training length"),
|
||||||
|
("DCA-4", "dca-training-free", "1 Introduction",
|
||||||
|
"It first shows that LLMs with a 4k context window can be expanded to more than 32k without "
|
||||||
|
"training, maintaining a negligible increase in PPL, whereas previous methods typically falter "
|
||||||
|
"at context lengths beyond 8k."),
|
||||||
|
("DCA-5", "dca-training-free", "1 Introduction",
|
||||||
|
"existing long-context LLMs, which have already supported a 32k context window, can further "
|
||||||
|
"extrapolate to a 192k context length while maintaining high passkey retrieval accuracy and low "
|
||||||
|
"perplexity."),
|
||||||
|
|
||||||
|
# --- YaRN (arXiv:2309.00071) ---
|
||||||
|
("YARN-1", "yarn", "Abstract",
|
||||||
|
"Rotary Position Embeddings (RoPE) have been shown to effectively encode positional information "
|
||||||
|
"in transformer-based language models. However, these models fail to generalize past the "
|
||||||
|
"sequence length they were trained on."),
|
||||||
|
("YARN-2", "yarn", "Abstract",
|
||||||
|
"We present YaRN (Yet another RoPE extensioN method), a compute-efficient method to extend the "
|
||||||
|
"context window of such models, requiring 10x less tokens and 2.5x less training steps than "
|
||||||
|
"previous methods."),
|
||||||
|
("YARN-3", "yarn", "4.1 Training",
|
||||||
|
"As shown in Figure 2, YaRN converges faster compared to other interpolation techniques during "
|
||||||
|
"training and consistently has lower loss."),
|
||||||
|
("YARN-4", "yarn", "B.2 Training Efficiency of YaRN",
|
||||||
|
"Even if YaRN was only fine-tuned for 400 steps compared to PI's 1000 steps, we obtain similar "
|
||||||
|
"results to PI."),
|
||||||
|
|
||||||
|
# --- A Comprehensive Survey on Long Context Language Modeling (arXiv:2503.17407) ---
|
||||||
|
("SURVEY-1", "lclm-survey", "7.1.1 The False Promise of Support Context Length",
|
||||||
|
"Despite this impressive scaling of context extension, there exists a significant gap between "
|
||||||
|
"the context length these models claim to support and the actual context length they can "
|
||||||
|
"process effectively"),
|
||||||
|
("SURVEY-2", "lclm-survey", "7.1.1 The False Promise of Support Context Length",
|
||||||
|
"The findings reveal a consistent pattern: For most models across both categories, the "
|
||||||
|
"effective context length rarely exceeds half of the claimed length."),
|
||||||
|
("SURVEY-3", "lclm-survey", "7.1.1 The False Promise of Support Context Length",
|
||||||
|
"performance remains robust when information is located at the beginning or end of the input, "
|
||||||
|
"but deteriorates substantially when critical information is positioned in the middle"),
|
||||||
|
("SURVEY-4", "lclm-survey", "7.2.1 Positional Embedding",
|
||||||
|
"They point out that scaling down rotation bases can only achieve superficial long context "
|
||||||
|
"capabilities."),
|
||||||
|
("SURVEY-5", "lclm-survey", "8.6 Application in Multimodal Tasks",
|
||||||
|
"Multimodal long context benchmarks can primarily be divided into two types: those that use "
|
||||||
|
"multiple images and those that use long videos as the context."),
|
||||||
|
("SURVEY-6", "lclm-survey", "8.6 Application in Multimodal Tasks",
|
||||||
|
"Compared to multi-image long context data, understanding long videos is more challenging due "
|
||||||
|
"to their larger context length and the inclusion of more redundant and noisy information."),
|
||||||
|
|
||||||
|
# --- Data Engineering for Scaling Language Models to 128K Context (arXiv:2402.10171) ---
|
||||||
|
("DATAENG-1", "data-eng-128k", "Abstract",
|
||||||
|
"for quantity, we show that 500 million to 5 billion tokens are enough to enable the model to "
|
||||||
|
"retrieve information anywhere within the 128K context"),
|
||||||
|
("DATAENG-2", "data-eng-128k", "Abstract",
|
||||||
|
"naively upsampling longer data on certain domains like books, a common practice of existing "
|
||||||
|
"work, gives suboptimal performance, and that a balanced domain mixture is important."),
|
||||||
|
("DATAENG-3", "data-eng-128k", "1 Introduction",
|
||||||
|
"continual pretraining on a small amount of long-context data, in our case, 1-5B tokens, can "
|
||||||
|
"\"unlock\" a 7B model's capability of precise retrieval over much longer context lengths than "
|
||||||
|
"seen in original pretraining."),
|
||||||
|
("DATAENG-4", "data-eng-128k", "5.1 Overall Performance",
|
||||||
|
"the model's retrieval performance saturates at about 5B tokens, and further scaling to 10B "
|
||||||
|
"tokens does not improve length generalization."),
|
||||||
|
]
|
||||||
|
|
||||||
|
SUBS = {
|
||||||
|
"\u2019": "'", "\u2018": "'", "\u201c": '"', "\u201d": '"',
|
||||||
|
"\u2014": "-", "\u2013": "-", "\u2026": "...", "\u00a0": " ",
|
||||||
|
"\u00ef": "i", "\u2028": " ", "\u2029": " ",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def norm_char(ch):
|
||||||
|
ch = SUBS.get(ch, ch)
|
||||||
|
if ch in "\t\r\n ":
|
||||||
|
return " "
|
||||||
|
return ch
|
||||||
|
|
||||||
|
|
||||||
|
def build_index(raw):
|
||||||
|
"""Return (normalised_string, raw_index_per_normalised_char).
|
||||||
|
|
||||||
|
Whitespace runs collapse to one space; a substitution that expands one raw
|
||||||
|
character into several ('\\u2026' -> '...') contributes one raw index per
|
||||||
|
produced character, so the two lists stay aligned.
|
||||||
|
"""
|
||||||
|
out = []
|
||||||
|
pos = []
|
||||||
|
prev_space = False
|
||||||
|
for i, ch in enumerate(raw):
|
||||||
|
c = norm_char(ch)
|
||||||
|
if c == " ":
|
||||||
|
if prev_space:
|
||||||
|
continue
|
||||||
|
prev_space = True
|
||||||
|
else:
|
||||||
|
prev_space = False
|
||||||
|
out.append(c)
|
||||||
|
pos.extend([i] * len(c))
|
||||||
|
s = "".join(out)
|
||||||
|
assert len(s) == len(pos), (len(s), len(pos))
|
||||||
|
return s, pos
|
||||||
|
|
||||||
|
|
||||||
|
def norm_str(s):
|
||||||
|
"""Same mapping as build_index, but for a standalone string (runs collapsed)."""
|
||||||
|
out = []
|
||||||
|
prev_space = False
|
||||||
|
for ch in s:
|
||||||
|
c = norm_char(ch)
|
||||||
|
if c == " ":
|
||||||
|
if prev_space:
|
||||||
|
continue
|
||||||
|
prev_space = True
|
||||||
|
else:
|
||||||
|
prev_space = False
|
||||||
|
out.append(c)
|
||||||
|
return "".join(out).strip()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
manifest = json.load(open(os.path.join(HERE, "manifest.json"), encoding="utf-8"))
|
||||||
|
by_slug = {p["slug"]: p for p in manifest["papers"]}
|
||||||
|
cache = {}
|
||||||
|
citations = []
|
||||||
|
for cid, slug, section, span in QUOTES:
|
||||||
|
if slug not in by_slug:
|
||||||
|
sys.exit("ABORT: unknown slug %r for %s" % (slug, cid))
|
||||||
|
if slug not in cache:
|
||||||
|
raw = open(os.path.join(SRC, slug + ".txt"), encoding="utf-8").read()
|
||||||
|
cache[slug] = (raw,) + build_index(raw)
|
||||||
|
raw, nstr, pos = cache[slug]
|
||||||
|
needle = norm_str(span)
|
||||||
|
at = nstr.find(needle)
|
||||||
|
if at < 0:
|
||||||
|
sys.exit("ABORT: quote %s not found in %s" % (cid, slug))
|
||||||
|
if nstr.find(needle, at + 1) >= 0:
|
||||||
|
sys.exit("ABORT: quote %s is not unique inside %s" % (cid, slug))
|
||||||
|
raw_start = pos[at]
|
||||||
|
raw_end = pos[at + len(needle) - 1] + 1
|
||||||
|
quote = raw[raw_start:raw_end]
|
||||||
|
if norm_str(quote) != needle:
|
||||||
|
sys.exit("ABORT: slice mismatch for %s" % cid)
|
||||||
|
if norm_str(section) not in nstr:
|
||||||
|
sys.exit("ABORT: section heading %r not present in %s" % (section, slug))
|
||||||
|
sec_at = nstr.find(norm_str(section))
|
||||||
|
if sec_at > at:
|
||||||
|
sys.exit("ABORT: section heading for %s occurs after the quote" % cid)
|
||||||
|
citations.append({
|
||||||
|
"id": cid,
|
||||||
|
"slug": slug,
|
||||||
|
"arxiv_id": by_slug[slug]["arxiv_id"],
|
||||||
|
"title": by_slug[slug]["title"],
|
||||||
|
"section": section,
|
||||||
|
"line": raw.count("\n", 0, raw_start) + 1,
|
||||||
|
"char_offset": raw_start,
|
||||||
|
"words": len(quote.split()),
|
||||||
|
"quote": quote,
|
||||||
|
})
|
||||||
|
doc = {
|
||||||
|
"schema": "sphinx/archive-citations/1",
|
||||||
|
"corpus": "manifest.json",
|
||||||
|
"source_dir": "sources/",
|
||||||
|
"citation_count": len(citations),
|
||||||
|
"citations": citations,
|
||||||
|
}
|
||||||
|
path = os.path.join(HERE, "citations.json")
|
||||||
|
with open(path, "w", encoding="utf-8") as f:
|
||||||
|
json.dump(doc, f, ensure_ascii=False, indent=2)
|
||||||
|
f.write("\n")
|
||||||
|
per = {}
|
||||||
|
for c in citations:
|
||||||
|
per[c["slug"]] = per.get(c["slug"], 0) + 1
|
||||||
|
print("%-10s %-20s line %-5d %3d words %s" % (
|
||||||
|
c["id"], c["slug"], c["line"], c["words"], c["quote"][:64].replace("\n", " ") + "..."))
|
||||||
|
print("citations:", len(citations), "per doc:", per)
|
||||||
|
print("wrote", path)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(main())
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
{
|
||||||
|
"papers": [
|
||||||
|
{
|
||||||
|
"slug": "lost-in-the-middle",
|
||||||
|
"arxiv_id": "2307.03172",
|
||||||
|
"title": "Lost in the Middle: How Language Models Use Long Contexts",
|
||||||
|
"url": "https://arxiv.org/abs/2307.03172",
|
||||||
|
"html_sha256": "a2fc87443a88f02658dbfc67deb3634f4bd4c857a5c5f210f0d8f4bee6672262",
|
||||||
|
"text_sha256": "0853c5c8f08224ef0580fc74ecd29c2bf27a2e3520135cb79afeb39ffc752f57",
|
||||||
|
"text_bytes": 63557,
|
||||||
|
"text_lines": 751,
|
||||||
|
"text_words": 9344
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"slug": "ruler",
|
||||||
|
"arxiv_id": "2404.06654",
|
||||||
|
"title": "Ruler: What\u2019s the Real Context Size of Your Long-Context Language Models?",
|
||||||
|
"url": "https://arxiv.org/abs/2404.06654",
|
||||||
|
"html_sha256": "782f6b54d38b37ee70902f6a0f22c840abedcb59a4364c43be1609e033e7abfb",
|
||||||
|
"text_sha256": "2c4837440b130da198ca30fc0384ee13479c362861bd540ab3d67698d5c8fcb2",
|
||||||
|
"text_bytes": 86860,
|
||||||
|
"text_lines": 3251,
|
||||||
|
"text_words": 13150
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"slug": "dca-training-free",
|
||||||
|
"arxiv_id": "2402.17463",
|
||||||
|
"title": "Training-Free Long-Context Scaling of Large Language Models",
|
||||||
|
"url": "https://arxiv.org/abs/2402.17463",
|
||||||
|
"html_sha256": "debb9d98c57b7c1f737e5d8697fa5cffb35076d860383cf2d8be2e2d02051155",
|
||||||
|
"text_sha256": "ff70dfff9fa3d789290141c7475bb3f25669563b91ec9c1b2791e489db6665c1",
|
||||||
|
"text_bytes": 82164,
|
||||||
|
"text_lines": 1329,
|
||||||
|
"text_words": 11556
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"slug": "yarn",
|
||||||
|
"arxiv_id": "2309.00071",
|
||||||
|
"title": "YaRN: Efficient Context Window Extension of Large Language Models",
|
||||||
|
"url": "https://arxiv.org/abs/2309.00071",
|
||||||
|
"html_sha256": "a8759e78bb3223c222c13d5e2bc6530a71a397ba69a48c187160587ae4303c9f",
|
||||||
|
"text_sha256": "5094e6676e151f2f1535c3a90ea5a6687c479f0d9b139125dd20ea109588baf6",
|
||||||
|
"text_bytes": 60973,
|
||||||
|
"text_lines": 1416,
|
||||||
|
"text_words": 9118
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"slug": "lclm-survey",
|
||||||
|
"arxiv_id": "2503.17407",
|
||||||
|
"title": "A Comprehensive Survey on Long Context Language Modeling",
|
||||||
|
"url": "https://arxiv.org/abs/2503.17407",
|
||||||
|
"html_sha256": "294abb64fe268b5e3fc8a2030f6c8be0f7b01f4ac805c72355e73069b573c48b",
|
||||||
|
"text_sha256": "36126f969b61126da3c165b26bc6bc8faed0fc317512a9932d05bbba93746616",
|
||||||
|
"text_bytes": 413560,
|
||||||
|
"text_lines": 6686,
|
||||||
|
"text_words": 60144
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"slug": "data-eng-128k",
|
||||||
|
"arxiv_id": "2402.10171",
|
||||||
|
"title": "Data Engineering for Scaling Language Models to 128K Context",
|
||||||
|
"url": "https://arxiv.org/abs/2402.10171",
|
||||||
|
"html_sha256": "a48721dc95fb35dd89d61324125c0a73bda351ebe36dc558a471747c982898fa",
|
||||||
|
"text_sha256": "52113f58d5c75f8d1f7c07f5e3de23573cb9050df9dbe2d6e5ae0b9c9a55161a",
|
||||||
|
"text_bytes": 47714,
|
||||||
|
"text_lines": 729,
|
||||||
|
"text_words": 7262
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Negative controls for the archive verifier — the CHECK for this artifact.
|
||||||
|
|
||||||
|
Passes (exit 0) only if BOTH hold:
|
||||||
|
(a) verify.py passes on the artifact as committed;
|
||||||
|
(b) verify.py FAILS on each of four tampered copies (source byte flipped,
|
||||||
|
citation quote altered, citation offset shifted, citation id removed
|
||||||
|
from the synthesis).
|
||||||
|
(b) is what makes this a test rather than a restatement: a verifier that
|
||||||
|
cannot fail proves nothing. All tampering happens in a scratch copy; the
|
||||||
|
artifact under test is never modified.
|
||||||
|
|
||||||
|
Run: python3 self_test.py
|
||||||
|
"""
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
SCRATCH = os.environ.get("SPHINX_SCRATCH", "/root/.hermes/profiles/sphinx/cache/scratch")
|
||||||
|
|
||||||
|
|
||||||
|
def run_verify(d):
|
||||||
|
p = subprocess.run([sys.executable, os.path.join(d, "verify.py")],
|
||||||
|
capture_output=True, text=True)
|
||||||
|
return p.returncode, p.stdout
|
||||||
|
|
||||||
|
|
||||||
|
def copy_artifact():
|
||||||
|
tmp = tempfile.mkdtemp(prefix="lctx-selftest-", dir=SCRATCH if os.path.isdir(SCRATCH) else None)
|
||||||
|
d = os.path.join(tmp, "longcontext-citations")
|
||||||
|
shutil.copytree(HERE, d, ignore=shutil.ignore_patterns("__pycache__"))
|
||||||
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
def first_citation(d):
|
||||||
|
cites = json.load(open(os.path.join(d, "citations.json"), encoding="utf-8"))
|
||||||
|
return cites["citations"][0]
|
||||||
|
|
||||||
|
|
||||||
|
def tamper_source_byte(d):
|
||||||
|
c = first_citation(d)
|
||||||
|
path = os.path.join(d, "sources", c["slug"] + ".txt")
|
||||||
|
raw = open(path, encoding="utf-8").read()
|
||||||
|
off = c["char_offset"] + 5
|
||||||
|
raw = raw[:off] + ("Z" if raw[off] != "Z" else "Q") + raw[off + 1:]
|
||||||
|
open(path, "w", encoding="utf-8").write(raw)
|
||||||
|
return "flipped a byte inside a quoted span in sources/%s.txt" % c["slug"]
|
||||||
|
|
||||||
|
|
||||||
|
def tamper_quote(d):
|
||||||
|
path = os.path.join(d, "citations.json")
|
||||||
|
doc = json.load(open(path, encoding="utf-8"))
|
||||||
|
doc["citations"][0]["quote"] = doc["citations"][0]["quote"].replace("performance", "performanz", 1)
|
||||||
|
json.dump(doc, open(path, "w", encoding="utf-8"), ensure_ascii=False, indent=2)
|
||||||
|
return "altered the first stored quote (performance -> performanz)"
|
||||||
|
|
||||||
|
|
||||||
|
def tamper_offset(d):
|
||||||
|
path = os.path.join(d, "citations.json")
|
||||||
|
doc = json.load(open(path, encoding="utf-8"))
|
||||||
|
doc["citations"][1]["char_offset"] += 3
|
||||||
|
json.dump(doc, open(path, "w", encoding="utf-8"), ensure_ascii=False, indent=2)
|
||||||
|
return "shifted the second citation's char_offset by 3"
|
||||||
|
|
||||||
|
|
||||||
|
def tamper_synthesis(d):
|
||||||
|
path = os.path.join(d, "SYNTHESIS.md")
|
||||||
|
md = open(path, encoding="utf-8").read()
|
||||||
|
cid = json.load(open(os.path.join(d, "citations.json"), encoding="utf-8"))["citations"][2]["id"]
|
||||||
|
md = md.replace(cid, cid.lower() + "-x")
|
||||||
|
open(path, "w", encoding="utf-8").write(md)
|
||||||
|
return "renamed citation id %s in SYNTHESIS.md" % cid
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print("self_test.py — negative controls")
|
||||||
|
print("=" * 72)
|
||||||
|
print("[1/5] clean run")
|
||||||
|
code, out = run_verify(HERE)
|
||||||
|
clean_ok = code == 0 and "VERIFICATION PASSED" in out
|
||||||
|
print(" exit=%d %s" % (code, "PASS" if clean_ok else "FAIL"))
|
||||||
|
if not clean_ok:
|
||||||
|
print(out[-2000:])
|
||||||
|
print("SELF-TEST FAILED: the artifact does not verify")
|
||||||
|
return 1
|
||||||
|
|
||||||
|
tampers = [("source byte", tamper_source_byte), ("stored quote", tamper_quote),
|
||||||
|
("char_offset", tamper_offset), ("synthesis id", tamper_synthesis)]
|
||||||
|
caught = 0
|
||||||
|
for i, (name, fn) in enumerate(tampers, start=2):
|
||||||
|
d = copy_artifact()
|
||||||
|
what = fn(d)
|
||||||
|
code, out = run_verify(d)
|
||||||
|
ok = code != 0 and "VERIFICATION FAILED" in out
|
||||||
|
first = [ln for ln in out.splitlines() if ln.strip().startswith("FAIL")]
|
||||||
|
print("[%d/5] tamper: %s -> verifier exit=%d %s" % (
|
||||||
|
i, what, code, "CAUGHT" if ok else "MISSED"))
|
||||||
|
if first:
|
||||||
|
print(" %s" % first[0].strip())
|
||||||
|
caught += 1 if ok else 0
|
||||||
|
shutil.rmtree(os.path.dirname(d), ignore_errors=True)
|
||||||
|
|
||||||
|
print("=" * 72)
|
||||||
|
if caught == len(tampers):
|
||||||
|
print("SELF-TEST PASSED — clean artifact verifies (307 checks), all %d tampered copies "
|
||||||
|
"rejected" % caught)
|
||||||
|
return 0
|
||||||
|
print("SELF-TEST FAILED — only %d/%d tampers caught" % (caught, len(tampers)))
|
||||||
|
return 1
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(main())
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,729 @@
|
|||||||
|
Data Engineering for Scaling Language Models to 128K Context
|
||||||
|
Skip to main content
|
||||||
|
Report GitHub Issue
|
||||||
|
×
|
||||||
|
Title:
|
||||||
|
Content selection saved. Describe the issue below:
|
||||||
|
Description:
|
||||||
|
Submit without GitHub
|
||||||
|
Submit in GitHub
|
||||||
|
Why HTML?
|
||||||
|
Report Issue
|
||||||
|
Back to Abstract
|
||||||
|
Download PDF
|
||||||
|
Contents
|
||||||
|
Reading mode
|
||||||
|
Colour theme
|
||||||
|
Abstract
|
||||||
|
1 Introduction
|
||||||
|
2 Background
|
||||||
|
3 Long Context Data Composition
|
||||||
|
4 Infrastructure and Engineering
|
||||||
|
5 Experimental Results
|
||||||
|
5.1 Overall Performance
|
||||||
|
5.2 Data Quantity
|
||||||
|
5.3 Data Mixture
|
||||||
|
6 Discussion
|
||||||
|
7 Conclusion
|
||||||
|
References
|
||||||
|
License: CC BY 4.0
|
||||||
|
arXiv:2402.10171v1 [cs.CL] 15 Feb 2024
|
||||||
|
Data Engineering for Scaling Language Models to 128K Context
|
||||||
|
Abstract
|
||||||
|
We study the continual pretraining recipe for scaling language models’ context lengths to 128K, with a focus on data engineering.
|
||||||
|
We hypothesize that long context modeling, in particular the ability to utilize information at arbitrary input locations, is a capability that is
|
||||||
|
mostly already acquired through large-scale pretraining, and that this capability can be readily extended to contexts substantially longer than seen during training (e.g., 4K to 128K) through lightweight continual pretraining on appropriate data mixture.
|
||||||
|
We investigate the quantity and quality of the data for continual pretraining:
|
||||||
|
(1) for quantity, we show that 500 million to 5 billion tokens are enough to enable the model to retrieve information anywhere within the 128K context;
|
||||||
|
(2) for quality, our results equally emphasize domain balance and length upsampling.
|
||||||
|
Concretely, we find that naïvely upsampling longer data on certain domains like books, a common practice of existing work, gives suboptimal performance, and that a balanced domain mixture is important.
|
||||||
|
We demonstrate that continual pretraining of the full model on 1B-5B tokens of such data is an effective and affordable strategy for scaling the context length of language models to 128K.
|
||||||
|
Our recipe outperforms strong open-source long-context models
|
||||||
|
and closes the gap to frontier models like GPT-4 128K.
|
||||||
|
Keywords:
|
||||||
|
Machine Learning, ICML
|
||||||
|
Yao Fuκ{}^{\text{\textkappa}} Rameswar Pandaη{}^{\text{\texteta}} Xinyao Niuµ{}^{\text{\textmu}} Xiang Yueπ{}^{\text{\textpi}} Hannaneh Hajishirziσ{}^{\text{\textsigma}} Yoon Kimλ{}^{\text{\textlambda}} Hao Pengδ{}^{\text{\textdelta}}
|
||||||
|
κ{}^{\text{\textkappa}}University of Edinburgh η{}^{\text{\texteta}}MIT-IBM Watson AI Lab µ{}^{\text{\textmu}}University of Melbourne π{}^{\text{\textpi}} Ohio State University
|
||||||
|
σ{}^{\text{\textsigma}}University of Washington λ{}^{\text{\textlambda}}MIT δ{}^{\text{\textdelta}}UIUC
|
||||||
|
yao.fu@ed.ac.uk yoonkim@mit.edu haopeng@illinois.edu
|
||||||
|
https://github.com/FranxYao/Long-Context-Data-Engineering
|
||||||
|
1 Introduction
|
||||||
|
Figure 1:
|
||||||
|
Needle-in-a-Haystack test (Kamradt, 2023) performance comparison.
|
||||||
|
The x-axis denotes the length of the document (the “haystack”); the y-axis indicates the position that the “needle” (a short sentence) is located within the document, from 1K to 128K tokens. For example, 50% indicates that the needle is placed in the middle of the document.
|
||||||
|
A red cell means the the language model cannot recite the information in the needle, and a green cell means the model can. A white dashed line means models’ continual pretraining (or finetuning for instruction-tuned models) context length; thus the area to its right indicates length generalization. Most existing open-source models make mistakes when the document is long.
|
||||||
|
Our post-training recipe demonstrates strong performance up to about 100K length.
|
||||||
|
A context window of 128K tokens enables large language models to perform tasks that significantly beyond existing paradigm, such as multi-document question answering (Caciularu et al., 2023), repository-level code understanding (Bairi et al., 2023), long-history dialog modeling (Mazumder & Liu, 2024), and language model-powered autonomous agents (Weng, 2023).
|
||||||
|
A popular testbed for whether models can actually utilize long context length is the recent Needle-in-a-Haystack test (Kamradt, 2023), which asks the model to precisely recite the information in a given sentence where the sentence (the “needle”) is placed in an arbitrary location of a 128K long document (the “haystack”).
|
||||||
|
In the open-source space, although works like LongLoRA (Chen et al., 2023b) and YaRN-Mistral (Peng et al., 2023) theoretically support 100K context, they are not able to pass this test at such context lengths, as shown in Fig. 1.
|
||||||
|
Currently, only closed-source frontier models like GPT-4 128K have demonstrated strong performance on the Needle-in-a-Haystack test.
|
||||||
|
This work investigates data engineering methods for scaling language models’ context lengths.
|
||||||
|
Our objective is to continue pretraining the language model on appropriate data mixtures such that it can pass the Needle-in-a-Haystack test at 128K length.
|
||||||
|
Given that most existing models are trained on less than 4K context length (Touvron et al., 2023a) and that attention has quadratic complexity, continual pretraining with full attention on much longer context lengths (we train on 64K-80K context lengths) may seem prohibitively costly at a first glance. However, we show that this is feasible under academic-level resources (see Table 2).
|
||||||
|
We use LLaMA-2 7B and 13B as our base models.
|
||||||
|
We do not make any significant change to model architecture other than adjusting the base of RoPE, as in Xiong et al. (2023).
|
||||||
|
Our major focus is the data recipe: what and how much data is able to well-adapt a model to pass the Needle-in-a-Haystack test at 128K context length.
|
||||||
|
We hypothesize that the capability to utilize
|
||||||
|
information at arbitrary locations within long
|
||||||
|
context length is (mostly) already acquired during pretraining, even for
|
||||||
|
models pretrained on substantially shorter
|
||||||
|
4K contexts.
|
||||||
|
This hypothesis is in contrast to existing works like Xiong et al. (2023); XVerse (2024), which perform continual pretraining on a large amount of data (400B tokens) to inject long-context-modeling capabilities; in this strategy, the cost can be as high as pre-training from scratch.
|
||||||
|
In this work we show that continual pretraining on a small amount of long-context data, in our case, 1-5B tokens, can “unlock” a 7B model’s capability of precise retrieval over much longer context lengths than seen in original pretraining.
|
||||||
|
We further show that upsampling long sequences while retaining the domain mixture of the pretraining corpora is crucial for context scaling, yet overlooked by existing works (Table 1).
|
||||||
|
Most existing works are based on the following intuition: to model long-range dependencies one needs long sequence data, which domains like books provide; therefore, it is necessary to upsample domains containing long sequences in the data mixture, as done by LongChat 32K (Li et al., 2023a) and YaRN Mistral 128K (Peng et al., 2023).
|
||||||
|
However, we show that this intuitive solution is suboptimal because, as we observe, this results in perplexiy degradations in other domains (Table 5).
|
||||||
|
Instead, a data mixture that keeps the domain mixture ratio the same as the pretraining mixture, and then upsampling long sequences within each domain gives the most stable performance gain.
|
||||||
|
We give evidence that this is the primary reason our solution improves long context tasks while maintaining short context performance, compared with strong baselines like YaRN-Mistral 128K (Peng et al., 2023) and LongLoRA 100K (Chen et al., 2023b).
|
||||||
|
In summary, we propose a concrete data recipe for scaling language model context length to 128K,
|
||||||
|
specifically, which involves continual pretrain the full-attention model on 1-5B tokens of per-source-length upsampled data.
|
||||||
|
We show that our recipe results in 7B and 13B LLaMA-2 of strong long-context performance, substantially closing the gap to frontier models like GPT-4 128K on the Needle-in-a-Haystack test,
|
||||||
|
opening future possibilities of studying long-context modeling under academic budgets.
|
||||||
|
2 Background
|
||||||
|
Table 1:
|
||||||
|
Major differences between our method v.s. existing work from a data perspective, which we view as critical for extending context length.
|
||||||
|
Our data mixture differs from previous work in three ways:
|
||||||
|
(1) length of continual pretraining data: we use 80K compared to Together’s 32K, which does not generalizes beyond 32K;
|
||||||
|
(2) data mixture: we use SlimPajama which has balanced domains compared to YaRN, which uses book-only PG19;
|
||||||
|
(3) length upsampling: we upsample long sequences compared to LongLoRA, which does not.
|
||||||
|
Despite the subtlety of these details (e.g., many of these details are just mentioned as a single line in previous works), we find that these details are crucial for performance on long-range retrieval.
|
||||||
|
Existing data solution
|
||||||
|
Our solution
|
||||||
|
Together LLaMA-2 32K
|
||||||
|
Train on 32K length
|
||||||
|
Train on 80K length
|
||||||
|
LongChat v1.5 32K
|
||||||
|
Train on 32K length dialog data
|
||||||
|
Train on 80K length-upsampled SlimPajama
|
||||||
|
YaRN Mistral 7B 128K
|
||||||
|
Train on PG19 book-only
|
||||||
|
Trained on length-upsampled SlimPajama
|
||||||
|
LongLoRA 100K
|
||||||
|
Train on Redpajama no length upsampling
|
||||||
|
With length upsampling
|
||||||
|
Frontier language models feature extremely long context lengths, such as OpenAI’s GPT-4 Turbo 128K (Nov 2023) and Anthropic’s Claude-100K (May 2023).
|
||||||
|
In the regime of 100K, a wide array of new applications emerge, such as repo-level code understanding (Bairi et al., 2023), long-history dialog modeling (Mazumder & Liu, 2024), and language model-powered autonomous agents (Weng, 2023).
|
||||||
|
A recent testbed for long-range capabilities is the Needle-in-a-Haystack benchmark, first proposed by Kamradt (2023) in Nov 2023. This benchmark asks the language model to recite the information in a “needle” sentence (“The best thing to do in San Francisco is eat a sandwich and sit in Dolores Park on a sunny day”) that is randomly inserted at an arbitrary location in a long essay.
|
||||||
|
Since its release, it has become a popular sandbox for testing whether models can utilize 100K+ context lengths, as it differentiates models that can precisely recite the given information at arbitrary input location versus those models that cannot.
|
||||||
|
So far there is neither public knowledge nor open-source work about achieving precise retrieval anywhere at this scale to the best of our knowledge.
|
||||||
|
This work improves the long-context capability over strong open-source baselines, and closes the gap to GPT-4 on the Needle-in-a-Haystack benchmark, as demonstrated in Fig. 1.
|
||||||
|
Our baselines here include LMSys’ LongChat v1.5 32K (Li et al., 2023a), Together Compute’s LLaMA-2 32K (Together, 2023), YaRN Mistral 128K (Peng et al., 2023), and LongLoRA (Chen et al., 2023b), which are so far the top open-source long-context language models.
|
||||||
|
These works focus on different aspects of long-context language modeling. For example, YaRN (Peng et al., 2023) focuses on positional embeddings, LongLoRA (Chen et al., 2023b) focuses on efficient attention, and Together (Together, 2023) focuses on a full-stack solution.
|
||||||
|
Our work focuses on data-engineering, and identifies critical data aspects for extending language models’ long-term dependency modeling to much longer contexts than seen during regular pretraining.
|
||||||
|
The major differences between this work and existing work are listed on Table 1.
|
||||||
|
Together’s LLaMA-2 is trained on 32K, but only generalizes to about 40K length.
|
||||||
|
YaRN Mistral is trained on book-only data; later in Table 5 we will show that improvements on one domain has limited transfer to other domains, indicating that one should consider a balanced mixture of different domains.
|
||||||
|
LongLoRA does not upsample long sequences; later in Fig. 4 we will show that upsampling long sequences is critical for precise retrieval.
|
||||||
|
These details are relatively hard to notice, yet we believe that they are the important for improved performance.
|
||||||
|
Before the Needle-in-a-Haystack test, most existing works use test negative log-likelihood as evaluation,
|
||||||
|
effectively concealing the underlying differences beyond low loss.
|
||||||
|
We show that, similar test loss could result in substantially different behavior when performing precise retrieval (Fig. 4).
|
||||||
|
Another important related work is the previous LLaMA Long (Xiong et al., 2023) work and the concurrent XVERSE (XVerse, 2024) work, which continue pretraining the model on 32K sequences for about 500 billion tokens.
|
||||||
|
These works are implicitly motivated by the view that long-context modeling is a new capability that must be “injected” through large-scale training.
|
||||||
|
We instead hypothesize that the base model has mostly already acquired this capability through large-scale pretraining, and thus a lightweight continual pretraining on relatively small data (e.g., 5B tokens) is enough to extend these capabilities to much longer context lengths (Fig. 3).
|
||||||
|
3 Long Context Data Composition
|
||||||
|
Figure 2:
|
||||||
|
Length and domain distributions of the various data mixture strategies.
|
||||||
|
We use SlimPajama (Soboleva et al., 2023),
|
||||||
|
an open-source reproduction of LLaMA (Touvron et al., 2023a) pretraining data mixture, as the source dataset.
|
||||||
|
The original data mixture has about 30% of documents that are naturally longer than 4K.
|
||||||
|
Cutting documents at 4K, the common practice of pretraining like Touvron et al. (2023a), breaks such long-range dependencies.
|
||||||
|
Cutting documents at 128K retains the naturally-existing long-range dependencies.
|
||||||
|
Global upsampling longer sequences slightly changes the data mixture.
|
||||||
|
Per-source upsampling longer sequences increases the portion of long sequences while keeping the domain mixture the same.
|
||||||
|
Upsampling Arxiv / Book / Github data simultaneously changes domain and length distributions.
|
||||||
|
We use the SlimPajama (Soboleva et al., 2023) dataset for continual pretraining.
|
||||||
|
This dataset is an open-source reproduction of the LLaMA (Touvron et al., 2023a) pretraining data mixture,
|
||||||
|
consisting of 82% web data (67% from CommonCrawl and 15% from C4), 4.5% code (Github), 4.5% Wikipedia, 4.5% books, 2.5% Arxiv, and 2.0% StackExchange.
|
||||||
|
Since this dataset closely mirrors that used to pretrain the LLaMA models,
|
||||||
|
there is less concern of distribution shift during continual pretraining; it is therefore used by many recent works like Fuzhao Xue & You (2023).
|
||||||
|
The documents’ lengths and their source domains are two closely related confounding factors in data engineering because long data usually come from particular sources.
|
||||||
|
Our examination shows books and Github code are the longest sources, followed by Arxiv.
|
||||||
|
Webpages like C4 and StackExchange tend to be shorter.
|
||||||
|
Directly upsampling long data changes the domain mixture, e.g., upsampling sequences longer than 100K will increase the portion of the books domain.
|
||||||
|
Likewise, changes in the domain mixture will result in shifts of the length distribution.
|
||||||
|
Our guideline is to decompose these two factors step by step, as is shown in Fig. 2.
|
||||||
|
We consider the following methods:
|
||||||
|
Cut at 4K: This truncates documents into 4K-length chunks. This approach inherits the original data mixture and is used by most pretraining works, such as (Touvron et al., 2023a; Hoffmann et al., 2022). Since there are about 30% documents that are naturally longer than 4K, this approach breaks such naturally-existing long-range dependencies.
|
||||||
|
Cut at 128K: This preserves most of the naturally-existing long-range dependencies without changing the domain mixture. LongLoRA (Chen et al., 2023b) follows this approach. However, we will show later that only using the naturally-existing long dependencies is inadequate (Fig. 4).
|
||||||
|
Per-source Upsampling: This retains the domain mixture, then upsamples long documents within each domain. This approach upsamples long documents without changing the domain mixture. We recommend this approach as our experiments suggest that this gives the most balanced performance gain.
|
||||||
|
Global Upsampling: This upsamples long documents while ignoring their source domains, and consequently slightly changes the domain mixture. Together (2023) uses this approach.
|
||||||
|
Upsample Arxiv/ Book/ Github: This intentionally upsamples Arxiv/Book/Github data, assuming that these domains are more likely to contain naturally-occurring long documents. For example, YaRN Mistral (Peng et al., 2023) and MPT-storyteller (Team, 2023) upsamples books. This approach changes both the domain and length distributions.
|
||||||
|
The above approaches generally cover most data recipes used in prior works discussed in section 2.
|
||||||
|
In our experiments, we will show that:
|
||||||
|
(1) using the original mixture cutting at 128K is insufficient for precise retrieval over long-context (Fig. 4), and one need to upsample long sequences;
|
||||||
|
(2) improved performance in one domain may not transfer and could even hurt another domain (Table 5), showing that
|
||||||
|
one needs to balance the mixture ratio of different domains.
|
||||||
|
4 Infrastructure and Engineering
|
||||||
|
We continue pretraining the model on the data mixture yielded by the ”Per-source Upsampling” strategy as introduced in section 3, where we train with a 80K sequence length for 7B models, and 64K for 13B models. A “brute force” training on 80K context may seem impractical at first glance
|
||||||
|
given the quadratic complexity of attention.
|
||||||
|
However, in our initial tests, we found this to be feasible, and the actual wallclock time was far from quadratic.
|
||||||
|
This is due to the fact that most of the time is spent on data transfer from CPU to GPU (since we use offloading), from one GPU to another GPU via NVLink (since we use Zero3, see Rajbhandari et al., 2020) and from GPU High-Bandwidth Memory (HBM) to Streaming Multiprocessors (SM) (as in FlashAttention, see Dao, 2023). These IO operations are all constant or linear in sequence length.
|
||||||
|
The actual quadratic attention computation, when performed on SM, is highly parallelized, and thus largely hidden by the linear IO cost.
|
||||||
|
Consequently, training on 80K is only 3x slower than training on 4K.
|
||||||
|
Our specific configuration is listed on Table 2.
|
||||||
|
We note that this configuration is substantially cheaper than previous work (Xiong et al., 2023), as they continue pretraining the model on more than 400B tokens. However this configuration seems to be the limit of Huggingface-DeepSpeed framework, and setting even longer context leads to memory overflow.
|
||||||
|
Since Zero Optimizer is data parallel, increasing number of GPUs cannot further increase context length, and most of the GPU memory is taken by the KV cache.
|
||||||
|
We refer the reader to more advanced sequence parallelism techniques in (Li et al., 2021; Jacobs et al., 2023) for training on even longer sequences (e.g., 200K), and we leave the exploration of training on 200K context for future work.
|
||||||
|
For training, we use a constant learning rate 2e-5.
|
||||||
|
We modify the base of RoPE positional encoding to adjust it to longer context, as in Xiong et al. (2023).
|
||||||
|
We pack all data to 80K chunks regardless of the document boundary, following common practice (Raffel et al., 2020; Touvron et al., 2023a).
|
||||||
|
We set the batch size to be 4M tokens.
|
||||||
|
Note that this batch size is the same as training on 4K context length, as we increase the length of a chunk but decrease the number of chunks in a batch.
|
||||||
|
We train the model on 5B tokens, which translates to 5B (size of data) / 4M (batch size) = 2000 optimization steps.
|
||||||
|
Table 2: We show that long context continual pretraining is feasible under academic-level resources.
|
||||||
|
Our configuration on 8×\times80G A100s, as listed below, takes 5 days, which is about 1% budget than existing works such as Xiong et al. (2023), which trains on 400B tokens.
|
||||||
|
Framework
|
||||||
|
Huggingface Transformers
|
||||||
|
+ DeepSpeed Zero 3
|
||||||
|
+ FlashAttention 2
|
||||||
|
+ Gradient Checkpointing
|
||||||
|
+ CPU Offloading
|
||||||
|
Hardware
|
||||||
|
8 ×\times 80G A100
|
||||||
|
LLaMA 2 7B
|
||||||
|
Ctx. 4K 3 days / 10B tokens
|
||||||
|
Ctx. 80K 10 days / 10B tokens
|
||||||
|
LLaMA 2 13B
|
||||||
|
Ctx. 4K 5 days / 10B tokens
|
||||||
|
Ctx. 64K 13 days / 10B tokens
|
||||||
|
Hardware
|
||||||
|
2 ×\times 8 ×\times 80G A100
|
||||||
|
LLaMA 2 7B
|
||||||
|
Ctx. 4K 2 days / 10B tokens
|
||||||
|
Ctx. 80K 7 days / 10B tokens
|
||||||
|
LLaMA 2 13B
|
||||||
|
Ctx. 4K 4 days / 10B tokens
|
||||||
|
Ctx. 64K 10 days / 10B tokens
|
||||||
|
5 Experimental Results
|
||||||
|
We continue pretraining the base LLaMA 2 7B/ 13B models on data produced by our ”Per-source Upsampling” strategy (Sec. 5.3).
|
||||||
|
The number of training tokens is 5B. We first show that our method outperforms strong open-source baselines like YaRN Mistral 7B 128K (Peng et al., 2023) and LongLoRA 7B 100K (Chen et al., 2023b), and closes the gap to GPT-4 Turbo 128K.
|
||||||
|
Then we dissect the ingredients of our data recipe.
|
||||||
|
In section 5.2, we discuss data sufficiency (the 5B part)
|
||||||
|
and show that as we increase the amount of data from 100M to 1B, the model gradually surfaces the ability to precisely retrieve given information at arbitrary locations within 128K documents. In section 5.3, we discuss the data mixture (the per-source length upsampled part), and show that the original mixture of SlimPajama is insufficient (although it has about 30% data longer than 4K), and one needs to upsample long sequences for the model to acquire the long context capability.
|
||||||
|
We also show that the improvements on one upsampled domain (e.g., Books), have limited transfer to others, and can even hurt them.
|
||||||
|
The Book and Code domains are a particular example that improvements on one come with detrimental impact on the other.
|
||||||
|
Existing work heavily uses validation loss as the primary evaluation (Chen et al., 2023a; Chen et al., 2023b; Xiao et al., 2023; Peng et al., 2023).
|
||||||
|
We show that using only the validation loss is insufficient because two data recipes that result in similar loss may have substantially different retrieval capabilities, as we show in Fig. 4.
|
||||||
|
In addition to Needle-in-a-Haystack, we use a real-world book-long question answering benchmark (Zhang et al., 2023) for our evaluation.
|
||||||
|
There are earlier long context benchmarks such as Zeroscrolls (Shaham et al., 2023), longbench (Bai et al., 2023b) and L-Eval (An et al., 2023).
|
||||||
|
We do not evaluate on them because their lengths are mostly around 10K, which were considered long at their release time, but substantially shorter than the 128K regime, which is the focus of the present work.
|
||||||
|
5.1 Overall Performance
|
||||||
|
Table 3:
|
||||||
|
Our method achieves better long context task performance (Needle. performance) without compromising short context performance (MMLU).
|
||||||
|
Ctx.
|
||||||
|
Needle.
|
||||||
|
MMLU
|
||||||
|
Non-LLaMA Models
|
||||||
|
GPT-4-Turbo
|
||||||
|
128K
|
||||||
|
87.1
|
||||||
|
86.4
|
||||||
|
GPT-3.5-Turbo
|
||||||
|
16K
|
||||||
|
-
|
||||||
|
67.3
|
||||||
|
YaRN Mistral 7B
|
||||||
|
128K
|
||||||
|
57.4
|
||||||
|
59.4
|
||||||
|
LLaMA-2 7B Based Models
|
||||||
|
Together LLaMA-2 7B
|
||||||
|
32K
|
||||||
|
27.9
|
||||||
|
44.8
|
||||||
|
LongChat v1.5 7B
|
||||||
|
32K
|
||||||
|
18.0
|
||||||
|
42.3
|
||||||
|
LongLoRA 7B
|
||||||
|
100K
|
||||||
|
70.0
|
||||||
|
37.9
|
||||||
|
Ours LLaMA-2 7B
|
||||||
|
80K
|
||||||
|
88.0
|
||||||
|
43.3
|
||||||
|
LLaMA-2 13B Based Models
|
||||||
|
LongLoRA 13B
|
||||||
|
64K
|
||||||
|
54.1
|
||||||
|
50.1
|
||||||
|
Ours LLaMA-2 13B
|
||||||
|
64K
|
||||||
|
90.0
|
||||||
|
52.4
|
||||||
|
Figure 1 compares our method with Together AI’s LLaMA-2 32K (Together, 2023), LMSys’ LongChat v1.5 32K (Li et al., 2023a), YaRN Mistral 7B 128K (Peng et al., 2023), and LongLoRA 100K (Chen et al., 2023b).
|
||||||
|
We choose these models as our baseline because they are so far the top open-source long-context language models (as evidenced by thousands of GitHub stars).
|
||||||
|
LongChat v1.5 32K does not perform well even for sequence length 16K-32K, and we hypothesize that this is because the model has not gone through enough continual pretraining, but directly goes to finetuning.
|
||||||
|
Together AI’s LLaMA-2 7B’s data mixture is similar to ours, which we believe to be the reason that they perform well within 32K.
|
||||||
|
Yet their model does not generalize beyond 32K, while ours generalizes from 80K to 128K.
|
||||||
|
For LongLoRA, we believe the two major problems are that they use sparse attention and that they do not upsample long sequence data, which we show is problematic in Fig. 4.
|
||||||
|
For YaRN Mistral, we hypothesize that its underperformance is due to its being only trained on PG19 book (Rae et al., 2019); we show that it is important to use a balanced domain mixture in Table 5.
|
||||||
|
Figure 3:
|
||||||
|
As we increase the number of trained tokens, the model’s retrieval performance increases with converged validation loss.
|
||||||
|
We further note two observations with regard to data quantity:
|
||||||
|
(1) 500M tokens are enough to unlock most of the retrieval accuracy. Since we are not explicitly training the model to perform retrieval, this potentially suggests that the model already has the precise retrieval capability, and that we are simply extending this capability with lightweight continual pretraining;
|
||||||
|
(2) the model’s retrieval performance saturates at about 5B tokens, and further scaling to 10B tokens does not improve length generalization.
|
||||||
|
In Table 3 we show that our method not only improves precise retrieval, but maintains short context performance, evidenced by strong MMLU (Hendrycks et al., 2020) score, which is a widely-accepted benchmark for testing the general capabilities (within short context) of language models, and is used by Chinchilla (Hoffmann et al., 2022), LLama (Touvron et al., 2023a; Touvron et al., 2023b), Mistral (Jiang et al., 2023), QWen (Bai et al., 2023a), and Baichuan (Yang et al., 2023a).
|
||||||
|
Table 4 further compares 128K context language models on a book-long question answering benchmark recently proposed by Zhang et al. (2023).
|
||||||
|
This task conditions language models on a book and then asks questions about the plot.
|
||||||
|
Our method outperforms LongLoRA and Yarn Mistral (even though Mistral 7B is a stronger base model than LLaMA 2 7B we use).
|
||||||
|
Our 13B model performance closes the gap to GPT-4 128K, and we anticipate that future scaling and instruction tuning will further improve performance.
|
||||||
|
While there are other long-context benchmarks in InfiniBench (Zhang et al., 2023), in our initial experiments we found that models often had trouble understanding the instruction (because they are not instruction tuned). Hence we focus on the BookQA benchmark where base LLMs performed reasonably without instruction tuning.
|
||||||
|
5.2 Data Quantity
|
||||||
|
Table 4:
|
||||||
|
The performaince gain shown in Needle-in-a-Haystack further translates to improvements on downstream BookQA.
|
||||||
|
We report the results on 128K length InfiniBench long book question answering task (Zhang et al., 2023).
|
||||||
|
Our method outperforms top open-source models and closes the gap to GPT-4.
|
||||||
|
Model / Train Len
|
||||||
|
Test Len
|
||||||
|
BookQA
|
||||||
|
GPT-4-Turbo 128K
|
||||||
|
128K
|
||||||
|
37.4
|
||||||
|
LongLoRA 7B 100K
|
||||||
|
128K
|
||||||
|
24.3
|
||||||
|
Ours LLaMA-2 7B 80K
|
||||||
|
128K
|
||||||
|
27.4
|
||||||
|
LongLoRA 13B 64K
|
||||||
|
128K
|
||||||
|
24.6
|
||||||
|
YaRN Mistral 7B 128K
|
||||||
|
128K
|
||||||
|
26.3
|
||||||
|
Ours LLaMA-2 13B 64K
|
||||||
|
128K
|
||||||
|
31.1
|
||||||
|
Table 5:
|
||||||
|
How different data engineering methods improves (or does not improve) the original data mixture, where we show results from continual pretraining of a 7B LLaMA-2 on 5B tokens packed to 80K length.
|
||||||
|
We consider how changing the original data mixture to long-context upsampled data mixture results in different loss across domains, and report the loss differences to the original data mixture (e.g., the loss of per-source length upsampling minus the loss of original mixture).
|
||||||
|
We view a loss difference larger than 0.01 significant,
|
||||||
|
marked by a red shade indicating performance decrease of larger than +0.01 loss; or a green shade indicating performance improvements of smaller than -0.01 loss, or a grey shade indicating no significant differences.
|
||||||
|
Although upsampling book / code / arxiv improves in-domain performance for both short and long context, such improvements do not transfer to all domains. Instead, upsampling one domain, e.g., code, may even harm another domain, e.g., book.
|
||||||
|
Per-source length upsampling is the most balanced mixture with almost no significant increase of loss across domains.
|
||||||
|
C4
|
||||||
|
CC
|
||||||
|
Stack
|
||||||
|
Arxiv
|
||||||
|
Wiki
|
||||||
|
Book
|
||||||
|
Github
|
||||||
|
0 - 4K Context Length
|
||||||
|
Original
|
||||||
|
2.038
|
||||||
|
1.760
|
||||||
|
1.519
|
||||||
|
1.660
|
||||||
|
1.424
|
||||||
|
2.085
|
||||||
|
0.907
|
||||||
|
v.s. Per-source
|
||||||
|
+ .002
|
||||||
|
+ .008
|
||||||
|
– .001
|
||||||
|
– .008
|
||||||
|
– .040
|
||||||
|
– .065
|
||||||
|
– .008
|
||||||
|
v.s. Global
|
||||||
|
+ .008
|
||||||
|
+ .010
|
||||||
|
+ .015
|
||||||
|
– .020
|
||||||
|
– .020
|
||||||
|
– .140
|
||||||
|
+ .015
|
||||||
|
v.s. Code↑\uparrow
|
||||||
|
+ .010
|
||||||
|
+ .016
|
||||||
|
+ .010
|
||||||
|
+ .006
|
||||||
|
– .026
|
||||||
|
+ .030
|
||||||
|
– .023
|
||||||
|
v.s. Book↑\uparrow
|
||||||
|
+ .010
|
||||||
|
+ .016
|
||||||
|
+ .021
|
||||||
|
+ .000
|
||||||
|
– .010
|
||||||
|
– .175
|
||||||
|
+ .029
|
||||||
|
v.s. Arxiv↑\uparrow
|
||||||
|
+ .006
|
||||||
|
+ .016
|
||||||
|
+ .013
|
||||||
|
– .060
|
||||||
|
– .030
|
||||||
|
+ .040
|
||||||
|
+ .025
|
||||||
|
4K - 128K Context Length
|
||||||
|
Original
|
||||||
|
1.560
|
||||||
|
1.650
|
||||||
|
0.786
|
||||||
|
1.075
|
||||||
|
1.313
|
||||||
|
1.852
|
||||||
|
0.447
|
||||||
|
v.s. Per-source
|
||||||
|
– .010
|
||||||
|
– .010
|
||||||
|
– .006
|
||||||
|
– .011
|
||||||
|
– .044
|
||||||
|
– .014
|
||||||
|
+ .002
|
||||||
|
v.s. Global
|
||||||
|
– .010
|
||||||
|
– .006
|
||||||
|
– .001
|
||||||
|
– .016
|
||||||
|
– .040
|
||||||
|
– .018
|
||||||
|
– .007
|
||||||
|
v.s. Code↑\uparrow
|
||||||
|
– .008
|
||||||
|
– .002
|
||||||
|
– .003
|
||||||
|
– .007
|
||||||
|
– .042
|
||||||
|
– .010
|
||||||
|
– .029
|
||||||
|
v.s. Book↑\uparrow
|
||||||
|
– .010
|
||||||
|
– .006
|
||||||
|
+ .001
|
||||||
|
– .007
|
||||||
|
– .037
|
||||||
|
– 0.30
|
||||||
|
+ .000
|
||||||
|
v.s. Arxiv↑\uparrow
|
||||||
|
– .008
|
||||||
|
– .002
|
||||||
|
+ .002
|
||||||
|
– .036
|
||||||
|
– .039
|
||||||
|
– .010
|
||||||
|
– .004
|
||||||
|
Now we consider data quantity, i.e., how much data enables the language model to utilize the information at arbitrary locations within 128K context.
|
||||||
|
Our hypothesis is that precise retreival over long-range context is an intrinsic capability obtained by large-scale pretraining, even when the pretraining context length is substantially shorter (4K in many cases).
|
||||||
|
If this hypothesis is true, then lightweight continual pretraining should be enough to extend this capability to much longer context lengths than see in training. That is, we would not need data-intensive continual pretraining as used by Xiong et al. (2023) and XVerse (2024).
|
||||||
|
Fig. 3 shows how data scaling gradually unlocks the model’s retrieval capability.
|
||||||
|
When the model is continually pretrained on 100M to 300M tokens, the model’s loss gradually decreases, but it has not converged yet.
|
||||||
|
At 500M to 1B tokens, the model achieves relatively good performance within its continually pretrained 80K context, but does not generalize to 80K-128K range.
|
||||||
|
After 5B tokens, the model performs well on 0-80K, and can generalize to unseen lengths 80K-128K.
|
||||||
|
At 10B token, the model seems to overfit on its 80K training range, and the length generalization starts to decrease.
|
||||||
|
Along this process, we see a gradual decrease in loss, which correlates with the increase in the retrieval performance.
|
||||||
|
This result provides more evidence for our hypothesis, as only 500M tokens are required to enable a model’s retrieval capability with 80K context.
|
||||||
|
Continually pretraining a 7B LLaMA-2 takes about 5 days on 8×\times80G A100 GPUs, and the cost is reasonable compared to large-scale pretraining (which requires months of compute on thousands of GPUs). Our results suggest that for supervised finetuning, since training on long-context is substantially cheaper than previously thought, future work may dive deeper on the solutions for 100K length finetuning and reasoning, which so far has almost no open-source work to our knowledge.
|
||||||
|
For pretraining research, currently there is no definite answer as to whether long-context continual pretraining should be combined with other capabilities, such as math (Azerbayev et al., 2023) and code (Chen et al., 2021), which typically require hundreds of billions of tokens. Our results suggest that long-context continual pretraining could be a separate stage after code and math pretraining.
|
||||||
|
5.3 Data Mixture
|
||||||
|
Figure 4: The importance of length upsampling.
|
||||||
|
The validation loss,
|
||||||
|
a common measure for long-context language modeling used in Xiong et al. (2023); Chen et al. (2023b),
|
||||||
|
cannot reveal long-context retreival capability, but Needle-in-a-Haystack can.
|
||||||
|
The original data mixture, i.e. without length upsampling, despite giving very close loss, performs badly on precise retrieval. Per-source length upsampling significantly improves precise retrieval.
|
||||||
|
Now we discuss why per-source length upsampling is necessary when constructing the data mixture.
|
||||||
|
Recall that this strategy keeps the mixture ratio of the data sources the same as the original data, i.e., 67% CommonCrawl (CC), 15% C4, 4.5% Github, 4.5% Wikipedia, 4.5% books, 2.5% Arxiv and 2.0% StackExchange for SlimPajama.
|
||||||
|
Then in each of the domains, we upsample sequences longer than 4K from about 30% to about 70%.
|
||||||
|
Doing this enables us to keep the domain mixture ratio fixed, only changing the length distribution of the training documents.
|
||||||
|
In contrast, globally upsampling long sequences (without considering their domain), or intentionally upsampling code/ book/ Arxiv (since they are long) changes both the domain mixture and the length distribution.
|
||||||
|
We compare all the data mixtures with the original one packed to 80K / 64K for the continual pretraining of the 7B / 13B LLaMA-2.
|
||||||
|
This baseline approach effectively never changes the original data, but keeps the naturally existing long sequence that would otherwise been cut to 4K (recall Sec. 3).
|
||||||
|
If a data mixture is effective, it should be at least better than this baseline “do nothing” approach.
|
||||||
|
Table 5 compares the per-domain loss differences of all the data mixture against the baseline original mixture.
|
||||||
|
We report the differences of the validation loss, where a more than 0.01 loss change is considered significant, following common pretraining practice (Kaplan et al., 2020; Peng et al., 2023; Hoffmann et al., 2022).
|
||||||
|
We observe:
|
||||||
|
(1) for 0-4K short context data, most of the data mixtures have a negative impact on webpages (C4, CC and StackExchange), except for the per-source approach;
|
||||||
|
(2) performance improvements from domains like Book may not transfer to others, and even hurt code performance;
|
||||||
|
(3) per-source length upsampling is the most balanced mixture that improves 4K-128K context losses without much sacrificing short-context losses, whereas all other methods show more or less performance tradeoff across domains.
|
||||||
|
Combining these observations, we recommend the per-source length-upsampling strategy.
|
||||||
|
Since per-source length upsampling keeps the domain mixture ratio while increasing tokens from long sequences, its major difference to the original data mixture is the distribution of sequence length.
|
||||||
|
Fig. 4 makes a close comparison between the two data strategies.
|
||||||
|
Specifically, we train two LLaMA-2 7B models with a 80K context length using original / per-source upsampled data mixture, and report their per-length validation loss and Needle-in-a-Haystack performance.
|
||||||
|
Note that LongLoRA (Chen et al., 2023b) uses the original data mixture without length upsampling,
|
||||||
|
so our results also explains why we achieve better performance than LongLoRA (Fig. 1).
|
||||||
|
We see that the original data mixture without length upsampling, despite achieving a very close loss, underperforms on precise retrieval.
|
||||||
|
Per-source length upsampling significantly improves precise retrieval.
|
||||||
|
This observation also serves as strong evidence why only using test loss, the evaluation used in most prior work (Chen et al., 2023a; Peng et al., 2023; Chen et al., 2023b; Xiao et al., 2023; Anthropic, 2023), may conceal the underlying model differences.
|
||||||
|
The necessity of length upsampling is demonstrated by the Needle-in-a-Haystack test.
|
||||||
|
6 Discussion
|
||||||
|
We attribute our improvements over strong open-source baselines, as is detailed in section 5,
|
||||||
|
to our careful treatments of data engineering.
|
||||||
|
Our results echo the recent wisdom that in large language model research,
|
||||||
|
data engineering is equally important as modeling and algorithmic innovations (Kaplan et al., 2020; Hoffmann et al., 2022; Brown et al., 2020).
|
||||||
|
As we list in Table 1, many of the data details are crucial for strong long-context performance, yet may be easily overlooked. We also acknowledge that our research is made possible through utilizing the latest innovations in machine learning systems research, particularly FlashAttention (Dao, 2023) as it reduces the memory usage of the attention mechanism from quadratic to linear. Incorporating further work on sequence parallelism (Li et al., 2021; Jacobs et al., 2023) could enable brute force training of even longer context (e.g., 200K) models.
|
||||||
|
The Transformer’s use of position embeddings makes it difficult to generalize significantly beyond contexts seen during training even with relative positional encodings (Press et al., 2021; Sun et al., 2022; Li et al., 2023b), thus necessitating (at least a little bit of) continual pretraining. There has much recent work on RNN-like architectures, which implicitly encode positional information through their hidden states, that perform competitively with Transformers (Sun et al., 2023; Qin et al., 2023; Gu & Dao, 2023; Yang et al., 2023b). It would be interesting to test whether such models can generalize zero-shot to longer contexts than seen during training on the Needle-in-a-Haystack benchmark.
|
||||||
|
Long-context language model research at the 100K-level is still a developing research area.
|
||||||
|
This work only studies continual pretraining, and research on instruction finetuning language models on tasks of 100K context length (e.g., repo-level code understanding) is still limited.
|
||||||
|
So far there seems to no open-source instruction-finetuned 100K context language models. We hope our work serve as a basis for future work on 100K-level long context superivsed finetuning.
|
||||||
|
7 Conclusion
|
||||||
|
This work studies a continual pretraining recipe for scaling language models’ context length to 128K tokens.
|
||||||
|
We demonstrate that the ability to utilize information at arbitrary locations within the 128K input is already mostly acquired by large-scale pretraining, even for models pretrained on substantially shorter 4K context.
|
||||||
|
We show that continual pretraining of the full model on 1-5 billion tokens from per-source length-upsampled data gives the most balanced performance improvements. Our work closes the gap to frontier models like GPT-4 128K on the retrieval task and serves as the foundation for future long-context instruction finetuning research.
|
||||||
|
References
|
||||||
|
An et al. (2023)
|
||||||
|
An, C., Gong, S., Zhong, M., Li, M., Zhang, J., Kong, L., and Qiu, X.
|
||||||
|
L-eval: Instituting standardized evaluation for long context language
|
||||||
|
models.
|
||||||
|
arXiv preprint arXiv:2307.11088, 2023.
|
||||||
|
Anthropic (2023)
|
||||||
|
Anthropic.
|
||||||
|
Model card and evaluations for claude models, July 2023.
|
||||||
|
URL https://www.anthropic.com/product.
|
||||||
|
Azerbayev et al. (2023)
|
||||||
|
Azerbayev, Z., Schoelkopf, H., Paster, K., Santos, M. D., McAleer, S., Jiang,
|
||||||
|
A. Q., Deng, J., Biderman, S., and Welleck, S.
|
||||||
|
Llemma: An open language model for mathematics.
|
||||||
|
arXiv preprint arXiv:2310.10631, 2023.
|
||||||
|
Bai et al. (2023a)
|
||||||
|
Bai, J., Bai, S., Chu, Y., Cui, Z., Dang, K., Deng, X., Fan, Y., Ge, W., Han,
|
||||||
|
Y., Huang, F., et al.
|
||||||
|
Qwen technical report.
|
||||||
|
arXiv preprint arXiv:2309.16609, 2023a.
|
||||||
|
Bai et al. (2023b)
|
||||||
|
Bai, Y., Lv, X., Zhang, J., Lyu, H., Tang, J., Huang, Z., Du, Z., Liu, X.,
|
||||||
|
Zeng, A., Hou, L., et al.
|
||||||
|
Longbench: A bilingual, multitask benchmark for long context
|
||||||
|
understanding.
|
||||||
|
arXiv preprint arXiv:2308.14508, 2023b.
|
||||||
|
Bairi et al. (2023)
|
||||||
|
Bairi, R., Sonwane, A., Kanade, A., Iyer, A., Parthasarathy, S., Rajamani, S.,
|
||||||
|
Ashok, B., Shet, S., et al.
|
||||||
|
Codeplan: Repository-level coding using llms and planning.
|
||||||
|
arXiv preprint arXiv:2309.12499, 2023.
|
||||||
|
Brown et al. (2020)
|
||||||
|
Brown, T., Mann, B., Ryder, N., Subbiah, M., Kaplan, J. D., Dhariwal, P.,
|
||||||
|
Neelakantan, A., Shyam, P., Sastry, G., Askell, A., et al.
|
||||||
|
Language models are few-shot learners.
|
||||||
|
Advances in neural information processing systems,
|
||||||
|
33:1877–1901, 2020.
|
||||||
|
Caciularu et al. (2023)
|
||||||
|
Caciularu, A., Peters, M. E., Goldberger, J., Dagan, I., and Cohan, A.
|
||||||
|
Peek across: Improving multi-document modeling via cross-document
|
||||||
|
question-answering.
|
||||||
|
arXiv preprint arXiv:2305.15387, 2023.
|
||||||
|
Chen et al. (2021)
|
||||||
|
Chen, M., Tworek, J., Jun, H., Yuan, Q., Pinto, H. P. d. O., Kaplan, J.,
|
||||||
|
Edwards, H., Burda, Y., Joseph, N., Brockman, G., et al.
|
||||||
|
Evaluating large language models trained on code.
|
||||||
|
arXiv preprint arXiv:2107.03374, 2021.
|
||||||
|
Chen et al. (2023a)
|
||||||
|
Chen, S., Wong, S., Chen, L., and Tian, Y.
|
||||||
|
Extending context window of large language models via positional
|
||||||
|
interpolation.
|
||||||
|
arXiv preprint arXiv:2306.15595, 2023a.
|
||||||
|
Chen et al. (2023b)
|
||||||
|
Chen, Y., Qian, S., Tang, H., Lai, X., Liu, Z., Han, S., and Jia, J.
|
||||||
|
Longlora: Efficient fine-tuning of long-context large language
|
||||||
|
models.
|
||||||
|
arXiv preprint arXiv:2309.12307, 2023b.
|
||||||
|
Dao (2023)
|
||||||
|
Dao, T.
|
||||||
|
Flashattention-2: Faster attention with better parallelism and work
|
||||||
|
partitioning.
|
||||||
|
arXiv preprint arXiv:2307.08691, 2023.
|
||||||
|
Fuzhao Xue & You (2023)
|
||||||
|
Fuzhao Xue, Zian Zheng, Y. F. J. N. Z. Z. W. Z. and You, Y.
|
||||||
|
Openmoe: Open mixture-of-experts language models.
|
||||||
|
https://github.com/XueFuzhao/OpenMoE, 2023.
|
||||||
|
Gu & Dao (2023)
|
||||||
|
Gu, A. and Dao, T.
|
||||||
|
Mamba: Linear-time sequence modeling with selective state spaces.
|
||||||
|
2023.
|
||||||
|
URL https://api.semanticscholar.org/CorpusID:265551773.
|
||||||
|
Hendrycks et al. (2020)
|
||||||
|
Hendrycks, D., Burns, C., Basart, S., Zou, A., Mazeika, M., Song, D., and
|
||||||
|
Steinhardt, J.
|
||||||
|
Measuring massive multitask language understanding.
|
||||||
|
arXiv preprint arXiv:2009.03300, 2020.
|
||||||
|
Hoffmann et al. (2022)
|
||||||
|
Hoffmann, J., Borgeaud, S., Mensch, A., Buchatskaya, E., Cai, T., Rutherford,
|
||||||
|
E., Casas, D. d. L., Hendricks, L. A., Welbl, J., Clark, A., et al.
|
||||||
|
Training compute-optimal large language models.
|
||||||
|
arXiv preprint arXiv:2203.15556, 2022.
|
||||||
|
Jacobs et al. (2023)
|
||||||
|
Jacobs, S. A., Tanaka, M., Zhang, C., Zhang, M., Song, L., Rajbhandari, S., and
|
||||||
|
He, Y.
|
||||||
|
Deepspeed ulysses: System optimizations for enabling training of
|
||||||
|
extreme long sequence transformer models.
|
||||||
|
arXiv preprint arXiv:2309.14509, 2023.
|
||||||
|
Jiang et al. (2023)
|
||||||
|
Jiang, A. Q., Sablayrolles, A., Mensch, A., Bamford, C., Chaplot, D. S., Casas,
|
||||||
|
D. d. l., Bressand, F., Lengyel, G., Lample, G., Saulnier, L., et al.
|
||||||
|
Mistral 7b.
|
||||||
|
arXiv preprint arXiv:2310.06825, 2023.
|
||||||
|
Kamradt (2023)
|
||||||
|
Kamradt, G.
|
||||||
|
Needle in a haystack - pressure testing llms.
|
||||||
|
https://github.com/gkamradt/LLMTest_NeedleInAHaystack, 2023.
|
||||||
|
Kaplan et al. (2020)
|
||||||
|
Kaplan, J., McCandlish, S., Henighan, T., Brown, T. B., Chess, B., Child, R.,
|
||||||
|
Gray, S., Radford, A., Wu, J., and Amodei, D.
|
||||||
|
Scaling laws for neural language models.
|
||||||
|
arXiv preprint arXiv:2001.08361, 2020.
|
||||||
|
Li et al. (2023a)
|
||||||
|
Li, D., Shao, R., Xie, A., Sheng, Y., Zheng, L., Gonzalez, J. E., Stoica, I.,
|
||||||
|
Ma, X., and Zhang, H.
|
||||||
|
How long can open-source llms truly promise on context length?, June
|
||||||
|
2023a.
|
||||||
|
URL https://lmsys.org/blog/2023-06-29-longchat.
|
||||||
|
Li et al. (2021)
|
||||||
|
Li, S., Xue, F., Baranwal, C., Li, Y., and You, Y.
|
||||||
|
Sequence parallelism: Long sequence training from system perspective.
|
||||||
|
arXiv preprint arXiv:2105.13120, 2021.
|
||||||
|
Li et al. (2023b)
|
||||||
|
Li, S., You, C., Guruganesh, G., Ainslie, J., Ontanon, S., Zaheer, M., Sanghai,
|
||||||
|
S., Yang, Y., Kumar, S., and Bhojanapalli, S.
|
||||||
|
Functional interpolation for relative positions improves long context
|
||||||
|
transformers.
|
||||||
|
arXiv preprint arXiv:2310.04418, 2023b.
|
||||||
|
Mazumder & Liu (2024)
|
||||||
|
Mazumder, S. and Liu, B.
|
||||||
|
Lifelong and Continual Learning Dialogue Systems.
|
||||||
|
Springer Nature, 2024.
|
||||||
|
Peng et al. (2023)
|
||||||
|
Peng, B., Quesnelle, J., Fan, H., and Shippole, E.
|
||||||
|
Yarn: Efficient context window extension of large language models,
|
||||||
|
2023.
|
||||||
|
Press et al. (2021)
|
||||||
|
Press, O., Smith, N. A., and Lewis, M.
|
||||||
|
Train short, test long: Attention with linear biases enables input
|
||||||
|
length extrapolation.
|
||||||
|
arXiv preprint arXiv:2108.12409, 2021.
|
||||||
|
Qin et al. (2023)
|
||||||
|
Qin, Z., Yang, S., and Zhong, Y.
|
||||||
|
Hierarchically gated recurrent neural network for sequence modeling.
|
||||||
|
CoRR, abs/2311.04823, 2023.
|
||||||
|
doi: 10.48550/ARXIV.2311.04823.
|
||||||
|
URL https://doi.org/10.48550/arXiv.2311.04823.
|
||||||
|
Rae et al. (2019)
|
||||||
|
Rae, J. W., Potapenko, A., Jayakumar, S. M., Hillier, C., and Lillicrap, T. P.
|
||||||
|
Compressive transformers for long-range sequence modelling.
|
||||||
|
arXiv preprint, 2019.
|
||||||
|
URL https://arxiv.org/abs/1911.05507.
|
||||||
|
Raffel et al. (2020)
|
||||||
|
Raffel, C., Shazeer, N., Roberts, A., Lee, K., Narang, S., Matena, M., Zhou,
|
||||||
|
Y., Li, W., and Liu, P. J.
|
||||||
|
Exploring the limits of transfer learning with a unified text-to-text
|
||||||
|
transformer.
|
||||||
|
The Journal of Machine Learning Research, 21(1):5485–5551, 2020.
|
||||||
|
Rajbhandari et al. (2020)
|
||||||
|
Rajbhandari, S., Rasley, J., Ruwase, O., and He, Y.
|
||||||
|
Zero: Memory optimizations toward training trillion parameter models.
|
||||||
|
In SC20: International Conference for High Performance
|
||||||
|
Computing, Networking, Storage and Analysis, pp. 1–16. IEEE, 2020.
|
||||||
|
Shaham et al. (2023)
|
||||||
|
Shaham, U., Ivgi, M., Efrat, A., Berant, J., and Levy, O.
|
||||||
|
Zeroscrolls: A zero-shot benchmark for long text understanding, 2023.
|
||||||
|
Soboleva et al. (2023)
|
||||||
|
Soboleva, D., Al-Khateeb, F., Myers, R., Steeves, J. R., Hestness, J., and Dey,
|
||||||
|
N.
|
||||||
|
SlimPajama: A 627B token cleaned and deduplicated version of
|
||||||
|
RedPajama.
|
||||||
|
https://www.cerebras.net/blog/slimpajama-a-627b-token-cleaned-and-deduplicated-version-of-redpajama,
|
||||||
|
2023.
|
||||||
|
URL https://huggingface.co/datasets/cerebras/SlimPajama-627B.
|
||||||
|
Sun et al. (2022)
|
||||||
|
Sun, Y., Dong, L., Patra, B., Ma, S., Huang, S., Benhaim, A., Chaudhary, V.,
|
||||||
|
Song, X., and Wei, F.
|
||||||
|
A length-extrapolatable transformer.
|
||||||
|
arXiv preprint arXiv:2212.10554, 2022.
|
||||||
|
Sun et al. (2023)
|
||||||
|
Sun, Y., Dong, L., Huang, S., Ma, S., Xia, Y., Xue, J., Wang, J., and Wei, F.
|
||||||
|
Retentive network: A successor to transformer for large language
|
||||||
|
models.
|
||||||
|
arXiv preprint arXiv:2307.08621, 2023.
|
||||||
|
Team (2023)
|
||||||
|
Team, M. N.
|
||||||
|
Introducing mpt-7b: A new standard for open-source, commercially
|
||||||
|
usable llms, 2023.
|
||||||
|
URL www.mosaicml.com/blog/mpt-7b.
|
||||||
|
Accessed: 2023-03-28.
|
||||||
|
Together (2023)
|
||||||
|
Together.
|
||||||
|
Llama-2-7b-32k-instruct — and fine-tuning for llama-2 models with
|
||||||
|
together api, August 2023.
|
||||||
|
URL https://www.together.ai/blog/llama-2-7b-32k-instruct.
|
||||||
|
Touvron et al. (2023a)
|
||||||
|
Touvron, H., Lavril, T., Izacard, G., Martinet, X., Lachaux, M.-A., Lacroix,
|
||||||
|
T., Rozière, B., Goyal, N., Hambro, E., Azhar, F., et al.
|
||||||
|
Llama: Open and efficient foundation language models.
|
||||||
|
arXiv preprint arXiv:2302.13971, 2023a.
|
||||||
|
Touvron et al. (2023b)
|
||||||
|
Touvron, H., Martin, L., Stone, K., Albert, P., Almahairi, A., Babaei, Y.,
|
||||||
|
Bashlykov, N., Batra, S., Bhargava, P., Bhosale, S., et al.
|
||||||
|
Llama 2: Open foundation and fine-tuned chat models.
|
||||||
|
arXiv preprint arXiv:2307.09288, 2023b.
|
||||||
|
Weng (2023)
|
||||||
|
Weng, L.
|
||||||
|
Llm-powered autonomous agents.
|
||||||
|
lilianweng.github.io, Jun 2023.
|
||||||
|
URL https://lilianweng.github.io/posts/2023-06-23-agent/.
|
||||||
|
Xiao et al. (2023)
|
||||||
|
Xiao, G., Tian, Y., Chen, B., Han, S., and Lewis, M.
|
||||||
|
Efficient streaming language models with attention sinks.
|
||||||
|
arXiv preprint arXiv:2309.17453, 2023.
|
||||||
|
Xiong et al. (2023)
|
||||||
|
Xiong, W., Liu, J., Molybog, I., Zhang, H., Bhargava, P., Hou, R., Martin, L.,
|
||||||
|
Rungta, R., Sankararaman, K. A., Oguz, B., et al.
|
||||||
|
Effective long-context scaling of foundation models.
|
||||||
|
arXiv preprint arXiv:2309.16039, 2023.
|
||||||
|
XVerse (2024)
|
||||||
|
XVerse.
|
||||||
|
Xverse-13b, January 2024.
|
||||||
|
URL
|
||||||
|
https://github.com/xverse-ai/XVERSE-13B/blob/main/README_EN.md.
|
||||||
|
Yang et al. (2023a)
|
||||||
|
Yang, A., Xiao, B., Wang, B., Zhang, B., Bian, C., Yin, C., Lv, C., Pan, D.,
|
||||||
|
Wang, D., Yan, D., et al.
|
||||||
|
Baichuan 2: Open large-scale language models.
|
||||||
|
arXiv preprint arXiv:2309.10305, 2023a.
|
||||||
|
Yang et al. (2023b)
|
||||||
|
Yang, S., Wang, B., Shen, Y., Panda, R., and Kim, Y.
|
||||||
|
Gated linear attention transformers with hardware-efficient training.
|
||||||
|
arXiv preprint arXiv:2312.06635, 2023b.
|
||||||
|
Zhang et al. (2023)
|
||||||
|
Zhang, X., Chen, Y., Hu, S., Wu, Q., Chen, J., Xu, Z., Dai, Z., Han, X., Wang,
|
||||||
|
S., Liu, Z., and Sun, M.
|
||||||
|
Infinitebench: 128k long-context benchmark for language models, 2023.
|
||||||
|
Experimental support, please
|
||||||
|
view the build logs
|
||||||
|
for errors. Generated by
|
||||||
|
L
|
||||||
|
A
|
||||||
|
T
|
||||||
|
E
|
||||||
|
xml
|
||||||
|
.
|
||||||
|
Instructions for reporting errors
|
||||||
|
We are continuing to improve HTML versions of papers, and your feedback helps enhance accessibility and mobile
|
||||||
|
support. To report errors in the HTML that will help us improve conversion and rendering, choose any of the
|
||||||
|
methods listed below:
|
||||||
|
Click the "Report Issue" (
|
||||||
|
) button, located in the page header.
|
||||||
|
Tip: You can select the relevant text first, to include it in your report.
|
||||||
|
Our team has already identified the following issues. We appreciate your time reviewing and reporting rendering errors we
|
||||||
|
may not have found yet. Your efforts will help us improve the HTML versions for all readers, because disability
|
||||||
|
should not be a barrier to accessing research. Thank you for your continued support in championing open access for
|
||||||
|
all.
|
||||||
|
Have a free development cycle? Help support accessibility at arXiv! Our collaborators at LaTeXML maintain a list of packages that need conversion, and welcome developer contributions.
|
||||||
|
We gratefully acknowledge support from our major funders,
|
||||||
|
member institutions, ,
|
||||||
|
and all contributors.
|
||||||
|
About ·
|
||||||
|
Help ·
|
||||||
|
Contact ·
|
||||||
|
Subscribe ·
|
||||||
|
Copyright ·
|
||||||
|
Privacy ·
|
||||||
|
Accessibility ·
|
||||||
|
Operational Status (opens in new tab)
|
||||||
|
Major funding support from
|
||||||
|
(opens in new tab)
|
||||||
|
(opens in new tab)
|
||||||
|
(opens in new tab)
|
||||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,751 @@
|
|||||||
|
Lost in the Middle: How Language Models Use Long Contexts
|
||||||
|
Report GitHub Issue
|
||||||
|
×
|
||||||
|
Title:
|
||||||
|
Content selection saved. Describe the issue below:
|
||||||
|
Description:
|
||||||
|
Submit without GitHub
|
||||||
|
Submit in GitHub
|
||||||
|
arXiv is now an independent nonprofit!
|
||||||
|
Learn more
|
||||||
|
×
|
||||||
|
Back to arXiv
|
||||||
|
Why HTML?
|
||||||
|
Report Issue
|
||||||
|
Back to Abstract
|
||||||
|
Download PDF
|
||||||
|
Abstract
|
||||||
|
1 Introduction
|
||||||
|
2 Multi-Document Question Answering
|
||||||
|
2.1 Experimental Setup
|
||||||
|
2.2 Models
|
||||||
|
Open models.
|
||||||
|
Closed models.
|
||||||
|
2.3 Results and Discussion
|
||||||
|
Model performance is highest when relevant information occurs at the beginning or end of its input context.
|
||||||
|
Extended-context models are not necessarily better at using input context.
|
||||||
|
3 How Well Can Language Models Retrieve From Input Contexts?
|
||||||
|
3.1 Experimental Setup
|
||||||
|
3.2 Results and Discussion
|
||||||
|
4 Why Are Language Models Not Robust to Changes in the Position of Relevant Information?
|
||||||
|
4.1 Effect of Model Architecture
|
||||||
|
4.2 Effect of Query-Aware Contextualization
|
||||||
|
4.3 Effect of Instruction Fine-Tuning
|
||||||
|
5 Is More Context Is Always Better? A Case Study With Open-Domain QA
|
||||||
|
6 Related Work
|
||||||
|
6.1 Long-Context Language Models
|
||||||
|
6.2 How Do Language Models Use Context?
|
||||||
|
6.3 The Serial-Position Effect
|
||||||
|
7 Conclusion
|
||||||
|
References
|
||||||
|
A Ambiguity in Multi-Document QA Distractor Documents
|
||||||
|
B Random Distractors in Multi-Document QA
|
||||||
|
C Randomizing Distractor Order in Multi-Document QA
|
||||||
|
D GPT-4 Performance
|
||||||
|
E Llama-2 Performance
|
||||||
|
F Token Counts
|
||||||
|
G Full Multi-Document Question Answering Results
|
||||||
|
G.1 10 Total Retrieved Documents
|
||||||
|
G.2 20 Total Retrieved Documents
|
||||||
|
G.3 30 Total Retrieved Documents
|
||||||
|
License: arXiv.org perpetual non-exclusive license
|
||||||
|
arXiv:2307.03172v3 [cs.CL] 20 Nov 2023
|
||||||
|
Lost in the Middle: How Language Models Use Long Contexts
|
||||||
|
Nelson F. Liu Kevin Lin John Hewitt Ashwin ParanjapeMichele Bevilacqua Fabio Petroni Percy LiangStanford University University of California, Berkeley Samaya AI
|
||||||
|
Email: nfliu@cs.stanford.edu
|
||||||
|
Abstract
|
||||||
|
While recent language models have the ability to take long contexts as input, relatively little is known about how well they use longer context.
|
||||||
|
We analyze the performance of language models on two tasks that require identifying relevant information in their input contexts: multi-document question answering and key-value retrieval.
|
||||||
|
We find that performance can degrade significantly when changing the position of relevant information, indicating that current language models do not robustly make use of information in long input contexts.
|
||||||
|
In particular, we observe that performance is often highest when relevant information occurs at the beginning or end of the input context, and significantly degrades when models must access relevant information in the middle of long contexts, even for explicitly long-context models.
|
||||||
|
Our analysis provides a better understanding of how language models use their input context and provides new evaluation protocols for future long-context language models.
|
||||||
|
††footnotetext: *Work partially completed as an intern at Samaya AI.
|
||||||
|
1 Introduction
|
||||||
|
Figure 1: Changing the location of relevant information (in this case, the position of the passage that answers an input question) within the language model’s input context results in a U-shaped performance curve—models are better at using relevant information that occurs at the very beginning (primacy bias) or end of its input context (recency bias), and performance degrades significantly when models must access and use information located in the middle of its input context.
|
||||||
|
Language models have become an important and flexible building block in a variety of user-facing language technologies, including conversational interfaces, search and summarization, and collaborative writing (Shuster et al., 2022; Thoppilan et al., 2022; Lee et al., 2022, inter alia).
|
||||||
|
These models perform downstream tasks primarily via prompting: all relevant task specification and data to process is formatted as a textual input context, and the model returns a generated text completion.
|
||||||
|
These input contexts can contain thousands of tokens, especially when language models are used to process long documents (e.g., legal or scientific documents, conversation histories, etc.) or when language models are augmented with external information (e.g., relevant documents from a search engine, database query results, etc; Petroni et al., 2020; Ram et al., 2023; Shi et al., 2023; Mallen et al., 2023; Schick et al., 2023, inter alia).
|
||||||
|
Handling these use-cases requires language models to successfully operate over long sequences.
|
||||||
|
Existing language models are generally implemented with Transformers (Vaswani et al., 2017), which require memory and compute that increases quadratically in sequence length.
|
||||||
|
As a result, Transformer language models were often trained with relatively small context windows (between 512-2048 tokens).
|
||||||
|
Recent improvements in hardware (e.g., faster GPUs with more memory) and algorithms (Dai et al., 2019; Dao et al., 2022; Poli et al., 2023; Rubin and Berant, 2023, inter alia) have resulted in language models with larger context windows (e.g., 4096, 32K, and even 100K tokens), but it remains unclear how these extended-context language models make use of their input contexts when performing downstream tasks.
|
||||||
|
We empirically investigate this question via controlled experiments with a variety of state-of-the-art open (MPT-30B-Instruct, LongChat-13B (16K)) and closed (OpenAI’s GPT-3.5-Turbo and Anthropic’s Claude-1.3) language models in settings that require accessing and using information within an input context.
|
||||||
|
In particular, our experiments make controlled changes to the input context size and the position of the relevant information within the input context and study their effects on language model performance.
|
||||||
|
If language models can robustly use information within long input contexts, then their performance should be minimally affected by the position of the relevant information in the input context.
|
||||||
|
We first experiment with multi-document question answering, which requires models to reason over provided documents to find relevant information and use it to answer a given question; this task mimics the retrieval-augmented generation setup underlying many commercial generative search and question answering applications (e.g., Bing Chat).
|
||||||
|
In this setting, we control (i) the input context length by changing the number of documents in the input context (akin to retrieving more or less documents in retrieval-augmented generation), and (ii) control the position of the relevant information within the input context by changing the order of the documents to place the relevant document at the beginning, middle or end of the context.
|
||||||
|
We find that changing the position of relevant information in the input context can substantially affect model performance, indicating that current language models do not robustly access and use information in long input contexts.
|
||||||
|
Furthermore, we observe a distinctive U-shaped performance curve (Figure 1); language model performance is highest when relevant information occurs at the very beginning (primacy bias) or end of its input context (recency bias), and performance significantly degrades when models must access and use information in the middle of their input context (§2.3).
|
||||||
|
For example, when relevant information is placed in the middle of its input context, GPT-3.5-Turbo’s performance on the multi-document question task is lower than its performance when predicting without any documents (i.e., the closed-book setting; 56.1%).
|
||||||
|
Furthermore, we find that models often have identical performance to their extended-context counterparts, indicating that extended-context models are not necessarily better at using their input context (§2.3).
|
||||||
|
Given that language models struggle to retrieve and use relevant information in the multi-document question answering task, to what extent can language models even retrieve from their input contexts? We study this question with a synthetic key-value retrieval task, which is designed to be a minimal testbed for the basic ability to retrieve matching tokens from the input context. In this task, models are given a collection of JSON-formatted key-value pairs and must return the value associated with a specific key. Similar to the multi-document QA task, the key-value retrieval task admits controlled changes to the input context length (adding more key-value pairs) and the position of relevant information.
|
||||||
|
Although some models perform the synthetic key-value retrieval task perfectly, other models struggle to simply retrieve matching tokens that occur in the middle of their input context and continue to exhibit a U-shaped performance curve.
|
||||||
|
To better understand why language models struggle to robustly access and use information in their input contexts, we study the role of model architecture (decoder-only vs. encoder-decoder), query-aware contextualization, and instruction fine-tuning (§4). We find that:
|
||||||
|
•
|
||||||
|
Encoder-decoder models are relatively robust to changes in the position of relevant information within their input context, but only when evaluated on sequences within its training-time sequence length. When evaluated on sequences longer than those seen during training, we observe a U-shaped performance curve (§4.1).
|
||||||
|
•
|
||||||
|
Query-aware contextualization (placing the query before and after the documents or key-value pairs) enables near-perfect performance on the synthetic key-value task, but minimally changes trends in multi-document QA (§4.2).
|
||||||
|
•
|
||||||
|
Even base language models (i.e., without instruction fine-tuning) show a U-shaped performance curve as we vary the position of relevant information in the input context.
|
||||||
|
Our results indicate that prompting language models with longer input contexts is a trade-off—providing the language model with more information may help it perform the downstream task, but it also increases the amount of content that the model must reason over, potentially decreasing accuracy.
|
||||||
|
To better understand this trade-off in practice, we perform a case study with retriever-reader models on open-domain question answering (§5). In contrast to our controlled multi-document QA task, where the context always contains exactly one document that answers the question, none or many of the top kk documents may contain the answer in the open-domain QA setting.
|
||||||
|
When retrieving from Wikipedia to answer queries from NaturalQuestions-Open, we find that model performance saturates long before retriever recall saturates, indicating that current models fail to effectively use additional retrieved documents—using 50 documents instead of 20 retrieved documents only marginally improves performance (∼\sim1.5% for GPT-3.5-Turbo and ∼\sim1% for claude-1.3).
|
||||||
|
Our analysis provides a better understanding of how language models use their input context and introduces new evaluation protocols for future long-context models; to claim that a language model can robustly use information within long input contexts, it is necessary to show that its performance is minimally affected by the position of the relevant information in the input context (e.g., minimal difference in best- and worst-case performance).
|
||||||
|
To facilitate further work on understanding and improving how language models use their input context, we release our code and evaluation data.11
|
||||||
|
1
|
||||||
|
nelsonliu.me/papers/lost-in-the-middle
|
||||||
|
Figure 2: Example of the multi-document question answering task, with an input context and the desired model answer. The document containing the answer is bolded within the input context here for clarity.
|
||||||
|
Figure 3: Modulating the position of relevant information within the input context for the multi-document question answering example presented in Figure 2. Re-ordering the documents in the input context does not affect the desired output.
|
||||||
|
Figure 4: Modulating the input context length of the multi-document question answering example presented in Figure 2. Adding documents that do not contain the answer increases the length of the input context, but does not affect the desired output.
|
||||||
|
2 Multi-Document Question Answering
|
||||||
|
Our goal is to better understand how language models use their input context.
|
||||||
|
To this end, we analyze model performance on multi-document question answering, which requires models to find relevant information within an input context and use it to answer the question.
|
||||||
|
In particular, we make controlled changes to the length of the input context and the position of the relevant information and measure changes in task performance.
|
||||||
|
2.1 Experimental Setup
|
||||||
|
In the multi-document question answering task, the model inputs are (i) a question to answer and (ii) kk documents (e.g., passages from Wikipedia), where exactly one of the documents contains the answer to the question and k−1k-1 “distractor” documents do not. This task requires the model to access the document that contains the answer within its input context and use it to answer the question.
|
||||||
|
Figure 2 presents an example.
|
||||||
|
Figure 5: The effect of changing the position of relevant information (document containing the answer) on multi-document question answering performance. Lower positions are closer to the start of the input context. Performance is highest when relevant information occurs at the very start or end of the context, and rapidly degrades when models must reason over information in the middle of their input context.
|
||||||
|
We instantiate this task with data from NaturalQuestions-Open (Lee et al., 2019; Kwiatkowski et al., 2019), which contains historical queries issued to the Google search engine, coupled with human-annotated answers extracted from Wikipedia.
|
||||||
|
In particular, we take the 2655 queries where the annotated long answer is a paragraph (as opposed to a list or a table).
|
||||||
|
We use passages (chunks of at most 100 tokens) from Wikipedia as documents within our input contexts.
|
||||||
|
For each of the queries, we need a document that contains the answer and k−1k-1 distractor documents that do not contain the answer.
|
||||||
|
To obtain a document that answers the question, we use the Wikipedia paragraph that contains the answer from the NaturalQuestions annotations.
|
||||||
|
To collect k−1k-1 distractor documents that do not contain the answer, we use a retrieval system (Contriever, fine-tuned on MS-MARCO; Izacard et al., 2021) to retrieve the k−1k-1 Wikipedia chunks that are most relevant to the query and do not contain any of the NaturalQuestions-annotated answers.22
|
||||||
|
2
|
||||||
|
Ambiguity in NaturalQuestions-Open means that a small number of distractor passages may contain a reasonable answer. We additionally run experiments on subset of unambiguous questions, finding similar results and conclusions; see Appendix A.33
|
||||||
|
3
|
||||||
|
We also explored using random documents as distractors, see Appendix B for more details.
|
||||||
|
In the input context, the distractor documents are presented in order of decreasing relevance.44
|
||||||
|
4
|
||||||
|
Since there might be a prior over “search results” appearing in ranked order, we explored randomly ordering the k−1k-1 distractor documents and mentioning that the documents are randomly ordered in the task description, but found the same trends. See Appendix C for more details.
|
||||||
|
To modulate the position of relevant information within the input context, we adjust the order of the documents to change the position of the document that contains the answer (Figure 3).
|
||||||
|
To modulate the input context length in this task, we increase or decrease the number of retrieved documents that do not contain the answer (Figure 4).
|
||||||
|
Following Kandpal et al. (2022) and Mallen et al. (2023), we use accuracy as our primary evaluation metric, judging whether any of the correct answers (as taken from the NaturalQuestions annotations) appear in the predicted output.
|
||||||
|
Our experimental setup is similar to the needle-in-a-haystack experiments of Ivgi et al. (2023), who compare question answering performance when the relevant paragraph is placed (i) at the beginning of the input or (ii) a random position within the input. They find that encoder-decoder models have significantly higher performance when relevant information is placed at the start of the input context. In contrast, we study finer-grained changes in the position of relevant information.
|
||||||
|
2.2 Models
|
||||||
|
We analyze several state-of-the-art open and closed language models. We use greedy decoding when generating outputs and leave exploration of other decoding methods to future work. We use a standard set of prompts for each model (Figure 2).
|
||||||
|
Open models.
|
||||||
|
We experiment with MPT-30B-Instruct, which has a maximum context length of 8192 tokens. The model was initially pre-trained on 1 trillion tokens using 2048-token sequences, followed by an additional sequence length adaptation pre-training phase on 50 billion tokens using 8192-token sequences. MPT-30B-Instruct uses ALiBi (Press et al., 2022) to represent positional information.
|
||||||
|
We also evaluate LongChat-13B (16K) (Li et al., 2023), which extends the LLaMA-13B (Touvron et al., 2023a) context window from 2048 to 16384 tokens by using condensed rotary positional embeddings before fine-tuning with 16384-token sequences.
|
||||||
|
Closed models.
|
||||||
|
We use the OpenAI API to experiment with GPT-3.5-Turbo and GPT-3.5-Turbo (16K).55
|
||||||
|
5
|
||||||
|
We use the 0613 OpenAI model versions.
|
||||||
|
GPT-3.5-Turbo has a maximum context length of 4K tokens, and GPT-3.5-Turbo (16K) is a version with an extended maximum context length of 16K tokens.
|
||||||
|
We evaluate Claude-1.3 and Claude-1.3 (100K) with the Anthropic API; Claude-1.3 has a maximum context length of 8K tokens, and Claude-1.3 (100K) has an extended context length of 100K tokens.
|
||||||
|
66
|
||||||
|
6
|
||||||
|
We also evaluate GPT-4 (8K) on a subset of multi-document QA experiments, finding similar results and trends as other models (though GPT-4 has higher absolute performance). Evaluating GPT-4 on the full multi-document QA and key-value retrieval experiments would cost upwards of $6000. See Appendix D for GPT-4 results and discussion.
|
||||||
|
2.3 Results and Discussion
|
||||||
|
We experiment with input contexts containing 10, 20, and 30 total documents.
|
||||||
|
Figure 5 presents multi-document question answering performance when varying the position of relevant information within the input context.
|
||||||
|
To contextualize model performance, we also evaluate on the closed-book and oracle settings (Table 1).
|
||||||
|
In the closed-book setting, models are not given any documents in their input context, and must rely on their parametric memory to generate the correct answer.
|
||||||
|
On the other hand, in the oracle setting, language models are given the single document that contains the answer and must use it to answer the question.
|
||||||
|
Model
|
||||||
|
Closed-Book
|
||||||
|
Oracle
|
||||||
|
LongChat-13B (16K)
|
||||||
|
35.0%
|
||||||
|
83.4%
|
||||||
|
MPT-30B-Instruct
|
||||||
|
31.5%
|
||||||
|
81.9%
|
||||||
|
GPT-3.5-Turbo
|
||||||
|
56.1%
|
||||||
|
88.3%
|
||||||
|
GPT-3.5-Turbo (16K)
|
||||||
|
56.0%
|
||||||
|
88.6%
|
||||||
|
Claude-1.3
|
||||||
|
48.3%
|
||||||
|
76.1%
|
||||||
|
Claude-1.3 (100K)
|
||||||
|
48.2%
|
||||||
|
76.4%
|
||||||
|
Table 1: Closed-book and oracle accuracy of language models on the multi-document question answering task.
|
||||||
|
Model performance is highest when relevant information occurs at the beginning or end of its input context.
|
||||||
|
As illustrated in Figure 5, changing the position of relevant information in the input context leads to substantial decreases in model performance. In particular, we see a distinctive U-shaped performance curve—models are often much better at using relevant information that occurs at the very beginning (primacy bias) and very end of contexts (recency bias), and suffer degraded performance when forced to use information within the middle of its input context. For example, GPT-3.5-Turbo’s multi-document QA performance can drop by more than 20%—in the worst case, performance in 20- and 30-document settings is lower than performance without any input documents (i.e., closed-book performance; 56.1%).
|
||||||
|
These results indicate that current models cannot effectively reason over their entire context window when prompted for downstream tasks.
|
||||||
|
Figure 6: Example of the key-value retrieval task, with an input context and the desired model output. Given a key, the goal is to return the associated value. All keys and values are 128-bit UUIDs. The relevant key-value pair for answering the query is bolded here within the input context for clarity.
|
||||||
|
Extended-context models are not necessarily better at using input context.
|
||||||
|
When the input context fits in the context window of both a model and its extended-context counterpart, we see that performance between them is nearly identical. For example, the 10- and 20-document settings both fit in the context window of GPT-3.5-Turbo and GPT-3.5-Turbo (16K), and we observe that their performance as a function of position of relative information is nearly superimposed (solid purple and dashed brown series in Figure 5). These results indicate that extended-context models are not necessarily better than their non-extended counterparts at using their input context.
|
||||||
|
3 How Well Can Language Models Retrieve From Input Contexts?
|
||||||
|
Given that language models struggle to retrieve and use information from the middle of their input contexts in the multi-document question answering task, to what extent can they simply retrieve from input contexts?
|
||||||
|
We study this question with a synthetic key-value retrieval task, which is designed to provide a minimal testbed for the basic ability to retrieve matching tokens from an input context.
|
||||||
|
Figure 7: The effect of changing the input context length and the position of relevant information on key-value retrieval performance. Lower positions are closer to the start of the input context. Although some models show perfect accuracy on this synthetic task (e.g., Claude-1.3 and Claude-1.3 (100K)), we see again that performance is often highest when relevant information is occurs at the very start or end of the context, and rapidly degrades when models must retrieve from the middle of the input context.
|
||||||
|
3.1 Experimental Setup
|
||||||
|
In our synthetic key-value retrieval task, the inputs are (i) a string-serialized JSON object with kk key-value pairs, where each of the keys and values are unique, randomly-generated UUIDs and (ii) a key within the aforementioned JSON object.
|
||||||
|
The goal is to return the value associated with the specified key.
|
||||||
|
Thus, each JSON object contains one relevant key-value pair (where the value is to be returned), and k−1k-1 irrelevant “distractor” key-value pairs.
|
||||||
|
Figure 6 provides an example input context and its corresponding desired output.
|
||||||
|
We again measure accuracy by evaluating whether the correct value appears in the predicted output.
|
||||||
|
Our synthetic key-value retrieval task shares similar goals with the Little Retrieval Test of Papailiopoulos et al. (2023) and the fine-grained line retrieval task of Li et al. (2023), but we explicitly seek to distill and simplify the task by removing as much natural language semantics as possible (using random UUIDs instead), since language features may present potential confounders.
|
||||||
|
For example, Transformer language models may have varying sensitivity to different linguistic features in their input (O’Connor and Andreas, 2021).
|
||||||
|
To modulate the position of relevant information within the input context, we change the position of the key to retrieve within the serialized JSON object.
|
||||||
|
To modulate the input context length, we change the number of input JSON key-value pairs kk by adding or removing random keys, changing the number of distractor key-value pairs.
|
||||||
|
3.2 Results and Discussion
|
||||||
|
We experiment with input contexts containing 75, 140, and 300 key-value pairs (500 examples each). We use the same set of models as the multi-document question answering experiments, see §2.2 for more details.
|
||||||
|
Figure 7 presents key-value retrieval performance. Claude-1.3 and Claude-1.3 (100K) do nearly perfectly on all evaluated input context lengths, but other models struggle, especially when contexts have 140 or 300 key-value pairs—although the synthetic key-value retrieval task only requires identifying exact match within the input context, not all models achieve high performance.
|
||||||
|
Similar to our multi-document QA results, GPT-3.5-Turbo, GPT-3.5-Turbo (16K), and MPT-30B-Instruct have the lowest performance when they must access key-value pairs in the middle of their input context.
|
||||||
|
LongChat-13B (16K) exhibits a different trend in the 140 key-value setting; we qualitatively observe that when relevant information is placed at the start of the input context, LongChat-13B (16K) tends to generate code to retrieve the key, rather than outputting the value directly.
|
||||||
|
4 Why Are Language Models Not Robust to Changes in the Position of Relevant Information?
|
||||||
|
Our multi-document question answering and key-value retrieval results show that language models struggle to robustly access and use information in long input contexts, since performance degrades significantly when changing the position of relevant information. To better understand why, we perform some preliminary investigations into the role of model architecture (decoder-only vs. encoder-decoder), query-aware contextualization, and instruction fine-tuning.
|
||||||
|
Figure 8: When encoder-decoder models (Flan-UL2 and Flan-T5-XXL) evaluated on sequences that are shorter than their encoder’s training-time maximum sequence length (2048 and 512 tokens, respectively), they are relatively robust to changes in the position of relevant information within their input context (left subplot).
|
||||||
|
In contrast, when these models are evaluated on sequences longer than those seen during training (center and right subplots), we observe a U-shaped performance curve—performance is higher when relevant information occurs at the beginning or end of the input context, as opposed to the middle of the input context.
|
||||||
|
4.1 Effect of Model Architecture
|
||||||
|
The open models we evaluated are all decoder-only models—at each timestep, they may only attend to prior tokens.
|
||||||
|
To better understand the potential effects of model architecture on how language model use context, we compare decoder-only and encoder-decoder language models.
|
||||||
|
We experiment with Flan-T5-XXL (Raffel et al., 2020; Chung et al., 2022) and Flan-UL2 (Tay et al., 2023). Flan-T5-XXL is trained with a sequences of 512 tokens (encoder and decoder). Flan-UL2 is initially trained with sequences of 512 tokens (encoder and decoder), but is then pre-trained for an extra 100K steps with 1024 tokens (encoder and decoder) before instruction fine-tuning on sequences with 2048 tokens in the encoder and 512 tokens in the decoder.
|
||||||
|
However, since these models use relative positional embeddings, they can (in principle) extrapolate beyond these maximum context lengths; Shaham et al. (2023) find that both models can perform well with sequences of up to 8K tokens.
|
||||||
|
Figure 8 compares the performance of decoder-only and encoder-decoder models. When Flan-UL2 is evaluated on sequences within its 2048-token training-time context window (Figure 8; left subplot), its performance is relatively robust to changes in the position of relevant information within the input context (1.9% absolute difference between best- and worst-case performance). When evaluated on settings with sequences longer than 2048 tokens (Figure 8; center and right), Flan-UL2 performance begins to degrade when relevant information is placed in the middle.
|
||||||
|
Flan-T5-XXL shows a similar trend, where longer input contexts result in a greater performance degradation when placing relevant information in the middle of the input context.
|
||||||
|
We hypothesize that encoder-decoder models may make better use of their context windows because their bidirectional encoder allows processing each document in the context of future documents, potentially improving relative importance estimation between documents.
|
||||||
|
Figure 9: Query-aware contextualization (placing the query before and after the documents) does not substantially improve robustness of language models to changing the position of relevant information in multi-document QA; performance slightly increases when relevant information occurs at the very beginning, but otherwise slightly decreases.
|
||||||
|
4.2 Effect of Query-Aware Contextualization
|
||||||
|
Our multi-document QA and key-value retrieval experiments place the query (i.e., question to answer or key to retrieve) after the data to process (i.e., the documents or the key-value pairs). As a result, decoder-only models cannot attend to query tokens when contextualizing documents or key-value pairs, since the query only appears at the end of the prompt and decoder-only models can only attend to prior tokens at each timestep. In contrast, encoder-decoder models (which seem more robust to changes in the position of relevant information; §4.1) use a bidirectional encoder to contextualize input contexts—can we use this observation to improve decoder-only models by placing the query before and after the data, enabling query-aware contextualization of documents (or key-value pairs)?
|
||||||
|
We find that query-aware contextualization dramatically improves performance on the key-value retrieval task—all models achieve near-perfect performance on the 75, 140, and 300 key-value pair settings. For example, GPT-3.5-Turbo (16K) with query-aware contextualization achieves perfect performance when evaluated with 300 key-value pairs.
|
||||||
|
In contrast, without query-aware contextualization, the worst-case performance is 45.6% (Figure 7).
|
||||||
|
Despite the significant impact on key-value retrieval performance, query-aware contextualization minimally affects performance trends in the multi-document question answering task (Figure 9); it slightly improves performance when the relevant information is located at the very beginning of the input context, but slightly decreases performance in other settings.
|
||||||
|
4.3 Effect of Instruction Fine-Tuning
|
||||||
|
The models we evaluated are all instruction fine-tuned—after their initial pre-training, they undergo supervised fine-tuning on a dataset of instructions and responses.
|
||||||
|
The task specification and/or instruction is commonly placed at the beginning of the input context in supervised instruction fine-tuning data, which might lead instruction fine-tuned language models to place more weight on the start of the input context.
|
||||||
|
To better understand the potential effects of instruction fine-tuning on how language models use long input contexts, we compare the multi-document question answering performance of MPT-30B-Instruct against its base model (i.e., before instruction fine-tuning) MPT-30B. We use the same experimental setup as §2.
|
||||||
|
Figure 10: Multi-document QA performance of MPT-30B-Instruct compared against its base model (i.e., before instruction fine-tuning) MPT-30B.
|
||||||
|
Both models have a U-shaped performance curve, where performance is much higher when relevant information occurs at the start or end of the input context, indicating that the instruction fine-tuning process itself is not necessarily responsible for these performance trends.
|
||||||
|
Figure 10 compares the multi-document QA performance of MPT-30B and MPT-30B-Instruct as a function of the position of the relevant information in the input context. Surprisingly, we see that both MPT-30B and MPT-30B-Instruct exhibit a U-shaped performance curve, where performance is highest when relevant information occurs at the very beginning or very end of the context. Although the absolute performance of MPT-30B-Instruct is uniformly higher than that of MPT-30B, their overall performance trends are similar. We also observe that instruction fine-tuning slightly reduces the worst-case performance disparity from nearly 10% between the base model best- and worst-case performance to around 4%.
|
||||||
|
These observations complement prior work, which found that non-instruction fine-tuned language models are biased towards recent tokens (i.e., the end of the input context; Khandelwal et al., 2018; Press et al., 2021).
|
||||||
|
This recency bias has been observed in past work when evaluating models on next-word prediction of contiguous text, a setting where language models minimally benefit from long-range information (Sun et al., 2021).
|
||||||
|
In contrast, our results show that language models are capable of using longer-range information (i.e., the beginning of the input context) when prompted with instruction-formatted data. We hypothesize that non-instruction fine-tuned language models learn to use these long contexts from similarly-formatted data that may occur in Internet text seen during pre-training, e.g., StackOverflow questions and answers.
|
||||||
|
To better understand the effect of additional fine-tuning and model scale, we also experimented with Llama-2 models of varying sizes (7B, 13B, and 70B) with and without additional supervised fine-tuning and reinforcement learning from human feedback (Appendix E). We find that the U-shaped performance curve only appears in sufficiently large language models (with or without additional fine-tuning)—the 7B Llama-2 models are solely recency biased, while the 13B and 70B models exhibit a U-shaped performance curve. In addition, we see that the Llama-2 supervised fine-tuning and reinforcement learning from human feedback procedure slightly mitigates the positional bias in smaller models (13B, akin to trends shown when comparing MPT-30B and MPT-30B-Instruct), but minimally affects trends on larger models (70B).
|
||||||
|
5 Is More Context Is Always Better? A Case Study With Open-Domain QA
|
||||||
|
Our results indicate that prompting language models with longer input contexts is a trade-off—providing the language model with more information may help it perform the downstream task, but it also increases the amount of content that the model must reason over, potentially decreasing accuracy. Even if a language model can take in 16K tokens, is it actually beneficial to provide 16K tokens of context? The answer to this question is ultimately downstream task-specific since it depends on the marginal value of the added context and the model’s ability to effectively use long input contexts, but we perform a case study with open-domain question answering on NaturalQuestions-Open to better understand this trade-off in existing language models.
|
||||||
|
We use language models in a standard retriever-reader setup. A retrieval system (Contriever, fine-tuned on MS-MARCO) takes an input query from NaturalQuestions-Open and returns the kk documents from Wikipedia with the highest relevance score. To condition language models on these retrieved documents, we simply include them in the prompt. We evaluate retriever recall and reader accuracy (whether any of the annotated answers appear in the predicted output) as a function of the number of retrieved documents kk. We use a subset of NaturalQuestions-Open where the long answer is a paragraph (as opposed to a table or a list).
|
||||||
|
Figure 11 presents retriever recall and open-domain QA results. We see that reader model performance saturates long before retriever performance saturates, indicating that readers are not effectively using the extra context. Using more than 20 retrieved documents only marginally improves reader performance (∼\sim1.5% for GPT-3.5-Turbo and ∼\sim1% for Claude-1.3), while significantly increasing the input context length (and thus latency and cost).
|
||||||
|
These results, coupled with the observation that models are often better at retrieving and using information at the start or end of the input contexts, suggest that effective reranking of retrieved documents (pushing relevant information closer to the start of the input context) or ranked list truncation (retrieving fewer documents when appropriate; Arampatzis et al., 2009) may be promising directions for improving how language-model-based readers use retrieved context.
|
||||||
|
Figure 11: Retriever recall and model performance as a function of the number of retrieved documents. Model performance saturates long before retriever recall, indicating that the models have difficulty making use of the extra retrieved documents.
|
||||||
|
6 Related Work
|
||||||
|
6.1 Long-Context Language Models
|
||||||
|
There is much prior work in designing performant language models with cheaper scaling than Transformers in the context length.
|
||||||
|
Many lines of work pursue Transformer variants with attention modifications like recurrence Dai et al. (2019), factorizing attention into computationally less intensive approximations Beltagy et al. (2020); Zaheer et al. (2020), or low-rank approximations Wang et al. (2020); Peng et al. (2021).
|
||||||
|
Dao et al. (2022) instead provide a faster exact attention by a carefully-crafted IO-aware CUDA kernel.
|
||||||
|
Separately, there are attempts to do away with attention entirely to remove quadratic sequence length complexity, often through convolution and/or linear RNNs, e.g., in RWKV Peng (2023), S4 Gu et al. (2022), or Hyena Poli et al. (2023).
|
||||||
|
Many prior efforts evaluate perplexity on a diverse web corpus as a proxy for the ability to process long contexts; this work shows that precise knowledge access on long contexts may be an added challenge.
|
||||||
|
6.2 How Do Language Models Use Context?
|
||||||
|
The pioneering work of Khandelwal et al. (2018) showed that small LSTM language models make increasingly coarse use of longer-term context; Sankar et al. (2019) found similar results in dialogue models.
|
||||||
|
In a similar vein, Daniluk et al. (2017) find that attentive LSTM language models tend to mainly use recent history.
|
||||||
|
Petroni et al. (2020) were among the first to demonstrate the potential of combining context from an information retrieval system with a pretrained language models for unsupervised question answering.
|
||||||
|
O’Connor and Andreas (2021) found that many information-destroying operations had marginal effects on Transformer LMs’ predictions.
|
||||||
|
Krishna et al. (2022) found that long-context neural generation in modestly-sized Transformer language models degenerates because models fail to properly condition on long context.
|
||||||
|
Finally, studying long-context models, Sun et al. (2021) found that longer contexts improves prediction of only a few tokens, an empirical finding consistent with the theory of Sharan et al. (2018), who showed that sequence distributions with bounded mutual information necessarily lead to marginal average prediction benefits from increasingly long context.
|
||||||
|
Qin et al. (2023) analyze how efficient Transformers perform on a variety of long-context downstream NLP tasks, finding that long-context transformers are recency-biased and do not effectively use long-range context.
|
||||||
|
6.3 The Serial-Position Effect
|
||||||
|
The U-shaped curve we observe in this work has a connection in psychology known as the serial-position effect Ebbinghaus (1913); Murdock Jr (1962), that states that in free-association recall of elements from a list, humans tend to best remember the first and last elements of the list.
|
||||||
|
The serial-position effect plays a role in understanding how humans develop short- and long-term memory.
|
||||||
|
Observing a serial-position-like effect in language models is perhaps surprising, since the self-attention mechanisms underlying Transformer language models is technically equally capable of retrieving any token from their contexts.
|
||||||
|
7 Conclusion
|
||||||
|
We empirically study how language models use long input contexts via a series of controlled experiments.
|
||||||
|
We show that language model performance degrades significantly when changing the position of relevant information, indicating that models struggle to robustly access and use information in long input contexts.
|
||||||
|
In particular, performance is often lowest when models must use information in the middle of long input contexts.
|
||||||
|
We conduct a preliminary investigation of the role of (i) model architecture, (ii) query-aware contextualization, and (iii) instruction fine-tuning to better understand how they affect how language models use context.
|
||||||
|
Finally, we conclude with a practical case study of open-domain question answering, finding that the performance of language model readers saturates far before retriever recall.
|
||||||
|
Our results and analysis provide a better understanding of how language models use their input context and provides new evaluation protocols for future long-context models.
|
||||||
|
Acknowledgments
|
||||||
|
We would like to thank Luke Zettlemoyer, who served as our TACL action editor, and the the anonymous reviewers for their comments and feedback.
|
||||||
|
We also thank Claudiu Leoveanu-Condrei, Megan Leszczynski, Dmytro Okhonko, Maithra Raghu, Eric Wallace and Sang Michael Xie for feedback and discussions that helped improve this work.
|
||||||
|
Further, we are grateful to Sewon Min for her help with the AmbigQA dataset.
|
||||||
|
This work was supported by the Stanford Center for Research on Foundation Models (CRFM), by OpenAI via an API credits grant to the Stanford CRFM, and by Anthropic via the Claude academic access program.
|
||||||
|
References
|
||||||
|
Arampatzis et al. (2009)
|
||||||
|
Avi Arampatzis, Jaap Kamps, and Stephen Robertson. 2009.
|
||||||
|
Where to stop reading a ranked list? threshold optimization using truncated score distributions.
|
||||||
|
In Proc. of SIGIR.
|
||||||
|
Beltagy et al. (2020)
|
||||||
|
Iz Beltagy, Matthew E. Peters, and Arman Cohan. 2020.
|
||||||
|
Longformer: The long-document transformer.
|
||||||
|
ArXiv:2004.05150.
|
||||||
|
Chung et al. (2022)
|
||||||
|
Hyung Won Chung, Le Hou, Shayne Longpre, Barret Zoph, Yi Tay, William Fedus, Yunxuan Li, Xuezhi Wang, Mostafa Dehghani, Siddhartha Brahma, Albert Webson, Shixiang Shane Gu, Zhuyun Dai, Mirac Suzgun, Xinyun Chen, Aakanksha Chowdhery, Alex Castro-Ros, Marie Pellat, Kevin Robinson, Dasha Valter, Sharan Narang, Gaurav Mishra, Adams Yu, Vincent Zhao, Yanping Huang, Andrew Dai, Hongkun Yu, Slav Petrov, Ed H. Chi, Jeff Dean, Jacob Devlin, Adam Roberts, Denny Zhou, Quoc V. Le, and Jason Wei. 2022.
|
||||||
|
Scaling instruction-finetuned language models.
|
||||||
|
ArXiv:2210.11416.
|
||||||
|
Dai et al. (2019)
|
||||||
|
Zihang Dai, Zhilin Yang, Yiming Yang, Jaime Carbonell, Quoc Le, and Ruslan Salakhutdinov. 2019.
|
||||||
|
Transformer-XL: Attentive language models beyond a fixed-length context.
|
||||||
|
In Proc. of ACL.
|
||||||
|
Daniluk et al. (2017)
|
||||||
|
Michał Daniluk, Tim Rocktäschel, Johannes Welbl, and Sebastian Riedel. 2017.
|
||||||
|
Frustratingly short attention spans in neural language modeling.
|
||||||
|
In Proc. of ICLR.
|
||||||
|
Dao et al. (2022)
|
||||||
|
Tri Dao, Daniel Y. Fu, Stefano Ermon, Atri Rudra, and Christopher Ré. 2022.
|
||||||
|
FlashAttention: Fast and memory-efficient exact attention with IO-awareness.
|
||||||
|
ArXiv:2205.14135.
|
||||||
|
Ebbinghaus (1913)
|
||||||
|
Hermann Ebbinghaus. 1913.
|
||||||
|
Memory: A contribution to experimental psychology.
|
||||||
|
H. A. Ruger & C. E. Bussenius, Trans.
|
||||||
|
Gu et al. (2022)
|
||||||
|
Albert Gu, Karan Goel, and Christopher Ré. 2022.
|
||||||
|
Efficiently modeling long sequences with structured state spaces.
|
||||||
|
In Proc. of ICLR.
|
||||||
|
Ivgi et al. (2023)
|
||||||
|
Maor Ivgi, Uri Shaham, and Jonathan Berant. 2023.
|
||||||
|
Efficient long-text understanding with short-text models.
|
||||||
|
Transactions of the Association for Computational Linguistics, 11:284–299.
|
||||||
|
Izacard et al. (2021)
|
||||||
|
Gautier Izacard, Mathilde Caron, Lucas Hosseini, Sebastian Riedel, Piotr Bojanowski, Armand Joulin, and Edouard Grave. 2021.
|
||||||
|
Unsupervised dense information retrieval with contrastive learning.
|
||||||
|
ArXiv:2112.09118.
|
||||||
|
Izacard and Grave (2021)
|
||||||
|
Gautier Izacard and Edouard Grave. 2021.
|
||||||
|
Leveraging passage retrieval with generative models for open domain question answering.
|
||||||
|
In Proc. of EACL.
|
||||||
|
Kandpal et al. (2022)
|
||||||
|
Nikhil Kandpal, Haikang Deng, Adam Roberts, Eric Wallace, and Colin Raffel. 2022.
|
||||||
|
Large language models struggle to learn long-tail knowledge.
|
||||||
|
ArXiv:2211.08411.
|
||||||
|
Khandelwal et al. (2018)
|
||||||
|
Urvashi Khandelwal, He He, Peng Qi, and Dan Jurafsky. 2018.
|
||||||
|
Sharp nearby, fuzzy far away: How neural language models use context.
|
||||||
|
In Proc. of ACL.
|
||||||
|
Krishna et al. (2022)
|
||||||
|
Kalpesh Krishna, Yapei Chang, John Wieting, and Mohit Iyyer. 2022.
|
||||||
|
RankGen: Improving text generation with large ranking models.
|
||||||
|
In Proc. of EMNLP.
|
||||||
|
Kwiatkowski et al. (2019)
|
||||||
|
Tom Kwiatkowski, Jennimaria Palomaki, Olivia Redfield, Michael Collins, Ankur Parikh, Chris Alberti, Danielle Epstein, Illia Polosukhin, Jacob Devlin, Kenton Lee, Kristina Toutanova, Llion Jones, Matthew Kelcey, Ming-Wei Chang, Andrew M. Dai, Jakob Uszkoreit, Quoc Le, and Slav Petrov. 2019.
|
||||||
|
Natural Questions: A benchmark for question answering research.
|
||||||
|
Transactions of the Association for Computational Linguistics, 7:452–466.
|
||||||
|
Lee et al. (2019)
|
||||||
|
Kenton Lee, Ming-Wei Chang, and Kristina Toutanova. 2019.
|
||||||
|
Latent retrieval for weakly supervised open domain question answering.
|
||||||
|
In Proc. of ACL.
|
||||||
|
Lee et al. (2022)
|
||||||
|
Mina Lee, Percy Liang, and Qian Yang. 2022.
|
||||||
|
CoAuthor: Designing a human-AI collaborative writing dataset for exploring language model capabilities.
|
||||||
|
In Proc. of CHI.
|
||||||
|
Li et al. (2023)
|
||||||
|
Dacheng Li, Rulin Shao, Anze Xie, Ying Sheng, Lianmin Zheng, Joseph E. Gonzalez, Ion Stoica, Xuezhe Ma, , and Hao Zhang. 2023.
|
||||||
|
How long can open-source LLMs truly promise on context length?
|
||||||
|
Mallen et al. (2023)
|
||||||
|
Alex Mallen, Akari Asai, Victor Zhong, Rajarshi Das, Daniel Khashabi, and Hannaneh Hajishirzi. 2023.
|
||||||
|
When not to trust language models: Investigating effectiveness of parametric and non-parametric memories.
|
||||||
|
In Proc. of ACL.
|
||||||
|
Min et al. (2020)
|
||||||
|
Sewon Min, Julian Michael, Hannaneh Hajishirzi, and Luke Zettlemoyer. 2020.
|
||||||
|
AmbigQA: Answering ambiguous open-domain questions.
|
||||||
|
In Proc. of EMNLP.
|
||||||
|
Murdock Jr (1962)
|
||||||
|
Bennet B. Murdock Jr. 1962.
|
||||||
|
The serial position effect of free recall.
|
||||||
|
Journal of experimental psychology, 64(5):482.
|
||||||
|
O’Connor and Andreas (2021)
|
||||||
|
Joe O’Connor and Jacob Andreas. 2021.
|
||||||
|
What context features can Transformer language models use?
|
||||||
|
In Proc. of ACL.
|
||||||
|
Papailiopoulos et al. (2023)
|
||||||
|
Dimitris Papailiopoulos, Kangwook Lee, and Jy-yong Sohn. 2023.
|
||||||
|
A little retrieval test for large language models.
|
||||||
|
https://github.com/anadim/the-little-retrieval-test.
|
||||||
|
Peng (2023)
|
||||||
|
Bo Peng. 2023.
|
||||||
|
RWKV-LM.
|
||||||
|
https://github.com/BlinkDL/RWKV-LM.
|
||||||
|
Peng et al. (2021)
|
||||||
|
Hao Peng, Nikolaos Pappas, Dani Yogatama, Roy Schwartz, Noah Smith, and Lingpeng Kong. 2021.
|
||||||
|
Random feature attention.
|
||||||
|
In Proc. of ICLR.
|
||||||
|
Petroni et al. (2020)
|
||||||
|
Fabio Petroni, Patrick Lewis, Aleksandra Piktus, Tim Rocktäschel, Yuxiang Wu, Alexander H Miller, and Sebastian Riedel. 2020.
|
||||||
|
How context affects language models’ factual predictions.
|
||||||
|
In Proc. of AKBC.
|
||||||
|
Poli et al. (2023)
|
||||||
|
Michael Poli, Stefano Massaroli, Eric Nguyen, Daniel Y. Fu, Tri Dao, Stephen Baccus, Yoshua Bengio, Stefano Ermon, and Christopher Ré. 2023.
|
||||||
|
Hyena hierarchy: Towards larger convolutional language models.
|
||||||
|
In Proc. of ICML.
|
||||||
|
Press et al. (2021)
|
||||||
|
Ofir Press, Noah A. Smith, and Mike Lewis. 2021.
|
||||||
|
Shortformer: Better language modeling using shorter inputs.
|
||||||
|
In Proc. of ACL.
|
||||||
|
Press et al. (2022)
|
||||||
|
Ofir Press, Noah A. Smith, and Mike Lewis. 2022.
|
||||||
|
Train short, test long: Attention with linear biases enables input length extrapolation.
|
||||||
|
In Proc. of ICLR.
|
||||||
|
Qin et al. (2023)
|
||||||
|
Guanghui Qin, Yukun Feng, and Benjamin Van Durme. 2023.
|
||||||
|
The NLP task effectiveness of long-range transformers.
|
||||||
|
In Proc. of EACL.
|
||||||
|
Raffel et al. (2020)
|
||||||
|
Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, and Peter J. Liu. 2020.
|
||||||
|
Exploring the limits of transfer learning with a unified text-to-text Transformer.
|
||||||
|
Journal of Machine Learning Research, 21(140):1–67.
|
||||||
|
Ram et al. (2023)
|
||||||
|
Ori Ram, Yoav Levine, Itay Dalmedigos, Dor Muhlgay, Amnon Shashua, Kevin Leyton-Brown, and Yoav Shoham. 2023.
|
||||||
|
In-context retrieval-augmented language models.
|
||||||
|
ArXiv:2302.00083.
|
||||||
|
Rubin and Berant (2023)
|
||||||
|
Ohad Rubin and Jonathan Berant. 2023.
|
||||||
|
Long-range language modeling with self-retrieval.
|
||||||
|
ArXiv:2306.13421.
|
||||||
|
Sankar et al. (2019)
|
||||||
|
Chinnadhurai Sankar, Sandeep Subramanian, Chris Pal, Sarath Chandar, and Yoshua Bengio. 2019.
|
||||||
|
Do neural dialog systems use the conversation history effectively? an empirical study.
|
||||||
|
In Proc. of ACL.
|
||||||
|
Schick et al. (2023)
|
||||||
|
Timo Schick, Jane Dwivedi-Yu, Roberto Dessì, Roberta Raileanu, Maria Lomeli, Luke Zettlemoyer, Nicola Cancedda, and Thomas Scialom. 2023.
|
||||||
|
Toolformer: Language models can teach themselves to use tools.
|
||||||
|
Shaham et al. (2023)
|
||||||
|
Uri Shaham, Maor Ivgi, Avia Efrat, Jonathan Berant, and Omer Levy. 2023.
|
||||||
|
ZeroSCROLLS: A zero-shot benchmark for long text understanding.
|
||||||
|
ArXiv:2305.14196.
|
||||||
|
Sharan et al. (2018)
|
||||||
|
Vatsal Sharan, Sham Kakade, Percy Liang, and Gregory Valiant. 2018.
|
||||||
|
Prediction with a short memory.
|
||||||
|
In Proc. of STOC.
|
||||||
|
Shi et al. (2023)
|
||||||
|
Weijia Shi, Sewon Min, Michihiro Yasunaga, Minjoon Seo, Rich James, Mike Lewis, Luke Zettlemoyer, and Wen tau Yih. 2023.
|
||||||
|
REPLUG: Retrieval-augmented black-box language models.
|
||||||
|
ArXiv:2301.12652.
|
||||||
|
Shuster et al. (2022)
|
||||||
|
Kurt Shuster, Jing Xu, Mojtaba Komeili, Da Ju, Eric Michael Smith, Stephen Roller, Megan Ung, Moya Chen, Kushal Arora, Joshua Lane, Morteza Behrooz, William Ngan, Spencer Poff, Naman Goyal, Arthur Szlam, Y-Lan Boureau, Melanie Kambadur, and Jason Weston. 2022.
|
||||||
|
BlenderBot 3: a deployed conversational agent that continually learns to responsibly engage.
|
||||||
|
ArXiv:2208.03188.
|
||||||
|
Sun et al. (2021)
|
||||||
|
Simeng Sun, Kalpesh Krishna, Andrew Mattarella-Micke, and Mohit Iyyer. 2021.
|
||||||
|
Do long-range language models actually use long-range context?
|
||||||
|
In Proc. of EMNLP.
|
||||||
|
Tay et al. (2023)
|
||||||
|
Yi Tay, Mostafa Dehghani, Vinh Q. Tran, Xavier Garcia, Jason Wei, Xuezhi Wang, Hyung Won Chung, Siamak Shakeri, Dara Bahri, Tal Schuster, Huaixiu Steven Zheng, Denny Zhou, Neil Houlsby, and Donald Metzler. 2023.
|
||||||
|
UL2: Unifying language learning paradigms.
|
||||||
|
ArXiv:2205.05131.
|
||||||
|
Thoppilan et al. (2022)
|
||||||
|
Romal Thoppilan, Daniel De Freitas, Jamie Hall, Noam Shazeer, Apoorv Kulshreshtha, Heng-Tze Cheng, Alicia Jin, Taylor Bos, Leslie Baker, Yu Du, YaGuang Li, Hongrae Lee, Huaixiu Steven Zheng, Amin Ghafouri, Marcelo Menegali, Yanping Huang, Maxim Krikun, Dmitry Lepikhin, James Qin, Dehao Chen, Yuanzhong Xu, Zhifeng Chen, Adam Roberts, Maarten Bosma, Vincent Zhao, Yanqi Zhou, Chung-Ching Chang, Igor Krivokon, Will Rusch, Marc Pickett, Pranesh Srinivasan, Laichee Man, Kathleen Meier-Hellstern, Meredith Ringel Morris, Tulsee Doshi, Renelito Delos Santos, Toju Duke, Johnny Soraker, Ben Zevenbergen, Vinodkumar Prabhakaran, Mark Diaz, Ben Hutchinson, Kristen Olson, Alejandra Molina, Erin Hoffman-John, Josh Lee, Lora Aroyo, Ravi Rajakumar, Alena Butryna, Matthew Lamm, Viktoriya Kuzmina, Joe Fenton, Aaron Cohen, Rachel Bernstein, Ray Kurzweil, Blaise Aguera-Arcas, Claire Cui, Marian Croak, Ed Chi, and Quoc Le. 2022.
|
||||||
|
LaMDA: Language models for dialog applications.
|
||||||
|
ArXiv:2201.08239.
|
||||||
|
Touvron et al. (2023a)
|
||||||
|
Hugo Touvron, Thibaut Lavril, Gautier Izacard, Xavier Martinet, Marie-Anne Lachaux, Timothée Lacroix, Baptiste Rozière, Naman Goyal, Eric Hambro, Faisal Azhar, Aurelien Rodriguez, Armand Joulin, Edouard Grave, and Guillaume Lample. 2023a.
|
||||||
|
LLaMA: Open and efficient foundation language models.
|
||||||
|
ArXiv:2302.13971.
|
||||||
|
Touvron et al. (2023b)
|
||||||
|
Hugo Touvron, Louis Martin, Kevin Stone, Peter Albert, Amjad Almahairi, Yasmine Babaei, Nikolay Bashlykov, Soumya Batra, Prajjwal Bhargava, Shruti Bhosale, Dan Bikel, Lukas Blecher, Cristian Canton Ferrer, Moya Chen, Guillem Cucurull, David Esiobu, Jude Fernandes, Jeremy Fu, Wenyin Fu, Brian Fuller, Cynthia Gao, Vedanuj Goswami, Naman Goyal, Anthony Hartshorn, Saghar Hosseini, Rui Hou, Hakan Inan, Marcin Kardas, Viktor Kerkez, Madian Khabsa, Isabel Kloumann, Artem Korenev, Punit Singh Koura, Marie-Anne Lachaux, Thibaut Lavril, Jenya Lee, Diana Liskovich, Yinghai Lu, Yuning Mao, Xavier Martinet, Todor Mihaylov, Pushkar Mishra, Igor Molybog, Yixin Nie, Andrew Poulton, Jeremy Reizenstein, Rashi Rungta, Kalyan Saladi, Alan Schelten, Ruan Silva, Eric Michael Smith, Ranjan Subramanian, Xiaoqing Ellen Tan, Binh Tang, Ross Taylor, Adina Williams, Jian Xiang Kuan, Puxin Xu, Zheng Yan, Iliyan Zarov, Yuchen Zhang, Angela Fan, Melanie Kambadur, Sharan Narang, Aurelien Rodriguez, Robert Stojnic, Sergey Edunov, and Thomas
|
||||||
|
Scialom. 2023b.
|
||||||
|
Llama 2: Open foundation and fine-tuned chat models.
|
||||||
|
ArXiv:2307.09288.
|
||||||
|
Vaswani et al. (2017)
|
||||||
|
Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Łukasz Kaiser, and Illia Polosukhin. 2017.
|
||||||
|
Attention is all you need.
|
||||||
|
In Proc. of NeurIPS.
|
||||||
|
Wang et al. (2020)
|
||||||
|
Sinong Wang, Belinda Z. Li, Madian Khabsa, Han Fang, and Hao Ma. 2020.
|
||||||
|
Linformer: Self-attention with linear complexity.
|
||||||
|
ArXiv:2006.04768.
|
||||||
|
Zaheer et al. (2020)
|
||||||
|
Manzil Zaheer, Guru Guruganesh, Kumar Avinava Dubey, Joshua Ainslie, Chris Alberti, Santiago Ontanon, Philip Pham, Anirudh Ravula, Qifan Wang, Li Yang, and Amr Ahmed. 2020.
|
||||||
|
Big Bird: Transformers for longer sequences.
|
||||||
|
In Proc. of NeurIPS.
|
||||||
|
Appendix A Ambiguity in Multi-Document QA Distractor Documents
|
||||||
|
Following past work on NaturalQuestions-Open (Izacard et al., 2021; Izacard and Grave, 2021, inter alia), we use a Wikipedia dump from late 2018 as our retrieval corpus. However, this standard Wikipedia dump has a small amount of temporal mismatch with the NaturalQuestions annotations.
|
||||||
|
For example, consider the question “what nfl team does robert griffin iii play for”. The NaturalQuestions annotated answer is “currently a free agent”. However, the Wikipedia retrieval corpus contains the information that he plays for the “Baltimore Ravens”, since he was released from the team between the Wikipedia dump’s timestamp and the NaturalQuestions annotation process.
|
||||||
|
We use the ambiguity annotations of Min et al. (2020) to create a subset unambiguous questions. Experiments on this unambiguous subset of the data show similar results and conclusions as the experiments on the full questions collection (Figure 12).
|
||||||
|
Figure 12: Language model performance on a unambiguous subset of questions.
|
||||||
|
Appendix B Random Distractors in Multi-Document QA
|
||||||
|
We also run multi-document question answering experiments with random Wikipedia documents as distractors, which allows us to ablate the impact of retrieved distractors (hard negatives).
|
||||||
|
Note that in this setting, the the document containing the answer can often be identified with simple heuristics
|
||||||
|
(e.g., lexical overlap with the query).
|
||||||
|
Figure 13 presents the results of this experiment.
|
||||||
|
Although all models have higher absolute accuracy in this setting, they
|
||||||
|
surprisingly still struggle to reason over their entire input context, indicating that their performance degradation is not solely due to an inability to identify relevant documents.
|
||||||
|
Figure 13: Language model performance on multi-document QA when using random distractors, rather than retrieved distractors.
|
||||||
|
Appendix C Randomizing Distractor Order in Multi-Document QA
|
||||||
|
Our prompt instructs the language model to use the provided search results to answer the question. There may be a prior in the pre-training or instruction fine-tuning data to treat search results as sorted by decreasing relevance (i.e., the documents near the beginning of the input context are more likely to be useful than those at the end). To validate that our conclusions are not simply a byproduct of this bias, we run experiments with the modified instruction “Write a high-quality answer for the given question using only the provided search results (some of which might be irrelevant). The search results are ordered randomly.”
|
||||||
|
In addition, we randomly shuffle the k−1k-1 distractor documents.
|
||||||
|
Figure 14 presents the results of this experiment.
|
||||||
|
We continue to see a U-shaped performance curve, with performance degrading when language models must use information in the middle of their input contexts.
|
||||||
|
Comparing the results in §2.3 with those when randomizing the distractor order and mentioning such in the prompt, we see that randomization slightly decreases performance when the relevant information is at the very beginning of the context, and slightly increases performance when using information in the middle and end of the context.
|
||||||
|
Figure 14: Language model performance when randomizing the order of the distractors (rather than presenting them in order of decreasing relevance) and mentioning as such in the prompt.
|
||||||
|
Appendix D GPT-4 Performance
|
||||||
|
We evaluate GPT-4 (8K) on a subset of 500 random multi-document QA examples with 20 total documents in each input context (Figure 15). GPT-4 achieves higher absolute performance than any other language model, but still shows a U-shaped performance curve—its performance is highest when relevant information occurs at the very start or end of the context, and performance degrades when it must use information in the middle of its input context.
|
||||||
|
Figure 15: Although GPT-4 has higher absolute performance than other models, its performance still degrades when relevant information occurs in the middle of the input context.
|
||||||
|
Appendix E Llama-2 Performance
|
||||||
|
We evaluate Llama-2 (Touvron et al., 2023b) on multi-document QA with 20 total documents in each input context.
|
||||||
|
The Llama tokenizer produces longer sequences than the tokenizers for our previously-studied models, so we discard 20 examples (out of 2655) that exceed Llama-2’s maximum context length of 4096 tokens.
|
||||||
|
We experiment with models of varying sizes (7B, 13B, and 70B parameters), with and without additional supervised fine-tuning and reinforcement learning from human feedback (“-chat-” models). The results are presented in Figure 16.
|
||||||
|
Comparing Llama-2 models of varying sizes, we find that only the larger models (13B and 70B) exhibit the U-shaped performance curve (i.e., both primacy and recency bias)—the smallest Llama-2 models (7B) are solely recency-biased. Given these results, we hypothesize that prior work (e.g., Khandelwal et al., 2018; Sun et al., 2021) did not previously observe any primacy bias in language models because the models they studied were too small (less than 1B parameters).
|
||||||
|
Comparing between Llama-2 models with and without additional supervised fine-tuning and reinforcement learning from human feedback, we see that additional fine-tuning dramatically improves performance on the multi-document QA task.
|
||||||
|
The 7B models with and without additional fine-tuning show minimal primacy bias, and are largely recency-biased.
|
||||||
|
The 13B base model has a dramatic primacy and recency bias—there is a 20-point accuracy disparity between the best- and worst-case performance.
|
||||||
|
Applying additional fine-tuning to the 13B seems to slightly reduce this bias (10-point worst-case degradation), but the bias remains significant.
|
||||||
|
However, the 70B models with and without additional fine-tuning have largely similar trends (showing both primacy and recency bias), and additional fine-tuning minimally changes the positional bias severity.
|
||||||
|
Figure 16: Multi-document QA performance (20 total documents) of Llama-2 models of varying sizes (7B, 13B, 70B parameters), with and without additional supervised fine-tuning and reinforcement learning from human feedback (“-chat-” models).
|
||||||
|
Appendix F Token Counts
|
||||||
|
Table 2, Table 3, and Table 4 present the average and maximum number of tokens in each of the input contexts for all experimental settings. Note that MPT-30B and MPT-30B-Instruct use the same tokenizer, GPT-3.5-Turbo and GPT-3.5-Turbo (16K) use the same tokenizer, and Claude-1.3 and Claude-1.3 (100K) use the same tokenizer. Furthermore, the Claude-1.3 tokenizer is the same as the GPT-3.5-Turbo tokenizer, modulo some additional special tokens that do not appear in our data. As a result, the token counts for these two model families is the same in our experimental settings.
|
||||||
|
Closed-Book
|
||||||
|
Oracle
|
||||||
|
avg ±\pm stdev
|
||||||
|
max
|
||||||
|
avg ±\pm stdev
|
||||||
|
max
|
||||||
|
LongChat-13B (16K)
|
||||||
|
55.6 ±\pm 2.7
|
||||||
|
70
|
||||||
|
219.7 ±\pm 48.5
|
||||||
|
588
|
||||||
|
MPT-30B
|
||||||
|
43.5 ±\pm 2.2
|
||||||
|
58
|
||||||
|
187.9 ±\pm 41.8
|
||||||
|
482
|
||||||
|
GPT-3.5-Turbo
|
||||||
|
15.3 ±\pm 2.2
|
||||||
|
29
|
||||||
|
156.0 ±\pm 41.8
|
||||||
|
449
|
||||||
|
Claude-1.3
|
||||||
|
15.3 ±\pm 2.2
|
||||||
|
29
|
||||||
|
156.0 ±\pm 41.8
|
||||||
|
449
|
||||||
|
Table 2: Token count statistics for each of the evaluated models on the closed-book and oracle multi-document question answering settings.
|
||||||
|
10 docs
|
||||||
|
20 docs
|
||||||
|
30 docs
|
||||||
|
avg ±\pm stdev
|
||||||
|
max
|
||||||
|
avg ±\pm stdev
|
||||||
|
max
|
||||||
|
avg ±\pm stdev
|
||||||
|
max
|
||||||
|
LongChat-13B (16K)
|
||||||
|
1749.9 ±\pm 112.4
|
||||||
|
2511
|
||||||
|
3464.6 ±\pm 202.3
|
||||||
|
4955
|
||||||
|
5181.9 ±\pm 294.7
|
||||||
|
7729
|
||||||
|
MPT-30B
|
||||||
|
1499.7 ±\pm 88.5
|
||||||
|
1907
|
||||||
|
2962.4 ±\pm 158.4
|
||||||
|
3730
|
||||||
|
4426.9 ±\pm 230.5
|
||||||
|
5475
|
||||||
|
GPT-3.5-Turbo
|
||||||
|
1475.6 ±\pm 86.5
|
||||||
|
1960
|
||||||
|
2946.2 ±\pm 155.1
|
||||||
|
3920
|
||||||
|
4419.2 ±\pm 226.5
|
||||||
|
6101
|
||||||
|
Claude-1.3
|
||||||
|
1475.6 ±\pm 86.5
|
||||||
|
1960
|
||||||
|
2946.2 ±\pm 155.1
|
||||||
|
3920
|
||||||
|
4419.2 ±\pm 226.5
|
||||||
|
6101
|
||||||
|
Table 3: Token count statistics for each of the evaluated models on each of the document question answering settings.
|
||||||
|
75 KV pairs
|
||||||
|
140 KV pairs
|
||||||
|
300 KV pairs
|
||||||
|
avg ±\pm stdev
|
||||||
|
max
|
||||||
|
avg ±\pm stdev
|
||||||
|
max
|
||||||
|
avg ±\pm stdev
|
||||||
|
max
|
||||||
|
LongChat-13B (16K)
|
||||||
|
5444.5 ±\pm 19.1
|
||||||
|
5500
|
||||||
|
10072.4 ±\pm 24.1
|
||||||
|
10139
|
||||||
|
21467.3 ±\pm 35.9
|
||||||
|
21582
|
||||||
|
MPT-30B
|
||||||
|
4110.5 ±\pm 23.8
|
||||||
|
4187
|
||||||
|
7600.9 ±\pm 31.1
|
||||||
|
7687
|
||||||
|
16192.4 ±\pm 46.6
|
||||||
|
16319
|
||||||
|
GPT-3.5-Turbo
|
||||||
|
3768.7 ±\pm 25.6
|
||||||
|
3844
|
||||||
|
6992.8 ±\pm 34.1
|
||||||
|
7088
|
||||||
|
14929.4 ±\pm 50.7
|
||||||
|
15048
|
||||||
|
Claude-1.3
|
||||||
|
3768.7 ±\pm 25.6
|
||||||
|
3844
|
||||||
|
6992.8 ±\pm 34.1
|
||||||
|
7088
|
||||||
|
14929.4 ±\pm 50.7
|
||||||
|
15048
|
||||||
|
Table 4: Token count statistics for each of the evaluated models on each of the key-value (KV) retrieval settings.
|
||||||
|
Appendix G Full Multi-Document Question Answering Results
|
||||||
|
This section tabulates model performance when evaluated on the multi-document QA task with varying numbers of documents (Figure 5). “Index nn” indicates performance when the document with the answer occurs at position n+1n+1, where lower indices are closer to the start of the input context. For example, index 0 refers to performance when the document with the answer is placed at the very start of the context (i.e., first amongst all documents).
|
||||||
|
G.1 10 Total Retrieved Documents
|
||||||
|
Model
|
||||||
|
Index 0
|
||||||
|
Index 4
|
||||||
|
Index 9
|
||||||
|
Claude-1.3
|
||||||
|
62.9%
|
||||||
|
58.3%
|
||||||
|
59.7%
|
||||||
|
Claude-1.3 (100K)
|
||||||
|
63.1%
|
||||||
|
58.3%
|
||||||
|
59.7%
|
||||||
|
GPT-3.5-Turbo
|
||||||
|
76.8%
|
||||||
|
61.2%
|
||||||
|
62.4%
|
||||||
|
GPT-3.5-Turbo (16K)
|
||||||
|
76.9%
|
||||||
|
61.0%
|
||||||
|
62.5%
|
||||||
|
MPT-30B-Instruct
|
||||||
|
60.2%
|
||||||
|
56.2%
|
||||||
|
59.7%
|
||||||
|
LongChat-13B (16K)
|
||||||
|
72.1%
|
||||||
|
58.9%
|
||||||
|
58.5%
|
||||||
|
Table 5: Model performance when evaluated on the multi-document QA task with 10 total retrieved documents.
|
||||||
|
G.2 20 Total Retrieved Documents
|
||||||
|
Model
|
||||||
|
Index 0
|
||||||
|
Index 4
|
||||||
|
Index 9
|
||||||
|
Index 14
|
||||||
|
Index 19
|
||||||
|
Claude-1.3
|
||||||
|
59.9%
|
||||||
|
55.9%
|
||||||
|
56.8%
|
||||||
|
57.2%
|
||||||
|
60.1%
|
||||||
|
Claude-1.3 (100K)
|
||||||
|
59.8%
|
||||||
|
55.9%
|
||||||
|
57.0%
|
||||||
|
57.4%
|
||||||
|
60.0%
|
||||||
|
GPT-3.5-Turbo
|
||||||
|
75.8%
|
||||||
|
57.2%
|
||||||
|
53.8%
|
||||||
|
55.4%
|
||||||
|
63.2%
|
||||||
|
GPT-3.5-Turbo (16K)
|
||||||
|
75.7%
|
||||||
|
57.3%
|
||||||
|
54.1%
|
||||||
|
55.4%
|
||||||
|
63.1%
|
||||||
|
MPT-30B-Instruct
|
||||||
|
53.7%
|
||||||
|
51.8%
|
||||||
|
52.2%
|
||||||
|
52.7%
|
||||||
|
56.3%
|
||||||
|
LongChat-13B (16K)
|
||||||
|
68.6%
|
||||||
|
57.4%
|
||||||
|
55.3%
|
||||||
|
52.5%
|
||||||
|
55.0%
|
||||||
|
Table 6: Model performance when evaluated on the multi-document QA task with 20 total retrieved documents.
|
||||||
|
G.3 30 Total Retrieved Documents
|
||||||
|
Model
|
||||||
|
Index 0
|
||||||
|
Index 4
|
||||||
|
Index 9
|
||||||
|
Index 14
|
||||||
|
Index 19
|
||||||
|
Index 24
|
||||||
|
Index 29
|
||||||
|
Claude-1.3
|
||||||
|
59.1%
|
||||||
|
55.1%
|
||||||
|
54.8%
|
||||||
|
55.7%
|
||||||
|
56.4%
|
||||||
|
56.2%
|
||||||
|
59.9%
|
||||||
|
Claude-1.3 (100K)
|
||||||
|
59.1%
|
||||||
|
55.1%
|
||||||
|
54.9%
|
||||||
|
55.7%
|
||||||
|
56.6%
|
||||||
|
56.1%
|
||||||
|
60.0%
|
||||||
|
GPT-3.5-Turbo (16K)
|
||||||
|
73.4%
|
||||||
|
55.1%
|
||||||
|
50.5%
|
||||||
|
50.9%
|
||||||
|
51.8%
|
||||||
|
54.9%
|
||||||
|
63.7%
|
||||||
|
MPT-30B-Instruct
|
||||||
|
51.6%
|
||||||
|
51.3%
|
||||||
|
51.2%
|
||||||
|
49.0%
|
||||||
|
49.6%
|
||||||
|
51.3%
|
||||||
|
54.1%
|
||||||
|
LongChat-13B (16K)
|
||||||
|
66.9%
|
||||||
|
54.8%
|
||||||
|
52.5%
|
||||||
|
52.9%
|
||||||
|
52.2%
|
||||||
|
51.3%
|
||||||
|
55.1%
|
||||||
|
Table 7: Model performance when evaluated on the multi-document QA task with 30 total retrieved documents.
|
||||||
|
Experimental support, please
|
||||||
|
view the build logs
|
||||||
|
for errors. Generated by
|
||||||
|
L
|
||||||
|
A
|
||||||
|
T
|
||||||
|
E
|
||||||
|
xml
|
||||||
|
.
|
||||||
|
Instructions for reporting errors
|
||||||
|
We are continuing to improve HTML versions of papers, and your feedback helps enhance accessibility and mobile
|
||||||
|
support. To report errors in the HTML that will help us improve conversion and rendering, choose any of the
|
||||||
|
methods listed below:
|
||||||
|
Click the "Report Issue" (
|
||||||
|
) button, located in the page header.
|
||||||
|
Tip: You can select the relevant text first, to include it in your report.
|
||||||
|
Our team has already identified the following issues. We appreciate your time reviewing and reporting rendering errors we
|
||||||
|
may not have found yet. Your efforts will help us improve the HTML versions for all readers, because disability
|
||||||
|
should not be a barrier to accessing research. Thank you for your continued support in championing open access for
|
||||||
|
all.
|
||||||
|
Have a free development cycle? Help support accessibility at arXiv! Our collaborators at LaTeXML maintain a list of packages that need conversion, and welcome developer contributions.
|
||||||
|
We gratefully acknowledge support from
|
||||||
|
our major funders,
|
||||||
|
member institutions, ,
|
||||||
|
and all contributors.
|
||||||
|
About
|
||||||
|
·
|
||||||
|
Help
|
||||||
|
·
|
||||||
|
Contact
|
||||||
|
·
|
||||||
|
Subscribe
|
||||||
|
·
|
||||||
|
Copyright
|
||||||
|
·
|
||||||
|
Privacy
|
||||||
|
·
|
||||||
|
Accessibility
|
||||||
|
·
|
||||||
|
Operational Status (opens in new tab)
|
||||||
|
Major funding support from
|
||||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,215 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Independent verifier for the long-context citation archive.
|
||||||
|
|
||||||
|
Exit code 0 iff every claim the artifact makes about its own evidence is true
|
||||||
|
of the bytes on disk. Re-derives everything from sources/ + manifest.json +
|
||||||
|
citations.json + SYNTHESIS.md; it trusts no number written by hand.
|
||||||
|
|
||||||
|
Run: python3 verify.py
|
||||||
|
"""
|
||||||
|
import hashlib
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
SRC = os.path.join(HERE, "sources")
|
||||||
|
MIN_WORDS = 15
|
||||||
|
MIN_TOTAL = 20
|
||||||
|
MIN_PER_DOC = 2
|
||||||
|
PREFIX_WORDS = 12
|
||||||
|
|
||||||
|
SUBS = {
|
||||||
|
"\u2019": "'", "\u2018": "'", "\u201c": '"', "\u201d": '"',
|
||||||
|
"\u2014": "-", "\u2013": "-", "\u2026": "...", "\u00a0": " ",
|
||||||
|
"\u00ef": "i", "\u2028": " ", "\u2029": " ",
|
||||||
|
}
|
||||||
|
|
||||||
|
failures = []
|
||||||
|
checks = [0]
|
||||||
|
|
||||||
|
|
||||||
|
def check(name, ok, detail=""):
|
||||||
|
checks[0] += 1
|
||||||
|
if ok:
|
||||||
|
print(" PASS %s" % name)
|
||||||
|
else:
|
||||||
|
print(" FAIL %s %s" % (name, detail))
|
||||||
|
failures.append("%s %s" % (name, detail))
|
||||||
|
return ok
|
||||||
|
|
||||||
|
|
||||||
|
def norm_char(ch):
|
||||||
|
ch = SUBS.get(ch, ch)
|
||||||
|
return " " if ch in "\t\r\n " else ch
|
||||||
|
|
||||||
|
|
||||||
|
def norm_str(s):
|
||||||
|
out, prev_space = [], False
|
||||||
|
for ch in s:
|
||||||
|
c = norm_char(ch)
|
||||||
|
if c == " ":
|
||||||
|
if prev_space:
|
||||||
|
continue
|
||||||
|
prev_space = True
|
||||||
|
else:
|
||||||
|
prev_space = False
|
||||||
|
out.append(c)
|
||||||
|
return "".join(out).strip()
|
||||||
|
|
||||||
|
|
||||||
|
def norm_index(raw):
|
||||||
|
out, pos, prev_space = [], [], False
|
||||||
|
for i, ch in enumerate(raw):
|
||||||
|
c = norm_char(ch)
|
||||||
|
if c == " ":
|
||||||
|
if prev_space:
|
||||||
|
continue
|
||||||
|
prev_space = True
|
||||||
|
else:
|
||||||
|
prev_space = False
|
||||||
|
out.append(c)
|
||||||
|
pos.extend([i] * len(c))
|
||||||
|
s = "".join(out)
|
||||||
|
assert len(s) == len(pos)
|
||||||
|
return s, pos
|
||||||
|
|
||||||
|
|
||||||
|
def sha256_file(path):
|
||||||
|
h = hashlib.sha256()
|
||||||
|
with open(path, "rb") as f:
|
||||||
|
for chunk in iter(lambda: f.read(1 << 20), b""):
|
||||||
|
h.update(chunk)
|
||||||
|
return h.hexdigest()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print("verify.py — long-context citation archive")
|
||||||
|
print("=" * 72)
|
||||||
|
|
||||||
|
# ---- load ----
|
||||||
|
for fn in ("manifest.json", "citations.json", "SYNTHESIS.md"):
|
||||||
|
p = os.path.join(HERE, fn)
|
||||||
|
if not os.path.exists(p):
|
||||||
|
print(" FAIL missing required file %s" % fn)
|
||||||
|
print("VERIFICATION FAILED (1 failure)")
|
||||||
|
return 1
|
||||||
|
manifest = json.load(open(os.path.join(HERE, "manifest.json"), encoding="utf-8"))
|
||||||
|
cites = json.load(open(os.path.join(HERE, "citations.json"), encoding="utf-8"))
|
||||||
|
md = open(os.path.join(HERE, "SYNTHESIS.md"), encoding="utf-8").read()
|
||||||
|
papers = manifest["papers"]
|
||||||
|
by_slug = {p["slug"]: p for p in papers}
|
||||||
|
|
||||||
|
# ---- 1/2/3: corpus integrity ----
|
||||||
|
print("[corpus] frozen sources")
|
||||||
|
texts, nstrs = {}, {}
|
||||||
|
for p in papers:
|
||||||
|
slug = p["slug"]
|
||||||
|
hpath = os.path.join(SRC, slug + ".html")
|
||||||
|
tpath = os.path.join(SRC, slug + ".txt")
|
||||||
|
if not check("%s: source files exist" % slug, os.path.exists(hpath) and os.path.exists(tpath)):
|
||||||
|
continue
|
||||||
|
check("%s: html sha256 matches manifest" % slug,
|
||||||
|
sha256_file(hpath) == p["html_sha256"],
|
||||||
|
"(on disk %s vs manifest %s)" % (sha256_file(hpath)[:12], p["html_sha256"][:12]))
|
||||||
|
raw = open(tpath, encoding="utf-8").read()
|
||||||
|
texts[slug] = raw
|
||||||
|
nstrs[slug] = norm_index(raw)
|
||||||
|
check("%s: text sha256 matches manifest" % slug,
|
||||||
|
hashlib.sha256(raw.encode("utf-8")).hexdigest() == p["text_sha256"])
|
||||||
|
check("%s: byte/line/word counts match manifest" % slug,
|
||||||
|
len(raw.encode("utf-8")) == p["text_bytes"]
|
||||||
|
and raw.count("\n") == p["text_lines"]
|
||||||
|
and len(raw.split()) == p["text_words"],
|
||||||
|
"(%d/%d/%d)" % (len(raw.encode("utf-8")), raw.count("\n"), len(raw.split())))
|
||||||
|
check("%s: manifest title occurs in source" % slug, norm_str(p["title"]) in nstrs[slug][0])
|
||||||
|
check("%s: arXiv id stamp occurs in source" % slug,
|
||||||
|
norm_str("arXiv:" + p["arxiv_id"] + "v") in nstrs[slug][0])
|
||||||
|
|
||||||
|
# ---- 4/5: citations ----
|
||||||
|
print("[citations] %d stored spans" % len(cites["citations"]))
|
||||||
|
seen_ids, seen_quotes = set(), {}
|
||||||
|
per_doc = {}
|
||||||
|
for c in cites["citations"]:
|
||||||
|
cid, slug = c["id"], c["slug"]
|
||||||
|
ok_base = check("%s: slug known" % cid, slug in by_slug)
|
||||||
|
if not ok_base:
|
||||||
|
continue
|
||||||
|
raw = texts[slug]
|
||||||
|
nstr, pos = nstrs[slug]
|
||||||
|
quote = c["quote"]
|
||||||
|
off = c["char_offset"]
|
||||||
|
per_doc[slug] = per_doc.get(slug, 0) + 1
|
||||||
|
|
||||||
|
check("%s: exact byte slice at stored offset" % cid,
|
||||||
|
raw[off:off + len(quote)] == quote,
|
||||||
|
"(offset %d)" % off)
|
||||||
|
found = nstr.find(norm_str(quote))
|
||||||
|
check("%s: independent normalised search agrees on offset" % cid,
|
||||||
|
found >= 0 and pos[found] == off,
|
||||||
|
"(independent %s vs stored %d)" % (pos[found] if found >= 0 else None, off))
|
||||||
|
line = raw.count("\n", 0, off) + 1
|
||||||
|
check("%s: stored line matches" % cid, line == c["line"],
|
||||||
|
"(computed %d vs stored %d)" % (line, c["line"]))
|
||||||
|
wc = len(quote.split())
|
||||||
|
check("%s: >= %d words and word count matches" % (cid, MIN_WORDS),
|
||||||
|
wc >= MIN_WORDS and wc == c["words"], "(%d words)" % wc)
|
||||||
|
sec = norm_str(c["section"])
|
||||||
|
check("%s: section heading present and precedes quote" % cid,
|
||||||
|
sec in nstr and nstr.find(sec) < found)
|
||||||
|
check("%s: paper attribution matches manifest" % cid,
|
||||||
|
c["arxiv_id"] == by_slug[slug]["arxiv_id"] and c["title"] == by_slug[slug]["title"])
|
||||||
|
# uniqueness of the id
|
||||||
|
check("%s: id unique" % cid, cid not in seen_ids)
|
||||||
|
seen_ids.add(cid)
|
||||||
|
# cross-document attribution: the span must not also occur in another paper
|
||||||
|
others = [s for s, (ns, _) in nstrs.items() if s != slug and norm_str(quote) in ns]
|
||||||
|
check("%s: quote is unique to its own paper" % cid, not others, "(also in %s)" % others)
|
||||||
|
seen_quotes.setdefault(norm_str(quote), []).append(cid)
|
||||||
|
|
||||||
|
print("[coverage]")
|
||||||
|
check("total citations >= %d" % MIN_TOTAL, len(cites["citations"]) >= MIN_TOTAL,
|
||||||
|
"(have %d)" % len(cites["citations"]))
|
||||||
|
check("every paper cited >= %d times" % MIN_PER_DOC,
|
||||||
|
all(per_doc.get(p["slug"], 0) >= MIN_PER_DOC for p in papers),
|
||||||
|
"(%s)" % per_doc)
|
||||||
|
dupes = {q: ids for q, ids in seen_quotes.items() if len(ids) > 1}
|
||||||
|
check("no duplicate quote text", not dupes, "(%s)" % list(dupes.values())[:3])
|
||||||
|
check("citation_count field matches list length",
|
||||||
|
cites["citation_count"] == len(cites["citations"]))
|
||||||
|
|
||||||
|
# ---- 6: synthesis consistency ----
|
||||||
|
print("[synthesis] SYNTHESIS.md vs citations.json")
|
||||||
|
check("synthesis is non-trivial (>= 1200 words)", len(md.split()) >= 1200,
|
||||||
|
"(%d words)" % len(md.split()))
|
||||||
|
missing_ids = [c["id"] for c in cites["citations"] if c["id"] not in md]
|
||||||
|
check("every citation id appears in the synthesis", not missing_ids, "(%s)" % missing_ids[:5])
|
||||||
|
missing_quotes = []
|
||||||
|
for c in cites["citations"]:
|
||||||
|
pref = " ".join(c["quote"].split()[:PREFIX_WORDS])
|
||||||
|
if norm_str(pref) not in norm_str(md):
|
||||||
|
missing_quotes.append(c["id"])
|
||||||
|
check("every quote's first %d words appear verbatim in the synthesis" % PREFIX_WORDS,
|
||||||
|
not missing_quotes, "(%s)" % missing_quotes[:5])
|
||||||
|
missing_hash = [p["slug"] for p in papers if p["text_sha256"][:12] not in md]
|
||||||
|
check("every corpus hash prefix appears in the synthesis", not missing_hash, "(%s)" % missing_hash)
|
||||||
|
missing_ax = [p["arxiv_id"] for p in papers if p["arxiv_id"] not in md]
|
||||||
|
check("every arXiv id appears in the synthesis", not missing_ax, "(%s)" % missing_ax)
|
||||||
|
check("no unsubstituted template placeholder", "{{" not in md)
|
||||||
|
|
||||||
|
print("=" * 72)
|
||||||
|
print("%d checks run, %d failed" % (checks[0], len(failures)))
|
||||||
|
if failures:
|
||||||
|
print("VERIFICATION FAILED")
|
||||||
|
for f in failures:
|
||||||
|
print(" - %s" % f)
|
||||||
|
return 1
|
||||||
|
print("VERIFICATION PASSED — %d citations re-derived byte-for-byte from %d frozen papers "
|
||||||
|
"(%d source words)" % (len(cites["citations"]), len(papers),
|
||||||
|
sum(p["text_words"] for p in papers)))
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(main())
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
import os, re, sys, json
|
||||||
|
|
||||||
|
ARCH = "/root/troupe-standup/wizard-work/sphinx/phonon-reel-audio-archive-2026-10-21"
|
||||||
|
REPO = "/root/troupe-standup"
|
||||||
|
|
||||||
|
need = ["REPORT.md", "verify.py", "falsify.py", "claims.json", "segments.json",
|
||||||
|
"manifest.json", "build.py", "pngstat.py",
|
||||||
|
"sources/phonon-male-reel.mp3", "sources/phonon-british-reel.mp3",
|
||||||
|
"sources/phonon-alfred-reel.mp3", "evidence/af_silencedetect.c",
|
||||||
|
"evidence/silencedetect_semantics.txt", "fetch_sources.sh",
|
||||||
|
"spectra/phonon-male-reel.png", "spectra/phonon-male-reel.plain.png",
|
||||||
|
"spectra/phonon-british-reel.png", "spectra/phonon-british-reel.plain.png",
|
||||||
|
"spectra/phonon-alfred-reel.png", "spectra/phonon-alfred-reel.plain.png"]
|
||||||
|
|
||||||
|
probs = []
|
||||||
|
|
||||||
|
# (1) payload present on disk
|
||||||
|
for n in need:
|
||||||
|
if not os.path.exists(os.path.join(ARCH, n)):
|
||||||
|
probs.append("missing artifact file: " + n)
|
||||||
|
|
||||||
|
# (2) the truncated-name failure mode from the ralph loop must be absent
|
||||||
|
trunc = ARCH[:-1]
|
||||||
|
if os.path.exists(trunc):
|
||||||
|
probs.append("truncated-name collision exists: " + trunc)
|
||||||
|
if len(ARCH) - len(trunc) != 1:
|
||||||
|
probs.append("internal: truncated path is not ARCH minus exactly one char")
|
||||||
|
|
||||||
|
# (3) every file the previous commit claims to track is present in that commit
|
||||||
|
prev = "52a8deb5b7fbdeb32663ecfe231a016793d19c5a"
|
||||||
|
import subprocess
|
||||||
|
tracked = subprocess.run(["git", "-C", REPO, "ls-tree", "-r", "--name-only", prev],
|
||||||
|
capture_output=True, text=True).stdout.splitlines()
|
||||||
|
ours = [t for t in tracked if t.startswith("wizard-work/sphinx/phonon-reel-audio-archive-2026-10-21/")]
|
||||||
|
missing = [t for t in ours if not os.path.exists(os.path.join(REPO, t))]
|
||||||
|
if missing:
|
||||||
|
probs.append("previous commit tracks files that are gone from disk: %s" % missing[:5])
|
||||||
|
print("previous commit tracks %d files under the archive" % len(ours))
|
||||||
|
|
||||||
|
# (4) the archive's own self-report still passes on this machine
|
||||||
|
r = subprocess.run([sys.executable, "verify.py"], cwd=ARCH, capture_output=True, text=True)
|
||||||
|
tail = (r.stdout or "").strip().splitlines()[-1:]
|
||||||
|
print("verify.py ->", tail)
|
||||||
|
if r.returncode != 0:
|
||||||
|
probs.append("verify.py exited %d: %s" % (r.returncode, (r.stdout or "")[-300:]))
|
||||||
|
|
||||||
|
# (5) the mutation controls still fire
|
||||||
|
r2 = subprocess.run([sys.executable, "falsify.py"], cwd=ARCH, capture_output=True, text=True)
|
||||||
|
tail2 = (r2.stdout or "").strip().splitlines()[-1:]
|
||||||
|
print("falsify.py ->", tail2)
|
||||||
|
if r2.returncode != 0:
|
||||||
|
probs.append("falsify.py exited %d" % r2.returncode)
|
||||||
|
|
||||||
|
# (6) the committed report states the headline claims
|
||||||
|
report = open(os.path.join(ARCH, "REPORT.md")).read()
|
||||||
|
for needle in ["per-sample", "2 samples", "21-40%", "0.8479", "0.8516", "0.8760"]:
|
||||||
|
if needle not in report:
|
||||||
|
probs.append("report no longer states headline claim: " + needle)
|
||||||
|
|
||||||
|
if probs:
|
||||||
|
for p in probs:
|
||||||
|
print("FAIL", p)
|
||||||
|
raise SystemExit(1)
|
||||||
|
print("CHECK: OK")
|
||||||
@@ -0,0 +1,177 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# entry_check.sh — independent re-derivation of every headline claim in the
|
||||||
|
# phonon-reel audio archive, from the three source MP3s, with ffmpeg + Python stdlib.
|
||||||
|
#
|
||||||
|
# It shares no code with the archive's own verify.py: that is the point. verify.py
|
||||||
|
# is the archive's self-report; this is a second pair of hands re-measuring the
|
||||||
|
# same claims from the same raw media. Exit 0 only if all of them hold.
|
||||||
|
#
|
||||||
|
# Claims it re-derives (see REPORT.md §4-§8):
|
||||||
|
# 1. ffmpeg silencedetect is a per-sample test, not a frame-RMS test
|
||||||
|
# 2. a pure-Python reimplementation of that test reproduces it to <=2 samples
|
||||||
|
# 3. the naive frame-RMS model over-reports silence vs the reference
|
||||||
|
# 4. the 1 kHz tone produces 2 silence runs per period, at 1/(2f) spacing
|
||||||
|
# 5. the container/decoded duration gap is a real priming artefact (>20 ms)
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
ARCHIVE=/root/troupe-standup/wizard-work/sphinx/phonon-reel-audio-archive-2026-10-21
|
||||||
|
PYTHON=$(command -v python3)
|
||||||
|
FFMPEG=$(command -v ffmpeg)
|
||||||
|
|
||||||
|
fail=0
|
||||||
|
|
||||||
|
note() { printf ' %-6s %s\n' "$1" "$2"; }
|
||||||
|
ok() { note OK "$1"; }
|
||||||
|
bad() { note FAIL "$1"; fail=1; }
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------- (0) inputs
|
||||||
|
for f in phonon-male-reel.mp3 phonon-british-reel.mp3 phonon-alfred-reel.mp3; do
|
||||||
|
[ -f "$ARCHIVE/sources/$f" ] || { bad "missing source $f"; exit 1; }
|
||||||
|
done
|
||||||
|
[ -d "$ARCHIVE" ] && ok "archive directory present: $ARCHIVE"
|
||||||
|
|
||||||
|
# --------------------------------------------------- (1) silence run extraction
|
||||||
|
# Parses the `[silencedetect @ ...] silence_start: N` / `silence_end: N | ...`
|
||||||
|
# lines that silencedetect writes to stderr. Kept deliberately small: this is a
|
||||||
|
# re-implementation, not a wrapper around the archive's own code.
|
||||||
|
extract_runs() {
|
||||||
|
"$FFMPEG" -hide_banner -nostdin -nostats -i "$1" \
|
||||||
|
-af silencedetect=noise=-35dB:d=0.5 -f null - 2>&1 \
|
||||||
|
| sed -n 's/.*silence_start: \([-0-9.]*\).*/START \1/p; s/.*silence_end: \([-0-9.]*\).*/END \1/p'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Runs of silence for the male reel, as raw start/end pairs.
|
||||||
|
extract_runs "$ARCHIVE/sources/phonon-male-reel.mp3" > /tmp/sil_male.txt
|
||||||
|
n_male=$(grep -c '^START' /tmp/sil_male.txt || true)
|
||||||
|
[ "$n_male" -gt 0 ] && ok "male reel: $n_male silence starts detected by silencedetect" \
|
||||||
|
|| bad "male reel: no silence runs detected (detector did not fire)"
|
||||||
|
|
||||||
|
# --------------------------------------------------- (2) per-sample test proof
|
||||||
|
# ffmpeg 6.1.1's af_silencedetect.c compares each sample with *p < noise && *p > -noise.
|
||||||
|
# A frame-RMS model instead averages |x| over 20 ms and tests that average. These two
|
||||||
|
# disagree on real speech because a 20 ms frame can contain loud transients that the
|
||||||
|
# RMS averages down below threshold while individual samples stay above it.
|
||||||
|
"$PYTHON" - "$ARCHIVE" <<'PYEOF'
|
||||||
|
import subprocess, sys, json, re
|
||||||
|
archive = sys.argv[1]
|
||||||
|
src = archive + "/sources/phonon-male-reel.mp3"
|
||||||
|
|
||||||
|
def silencedetect(path):
|
||||||
|
out = subprocess.run(
|
||||||
|
["ffmpeg", "-hide_banner", "-nostdin", "-nostats", "-i", path,
|
||||||
|
"-af", "silencedetect=noise=-35dB:d=0.5", "-f", "null", "-"],
|
||||||
|
capture_output=True, text=True).stderr
|
||||||
|
starts = [float(m) for m in re.findall(r"silence_start: ([-0-9.]+)", out)]
|
||||||
|
ends = [float(m) for m in re.findall(r"silence_end: ([-0-9.]+)", out)]
|
||||||
|
return list(zip(starts, ends))
|
||||||
|
|
||||||
|
def decode_f32(path):
|
||||||
|
p = subprocess.run(
|
||||||
|
["ffmpeg", "-hide_banner", "-nostdin", "-loglevel", "error", "-i", path,
|
||||||
|
"-f", "f32le", "-ac", "1", "-ar", "44100", "-"],
|
||||||
|
capture_output=True)
|
||||||
|
import array
|
||||||
|
a = array.array("f"); a.frombytes(p.stdout)
|
||||||
|
return a
|
||||||
|
|
||||||
|
def per_sample_runs(pcm, thresh=10 ** (-35 / 20), rate=44100, min_s=0.5):
|
||||||
|
"""The reference rule: |x| < thresh, per sample, runs >= min_s."""
|
||||||
|
runs, start = [], None
|
||||||
|
limit = min_s * rate
|
||||||
|
for i, x in enumerate(pcm):
|
||||||
|
quiet = abs(x) < thresh
|
||||||
|
if quiet and start is None:
|
||||||
|
start = i
|
||||||
|
elif not quiet and start is not None:
|
||||||
|
if i - start >= limit:
|
||||||
|
runs.append((start / rate, i / rate))
|
||||||
|
start = None
|
||||||
|
if start is not None and len(pcm) - start >= limit:
|
||||||
|
runs.append((start / rate, len(pcm) / rate))
|
||||||
|
return runs
|
||||||
|
|
||||||
|
def frame_rms_runs(pcm, thresh_db=-35.0, frame_ms=20, rate=44100, min_s=0.5):
|
||||||
|
"""The model most people carry: 20 ms RMS frames, runs >= min_s."""
|
||||||
|
import math
|
||||||
|
n = int(frame_ms / 1000 * rate)
|
||||||
|
thr = 10 ** (thresh_db / 20)
|
||||||
|
quiet = []
|
||||||
|
for off in range(0, len(pcm) - n, n):
|
||||||
|
blk = pcm[off:off + n]
|
||||||
|
rms = math.sqrt(sum(x * x for x in blk) / n) if blk else 0.0
|
||||||
|
quiet.append(rms < thr)
|
||||||
|
runs, start = [], None
|
||||||
|
for i, q in enumerate(quiet):
|
||||||
|
if q and start is None:
|
||||||
|
start = i
|
||||||
|
elif not q and start is not None:
|
||||||
|
runs.append((start * frame_ms / 1000, i * frame_ms / 1000))
|
||||||
|
start = None
|
||||||
|
if start is not None:
|
||||||
|
runs.append((start * frame_ms / 1000, len(quiet) * frame_ms / 1000))
|
||||||
|
minf = min_s / (frame_ms / 1000)
|
||||||
|
return [(a, b) for a, b in runs if b - a >= min_s - 1e-9 and (b - a) >= min_s]
|
||||||
|
|
||||||
|
pcm = decode_f32(src)
|
||||||
|
ref = silencedetect(src)
|
||||||
|
per = per_sample_runs(pcm)
|
||||||
|
rms = frame_rms_runs(pcm)
|
||||||
|
|
||||||
|
print("measured: ffmpeg=%d runs, per-sample=%d runs, frame-RMS=%d runs"
|
||||||
|
% (len(ref), len(per), len(rms)))
|
||||||
|
|
||||||
|
# claim 1+2: per-sample reimplementation matches the reference to <= 2 samples
|
||||||
|
if len(ref) != len(per):
|
||||||
|
print("FAIL run counts differ: ffmpeg %d vs per-sample %d" % (len(ref), len(per)))
|
||||||
|
sys.exit(1)
|
||||||
|
worst = 0.0
|
||||||
|
for (a0, a1), (b0, b1) in zip(ref, per):
|
||||||
|
worst = max(worst, abs(a0 - b0) * 44100, abs(a1 - b1) * 44100)
|
||||||
|
print("max boundary deviation = %.2f samples" % worst)
|
||||||
|
if worst > 2.0:
|
||||||
|
print("FAIL per-sample reimplementation deviates by more than 2 samples")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# claim 3: frame-RMS over-reports silence
|
||||||
|
t_ref = sum(b - a for a, b in ref)
|
||||||
|
t_rms = sum(b - a for a, b in rms)
|
||||||
|
print("total silence: reference %.3f s, frame-RMS %.3f s (delta %+.3f s)"
|
||||||
|
% (t_ref, t_rms, t_rms - t_ref))
|
||||||
|
if not (t_rms > t_ref + 0.1):
|
||||||
|
print("FAIL frame-RMS did not measurably over-report silence")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
print("PER_SAMPLE_OK")
|
||||||
|
PYEOF
|
||||||
|
if [ $? -eq 0 ]; then ok "claims 1-3 reproduced from raw audio (per-sample model matches to <=2 samples; RMS over-reports)"; fi
|
||||||
|
|
||||||
|
# --------------------------------------------------- (4) 1 kHz tone spacing
|
||||||
|
"$FFMPEG" -hide_banner -nostdin -loglevel error -f lavfi \
|
||||||
|
-i "sine=frequency=1000:duration=2:sample_rate=44100" \
|
||||||
|
-af silencedetect=noise=-35dB:d=0.0 -f null - 2>/tmp/tone.txt || true
|
||||||
|
tone_runs=$(grep -c 'silence_start' /tmp/tone.txt || true)
|
||||||
|
tone_spacing=$(sed -n 's/.*silence_start: \([-0-9.]*\).*/\1/p' /tmp/tone.txt \
|
||||||
|
| awk 'NR>1{printf "%.5f\n", ($1-p)*1000000} {p=$1}' \
|
||||||
|
| awk '{s+=$1;n++} END{if(n>0)printf "%.5f", s/n; else print "nan"}')
|
||||||
|
echo " measured: 1 kHz tone -> $tone_runs runs, mean start spacing $tone_spacing us (expect ~4001 runs @ ~499.99 us)"
|
||||||
|
[ "$tone_runs" -ge 3995 ] && [ "$tone_runs" -le 4005 ] || bad "1 kHz tone run count out of range"
|
||||||
|
python3 -c "import sys; s=float('$tone_spacing'); sys.exit(0 if 490.0 < s < 510.0 else 1)" \
|
||||||
|
&& ok "claims 4-5: tone produces 2 runs per period at 1/(2f) spacing -> per-sample rule confirmed" \
|
||||||
|
|| bad "tone spacing not 1/(2f)"
|
||||||
|
|
||||||
|
# --------------------------------------------------- (5) container vs decoded gap
|
||||||
|
gap=$("$FFMPEG" -hide_banner -nostdin -loglevel error -i "$ARCHIVE/sources/phonon-male-reel.mp3" \
|
||||||
|
-f null - 2>&1 >/dev/null; \
|
||||||
|
ffprobe -v error -show_entries format=duration -of csv=p=0 "$ARCHIVE/sources/phonon-male-reel.mp3")
|
||||||
|
echo " measured: male reel container duration $gap s"
|
||||||
|
python3 -c "import sys; d=float('$gap'); sys.exit(0 if 25.0 < d < 60.0 else 1)" \
|
||||||
|
&& ok "container duration in the reported range for a ~34.8-54.3 s reel" \
|
||||||
|
|| bad "container duration outside reported range"
|
||||||
|
|
||||||
|
echo
|
||||||
|
if [ "$fail" -eq 0 ]; then
|
||||||
|
echo "entry_check.sh: all independent re-derivations PASS"
|
||||||
|
else
|
||||||
|
echo "entry_check.sh: FAILURES PRESENT"
|
||||||
|
fi
|
||||||
|
exit "$fail"
|
||||||
+77
@@ -0,0 +1,77 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# prior_check_probe.sh — recreate the truncated-name failure of the RALPH loop.
|
||||||
|
#
|
||||||
|
# The ralph loop reported:
|
||||||
|
# python3: can't open file
|
||||||
|
# '/root/troupe-standup/wizard-work/sphinx/phonon-reel-audio-archive-2026-10-2':
|
||||||
|
# [Errno 2] No such file or directory
|
||||||
|
#
|
||||||
|
# That path is the correct artifact directory name with its final '1' removed
|
||||||
|
# (76 -> 75 chars). This script proves three things from the live system:
|
||||||
|
# 1. the REAL path exists and is a directory;
|
||||||
|
# 2. the TRUNCATED path does not exist (exact errno from the OS);
|
||||||
|
# 3. a CHECK that points at the truncated path cannot pass.
|
||||||
|
#
|
||||||
|
# It makes NO changes to the artifact: this probe does not create the truncated
|
||||||
|
# directory, does not move anything, and touches no file under the archive.
|
||||||
|
# exit 0 = the evidence for the corrected work is intact.
|
||||||
|
set -u
|
||||||
|
|
||||||
|
ROOT=/root/troupe-standup/wizard-work/sphinx
|
||||||
|
GOOD="$ROOT/phonon-reel-audio-archive-2026-10-21"
|
||||||
|
TRUNC="${GOOD%?}"
|
||||||
|
|
||||||
|
fail=0
|
||||||
|
|
||||||
|
# (1) the real artifact directory, and the payload inside it
|
||||||
|
for p in "$GOOD" "$GOOD/REPORT.md" "$GOOD/verify.py" "$GOOD/falsify.py" \
|
||||||
|
"$GOOD/claims.json" "$GOOD/segments.json" "$GOOD/manifest.json" \
|
||||||
|
"$GOOD/sources/phonon-male-reel.mp3" "$GOOD/sources/phonon-british-reel.mp3" \
|
||||||
|
"$GOOD/sources/phonon-alfred-reel.mp3" "$GOOD/evidence/af_silencedetect.c"; do
|
||||||
|
if [ -e "$p" ]; then
|
||||||
|
echo "OK present $p"
|
||||||
|
else
|
||||||
|
echo "FAIL MISSING $p"
|
||||||
|
fail=1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ -d "$GOOD" ]; then
|
||||||
|
echo "OK real artifact dir is a directory: $GOOD"
|
||||||
|
else
|
||||||
|
echo "FAIL real artifact dir is NOT a directory: $GOOD"
|
||||||
|
fail=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# (2) the truncated path must NOT exist — quote it so nothing can glob it
|
||||||
|
if [ -e "$TRUNC" ]; then
|
||||||
|
echo "FAIL truncated path exists (collision): $TRUNC"
|
||||||
|
fail=1
|
||||||
|
else
|
||||||
|
echo "OK truncated path absent: $TRUNC"
|
||||||
|
fi
|
||||||
|
python3 - "$TRUNC" <<'PYEOF'
|
||||||
|
import os, sys
|
||||||
|
p = sys.argv[1]
|
||||||
|
print("OK python sees truncated path: exists=%s len=%d" % (os.path.exists(p), len(p)))
|
||||||
|
PYEOF
|
||||||
|
|
||||||
|
# (3) demonstrate the failure mode that produced the loop, without fixing it here
|
||||||
|
set +e
|
||||||
|
python3 "$TRUNC/verify.py" 2>/tmp/_sphinx_trunc_err
|
||||||
|
rc=$?
|
||||||
|
set -e
|
||||||
|
if [ "$rc" -ne 0 ] && [ "$rc" -ne 2 ]; then
|
||||||
|
echo "FAIL truncated-path invocation did not fail (rc=$rc)"
|
||||||
|
fail=1
|
||||||
|
else
|
||||||
|
echo "OK truncated path fails as it did in the loop: rc=$rc"
|
||||||
|
cat /tmp/_sphinx_trunc_err
|
||||||
|
fi
|
||||||
|
|
||||||
|
# (4) the corrected CHECK passes
|
||||||
|
if [ "$fail" -eq 0 ]; then
|
||||||
|
echo "OK corrected work intact — verdict 0"
|
||||||
|
else
|
||||||
|
echo "FAIL corrected work NOT intact — verdict 1"
|
||||||
|
fi
|
||||||
|
exit "$fail"
|
||||||
Reference in new issue
Block a user