o
    à¥µi÷P  ã                   @   sü  d dl mZ d dlmZmZmZmZ d dlZd dl	m
Z
 ed ZeG dd„ de
ƒƒZeG dd	„ d	eƒƒZeG d
d„ de
ƒƒZeG dd„ de
ƒƒZeG dd„ de
ƒƒZeG dd„ de
ƒƒZeG dd„ deƒƒZeG dd„ de
ƒƒZeG dd„ de
ƒƒZeG dd„ de
ƒƒZeG dd„ deƒƒZeG dd„ de
ƒƒZeG dd„ de
ƒƒZeG d d!„ d!e
ƒƒZeG d"d#„ d#eƒƒZeG d$d%„ d%e
ƒƒZeG d&d'„ d'e
ƒƒZeG d(d)„ d)eƒƒZeG d*d+„ d+e
ƒƒZeG d,d-„ d-e
ƒƒZeG d.d/„ d/e
ƒƒZ eG d0d1„ d1e
ƒƒZ!dS )2é    )Ú	dataclass)ÚListÚOptionalÚTupleÚUnionN)ÚModelOutputBase)ztorch.Tensorz	tf.Tensorc                   @   ó6   e Zd ZU dZdZeed< dZeed< dZeed< dS )ÚBackboneModelOutputa·  The output class for text classification models.

    Args:
        last_hidden_state (`Tensor`, *optional*): Sequence of hidden-states at
            the output of the last layer of the model.
        pooler_output (`Tensor`, *optional*) The tensor of the pooled hidden state.
        hidden_states (`Tensor`, *optional*) Hidden-states of the model at
            the output of each layer plus the optional initial embedding outputs.
    NÚlast_hidden_stateÚpooler_outputÚhidden_states)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   ÚTensorÚ__annotations__r   r   © r   r   úR/home/ubuntu/.local/lib/python3.10/site-packages/modelscope/outputs/nlp_outputs.pyr	      s
   
 
