paddlenlp/metrics/chunk.py
def compute(self, lengths, predictions, labels, dummy=None):
        """
        Computes the precision, recall and F1-score for chunk detection.

        Args:
            lengths (Tensor): The valid length of every sequence, a tensor with shape `[batch_size]`
            predictions (Tensor): The predictions index, a tensor with shape `[batch_size, sequence_length]`.
            labels (Tensor): The labels index, a tensor with shape `[batch_size, sequence_length]`.
            dummy (Tensor, optional): Unnecessary parameter for compatibility with older versions with parameters list `inputs`, `lengths`, `predictions`, `labels`. Defaults to None.

        Returns:
            tuple: Returns tuple (`num_infer_chunks, num_label_chunks, num_correct_chunks`).

            With the fields:

            - `num_infer_chunks` (Tensor):
                The number of the inference chunks.

            - `num_label_chunks` (Tensor):
                The number of the label chunks.

            - `num_correct_chunks` (Tensor):
                The number of the correct chunks.
        """
        if dummy is not None:
            # TODO(qiujinxuan): rm compatibility support after lic.
            dummy, lengths, predictions, labels = lengths, predictions, labels, dummy
            if not getattr(self, "has_warn", False):
                logger.warning(
                    'Compatibility Warning: The params of ChunkEvaluator.compute has been modified. The old version is `inputs`, `lengths`, `predictions`, `labels` while the current version is `lengths`, `predictions`, `labels`.  Please update the usage.'
                )
                self.has_warn = True
        labels = labels.numpy()
        predictions = predictions.numpy()
        unpad_labels = [[
            self.id2label_dict[index]
            for index in labels[sent_index][:lengths[sent_index]]
        ] for sent_index in range(len(lengths))]
        unpad_predictions = [[
            self.id2label_dict.get(index, "O")
            for index in predictions[sent_index][:lengths[sent_index]]
        ] for sent_index in range(len(lengths))]

        pred_sum, tp_sum, true_sum = extract_tp_actual_correct(
            unpad_labels, unpad_predictions, self.suffix)
        num_correct_chunks = paddle.to_tensor([tp_sum.sum()])
        num_infer_chunks = paddle.to_tensor([pred_sum.sum()])
        num_label_chunks = paddle.to_tensor([true_sum.sum()])

        return num_infer_chunks, num_label_chunks, num_correct_chunks

        Computes the precision, recall and F1-score for chunk detection.

        Args:
            lengths (Tensor): The valid length of every sequence, a tensor with shape `[batch_size]`
            predictions (Tensor): The predictions index, a tensor with shape `[batch_size, sequence_length]`.
            labels (Tensor): The labels index, a tensor with shape `[batch_size, sequence_length]`.
            dummy (Tensor, optional): Unnecessary parameter for compatibility with older versions with parameters list `inputs`, `lengths`, `predictions`, `labels`. Defaults to None.

        Returns:
            tuple: Returns tuple (`num_infer_chunks, num_label_chunks, num_correct_chunks`).

            With the fields:

            - `num_infer_chunks` (Tensor):
                The number of the inference chunks.

            - `num_label_chunks` (Tensor):
                The number of the label chunks.

            - `num_correct_chunks` (Tensor):
                The number of the correct chunks.
        
Computes the precision, recall and F1-score for chunk detection.
Computes the precision recall and F1 - score for chunk detection .
def compute(self, lengths, predictions, labels, dummy=None):
        if dummy is not None:
            dummy, lengths, predictions, labels = lengths, predictions, labels, dummy
            if not getattr(self, "has_warn", False):
                logger.warning(
                    'Compatibility Warning: The params of ChunkEvaluator.compute has been modified. The old version is `inputs`, `lengths`, `predictions`, `labels` while the current version is `lengths`, `predictions`, `labels`.  Please update the usage.'
                )
                self.has_warn = True
        labels = labels.numpy()
        predictions = predictions.numpy()
        unpad_labels = [[
            self.id2label_dict[index]
            for index in labels[sent_index][:lengths[sent_index]]
        ] for sent_index in range(len(lengths))]
        unpad_predictions = [[
            self.id2label_dict.get(index, "O")
            for index in predictions[sent_index][:lengths[sent_index]]
        ] for sent_index in range(len(lengths))]
        pred_sum, tp_sum, true_sum = extract_tp_actual_correct(
            unpad_labels, unpad_predictions, self.suffix)
        num_correct_chunks = paddle.to_tensor([tp_sum.sum()])
        num_infer_chunks = paddle.to_tensor([pred_sum.sum()])
        num_label_chunks = paddle.to_tensor([true_sum.sum()])
        return num_infer_chunks, num_label_chunks, num_correct_chunks
