


import datasets

from .evaluate import evaluate


__snake_case   							=						'''\
@inproceedings{Rajpurkar2016SQuAD10,
  title={SQuAD: 100, 000+ Questions for Machine Comprehension of Text},
  author={Pranav Rajpurkar and Jian Zhang and Konstantin Lopyrev and Percy Liang},
  booktitle={EMNLP},
  year={2016}
}
'''

__snake_case   							=						'''
This metric wrap the official scoring script for version 1 of the Stanford Question Answering Dataset (SQuAD).

Stanford Question Answering Dataset (SQuAD) is a reading comprehension dataset, consisting of questions posed by
crowdworkers on a set of Wikipedia articles, where the answer to every question is a segment of text, or span,
from the corresponding reading passage, or the question might be unanswerable.
'''

__snake_case   							=						'''
Computes SQuAD scores (F1 and EM).
Args:
    predictions: List of question-answers dictionaries with the following key-values:
        - \'id\': id of the question-answer pair as given in the references (see below)
        - \'prediction_text\': the text of the answer
    references: List of question-answers dictionaries with the following key-values:
        - \'id\': id of the question-answer pair (see above),
        - \'answers\': a Dict in the SQuAD dataset format
            {
                \'text\': list of possible texts for the answer, as a list of strings
                \'answer_start\': list of start positions for the answer, as a list of ints
            }
            Note that answer_start values are not taken into account to compute the metric.
Returns:
    \'exact_match\': Exact match (the normalized answer exactly match the gold answer)
    \'f1\': The F-score of predicted tokens versus the gold answer
Examples:

    >>> predictions = [{\'prediction_text\': \'1976\', \'id\': \'56e10a3be3433e1400422b22\'}]
    >>> references = [{\'answers\': {\'answer_start\': [97], \'text\': [\'1976\']}, \'id\': \'56e10a3be3433e1400422b22\'}]
    >>> squad_metric = datasets.load_metric("squad")
    >>> results = squad_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {\'exact_match\': 100.0, \'f1\': 100.0}
'''



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







       def 		snake_case_	(			self: Union[str, Any]					):






            '''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 		snake_case_	(			self: int,A_: int,A_: int					):






            '''simple docstring'''




            __UpperCamelCase =			{prediction['id']: prediction['prediction_text'] for prediction in predictions}
            __UpperCamelCase =			[
                {
                    'paragraphs': [
                        {
                            'qas': [
                                {
                                    'answers': [{'text': answer_text} for answer_text in ref['answers']['text']],
                                    'id': ref['id'],
                                }
                                for ref in references
                            ]
                        }
                    ]
                }
            ]
            __UpperCamelCase =			evaluate(dataset=A_,predictions=A_					)
            return score






from collections.abc import Generator
from math import sin






def 		_A		(		_lowercase )					-> bytes:


     """simple docstring"""


     if len(_lowercase ) != 32:
          raise ValueError('Input must be of length 32' )

     __UpperCamelCase =			B''
     for i in [3, 2, 1, 0]:
          little_endian += string_aa[8 * i : 8 * i + 8]
     return little_endian






def 		_A		(		_lowercase )					-> bytes:


     """simple docstring"""


     if i < 0:
          raise ValueError('Input must be non-negative' )

     __UpperCamelCase =			format(_lowercase					,  '08x' )[-8:]
     __UpperCamelCase =			B''
     for i in [3, 2, 1, 0]:
          little_endian_hex += hex_rep[2 * i : 2 * i + 2].encode('utf-8' )
     return little_endian_hex






def 		_A		(		_lowercase )					-> bytes:


     """simple docstring"""


     __UpperCamelCase =			B''
     for char in message:
          bit_string += format(_lowercase					,  '08b' ).encode('utf-8' )
     __UpperCamelCase =			format(len(_lowercase )					,  '064b' ).encode('utf-8' )

     # Pad bit_string to a multiple of 512 chars
     bit_string += b"1"
     while len(_lowercase ) % 5_12 != 4_48:
          bit_string += b"0"
     bit_string += to_little_endian(start_len[32:] ) + to_little_endian(start_len[:32] )

     return bit_string






def 		_A		(		_lowercase )					-> Generator[list[int], None, None]:


     """simple docstring"""


     if len(_lowercase ) % 5_12 != 0:
          raise ValueError('Input must have length that\'s a multiple of 512' )

     for pos in range(0					,  len(_lowercase )					,  5_12 ):
          __UpperCamelCase =			bit_string[pos : pos + 5_12]
          __UpperCamelCase =			[]
          for i in range(0					,  5_12					,  32 ):
               block_words.append(int(to_little_endian(block[i : i + 32] )					,  2 ) )
          yield block_words






def 		_A		(		_lowercase )					-> int:


     """simple docstring"""


     if i < 0:
          raise ValueError('Input must be non-negative' )

     __UpperCamelCase =			format(_lowercase					,  '032b' )
     __UpperCamelCase =			''
     for c in i_str:
          new_str += "1" if c == "0" else "0"
     return int(_lowercase					,  2 )






def 		_A		(		_lowercase					,  _lowercase )					-> int:


     """simple docstring"""


     return (a + b) % 2**32






def 		_A		(		_lowercase					,  _lowercase )					-> int:


     """simple docstring"""


     if i < 0:
          raise ValueError('Input must be non-negative' )
     if shift < 0:
          raise ValueError('Shift must be non-negative' )
     return ((i << shift) ^ (i >> (32 - shift))) % 2**32






def 		_A		(		_lowercase )					-> bytes:


     """simple docstring"""


     __UpperCamelCase =			preprocess(_lowercase )

     __UpperCamelCase =			[int(2**32 * abs(sin(i + 1 ) ) ) for i in range(64 )]

     # Starting states
     __UpperCamelCase =			0X67_45_23_01
     __UpperCamelCase =			0Xef_cd_ab_89
     __UpperCamelCase =			0X98_ba_dc_fe
     __UpperCamelCase =			0X10_32_54_76

     __UpperCamelCase =			[
         7,
         12,
         17,
         22,
         7,
         12,
         17,
         22,
         7,
         12,
         17,
         22,
         7,
         12,
         17,
         22,
         5,
         9,
         14,
         20,
         5,
         9,
         14,
         20,
         5,
         9,
         14,
         20,
         5,
         9,
         14,
         20,
         4,
         11,
         16,
         23,
         4,
         11,
         16,
         23,
         4,
         11,
         16,
         23,
         4,
         11,
         16,
         23,
         6,
         10,
         15,
         21,
         6,
         10,
         15,
         21,
         6,
         10,
         15,
         21,
         6,
         10,
         15,
         21,
     ]

     # Process bit string in chunks, each with 16 32-char words
     for block_words in get_block_words(_lowercase ):
          __UpperCamelCase =			aa
          __UpperCamelCase =			ba
          __UpperCamelCase =			ca
          __UpperCamelCase =			da

          # Hash current chunk
          for i in range(64 ):
               if i <= 15:
                    # f = (b & c) | (not_32(b) & d)     # Alternate definition for f
                    __UpperCamelCase =			d ^ (b & (c ^ d))
                    __UpperCamelCase =			i
               elif i <= 31:
                    # f = (d & b) | (not_32(d) & c)     # Alternate definition for f
                    __UpperCamelCase =			c ^ (d & (b ^ c))
                    __UpperCamelCase =			(5 * i + 1) % 16
               elif i <= 47:
                    __UpperCamelCase =			b ^ c ^ d
                    __UpperCamelCase =			(3 * i + 5) % 16
               else:
                    __UpperCamelCase =			c ^ (b | not_aa(_lowercase ))
                    __UpperCamelCase =			(7 * i) % 16
               __UpperCamelCase =			(f + a + added_consts[i] + block_words[g]) % 2**32
               __UpperCamelCase =			d
               __UpperCamelCase =			c
               __UpperCamelCase =			b
               __UpperCamelCase =			sum_aa(_lowercase					,  left_rotate_aa(_lowercase					,  shift_amounts[i] ) )

          # Add hashed chunk to running total
          __UpperCamelCase =			sum_aa(_lowercase					,  _lowercase )
          __UpperCamelCase =			sum_aa(_lowercase					,  _lowercase )
          __UpperCamelCase =			sum_aa(_lowercase					,  _lowercase )
          __UpperCamelCase =			sum_aa(_lowercase					,  _lowercase )

     __UpperCamelCase =			reformat_hex(_lowercase ) + reformat_hex(_lowercase ) + reformat_hex(_lowercase ) + reformat_hex(_lowercase )
     return digest


if __name__ == "__main__":
    import doctest

    doctest.testmod()


