'''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_convbert import ConvBertTokenizer


lowerCAmelCase_ : Tuple						  =      logging.get_logger(__name__)

lowerCAmelCase_ : Any						  =      {"vocab_file": "vocab.txt"}

lowerCAmelCase_ : str						  =      {
    "vocab_file": {
        "YituTech/conv-bert-base": "https://huggingface.co/YituTech/conv-bert-base/resolve/main/vocab.txt",
        "YituTech/conv-bert-medium-small": (
            "https://huggingface.co/YituTech/conv-bert-medium-small/resolve/main/vocab.txt"
        ),
        "YituTech/conv-bert-small": "https://huggingface.co/YituTech/conv-bert-small/resolve/main/vocab.txt",
    }
}

lowerCAmelCase_ : List[str]						  =      {
    "YituTech/conv-bert-base": 512,
    "YituTech/conv-bert-medium-small": 512,
    "YituTech/conv-bert-small": 512,
}


lowerCAmelCase_ : Union[str, Any]						  =      {
    "YituTech/conv-bert-base": {"do_lower_case": True},
    "YituTech/conv-bert-medium-small": {"do_lower_case": True},
    "YituTech/conv-bert-small": {"do_lower_case": True},
}





class 							lowercase						(						__lowerCamelCase ):
   lowerCamelCase_    					=VOCAB_FILES_NAMES
   lowerCamelCase_    					=PRETRAINED_VOCAB_FILES_MAP
   lowerCamelCase_    					=PRETRAINED_INIT_CONFIGURATION
   lowerCamelCase_    					=PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
   lowerCamelCase_    					=ConvBertTokenizer


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

         lowercase_     =      json.loads(self.backend_tokenizer.normalizer.__getstate__())
         if (
             normalizer_state.get("lowercase"   ,		__lowerCAmelCase) != do_lower_case
             or normalizer_state.get("strip_accents"   ,		__lowerCAmelCase) != strip_accents
             or normalizer_state.get("handle_chinese_chars"   ,		__lowerCAmelCase) != tokenize_chinese_chars
         ):
               lowercase_     =      getattr(__lowerCAmelCase   ,		normalizer_state.pop("type"))
               lowercase_     =      do_lower_case
               lowercase_     =      strip_accents
               lowercase_     =      tokenize_chinese_chars
               lowercase_     =      normalizer_class(**__lowerCAmelCase)

         lowercase_     =      do_lower_case


   def __UpperCAmelCase       (   self				:	int   ,		__lowerCAmelCase				:	List[str]   ,		__lowerCAmelCase				:	Tuple=None)      ->					Dict:
         lowercase_     =      [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 __UpperCAmelCase       (   self				:	str   ,		__lowerCAmelCase				:	List[int]   ,		__lowerCAmelCase				:	Optional[List[int]] = None)      ->					List[int]:
         lowercase_     =      [self.sep_token_id]
         lowercase_     =      [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 __UpperCAmelCase       (   self				:	Optional[int]   ,		__lowerCAmelCase				:	str   ,		__lowerCAmelCase				:	Optional[str] = None)      ->					Tuple[str]:
         lowercase_     =      self._tokenizer.model.save(__lowerCAmelCase   ,		name=__lowerCAmelCase)
         return tuple(__lowerCAmelCase)







'''simple docstring'''

from typing import List, Optional, Union

import numpy as np
import PIL.Image

from ...image_processing_utils import BaseImageProcessor, BatchFeature
from ...image_transforms import rescale, resize, to_channel_dimension_format
from ...image_utils import (
    ChannelDimension,
    PILImageResampling,
    get_image_size,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


lowerCAmelCase_ : Any						  =      logging.get_logger(__name__)





class 							lowercase						(						__lowerCamelCase ):
   lowerCamelCase_    					=['pixel_values']


   def __init__(   self				:	Optional[int]   ,		__lowerCAmelCase				:	bool = True   ,		__lowerCAmelCase				:	int = 32   ,		__lowerCAmelCase				:	List[str]=PILImageResampling.BILINEAR   ,		__lowerCAmelCase				:	bool = True   ,		**__lowerCAmelCase				:	Union[str, Any]   ,		)      ->					None:
         lowercase_     =      do_resize
         lowercase_     =      do_rescale
         lowercase_     =      size_divisor
         lowercase_     =      resample
         super().__init__(**__lowerCAmelCase)


   def __UpperCAmelCase       (   self				:	List[str]   ,		__lowerCAmelCase				:	np.ndarray   ,		__lowerCAmelCase				:	int   ,		__lowerCAmelCase				:	Optional[int]   ,		__lowerCAmelCase				:	Optional[ChannelDimension] = None   ,		**__lowerCAmelCase				:	Any)      ->					np.ndarray:
         lowercase_ ,							lowercase_     =      get_image_size(__lowerCAmelCase)
         # Rounds the height and width down to the closest multiple of size_divisor
         lowercase_     =      height // size_divisor * size_divisor
         lowercase_     =      width // size_divisor * size_divisor
         lowercase_     =      resize(__lowerCAmelCase   ,		(new_h, new_w)   ,		resample=__lowerCAmelCase   ,		data_format=__lowerCAmelCase   ,		**__lowerCAmelCase)
         return image


   def __UpperCAmelCase       (   self				:	str   ,		__lowerCAmelCase				:	np.ndarray   ,		__lowerCAmelCase				:	float   ,		__lowerCAmelCase				:	Optional[ChannelDimension] = None   ,		**__lowerCAmelCase				:	int)      ->					np.ndarray:
         return rescale(image=__lowerCAmelCase   ,		scale=__lowerCAmelCase   ,		data_format=__lowerCAmelCase   ,		**__lowerCAmelCase)


   def __UpperCAmelCase       (   self				:	Optional[Any]   ,		__lowerCAmelCase				:	Union["PIL.Image.Image", TensorType, List["PIL.Image.Image"], List[TensorType]]   ,		__lowerCAmelCase				:	Optional[bool] = None   ,		__lowerCAmelCase				:	Optional[int] = None   ,		__lowerCAmelCase				:	str=None   ,		__lowerCAmelCase				:	Optional[bool] = None   ,		__lowerCAmelCase				:	Optional[Union[TensorType, str]] = None   ,		__lowerCAmelCase				:	ChannelDimension = ChannelDimension.FIRST   ,		**__lowerCAmelCase				:	List[str]   ,		)      ->					BatchFeature:
         lowercase_     =      do_resize if do_resize is not None else self.do_resize
         lowercase_     =      do_rescale if do_rescale is not None else self.do_rescale
         lowercase_     =      size_divisor if size_divisor is not None else self.size_divisor
         lowercase_     =      resample if resample is not None else self.resample

         if do_resize and size_divisor is None:
               raise ValueError("size_divisor is required for resizing")

         lowercase_     =      make_list_of_images(__lowerCAmelCase)

         if not valid_images(__lowerCAmelCase):
               raise ValueError("Invalid image(s)")

         # All transformations expect numpy arrays.
         lowercase_     =      [to_numpy_array(__lowerCAmelCase) for img in images]

         if do_resize:
               lowercase_     =      [self.resize(__lowerCAmelCase   ,		size_divisor=__lowerCAmelCase   ,		resample=__lowerCAmelCase) for image in images]

         if do_rescale:
               lowercase_     =      [self.rescale(__lowerCAmelCase   ,		scale=1 / 255) for image in images]

         lowercase_     =      [to_channel_dimension_format(__lowerCAmelCase   ,		__lowerCAmelCase) for image in images]

         lowercase_     =      {"pixel_values": images}
         return BatchFeature(data=__lowerCAmelCase   ,		tensor_type=__lowerCAmelCase)






