def evaluate(data_eval, model, nsp_loss, mlm_loss, vocab_size, ctx, log_interval, dtype):
mlm_metric = MaskedAccuracy()<EOL>nsp_metric = MaskedAccuracy()<EOL>mlm_metric.reset()<EOL>nsp_metric.reset()<EOL>eval_begin_time = time.time()<EOL>begin_time = time.time()<EOL>step_num = <NUM_LIT:0><EOL>running_mlm_loss = running_nsp_loss = <NUM_LIT:0><EOL>total_mlm_loss = total_nsp_loss = <NUM_LIT:0><EOL>running_num_tks = <NUM_LIT:0><EOL>for _, dataloader in enumerate(data_eval):<EOL><INDENT>for _, data_batch in enumerate(dataloader):<EOL><INDENT>step_num += <NUM_LIT:1><EOL>data_list = split_and_load(data_batch, ctx)<EOL>loss_list = []<EOL>ns_label_list, ns_pred_list = [], []<EOL>mask_label_list, mask_pred_list, mask_weight_list = [], [], []<EOL>for data in data_list:<EOL><INDENT>out = forward(data, model, mlm_loss, nsp_loss, vocab_size, dtype)<EOL>(ls, next_sentence_label, classified, masked_id,<EOL>decoded, masked_weight, ls1, ls2, valid_length) = out<EOL>loss_list.append(ls)<EOL>ns_label_list.append(next_sentence_label)<EOL>ns_pred_list.append(classified)<EOL>mask_label_list.append(masked_id)<EOL>mask_pred_list.append(decoded)<EOL>mask_weight_list.append(masked_weight)<EOL>running_mlm_loss += ls1.as_in_context(mx.cpu())<EOL>running_nsp_loss += ls2.as_in_context(mx.cpu())<EOL>running_num_tks += valid_length.sum().as_in_context(mx.cpu())<EOL><DEDENT>nsp_metric.update(ns_label_list, ns_pred_list)<EOL>mlm_metric.update(mask_label_list, mask_pred_list, mask_weight_list)<EOL>if (step_num + <NUM_LIT:1>) % (log_interval) == <NUM_LIT:0>:<EOL><INDENT>total_mlm_loss += running_mlm_loss<EOL>total_nsp_loss += running_nsp_loss<EOL>log(begin_time, running_num_tks, running_mlm_loss, running_nsp_loss,<EOL>step_num, mlm_metric, nsp_metric, None, log_interval)<EOL>begin_time = time.time()<EOL>running_mlm_loss = running_nsp_loss = running_num_tks = <NUM_LIT:0><EOL>mlm_metric.reset_local()<EOL>nsp_metric.reset_local()<EOL><DEDENT><DEDENT><DEDENT>mx.nd.waitall()<EOL>eval_end_time = time.time()<EOL>total_mlm_loss /= step_num<EOL>total_nsp_loss /= step_num<EOL>logging.info('<STR_LIT>'<EOL>.format(total_mlm_loss.asscalar(), mlm_metric.get_global()[<NUM_LIT:1>] * <NUM_LIT:100>,<EOL>total_nsp_loss.asscalar(), nsp_metric.get_global()[<NUM_LIT:1>] * <NUM_LIT:100>))<EOL>logging.info('<STR_LIT>'.format(eval_end_time - eval_begin_time))<EOL>
Evaluation function.