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


A							     = logging.get_logger(__name__)

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

A							     = {
    "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							     = {
    "openai/clip-vit-base-patch32": 7_7,
}



class 			lowerCAmelCase__ (							UpperCamelCase							):



  '''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	:			Dict						,			lowerCAmelCase_	:			Any=None						,			lowerCAmelCase_	:			List[Any]=None						,			lowerCAmelCase_	:			Dict=None						,			lowerCAmelCase_	:			Union[str, Any]="<|endoftext|>"						,			lowerCAmelCase_	:			Union[str, Any]="<|startoftext|>"						,			lowerCAmelCase_	:			Optional[int]="<|endoftext|>"						,			lowerCAmelCase_	:			int="<|endoftext|>"						,			**lowerCAmelCase_	:			Union[str, Any]						,			) ->							Tuple:
        super().__init__(
            lowerCAmelCase_						,			lowerCAmelCase_						,			tokenizer_file=lowerCAmelCase_						,			unk_token=lowerCAmelCase_						,			bos_token=lowerCAmelCase_						,			eos_token=lowerCAmelCase_						,			pad_token=lowerCAmelCase_						,			**lowerCAmelCase_						,			)

        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 		_lowerCamelCase						(self	:			Optional[int]     ) ->							Optional[Any]:
        snake_case_    							=				self.backend_tokenizer.decode

        def new_decode_method(*lowerCAmelCase_	:			Any						,			**lowerCAmelCase_	:			Any     ):
              snake_case_    							=				orig_decode_method(*lowerCAmelCase_						,			**lowerCAmelCase_     )
              snake_case_    							=				text.replace(self.backend_tokenizer.model.end_of_word_suffix						,			" "     ).strip()
              return text

        snake_case_    							=				new_decode_method

  def 		_lowerCamelCase						(self	:			List[Any]						,			lowerCAmelCase_	:			List[int]						,			lowerCAmelCase_	:			Optional[List[int]] = None     ) ->							List[int]:
        snake_case_    							=				[self.bos_token_id]
        snake_case_    							=				[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 		_lowerCamelCase						(self	:			str						,			lowerCAmelCase_	:			List[int]						,			lowerCAmelCase_	:			Optional[List[int]] = None     ) ->							List[int]:
        snake_case_    							=				[self.bos_token_id]
        snake_case_    							=				[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 		_lowerCamelCase						(self	:			Optional[int]						,			lowerCAmelCase_	:			str						,			lowerCAmelCase_	:			Optional[str] = None     ) ->							Tuple[str]:
        snake_case_    							=				self._tokenizer.model.save(lowerCAmelCase_						,			name=lowerCAmelCase_     )
        return tuple(lowerCAmelCase_     )








import numpy as np






def 				_lowerCAmelCase			(	_a :       Optional[int]       , _a :       str      )						->      Union[str, Any]:
     lowerCAmelCase_       :							int			 =		np.array(_a      )
     lowerCAmelCase_       :							str			 =		np.array(_a      )

     lowerCAmelCase_       :							Optional[Any]			 =		abs(predict - actual      )
     lowerCAmelCase_       :							Dict			 =		difference.mean()

     return score






def 				_lowerCAmelCase			(	_a :       Union[str, Any]       , _a :       int      )						->      Tuple:
     lowerCAmelCase_       :							int			 =		np.array(_a      )
     lowerCAmelCase_       :							int			 =		np.array(_a      )

     lowerCAmelCase_       :							Union[str, Any]			 =		predict - actual
     lowerCAmelCase_       :							Tuple			 =		np.square(_a      )

     lowerCAmelCase_       :							Tuple			 =		square_diff.mean()
     return score






def 				_lowerCAmelCase			(	_a :       Optional[Any]       , _a :       Tuple      )						->      Optional[int]:
     lowerCAmelCase_       :							Optional[Any]			 =		np.array(_a      )
     lowerCAmelCase_       :							Optional[Any]			 =		np.array(_a      )

     lowerCAmelCase_       :							int			 =		predict - actual
     lowerCAmelCase_       :							Any			 =		np.square(_a      )
     lowerCAmelCase_       :							Union[str, Any]			 =		square_diff.mean()
     lowerCAmelCase_       :							Optional[Any]			 =		np.sqrt(_a      )
     return score






def 				_lowerCAmelCase			(	_a :       Optional[Any]       , _a :       Optional[Any]      )						->      List[Any]:
     lowerCAmelCase_       :							Dict			 =		np.array(_a      )
     lowerCAmelCase_       :							List[Any]			 =		np.array(_a      )

     lowerCAmelCase_       :							str			 =		np.log(predict + 1      )
     lowerCAmelCase_       :							Any			 =		np.log(actual + 1      )

     lowerCAmelCase_       :							List[str]			 =		log_predict - log_actual
     lowerCAmelCase_       :							Dict			 =		np.square(_a      )
     lowerCAmelCase_       :							Optional[Any]			 =		square_diff.mean()

     lowerCAmelCase_       :							int			 =		np.sqrt(_a      )

     return score






def 				_lowerCAmelCase			(	_a :       str       , _a :       List[Any]      )						->      int:
     lowerCAmelCase_       :							Any			 =		np.array(_a      )
     lowerCAmelCase_       :							Optional[int]			 =		np.array(_a      )

     lowerCAmelCase_       :							Optional[int]			 =		predict - actual
     lowerCAmelCase_       :							str			 =		np.sum(_a      ) / len(_a      )
     lowerCAmelCase_       :							List[str]			 =		np.sum(_a      ) / len(_a      )
     # print(numerator, denumerator)
     lowerCAmelCase_       :							int			 =		float(_a      ) / denumerator * 1_00

     return score







def 				_lowerCAmelCase			(	_a :       Any       , _a :       Union[str, Any]      )						->      str:
     return np.mean(np.array(_a      ) == np.array(_a      )      )
