Ë
    T^(hu  ã                   ó|   — d Z ddlmZmZmZmZ ddlmZmZ ddl	m
Z
  e
j                  e«      Z G d„ de«      ZdgZy)	z!Tokenization class for Perceiver.é    )ÚDictÚListÚOptionalÚTupleé   )Ú
AddedTokenÚPreTrainedTokenizer)Úloggingc            
       ó  ‡ — e Zd ZdZddgZ	 	 	 	 	 	 	 d	 dˆ fd„Zdeeef   fd„Z	e
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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 )ÚPerceiverTokenizeraS  
    Construct a Perceiver tokenizer. The Perceiver simply uses raw bytes utf-8 encoding.

    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:
        pad_token (`str`, *optional*, defaults to `"[PAD]"`):
            The token used for padding, for example when batching sequences of different lengths.
        bos_token (`str`, *optional*, defaults to `"[BOS]"`):
            The BOS token (reserved in the vocab, but not actually used).
        eos_token (`str`, *optional*, defaults to `"[EOS]"`):
            The end of sequence token (reserved in the vocab, but not actually used).

            <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>

        mask_token (`str`, *optional*, defaults to `"[MASK]"`):
            The MASK token, useful for masked language modeling.
        cls_token (`str`, *optional*, defaults to `"[CLS]"`):
            The CLS token (reserved in the vocab, but not actually used).
        sep_token (`str`, *optional*, defaults to `"[SEP]"`):
            The separator token, which is used when building a sequence from two sequences.

    Ú	input_idsÚattention_maskÚreturnc                 ó  •— 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        |t        «      rt        |dd¬«      n|}t        |t        «      rt        |dd¬«      n|}d| _        ||||||dœ| _        t        | j                  «      | _        t        ‰	| �   d|||||||dœ|¤Ž y )NF)ÚlstripÚrstripé   )r   é   é   r   é   é   )Ú	pad_tokenÚ	bos_tokenÚ	eos_tokenÚ
mask_tokenÚ	cls_tokenÚ	sep_tokenÚmodel_max_length© )	Ú
isinstanceÚstrr   Ú_utf_vocab_sizeÚ_added_tokens_decoderÚlenÚ_num_special_tokensÚsuperÚ__init__)
Úselfr   r   r   r   r   r   r   ÚkwargsÚ	__class__s
            €úr/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/perceiver/tokenization_perceiver.pyr'   zPerceiverTokenizer.__init__;   s  ø€ ô JTÐT]Ô_bÔIc”J˜y°¸uÕEÐirˆ	ÜISÐT]Ô_bÔIc”J˜y°¸uÕEÐirˆ	ÜISÐT]Ô_bÔIc”J˜y°¸uÕEÐirˆ	ÜKUÐV`ÔbeÔKf”Z 
