





'''simple docstring'''

import argparse
from collections import defaultdict

import yaml


__lowerCamelCase : Tuple											=			"docs/source/en/_toctree.yml"







def 							UpperCAmelCase_    (	lowerCAmelCase_							):

				"""simple docstring"""






				lowercase         = defaultdict(lowerCAmelCase_							)
				lowercase         = []
				lowercase         = []
				for doc in doc_list:
								if "local" in doc:
												counts[doc["local"]] += 1

								if doc["title"].lower() == "overview":
												overview_doc.append({"local": doc["local"], "title": doc["title"]}							)
								else:
												new_doc_list.append(lowerCAmelCase_							)

				lowercase         = new_doc_list
				lowercase         = [key for key, value in counts.items() if value > 1]

				lowercase         = []
				for duplicate_key in duplicates:
								lowercase         = list({doc["title"] for doc in doc_list if doc["local"] == duplicate_key}							)
								if len(lowerCAmelCase_							) > 1:
												raise ValueError(
												    f'{duplicate_key} is present several times in the documentation table of content at '
												    "`docs/source/en/_toctree.yml` with different *Title* values. Choose one of those and remove the "
												    "others."							)
								# Only add this once
								new_doc.append({"local": duplicate_key, "title": titles[0]}							)

				# Add none duplicate-keys
				new_doc.extend([doc for doc in doc_list if "local" not in counts or counts[doc["local"]] == 1]							)
				lowercase         = sorted(lowerCAmelCase_		,							key=lambda lowerCAmelCase_							: s["title"].lower()							)

				# "overview" gets special treatment and is always first
				if len(lowerCAmelCase_							) > 1:
								raise ValueError("{doc_list} has two 'overview' docs which is not allowed."							)

				overview_doc.extend(lowerCAmelCase_							)

				# Sort
				return overview_doc







def 							UpperCAmelCase_    (	lowerCAmelCase_=False							):

				"""simple docstring"""






				with open(lowerCAmelCase_		,							encoding="utf-8"							) as f:
								lowercase         = yaml.safe_load(f.read()							)

				# Get to the API doc
				lowercase         = 0
				while content[api_idx]["title"] != "API":
								api_idx += 1
				lowercase         = content[api_idx]["sections"]

				# Then to the model doc
				lowercase         = 0
				while api_doc[scheduler_idx]["title"] != "Schedulers":
								scheduler_idx += 1

				lowercase         = api_doc[scheduler_idx]["sections"]
				lowercase         = clean_doc_toc(lowerCAmelCase_							)

				lowercase         = False
				if new_scheduler_doc != scheduler_doc:
								lowercase         = True
								if overwrite:
												lowercase         = new_scheduler_doc

				if diff:
								if overwrite:
												lowercase         = api_doc
												with open(lowerCAmelCase_		,							"w"		,							encoding="utf-8"							) as f:
																f.write(yaml.dump(lowerCAmelCase_		,							allow_unicode=lowerCAmelCase_							)							)
								else:
												raise ValueError(
												    "The model doc part of the table of content is not properly sorted, run `make style` to fix this."							)







def 							UpperCAmelCase_    (	lowerCAmelCase_=False							):

				"""simple docstring"""






				with open(lowerCAmelCase_		,							encoding="utf-8"							) as f:
								lowercase         = yaml.safe_load(f.read()							)

				# Get to the API doc
				lowercase         = 0
				while content[api_idx]["title"] != "API":
								api_idx += 1
				lowercase         = content[api_idx]["sections"]

				# Then to the model doc
				lowercase         = 0
				while api_doc[pipeline_idx]["title"] != "Pipelines":
								pipeline_idx += 1

				lowercase         = False
				lowercase         = api_doc[pipeline_idx]["sections"]
				lowercase         = []

				# sort sub pipeline docs
				for pipeline_doc in pipeline_docs:
								if "section" in pipeline_doc:
												lowercase         = pipeline_doc["section"]
												lowercase         = clean_doc_toc(lowerCAmelCase_							)
												if overwrite:
																lowercase         = new_sub_pipeline_doc
								new_pipeline_docs.append(lowerCAmelCase_							)

				# sort overall pipeline doc
				lowercase         = clean_doc_toc(lowerCAmelCase_							)

				if new_pipeline_docs != pipeline_docs:
								lowercase         = True
								if overwrite:
												lowercase         = new_pipeline_docs

				if diff:
								if overwrite:
												lowercase         = api_doc
												with open(lowerCAmelCase_		,							"w"		,							encoding="utf-8"							) as f:
																f.write(yaml.dump(lowerCAmelCase_		,							allow_unicode=lowerCAmelCase_							)							)
								else:
												raise ValueError(
												    "The model doc part of the table of content is not properly sorted, run `make style` to fix this."							)


