Fix parser tests

This commit is contained in:
Matthew Honnibal 2017-07-20 00:16:52 +02:00
parent 49026a1346
commit f014138c11

View File

@ -36,7 +36,7 @@ def parser(vocab, arc_eager):
@pytest.fixture @pytest.fixture
def model(arc_eager, tok2vec): def model(arc_eager, tok2vec):
return Parser.Model(arc_eager.n_moves, token_vector_width=tok2vec.nO) return Parser.Model(arc_eager.n_moves, token_vector_width=tok2vec.nO)[0]
@pytest.fixture @pytest.fixture
def doc(vocab): def doc(vocab):
@ -45,29 +45,29 @@ def doc(vocab):
@pytest.fixture @pytest.fixture
def gold(doc): def gold(doc):
return GoldParse(doc, heads=[1, 1, 1], deps=['L', 'ROOT', 'R']) return GoldParse(doc, heads=[1, 1, 1], deps=['L', 'ROOT', 'R'])
def test_can_init_nn_parser(parser): def test_can_init_nn_parser(parser):
assert parser.model is None assert parser.model is None
def test_build_model(parser): def test_build_model(parser):
parser.model = Parser.Model(parser.moves.n_moves) parser.model = Parser.Model(parser.moves.n_moves)[0]
assert parser.model is not None assert parser.model is not None
@pytest.mark.xfail
def test_predict_doc(parser, tok2vec, model, doc): def test_predict_doc(parser, tok2vec, model, doc):
doc.tensor = tok2vec([doc]) doc.tensor = tok2vec([doc])[0]
parser.model = model parser.model = model
parser(doc) parser(doc)
@pytest.mark.xfail
def test_update_doc(parser, tok2vec, model, doc, gold): def test_update_doc(parser, tok2vec, model, doc, gold):
parser.model = model parser.model = model
tokvecs, bp_tokvecs = tok2vec.begin_update([doc]) tokvecs, bp_tokvecs = tok2vec.begin_update([doc])
d_tokvecs = parser.update((doc, tokvecs), gold) d_tokvecs = parser.update(([doc], tokvecs), [gold])
assert d_tokvecs.shape == tokvecs.shape assert d_tokvecs[0].shape == tokvecs[0].shape
def optimize(weights, gradient, key=None): def optimize(weights, gradient, key=None):
weights -= 0.001 * gradient weights -= 0.001 * gradient
bp_tokvecs(d_tokvecs, sgd=optimize) bp_tokvecs(d_tokvecs, sgd=optimize)
assert d_tokvecs.sum() == 0. assert d_tokvecs[0].sum() == 0.