


import inspect
import tempfile
from collections import OrderedDict, UserDict
from collections.abc import MutableMapping
from contextlib import ExitStack, contextmanager
from dataclasses import fields
from enum import Enum
from typing import Any, ContextManager, List, Tuple

import numpy as np

from .import_utils import is_flax_available, is_tf_available, is_torch_available, is_torch_fx_proxy


if is_flax_available():
    import jax.numpy as jnp



class 							_UpperCamelCase (						lowercase__						):

   '''simple docstring'''







   def __get__(  self  : Union[str, Any]       ,  _lowerCamelCase  : List[str]       ,  _lowerCamelCase  : Any=None							):






         '''simple docstring'''



         if obj is None:
               return self
         if self.fget is None:
               raise AttributeError("""unreadable attribute"""							)
         __lowerCamelCase     :      Optional[int]       						=						"__cached_" + self.fget.__name__
         __lowerCamelCase     :      Optional[Any]       						=						getattr(__lowerCamelCase       ,  __lowerCamelCase       ,  __lowerCamelCase							)
         if cached is None:
               __lowerCamelCase     :      List[Any]       						=						self.fget(__lowerCamelCase							)
               setattr(__lowerCamelCase       ,  __lowerCamelCase       ,  __lowerCamelCase							)
         return cached





def   _UpperCAmelCase       (     UpperCAmelCase      :			List[str]      ):
      """simple docstring"""




      __lowerCamelCase     :      List[Any]       						=						val.lower()
      if val in {"y", "yes", "t", "true", "on", "1"}:
            return 1
      if val in {"n", "no", "f", "false", "off", "0"}:
            return 0
      raise ValueError(f"""invalid truth value {val!r}"""      )





def   _UpperCAmelCase       (     UpperCAmelCase      :			str      ):
      """simple docstring"""




      if is_torch_fx_proxy(_A      ):
            return True
      if is_torch_available():
            import torch

            if isinstance(_A						,	torch.Tensor      ):
                  return True
      if is_tf_available():
            import tensorflow as tf

            if isinstance(_A						,	tf.Tensor      ):
                  return True

      if is_flax_available():
            import jax.numpy as jnp
            from jax.core import Tracer

            if isinstance(_A						,	(jnp.ndarray, Tracer)      ):
                  return True

      return isinstance(_A						,	np.ndarray      )





def   _UpperCAmelCase       (     UpperCAmelCase      :			int      ):
      """simple docstring"""




      return isinstance(_A						,	np.ndarray      )





def   _UpperCAmelCase       (     UpperCAmelCase      :			Dict      ):
      """simple docstring"""




      return _is_numpy(_A      )





def   _UpperCAmelCase       (     UpperCAmelCase      :			List[str]      ):
      """simple docstring"""




      import torch

      return isinstance(_A						,	torch.Tensor      )





def   _UpperCAmelCase       (     UpperCAmelCase      :			Any      ):
      """simple docstring"""




      return False if not is_torch_available() else _is_torch(_A      )





def   _UpperCAmelCase       (     UpperCAmelCase      :			str      ):
      """simple docstring"""




      import torch

      return isinstance(_A						,	torch.device      )





def   _UpperCAmelCase       (     UpperCAmelCase      :			Any      ):
      """simple docstring"""




      return False if not is_torch_available() else _is_torch_device(_A      )





def   _UpperCAmelCase       (     UpperCAmelCase      :			int      ):
      """simple docstring"""




      import torch

      if isinstance(_A						,	_A      ):
            if hasattr(_A						,	_A      ):
                  __lowerCamelCase     :      List[Any]       						=						getattr(_A						,	_A      )
            else:
                  return False
      return isinstance(_A						,	torch.dtype      )





def   _UpperCAmelCase       (     UpperCAmelCase      :			Tuple      ):
      """simple docstring"""




      return False if not is_torch_available() else _is_torch_dtype(_A      )





def   _UpperCAmelCase       (     UpperCAmelCase      :			str      ):
      """simple docstring"""




      import tensorflow as tf

      return isinstance(_A						,	tf.Tensor      )





