Ë
    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mZm	Z	 ddl
mZ ddlmZmZ  e«       rdd	lmZ ndZ ej"                  e«      Zd
ddœZ G d„ de«      ZdgZy)z Tokenization class for model T5.é    N)Úcopyfile)ÚListÚOptionalÚTupleé   )ÚPreTrainedTokenizerFast)Úis_sentencepiece_availableÚloggingé   )ÚT5Tokenizerzspiece.modelztokenizer.json)Ú
vocab_fileÚtokenizer_filec                   ó  ‡ — e Zd ZU dZeZddgZeZg Z	e
e   ed<   	 	 	 	 	 	 	 	 dˆ fd„	Zedefd„«       Zed„ «       Zdd	ed
ee   dee   fd„Z	 dde
e   dee
e      de
e   fd„Z	 dde
e   dee
e      de
e   fd„Zd„ Zd„ Zˆ xZS )ÚT5TokenizerFasta`  
    Construct a "fast" T5 tokenizer (backed by HuggingFace's *tokenizers* library). Based on
    [Unigram](https://huggingface.co/docs/tokenizers/python/latest/components.html?highlight=unigram#models).

    This tokenizer inherits from [`PreTrainedTokenizerFast`] 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.
        eos_token (`str`, *optional*, defaults to `"</s>"`):
            The end of sequence token.

            <Tip>

            When building a sequence using special tokens, this is not the token that is used for the end of sequence.
            The token used is the `sep_token`.

            </Tip>

        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.
        extra_ids (`int`, *optional*, defaults to 100):
            Add a number of extra ids added to the vocabulary for use as sentinels. These tokens are accessible as
            "<extra_id_{%d}>" where "{%d}" is a number between 0 and extra_ids-1. These tokens can be retrieved by
            calling get_sentinel_tokens method and token ids can be by calling get_sentinel_token_ids method
        additional_special_tokens (`List[str]`, *optional*):
            Additional special tokens used by the tokenizer.
        add_prefix_space (`bool`, *optional*):
            Whether or not the tokenizer should automatically add a prefix space
        from_slow (`book`, *optional*, defaults to `False`):
            Whether or not the tokenizer should be converted from a slow one. If `add_prefix_space` is set, this will be set to `True`.
    Ú	input_idsÚattention_maskÚprefix_tokensc	                 óÊ  •— |�q|D �
cg c]  }
dt        |
«      v sŒ|
‘Œ }}
t        |«      dk  r!|t        |«      D �cg c]  }d|› d�‘Œ
 c}z  }nC|dkD  r>|t        |«      k7  r0t        d|› d|› d�«      ‚t        |«      D �cg c]  }d|› d�‘Œ
 }}|}|�t        j                  d«       d	|	d
<   t        ‰| �  d||||||||dœ|	¤Ž || _        || _	        y c c}
w c c}w c c}w )Nz
<extra_id_r   ú>r   zBoth extra_ids (z!) and additional_special_tokens (zk) are provided to T5Tokenizer. In this case the additional_special_tokens must include the extra_ids tokenszXYou set `add_prefix_space`. The tokenizer needs to be converted from the slow tokenizersTÚ	from_slow)r   r   Ú	eos_tokenÚ	unk_tokenÚ	pad_tokenÚ	extra_idsÚadditional_special_tokensÚadd_prefix_space© )
ÚstrÚlenÚrangeÚ
ValueErrorÚloggerÚwarning_onceÚsuperÚ__init__r   Ú
_extra_ids)Úselfr   r   r   r   r   r   r   r   ÚkwargsÚxÚextra_tokensÚiÚ	__class__s                €úi/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/t5/tokenization_t5_fast.pyr%   zT5TokenizerFast.__init__V   s8  ø€ ð %Ð0Ø'@Ö[ !ÀLÔTWÐXYÓTZÒDZšAÐ[ˆLÐ[Ü�<Ó  1Ò$Ø)ÌÈyÓIYÖ-ZÀA°
¸1¸#¸QÒ.?Ò-ZÑZÑ)Ø˜Q’ 9´°LÓ0AÒ#AÜ Ø& y kÐ1RÐSlÐRmð nð óð ô 8=¸YÓ7GÖH°!˜j¨¨¨1Ò-ÐHˆLÐHØ(4Ð%àÐ'Ü×ÑØjôð #'ˆF�;Ñä‰Ñð 
	
Ø!Ø)ØØØØØ&?Ø-ñ
	
ð ò
	
ð %ˆŒØ#ˆ�ùòA \ùâ-Zùò Is   ˆC›C½CÂC Úreturnc                 óp   — | j                   r)t        j                  j                  | j                   «      S dS )NF)r   ÚosÚpathÚisfile©r'   s    r-   Úcan_save_slow_tokenizerz'T5TokenizerFast.can_save_slow_tokenizer†   s$   € à26·/²/Œr�w‰w�~‰~˜dŸo™oÓ.ÐLÀuÐLó    c                 ó´   — | t         j                  v rEt         j                  |    }|�||k7  r|S |€'t        j                  d|› d| › d|› d|› d�	t        «       |S )NzGThis tokenizer was incorrectly instantiated with a model max length of zÎ which will be corrected in Transformers v5.
For now, this behavior is kept to avoid breaking backwards compatibility when padding/encoding with `truncation is True`.
- Be aware that you SHOULD NOT rely on z( automatically truncating your input to zM when padding/encoding.
- If you want to encode/pad to sequences longer than zÞ you can either instantiate this tokenizer with `model_max_length` or pass `max_length` when encoding/padding.
- To avoid this warning, please instantiate this tokenizer with `model_max_length` set to your preferred value.)r   Úmax_model_input_sizesÚwarningsÚwarnÚFutureWarning)Úpretrained_model_name_or_pathÚmax_model_lengthÚinit_max_model_lengthÚdeprecated_max_model_lengths       r-   Ú!_eventually_correct_t5_max_lengthz1T5TokenizerFast._eventually_correct_t5_max_lengthŠ   s‘   € à(¬O×,QÑ,QÑQÜ*9×*OÑ*OÐPmÑ*nÐ'Ø$Ð0Ð5JÐN^Ò5^Ø,Ð,Ø&Ð.Ü—‘ðØ3Ð4ð 5ð 6Ð6ð 7Ø3Ð4ð 5$Ø$?Ð#@ð Agðgô "ôð  Ðr5   Úsave_directoryÚfilename_prefixc                 óø  — | j                   st        d«      ‚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  r.t        | j                  |«       t
        j                  d|› �«       |fS )NzhYour fast tokenizer does not have the necessary information to save the vocabulary for a slow tokenizer.zVocabulary path (z) should be a directoryú-Ú r   zCopy vocab file to )r4   r!   r0   r1   Úisdirr"   ÚerrorÚjoinÚVOCAB_FILES_NAMESÚabspathr   r   Úinfo)r'   r@   rA   Úout_vocab_files       r-   Úsave_vocabularyzT5TokenizerFast.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Ü�T—_‘_ nÔ5Ü�K‰KÐ-¨nÐ-=Ð>Ô?àÐ Ð r5   Útoken_ids_0Útoken_ids_1c                 óˆ   — || j                   gz   }|€| j                  |z   S || j                   gz   }| j                  |z   |z   S )a‚  
        Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
        adding special tokens. A sequence has the following format:

        - single sequence: `X </s>`
        - pair of sequences: `A </s> B </s>`

        Args:
            token_ids_0 (`List[int]`):
                List of IDs to which the special tokens will be added.
            token_ids_1 (`List[int]`, *optional*):
                Optional second list of IDs for sequence pairs.

        Returns:
            `List[int]`: List of [input IDs](../glossary#input-ids) with the appropriate special tokens.
        )Úeos_token_idr   )r'   rM   rN   s      r-   Ú build_inputs_with_special_tokensz0T5TokenizerFast.build_inputs_with_special_tokens´   sW   € ð& " T×%6Ñ%6Ð$7Ñ7ˆØÐØ×%Ñ%¨Ñ3Ð3à%¨×):Ñ):Ð(;Ñ;ˆKØ×%Ñ%¨Ñ3°kÑAÐAr5   c                 ót   — | j                   g}|€t        ||z   «      dgz  S t        ||z   |z   |z   «      dgz  S )aÇ  
        Create a mask from the two sequences passed to be used in a sequence-pair classification task. T5 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   )rP   r   )r'   rM   rN   Úeoss       r-   Ú$create_token_type_ids_from_sequencesz4T5TokenizerFast.create_token_type_ids_from_sequencesÎ   sP   € ð  × Ñ Ð!ˆàÐÜ�{ SÑ(Ó)¨Q¨CÑ/Ð/Ü�; Ñ$ {Ñ2°SÑ8Ó9¸Q¸CÑ?Ð?r5   c                 óT   — t        t        t        d„ | j                  «      «      «      S )Nc                 óD   — t        t        j                  d| «      «      d uS )Nz<extra_id_\d+>)ÚboolÚreÚsearch)r)   s    r-   ú<lambda>z5T5TokenizerFast.get_sentinel_tokens.<locals>.<lambda>æ   s   € ¤¤b§i¡iÐ0AÀ1Ó&EÓ!FÈdÐ!R€ r5   )ÚlistÚsetÚfilterr   r3   s    r-   Úget_sentinel_tokensz#T5TokenizerFast.get_sentinel_tokensä   s&   € ÜÜ”ÑRÐTX×TrÑTrÓsÓtó
ð 	
r5   c                 óf   — | j                  «       D �cg c]  }| j                  |«      ‘Œ c}S c c}w ©N)r^   Úconvert_tokens_to_ids)r'   Útokens     r-   Úget_sentinel_token_idsz&T5TokenizerFast.get_sentinel_token_idsé   s*   € Ø?C×?WÑ?WÓ?YÖZ°e�×*Ñ*¨5Õ1ÒZÐZùÒZs   “.)NNz</s>z<unk>z<pad>éd   NNr`   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rH   Úvocab_files_namesÚmodel_input_namesr   Úslow_tokenizer_classr   r   ÚintÚ__annotations__r%   ÚpropertyrW   r4   Ústaticmethodr?   r   r   r   rL   rQ   rT   r^   rc   Ú__classcell__)r,   s   @r-   r   r   )   s%  ø… ñ$ðL *ÐØ$Ð&6Ð7ÐØ&Ðà!€M�4˜‘9Ó!ð ØØØØØØ"&Øõ.$ð` ðM¨ò Mó ðMð ñ ó ð ñ*!¨cð !ÀHÈSÁMð !Ð]bÐcfÑ]gó !ð* JNñBØ ™9ðBØ3;¸DÀ¹IÑ3FðBà	ˆc‰óBð6 JNñ@Ø ™9ð@Ø3;¸DÀ¹IÑ3Fð@à	ˆc‰ó@ò,
ö
[r5   r   )rh   r0   rX   r8   Úshutilr   Útypingr   r   r   Útokenization_utils_fastr   Úutilsr	   r
   Útokenization_t5r   Ú
get_loggerre   r"   rH   r   Ú__all__r   r5   r-   ú<module>rx      sn   ðñ 'ã 	Û 	Û Ý ß (Ñ (å >ß 8ñ ÔÞ,à€Kð 
ˆ×	Ñ	˜HÓ	%€à#1ÐEUÑVÐ ôA[Ð-ô A[ðH Ð
�r5   