Ë
    T^(h¶—  ã                   ó–  — d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	m
Z
mZmZmZmZ ddlZddlmZ ddlmZmZ dd	lmZmZmZmZmZmZmZmZmZ  ej@                  e!«      Z"e	r# e«       rddl#Z# e«       rddl$Z% e«       rddl&mZ' d
ddœZ(dZ)ee
e*ee+e*f   f      Z,e G d„ de«      «       Z- G d„ de«      Z. G d„ de«      Z/ddgZ0y)z Tokenization class for Wav2Vec2.é    N)Ú	dataclass)Úgroupby)ÚTYPE_CHECKINGÚDictÚListÚOptionalÚTupleÚUnioné   )ÚPreTrainedTokenizer)Ú
AddedTokenÚBatchEncoding)	ÚModelOutputÚPaddingStrategyÚ
TensorTypeÚadd_end_docstringsÚis_flax_availableÚis_tf_availableÚis_torch_availableÚloggingÚ	to_py_objz
vocab.jsonztokenizer_config.json©Ú
vocab_fileÚtokenizer_config_filea�  
            padding (`bool`, `str` or [`~utils.PaddingStrategy`], *optional*, defaults to `False`):
                Activates and controls padding. Accepts the following values:

                - `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*):
                Controls the maximum length to use by one of the truncation/padding parameters.

                If left unset or set to `None`, this will use the predefined model maximum length if a maximum length
                is required by one of the truncation/padding parameters. If the model has no specific maximum input
                length (like XLNet) truncation/padding to a maximum length will be deactivated.
            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).
            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.
            verbose (`bool`, *optional*, defaults to `True`):
                Whether or not to print more information and warnings.
c                   óh   — e Zd ZU dZeee   ef   ed<   dZeee	   e	f   ed<   dZ
eee	   e	f   ed<   y)ÚWav2Vec2CTCTokenizerOutputaN  
    Output type of [` Wav2Vec2CTCTokenizer`], with transcription.

    Args:
        text (list of `str` or `str`):
            Decoded logits in text from. Usually the speech transcription.
        char_offsets (list of `List[Dict[str, Union[int, str]]]` or `List[Dict[str, Union[int, str]]]`):
            Offsets of the decoded characters. In combination with sampling rate and model downsampling rate char
            offsets can be used to compute time stamps for each charater. Total logit score of the beam associated with
            produced text.
        word_offsets (list of `List[Dict[str, Union[int, str]]]` or `List[Dict[str, Union[int, str]]]`):
            Offsets of the decoded words. In combination with sampling rate and model downsampling rate word offsets
            can be used to compute time stamps for each word.
    ÚtextNÚchar_offsetsÚword_offsets)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   ÚstrÚ__annotations__r   Ú
ListOfDictr   © ó    úp/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/wav2vec2/tokenization_wav2vec2.pyr   r   ]   sN   … ñð ��S‘	˜3�Ñ
ÓØ8<€L�%˜˜ZÑ(¨*Ð4Ñ5Ó<Ø8<€L�%˜˜ZÑ(¨*Ð4Ñ5Ô<r(   r   c                   ó*  ‡ — e Zd ZdZeZddgZ	 	 	 	 	 	 	 	 d1ˆ fd„	Zdefd„Z	e
defd„«       Ze
dee   fd	„«       Zej                  d
„ «       Zej                  d„ «       Ze
defd„«       Zdefd„Zd2deee   ee   f   dedefˆ fd„Zd„ Zdedefd„Zdedefd„Z	 	 	 	 d3dee   dededededeeeeef   f   fd„Zedee   dee   dedeeeeeef   f      fd„«       Ze	 d4d eeeeef   f   d!edeeeeef   f   fd"„«       Zd2d#„Z 	 	 	 	 	 	 d5d$ee   d%ed&ee   dededee   dee   defd'„Z!	 	 	 	 d6d(eee   eee      d)d*d+f   d%ed&ee   dededee   fd,„Z"	 	 	 	 d6d$eeee   d)d*d+f   d%ed&ee   dededefd-„Z#d7d.ed/ee   de$e   fd0„Z%ˆ xZ&S )8ÚWav2Vec2CTCTokenizera   
    Constructs a Wav2Vec2CTC tokenizer.

    This tokenizer inherits from [`PreTrainedTokenizer`] which contains some of the main methods. Users should refer to
    the superclass for more information regarding such methods.

    Args:
        vocab_file (`str`):
            File containing the vocabulary.
        bos_token (`str`, *optional*, defaults to `"<s>"`):
            The beginning of sentence token.
        eos_token (`str`, *optional*, defaults to `"</s>"`):
            The end of sentence token.
        unk_token (`str`, *optional*, defaults to `"<unk>"`):
            The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this
            token instead.
        pad_token (`str`, *optional*, defaults to `"<pad>"`):
            The token used for padding, for example when batching sequences of different lengths.
        word_delimiter_token (`str`, *optional*, defaults to `"|"`):
            The token used for defining the end of a word.
        do_lower_case (`bool`, *optional*, defaults to `False`):
            Whether or not to accept lowercase input and lowercase the output when decoding.
        target_lang (`str`, *optional*):
            A target language the tokenizer should set by default. `target_lang` has to be defined for multi-lingual,
            nested vocabulary such as [facebook/mms-1b-all](https://huggingface.co/facebook/mms-1b-all).

        **kwargs
            Additional keyword arguments passed along to [`PreTrainedTokenizer`]
    Ú	input_idsÚattention_maskc
                 ó@  •— || _         || _        || _        |	| _        t	        |d¬«      5 }t        j                  |«      | _        d d d «       |	�| j                  |	   | _        n| j                  | _        | j                  j                  «       D ��ci c]  \  }}||“Œ
 c}}| _
        t        ‰| �0  d||||||||	dœ|
¤Ž | j                  j                  «       D ]/  }t        |«      dkD  sŒ| j                  t!        |ddd¬«      «       Œ1 y # 1 sw Y   ŒÉxY wc c}}w )	Núutf-8©Úencoding)Ú	unk_tokenÚ	bos_tokenÚ	eos_tokenÚ	pad_tokenÚdo_lower_caseÚword_delimiter_tokenÚreplace_word_delimiter_charÚtarget_langé   TF©ÚrstripÚlstripÚ
normalizedr'   )Ú_word_delimiter_tokenr6   r8   r9   ÚopenÚjsonÚloadÚvocabÚencoderÚitemsÚdecoderÚsuperÚ__init__ÚkeysÚlenÚ
add_tokensr   )Úselfr   r3   r4   r2   r5   r7   r8   r6   r9   ÚkwargsÚvocab_handleÚkÚvÚtokenÚ	__class__s                  €r)   rH   zWav2Vec2CTCTokenizer.__init__•   s  ø€ ð &:ˆÔ"à*ˆÔØ+FˆÔ(Ø&ˆÔä�* wÔ/ð 	1°<ÜŸ™ <Ó0ˆDŒJ÷	1ð
 Ð"ØŸ:™: kÑ2ˆD�LàŸ:™:ˆDŒLà)-¯©×);Ñ);Ó)=×>¡  A˜˜1™Ó>ˆŒä‰Ñð 
	
ØØØØØ'Ø!5Ø(CØ#ñ
	
ð ò
	
ð —\‘\×&Ñ&Ó(ò 	_ˆEÜ�5‹z˜A‹~Ø—‘¤
¨5¸ÀdÐW\Ô ]Õ^ñ	_÷5	1ð 	1üó ?s   «DÂDÄDr9   c           	      óP  — | j                   | j                  k(  rt        | j                   › d�«      ‚|| j                   vr8t        |› ddj                  | j                   j	                  «       «      › d�«      ‚|| _        || j                  d<   | j                   |   | _        | j                  j                  «       D ��ci c]  \  }}||“Œ
 c}}| _        | j                  j	                  «       D ]/  }t        |«      dkD  sŒ| j                  t        |ddd¬	«      «       Œ1 y
c c}}w )zN
        Set the target language of a nested multi-lingual dictionary
        zF is not a multi-lingual, nested tokenizer. Cannot set target language.z does not exist. Choose one of z, ú.r9   r:   TFr;   N)rC   rD   Ú
ValueErrorÚjoinrI   r9   Úinit_kwargsrE   rF   rJ   rK   r   )rL   r9   rO   rP   rQ   s        r)   Úset_target_langz$Wav2Vec2CTCTokenizer.set_target_langÆ   s  € ð �:‰:˜Ÿ™Ò%Ü §
¡
˜|Ð+qÐrÓsÐsà˜dŸj™jÑ(Ü ˜}Ð,KÈDÏIÉIÐVZ×V`ÑV`×VeÑVeÓVgÓLhÐKiÐijÐkÓlÐlà&ˆÔØ*5ˆ×Ñ˜Ñ'Ø—z‘z +Ñ.ˆŒØ)-¯©×);Ñ);Ó)=×>¡  A˜˜1™Ó>ˆŒð —\‘\×&Ñ&Ó(ò 	_ˆEÜ�5‹z˜A‹~Ø—‘¤
¨5¸ÀdÐW\Ô ]Õ^ñ	_ùó	 ?s   Â?D"Úreturnc                 óˆ   — | j                   €"| j                  rt        j                  d«       yt	        | j                   «      S )z^
        `str`: Word delimiter token. Log an error if used while not having been set.
        Nú2Using word_delimiter_token, but it is not set yet.©r?   ÚverboseÚloggerÚerrorr$   ©rL   s    r)   r7   z)Wav2Vec2CTCTokenizer.word_delimiter_tokenÛ   ó7   € ð
 ×%Ñ%Ð-°$·,²,Ü�L‰LÐMÔNØÜ�4×-Ñ-Ó.Ð.r(   c                 óR   — | j                   €y| j                  | j                  «      S ©zŠ
        `Optional[int]`: Id of the word_delimiter_token in the vocabulary. Returns `None` if the token has not been
        set.
        N©r?   Úconvert_tokens_to_idsr7   r`   s    r)   Úword_delimiter_token_idz,Wav2Vec2CTCTokenizer.word_delimiter_token_idå   ó*   € ð ×%Ñ%Ð-ØØ×)Ñ)¨$×*CÑ*CÓDÐDr(   c                 ó   — || _         y ©N©r?   ©rL   Úvalues     r)   r7   z)Wav2Vec2CTCTokenizer.word_delimiter_tokenï   ó
   € à%*ˆÕ"r(   c                 ó0   — | j                  |«      | _        y ri   ©re   r?   rk   s     r)   rf   z,Wav2Vec2CTCTokenizer.word_delimiter_token_idó   ó   € à%)×%?Ñ%?ÀÓ%FˆÕ"r(   c                 ó,   — t        | j                  «      S ri   ©rJ   rF   r`   s    r)   Ú
vocab_sizezWav2Vec2CTCTokenizer.vocab_size÷   ó   € ä�4—<‘<Ó Ð r(   c                 óf   — t        | j                  «      }|j                  | j                  «       |S ri   )ÚdictrD   ÚupdateÚadded_tokens_encoder)rL   rC   s     r)   Ú	get_vocabzWav2Vec2CTCTokenizer.get_vocabû   s'   € Ü�T—\‘\Ó"ˆØ�‰�T×.Ñ.Ô/Øˆr(   Ú
new_tokensÚspecial_tokensc           	      ó¶   •— g }|D ]B  }t        |t        «      r|j                  t        |ddd¬«      «       Œ2|j                  |«       ŒD t        ‰| �  ||«      S )NFr;   )Ú
isinstancer$   Úappendr   rG   Ú_add_tokens)rL   rz   r{   Úto_addrQ   rR   s        €r)   r   z Wav2Vec2CTCTokenizer._add_tokens   sY   ø€ àˆØò 	%ˆEÜ˜%¤Ô%Ø—‘œj¨°uÀUÐW\Ô]Õ^à—‘˜eÕ$ð		%ô ‰wÑ" 6¨>Ó:Ð:r(   c                 ó„   — | j                   r|j                  «       }t        |j                  d| j                  «      «      S )z\
        Converts a string into a sequence of tokens (string), using the tokenizer.
        ú )r6   ÚupperÚlistÚreplacer7   )rL   r   rM   s      r)   Ú	_tokenizezWav2Vec2CTCTokenizer._tokenize  s4   € ð ×ÒØ—:‘:“<ˆDä�D—L‘L  d×&?Ñ&?Ó@ÓAÐAr(   rQ   c                 ó€   — | j                   j                  || j                   j                  | j                  «      «      S ©z=Converts a token (str) in an index (integer) using the vocab.©rD   Úgetr2   ©rL   rQ   s     r)   Ú_convert_token_to_idz)Wav2Vec2CTCTokenizer._convert_token_to_id  ó,   € à�|‰|×Ñ  t§|¡|×'7Ñ'7¸¿¹Ó'GÓHÐHr(   Úindexc                 óR   — | j                   j                  || j                  «      }|S ©z=Converts an index (integer) in a token (str) using the vocab.©rF   rŠ   r2   ©rL   rŽ   Úresults      r)   Ú_convert_id_to_tokenz)Wav2Vec2CTCTokenizer._convert_id_to_token  ó!   € à—‘×!Ñ! %¨¯©Ó8ˆØˆr(   ÚtokensÚgroup_tokensÚspaces_between_special_tokensÚoutput_char_offsetsÚoutput_word_offsetsc                 óî  ‡ — t        |«      dk(  rdg g dœS |rt        d„ t        |«      D «       Ž \  }}n|}t        |«      dgz  }t        t	        ˆ fd„|«      «      }|D �	cg c]  }	|	‰ j
                  k(  r‰ j                  n|	‘Œ! }}	dx}
}|s|rœ‰ j                  ||‰ j                  «      }
t        |
«      t        |«      k7  r)t        d|
› d	|› d
t        |
«      › dt        |«      › �«      ‚t        |«      D ]  \  }}	|	|
|   d<   Œ d}|r‰ j                  |
‰ j                  «      }|sd}
|rdnd}|j                  |«      j                  «       }‰ j                  r|j                  «       }||
|dœS c c}	w )úl
        Converts a connectionist-temporal-classification (CTC) output tokens into a single string.
        r   Ú ©r   r   r   c              3   óN   K  — | ]  \  }}|t        t        |«      «      f–— Œ y ­wri   )rJ   r„   )Ú.0rQ   Ú
group_iters      r)   ú	<genexpr>z@Wav2Vec2CTCTokenizer.convert_tokens_to_string.<locals>.<genexpr>,  s%   è ø€ Ò+tÑO`ÈuÐV`¨U´C¼¸ZÓ8HÓ4IÔ,JÑ+tùs   ‚#%r:   c                 ó"   •— | ‰j                   k7  S ri   ©r5   )ÚcharrL   s    €r)   ú<lambda>z?Wav2Vec2CTCTokenizer.convert_tokens_to_string.<locals>.<lambda>2  s   ø€ °4¸4¿>¹>Ñ3I€ r(   Nz`char_offsets`: z and `processed_tokens`: z9 have to be of the same length, but are: `len(offsets)`: z and `len(processed_tokens)`: r¥   r‚   )rJ   Úzipr   r„   Úfilterr7   r8   Ú_compute_offsetsr5   rU   Ú	enumerateÚ_get_word_offsetsrV   Ústripr6   Úlower)rL   r–   r—   r˜   r™   rš   ÚcharsÚchar_repetitionsÚprocessed_charsr¥   r   r   ÚiÚ	join_charÚstrings   `              r)   Úconvert_tokens_to_stringz-Wav2Vec2CTCTokenizer.convert_tokens_to_string  sº  ø€ ô ˆv‹;˜!ÒØ°ÀBÑGÐGáÜ&)Ñ+tÔdkÐlrÓdsÔ+tÐ&uÑ#ˆEÑ#àˆEÜ" 6›{¨a¨SÑ0Ðô œvÓ&IÈ5ÓQÓRˆð ixö
Ø`d°¸×8QÑ8QÒ0QˆD×,Ò,ÐW[Ñ[ð
ˆð 
ð
 '+Ð*ˆ�|ÙÑ"5Ø×0Ñ0Ð1AÀ5È$Ï.É.ÓYˆLä�<Ó ¤C¨Ó$8Ò8Ü Ø& | nÐ4MÈoÐM^ð'Ü'*¨<Ó'8Ð&9ð :Ü˜OÓ,Ð-ð/óð ô % _Ó5ò /‘��4Ø*.�˜Q‘ Ò'ð/ð  ˆLÙ"Ø#×5Ñ5°lÀD×DdÑDdÓe�ñ 'Ø#�ñ 9‘C¸bˆ	Ø—‘ Ó0×6Ñ6Ó8ˆà×ÒØ—\‘\“^ˆFà°ÈlÑ[Ð[ùòK
s   Á!$E2r¯   r®   Ú	ctc_tokenc           	      ó  ‡— t        j                  | «      j                  «       }t        j                  dg|d d f«      }t	        |||«      D ���cg c]  \  }}}|||dœ‘Œ }}}}t        t        ˆfd„|«      «      }|S c c}}}w )Nr   éÿÿÿÿ)r¥   Ústart_offsetÚ
end_offsetc                 ó   •— | d   ‰k7  S )Nr¥   r'   )Úoffsetsrµ   s    €r)   r¦   z7Wav2Vec2CTCTokenizer._compute_offsets.<locals>.<lambda>h  s   ø€ ¨g°f©oÀÑ.J€ r(   )ÚnpÚasarrayÚcumsumÚconcatenater§   r„   r¨   )	r¯   r®   rµ   Úend_indicesÚstart_indicesÚtÚsÚer»   s	     `      r)   r©   z%Wav2Vec2CTCTokenizer._compute_offsets\  s’   ø€ ô —j‘jÐ!1Ó2×9Ñ9Ó;ˆÜŸ™¨¨¨[¸¸"Ð-=Ð'>Ó?ˆô LOÈuÐVcÐepÓKq÷
ð 
Ù@GÀÀ1Àa�Q¨¸Ó;ð
ˆò 
ô
 ”vÓJÈGÓTÓUˆØˆùô
s   ÁB r»   Úword_delimiter_charc                 ó  — g }d}d}d}d}t        | «      D ]L  \  }}|d   }	|	|k(  rdnd}
|
|k(  r|d   }||	z  }n'|
dk(  r|j                  |||dœ«       n|d   }|d   }|	}|
}ŒN |dk(  r|j                  |||dœ«       |S )	NÚSPACEr�   r   r¥   ÚWORDr¹   )Úwordr¸   r¹   r¸   )rª   r~   )r»   rÅ   r   Ú
last_staterÉ   r¸   r¹   r±   Úoffsetr¥   Ústates              r)   r«   z&Wav2Vec2CTCTokenizer._get_word_offsetsk  sÎ   € ð ˆàˆ
ØˆØˆØˆ
Ü" 7Ó+ò 	‰IˆAˆvØ˜&‘>ˆDØ#Ð':Ò:‘GÀˆEà˜
Ò"à# LÑ1�
Ø˜‘‘ð ˜GÒ#à ×'Ñ'°À|ÐcmÑ(nÕoð $*¨.Ñ#9�LØ!'¨Ñ!5�JØ�Dà‰Jð'	ð( ˜ÒØ×Ñ¨¸|Ð[eÑ fÔgàÐr(   c                 ó   — |rd|z   }||fS )Nr‚   r'   )rL   r   Úis_split_into_wordsrM   s       r)   Úprepare_for_tokenizationz-Wav2Vec2CTCTokenizer.prepare_for_tokenizationŽ  s   € ÙØ˜‘:ˆDØ�fˆ~Ðr(   Ú	token_idsÚskip_special_tokensÚclean_up_tokenization_spacesc                 óh  — | j                  ||¬«      }g }	|D ]A  }
|r,|
| j                  v s|
| j                  k7  r|
| j                  v rŒ1|	j	                  |
«       ŒC | j                  |	||||¬«      }|d   }|�|n| j                  }|r| j                  |«      }|s|rt        ||d   |d   ¬«      S |S )á7  
        special _decode function is needed for Wav2Vec2Tokenizer because added tokens should be treated exactly the
        same as tokens of the base vocabulary and therefore the function `convert_tokens_to_string` has to be called on
        the whole token list and not individually on added tokens
        ©rÑ   )r—   r˜   rš   r™   r   r   r   rž   )	Úconvert_ids_to_tokensÚall_special_idsr5   Úall_special_tokensr~   r´   rÒ   Úclean_up_tokenizationr   )rL   rÐ   rÑ   rÒ   r—   r˜   rš   r™   Úfiltered_tokensr“   rQ   Ústring_outputr   s                r)   Ú_decodezWav2Vec2CTCTokenizer._decode“  sö   € ð ×4Ñ4°YÐTgÐ4ÓhˆàˆØ$ò 	!ˆEÙ"Ø˜×-Ñ-Ñ-°%¸4¿>¹>Ò2IÈeÐW[×WnÑWnÑNnàØ�M‰M˜%Õ ð	!ð ×5Ñ5ØØ%Ø*GØ 3Ø 3ð 6ó 
