From e85e31cfbd43e88184ed08cb977e2acaf5752d86 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Wed, 1 Nov 2017 19:27:26 +0100 Subject: [PATCH] Fix backprop of d_pad --- spacy/_ml.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spacy/_ml.py b/spacy/_ml.py index bcc2a55b6..8c98567fc 100644 --- a/spacy/_ml.py +++ b/spacy/_ml.py @@ -150,10 +150,10 @@ class PrecomputableAffine(Model): def _backprop_padding(self, dY, ids): # (1, nF, nO, nP) += (nN, nF, nO, nP) where IDs (nN, nF) < 0 - d_feats = dY[ids] - ids = ids.reshape((ids.shape[0], ids.shape[1], 1, 1)) - d_feats *= ids < 0 - self.d_pad += d_feats.sum(axis=0, keepdims=True) + for i in range(ids.shape[0]): + for j in range(ids.shape[1]): + if ids[i,j] < 0: + self.d_pad[0,j] += dY[i, j] return dY, ids @staticmethod