Fix tensor gradient in parser

This commit is contained in:
Matthew Honnibal 2017-08-15 03:14:36 -05:00
parent e420e0366c
commit a8e4064dd8

View File

@ -633,10 +633,9 @@ cdef class Parser:
xp = get_array_module(d_tokvecs) xp = get_array_module(d_tokvecs)
for ids, d_vector, bp_vector in backprops: for ids, d_vector, bp_vector in backprops:
d_state_features = bp_vector(d_vector, sgd=sgd) d_state_features = bp_vector(d_vector, sgd=sgd)
mask = ids >= 0 mask = (ids >= 0).reshape((ids.shape[0], ids.shape[1], 1))
indices = xp.nonzero(mask) self.model[0].ops.scatter_add(d_tokvecs, ids,
self.model[0].ops.scatter_add(d_tokvecs, ids[indices], d_state_features * mask)
d_state_features[indices])
@property @property
def move_names(self): def move_names(self):