From bc94fdabd0ec7362a68f38aa8cbb0b80f818f243 Mon Sep 17 00:00:00 2001 From: Matthw Honnibal Date: Thu, 21 May 2020 20:46:21 +0200 Subject: [PATCH] Fix begin_training --- spacy/pipeline/pipes.pyx | 12 ++++++++---- spacy/syntax/nn_parser.pyx | 18 +++++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/spacy/pipeline/pipes.pyx b/spacy/pipeline/pipes.pyx index 00c8894fd..f75ed1659 100644 --- a/spacy/pipeline/pipes.pyx +++ b/spacy/pipeline/pipes.pyx @@ -532,10 +532,14 @@ class Tagger(Pipe): exc=vocab.morphology.exc) self.set_output(len(self.labels)) doc_sample = [Doc(self.vocab, words=["hello", "world"])] - for name, component in pipeline: - if component is self: - break - doc_sample = list(component.pipe(doc_sample)) + if pipeline is not None: + for name, component in pipeline: + if component is self: + break + if hasattr(component, "pipe"): + doc_sample = list(component.pipe(doc_sample)) + else: + doc_sample = [component(doc) for doc in doc_sample] self.model.initialize(X=doc_sample) # Get batch of example docs, example outputs to call begin_training(). # This lets the model infer shapes. diff --git a/spacy/syntax/nn_parser.pyx b/spacy/syntax/nn_parser.pyx index ed4697302..f8e819268 100644 --- a/spacy/syntax/nn_parser.pyx +++ b/spacy/syntax/nn_parser.pyx @@ -630,11 +630,19 @@ cdef class Parser: if len(doc): doc_sample.append(doc) gold_sample.append(gold) - for name, component in pipeline: - if component is self: - break - doc_sample = list(component.pipe(doc_sample)) - self.model.initialize(doc_sample, gold_sample) + + if pipeline is not None: + for name, component in pipeline: + if component is self: + break + if hasattr(component, "pipe"): + doc_sample = list(component.pipe(doc_sample)) + else: + doc_sample = [component(doc) for doc in doc_sample] + if doc_sample: + self.model.initialize(doc_sample) + else: + self.model.initialize() if pipeline is not None: self.init_multitask_objectives(get_examples, pipeline, sgd=sgd, **self.cfg) link_vectors_to_models(self.vocab)