


import itertools
from dataclasses import dataclass
from typing import Optional

import pyarrow as pa

import datasets
from datasets.table import table_cast


UpperCAmelCase__            =							datasets.utils.logging.get_logger(__name__)







@dataclass
class 				lowerCamelCase__       (	datasets.BuilderConfig):
     SCREAMING_SNAKE_CASE__				      =      None







class 				lowerCamelCase__       (	datasets.ArrowBasedBuilder):
     SCREAMING_SNAKE_CASE__				      =      ArrowConfig





     def 					__A (self	)					->       Union[str, Any]:
      return datasets.DatasetInfo(features=self.config.features	)





     def 					__A (self		,					UpperCAmelCase	)					->       Any:
      if not self.config.data_files:
       raise ValueError(f"At least one data file must be specified, but got data_files={self.config.data_files}"	)
      _lowercase											=dl_manager.download_and_extract(self.config.data_files	)
      if isinstance(UpperCAmelCase		,					(str, list, tuple)	):
       _lowercase											=data_files
       if isinstance(UpperCAmelCase		,					UpperCAmelCase	):
        _lowercase											=[files]
       # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
       _lowercase											=[dl_manager.iter_files(UpperCAmelCase	) for file in files]
       return [datasets.SplitGenerator(name=datasets.Split.TRAIN		,					gen_kwargs={'''files''': files}	)]
      _lowercase											=[]
      for split_name, files in data_files.items():
       if isinstance(UpperCAmelCase		,					UpperCAmelCase	):
        _lowercase											=[files]
       # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
       _lowercase											=[dl_manager.iter_files(UpperCAmelCase	) for file in files]
       # Infer features is they are stoed in the arrow schema
       if self.info.features is None:
        for file in itertools.chain.from_iterable(UpperCAmelCase	):
         with open(UpperCAmelCase		,					'''rb'''	) as f:
          _lowercase											=datasets.Features.from_arrow_schema(pa.ipc.open_stream(UpperCAmelCase	).schema	)
         break
       splits.append(datasets.SplitGenerator(name=UpperCAmelCase		,					gen_kwargs={'''files''': files}	)	)
      return splits





     def 					__A (self		,					UpperCAmelCase	)					->       pa.Table:
      if self.info.features is not None:
       # more expensive cast to support nested features with keys in a different order
       # allows str <-> int/float or str to Audio for example
       _lowercase											=table_cast(UpperCAmelCase		,					self.info.features.arrow_schema	)
      return pa_table





     def 					__A (self		,					UpperCAmelCase	)					->       Union[str, Any]:
      for file_idx, file in enumerate(itertools.chain.from_iterable(UpperCAmelCase	)	):
       with open(UpperCAmelCase		,					'''rb'''	) as f:
        try:
         for batch_idx, record_batch in enumerate(pa.ipc.open_stream(UpperCAmelCase	)	):
          _lowercase											=pa.Table.from_batches([record_batch]	)
          # Uncomment for debugging (will print the Arrow table size and elements)
          # logger.warning(f"pa_table: {pa_table} num rows: {pa_table.num_rows}")
          # logger.warning('\n'.join(str(pa_table.slice(i, 1).to_pydict()) for i in range(pa_table.num_rows)))
          yield f"{file_idx}_{batch_idx}", self._cast_table(UpperCAmelCase	)
        except ValueError as e:
         logger.error(f"Failed to read file '{file}' with error {type(UpperCAmelCase	)}: {e}"	)
         raise





from collections import OrderedDict
from typing import TYPE_CHECKING, Any, Mapping, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


if TYPE_CHECKING:
  from ... import FeatureExtractionMixin, PreTrainedTokenizerBase, TensorType


UpperCAmelCase__            =							logging.get_logger(__name__)

