




"""simple docstring"""






import argparse
import collections
import json
import os
import re
import string
import sys

import numpy as np


lowercase__			=		re.compile(R"""\b(a|an|the)\b""", re.UNICODE)

lowercase__			=		None







def 	_snake_case     (							):
				_lowerCamelCase	:     Any       =       argparse.ArgumentParser('Official evaluation script for SQuAD version 2.0.'						)
				parser.add_argument('data_file'				,       metavar='data.json'				,       help='Input data JSON file.'						)
				parser.add_argument('pred_file'				,       metavar='pred.json'				,       help='Model predictions.'						)
				parser.add_argument(
				    '--out-file'				,       '-o'				,       metavar='eval.json'				,       help='Write accuracy metrics to file (default is stdout).'						)
				parser.add_argument(
				    '--na-prob-file'				,       '-n'				,       metavar='na_prob.json'				,       help='Model estimates of probability of no answer.'						)
				parser.add_argument(
				    '--na-prob-thresh'				,       '-t'				,       type=lowercase__				,       default=1.0				,       help='Predict "" if no-answer probability exceeds this (default = 1.0).'				,       )
				parser.add_argument(
				    '--out-image-dir'				,       '-p'				,       metavar='out_images'				,       default=lowercase__				,       help='Save precision-recall curves to directory.'						)
				parser.add_argument('--verbose'				,       '-v'				,       action='store_true'						)
				if len(sys.argv						) == 1:
								parser.print_help()
								sys.exit(1						)
				return parser.parse_args()







def 	_snake_case     (							lowercase__						):
				_lowerCamelCase	:     Union[str, Any]       =       {}
				for article in dataset:
								for p in article["paragraphs"]:
												for qa in p["qas"]:
																_lowerCamelCase	:     List[str]       =       bool(qa['answers']['text']						)
				return qid_to_has_ans







def 	_snake_case     (							lowercase__						):

				def remove_articles(lowercase__						):
								return ARTICLES_REGEX.sub(' '				,       lowercase__						)

				def white_space_fix(lowercase__						):
								return " ".join(text.split()						)

				def remove_punc(lowercase__						):
								_lowerCamelCase	:     Optional[Any]       =       set(string.punctuation						)
								return "".join(ch for ch in text if ch not in exclude						)

				def lower(lowercase__						):
								return text.lower()

				return white_space_fix(remove_articles(remove_punc(lower(lowercase__						)						)						)						)







def 	_snake_case     (							lowercase__						):
				if not s:
								return []
				return normalize_answer(lowercase__						).split()







def 	_snake_case     (							lowercase__				,       lowercase__						):
				return int(normalize_answer(lowercase__						) == normalize_answer(lowercase__						)						)







def 	_snake_case     (							lowercase__				,       lowercase__						):
				_lowerCamelCase	:     Optional[int]       =       get_tokens(lowercase__						)
				_lowerCamelCase	:     int       =       get_tokens(lowercase__						)
				_lowerCamelCase	:     Tuple       =       collections.Counter(lowercase__						) & collections.Counter(lowercase__						)
				_lowerCamelCase	:     Union[str, Any]       =       sum(common.values()						)
				if len(lowercase__						) == 0 or len(lowercase__						) == 0:
								# If either is no-answer, then F1 is 1 if they agree, 0 otherwise
								return int(gold_toks == pred_toks						)
				if num_same == 0:
								return 0
				_lowerCamelCase	:     List[Any]       =       1.0 * num_same / len(lowercase__						)
				_lowerCamelCase	:     Optional[int]       =       1.0 * num_same / len(lowercase__						)
				_lowerCamelCase	:     str       =       (2 * precision * recall) / (precision + recall)
				return fa







