Ë
    S^(hV7  ã                   ó¸   — d dl 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mZ ddlmZ erddlmZ  ej&                  e«      Zdd	iZd
Z G d„ de«      ZdgZy)é    N)Úcopyfile)ÚTYPE_CHECKINGÚAnyÚDictÚListÚOptionalÚTupleé   )Ú
AddedTokenÚPreTrainedTokenizer)Úlogging)Ú	TextInputÚ
vocab_fileztokenizer.modelu   â–�c            
       ó`  ‡ — e Zd ZdZeZddgZ	 	 	 	 	 	 	 	 	 	 ddeee	e
f      fˆ fd„Zd„ Zd„ Zed„ «       Zd	„ Zd
ddee	   fˆ fd„Zd„ Zd„ Zd„ Zd„ Zddee	   dee	   fd„Zdd„Z	 d dee   deee      dedee   fˆ fd„Z	 ddee   deee      dee   fd„Z	 	 d!dee   dedede	fd„Zˆ xZS )"ÚGemmaTokenizeraý
  
    Construct a Gemma tokenizer. Based on byte-level Byte-Pair-Encoding. The default padding token is unset as there is
    no padding token in the original model.

    Args:
        vocab_file (`str`):
            Path to the vocabulary file.
        unk_token (`str` or `tokenizers.AddedToken`, *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.
        bos_token (`str` or `tokenizers.AddedToken`, *optional*, defaults to `"<bos>"`):
            The beginning of sequence token that was used during pretraining. Can be used a sequence classifier token.
        eos_token (`str` or `tokenizers.AddedToken`, *optional*, defaults to `"<eos>"`):
            The end of sequence token.
        pad_token (`str` or `tokenizers.AddedToken`, *optional*, defaults to `"<pad>"`):
            A special token used to make arrays of tokens the same size for batching purpose. Will then be ignored by
            attention mechanisms or loss computation.
        sp_model_kwargs (`Dict[str, Any]`, `Optional`, *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.

        add_bos_token (`bool`, *optional*, defaults to `True`):
            Whether or not to add an `bos_token` at the start of sequences.
        add_eos_token (`bool`, *optional*, defaults to `False`):
            Whether or not to add an `eos_token` at the end of sequences.
        clean_up_tokenization_spaces (`bool`, *optional*, defaults to `False`):
            Whether or not to cleanup spaces after decoding, cleanup consists in removing potential artifacts like
            extra spaces.
        use_default_system_prompt (`bool`, *optional*, defaults to `False`):
            Whether or not the default system prompt for Gemma should be used.
        spaces_between_special_tokens (`bool`, *optional*, defaults to `False`):
            Whether or not to add spaces between special tokens.
    Ú	input_idsÚattention_maskÚsp_model_kwargsc                 ó  •— |€i n|| _         t        |t        «      rt        |dd¬«      n|}t        |t        «      rt        |dd¬«      n|}t        |t        «      rt        |dd¬«      n|}t        |t        «      rt        |dd¬«      n|}|| _        || _        || _        |
| _        t        j                  di | j                   ¤Ž| _
        | j                  j                  |«       t        ‰| �4  d||||||||	|
|dœ
|¤Ž y )NFT)Ú
normalizedÚspecial)
Ú	bos_tokenÚ	eos_tokenÚ	unk_tokenÚ	pad_tokenÚadd_bos_tokenÚadd_eos_tokenr   Úclean_up_tokenization_spacesÚuse_default_system_promptÚspaces_between_special_tokens© )r   Ú
isinstanceÚstrr   r   r   r   r   ÚspmÚSentencePieceProcessorÚsp_modelÚLoadÚsuperÚ__init__)Úselfr   r   r   r   r   r   r   r   r   r   r    ÚkwargsÚ	__class__s                €új/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/gemma/tokenization_gemma.pyr)   zGemmaTokenizer.__init__\   s
  ø€ ð &5Ð%<™rÀ/ˆÔÜMWÐXaÔcfÔMg”J˜y°UÀDÕIÐmvˆ	ÜMWÐXaÔcfÔMg”J˜y°UÀDÕIÐmvˆ	ÜMWÐXaÔcfÔMg”J˜y°UÀDÕIÐmvˆ	ÜMWÐXaÔcfÔMg”J˜y°UÀDÕIÐmvˆ	à$ˆŒØ*ˆÔØ*ˆÔØ)BˆÔ&Ü×2Ñ2ÑJ°T×5IÑ5IÑJˆŒØ�‰×Ñ˜:Ô&ä‰Ñð 	
ØØØØØ'Ø'Ø+Ø)EØ&?Ø*Gñ	
ð ó	
ó    c                 ó~   — | j                   j                  «       }d |d<   | j                  j                  «       |d<   |S )Nr&   Úsp_model_proto)Ú__dict__Úcopyr&   Úserialized_model_proto)r*   Ústates     r-   Ú__getstate__zGemmaTokenizer.__getstate__†   s;   € Ø—‘×"Ñ"Ó$ˆØ ˆˆjÑØ"&§-¡-×"FÑ"FÓ"HˆÐÑØˆr.   c                 óÌ   — | j                   j                  |«       t        j                  di | j                  ¤Ž| _        | j
                  j                  | j                  «       y )Nr!   )r1   Úupdater$   r%   r   r&   ÚLoadFromSerializedProtor0   )r*   Úds     r-   Ú__setstate__zGemmaTokenizer.__setstate__Œ   sG   € Ø�‰×Ñ˜QÔÜ×2Ñ2ÑJ°T×5IÑ5IÑJˆŒØ�‰×-Ñ-¨d×.AÑ.AÕBr.   c                 ó6   — | j                   j                  «       S )zReturns vocab size)r&   Úget_piece_size)r*   s    r-   Ú
vocab_sizezGemmaTokenizer.vocab_size‘   s   € ð �}‰}×+Ñ+Ó-Ð-r.   c                 óª   — t        | j                  «      D �ci c]  }| j                  |«      |“Œ }}|j                  | j                  «       |S c c}w )zReturns vocab as a dict)Úranger=   Úconvert_ids_to_tokensr7   Úadded_tokens_encoder)r*   ÚiÚvocabs      r-   Ú	get_vocabzGemmaTokenizer.get_vocab–   sK   € ä;@ÀÇÁÓ;QÖR°a�×+Ñ+¨AÓ.°Ñ1ÐRˆÐRØ�‰�T×.Ñ.Ô/Øˆùò Ss   ˜AÚtextr   Úreturnc                 ó$   •— t        ‰| �  |fi |¤ŽS )ze
        Args:
            text: TextInput
        Simply calls PreTrainedTokenizer's method
        )r(   Útokenize)r*   rE   r+   r,   s      €r-   rH   zGemmaTokenizer.tokenizeœ   s   ø€ ô ‰wÑ Ñ/¨Ñ/Ð/r.   c                 óD   — | j                   j                  |t        ¬«      S )z†
        Args:
            text: TextInput
        Returns a tokenized string. The Gemma tokenizer never adds a prefix space.
        )Úout_type)r&   Úencoder#   )r*   rE   r+   s      r-   Ú	_tokenizezGemmaTokenizer._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#GemmaTokenizer._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#GemmaTokenizer._convert_id_to_token°   s   € à—‘×'Ñ'¨Ó.ˆØˆr.   c                 óÞ   — g }d}|D ]E  }|| j                   v r$|| j                  j                  |«      |z   z  }g }Œ5|j                  |«       ŒG || j                  j                  |«      z  }|S )z:Converts a sequence of tokens (string) in a single string.Ú )Ú_added_tokens_encoderr&   ÚdecodeÚappend)r*   ÚtokensÚcurrent_sub_tokensÚ
out_stringrO   s        r-   Úconvert_tokens_to_stringz'GemmaTokenizer.convert_tokens_to_stringµ   s   € àÐØˆ
Øò 	1ˆEà˜×2Ñ2Ñ2Ø˜dŸm™m×2Ñ2Ð3EÓFÈÑNÑN�
Ø%'Ñ"à"×)Ñ)¨%Õ0ð	1ð 	�d—m‘m×*Ñ*Ð+=Ó>Ñ>ˆ
ØÐr.   Ú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)a  
        Save the vocabulary and special tokens file to a directory.

        Args:
            save_directory (`str`):
                The directory in which to save the vocabulary.

        Returns:
            `Tuple(str)`: Paths to the files saved.
        zVocabulary path (z) should be a directoryNú-rV   r   Úwb)ÚosÚpathÚisdirÚloggerÚerrorÚjoinÚVOCAB_FILES_NAMESÚabspathr   Úisfiler   Úopenr&   r3   Úwrite)r*   Úsave_directoryr^   Úout_vocab_fileÚfiÚcontent_spiece_models         r-   Úsave_vocabularyzGemmaTokenizer.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c                 óœ   — | j                   r| j                  gng }| j                  r| j                  gng }||z   |z   }|�||z   |z   |z   }|S ©N)r   Úbos_token_idr   Úeos_token_id©r*   Útoken_ids_0Útoken_ids_1rt   ru   Úoutputs         r-   Ú build_inputs_with_special_tokensz/GemmaTokenizer.build_inputs_with_special_tokensÞ   s`   € Ø.2×.@Ò.@˜×)Ñ)Ñ*ÀbˆØ.2×.@Ò.@˜×)Ñ)Ñ*Àbˆà Ñ+¨lÑ:ˆàÐ"Ø˜lÑ*¨[Ñ8¸<ÑGˆFàˆr.   rw   rx   Úalready_has_special_tokensc                 óô   •— |rt         ‰| �  ||d¬«      S | j                  rdgng }| j                  rdgng }|€|dgt	        |«      z  z   |z   S |dgt	        |«      z  z   |z   |z   dgt	        |«      z  z   |z   S )aÄ  
        Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
        special tokens using the tokenizer `prepare_for_model` method.

        Args:
            token_ids_0 (`List[int]`):
                List of IDs.
            token_ids_1 (`List[int]`, *optional*):
                Optional second list of IDs for sequence pairs.
            already_has_special_tokens (`bool`, *optional*, defaults to `False`):
                Whether or not the token list is already formatted with special tokens for the model.

        Returns:
            `List[int]`: A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token.
        T)rw   rx   r{   é   r   )r(   Úget_special_tokens_maskr   r   Úlen)r*   rw   rx   r{   rt   ru   r,   s         €r-   r~   z&GemmaTokenizer.get_special_tokens_maské   s»   ø€ ñ$ &Ü‘7Ñ2Ø'°[Ð]að 3ó ð ð #×0Ò0˜‘s°bˆØ"×0Ò0˜‘s°bˆàÐØ A 3¬¨[Ó)9Ñ#9Ñ:¸\ÑIÐIàØˆs”S˜Ó%Ñ%ñ'àñð ñð ˆs”S˜Ó%Ñ%ñ	'ð
 ñð	
r.   c                 óÐ   — | j                   r| j                  gng }| j                  r| j                  gng }dgt	        ||z   |z   «      z  }|�|dgt	        ||z   |z   «      z  z  }|S )aÅ  
        Creates a mask from the two sequences passed to be used in a sequence-pair classification task. An ALBERT
        sequence pair mask has the following format:

        ```
        0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
        | first sequence    | second sequence |
        ```

        if token_ids_1 is None, only returns the first portion of the mask (0s).

        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 [token type IDs](../glossary#token-type-ids) according to the given sequence(s).
        r   r}   )r   rt   r   ru   r   rv   s         r-   Ú$create_token_type_ids_from_sequencesz3GemmaTokenizer.create_token_type_ids_from_sequences  sz   € ð. /3×.@Ò.@˜×)Ñ)Ñ*ÀbˆØ.2×.@Ò.@˜×)Ñ)Ñ*Àbˆà�”s˜<¨+Ñ5¸ÑDÓEÑEˆàÐ"Ø�q�cœC ¨{Ñ :¸\Ñ IÓJÑJÑJˆFàˆr.   Ú	token_idsÚskip_special_tokensr    c                 óô  — g }g }|D ]‰  }|r|| j                   v rŒ|| j                  v rW|r*|j                  | j                  j	                  |«      «       |j                  | j                  |   j
                  «       g }Œy|j                  |«       Œ‹ |r*|j                  | j                  j	                  |«      «       |rdj                  |«      }ndj                  |«      }|j                  t        d«      S )Nú rV   )	Úall_special_idsÚ_added_tokens_decoderrY   r&   rX   Úcontentrg   ÚreplaceÚSPIECE_UNDERLINE)r*   r‚   rƒ   r    r+   Ú	sub_textsÚcurrent_sub_textÚidss           r-   Ú_decodezGemmaTokenizer._decode/  sé   € ð ˆ	ØÐØò 		-ˆCÙ" s¨d×.BÑ.BÑ'BØØ�d×0Ñ0Ñ0Ù#Ø×$Ñ$ T§]¡]×%9Ñ%9Ð:JÓ%KÔLØ× Ñ  ×!;Ñ!;¸CÑ!@×!HÑ!HÔIØ#%Ñ à ×'Ñ'¨Õ,ð		-ñ Ø×Ñ˜TŸ]™]×1Ñ1Ð2BÓCÔDá(ØŸ™ Ó+‰IàŸ™ 	Ó*ˆIà× Ñ Ô!1°3Ó7Ð7r.   )
