Ë
    T^(há0  ã                   ó¤   — 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  ej                   e«      ZdZd	d
iZ G d„ de«      ZdgZy)zTokenization classes for .é    N)Úcopyfile)ÚAnyÚDictÚListÚOptionalÚTupleé   )ÚPreTrainedTokenizer)Úloggingu   â–�Ú
vocab_filezsentencepiece.bpe.modelc            
       ó\  ‡ — 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„ Z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dee   fˆ fd„Z	 dd
ee   deee      dee   fd„Zed„ «       Zd„ Zde	dee	   fd„Zd„ Zd„ Zd„ Zdde	dee	   dee	   fd„Zˆ xZS )ÚXGLMTokenizera€  
    Adapted from [`RobertaTokenizer`] and [`XLNetTokenizer`]. 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`):
            Path to the vocabulary file.
        bos_token (`str`, *optional*, defaults to `"<s>"`):
            The beginning of sequence token that was used during pretraining. Can be used a sequence classifier token.

            <Tip>

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

            </Tip>

        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>

        sep_token (`str`, *optional*, defaults to `"</s>"`):
            The separator token, which is used when building a sequence from multiple sequences, e.g. two sequences for
            sequence classification or for a text and a question for question answering. It is also used as the last
            token of a sequence built with special tokens.
        cls_token (`str`, *optional*, defaults to `"<s>"`):
            The classifier token which is used when doing sequence classification (classification of the whole sequence
            instead of per-token classification). It is the first token of the sequence when built with special tokens.
        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.
        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	                 óR  •— |€i n|| _         d| _        t        | j                  «      D �
cg c]  }
d|
› d�‘Œ
 }}
|	j                  dg «      xs g |	d<   |	dxx   |D �cg c]  }||	d   vsŒ|‘Œ c}z  cc<   t	        j
                  di | j                   ¤Ž| _        | j                  j                  t        |«      «       || _	        d| _
        ddddd	œ| _        t        | j                  «      }t        | j                  «      D �
ci c]  }
d|
› d�||
z   | j                  z   “Œ }}
| j                  j                  |«       | j                  j                  «       D ��ci c]  \  }}||“Œ
 c}}| _        t!        ‰| �D  d||||||| j                   d
œ|	¤Ž y c c}
w c c}w c c}
w c c}}w )Né   z<madeupwordú>Úadditional_special_tokensé   r   é   r	   )ú<s>ú<pad>ú</s>ú<unk>)Ú	bos_tokenÚ	eos_tokenÚ	unk_tokenÚ	sep_tokenÚ	cls_tokenÚ	pad_tokenr   © )r   Únum_madeup_wordsÚrangeÚgetÚspmÚSentencePieceProcessorÚsp_modelÚLoadÚstrr   Úfairseq_offsetÚfairseq_tokens_to_idsÚlenÚupdateÚitemsÚfairseq_ids_to_tokensÚsuperÚ__init__)Úselfr   r   r   r    r!   r   r"   r   ÚkwargsÚiÚmadeup_wordsÚwordÚsp_sizeÚkÚvÚ	__class__s                   €úh/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/xglm/tokenization_xglm.pyr3   zXGLMTokenizer.__init__e   sÃ  ø€ ð &5Ð%<™rÀ/ˆÔð !"ˆÔÜ49¸$×:OÑ:OÓ4PÖQ¨q˜+ a S¨Ò*ÐQˆÐQà.4¯j©jÐ9TÐVXÓ.YÒ._Ð]_ˆÐ*Ñ+ØÐ*Ó+Ø)ö0
Ø¨T¸Ð@[Ñ9\Ò-\ŠDò0
ñ 	
Ó+ô ×2Ñ2ÑJ°T×5IÑ5IÑJˆŒØ�‰×Ñœ3˜z›?Ô+Ø$ˆŒð  ˆÔð ./¸ÀAÐPQÑ%RˆÔ"ä�d—m‘mÓ$ˆÜW\Ð]a×]rÑ]rÓWsÖtÐRS˜+ a S¨Ð*¨G°a©K¸$×:MÑ:MÑ,MÑMÐtˆÐtØ×"Ñ"×)Ñ)¨,Ô7à7;×7QÑ7Q×7WÑ7WÓ7Y×%Z©t¨q°! a¨¡dÓ%ZˆÔ"ä‰Ñð 		
ØØØØØØØ ×0Ñ0ñ		
ð ó		
ùò; Rùò0
ùò* uùó &[s   «FÁF
Á*F
ÄFÅF#c                 ó~   — | j                   j                  «       }d |d<   | j                  j                  «       |d<   |S )Nr)   Úsp_model_proto)Ú__dict__Úcopyr)   Úserialized_model_proto)r4   Ústates     r=   Ú__getstate__zXGLMTokenizer.__getstate__�   s;   € Ø—‘×"Ñ"Ó$ˆØ ˆˆjÑØ"&§-¡-×"FÑ"FÓ"HˆÐÑØˆó    c                 óÊ   — || _         t        | d«      si | _        t        j                  di | j                  ¤Ž| _        | j
                  j                  | j                  «       y )Nr   r#   )r@   Úhasattrr   r'   r(   r)   ÚLoadFromSerializedProtor?   )r4   Úds     r=   Ú__setstate__zXGLMTokenizer.__setstate__£   sQ   € ØˆŒô �tÐ.Ô/Ø#%ˆDÔ ä×2Ñ2ÑJ°T×5IÑ5IÑJˆŒØ�‰×-Ñ-¨d×.AÑ.AÕBrE   Útoken_ids_0Útoken_ids_1c                 ó\   — |€| j                   g|z   S | j                   g}||z   |z   |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. An XLM-RoBERTa sequence has the following format:

        - single sequence: `<s> X </s>`
        - pair of sequences: `<s> A </s></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.
        )Úsep_token_id©r4   rK   rL   Úseps       r=   Ú build_inputs_with_special_tokensz.XGLMTokenizer.build_inputs_with_special_tokens­   sF   € ð( ÐØ×%Ñ%Ð&¨Ñ4Ð4Ø× Ñ Ð!ˆØ�[Ñ  3Ñ&¨Ñ,¨{Ñ:Ð:rE   Úalready_has_special_tokensc                 ó¦   •— |rt         ‰| �  ||d¬«      S |€dgdgt        |«      z  z   S dgdgt        |«      z  z   ddgz   dgt        |«      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)rK   rL   rR   r   r   )r2   Úget_special_tokens_maskr.   )r4   rK   rL   rR   r<   s       €r=   rT   z%XGLMTokenizer.get_special_tokens_maskÆ   s{   ø€ ñ& &Ü‘7Ñ2Ø'°[Ð]að 3ó ð ð ÐØ�3˜1˜#¤ KÓ 0Ñ0Ñ1Ð1Øˆs�q�cœC Ó,Ñ,Ñ-°°A°Ñ6¸1¸#ÄÀKÓ@PÑ:PÑQÐQrE   c                 óz   — | j                   g}|€t        ||z   «      dgz  S t        ||z   |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. XLM-RoBERTa 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   )rN   r.   rO   s       r=   Ú$create_token_type_ids_from_sequencesz2XGLMTokenizer.create_token_type_ids_from_sequencesâ   sU   € ð$ × Ñ Ð!ˆàÐÜ�s˜[Ñ(Ó)¨Q¨CÑ/Ð/Ü�3˜Ñ$ sÑ*¨SÑ0°;Ñ>Ó?À1À#ÑEÐErE   c                 ó`   — t        | j                  «      | j                  z   | j                  z   S ©N)r.   r)   r,   r$   )r4   s    r=   Ú
vocab_sizezXGLMTokenizer.vocab_sizeú   s'   € ä�4—=‘=Ó! D×$7Ñ$7Ñ7¸$×:OÑ:OÑOÐOrE   c                 óª   — t        | j                  «      D �ci c]  }| j                  |«      |“Œ }}|j                  | j                  «       |S c c}w rX   )r%   rY   Úconvert_ids_to_tokensr/   Úadded_tokens_encoder)r4   r6   Úvocabs      r=   Ú	get_vocabzXGLMTokenizer.get_vocabþ   sK   € Ü;@ÀÇÁÓ;QÖR°a�×+Ñ+¨AÓ.°Ñ1ÐRˆÐRØ�‰�T×.Ñ.Ô/Øˆùò Ss   ˜AÚtextc                 óD   — | j                   j                  |t        ¬«      S )N)Úout_type)r)   Úencoder+   )r4   r_   s     r=   Ú	_tokenizezXGLMTokenizer._tokenize  s   € Ø�}‰}×#Ñ# D´3Ð#Ó7Ð7rE   c                 ó¬   — || j                   v r| j                   |   S | j                  j                  |«      }|r|| j                  z   S | j                  S )z0Converts a token (str) in an id using the vocab.)r-   r)   Ú	PieceToIdr,   Úunk_token_id)r4   ÚtokenÚspm_ids      r=   Ú_convert_token_to_idz"XGLMTokenizer._convert_token_to_id  sU   € à�D×.Ñ.Ñ.Ø×-Ñ-¨eÑ4Ð4Ø—‘×(Ñ(¨Ó/ˆñ 06ˆv˜×+Ñ+Ñ+ÐL¸4×;LÑ;LÐLrE   c                 óŒ   — || j                   v r| j                   |   S | j                  j                  || j                  z
  «      S )z=Converts an index (integer) in a token (str) using the vocab.)r1   r)   Ú	IdToPiecer,   )r4   Úindexs     r=   Ú_convert_id_to_tokenz"XGLMTokenizer._convert_id_to_token  sA   € à�D×.Ñ.Ñ.Ø×-Ñ-¨eÑ4Ð4Ø�}‰}×&Ñ& u¨t×/BÑ/BÑ'BÓCÐCrE   c                 ól   — dj                  |«      j                  t        d«      j                  «       }|S )zIConverts a sequence of tokens (strings for sub-words) in a single string.Ú ú )ÚjoinÚreplaceÚSPIECE_UNDERLINEÚstrip)r4   ÚtokensÚ