def 	_snake_case     (							lowercase__				,       lowercase__						):
				_lowerCamelCase	:     Dict       =       {}
				_lowerCamelCase	:     Union[str, Any]       =       {}
				for article in dataset:
								for p in article["paragraphs"]:
												for qa in p["qas"]:
																_lowerCamelCase	:     str       =       qa['id']
																_lowerCamelCase	:     List[str]       =       [t for t in qa['answers']['text'] if normalize_answer(lowercase__						)]
																if not gold_answers:
																				# For unanswerable questions, only correct answer is empty string
																				_lowerCamelCase	:     Any       =       ['']
																if qid not in preds:
																				print(f'''Missing prediction for {qid}'''						)
																				continue
																_lowerCamelCase	:     Tuple       =       preds[qid]
																# Take max over all gold answers
																_lowerCamelCase	:     Tuple       =       max(compute_exact(lowercase__				,       lowercase__						) for a in gold_answers						)
																_lowerCamelCase	:     Dict       =       max(compute_fa(lowercase__				,       lowercase__						) for a in gold_answers						)
				return exact_scores, fa_scores







def 	_snake_case     (							lowercase__				,       lowercase__				,       lowercase__				,       lowercase__						):
				_lowerCamelCase	:     Union[str, Any]       =       {}
				for qid, s in scores.items():
								_lowerCamelCase	:     Dict       =       na_probs[qid] > na_prob_thresh
								if pred_na:
												_lowerCamelCase	:     Optional[Any]       =       float(not qid_to_has_ans[qid]						)
								else:
												_lowerCamelCase	:     Optional[Any]       =       s
				return new_scores







def 	_snake_case     (							lowercase__				,       lowercase__				,       lowercase__=None						):
				if not qid_list:
								_lowerCamelCase	:     Union[str, Any]       =       len(lowercase__						)
								return collections.OrderedDict(
								    [
								        ('exact', 1_0_0.0 * sum(exact_scores.values()						) / total),
								        ('f1', 1_0_0.0 * sum(fa_scores.values()						) / total),
								        ('total', total),
								    ]						)
				else:
								_lowerCamelCase	:     List[str]       =       len(lowercase__						)
								return collections.OrderedDict(
								    [
								        ('exact', 1_0_0.0 * sum(exact_scores[k] for k in qid_list						) / total),
								        ('f1', 1_0_0.0 * sum(fa_scores[k] for k in qid_list						) / total),
								        ('total', total),
								    ]						)







def 	_snake_case     (							lowercase__				,       lowercase__				,       lowercase__						):
				for k in new_eval:
								_lowerCamelCase	:     str       =       new_eval[k]







def 	_snake_case     (							lowercase__				,       lowercase__				,       lowercase__				,       lowercase__						):
				plt.step(lowercase__				,       lowercase__				,       color='b'				,       alpha=0.2				,       where='post'						)
				plt.fill_between(lowercase__				,       lowercase__				,       step='post'				,       alpha=0.2				,       color='b'						)
				plt.xlabel('Recall'						)
				plt.ylabel('Precision'						)
				plt.xlim([0.0, 1.0_5]						)
				plt.ylim([0.0, 1.0_5]						)
				plt.title(lowercase__						)
				plt.savefig(lowercase__						)
				plt.clf()







def 	_snake_case     (							lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__=None				,       lowercase__=None						):
				_lowerCamelCase	:     Any       =       sorted(lowercase__				,       key=lambda lowercase__						: na_probs[k]						)
				_lowerCamelCase	:     Optional[Any]       =       0.0
				_lowerCamelCase	:     List[Any]       =       1.0
				_lowerCamelCase	:     int       =       0.0
				_lowerCamelCase	:     Tuple       =       [1.0]
				_lowerCamelCase	:     Any       =       [0.0]
				_lowerCamelCase	:     Dict       =       0.0
				for i, qid in enumerate(lowercase__						):
								if qid_to_has_ans[qid]:
												true_pos += scores[qid]
								_lowerCamelCase	:     List[Any]       =       true_pos / float(i + 1						)
								_lowerCamelCase	:     Dict       =       true_pos / float(lowercase__						)
								if i == len(lowercase__						) - 1 or na_probs[qid] != na_probs[qid_list[i + 1]]:
												# i.e., if we can put a threshold after this point
												avg_prec += cur_p * (cur_r - recalls[-1])
												precisions.append(lowercase__						)
												recalls.append(lowercase__						)
				if out_image:
								plot_pr_curve(lowercase__				,       lowercase__				,       lowercase__				,       lowercase__						)
				return {"ap": 1_0_0.0 * avg_prec}