def   _UpperCAmelCase       (     UpperCAmelCase      :			Union[str, Any]      ):
      """simple docstring"""




      return False if not is_tf_available() else _is_tensorflow(_A      )





def   _UpperCAmelCase       (     UpperCAmelCase      :			Dict      ):
      """simple docstring"""




      import tensorflow as tf

      # the `is_symbolic_tensor` predicate is only available starting with TF 2.14
      if hasattr(_A						,	"""is_symbolic_tensor"""      ):
            return tf.is_symbolic_tensor(_A      )
      return type(_A      ) == tf.Tensor





def   _UpperCAmelCase       (     UpperCAmelCase      :			Optional[Any]      ):
      """simple docstring"""




      return False if not is_tf_available() else _is_tf_symbolic_tensor(_A      )





def   _UpperCAmelCase       (     UpperCAmelCase      :			Optional[int]      ):
      """simple docstring"""




      import jax.numpy as jnp  # noqa: F811

      return isinstance(_A						,	jnp.ndarray      )





def   _UpperCAmelCase       (     UpperCAmelCase      :			List[Any]      ):
      """simple docstring"""




      return False if not is_flax_available() else _is_jax(_A      )





def   _UpperCAmelCase       (     UpperCAmelCase      :			Any      ):
      """simple docstring"""




      if isinstance(_A						,	(dict, UserDict)      ):
            return {k: to_py_obj(_A      ) for k, v in obj.items()}
      elif isinstance(_A						,	(list, tuple)      ):
            return [to_py_obj(_A      ) for o in obj]
      elif is_tf_tensor(_A      ):
            return obj.numpy().tolist()
      elif is_torch_tensor(_A      ):
            return obj.detach().cpu().tolist()
      elif is_jax_tensor(_A      ):
            return np.asarray(_A      ).tolist()
      elif isinstance(_A						,	(np.ndarray, np.number)      ):  # tolist also works on 0d np arrays
            return obj.tolist()
      else:
            return obj





def   _UpperCAmelCase       (     UpperCAmelCase      :			List[Any]      ):
      """simple docstring"""




      if isinstance(_A						,	(dict, UserDict)      ):
            return {k: to_numpy(_A      ) for k, v in obj.items()}
      elif isinstance(_A						,	(list, tuple)      ):
            return np.array(_A      )
      elif is_tf_tensor(_A      ):
            return obj.numpy()
      elif is_torch_tensor(_A      ):
            return obj.detach().cpu().numpy()
      elif is_jax_tensor(_A      ):
            return np.asarray(_A      )
      else:
            return obj



