Improve initialization for hidden layers

This commit is contained in:
Matthew Honnibal 2017-10-28 17:05:01 +00:00
parent 5414e2f14b
commit 6ef72864fa

View File

@ -166,14 +166,18 @@ class PrecomputableAffine(Model):
size=tokvecs.size).reshape(tokvecs.shape)
def predict(ids, tokvecs):
hiddens = model(tokvecs) # (b, f, o, p)
vector = model.ops.allocate((hiddens.shape[0], model.nO, model.nP))
model.ops.xp.add.at(vector, ids, hiddens)
vector += model.b
# nS ids. nW tokvecs
hiddens = model(tokvecs) # (nW, f, o, p)
# need nS vectors
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:
return model.ops.maxout(vector)[0]
return model.ops.maxout(vectors)[0]
else:
return vector * (vector >= 0)
return vectors * (vectors >= 0)
tol_var = 0.01
tol_mean = 0.01