ˆð ˜VÑ$ˆð ,Ð7ñ )à×2Ñ2ð 	%ñ
 (Ø×-Ñ-¨dÓ3ˆDáÑ"5Ü-ØØ*¨>Ñ:Ø*¨>Ñ:ôð ð ˆKr(   Ú	sequencesz
np.ndarrayztorch.Tensorz	tf.Tensorc                 óØ   — |D �cg c]  } | j                   |f||||dœ|¤Ž‘Œ }}|s|r0t        |d   D �	�
ci c]  }	|	|D �
cg c]  }
|
|	   ‘Œ	 c}
“Œ c}
}	«      S |S c c}w c c}
w c c}
}	w )aÅ  
        Convert a list of lists of token ids into a list of strings by calling decode.

        Args:
            sequences (`Union[List[int], List[List[int]], np.ndarray, torch.Tensor, tf.Tensor]`):
                List of tokenized input ids. Can be obtained using the `__call__` method.
            skip_special_tokens (`bool`, *optional*, defaults to `False`):
                Whether or not to remove special tokens in the decoding.
            clean_up_tokenization_spaces (`bool`, *optional*):
                Whether or not to clean up the tokenization spaces.
            output_char_offsets (`bool`, *optional*, defaults to `False`):
                Whether or not to output character offsets. Character offsets can be used in combination with the
                sampling rate and model downsampling rate to compute the time-stamps of transcribed characters.

                <Tip>

                Please take a look at the Example of [`~Wav2Vec2CTCTokenizer.decode`] to better understand how to make
                use of `output_char_offsets`. [`~Wav2Vec2CTCTokenizer.batch_decode`] works the same way with batched
                output.

                </Tip>

            output_word_offsets (`bool`, *optional*, defaults to `False`):
                Whether or not to output word offsets. Word offsets can be used in combination with the sampling rate
                and model downsampling rate to compute the time-stamps of transcribed words.

                <Tip>

                Please take a look at the Example of [`~Wav2Vec2CTCTokenizer.decode`] to better understand how to make
                use of `output_word_offsets`. [`~Wav2Vec2CTCTokenizer.batch_decode`] works the same way with batched
                output.

                </Tip>

            kwargs (additional keyword arguments, *optional*):
                Will be passed to the underlying model specific decode method.

        Returns:
            `List[str]` or [`~models.wav2vec2.tokenization_wav2vec2.Wav2Vec2CTCTokenizerOutput`]: The list of decoded
            sentences. Will be a [`~models.wav2vec2.tokenization_wav2vec2.Wav2Vec2CTCTokenizerOutput`] when
            `output_char_offsets == True` or `output_word_offsets == True`.
        )rÑ   rÒ   r™   rš   r   )Údecoder   )rL   rÝ   rÑ   rÒ   r™   rš   rM   ÚseqÚbatch_decodedrO   Úds              r)   Úbatch_decodez!Wav2Vec2CTCTokenizer.batch_decodeÊ  s›   € ðx !ö

