Start work on max violation update. About to clean up commented out code.

This commit is contained in:
Matthew Honnibal 2016-07-24 11:01:54 +02:00
parent 8b4abc24e3
commit 476977ef62

View File

@ -105,13 +105,21 @@ cdef class BeamParser(Parser):
# parse. # parse.
self._advance_beam(pred, gold_parse, False) self._advance_beam(pred, gold_parse, False)
self._advance_beam(gold, gold_parse, True) self._advance_beam(gold, gold_parse, True)
# Early update if MAX_VIOLN_UPDATE:
if pred.min_score > gold.score: violn.check_crf(pred, gold)
elif pred.min_score > gold.score: # Early update
break break
cdef long double Z = 0.0
if MAX_VIOLN_UPDATE:
if violn.delta != -1:
for prob, hist in zip(violn.p_scores, violn.p_hist):
self._update_dense(tokens, hist, prob / violn.Z)
for prob, hist in zip(violn.g_scores, violn.g_hist):
self._update_dense(tokens, hist, -prob / violn.gZ)
else:
# Gather the partition function --- Z --- by which we can normalize the # Gather the partition function --- Z --- by which we can normalize the
# scores into a probability distribution. The simple idea here is that # scores into a probability distribution. The simple idea here is that
# we clip the probability of all parses outside the beam to 0. # we clip the probability of all parses outside the beam to 0.
cdef long double Z = 0.0
for i in range(pred.size): for i in range(pred.size):
# Make sure we've only got negative examples here. # Make sure we've only got negative examples here.
# Otherwise, we might double-count the gold. # Otherwise, we might double-count the gold.