Refactor Tok2Vec

This commit is contained in:
Matthew Honnibal 2017-09-18 15:00:05 -05:00
parent 217e7891cd
commit 3fa76c17d1

View File

@ -242,20 +242,24 @@ def Tok2Vec(width, embed_size, pretrained_dims=0):
>> LN(Maxout(width, width*4, pieces=3)), column=5)
)
)
if pretrained_dims >= 1:
embed = concatenate_lists(trained_vectors, SpacyVectors)
else:
embed = trained_vectors
convolution = Residual(ExtractWindow(nW=1) >> LN(Maxout(width, width*3, pieces=3)))
tok2vec = (
embed
>> with_flatten(
(Affine(width, width+pretrained_dims)
if pretrained_dims else noop())
>> convolution ** 4,
pad=4)
)
if pretrained_dims >= 1:
embed = concatenate_lists(trained_vectors, SpacyVectors)
tok2vec = (
embed
>> with_flatten(
Affine(width, width+pretrained_dims)
>> convolution ** 4,
pad=4)
)
else:
embed = trained_vectors
tok2vec = (
embed
>> with_flatten(convolution ** 4, pad=4)
)
# Work around thinc API limitations :(. TODO: Revise in Thinc 7
tok2vec.nO = width
tok2vec.embed = embed