class 							_UpperCamelCase (						lowercase__						):

   '''simple docstring'''







   def   _snake_case    (  self  : Tuple							):






         '''simple docstring'''



         __lowerCamelCase     :      Optional[int]       						=						fields(self							)

         # Safety and consistency checks
         if not len(__lowerCamelCase							):
               raise ValueError(F"""{self.__class__.__name__} has no fields."""							)
         if not all(field.default is None for field in class_fields[1:]							):
               raise ValueError(F"""{self.__class__.__name__} should not have more than one required field."""							)

         __lowerCamelCase     :      str       						=						getattr(self       ,  class_fields[0].name							)
         __lowerCamelCase     :      List[Any]       						=						all(getattr(self       ,  field.name							) is None for field in class_fields[1:]							)

         if other_fields_are_none and not is_tensor(__lowerCamelCase							):
               if isinstance(__lowerCamelCase       ,  __lowerCamelCase							):
                     __lowerCamelCase     :      Dict       						=						first_field.items()
                     __lowerCamelCase     :      List[str]       						=						True
               else:
                     try:
                           __lowerCamelCase     :      Dict       						=						iter(__lowerCamelCase							)
                           __lowerCamelCase     :      Dict       						=						True
                     except TypeError:
                           __lowerCamelCase     :      Optional[int]       						=						False

            # if we provided an iterator as first field and the iterator is a (key, value) iterator
            # set the associated fields
               if first_field_iterator:
                     for idx, element in enumerate(__lowerCamelCase							):
                           if (
                               not isinstance(__lowerCamelCase       ,  (list, tuple)							)
                               or not len(__lowerCamelCase							) == 2
                               or not isinstance(element[0]       ,  __lowerCamelCase							)
                           ):
                                 if idx == 0:
                                       # If we do not have an iterator of key/values, set it as attribute
                                       __lowerCamelCase     :      int       						=						first_field
                                 else:
                                       # If we have a mixed iterator, raise an error
                                       raise ValueError(
                                           F"""Cannot set key/value for {element}. It needs to be a tuple (key, value)."""							)
                                 break
                           setattr(self       ,  element[0]       ,  element[1]							)
                           if element[1] is not None:
                                 __lowerCamelCase     :      Optional[int]       						=						element[1]
               elif first_field is not None:
                     __lowerCamelCase     :      str       						=						first_field
         else:
               for field in class_fields:
                     __lowerCamelCase     :      str       						=						getattr(self       ,  field.name							)
                     if v is not None:
                           __lowerCamelCase     :      Any       						=						v

   def __delitem__(  self  : Tuple       ,  *_lowerCamelCase  : str       ,  **_lowerCamelCase  : Union[str, Any]							):






         '''simple docstring'''



         raise Exception(F"""You cannot use ``__delitem__`` on a {self.__class__.__name__} instance."""							)

   def   _snake_case    (  self  : Optional[int]       ,  *_lowerCamelCase  : Tuple       ,  **_lowerCamelCase  : Optional[int]							):






         '''simple docstring'''



         raise Exception(F"""You cannot use ``setdefault`` on a {self.__class__.__name__} instance."""							)

   def   _snake_case    (  self  : Optional[int]       ,  *_lowerCamelCase  : Any       ,  **_lowerCamelCase  : int							):






         '''simple docstring'''



         raise Exception(F"""You cannot use ``pop`` on a {self.__class__.__name__} instance."""							)

   def   _snake_case    (  self  : str       ,  *_lowerCamelCase  : Union[str, Any]       ,  **_lowerCamelCase  : str							):






         '''simple docstring'''



         raise Exception(F"""You cannot use ``update`` on a {self.__class__.__name__} instance."""							)

   def __getitem__(  self  : int       ,  _lowerCamelCase  : Any							):






         '''simple docstring'''



         if isinstance(__lowerCamelCase       ,  __lowerCamelCase							):
               __lowerCamelCase     :      List[str]       						=						dict(self.items()							)
               return inner_dict[k]
         else:
               return self.to_tuple()[k]

   def __setattr__(  self  : List[str]       ,  _lowerCamelCase  : Tuple       ,  _lowerCamelCase  : Union[str, Any]							):






         '''simple docstring'''



         if name in self.keys() and value is not None:
               # Don't call self.__setitem__ to avoid recursion errors
               super().__setitem__(__lowerCamelCase       ,  __lowerCamelCase							)
         super().__setattr__(__lowerCamelCase       ,  __lowerCamelCase							)

   def __setitem__(  self  : Tuple       ,  _lowerCamelCase  : Tuple       ,  _lowerCamelCase  : List[str]							):






         '''simple docstring'''



         super().__setitem__(__lowerCamelCase       ,  __lowerCamelCase							)
         # Don't call self.__setattr__ to avoid recursion errors
         super().__setattr__(__lowerCamelCase       ,  __lowerCamelCase							)


   def   _snake_case    (  self  : str							):






         '''simple docstring'''



         return tuple(self[k] for k in self.keys()							)



class 							_UpperCamelCase (						lowercase__,lowercase__						):

   '''simple docstring'''







   @classmethod
   def   _snake_case    (  cls  : List[Any]       ,  _lowerCamelCase  : List[str]							):






         '''simple docstring'''



         raise ValueError(
             F"""{value} is not a valid {cls.__name__}, please select one of {list(cls._valueamember_map_.keys()							)}"""							)