def compute ( self , lengths , predictions , labels , dummy = None ) : if dummy is not None : dummy , lengths , predictions , labels = lengths , predictions , labels , dummy if not getattr ( self , "has_warn" , False ) : logger . warning ( 'Compatibility Warning: The params of ChunkEvaluator.compute has been modified. The old version is `inputs`, `lengths`, `predictions`, `labels` while the current version is `lengths`, `predictions`, `labels`.  Please update the usage.' ) self . has_warn = True labels = labels . numpy ( ) predictions = predictions . numpy ( ) unpad_labels = [ [ self . id2label_dict [ index ] for index in labels [ sent_index ] [ : lengths [ sent_index ] ] ] for sent_index in range ( len ( lengths ) ) ] unpad_predictions = [ [ self . id2label_dict . get ( index , "O" ) for index in predictions [ sent_index ] [ : lengths [ sent_index ] ] ] for sent_index in range ( len ( lengths ) ) ] pred_sum , tp_sum , true_sum = extract_tp_actual_correct ( unpad_labels , unpad_predictions , self . suffix ) num_correct_chunks = paddle . to_tensor ( [ tp_sum . sum ( ) ] ) num_infer_chunks = paddle . to_tensor ( [ pred_sum . sum ( ) ] ) num_label_chunks = paddle . to_tensor ( [ true_sum . sum ( ) ] ) return num_infer_chunks , num_label_chunks , num_correct_chunks
Computes the precision, recall and F1-score for chunk detection.
Computes the precision recall and F1 - score for chunk detection .
"""
        Computes the precision, recall and F1-score for chunk detection.

        Args:
            lengths (Tensor): The valid length of every sequence, a tensor with shape `[batch_size]`
            predictions (Tensor): The predictions index, a tensor with shape `[batch_size, sequence_length]`.
            labels (Tensor): The labels index, a tensor with shape `[batch_size, sequence_length]`.
            dummy (Tensor, optional): Unnecessary parameter for compatibility with older versions with parameters list `inputs`, `lengths`, `predictions`, `labels`. Defaults to None.

        Returns:
            tuple: Returns tuple (`num_infer_chunks, num_label_chunks, num_correct_chunks`).

            With the fields:

            - `num_infer_chunks` (Tensor):
                The number of the inference chunks.

            - `num_label_chunks` (Tensor):
                The number of the label chunks.

            - `num_correct_chunks` (Tensor):
                The number of the correct chunks.
        """ # TODO(qiujinxuan): rm compatibility support after lic.
Returns tuple (`num_infer_chunks, num_label_chunks, num_correct_chunks`).
With the fields.

`num_infer_chunks` (Tensor):
The number of the inference chunks.

`num_label_chunks` (Tensor):
The number of the label chunks.

`num_correct_chunks` (Tensor):
The number of the correct chunks.
Returns tuple ( ` num_infer_chunks num_label_chunks num_correct_chunks ` ) . With the fields . ` num_infer_chunks ` ( Tensor ) : The number of the inference chunks . ` num_label_chunks ` ( Tensor ) : The number of the label chunks . ` num_correct_chunks ` ( Tensor ) : The number of the correct chunks .
tuple
self
lengths
The valid length of every sequence, a tensor with shape `[batch_size]`
The valid length of every sequence a tensor with shape ` [ batch_size ] `
predictions
The predictions index, a tensor with shape `[batch_size, sequence_length]`.
The predictions index a tensor with shape ` [ batch_size sequence_length ] ` .
labels
The labels index, a tensor with shape `[batch_size, sequence_length]`.
The labels index a tensor with shape ` [ batch_size sequence_length ] ` .
dummy
Unnecessary parameter for compatibility with older versions with parameters list `inputs`, `lengths`, `predictions`, `labels`. Defaults to None.
Unnecessary parameter for compatibility with older versions with parameters list ` inputs ` ` lengths ` ` predictions ` ` labels ` . Defaults to None .
None