Ë
    S^(h~P  ã                   óú   — d Z ddlZddlZddlZddlmZ ddlmZmZm	Z	 ddl
ZddlmZmZmZmZmZ ddlmZ  ej(                  e«      Zdd	d
œZ e«       d„ «       Zd„ Zd„ Zd„ Z G d„ d«      Z G d„ de«      ZdgZy)zTokenization classes for CLIP.é    N)Ú	lru_cache)ÚListÚOptionalÚTupleé   )Ú
AddedTokenÚPreTrainedTokenizerÚ_is_controlÚ_is_punctuationÚ_is_whitespace)Úloggingz
vocab.jsonz
merges.txt)Ú
vocab_fileÚmerges_filec            	      óò  — t        t        t        d«      t        d«      dz   «      «      t        t        t        d«      t        d«      dz   «      «      z   t        t        t        d«      t        d«      dz   «      «      z   } | dd }d	}t        d
«      D ]1  }|| vsŒ| j                  |«       |j                  d
|z   «       |dz  }Œ3 |D �cg c]  }t	        |«      ‘Œ }}t        t        | |«      «      S c c}w )a8  
    Returns list of utf-8 byte and a mapping to unicode strings. We specifically avoids mapping to whitespace/control
    characters the bpe code barfs on.

    The reversible bpe codes work on unicode strings. This means you need a large # of unicode characters in your vocab
    if you want to avoid UNKs. When you're at something like a 10B token dataset you end up needing around 5K for
    decent coverage. This is a significant percentage of your normal, say, 32K bpe vocab. To avoid that, we want lookup
    tables between utf-8 bytes and unicode strings.
    ú!ú~é   õ   Â¡õ   Â¬õ   Â®õ   Ã¿Nr   é   )ÚlistÚrangeÚordÚappendÚchrÚdictÚzip)ÚbsÚcsÚnÚbs       úh/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/clip/tokenization_clip.pyÚbytes_to_unicoder%   %   sæ   € ô 	ŒU”3�s“8œS ›X¨™\Ó*Ó+¬d´5¼¸T»ÄCÈÃIÐPQÁMÓ3RÓ.SÑSÔVZÔ[`ÔadÐeiÓajÔloÐptÓluÐxyÑlyÓ[zÓV{Ñ{ð ð 
‰Aˆ€BØ	€AÜ�4‹[ò ˆØ�BŠ;Ø�I‰I�aŒLØ�I‰I�d˜Q‘hÔØ�‰F‰Að	ð
 Ö	�QŒ#ˆa�&Ð	€BÐ	Ü”�B˜“ÓÐùò 
s   ÃC4c                 ób   — t        «       }| d   }| dd D ]  }|j                  ||f«       |}Œ |S )z…
    Return set of symbol pairs in a word.

    Word is represented as tuple of symbols (symbols being variable-length strings).
    r   r   N)ÚsetÚadd)ÚwordÚpairsÚ	prev_charÚchars       r$   Ú	get_pairsr-   >   sF   € ô ‹E€EØ�Q‘€IØ�Q�R�ò ˆØ�	‰	�9˜dÐ#Ô$Ø‰	ðð €Ló    c                 óT   — t        j                  dd| «      } | j                  «       } | S )Nz\s+ú )ÚreÚsubÚstrip)Útexts    r$   Úwhitespace_cleanr5   L   s$   € Ü�6‰6�&˜#˜tÓ$€DØ�:‰:‹<€DØ€Kr.   c                 óN   — | j                  «       } | sg S | j                  «       }|S )z@Runs basic whitespace cleaning and splitting on a piece of text.)r3   Úsplit)r4   Útokenss     r$   Úwhitespace_tokenizer9   S   s%   € à�:‰:‹<€DÙØˆ	Ø�Z‰Z‹\€FØ€Mr.   c                   óJ   — e Zd ZdZ	 	 	 	 	 d
d„Zdd„Zd„ Zdd„Zd„ Zd„ Z	d	„ Z
y)ÚBasicTokenizeraª  
    Constructs a BasicTokenizer that will run basic tokenization (punctuation splitting, lower casing, etc.).

    Args:
        do_lower_case (`bool`, *optional*, defaults to `True`):
            Whether or not to lowercase the input when tokenizing.
        never_split (`Iterable`, *optional*):
            Collection of tokens which will never be split during tokenization. Only has an effect when
            `do_basic_tokenize=True`
        tokenize_chinese_chars (`bool`, *optional*, defaults to `True`):
            Whether or not to tokenize Chinese characters.

            This should likely be deactivated for Japanese (see this
            [issue](https://github.com/huggingface/transformers/issues/328)).
        strip_accents (`bool`, *optional*):
            Whether or not to strip all accents. If this option is not specified, then it will be determined by the
            value for `lowercase` (as in the original BERT).
        do_split_on_punc (`bool`, *optional*, defaults to `True`):
            In some instances we want to skip the basic punctuation splitting so that later tokenization can capture
            the full context of the words, such as contractions.
    Nc                 ód   — |€g }|| _         t        |«      | _        || _        || _        || _        y ©N)Údo_lower_caser'   Únever_splitÚtokenize_chinese_charsÚstrip_accentsÚdo_split_on_punc)Úselfr>   r?   r@   rA   rB   s         r$   Ú__init__zBasicTokenizer.__init__t   s<   € ð ÐØˆKØ*ˆÔÜ˜{Ó+ˆÔØ&<ˆÔ#Ø*ˆÔØ 0ˆÕr.   c                 óJ  — |r$| j                   j                  t        |«      «      n| j                   }| j                  |«      }| j                  r| j                  |«      }t        j                  d|«      }t        |«      }g }|D ]€  }||vrY| j                  r0|j                  «       }| j                  dur/| j                  |«      }n| j                  r| j                  |«      }|j                  | j                  ||«      «       Œ‚ t        dj                  |«      «      }|S )aj  
        Basic Tokenization of a piece of text. For sub-word tokenization, see WordPieceTokenizer.

        Args:
            never_split (`List[str]`, *optional*)
                Kept for backward compatibility purposes. Now implemented directly at the base class level (see
                [`PreTrainedTokenizer.tokenize`]) List of token not to split.
        ÚNFCFr0   )r?   Úunionr'   Ú_clean_textr@   Ú_tokenize_chinese_charsÚunicodedataÚ	normalizer9   r>   ÚlowerrA   Ú_run_strip_accentsÚextendÚ_run_split_on_puncÚjoin)rC   r4   r?   Úunicode_normalized_textÚorig_tokensÚsplit_tokensÚtokenÚoutput_tokenss           r$   ÚtokenizezBasicTokenizer.tokenize„   s  € ñ CN�d×&Ñ&×,Ñ,¬S°Ó-=Ô>ÐSW×ScÑScˆØ×Ñ Ó%ˆð ×&Ò&Ø×/Ñ/°Ó5ˆDä"-×"7Ñ"7¸¸tÓ"DÐÜ)Ð*AÓBˆØˆØ ò 	MˆEØ˜KÑ'Ø×%Ò%Ø!ŸK™K›M�EØ×)Ñ)°Ñ6Ø $× 7Ñ 7¸Ó >™Ø×'Ò'Ø ×3Ñ3°EÓ:�EØ×Ñ × 7Ñ 7¸¸{Ó KÕLð	Mô ,¨C¯H©H°\Ó,BÓCˆØÐr.   c                 óº   — t        j                  d|«      }g }|D ].  }t        j                  |«      }|dk(  rŒ|j                  |«       Œ0 dj	                  |«      S )z$Strips accents from a piece of text.ÚNFDÚMnÚ )rJ   rK   Úcategoryr   rP   )rC   r4   Úoutputr,   Úcats        r$   rM   z!BasicTokenizer._run_strip_accentsª   s^   € ä×$Ñ$ U¨DÓ1ˆØˆØò 	 ˆDÜ×&Ñ& tÓ,ˆCØ�dŠ{ØØ�M‰M˜$Õð		 ð
 �w‰w�v‹Ðr.   c                 óv  — | j                   r|�||v r|gS t        |«      }d}d}g }|t        |«      k  rb||   }t        |«      r|j	                  |g«       d}n)|r|j	                  g «       d}|d   j	                  |«       |dz  }|t        |«      k  rŒb|D �cg c]  }dj                  |«      ‘Œ c}S c c}w )z&Splits punctuation on a piece of text.r   TFéÿÿÿÿr   rZ   )rB   r   Úlenr   r   rP   )	rC   r4   r?   ÚcharsÚiÚstart_new_wordr\   r,   Úxs	            r$   rO   z!BasicTokenizer._run_split_on_puncµ   s¿   € à×$Ò$¨Ð)@ÀTÈ[ÑEXØ�6ˆMÜ�T“
ˆØˆØˆØˆØ”#�e“*ŠnØ˜‘8ˆDÜ˜tÔ$Ø—‘˜t˜fÔ%Ø!%‘á!Ø—M‘M "Ô%Ø!&�Ø�r‘
×!Ñ! $Ô'Ø�‰FˆAð ”#�e“*‹nð %+Ö+˜q�—‘˜•
Ò+Ð+ùÒ+s   ÂB6c                 óø   — g }|D ]c  }t        |«      }| j                  |«      r4|j                  d«       |j                  |«       |j                  d«       ŒS|j                  |«       Œe dj                  |«      S )z)Adds whitespace around any CJK character.r0   rZ   )r   Ú_is_chinese_charr   rP   ©rC   r4   r\   r,   Úcps        r$   rI   z&BasicTokenizer._tokenize_chinese_charsË   sm   € àˆØò 	$ˆDÜ�T“ˆBØ×$Ñ$ RÔ(Ø—‘˜cÔ"Ø—‘˜dÔ#Ø—‘˜cÕ"à—‘˜dÕ#ð	$ð �w‰w�v‹Ðr.   c                 ó¦   — |dk\  r|dk  sF|dk\  r|dk  s<|dk\  r|dk  s2|dk\  r|dk  s(|d	k\  r|d
k  s|dk\  r|dk  s|dk\  r|dk  s
|dk\  r|dk  ryy)z6Checks whether CP is the codepoint of a CJK character.i N  iÿŸ  i 4  i¿M  i   iß¦ i § i?· i@· i¸ i ¸ i¯Î i ù  iÿú  i ø iú TF© )rC   rh   s     r$   rf   zBasicTokenizer._is_chinese_charØ   sr   € ð �6Š\˜b FšlØ�f’  v¢Ø�g’ "¨¢-Ø�g’ "¨¢-Ø�g’ "¨¢-Ø�g’ "¨¢-Ø�f’  v¢Ø�g’ "¨¢-ààr.   c                 óÔ   — g }|D ]Q  }t        |«      }|dk(  s|dk(  st        |«      rŒ$t        |«      r|j                  d«       ŒA|j                  |«       ŒS dj	                  |«      S )zBPerforms invalid character removal and whitespace cleanup on text.r   iýÿ  r0   rZ   )r   r
   r   r   rP   rg   s        r$   rH   zBasicTokenizer._clean_textð   sf   € àˆØò 	$ˆDÜ�T“ˆBØ�QŠw˜" š,¬+°dÔ*;ØÜ˜dÔ#Ø—‘˜cÕ"à—‘˜dÕ#ð	$ð �w‰w�v‹Ðr.   )TNTNTr=   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rD   rV   rM   rO   rI   rf   rH   rj   r.   r$   r;   r;   ]   s<   „ ñð0 ØØ#ØØó1ó $òL	ó,ò,òó0r.   r;   c            
       ó(  ‡ — e Zd ZdZeZddgZ	 	 	 	 	 dˆ fd„	Ze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d„ Zd„ Zd„ Zd„ Zd„ Zddedee   d	ee   fd„Zˆ xZS )ÚCLIPTokenizeraê  
    Construct a CLIP tokenizer. Based on byte-level Byte-Pair-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:
        vocab_file (`str`):
            Path to the vocabulary file.
        merges_file (`str`):
            Path to the merges file.
        errors (`str`, *optional*, defaults to `"replace"`):
            Paradigm to follow when decoding bytes to UTF-8. See
            [bytes.decode](https://docs.python.org/3/library/stdtypes.html#bytes.decode) for more information.
        unk_token (`str`, *optional*, defaults to `"<|endoftext|>"`):
            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`, *optional*, defaults to `"<|startoftext|>"`):
            The beginning of sequence token.
        eos_token (`str`, *optional*, defaults to `"<|endoftext|>"`):
            The end of sequence token.
        pad_token (`str`, *optional*, defaults to `"<|endoftext|>"`):
            The token used for padding, for example when batching sequences of different lengths.
    Ú	input_idsÚattention_maskc           
      óÚ  •— t        |t        «      rt        |dd¬«      n|}t        |t        «      rt        |dd¬«      n|}t        |t        «      rt        |dd¬«      n|}	 dd l}	|	j                  | _        t        |d¬«      5 }