class 							_UpperCamelCase (						lowercase__						):

   '''simple docstring'''







   a_				:							Optional[int]    = "longest"
   a_				:							Any    = "max_length"
   a_				:							str    = "do_not_pad"



class 							_UpperCamelCase (						lowercase__						):

   '''simple docstring'''







   a_				:							Optional[Any]    = "pt"
   a_				:							Optional[int]    = "tf"
   a_				:							List[str]    = "np"
   a_				:							Dict    = "jax"



class 							_UpperCamelCase :

   '''simple docstring'''







   def __init__(  self  : Tuple       ,  _lowerCamelCase  : List[ContextManager]							):






         '''simple docstring'''



         __lowerCamelCase     :      Optional[int]       						=						context_managers
         __lowerCamelCase     :      Dict       						=						ExitStack()

   def __enter__(  self  : Dict							):






         '''simple docstring'''



         for context_manager in self.context_managers:
               self.stack.enter_context(__lowerCamelCase							)


   def __exit__(  self  : List[str]       ,  *_lowerCamelCase  : Any       ,  **_lowerCamelCase  : int							):






         '''simple docstring'''



         self.stack.__exit__(*__lowerCamelCase       ,  **__lowerCamelCase							)





def   _UpperCAmelCase       (     UpperCAmelCase      :			List[Any]      ):
      """simple docstring"""




      __lowerCamelCase     :      str       						=						infer_framework(_A      )
      if framework == "tf":
            __lowerCamelCase     :      Union[str, Any]       						=						inspect.signature(model_class.call      )  # TensorFlow models
      elif framework == "pt":
            __lowerCamelCase     :      Union[str, Any]       						=						inspect.signature(model_class.forward      )  # PyTorch models
      else:
            __lowerCamelCase     :      Optional[Any]       						=						inspect.signature(model_class.__call__      )  # Flax models

      for p in signature.parameters:
            if p == "return_loss" and signature.parameters[p].default is True:
                  return True

      return False





def   _UpperCAmelCase       (     UpperCAmelCase      :			Any      ):
      """simple docstring"""




      __lowerCamelCase     :      Any       						=						model_class.__name__
      __lowerCamelCase     :      Optional[Any]       						=						infer_framework(_A      )
      if framework == "tf":
            __lowerCamelCase     :      Optional[int]       						=						inspect.signature(model_class.call      )  # TensorFlow models
      elif framework == "pt":
            __lowerCamelCase     :      Optional[Any]       						=						inspect.signature(model_class.forward      )  # PyTorch models
      else:
            __lowerCamelCase     :      Optional[Any]       						=						inspect.signature(model_class.__call__      )  # Flax models

      if "QuestionAnswering" in model_name:
            return [p for p in signature.parameters if "label" in p or p in ("start_positions", "end_positions")]
      else:
            return [p for p in signature.parameters if "label" in p]





def   _UpperCAmelCase       (     UpperCAmelCase      :			MutableMapping						,	UpperCAmelCase      :			str = ""						,	UpperCAmelCase      :			str = "."      ):
      """simple docstring"""




      def _flatten_dict(UpperCAmelCase      :			Optional[int]						,	UpperCAmelCase      :			Any=""						,	UpperCAmelCase      :			Any="."      ):
            for k, v in d.items():
                  __lowerCamelCase     :      List[str]       						=						str(_A      ) + delimiter + str(_A      ) if parent_key else k
                  if v and isinstance(_A						,	_A      ):
                        yield from flatten_dict(_A						,	_A						,	delimiter=_A      ).items()
                  else:
                        yield key, v

      return dict(_flatten_dict(_A						,	_A						,	_A      )      )





@contextmanager
def   _UpperCAmelCase       (     UpperCAmelCase      :			Dict						,	UpperCAmelCase      :			bool = False      ):
      """simple docstring"""




      if use_temp_dir:
            with tempfile.TemporaryDirectory() as tmp_dir:
                  yield tmp_dir
      else:
            yield working_dir





