






'''simple docstring'''
from __future__ import annotations

import collections
import tempfile
import unittest

import numpy as np

from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import is_tf_available, is_vision_available

from ...test_modeling_tf_common import floats_tensor, ids_tensor, random_attention_mask
from ..bert.test_modeling_tf_bert import TFBertModelTester
from ..clip.test_modeling_tf_clip import TFCLIPVisionModelTester
from ..deit.test_modeling_tf_deit import TFDeiTModelTester
from ..roberta.test_modeling_tf_roberta import TFRobertaModelTester
from ..vit.test_modeling_tf_vit import TFViTModelTester


if is_tf_available():
  from transformers import (
      TFBertModel,
      TFCLIPVisionModel,
      TFDeiTModel,
      TFRobertaModel,
      TFVisionTextDualEncoderModel,
      TFViTModel,
      VisionTextDualEncoderConfig,
  )

if is_vision_available():
  from PIL import Image

  from transformers import VisionTextDualEncoderProcessor





def  _a(  UpperCamelCase__				:						List[str]							):




      '''simple docstring'''






      if isinstance(UpperCamelCase__,	collections.abc.Iterable							):
            return x
      return (x, x)






@require_tf
class      __SCREAMING_SNAKE_CASE      :




 def      __magic_name__	(      self	:							Tuple					,      __lowercase	:							Tuple					,      __lowercase	:							Tuple      )	->						Optional[Any]:
       pass




 def      __magic_name__	(      self	:							List[Any]      )	->						Any:
       pass




 def      __magic_name__	(      self	:							Optional[Any]      )	->						Union[str, Any]:
       pass




 def      __magic_name__	(      self	:							int					,      __lowercase	:							List[str]					,      __lowercase	:							Optional[int]					,      __lowercase	:							Any					,      __lowercase	:							Dict					,      __lowercase	:							Optional[int]=None					,      **__lowercase	:							List[str]      )	->						int:
       SCREAMING_SNAKE_CASE__     :				Tuple									=VisionTextDualEncoderConfig.from_vision_text_configs(__lowercase					,      __lowercase      )

       SCREAMING_SNAKE_CASE__     :				List[Any]									=TFVisionTextDualEncoderModel(__lowercase      )

       SCREAMING_SNAKE_CASE__     :				Optional[int]									=model(input_ids=__lowercase					,      pixel_values=__lowercase					,      attention_mask=__lowercase      )

       self.assertEqual(output['''text_embeds'''].shape					,      (input_ids.shape[0], config.projection_dim)      )
       self.assertEqual(output['''image_embeds'''].shape					,      (pixel_values.shape[0], config.projection_dim)      )




 def      __magic_name__	(      self	:							int					,      __lowercase	:							str					,      __lowercase	:							int					,      __lowercase	:							int					,      __lowercase	:							int					,      __lowercase	:							str=None					,      **__lowercase	:							Optional[int]      )	->						Dict:
       SCREAMING_SNAKE_CASE__		,	SCREAMING_SNAKE_CASE__     :				Tuple									=self.get_vision_text_model(__lowercase					,      __lowercase      )
       SCREAMING_SNAKE_CASE__     :				Optional[int]									=TFVisionTextDualEncoderModel(vision_model=__lowercase					,      text_model=__lowercase      )

       SCREAMING_SNAKE_CASE__     :				Dict									=model(input_ids=__lowercase					,      pixel_values=__lowercase					,      attention_mask=__lowercase      )

       self.assertEqual(output['''text_embeds'''].shape					,      (input_ids.shape[0], model.config.projection_dim)      )
       self.assertEqual(output['''image_embeds'''].shape					,      (pixel_values.shape[0], model.config.projection_dim)      )




 def      __magic_name__	(      self	:							List[Any]					,      __lowercase	:							int					,      __lowercase	:							Any					,      __lowercase	:							int					,      __lowercase	:							Tuple					,      __lowercase	:							Union[str, Any]=None					,      **__lowercase	:							Optional[Any]      )	->						Optional[int]:
       SCREAMING_SNAKE_CASE__		,	SCREAMING_SNAKE_CASE__     :				int									=self.get_vision_text_model(__lowercase					,      __lowercase      )
       SCREAMING_SNAKE_CASE__     :				List[str]									={'''vision_model''': vision_model, '''text_model''': text_model}
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=TFVisionTextDualEncoderModel.from_vision_text_pretrained(**__lowercase      )

       SCREAMING_SNAKE_CASE__     :				List[Any]									=model(input_ids=__lowercase					,      pixel_values=__lowercase					,      attention_mask=__lowercase      )

       self.assertEqual(output['''text_embeds'''].shape					,      (input_ids.shape[0], model.config.projection_dim)      )
       self.assertEqual(output['''image_embeds'''].shape					,      (pixel_values.shape[0], model.config.projection_dim)      )




 def      __magic_name__	(      self	:							str					,      __lowercase	:							Optional[int]					,      __lowercase	:							Union[str, Any]					,      __lowercase	:							Any					,      __lowercase	:							Any					,      __lowercase	:							str=None					,      **__lowercase	:							str      )	->						str:
       SCREAMING_SNAKE_CASE__		,	SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=self.get_vision_text_model(__lowercase					,      __lowercase      )
       SCREAMING_SNAKE_CASE__     :				Dict									=TFVisionTextDualEncoderModel(vision_model=__lowercase					,      text_model=__lowercase      )

       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=model(input_ids=__lowercase					,      pixel_values=__lowercase					,      attention_mask=__lowercase      )
       SCREAMING_SNAKE_CASE__     :				Any									=output[0].numpy()

       with tempfile.TemporaryDirectory() as tmpdirname:
             model.save_pretrained(__lowercase      )
             SCREAMING_SNAKE_CASE__     :				str									=TFVisionTextDualEncoderModel.from_pretrained(__lowercase      )

             SCREAMING_SNAKE_CASE__     :				Optional[int]									=model(input_ids=__lowercase					,      pixel_values=__lowercase					,      attention_mask=__lowercase      )
             SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=after_output[0].numpy()
             SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=np.amax(np.abs(out_a - out_a      )      )
             self.assertLessEqual(__lowercase					,      1e-5      )




 def      __magic_name__	(      self	:							List[Any]					,      __lowercase	:							Optional[Any]					,      __lowercase	:							Optional[Any]					,      __lowercase	:							List[Any]					,      __lowercase	:							List[Any]					,      __lowercase	:							List[Any]=None					,      **__lowercase	:							Tuple      )	->						int:
       SCREAMING_SNAKE_CASE__		,	SCREAMING_SNAKE_CASE__     :				List[Any]									=self.get_vision_text_model(__lowercase					,      __lowercase      )
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=TFVisionTextDualEncoderModel(vision_model=__lowercase					,      text_model=__lowercase      )

       SCREAMING_SNAKE_CASE__     :				Optional[int]									=model(
           input_ids=__lowercase					,      pixel_values=__lowercase					,      attention_mask=__lowercase					,      output_attentions=__lowercase      )

       SCREAMING_SNAKE_CASE__     :				Dict									=output.vision_model_output.attentions
       self.assertEqual(len(__lowercase      )					,      vision_config.num_hidden_layers      )

       # in ViT, the seq_len equals the number of patches + 1 (we add 1 for the [CLS] token)
       SCREAMING_SNAKE_CASE__     :				int									=to_atuple(vision_model.config.image_size      )
       SCREAMING_SNAKE_CASE__     :				Dict									=to_atuple(vision_model.config.patch_size      )
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=num_patches + 1
       self.assertEqual(vision_attentions[0].shape[-3:]					,      (vision_config.num_attention_heads, seq_len, seq_len)      )

       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=output.text_model_output.attentions
       self.assertEqual(len(__lowercase      )					,      text_config.num_hidden_layers      )

       self.assertEqual(
           text_attentions[0].shape[-3:]					,      (text_config.num_attention_heads, input_ids.shape[-1], input_ids.shape[-1])					,      )




 def      __magic_name__	(      self	:							int					,      __lowercase	:							np.ndarray					,      __lowercase	:							np.ndarray					,      __lowercase	:							float      )	->						List[Any]:
       SCREAMING_SNAKE_CASE__     :				Optional[int]									=np.abs((a - b)      ).max()
       self.assertLessEqual(__lowercase					,      __lowercase					,      F"Difference between torch and flax is {diff} (>= {tol})."      )




 def      __magic_name__	(      self	:							str      )	->						Optional[Any]:
       SCREAMING_SNAKE_CASE__     :				Tuple									=self.prepare_config_and_inputs()
       self.check_vision_text_dual_encoder_model(**__lowercase      )




 def      __magic_name__	(      self	:							Any      )	->						str:
       SCREAMING_SNAKE_CASE__     :				Tuple									=self.prepare_config_and_inputs()
       self.check_model_from_pretrained_configs(**__lowercase      )




 def      __magic_name__	(      self	:							List[str]      )	->						Optional[Any]:
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=self.prepare_config_and_inputs()
       self.check_vision_text_dual_encoder_from_pretrained(**__lowercase      )




 def      __magic_name__	(      self	:							List[str]      )	->						List[Any]:
       SCREAMING_SNAKE_CASE__     :				List[str]									=self.prepare_config_and_inputs()
       self.check_save_load(**__lowercase      )




 def      __magic_name__	(      self	:							int      )	->						Optional[int]:
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=self.prepare_config_and_inputs()
       self.check_vision_text_output_attention(**__lowercase      )




 @slow
 def      __magic_name__	(      self	:							Optional[int]      )	->						Any:
       SCREAMING_SNAKE_CASE__		,	SCREAMING_SNAKE_CASE__     :				Optional[Any]									=self.get_pretrained_model_and_inputs()

       SCREAMING_SNAKE_CASE__     :				List[Any]									=model_a(**__lowercase      )
       SCREAMING_SNAKE_CASE__     :				List[Any]									=outputs[0].numpy()

       with tempfile.TemporaryDirectory() as tmp_dirname:
             model_a.save_pretrained(__lowercase      )
             SCREAMING_SNAKE_CASE__     :				str									=TFVisionTextDualEncoderModel.from_pretrained(__lowercase      )

             SCREAMING_SNAKE_CASE__     :				int									=model_a(**__lowercase      )
             SCREAMING_SNAKE_CASE__     :				str									=after_outputs[0].numpy()
             SCREAMING_SNAKE_CASE__     :				Optional[int]									=np.amax(np.abs(out_a - out_a      )      )
             self.assertLessEqual(__lowercase					,      1e-5      )






