def evaluate(data_source, batch_size, params_file_name, ctx=None):
total_L = <NUM_LIT:0.0><EOL>ntotal = <NUM_LIT:0><EOL>model_eval.load_parameters(params_file_name, context)<EOL>hidden = model_eval.begin_state(batch_size=batch_size, func=mx.nd.zeros, ctx=context[<NUM_LIT:0>])<EOL>i = <NUM_LIT:0><EOL>while i < len(data_source) - <NUM_LIT:1> - <NUM_LIT:1>:<EOL><INDENT>data, target = get_batch(data_source, i, seq_len=args.bptt)<EOL>data = data.as_in_context(ctx)<EOL>target = target.as_in_context(ctx)<EOL>output, hidden = model_eval(data, hidden)<EOL>hidden = detach(hidden)<EOL>L = loss(output.reshape(-<NUM_LIT:3>, -<NUM_LIT:1>),<EOL>target.reshape(-<NUM_LIT:1>,))<EOL>total_L += mx.nd.sum(L).asscalar()<EOL>ntotal += L.size<EOL>i += args.bptt<EOL><DEDENT>return total_L / ntotal<EOL>
Evaluate the model on the dataset.

    Parameters
    ----------
    data_source : NDArray
        The dataset is evaluated on.
    batch_size : int
        The size of the mini-batch.
    params_file_name : str
        The parameter file to use to evaluate,
        e.g., val.params or args.save
    ctx : mx.cpu() or mx.gpu()
        The context of the computation.

    Returns
    -------
    loss: float
        The loss on the dataset