Refactor Tok2Vec

This commit is contained in:
Matthew Honnibal 2017-09-18 15:00:05 -05:00
parent 217e7891cd
commit 3fa76c17d1
1 changed files with 16 additions and 12 deletions

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)))
if pretrained_dims >= 1:
embed = concatenate_lists(trained_vectors, SpacyVectors)
tok2vec = (
embed
>> with_flatten(
(Affine(width, width+pretrained_dims)
if pretrained_dims else noop())
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