°5ÀÕGÐlvˆ
ÜISÐT]Ô_bÔIc”J˜y°¸uÕEÐirˆ	ÜISÐT]Ô_bÔIc”J˜y°¸uÕEÐirˆ	à#ˆÔð ØØØØØñ6
ˆÔ"ô $' t×'AÑ'AÓ#BˆÔ Ü‰Ñð 		
ØØØØ!ØØØ-ñ		
ð ó		
ó    c                 ó®   — i }t        | j                  «      D ]  }t        |«      }|| j                  z   ||<   Œ! |j	                  | j
                  «       |S ©N)Úranger"   Úchrr%   ÚupdateÚadded_tokens_encoder)r(   ÚvocabÚiÚtokens       r+   Ú	get_vocabzPerceiverTokenizer.get_vocabd   sW   € ØˆÜ�t×+Ñ+Ó,ò 	8ˆAÜ˜“FˆEØ˜t×7Ñ7Ñ7ˆE�%ŠLð	8ð 	�‰�T×.Ñ.Ô/Øˆr,   c                 ó   — | j                   S r.   )r"   )r(   s    r+   Ú
vocab_sizezPerceiverTokenizer.vocab_sizel   s   € à×#Ñ#Ð#r,   Útoken_ids_0Útoken_ids_1Úalready_has_special_tokensc                 ó´   •— |rt         ‰| �  ||d¬«      S |€dgdgt        |«      z  z   dgz   S dgdgt        |«      z  z   dgz   dgt        |«      z  z   dg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)r9   r:   r;   r   r   )r&   Úget_special_tokens_maskr$   )r(   r9   r:   r;   r*   s       €r+   r=   z*PerceiverTokenizer.get_special_tokens_maskp   s‰   ø€ ñ$ &Ü‘7Ñ2Ø'°[Ð]að 3ó ð ð
 ÐØ�3˜!˜œs ;Ó/Ñ/Ñ/°1°#Ñ5Ð5Øˆs�q�cœC Ó,Ñ,Ñ-°°Ñ3¸°s¼SÀÓ=MÑ7MÑNÐRSÐQTÑTÐTr,   c                 ó    — |€| j                   g|z   | j                  gz   S | j                   g|z   | j                  gz   |z   | j                  gz   S )af  
        Build model inputs from a sequence or a pair of sequence for sequence classification tasks. A 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*):
                Optional second list of IDs for sequence pairs.

        Returns:
            `List[int]`: List of [input IDs](../glossary#input-ids) with the appropriate special tokens.
        )Úcls_token_idÚsep_token_id)r(   r9   r:   s      r+   Ú build_inputs_with_special_tokensz3PerceiverTokenizer.build_inputs_with_special_tokensŒ   sb   € ð& ÐØ×%Ñ%Ð&¨Ñ4¸×8IÑ8IÐ7JÑJÐJà×%Ñ%Ð&¨Ñ4¸×8IÑ8IÐ7JÑJÈ[ÑXÐ\`×\mÑ\mÐ[nÑnÐnr,   Útextc                 ó^   — |j                  d«      D �cg c]  }t        |«      ‘Œ }}|S c c}w )zPTake as input a string and return a list of strings (tokens) for words/sub-wordsúutf-8)Úencoder0   )r(   rB   r4   Útokenss       r+   Ú	_tokenizezPerceiverTokenizer._tokenize¤   s,   € à"&§+¡+¨gÓ"6Ö7˜Q”#�a•&Ð7ˆÐ7Øˆùò 8s   ”*c                 ón   — t        |«      dk7  r| j                  }|S t        |«      | j                  z   }|S )z0Converts a token (str) in an id using the vocab.r   )r$   Úunk_token_idÚordr%   )r(   r5   Útoken_ids      r+   Ú_convert_token_to_idz'PerceiverTokenizer._convert_token_to_id©   s:   € äˆu‹:˜Š?Ø×(Ñ(ˆHð ˆô ˜5“z D×$<Ñ$<Ñ<ˆHØˆr,   c                 ó6   — t        || j                  z
  «      }|S )z=Converts an index (integer) in a token (str) using the vocab.)r0   r%   )r(   Úindexr5   s      r+   Ú_convert_id_to_tokenz'PerceiverTokenizer._convert_id_to_token±   s   € ä�E˜D×4Ñ4Ñ4Ó5ˆØˆr,   c                 óÄ   — d}|D ]E  }|| j                   v rt        |«      j                  d«      }nt        t	        |«      g«      }||z  }ŒG |j                  dd¬«      }|S )z:Converts a sequence of tokens (string) in a single string.r,   rD   Úreplace)Úerrors)r2   r!   rE   ÚbytesrJ   Údecode)r(   rF   Úbstringr5   Ú
tok_stringÚstrings         r+   Úconvert_tokens_to_stringz+PerceiverTokenizer.convert_tokens_to_string·   sk   € àˆØò 	"ˆEØ˜×1Ñ1Ñ1Ü  ›Z×.Ñ.¨wÓ7‘
ä"¤C¨£J <Ó0�
Ø�zÑ!‰Gð	"ð —‘ °	�Ó:ˆØˆr,   Úsave_directoryÚfilename_prefixc                  ó   — y)Nr   r   )r(   rY   rZ   s      r+   Úsave_vocabularyz"PerceiverTokenizer.save_vocabularyÄ   s   € Ør,   )z[PAD]z[BOS]z[EOS]z[MASK]z[CLS]z[SEP]i   )r   N)NFr.   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úmodel_input_namesr'   r   r!   Úintr6   Úpropertyr8   r   r   Úboolr=   rA   rG   rL   rO   rX   r   r\   Ú__classcell__)r*   s   @r+   r   r      s+  ø„ ñð< %Ð&6Ð7Ðð ØØØØØØð'
ð 
õ'
ðR˜4  S ™>ó ð ñ$ó ð$ð sxñUØ ™9ðUØ3;¸DÀ¹IÑ3FðUØkoðUà	ˆc‰õUð: JNñoØ ™9ðoØ3;¸DÀ¹IÑ3Fðoà	ˆc‰óoð0˜cð  d¨3¡ió ò
òò
ñ¨cð ÀHÈSÁMð Ð]bÐcfÑ]g÷ r,   r   N)r`   Útypingr   r   r   r   Útokenization_utilsr   r	   Úutilsr
   Ú
get_loggerr]   Úloggerr   Ú__all__r   r,   r+   ú<module>rl      sD   ðñ (ç .Ó .ç AÝ ð 
ˆ×	Ñ	˜HÓ	%€ôkÐ,ô kð\  Ð
 �r,   