mirror of https://github.com/explosion/spaCy.git
Restore tok2vec function
This commit is contained in:
parent
efe9630e1c
commit
fa7c1990b6
36
spacy/_ml.py
36
spacy/_ml.py
|
@ -1,7 +1,11 @@
|
||||||
from thinc.api import layerize, chain, clone
|
from thinc.api import layerize, chain, clone, concatenate
|
||||||
from thinc.neural import Model, Maxout, Softmax
|
from thinc.neural import Model, Maxout, Softmax
|
||||||
from thinc.neural._classes.hash_embed import HashEmbed
|
from thinc.neural._classes.hash_embed import HashEmbed
|
||||||
from .attrs import TAG, DEP
|
|
||||||
|
from thinc.neural._classes.convolution import ExtractWindow
|
||||||
|
from thinc.neural._classes.static_vectors import StaticVectors
|
||||||
|
|
||||||
|
from .attrs import ID, PREFIX, SUFFIX, SHAPE, TAG, DEP
|
||||||
|
|
||||||
|
|
||||||
def get_col(idx):
|
def get_col(idx):
|
||||||
|
@ -79,19 +83,15 @@ def _reshape(layer):
|
||||||
model._layers.append(layer)
|
model._layers.append(layer)
|
||||||
return model
|
return model
|
||||||
|
|
||||||
#from thinc.api import layerize, chain, clone, concatenate, add
|
def build_tok2vec(lang, width, depth, embed_size, cols):
|
||||||
# from thinc.neural._classes.convolution import ExtractWindow
|
with Model.define_operators({'>>': chain, '|': concatenate, '**': clone}):
|
||||||
# from thinc.neural._classes.static_vectors import StaticVectors
|
static = get_col(cols.index(ID)) >> StaticVectors(lang, width)
|
||||||
|
prefix = get_col(cols.index(PREFIX)) >> HashEmbed(width, embed_size)
|
||||||
#def build_tok2vec(lang, width, depth, embed_size, cols):
|
suffix = get_col(cols.index(SUFFIX)) >> HashEmbed(width, embed_size)
|
||||||
# with Model.define_operators({'>>': chain, '|': concatenate, '**': clone}):
|
shape = get_col(cols.index(SHAPE)) >> HashEmbed(width, embed_size)
|
||||||
# static = get_col(cols.index(ID)) >> StaticVectors(lang, width)
|
tok2vec = (
|
||||||
# prefix = get_col(cols.index(PREFIX)) >> HashEmbed(width, embed_size)
|
(static | prefix | suffix | shape)
|
||||||
# suffix = get_col(cols.index(SUFFIX)) >> HashEmbed(width, embed_size)
|
>> Maxout(width, width*4)
|
||||||
# shape = get_col(cols.index(SHAPE)) >> HashEmbed(width, embed_size)
|
>> (ExtractWindow(nW=1) >> Maxout(width, width*3)) ** depth
|
||||||
# tok2vec = (
|
)
|
||||||
# (static | prefix | suffix | shape)
|
return tok2vec
|
||||||
# >> Maxout(width, width*4)
|
|
||||||
# >> (ExtractWindow(nW=1) >> Maxout(width, width*3)) ** depth
|
|
||||||
# )
|
|
||||||
# return tok2vec
|
|
||||||
|
|
Loading…
Reference in New Issue