ó
    pyüižI  ã                   ó†   • S r SSKrSSKJrJr  SSKJrJr  SSK	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.
é    Né   )Úis_valid_audioÚ
load_audio)ÚBatchFeatureÚFeatureExtractionMixin)ÚPaddingStrategyÚ
TensorTypeÚ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      -  S	\\-  \-  S
\S-  S\S\S-  S\S-  S\\-  S-  S\4S jjrS\R                   SS4S\
\\R$                  4   \-  S
\S-  S\S\S-  S\S-  S\
4S jjr   SS\
\\R$                  4   \-  S
\S-  S\S-  S\S-  4S jjrSS jrS\\	\   -  \	\	\      -  4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        €Úk/home/mande/repo/quber/.venv/lib/python3.13/site-packages/transformers/feature_extraction_sequence_utils.pyr   Ú!SequenceFeatureExtractor.__init__)   sL   ø€ Ø(ÔØ*ÔØ*Ôà"ŸJ™J ~°wÓ?ˆÔØ%+§Z¡ZÐ0GÈÓ%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  oˆU V	s/ s H  o™U   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ce  [        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R/                  U5        MQ     U[0        R2                  :X  a%  [5        U 4S jU 5       5      n[0        R6                  n0 n[+        T5       H¡  nT R9                  UU   UUUUS9nUR!                  5        Ht  u  p�UU;  a  / UU'   UR:                  [        R:                  " [        R<                  5      L a  UR?                  [        R@                  5      nUU   R/                  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 or PyTorch 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 or PyTorch 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:

        - `'pt'`: Return PyTorch `torch.Tensor` objects.
        - `'np'`: Return Numpy `np.ndarray` objects.
r   z�You should supply an instance of `transformers.BatchFeature` or list of `transformers.BatchFeature` to this method that includes z, but you provided Úattention_maskr   ÚptÚnpztype of z
 unknown: z6. Should be one of a python, numpy, or pytorch 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   øé € ÐMÒ1L¨A”3�q“6˜ZÖ'Ò1Lùs   ƒ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)r.   Úinput_slicer   s     €r   r1   r2   Æ   s+   øé € ÐmÒ\lÈ[œS ¨T×-CÑ-CÀAÑ-FÑ!G×HÐHÒ\lùs   ƒ(+)r#   Úpadding_strategyr%   r   )Útensor_type)!Ú
isinstanceÚlistÚtupleÚdictr   Úkeysr4   Ú
ValueErrorr   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Úvaluer/   r6   Útruncated_inputsÚiÚkÚinputsÚinputs_sliceÚbatch_outputsÚoutputsr0   s   `                      @r   ÚpadÚSequenceFeatureExtractor.pad3   s  ù€ ôL Ð(¬4´¨-×8Ñ8¼ZÐHZÐ[\ÑH]Ô`dÔfrÐ_s×=tÑ=tð RdÐdeÑQf×QkÑQkÔQmô"ÚQmÈ#Ñ2DÓEÒ2D w˜c”lÑ2DÑEÒEÑQmð ñ "ð
 ×!Ñ! !Ñ$Ð,>Ó>Üð1Ø15×1GÑ1GÈÑ1JÐ0Kð LÜÐ+×0Ñ0Ó2Ó3Ð4ð6óð ð ,¨D×,BÑ,BÀ1Ñ,EÑFˆà%:Ñ%FÑ!ÈD×LfÑLfð 	ô ˆ~Ó !Ó#Þ$Ø79Ð"Ð#3Ñ4Ø%Ð%ð ' qÑ)ˆÜ�m¤d¬E ]×3Ñ3àˆEÜ�nÑ+Ó,°Ó1Ø˜‘
�ô �nÑ+Ó,°Õ1à”s˜>Ó*Ó*Ø .Ñ 5°aÑ 8�àÑ!Ü˜}×-Ñ-Ø!%‘Ü˜M¬C´¼¼eÄRÇZÁZÐ+P×QÑQØ!%‘ä Ø˜}˜o¨Z¼¸]Ó8KÐ7Lð MKð Kóð ð
 -×2Ñ2Ö4‰JˆCÜ˜% ™(¤S¬% L×1Ñ1Ü*2°5«/Ð"Ó'á@EÓ*FÂ¸1¬8°A®;ÁÑ*FÐ"Ó'ñ	 5ð  ×7Ñ7ÀÐ7Ð_Ðà+¨D×,BÑ,BÀ1Ñ,EÑFˆä˜Ó(ˆ
ÜÔMÐ1C×1JÑ1JÔ1LÓM×MÑMÜÐkÓlÐlàÐÜ�zÖ"ˆAØ*<×*BÑ*BÔ*DÔEÒ*D¡$ ! Q�a˜˜1™’gÑ*DˆFÑEàŸ>™>ØØ%Ø#5Ø%ð	 *ð ˆLð ×#Ñ# LÖ1ñ #ð œ×6Ñ6Ó6äÔmÑ\lÓmÓmˆJÜ.×9Ñ9ÐàˆÜ�zÖ"ˆAà—i‘iØ  Ñ#Ø%Ø!1Ø#5Ø&;ð  ð ˆGð &Ÿm™mžo‘
�Ø˜mÓ+Ø)+�M #Ñ&Ø—;‘;¤"§(¢(¬2¯:©:Ó"6Ò6Ø!ŸL™L¬¯©Ó4�EØ˜cÑ"×)Ñ)¨%Ö0ó .ñ #ô" ˜M°~ÑFÐFùò Fùó"ùòd +Gùó Fs$   Á
O"ÁOÁ*O"ÈO(Ê+O-ÏO"r6   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)   )rM   r   )r   r   Úconstant)Úconstant_valuesÚleftzInvalid padding strategy:)r4   r   rI   r-   Ú
DO_NOT_PADr+   ÚonesÚint32r   r^   r   r   r=   Ústr)
r   r!   r#   r6   r%   r   rS   Úneeds_to_be_paddedÚ
differenceÚpadding_shapes
             r   rL   ÚSequenceFeatureExtractor._padÝ   s  € ðD ,×,BÑ,BÀ1Ñ,EÑFˆàœ×6Ñ6Ó6Ü˜^Ó,ˆJàÑ!Ð&8Ñ&DÈ*ÑJiÐmnÓJnØ%Ñ;¸qÑ@ÐDVÑVˆJà-´×1KÑ1KÑK×pÔPSÐTbÓPcÐfpÑPpÐæ Ð%5Ð=OÓ%OÜ35·7²7¼3¸~Ó;NÔVX×V^ÑV^Ñ3_ÐÐ/Ñ0çØ#¤c¨.Ó&9Ñ9ˆJØ× Ñ  GÓ+Þ(Ü;=¿6º6Ø*Ð+;Ñ<¸qÀ*¸oó<Ð&Ð'7Ñ8ð >B×=NÑ=NÐQRÓ=R ! Z °&Ñ 9ÐYZÐ\fÐXg�Ü@BÇÂØ"°:Èt×OaÑOañAÐ"×#9Ñ#9¸!Ñ#<Ñ=ð "Ð!ð ×"Ñ" fÓ,Þ(Ü;=¿6º6Ø*Ð+;Ñ<¸zÈ1¸oó<Ð&Ð'7Ñ8ð >B×=NÑ=NÐQRÓ=R *¨a °&Ñ 9ÐYcÐefÐXg�Ü@BÇÂØ"°:Èt×OaÑOañAÐ"×#9Ñ#9¸!Ñ#<Ñ=ð "Ð!ô !Ð!<¼sÀ4×CTÑCTÓ?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=   r4   r-   )r   r!   r#   r%   r$   rS   Úneeds_to_be_truncateds          r   rG   Ú"SequenceFeatureExtractor._truncate%  sÉ   € ö. Ø%Ð%Þ˜JÑ.ÜÐjÓkÐkà+×,BÑ,BÀ1Ñ,EÑFˆð Ñ!Ð&8Ñ&DÈ*ÑJiÐmnÓJnØ%Ñ;¸qÑ@ÐDVÑVˆJä # NÓ 3°jÑ @Ðæ Ø<N×OeÑOeÐfgÑOhÑ<iÐjuÐkuÐ<vÐ×5Ñ5°aÑ8Ñ9ØÐ#5Ó5Ø7IÐJZÑ7[Ð\gÐ]gÐ7hÐ"Ð#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 definedz­Asking 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   rI   r8   rd   rK   r=   r   )r   r"   r#   r6   s       r   rC   Ú0SequenceFeatureExtractor._get_padding_strategiesP  sÄ   € ð ˜%ÒØ˜$ŠÜ#2×#:Ñ#:Ñ Ü ¬×9Ñ9Ü#2°7Ó#;Ñ Ü˜G¤_×5Ñ5Ø#*Ð øä.×9Ñ9Ðð ÑØ¤?×#=Ñ#=Ó=Ü Ø-¬o×.HÑ.HÐ-IÐIqÐróð ð
 œ×9Ñ9Ó9¸t×?QÑ?QÑ?YÜð]óð ð
  Ðr    Úaudio_url_or_urlsc                 ó
  • [        U[        5      (       a!  U Vs/ s H  o R                  U5      PM     sn$ [        U[        5      (       a  [	        U5      $ [        U5      (       a  U$ [        S[        U5       35      es  snf )zÊ
Convert a single or a list of urls into the corresponding `np.ndarray` objects.

If a single url is passed, the return value will be a single object. If a list is passed a list of objects is
returned.
z=only a single or a list of entries is supported but got type=)r8   r9   Úfetch_audiorg   r   r   Ú	TypeErrorrA   )r   rq   Úxs      r   rs   Ú$SequenceFeatureExtractor.fetch_audiop  s   € ô Ð'¬×.Ñ.Ù1BÓCÒ1B¨A×$Ñ$ QÖ'Ñ1BÑCÐCÜÐ)¬3×/Ñ/ÜÐ/Ó0Ð0ÜÐ-×.Ñ.Ø$Ð$äÐ[Ô\`ÐarÓ\sÐ[tÐuÓvÐvùò Ds   šB )r   r   r   r   r   )TNFNNN)NNN)FN)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r>   r?   r   r   r9   r;   rg   Úboolr   r	   r^   rd   r+   r@   rL   rG   rC   rs   Ú__static_attributes__Ú__classcell__)r   s   @r   r   r      s	  ø† ñ
ð# Sð #¸ð #ÈU÷ #ð" 15Ø!%Ø Ø)-Ø-1Ø26ñhGà(Ø
ˆ|Ñ
ñà
ˆs�LÐ Ñ
!ñ"ð ˆs�D˜Ñ&Ð&Ñ
'ñ(ð ˆt�C˜Ð%Ñ&Ñ
'ñ	(ðhGð ˜‘˜oÑ-ðhGð ˜$‘JðhGð ðhGð   $™JðhGð  $ d™{ðhGð ˜jÑ(¨4Ñ/ðhGð 
õhGðZ "&Ø,;×,FÑ,FØ)-Ø-1ñF"à   b§j¡j Ñ1°LÑ@ðF"ð ˜$‘JðF"ð *ð	F"ð
   $™JðF"ð  $ d™{ðF"ð 
õF"ðV "&Ø)-Ø"&ñ)"à   b§j¡j Ñ1°LÑ@ð)"ð ˜$‘Jð)"ð   $™Jð	)"ð
 ˜4‘Kõ)"ôV ð@w¨S°4¸±9©_¸tÀDÈÁI¹Ñ-N÷ wò wr    r   )r{   Únumpyr+   Úaudio_utilsr   r   Úfeature_extraction_utilsr   r   Úutilsr   r	   r
   r   r   Ú
get_loggerrw   Úloggerr   r   r    r   Ú<module>r…      s>   ðñó ç 3ß Jß RÕ Rð 
×	Ò	˜HÓ	%€ôbwÐ5õ bwr    