


'''simple docstring'''

from __future__ import annotations

import unittest

from transformers import MPNetConfig, 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.models.mpnet.modeling_tf_mpnet import (
         TFMPNetForMaskedLM,
         TFMPNetForMultipleChoice,
         TFMPNetForQuestionAnswering,
         TFMPNetForSequenceClassification,
         TFMPNetForTokenClassification,
         TFMPNetModel,
     )





class 					snake_case   :





  """simple docstring"""




  def __init__(   self      ,  UpperCamelCase      ,  UpperCamelCase=13      ,  UpperCamelCase=7      ,  UpperCamelCase=True      ,  UpperCamelCase=True      ,  UpperCamelCase=False      ,  UpperCamelCase=True      ,  UpperCamelCase=99      ,  UpperCamelCase=64      ,  UpperCamelCase=2      ,  UpperCamelCase=4      ,  UpperCamelCase=64      ,  UpperCamelCase="gelu"      ,  UpperCamelCase=0.1      ,  UpperCamelCase=0.1      ,  UpperCamelCase=512      ,  UpperCamelCase=16      ,  UpperCamelCase=2      ,  UpperCamelCase=0.02      ,  UpperCamelCase=3      ,  UpperCamelCase=4      ,  UpperCamelCase=None      ,  ):







   """simple docstring"""
   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					):







   """simple docstring"""
   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
   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_								=  MPNetConfig(
       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      ,  initializer_range=self.initializer_range      ,  )
   return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels






  def   snake_case		(   self      ,  UpperCamelCase      ,  UpperCamelCase      ,  UpperCamelCase      ,  UpperCamelCase      ,  UpperCamelCase      ,  UpperCamelCase					):







   """simple docstring"""
   lowerCamelCase_								=  TFMPNetModel(config=UpperCamelCase					)
   lowerCamelCase_								=  {"input_ids": input_ids, "attention_mask": input_mask}
   lowerCamelCase_								=  model(UpperCamelCase					)
   lowerCamelCase_								=  [input_ids, input_mask]
   lowerCamelCase_								=  model(UpperCamelCase					)
   self.parent.assertEqual(result.last_hidden_state.shape      ,  (self.batch_size, self.seq_length, self.hidden_size)					)






  def   snake_case		(   self      ,  UpperCamelCase      ,  UpperCamelCase      ,  UpperCamelCase      ,  UpperCamelCase      ,  UpperCamelCase      ,  UpperCamelCase					):







   """simple docstring"""
   lowerCamelCase_								=  TFMPNetForMaskedLM(config=UpperCamelCase					)
   lowerCamelCase_								=  {"input_ids": input_ids, "attention_mask": input_mask}
   lowerCamelCase_								=  model(UpperCamelCase					)
   self.parent.assertEqual(result.logits.shape      ,  (self.batch_size, self.seq_length, self.vocab_size)					)






  def   snake_case		(   self      ,  UpperCamelCase      ,  UpperCamelCase      ,  UpperCamelCase      ,  UpperCamelCase      ,  UpperCamelCase      ,  UpperCamelCase					):







   """simple docstring"""
   lowerCamelCase_								=  TFMPNetForQuestionAnswering(config=UpperCamelCase					)
   lowerCamelCase_								=  {
       "input_ids": input_ids,
       "attention_mask": input_mask,
   }
   lowerCamelCase_								=  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   snake_case		(   self      ,  UpperCamelCase      ,  UpperCamelCase      ,  UpperCamelCase      ,  UpperCamelCase      ,  UpperCamelCase      ,  UpperCamelCase					):







   """simple docstring"""
   lowerCamelCase_								=  self.num_labels
   lowerCamelCase_								=  TFMPNetForSequenceClassification(UpperCamelCase					)
   lowerCamelCase_								=  {"input_ids": input_ids, "attention_mask": input_mask}
   lowerCamelCase_								=  model(UpperCamelCase					)
   self.parent.assertEqual(result.logits.shape      ,  (self.batch_size, self.num_labels)					)






  def   snake_case		(   self      ,  UpperCamelCase      ,  UpperCamelCase      ,  UpperCamelCase      ,  UpperCamelCase      ,  UpperCamelCase      ,  UpperCamelCase					):







   """simple docstring"""
   lowerCamelCase_								=  self.num_choices
   lowerCamelCase_								=  TFMPNetForMultipleChoice(UpperCamelCase					)
   lowerCamelCase_								=  tf.tile(tf.expand_dims(UpperCamelCase      ,  1					)      ,  (1, self.num_choices, 1)					)
   lowerCamelCase_								=  tf.tile(tf.expand_dims(UpperCamelCase      ,  1					)      ,  (1, self.num_choices, 1)					)
   lowerCamelCase_								=  {
       "input_ids": multiple_choice_inputs_ids,
       "attention_mask": multiple_choice_input_mask,
   }
   lowerCamelCase_								=  model(UpperCamelCase					)
   self.parent.assertEqual(result.logits.shape      ,  (self.batch_size, self.num_choices)					)






  def   snake_case		(   self      ,  UpperCamelCase      ,  UpperCamelCase      ,  UpperCamelCase      ,  UpperCamelCase      ,  UpperCamelCase      ,  UpperCamelCase					):







   """simple docstring"""
   lowerCamelCase_								=  self.num_labels
   lowerCamelCase_								=  TFMPNetForTokenClassification(UpperCamelCase					)
   lowerCamelCase_								=  {"input_ids": input_ids, "attention_mask": input_mask}
   lowerCamelCase_								=  model(UpperCamelCase					)
   self.parent.assertEqual(result.logits.shape      ,  (self.batch_size, self.seq_length, self.num_labels)					)







  def   snake_case		(   self					):







   """simple docstring"""
   lowerCamelCase_								=  self.prepare_config_and_inputs()
   ((lowerCamelCase_)			,(lowerCamelCase_)			,(lowerCamelCase_)			,(lowerCamelCase_)			,(lowerCamelCase_)			,(lowerCamelCase_))								=  config_and_inputs
   lowerCamelCase_								=  {"input_ids": input_ids, "attention_mask": input_mask}
   return config, inputs_dict





