mirror of
https://github.com/explosion/spaCy.git
synced 2024-11-13 13:17:06 +03:00
Add padding vector in parser, to make gradient more correct
This commit is contained in:
parent
c2bbf076a4
commit
98c29b7912
|
@ -532,7 +532,9 @@ cdef class Parser:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
backprops = []
|
backprops = []
|
||||||
d_tokvecs = state2vec.ops.allocate(tokvecs.shape)
|
# Add a padding vector to the d_tokvecs gradient, so that missing
|
||||||
|
# values don't affect the real gradient.
|
||||||
|
d_tokvecs = state2vec.ops.allocate((tokvecs.shape[0]+1, tokvecs.shape[1]))
|
||||||
cdef float loss = 0.
|
cdef float loss = 0.
|
||||||
n_steps = 0
|
n_steps = 0
|
||||||
while todo:
|
while todo:
|
||||||
|
@ -615,7 +617,9 @@ cdef class Parser:
|
||||||
bp_vectors))
|
bp_vectors))
|
||||||
else:
|
else:
|
||||||
backprop_lower.append((ids, d_vector, bp_vectors))
|
backprop_lower.append((ids, d_vector, bp_vectors))
|
||||||
d_tokvecs = self.model[0].ops.allocate(tokvecs.shape)
|
# Add a padding vector to the d_tokvecs gradient, so that missing
|
||||||
|
# values don't affect the real gradient.
|
||||||
|
d_tokvecs = state2vec.ops.allocate((tokvecs.shape[0]+1, tokvecs.shape[1]))
|
||||||
self._make_updates(d_tokvecs, bp_tokvecs, backprop_lower, sgd,
|
self._make_updates(d_tokvecs, bp_tokvecs, backprop_lower, sgd,
|
||||||
cuda_stream)
|
cuda_stream)
|
||||||
|
|
||||||
|
@ -668,7 +672,8 @@ cdef class Parser:
|
||||||
(ids.size, d_state_features.shape[2]))
|
(ids.size, d_state_features.shape[2]))
|
||||||
self.model[0].ops.scatter_add(d_tokvecs, ids,
|
self.model[0].ops.scatter_add(d_tokvecs, ids,
|
||||||
d_state_features)
|
d_state_features)
|
||||||
bp_tokvecs(d_tokvecs, sgd=sgd)
|
# Padded -- see update()
|
||||||
|
bp_tokvecs(d_tokvecs[:-1], sgd=sgd)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def move_names(self):
|
def move_names(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user