nn_mlp: A shortcut to create a feed-forward block (MLP block)

nn_mlpR Documentation

A shortcut to create a feed-forward block (MLP block)

Description

A shortcut to create a feed-forward block (MLP block)

Usage

nn_mlp(..., activation = nnf_relu)

Arguments

...

(nn_module, function integer, character) An arbitrary number of arguments, than can be: * nn_module - e.g. torch::nn_relu() * function - e.g. torch::nnf_relu * character - e.g. selu, which is converted to nnf_selu * integer -

activation

Used if only integers are specified. By default: nnf_relu

Examples

nn_mlp(10, 1)
nn_mlp(30, 10, 1)

# Simple forward pass
net <- nn_mlp(4, 2, 1)
x <- as_torch_tensor(iris[, 1:4])
net(x)

# Simple forward pass with identity function
net <- nn_mlp(4, 2, 1, activation = function (x) x)
x <- as_torch_tensor(iris[, 1:4])
net(x)


krzjoa/torchts documentation built on June 24, 2022, 5:30 a.m.