Fix backprop of padding variable

This commit is contained in:
Matthew Honnibal 2017-11-03 01:54:34 +01:00
parent 54a716f2ec
commit 6771780d3f

View File

@ -150,7 +150,9 @@ class PrecomputableAffine(Model):
def _backprop_padding(self, dY, ids):
# (1, nF, nO, nP) += (nN, nF, nO, nP) where IDs (nN, nF) < 0
d_pad = dY * (ids.reshape((ids.shape[0], self.nF, 1, 1)) < 0.)
mask = ids < 0.
mask = mask.sum(axis=1)
d_pad = dY * mask.reshape((ids.shape[0], 1, 1))
self.d_pad += d_pad.sum(axis=0)
return dY, ids