def 	_snake_case     (							lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__						):
				if out_image_dir and not os.path.exists(lowercase__						):
								os.makedirs(lowercase__						)
				_lowerCamelCase	:     Any       =       sum(1 for v in qid_to_has_ans.values() if v						)
				if num_true_pos == 0:
								return
				_lowerCamelCase	:     str       =       make_precision_recall_eval(
				    lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       out_image=os.path.join(lowercase__				,       'pr_exact.png'						)				,       title='Precision-Recall curve for Exact Match score'				,       )
				_lowerCamelCase	:     int       =       make_precision_recall_eval(
				    lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       out_image=os.path.join(lowercase__				,       'pr_f1.png'						)				,       title='Precision-Recall curve for F1 score'				,       )
				_lowerCamelCase	:     List[str]       =       {k: float(lowercase__						) for k, v in qid_to_has_ans.items()}
				_lowerCamelCase	:     int       =       make_precision_recall_eval(
				    lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       out_image=os.path.join(lowercase__				,       'pr_oracle.png'						)				,       title='Oracle Precision-Recall curve (binary task of HasAns vs. NoAns)'				,       )
				merge_eval(lowercase__				,       lowercase__				,       'pr_exact'						)
				merge_eval(lowercase__				,       lowercase__				,       'pr_f1'						)
				merge_eval(lowercase__				,       lowercase__				,       'pr_oracle'						)







def 	_snake_case     (							lowercase__				,       lowercase__				,       lowercase__				,       lowercase__						):
				if not qid_list:
								return
				_lowerCamelCase	:     List[str]       =       [na_probs[k] for k in qid_list]
				_lowerCamelCase	:     Tuple       =       np.ones_like(lowercase__						) / float(len(lowercase__						)						)
				plt.hist(lowercase__				,       weights=lowercase__				,       bins=20				,       range=(0.0, 1.0)						)
				plt.xlabel('Model probability of no-answer'						)
				plt.ylabel('Proportion of dataset'						)
				plt.title(f'''Histogram of no-answer probability: {name}'''						)
				plt.savefig(os.path.join(lowercase__				,       f'''na_prob_hist_{name}.png'''						)						)
				plt.clf()







def 	_snake_case     (							lowercase__				,       lowercase__				,       lowercase__				,       lowercase__						):
				_lowerCamelCase	:     Optional[Any]       =       sum(1 for k in qid_to_has_ans if not qid_to_has_ans[k]						)
				_lowerCamelCase	:     Optional[int]       =       num_no_ans
				_lowerCamelCase	:     Optional[Any]       =       cur_score
				_lowerCamelCase	:     List[str]       =       0.0
				_lowerCamelCase	:     Optional[Any]       =       sorted(lowercase__				,       key=lambda lowercase__						: na_probs[k]						)
				for i, qid in enumerate(lowercase__						):
								if qid not in scores:
												continue
								if qid_to_has_ans[qid]:
												_lowerCamelCase	:     Union[str, Any]       =       scores[qid]
								else:
												if preds[qid]:
																_lowerCamelCase	:     str       =       -1
												else:
																_lowerCamelCase	:     Dict       =       0
								cur_score += diff
								if cur_score > best_score:
												_lowerCamelCase	:     str       =       cur_score
												_lowerCamelCase	:     Tuple       =       na_probs[qid]
				return 1_0_0.0 * best_score / len(lowercase__						), best_thresh







def 	_snake_case     (							lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__						):
				_lowerCamelCase,					_lowerCamelCase	:     int       =       find_best_thresh(lowercase__				,       lowercase__				,       lowercase__				,       lowercase__						)
				_lowerCamelCase,					_lowerCamelCase	:     Optional[Any]       =       find_best_thresh(lowercase__				,       lowercase__				,       lowercase__				,       lowercase__						)
				_lowerCamelCase	:     str       =       best_exact
				_lowerCamelCase	:     Tuple       =       exact_thresh
				_lowerCamelCase	:     Optional[int]       =       best_fa
				_lowerCamelCase	:     Tuple       =       fa_thresh







