From 836fe1d8800c028e34920812773ec9426d716c90 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Fri, 19 May 2017 18:11:29 -0500 Subject: [PATCH] Update neural net tests --- spacy/tests/parser/test_neural_parser.py | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/spacy/tests/parser/test_neural_parser.py b/spacy/tests/parser/test_neural_parser.py index 1cf122be8..9a1d678d4 100644 --- a/spacy/tests/parser/test_neural_parser.py +++ b/spacy/tests/parser/test_neural_parser.py @@ -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.