"""simple docstring"""




import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from .tokenization_electra import ElectraTokenizer


_a      :		List[Any]           =   {'vocab_file': 'vocab.txt', 'tokenizer_file': 'tokenizer.json'}

_a      :		Union[str, Any]           =   {
    'vocab_file': {
        'google/electra-small-generator': (
            'https://huggingface.co/google/electra-small-generator/resolve/main/vocab.txt'
        ),
        'google/electra-base-generator': 'https://huggingface.co/google/electra-base-generator/resolve/main/vocab.txt',
        'google/electra-large-generator': (
            'https://huggingface.co/google/electra-large-generator/resolve/main/vocab.txt'
        ),
        'google/electra-small-discriminator': (
            'https://huggingface.co/google/electra-small-discriminator/resolve/main/vocab.txt'
        ),
        'google/electra-base-discriminator': (
            'https://huggingface.co/google/electra-base-discriminator/resolve/main/vocab.txt'
        ),
        'google/electra-large-discriminator': (
            'https://huggingface.co/google/electra-large-discriminator/resolve/main/vocab.txt'
        ),
    },
    'tokenizer_file': {
        'google/electra-small-generator': (
            'https://huggingface.co/google/electra-small-generator/resolve/main/tokenizer.json'
        ),
        'google/electra-base-generator': (
            'https://huggingface.co/google/electra-base-generator/resolve/main/tokenizer.json'
        ),
        'google/electra-large-generator': (
            'https://huggingface.co/google/electra-large-generator/resolve/main/tokenizer.json'
        ),
        'google/electra-small-discriminator': (
            'https://huggingface.co/google/electra-small-discriminator/resolve/main/tokenizer.json'
        ),
        'google/electra-base-discriminator': (
            'https://huggingface.co/google/electra-base-discriminator/resolve/main/tokenizer.json'
        ),
        'google/electra-large-discriminator': (
            'https://huggingface.co/google/electra-large-discriminator/resolve/main/tokenizer.json'
        ),
    },
}

_a      :		Optional[Any]           =   {
    'google/electra-small-generator': 512,
    'google/electra-base-generator': 512,
    'google/electra-large-generator': 512,
    'google/electra-small-discriminator': 512,
    'google/electra-base-discriminator': 512,
    'google/electra-large-discriminator': 512,
}

_a      :		Any           =   {
    'google/electra-small-generator': {'do_lower_case': True},
    'google/electra-base-generator': {'do_lower_case': True},
    'google/electra-large-generator': {'do_lower_case': True},
    'google/electra-small-discriminator': {'do_lower_case': True},
    'google/electra-base-discriminator': {'do_lower_case': True},
    'google/electra-large-discriminator': {'do_lower_case': True},
}
class 						__A							( SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:			Tuple							=		VOCAB_FILES_NAMES
     _UpperCamelCase							:			List[Any]							=		PRETRAINED_VOCAB_FILES_MAP
     _UpperCamelCase							:			List[Any]							=		PRETRAINED_INIT_CONFIGURATION
     _UpperCamelCase							:			Union[str, Any]							=		PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     _UpperCamelCase							:			Optional[Any]							=		ElectraTokenizer






     def __init__(		self				,     a__=None				,     a__=None				,     a__=True				,     a__="[UNK]"				,     a__="[SEP]"				,     a__="[PAD]"				,     a__="[CLS]"				,     a__="[MASK]"				,     a__=True				,     a__=None				,     **a__				,     ):
       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__				,     **a__				,     )

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

       _lowerCAmelCase						:       List[str]  			=     do_lower_case






     def     __A  (		self				,     a__				,     a__=None  ):
       _lowerCAmelCase						:       int  			=     [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     __A  (		self				,     a__				,     a__ = None  ):
       _lowerCAmelCase						:       List[str]  			=     [self.sep_token_id]
       _lowerCAmelCase						:       Any  			=     [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     __A  (		self				,     a__				,     a__ = None  ):
       _lowerCAmelCase						:       Optional[Any]  			=     self._tokenizer.model.save(a__				,     name=a__  )
       return tuple(a__  )





"""simple docstring"""




import itertools
from dataclasses import dataclass
from typing import List, Optional

import pyarrow as pa
import pyarrow.parquet as pq

import datasets
from datasets.table import table_cast


_a      :		Dict           =   datasets.utils.logging.get_logger(__name__)
@dataclass
class 						__A							( datasets.BuilderConfig		):
     _UpperCamelCase							:			int							=		10_000
     _UpperCamelCase							:			Optional[List[str]]							=		None
     _UpperCamelCase							:			Optional[datasets.Features]							=		None







class 						__A							( datasets.ArrowBasedBuilder		):
     _UpperCamelCase							:			List[str]							=		ParquetConfig






     def     __A  (		self  ):
       return datasets.DatasetInfo(features=self.config.features  )






     def     __A  (		self				,     a__  ):
       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}"  )
       _lowerCAmelCase						:       Optional[Any]  			=     dl_manager.download_and_extract(self.config.data_files  )
       if isinstance(a__				,     (str, list, tuple)  ):
         _lowerCAmelCase						:       Any  			=     data_files
         if isinstance(a__				,     a__  ):
           _lowerCAmelCase						:       Tuple  			=     [files]
         # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
         _lowerCAmelCase						:       Any  			=     [dl_manager.iter_files(a__  ) for file in files]
         return [datasets.SplitGenerator(name=datasets.Split.TRAIN				,     gen_kwargs={"""files""": files}  )]
       _lowerCAmelCase						:       Optional[Any]  			=     []
       for split_name, files in data_files.items():
         if isinstance(a__				,     a__  ):
           _lowerCAmelCase						:       Dict  			=     [files]
         # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
         _lowerCAmelCase						:       Tuple  			=     [dl_manager.iter_files(a__  ) 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(a__  ):
             with open(a__				,     """rb"""  ) as f:
               _lowerCAmelCase						:       Optional[Any]  			=     datasets.Features.from_arrow_schema(pq.read_schema(a__  )  )
             break
         splits.append(datasets.SplitGenerator(name=a__				,     gen_kwargs={"""files""": files}  )  )
       return splits






     def     __A  (		self				,     a__  ):
       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
         _lowerCAmelCase						:       Optional[int]  			=     table_cast(a__				,     self.info.features.arrow_schema  )
       return pa_table






     def     __A  (		self				,     a__  ):
       _lowerCAmelCase						:       Optional[int]  			=     self.info.features.arrow_schema if self.info.features is not None else None
       if self.info.features is not None and self.config.columns is not None:
         if sorted(field.name for field in schema  ) != sorted(self.config.columns  ):
           raise ValueError(
               F"Tried to load parquet data with columns '{self.config.columns}' with mismatching features '{self.info.features}'"  )
       for file_idx, file in enumerate(itertools.chain.from_iterable(a__  )  ):
         with open(a__				,     """rb"""  ) as f:
           _lowerCAmelCase						:       Tuple  			=     pq.ParquetFile(a__  )
           try:
             for batch_idx, record_batch in enumerate(
                 parquet_file.iter_batches(batch_size=self.config.batch_size				,     columns=self.config.columns  )  ):
               _lowerCAmelCase						:       Any  			=     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(a__  )
           except ValueError as e:
             logger.error(F"Failed to read file '{file}' with error {type(a__  )}: {e}"  )
             raise