@require_tf
class      __SCREAMING_SNAKE_CASE      (			lowerCamelCase	,				unittest.TestCase				):




 def      __magic_name__	(      self	:							Tuple      )	->						List[Any]:
       SCREAMING_SNAKE_CASE__     :				Tuple									=TFVisionTextDualEncoderModel.from_vision_text_pretrained(
           '''hf-internal-testing/tiny-random-vit'''					,      '''hf-internal-testing/tiny-random-bert'''      )
       SCREAMING_SNAKE_CASE__     :				List[str]									=13
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=floats_tensor(
           [
               batch_size,
               model.vision_model.config.num_channels,
               model.vision_model.config.image_size,
               model.vision_model.config.image_size,
           ]      )
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=ids_tensor([batch_size, 4]					,      model.text_model.config.vocab_size      )
       SCREAMING_SNAKE_CASE__     :				List[Any]									=random_attention_mask([batch_size, 4]      )
       SCREAMING_SNAKE_CASE__     :				Dict									={'''pixel_values''': pixel_values, '''input_ids''': input_ids, '''attention_mask''': attention_mask}

       return model, inputs




 def      __magic_name__	(      self	:							Dict					,      __lowercase	:							str					,      __lowercase	:							List[str]      )	->						str:
       SCREAMING_SNAKE_CASE__     :				Optional[int]									=TFViTModel(__lowercase					,      name='''vision_model'''      )
       SCREAMING_SNAKE_CASE__     :				Dict									=TFBertModel(__lowercase					,      name='''text_model'''      )
       return vision_model, text_model




 def      __magic_name__	(      self	:							Tuple      )	->						Dict:
       SCREAMING_SNAKE_CASE__     :				int									=TFViTModelTester(self      )
       SCREAMING_SNAKE_CASE__     :				Any									=TFBertModelTester(self      )
       SCREAMING_SNAKE_CASE__     :				Optional[int]									=vit_model_tester.prepare_config_and_inputs()
       SCREAMING_SNAKE_CASE__     :				Any									=bert_model_tester.prepare_config_and_inputs()

       SCREAMING_SNAKE_CASE__		,	SCREAMING_SNAKE_CASE__		,	SCREAMING_SNAKE_CASE__     :				List[Any]									=vision_config_and_inputs

       (
           (
           SCREAMING_SNAKE_CASE__
       )		,	(
           SCREAMING_SNAKE_CASE__
       )		,	(
           SCREAMING_SNAKE_CASE__
       )		,	(
           SCREAMING_SNAKE_CASE__
       )		,	(
           SCREAMING_SNAKE_CASE__
       )		,	(
           SCREAMING_SNAKE_CASE__
       )		,	(
           SCREAMING_SNAKE_CASE__
       )		,	
       )     :				Tuple									=text_config_and_inputs

       return {
           "text_config": text_config,
           "vision_config": vision_config,
           "pixel_values": pixel_values,
           "attention_mask": input_mask,
           "input_ids": input_ids,
           "text_token_type_ids": token_type_ids,
           "text_sequence_labels": sequence_labels,
           "text_token_labels": token_labels,
           "text_choice_labels": choice_labels,
       }