t        j                  |
«      | _        d d d «       | j                  j                  «       D ��ci c]  \  }}||“Œ
 c}}| _        || _        t#        «       | _        | j$                  j                  «       D ��ci c]  \  }}||“Œ
 c}}| _        t        |d¬«      5 }|j)                  «       j+                  «       j-                  d«      d	d
 }d d d «       D �cg c]  }t/        |j-                  «       «      ‘Œ }}t1        t3        |t5        t7        |«      «      «      «      | _        dddœ| _        t=        j>                  dt<        j@                  «      | _!        tE        ‰| �Œ  d|||||dœ|¤Ž y # t
        $ r2 t        j                  d«       t        dd¬«      | _	        d | _        Y �ŒÇw xY w# 1 sw Y   �Œ¥xY wc c}}w c c}}w # 1 sw Y   ŒûxY wc c}w )NF)ÚlstripÚrstripr   zKftfy or spacy is not installed using custom BasicTokenizer instead of ftfy.)rA   rB   úutf-8©Úencodingú
r   iÿ¾  ú<|startoftext|>ú<|endoftext|>)r{   r|   z[<\|startoftext\|>|<\|endoftext\|>|'s|'t|'re|'ve|'m|'ll|'d|[\p{L}]+|[\p{N}]|[^\s\p{L}\p{N}]+)ÚerrorsÚ	unk_tokenÚ	bos_tokenÚ	eos_tokenÚ	pad_tokenrj   )$Ú
isinstanceÚstrr   ÚftfyÚfix_textÚImportErrorÚloggerÚinfor;   ÚnlpÚopenÚjsonÚloadÚencoderÚitemsÚdecoderr}   r%   Úbyte_encoderÚbyte_decoderÚreadr3   r7   Útupler   r   r   r`   Ú	bpe_ranksÚcacher1   ÚcompileÚ
IGNORECASEÚpatÚsuperrD   )rC   r   r   r}   r~   r   r€   r�   Úkwargsr„   Úvocab_handleÚkÚvÚmerges_handleÚ
bpe_mergesÚmergeÚ	__class__s                   €r$   rD   zCLIPTokenizer.__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ˆ	ð	!Ûà ŸM™MˆDŒMô �* wÔ/ð 	3°<ÜŸ9™9 \Ó2ˆDŒL÷	3à)-¯©×);Ñ);Ó)=×>¡  A˜˜1™Ó>ˆŒØˆŒÜ,Ó.ˆÔØ.2×.?Ñ.?×.EÑ.EÓ.G×H¡d a¨˜Q ™TÓHˆÔÜ�+¨Ô0ð 	[°MØ&×+Ñ+Ó-×3Ñ3Ó5×;Ñ;¸DÓAÀ!ÐFYÐZˆJ÷	[à8BÖC¨u”e˜EŸK™K›MÕ*ÐCˆ
ÐCÜœc *¬e´C¸
³OÓ.DÓEÓFˆŒØ):È_Ñ]ˆŒ
ä—:‘:ØnÜ�M‰Mó
ˆŒô
 	‰Ñð 	
ØØØØØñ	
ð ó	
øô- ò 	!Ü�K‰KÐeÔfÜ%°EÈEÔRˆDŒHØ ˆD�Mð	!ú÷
	3ñ 	3üã>ùó I÷	[ð 	[üâCs<   Á#H ÂIÃIÄIÄ11IÅ. I(È7I È?I ÉIÉI%c                 ó,   — t        | j                  «      S r=   )r`   r�   ©rC   s    r$   Ú
vocab_sizezCLIPTokenizer.vocab_sizeL  s   € ä�4—<‘<Ó Ð r.   c                 óB   — t        | j                  fi | j                  ¤ŽS r=   )r   r�   Úadded_tokens_encoderr£   s    r$   Ú	get_vocabzCLIPTokenizer.get_vocabP  s   € Ü�D—L‘LÑ> D×$=Ñ$=Ñ>Ð>r.   Útoken_ids_0Útoken_ids_1Úreturnc                 ól   — | j                   g}| j                  g}|€||z   |z   S ||z   |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 CLIP sequence has the following format:

        - single sequence: `<|startoftext|> X <|endoftext|>`

        Pairs of sequences are not the expected use case, but they will be handled without a separator.

        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.
        )Úbos_token_idÚeos_token_id©rC   r¨   r©   r   r€   s        r$   Ú build_inputs_with_special_tokensz.CLIPTokenizer.build_inputs_with_special_tokensS  sU   € ð( ×&Ñ&Ð'ˆ	Ø×&Ñ&Ð'ˆ	àÐØ˜{Ñ*¨YÑ6Ð6Ø˜;Ñ&¨Ñ2°YÑ>ÀÑLÈyÑXÐXr.   Ú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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`   )rC   r¨   r©   r°   r¡   s       €r$   r²   z%CLIPTokenizer.get_special_tokens_maskn  s�   ø€ ñ& &Ü‘7Ñ2Ø'°[Ð]að 3ó ð ð ÐØ�3˜1˜#¤ KÓ 0Ñ0Ñ1°Q°CÑ7Ð7Øˆs�q�cœC Ó,Ñ,Ñ-°°Ñ3°q°cÑ9¸a¸SÄ3À{ÓCSÑ=SÑTÐXYÐWZÑZÐZr.   c                 ó    — | j                   g}| j                  g}|€t        ||z   |z   «      dgz  S t        ||z   |z   |z   |z   |z   «      dgz  S )a—  
        Create a mask from the two sequences passed. CLIP 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   )r¬   r­   r`   r®   s        r$   Ú$create_token_type_ids_from_sequencesz2CLIPTokenizer.create_token_type_ids_from_sequencesŠ  sp   € ð  ×&Ñ&Ð'ˆ	Ø×&Ñ&Ð'ˆ	àÐÜ�y ;Ñ.°Ñ:Ó;¸q¸cÑAÐAÜ�9˜{Ñ*¨YÑ6¸ÑBÀ[ÑPÐS\Ñ\Ó]ÐabÐ`cÑcÐcr.   c                 óø  ‡ — |‰ j                   v r‰ j                   |   S t        |d d «      |d   dz   fz   }t        |«      }|s|dz   S 	 t        |ˆ fd„¬«      }|‰ j                  vrnÎ|\  }}g }d}|t        |«      k  r�	 |j                  ||«      }	|j                  |||	 «       |	}||   |k(  r6|t        |«      dz
  k  r%||dz      |k(  r|j                  ||z   «       |dz  }n|j                  ||   «       |dz  }|t        |«      k  rŒ�t        |«      }|}t        |«      dk(  rnt        |«      }Œídj                  |«      }|‰ j                   |<   |S # t        $ r |j                  ||d  «       Y Œiw xY w)	Nr_   ú</w>c                 óN   •— ‰j                   j                  | t        d«      «      S )NÚinf)r”   ÚgetÚfloat)ÚpairrC   s    €r$   ú<lambda>z#CLIPTokenizer.bpe.<locals>.<lambda>«  s   ø€ °·±×1CÑ1CÀDÌ%ÐPUË,Ó1W€ r.   ©Úkeyr   r   é   r0   )r•   r“   r-   Úminr”   r`   ÚindexrN   Ú
ValueErrorr   rP   )
rC   rT   r)   r*   ÚbigramÚfirstÚsecondÚnew_wordrb   Újs
   `         r$   ÚbpezCLIPTokenizer.bpe¡  s�  ø€ Ø�D—J‘JÑØ—:‘:˜eÑ$Ð$Ü�U˜3˜B�ZÓ  E¨"¡I°Ñ$6Ð#8Ñ8ˆÜ˜$“ˆáØ˜6‘>Ð!àÜ˜Ó$WÔXˆFØ˜TŸ^™^Ñ+ØØ"‰MˆE�6ØˆHØˆAØ”c˜$“i’-ðØŸ
™
 5¨!Ó,�Að
 —O‘O D¨¨1 IÔ.Ø�Aà˜‘7˜eÒ#¨¬C°«I¸©MÒ(9¸dÀ1ÀqÁ5¹kÈVÒ>SØ—O‘O E¨F¡NÔ3Ø˜‘F‘Aà—O‘O D¨¡GÔ,Ø˜‘F�Að ”c˜$“i“-ô  ˜X“ˆHØˆDÜ�4‹y˜AŠ~Øä! $›�ð9 ð: �x‰x˜‹~ˆØ ˆ�
‰
�5ÑØˆøô+ "ò Ø—O‘O D¨¨ HÔ-Ùðús   ÂE ÅE9Å8E9c                 óÒ  ‡ — g }‰ j                   €+dj                  ‰ j                  j                  |«      «      }n(t	        ‰ j                  |«      «      j                  «       }t        j                  ‰ j                  |«      D ]a  }dj                  ˆ fd„|j                  d«      D «       «      }|j                  d„ ‰ j                  |«      j                  d«      D «       «       Œc |S )zTokenize a string.r0   rZ   c              3   ó<   •K  — | ]  }‰j                   |   –— Œ y ­wr=   )r�   )Ú.0r#   rC   s     €r$   ú	<genexpr>z*CLIPTokenizer._tokenize.<locals>.<genexpr>Ô  s!   øè ø€ ò Ø)*�×!Ñ! !Õ$ñùs   ƒrw   c              3   ó    K  — | ]  }|–— Œ y ­wr=   rj   )rË   Ú	bpe_tokens     r$   rÌ   z*CLIPTokenizer._tokenize.<locals>.<genexpr>×  s   è ø€ ÒT¨IœiÑTùs   ‚)r…   rP   r‰   rV   r5   rL   r1   Úfindallr˜   ÚencoderN   rÈ   r7   )rC   r4   Ú
bpe_tokensrT   s   `   r$   Ú	_tokenizezCLIPTokenizer._tokenizeË  sÀ   ø€ àˆ
Ø�=‰=Ð Ø—8‘8˜DŸH™H×-Ñ-¨dÓ3Ó4‰Dä# D§M¡M°$Ó$7Ó8×>Ñ>Ó@ˆDä—Z‘Z §¡¨$Ó/ò 	UˆEØ—G‘Gó Ø.3¯l©l¸7Ó.Côó ˆEð ×ÑÑT¸¿¹À%»×9NÑ9NÈsÓ9SÔTÕTð		Uð
 Ðr.   c                 ó€   — | j                   j                  || j                   j                  | j                  «      «      S )z0Converts a token (str) in an id using the vocab.)r�   r¹   r~   )rC   rT   s     r$   Ú_convert_token_to_idz"CLIPTokenizer._convert_token_to_idÚ  s,   € à�|‰|×Ñ  t§|¡|×'7Ñ'7¸¿¹Ó'GÓHÐHr.   c                 ó8   — | j                   j                  |«      S )z=Converts an index (integer) in a token (str) using the vocab.)r�   r¹   )rC   rÁ   s     r$   Ú_convert_id_to_tokenz"CLIPTokenizer._convert_id_to_tokenÞ  s   € à�|‰|×Ñ Ó&Ð&r.   c                 óô   — dj                  |«      }t        |D �cg c]  }| j                  |   ‘Œ c}«      }|j                  d| j                  ¬«      j                  dd«      j                  «       }|S c c}w )z:Converts a sequence of tokens (string) in a single string.rZ   rw   )r}   r¶   r0   )rP   Ú	bytearrayr‘   Údecoder}   Úreplacer3   )rC   r8   r4   ÚcÚ
