Ë
    T^(h0'  ã                   óÆ   — d 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 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dZ G d„ de«      ZdgZy)z'Tokenization classes for RemBERT model.é    N)Úcopyfile)ÚListÚOptionalÚTupleé   )Ú
AddedToken)ÚPreTrainedTokenizerFast)Úis_sentencepiece_availableÚloggingé   )ÚRemBertTokenizerzsentencepiece.modelztokenizer.json)Ú
vocab_fileÚtokenizer_fileu   â–�c            
       ó  ‡ — e Zd ZdZeZeZ	 	 	 	 	 	 	 	 	 	 	 	 dˆ fd„	Ze	d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
dee   fd	„Z	 ddee   deee      dee   fd
„Zddedee   dee   fd„Zˆ xZS )ÚRemBertTokenizerFasta¿  
    Construct a "fast" RemBert 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.
        do_lower_case (`bool`, *optional*, defaults to `True`):
            Whether or not to lowercase the input when tokenizing.
        remove_space (`bool`, *optional*, defaults to `True`):
            Whether or not to strip the text when tokenizing (removing excess spaces before and after the string).
        keep_accents (`bool`, *optional*, defaults to `False`):
            Whether or not to keep accents when tokenizing.
        bos_token (`str`, *optional*, defaults to `"[CLS]"`):
            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 `"[SEP]"`):
            The end of sequence token. .. note:: 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`.
        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.
        sep_token (`str`, *optional*, defaults to `"[SEP]"`):
            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.
        pad_token (`str`, *optional*, defaults to `"<pad>"`):
            The token used for padding, for example when batching sequences of different lengths.
        cls_token (`str`, *optional*, defaults to `"[CLS]"`):
            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.
        mask_token (`str`, *optional*, defaults to `"[MASK]"`):
            The token used for masking values. This is the token used when training this model with masked language
            modeling. This is the token which the model will try to predict.
    c                 ó¶   •— t        |t        «      rt        |dd¬«      n|}t        ‰| �  |f||||||||	|
||dœ|¤Ž || _        || _        || _        || _        y )NTF)ÚlstripÚrstrip)r   Údo_lower_caseÚremove_spaceÚkeep_accentsÚ	bos_tokenÚ	eos_tokenÚ	unk_tokenÚ	sep_tokenÚ	pad_tokenÚ	cls_tokenÚ
mask_token)	Ú
isinstanceÚstrr   ÚsuperÚ__init__r   r   r   r   )Úselfr   r   r   r   r   r   r   r   r   r   r   r   ÚkwargsÚ	__class__s                 €ús/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/rembert/tokenization_rembert_fast.pyr"   zRemBertTokenizerFast.__init__X   s„   ø€ ô" KUÐU_ÔadÔJe”Z 
°4ÀÕFÐkuˆ
ä‰ÑØð	
à)Ø'Ø%Ø%ØØØØØØØ!ñ	
ð ò	
ð  +ˆÔØ(ˆÔØ(ˆÔØ$ˆ�ó    Úreturnc                 óp   — | j                   r)t        j                  j                  | j                   «      S dS ©NF)r   ÚosÚpathÚisfile)r#   s    r&   Úcan_save_slow_tokenizerz,RemBertTokenizerFast.can_save_slow_tokenizer€   s$   € à26·/²/Œr�w‰w�~‰~˜dŸo™oÓ.ÐLÀuÐLr'   Útoken_ids_0Útoken_ids_1c                 óf   — | j                   g}| j                  g}|€||z   |z   S ||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. A RemBERT sequence has the following format:

        - single sequence: `[CLS] X [SEP]`
        - pair of sequences: `[CLS] A [SEP] B [SEP]`

        Args:
            token_ids_0 (`List[int]`):
                List of IDs to which the special tokens will be added
            token_ids_1 (`List[int]`, *optional*, defaults to `None`):
                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Úcls_token_id©r#   r/   r0   ÚsepÚclss        r&   Ú build_inputs_with_special_tokensz5RemBertTokenizerFast.build_inputs_with_special_tokens„   sP   € ð& × Ñ Ð!ˆØ× Ñ Ð!ˆØÐØ˜Ñ$ sÑ*Ð*Ø�[Ñ  3Ñ&¨Ñ4°sÑ:Ð:r'   Úalready_has_special_tokensc                 ó
  — |r9|�t        d«      ‚|D �cg c]   }|| j                  | j                  fv rdnd‘Œ" c}S |�+dgdgt        |«      z  z   dgz   dgt        |«      z  z   dgz   S dgdgt        |«      z  z   dgz   S c c}w )aØ  
        Retrieves 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*, defaults to `None`):
                Optional second list of IDs for sequence pairs.
            already_has_special_tokens (`bool`, *optional*, defaults to `False`):
                Set to True if 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.
        zYou should not supply a second sequence if the provided sequence of ids is already formatted with special tokens for the model.r   r   )Ú
ValueErrorr2   r3   Úlen)r#   r/   r0   r8   Úxs        r&   Úget_special_tokens_maskz,RemBertTokenizerFast.get_special_tokens_mask�   s¹   € ñ& &ØÐ&Ü ðRóð ð VaÖaÐPQ˜˜t×0Ñ0°$×2CÑ2CÐDÑD‘AÈ!ÑKÒaÐaàÐ"Ø�3˜1˜#¤ KÓ 0Ñ0Ñ1°Q°CÑ7¸A¸3ÄÀ[ÓAQÑ;QÑRÐVWÐUXÑXÐXØˆs�q�cœC Ó,Ñ,Ñ-°°Ñ3Ð3ùò	 bs   ”%B c                 ó´   — | j                   g}| j                  g}|€t        ||z   |z   «      dgz  S t        ||z   |z   «      dgz  t        ||z   «      dgz  z   S )aÙ  
        Creates a mask from the two sequences passed to be used in a sequence-pair classification task. A RemBERT
        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*, defaults to `None`):
                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   )r2   r3   r;   r4   s        r&   Ú$create_token_type_ids_from_sequencesz9RemBertTokenizerFast.create_token_type_ids_from_sequences¼   st   € ð. × Ñ Ð!ˆØ× Ñ Ð!ˆàÐÜ�s˜[Ñ(¨3Ñ.Ó/°1°#Ñ5Ð5Ü�3˜Ñ$ sÑ*Ó+¨q¨cÑ1´C¸ÀcÑ8IÓ4JÈaÈSÑ4PÑPÐPr'   Úsave_directoryÚfilename_prefixc                 ó°  — t         j                  j                  |«      s%t        j	                  dj                  |«      «       y t         j                  j                  ||r|dz   ndt        d   z   «      }t         j                  j                  | j                  «      t         j                  j                  |«      k7  rt        | j                  |«       |fS )Nz*Vocabulary path ({}) should be a directoryú-Ú r   )r+   r,   ÚisdirÚloggerÚerrorÚformatÚjoinÚVOCAB_FILES_NAMESÚabspathr   r   )r#   r@   rA   Úout_vocab_files       r&   Úsave_vocabularyz$RemBertTokenizerFast.save_vocabularyÚ   s˜   € Ü�w‰w�}‰}˜^Ô,Ü�L‰LÐE×LÑLÈ^Ó\Ô]ØÜŸ™Ÿ™Ø±o˜_¨sÒ2È2ÔQbÐcoÑQpÑpó
ˆô �7‰7�?‰?˜4Ÿ?™?Ó+¬r¯w©w¯©¸~Ó/NÒNÜ�T—_‘_ nÔ5àÐ Ð r'   )NNTTFú[CLS]ú[SEP]z<unk>rO   z<pad>rN   z[MASK])Nr*   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rJ   Úvocab_files_namesr   Úslow_tokenizer_classr"   ÚpropertyÚboolr.   r   Úintr   r7   r=   r?   r    r   rM   Ú__classcell__)r%   s   @r&   r   r   &   s2  ø„ ñ,ð\ *ÐØ+Ðð ØØØØØØØØØØØõ&%ðP ðM¨ò Mó ðMð JNñ;Ø ™9ð;Ø3;¸DÀ¹IÑ3Fð;à	ˆc‰ó;ð4 sxñ4Ø ™9ð4Ø3;¸DÀ¹IÑ3Fð4Økoð4à	ˆc‰ó4ð@ JNñQØ ™9ðQØ3;¸DÀ¹IÑ3FðQà	ˆc‰óQñ<!¨cð !ÀHÈSÁMð !Ð]bÐcfÑ]g÷ !r'   r   )rS   r+   Úshutilr   Útypingr   r   r   Útokenization_utilsr   Útokenization_utils_fastr	   Úutilsr
   r   Útokenization_rembertr   Ú
get_loggerrP   rF   rJ   ÚSPIECE_UNDERLINEr   Ú__all__© r'   r&   ú<module>rd      sp   ðñ .ã 	Ý ß (Ñ (å ,Ý >ß 8ñ ÔÞ6àÐà	ˆ×	Ñ	˜HÓ	%€Ø#8ÐL\Ñ]Ð ð Ð ô!Ð2ô !ðD "Ð
"�r'   