ð ð ˆD�K‰KØðà$7Ø-IØ$7Ø$7ñð óð

ˆð 

ñ Ñ"5ä-ÐYfÐghÑYi×.jÐTU¨qÀÖ2O¸A°1°Q³4Ò2OÑ/OÓ.jÓkÐkàÐùò

ùò 3PùÓ.js   …A·
A&
ÁA!ÁA&
Á!A&
c           	      óH   — t        |«      } | j                  d|||||dœ|¤ŽS )a‚  
        Converts a sequence of ids in a string, using the tokenizer and vocabulary with options to remove special
        tokens and clean up tokenization spaces.

        Similar to doing `self.convert_tokens_to_string(self.convert_ids_to_tokens(token_ids))`.

        Args:
            token_ids (`Union[int, List[int], np.ndarray, torch.Tensor, tf.Tensor]`):
                List of tokenized input ids. Can be obtained using the `__call__` method.
            skip_special_tokens (`bool`, *optional*, defaults to `False`):
                Whether or not to remove special tokens in the decoding.
            clean_up_tokenization_spaces (`bool`, *optional*):
                Whether or not to clean up the tokenization spaces.
            output_char_offsets (`bool`, *optional*, defaults to `False`):
                Whether or not to output character offsets. Character offsets can be used in combination with the
                sampling rate and model downsampling rate to compute the time-stamps of transcribed characters.

                <Tip>

                Please take a look at the example below to better understand how to make use of `output_char_offsets`.

                </Tip>

            output_word_offsets (`bool`, *optional*, defaults to `False`):
                Whether or not to output word offsets. Word offsets can be used in combination with the sampling rate
                and model downsampling rate to compute the time-stamps of transcribed words.

                <Tip>

                Please take a look at the example below to better understand how to make use of `output_word_offsets`.

                </Tip>

            kwargs (additional keyword arguments, *optional*):
                Will be passed to the underlying model specific decode method.

        Returns:
            `str` or [`~models.wav2vec2.tokenization_wav2vec2.Wav2Vec2CTCTokenizerOutput`]: The list of decoded
            sentences. Will be a [`~models.wav2vec2.tokenization_wav2vec2.Wav2Vec2CTCTokenizerOutput`] when
            `output_char_offsets == True` or `output_word_offsets == True`.

        Example:

        ```python
        >>> # Let's see how to retrieve time steps for a model
        >>> from transformers import AutoTokenizer, AutoFeatureExtractor, AutoModelForCTC
        >>> from datasets import load_dataset
        >>> import datasets
        >>> import torch

        >>> # import model, feature extractor, tokenizer
        >>> model = AutoModelForCTC.from_pretrained("facebook/wav2vec2-base-960h")
        >>> tokenizer = AutoTokenizer.from_pretrained("facebook/wav2vec2-base-960h")
        >>> feature_extractor = AutoFeatureExtractor.from_pretrained("facebook/wav2vec2-base-960h")

        >>> # load first sample of English common_voice
        >>> dataset = load_dataset("mozilla-foundation/common_voice_11_0", "en", split="train", streaming=True, trust_remote_code=True)
        >>> dataset = dataset.cast_column("audio", datasets.Audio(sampling_rate=16_000))
        >>> dataset_iter = iter(dataset)
        >>> sample = next(dataset_iter)

        >>> # forward sample through model to get greedily predicted transcription ids
        >>> input_values = feature_extractor(sample["audio"]["array"], return_tensors="pt").input_values
        >>> logits = model(input_values).logits[0]
        >>> pred_ids = torch.argmax(logits, axis=-1)

        >>> # retrieve word stamps (analogous commands for `output_char_offsets`)
        >>> outputs = tokenizer.decode(pred_ids, output_word_offsets=True)
        >>> # compute `time_offset` in seconds as product of downsampling ratio and sampling_rate
        >>> time_offset = model.config.inputs_to_logits_ratio / feature_extractor.sampling_rate

        >>> word_offsets = [
        ...     {
        ...         "word": d["word"],
        ...         "start_time": round(d["start_offset"] * time_offset, 2),
        ...         "end_time": round(d["end_offset"] * time_offset, 2),
        ...     }
        ...     for d in outputs.word_offsets
        ... ]
        >>> # compare word offsets with audio `en_train_0/common_voice_en_19121553.mp3` online on the dataset viewer:
        >>> # https://huggingface.co/datasets/mozilla-foundation/common_voice_11_0/viewer/en
        >>> word_offsets[:3]
        [{'word': 'THE', 'start_time': 0.7, 'end_time': 0.78}, {'word': 'TRICK', 'start_time': 0.88, 'end_time': 1.08}, {'word': 'APPEARS', 'start_time': 1.2, 'end_time': 1.64}]
        ```)rÐ   rÑ   rÒ   r™   rš   r'   )r   rÜ   )rL   rÐ   rÑ   rÒ   r™   rš   rM   s          r)   rß   zWav2Vec2CTCTokenizer.decode  s@   € ô| ˜iÓ(ˆ	àˆt�|‰|ð 
