mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-12 10:16:27 +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 = (
|
||||
with_flatten(
|
||||
(lower | prefix | suffix | shape )
|
||||
asarray(Model.ops, dtype='uint64')
|
||||
>> (lower | prefix | suffix | shape )
|
||||
>> Maxout(width, width*4, pieces=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
|
||||
|
||||
|
||||
def asarray(ops, dtype):
|
||||
def forward(X, drop=0.):
|
||||
return ops.asarray(X, dtype=dtype), None
|
||||
return layerize(forward)
|
||||
|
||||
|
||||
def foreach(layer):
|
||||
def forward(Xs, drop=0.):
|
||||
results = []
|
||||
|
@ -234,9 +241,7 @@ def doc2feats(cols=None):
|
|||
def forward(docs, drop=0.):
|
||||
feats = []
|
||||
for doc in docs:
|
||||
feats.append(
|
||||
model.ops.asarray(doc.to_array(cols),
|
||||
dtype='uint64'))
|
||||
feats.append(doc.to_array(cols))
|
||||
return feats, None
|
||||
model = layerize(forward)
|
||||
model.cols = cols
|
||||
|
|
Loading…
Reference in New Issue
Block a user