mirror of
https://github.com/explosion/spaCy.git
synced 2025-07-13 09:42:26 +03:00
Start work on max violation update. About to clean up commented out code.
This commit is contained in:
parent
8b4abc24e3
commit
476977ef62
|
@ -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.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user