
    ёi                        S SK Jr  S SKJr  S SKJr  SSKJrJr  SSK	J
r
  SSKJr  SSKJr  \(       a  S S	KJr  S
S/r  S           SS jjr " S S\5      rg)    )annotations)TYPE_CHECKING)_C_ops   )
check_typecheck_variable_and_dtype)in_dynamic_or_pir_mode)LayerHelper)Layer)Tensorviterbi_decodeViterbiDecoderNc                   [        5       (       a  [        R                  " XX#5      $ [        U SSS/S5        [        USSS/S5        [        USSS5        [	        US[
        S5        [        S0 [        5       D6nS	U0nUR                  U R                  5      nUR                  S5      nUR                  SU UUS
.XxS.US9  Xx4$ )a  
Decode the highest scoring sequence of tags computed by transitions and potentials and get the viterbi path.

Args:
    potentials (Tensor): The input tensor of unary emission. This is a 3-D
        tensor with shape of [batch_size, sequence_length, num_tags]. The data type is float32 or float64.
    transition_params (Tensor): The input tensor of transition matrix. This is a 2-D
        tensor with shape of [num_tags, num_tags]. The data type is float32 or float64.
    lengths (Tensor):  The input tensor of length of each sequence. This is a 1-D tensor with shape of [batch_size]. The data type is int64.
    include_bos_eos_tag (`bool`, optional): If set to True, the last row and the last column of transitions will be considered
        as start tag, the second to last row and the second to last column of transitions will be considered as stop tag. Defaults to ``True``.
    name (str|None, optional): The default value is None. Normally there is no need for user to set this property. For more information, please
        refer to :ref:`api_guide_Name`.

Returns:
    scores(Tensor): The output tensor containing the score for the Viterbi sequence. The shape is [batch_size]
        and the data type is float32 or float64.
    paths(Tensor): The output tensor containing the highest scoring tag indices. The shape is [batch_size, sequence_length]
        and the data type is int64.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> paddle.seed(2023)
        >>> batch_size, seq_len, num_tags = 2, 4, 3
        >>> emission = paddle.rand((batch_size, seq_len, num_tags), dtype='float32')
        >>> length = paddle.randint(1, seq_len + 1, [batch_size])
        >>> tags = paddle.randint(0, num_tags, [batch_size, seq_len])
        >>> transition = paddle.rand((num_tags, num_tags), dtype='float32')
        >>> scores, path = paddle.text.viterbi_decode(emission, transition, length, False)
        >>> print(scores)
        Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [2.57385254, 2.04533720])
        >>> print(path)
        Tensor(shape=[2, 2], dtype=int64, place=Place(cpu), stop_gradient=True,
        [[0, 0],
         [1, 1]])
inputfloat32float64r   transitionslengthint64include_taginclude_bos_eos_tag)Input
TransitionLength)ScoresPath)typeinputsoutputsattrs)r   )r	   r   r   r   r   boolr
   locals"create_variable_for_type_inferencedtype	append_op)	
potentialstransition_paramslengthsr   namehelperr    scorespaths	            Z/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/text/viterbi_decode.pyr   r      s    \ $$7
 	
 Gi35E 	I	 Wh9IJ"M49IJ6VX6F"$78E66z7G7GHF44W=D
+

 "0  	 <    c                  p   ^  \ rS rSr% SrS\S'   S\S'   S\S'     S       SU 4S	 jjjrSS
 jrSrU =r	$ )r   n   a  
Decode the highest scoring sequence of tags computed by transitions and potentials and get the viterbi path.

Args:
    transitions (`Tensor`): The transition matrix. Its dtype is float32 and has a shape of `[num_tags, num_tags]`.
    include_bos_eos_tag (`bool`, optional): If set to True, the last row and the last column of transitions will be considered
        as start tag, the second to last row and the second to last column of transitions will be considered as stop tag. Defaults to ``True``.
    name (str|None, optional): The default value is None. Normally there is no need for user to set this property. For more information, please
        refer to :ref:`api_guide_Name`.

Shape:
    potentials (Tensor): The input tensor of unary emission. This is a 3-D tensor with shape of
        [batch_size, sequence_length, num_tags]. The data type is float32 or float64.
    lengths (Tensor): The input tensor of length of each sequence. This is a 1-D tensor with shape of
        [batch_size]. The data type is int64.

Returns:
    scores(Tensor): The output tensor containing the score for the Viterbi sequence. The shape is [batch_size]
        and the data type is float32 or float64.
    paths(Tensor): The output tensor containing the highest scoring tag indices. The shape is [batch_size, sequence_length]
        and the data type is int64.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> paddle.seed(2023)
        >>> batch_size, seq_len, num_tags = 2, 4, 3
        >>> emission = paddle.rand((batch_size, seq_len, num_tags), dtype='float32')
        >>> length = paddle.randint(1, seq_len + 1, [batch_size])
        >>> tags = paddle.randint(0, num_tags, [batch_size, seq_len])
        >>> transition = paddle.rand((num_tags, num_tags), dtype='float32')
        >>> decoder = paddle.text.ViterbiDecoder(transition, include_bos_eos_tag=False)
        >>> scores, path = decoder(emission, length)
        >>> print(scores)
        Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [2.57385254, 2.04533720])
        >>> print(path)
        Tensor(shape=[2, 2], dtype=int64, place=Place(cpu), stop_gradient=True,
        [[0, 0],
         [1, 1]])
r   r   r!   r   
str | Noner)   c                F   > [         TU ]  5         Xl        X l        X0l        g N)super__init__r   r   r)   )selfr   r   r)   	__class__s       r-   r5   ViterbiDecoder.__init__   s!     	&#6 	r.   c                \    [        UU R                  UU R                  U R                  5      $ r3   )r   r   r   r)   )r6   r&   r(   s      r-   forwardViterbiDecoder.forward   s.    $$II
 	
r.   )r   r)   r   TN)r   r   r   r!   r)   r1   returnNone)r&   r   r(   r   r=   r   )
__name__
__module____qualname____firstlineno____doc____annotations__r5   r:   __static_attributes____classcell__)r7   s   @r-   r   r   n   s_    )V 

 %)			 "	 		
 
	 	
 
r.   r<   )r&   r   r'   r   r(   r   r   r!   r)   r1   r=   r   )
__future__r   typingr   paddler   base.data_feederr   r   base.frameworkr	   base.layer_helperr
   nnr   r   __all__r   r    r.   r-   <module>rP      s    #    C 3 + -
. !%LLL L 	L
 L L^B
U B
r.   