
    eThhG                         S r SSKJrJr  SSKrSSKJrJr  SSK	J
r
JrJrJrJrJr  \R                   " \5      r " S S\5      rg)	zZ
Sequence feature extraction class for common feature extractors to preprocess sequences.
    )OptionalUnionN   )BatchFeatureFeatureExtractionMixin)PaddingStrategy
TensorTypeis_tf_tensoris_torch_tensorloggingto_numpyc                     ^  \ rS rSrSrS\S\S\4U 4S jjr      SS\\	\
\	   \\\	4   \\\
\	   4   \
\\\	4      4   S	\\\\4   S
\\   S\S\\   S\\   S\\\\4      S\	4S jjrS\R$                  SS4S\\\\R(                  4   \	4   S
\\   S\S\\   S\\   S\4S jjr   SS\\\\R(                  4   \	4   S
\\   S\\   S\\   4S jjrSS jrSrU =r$ )SequenceFeatureExtractor   a}  
This is a general feature extraction class for speech recognition.

Args:
    feature_size (`int`):
        The feature dimension of the extracted features.
    sampling_rate (`int`):
        The sampling rate at which the audio files should be digitalized expressed in hertz (Hz).
    padding_value (`float`):
        The value that is used to fill the padding values / vectors.
feature_sizesampling_ratepadding_valuec                    > Xl         X l        X0l        UR                  SS5      U l        UR                  SS5      U l        [        TU ]  " S0 UD6  g )Npadding_siderightreturn_attention_maskT )r   r   r   popr   r   super__init__)selfr   r   r   kwargs	__class__s        f/var/www/auris/envauris/lib/python3.13/site-packages/transformers/feature_extraction_sequence_utils.pyr   !SequenceFeatureExtractor.__init__*   sL    (**"JJ~w?%+ZZ0G%N""6"    Nprocessed_featurespadding
max_length
truncationpad_to_multiple_ofr   return_tensorsreturnc           
        ^ ^ [        U[        [        45      (       aV  [        US   [        [        45      (       a8  US   R                  5        VV	s0 s H  oU V	s/ s H  oU   PM	     sn	_M     nnn	T R                  S   U;  a5  [        ST R                  S    S[        UR                  5       5       35      eUT R                  S      n
Ub  UOT R                  n[        U
5      S:X  a  U(       a  / US'   U$ U
S   n[        U[        [        45      (       aA  Sn[        X   5      S:X  a  US-  n[        X   5      S:X  a  M  U[        U
5      :  a  X   S   nUcx  [        U5      (       a  SnOe[        U5      (       a  SnOR[        U[        [        [        [        [        R                  45      (       a  SnO[        S	U S
[!        U5       S35      eUR#                  5        HP  u  p[        US   [        [        45      (       a  [%        U5      X'   M2  U Vs/ s H  n[%        U5      PM     snX'   MR     T R'                  X#S9nUT R                  S      n
[        U
5      m[)        U4S jUR+                  5        5       5      (       d  [        S5      e/ n[-        T5       HO  nUR#                  5        VVs0 s H  u  nnUUU   _M     nnnT R/                  UUUUS9nUR1                  U5        MQ     U[2        R4                  :X  a%  [7        U 4S jU 5       5      n[2        R8                  n0 n[-        T5       H  nT R;                  UU   UUUUS9nUR#                  5        Ht  u  pUU;  a  / UU'   UR<                  [        R<                  " [        R>                  5      L a  URA                  [        RB                  5      nUU   R1                  U5        Mv     M     [	        UUS9$ s  sn	f s  sn	nf s  snf s  snnf )a=  
Pad input values / input vectors or a batch of input values / input vectors up to predefined length or to the
max sequence length in the batch.

Padding side (left/right) padding values are defined at the feature extractor level (with `self.padding_side`,
`self.padding_value`)

<Tip>

If the `processed_features` passed are dictionary of numpy arrays, PyTorch tensors or TensorFlow tensors, the
result will use the same type unless you provide a different tensor type with `return_tensors`. In the case of
PyTorch tensors, you will lose the specific device of your tensors however.

</Tip>

Args:
    processed_features ([`BatchFeature`], list of [`BatchFeature`], `Dict[str, List[float]]`, `Dict[str, List[List[float]]` or `List[Dict[str, List[float]]]`):
        Processed inputs. Can represent one input ([`BatchFeature`] or `Dict[str, List[float]]`) or a batch of
        input values / vectors (list of [`BatchFeature`], *Dict[str, List[List[float]]]* or *List[Dict[str,
        List[float]]]*) so you can use this method during preprocessing as well as in a PyTorch Dataloader
        collate function.

        Instead of `List[float]` you can have tensors (numpy arrays, PyTorch tensors or TensorFlow tensors),
        see the note above for the return type.
    padding (`bool`, `str` or [`~utils.PaddingStrategy`], *optional*, defaults to `True`):
        Select a strategy to pad the returned sequences (according to the model's padding side and padding
        index) among:

        - `True` or `'longest'`: Pad to the longest sequence in the batch (or no padding if only a single
          sequence if provided).
        - `'max_length'`: Pad to a maximum length specified with the argument `max_length` or to the maximum
          acceptable input length for the model if that argument is not provided.
        - `False` or `'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of different
          lengths).
    max_length (`int`, *optional*):
        Maximum length of the returned list and optionally padding length (see above).
    truncation (`bool`):
        Activates truncation to cut input sequences longer than `max_length` to `max_length`.
    pad_to_multiple_of (`int`, *optional*):
        If set will pad the sequence to a multiple of the provided value.

        This is especially useful to enable the use of Tensor Cores on NVIDIA hardware with compute capability
        `>= 7.5` (Volta), or on TPUs which benefit from having sequence lengths be a multiple of 128.
    return_attention_mask (`bool`, *optional*):
        Whether to return the attention mask. If left to the default, will return the attention mask according
        to the specific feature_extractor's default.

        [What are attention masks?](../glossary#attention-mask)
    return_tensors (`str` or [`~utils.TensorType`], *optional*):
        If set, will return tensors instead of list of python integers. Acceptable values are:

        - `'tf'`: Return TensorFlow `tf.constant` objects.
        - `'pt'`: Return PyTorch `torch.Tensor` objects.
        - `'np'`: Return Numpy `np.ndarray` objects.
r   zYou should supply an instance of `transformers.BatchFeature` or list of `transformers.BatchFeature` to this method that includes z, but you provided attention_maskr   tfptnpztype of z
 unknown: zA. Should be one of a python, numpy, pytorch or tensorflow object.)r#   r$   c              3   @   >#    U  H  n[        U5      T:H  v   M     g 7f)N)len).0v
batch_sizes     r   	<genexpr>/SequenceFeatureExtractor.pad.<locals>.<genexpr>   s     M1LA3q6Z'1Ls   zLSome items in the output dictionary have a different batch size than others.)r$   r&   r%   c              3   Z   >#    U  H   n[        UTR                  S       5      v   M"     g7f)r   N)r/   model_input_names)r0   input_slicer   s     r   r3   r4      s+     m\l[ST-C-CA-F!GHH\ls   (+)r$   padding_strategyr&   r   )tensor_type)"
isinstancelisttupledictr   keysr6   
ValueErrorr   r/   r
   r   intfloatr-   ndarraytypeitemsr   _get_padding_strategiesallvaluesrange	_truncateappendr   LONGESTmax
MAX_LENGTH_paddtypefloat64astypefloat32)r   r"   r#   r$   r%   r&   r   r'   keyexamplerequired_inputfirst_elementindexvaluer1   r8   truncated_inputsikinputsinputs_slicebatch_outputsoutputsr2   s   `                      @r   padSequenceFeatureExtractor.pad4   s   R (4-88ZHZ[\H]`dfr_s=t=tQcdeQfQkQkQm"Qm#2DE2Dwcl2DEEQm  "
 !!!$,>>1151G1G1J0K L+002346  ,D,B,B1,EF%:%F!DLfLf 	 ~!#$79"#34%% 'q)mdE]33En+,1
 n+,1s>** . 5a 8!M**!% //!%MCeRZZ+PQQ!% }oZ]8K7L MV V 
 -224JC%(S%L11*25/"'@E*F18A;*F"'	 5  777_+D,B,B1,EF(
M1C1J1J1LMMMkllz"A*<*B*B*DE*D$!Qa1g*DFE>>%#5%	 * L ##L1 # 666m\lmmJ.99z"Aii #%!1#5&;   G &mmo
m+)+M#&;;"((2::"66!LL4Ec"))%0 . #" M~FFC F"h +G Fs$   
O5O0*O5O;>P 0O5r8   c                    XR                   S      nU[        R                  :X  a  [        U5      nUb  Ub  X$-  S:w  a
  X$-  S-   U-  nU[        R                  :g  =(       a    [        U5      U:  nU(       a5  SU;  a/  [
        R                  " [        U5      [
        R                  S9US'   U(       Ga1  U[        U5      -
  nU R                  S:X  aq  U(       a  [
        R                  " US   SU45      US'   U R                  S:  a  SU4S4OSU4n	[
        R                  " XiSU R                  S9XR                   S   '   U$ U R                  S	:X  aq  U(       a  [
        R                  " US   US45      US'   U R                  S:  a  US4S4OUS4n	[
        R                  " XiSU R                  S9XR                   S   '   U$ [        S
[        U R                  5      -   5      eU$ )a  
Pad inputs (on left/right and up to predefined length or max length in the batch)

Args:
    processed_features (`Union[Dict[str, np.ndarray], BatchFeature]`):
        Dictionary of input values (`np.ndarray[float]`) / input vectors (`List[np.ndarray[float]]`) or batch
        of inputs values (`List[np.ndarray[int]]`) / input vectors (`List[np.ndarray[int]]`)
    max_length (`int`, *optional*):
        Maximum length of the returned list and optionally padding length (see below)
    padding_strategy (`PaddingStrategy`, *optional*, default to `PaddingStrategy.DO_NOT_PAD`):
        PaddingStrategy to use for padding.

        - PaddingStrategy.LONGEST Pad to the longest sequence in the batch
        - PaddingStrategy.MAX_LENGTH: Pad to the max length (default)
        - PaddingStrategy.DO_NOT_PAD: Do not pad
        The feature_extractor padding sides are defined in self.padding_side:

            - 'left': pads on the left of the sequences
            - 'right': pads on the right of the sequences
    pad_to_multiple_of (`int`, *optional*):
        Integer if set will pad the sequence to a multiple of the provided value. This is especially useful to
        enable the use of Tensor Core on NVIDIA hardware with compute capability `>= 7.5` (Volta), or on TPUs
        which benefit from having sequence lengths be a multiple of 128.
    return_attention_mask (`bool`, *optional*):
        Set to False to avoid returning attention mask (default: set to model specifics)
r   r   r*   )rO   r   )r   r   constant)constant_valuesleftzInvalid padding strategy:)r6   r   rK   r/   
DO_NOT_PADr-   onesint32r   r`   r   r   r?   str)
r   r"   r$   r8   r&   r   rU   needs_to_be_padded
differencepadding_shapes
             r   rN   SequenceFeatureExtractor._pad   s   D ,,B,B1,EF666^,J!&8&D*JimnJn%;q@DVVJ-1K1KKpPSTbPcfpPp %5=O%O35773~;NVXV^V^3_/0#c.&99J  G+(;=66*+;<q*o<&'78 >B=N=NQR=R!Z& 9YZ\fXg@B":tOaOaA"#9#9!#<= "! ""f,(;=66*+;<z1o<&'78 >B=N=NQR=R*a& 9YcefXg@B":tOaOaA"#9#9!#<= "! !!<s4CTCT?U!UVV!!r!   c                 &   U(       d  U$ U(       a  Uc  [        S5      eXR                  S      nUb  Ub  X#-  S:w  a
  X#-  S-   U-  n[        U5      U:  nU(       a4  XR                  S      SU XR                  S   '   SU;   a  US   SU US'   U$ )a  
Truncate inputs to predefined length or max length in the batch

Args:
    processed_features(`Union[Dict[str, np.ndarray], BatchFeature]`):
        Dictionary of input values (`np.ndarray[float]`) / input vectors (`List[np.ndarray[float]]`) or batch
        of inputs values (`List[np.ndarray[int]]`) / input vectors (`List[np.ndarray[int]]`)
    max_length (`int`, *optional*):
        maximum length of the returned list and optionally padding length (see below)
    pad_to_multiple_of (`int`, *optional*) :
        Integer if set will pad the sequence to a multiple of the provided value. This is especially useful to
        enable the use of Tensor Core on NVIDIA hardware with compute capability `>= 7.5` (Volta), or on TPUs
        which benefit from having sequence lengths be a multiple of 128.
    truncation (`bool`, *optional*):
        Activates truncation to cut input sequences longer than `max_length` to `max_length`.
NzKWhen setting ``truncation=True``, make sure that ``max_length`` is defined.r   r   r*   )r?   r6   r/   )r   r"   r$   r&   r%   rU   needs_to_be_truncateds          r   rI   "SequenceFeatureExtractor._truncate*  s    . %%J.jkk+,B,B1,EF !&8&D*JimnJn%;q@DVVJ #N 3j @ <NOeOefgOh<ijuku<v55a89#557IJZ7[\g]g7h"#34!!r!   c                    USLaO  USL a  [         R                  nOI[        U[         5      (       d  [        U5      nO([        U[         5      (       a  UnO[         R                  nUc1  W[         R                  :X  a  [        S[         R                   S35      eW[         R                  :w  a  U R                  c  [        S5      eU$ )z#
Find the correct padding strategy
FTzWhen setting ``padding=z(``, make sure that max_length is definedzAsking to pad but the feature_extractor does not have a padding value. Please select a value to use as `padding_value`. For example: `feature_extractor.padding_value = 0.0`.)r   rK   r:   rf   rM   r?   r   )r   r#   r$   r8   s       r   rE   0SequenceFeatureExtractor._get_padding_strategiesU  s     %$#2#:#: 99#27#; G_55#* .99 ?#=#== -o.H.H-IIqr 
 999t?Q?Q?Y] 
  r!   )r   r   r   r   r   )TNFNNN)NNN)FN)__name__
__module____qualname____firstlineno____doc__r@   rA   r   r   r   r;   r=   ri   boolr   r   r	   r`   rf   r-   rB   rN   rI   rE   __static_attributes____classcell__)r   s   @r   r   r      s   
#S # #U #& 6:$( ,004;?lG!l"#d<(()c<'()	+
lG tS/12lG SMlG lG %SMlG  (~lG !sJ!78lG 
lGb %),;,F,F,004F"!$sBJJ"7"EFF" SMF" *	F"
 %SMF"  (~F" 
F"V %),0%))"!$sBJJ"7"EF)" SM)" %SM	)"
 TN)"V   r!   r   )rw   typingr   r   numpyr-   feature_extraction_utilsr   r   utilsr   r	   r
   r   r   r   
get_loggerrs   loggerr   r   r!   r   <module>r      s<    #  J ` ` 
		H	%V 5 V r!   