



"""simple docstring"""





import re
import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin



class    _lowerCAmelCase    (				_A		):





  """simple docstring"""






  _lowerCamelCase			  =       ['''image_processor''', '''tokenizer''']
  _lowerCamelCase			  =       '''AutoImageProcessor'''
  _lowerCamelCase			  =       '''AutoTokenizer'''





  def __init__(					self							,    _lowercase=None							,    _lowercase=None							,    **_lowercase   ) ->						Union[str, Any]:







        '''simple docstring'''

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

        snake_case_   : int						=			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__(UpperCamelCase__							,    UpperCamelCase__   )
        snake_case_   : Optional[Any]						=			self.image_processor
        snake_case_   : Any						=			False





  def __call__(					self							,    *_lowercase							,    **_lowercase   ) ->						Any:







        '''simple docstring'''

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

        snake_case_   : Dict						=			kwargs.pop("""images"""							,    UpperCamelCase__   )
        snake_case_   : Any						=			kwargs.pop("""text"""							,    UpperCamelCase__   )
        if len(UpperCamelCase__   ) > 0:
              snake_case_   : List[Any]						=			args[0]
              snake_case_   : Tuple						=			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:
              snake_case_   : Any						=			self.image_processor(UpperCamelCase__							,    *UpperCamelCase__							,    **UpperCamelCase__   )
        if text is not None:
              snake_case_   : List[str]						=			self.tokenizer(UpperCamelCase__							,    **UpperCamelCase__   )

        if text is None:
              return inputs
        elif images is None:
              return encodings
        else:
              snake_case_   : List[str]						=			encodings["""input_ids"""]
              return inputs





  def    UpperCAmelCase__							(					self							,    *_lowercase							,    **_lowercase   ) ->						List[Any]:







        '''simple docstring'''

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





  def    UpperCAmelCase__							(					self							,    *_lowercase							,    **_lowercase   ) ->						Any:







        '''simple docstring'''

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





  @contextmanager
  def    UpperCAmelCase__							(					self   ) ->						Dict:







        '''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."""   )
        snake_case_   : Optional[Any]						=			True
        snake_case_   : Optional[Any]						=			self.tokenizer
        yield
        snake_case_   : List[Any]						=			self.image_processor
        snake_case_   : Any						=			False





  def    UpperCAmelCase__							(					self							,    _lowercase							,    _lowercase=False							,    _lowercase=None   ) ->						Optional[Any]:







        '''simple docstring'''

        if added_vocab is None:
              snake_case_   : Tuple						=			self.tokenizer.get_added_vocab()

        snake_case_   : Optional[Any]						=			{}

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

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

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





  @property
  def    UpperCAmelCase__							(					self   ) ->						Tuple:







        '''simple docstring'''

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





  @property
  def    UpperCAmelCase__							(					self   ) ->						Tuple:







        '''simple docstring'''

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






"""simple docstring"""





from .data_collator import (
    DataCollatorForLanguageModeling,
    DataCollatorForPermutationLanguageModeling,
    DataCollatorForSeqaSeq,
    DataCollatorForSOP,
    DataCollatorForTokenClassification,
    DataCollatorForWholeWordMask,
    DataCollatorWithPadding,
    DefaultDataCollator,
    default_data_collator,
)
from .metrics import glue_compute_metrics, xnli_compute_metrics
from .processors import (
    DataProcessor,
    InputExample,
    InputFeatures,
    SingleSentenceClassificationProcessor,
    SquadExample,
    SquadFeatures,
    SquadVaProcessor,
    SquadVaProcessor,
    glue_convert_examples_to_features,
    glue_output_modes,
    glue_processors,
    glue_tasks_num_labels,
    squad_convert_examples_to_features,
    xnli_output_modes,
    xnli_processors,
    xnli_tasks_num_labels,
)