ØØ 3Ø)EØ 3Ø 3ñ
ð ñ
ð 	
r(   Úsave_directoryÚfilename_prefixc           	      ó�  — t         j                  j                  |«      st        j	                  d|› d�«       y t         j                  j                  ||r|dz   ndt        d   z   «      }t        |dd¬«      5 }|j                  t        j                  | j                  d	d
d¬«      dz   «       d d d «       |fS # 1 sw Y   |fS xY w©NzVocabulary path (z) should be a directoryú-r�   r   Úwr/   r0   é   TF)ÚindentÚ	sort_keysÚensure_asciiú
)ÚosÚpathÚisdirr^   r_   rV   ÚVOCAB_FILES_NAMESr@   ÚwriterA   ÚdumpsrC   ©rL   rå   ræ   r   Úfs        r)   Úsave_vocabularyz$Wav2Vec2CTCTokenizer.save_vocabularyy  s¶   € Ü�w‰w�}‰}˜^Ô,Ü�L‰LÐ,¨^Ð,<Ð<SÐTÔUØÜ—W‘W—\‘\Ø±o˜_¨sÒ2È2ÔQbÐcoÑQpÑpó
ˆ
ô �*˜c¨GÔ4ð 	a¸Ø�G‰G”D—J‘J˜tŸz™z°!¸tÐRWÔXÐ[_Ñ_Ô`÷	að ˆ}Ð÷	að ˆ}Ðúó   Á96B:Â:C)ú<s>ú</s>ú<unk>ú<pad>ú|r‚   FN)F)TFFF)r‚   )FNTFFF)FNFFri   )'r    r!   r"   r#   ró   Úvocab_files_namesÚmodel_input_namesrH   r$   rX   Úpropertyr7   r   Úintrf   Úsetterrs   r   ry   r
   r   r   Úboolr   r†   rŒ   r”   Úfloatr´   Ústaticmethodr©   r«   rÏ   rÜ   rã   rß   r	   rø   Ú__classcell__©rR   s   @r)   r+   r+   s   sá  ø„ ñð< *ÐØ$Ð&6Ð7Ðð
 ØØØØ Ø$'ØØõ/_ðb_¨3ó _ð* ð/ cò /ó ð/ð ðE¨°#©ò Eó ðEð × Ñ ñ+ó !ð+ð ×#Ñ#ñGó $ðGð ð!˜Cò !ó ð!ð˜4ó ñ
	; e¨D°©I°t¸JÑ7GÐ,GÑ&Hð 	;ÐZ^ð 	;Ðknõ 	;òBðI¨#ð I°#ó Ið¨#ð °#ó ð "Ø.3Ø$)Ø$)ñ=\à�S‘	ð=\ð ð=\ð (,ð	=\ð
 "ð=\ð "ð=\ð 
ˆc�5˜˜e˜Ñ$Ð$Ñ	%ó=\ð~ ðØ˜s™)ðØ,0°©IðØBEðà	ˆd�3˜˜c 3˜h™Ð'Ñ(Ñ	)òó ðð àJMñ Ø�c˜5  e Ñ,Ð,Ñ-ð ØDGð à	ˆc�5˜˜e˜Ñ$Ð$Ñ	%ò ó ð óDð %*Ø7;Ø!Ø.3Ø.3Ø.3ñ2à˜‘9ð2ð "ð2ð '/¨t¡nð	2ð
 ð2ð (,ð2ð & d™^ð2ð & d™^ð2ð 
ó2ðt %*Ø7;Ø$)Ø$)ñBà˜˜c™ D¨¨c©¡O°\À>ÐS^Ð^Ñ_ðBð "ðBð '/¨t¡nð	Bð
 "ðBð "ðBð 
ˆc‰óBðR %*Ø7;Ø$)Ø$)ñg
à˜˜d 3™i¨°~À{ÐRÑSðg
ð "ðg
ð '/¨t¡nð	g
ð
 "ðg
ð "ðg
ð 
óg
ñR¨cð ÀHÈSÁMð Ð]bÐcfÑ]g÷ r(   r+   c                   ó8  ‡ — e Zd ZdZeZddiddidœZddgZ	 	 	 	 	 	 	 	 d%ˆ fd„	Ze	d	e
fd
„«       Ze	d	ee   fd„«       Zej                  d„ «       Zej                  d„ «       Z ee«      	 	 	 	 	 	 d&deej(                  ee   eej(                     eee      f   deee
ef   dee   dee   dee
   deee
ef      ded	efd„«       Ze	d	efd„«       Zd	efd„Zde
d	efd„Zded	e
fd„Z dee
   d	e
fd„Z!	 	 d'dee   ded ee   d	e
fd!„Z"d(d"e
d#ee
   d	e#e
   fd$„Z$ˆ xZ%S ))ÚWav2Vec2Tokenizera8	  
    Constructs a Wav2Vec2 tokenizer.

    This tokenizer inherits from [`PreTrainedTokenizer`] which contains some of the main methods. Users should refer to
    the superclass for more information regarding such methods.

    Args:
        vocab_file (`str`):
            File containing the vocabulary.
        bos_token (`str`, *optional*, defaults to `"<s>"`):
            The beginning of sentence token.
        eos_token (`str`, *optional*, defaults to `"</s>"`):
            The end of sentence token.
        unk_token (`str`, *optional*, defaults to `"<unk>"`):
            The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this
            token instead.
        pad_token (`str`, *optional*, defaults to `"<pad>"`):
            The token used for padding, for example when batching sequences of different lengths.
        word_delimiter_token (`str`, *optional*, defaults to `"|"`):
            The token used for defining the end of a word.
        do_lower_case (`bool`, *optional*, defaults to `False`):
            Whether or not to lowercase the output when decoding.
        do_normalize (`bool`, *optional*, defaults to `False`):
            Whether or not to zero-mean unit-variance normalize the input. Normalizing can help to significantly
            improve the performance for some models, *e.g.*,
            [wav2vec2-lv60](https://huggingface.co/models?search=lv60).
        return_attention_mask (`bool`, *optional*, defaults to `False`):
            Whether or not [`~Wav2Vec2Tokenizer.__call__`] should return `attention_mask`.

            <Tip>

            Wav2Vec2 models that have set `config.feat_extract_norm == "group"`, such as
            [wav2vec2-base](https://huggingface.co/facebook/wav2vec2-base-960h), have **not** been trained using
            `attention_mask`. For such models, `input_values` should simply be padded with 0 and no `attention_mask`
            should be passed.

            For Wav2Vec2 models that have set `config.feat_extract_norm == "layer"`, such as
            [wav2vec2-lv60](https://huggingface.co/facebook/wav2vec2-large-960h-lv60-self), `attention_mask` should be
            passed for batched inference.

            </Tip>

        **kwargs
            Additional keyword arguments passed along to [`PreTrainedTokenizer`]
    zfacebook/wav2vec2-base-960hzJhttps://huggingface.co/facebook/wav2vec2-base-960h/resolve/main/vocab.jsonzNhttps://huggingface.co/facebook/wav2vec2-base-960h/resolve/main/tokenizer.jsonr   Úinput_valuesr-   c
                 óŒ  •— t        j                  dt        «       || _        || _        |	| _        || _        t        |d¬«      5 }t        j                  |«      | _
        d d d «       | j                  j                  «       D ��ci c]  \  }}||“Œ
 c}}| _        t        ‰| �8  d|||||||	|dœ|
¤Ž y # 1 sw Y   ŒUxY wc c}}w )NzŸThe class `Wav2Vec2Tokenizer` is deprecated and will be removed in version 5 of Transformers. Please use `Wav2Vec2Processor` or `Wav2Vec2CTCTokenizer` instead.r/   r0   )r2   r3   r4   r5   r6   Údo_normalizeÚreturn_attention_maskr7   r'   )ÚwarningsÚwarnÚFutureWarningr?   r6   r  r  r@   rA   rB   rD   rE   rF   rG   rH   )rL   r   r3   r4   r2   r5   r7   r6   r  r  rM   rN   rO   rP   rR   s                 €r)   rH   zWav2Vec2Tokenizer.__init__Ã  sÎ   ø€ ô 	�‰ðFäô	
ð &:ˆÔ"à*ˆÔØ%:ˆÔ"Ø(ˆÔä�* wÔ/ð 	3°<ÜŸ9™9 \Ó2ˆDŒL÷	3ð *.¯©×);Ñ);Ó)=×>¡  A˜˜1™Ó>ˆŒä‰Ñð 
	
ØØØØØ'Ø%Ø"7Ø!5ñ
	
ð ó
	
÷	3ð 	3üó ?s   ÁB4ÂC Â4B=rY   c                 óˆ   — | j                   €"| j                  rt        j                  d«       yt	        | j                   «      S )zW
        `str`: Padding token. Log an error if used while not having been set.
        Nr[   r\   r`   s    r)   r7   z&Wav2Vec2Tokenizer.word_delimiter_tokení  ra   r(   c                 óR   — | j                   €y| j                  | j                  «      S rc   rd   r`   s    r)   rf   z)Wav2Vec2Tokenizer.word_delimiter_token_id÷  rg   r(   c                 ó   — || _         y ri   rj   rk   s     r)   r7   z&Wav2Vec2Tokenizer.word_delimiter_token  rm   r(   c                 ó0   — | j                  |«      | _        y ri   ro   rk   s     r)   rf   z)Wav2Vec2Tokenizer.word_delimiter_token_id  rp   r(   Ú
raw_speechÚpaddingÚ
max_lengthÚpad_to_multiple_ofÚpadding_sideÚreturn_tensorsr]   c           
      ód  — t        |t        j                  «      xr t        |j                  «      dkD  }	|	r&t        |j                  «      dkD  rt        d| › �«      ‚|	xs@ t        |t        t        f«      xr( t        |d   t        j                  t        t        f«      }
|
r@t        |d   t        j                  «      s#|D �cg c]  }t        j                  |«      ‘Œ }}n1|
s/t        |t        j                  «      st        j                  |«      }|
s|g}| j                  rQ|D �cg c]F  }|t        j                  |«      z
  t        j                  t        j                  |«      dz   «      z  ‘ŒH }}t        d|i«      }| j                  |||||| j                  ||¬«      }|S c c}w c c}w )a  
        Main method to tokenize and prepare for the model one or several sequence(s) or one or several pair(s) of
        sequences.

        Args:
            raw_speech (`np.ndarray`, `List[float]`, `List[np.ndarray]`, `List[List[float]]`):
                The sequence or batch of sequences to be padded. Each sequence can be a numpy array, a list of float
                values, a list of numpy array or a list of list of float values. Must be mono channel audio, not
                stereo, i.e. single float per timestep.

            padding_side (`str`, *optional*):
                The side on which the model should have padding applied. Should be selected between ['right', 'left'].
                Default value is picked from the class attribute of the same name.
        r:   rë   z2Only mono-channel audio is supported for input to r   gñhãˆµøä>r  )r  r  r  r  r  r  r]   )r}   r¼   ÚndarrayrJ   ÚshaperU   r„   Útupler½   r  ÚmeanÚsqrtÚvarr   Úpadr  )rL   r  r  r  r  r  r  r]   rM   Úis_batched_numpyÚ
is_batchedÚspeechÚxÚencoded_inputsÚpadded_inputss                  r)   Ú__call__zWav2Vec2Tokenizer.__call__	  s‡  € ô6 & j´"·*±*Ó=Ò[Ä#Àj×FVÑFVÓBWÐZ[ÑB[ÐÙ¤ J×$4Ñ$4Ó 5¸Ò 9ÜÐQÐRVÐQWÐXÓYÐYØ%ò 
Ü�z¤D¬% =Ó1Òl´zÀ*ÈQÁ-ÔRT×R\ÑR\Ô^cÔeiÐQjÓ7kð 	ñ
 œj¨°A©¼¿
¹
ÔCØ;EÖF°œ"Ÿ*™* VÕ,ÐFˆJÑFÙ¤J¨z¼2¿:¹:Ô$FÜŸ™ JÓ/ˆJñ Ø$˜ˆJð ×ÒØPZÖ[È1˜1œrŸw™w q›z™>¬R¯W©W´R·V±V¸A³YÀÑ5EÓ-FÓFÐ[ˆJÐ[ô '¨¸
Ð'CÓDˆàŸ™ØØØ!Ø1Ø%Ø"&×"<Ñ"<Ø)Øð !ó 	
ˆð Ðùò5 Gùò \s   ÃF(Ä)AF-c                 ó,   — t        | j                  «      S ri   rr   r`   s    r)   rs   zWav2Vec2Tokenizer.vocab_sizeI  rt   r(   c                 óB   — t        | j                  fi | j                  ¤ŽS ri   )rv   rD   rx   r`   s    r)   ry   zWav2Vec2Tokenizer.get_vocabM  s   € Ü�D—L‘LÑ> D×$=Ñ$=Ñ>Ð>r(   rQ   c                 ó€   — | j                   j                  || j                   j                  | j                  «      «      S rˆ   r‰   r‹   s     r)   rŒ   z&Wav2Vec2Tokenizer._convert_token_to_idP  r�   r(   rŽ   c                 óR   — | j                   j                  || j                  «      }|S r�   r‘   r’   s      r)   r”   z&Wav2Vec2Tokenizer._convert_id_to_tokenT  r•   r(   r–   c                 ó6  ‡ — t        |«      D �cg c]  }|d   ‘Œ	 }}t        t        ˆ fd„|«      «      }dj                  |D �cg c]  }|‰ j                  k(  rdn|‘Œ c}«      j                  «       }‰ j                  r|j                  «       }|S c c}w c c}w )rœ   r   c                 ó"   •— | ‰j                   k7  S ri   r¤   )rQ   rL   s    €r)   r¦   z<Wav2Vec2Tokenizer.convert_tokens_to_string.<locals>.<lambda>a  s   ø€ °E¸T¿^¹^Ñ4K€ r(   r�   r‚   )r   r„   r¨   rV   r7   r¬   r6   r­   )rL   r–   Útoken_groupÚgrouped_tokensrÚ   rQ   r³   s   `      r)   r´   z*Wav2Vec2Tokenizer.convert_tokens_to_stringY  s’   ø€ ô
 =DÀF»OÖL¨[˜+ a›.ÐLˆÐLô œvÓ&KÈ^Ó\Ó]ˆð —‘Ð\kÖlÐSX ¨$×*CÑ*CÒ!C™#ÈÑNÒlÓm×sÑsÓuˆà×ÒØ—\‘\“^ˆFàˆùò Mùò ms   �BÁBrÐ   rÑ   rÒ   c                 ó(  — | j                  ||¬«      }g }|D ]A  }|r,|| j                  v s|| j                  k7  r|| j                  v rŒ1|j	                  |«       ŒC | j                  |«      }|�|n| j                  }|r| j                  |«      }	|	S |S )rÔ   rÕ   )rÖ   r×   r5   rØ   r~   r´   rÒ   rÙ   )