byte_arrays        r$   Úconvert_tokens_to_stringz&CLIPTokenizer.convert_tokens_to_stringâ  si   € à�w‰w�v‹ˆÜ¸dÖC¸ × 1Ñ 1°!Ó 4ÒCÓDˆ
Ø× Ñ  °·±Ð Ó=×EÑEÀfÈcÓR×XÑXÓZˆØˆùò  Ds   ›A5Ú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                  ||r|dz   ndt        d   z   «      }t        |dd¬«      5 }|j                  t        j                  | j                  d	d
d¬«      dz   «       d d d «       d}t        |dd¬«      5 }|j                  d«       t        | j                  j                  «       d„ ¬«      D ]X  \  }}	||	k7  r&t        j!                  dj                  |«      «       |	}|j                  dj                  |«      dz   «       |dz  }ŒZ 	 d d d «       ||fS # 1 sw Y   Œ¹xY w# 1 sw Y   ||fS xY w)Nz*Vocabulary path ({}) should be a directoryú-rZ   r   r   Úwrw   rx   r¿   TF)ÚindentÚ	sort_keysÚensure_asciirz   r   z#version: 0.2
c                 ó   — | d   S )Nr   rj   )Úkvs    r$   r¼   z/CLIPTokenizer.save_vocabulary.<locals>.<lambda>ú  s   € ÐY[Ð\]ÑY^€ r.   r½   zqSaving vocabulary to {}: BPE merge indices are not consecutive. Please check that the tokenizer is not corrupted!r0   r   )ÚosÚpathÚisdirr‡   ÚerrorÚformatrP   ÚVOCAB_FILES_NAMESrŠ   Úwriter‹   Údumpsr�   Úsortedr”   rŽ   Úwarning)
rC   rÞ   rß   r   Ú
merge_fileÚfrÁ   ÚwriterrÑ   Útoken_indexs
             r$   Úsave_vocabularyzCLIPTokenizer.save_vocabularyé  sš  € Ü�w‰w�}‰}˜^Ô,Ü�L‰LÐE×LÑLÈ^Ó\Ô]ØÜ—W‘W—\‘\Ø±o˜_¨sÒ2È2ÔQbÐcoÑQpÑpó