@require_tf
class 					snake_case   (   lowercase      ,						lowercase      ,						unittest.TestCase      ):





  """simple docstring"""




  _lowerCamelCase		   =  (
      (
          TFMPNetForMaskedLM,
          TFMPNetForMultipleChoice,
          TFMPNetForQuestionAnswering,
          TFMPNetForSequenceClassification,
          TFMPNetForTokenClassification,
          TFMPNetModel,
      )
      if is_tf_available()
      else ()
  )
  _lowerCamelCase		   =  (
      {
          "feature-extraction": TFMPNetModel,
          "fill-mask": TFMPNetForMaskedLM,
          "question-answering": TFMPNetForQuestionAnswering,
          "text-classification": TFMPNetForSequenceClassification,
          "token-classification": TFMPNetForTokenClassification,
          "zero-shot": TFMPNetForSequenceClassification,
      }
      if is_tf_available()
      else {}
  )
  _lowerCamelCase		   =  False
  _lowerCamelCase		   =  False






  def   snake_case		(   self					):







   """simple docstring"""
   lowerCamelCase_								=  TFMPNetModelTester(self					)
   lowerCamelCase_								=  ConfigTester(self      ,  config_class=UpperCamelCase      ,  hidden_size=37					)






  def   snake_case		(   self					):







   """simple docstring"""
   self.config_tester.run_common_tests()






  def   snake_case		(   self					):







   """simple docstring"""
   lowerCamelCase_								=  self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_mpnet_model(*UpperCamelCase					)






  def   snake_case		(   self					):







   """simple docstring"""
   lowerCamelCase_								=  self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_mpnet_for_masked_lm(*UpperCamelCase					)






  def   snake_case		(   self					):







   """simple docstring"""
   lowerCamelCase_								=  self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_mpnet_for_question_answering(*UpperCamelCase					)






  def   snake_case		(   self					):







   """simple docstring"""
   lowerCamelCase_								=  self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_mpnet_for_sequence_classification(*UpperCamelCase					)






  def   snake_case		(   self					):







   """simple docstring"""
   lowerCamelCase_								=  self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_mpnet_for_multiple_choice(*UpperCamelCase					)






  def   snake_case		(   self					):







   """simple docstring"""
   lowerCamelCase_								=  self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_mpnet_for_token_classification(*UpperCamelCase					)







  @slow
  def   snake_case		(   self					):







   """simple docstring"""
   for model_name in ["microsoft/mpnet-base"]:
    lowerCamelCase_								=  TFMPNetModel.from_pretrained(UpperCamelCase					)
    self.assertIsNotNone(UpperCamelCase					)





@require_tf
class 					snake_case   (   unittest.TestCase      ):





  """simple docstring"""




  @slow
  def   snake_case		(   self					):







   """simple docstring"""
   lowerCamelCase_								=  TFMPNetModel.from_pretrained("microsoft/mpnet-base"					)
   lowerCamelCase_								=  tf.constant([[0, 1, 2, 3, 4, 5]]					)
   lowerCamelCase_								=  model(UpperCamelCase					)[0]

   lowerCamelCase_								=  [1, 6, 768]
   self.assertEqual(output.shape      ,  UpperCamelCase					)

   lowerCamelCase_								=  tf.constant(
       [
           [
               [-0.1_067_172, 0.08_216_473, 0.0_024_543],
               [-0.03_465_879, 0.8_354_118, -0.03_252_288],
               [-0.06_569_476, -0.12_424_111, -0.0_494_436],
           ]
       ]					)
   tf.debugging.assert_near(output[:, :3, :3]      ,  UpperCamelCase      ,  atol=1e-4					)