r	   c                   @   r   )ÚAttentionBackboneModelOutputa‡  The output class for backbones of attention based models.

    Args:
        attentions (`tuple(torch.FloatTensor)`, *optional*, returned when
        `output_attentions=True` is passed or when
        `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (one for each layer) of shape
            `(batch_size, num_heads, sequence_length, sequence_length)`.

            Attentions weights after the attention softmax, used to compute the
            weighted average in the self-attention heads.
        cross_attentions (`tuple(torch.FloatTensor)`, *optional*, returned when
        `output_attentions=True` and `config.add_cross_attention=True` is passed
        or when `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (one for each layer) of shape
            `(batch_size, num_heads, sequence_length, sequence_length)`.

            Attentions weights of the decoder's cross-attention layer, after the
            attention softmax, used to compute the weighted average in the
            cross-attention heads.
        past_key_values (`tuple(tuple(torch.FloatTensor))`, *optional*, returned
        when `use_cache=True` is passed or when `config.use_cache=True`):
            Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`,
            with each tuple having 2 tensors of shape `(batch_size, num_heads,
            sequence_length, embed_size_per_head)`) and optionally if
            `config.is_encoder_decoder=True` 2 additional tensors of shape
            `(batch_size, num_heads, encoder_sequence_length,
            embed_size_per_head)`.

            Contains pre-computed hidden-states (key and values in the
            self-attention blocks and optionally if
            `config.is_encoder_decoder=True` in the cross-attention blocks) that
            can be used (see `past_key_values` input) to speed up sequential
            decoding.
    NÚ
attentionsÚpast_key_valuesÚcross_attentions)	r   r   r   r   r   r   r   r   r   r   r   r   r   r      s
   
 #r   c                   @   sª   e Zd ZU dZdZeed< dZee	e	e   ed< dZ
ee	e  ed< dZee	e  ed< dZee	e  ed< dZee ed< dZee	e  ed	< dZee	e  ed
< dS )ÚSeq2SeqModelOutputaÁ  
    Base class for model encoder's outputs that also contains : pre-computed
    hidden states that can speed up sequential decoding.

    Args:
        last_hidden_state (`torch.FloatTensor` of shape `(batch_size,
        sequence_length, hidden_size)`):
            Sequence of hidden-states at the output of the last layer of the
            decoder of the model.

            If `past_key_values` is used only the last hidden-state of the
            sequences of shape `(batch_size, 1, hidden_size)` is output.
        past_key_values (`tuple(tuple(torch.FloatTensor))`, *optional*, returned
        when `use_cache=True` is passed or when `config.use_cache=True`):
            Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`,
            with each tuple having 2 tensors of shape `(batch_size, num_heads,
            sequence_length, embed_size_per_head)`) and 2 additional tensors of
            shape `(batch_size, num_heads, encoder_sequence_length,
            embed_size_per_head)`.

            Contains pre-computed hidden-states (key and values in the
            self-attention blocks and in the cross-attention blocks) that can be
            used (see `past_key_values` input) to speed up sequential decoding.
        decoder_hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned
        when `output_hidden_states=True` is passed or when
        `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings,
            if the model has an embedding layer, + one for the output of each
            layer) of shape `(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the decoder at the output of each layer plus the
            optional initial embedding outputs.
        decoder_attentions (`tuple(torch.FloatTensor)`, *optional*, returned
        when `output_attentions=True` is passed or when
        `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (one for each layer) of shape
            `(batch_size, num_heads, sequence_length, sequence_length)`.

            Attentions weights of the decoder, after the attention softmax, used
            to compute the weighted average in the self-attention heads.
        cross_attentions (`tuple(torch.FloatTensor)`, *optional*, returned when
        `output_attentions=True` is passed or when
        `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (one for each layer) of shape
            `(batch_size, num_heads, sequence_length, sequence_length)`.

            Attentions weights of the decoder's cross-attention layer, after the
            attention softmax, used to compute the weighted average in the
            cross-attention heads.
        encoder_last_hidden_state (`torch.FloatTensor` of shape `(batch_size,
        sequence_length, hidden_size)`, *optional*):
            Sequence of hidden-states at the output of the last layer of the
            encoder of the model.
        encoder_hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned
        when `output_hidden_states=True` is passed or when
        `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings,
            if the model has an embedding layer, + one for the output of each
            layer) of shape `(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the encoder at the output of each layer plus the
            optional initial embedding outputs.
        encoder_attentions (`tuple(torch.FloatTensor)`, *optional*, returned
        when `output_attentions=True` is passed or when
        `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (one for each layer) of shape
            `(batch_size, num_heads, sequence_length, sequence_length)`.

            Attentions weights of the encoder, after the attention softmax, used
            to compute the weighted average in the self-attention heads.
    Nr
   r   Údecoder_hidden_statesÚdecoder_attentionsr   Úencoder_last_hidden_stateÚencoder_hidden_statesÚencoder_attentions)r   r   r   r   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   F   s   
 Hr   c                   @   óB   e Zd ZU dZdZeed< dZeed< dZeed< dZ	eed< dS )ÚFaqQuestionAnsweringOutputz(The output class for faq QA models.
    NÚscoresÚlabelsÚlossÚlogits)
r   r   r   r   r!   r   r   r"   r#   r$   r   r   r   r   r    š   s   
 r    c                   @   ó   e Zd ZU dZdZeed< dS )ÚFeatureExtractionOutputz4The output class for feature extraction models.
    NÚtext_embedding)r   r   r   r   r'   r   r   r   r   r   r   r&   ¥   ó   
 r&   c                   @   r   )ÚFillMaskModelOutputa³  The output class for fill mask models.

    Args:
        logits (`Tensor`): The logits output of the model.
        loss (`Tensor`, *optional*) The loss of the model, available when training.
        input_ids (`Tensor`, *optional*) The input id tensor fed into the model.
        hidden_states (`Tensor`, *optional*) Hidden-states of the model at the
            output of each layer plus the optional initial embedding outputs.
    Nr$   r#   Ú	input_idsr   )
r   r   r   r   r$   r   r   r#   r*   r   r   r   r   r   r)   ­   s   
 
r)   c                   @   r%   )ÚAttentionFillMaskModelOutputa   The output class for the fill mask and attention based models.

    Args:
        attentions (`tuple(Tensor)`, *optional* Attentions weights after the
        attention softmax, used to compute the weighted average in the
        self-attention heads.
    Nr   )r   r   r   r   r   r   r   r   r   r   r   r+   ¿   s   
 r+   c                   @   ó    e Zd ZU dZdZejed< dS )ÚInformationExtractionOutputú8The output class for information extraction models.
    NÚspo_list)r   r   r   r   r/   ÚnpÚndarrayr   r   r   r   r   r-   Ë   ó   
 r-   c                   @   sº   e Zd ZU dZdZee ed< dZeed< dZ	ee
e
e   ed< dZee
e  ed< dZee
e  ed< dZee
e  ed< dZee ed	< dZee
e  ed
< dZee
e  ed< dS )ÚSeq2SeqLMOutputal  
    Base class for sequence-to-sequence language models outputs.

    Args:
        loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when
        `labels` is provided):
            Language modeling loss.
        logits (`torch.FloatTensor` of shape `(batch_size, sequence_length,
        config.vocab_size)`):
            Prediction scores of the language modeling head (scores for each
            vocabulary token before SoftMax).
        past_key_values (`tuple(tuple(torch.FloatTensor))`, *optional*, returned
        when `use_cache=True` is passed or when `config.use_cache=True`):
            Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`,
            with each tuple having 2 tensors of shape `(batch_size, num_heads,
            sequence_length, embed_size_per_head)`) and 2 additional tensors of
            shape `(batch_size, num_heads, encoder_sequence_length,
            embed_size_per_head)`.

            Contains pre-computed hidden-states (key and values in the
            self-attention blocks and in the cross-attention blocks) that can be
            used (see `past_key_values` input) to speed up sequential decoding.
        decoder_hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned
        when `output_hidden_states=True` is passed or when
        `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings,
            if the model has an embedding layer, + one for the output of each
            layer) of shape `(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the decoder at the output of each layer plus the
            initial embedding outputs.
        decoder_attentions (`tuple(torch.FloatTensor)`, *optional*, returned
        when `output_attentions=True` is passed or when
        `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (one for each layer) of shape
            `(batch_size, num_heads, sequence_length, sequence_length)`.

            Attentions weights of the decoder, after the attention softmax, used
            to compute the weighted average in the self-attention heads.
        cross_attentions (`tuple(torch.FloatTensor)`, *optional*, returned when
        `output_attentions=True` is passed or when
        `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (one for each layer) of shape
            `(batch_size, num_heads, sequence_length, sequence_length)`.

            Attentions weights of the decoder's cross-attention layer, after the
            attention softmax, used to compute the weighted average in the
            cross-attention heads.
        encoder_last_hidden_state (`torch.FloatTensor` of shape `(batch_size,
        sequence_length, hidden_size)`, *optional*):
            Sequence of hidden-states at the output of the last layer of the
            encoder of the model.
        encoder_hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned
        when `output_hidden_states=True` is passed or when
        `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings,
            if the model has an embedding layer, + one for the output of each
            layer) of shape `(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the encoder at the output of each layer plus the
            initial embedding outputs.
        encoder_attentions (`tuple(torch.FloatTensor)`, *optional*, returned
        when `output_attentions=True` is passed or when
        `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (one for each layer) of shape
            `(batch_size, num_heads, sequence_length, sequence_length)`.

            Attentions weights of the encoder, after the attention softmax, used
            to compute the weighted average in the self-attention heads.
    Nr#   r$   r   r   r   r   r   r   r   )r   r   r   r   r#   r   r   r   r$   r   r   r   r   r   r   r   r   r   r   r   r   r3   Ó   s   
 Gr3   c                   @   ó*   e Zd ZU dZdZeed< dZeed< dS )ÚTextClassificationModelOutputah  The output class for text classification models.

    Args:
        logits (`Tensor`): The logits output of the model. loss (`Tensor`,
        *optional*) The loss of the model, available when training.
        hidden_states (`Tensor`, *optional*) Hidden-states of the model at the
        output of each layer plus the optional initial embedding outputs.
    Nr$   r#   ©r   r   r   r   r$   r   r   r#   r   r   r   r   r5   '  ó   
 	r5   c                   @   r   )Ú&AttentionTextClassificationModelOutputzûThe output class for backbones of attention based models.

    Args:
        attentions (`tuple(Tensor)`, *optional* Attentions weights after the
        attention softmax, used to compute the weighted average in the
        self-attention heads.
    Nr   r   r   ©	r   r   r   r   r   r   r   r   r   r   r   r   r   r8   6  s
   
 r8   c                   @   r,   )ÚTextErrorCorrectionOutputr.   NÚpredictions)r   r   r   r   r;   r0   r1   r   r   r   r   r   r:   D  r2   r:   c                   @   r%   )ÚWordAlignmentOutputz0The output class for word alignment models.
    Nr;   )r   r   r   r   r;   r   r   r   r   r   r   r<   L  r(   r<   c                   @   r4   )ÚTextGenerationModelOutputad  The output class for text generation models.

    Args:
        logits (`Tensor`): The logits output of the model. loss (`Tensor`,
        *optional*) The loss of the model, available when training.
        hidden_states (`Tensor`, *optional*) Hidden-states of the model at the
        output of each layer plus the optional initial embedding outputs.
    Nr$   r#   r6   r   r   r   r   r=   T  r7   r=   c                   @   r   )Ú"AttentionTextGenerationModelOutputaw  The output class for text generation of attention based models.

    Args:
        logits (`Tensor`): The logits output of the model. loss (`Tensor`,
        *optional*) The loss of the model, available when training.
        hidden_states (`Tensor`, *optional*) Hidden-states of the model at the
        output of each layer plus the optional initial embedding outputs.
    Nr   r   r   r9   r   r   r   r   r>   c  ó
   
 r>   c                   @   sb   e Zd ZU dZdZeed< dZee	e  ed< dZ
ee	e	e   ed< dZee	e	e   ed< dS )ÚTokenGeneratorOutputa—  
    The output class for generate method of text generation models.


    Args:
        sequences (`torch.LongTensor` of shape `(batch_size*num_return_sequences, sequence_length)`):
            The generated sequences. The second dimension (sequence_length) is either equal to `max_length` or shorter
            if all batches finished early due to the `eos_token_id`.
        scores (`tuple(torch.FloatTensor)` *optional*, returned when `output_scores=True`
        is passed or when `config.output_scores=True`):
            Processed prediction scores of the language modeling head (scores for each vocabulary token before SoftMax)
            at each generation step. Tuple of `torch.FloatTensor` with up to `max_new_tokens` elements (one element for
            each generated token), with each tensor of shape `(batch_size*num_return_sequences, config.vocab_size)`.
        attentions (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_attentions=True`
        is passed or `config.output_attentions=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(num_return_sequences*batch_size, num_heads, generated_length,
            sequence_length)`.
        hidden_states (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_hidden_states=True`
        is passed or when `config.output_hidden_states=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(num_return_sequences*batch_size, generated_length, hidden_size)`.
    NÚ	sequencesr!   r   r   )r   r   r   r   rA   r   r   r!   r   r   r   r   r   r   r   r   r@   r  s   
 r@   c                   @   sN   e Zd ZU dZdZeed< dZeed< dZeed< dZ	eed< dZ
eed< dS )ÚTokenClassificationModelOutputaM  The output class for token classification models.
        logits (`Tensor`): The logits output of the model.
        loss (`Tensor`, *optional*) The loss of the model, available when training.
        predictions: A PyTorch tensor of the best tag sequence for each batch of shape
            (nbest, batch_size, seq_length)
        offset_mapping (:obj:`torch.FloatTensor` of shape :obj:`(batch_size,
        sequence_length)`, `optional`):
            Indices of positions of each input sequence tokens in the sentence.
            Selected in the range ``[0, sequence_length - 1]``.
    Nr$   r#   Úoffset_mappingr;   Ú
label_mask)r   r   r   r   r$   r   r   r#   rC   r;   rD   r   r   r   r   rB   ’  s   
 rB   c                   @   r4   )Ú'AttentionTokenClassificationModelOutputzóThe output class for backbones of attention based models.

    Args:
        attentions (`tuple(Tensor)`, *optional* Attentions weights after the attention softmax,
        used to compute the weighted average in the self-attention heads.
    Nr   r   )r   r   r   r   r   r   r   r   r   r   r   r   rE   ¦  s   
 rE   c                   @   r%   )Ú-DialogueUserSatisfactionEstimationModelOutputz}The output class for user satisfaction estimation.

    Args:
        logits (`Tensor`): The logits output of the model.
    Nr$   )r   r   r   r   r$   r   r   r   r   r   r   rF   ²  s   
 rF   c                   @   r   )ÚSentencEmbeddingModelOutputa<  The output class for text classification models.

    Args:
        query_embs (`Tensor`, *optional*): The tensor of the query embeddings.
        doc_embs (`Tensor`, *optional*) Then tensor of the doc embeddings.
        loss (`torch.FloatTensor` of shape `(1,)`, *optional*): Sentence Embedding modeling loss.
    NÚquery_embeddingsÚdoc_embeddingsr#   )	r   r   r   r   rH   r   r   rI   r#   r   r   r   r   rG   ¼  r?   rG   c                   @   s:   e Zd ZU dZdZeed< dZeed< dZe	e
 ed< dS )ÚTranslationEvaluationOutputz8The output class for translation evaluation models.
    NÚscorer#   Úinput_format)r   r   r   r   rK   r   r   r#   rL   r   Ústrr   r   r   r   rJ   Ë  s
   
 rJ   c                   @   sr   e Zd ZU dZdZee ed< dZee ed< dZ	eed< dZ
eee  ed< dZeee  ed< dZeed< dS )	Ú!MachineReadingComprehensionOutputa.  The output class for machine reading comprehension models.

    Args:
        loss (`Tensor`, *optional*): The training loss of the current batch
        match_loss (`Tensor`, *optinal*): The match loss of the current batch
        span_logits (`Tensor`): The logits of the span matrix output by the model
        hidden_states (`Tuple[Tensor]`, *optinal*): The hidden states output by the model
        attentions (`Tuple[Tensor]`, *optinal*):  The attention scores output by the model
        input_ids (`Tensor`): The token ids of the input sentence

    Nr#   Ú
match_lossÚspan_logitsr   r   r*   )r   r   r   r   r#   r   r   r   rO   rP   r   r   r   r*   r   r   r   r   rN   Õ  s   
 rN   )"Údataclassesr   Útypingr   r   r   r   Únumpyr0   Úmodelscope.outputs.outputsr   r   r	   r   r   r    r&   r)   r+   r-   r3   r5   r8   r:   r<   r=   r>   r@   rB   rE   rF   rG   rJ   rN   r   r   r   r   Ú<module>   sb    )S
S		