From 73a643d32a20d8c4a109bf3a92dff645c370bd17 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sat, 27 May 2017 08:20:13 -0500 Subject: [PATCH] Don't randomise pipeline for training, and don't update if no gradient --- spacy/language.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/spacy/language.py b/spacy/language.py index e4c18f8ca..7adae0ed5 100644 --- a/spacy/language.py +++ b/spacy/language.py @@ -212,18 +212,17 @@ class Language(object): """ tok2vec = self.pipeline[0] feats = tok2vec.doc2feats(docs) - procs = list(self.pipeline[1:]) - random.shuffle(procs) grads = {} def get_grads(W, dW, key=None): grads[key] = (W, dW) - for proc in procs: + for proc in self.pipeline[1:]: if not hasattr(proc, 'update'): continue tokvecses, bp_tokvecses = tok2vec.model.begin_update(feats, drop=drop) d_tokvecses = proc.update((docs, tokvecses), golds, drop=drop, sgd=get_grads, losses=losses) - bp_tokvecses(d_tokvecses, sgd=sgd) + if d_tokvecses is not None: + bp_tokvecses(d_tokvecses, sgd=sgd) for key, (W, dW) in grads.items(): sgd(W, dW, key=key) # Clear the tensor variable, to free GPU memory.