Ë
    ÜÓ^j   ã                   ó¤   — d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
  ej                  e«      Zd	d
iZ ed¬«       G d„ de«      «       ZdgZy)z Tokenization class for SpeechT5.é    )ÚAnyé   )ÚSentencePieceBackend)Úlogging)Úrequiresé   )ÚEnglishNumberNormalizerÚ
vocab_filezspm_char.model)Úsentencepiece)Úbackendsc            
       ó  ‡ — e Zd ZdZeZddgZdZ	 	 	 	 	 	 ddee	e
f   dz  ddfˆ fd„Zdd	„Zed
„ «       Zej                  d„ «       Zddee   fd„Z	 ddee   dee   dz  dedee   fˆ fd„Z	 ddee   dee   dz  dee   fd„Zˆ xZS )ÚSpeechT5Tokenizera	  
    Construct a SpeechT5 tokenizer. Based on [SentencePiece](https://github.com/google/sentencepiece).

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

    Args:
        vocab_file (`str`):
            [SentencePiece](https://github.com/google/sentencepiece) file (generally has a *.spm* extension) that
            contains the vocabulary necessary to instantiate a tokenizer.
        bos_token (`str`, *optional*, defaults to `"<s>"`):
            The begin of sequence token.
        eos_token (`str`, *optional*, defaults to `"</s>"`):
            The end of sequence 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.
        normalize (`bool`, *optional*, defaults to `False`):
            Whether to convert numeric quantities in the text to their spelt-out english counterparts.
        sp_model_kwargs (`dict`, *optional*):
            Will be passed to the `SentencePieceProcessor.__init__()` method. The [Python wrapper for
            SentencePiece](https://github.com/google/sentencepiece/tree/master/python) can be used, among other things,
            to set:

            - `enable_sampling`: Enable subword regularization.
            - `nbest_size`: Sampling parameters for unigram. Invalid for BPE-Dropout.

              - `nbest_size = {0,1}`: No sampling is performed.
              - `nbest_size > 1`: samples from the nbest_size results.
              - `nbest_size < 0`: assuming that nbest_size is infinite and samples from the all hypothesis (lattice)
                using forward-filtering-and-backward-sampling algorithm.

            - `alpha`: Smoothing parameter for unigram sampling, and dropout probability of merge operations for
              BPE-dropout.

    Attributes:
        sp_model (`SentencePieceProcessor`):
            The *SentencePiece* processor that is used for every conversion (string, tokens and IDs).
    Ú	input_idsÚattention_maskFNÚsp_model_kwargsÚreturnc           
      ó\   •— || _         d | _        |�||d<   t        ‰	| �  d||||||dœ|¤Ž y )Nr   )r
   Ú	bos_tokenÚ	eos_tokenÚ	unk_tokenÚ	pad_tokenÚ	normalize© )r   Ú_normalizerÚsuperÚ__init__)
Úselfr
   r   r   r   r   r   r   ÚkwargsÚ	__class__s
            €ú}/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/transformers/models/speecht5/tokenization_speecht5.pyr   zSpeechT5Tokenizer.__init__M   sW   ø€ ð #ˆŒØˆÔð Ð&Ø(7ˆFÐ$Ñ%ô 	‰Ñð 	
