mxnet-nn- Train a neural network with MXNet in Haskell.

Safe HaskellNone




data Parameter a Source #

A parameter is two NDArray to back a Symbol




(Pretty a, DType a) => Show (Parameter a) Source # 

data Config a Source #

For every symbol in the neural network, it can be placeholder or a variable. therefore, a Config is to specify the shape of the placeholder and the method to initialize the variables.

Note that it is not right to specify a symbol as both placeholder and initializer, although it is tolerated and such a symbol is considered as a variable.

Note that any symbol not specified will be initialized with the _cfg_default_initializer.

type Initializer a = [Int] -> IO (NDArray a) Source #

Initializer is about how to create a NDArray from a given shape.

Usually, it can be a wrapper of MXNet operators, such as random_uniform, random_normal, random_gamma, etc..

type Optimizer a = NDArray a -> NDArray a -> IO (NDArray a) Source #

type TrainM a m = StateT (HashMap String (Parameter a), Context) m Source #

TrainM is a StateT monad, where the state is all the Parameters and a Context

train :: (DType a, Monad m) => HashMap String (Parameter a) -> Context -> TrainM a m r -> m r Source #

Execute the TrainM monad

inferShape :: DType a => Symbol a -> HashMap String (NDArray a) -> IO (HashMap String [Int]) Source #

infer the shapes of all the symbols in a symbolic neural network

initialize :: DType a => Symbol a -> Config a -> IO (HashMap String (Parameter a)) Source #

initialize all parameters

fit :: (DType a, MonadIO m, MonadThrow m) => Optimizer a -> Symbol a -> HashMap String (NDArray a) -> TrainM a m () Source #

single step train. Must provide all the placeholders.

forwardOnly :: (DType a, MonadIO m, MonadThrow m) => Symbol a -> HashMap String (Maybe (NDArray a)) -> TrainM a m [NDArray a] Source #

forward only. Must provide all the placeholders, setting the data to Just xx, and set label to Nothing.

Note that the batch size here can be different from that in the training phase.