if __name__ == "__main__":
			__lowerCamelCase : int											=			argparse.ArgumentParser()
			parser.add_argument("--fix_and_overwrite", action="store_true", help="Whether to fix inconsistencies.")
			__lowerCamelCase : Optional[int]											=			parser.parse_args()

			check_scheduler_doc(args.fix_and_overwrite)
			check_pipeline_doc(args.fix_and_overwrite)











'''simple docstring'''

import datasets

from .evaluate import evaluate


__lowerCamelCase : Optional[Any]											=			"\\n@inproceedings{Rajpurkar2016SQuAD10,\n  title={SQuAD: 100, 000+ Questions for Machine Comprehension of Text},\n  author={Pranav Rajpurkar and Jian Zhang and Konstantin Lopyrev and Percy Liang},\n  booktitle={EMNLP},\n  year={2016}\n}\n"

__lowerCamelCase : Any											=			"\nThis metric wrap the official scoring script for version 1 of the Stanford Question Answering Dataset (SQuAD).\n\nStanford Question Answering Dataset (SQuAD) is a reading comprehension dataset, consisting of questions posed by\ncrowdworkers on a set of Wikipedia articles, where the answer to every question is a segment of text, or span,\nfrom the corresponding reading passage, or the question might be unanswerable.\n"

__lowerCamelCase : Union[str, Any]											=			"\nComputes SQuAD scores (F1 and EM).\nArgs:\n    predictions: List of question-answers dictionaries with the following key-values:\n        - 'id': id of the question-answer pair as given in the references (see below)\n        - 'prediction_text': the text of the answer\n    references: List of question-answers dictionaries with the following key-values:\n        - 'id': id of the question-answer pair (see above),\n        - 'answers': a Dict in the SQuAD dataset format\n            {\n                'text': list of possible texts for the answer, as a list of strings\n                'answer_start': list of start positions for the answer, as a list of ints\n            }\n            Note that answer_start values are not taken into account to compute the metric.\nReturns:\n    'exact_match': Exact match (the normalized answer exactly match the gold answer)\n    'f1': The F-score of predicted tokens versus the gold answer\nExamples:\n\n    >>> predictions = [{'prediction_text': '1976', 'id': '56e10a3be3433e1400422b22'}]\n    >>> references = [{'answers': {'answer_start': [97], 'text': ['1976']}, 'id': '56e10a3be3433e1400422b22'}]\n    >>> squad_metric = datasets.load_metric(\"squad\")\n    >>> results = squad_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {'exact_match': 100.0, 'f1': 100.0}\n"

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




		def 				UpperCAmelCase__   (self      :	Union[str, Any]				)					-> Union[str, Any]:
						return datasets.MetricInfo(
						    description=_DESCRIPTION							,			citation=_CITATION							,			inputs_description=_KWARGS_DESCRIPTION							,			features=datasets.Features(
						        {
						            "predictions": {"id": datasets.Value("string"				), "prediction_text": datasets.Value("string"				)},
						            "references": {
						                "id": datasets.Value("string"				),
						                "answers": datasets.features.Sequence(
						                    {
						                        "text": datasets.Value("string"				),
						                        "answer_start": datasets.Value("int32"				),
						                    }				),
						            },
						        }				)							,			codebase_urls=["https://rajpurkar.github.io/SQuAD-explorer/"]							,			reference_urls=["https://rajpurkar.github.io/SQuAD-explorer/"]							,			)





		def 				UpperCAmelCase__   (self      :	List[str]							,			A__      :	List[Any]							,			A__      :	List[str]				)					-> str:
						lowercase         = {prediction["id"]: prediction["prediction_text"] for prediction in predictions}
						lowercase         = [
						    {
						        "paragraphs": [
						            {
						                "qas": [
						                    {
						                        "answers": [{"text": answer_text} for answer_text in ref["answers"]["text"]],
						                        "id": ref["id"],
						                    }
						                    for ref in references
						                ]
						            }
						        ]
						    }
						]
						lowercase         = evaluate(dataset=A__							,			predictions=A__				)
						return score




