applications/neural_search/ranking/ernie_matching/train_pairwise.py
def evaluate(model, metric, data_loader, phase="dev"):
    """
    Given a dataset, it evals model and computes the metric.

    Args:
        model(obj:`paddle.nn.Layer`): A model to classify texts.
        data_loader(obj:`paddle.io.DataLoader`): The dataset loader which generates batches.
        metric(obj:`paddle.metric.Metric`): The evaluation metric.
    """
    model.eval()
    metric.reset()

    for idx, batch in enumerate(data_loader):
        input_ids, token_type_ids, labels = batch

        pos_probs = model.predict(
            input_ids=input_ids, token_type_ids=token_type_ids)

        neg_probs = 1.0 - pos_probs

        preds = np.concatenate((neg_probs, pos_probs), axis=1)
        metric.update(preds=preds, labels=labels)

    print("eval_{} auc:{:.3}".format(phase, metric.accumulate()))
    metric.reset()
    model.train()

    Given a dataset, it evals model and computes the metric.

    Args:
        model(obj:`paddle.nn.Layer`): A model to classify texts.
        data_loader(obj:`paddle.io.DataLoader`): The dataset loader which generates batches.
        metric(obj:`paddle.metric.Metric`): The evaluation metric.
    
Given a dataset, it evals model and computes the metric.
Given a dataset it evals model and computes the metric .
def evaluate(model, metric, data_loader, phase="dev"):
    model.eval()
    metric.reset()
    for idx, batch in enumerate(data_loader):
        input_ids, token_type_ids, labels = batch
        pos_probs = model.predict(
            input_ids=input_ids, token_type_ids=token_type_ids)
        neg_probs = 1.0 - pos_probs
        preds = np.concatenate((neg_probs, pos_probs), axis=1)
        metric.update(preds=preds, labels=labels)
    print("eval_{} auc:{:.3}".format(phase, metric.accumulate()))
    metric.reset()
    model.train()
def evaluate ( model , metric , data_loader , phase = "dev" ) : model . eval ( ) metric . reset ( ) for idx , batch in enumerate ( data_loader ) : input_ids , token_type_ids , labels = batch pos_probs = model . predict ( input_ids = input_ids , token_type_ids = token_type_ids ) neg_probs = 1.0 - pos_probs preds = np . concatenate ( ( neg_probs , pos_probs ) , axis = 1 ) metric . update ( preds = preds , labels = labels ) print ( "eval_{} auc:{:.3}" . format ( phase , metric . accumulate ( ) ) ) metric . reset ( ) model . train ( )
Given a dataset, it evals model and computes the metric.
Given a dataset it evals model and computes the metric .
"""
    Given a dataset, it evals model and computes the metric.

    Args:
        model(obj:`paddle.nn.Layer`): A model to classify texts.
        data_loader(obj:`paddle.io.DataLoader`): The dataset loader which generates batches.
        metric(obj:`paddle.metric.Metric`): The evaluation metric.
    """
model
metric
data_loader
phase
model(obj
`paddle.nn.Layer`): A model to classify texts.
` paddle . nn . Layer ` ) : A model to classify texts .
data_loader(obj
`paddle.io.DataLoader`): The dataset loader which generates batches.
` paddle . io . DataLoader ` ) : The dataset loader which generates batches .
metric(obj
`paddle.metric.Metric`): The evaluation metric.
` paddle . metric . Metric ` ) : The evaluation metric .