mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-25 17:36:30 +03:00
Fix parser config serialization
This commit is contained in:
parent
c66399d8ae
commit
16ba6aa8a6
|
@ -238,14 +238,15 @@ cdef class Parser:
|
||||||
Base class of the DependencyParser and EntityRecognizer.
|
Base class of the DependencyParser and EntityRecognizer.
|
||||||
"""
|
"""
|
||||||
@classmethod
|
@classmethod
|
||||||
def Model(cls, nr_class, token_vector_width=128, hidden_width=200, depth=1, **cfg):
|
def Model(cls, nr_class, **cfg):
|
||||||
depth = util.env_opt('parser_hidden_depth', depth)
|
depth = util.env_opt('parser_hidden_depth', cfg.get('parser_hidden_depth', 1))
|
||||||
token_vector_width = util.env_opt('token_vector_width', token_vector_width)
|
token_vector_width = util.env_opt('token_vector_width', cfg.get('token_vector_width', 128))
|
||||||
hidden_width = util.env_opt('hidden_width', hidden_width)
|
hidden_width = util.env_opt('hidden_width', cfg.get('hidden_width', 200))
|
||||||
parser_maxout_pieces = util.env_opt('parser_maxout_pieces', 2)
|
parser_maxout_pieces = util.env_opt('parser_maxout_pieces', cfg.get('parser_maxout_pieces', 3))
|
||||||
embed_size = util.env_opt('embed_size', 7000)
|
embed_size = util.env_opt('embed_size', cfg.get('embed_size', 7000))
|
||||||
hist_size = util.env_opt('history_feats', cfg.get('history_feats', 0))
|
hist_size = util.env_opt('history_feats', cfg.get('hist_size', 0))
|
||||||
hist_width = util.env_opt('history_width', cfg.get('history_width', 0))
|
hist_width = util.env_opt('history_width', cfg.get('hist_width', 0))
|
||||||
|
print("Create parser model", locals())
|
||||||
if hist_size >= 1 and depth == 0:
|
if hist_size >= 1 and depth == 0:
|
||||||
raise ValueError("Inconsistent hyper-params: "
|
raise ValueError("Inconsistent hyper-params: "
|
||||||
"history_feats >= 1 but parser_hidden_depth==0")
|
"history_feats >= 1 but parser_hidden_depth==0")
|
||||||
|
@ -277,14 +278,14 @@ cdef class Parser:
|
||||||
upper = chain(
|
upper = chain(
|
||||||
HistoryFeatures(nr_class=nr_class, hist_size=hist_size,
|
HistoryFeatures(nr_class=nr_class, hist_size=hist_size,
|
||||||
nr_dim=hist_width),
|
nr_dim=hist_width),
|
||||||
Maxout(hidden_width, hidden_width+hist_size*hist_width),
|
LayerNorm(Maxout(hidden_width, hidden_width+hist_size*hist_width)),
|
||||||
clone(Maxout(hidden_width, hidden_width), depth-2),
|
clone(LayerNorm(Maxout(hidden_width, hidden_width)), depth-2),
|
||||||
zero_init(Affine(nr_class, hidden_width, drop_factor=0.0))
|
zero_init(Affine(nr_class, hidden_width, drop_factor=0.0))
|
||||||
)
|
)
|
||||||
upper.is_noop = False
|
upper.is_noop = False
|
||||||
else:
|
else:
|
||||||
upper = chain(
|
upper = chain(
|
||||||
clone(Maxout(hidden_width, hidden_width), depth-1),
|
clone(LayerNorm(Maxout(hidden_width, hidden_width)), depth-1),
|
||||||
zero_init(Affine(nr_class, hidden_width, drop_factor=0.0))
|
zero_init(Affine(nr_class, hidden_width, drop_factor=0.0))
|
||||||
)
|
)
|
||||||
upper.is_noop = False
|
upper.is_noop = False
|
||||||
|
|
Loading…
Reference in New Issue
Block a user