code: 
  
  
  
  
  '''simple docstring'''
  
  
  
  
  
  import warnings
  from typing import List, Optional, Union
  
  import numpy as np
  import PIL
  import torch
  from PIL import Image
  
  from .configuration_utils import ConfigMixin, register_to_config
  from .utils import CONFIG_NAME, PIL_INTERPOLATION, deprecate
  
  
  
  
  
  
  class 						lowercase     (   lowercase__):
        __lowercase 		=  CONFIG_NAME
  
  
  
  
  
  
        @register_to_config
        def __init__(self ,  a__ = True ,  a__ = 8 ,  a__ = "lanczos" ,  a__ = True ,  a__ = False ,  )       ->   int:
           super().__init__()
  
  
  
  
  
  
        @staticmethod
        def    A__(a__					)       ->   PIL.Image.Image:
           if images.ndim == 3:
              SCREAMING_SNAKE_CASE__			:				Optional[int]       						= images[None, ...]
           SCREAMING_SNAKE_CASE__			:				Dict       						= (images * 2_5_5).round().astype('''uint8'''					)
           if images.shape[-1] == 1:
              # special case for grayscale (single channel) images
              SCREAMING_SNAKE_CASE__			:				Dict       						= [Image.fromarray(image.squeeze() ,  mode='''L'''					) for image in images]
           else:
              SCREAMING_SNAKE_CASE__			:				int       						= [Image.fromarray(_A					) for image in images]
  
           return pil_images
  
  
  
  
  
  
        @staticmethod
        def    A__(a__					)       ->   np.ndarray:
           if not isinstance(_A ,  _A					):
              SCREAMING_SNAKE_CASE__			:				List[str]       						= [images]
           SCREAMING_SNAKE_CASE__			:				str       						= [np.array(_A					).astype(np.floataa					) / 2_55.0 for image in images]
           SCREAMING_SNAKE_CASE__			:				str       						= np.stack(_A ,  axis=0					)
  
           return images
  
  
  
  
  
  
        @staticmethod
        def    A__(a__					)       ->   torch.FloatTensor:
           if images.ndim == 3:
              SCREAMING_SNAKE_CASE__			:				Tuple       						= images[..., None]
  
           SCREAMING_SNAKE_CASE__			:				List[str]       						= torch.from_numpy(images.transpose(0 ,  3 ,  1 ,  2					)					)
           return images
  
  
  
  
  
  
        @staticmethod
        def    A__(a__					)       ->   np.ndarray:
           SCREAMING_SNAKE_CASE__			:				str       						= images.cpu().permute(0 ,  2 ,  3 ,  1					).float().numpy()
           return images
  
  
  
  
  
  
        @staticmethod
        def    A__(a__					)       ->   Union[str, Any]:
           return 2.0 * images - 1.0
  
  
  
  
  
  
        @staticmethod
        def    A__(a__					)       ->   Union[str, Any]:
           return (images / 2 + 0.5).clamp(0 ,  1					)
  
  
  
  
  
  
        @staticmethod
        def    A__(a__					)       ->   PIL.Image.Image:
           SCREAMING_SNAKE_CASE__			:				List[Any]       						= image.convert('''RGB'''					)
           return image
  
  
  
  
  
  
        def    A__(self ,  a__ ,  a__ = None ,  a__ = None ,  )       ->   PIL.Image.Image:
           if height is None:
              SCREAMING_SNAKE_CASE__			:				Tuple       						= image.height
           if width is None:
              SCREAMING_SNAKE_CASE__			:				Optional[int]       						= image.width
  
           SCREAMING_SNAKE_CASE__			:				List[Any]       						= (
               x - x % self.config.vae_scale_factor for x in (width, height)
           )  # resize to integer multiple of vae_scale_factor
           SCREAMING_SNAKE_CASE__			:				int       						= image.resize((width, height) ,  resample=PIL_INTERPOLATION[self.config.resample]					)
           return image
  
  
  
  
  
  
        def    A__(self ,  a__ ,  a__ = None ,  a__ = None ,  )       ->   torch.Tensor:
           SCREAMING_SNAKE_CASE__			:				List[Any]       						= (PIL.Image.Image, np.ndarray, torch.Tensor)
           if isinstance(_A ,  _A					):
              SCREAMING_SNAKE_CASE__			:				Optional[int]       						= [image]
           elif not (isinstance(_A ,  _A					) and all(isinstance(_A ,  _A					) for i in image					)):
              raise ValueError(
                  f"""Input is in incorrect format: {[type(_A					) for i in image]}. Currently, we only support {", ".join(_A					)}"""					)
  
           if isinstance(image[0] ,  PIL.Image.Image					):
              if self.config.do_convert_rgb:
                 SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= [self.convert_to_rgb(_A					) for i in image]
              if self.config.do_resize:
                 SCREAMING_SNAKE_CASE__			:				int       						= [self.resize(_A ,  _A ,  _A					) for i in image]
              SCREAMING_SNAKE_CASE__			:				Dict       						= self.pil_to_numpy(_A					)  # to np
              SCREAMING_SNAKE_CASE__			:				int       						= self.numpy_to_pt(_A					)  # to pt
  
           elif isinstance(image[0] ,  np.ndarray					):
              SCREAMING_SNAKE_CASE__			:				str       						= np.concatenate(_A ,  axis=0					) if image[0].ndim == 4 else np.stack(_A ,  axis=0					)
              SCREAMING_SNAKE_CASE__			:				Any       						= self.numpy_to_pt(_A					)
              SCREAMING_SNAKE_CASE__			:				Tuple       						= image.shape
              if self.config.do_resize and (
                  height % self.config.vae_scale_factor != 0 or width % self.config.vae_scale_factor != 0
              ):
                 raise ValueError(
                     f"""Currently we only support resizing for PIL image - please resize your numpy array to be divisible by {self.config.vae_scale_factor}"""
                     f"""currently the sizes are {height} and {width}. You can also pass a PIL image instead to use resize option in VAEImageProcessor"""					)
  
           elif isinstance(image[0] ,  torch.Tensor					):
              SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= torch.cat(_A ,  axis=0					) if image[0].ndim == 4 else torch.stack(_A ,  axis=0					)
              SCREAMING_SNAKE_CASE__			:				List[Any]       						= image.shape
  
              # don't need any preprocess if the image is latents
              if channel == 4:
                 return image
  
              if self.config.do_resize and (
                  height % self.config.vae_scale_factor != 0 or width % self.config.vae_scale_factor != 0
              ):
                 raise ValueError(
                     f"""Currently we only support resizing for PIL image - please resize your pytorch tensor to be divisible by {self.config.vae_scale_factor}"""
                     f"""currently the sizes are {height} and {width}. You can also pass a PIL image instead to use resize option in VAEImageProcessor"""					)
  
          # expected range [0,1], normalize to [-1,1]
           SCREAMING_SNAKE_CASE__			:				str       						= self.config.do_normalize
           if image.min() < 0:
              warnings.warn(
                  '''Passing `image` as torch tensor with value range in [-1,1] is deprecated. The expected value range for image tensor is [0,1] '''
                  f"""when passing as pytorch tensor or numpy Array. You passed `image` with value range [{image.min()},{image.max()}]""" ,  _A ,  )
              SCREAMING_SNAKE_CASE__			:				str       						= False
  
           if do_normalize:
              SCREAMING_SNAKE_CASE__			:				int       						= self.normalize(_A					)
  
           return image
  
  
  
  
  
  
        def    A__(self ,  a__ ,  a__ = "pil" ,  a__ = None ,  )       ->   Optional[Any]:
           if not isinstance(_A ,  torch.Tensor					):
              raise ValueError(
                  f"""Input for postprocessing is in incorrect format: {type(_A					)}. We only support pytorch tensor"""					)
           if output_type not in ["latent", "pt", "np", "pil"]:
              SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= (
                  f"""the output_type {output_type} is outdated and has been set to `np`. Please make sure to set it to one of these instead: """
                  '`pil`, `np`, `pt`, `latent`'
              )
              deprecate('''Unsupported output_type''' ,  '''1.0.0''' ,  _A ,  standard_warn=_A					)
              SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= 'np'
  
           if output_type == "latent":
              return image
  
           if do_denormalize is None:
              SCREAMING_SNAKE_CASE__			:				Any       						= [self.config.do_normalize] * image.shape[0]
  
           SCREAMING_SNAKE_CASE__			:				Optional[int]       						= torch.stack(
               [self.denormalize(image[i]					) if do_denormalize[i] else image[i] for i in range(image.shape[0]					)]					)
  
           if output_type == "pt":
              return image
  
           SCREAMING_SNAKE_CASE__			:				Any       						= self.pt_to_numpy(_A					)
  
           if output_type == "np":
              return image
  
           if output_type == "pil":
              return self.numpy_to_pil(_A					)
  
  
  
  
  
  
  class 						lowercase     (   lowercase__):
        __lowercase 		=  CONFIG_NAME
  
  
  
  
  
  
        @register_to_config
        def __init__(self ,  a__ = True ,  a__ = 8 ,  a__ = "lanczos" ,  a__ = True ,  )       ->   Tuple:
           super().__init__()
  
  
  
  
  
  
        @staticmethod
        def    A__(a__					)       ->   Optional[int]:
           if images.ndim == 3:
              SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= images[None, ...]
           SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= (images * 2_5_5).round().astype('''uint8'''					)
           if images.shape[-1] == 1:
              # special case for grayscale (single channel) images
              SCREAMING_SNAKE_CASE__			:				Optional[int]       						= [Image.fromarray(image.squeeze() ,  mode='''L'''					) for image in images]
           else:
              SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= [Image.fromarray(image[:, :, :3]					) for image in images]
  
           return pil_images
  
  
  
  
  
  
        @staticmethod
        def    A__(a__					)       ->   Optional[Any]:
           return image[:, :, 1] * 2**8 + image[:, :, 2]
  
  
  
  
  
  
        def    A__(self ,  a__					)       ->   Dict:
           if images.ndim == 3:
              SCREAMING_SNAKE_CASE__			:				Tuple       						= images[None, ...]
           SCREAMING_SNAKE_CASE__			:				Any       						= images[:, :, :, 3:]
           if images.shape[-1] == 6:
              SCREAMING_SNAKE_CASE__			:				List[str]       						= (images_depth * 2_5_5).round().astype('''uint8'''					)
              SCREAMING_SNAKE_CASE__			:				Any       						= [
                  Image.fromarray(self.rgblike_to_depthmap(_A					) ,  mode='''I;16'''					) for image_depth in images_depth
              ]
           elif images.shape[-1] == 4:
              SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= (images_depth * 6_5_5_3_5.0).astype(np.uintaa					)
              SCREAMING_SNAKE_CASE__			:				Any       						= [Image.fromarray(_A ,  mode='''I;16'''					) for image_depth in images_depth]
           else:
              raise Exception('''Not supported'''					)
  
           return pil_images
  
  
  
  
  
  
        def    A__(self ,  a__ ,  a__ = "pil" ,  a__ = None ,  )       ->   int:
           if not isinstance(_A ,  torch.Tensor					):
              raise ValueError(
                  f"""Input for postprocessing is in incorrect format: {type(_A					)}. We only support pytorch tensor"""					)
           if output_type not in ["latent", "pt", "np", "pil"]:
              SCREAMING_SNAKE_CASE__			:				List[Any]       						= (
                  f"""the output_type {output_type} is outdated and has been set to `np`. Please make sure to set it to one of these instead: """
                  '`pil`, `np`, `pt`, `latent`'
              )
              deprecate('''Unsupported output_type''' ,  '''1.0.0''' ,  _A ,  standard_warn=_A					)
              SCREAMING_SNAKE_CASE__			:				List[str]       						= 'np'
  
           if do_denormalize is None:
              SCREAMING_SNAKE_CASE__			:				Tuple       						= [self.config.do_normalize] * image.shape[0]
  
           SCREAMING_SNAKE_CASE__			:				Tuple       						= torch.stack(
               [self.denormalize(image[i]					) if do_denormalize[i] else image[i] for i in range(image.shape[0]					)]					)
  
           SCREAMING_SNAKE_CASE__			:				Optional[int]       						= self.pt_to_numpy(_A					)
  
           if output_type == "np":
              if image.shape[-1] == 6:
                 SCREAMING_SNAKE_CASE__			:				str       						= np.stack([self.rgblike_to_depthmap(im[:, :, 3:]					) for im in image] ,  axis=0					)
              else:
                 SCREAMING_SNAKE_CASE__			:				Tuple       						= image[:, :, :, 3:]
              return image[:, :, :, :3], image_depth
  
           if output_type == "pil":
              return self.numpy_to_pil(_A					), self.numpy_to_depth(_A					)
           else:
              raise Exception(f"""This type {output_type} is not supported"""					)
  
  
