Ë
    T^(hò"  ã                   ó¬   — d Z ddlZddlmZ ddlmZmZmZmZm	Z	 ddl
ZddlmZ ddlmZ dd	lmZ  ej$                  e«      Zd
diZ G d„ de«      ZdgZy)z Tokenization class for SpeechT5.é    N)Úcopyfile)ÚAnyÚDictÚListÚOptionalÚTupleé   )ÚPreTrainedTokenizer)Úloggingé   )ÚEnglishNumberNormalizerÚ
vocab_filezspm_char.modelc            
       óJ  ‡ — e Zd ZdZeZddgZ	 	 	 	 	 	 ddeee	e
f      ddfˆ fd„Zdd„Zed	„ «       Zed
„ «       Zej                   d„ «       Zd„ Zd„ Zd„ Zde	dee	   fd„Zd„ Zd„ Zd„ Zddee   fd„Z	 ddee   deee      dedee   fˆ fd„Zdde	dee	   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_maskNÚsp_model_kwargsÚreturnc           
      ó  •— |€i n|| _         || _        || _        d | _        t	        j
                  di | j                   ¤Ž| _        | j                  j                  |«       t        ‰	| �$  d|||||| j                   dœ|¤Ž y )N)Ú	bos_tokenÚ	eos_tokenÚ	unk_tokenÚ	pad_tokenÚ	normalizer   © )
r   r   r   Ú_normalizerÚspmÚSentencePieceProcessorÚsp_modelÚLoadÚsuperÚ__init__)
Úselfr   r   r   r   r   r   r   ÚkwargsÚ	__class__s
            €úp/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/speecht5/tokenization_speecht5.pyr"   zSpeechT5Tokenizer.__init__O   s‹   ø€ ð &5Ð%<™rÀ/ˆÔØ$ˆŒØ"ˆŒØˆÔä×2Ñ2ÑJ°T×5IÑ5IÑJˆŒØ�‰×Ñ˜:Ô&ä‰Ñð 	
ØØØØØØ ×0Ñ0ñ	
ð ó	
ó    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_tokenizationl   s=   € Ø—J‘J˜{¨D¯N©NÓ;ˆ	ÙØ˜‘:ˆDÙØ—?‘? 4Ó(ˆDØ�fˆ~Ðr'   c                 ó6   — | j                   j                  «       S ©N)r   Úget_piece_size©r#   s    r&   Ú
vocab_sizezSpeechT5Tokenizer.vocab_sizet   s   € à�}‰}×+Ñ+Ó-Ð-r'   c                 óP   — | j                   €t        «       | _         | j                   S r0   )r   r   r2   s    r&   r+   zSpeechT5Tokenizer.normalizerx   s%   € à×ÑÐ#Ü6Ó8ˆDÔØ×ÑÐr'   c                 ó   — || _         y r0   )r   )r#   Úvalues     r&   r+   zSpeechT5Tokenizer.normalizer~   s
   € à ˆÕr'   c                 óª   — t        | j                  «      D �ci c]  }| j                  |«      |“Œ }}|j                  | j                  «       |S c c}w r0   )Úranger3   Úconvert_ids_to_tokensÚupdateÚadded_tokens_encoder)r#   ÚiÚvocabs      r&   Ú	get_vocabzSpeechT5Tokenizer.get_vocab‚   sK   € Ü;@ÀÇÁÓ;QÖR°a�×+Ñ+¨AÓ.°Ñ1ÐRˆÐRØ�‰�T×.Ñ.Ô/Øˆùò Ss   ˜Ac                 óD   — | j                   j                  «       }d |d<   |S )Nr   )Ú__dict__Úcopy)r#   Ústates     r&   Ú__getstate__zSpeechT5Tokenizer.__getstate__‡   s#   € Ø—‘×"Ñ"Ó$ˆØ ˆˆjÑØˆr'   c                 óÊ   — || _         t        | d«      si | _        t        j                  di | j                  ¤Ž| _        | j
                  j                  | j                  «       y )Nr   r   )r@   Úhasattrr   r   r   r   r    r   )r#   Úds     r&   Ú__setstate__zSpeechT5Tokenizer.__setstate__Œ   sO   € ØˆŒô �tÐ.Ô/Ø#%ˆDÔ ä×2Ñ2ÑJ°T×5IÑ5IÑJˆŒØ�‰×Ñ˜4Ÿ?™?Õ+r'   r,   c                 óD   — | j                   j                  |t        ¬«      S )zPTake as input a string and return a list of strings (tokens) for words/sub-words)Úout_type)r   ÚencodeÚstr)r#   r,   s     r&   Ú	_tokenizezSpeechT5Tokenizer._tokenize–   s   € à�}‰}×#Ñ# D´3Ð#Ó7Ð7r'   c                 ó8   — | j                   j                  |«      S )z0Converts a token (str) in an id using the vocab.)r   Úpiece_to_id)r#   Útokens     r&   Ú_convert_token_to_idz&SpeechT5Tokenizer._convert_token_to_idš   s   € à�}‰}×(Ñ(¨Ó/Ð/r'   c                 ó<   — | j                   j                  |«      }|S )z=Converts an index (integer) in a token (str) using the vocab.)r   Ú	IdToPiece)r#   ÚindexrO   s      r&   Ú_convert_id_to_tokenz&SpeechT5Tokenizer._convert_id_to_tokenž   s   € à—‘×'Ñ'¨Ó.ˆØˆr'   c                 ó  — g }d}d}|D ]P  }|| j                   v r-|s|dz  }|| j                  j                  |«      |z   z  }d}g }Œ>|j                  |«       d}ŒR || j                  j                  |«      z  }|j	                  «       S )z:Converts a sequence of tokens (string) in a single string.Ú Fr)   T)Úall_special_tokensr   ÚdecodeÚappendÚstrip)r#   ÚtokensÚcurrent_sub_tokensÚ
