From 1baa334b8a49c8dd7b821af5ba3dc6fae6be02de Mon Sep 17 00:00:00 2001 From: Paul O'Leary McCann Date: Tue, 12 Jul 2022 14:07:40 +0900 Subject: [PATCH] Make get_clusters_from_doc return spans in order There's no guarantee about the order in which SpanGroup keys will come out, so access them in sorted order when doing comparisons. --- spacy/ml/models/coref_util.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spacy/ml/models/coref_util.py b/spacy/ml/models/coref_util.py index 1a6bc6364..e37436009 100644 --- a/spacy/ml/models/coref_util.py +++ b/spacy/ml/models/coref_util.py @@ -147,7 +147,9 @@ def get_clusters_from_doc(doc) -> List[List[Tuple[int, int]]]: ints are char spans, to be tokenization independent. """ out = [] - for key, val in doc.spans.items(): + keys = sorted(list(doc.spans.keys())) + for key in keys: + val = doc.spans[key] cluster = [] for span in val: