code: 
  
  
  
  import itertools
  from dataclasses import dataclass
  from io import StringIO
  from typing import Optional
  
  import pyarrow as pa
  
  import datasets
  from datasets.features.features import require_storage_cast
  from datasets.table import table_cast
  
  
  __lowerCamelCase  				=					datasets.utils.logging.get_logger(__name__)
  
  
  
  @dataclass
  class 		_snake_case      (			datasets.BuilderConfig				):
  
  
  
  
  
   """simple docstring"""
  
  
  
   lowerCamelCase_          =			None
   lowerCamelCase_          =			"utf-8"
   lowerCamelCase_          =			None
   lowerCamelCase_          =			1_0 << 2_0  # 10MB
   lowerCamelCase_          =			False
   lowerCamelCase_          =			"line"
  
  
  
  
  
  
  
  class 		_snake_case      (			datasets.ArrowBasedBuilder				):
  
  
  
  
  
   """simple docstring"""
  
  
  
   lowerCamelCase_          =			TextConfig
   def lowercase_		(						self					)	->							List[str]:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     return datasets.DatasetInfo(features=self.config.features					)
   def lowercase_		(						self	,    a					)	->							Union[str, Any]:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     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}'''					)
     _A           =    dl_manager.download_and_extract(self.config.data_files					)
     if isinstance(a	,    (str, list, tuple)					):
       _A           =    data_files
       if isinstance(a	,    a					):
         _A           =    [files]
       _A           =    [dl_manager.iter_files(a					) for file in files]
       return [datasets.SplitGenerator(name=datasets.Split.TRAIN	,    gen_kwargs={'''files''': files}					)]
     _A           =    []
     for split_name, files in data_files.items():
       if isinstance(a	,    a					):
         _A           =    [files]
       _A           =    [dl_manager.iter_files(a					) for file in files]
       splits.append(datasets.SplitGenerator(name=a	,    gen_kwargs={'''files''': files}					)					)
     return splits
   def lowercase_		(						self	,    a					)	->							pa.Table:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     if self.config.features is not None:
       _A           =    self.config.features.arrow_schema
       if all(not require_storage_cast(a					) for feature in self.config.features.values()					):
         # cheaper cast
         _A           =    pa_table.cast(a					)
       else:
         # more expensive cast; allows str <-> int/float or str to Audio for example
         _A           =    table_cast(a	,    a					)
       return pa_table
     else:
       return pa_table.cast(pa.schema({'''text''': pa.string()}					)					)
  
  
  
   def lowercase_		(						self	,    a					)	->							List[str]:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     _A           =    list(self.config.features					) if self.config.features is not None else ['''text''']
     for file_idx, file in enumerate(itertools.chain.from_iterable(a					)					):
       # open in text mode, by default translates universal newlines ("\n", "\r\n" and "\r") into "\n"
       with open(a	,    encoding=self.config.encoding	,    errors=self.config.errors					) as f:
         if self.config.sample_by == "line":
           _A           =    0
           while True:
             _A           =    f.read(self.config.chunksize					)
             if not batch:
               break
             batch += f.readline()  # finish current line
             # StringIO.readlines, by default splits only on "\n" (and keeps line breaks)
             _A           =    StringIO(a					).readlines()
             if not self.config.keep_linebreaks:
               _A           =    [line.rstrip('''\n'''					) for line in batch]
             _A           =    pa.Table.from_arrays([pa.array(a					)]	,    names=a					)
             # 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 (file_idx, batch_idx), self._cast_table(a					)
             batch_idx += 1
         elif self.config.sample_by == "paragraph":
           _A           =    0
           _A           =    ''''''
           while True:
             _A           =    f.read(self.config.chunksize					)
             if not new_batch:
               break
             batch += new_batch
             batch += f.readline()  # finish current line
             _A           =    batch.split('''\n\n'''					)
             _A           =    pa.Table.from_arrays(
                 [pa.array([example for example in batch[:-1] if example]					)]	,    names=a					)
             # 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 (file_idx, batch_idx), self._cast_table(a					)
             batch_idx += 1
             _A           =    batch[-1]
           if batch:
             _A           =    pa.Table.from_arrays([pa.array([batch]					)]	,    names=a					)
             yield (file_idx, batch_idx), self._cast_table(a					)
         elif self.config.sample_by == "document":
           _A           =    f.read()
           _A           =    pa.Table.from_arrays([pa.array([text]					)]	,    names=a					)
           yield file_idx, self._cast_table(a					)
style_context: 
  
  
  
  import argparse
  
  import torch
  
  from transformers import ElectraConfig, ElectraForMaskedLM, ElectraForPreTraining, load_tf_weights_in_electra
  from transformers.utils import logging
  
  
  logging.set_verbosity_info()
  
  
  
  
  def     UpperCAmelCase__ (							__snake_case						,				__snake_case						,				__snake_case						,				__snake_case							)   -> Tuple:
    # Initialise PyTorch model
    _A           =    ElectraConfig.from_json_file(__snake_case							)
    print(F'''Building PyTorch model from configuration: {config}'''							)
  
    if discriminator_or_generator == "discriminator":
      _A           =    ElectraForPreTraining(__snake_case							)
    elif discriminator_or_generator == "generator":
      _A           =    ElectraForMaskedLM(__snake_case							)
    else:
      raise ValueError('''The discriminator_or_generator argument should be either \'discriminator\' or \'generator\''''							)
  
    # Load weights from tf checkpoint
    load_tf_weights_in_electra(
        __snake_case						,				__snake_case						,				__snake_case						,				discriminator_or_generator=__snake_case							)
  
    # Save pytorch-model
    print(F'''Save PyTorch model to {pytorch_dump_path}'''							)
    torch.save(model.state_dict()						,				__snake_case							)
  
  
  if __name__ == "__main__":
      __lowerCamelCase  				=					argparse.ArgumentParser()
      # Required parameters
      parser.add_argument(
          """--tf_checkpoint_path""", default=None, type=str, required=True, help="""Path to the TensorFlow checkpoint path."""
      )
      parser.add_argument(
          """--config_file""",
          default=None,
          type=str,
          required=True,
          help="""The config json file corresponding to the pre-trained model. \nThis specifies the model architecture.""",
      )
      parser.add_argument(
          """--pytorch_dump_path""", default=None, type=str, required=True, help="""Path to the output PyTorch model."""
      )
      parser.add_argument(
          """--discriminator_or_generator""",
          default=None,
          type=str,
          required=True,
          help=(
              """Whether to export the generator or the discriminator. Should be a string, either 'discriminator' or """
              """'generator'."""
          ),
      )
      __lowerCamelCase  				=					parser.parse_args()
      convert_tf_checkpoint_to_pytorch(
          args.tf_checkpoint_path, args.config_file, args.pytorch_dump_path, args.discriminator_or_generator
      )