@require_tf
class      __SCREAMING_SNAKE_CASE      (			lowerCamelCase	,				unittest.TestCase				):




 def      __magic_name__	(      self	:							List[str]      )	->						int:
       # DeiT repo doesn't have TF weights, but we don't actually use the weights at all so let's
       # just reinitialize it.
       SCREAMING_SNAKE_CASE__     :				List[str]									=TFVisionTextDualEncoderModel.from_vision_text_pretrained(
           '''Rocketknight1/tiny-random-deit-tf'''					,      '''hf-internal-testing/tiny-random-roberta'''      )
       SCREAMING_SNAKE_CASE__     :				Any									=13
       SCREAMING_SNAKE_CASE__     :				Tuple									=floats_tensor(
           [
               batch_size,
               model.vision_model.config.num_channels,
               model.vision_model.config.image_size,
               model.vision_model.config.image_size,
           ]      )
       SCREAMING_SNAKE_CASE__     :				List[Any]									=ids_tensor([batch_size, 4]					,      model.text_model.config.vocab_size      )
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=random_attention_mask([batch_size, 4]      )
       SCREAMING_SNAKE_CASE__     :				Optional[int]									={'''pixel_values''': pixel_values, '''input_ids''': input_ids, '''attention_mask''': attention_mask}

       return model, inputs




 def      __magic_name__	(      self	:							List[str]					,      __lowercase	:							Optional[int]					,      __lowercase	:							Optional[int]					,      __lowercase	:							Tuple					,      __lowercase	:							Optional[Any]					,      __lowercase	:							str=None					,      **__lowercase	:							Tuple      )	->						Tuple:
       SCREAMING_SNAKE_CASE__		,	SCREAMING_SNAKE_CASE__     :				Optional[int]									=self.get_vision_text_model(__lowercase					,      __lowercase      )
       SCREAMING_SNAKE_CASE__     :				Optional[int]									=TFVisionTextDualEncoderModel(vision_model=__lowercase					,      text_model=__lowercase      )

       SCREAMING_SNAKE_CASE__     :				Dict									=model(
           input_ids=__lowercase					,      pixel_values=__lowercase					,      attention_mask=__lowercase					,      output_attentions=__lowercase      )

       SCREAMING_SNAKE_CASE__     :				List[str]									=output.vision_model_output.attentions
       self.assertEqual(len(__lowercase      )					,      vision_config.num_hidden_layers      )

       # in DEiT, the seq_len equals the number of patches + 2 (we add 2 for the [CLS] and distillation tokens)
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=to_atuple(vision_model.config.image_size      )
       SCREAMING_SNAKE_CASE__     :				int									=to_atuple(vision_model.config.patch_size      )
       SCREAMING_SNAKE_CASE__     :				str									=(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
       SCREAMING_SNAKE_CASE__     :				Tuple									=num_patches + 2
       self.assertEqual(vision_attentions[0].shape[-3:]					,      (vision_config.num_attention_heads, seq_len, seq_len)      )

       SCREAMING_SNAKE_CASE__     :				Any									=output.text_model_output.attentions
       self.assertEqual(len(__lowercase      )					,      text_config.num_hidden_layers      )

       self.assertEqual(
           text_attentions[0].shape[-3:]					,      (text_config.num_attention_heads, input_ids.shape[-1], input_ids.shape[-1])					,      )




 def      __magic_name__	(      self	:							str					,      __lowercase	:							List[str]					,      __lowercase	:							List[Any]      )	->						Tuple:
       SCREAMING_SNAKE_CASE__     :				Dict									=TFDeiTModel(__lowercase					,      name='''vision_model'''      )
       SCREAMING_SNAKE_CASE__     :				List[Any]									=TFRobertaModel(__lowercase					,      name='''text_model'''      )
       return vision_model, text_model




 def      __magic_name__	(      self	:							Dict      )	->						Any:
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=TFDeiTModelTester(self      )
       SCREAMING_SNAKE_CASE__     :				str									=TFRobertaModelTester(self      )
       SCREAMING_SNAKE_CASE__     :				str									=vit_model_tester.prepare_config_and_inputs()
       SCREAMING_SNAKE_CASE__     :				Any									=bert_model_tester.prepare_config_and_inputs()

       SCREAMING_SNAKE_CASE__		,	SCREAMING_SNAKE_CASE__		,	SCREAMING_SNAKE_CASE__     :				int									=vision_config_and_inputs

       (
           (
           SCREAMING_SNAKE_CASE__
       )		,	(
           SCREAMING_SNAKE_CASE__
       )		,	(
           SCREAMING_SNAKE_CASE__
       )		,	(
           SCREAMING_SNAKE_CASE__
       )		,	(
           SCREAMING_SNAKE_CASE__
       )		,	(
           SCREAMING_SNAKE_CASE__
       )		,	(
           SCREAMING_SNAKE_CASE__
       )		,	
       )     :				Dict									=text_config_and_inputs

       return {
           "text_config": text_config,
           "vision_config": vision_config,
           "pixel_values": pixel_values,
           "attention_mask": input_mask,
           "input_ids": input_ids,
           "text_token_type_ids": token_type_ids,
           "text_sequence_labels": sequence_labels,
           "text_token_labels": token_labels,
           "text_choice_labels": choice_labels,
       }






@require_tf
class      __SCREAMING_SNAKE_CASE      (			lowerCamelCase	,				unittest.TestCase				):




 def      __magic_name__	(      self	:							str      )	->						List[Any]:
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=TFVisionTextDualEncoderModel.from_vision_text_pretrained(
           '''Rocketknight1/tiny-random-clip-tf'''					,      '''hf-internal-testing/tiny-random-bert'''      )
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=13
       SCREAMING_SNAKE_CASE__     :				Any									=floats_tensor(
           [
               batch_size,
               model.vision_model.config.num_channels,
               model.vision_model.config.image_size,
               model.vision_model.config.image_size,
           ]      )
       SCREAMING_SNAKE_CASE__     :				Dict									=ids_tensor([batch_size, 4]					,      model.text_model.config.vocab_size      )
       SCREAMING_SNAKE_CASE__     :				Dict									=random_attention_mask([batch_size, 4]      )
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									={'''pixel_values''': pixel_values, '''input_ids''': input_ids, '''attention_mask''': attention_mask}

       return model, inputs




 def      __magic_name__	(      self	:							int					,      __lowercase	:							Optional[int]					,      __lowercase	:							str      )	->						Union[str, Any]:
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=TFCLIPVisionModel(__lowercase					,      name='''vision_model'''      )
       SCREAMING_SNAKE_CASE__     :				Any									=TFBertModel(__lowercase					,      name='''text_model'''      )
       return vision_model, text_model




 def      __magic_name__	(      self	:							Union[str, Any]      )	->						Tuple:
       SCREAMING_SNAKE_CASE__     :				Optional[int]									=TFCLIPVisionModelTester(self      )
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=TFBertModelTester(self      )
       SCREAMING_SNAKE_CASE__     :				List[str]									=clip_model_tester.prepare_config_and_inputs()
       SCREAMING_SNAKE_CASE__     :				List[str]									=bert_model_tester.prepare_config_and_inputs()

       SCREAMING_SNAKE_CASE__		,	SCREAMING_SNAKE_CASE__     :				Dict									=vision_config_and_inputs

       (
           (
           SCREAMING_SNAKE_CASE__
       )		,	(
           SCREAMING_SNAKE_CASE__
       )		,	(
           SCREAMING_SNAKE_CASE__
       )		,	(
           SCREAMING_SNAKE_CASE__
       )		,	(
           SCREAMING_SNAKE_CASE__
       )		,	(
           SCREAMING_SNAKE_CASE__
       )		,	(
           SCREAMING_SNAKE_CASE__
       )		,	
       )     :				Any									=text_config_and_inputs

       return {
           "text_config": text_config,
           "vision_config": vision_config,
           "pixel_values": pixel_values,
           "attention_mask": input_mask,
           "input_ids": input_ids,
           "text_token_type_ids": token_type_ids,
           "text_sequence_labels": sequence_labels,
           "text_token_labels": token_labels,
           "text_choice_labels": choice_labels,
       }






@require_vision
@require_tf
class      __SCREAMING_SNAKE_CASE      (			unittest.TestCase				):




 @slow
 def      __magic_name__	(      self	:							Any      )	->						Dict:
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=TFVisionTextDualEncoderModel.from_pretrained(
           '''clip-italian/clip-italian'''					,      logit_scale_init_value=1.0					,      from_pt=__lowercase      )
       SCREAMING_SNAKE_CASE__     :				str									=VisionTextDualEncoderProcessor.from_pretrained('''clip-italian/clip-italian'''      )

       SCREAMING_SNAKE_CASE__     :				Dict									=Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''      )
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=processor(
           text=['''una foto di un gatto''', '''una foto di un cane''']					,      images=__lowercase					,      padding=__lowercase					,      return_tensors='''np'''      )

       SCREAMING_SNAKE_CASE__     :				Dict									=model(**__lowercase      )

       # verify the logits
       self.assertEqual(outputs.logits_per_image.shape					,      (inputs.pixel_values.shape[0], inputs.input_ids.shape[0])      )
       self.assertEqual(
           outputs.logits_per_text.shape					,      (inputs.input_ids.shape[0], inputs.pixel_values.shape[0])					,      )

       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=np.array([[1.2284727, 0.3104122]]      )

       self.assertTrue(np.allclose(outputs.logits_per_image.numpy()					,      __lowercase					,      atol=1e-3      )      )







