
"""simple docstring"""






import datasets

from .evaluate import evaluate


lowerCamelCase__ :       List[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__ :       int						     =			"\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__ :       Tuple						     =			"\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 				lowercase__(				datasets.Metric   ):
	'''simple docstring'''

	def   __lowerCAmelCase (						self    :str					)							->			Dict:







			'''simple docstring'''




			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   __lowerCAmelCase (						self    :List[str]		, lowerCamelCase_    :Optional[int]		, lowerCamelCase_    :List[Any]					)							->			Any:







			'''simple docstring'''




			SCREAMING_SNAKE_CASE       :     Dict				= {prediction['''id''']: prediction['''prediction_text'''] for prediction in predictions}
			SCREAMING_SNAKE_CASE       :     str				= [
			    {
			        '''paragraphs''': [
			            {
			                '''qas''': [
			                    {
			                        '''answers''': [{'''text''': answer_text} for answer_text in ref['''answers''']['''text''']],
			                        '''id''': ref['''id'''],
			                    }
			                    for ref in references
			                ]
			            }
			        ]
			    }
			]
			SCREAMING_SNAKE_CASE       :     List[Any]				= evaluate(dataset=lowerCamelCase_		, predictions=lowerCamelCase_					)
			return score







"""simple docstring"""






import math
from typing import Optional

import numpy as np

from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCamelCase__ :       Tuple						     =			logging.get_logger(__name__)

lowerCamelCase__ :       Any						     =			{
    "facebook/encodec_24khz": "https://huggingface.co/facebook/encodec_24khz/resolve/main/config.json",
    "facebook/encodec_48khz": "https://huggingface.co/facebook/encodec_48khz/resolve/main/config.json",
}




class 				lowercase__(				_UpperCAmelCase   ):
	'''simple docstring'''

	UpperCamelCase				=  """encodec"""





	def __init__(						self    :List[str]		, lowerCamelCase_    :Tuple=[1.5, 3.0, 6.0, 1_2.0, 2_4.0]		, lowerCamelCase_    :str=2_40_00		, lowerCamelCase_    :Any=1		, lowerCamelCase_    :List[Any]=False		, lowerCamelCase_    :Optional[int]=None		, lowerCamelCase_    :Optional[Any]=None		, lowerCamelCase_    :str=1_28		, lowerCamelCase_    :Any=32		, lowerCamelCase_    :int=1		, lowerCamelCase_    :Dict=[8, 5, 4, 2]		, lowerCamelCase_    :List[Any]="weight_norm"		, lowerCamelCase_    :Optional[int]=7		, lowerCamelCase_    :Tuple=7		, lowerCamelCase_    :Optional[Any]=3		, lowerCamelCase_    :int=2		, lowerCamelCase_    :Dict=True		, lowerCamelCase_    :Optional[int]="reflect"		, lowerCamelCase_    :Optional[int]=2		, lowerCamelCase_    :Union[str, Any]=2		, lowerCamelCase_    :Dict=1.0		, lowerCamelCase_    :Any=10_24		, lowerCamelCase_    :str=None		, lowerCamelCase_    :Union[str, Any]=True		, **lowerCamelCase_    :Optional[int]		, )							->			Dict:







			'''simple docstring'''




			SCREAMING_SNAKE_CASE       :     Optional[Any]				= target_bandwidths
			SCREAMING_SNAKE_CASE       :     List[str]				= sampling_rate
			SCREAMING_SNAKE_CASE       :     Tuple				= audio_channels
			SCREAMING_SNAKE_CASE       :     Tuple				= normalize
			SCREAMING_SNAKE_CASE       :     str				= chunk_length_s
			SCREAMING_SNAKE_CASE       :     List[str]				= overlap
			SCREAMING_SNAKE_CASE       :     int				= hidden_size
			SCREAMING_SNAKE_CASE       :     Optional[int]				= num_filters
			SCREAMING_SNAKE_CASE       :     Tuple				= num_residual_layers
			SCREAMING_SNAKE_CASE       :     List[Any]				= upsampling_ratios
			SCREAMING_SNAKE_CASE       :     Optional[int]				= norm_type
			SCREAMING_SNAKE_CASE       :     Any				= kernel_size
			SCREAMING_SNAKE_CASE       :     Union[str, Any]				= last_kernel_size
			SCREAMING_SNAKE_CASE       :     Tuple				= residual_kernel_size
			SCREAMING_SNAKE_CASE       :     Any				= dilation_growth_rate
			SCREAMING_SNAKE_CASE       :     Optional[int]				= use_causal_conv
			SCREAMING_SNAKE_CASE       :     str				= pad_mode
			SCREAMING_SNAKE_CASE       :     List[Any]				= compress
			SCREAMING_SNAKE_CASE       :     Optional[Any]				= num_lstm_layers
			SCREAMING_SNAKE_CASE       :     Dict				= trim_right_ratio
			SCREAMING_SNAKE_CASE       :     List[Any]				= codebook_size
			SCREAMING_SNAKE_CASE       :     Union[str, Any]				= codebook_dim if codebook_dim is not None else hidden_size
			SCREAMING_SNAKE_CASE       :     Union[str, Any]				= use_conv_shortcut

			if self.norm_type not in ["weight_norm", "time_group_norm"]:
					raise ValueError(
					    f"self.norm_type must be one of `\"weight_norm\"`, `\"time_group_norm\"`), got {self.norm_type}"					)

			super().__init__(**lowerCamelCase_					)





	@property
	def   __lowerCAmelCase (						self    :Optional[Any]					)							->			Optional[int]:







			'''simple docstring'''




			if self.chunk_length_s is None:
					return None
			else:
					return int(self.chunk_length_s * self.sampling_rate					)





	@property
	def   __lowerCAmelCase (						self    :List[str]					)							->			Optional[int]:







			'''simple docstring'''




			if self.chunk_length_s is None or self.overlap is None:
					return None
			else:
					return max(1		, int((1.0 - self.overlap) * self.chunk_length					)					)





	@property
	def   __lowerCAmelCase (						self    :Dict					)							->			int:







			'''simple docstring'''




			SCREAMING_SNAKE_CASE       :     Tuple				= np.prod(self.upsampling_ratios					)
			return math.ceil(self.sampling_rate / hop_length					)







	@property
	def   __lowerCAmelCase (						self    :Dict					)							->			int:







			'''simple docstring'''




			return int(10_00 * self.target_bandwidths[-1] // (self.frame_rate * 10)					)