'''simple docstring'''

import csv
import json
import os

import datasets


# TODO: Add BibTeX citation
# Find for instance the citation on arxiv or on the dataset repo/website
a_  :    Any      =			"""\
@InProceedings{huggingface:dataset,
title = {A great new dataset},
author={huggingface, Inc.
},
year={2020}
}
"""

# TODO: Add description of the dataset here
# You can copy an official description
a_  :    Optional[Any]      =			"""\
This new dataset is designed to solve this great NLP task and is crafted with a lot of care.
"""

# TODO: Add a link to an official homepage for the dataset here
a_  :    List[str]      =			""""""

# TODO: Add the licence for the dataset here if you can find it
a_  :    Dict      =			""""""

# TODO: Add link to the official dataset URLs here
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
a_  :    Optional[int]      =			{
    """first_domain""": """https://huggingface.co/great-new-dataset-first_domain.zip""",
    """second_domain""": """https://huggingface.co/great-new-dataset-second_domain.zip""",
}





class 					snake_case   (   datasets.GeneratorBasedBuilder      ):





  """simple docstring"""




  _lowerCamelCase		   =  datasets.Version("1.1.0"      )

  # This is an example of a dataset with multiple configurations.
  # If you don't want/need to define several sub-sets in your dataset,
  # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.

  # If you need to make complex sub-parts in the datasets with configurable options
  # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
  # BUILDER_CONFIG_CLASS = MyBuilderConfig

  # You will be able to load one or the other configurations in the following list with
  # data = datasets.load_dataset('my_dataset', 'first_domain')
  # data = datasets.load_dataset('my_dataset', 'second_domain')
  _lowerCamelCase		   =  [
      datasets.BuilderConfig(name="first_domain"      ,						version=lowercase      ,						description="This part of my dataset covers a first domain"      ),
      datasets.BuilderConfig(name="second_domain"      ,						version=lowercase      ,						description="This part of my dataset covers a second domain"      ),
  ]

  _lowerCamelCase		   =  "first_domain"  # It's not mandatory to have a default configuration. Just use one if it make sense.






  def   snake_case		(   self					):







   """simple docstring"""
   # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
   if self.config.name == "first_domain":  # This is the name of the configuration selected in BUILDER_CONFIGS above
    lowerCamelCase_								=  datasets.Features(
        {
            "sentence": datasets.Value("string"					),
            "option1": datasets.Value("string"					),
            "answer": datasets.Value("string"					)
            # These are the features of your dataset like images, labels ...
        }					)
   else:  # This is an example to show how to have different features for "first_domain" and "second_domain"
    lowerCamelCase_								=  datasets.Features(
        {
            "sentence": datasets.Value("string"					),
            "option2": datasets.Value("string"					),
            "second_domain_answer": datasets.Value("string"					)
            # These are the features of your dataset like images, labels ...
        }					)
   return datasets.DatasetInfo(
       # This is the description that will appear on the datasets page.
       description=_DESCRIPTION      ,  features=UpperCamelCase      ,  homepage=_HOMEPAGE      ,  license=_LICENSE      ,  citation=_CITATION      ,  )






  def   snake_case		(   self      ,  UpperCamelCase					):







   """simple docstring"""
   # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
   # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name

   # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
   # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
   # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
   lowerCamelCase_								=  _URLS[self.config.name]
   lowerCamelCase_								=  dl_manager.download_and_extract(UpperCamelCase					)
   return [
       datasets.SplitGenerator(
           name=datasets.Split.TRAIN      ,  gen_kwargs={
               "filepath": os.path.join(UpperCamelCase      ,  "train.jsonl"					),
               "split": "train",
           }      ,  ),
       datasets.SplitGenerator(
           name=datasets.Split.VALIDATION      ,  gen_kwargs={
               "filepath": os.path.join(UpperCamelCase      ,  "dev.jsonl"					),
               "split": "dev",
           }      ,  ),
       datasets.SplitGenerator(
           name=datasets.Split.TEST      ,  gen_kwargs={
               "filepath": os.path.join(UpperCamelCase      ,  "test.jsonl"					),
               "split": "test"
           }      ,  ),
   ]







  def   snake_case		(   self      ,  UpperCamelCase      ,  UpperCamelCase					):







   """simple docstring"""
   # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
   # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
   with open(UpperCamelCase      ,  encoding="utf-8"					) as f:
    for key, row in enumerate(UpperCamelCase					):
     lowerCamelCase_								=  json.loads(UpperCamelCase					)
     if self.config.name == "first_domain":
      # Yields examples as (key, example) tuples
      yield key, {
          "sentence": data["sentence"],
          "option1": data["option1"],
          "answer": "" if split == "test" else data["answer"],
      }
     else:
      yield key, {
          "sentence": data["sentence"],
          "option2": data["option2"],
          "second_domain_answer": "" if split == "test" else data["second_domain_answer"],
      }