UpperCAmelCase__            =							{
    '''microsoft/deberta-base''': '''https://huggingface.co/microsoft/deberta-base/resolve/main/config.json''',
    '''microsoft/deberta-large''': '''https://huggingface.co/microsoft/deberta-large/resolve/main/config.json''',
    '''microsoft/deberta-xlarge''': '''https://huggingface.co/microsoft/deberta-xlarge/resolve/main/config.json''',
    '''microsoft/deberta-base-mnli''': '''https://huggingface.co/microsoft/deberta-base-mnli/resolve/main/config.json''',
    '''microsoft/deberta-large-mnli''': '''https://huggingface.co/microsoft/deberta-large-mnli/resolve/main/config.json''',
    '''microsoft/deberta-xlarge-mnli''': '''https://huggingface.co/microsoft/deberta-xlarge-mnli/resolve/main/config.json''',
}







class 				lowerCamelCase__       (	lowerCAmelCase):
     SCREAMING_SNAKE_CASE__				      =      '''deberta'''





     def __init__(self		,					UpperCAmelCase=5_0_2_6_5		,					UpperCAmelCase=7_6_8		,					UpperCAmelCase=1_2		,					UpperCAmelCase=1_2		,					UpperCAmelCase=3_0_7_2		,					UpperCAmelCase="gelu"		,					UpperCAmelCase=0.1		,					UpperCAmelCase=0.1		,					UpperCAmelCase=5_1_2		,					UpperCAmelCase=0		,					UpperCAmelCase=0.02		,					UpperCAmelCase=1e-7		,					UpperCAmelCase=False		,					UpperCAmelCase=-1		,					UpperCAmelCase=0		,					UpperCAmelCase=True		,					UpperCAmelCase=None		,					UpperCAmelCase=0		,					UpperCAmelCase="gelu"		,					**UpperCAmelCase		,					)					->       Dict:
      super().__init__(**UpperCAmelCase	)

      _lowercase											=hidden_size
      _lowercase											=num_hidden_layers
      _lowercase											=num_attention_heads
      _lowercase											=intermediate_size
      _lowercase											=hidden_act
      _lowercase											=hidden_dropout_prob
      _lowercase											=attention_probs_dropout_prob
      _lowercase											=max_position_embeddings
      _lowercase											=type_vocab_size
      _lowercase											=initializer_range
      _lowercase											=relative_attention
      _lowercase											=max_relative_positions
      _lowercase											=pad_token_id
      _lowercase											=position_biased_input

      # Backwards compatibility
      if type(UpperCAmelCase	) == str:
       _lowercase											=[x.strip() for x in pos_att_type.lower().split('''|'''	)]

      _lowercase											=pos_att_type
      _lowercase											=vocab_size
      _lowercase											=layer_norm_eps

      _lowercase											=kwargs.get('''pooler_hidden_size'''		,					UpperCAmelCase	)
      _lowercase											=pooler_dropout
      _lowercase											=pooler_hidden_act







class 				lowerCamelCase__       (	lowerCAmelCase):





     @property
     def 					__A (self	)					->       Mapping[str, Mapping[int, str]]:
      if self.task == "multiple-choice":
       _lowercase											={0: '''batch''', 1: '''choice''', 2: '''sequence'''}
      else:
       _lowercase											={0: '''batch''', 1: '''sequence'''}
      if self._config.type_vocab_size > 0:
       return OrderedDict(
           [('''input_ids''', dynamic_axis), ('''attention_mask''', dynamic_axis), ('''token_type_ids''', dynamic_axis)]	)
      else:
       return OrderedDict([('''input_ids''', dynamic_axis), ('''attention_mask''', dynamic_axis)]	)





     @property
     def 					__A (self	)					->       int:
      return 1_2





     def 					__A (self		,					UpperCAmelCase		,					UpperCAmelCase = -1		,					UpperCAmelCase = -1		,					UpperCAmelCase = -1		,					UpperCAmelCase = False		,					UpperCAmelCase = None		,					UpperCAmelCase = 3		,					UpperCAmelCase = 4_0		,					UpperCAmelCase = 4_0		,					UpperCAmelCase = None		,					)					->       Mapping[str, Any]:
      _lowercase											=super().generate_dummy_inputs(preprocessor=UpperCAmelCase		,					framework=UpperCAmelCase	)
      if self._config.type_vocab_size == 0 and "token_type_ids" in dummy_inputs:
       del dummy_inputs["token_type_ids"]
      return dummy_inputs

