





from typing import List, Optional, Tuple

from tokenizers import pre_tokenizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_clip import CLIPTokenizer


a__			:    str			      =		logging.get_logger(__name__)

a__			:    List[str]			      =		{"""vocab_file""": """vocab.json""", """merges_file""": """merges.txt""", """tokenizer_file""": """tokenizer.json"""}

a__			:    str			      =		{
    """vocab_file""": {
        """openai/clip-vit-base-patch32""": """https://huggingface.co/openai/clip-vit-base-patch32/resolve/main/vocab.json""",
    },
    """merges_file""": {
        """openai/clip-vit-base-patch32""": """https://huggingface.co/openai/clip-vit-base-patch32/resolve/main/merges.txt""",
    },
    """tokenizer_file""": {
        """openai/clip-vit-base-patch32""": (
            """https://huggingface.co/openai/clip-vit-base-patch32/resolve/main/tokenizer.json"""
        ),
    },
}

a__			:    Dict			      =		{
    """openai/clip-vit-base-patch32""": 77,
}





class UpperCAmelCase_							(   a_   ):
  __lowerCAmelCase      :	List[Any]  	=      VOCAB_FILES_NAMES
  __lowerCAmelCase      :	str  	=      PRETRAINED_VOCAB_FILES_MAP
  __lowerCAmelCase      :	List[Any]  	=      PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
  __lowerCAmelCase      :	Tuple  	=      ['input_ids', 'attention_mask']
  __lowerCAmelCase      :	List[str]  	=      CLIPTokenizer


  def __init__(       self   ,__snake_case=None   ,__snake_case=None   ,__snake_case=None   ,__snake_case="<|endoftext|>"   ,__snake_case="<|startoftext|>"   ,__snake_case="<|endoftext|>"   ,__snake_case="<|endoftext|>"   ,**__snake_case   ,):



       """simple docstring"""





       super().__init__(
           _snake_case   ,_snake_case   ,tokenizer_file=_snake_case   ,unk_token=_snake_case   ,bos_token=_snake_case   ,eos_token=_snake_case   ,pad_token=_snake_case   ,**_snake_case   ,)

       if not isinstance(self.backend_tokenizer.pre_tokenizer   ,pre_tokenizers.Sequence   ):
            raise ValueError(
                '''The `backend_tokenizer` provided does not match the expected format. The CLIP tokenizer has been'''
                ''' heavily modified from transformers version 4.17.0. You need to convert the tokenizer you are using'''
                ''' to be compatible with this version.The easiest way to do so is'''
                ''' `CLIPTokenizerFast.from_pretrained("path_to_local_folder_or_hub_repo, from_slow=True)`. If you want'''
                ''' to use your existing tokenizer, you will have to revert to a version prior to 4.17.0 of'''
                ''' transformers.'''   )

       self._wrap_decode_method_backend_tokenizer()


  def 	__UpperCAmelCase    (       self   ):



       """simple docstring"""





       A_					      =					self.backend_tokenizer.decode

       def new_decode_method(*__snake_case   ,**__snake_case   ):
            A_					      =					orig_decode_method(*_snake_case   ,**_snake_case   )
            A_					      =					text.replace(self.backend_tokenizer.model.end_of_word_suffix   ,''' '''   ).strip()
            return text

       A_					      =					new_decode_method


  def 	__UpperCAmelCase    (       self   ,__snake_case   ,__snake_case = None   ):



       """simple docstring"""





       A_					      =					[self.bos_token_id]
       A_					      =					[self.eos_token_id]

       if token_ids_a is None:
            return bos_token + token_ids_a + eos_token
       return bos_token + token_ids_a + eos_token + eos_token + token_ids_a + eos_token


  def 	__UpperCAmelCase    (       self   ,__snake_case   ,__snake_case = None   ):



       """simple docstring"""





       A_					      =					[self.bos_token_id]
       A_					      =					[self.eos_token_id]

       if token_ids_a is None:
            return len(bos_token + token_ids_a + eos_token   ) * [0]
       return len(bos_token + token_ids_a + eos_token + eos_token + token_ids_a + eos_token   ) * [0]




  def 	__UpperCAmelCase    (       self   ,__snake_case   ,__snake_case = None   ):



       """simple docstring"""





       A_					      =					self._tokenizer.model.save(_snake_case   ,name=_snake_case   )
       return tuple(_snake_case   )










from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier

# Load iris file
a__			:    List[str]			      =		load_iris()
iris.keys()


print(f'''Target names: \n {iris.target_names} ''')
print(f'''\n Features: \n {iris.feature_names}''')

# Train set e Test set
a__      ,							a__      ,							a__      ,							a__			:    Any			      =		train_test_split(
    iris['data'], iris['target'], random_state=4
)

# KNN

a__			:    List[Any]			      =		KNeighborsClassifier(n_neighbors=1)
knn.fit(X_train, y_train)

# new array to test
a__			:    Optional[Any]			      =		[[1, 2, 1, 4], [2, 3, 4, 5]]

a__			:    Union[str, Any]			      =		knn.predict(X_new)

print(
    f'''\nNew array: \n {X_new}\n\nTarget Names Prediction: \n'''
    f''' {iris['target_names'][prediction]}'''
)



