# Landmark Attention Eval

> Evaluates a transformer variant's ability to retrieve relevant past context blocks and maintain language modeling performance over extended sequence lengths. It probes long-range dependency retention and random-access memory retrieval capabilities compared to standard and recurrent transformer baselines. Use when the user wants to benchmark on PG-19, arXiv math papers, RedPajama (subset), or asks about evaluating this task. Reports perplexity.

- Skill: `qhjqhj00/landmark-attention-eval` (Agent Skill)
- Install (CLI): `npx skillmds add qhjqhj00/landmark-attention-eval`
- Raw SKILL.md: https://api.skillmd.com/api/skills/qhjqhj00/landmark-attention-eval/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: qhjqhj00 (https://skillmd.com/u/qhjqhj00)
- Updated: 2026-09-08
- Page: https://skillmd.com/skills/qhjqhj00/landmark-attention-eval

---


# landmark-attention-eval

> Landmark Attention: Random-Access Infinite Context Length for Transformers — Mohtanami et al. (2023) (arXiv:2305.16300, 2023)

## What this evaluates

Evaluates a transformer variant's ability to retrieve relevant past context blocks and maintain language modeling performance over extended sequence lengths. It probes long-range dependency retention and random-access memory retrieval capabilities compared to standard and recurrent transformer baselines.

## Datasets

- **PG-19** — total ?; splits: test (-1)
- **arXiv math papers** — total ?; splits: test (-1)
- **RedPajama (subset)** — total ?; splits: fine-tuning (-1); repo https://github.com/togethercomputer/RedPajama-Data

## Metrics

- `perplexity` **(primary)** — range: other
  - Standard language modeling metric: exp(mean(-log_softmax(logits) * one_hot(targets))). Lower values indicate better performance.
- `pass key accuracy` — range: [0, 1]
  - Proportion of prompts where the model correctly outputs the hidden integer pass key within the first 100 generated tokens. Averaged over 50 random pass key generations and positions.

## Input / output format

**Input**: Text segments divided into chunks of length l_local (e.g., 250 tokens) with landmark tokens inserted. For retrieval evaluation: prompts containing a prefix filler, a randomly generated pass key at a random position, and a suffix filler.

**Output**: Next-token probability distribution (for perplexity) or the generated integer pass key (for retrieval accuracy).

## Scoring recipe

```python
# Perplexity
perplexity = exp(mean(-log_softmax(logits) * one_hot(targets)))

# Pass key accuracy
correct = 0
for prompt in prompts:
    generated = model.generate(prompt, max_new_tokens=100)
    predicted_key = extract_first_integer(generated)
    if predicted_key == prompt.pass_key:
        correct += 1
accuracy = correct / len(prompts)
```

## Common pitfalls

- Confusing local context length (l_local) with total effective context length, which includes retrieved blocks and landmark tokens.
- Assuming retrieval accuracy is computed over a fixed dataset split; it is actually averaged over 50 random generations of the pass key and its position.
- Overlooking that evaluating contexts >2048 tokens requires KV cache offloading to CPU, which affects memory but not the metric itself.

## Evidence (verbatim from paper)

> Table 1 presents the perplexity of the trained models under various inference settings. ... compute the accuracy of generating the correct pass key (as the first integer within the first 100 generated tokens).

## Citation

```bibtex
@misc{mohtanami2023landmark,
  title={Landmark Attention: Random-Access Infinite Context Length for Transformers},
  author={Mohtanami et al. (2023)},
  year={2023},
  note={arXiv:2305.16300}
}
```

- arXiv: 2305.16300