def   _UpperCAmelCase       (     UpperCAmelCase      :			Optional[int]						,	UpperCAmelCase      :			Optional[int]=None      ):
      """simple docstring"""




      if is_numpy_array(_A      ):
            return np.transpose(_A						,	axes=_A      )
      elif is_torch_tensor(_A      ):
            return array.T if axes is None else array.permute(*_A      )
      elif is_tf_tensor(_A      ):
            import tensorflow as tf

            return tf.transpose(_A						,	perm=_A      )
      elif is_jax_tensor(_A      ):
            return jnp.transpose(_A						,	axes=_A      )
      else:
            raise ValueError(f"""Type not supported for transpose: {type(_A      )}."""      )





def   _UpperCAmelCase       (     UpperCAmelCase      :			Any						,	UpperCAmelCase      :			Any      ):
      """simple docstring"""




      if is_numpy_array(_A      ):
            return np.reshape(_A						,	_A      )
      elif is_torch_tensor(_A      ):
            return array.reshape(*_A      )
      elif is_tf_tensor(_A      ):
            import tensorflow as tf

            return tf.reshape(_A						,	_A      )
      elif is_jax_tensor(_A      ):
            return jnp.reshape(_A						,	_A      )
      else:
            raise ValueError(f"""Type not supported for reshape: {type(_A      )}."""      )





def   _UpperCAmelCase       (     UpperCAmelCase      :			Dict						,	UpperCAmelCase      :			int=None      ):
      """simple docstring"""




      if is_numpy_array(_A      ):
            return np.squeeze(_A						,	axis=_A      )
      elif is_torch_tensor(_A      ):
            return array.squeeze() if axis is None else array.squeeze(dim=_A      )
      elif is_tf_tensor(_A      ):
            import tensorflow as tf

            return tf.squeeze(_A						,	axis=_A      )
      elif is_jax_tensor(_A      ):
            return jnp.squeeze(_A						,	axis=_A      )
      else:
            raise ValueError(f"""Type not supported for squeeze: {type(_A      )}."""      )





def   _UpperCAmelCase       (     UpperCAmelCase      :			Any						,	UpperCAmelCase      :			Union[str, Any]      ):
      """simple docstring"""




      if is_numpy_array(_A      ):
            return np.expand_dims(_A						,	_A      )
      elif is_torch_tensor(_A      ):
            return array.unsqueeze(dim=_A      )
      elif is_tf_tensor(_A      ):
            import tensorflow as tf

            return tf.expand_dims(_A						,	axis=_A      )
      elif is_jax_tensor(_A      ):
            return jnp.expand_dims(_A						,	axis=_A      )
      else:
            raise ValueError(f"""Type not supported for expand_dims: {type(_A      )}."""      )





def   _UpperCAmelCase       (     UpperCAmelCase      :			int      ):
      """simple docstring"""




      if is_numpy_array(_A      ):
            return np.size(_A      )
      elif is_torch_tensor(_A      ):
            return array.numel()
      elif is_tf_tensor(_A      ):
            import tensorflow as tf

            return tf.size(_A      )
      elif is_jax_tensor(_A      ):
            return array.size
      else:
            raise ValueError(f"""Type not supported for expand_dims: {type(_A      )}."""      )





def   _UpperCAmelCase       (     UpperCAmelCase      :			Tuple						,	UpperCAmelCase      :			Tuple      ):
      """simple docstring"""




      for key, value in auto_map.items():
            if isinstance(_A						,	(tuple, list)      ):
                  __lowerCamelCase     :      Optional[Any]       						=						[f"""{repo_id}--{v}""" if (v is not None and "--" not in v) else v for v in value]
            elif value is not None and "--" not in value:
                  __lowerCamelCase     :      Tuple       						=						f"""{repo_id}--{value}"""

      return auto_map