'''simple docstring'''
import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_bert import BertTokenizer


a_					= logging.get_logger(__name__)

a_					= {'vocab_file': 'vocab.txt', 'tokenizer_file': 'tokenizer.json'}

a_					= {
    'vocab_file': {
        'bert-base-uncased': 'https://huggingface.co/bert-base-uncased/resolve/main/vocab.txt',
        'bert-large-uncased': 'https://huggingface.co/bert-large-uncased/resolve/main/vocab.txt',
        'bert-base-cased': 'https://huggingface.co/bert-base-cased/resolve/main/vocab.txt',
        'bert-large-cased': 'https://huggingface.co/bert-large-cased/resolve/main/vocab.txt',
        'bert-base-multilingual-uncased': (
            'https://huggingface.co/bert-base-multilingual-uncased/resolve/main/vocab.txt'
        ),
        'bert-base-multilingual-cased': 'https://huggingface.co/bert-base-multilingual-cased/resolve/main/vocab.txt',
        'bert-base-chinese': 'https://huggingface.co/bert-base-chinese/resolve/main/vocab.txt',
        'bert-base-german-cased': 'https://huggingface.co/bert-base-german-cased/resolve/main/vocab.txt',
        'bert-large-uncased-whole-word-masking': (
            'https://huggingface.co/bert-large-uncased-whole-word-masking/resolve/main/vocab.txt'
        ),
        'bert-large-cased-whole-word-masking': (
            'https://huggingface.co/bert-large-cased-whole-word-masking/resolve/main/vocab.txt'
        ),
        'bert-large-uncased-whole-word-masking-finetuned-squad': (
            'https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/vocab.txt'
        ),
        'bert-large-cased-whole-word-masking-finetuned-squad': (
            'https://huggingface.co/bert-large-cased-whole-word-masking-finetuned-squad/resolve/main/vocab.txt'
        ),
        'bert-base-cased-finetuned-mrpc': (
            'https://huggingface.co/bert-base-cased-finetuned-mrpc/resolve/main/vocab.txt'
        ),
        'bert-base-german-dbmdz-cased': 'https://huggingface.co/bert-base-german-dbmdz-cased/resolve/main/vocab.txt',
        'bert-base-german-dbmdz-uncased': (
            'https://huggingface.co/bert-base-german-dbmdz-uncased/resolve/main/vocab.txt'
        ),
        'TurkuNLP/bert-base-finnish-cased-v1': (
            'https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1/resolve/main/vocab.txt'
        ),
        'TurkuNLP/bert-base-finnish-uncased-v1': (
            'https://huggingface.co/TurkuNLP/bert-base-finnish-uncased-v1/resolve/main/vocab.txt'
        ),
        'wietsedv/bert-base-dutch-cased': (
            'https://huggingface.co/wietsedv/bert-base-dutch-cased/resolve/main/vocab.txt'
        ),
    },
    'tokenizer_file': {
        'bert-base-uncased': 'https://huggingface.co/bert-base-uncased/resolve/main/tokenizer.json',
        'bert-large-uncased': 'https://huggingface.co/bert-large-uncased/resolve/main/tokenizer.json',
        'bert-base-cased': 'https://huggingface.co/bert-base-cased/resolve/main/tokenizer.json',
        'bert-large-cased': 'https://huggingface.co/bert-large-cased/resolve/main/tokenizer.json',
        'bert-base-multilingual-uncased': (
            'https://huggingface.co/bert-base-multilingual-uncased/resolve/main/tokenizer.json'
        ),
        'bert-base-multilingual-cased': (
            'https://huggingface.co/bert-base-multilingual-cased/resolve/main/tokenizer.json'
        ),
        'bert-base-chinese': 'https://huggingface.co/bert-base-chinese/resolve/main/tokenizer.json',
        'bert-base-german-cased': 'https://huggingface.co/bert-base-german-cased/resolve/main/tokenizer.json',
        'bert-large-uncased-whole-word-masking': (
            'https://huggingface.co/bert-large-uncased-whole-word-masking/resolve/main/tokenizer.json'
        ),
        'bert-large-cased-whole-word-masking': (
            'https://huggingface.co/bert-large-cased-whole-word-masking/resolve/main/tokenizer.json'
        ),
        'bert-large-uncased-whole-word-masking-finetuned-squad': (
            'https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/tokenizer.json'
        ),
        'bert-large-cased-whole-word-masking-finetuned-squad': (
            'https://huggingface.co/bert-large-cased-whole-word-masking-finetuned-squad/resolve/main/tokenizer.json'
        ),
        'bert-base-cased-finetuned-mrpc': (
            'https://huggingface.co/bert-base-cased-finetuned-mrpc/resolve/main/tokenizer.json'
        ),
        'bert-base-german-dbmdz-cased': (
            'https://huggingface.co/bert-base-german-dbmdz-cased/resolve/main/tokenizer.json'
        ),
        'bert-base-german-dbmdz-uncased': (
            'https://huggingface.co/bert-base-german-dbmdz-uncased/resolve/main/tokenizer.json'
        ),
        'TurkuNLP/bert-base-finnish-cased-v1': (
            'https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1/resolve/main/tokenizer.json'
        ),
        'TurkuNLP/bert-base-finnish-uncased-v1': (
            'https://huggingface.co/TurkuNLP/bert-base-finnish-uncased-v1/resolve/main/tokenizer.json'
        ),
        'wietsedv/bert-base-dutch-cased': (
            'https://huggingface.co/wietsedv/bert-base-dutch-cased/resolve/main/tokenizer.json'
        ),
    },
}

