mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-26 09:56:28 +03:00
Cleanup states after beam parsing, explicitly
This commit is contained in:
parent
63ef9a2e73
commit
ca73d0d8fe
|
@ -374,6 +374,8 @@ cdef class Parser:
|
||||||
parse_states.append(<StateClass>beam.at(0))
|
parse_states.append(<StateClass>beam.at(0))
|
||||||
self.set_annotations(subbatch, parse_states, tensors=tokvecs)
|
self.set_annotations(subbatch, parse_states, tensors=tokvecs)
|
||||||
yield from batch
|
yield from batch
|
||||||
|
for beam in beams:
|
||||||
|
_cleanup(beam)
|
||||||
|
|
||||||
def parse_batch(self, docs):
|
def parse_batch(self, docs):
|
||||||
cdef:
|
cdef:
|
||||||
|
@ -609,7 +611,7 @@ cdef class Parser:
|
||||||
cuda_stream = util.get_cuda_stream()
|
cuda_stream = util.get_cuda_stream()
|
||||||
(tokvecs, bp_tokvecs), state2vec, vec2scores = self.get_batch_model(
|
(tokvecs, bp_tokvecs), state2vec, vec2scores = self.get_batch_model(
|
||||||
docs, cuda_stream, drop)
|
docs, cuda_stream, drop)
|
||||||
states_d_scores, backprops = _beam_utils.update_beam(
|
states_d_scores, backprops, beams = _beam_utils.update_beam(
|
||||||
self.moves, self.nr_feature, 500, states, golds, state2vec,
|
self.moves, self.nr_feature, 500, states, golds, state2vec,
|
||||||
vec2scores, width, density, self.cfg.get('hist_size', 0),
|
vec2scores, width, density, self.cfg.get('hist_size', 0),
|
||||||
drop=drop, losses=losses)
|
drop=drop, losses=losses)
|
||||||
|
@ -634,6 +636,10 @@ cdef class Parser:
|
||||||
d_tokvecs = state2vec.ops.allocate((tokvecs.shape[0]+1, tokvecs.shape[1]))
|
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)
|
||||||
|
cdef Beam beam
|
||||||
|
for beam in beams:
|
||||||
|
_cleanup(beam)
|
||||||
|
|
||||||
|
|
||||||
def _init_gold_batch(self, whole_docs, whole_golds):
|
def _init_gold_batch(self, whole_docs, whole_golds):
|
||||||
"""Make a square batch, of length equal to the shortest doc. A long
|
"""Make a square batch, of length equal to the shortest doc. A long
|
||||||
|
|
Loading…
Reference in New Issue
Block a user