Ë
    S^(hK'  ã                   ó€   — d Z ddlZddl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 model ByT5.é    N)ÚListÚOptionalÚTupleé   )Ú
AddedTokenÚPreTrainedTokenizer)Úloggingc            
       óN  ‡ — e Zd ZdZddgZ	 	 	 	 	 d	 dˆ fd„Zed„ «       Zd„ Z	 dde	e
   d	ee	e
      d
ede	e
   fˆ fd„Z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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 )ÚByT5Tokenizera—  
    Construct a ByT5 tokenizer. ByT5 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:
        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 125):
            Add a number of extra ids added to the end of 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. Extra tokens are
            indexed from the end of the vocabulary up to beginning ("<extra_id_0>" is the last token in the vocabulary
            like in ByT5 preprocessing see
            [here](https://github.com/google-research/text-to-text-transfer-transformer/blob/9fd7b14a769417be33bc6c850f9598764913c833/t5/data/preprocessors.py#L2117)).
        additional_special_tokens (`List[str]`, *optional*):
            Additional special tokens used by the tokenizer.
    Ú	input_idsÚattention_maskÚreturnc           	      ó0  •— |dkD  r|€t        |«      D �cg c]  }d|› d�‘Œ
 }}nK|dkD  rF|�Dt        |«      dkD  r6t        t        t        d„ |«      «      «      }||k7  rt	        d|› d|› d�«      ‚t        |t        «      rt        |dd¬	«      n|}t        |t        «      rt        |dd¬	«      n|}t        |t        «      rt        |dd¬	«      n|}|||d
œ| _        t        | j                  «      | _	        d| _
        t        ‰	| �0  d|||d|dœ|¤Ž y c c}w )Nr   z
