# Coreference resolution

> Group every mention of the same entity: score each span as a mention, score its earlier spans plus a dummy “no antecedent” at 0, pick by softmax, and read the clusters off the links.

Source: https://www.mlfoundry.in/learn/coreference-resolution  
Section: Deep Learning › Deep Learning for NLP  
Level: advanced · 8 min read · updated 2026-10-15

**Coreference resolution:** is the task of finding every span of a document that refers to some entity (a **mention**) and partitioning the mentions into **clusters**, one per entity. The standard neural approach is the end-to-end span-ranking model of Lee, He, Lewis and Zettlemoyer (EMNLP 2017), which learns mention detection and antecedent linking jointly from raw text.

## The task

Input: a document. Output: a set of clusters. In “Alice called Bob because she needed his car. He lent it to her.” the clusters are {Alice, she, her}, {Bob, his, He} and {his car, it}. Mentions can nest: “his” sits inside “his car” and belongs to a different entity.

It is hard because the cues are scattered. Gender and number agreement rule out some links, but choosing between two compatible candidates often needs world knowledge. In “The trophy doesn't fit in the suitcase because it is too big”, only physical knowledge says “it” is the trophy. This is the Winograd schema (Levesque et al. 2012).

Before deep learning came Hobbs' (1978) syntactic search for pronoun antecedents, then mention-pair classifiers over hand-built features (Soon, Ng and Lim 2001), then the deterministic multi-pass sieve of Stanford (Raghunathan et al. 2010). They all depended on a parser and a separate mention detector, so errors there could not be fixed later.

## End-to-end span ranking

Lee et al. drop the pipeline. They consider every span up to $L=10$ words, give each one a vector, and let one network decide both whether it is a mention and which earlier span it points to. Each span $i$ picks an **antecedent** $y_i\in\mathcal{Y}(i)=\{\varepsilon,1,\dots,i-1\}$, where the dummy $\varepsilon$ means “not a mention, or the first mention of its entity”.

> Figure: The span-ranking pipeline on the example text. Each span becomes $g_i$; a mention score prunes the candidates; each surviving span scores all earlier spans and the dummy ε at 0; argmax links form the clusters. For “it”, the pair score with “his car” is 0.4 + 0.7 − 0.4 = 0.7, which wins the softmax with 0.516.

$$
g_i=\big[\,x^*_{\mathrm{START}(i)},\;x^*_{\mathrm{END}(i)},\;\hat x_i,\;\phi(i)\,\big],\qquad s_m(i)=w_m\cdot\mathrm{FFNN}_m(g_i)
$$

- $x^*_t$: contextual state of token $t$ (a BiLSTM in 2017; BERT or SpanBERT later)
- $\hat x_i$: attention-weighted sum of the span's word embeddings, a learned soft head word
- $\phi(i)$: embedding of the span width
- $s_m(i)$: mention score: how likely span $i$ is a mention at all

$$
s(i,j)=s_m(i)+s_m(j)+s_a(i,j),\quad s(i,\varepsilon)=0,\qquad P(y_i=j)=\frac{e^{s(i,j)}}{\sum_{j'\in\mathcal{Y}(i)}e^{s(i,j')}}
$$

- $s_a(i,j)$: antecedent score, $w_a\cdot\mathrm{FFNN}_a([g_i,g_j,g_i\circ g_j,\phi(i,j)])$; $\phi(i,j)$ holds speaker, genre and distance features
- $s(i,\varepsilon)=0$: fixed dummy score: a link is predicted only if some pair score is positive

There is no gold antecedent for each span, only gold clusters. So the loss marginalises over every correct choice:

$$
\mathcal{L}=-\sum_{i}\log\!\!\sum_{\hat y\in\mathcal{Y}(i)\cap\mathrm{GOLD}(i)}\!\!P(\hat y)
$$

- $\mathrm{GOLD}(i)$: earlier spans in the gold cluster of $i$; $\{\varepsilon\}$ if $i$ is not a mention or opens its cluster

Scoring all pairs of all spans would be $O(T^4)$ in document length $T$. Two prunes make it tractable: keep only the $\lambda T$ spans with the highest $s_m$ ($\lambda=0.4$), and let each consider at most $K=250$ antecedents. Clusters are the connected components of the argmax links.

**Data, metrics and reference scores**