def 	_snake_case     (							):
				with open(OPTS.data_file						) as f:
								_lowerCamelCase	:     List[Any]       =       json.load(lowercase__						)
								_lowerCamelCase	:     Any       =       dataset_json['data']
				with open(OPTS.pred_file						) as f:
								_lowerCamelCase	:     Tuple       =       json.load(lowercase__						)
				if OPTS.na_prob_file:
								with open(OPTS.na_prob_file						) as f:
												_lowerCamelCase	:     str       =       json.load(lowercase__						)
				else:
								_lowerCamelCase	:     List[str]       =       {k: 0.0 for k in preds}
				_lowerCamelCase	:     Any       =       make_qid_to_has_ans(lowercase__						)  # maps qid to True/False
				_lowerCamelCase	:     str       =       [k for k, v in qid_to_has_ans.items() if v]
				_lowerCamelCase	:     Optional[int]       =       [k for k, v in qid_to_has_ans.items() if not v]
				_lowerCamelCase,					_lowerCamelCase	:     Tuple       =       get_raw_scores(lowercase__				,       lowercase__						)
				_lowerCamelCase	:     Optional[Any]       =       apply_no_ans_threshold(lowercase__				,       lowercase__				,       lowercase__				,       OPTS.na_prob_thresh						)
				_lowerCamelCase	:     int       =       apply_no_ans_threshold(lowercase__				,       lowercase__				,       lowercase__				,       OPTS.na_prob_thresh						)
				_lowerCamelCase	:     Optional[Any]       =       make_eval_dict(lowercase__				,       lowercase__						)
				if has_ans_qids:
								_lowerCamelCase	:     Tuple       =       make_eval_dict(lowercase__				,       lowercase__				,       qid_list=lowercase__						)
								merge_eval(lowercase__				,       lowercase__				,       'HasAns'						)
				if no_ans_qids:
								_lowerCamelCase	:     Dict       =       make_eval_dict(lowercase__				,       lowercase__				,       qid_list=lowercase__						)
								merge_eval(lowercase__				,       lowercase__				,       'NoAns'						)
				if OPTS.na_prob_file:
								find_all_best_thresh(lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__						)
				if OPTS.na_prob_file and OPTS.out_image_dir:
								run_precision_recall_analysis(lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       OPTS.out_image_dir						)
								histogram_na_prob(lowercase__				,       lowercase__				,       OPTS.out_image_dir				,       'hasAns'						)
								histogram_na_prob(lowercase__				,       lowercase__				,       OPTS.out_image_dir				,       'noAns'						)
				if OPTS.out_file:
								with open(OPTS.out_file				,       'w'						) as f:
												json.dump(lowercase__				,       lowercase__						)
				else:
								print(json.dumps(lowercase__				,       indent=2						)						)


if __name__ == "__main__":
			lowercase__			=		parse_args()
			if OPTS.out_image_dir:
						import matplotlib

						matplotlib.use("""Agg""")
						import matplotlib.pyplot as plt
			main()





"""simple docstring"""






import unittest

from transformers import MPNetConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch

			from transformers import (
			    MPNetForMaskedLM,
			    MPNetForMultipleChoice,
			    MPNetForQuestionAnswering,
			    MPNetForSequenceClassification,
			    MPNetForTokenClassification,
			    MPNetModel,
			)






