Coreference Resolution › Long-Document Coreference

Michael BrenndoerferNovember 17, 20266 min read
Language AI HandbookAll chapters
Part 9 of 67Coreference, Discourse, Pragmatics, and Dialogue
Chapter 56Coreference Resolution › Long-Document Coreference
Reading section 7 of 14 · Long-Document Coreference · 6 minSection 7 of 14 · 6 min

Section 7 of 14 · 6 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

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 TT tokens. Dense self-attention scores T2T^2 position pairs per head and layer. At T=10,000T=10{,}000, one explicitly stored matrix contains 10810^8 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. O(WT)O(WT) span scores per document, which is linear in TT and usually cheap.
  • Pair scoring cost. The fine scorer evaluates at most Mmax⁡KM_{\max}K pairs after pruning. A separate coarse pass over all retained spans can still evaluate up to Mmax⁡(Mmax⁡−1)/2M_{\max}(M_{\max}-1)/2 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 WW tokens with stride ss overlaps its neighbor by W−sW-s tokens for 1≤s≤W1 \le s \le W. The maximum achievable distance between any two positions in a single window is min⁡(T,W)−1\min(T,W)-1 when the document has T≥1T\geq1 tokens and a window starts at position zero. This equals W−1W-1 when T≥WT\geq W and T−1T-1 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 0,s,2s,…0,s,2s,\ldots and the final windows are truncated at the document end. Count each pair once by its earlier token. For T≥2T \geq 2, dividing by the number of distinct pairs gives the probability of joint visibility under a uniform draw.

PythonIn [5]
CollapseExpand
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)]
    ]
)
Out[6]:
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 KK 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 MM proposals, this takes at most MKMK slot comparisons, compared with M(M−1)/2M(M-1)/2 comparisons for exhaustive span pairing.

At M=999,955M = 999{,}955 spans and K=64K = 64, that is about 64 million slot interactions instead of roughly 500 billion span pairs.

PythonIn [7]
CollapseExpand
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)
Out[8]:
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 TT vectors of width dd 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!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy