From b13b2aeb541d88d2eebced5399bda4d2ad8fc672 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Fri, 15 Mar 2019 15:22:38 +0100 Subject: [PATCH] Use hash_state in beam --- spacy/syntax/_beam_utils.pyx | 2 +- spacy/syntax/nn_parser.pyx | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/spacy/syntax/_beam_utils.pyx b/spacy/syntax/_beam_utils.pyx index 83137a4c4..dc482f278 100644 --- a/spacy/syntax/_beam_utils.pyx +++ b/spacy/syntax/_beam_utils.pyx @@ -96,7 +96,7 @@ cdef class ParserBeam(object): self._set_scores(beam, scores[i]) if self.golds is not None: self._set_costs(beam, self.golds[i], follow_gold=follow_gold) - beam.advance(transition_state, NULL, self.moves.c) + beam.advance(transition_state, hash_state, self.moves.c) beam.check_done(check_final_state, NULL) # This handles the non-monotonic stuff for the parser. if beam.is_done and self.golds is not None: diff --git a/spacy/syntax/nn_parser.pyx b/spacy/syntax/nn_parser.pyx index cbeef756d..c140cc4f3 100644 --- a/spacy/syntax/nn_parser.pyx +++ b/spacy/syntax/nn_parser.pyx @@ -119,6 +119,8 @@ cdef class Parser: cfg['beam_width'] = util.env_opt('beam_width', 1) if 'beam_density' not in cfg: cfg['beam_density'] = util.env_opt('beam_density', 0.0) + if 'beam_update_prob' not in cfg: + cfg['beam_update_prob'] = util.env_opt('beam_update_prob', 1.0) cfg.setdefault('cnn_maxout_pieces', 3) self.cfg = cfg self.model = model @@ -383,7 +385,7 @@ cdef class Parser: self.moves.set_valid(beam.is_valid[i], state) memcpy(beam.scores[i], c_scores, scores.shape[1] * sizeof(float)) c_scores += scores.shape[1] - beam.advance(_beam_utils.transition_state, NULL, self.moves.c) + beam.advance(_beam_utils.transition_state, _beam_utils.hash_state, self.moves.c) beam.check_done(_beam_utils.check_final_state, NULL) return [b for b in beams if not b.is_done]