class MeanPooling(Model):
name = "mean-pool"
def predict(self, seqs):
X = self.ops.xp.vstack(seqs)lengths = [len(seq) for seq in seqs]
means = self.ops.allocate((len(lengths), X.shape[1]))
start = 0
for i, length in enumerate(lengths):
end = start + length
means[i] = X[start : end].mean(axis=0)
start = end
assert means.shape == (len(seqs), seqs[0].shape[1])
return means
def begin_update(self, seqs, drop=0.0):
X = self.ops.xp.vstack(seqs)
lengths = [len(seq) for seq in seqs]