ˆ
ô —W‘W—\‘\Ø±o˜_¨sÒ2È2ÔQbÐcpÑQqÑqó
ˆ
ô �*˜c¨GÔ4ð 	c¸Ø�G‰G”D—J‘J˜tŸ|™|°AÀÐTYÔZÐ]aÑaÔb÷	cð ˆÜ�*˜c¨GÔ4ð 
	¸Ø�L‰LÐ*Ô+Ü+1°$·.±.×2FÑ2FÓ2HÑN^Ô+_ò Ñ'�
˜KØ˜KÒ'Ü—N‘NðMßMSÉVÐT^ÓM_ôð (�EØ—‘˜SŸX™X jÓ1°DÑ8Ô9Ø˜‘
‘ñ÷
	ð ˜:Ð%Ð%÷!	cð 	cú÷
	ð ˜:Ð%Ð%ús   Â56F#ÄBF/Æ#F,Æ/F;)rÚ   r|   r{   r|   r|   r=   )NF)rl   rm   rn   ro   rí   Úvocab_files_namesÚmodel_input_namesrD   Úpropertyr¤   r§   r   Úintr   r¯   Úboolr²   r´   rÈ   rÒ   rÔ   rÖ   rÝ   rƒ   r   rö   Ú__classcell__)r¡   s   @r$   rq   rq   þ   s@  ø„ ñð2 *ÐØ$Ð&6Ð7Ðð Ø!Ø#Ø!Ø!õ/
ðb ñ!ó ð!ò?ð JNñYØ ™9ðYØ3;¸DÀ¹IÑ3FðYà	ˆc‰óYð8 sxñ[Ø ™9ð[Ø3;¸DÀ¹IÑ3Fð[Økoð[à	ˆc‰õ[ð: JNñdØ ™9ðdØ3;¸DÀ¹IÑ3Fðdà	ˆc‰ódò.(òTòIò'òñ&¨cð &ÀHÈSÁMð &Ð]bÐcfÑ]g÷ &r.   rq   )ro   r‹   rè   rJ   Ú	functoolsr   Útypingr   r   r   Úregexr1   Útokenization_utilsr   r	   r
   r   r   Úutilsr   Ú
get_loggerrl   r‡   rí   r%   r-   r5   r9   r;   rq   Ú__all__rj   r.   r$   ú<module>r     s˜   ðñ %ã Û 	Û Ý ß (Ñ (ã ç oÕ oÝ ð 
ˆ×	Ñ	˜HÓ	%€ð ØñÐ ñ ƒñó ðò0òò÷^ñ ^ôBF&Ð'ô F&ðR Ð
�r.   