mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-26 09:14:32 +03:00
Make single array for features, to reduce GPU copies
This commit is contained in:
parent
bc2294d7f1
commit
c998776c25
13
spacy/_ml.py
13
spacy/_ml.py
|
@ -136,7 +136,8 @@ def Tok2Vec(width, embed_size, preprocess=None):
|
||||||
|
|
||||||
tok2vec = (
|
tok2vec = (
|
||||||
with_flatten(
|
with_flatten(
|
||||||
(lower | prefix | suffix | shape )
|
asarray(Model.ops, dtype='uint64')
|
||||||
|
>> (lower | prefix | suffix | shape )
|
||||||
>> Maxout(width, width*4, pieces=3)
|
>> Maxout(width, width*4, pieces=3)
|
||||||
>> Residual(ExtractWindow(nW=1) >> Maxout(width, width*3))
|
>> Residual(ExtractWindow(nW=1) >> Maxout(width, width*3))
|
||||||
>> Residual(ExtractWindow(nW=1) >> Maxout(width, width*3))
|
>> Residual(ExtractWindow(nW=1) >> Maxout(width, width*3))
|
||||||
|
@ -151,6 +152,12 @@ def Tok2Vec(width, embed_size, preprocess=None):
|
||||||
return tok2vec
|
return tok2vec
|
||||||
|
|
||||||
|
|
||||||
|
def asarray(ops, dtype):
|
||||||
|
def forward(X, drop=0.):
|
||||||
|
return ops.asarray(X, dtype=dtype), None
|
||||||
|
return layerize(forward)
|
||||||
|
|
||||||
|
|
||||||
def foreach(layer):
|
def foreach(layer):
|
||||||
def forward(Xs, drop=0.):
|
def forward(Xs, drop=0.):
|
||||||
results = []
|
results = []
|
||||||
|
@ -234,9 +241,7 @@ def doc2feats(cols=None):
|
||||||
def forward(docs, drop=0.):
|
def forward(docs, drop=0.):
|
||||||
feats = []
|
feats = []
|
||||||
for doc in docs:
|
for doc in docs:
|
||||||
feats.append(
|
feats.append(doc.to_array(cols))
|
||||||
model.ops.asarray(doc.to_array(cols),
|
|
||||||
dtype='uint64'))
|
|
||||||
return feats, None
|
return feats, None
|
||||||
model = layerize(forward)
|
model = layerize(forward)
|
||||||
model.cols = cols
|
model.cols = cols
|
||||||
|
|
Loading…
Reference in New Issue
Block a user