From bc97bc292ce6b7349d3948cb6d0471aab686b29c Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sun, 28 May 2017 08:11:58 -0500 Subject: [PATCH] Fix __call__ method --- spacy/language.py | 2 +- spacy/pipeline.pyx | 10 +++++----- spacy/syntax/nn_parser.pyx | 5 +++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/spacy/language.py b/spacy/language.py index 7adae0ed5..9dde3c1a9 100644 --- a/spacy/language.py +++ b/spacy/language.py @@ -192,7 +192,7 @@ class Language(object): name = getattr(proc, 'name', None) if name in disable: continue - proc(doc) + doc = proc(doc) return doc def update(self, docs, golds, drop=0., sgd=None, losses=None): diff --git a/spacy/pipeline.pyx b/spacy/pipeline.pyx index 724891c9b..95d4a144d 100644 --- a/spacy/pipeline.pyx +++ b/spacy/pipeline.pyx @@ -73,17 +73,16 @@ class TokenVectorEncoder(object): self.doc2feats = doc2feats() self.model = model - def __call__(self, docs): + def __call__(self, doc): """Add context-sensitive vectors to a `Doc`, e.g. from a CNN or LSTM model. Vectors are set to the `Doc.tensor` attribute. docs (Doc or iterable): One or more documents to add vectors to. RETURNS (dict or None): Intermediate computations. """ - if isinstance(docs, Doc): - docs = [docs] - tokvecses = self.predict(docs) - self.set_annotations(docs, tokvecses) + tokvecses = self.predict([doc]) + self.set_annotations([doc], tokvecses) + return doc def pipe(self, stream, batch_size=128, n_threads=-1): """Process `Doc` objects as a stream. @@ -169,6 +168,7 @@ class NeuralTagger(object): def __call__(self, doc): tags = self.predict([doc.tensor]) self.set_annotations([doc], tags) + return doc def pipe(self, stream, batch_size=128, n_threads=-1): for docs in cytoolz.partition_all(batch_size, stream): diff --git a/spacy/syntax/nn_parser.pyx b/spacy/syntax/nn_parser.pyx index 095dcc5e7..6723821d7 100644 --- a/spacy/syntax/nn_parser.pyx +++ b/spacy/syntax/nn_parser.pyx @@ -305,8 +305,9 @@ cdef class Parser: Returns: None """ - states = self.parse_batch([doc], doc.tensor) - self.set_annotations(doc, states[0]) + states = self.parse_batch([doc], [doc.tensor]) + self.set_annotations([doc], states) + return doc def pipe(self, docs, int batch_size=1000, int n_threads=2): """