rL   rÐ   rÑ   rÒ   rM   rÚ   r“   rQ   r   Ú
clean_texts
             r)   rÜ   zWav2Vec2Tokenizer._decodek  s´   € ð ×4Ñ4°YÐTgÐ4ÓhˆàˆØ$ò 	!ˆEÙ"Ø˜×-Ñ-Ñ-°%¸4¿>¹>Ò2IÈeÐW[×WnÑWnÑNnàØ�M‰M˜%Õ ð	!ð ×,Ñ,¨VÓ4ˆð ,Ð7ñ )à×2Ñ2ð 	%ñ
 (Ø×3Ñ3°DÓ9ˆJØÐàˆKr(   rå   ræ   c           	      ó�  — t         j                  j                  |«      st        j	                  d|› d�«       y t         j                  j                  ||r|dz   ndt        d   z   «      }t        |dd¬«      5 }|j                  t        j                  | j                  d	d
d¬«      dz   «       d d d «       |fS # 1 sw Y   |fS xY wrè   )rð   rñ   rò   r^   r_   rV   ró   r@   rô   rA   rõ   rD   rö   s        r)   rø   z!Wav2Vec2Tokenizer.save_vocabularyŽ  s¶   € Ü�w‰w�}‰}˜^Ô,Ü�L‰LÐ,¨^Ð,<Ð<SÐTÔUØÜ—W‘W—\‘\Ø±o˜_¨sÒ2È2ÔQbÐcoÑQpÑpó
ˆ
ô �*˜c¨GÔ4ð 	c¸Ø�G‰G”D—J‘J˜tŸ|™|°AÀÐTYÔZÐ]aÑaÔb÷	cð ˆ}Ð÷	cð ˆ}Ðúrù   )rú   rû   rü   rý   rþ   FFF)FNNNNT)FNri   )&r    r!   r"   r#   ró   rÿ   Úpretrained_vocab_files_mapr   rH   r  r$   r7   r   r  rf   r  r   ÚWAV2VEC2_KWARGS_DOCSTRINGr
   r¼   r  r   r  r  r   r   r   r*  rs   r   ry   rŒ   r”   r´   rÜ   r	   rø   r  r  s   @r)   r
  r
  ‡  sg  ø„ ñ,ð\ *Ðð *Ð+wð