out_strings      r=   Úconvert_tokens_to_stringz&XGLMTokenizer.convert_tokens_to_string  s,   € à—W‘W˜V“_×,Ñ,Ô-=¸sÓC×IÑIÓKˆ
ØÐrE   Ú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ú-ro   r   Úwb)ÚosÚpathÚisdirÚloggerÚerrorrq   ÚVOCAB_FILES_NAMESÚabspathr   Úisfiler   Úopenr)   rB   Úwrite)r4   rx   ry   Úout_vocab_fileÚfiÚcontent_spiece_models         r=   Úsave_vocabularyzXGLMTokenizer.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)r   r   r   r   r   r   NrX   )NF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r‚   Úvocab_files_namesÚmodel_input_namesr   r   r+   r   r3   rD   rJ   r   ÚintrQ   ÚboolrT   rV   ÚpropertyrY   r^   rc   ri   rm   rw   r   rŠ   Ú__classcell__)r<   s   @r=   r   r   "   s~  ø„ ñ=ð~ *ÐØ$Ð&6Ð7Ðð
 ØØØØØØ48ñ6
ð " $ s¨C x¡.Ñ1ð6
ð 
õ6
òpòCð JNñ;Ø ™9ð;Ø3;¸DÀ¹IÑ3Fð;à	ˆc‰ó;ð4 sxñRØ ™9ðRØ3;¸DÀ¹IÑ3FðRØkoðRà	ˆc‰õRð: JNñFØ ™9ðFØ3;¸DÀ¹IÑ3FðFà	ˆc‰óFð0 ñPó ðPòð
8˜cð 8 d¨3¡ió 8òMòDòñ
!¨cð !ÀHÈSÁMð !Ð]bÐcfÑ]g÷ !rE   r   )rŽ   r}   Úshutilr   Útypingr   r   r   r   r   Úsentencepiecer'   Útokenization_utilsr
   Úutilsr   Ú
get_loggerr‹   r€   rs   r‚   r   Ú__all__r#   rE   r=   ú<module>rœ      s_   ðñ !ã 	Ý ß 3Õ 3ã å 5Ý ð 
ˆ×	Ñ	˜HÓ	%€àÐ à!Ð#<Ð=Ð ôG!Ð'ô G!ðT Ð
�rE   