def   _UpperCAmelCase       (     UpperCAmelCase      :			Dict      ):
      """simple docstring"""




      for base_class in inspect.getmro(_A      ):
            __lowerCamelCase     :      Optional[int]       						=						base_class.__module__
            __lowerCamelCase     :      List[str]       						=						base_class.__name__
            if module.startswith("""tensorflow"""      ) or module.startswith("""keras"""      ) or name == "TFPreTrainedModel":
                  return "tf"
            elif module.startswith("""torch"""      ) or name == "PreTrainedModel":
                  return "pt"
            elif module.startswith("""flax"""      ) or module.startswith("""jax"""      ) or name == "FlaxPreTrainedModel":
                  return "flax"
      else:
            raise TypeError(f"""Could not infer framework from class {model_class}."""      )





import re
import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin



class 							_UpperCamelCase (						A						):

   '''simple docstring'''







   a_				:							List[Any]    = ["image_processor", "tokenizer"]
   a_				:							Tuple    = "AutoImageProcessor"
   a_				:							Tuple    = "AutoTokenizer"

   def __init__(  self  : Union[str, Any]       ,  _lowerCamelCase  : List[Any]=None       ,  _lowerCamelCase  : Any=None       ,  **_lowerCamelCase  : List[str]							):






         '''simple docstring'''



         __lowerCamelCase     :      Tuple       						=						None
         if "feature_extractor" in kwargs:
               warnings.warn(
                   """The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"""
                   """ instead."""       ,  _lowerCamelCase       ,  )
               __lowerCamelCase     :      List[Any]       						=						kwargs.pop("""feature_extractor"""							)

         __lowerCamelCase     :      Optional[Any]       						=						image_processor if image_processor is not None else feature_extractor
         if image_processor is None:
               raise ValueError("""You need to specify an `image_processor`."""							)
         if tokenizer is None:
               raise ValueError("""You need to specify a `tokenizer`."""							)

         super().__init__(_lowerCamelCase       ,  _lowerCamelCase							)
         __lowerCamelCase     :      List[Any]       						=						self.image_processor
         __lowerCamelCase     :      Any       						=						False

   def __call__(  self  : Union[str, Any]       ,  *_lowerCamelCase  : str       ,  **_lowerCamelCase  : Dict							):






         '''simple docstring'''



         if self._in_target_context_manager:
               return self.current_processor(*_lowerCamelCase       ,  **_lowerCamelCase							)

         __lowerCamelCase     :      List[str]       						=						kwargs.pop("""images"""       ,  _lowerCamelCase							)
         __lowerCamelCase     :      List[str]       						=						kwargs.pop("""text"""       ,  _lowerCamelCase							)
         if len(_lowerCamelCase							) > 0:
               __lowerCamelCase     :      Tuple       						=						args[0]
               __lowerCamelCase     :      List[Any]       						=						args[1:]

         if images is None and text is None:
               raise ValueError("""You need to specify either an `images` or `text` input to process."""							)

         if images is not None:
               __lowerCamelCase     :      Tuple       						=						self.image_processor(_lowerCamelCase       ,  *_lowerCamelCase       ,  **_lowerCamelCase							)
         if text is not None:
               __lowerCamelCase     :      int       						=						self.tokenizer(_lowerCamelCase       ,  **_lowerCamelCase							)

         if text is None:
               return inputs
         elif images is None:
               return encodings
         else:
               __lowerCamelCase     :      Optional[int]       						=						encodings["""input_ids"""]
               return inputs

   def   _snake_case    (  self  : List[Any]       ,  *_lowerCamelCase  : Tuple       ,  **_lowerCamelCase  : Union[str, Any]							):






         '''simple docstring'''



         return self.tokenizer.batch_decode(*_lowerCamelCase       ,  **_lowerCamelCase							)

   def   _snake_case    (  self  : List[str]       ,  *_lowerCamelCase  : Optional[int]       ,  **_lowerCamelCase  : int							):






         '''simple docstring'''



         return self.tokenizer.decode(*_lowerCamelCase       ,  **_lowerCamelCase							)

   @contextmanager
   def   _snake_case    (  self  : Optional[Any]							):






         '''simple docstring'''



         warnings.warn(
             """`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your """
             """labels by using the argument `text` of the regular `__call__` method (either in the same call as """
             """your images inputs, or in a separate call."""							)
         __lowerCamelCase     :      Any       						=						True
         __lowerCamelCase     :      int       						=						self.tokenizer
         yield
         __lowerCamelCase     :      Dict       						=						self.image_processor
         __lowerCamelCase     :      List[Any]       						=						False

   def   _snake_case    (  self  : List[str]       ,  _lowerCamelCase  : str       ,  _lowerCamelCase  : List[str]=False       ,  _lowerCamelCase  : List[Any]=None							):






         '''simple docstring'''



         if added_vocab is None:
               __lowerCamelCase     :      List[str]       						=						self.tokenizer.get_added_vocab()

         __lowerCamelCase     :      List[Any]       						=						{}

         while tokens:
               __lowerCamelCase     :      Dict       						=						re.search(R"""<s_(.*?)>"""       ,  _lowerCamelCase       ,  re.IGNORECASE							)
               if start_token is None:
                     break
               __lowerCamelCase     :      Dict       						=						start_token.group(1							)
               __lowerCamelCase     :      List[str]       						=						re.search(RF"""</s_{key}>"""       ,  _lowerCamelCase       ,  re.IGNORECASE							)
               __lowerCamelCase     :      Optional[int]       						=						start_token.group()
               if end_token is None:
                     __lowerCamelCase     :      int       						=						tokens.replace(_lowerCamelCase       ,  """"""							)
               else:
                     __lowerCamelCase     :      Dict       						=						end_token.group()
                     __lowerCamelCase     :      Optional[Any]       						=						re.escape(_lowerCamelCase							)
                     __lowerCamelCase     :      List[str]       						=						re.escape(_lowerCamelCase							)
                     __lowerCamelCase     :      Any       						=						re.search(F"""{start_token_escaped}(.*?){end_token_escaped}"""       ,  _lowerCamelCase       ,  re.IGNORECASE							)
                     if content is not None:
                           __lowerCamelCase     :      Union[str, Any]       						=						content.group(1							).strip()
                           if r"<s_" in content and r"</s_" in content:  # non-leaf node
                                 __lowerCamelCase     :      Union[str, Any]       						=						self.tokenajson(_lowerCamelCase       ,  is_inner_value=_lowerCamelCase       ,  added_vocab=_lowerCamelCase							)
                                 if value:
                                       if len(_lowerCamelCase							) == 1:
                                             __lowerCamelCase     :      Optional[int]       						=						value[0]
                                       __lowerCamelCase     :      Union[str, Any]       						=						value
                           else:  # leaf nodes
                                 __lowerCamelCase     :      List[Any]       						=						[]
                                 for leaf in content.split(R"""<sep/>"""							):
                                       __lowerCamelCase     :      Optional[Any]       						=						leaf.strip()
                                       if leaf in added_vocab and leaf[0] == "<" and leaf[-2:] == "/>":
                                             __lowerCamelCase     :      str       						=						leaf[1:-2]  # for categorical special tokens
                                       output[key].append(_lowerCamelCase							)
                                 if len(output[key]							) == 1:
                                       __lowerCamelCase     :      Tuple       						=						output[key][0]

                     __lowerCamelCase     :      Tuple       						=						tokens[tokens.find(_lowerCamelCase							) + len(_lowerCamelCase							) :].strip()
                     if tokens[:6] == r"<sep/>":  # non-leaf nodes
                           return [output] + self.tokenajson(tokens[6:]       ,  is_inner_value=_lowerCamelCase       ,  added_vocab=_lowerCamelCase							)

         if len(_lowerCamelCase							):
               return [output] if is_inner_value else output
         else:
               return [] if is_inner_value else {"text_sequence": tokens}

   @property
   def   _snake_case    (  self  : Tuple							):






         '''simple docstring'''



         warnings.warn(
             """`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."""       ,  _lowerCamelCase       ,  )
         return self.image_processor_class


   @property
   def   _snake_case    (  self  : List[Any]							):






         '''simple docstring'''



         warnings.warn(
             """`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."""       ,  _lowerCamelCase       ,  )
         return self.image_processor



