liveBook · Manning

Coreferee

As explained in Natural Language Processing in Action, Second Edition

Coreferee is a spaCy pipeline extension that performs transformer-based coreference resolution.

Coreferee is a custom spaCy pipeline extension for coreference resolution: it groups mentions such as “Gebru” and “she” when they refer to the same entity. Its transformer-based models address difficult cases, including cataphora, where a pronoun appears before its antecedent. section 11.5.1 section 11.5

A practical setup and integration path is:

  • Create a separate virtual environment because Coreferee requires spaCy 3.0.0–3.5.4 and may conflict with environments using spaCy 3.7.5. section 11.5.1
  • Install a transformer language model, add the Coreferee pipeline to spaCy, and process text with the resulting NLP object. section 11.5.1
  • Inspect results through the document’s `_.coref_chains` extension and its printable chain representation. section 11.5.1
  • Treat predictions as a difficult natural-language-understanding capability rather than automatic proof of commonsense reasoning. section 11.5

Resolving mentions in a Wikipedia excerpt

Load `en_core_web_trf`, add `coreferee`, and process a Timnit Gebru excerpt. The resulting chains can identify `Gebru(13), she(16), she(26), she(34)` and `advice(51), it(56)`, making the model’s intermediate output inspectable. section 11.5.1

Listing 11.4 Coreference chains from Wikipedia text
>>> import spacy, coreferee                   #1
>>> nlptrf = spacy.load('en_core_web_trf')
>>> nlptrf.add_pipe('coreferee')
<coreferee.manager.CorefereeBroker at 0x...>
>>> doc_gebru = nlptrf(text_gebru)            #2
>>> doc_gebru._.coref_chains
[0: [13], [16], [26], [34],
 1: [51], [56]]
>>> doc_gebru._.coref_chains.print()
0: Gebru(13), she(16), she(26), she(34)    #3
1: advice(51), it(56)

Browse the runnable spaCy setup and printed coreference chains for a concrete integration pattern. section 11.5.1

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Explains installation, pipeline integration, and chain inspection, but defers training details and broader commonsense reasoning.
Examples
Uses a Timnit Gebru Wikipedia excerpt, pronoun chains, cataphora, and the Winograd schema sentence about councilmen and demonstrators.
What it assumes
Assumes Python and spaCy familiarity, while teaching environment setup, transformer model installation, and pipeline registration.
What you can do after
Operate Coreferee through spaCy, process documents, and inspect predicted coreference chains for downstream analysis.
How it connects
Connects spaCy pipelines, transformer language models, RoBERTa, natural-language understanding, and knowledge graphs.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.