Skip to main content

spacy-coref

Lightweight, fast co-reference resolution using a distilled version of AllenNLP's coreference model (exported to ONNX).

✨ Features

  • 🧠 Cross-lingual coreference resolution
  • 🪶 Lightweight model based on AllenNLP’s coref modeling
  • ⚡ Fast inference via ONNX
  • 🔌 Easy integration with spaCy

📦 Installation

$ pip install spacy-coref

🚀 Quickstart

Usage as a standalone component

from spacy_coref import CoreferenceResolver, decode_clusters

resolver = CoreferenceResolver.from_pretrained("talmago/allennlp-coref-onnx-mMiniLMv2-L12-H384-distilled-from-XLMR-Large")

sentences = [
    ["Barack", "Obama", "was", "the", "44th", "President", "of", "the", "United", "States", "."],
    ["He", "was", "born", "in", "Hawaii", "."]
]

pred = resolver(sentences)

print(decode_clusters(sentences, pred["clusters"][0]))

# Output is:
# [['Barack Obama', 'He']]

Usage with spaCy

import spacy

from spacy_coref import create_coref_minilm_component

nlp = spacy.load("en_core_web_sm")
nlp.add_pipe("coref_minilm")

doc = nlp("Barack Obama was born in Hawaii. He was elected president in 2008.")
print(doc._.coref_clusters[0])
print(doc._.cluster_heads)
print(doc._.resolved_text)

# Output is:
# [Barack Obama, He]
# {'Barack Obama': Barack Obama}
# Barack Obama was born in Hawaii. Barack Obama was elected president in 2008.

🛠️ Development

Set up virtualenv

$ make env

Set PYTHONPATH

$ export PYTHONPATH=$PYTHONPATH:/Users/talmago/git/spacy-coref/src

Code formatting

$ make format

📚 References

This project builds on the work of the following repositories:

Metadata

Release files for spacy-coref 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spacy-coref 0.1.1
File Size Uploaded
spacy_coref-0.1.1.tar.gz 6.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for spacy-coref 0.1.1
File Interpreter ABI Platform
spacy_coref-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 14.0 kB

Release files / spacy_coref-0.1.1.tar.gz

Download URL spacy_coref-0.1.1.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c341874afcee1da057fc0c5c02045168d351506c2ee85246a769e247f5462014
BLAKE2b-256 checksum
How to use checksums
772f5268afd914f10e95c7f58c07f9b63d7f333e885a4c20cca0e7f1a0e3b235
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.11.13 Linux/6.11.0-1018-azure

Release files / spacy_coref-0.1.1-py3-none-any.whl

Download URL spacy_coref-0.1.1-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a3aed60ac4416e25f562b4717981f106eb79b63e76478df69b4c09e125ea17fa
BLAKE2b-256 checksum
How to use checksums
070583d719559b4ca6f143665603d6260a7813bda749229153c45a1449b0df7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.11.13 Linux/6.11.0-1018-azure

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page