ð *Ø`ð"
ñ		"Ðð (Ð)9Ð:Ðð
 ØØØØ ØØØ#õ(
ðT ð/ cò /ó ð/ð ðE¨°#©ò Eó ðEð × Ñ ñ+ó !ð+ð ×#Ñ#ñGó $ðGñ Ð1Ó2ð 6;Ø$(Ø,0Ø&*Ø;?Øñ=à˜"Ÿ*™* d¨5¡k°4¸¿
¹
Ñ3CÀTÈ$ÈuÉ+ÑEVÐVÑWð=ð �t˜S /Ð1Ñ2ð=ð ˜S‘Mð	=ð
 % S™Mð=ð ˜s‘mð=ð !  s¨J Ñ!7Ñ8ð=ð ð=ð 
ò=ó 3ð=ð~ ð!˜Cò !ó ð!ð?˜4ó ?ðI¨#ð I°#ó Ið¨#ð °#ó ð
¨t°C©yð ¸Só ð* %*Ø7;ñ	!à˜‘9ð!ð "ð!ð '/¨t¡nð	!ð 
ó!ñF¨cð ÀHÈSÁMð Ð]bÐcfÑ]g÷ r(   r
  )1r#   rA   rð   r  Údataclassesr   Ú	itertoolsr   Útypingr   r   r   r   r	   r
   Únumpyr¼   Útokenization_utilsr   Útokenization_utils_baser   r   Úutilsr   r   r   r   r   r   r   r   r   Ú
get_loggerr    r^   ÚtorchÚ
tensorflowÚtfÚ	jax.numpyÚjnpró   r7  r$   r  r&   r   r+   r
  Ú__all__r'   r(   r)   ú<module>rF     sé   ðñ 'ã Û 	Û Ý !Ý ß D× Dã å 5ß @÷
÷ 
õ 
ð 
ˆ×	Ñ	˜HÓ	%€ñ ÙÔÛÙÔÛÙÔÝð Ø4ñÐ ðÐ ð: �$�s˜E # s (™OÐ+Ñ,Ñ-€
ð ô= ó =ó ð=ô*QÐ.ô QôhRÐ+ô Rðj "Ð#6Ð
7�r(   