






"""simple docstring"""





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


UpperCamelCase					=     logging.get_logger(__name__)

UpperCamelCase					=     {"""vocab_file""": """vocab.json""", """merges_file""": """merges.txt""", """tokenizer_file""": """tokenizer.json"""}

UpperCamelCase					=     {
    """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"""
        ),
    },
}

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







class 						_a  (		lowercase_       ):





   '''simple docstring'''






   UpperCamelCase__     	=							VOCAB_FILES_NAMES
   UpperCamelCase__     	=							PRETRAINED_VOCAB_FILES_MAP
   UpperCamelCase__     	=							PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
   UpperCamelCase__     	=							["""input_ids""", """attention_mask"""]
   UpperCamelCase__     	=							CLIPTokenizer





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




          '''simple docstring'''




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

          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 __lowercase							(       self)			->   Tuple:




          '''simple docstring'''




          lowercase__:							Union[str, Any]         =     self.backend_tokenizer.decode

          def new_decode_method(*UpperCAmelCase_					, **UpperCAmelCase_):
                 lowercase__:							Union[str, Any]         =     orig_decode_method(*UpperCAmelCase_					, **UpperCAmelCase_)
                 lowercase__:							Optional[Any]         =     text.replace(self.backend_tokenizer.model.end_of_word_suffix					, " ").strip()
                 return text

          lowercase__:							List[str]         =     new_decode_method





   def __lowercase							(       self					, UpperCAmelCase_					, UpperCAmelCase_ = None)			->   List[int]:




          '''simple docstring'''




          lowercase__:							List[str]         =     [self.bos_token_id]
          lowercase__:							Dict         =     [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 __lowercase							(       self					, UpperCAmelCase_					, UpperCAmelCase_ = None)			->   List[int]:




          '''simple docstring'''




          lowercase__:							str         =     [self.bos_token_id]
          lowercase__:							Any         =     [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 __lowercase							(       self					, UpperCAmelCase_					, UpperCAmelCase_ = None)			->   Tuple[str]:




          '''simple docstring'''




          lowercase__:							str         =     self._tokenizer.model.save(UpperCAmelCase_					, name=UpperCAmelCase_)
          return tuple(UpperCAmelCase_)











UpperCAmelCase__			:   Optional[int]      			=    [0.4_85, 0.4_56, 0.4_06]
UpperCAmelCase__			:   Union[str, Any]      			=    [0.2_29, 0.2_24, 0.2_25]
UpperCAmelCase__			:   Union[str, Any]      			=    [0.5, 0.5, 0.5]
UpperCAmelCase__			:   Optional[Any]      			=    [0.5, 0.5, 0.5]
UpperCAmelCase__			:   str      			=    [0.48_14_54_66, 0.4_57_82_75, 0.40_82_10_73]
UpperCAmelCase__			:   Dict      			=    [0.26_86_29_54, 0.26_13_02_58, 0.27_57_77_11]