- **Benchmark:** CoNLL-2012 shared task on English OntoNotes 5.0 (Pradhan et al. 2012): 2,802 train, 343 dev, 348 test documents across news, broadcast, conversation, web and other genres. Singletons are not annotated.
- **MUC:** Vilain et al. 1995. Link-based: counts the links needed to join the response's pieces of each key cluster.
- **B³:** Bagga and Baldwin 1998. Mention-based: per-mention precision and recall of its cluster's overlap, averaged.
- **CEAF$_{\phi_4}$:** Luo 2005. Entity-based: best one-to-one alignment of key and response clusters, similarity $\phi_4=2|K\cap R|/(|K|+|R|)$.
- **CoNLL F1:** Mean of the three F1 scores, the headline number.
- **Test CoNLL F1:** Lee et al. 2017: 67.2 (single), 68.8 (ensemble). Lee et al. 2018 (coarse-to-fine, ELMo): 73.0. BERT-large (Joshi et al. 2019): 76.9. SpanBERT-large (Joshi et al. 2020): 79.6.

> Figure: The span-ranking decision on the example text with hand-set scores. At shift Δ = 0 every argmax matches gold and CoNLL F1 is 100; “it” puts 0.516 on “his car” and 0.256 on ε (loss 0.662). Δ = +0.25 lets “his car” link to Bob (0.7 + 1.0 − 2.0 + 0.5 = 0.2 > 0), merging two entities: MUC F1 90.9, B³ 82.4, CEAFφ4 70.0, CoNLL 81.1. Δ = +0.75 merges everything into one cluster (CoNLL 53.9) while MUC recall stays 100. Δ = −0.5 drops the it → his car link (CoNLL 84.9).

## Worked example: the antecedent of “it”

s_m(it) = 0.4, shift Δ = 0. P is the softmax over the seven scores.

| candidate j | $s_m(j)$ | $s_a(\text{it},j)$ | $s(\text{it},j)$ | $P(y=j)$ |
| --- | --- | --- | --- | --- |
| $\varepsilon$ | — | — | 0 (fixed) | 0.256 |
| Alice | 1.0 | −3.5 | −2.1 | 0.031 |
| Bob | 1.0 | −2.4 | −1.0 | 0.094 |
| she | 0.8 | −3.5 | −2.3 | 0.026 |
| his | 0.6 | −3.0 | −2.0 | 0.035 |
| his car | 0.7 | −0.4 | 0.7 | 0.516 |
| He | 0.8 | −3.0 | −1.8 | 0.042 |

The argmax is “his car”, the gold antecedent, so the loss for this span is $-\ln 0.516=0.662$. For “her” two gold antecedents exist, Alice (0.377) and she (0.508). The loss sums them, $-\ln 0.885=0.122$, so the model is not penalised for spreading mass across correct choices. Averaged over all eight mentions the loss is 0.299.

**Scoring the over-merged output at Δ = +0.25**

1. Response: {Alice, she, her} and {Bob, his, his car, He, it}. Key: {Alice, she, her}, {Bob, his, He}, {his car, it}.
2. MUC: no key link is missing, so recall is $5/5=1$. The big response cluster spans 2 key clusters, so it has $5-2=3$ of its 4 links right. Precision is $(2+3)/(2+4)=0.833$ and F1 is 0.909.
3. B³: recall is 1. Precision is $\big(3^2/3+(3^2+2^2)/5\big)/8=5.6/8=0.700$, so F1 is 0.824.
4. CEAF$_{\phi_4}$: the best alignment pairs {Alice, she, her} with itself ($\phi_4=1$) and {Bob, his, He} with the big cluster ($\phi_4=6/8=0.75$). The total is 1.75, so recall is $1.75/3=0.583$, precision is $1.75/2=0.875$, and F1 is 0.700.
5. CoNLL F1 $=(90.9+82.4+70.0)/3=81.1$.