<extra_id_ú>c                 ó.   — t        dt        | «      v «      S )NÚextra_id)ÚboolÚstr)Úxs    úh/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/byt5/tokenization_byt5.pyú<lambda>z(ByT5Tokenizer.__init__.<locals>.<lambda>L   s   € ´D¸ÄsÈ1ÃvÐ9MÓ4N€ ó    zBoth extra_ids (z!) and additional_special_tokens (zm) are provided to ByT5Tokenizer. In this case the additional_special_tokens must include the extra_ids tokensT)ÚlstripÚrstrip)r   é   é   é   )Ú	eos_tokenÚ	unk_tokenÚ	pad_tokenÚ	extra_idsÚadditional_special_tokens© )ÚrangeÚlenÚsetÚfilterÚ
ValueErrorÚ
isinstancer   r   Ú_added_tokens_decoderÚoffsetÚ_utf_vocab_sizeÚsuperÚ__init__)
Úselfr   r   r    r!   r"   ÚkwargsÚiÚextra_tokensÚ	__class__s
            €r   r.   zByT5Tokenizer.__init__>   sI  ø€ ð �qŠ=Ð6Ð>ÜDIÈ)ÓDTÖ(U¸q¨:°a°S¸Ò):Ð(UÐ%Ñ(UØ˜Š]Ð8ÐDÌÐMfÓIgÐjkÒIkäœs¤6Ñ*NÐPiÓ#jÓkÓlˆLØ˜yÒ(Ü Ø& y kÐ1RÐSlÐRmð n(ð (óð ô HRÐR[Ô]`ÔGa”J˜y°¸dÕCÐgpˆ	äGQÐR[Ô]`ÔGa”J˜y°¸dÕCÐgpˆ	ÜGQÐR[Ô]`ÔGa”J˜y°¸dÕCÐgpˆ	à)2°yÀYÑ%OˆÔ"Ü˜$×4Ñ4Ó5ˆŒØ#ˆÔÜ‰Ñð 	
ØØØØØ&?ñ	
ð ó	
ùò' )Vs   –Dc                 ó   — | j                   S ©N)r,   )r/   s    r   Ú
vocab_sizezByT5Tokenizer.vocab_sizee   s   € à×#Ñ#Ð#r   c                 óÄ   — t        | j                  | j                  z   «      D �ci c]  }| j                  |«      |“Œ }}|j	                  | j
                  «       |S c c}w r5   )r$   r6   r+   Úconvert_ids_to_tokensÚupdateÚadded_tokens_encoder)r/   r1   Úvocabs      r   Ú	get_vocabzByT5Tokenizer.get_vocabi   sW   € Ü;@ÀÇÁÐSW×S^ÑS^ÑA^Ó;_Ö`°a�×+Ñ+¨AÓ.°Ñ1Ð`ˆÐ`Ø�‰�T×.Ñ.Ô/Øˆùò as   ¥AÚtoken_ids_0Útoken_ids_1Úalready_has_special_tokensc                 ó¤   •— |rt         ‰| �  ||d¬«      S |€dgt        |«      z  dgz   S dgt        |«      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)r=   r>   r?   r   r   )r-   Úget_special_tokens_maskr%   )r/   r=   r>   r?   r3   s       €r   rA   z%ByT5Tokenizer.get_special_tokens_maskn   sy   ø€ ñ$ &Ü‘7Ñ2Ø'°[Ð]að 3ó ð ð
 ÐØ�Cœ#˜kÓ*Ñ*¨q¨cÑ1Ð1Ø�”c˜+Ó&Ñ&¨1¨#Ñ-°!°´s¸;Ó7GÑ1GÑHÈAÈ3ÑNÐNr   Ú	token_idsc                 ó¬   — t        |«      dkD  r7|d   | j                  k(  r%t        j                  d| j                  › d�«       |S || j                  gz   S )z.Do not add eos again if user already added it.r   éÿÿÿÿzThis sequence already has zQ. In future versions this behavior may lead to duplicated eos tokens being added.)r%   Úeos_token_idÚwarningsÚwarnr   )r/   rB   s     r   Ú_add_eos_if_not_presentz%ByT5Tokenizer._add_eos_if_not_presentŠ   s]   € äˆy‹>˜AÒ )¨B¡-°4×3DÑ3DÒ"DÜ�M‰MØ,¨T¯^©^Ð,<ð =+ð +ôð Ðà × 1Ñ 1Ð2Ñ2Ð2r   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. ByT5 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   )rE   r%   )r/   r=   r>   Úeoss       r   Ú$create_token_type_ids_from_sequencesz2ByT5Tokenizer.create_token_type_ids_from_sequences•   sP   € ð  × Ñ Ð!ˆàÐÜ�{ SÑ(Ó)¨Q¨CÑ/Ð/Ü�; Ñ$ {Ñ2°SÑ8Ó9¸Q¸CÑ?Ð?r   c                 óX   — | j                  |«      }|€|S | j                  |«      }||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.
        )rH   )r/   r=   r>   s      r   Ú build_inputs_with_special_tokensz.ByT5Tokenizer.build_inputs_with_special_tokens«   s;   € ð& ×2Ñ2°;Ó?ˆØÐØÐà×6Ñ6°{ÓCˆKØ Ñ,Ð,r   Ú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)ÚencodeÚchr)r/   rN   r1   Útokenss       r   Ú	_tokenizezByT5Tokenizer._tokenizeÅ   s,   € à"&§+¡+¨gÓ"6Ö7˜Q”#�a•&Ð7ˆÐ7Øˆùò 8s   ”*c                 óZ   — t        |«      dk7  rd}|S t        |«      | j                  z   }|S )z0Converts a token (str) in an id using the vocab.r   N)r%   Úordr+   )r/   ÚtokenÚtoken_ids      r   Ú_convert_token_to_idz"ByT5Tokenizer._convert_token_to_idÊ   s4   € ô ˆu‹:˜Š?ØˆHð ˆô ˜5“z D§K¡KÑ/ˆHàˆr   c                 ó6   — t        || j                  z
  «      }|S )z=Converts an index (integer) in a token (str) using the vocab.)rR   r+   )r/   ÚindexrW   s      r   Ú_convert_id_to_tokenz"ByT5Tokenizer._convert_id_to_tokenÔ   s   € ä�E˜DŸK™KÑ'Ó(ˆØˆr   c                 ó  — d}|D ]i  }|| j                   v r| j                   |   j                  d«      }n5|| j                  v r|j                  d«      }nt        t	        |«      g«      }||z  }Œk |j                  dd¬«      }|S )z:Converts a sequence of tokens (string) in a single string.r   rP   Úignore)Úerrors)Úadded_tokens_decoderrQ   r:   ÚbytesrV   Údecode)r/   rS   ÚbstringrW   Ú
tok_stringÚstrings         r   Úconvert_tokens_to_stringz&ByT5Tokenizer.convert_tokens_to_stringÙ   sŽ   € àˆØò 	"ˆEØ˜×1Ñ1Ñ1Ø!×6Ñ6°uÑ=×DÑDÀWÓM‘
Ø˜$×3Ñ3Ñ3Ø"Ÿ\™\¨'Ó2‘
ä"¤C¨£J <Ó0�
Ø�zÑ!‰Gð	"ð —‘ °�Ó9ˆØˆr   Úsave_directoryÚfilename_prefixc                  ó   — y)Nr#   r#   )r/   rg   rh   s      r   Úsave_vocabularyzByT5Tokenizer.save_vocabularyè   s   € Ør   )z</s>z<unk>z<pad>é}   N)r   N)NFr5   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úmodel_input_namesr.   Úpropertyr6   r<   r   Úintr   r   rA   rH   rK   rM   r   rT   rY   r\   rf   r   rj   Ú__classcell__)r3   s   @r   r   r      sg  ø„ ñð@ %Ð&6Ð7Ðð ØØØØ"&ð%
ð 
õ%
ðN ñ$ó ð$òð sxñOØ ™9ðOØ3;¸DÀ¹IÑ3FðOØkoðOà	ˆc‰õOð8	3°°c±ð 	3¸tÀC¹yó 	3ð JNñ@Ø ™9ð@Ø3;¸DÀ¹IÑ3Fð@à	ˆc‰ó@ð. JNñ-Ø ™9ð-Ø3;¸DÀ¹IÑ3Fð-à	ˆc‰ó-ð4˜cð  d¨3¡ió ò
òò
ñ¨cð ÀHÈSÁMð Ð]bÐcfÑ]g÷ r   r   )ro   rF   Útypingr   r   r   Útokenization_utilsr   r   Úutilsr	   Ú
get_loggerrl   Úloggerr   Ú__all__r#   r   r   ú<module>rz      sG   ðñ )ã ß (Ñ (ç AÝ ð 
ˆ×	Ñ	˜HÓ	%€ôNÐ'ô Nðb Ð
�r   