def build_mean_max_reducer(hidden_size: int) -> Model[Ragged, Floats2d]: """Reduce sequences by concatenating their mean and max pooled vectors, and then combine the concatenated vectors with a hidden layer. """ return chain( concatenate(reduce_last(), reduce_first(), reduce_mean(), reduce_max()), Maxout(nO=hidden_size, normalize=True, dropout=0.0), )
def test_reduce_first(Xs): model = reduce_first() lengths = model.ops.asarray([x.shape[0] for x in Xs], dtype="i") X = Ragged(model.ops.flatten(Xs), lengths) Y, backprop = model(X, is_train=True) assert isinstance(Y, numpy.ndarray) assert Y.shape == (len(Xs), Xs[0].shape[1]) assert Y.dtype == Xs[0].dtype assert list(Y[0]) == list(Xs[0][0]) assert list(Y[1]) == list(Xs[1][0]) dX = backprop(Y) assert dX.dataXd.shape == X.dataXd.shape
def test_init_reduce_first(): model = reduce_first()