From 228bbf506dc5a76b6fdef5d9aa45ad0bf7b577c5 Mon Sep 17 00:00:00 2001 From: Ines Montani Date: Thu, 12 Sep 2019 18:02:44 +0200 Subject: [PATCH] Improve label properties on pipes --- spacy/pipeline/pipes.pyx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/spacy/pipeline/pipes.pyx b/spacy/pipeline/pipes.pyx index da376c396..3d799b3da 100644 --- a/spacy/pipeline/pipes.pyx +++ b/spacy/pipeline/pipes.pyx @@ -1062,8 +1062,15 @@ cdef class DependencyParser(Parser): @property def labels(self): + labels = set() # Get the labels from the model by looking at the available moves - return tuple(set(move.split("-")[1] for move in self.move_names if "-" in move)) + for move in self.move_names: + if "-" in move: + label = move.split("-")[1] + if "||" in label: + label = label.split("||")[1] + labels.add(label) + return tuple(sorted(labels)) cdef class EntityRecognizer(Parser): @@ -1098,8 +1105,9 @@ cdef class EntityRecognizer(Parser): def labels(self): # Get the labels from the model by looking at the available moves, e.g. # B-PERSON, I-PERSON, L-PERSON, U-PERSON - return tuple(set(move.split("-")[1] for move in self.move_names - if move[0] in ("B", "I", "L", "U"))) + labels = set(move.split("-")[1] for move in self.move_names + if move[0] in ("B", "I", "L", "U")) + return tuple(sorted(labels)) class EntityLinker(Pipe):