z<unk>z<bos>z<eos>z<pad>NTFFFFrs   )NF)FF) Ú__name__Ú
__module__Ú__qualname__Ú__doc__rh   Úvocab_files_namesÚmodel_input_namesr   r   r#   r   r)   r5   r:   Úpropertyr=   rD   r   rH   rL   rP   rT   r]   r	   rq   rz   ÚintÚboolr~   r�   rŽ   Ú__classcell__)r,   s   @r-   r   r   *   sw  ø„ ñ,ð\ *ÐØ$Ð&6Ð7Ðð
 ØØØØ48ØØØ%*Ø"'Ø&+ñ(
ð " $ s¨C x¡.Ñ1õ(
òTòCð
 ñ.ó ð.òð0˜[ð 0°t¸C±yõ 0ò8ò0òò
ñ!¸xÈ¹}ð !ÐX]Ð^aÑXbó !ó6	ð sxñ#
Ø ™9ð#
Ø3;¸DÀ¹IÑ3Fð#
Økoð#
à	ˆc‰õ#
ðL JNñØ ™9ðØ3;¸DÀ¹IÑ3Fðà	ˆc‰óðH %*Ø.3ñ	8à˜‘9ð8ð "ð8ð (,ð	8ð 
÷8r.   r   )rb   Úshutilr   Útypingr   r   r   r   r   r	   Úsentencepiecer$   Útokenization_utilsr   r   Úutilsr   Útokenization_utils_baser   Ú
get_loggerr�   re   rh   rŠ   r   Ú__all__r!   r.   r-   ú<module>r¡      sb   ðó, 
Ý ß B× Bã ç AÝ ñ Ý4à	ˆ×	Ñ	˜HÓ	%€à!Ð#4Ð5Ð àÐ ô`8Ð(ô `8ðF	 Ð
�r.   