From d507ac28d8db197e8eac6b8c420ef3502af0a006 Mon Sep 17 00:00:00 2001 From: Matthw Honnibal Date: Thu, 21 May 2020 20:46:10 +0200 Subject: [PATCH] Fix shape inference --- spacy/ml/models/parser.py | 3 ++- spacy/ml/models/tagger.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/spacy/ml/models/parser.py b/spacy/ml/models/parser.py index 0e0857ca8..bdcd709b1 100644 --- a/spacy/ml/models/parser.py +++ b/spacy/ml/models/parser.py @@ -15,9 +15,10 @@ def build_tb_parser_model( use_upper=True, nO=None, ): + t2v_width = tok2vec.get_dim("nO") if tok2vec.has_dim("nO") else None tok2vec = chain( tok2vec, - with_array(Linear(hidden_width)), + with_array(Linear(hidden_width, t2v_width)), list2array(), ) tok2vec.set_dim("nO", hidden_width) diff --git a/spacy/ml/models/tagger.py b/spacy/ml/models/tagger.py index 87256cb5c..00e268ede 100644 --- a/spacy/ml/models/tagger.py +++ b/spacy/ml/models/tagger.py @@ -7,7 +7,8 @@ from ...util import registry @registry.architectures.register("spacy.Tagger.v1") def build_tagger_model(tok2vec, nO=None) -> Model: # TODO: glorot_uniform_init seems to work a bit better than zero_init here?! - output_layer = Softmax(nO, init_W=zero_init) + t2v_width = tok2vec.get_dim("nO") if tok2vec.has_dim("nO") else None + output_layer = Softmax(nO, t2v_width, init_W=zero_init) softmax = with_array(output_layer) model = chain(tok2vec, softmax) model.set_ref("tok2vec", tok2vec)