






from __future__ import annotations

import os
import tempfile
import unittest

from transformers import ConvBertConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
 import tensorflow as tf

 from transformers import (
     TFConvBertForMaskedLM,
     TFConvBertForMultipleChoice,
     TFConvBertForQuestionAnswering,
     TFConvBertForSequenceClassification,
     TFConvBertForTokenClassification,
     TFConvBertModel,
 )


class 						_a       :






  """simple docstring"""





  def __init__(     self		,		_UpperCAmelCase		,		_UpperCAmelCase=13		,		_UpperCAmelCase=7		,		_UpperCAmelCase=True		,		_UpperCAmelCase=True		,		_UpperCAmelCase=True		,		_UpperCAmelCase=True		,		_UpperCAmelCase=99		,		_UpperCAmelCase=32		,		_UpperCAmelCase=2		,		_UpperCAmelCase=4		,		_UpperCAmelCase=37		,		_UpperCAmelCase="gelu"		,		_UpperCAmelCase=0.1		,		_UpperCAmelCase=0.1		,		_UpperCAmelCase=512		,		_UpperCAmelCase=16		,		_UpperCAmelCase=2		,		_UpperCAmelCase=0.0_2		,		_UpperCAmelCase=3		,		_UpperCAmelCase=4		,		_UpperCAmelCase=None		,		)			-> str:
     UpperCamelCase_									=     parent
     UpperCamelCase_									=     13
     UpperCamelCase_									=     7
     UpperCamelCase_									=     True
     UpperCamelCase_									=     True
     UpperCamelCase_									=     True
     UpperCamelCase_									=     True
     UpperCamelCase_									=     99
     UpperCamelCase_									=     384
     UpperCamelCase_									=     2
     UpperCamelCase_									=     4
     UpperCamelCase_									=     37
     UpperCamelCase_									=     'gelu'
     UpperCamelCase_									=     0.1
     UpperCamelCase_									=     0.1
     UpperCamelCase_									=     512
     UpperCamelCase_									=     16
     UpperCamelCase_									=     2
     UpperCamelCase_									=     0.0_2
     UpperCamelCase_									=     3
     UpperCamelCase_									=     4
     UpperCamelCase_									=     128
     UpperCamelCase_									=     2
     UpperCamelCase_									=     9
     UpperCamelCase_									=     1
     UpperCamelCase_									=     None




  def    _UpperCAmelCase     (     self )			-> Union[str, Any]:
     UpperCamelCase_									=     ids_tensor([self.batch_size, self.seq_length]		,		self.vocab_size )

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

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

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

     UpperCamelCase_									=     ConvBertConfig(
         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		,		initializer_range=self.initializer_range		,		return_dict=_UpperCAmelCase		,		)

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




  def    _UpperCAmelCase     (     self		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase )			-> List[Any]:
     UpperCamelCase_									=     TFConvBertModel(config=_UpperCAmelCase )
     UpperCamelCase_									=     {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}

     UpperCamelCase_									=     [input_ids, input_mask]
     UpperCamelCase_									=     model(_UpperCAmelCase )

     UpperCamelCase_									=     model(_UpperCAmelCase )

     self.parent.assertEqual(result.last_hidden_state.shape		,		(self.batch_size, self.seq_length, self.hidden_size) )




  def    _UpperCAmelCase     (     self		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase )			-> str:
     UpperCamelCase_									=     TFConvBertForMaskedLM(config=_UpperCAmelCase )
     UpperCamelCase_									=     {
         'input_ids': input_ids,
         'attention_mask': input_mask,
         'token_type_ids': token_type_ids,
     }
     UpperCamelCase_									=     model(_UpperCAmelCase )
     self.parent.assertEqual(result.logits.shape		,		(self.batch_size, self.seq_length, self.vocab_size) )




  def    _UpperCAmelCase     (     self		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase )			-> List[str]:
     UpperCamelCase_									=     self.num_labels
     UpperCamelCase_									=     TFConvBertForSequenceClassification(config=_UpperCAmelCase )
     UpperCamelCase_									=     {
         'input_ids': input_ids,
         'attention_mask': input_mask,
         'token_type_ids': token_type_ids,
     }

     UpperCamelCase_									=     model(_UpperCAmelCase )
     self.parent.assertEqual(result.logits.shape		,		(self.batch_size, self.num_labels) )




  def    _UpperCAmelCase     (     self		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase )			-> Dict:
     UpperCamelCase_									=     self.num_choices
     UpperCamelCase_									=     TFConvBertForMultipleChoice(config=_UpperCAmelCase )
     UpperCamelCase_									=     tf.tile(tf.expand_dims(_UpperCAmelCase		,		1 )		,		(1, self.num_choices, 1) )
     UpperCamelCase_									=     tf.tile(tf.expand_dims(_UpperCAmelCase		,		1 )		,		(1, self.num_choices, 1) )
     UpperCamelCase_									=     tf.tile(tf.expand_dims(_UpperCAmelCase		,		1 )		,		(1, self.num_choices, 1) )
     UpperCamelCase_									=     {
         'input_ids': multiple_choice_inputs_ids,
         'attention_mask': multiple_choice_input_mask,
         'token_type_ids': multiple_choice_token_type_ids,
     }
     UpperCamelCase_									=     model(_UpperCAmelCase )
     self.parent.assertEqual(result.logits.shape		,		(self.batch_size, self.num_choices) )




  def    _UpperCAmelCase     (     self		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase )			-> Union[str, Any]:
     UpperCamelCase_									=     self.num_labels
     UpperCamelCase_									=     TFConvBertForTokenClassification(config=_UpperCAmelCase )
     UpperCamelCase_									=     {
         'input_ids': input_ids,
         'attention_mask': input_mask,
         'token_type_ids': token_type_ids,
     }
     UpperCamelCase_									=     model(_UpperCAmelCase )
     self.parent.assertEqual(result.logits.shape		,		(self.batch_size, self.seq_length, self.num_labels) )




  def    _UpperCAmelCase     (     self		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase )			-> Union[str, Any]:
     UpperCamelCase_									=     TFConvBertForQuestionAnswering(config=_UpperCAmelCase )
     UpperCamelCase_									=     {
         'input_ids': input_ids,
         'attention_mask': input_mask,
         'token_type_ids': token_type_ids,
     }

     UpperCamelCase_									=     model(_UpperCAmelCase )
     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    _UpperCAmelCase     (     self )			-> Optional[Any]:
     UpperCamelCase_									=     self.prepare_config_and_inputs()
     (
         (
         UpperCamelCase_
     )		,      (
         UpperCamelCase_
     )		,      (
         UpperCamelCase_
     )		,      (
         UpperCamelCase_
     )		,      (
         UpperCamelCase_
     )		,      (
         UpperCamelCase_
     )		,      (
         UpperCamelCase_
     )		,      
     )									=     config_and_inputs
     UpperCamelCase_									=     {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
     return config, inputs_dict




@require_tf
class 						_a       (  UpperCAmelCase__						,       UpperCAmelCase__						,       unittest.TestCase    ):






  """simple docstring"""





  A_						=   (
      (
          TFConvBertModel,
          TFConvBertForMaskedLM,
          TFConvBertForQuestionAnswering,
          TFConvBertForSequenceClassification,
          TFConvBertForTokenClassification,
          TFConvBertForMultipleChoice,
      )
      if is_tf_available()
      else ()
  )
  A_						=   (
      {
          """feature-extraction""": TFConvBertModel,
          """fill-mask""": TFConvBertForMaskedLM,
          """question-answering""": TFConvBertForQuestionAnswering,
          """text-classification""": TFConvBertForSequenceClassification,
          """token-classification""": TFConvBertForTokenClassification,
          """zero-shot""": TFConvBertForSequenceClassification,
      }
      if is_tf_available()
      else {}
  )
  A_						=   False
  A_						=   False
  A_						=   False




  def    _UpperCAmelCase     (     self )			-> Union[str, Any]:
     UpperCamelCase_									=     TFConvBertModelTester(self )
     UpperCamelCase_									=     ConfigTester(self		,		config_class=_UpperCAmelCase		,		hidden_size=37 )




  def    _UpperCAmelCase     (     self )			-> str:
     self.config_tester.run_common_tests()




  def    _UpperCAmelCase     (     self )			-> Tuple:
     UpperCamelCase_									=     self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_model(*_UpperCAmelCase )




  def    _UpperCAmelCase     (     self )			-> Union[str, Any]:
     UpperCamelCase_									=     self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_masked_lm(*_UpperCAmelCase )




  def    _UpperCAmelCase     (     self )			-> List[Any]:
     UpperCamelCase_									=     self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_multiple_choice(*_UpperCAmelCase )




  def    _UpperCAmelCase     (     self )			-> Optional[int]:
     UpperCamelCase_									=     self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_question_answering(*_UpperCAmelCase )




  def    _UpperCAmelCase     (     self )			-> Optional[int]:
     UpperCamelCase_									=     self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_sequence_classification(*_UpperCAmelCase )




  def    _UpperCAmelCase     (     self )			-> int:
     UpperCamelCase_									=     self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_token_classification(*_UpperCAmelCase )




  @slow
  def    _UpperCAmelCase     (     self )			-> Any:
     UpperCamelCase_		,      UpperCamelCase_									=     self.model_tester.prepare_config_and_inputs_for_common()
     UpperCamelCase_									=     True
     UpperCamelCase_									=     True

     if hasattr(_UpperCAmelCase		,		'use_cache' ):
        UpperCamelCase_									=     True

     UpperCamelCase_									=     getattr(self.model_tester		,		'encoder_seq_length'		,		self.model_tester.seq_length )
     UpperCamelCase_									=     getattr(self.model_tester		,		'key_length'		,		_UpperCAmelCase )

     for model_class in self.all_model_classes:
        UpperCamelCase_									=     self._prepare_for_class(_UpperCAmelCase		,		_UpperCAmelCase )
        UpperCamelCase_									=     model_class(_UpperCAmelCase )
        UpperCamelCase_									=     len(model(_UpperCAmelCase ) )

        with tempfile.TemporaryDirectory() as tmpdirname:
           model.save_pretrained(_UpperCAmelCase		,		saved_model=_UpperCAmelCase )
           UpperCamelCase_									=     os.path.join(_UpperCAmelCase		,		'saved_model'		,		'1' )
           UpperCamelCase_									=     tf.keras.models.load_model(_UpperCAmelCase )
           UpperCamelCase_									=     model(_UpperCAmelCase )

           if self.is_encoder_decoder:
              UpperCamelCase_									=     outputs['encoder_hidden_states']
              UpperCamelCase_									=     outputs['encoder_attentions']
           else:
              UpperCamelCase_									=     outputs['hidden_states']
              UpperCamelCase_									=     outputs['attentions']

           self.assertEqual(len(_UpperCAmelCase )		,		_UpperCAmelCase )

           UpperCamelCase_									=     getattr(
               self.model_tester		,		'expected_num_hidden_layers'		,		self.model_tester.num_hidden_layers + 1 )

           self.assertEqual(len(_UpperCAmelCase )		,		_UpperCAmelCase )
           self.assertListEqual(
               list(output_hidden_states[0].shape[-2:] )		,		[self.model_tester.seq_length, self.model_tester.hidden_size]		,		)

           self.assertEqual(len(_UpperCAmelCase )		,		self.model_tester.num_hidden_layers )
           self.assertListEqual(
               list(output_attentions[0].shape[-3:] )		,		[self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]		,		)




  @slow
  def    _UpperCAmelCase     (     self )			-> Tuple:
     UpperCamelCase_									=     TFConvBertModel.from_pretrained('YituTech/conv-bert-base' )
     self.assertIsNotNone(_UpperCAmelCase )




  def    _UpperCAmelCase     (     self )			-> Any:
     UpperCamelCase_		,      UpperCamelCase_									=     self.model_tester.prepare_config_and_inputs_for_common()
     UpperCamelCase_									=     True
     UpperCamelCase_									=     getattr(self.model_tester		,		'decoder_seq_length'		,		self.model_tester.seq_length )
     UpperCamelCase_									=     getattr(self.model_tester		,		'encoder_seq_length'		,		self.model_tester.seq_length )
     UpperCamelCase_									=     getattr(self.model_tester		,		'key_length'		,		_UpperCAmelCase )
     UpperCamelCase_									=     getattr(self.model_tester		,		'key_length'		,		_UpperCAmelCase )

     def check_decoder_attentions_output(_UpperCAmelCase ):
        UpperCamelCase_									=     len(_UpperCAmelCase )
        self.assertEqual(out_len % 2		,		0 )
        UpperCamelCase_									=     outputs.decoder_attentions
        self.assertEqual(len(_UpperCAmelCase )		,		self.model_tester.num_hidden_layers )
        self.assertListEqual(
            list(decoder_attentions[0].shape[-3:] )		,		[self.model_tester.num_attention_heads / 2, decoder_seq_length, decoder_key_length]		,		)

     def check_encoder_attentions_output(_UpperCAmelCase ):
        UpperCamelCase_									=     [
            t.numpy() for t in (outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions)
        ]
        self.assertEqual(len(_UpperCAmelCase )		,		self.model_tester.num_hidden_layers )
        self.assertListEqual(
            list(attentions[0].shape[-3:] )		,		[self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]		,		)

     for model_class in self.all_model_classes:
        UpperCamelCase_									=     True
        UpperCamelCase_									=     False
        UpperCamelCase_									=     model_class(_UpperCAmelCase )
        UpperCamelCase_									=     model(self._prepare_for_class(_UpperCAmelCase		,		_UpperCAmelCase ) )
        UpperCamelCase_									=     len(_UpperCAmelCase )
        self.assertEqual(config.output_hidden_states		,		_UpperCAmelCase )
        check_encoder_attentions_output(_UpperCAmelCase )

        if self.is_encoder_decoder:
           UpperCamelCase_									=     model_class(_UpperCAmelCase )
           UpperCamelCase_									=     model(self._prepare_for_class(_UpperCAmelCase		,		_UpperCAmelCase ) )
           self.assertEqual(config.output_hidden_states		,		_UpperCAmelCase )
           check_decoder_attentions_output(_UpperCAmelCase )

        # Check that output attentions can also be changed via the config
        del inputs_dict["output_attentions"]
        UpperCamelCase_									=     True
        UpperCamelCase_									=     model_class(_UpperCAmelCase )
        UpperCamelCase_									=     model(self._prepare_for_class(_UpperCAmelCase		,		_UpperCAmelCase ) )
        self.assertEqual(config.output_hidden_states		,		_UpperCAmelCase )
        check_encoder_attentions_output(_UpperCAmelCase )

        # Check attention is always last and order is fine
        UpperCamelCase_									=     True
        UpperCamelCase_									=     True
        UpperCamelCase_									=     model_class(_UpperCAmelCase )
        UpperCamelCase_									=     model(self._prepare_for_class(_UpperCAmelCase		,		_UpperCAmelCase ) )

        self.assertEqual(out_len + (2 if self.is_encoder_decoder else 1)		,		len(_UpperCAmelCase ) )
        self.assertEqual(model.config.output_hidden_states		,		_UpperCAmelCase )
        check_encoder_attentions_output(_UpperCAmelCase )




@require_tf
class 						_a       (  unittest.TestCase    ):






  """simple docstring"""





  @slow
  def    _UpperCAmelCase     (     self )			-> Optional[int]:
     UpperCamelCase_									=     TFConvBertModel.from_pretrained('YituTech/conv-bert-base' )
     UpperCamelCase_									=     tf.constant([[0, 1, 2, 3, 4, 5]] )
     UpperCamelCase_									=     model(_UpperCAmelCase )[0]

     UpperCamelCase_									=     [1, 6, 768]
     self.assertEqual(output.shape		,		_UpperCAmelCase )

     UpperCamelCase_									=     tf.constant(
         [
             [
                 [-0.0_3_4_7_5_4_9_3, -0.4_6_8_6_0_3_4, -0.3_0_6_3_8_8_3_2],
                 [0.2_2_6_3_7_2_4_8, -0.2_6_9_8_8_6_4_6, -0.7_4_2_3_4_2_4],
                 [0.1_0_3_2_4_8_6_8, -0.4_5_0_1_3_5_0_8, -0.5_8_2_8_0_7_8_4],
             ]
         ] )
     tf.debugging.assert_near(output[:, :3, :3]		,		_UpperCAmelCase		,		atol=1e-4 )













import logging
import os
from dataclasses import dataclass
from typing import List, Optional, Union

import tqdm
from filelock import FileLock

from transformers import (
    BartTokenizer,
    BartTokenizerFast,
    DataProcessor,
    PreTrainedTokenizer,
    RobertaTokenizer,
    RobertaTokenizerFast,
    XLMRobertaTokenizer,
    is_tf_available,
    is_torch_available,
)


snake_case__      :	str       	=      logging.getLogger(__name__)


@dataclass(frozen=UpperCAmelCase__    )
class 						_a       :






  """simple docstring"""





  A_						=   42
  A_						=   42
  A_						=   None
  A_						=   None
  A_						=   None




@dataclass(frozen=UpperCAmelCase__    )
class 						_a       :






  """simple docstring"""





  A_						=   42
  A_						=   None
  A_						=   None
  A_						=   None
  A_						=   None


if is_torch_available():
 import torch
 from torch.utils.data import Dataset


 class 						_a       (  UpperCAmelCase__    ):






   """simple docstring"""





   A_						=   42




   def __init__(     self		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase = None		,		_UpperCAmelCase=False		,		_UpperCAmelCase = False		,		)			-> Any:
      UpperCamelCase_									=     hans_processors[task]()

      UpperCamelCase_									=     os.path.join(
          _UpperCAmelCase		,		'cached_{}_{}_{}_{}'.format(
              'dev' if evaluate else 'train'		,		tokenizer.__class__.__name__		,		str(_UpperCAmelCase )		,		_UpperCAmelCase		,		)		,		)
      UpperCamelCase_									=     processor.get_labels()
      if tokenizer.__class__ in (
          RobertaTokenizer,
          RobertaTokenizerFast,
          XLMRobertaTokenizer,
          BartTokenizer,
          BartTokenizerFast,
      ):
         # HACK(label indices are swapped in RoBERTa pretrained model)
         UpperCamelCase_		,      UpperCamelCase_									=     label_list[2], label_list[1]
      UpperCamelCase_									=     label_list

      # Make sure only the first process in distributed training processes the dataset,
      # and the others will use the cache.
      UpperCamelCase_									=     cached_features_file + '.lock'
      with FileLock(_UpperCAmelCase ):
         if os.path.exists(_UpperCAmelCase ) and not overwrite_cache:
            logger.info(f"""Loading features from cached file {cached_features_file}""" )
            UpperCamelCase_									=     torch.load(_UpperCAmelCase )
         else:
            logger.info(f"""Creating features from dataset file at {data_dir}""" )

            UpperCamelCase_									=     (
                processor.get_dev_examples(_UpperCAmelCase ) if evaluate else processor.get_train_examples(_UpperCAmelCase )
            )

            logger.info('Training examples: %s'		,		len(_UpperCAmelCase ) )
            UpperCamelCase_									=     hans_convert_examples_to_features(_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase )
            logger.info('Saving features into cached file %s'		,		_UpperCAmelCase )
            torch.save(self.features		,		_UpperCAmelCase )




   def __len__(     self )			-> Dict:
      return len(self.features )




   def __getitem__(     self		,		_UpperCAmelCase )			-> InputFeatures:
      return self.features[i]




   def    _UpperCAmelCase     (     self )			-> Dict:
      return self.label_list


if is_tf_available():
 import tensorflow as tf


 class 						_a       :






   """simple docstring"""





   A_						=   42




   def __init__(     self		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase = 128		,		_UpperCAmelCase=False		,		_UpperCAmelCase = False		,		)			-> int:
      UpperCamelCase_									=     hans_processors[task]()
      UpperCamelCase_									=     processor.get_labels()
      if tokenizer.__class__ in (
          RobertaTokenizer,
          RobertaTokenizerFast,
          XLMRobertaTokenizer,
          BartTokenizer,
          BartTokenizerFast,
      ):
         # HACK(label indices are swapped in RoBERTa pretrained model)
         UpperCamelCase_		,      UpperCamelCase_									=     label_list[2], label_list[1]
      UpperCamelCase_									=     label_list

      UpperCamelCase_									=     processor.get_dev_examples(_UpperCAmelCase ) if evaluate else processor.get_train_examples(_UpperCAmelCase )
      UpperCamelCase_									=     hans_convert_examples_to_features(_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase )

      def gen():
         for ex_index, ex in tqdm.tqdm(enumerate(self.features )		,		desc='convert examples to features' ):
            if ex_index % 10000 == 0:
               logger.info('Writing example %d of %d' % (ex_index, len(_UpperCAmelCase )) )

            yield (
                {
                    "example_id": 0,
                    "input_ids": ex.input_ids,
                    "attention_mask": ex.attention_mask,
                    "token_type_ids": ex.token_type_ids,
                },
                ex.label,
            )

      UpperCamelCase_									=     tf.data.Dataset.from_generator(
          _UpperCAmelCase		,		(
              {
                  'example_id': tf.intaa,
                  'input_ids': tf.intaa,
                  'attention_mask': tf.intaa,
                  'token_type_ids': tf.intaa,
              },
              tf.intaa,
          )		,		(
              {
                  'example_id': tf.TensorShape([] ),
                  'input_ids': tf.TensorShape([None, None] ),
                  'attention_mask': tf.TensorShape([None, None] ),
                  'token_type_ids': tf.TensorShape([None, None] ),
              },
              tf.TensorShape([] ),
          )		,		)




   def    _UpperCAmelCase     (     self )			-> List[str]:
      return self.dataset




   def __len__(     self )			-> str:
      return len(self.features )




   def __getitem__(     self		,		_UpperCAmelCase )			-> InputFeatures:
      return self.features[i]




   def    _UpperCAmelCase     (     self )			-> int:
      return self.label_list


class 						_a       (  UpperCAmelCase__    ):






  """simple docstring"""





  def    _UpperCAmelCase     (     self		,		_UpperCAmelCase )			-> Tuple:
     return self._create_examples(self._read_tsv(os.path.join(_UpperCAmelCase		,		'heuristics_train_set.txt' ) )		,		'train' )




  def    _UpperCAmelCase     (     self		,		_UpperCAmelCase )			-> Dict:
     return self._create_examples(self._read_tsv(os.path.join(_UpperCAmelCase		,		'heuristics_evaluation_set.txt' ) )		,		'dev' )




  def    _UpperCAmelCase     (     self )			-> List[Any]:
     return ["contradiction", "entailment", "neutral"]




  def    _UpperCAmelCase     (     self		,		_UpperCAmelCase		,		_UpperCAmelCase )			-> List[str]:
     UpperCamelCase_									=     []
     for i, line in enumerate(_UpperCAmelCase ):
        if i == 0:
           continue
        UpperCamelCase_									=     '%s-%s' % (set_type, line[0])
        UpperCamelCase_									=     line[5]
        UpperCamelCase_									=     line[6]
        UpperCamelCase_									=     line[7][2:] if line[7].startswith('ex' ) else line[7]
        UpperCamelCase_									=     line[0]
        examples.append(InputExample(guid=_UpperCAmelCase		,		text_a=_UpperCAmelCase		,		text_b=_UpperCAmelCase		,		label=_UpperCAmelCase		,		pairID=_UpperCAmelCase ) )
     return examples






def     _snake_case    (__lowercase    ,      __lowercase    ,      __lowercase    ,      __lowercase    ,      ):
   UpperCamelCase_									=     {label: i for i, label in enumerate(__lowercase)}

   UpperCamelCase_									=     []
   for ex_index, example in tqdm.tqdm(enumerate(__lowercase)    ,      desc='convert examples to features'):
      if ex_index % 10000 == 0:
         logger.info('Writing example %d' % (ex_index))

      UpperCamelCase_									=     tokenizer(
          example.text_a    ,      example.text_b    ,      add_special_tokens=__lowercase    ,      max_length=__lowercase    ,      padding='max_length'    ,      truncation=__lowercase    ,      return_overflowing_tokens=__lowercase    ,      )

      UpperCamelCase_									=     label_map[example.label] if example.label in label_map else 0

      UpperCamelCase_									=     int(example.pairID)

      features.append(InputFeatures(**__lowercase    ,      label=__lowercase    ,      pairID=__lowercase))

   for i, example in enumerate(examples[:5]):
      logger.info('*** Example ***')
      logger.info(f"""guid: {example}""")
      logger.info(f"""features: {features[i]}""")

   return features


snake_case__      :	List[str]       	=      {
    """hans""": 3,
}

snake_case__      :	Union[str, Any]       	=      {
    """hans""": HansProcessor,
}