```python
import torch
import torch.nn.functional as F

def antecedent_loss(s_m, s_a, gold):
    """s_m: (N,) mention scores; s_a: (N, N) antecedent scores, only j < i used;
    gold: (N, N+1) bool, column 0 = dummy antecedent. Returns loss and argmax links."""
    N = s_m.size(0)
    pair = s_m[:, None] + s_m[None, :] + s_a                      # s(i, j)
    earlier = torch.ones(N, N).tril(-1).bool()
    pair = pair.masked_fill(~earlier, float("-inf"))
    scores = torch.cat([torch.zeros(N, 1), pair], dim=1)            # s(i, eps) = 0
    logp = F.log_softmax(scores, dim=1)
    marg = torch.logsumexp(logp.masked_fill(~gold, float("-inf")), dim=1)
    return -marg.mean(), scores.argmax(dim=1) - 1                   # -1 means eps

# Alice Bob she his "his car" He it her
s_m = torch.tensor([1.0, 1.0, 0.8, 0.6, 0.7, 0.8, 0.4, 0.8])
lower = [[-3.2], [0.5, -2.5], [-2.5, 0.2, -2.8], [-3.0, -2.0, -3.0, -3.5],
         [-2.6, 0.4, -3.0, 0.6, -3.2], [-3.5, -2.4, -3.5, -3.0, -0.4, -3.0],
         [0.1, -2.8, 0.6, -2.9, -3.5, -3.1, -3.6]]
s_a = torch.zeros(8, 8)
for i, row in enumerate(lower, start=1):
    s_a[i, :i] = torch.tensor(row)

gold = torch.zeros(8, 9, dtype=torch.bool)
for cluster in [[0, 2, 7], [1, 3, 5], [4, 6]]:
    for k, i in enumerate(cluster):
        gold[i, 0] = k == 0                     # first mention: eps is correct
        for j in cluster[:k]:
            gold[i, j + 1] = True

loss, ante = antecedent_loss(s_m, s_a, gold)
print(ante.tolist())         # [-1, -1, 0, 1, -1, 1, 4, 2]
print(round(loss.item(), 3)) # 0.299
```

The antecedent softmax and marginal loss in PyTorch, on the toy scores above (torch was not available, so this was not run; the printed values were checked with the same maths in plain Python)

> **MUC rewards over-merging:** MUC only counts links, so putting every mention in one cluster keeps recall at 100 and precision at 71.4: 83.3 F1 in the figure at Δ = +0.75, where B³ falls to 51.2 and CEAF$_{\phi_4}$ to 27.3. That is why the CoNLL score averages three metrics with different biases.

> **The dummy score is a learned threshold:** Fixing $s(i,\varepsilon)=0$ costs nothing: the network can shift every $s_m$ and $s_a$ instead. The mention score enters every pair score, so a span that is not a mention gets low scores to all candidates and falls back to $\varepsilon$. That is how one softmax does both mention detection and linking.

**Strengths**

- No parser or separate mention detector; one model, one loss
- Swapping the encoder (BiLSTM → BERT → SpanBERT) lifted CoNLL F1 from 67.2 to 79.6 with the same head
- Marginal loss needs only gold clusters, not one chosen antecedent per mention

**Limitations**

- Span enumeration is quadratic in length, so long documents need pruning or segmenting
- Decisions are local (one antecedent per span); a cluster can become inconsistent through chains of links
- Winograd-style cases still need world knowledge that local features lack

**Question:** A span has pair scores −0.3, −1.2 and −2.0 to its three candidate antecedents. What does the model predict?

- A. The candidate scoring −0.3
- B. ε: no antecedent, because every pair score is below the dummy score 0
- C. A random candidate
- D. It depends on the gold cluster

**Answer:** B. ε: no antecedent, because every pair score is below the dummy score 0 — $s(i,\varepsilon)=0$ is always in the softmax. With every pair score negative, $\varepsilon$ has the largest probability, so the span is treated as not a mention or as the first mention of a new entity.

**Question:** Why does the loss sum P over all gold antecedents instead of picking the nearest one?

- A. To make training faster
- B. Gold data has only clusters, and any earlier mention of the same entity is a correct antecedent
- C. Because the softmax would otherwise be undefined
- D. To penalise long-distance links

**Answer:** B. Gold data has only clusters, and any earlier mention of the same entity is a correct antecedent — OntoNotes gives clusters, not links. For “her”, both Alice and she are correct, so the model gets credit for the mass on either: $P=0.377+0.508=0.885$, loss 0.122.

**Key points**

- Each span picks an antecedent from $\{\varepsilon,1,\dots,i-1\}$ by softmax over $s(i,j)=s_m(i)+s_m(j)+s_a(i,j)$, with $s(i,\varepsilon)=0$.
- Spans are $[x^*_{\text{start}},x^*_{\text{end}},\hat x,\phi]$; pruning keeps $\lambda T$ spans ($\lambda=0.4$) and up to $K=250$ antecedents.
- Loss: −log of the total probability on correct antecedents, so only gold clusters are needed.
- Evaluated on CoNLL-2012 (OntoNotes 5.0) by the mean F1 of MUC, B³ and CEAFφ4; 67.2 in 2017, 79.6 with SpanBERT.
- Each metric has a bias (MUC favours merging), which is why the three are averaged.

---

From MLFoundry (https://www.mlfoundry.in). The web page adds interactive figures and diagrams.
