paddlenlp/metrics/glue.py
def compute(self, pred, label):
        """
        Accepts network's output and the labels, and calculates the top-k
        (maximum value in topk) indices for accuracy.

        Args:
            pred (Tensor):
                Predicted tensor, and its dtype is float32 or float64, and
                has a shape of [batch_size, *, num_labels].
            label (Tensor):
                The ground truth tensor, and its dtype is is int64, and has a
                shape of [batch_size, *] or [batch_size, *, num_labels] in one
                hot representation.

        Returns:
            tuple of Tensor: it contains two Tensor of shape [*, 1].
            The tuple should be passed to `update` function.
        """
        if not (paddle.is_tensor(pred) and paddle.is_tensor(label)):
            raise ValueError('pred and label must be paddle tensor')

        if pred.shape[-1] != self.num_labels:
            raise ValueError(f'The last dim of pred is {pred.shape[-1]}, '
                             f'which should be num_labels')
        pred = paddle.reshape(pred, [-1, self.num_labels])
        pred = paddle.argmax(pred, axis=-1)

        if label.shape[-1] == self.num_labels:
            label = paddle.reshape(label, [-1, self.num_labels])
            label = paddle.argmax(label, axis=-1)
        else:
            label = paddle.reshape(label, [-1])
            if paddle.max(label) >= self.num_labels:
                raise ValueError(f"Tensor label has value {paddle.max(label)}, "
                                 f"which is no less than num_labels")

        if pred.shape[0] != label.shape[0]:
            raise ValueError(
                f"The length of pred is not equal to the length of label")

        return pred, label

        Accepts network's output and the labels, and calculates the top-k
        (maximum value in topk) indices for accuracy.

        Args:
            pred (Tensor):
                Predicted tensor, and its dtype is float32 or float64, and
                has a shape of [batch_size, *, num_labels].
            label (Tensor):
                The ground truth tensor, and its dtype is is int64, and has a
                shape of [batch_size, *] or [batch_size, *, num_labels] in one
                hot representation.

        Returns:
            tuple of Tensor: it contains two Tensor of shape [*, 1].
            The tuple should be passed to `update` function.
        
Accepts network's output and the labels, and calculates the top-k
(maximum value in topk) indices for accuracy.
Accepts network ' s output and the labels and calculates the top - k ( maximum value in topk ) indices for accuracy .
def compute(self, pred, label):
        if not (paddle.is_tensor(pred) and paddle.is_tensor(label)):
            raise ValueError('pred and label must be paddle tensor')
        if pred.shape[-1] != self.num_labels:
            raise ValueError(f'The last dim of pred is {pred.shape[-1]}, '
                             f'which should be num_labels')
        pred = paddle.reshape(pred, [-1, self.num_labels])
        pred = paddle.argmax(pred, axis=-1)
        if label.shape[-1] == self.num_labels:
            label = paddle.reshape(label, [-1, self.num_labels])
            label = paddle.argmax(label, axis=-1)
        else:
            label = paddle.reshape(label, [-1])
            if paddle.max(label) >= self.num_labels:
                raise ValueError(f"Tensor label has value {paddle.max(label)}, "
                                 f"which is no less than num_labels")
        if pred.shape[0] != label.shape[0]:
            raise ValueError(
                f"The length of pred is not equal to the length of label")
        return pred, label
def compute ( self , pred , label ) : if not ( paddle . is_tensor ( pred ) and paddle . is_tensor ( label ) ) : raise ValueError ( 'pred and label must be paddle tensor' ) if pred . shape [ - 1 ] != self . num_labels : raise ValueError ( f'The last dim of pred is {pred.shape[-1]}, ' f'which should be num_labels' ) pred = paddle . reshape ( pred , [ - 1 , self . num_labels ] ) pred = paddle . argmax ( pred , axis = - 1 ) if label . shape [ - 1 ] == self . num_labels : label = paddle . reshape ( label , [ - 1 , self . num_labels ] ) label = paddle . argmax ( label , axis = - 1 ) else : label = paddle . reshape ( label , [ - 1 ] ) if paddle . max ( label ) >= self . num_labels : raise ValueError ( f"Tensor label has value {paddle.max(label)}, " f"which is no less than num_labels" ) if pred . shape [ 0 ] != label . shape [ 0 ] : raise ValueError ( f"The length of pred is not equal to the length of label" ) return pred , label
Accepts network's output and the labels, and calculates the top-k
(maximum value in topk) indices for accuracy.
Accepts network ' s output and the labels and calculates the top - k ( maximum value in topk ) indices for accuracy .
"""
        Accepts network's output and the labels, and calculates the top-k
        (maximum value in topk) indices for accuracy.

        Args:
            pred (Tensor):
                Predicted tensor, and its dtype is float32 or float64, and
                has a shape of [batch_size, *, num_labels].
            label (Tensor):
                The ground truth tensor, and its dtype is is int64, and has a
                shape of [batch_size, *] or [batch_size, *, num_labels] in one
                hot representation.

        Returns:
            tuple of Tensor: it contains two Tensor of shape [*, 1].
            The tuple should be passed to `update` function.
        """
tuple of Tensor: it contains two Tensor of shape [*, 1].
The tuple should be passed to `update` function.
tuple of Tensor : it contains two Tensor of shape [ * 1 ] . The tuple should be passed to ` update ` function .
self
pred
Predicted tensor, and its dtype is float32 or float64, and
has a shape of [batch_size, *, num_labels].
Predicted tensor and its dtype is float32 or float64 and has a shape of [ batch_size * num_labels ] .
label
The ground truth tensor, and its dtype is is int64, and has a
shape of [batch_size, *] or [batch_size, *, num_labels] in one
hot representation.
The ground truth tensor and its dtype is is int64 and has a shape of [ batch_size * ] or [ batch_size * num_labels ] in one hot representation .