a_					= {
    'bert-base-uncased': 5_1_2,
    'bert-large-uncased': 5_1_2,
    'bert-base-cased': 5_1_2,
    'bert-large-cased': 5_1_2,
    'bert-base-multilingual-uncased': 5_1_2,
    'bert-base-multilingual-cased': 5_1_2,
    'bert-base-chinese': 5_1_2,
    'bert-base-german-cased': 5_1_2,
    'bert-large-uncased-whole-word-masking': 5_1_2,
    'bert-large-cased-whole-word-masking': 5_1_2,
    'bert-large-uncased-whole-word-masking-finetuned-squad': 5_1_2,
    'bert-large-cased-whole-word-masking-finetuned-squad': 5_1_2,
    'bert-base-cased-finetuned-mrpc': 5_1_2,
    'bert-base-german-dbmdz-cased': 5_1_2,
    'bert-base-german-dbmdz-uncased': 5_1_2,
    'TurkuNLP/bert-base-finnish-cased-v1': 5_1_2,
    'TurkuNLP/bert-base-finnish-uncased-v1': 5_1_2,
    'wietsedv/bert-base-dutch-cased': 5_1_2,
}

a_					= {
    'bert-base-uncased': {'do_lower_case': True},
    'bert-large-uncased': {'do_lower_case': True},
    'bert-base-cased': {'do_lower_case': False},
    'bert-large-cased': {'do_lower_case': False},
    'bert-base-multilingual-uncased': {'do_lower_case': True},
    'bert-base-multilingual-cased': {'do_lower_case': False},
    'bert-base-chinese': {'do_lower_case': False},
    'bert-base-german-cased': {'do_lower_case': False},
    'bert-large-uncased-whole-word-masking': {'do_lower_case': True},
    'bert-large-cased-whole-word-masking': {'do_lower_case': False},
    'bert-large-uncased-whole-word-masking-finetuned-squad': {'do_lower_case': True},
    'bert-large-cased-whole-word-masking-finetuned-squad': {'do_lower_case': False},
    'bert-base-cased-finetuned-mrpc': {'do_lower_case': False},
    'bert-base-german-dbmdz-cased': {'do_lower_case': False},
    'bert-base-german-dbmdz-uncased': {'do_lower_case': True},
    'TurkuNLP/bert-base-finnish-cased-v1': {'do_lower_case': False},
    'TurkuNLP/bert-base-finnish-uncased-v1': {'do_lower_case': True},
    'wietsedv/bert-base-dutch-cased': {'do_lower_case': False},
}






