





"""simple docstring"""





import os
import tempfile
import unittest

from transformers import NezhaConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
       import torch

       from transformers import (
           MODEL_FOR_PRETRAINING_MAPPING,
           NezhaForMaskedLM,
           NezhaForMultipleChoice,
           NezhaForNextSentencePrediction,
           NezhaForPreTraining,
           NezhaForQuestionAnswering,
           NezhaForSequenceClassification,
           NezhaForTokenClassification,
           NezhaModel,
       )
       from transformers.models.nezha.modeling_nezha import NEZHA_PRETRAINED_MODEL_ARCHIVE_LIST

class 		lowercase					:





      def __init__(       self      ,						lowercase      ,						lowercase=13      ,						lowercase=7      ,						lowercase=True      ,						lowercase=True      ,						lowercase=True      ,						lowercase=True      ,						lowercase=99      ,						lowercase=32      ,						lowercase=5      ,						lowercase=4      ,						lowercase=37      ,						lowercase="gelu"      ,						lowercase=0.1      ,						lowercase=0.1      ,						lowercase=128      ,						lowercase=32      ,						lowercase=16      ,						lowercase=2      ,						lowercase=0.02      ,						lowercase=3      ,						lowercase=4      ,						lowercase=None      ,						)		->     int:
            lowerCAmelCase  						=       parent
            lowerCAmelCase  						=       batch_size
            lowerCAmelCase  						=       seq_length
            lowerCAmelCase  						=       is_training
            lowerCAmelCase  						=       use_input_mask
            lowerCAmelCase  						=       use_token_type_ids
            lowerCAmelCase  						=       use_labels
            lowerCAmelCase  						=       vocab_size
            lowerCAmelCase  						=       hidden_size
            lowerCAmelCase  						=       num_hidden_layers
            lowerCAmelCase  						=       num_attention_heads
            lowerCAmelCase  						=       intermediate_size
            lowerCAmelCase  						=       hidden_act
            lowerCAmelCase  						=       hidden_dropout_prob
            lowerCAmelCase  						=       attention_probs_dropout_prob
            lowerCAmelCase  						=       max_position_embeddings
            lowerCAmelCase  						=       type_vocab_size
            lowerCAmelCase  						=       type_sequence_label_size
            lowerCAmelCase  						=       initializer_range
            lowerCAmelCase  						=       num_labels
            lowerCAmelCase  						=       num_choices
            lowerCAmelCase  						=       scope





      def     _snake_case			(       self )		->     Tuple:
            lowerCAmelCase  						=       ids_tensor([self.batch_size, self.seq_length]      ,						self.vocab_size )

            lowerCAmelCase  						=       None
            if self.use_input_mask:
                  lowerCAmelCase  						=       random_attention_mask([self.batch_size, self.seq_length] )

            lowerCAmelCase  						=       None
            if self.use_token_type_ids:
                  lowerCAmelCase  						=       ids_tensor([self.batch_size, self.seq_length]      ,						self.type_vocab_size )

            lowerCAmelCase  						=       None
            lowerCAmelCase  						=       None
            lowerCAmelCase  						=       None
            if self.use_labels:
                  lowerCAmelCase  						=       ids_tensor([self.batch_size]      ,						self.type_sequence_label_size )
                  lowerCAmelCase  						=       ids_tensor([self.batch_size, self.seq_length]      ,						self.num_labels )
                  lowerCAmelCase  						=       ids_tensor([self.batch_size]      ,						self.num_choices )

            lowerCAmelCase  						=       self.get_config()

            return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels





      def     _snake_case			(       self )		->     Optional[Any]:
            return NezhaConfig(
                vocab_size=self.vocab_size      ,						hidden_size=self.hidden_size      ,						num_hidden_layers=self.num_hidden_layers      ,						num_attention_heads=self.num_attention_heads      ,						intermediate_size=self.intermediate_size      ,						hidden_act=self.hidden_act      ,						hidden_dropout_prob=self.hidden_dropout_prob      ,						attention_probs_dropout_prob=self.attention_probs_dropout_prob      ,						max_position_embeddings=self.max_position_embeddings      ,						type_vocab_size=self.type_vocab_size      ,						is_decoder=lowercase      ,						initializer_range=self.initializer_range      ,						)





      def     _snake_case			(       self )		->     List[Any]:
            (
                (
                lowerCAmelCase
            )						,		(
                lowerCAmelCase
            )						,		(
                lowerCAmelCase
            )						,		(
                lowerCAmelCase
            )						,		(
                lowerCAmelCase
            )						,		(
                lowerCAmelCase
            )						,		(
                lowerCAmelCase
            )						,		
            )  						=       self.prepare_config_and_inputs()

            lowerCAmelCase  						=       True
            lowerCAmelCase  						=       floats_tensor([self.batch_size, self.seq_length, self.hidden_size] )
            lowerCAmelCase  						=       ids_tensor([self.batch_size, self.seq_length]      ,						vocab_size=2 )

            return (
                config,
                input_ids,
                token_type_ids,
                input_mask,
                sequence_labels,
                token_labels,
                choice_labels,
                encoder_hidden_states,
                encoder_attention_mask,
            )





      def     _snake_case			(       self      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase )		->     Any:
            lowerCAmelCase  						=       NezhaModel(config=lowercase )
            model.to(lowercase )
            model.eval()
            lowerCAmelCase  						=       model(lowercase      ,						attention_mask=lowercase      ,						token_type_ids=lowercase )
            lowerCAmelCase  						=       model(lowercase      ,						token_type_ids=lowercase )
            lowerCAmelCase  						=       model(lowercase )
            self.parent.assertEqual(result.last_hidden_state.shape      ,						(self.batch_size, self.seq_length, self.hidden_size) )
            self.parent.assertEqual(result.pooler_output.shape      ,						(self.batch_size, self.hidden_size) )





      def     _snake_case			(       self      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						)		->     Any:
            lowerCAmelCase  						=       True
            lowerCAmelCase  						=       NezhaModel(lowercase )
            model.to(lowercase )
            model.eval()
            lowerCAmelCase  						=       model(
                lowercase      ,						attention_mask=lowercase      ,						token_type_ids=lowercase      ,						encoder_hidden_states=lowercase      ,						encoder_attention_mask=lowercase      ,						)
            lowerCAmelCase  						=       model(
                lowercase      ,						attention_mask=lowercase      ,						token_type_ids=lowercase      ,						encoder_hidden_states=lowercase      ,						)
            lowerCAmelCase  						=       model(lowercase      ,						attention_mask=lowercase      ,						token_type_ids=lowercase )
            self.parent.assertEqual(result.last_hidden_state.shape      ,						(self.batch_size, self.seq_length, self.hidden_size) )
            self.parent.assertEqual(result.pooler_output.shape      ,						(self.batch_size, self.hidden_size) )





      def     _snake_case			(       self      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase )		->     Dict:
            lowerCAmelCase  						=       NezhaForMaskedLM(config=lowercase )
            model.to(lowercase )
            model.eval()
            lowerCAmelCase  						=       model(lowercase      ,						attention_mask=lowercase      ,						token_type_ids=lowercase      ,						labels=lowercase )
            self.parent.assertEqual(result.logits.shape      ,						(self.batch_size, self.seq_length, self.vocab_size) )





      def     _snake_case			(       self      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase )		->     List[str]:
            lowerCAmelCase  						=       NezhaForNextSentencePrediction(config=lowercase )
            model.to(lowercase )
            model.eval()
            lowerCAmelCase  						=       model(
                lowercase      ,						attention_mask=lowercase      ,						token_type_ids=lowercase      ,						labels=lowercase      ,						)
            self.parent.assertEqual(result.logits.shape      ,						(self.batch_size, 2) )





      def     _snake_case			(       self      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase )		->     List[Any]:
            lowerCAmelCase  						=       NezhaForPreTraining(config=lowercase )
            model.to(lowercase )
            model.eval()
            lowerCAmelCase  						=       model(
                lowercase      ,						attention_mask=lowercase      ,						token_type_ids=lowercase      ,						labels=lowercase      ,						next_sentence_label=lowercase      ,						)
            self.parent.assertEqual(result.prediction_logits.shape      ,						(self.batch_size, self.seq_length, self.vocab_size) )
            self.parent.assertEqual(result.seq_relationship_logits.shape      ,						(self.batch_size, 2) )





      def     _snake_case			(       self      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase )		->     Any:
            lowerCAmelCase  						=       NezhaForQuestionAnswering(config=lowercase )
            model.to(lowercase )
            model.eval()
            lowerCAmelCase  						=       model(
                lowercase      ,						attention_mask=lowercase      ,						token_type_ids=lowercase      ,						start_positions=lowercase      ,						end_positions=lowercase      ,						)
            self.parent.assertEqual(result.start_logits.shape      ,						(self.batch_size, self.seq_length) )
            self.parent.assertEqual(result.end_logits.shape      ,						(self.batch_size, self.seq_length) )





      def     _snake_case			(       self      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase )		->     Optional[int]:
            lowerCAmelCase  						=       self.num_labels
            lowerCAmelCase  						=       NezhaForSequenceClassification(lowercase )
            model.to(lowercase )
            model.eval()
            lowerCAmelCase  						=       model(lowercase      ,						attention_mask=lowercase      ,						token_type_ids=lowercase      ,						labels=lowercase )
            self.parent.assertEqual(result.logits.shape      ,						(self.batch_size, self.num_labels) )





      def     _snake_case			(       self      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase )		->     List[str]:
            lowerCAmelCase  						=       self.num_labels
            lowerCAmelCase  						=       NezhaForTokenClassification(config=lowercase )
            model.to(lowercase )
            model.eval()
            lowerCAmelCase  						=       model(lowercase      ,						attention_mask=lowercase      ,						token_type_ids=lowercase      ,						labels=lowercase )
            self.parent.assertEqual(result.logits.shape      ,						(self.batch_size, self.seq_length, self.num_labels) )





      def     _snake_case			(       self      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase )		->     Optional[Any]:
            lowerCAmelCase  						=       self.num_choices
            lowerCAmelCase  						=       NezhaForMultipleChoice(config=lowercase )
            model.to(lowercase )
            model.eval()
            lowerCAmelCase  						=       input_ids.unsqueeze(1 ).expand(-1      ,						self.num_choices      ,						-1 ).contiguous()
            lowerCAmelCase  						=       token_type_ids.unsqueeze(1 ).expand(-1      ,						self.num_choices      ,						-1 ).contiguous()
            lowerCAmelCase  						=       input_mask.unsqueeze(1 ).expand(-1      ,						self.num_choices      ,						-1 ).contiguous()
            lowerCAmelCase  						=       model(
                lowercase      ,						attention_mask=lowercase      ,						token_type_ids=lowercase      ,						labels=lowercase      ,						)
            self.parent.assertEqual(result.logits.shape      ,						(self.batch_size, self.num_choices) )





      def     _snake_case			(       self )		->     Union[str, Any]:
            lowerCAmelCase  						=       self.prepare_config_and_inputs()
            (
                (
                lowerCAmelCase
            )						,		(
                lowerCAmelCase
            )						,		(
                lowerCAmelCase
            )						,		(
                lowerCAmelCase
            )						,		(
                lowerCAmelCase
            )						,		(
                lowerCAmelCase
            )						,		(
                lowerCAmelCase
            )						,		
            )  						=       config_and_inputs
            lowerCAmelCase  						=       {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
            return config, inputs_dict







@require_torch
class 		lowercase					(					_UpperCAmelCase     ,  _UpperCAmelCase     ,  _UpperCAmelCase     ,  unittest.TestCase					):
      _SCREAMING_SNAKE_CASE					=      (
          (
              NezhaModel,
              NezhaForMaskedLM,
              NezhaForMultipleChoice,
              NezhaForNextSentencePrediction,
              NezhaForPreTraining,
              NezhaForQuestionAnswering,
              NezhaForSequenceClassification,
              NezhaForTokenClassification,
          )
          if is_torch_available()
          else ()
      )
      _SCREAMING_SNAKE_CASE					=      (
          {
              'feature-extraction': NezhaModel,
              'fill-mask': NezhaForMaskedLM,
              'question-answering': NezhaForQuestionAnswering,
              'text-classification': NezhaForSequenceClassification,
              'token-classification': NezhaForTokenClassification,
              'zero-shot': NezhaForSequenceClassification,
          }
          if is_torch_available()
          else {}
      )
      _SCREAMING_SNAKE_CASE					=      True





      def     _snake_case			(       self      ,						lowercase      ,						lowercase      ,						lowercase=False )		->     Tuple:
            lowerCAmelCase  						=       super()._prepare_for_class(lowercase      ,						lowercase      ,						return_labels=lowercase )

            if return_labels:
                  if model_class in get_values(lowercase ):
                        lowerCAmelCase  						=       torch.zeros(
                            (self.model_tester.batch_size, self.model_tester.seq_length)      ,						dtype=torch.long      ,						device=lowercase )
                        lowerCAmelCase  						=       torch.zeros(
                            self.model_tester.batch_size      ,						dtype=torch.long      ,						device=lowercase )
            return inputs_dict





      def     _snake_case			(       self )		->     Dict:
            lowerCAmelCase  						=       NezhaModelTester(self )
            lowerCAmelCase  						=       ConfigTester(self      ,						config_class=lowercase      ,						hidden_size=37 )





      def     _snake_case			(       self )		->     Tuple:
            self.config_tester.run_common_tests()





      def     _snake_case			(       self )		->     Optional[int]:
            lowerCAmelCase  						=       self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_model(*lowercase )





      def     _snake_case			(       self )		->     Optional[int]:
            lowerCAmelCase  						=       self.model_tester.prepare_config_and_inputs_for_decoder()
            self.model_tester.create_and_check_model_as_decoder(*lowercase )





      def     _snake_case			(       self )		->     Optional[Any]:
            # This regression test was failing with PyTorch < 1.3
            (
                (
                lowerCAmelCase
            )						,		(
                lowerCAmelCase
            )						,		(
                lowerCAmelCase
            )						,		(
                lowerCAmelCase
            )						,		(
                lowerCAmelCase
            )						,		(
                lowerCAmelCase
            )						,		(
                lowerCAmelCase
            )						,		(
                lowerCAmelCase
            )						,		(
                lowerCAmelCase
            )						,		
            )  						=       self.model_tester.prepare_config_and_inputs_for_decoder()

            lowerCAmelCase  						=       None

            self.model_tester.create_and_check_model_as_decoder(
                lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						)





      def     _snake_case			(       self )		->     str:
            lowerCAmelCase  						=       self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_for_masked_lm(*lowercase )





      def     _snake_case			(       self )		->     Tuple:
            lowerCAmelCase  						=       self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_for_multiple_choice(*lowercase )





      def     _snake_case			(       self )		->     int:
            lowerCAmelCase  						=       self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_for_next_sequence_prediction(*lowercase )





      def     _snake_case			(       self )		->     List[Any]:
            lowerCAmelCase  						=       self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_for_pretraining(*lowercase )





      def     _snake_case			(       self )		->     Optional[Any]:
            lowerCAmelCase  						=       self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_for_question_answering(*lowercase )





      def     _snake_case			(       self )		->     Optional[Any]:
            lowerCAmelCase  						=       self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_for_sequence_classification(*lowercase )





      def     _snake_case			(       self )		->     Optional[int]:
            lowerCAmelCase  						=       self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_for_token_classification(*lowercase )





      @slow
      def     _snake_case			(       self )		->     Tuple:
            for model_name in NEZHA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                  lowerCAmelCase  						=       NezhaModel.from_pretrained(lowercase )
                  self.assertIsNotNone(lowercase )





      @slow
      @require_torch_gpu
      def     _snake_case			(       self )		->     int:
            lowerCAmelCase						,		lowerCAmelCase  						=       self.model_tester.prepare_config_and_inputs_for_common()
            for model_class in self.all_model_classes:
                  # NezhaForMultipleChoice behaves incorrectly in JIT environments.
                  if model_class == NezhaForMultipleChoice:
                        return

                  lowerCAmelCase  						=       True
                  lowerCAmelCase  						=       model_class(config=lowercase )

                  lowerCAmelCase  						=       self._prepare_for_class(lowercase      ,						lowercase )
                  lowerCAmelCase  						=       torch.jit.trace(
                      lowercase      ,						(inputs_dict["""input_ids"""].to("""cpu""" ), inputs_dict["""attention_mask"""].to("""cpu""" )) )

                  with tempfile.TemporaryDirectory() as tmp:
                        torch.jit.save(lowercase      ,						os.path.join(lowercase      ,						"""bert.pt""" ) )
                        lowerCAmelCase  						=       torch.jit.load(os.path.join(lowercase      ,						"""bert.pt""" )      ,						map_location=lowercase )
                        loaded(inputs_dict["""input_ids"""].to(lowercase )      ,						inputs_dict["""attention_mask"""].to(lowercase ) )







@require_torch
class 		lowercase					(					unittest.TestCase					):





      @slow
      def     _snake_case			(       self )		->     Tuple:
            lowerCAmelCase  						=       NezhaModel.from_pretrained("""sijunhe/nezha-cn-base""" )
            lowerCAmelCase  						=       torch.tensor([[0, 1, 2, 3, 4, 5]] )
            lowerCAmelCase  						=       torch.tensor([[0, 1, 1, 1, 1, 1]] )
            with torch.no_grad():
                  lowerCAmelCase  						=       model(lowercase      ,						attention_mask=lowercase )[0]
            lowerCAmelCase  						=       torch.Size((1, 6, 768) )
            self.assertEqual(output.shape      ,						lowercase )
            lowerCAmelCase  						=       torch.tensor([[[0.0_685, 0.2_441, 0.1_102], [0.0_600, 0.1_906, 0.1_349], [0.0_221, 0.0_819, 0.0_586]]] )

            self.assertTrue(torch.allclose(output[:, 1:4, 1:4]      ,						lowercase      ,						atol=1e-4 ) )





      @slow
      def     _snake_case			(       self )		->     Optional[int]:
            lowerCAmelCase  						=       NezhaForMaskedLM.from_pretrained("""sijunhe/nezha-cn-base""" )
            lowerCAmelCase  						=       torch.tensor([[0, 1, 2, 3, 4, 5]] )
            lowerCAmelCase  						=       torch.tensor([[1, 1, 1, 1, 1, 1]] )
            with torch.no_grad():
                  lowerCAmelCase  						=       model(lowercase      ,						attention_mask=lowercase )[0]
            lowerCAmelCase  						=       torch.Size((1, 6, 21_128) )
            self.assertEqual(output.shape      ,						lowercase )
            lowerCAmelCase  						=       torch.tensor(
                [[-2.7_939, -1.7_902, -2.2_189], [-2.8_585, -1.8_908, -2.3_723], [-2.6_499, -1.7_750, -2.2_558]] )

            self.assertTrue(torch.allclose(output[:, 1:4, 1:4]      ,						lowercase      ,						atol=1e-4 ) )













"""simple docstring"""





from argparse import ArgumentParser

from ..pipelines import Pipeline, PipelineDataFormat, get_supported_tasks, pipeline
from ..utils import logging
from . import BaseTransformersCLICommand


SCREAMING_SNAKE_CASE__					=   logging.get_logger(__name__)  # pylint: disable=invalid-name


def 			UpperCAmelCase__							(  SCREAMING_SNAKE_CASE     :						str			):







      '''simple docstring'''




      if not path:
            return "pipe"

      for ext in PipelineDataFormat.SUPPORTED_FORMATS:
            if path.endswith(SCREAMING_SNAKE_CASE			):
                  return ext

      raise Exception(
          F'Unable to determine file format from file extension {path}. '
          F'Please provide the format through --format {PipelineDataFormat.SUPPORTED_FORMATS}'			)


def 			UpperCAmelCase__							(  SCREAMING_SNAKE_CASE     :						Optional[Any]			):







      '''simple docstring'''




      lowerCAmelCase  						=       pipeline(
          task=args.task							,						model=args.model if args.model else None							,						config=args.config							,						tokenizer=args.tokenizer							,						device=args.device							,						)
      lowerCAmelCase  						=       try_infer_format_from_ext(args.input			) if args.format == """infer""" else args.format
      lowerCAmelCase  						=       PipelineDataFormat.from_str(
          format=SCREAMING_SNAKE_CASE							,						output_path=args.output							,						input_path=args.input							,						column=args.column if args.column else nlp.default_input_names							,						overwrite=args.overwrite							,						)
      return RunCommand(SCREAMING_SNAKE_CASE							,						SCREAMING_SNAKE_CASE			)






class 		lowercase					(					_UpperCAmelCase					):





      def __init__(       self      ,						lowercase      ,						lowercase )		->     Union[str, Any]:
            lowerCAmelCase  						=       nlp
            lowerCAmelCase  						=       reader





      @staticmethod
      def     _snake_case			(       lowercase )		->     Optional[int]:
            lowerCAmelCase  						=       parser.add_parser("""run"""      ,						help="""Run a pipeline through the CLI""" )
            run_parser.add_argument("""--task"""      ,						choices=get_supported_tasks()      ,						help="""Task to run""" )
            run_parser.add_argument("""--input"""      ,						type=lowercase      ,						help="""Path to the file to use for inference""" )
            run_parser.add_argument("""--output"""      ,						type=lowercase      ,						help="""Path to the file that will be used post to write results.""" )
            run_parser.add_argument("""--model"""      ,						type=lowercase      ,						help="""Name or path to the model to instantiate.""" )
            run_parser.add_argument("""--config"""      ,						type=lowercase      ,						help="""Name or path to the model's config to instantiate.""" )
            run_parser.add_argument(
                """--tokenizer"""      ,						type=lowercase      ,						help="""Name of the tokenizer to use. (default: same as the model name)""" )
            run_parser.add_argument(
                """--column"""      ,						type=lowercase      ,						help="""Name of the column to use as input. (For multi columns input as QA use column1,columns2)"""      ,						)
            run_parser.add_argument(
                """--format"""      ,						type=lowercase      ,						default="""infer"""      ,						choices=PipelineDataFormat.SUPPORTED_FORMATS      ,						help="""Input format to read from"""      ,						)
            run_parser.add_argument(
                """--device"""      ,						type=lowercase      ,						default=-1      ,						help="""Indicate the device to run onto, -1 indicates CPU, >= 0 indicates GPU (default: -1)"""      ,						)
            run_parser.add_argument("""--overwrite"""      ,						action="""store_true"""      ,						help="""Allow overwriting the output file.""" )
            run_parser.set_defaults(func=lowercase )





      def     _snake_case			(       self )		->     int:
            lowerCAmelCase						,		lowerCAmelCase  						=       self._nlp, []

            for entry in self._reader:
                  lowerCAmelCase  						=       nlp(**lowercase ) if self._reader.is_multi_columns else nlp(lowercase )
                  if isinstance(lowercase      ,						lowercase ):
                        outputs.append(lowercase )
                  else:
                        outputs += output

        # Saving data
            if self._nlp.binary_output:
                  lowerCAmelCase  						=       self._reader.save_binary(lowercase )
                  logger.warning(f'Current pipeline requires output to be in binary format, saving at {binary_path}' )
            else:
                  self._reader.save(lowercase )






