mirror of https://github.com/explosion/spaCy.git
Refactor Tok2Vec
This commit is contained in:
parent
217e7891cd
commit
3fa76c17d1
28
spacy/_ml.py
28
spacy/_ml.py
|
@ -242,20 +242,24 @@ def Tok2Vec(width, embed_size, pretrained_dims=0):
|
||||||
>> LN(Maxout(width, width*4, pieces=3)), column=5)
|
>> 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)))
|
convolution = Residual(ExtractWindow(nW=1) >> LN(Maxout(width, width*3, pieces=3)))
|
||||||
|
|
||||||
tok2vec = (
|
if pretrained_dims >= 1:
|
||||||
embed
|
embed = concatenate_lists(trained_vectors, SpacyVectors)
|
||||||
>> with_flatten(
|
tok2vec = (
|
||||||
(Affine(width, width+pretrained_dims)
|
embed
|
||||||
if pretrained_dims else noop())
|
>> with_flatten(
|
||||||
>> convolution ** 4,
|
Affine(width, width+pretrained_dims)
|
||||||
pad=4)
|
>> 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
|
# Work around thinc API limitations :(. TODO: Revise in Thinc 7
|
||||||
tok2vec.nO = width
|
tok2vec.nO = width
|
||||||
tok2vec.embed = embed
|
tok2vec.embed = embed
|
||||||
|
|
Loading…
Reference in New Issue