From 96b612873b5f2c4efdffbe207bda0c836932d23e Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Tue, 3 Apr 2018 22:02:56 +0200 Subject: [PATCH] Add hyper-parameter to control whether parser makes a beam update --- spacy/syntax/nn_parser.pyx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spacy/syntax/nn_parser.pyx b/spacy/syntax/nn_parser.pyx index 05f73ecc5..5dbac10ce 100644 --- a/spacy/syntax/nn_parser.pyx +++ b/spacy/syntax/nn_parser.pyx @@ -546,7 +546,10 @@ cdef class Parser: if len(docs) != len(golds): raise ValueError(Errors.E077.format(value='update', n_docs=len(docs), n_golds=len(golds))) - if self.cfg.get('beam_width', 1) >= 2 and numpy.random.random() >= 0.0: + # The probability we use beam update, instead of falling back to + # a greedy update + beam_update_prob = 1-self.cfg.get('beam_update_prob', 0.5) + if self.cfg.get('beam_width', 1) >= 2 and numpy.random.random() >= beam_update_prob: return self.update_beam(docs, golds, self.cfg['beam_width'], self.cfg['beam_density'], drop=drop, sgd=sgd, losses=losses)