style_context: 
  
  
  
  
  '''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_splinter import SplinterTokenizer
  
  
  lowercase__			=	logging.get_logger(__name__)
  
  lowercase__			=	{'''vocab_file''': '''vocab.txt'''}
  
  lowercase__			=	{
      '''vocab_file''': {
          '''tau/splinter-base''': '''https://huggingface.co/tau/splinter-base/resolve/main/vocab.txt''',
          '''tau/splinter-base-qass''': '''https://huggingface.co/tau/splinter-base-qass/resolve/main/vocab.txt''',
          '''tau/splinter-large''': '''https://huggingface.co/tau/splinter-large/resolve/main/vocab.txt''',
          '''tau/splinter-large-qass''': '''https://huggingface.co/tau/splinter-large-qass/resolve/main/vocab.txt''',
      }
  }
  
  lowercase__			=	{
      '''tau/splinter-base''': 5_1_2,
      '''tau/splinter-base-qass''': 5_1_2,
      '''tau/splinter-large''': 5_1_2,
      '''tau/splinter-large-qass''': 5_1_2,
  }
  
  lowercase__			=	{
      '''tau/splinter-base''': {'''do_lower_case''': False},
      '''tau/splinter-base-qass''': {'''do_lower_case''': False},
      '''tau/splinter-large''': {'''do_lower_case''': False},
      '''tau/splinter-large-qass''': {'''do_lower_case''': False},
  }
  
  
  
  
  
  
  class 						lowercase     (   UpperCAmelCase_):
        __lowercase 		=  VOCAB_FILES_NAMES
        __lowercase 		=  PRETRAINED_VOCAB_FILES_MAP
        __lowercase 		=  PRETRAINED_INIT_CONFIGURATION
        __lowercase 		=  PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
        __lowercase 		=  SplinterTokenizer
  
  
  
  
  
  
        def __init__(self ,  a__=None ,  a__=None ,  a__=True ,  a__="[UNK]" ,  a__="[SEP]" ,  a__="[PAD]" ,  a__="[CLS]" ,  a__="[MASK]" ,  a__="[QUESTION]" ,  a__=True ,  a__=None ,  **a__ ,  )       ->   Any:
           super().__init__(
               a__ ,  tokenizer_file=a__ ,  do_lower_case=a__ ,  unk_token=a__ ,  sep_token=a__ ,  pad_token=a__ ,  cls_token=a__ ,  mask_token=a__ ,  tokenize_chinese_chars=a__ ,  strip_accents=a__ ,  additional_special_tokens=(question_token,) ,  **a__ ,  )
  
           SCREAMING_SNAKE_CASE__			:				Tuple       						= json.loads(self.backend_tokenizer.normalizer.__getstate__()					)
           if (
               pre_tok_state.get('''lowercase''' ,  a__					) != do_lower_case
               or pre_tok_state.get('''strip_accents''' ,  a__					) != strip_accents
           ):
              SCREAMING_SNAKE_CASE__			:				List[Any]       						= getattr(a__ ,  pre_tok_state.pop('''type'''					)					)
              SCREAMING_SNAKE_CASE__			:				Optional[int]       						= do_lower_case
              SCREAMING_SNAKE_CASE__			:				Optional[int]       						= strip_accents
              SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= pre_tok_class(**a__					)
  
           SCREAMING_SNAKE_CASE__			:				Optional[int]       						= do_lower_case
  
  
  
  
  
  
        @property
        def    A__(self					)       ->   List[str]:
           return self.convert_tokens_to_ids(self.question_token					)
  
  
  
  
  
  
        def    A__(self ,  a__ ,  a__ = None					)       ->   List[int]:
           if token_ids_a is None:
              return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
  
           SCREAMING_SNAKE_CASE__			:				Dict       						= [self.cls_token_id]
           SCREAMING_SNAKE_CASE__			:				Tuple       						= [self.sep_token_id]
           SCREAMING_SNAKE_CASE__			:				List[Any]       						= [self.question_token_id] + [self.convert_tokens_to_ids('''.'''					)]
           if self.padding_side == "right":
              # Input is question-then-context
              return cls + token_ids_a + question_suffix + sep + token_ids_a + sep
           else:
              # Input is context-then-question
              return cls + token_ids_a + sep + token_ids_a + question_suffix + sep
  
  
  
  
  
  
        def    A__(self ,  a__ ,  a__ = None					)       ->   List[int]:
           SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= [self.sep_token_id]
           SCREAMING_SNAKE_CASE__			:				Any       						= [self.cls_token_id]
           SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= [self.question_token_id] + [self.convert_tokens_to_ids('''.'''					)]
           if token_ids_a is None:
              return len(cls + token_ids_a + sep					) * [0]
  
           if self.padding_side == "right":
              # Input is question-then-context
              return len(cls + token_ids_a + question_suffix + sep					) * [0] + len(token_ids_a + sep					) * [1]
           else:
              # Input is context-then-question
              return len(cls + token_ids_a + sep					) * [0] + len(token_ids_a + question_suffix + sep					) * [1]
  
  
  
  
  
  
        def    A__(self ,  a__ ,  a__ = None					)       ->   Tuple[str]:
           SCREAMING_SNAKE_CASE__			:				int       						= self._tokenizer.model.save(a__ ,  name=a__					)
           return tuple(a__					)
  
  