Support dropout in beam parse

This commit is contained in:
Matthew Honnibal 2018-03-10 22:41:55 +01:00
parent 31b156d60b
commit 3d6487c734

View File

@ -477,14 +477,15 @@ cdef class Parser:
free(vectors) free(vectors)
free(scores) free(scores)
def beam_parse(self, docs, int beam_width=3, float beam_density=0.001): def beam_parse(self, docs, int beam_width=3, float beam_density=0.001,
float drop=0.):
cdef Beam beam cdef Beam beam
cdef np.ndarray scores cdef np.ndarray scores
cdef Doc doc cdef Doc doc
cdef int nr_class = self.moves.n_moves cdef int nr_class = self.moves.n_moves
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, 0.0) docs, cuda_stream, drop)
cdef int offset = 0 cdef int offset = 0
cdef int j = 0 cdef int j = 0
cdef int k cdef int k
@ -523,8 +524,8 @@ cdef class Parser:
n_states += 1 n_states += 1
if n_states == 0: if n_states == 0:
break break
vectors = state2vec(token_ids[:n_states]) vectors, _ = state2vec.begin_update(token_ids[:n_states], drop)
scores = vec2scores(vectors) scores, _ = vec2scores(vectors, drop)
c_scores = <float*>scores.data c_scores = <float*>scores.data
for beam in todo: for beam in todo:
for i in range(beam.size): for i in range(beam.size):