Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data Parameter a = Parameter {
- _param_in :: NDArray a
- _param_grad :: NDArray a
- data Config a = Config {}
- data Exc = MismatchedShape String
- type Initializer a = [Int] -> IO (NDArray a)
- type Optimizer a = NDArray a -> NDArray a -> IO (NDArray a)
- type TrainM a m = StateT (HashMap String (Parameter a), Context) m
- train :: (DType a, Monad m) => HashMap String (Parameter a) -> Context -> TrainM a m r -> m r
- inferShape :: DType a => Symbol a -> HashMap String (NDArray a) -> IO (HashMap String [Int])
- initialize :: DType a => Symbol a -> Config a -> IO (HashMap String (Parameter a))
- fit :: (DType a, MonadIO m, MonadThrow m) => Optimizer a -> Symbol a -> HashMap String (NDArray a) -> TrainM a m ()
- forwardOnly :: (DType a, MonadIO m, MonadThrow m) => Symbol a -> HashMap String (Maybe (NDArray a)) -> TrainM a m [NDArray a]
Documentation
Parameter | |
|
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.
Possible exception in TrainM
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 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.