mirror of
https://github.com/explosion/spaCy.git
synced 2025-02-03 21:24:11 +03:00
Add test for beam update
This commit is contained in:
parent
4638f4b869
commit
24b45b45c6
|
@ -78,3 +78,16 @@ def test_predict_doc_beam(parser, tok2vec, model, doc):
|
||||||
parser(doc, beam_width=32, beam_density=0.001)
|
parser(doc, beam_width=32, beam_density=0.001)
|
||||||
for word in doc:
|
for word in doc:
|
||||||
print(word.text, word.head, word.dep_)
|
print(word.text, word.head, word.dep_)
|
||||||
|
|
||||||
|
|
||||||
|
def test_update_doc_beam(parser, tok2vec, model, doc, gold):
|
||||||
|
parser.model = model
|
||||||
|
tokvecs, bp_tokvecs = tok2vec.begin_update([doc])
|
||||||
|
d_tokvecs = parser.update_beam(([doc], tokvecs), [gold])
|
||||||
|
assert d_tokvecs[0].shape == tokvecs[0].shape
|
||||||
|
def optimize(weights, gradient, key=None):
|
||||||
|
weights -= 0.001 * gradient
|
||||||
|
bp_tokvecs(d_tokvecs, sgd=optimize)
|
||||||
|
assert d_tokvecs[0].sum() == 0.
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user