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) 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