From 01ace9734d776a53cd835d482692e11f748d722a Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Fri, 29 Jun 2018 19:21:38 +0200 Subject: [PATCH] Make pipeline work on empty docs --- spacy/pipeline.pyx | 2 +- spacy/syntax/nn_parser.pyx | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/spacy/pipeline.pyx b/spacy/pipeline.pyx index faea20935..edc793158 100644 --- a/spacy/pipeline.pyx +++ b/spacy/pipeline.pyx @@ -482,7 +482,7 @@ class Tagger(Pipe): if lemma != 0 and lemma != doc.c[j].lex.orth: doc.c[j].lemma = lemma idx += 1 - if tensors is not None: + if tensors is not None and len(tensors): if isinstance(doc.tensor, numpy.ndarray) \ and not isinstance(tensors[i], numpy.ndarray): doc.extend_tensor(tensors[i].get()) diff --git a/spacy/syntax/nn_parser.pyx b/spacy/syntax/nn_parser.pyx index 21ee603a3..91e4b6852 100644 --- a/spacy/syntax/nn_parser.pyx +++ b/spacy/syntax/nn_parser.pyx @@ -217,6 +217,8 @@ cdef class Parser: def predict(self, docs, beam_width=1, beam_density=0.0, drop=0.): if isinstance(docs, Doc): docs = [docs] + if not any(len(doc) for doc in docs): + return self.moves.init_batch(docs) if beam_width < 2: return self.greedy_parse(docs, drop=drop) else: