

'''simple docstring'''





import argparse

from transformers import BigBirdConfig, BigBirdForPreTraining, BigBirdForQuestionAnswering, load_tf_weights_in_big_bird
from transformers.utils import logging


logging.set_verbosity_info()






def 				_lowerCAmelCase			(   __magic_name__						:     Union[str, Any]   , __magic_name__						:     Dict   , __magic_name__						:     Dict   , __magic_name__						:     int						)				->  Optional[Any]:
						# Initialise PyTorch model
						lowercase :							Union[str, Any]    		=BigBirdConfig.from_json_file(__magic_name__						)
						print(f'''Building PyTorch model from configuration: {config}'''						)

						if is_trivia_qa:
												lowercase :							Union[str, Any]    		=BigBirdForQuestionAnswering(__magic_name__						)
						else:
												lowercase :							Optional[Any]    		=BigBirdForPreTraining(__magic_name__						)

						# Load weights from tf checkpoint
						load_tf_weights_in_big_bird(__magic_name__   , __magic_name__   , is_trivia_qa=__magic_name__						)

						# Save pytorch-model
						print(f'''Save PyTorch model to {pytorch_dump_path}'''						)
						model.save_pretrained(__magic_name__						)


if __name__ == "__main__":
							UpperCamelCase_    						=       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(
							    """--big_bird_config_file""",
							    default=None,
							    type=str,
							    required=True,
							    help=(
							        """The config json file corresponding to the pre-trained BERT model. \n"""
							        """This 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(
							    """--is_trivia_qa""", action="""store_true""", help="""Whether to convert a model with a trivia_qa head."""
							)
							UpperCamelCase_    						=       parser.parse_args()
							convert_tf_checkpoint_to_pytorch(
							    args.tf_checkpoint_path, args.big_bird_config_file, args.pytorch_dump_path, args.is_trivia_qa
							)








'''simple docstring'''





import datasets


UpperCamelCase_    						=       """\
@InProceedings{conneau2018xnli,
  author = \"Conneau, Alexis
                 and Rinott, Ruty
                 and Lample, Guillaume
                 and Williams, Adina
                 and Bowman, Samuel R.
                 and Schwenk, Holger
                 and Stoyanov, Veselin\",
  title = \"XNLI: Evaluating Cross-lingual Sentence Representations\",
  booktitle = \"Proceedings of the 2018 Conference on Empirical Methods
               in Natural Language Processing\",
  year = \"2018\",
  publisher = \"Association for Computational Linguistics\",
  location = \"Brussels, Belgium\",
}
"""

UpperCamelCase_    						=       """\
XNLI is a subset of a few thousand examples from MNLI which has been translated
into a 14 different languages (some low-ish resource). As with MNLI, the goal is
to predict textual entailment (does sentence A imply/contradict/neither sentence
B) and is a classification task (given two sentences, predict one of three
labels).
"""

UpperCamelCase_    						=       """
Computes XNLI score which is just simple accuracy.
Args:
    predictions: Predicted labels.
    references: Ground truth labels.
Returns:
    'accuracy': accuracy
Examples:

    >>> predictions = [0, 1]
    >>> references = [0, 1]
    >>> xnli_metric = datasets.load_metric(\"xnli\")
    >>> results = xnli_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {'accuracy': 1.0}
"""






def 				_lowerCAmelCase			(   __magic_name__						:     Dict   , __magic_name__						:     Union[str, Any]						)				->  Union[str, Any]:
						return (preds == labels).mean()







@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION						,							_KWARGS_DESCRIPTION      )
class 		__SCREAMING_SNAKE_CASE							(			datasets.Metric      ):







				def  lowerCamelCase_	(       self     :		str   ):
										'''simple docstring'''
										return datasets.MetricInfo(
										    description=_DESCRIPTION		,					citation=_CITATION		,					inputs_description=_KWARGS_DESCRIPTION		,					features=datasets.Features(
										        {
										            '''predictions''': datasets.Value('''int64''' if self.config_name != '''sts-b''' else '''float32'''   ),
										            '''references''': datasets.Value('''int64''' if self.config_name != '''sts-b''' else '''float32'''   ),
										        }   )		,					codebase_urls=[]		,					reference_urls=[]		,					format='''numpy'''		,					)







				def  lowerCamelCase_	(       self     :		int		,					UpperCAmelCase__     :		Dict		,					UpperCAmelCase__     :		Optional[Any]   ):
										'''simple docstring'''
										return {"accuracy": simple_accuracy(UpperCAmelCase__		,					UpperCAmelCase__   )}





