Coreference Resolution › Long-Document Coreference
Language AI HandbookAll chapters Long documents break the standard formulation in two different places, and mixing them up leads to bad engineering decisions.
A full-document dense attention layer evaluates a quadratic number of token pairs. The resolver's own search is also quadratic when it scores all span pairs. Restricting the resolver's search does not affect the encoder computation.
The Three Costs
Separate them explicitly:
- Encoding cost. Producing contextual representations for tokens. Dense self-attention scores position pairs per head and layer. At , one explicitly stored matrix contains entries, which occupy 0.2 GB at two bytes per entry. Twelve such matrices in one layer occupy 2.4 GB. Retaining the matrices from all 12 layers simultaneously would use 28.8 GB in total for these matrices alone. This is an accounting example. Actual peak memory depends on kernel implementation, tensor lifetime, batching, and other activations.
- Span scoring cost. span scores per document, which is linear in and usually cheap.
- Pair scoring cost. The fine scorer evaluates at most pairs after pruning. A separate coarse pass over all retained spans can still evaluate up to pairs.
A resolver can be bounded while the encoder is not. When someone says "our model handles arbitrarily long documents," ask which of the three costs they are talking about. A bounded entity memory answers only the third. A sliding window bounds encoding and direct local candidate search within each window. A sparse or hierarchical encoder changes the first cost but leaves the candidate search unchanged.
Windowing
One long-document strategy resolves mentions within chunks and then stitches the resulting clusters. A direct local edge requires both mentions in the same window. Overlapping windows can still merge distant mentions into a cluster through a shared mention.
Overlap allows some pairs on opposite sides of a chunk boundary to be scored together. A window of tokens with stride overlaps its neighbor by tokens for . The maximum achievable distance between any two positions in a single window is when the document has tokens and a window starts at position zero. This equals when and when the first window is truncated. For a particular earlier token, the farthest visible later token lies at the end of the latest window that contains that earlier token. Both distance and position relative to the window grid determine visibility.
For this calculation, windows start at and the final windows are truncated at the document end. Count each pair once by its earlier token. For , dividing by the number of distinct pairs gives the probability of joint visibility under a uniform draw.
PythonIn [5]Expand
def jointly_visible_pairs(tokens, width, stride):
"""Count unordered position pairs sharing at least one fixed-grid window."""
if not 1 <= stride <= width:
raise ValueError("Expected stride between 1 and width")
return sum(
min(tokens, (earlier // stride) * stride + width) - earlier - 1
for earlier in range(tokens)
)
def visible_fraction(tokens, width, stride):
if tokens < 2:
raise ValueError("A distinct token pair requires at least two tokens")
return jointly_visible_pairs(tokens, width, stride) / math.comb(tokens, 2)
windowing = pd.DataFrame(
[
{
"window": width,
"stride": stride,
"overlap": width - stride,
"visible_pair_fraction_T10000": round(
visible_fraction(10_000, width, stride), 4
),
}
for width, stride in [(512, 512), (512, 256), (512, 128), (1024, 512)]
]
)| window | stride | overlap | visible_pair_fraction_T10000 | |
|---|---|---|---|---|
| 0 | 512 | 512 | 0 | 0.0505 |
| 1 | 512 | 256 | 256 | 0.0754 |
| 2 | 512 | 128 | 384 | 0.0875 |
| 3 | 1024 | 512 | 512 | 0.1476 |
The table measures a geometric limit of fixed windows under uniform sampling. Real mentions occupy spans and their candidate antecedents have a different distance distribution. On annotated documents, measure the fraction of gold links whose two full spans share a window, broken down by distance. A separate entity memory or cross-window linking step can give access to pairs outside this local search.
Bounded Entity Memory
Toshniwal et al. (2020) first encode the document and propose mention spans. Their bounded models process the proposals left to right and score each against up to active entity slots. A proposal can join an existing cluster, start a new cluster, or be ignored as invalid or because of capacity. When memory is full, admitting a new cluster requires evicting an existing one. For proposals, this takes at most slot comparisons, compared with comparisons for exhaustive span pairing.
At spans and , that is about 64 million slot interactions instead of roughly 500 billion span pairs.
PythonIn [7]Expand
memory_span_width = 10
memory_table = []
for T in (1_000, 10_000, 100_000):
M = memory_span_width * T - memory_span_width * (memory_span_width - 1) // 2
memory_table.append(
{
"tokens": T,
"candidate_spans": M,
"all_pairs": math.comb(M, 2),
"slot_interaction_upper_bound_K64": M * 64,
}
)
memory_table = pd.DataFrame(memory_table)| tokens | candidate_spans | all_pairs | slot_interaction_upper_bound_K64 | |
|---|---|---|---|---|
| 0 | 1000 | 9955 | 49546035 | 637120 |
| 1 | 10000 | 99955 | 4995451035 | 6397120 |
| 2 | 100000 | 999955 | 499954501035 | 63997120 |
A fixed slot budget supports streaming resolution when encoder working memory and input handling also support it.
- Encoder cost. A layer's contextual representations require storage for vectors of width when materialized. Dense self-attention computes quadratically many query-key scores, and storing the full score matrix uses quadratic space. Tiled attention can avoid materializing that matrix.
- It does not guarantee retrieval quality. If the slot holding the correct antecedent was evicted at token 40,000, no scoring function recovers it at token 90,000. Quality depends on the eviction policy, the number of slots, and the training procedure, none of which the bound constrains.
- Entity retention. When the slots fill, the eviction policy determines which entity records remain available for later mentions.
Distance Slices
For a distance diagnostic, group gold anaphors by the distance to their nearest earlier gold cluster mate. State whether distance is measured in tokens or sentences. In each group, report how many anaphors were retained, how many retained anaphors still had any earlier gold candidate, and how often the fine scorer chose a gold link when one was available. Report group sizes and document lengths. These measurements can locate losses a distance curve alone leaves ambiguous.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!