From 789e1a39805b8a299e880e8c0a091782753c205a Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Thu, 31 Aug 2017 14:13:00 -0500 Subject: [PATCH 1/2] Use 13 parser features, not 8 --- spacy/syntax/nn_parser.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spacy/syntax/nn_parser.pyx b/spacy/syntax/nn_parser.pyx index 552ea4f8f..2aaae4f05 100644 --- a/spacy/syntax/nn_parser.pyx +++ b/spacy/syntax/nn_parser.pyx @@ -705,7 +705,7 @@ cdef class Parser: lower, stream, drop=dropout) return state2vec, upper - nr_feature = 8 + nr_feature = 13 def get_token_ids(self, states): cdef StateClass state From 9f512e657a425af8b72795dd9d6a771ed1b9617d Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Mon, 4 Sep 2017 09:26:38 -0500 Subject: [PATCH 2/2] Fix drop_layer calculation --- spacy/_ml.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/spacy/_ml.py b/spacy/_ml.py index 8adacdfda..f8a78948e 100644 --- a/spacy/_ml.py +++ b/spacy/_ml.py @@ -212,12 +212,14 @@ class PrecomputableMaxouts(Model): def drop_layer(layer, factor=2.): def drop_layer_fwd(X, drop=0.): - drop *= factor - mask = layer.ops.get_dropout_mask((1,), drop) - if mask is None or mask > 0: + if drop <= 0.: return layer.begin_update(X, drop=drop) else: - return X, lambda dX, sgd=None: dX + coinflip = layer.ops.xp.random.random() + if (coinflip / factor) >= drop: + return layer.begin_update(X, drop=drop) + else: + return X, lambda dX, sgd=None: dX model = wrap(drop_layer_fwd, layer) model.predict = layer @@ -362,6 +364,8 @@ def get_token_vectors(tokens_attrs_vectors, drop=0.): def backward(d_output, sgd=None): return (tokens, d_output) return vectors, backward + + def fine_tune(embedding, combine=None): if combine is not None: raise NotImplementedError(