def noop_models(): return [ with_padded(noop()), with_array(noop()), with_array2d(noop()), with_list(noop()), with_ragged(noop()) ]
def test_validation(): model = chain(Relu(10), Relu(10), with_ragged(reduce_max()), Softmax()) with pytest.raises(DataValidationError): model.initialize(X=model.ops.alloc2f(1, 10), Y=model.ops.alloc2f(1, 10)) with pytest.raises(DataValidationError): model.initialize(X=model.ops.alloc3f(1, 10, 1), Y=model.ops.alloc2f(1, 10)) with pytest.raises(DataValidationError): model.initialize(X=[model.ops.alloc2f(1, 10)], Y=model.ops.alloc2f(1, 10))
def get_ragged_model(): def _trim_ragged_forward(model, Xr, is_train): def backprop(dYr): dY = dYr.data dX = model.ops.alloc2f(dY.shape[0], dY.shape[1] + 1) return Ragged(dX, dYr.lengths) return Ragged(Xr.data[:, :-1], Xr.lengths), backprop return with_ragged(Model("trimragged", _trim_ragged_forward))