Ø!ØØØØØñ	
ð ó	
ó    c                 óv   — |j                  d| j                  «      }|rd|z   }|r| j                  |«      }||fS )Nr   ú )Úpopr   Ú
normalizer)r   ÚtextÚis_split_into_wordsr   r   s        r    Úprepare_for_tokenizationz*SpeechT5Tokenizer.prepare_for_tokenizationj   s=   € Ø—J‘J˜{¨D¯N©NÓ;ˆ	ÙØ˜‘:ˆDÙØ—?‘? 4Ó(ˆDØ�fˆ~Ðr!   c                 óP   — | j                   €t        «       | _         | j                   S ©N)r   r	   )r   s    r    r%   zSpeechT5Tokenizer.normalizerr   s%   € à×ÑÐ#Ü6Ó8ˆDÔØ×ÑÐr!   c                 ó   — || _         y r*   )r   )r   Úvalues     r    r%   zSpeechT5Tokenizer.normalizerx   s
   € à ˆÕr!   c                 óL   — |€|| j                   gz   S ||z   | j                   gz   S )z=Build model inputs from a sequence by appending eos_token_id.)Úeos_token_id)r   Útoken_ids_0Útoken_ids_1s      r    Ú build_inputs_with_special_tokensz2SpeechT5Tokenizer.build_inputs_with_special_tokens|   s5   € àÐØ $×"3Ñ"3Ð!4Ñ4Ð4à˜[Ñ(¨D×,=Ñ,=Ð+>Ñ>Ð>r!   r/   r0   Úalready_has_special_tokensc                 óž   •— |rt         ‰| �  ||d¬«      S dg}|€dgt        |«      z  |z   S dgt        |«      z  dgt        |«      z  z   |z   S )NT)r/   r0   r2   r   r   )r   Úget_special_tokens_maskÚlen)r   r/   r0   r2   Úsuffix_onesr   s        €r    r4   z)SpeechT5Tokenizer.get_special_tokens_maskƒ   su   ø€ ñ &Ü‘7Ñ2Ø'°[Ð]að 3ó ð ð �cˆØÐØ�Cœ#˜kÓ*Ñ*¨kÑ9Ð9Ø�”c˜+Ó&Ñ&¨A¨3´°[Ó1AÑ+AÑBÀ[ÑPÐPr!   c                 ón   — | j                   g}|€t        ||z   «      dgz  S t        ||z   |z   «      dgz  S )aÍ  
        Create a mask from the two sequences passed to be used in a sequence-pair classification task. SpeechT5 does not
        make use of token type ids, therefore a list of zeros is returned.

        Args:
            token_ids_0 (`list[int]`):
                List of IDs.
            token_ids_1 (`list[int]`, *optional*):
                Optional second list of IDs for sequence pairs.

        Returns:
            `list[int]`: List of zeros.
        r   )r.   r5   )r   r/   r0   Úeoss       r    Ú$create_token_type_ids_from_sequencesz6SpeechT5Tokenizer.create_token_type_ids_from_sequences�   sK   € ð  × Ñ Ð!ˆØÐÜ�{ SÑ(Ó)¨Q¨CÑ/Ð/Ü�; Ñ,¨sÑ2Ó3°q°cÑ9Ð9r!   )z<s>z</s>z<unk>z<pad>FN)Fr*   )NF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚVOCAB_FILES_NAMESÚvocab_files_namesÚmodel_input_namesÚis_fastÚdictÚstrr   r   r(   Úpropertyr%   ÚsetterÚlistÚintr1   Úboolr4   r9   Ú__classcell__)r   s   @r    r   r      s  ø„ ñ(ðT *ÐØ$Ð&6Ð7ÐØ€Gð
 ØØØØØ15ñ
ð ˜c 3˜h™¨$Ñ.ð
ð 
õ
ó:ð ñ ó ð ð
 ×Ññ!ó ð!ñ?ÐQUÐVYÑQZó ?ð puñQØ ™9ðQØ37¸±9¸tÑ3CðQØhlðQà	ˆc‰õQð GKñ:Ø ™9ð:Ø37¸±9¸tÑ3Cð:à	ˆc‰÷:r!   r   N)r=   Útypingr   Ú tokenization_utils_sentencepiecer   Úutilsr   Úutils.import_utilsr   Únumber_normalizerr	   Ú
get_loggerr:   Úloggerr>   r   Ú__all__r   r!   r    ú<module>rR      si   ðñ 'å å DÝ Ý *Ý 6ð 
ˆ×	Ñ	˜HÓ	%€à!Ð#3Ð4Ð ñ 
Ð%Ô&ôE:Ð,ó E:ó 'ðE:ðP Ð
�r!   