mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-26 18:06:29 +03:00
Improve initialization for hidden layers
This commit is contained in:
parent
5414e2f14b
commit
6ef72864fa
16
spacy/_ml.py
16
spacy/_ml.py
|
@ -166,14 +166,18 @@ class PrecomputableAffine(Model):
|
||||||
size=tokvecs.size).reshape(tokvecs.shape)
|
size=tokvecs.size).reshape(tokvecs.shape)
|
||||||
|
|
||||||
def predict(ids, tokvecs):
|
def predict(ids, tokvecs):
|
||||||
hiddens = model(tokvecs) # (b, f, o, p)
|
# nS ids. nW tokvecs
|
||||||
vector = model.ops.allocate((hiddens.shape[0], model.nO, model.nP))
|
hiddens = model(tokvecs) # (nW, f, o, p)
|
||||||
model.ops.xp.add.at(vector, ids, hiddens)
|
# need nS vectors
|
||||||
vector += model.b
|
vectors = model.ops.allocate((ids.shape[0], model.nO, model.nP))
|
||||||
|
for i, feats in enumerate(ids):
|
||||||
|
for j, id_ in enumerate(feats):
|
||||||
|
vectors[i] += hiddens[id_, j]
|
||||||
|
vectors += model.b
|
||||||
if model.nP >= 2:
|
if model.nP >= 2:
|
||||||
return model.ops.maxout(vector)[0]
|
return model.ops.maxout(vectors)[0]
|
||||||
else:
|
else:
|
||||||
return vector * (vector >= 0)
|
return vectors * (vectors >= 0)
|
||||||
|
|
||||||
tol_var = 0.01
|
tol_var = 0.01
|
||||||
tol_mean = 0.01
|
tol_mean = 0.01
|
||||||
|
|
Loading…
Reference in New Issue
Block a user