out_stringÚprev_is_specialrO   s         r&   Úconvert_tokens_to_stringz*SpeechT5Tokenizer.convert_tokens_to_string¤   s¤   € àÐØˆ
ØˆØò 
	(ˆEà˜×/Ñ/Ñ/Ù&Ø #Ñ%�JØ˜dŸm™m×2Ñ2Ð3EÓFÈÑNÑN�
Ø"&�Ø%'Ñ"à"×)Ñ)¨%Ô0Ø"'‘ð
	(ð 	�d—m‘m×*Ñ*Ð+=Ó>Ñ>ˆ
Ø×ÑÓ!Ð!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'   rb   rc   Ú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)rb   rc   re   r   r   )r!   Úget_special_tokens_maskÚlen)r#   rb   rc   re   Úsuffix_onesr%   s        €r&   rg   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'   Ú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         j                  j                  | j                  «      t         j                  j                  |«      k7  rBt         j                  j                  | j                  «      rt        | j                  |«       |fS t         j                  j                  | j                  «      sCt        |d«      5 }| j                  j                  «       }|j                  |«       d d d «       |fS |fS # 1 sw Y   |fS xY w)NzVocabulary path (z) should be a directoryú-rV   r   Úwb)ÚosÚpathÚisdirÚloggerÚerrorÚjoinÚVOCAB_FILES_NAMESÚabspathr   Úisfiler   Úopenr   Úserialized_model_protoÚwrite)r#   rj   rk   Úout_vocab_fileÚfiÚcontent_spiece_models         r&   Úsave_vocabularyz!SpeechT5Tokenizer.save_vocabularyË   s%  € Ü�w‰w�}‰}˜^Ô,Ü�L‰LÐ,¨^Ð,<Ð<SÐTÔUØÜŸ™Ÿ™Ø±o˜_¨sÒ2È2ÔQbÐcoÑQpÑpó
ˆô �7‰7�?‰?˜4Ÿ?™?Ó+¬r¯w©w¯©¸~Ó/NÒNÔSU×SZÑSZ×SaÑSaÐbf×bqÑbqÔSrÜ�T—_‘_ nÔ5ð Ð Ð ô —‘—‘ §¡Ô0Ü�n dÓ+ð /¨rØ'+§}¡}×'KÑ'KÓ'MÐ$Ø—‘Ð-Ô.÷/ð Ð Ð �Ð Ð ÷	/ð Ð Ð ús   Ä+,E%Å%E0)z<s>z</s>z<unk>z<pad>FN)Fr0   )NF) Ú__name__Ú
__module__Ú__qualname__Ú__doc__ru   Úvocab_files_namesÚmodel_input_namesr   r   rK   r   r"   r.   Úpropertyr3   r+   Úsetterr>   rC   rG   r   rL   rP   rT   r_   Úintrd   Úboolrg   r   r~   Ú__classcell__)r%   s   @r&   r   r   !   sM  ø„ ñ(ðT *ÐØ$Ð&6Ð7Ðð
 ØØØØØ48ñ
ð " $ s¨C x¡.Ñ1ð
ð 
õ
ó:ð ñ.ó ð.ð ñ ó ð ð
 ×Ññ!ó ð!òò
ò
,ð8˜cð 8 d¨3¡ió 8ò0òò"ñ&?ÐQUÐVYÑQZó ?ð sxñQØ ™9ðQØ3;¸DÀ¹IÑ3FðQØkoðQà	ˆc‰õQñ!¨cð !ÀHÈSÁMð !Ð]bÐcfÑ]g÷ !r'   r   )r‚   ro   Úshutilr   Útypingr   r   r   r   r   Úsentencepiecer   Útokenization_utilsr
   Úutilsr   Únumber_normalizerr   Ú
get_loggerr   rr   ru   r   Ú__all__r   r'   r&   ú<module>r’      s\   ðñ 'ã 	Ý ß 3Õ 3ã å 5Ý Ý 6ð 
ˆ×	Ñ	˜HÓ	%€à!Ð#3Ð4Ð ôy!Ð+ô y!ðx Ð
�r'   