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:
-
crosslingual-coreference
David Berenstein's implementation of multilingual coreference resolution, adapted from the original AllenNLP coref model.
GitHub: davidberenstein1957/crosslingual-coreference -
AllenNLP coreference model
Official AllenNLP implementation of coreference resolution.
GitHub: allenai/allennlp-models
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| spacy_coref-0.1.1.tar.gz | 6.4 kB | Without provenance | Details for spacy_coref-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| spacy_coref-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for spacy_coref-0.1.1-py3-none-any.whl |
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
|
Security for spacy-coref 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.