The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

    AI::MXNet::Callback - A collection of predefined callback functions.

DESCRIPTION

    A collection of predefined callback functions, mainly to be used in AI::MXNet::Module::Base::fit.

SYNOPSIS

    my $model = mx->mod->Module(
        symbol  => $net,
        context => $contexts
    );
    $model->fit(
        $data_iter,
        eval_metric         => mx->metric->Perplexity,
        kvstore             => $kv_store,
        optimizer           => $optimizer,
        optimizer_params    => {
            learning_rate => $lr,
            momentum      => $mom,
            wd            => $wd,
            clip_gradient => 5,
            rescale_grad  => 1/$batch_size,
            lr_scheduler  => AI::MXNet::FactorScheduler->new(step => 1000, factor => 0.99)
        },
        initializer         => mx->init->Xavier(factor_type => "in", magnitude => 2.34),
        num_epoch           => $num_epoch,
        batch_end_callback  => mx->callback->Speedometer($batch_size, $disp_batches),
        ($chkp_epoch ? (epoch_end_callback  => [mx->callback->module_checkpoint($model, $chkp_prefix, $chkp_epoch), \&sample]) : ())
    );

module_checkpoint

    Callback to save the module setup in the checkpoint files.

    Parameters
    ----------
    $mod : subclass of AI::MXNet::Module::Base
        The module to checkpoint.
    $prefix : Str
        The file prefix to checkpoint to
    $period=1 : Int
        How many epochs to wait before checkpointing. Default is 1.
    $save_optimizer_states=0 : Bool
        Whether to save optimizer states for later training.

    Returns
    -------
    $callback : sub ref
        The callback function that can be passed as iter_end_callback to fit.

log_train_metric

    Callback to log the training evaluation result every period.

    Parameters
    ----------
    $period : Int
        The number of batches after which to log the training evaluation metric.
    $auto_reset : Bool
        Whether to reset the metric after the logging.

    Returns
    -------
    $callback : sub ref
        The callback function that can be passed as iter_epoch_callback to fit.

NAME

    AI::MXNet::Speedometer - A callback that logs training speed

DESCRIPTION

    Calculate and log training speed periodically.

    Parameters
    ----------
    batch_size: int
        batch_size of data
    frequent: int
        How many batches between calculations.
        Defaults to calculating & logging every 50 batches.
    auto_reset: Bool
        Reset the metric after each log, defaults to true.

NAME

    AI::MXNet::ProgressBar - A callback to show a progress bar.

DESCRIPTION

    Shows a progress bar.

    Parameters
    ----------
    total: Int
        batch size, default is 1
    length: Int
        the length of the progress bar, default is 80 chars

NAME

    AI::MXNet::LogValidationMetricsCallback - A callback to log the eval metrics at the end of an epoch.