From 3786942ff10de2c5144daa963d103a6549145db7 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Fri, 29 Jun 2018 15:13:45 +0200 Subject: [PATCH] Fix tagger when docs are empty --- spacy/pipeline.pyx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spacy/pipeline.pyx b/spacy/pipeline.pyx index ed4e4c066..339bf4f1c 100644 --- a/spacy/pipeline.pyx +++ b/spacy/pipeline.pyx @@ -449,7 +449,8 @@ class Tagger(Pipe): def predict(self, docs): if not any(len(doc) for doc in docs): # Handle case where there are no tokens in any docs. - return [self.model.ops.allocate((0, self.model.nO)) for doc in docs] + n_labels = len(self.labels) + return [self.model.ops.allocate((0, n_labels)) for doc in docs] tokvecs = self.model.tok2vec(docs) scores = self.model.softmax(tokvecs) guesses = []