class      __SCREAMING_SNAKE_CASE      (			lowerCamelCase				):
 snake_case_  							=							VOCAB_FILES_NAMES
 snake_case_  							=							PRETRAINED_VOCAB_FILES_MAP
 snake_case_  							=							PRETRAINED_INIT_CONFIGURATION
 snake_case_  							=							PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
 snake_case_  							=							BertTokenizer




 def __init__(      self	:							int					,      __lowercase	:							Union[str, Any]=None					,      __lowercase	:							Tuple=None					,      __lowercase	:							str=True					,      __lowercase	:							Optional[Any]="[UNK]"					,      __lowercase	:							Tuple="[SEP]"					,      __lowercase	:							Any="[PAD]"					,      __lowercase	:							List[Any]="[CLS]"					,      __lowercase	:							Union[str, Any]="[MASK]"					,      __lowercase	:							Tuple=True					,      __lowercase	:							str=None					,      **__lowercase	:							Any					,      )	->						Optional[Any]:
       super().__init__(
           __lowercase					,      tokenizer_file=__lowercase					,      do_lower_case=__lowercase					,      unk_token=__lowercase					,      sep_token=__lowercase					,      pad_token=__lowercase					,      cls_token=__lowercase					,      mask_token=__lowercase					,      tokenize_chinese_chars=__lowercase					,      strip_accents=__lowercase					,      **__lowercase					,      )

       SCREAMING_SNAKE_CASE__     :				str									=json.loads(self.backend_tokenizer.normalizer.__getstate__()      )
       if (
           normalizer_state.get('''lowercase'''					,      __lowercase      ) != do_lower_case
           or normalizer_state.get('''strip_accents'''					,      __lowercase      ) != strip_accents
           or normalizer_state.get('''handle_chinese_chars'''					,      __lowercase      ) != tokenize_chinese_chars
       ):
             SCREAMING_SNAKE_CASE__     :				int									=getattr(__lowercase					,      normalizer_state.pop('''type'''      )      )
             SCREAMING_SNAKE_CASE__     :				Any									=do_lower_case
             SCREAMING_SNAKE_CASE__     :				Any									=strip_accents
             SCREAMING_SNAKE_CASE__     :				Dict									=tokenize_chinese_chars
             SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=normalizer_class(**__lowercase      )

       SCREAMING_SNAKE_CASE__     :				Optional[int]									=do_lower_case




 def      __magic_name__	(      self	:							int					,      __lowercase	:							Optional[Any]					,      __lowercase	:							Union[str, Any]=None      )	->						int:
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=[self.cls_token_id] + token_ids_a + [self.sep_token_id]

       if token_ids_a:
             output += token_ids_a + [self.sep_token_id]

       return output




 def      __magic_name__	(      self	:							Union[str, Any]					,      __lowercase	:							List[int]					,      __lowercase	:							Optional[List[int]] = None      )	->						List[int]:
       SCREAMING_SNAKE_CASE__     :				List[str]									=[self.sep_token_id]
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=[self.cls_token_id]
       if token_ids_a is None:
             return len(cls + token_ids_a + sep      ) * [0]
       return len(cls + token_ids_a + sep      ) * [0] + len(token_ids_a + sep      ) * [1]




 def      __magic_name__	(      self	:							List[Any]					,      __lowercase	:							str					,      __lowercase	:							Optional[str] = None      )	->						Tuple[str]:
       SCREAMING_SNAKE_CASE__     :				Optional[int]									=self._tokenizer.model.save(__lowercase					,      name=__lowercase      )
       return tuple(__lowercase      )