class lowerCAmelCase__      :






			'''simple docstring'''



			def __init__(    self    , lowercase    , lowercase=13    , lowercase=7    , lowercase=True    , lowercase=True    , lowercase=False    , lowercase=True    , lowercase=99    , lowercase=64    , lowercase=5    , lowercase=4    , lowercase=64    , lowercase="gelu"    , lowercase=0.1    , lowercase=0.1    , lowercase=512    , lowercase=16    , lowercase=2    , lowercase=0.02    , lowercase=3    , lowercase=4    , lowercase=None    , ):
							_lowerCamelCase	:     List[str]       =       parent
							_lowerCamelCase	:     List[str]       =       batch_size
							_lowerCamelCase	:     Tuple       =       seq_length
							_lowerCamelCase	:     List[Any]       =       is_training
							_lowerCamelCase	:     int       =       use_input_mask
							_lowerCamelCase	:     Optional[Any]       =       use_token_type_ids
							_lowerCamelCase	:     List[Any]       =       use_labels
							_lowerCamelCase	:     str       =       vocab_size
							_lowerCamelCase	:     Optional[int]       =       hidden_size
							_lowerCamelCase	:     List[str]       =       num_hidden_layers
							_lowerCamelCase	:     Optional[int]       =       num_attention_heads
							_lowerCamelCase	:     List[str]       =       intermediate_size
							_lowerCamelCase	:     int       =       hidden_act
							_lowerCamelCase	:     Optional[int]       =       hidden_dropout_prob
							_lowerCamelCase	:     List[Any]       =       attention_probs_dropout_prob
							_lowerCamelCase	:     List[str]       =       max_position_embeddings
							_lowerCamelCase	:     List[Any]       =       type_vocab_size
							_lowerCamelCase	:     Optional[int]       =       type_sequence_label_size
							_lowerCamelCase	:     Union[str, Any]       =       initializer_range
							_lowerCamelCase	:     Tuple       =       num_labels
							_lowerCamelCase	:     int       =       num_choices
							_lowerCamelCase	:     int       =       scope
			def    A_       (    self    ):
							return MPNetConfig.from_pretrained('microsoft/mpnet-base'    )
			def    A_       (    self    ):
							_lowerCamelCase	:     Tuple       =       ids_tensor([self.batch_size, self.seq_length]    , self.vocab_size    )

							_lowerCamelCase	:     Dict       =       None
							if self.use_input_mask:
											_lowerCamelCase	:     Optional[int]       =       random_attention_mask([self.batch_size, self.seq_length]    )

							_lowerCamelCase	:     int       =       None
							_lowerCamelCase	:     List[str]       =       None
							_lowerCamelCase	:     Any       =       None
							if self.use_labels:
											_lowerCamelCase	:     List[str]       =       ids_tensor([self.batch_size]    , self.type_sequence_label_size    )
											_lowerCamelCase	:     str       =       ids_tensor([self.batch_size, self.seq_length]    , self.num_labels    )
											_lowerCamelCase	:     Dict       =       ids_tensor([self.batch_size]    , self.num_choices    )

							_lowerCamelCase	:     int       =       self.get_config()
							return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels
			def    A_       (    self    ):
							return 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    , )
			def    A_       (    self    , lowercase    , lowercase    , lowercase    , lowercase    , lowercase    , lowercase    ):
							_lowerCamelCase	:     Optional[Any]       =       MPNetModel(config=lowercase    )
							model.to(lowercase    )
							model.eval()
							_lowerCamelCase	:     Tuple       =       model(lowercase    , lowercase    )
							_lowerCamelCase	:     Tuple       =       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    A_       (    self    , lowercase    , lowercase    , lowercase    , lowercase    , lowercase    , lowercase    ):
							_lowerCamelCase	:     str       =       MPNetForQuestionAnswering(config=lowercase    )
							model.to(lowercase    )
							model.eval()
							_lowerCamelCase	:     str       =       model(
							    lowercase    , attention_mask=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    A_       (    self    , lowercase    , lowercase    , lowercase    , lowercase    , lowercase    , lowercase    ):
							_lowerCamelCase	:     Optional[int]       =       self.num_labels
							_lowerCamelCase	:     int       =       MPNetForSequenceClassification(lowercase    )
							model.to(lowercase    )
							model.eval()
							_lowerCamelCase	:     Optional[Any]       =       model(lowercase    , attention_mask=lowercase    , labels=lowercase    )
							self.parent.assertEqual(result.logits.shape    , (self.batch_size, self.num_labels)    )
			def    A_       (    self    , lowercase    , lowercase    , lowercase    , lowercase    , lowercase    , lowercase    ):
							_lowerCamelCase	:     List[str]       =       self.num_choices
							_lowerCamelCase	:     List[str]       =       MPNetForMultipleChoice(config=lowercase    )
							model.to(lowercase    )
							model.eval()
							_lowerCamelCase	:     Union[str, Any]       =       input_ids.unsqueeze(1    ).expand(-1    , self.num_choices    , -1    ).contiguous()
							_lowerCamelCase	:     List[str]       =       input_mask.unsqueeze(1    ).expand(-1    , self.num_choices    , -1    ).contiguous()
							_lowerCamelCase	:     Any       =       model(
							    lowercase    , attention_mask=lowercase    , labels=lowercase    , )
							self.parent.assertEqual(result.logits.shape    , (self.batch_size, self.num_choices)    )
			def    A_       (    self    , lowercase    , lowercase    , lowercase    , lowercase    , lowercase    , lowercase    ):
							_lowerCamelCase	:     Any       =       self.num_labels
							_lowerCamelCase	:     Union[str, Any]       =       MPNetForTokenClassification(config=lowercase    )
							model.to(lowercase    )
							model.eval()
							_lowerCamelCase	:     Union[str, Any]       =       model(lowercase    , attention_mask=lowercase    , labels=lowercase    )
							self.parent.assertEqual(result.logits.shape    , (self.batch_size, self.seq_length, self.num_labels)    )






			def    A_       (    self    ):
							_lowerCamelCase	:     Dict       =       self.prepare_config_and_inputs()
							((_lowerCamelCase),					(_lowerCamelCase),					(_lowerCamelCase),					(_lowerCamelCase),					(_lowerCamelCase),					(_lowerCamelCase))	:     List[Any]       =       config_and_inputs
							_lowerCamelCase	:     str       =       {'input_ids': input_ids, 'attention_mask': input_mask}
							return config, inputs_dict






@require_torch
class lowerCAmelCase__      (	lowercase,      lowercase,      unittest.TestCase		):






			'''simple docstring'''



			lowerCamelCase__ =     (
			    (
			        MPNetForMaskedLM,
			        MPNetForMultipleChoice,
			        MPNetForQuestionAnswering,
			        MPNetForSequenceClassification,
			        MPNetForTokenClassification,
			        MPNetModel,
			    )
			    if is_torch_available()
			    else ()
			)
			lowerCamelCase__ =     (
			    {
			        """feature-extraction""": MPNetModel,
			        """fill-mask""": MPNetForMaskedLM,
			        """question-answering""": MPNetForQuestionAnswering,
			        """text-classification""": MPNetForSequenceClassification,
			        """token-classification""": MPNetForTokenClassification,
			        """zero-shot""": MPNetForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)
			lowerCamelCase__ =     False
			lowerCamelCase__ =     True
			def    A_       (    self    ):
							_lowerCamelCase	:     Union[str, Any]       =       MPNetModelTester(self    )
							_lowerCamelCase	:     List[Any]       =       ConfigTester(self    , config_class=lowercase    , hidden_size=37    )
			def    A_       (    self    ):
							self.config_tester.run_common_tests()
			def    A_       (    self    ):
							_lowerCamelCase	:     Union[str, Any]       =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mpnet_model(*lowercase    )
			def    A_       (    self    ):
							_lowerCamelCase	:     List[Any]       =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mpnet_for_sequence_classification(*lowercase    )
			def    A_       (    self    ):
							_lowerCamelCase	:     Optional[Any]       =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mpnet_for_multiple_choice(*lowercase    )
			def    A_       (    self    ):
							_lowerCamelCase	:     List[Any]       =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mpnet_for_token_classification(*lowercase    )






			def    A_       (    self    ):
							_lowerCamelCase	:     str       =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mpnet_for_question_answering(*lowercase    )






@require_torch
class lowerCAmelCase__      (	unittest.TestCase		):






			'''simple docstring'''



			@slow
			def    A_       (    self    ):
							_lowerCamelCase	:     Optional[Any]       =       MPNetModel.from_pretrained('microsoft/mpnet-base'    )
							_lowerCamelCase	:     Optional[Any]       =       torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]    )
							_lowerCamelCase	:     Any       =       model(lowercase    )[0]
							_lowerCamelCase	:     Dict       =       torch.Size((1, 11, 768)    )
							self.assertEqual(output.shape    , lowercase    )
							_lowerCamelCase	:     List[Any]       =       torch.tensor(
							    [[[-0.05_50, 0.19_43, -0.07_40], [-0.05_62, 0.22_11, -0.05_79], [-0.04_37, 0.33_37, -0.06_41]]]    )
							# compare the actual values for a slice.
							self.assertTrue(torch.allclose(output[:, :3, :3]    , lowercase    , atol=1E-4    )    )