mirror of https://github.com/explosion/spaCy.git
Update neural net tests
This commit is contained in:
parent
08766240c3
commit
836fe1d880
|
@ -55,26 +55,17 @@ def test_build_model(parser):
|
|||
|
||||
|
||||
def test_predict_doc(parser, tok2vec, model, doc):
|
||||
state = {}
|
||||
state['tokvecs'] = tok2vec([doc])
|
||||
doc.tensor = tok2vec([doc])
|
||||
parser.model = model
|
||||
parser(doc, state=state)
|
||||
parser(doc)
|
||||
|
||||
|
||||
def test_update_doc(parser, tok2vec, model, doc, gold):
|
||||
parser.model = model
|
||||
tokvecs, bp_tokvecs = tok2vec.begin_update([doc])
|
||||
state = {'tokvecs': tokvecs, 'bp_tokvecs': bp_tokvecs}
|
||||
state = parser.update(doc, gold, state=state)
|
||||
loss1 = state['parser_loss']
|
||||
assert loss1 > 0
|
||||
state = parser.update(doc, gold, state=state)
|
||||
loss2 = state['parser_loss']
|
||||
assert loss2 == loss1
|
||||
d_tokvecs = parser.update((doc, tokvecs), gold)
|
||||
assert d_tokvecs.shape == tokvecs.shape
|
||||
def optimize(weights, gradient, key=None):
|
||||
weights -= 0.001 * gradient
|
||||
state = parser.update(doc, gold, sgd=optimize, state=state)
|
||||
loss3 = state['parser_loss']
|
||||
state = parser.update(doc, gold, sgd=optimize, state=state)
|
||||
lossr = state['parser_loss']
|
||||
assert loss3 < loss2
|
||||
bp_tokvecs(d_tokvecs, sgd=optimize)
|
||||
assert d_tokvecs.sum() == 0.
|
||||
|
|
Loading…
Reference in New Issue