def inference(metric):
logging.info('<STR_LIT>', ctx)<EOL>model = BERTClassifier(bert, dropout=<NUM_LIT:0.1>, num_classes=len(task.get_labels()))<EOL>model.hybridize(static_alloc=True)<EOL>model.load_parameters(model_parameters, ctx=ctx)<EOL>metric.reset()<EOL>step_loss = <NUM_LIT:0><EOL>tic = time.time()<EOL>for batch_id, seqs in enumerate(dev_data):<EOL><INDENT>input_ids, valid_length, type_ids, label = seqs<EOL>out = model(input_ids.as_in_context(ctx),<EOL>type_ids.as_in_context(ctx),<EOL>valid_length.astype('<STR_LIT>').as_in_context(ctx))<EOL>ls = loss_function(out, label.as_in_context(ctx)).mean()<EOL>step_loss += ls.asscalar()<EOL>metric.update([label], [out])<EOL>if (batch_id + <NUM_LIT:1>) % (args.log_interval) == <NUM_LIT:0>:<EOL><INDENT>log_inference(batch_id, len(dev_data), metric, step_loss, args.log_interval)<EOL>step_loss = <NUM_LIT:0><EOL><DEDENT><DEDENT>mx.nd.waitall()<EOL>toc = time.time()<EOL>total_num = dev_batch_size * len(dev_data)<EOL>logging.info('<STR_LIT>', toc - tic,total_num / (toc - tic))<EOL>
Inference function.