




'''simple docstring'''







import argparse
import json
import os
import sys
import tempfile
import unittest
from argparse import Namespace
from dataclasses import dataclass, field
from enum import Enum
from pathlib import Path
from typing import List, Literal, Optional

import yaml

from transformers import HfArgumentParser, TrainingArguments
from transformers.hf_argparser import make_choice_type_function, string_to_bool


# Since Python 3.10, we can use the builtin `|` operator for Union types
# See PEP 604: https://peps.python.org/pep-0604
lowerCAmelCase_     						=				sys.version_info >= (3, 1_0)







def 						_A      ( UpperCAmelCase=None      ,UpperCAmelCase=None						):






   '''simple docstring'''







   return field(default_factory=lambda: default      ,metadata=UpperCAmelCase						)

@dataclass
class 	_snake_case:
 __snake_case:							int
 __snake_case:							float
 __snake_case:							str
 __snake_case:							bool




@dataclass
class 	_snake_case:
 __snake_case:							int						=					42
 __snake_case:							str						=					field(default='''toto'''       , metadata={'''help''': '''help message'''}      )




@dataclass
class 	_snake_case:
 __snake_case:							bool						=					False
 __snake_case:							bool						=					True
 __snake_case:							Optional[bool]						=					None




class 	_snake_case(			UpperCAmelCase      ):
 __snake_case:							int						=					'''titi'''
 __snake_case:							Optional[Any]						=					'''toto'''




class 	_snake_case(			UpperCAmelCase      ):
 __snake_case:							List[Any]						=					'''titi'''
 __snake_case:							Any						=					'''toto'''
 __snake_case:							Any						=					42




@dataclass
class 	_snake_case:
 __snake_case:							BasicEnum						=					"toto"






 def 						_UpperCamelCase (self       :  Any    )       ->   List[Any]:






    """simple docstring"""


    A__       =     BasicEnum(self.foo    )




@dataclass
class 	_snake_case:
 __snake_case:							MixedTypeEnum						=					"toto"






 def 						_UpperCamelCase (self       :  Optional[int]    )       ->   Dict:






    """simple docstring"""


    A__       =     MixedTypeEnum(self.foo    )




@dataclass
class 	_snake_case:
 __snake_case:							Optional[int]						=					None
 __snake_case:							Optional[float]						=					field(default=UpperCAmelCase       , metadata={'''help''': '''help message'''}      )
 __snake_case:							Optional[str]						=					None
 __snake_case:							Optional[List[str]]						=					list_field(default=[]      )
 __snake_case:							Optional[List[int]]						=					list_field(default=[]      )




@dataclass
class 	_snake_case:
 __snake_case:							List[int]						=					list_field(default=[]      )
 __snake_case:							List[int]						=					list_field(default=[1, 2, 3]      )
 __snake_case:							List[str]						=					list_field(default=['''Hallo''', '''Bonjour''', '''Hello''']      )
 __snake_case:							List[float]						=					list_field(default=[0.1, 0.2, 0.3]      )




@dataclass
class 	_snake_case:
 __snake_case:							List[int]						=					field()
 __snake_case:							str						=					field()
 __snake_case:							BasicEnum						=					field()






 def 						_UpperCamelCase (self       :  Tuple    )       ->   Union[str, Any]:






    """simple docstring"""


    A__       =     BasicEnum(self.required_enum    )




@dataclass
class 	_snake_case:
 __snake_case:							int
 __snake_case:							"BasicEnum"						=					field()
 __snake_case:							"Optional[bool]"						=					None
 __snake_case:							"str"						=					field(default='''toto'''       , metadata={'''help''': '''help message'''}      )
 __snake_case:							"List[str]"						=					list_field(default=['''Hallo''', '''Bonjour''', '''Hello''']      )


if is_python_no_less_than_3_10:

    @dataclass
    class 	_snake_case:
     __snake_case:							bool						=					False
     __snake_case:							bool						=					True
     __snake_case:							bool | None						=					None




    @dataclass
    class 	_snake_case:
     __snake_case:							int | None						=					None
     __snake_case:							float | None						=					field(default=UpperCAmelCase       , metadata={'''help''': '''help message'''}      )
     __snake_case:							str | None						=					None
     __snake_case:							list[str] | None						=					list_field(default=[]      )
     __snake_case:							list[int] | None						=					list_field(default=[]      )







class 	_snake_case(			unittest.TestCase      ):






 def 						_UpperCamelCase (self       :  Dict    ,		a       :  argparse.ArgumentParser    ,		a       :  argparse.ArgumentParser    )       ->   Union[str, Any]:






    """simple docstring"""


    self.assertEqual(len(a._actions    )    ,		len(b._actions    )    )
    for x, y in zip(a._actions    ,		b._actions    ):
       A__       =     {k: v for k, v in vars(a    ).items() if k != 'container'}
       A__       =     {k: v for k, v in vars(a    ).items() if k != 'container'}

       # Choices with mixed type have custom function as "type"
       # So we need to compare results directly for equality
       if xx.get('choices'    ,		a    ) and yy.get('choices'    ,		a    ):
          for expected_choice in yy["choices"] + xx["choices"]:
             self.assertEqual(xx['type'](a    )    ,		yy['type'](a    )    )
          del xx["type"], yy["type"]

       self.assertEqual(a    ,		a    )






 def 						_UpperCamelCase (self       :  List[str]    )       ->   Optional[Any]:






    """simple docstring"""


    A__       =     HfArgumentParser(a    )

    A__       =     argparse.ArgumentParser()
    expected.add_argument('--foo'    ,		type=a    ,		required=a    )
    expected.add_argument('--bar'    ,		type=a    ,		required=a    )
    expected.add_argument('--baz'    ,		type=a    ,		required=a    )
    expected.add_argument('--flag'    ,		type=a    ,		default=a    ,		const=a    ,		nargs='?'    )
    self.argparsersEqual(a    ,		a    )

    A__       =     ['--foo', '1', '--baz', 'quux', '--bar', '0.5']
    ((A__)  ,			)       =     parser.parse_args_into_dataclasses(a    ,		look_for_args_file=a    )
    self.assertFalse(example.flag    )






 def 						_UpperCamelCase (self       :  str    )       ->   Tuple:






    """simple docstring"""


    A__       =     HfArgumentParser(a    )

    A__       =     argparse.ArgumentParser()
    expected.add_argument('--foo'    ,		default=42    ,		type=a    )
    expected.add_argument('--baz'    ,		default='toto'    ,		type=a    ,		help='help message'    )
    self.argparsersEqual(a    ,		a    )






 def 						_UpperCamelCase (self       :  Union[str, Any]    )       ->   Union[str, Any]:






    """simple docstring"""


    A__       =     argparse.ArgumentParser()
    expected.add_argument('--foo'    ,		type=a    ,		default=a    ,		const=a    ,		nargs='?'    )
    expected.add_argument('--baz'    ,		type=a    ,		default=a    ,		const=a    ,		nargs='?'    )
    # A boolean no_* argument always has to come after its "default: True" regular counter-part
    # and its default must be set to False
    expected.add_argument('--no_baz'    ,		action='store_false'    ,		default=a    ,		dest='baz'    )
    expected.add_argument('--opt'    ,		type=a    ,		default=a    )

    A__       =     [WithDefaultBoolExample]
    if is_python_no_less_than_3_10:
       dataclass_types.append(a    )

    for dataclass_type in dataclass_types:
       A__       =     HfArgumentParser(a    )
       self.argparsersEqual(a    ,		a    )

       A__       =     parser.parse_args([]    )
       self.assertEqual(a    ,		Namespace(foo=a    ,		baz=a    ,		opt=a    )    )

       A__       =     parser.parse_args(['--foo', '--no_baz']    )
       self.assertEqual(a    ,		Namespace(foo=a    ,		baz=a    ,		opt=a    )    )

       A__       =     parser.parse_args(['--foo', '--baz']    )
       self.assertEqual(a    ,		Namespace(foo=a    ,		baz=a    ,		opt=a    )    )

       A__       =     parser.parse_args(['--foo', 'True', '--baz', 'True', '--opt', 'True']    )
       self.assertEqual(a    ,		Namespace(foo=a    ,		baz=a    ,		opt=a    )    )

       A__       =     parser.parse_args(['--foo', 'False', '--baz', 'False', '--opt', 'False']    )
       self.assertEqual(a    ,		Namespace(foo=a    ,		baz=a    ,		opt=a    )    )






 def 						_UpperCamelCase (self       :  str    )       ->   Tuple:






    """simple docstring"""


    A__       =     HfArgumentParser(a    )

    A__       =     argparse.ArgumentParser()
    expected.add_argument(
        '--foo'    ,		default='toto'    ,		choices=['titi', 'toto', 42]    ,		type=make_choice_type_function(['titi', 'toto', 42]    )    ,		)
    self.argparsersEqual(a    ,		a    )

    A__       =     parser.parse_args([]    )
    self.assertEqual(args.foo    ,		'toto'    )
    A__       =     parser.parse_args_into_dataclasses([]    )[0]
    self.assertEqual(enum_ex.foo    ,		MixedTypeEnum.toto    )

    A__       =     parser.parse_args(['--foo', 'titi']    )
    self.assertEqual(args.foo    ,		'titi'    )
    A__       =     parser.parse_args_into_dataclasses(['--foo', 'titi']    )[0]
    self.assertEqual(enum_ex.foo    ,		MixedTypeEnum.titi    )

    A__       =     parser.parse_args(['--foo', '42']    )
    self.assertEqual(args.foo    ,		42    )
    A__       =     parser.parse_args_into_dataclasses(['--foo', '42']    )[0]
    self.assertEqual(enum_ex.foo    ,		MixedTypeEnum.fourtytwo    )






 def 						_UpperCamelCase (self       :  List[Any]    )       ->   Tuple:






    """simple docstring"""


    @dataclass
    class 	_snake_case:
     __snake_case:							Literal["titi", "toto", 42]						=					"toto"




    A__       =     HfArgumentParser(a    )

    A__       =     argparse.ArgumentParser()
    expected.add_argument(
        '--foo'    ,		default='toto'    ,		choices=('titi', 'toto', 42)    ,		type=make_choice_type_function(['titi', 'toto', 42]    )    ,		)
    self.argparsersEqual(a    ,		a    )

    A__       =     parser.parse_args([]    )
    self.assertEqual(args.foo    ,		'toto'    )

    A__       =     parser.parse_args(['--foo', 'titi']    )
    self.assertEqual(args.foo    ,		'titi'    )

    A__       =     parser.parse_args(['--foo', '42']    )
    self.assertEqual(args.foo    ,		42    )






 def 						_UpperCamelCase (self       :  Optional[Any]    )       ->   Optional[Any]:






    """simple docstring"""


    A__       =     HfArgumentParser(a    )

    A__       =     argparse.ArgumentParser()
    expected.add_argument('--foo_int'    ,		nargs='+'    ,		default=[]    ,		type=a    )
    expected.add_argument('--bar_int'    ,		nargs='+'    ,		default=[1, 2, 3]    ,		type=a    )
    expected.add_argument('--foo_str'    ,		nargs='+'    ,		default=['Hallo', 'Bonjour', 'Hello']    ,		type=a    )
    expected.add_argument('--foo_float'    ,		nargs='+'    ,		default=[0.1, 0.2, 0.3]    ,		type=a    )

    self.argparsersEqual(a    ,		a    )

    A__       =     parser.parse_args([]    )
    self.assertEqual(
        a    ,		Namespace(foo_int=[]    ,		bar_int=[1, 2, 3]    ,		foo_str=['Hallo', 'Bonjour', 'Hello']    ,		foo_float=[0.1, 0.2, 0.3]    )    ,		)

    A__       =     parser.parse_args('--foo_int 1 --bar_int 2 3 --foo_str a b c --foo_float 0.1 0.7'.split()    )
    self.assertEqual(a    ,		Namespace(foo_int=[1]    ,		bar_int=[2, 3]    ,		foo_str=['a', 'b', 'c']    ,		foo_float=[0.1, 0.7]    )    )






 def 						_UpperCamelCase (self       :  int    )       ->   int:






    """simple docstring"""


    A__       =     argparse.ArgumentParser()
    expected.add_argument('--foo'    ,		default=a    ,		type=a    )
    expected.add_argument('--bar'    ,		default=a    ,		type=a    ,		help='help message'    )
    expected.add_argument('--baz'    ,		default=a    ,		type=a    )
    expected.add_argument('--ces'    ,		nargs='+'    ,		default=[]    ,		type=a    )
    expected.add_argument('--des'    ,		nargs='+'    ,		default=[]    ,		type=a    )

    A__       =     [OptionalExample]
    if is_python_no_less_than_3_10:
       dataclass_types.append(a    )

    for dataclass_type in dataclass_types:
       A__       =     HfArgumentParser(a    )

       self.argparsersEqual(a    ,		a    )

       A__       =     parser.parse_args([]    )
       self.assertEqual(a    ,		Namespace(foo=a    ,		bar=a    ,		baz=a    ,		ces=[]    ,		des=[]    )    )

       A__       =     parser.parse_args('--foo 12 --bar 3.14 --baz 42 --ces a b c --des 1 2 3'.split()    )
       self.assertEqual(a    ,		Namespace(foo=12    ,		bar=3.14    ,		baz='42'    ,		ces=['a', 'b', 'c']    ,		des=[1, 2, 3]    )    )






 def 						_UpperCamelCase (self       :  Tuple    )       ->   List[str]:






    """simple docstring"""


    A__       =     HfArgumentParser(a    )

    A__       =     argparse.ArgumentParser()
    expected.add_argument('--required_list'    ,		nargs='+'    ,		type=a    ,		required=a    )
    expected.add_argument('--required_str'    ,		type=a    ,		required=a    )
    expected.add_argument(
        '--required_enum'    ,		type=make_choice_type_function(['titi', 'toto']    )    ,		choices=['titi', 'toto']    ,		required=a    ,		)
    self.argparsersEqual(a    ,		a    )






 def 						_UpperCamelCase (self       :  int    )       ->   Tuple:






    """simple docstring"""


    A__       =     HfArgumentParser(a    )

    A__       =     argparse.ArgumentParser()
    expected.add_argument('--foo'    ,		type=a    ,		required=a    )
    expected.add_argument(
        '--required_enum'    ,		type=make_choice_type_function(['titi', 'toto']    )    ,		choices=['titi', 'toto']    ,		required=a    ,		)
    expected.add_argument('--opt'    ,		type=a    ,		default=a    )
    expected.add_argument('--baz'    ,		default='toto'    ,		type=a    ,		help='help message'    )
    expected.add_argument('--foo_str'    ,		nargs='+'    ,		default=['Hallo', 'Bonjour', 'Hello']    ,		type=a    )
    self.argparsersEqual(a    ,		a    )






 def 						_UpperCamelCase (self       :  Any    )       ->   Optional[Any]:






    """simple docstring"""


    A__       =     HfArgumentParser(a    )

    A__       =     {
        'foo': 12,
        'bar': 3.14,
        'baz': '42',
        'flag': True,
    }

    A__       =     parser.parse_dict(a    )[0]
    A__       =     BasicExample(**a    )
    self.assertEqual(a    ,		a    )






 def 						_UpperCamelCase (self       :  Optional[int]    )       ->   List[str]:






    """simple docstring"""


    A__       =     HfArgumentParser(a    )

    A__       =     {
        'foo': 12,
        'bar': 3.14,
        'baz': '42',
        'flag': True,
        'extra': 42,
    }

    self.assertRaises(a    ,		parser.parse_dict    ,		a    ,		allow_extra_keys=a    )






 def 						_UpperCamelCase (self       :  List[Any]    )       ->   Union[str, Any]:






    """simple docstring"""


    A__       =     HfArgumentParser(a    )

    A__       =     {
        'foo': 12,
        'bar': 3.14,
        'baz': '42',
        'flag': True,
    }
    with tempfile.TemporaryDirectory() as tmp_dir:
       A__       =     os.path.join(a    ,		'temp_json'    )
       os.mkdir(a    )
       with open(temp_local_path + '.json'    ,		'w+'    ) as f:
          json.dump(a    ,		a    )
       A__       =     parser.parse_yaml_file(Path(temp_local_path + '.json'    )    )[0]

    A__       =     BasicExample(**a    )
    self.assertEqual(a    ,		a    )






 def 						_UpperCamelCase (self       :  Optional[int]    )       ->   List[Any]:






    """simple docstring"""


    A__       =     HfArgumentParser(a    )

    A__       =     {
        'foo': 12,
        'bar': 3.14,
        'baz': '42',
        'flag': True,
    }
    with tempfile.TemporaryDirectory() as tmp_dir:
       A__       =     os.path.join(a    ,		'temp_yaml'    )
       os.mkdir(a    )
       with open(temp_local_path + '.yaml'    ,		'w+'    ) as f:
          yaml.dump(a    ,		a    )
       A__       =     parser.parse_yaml_file(Path(temp_local_path + '.yaml'    )    )[0]
    A__       =     BasicExample(**a    )
    self.assertEqual(a    ,		a    )






 def 						_UpperCamelCase (self       :  List[Any]    )       ->   Optional[Any]:






    """simple docstring"""


    A__       =     HfArgumentParser(a    )
    self.assertIsNotNone(a    )








'''simple docstring'''







import re
import string

import numpy as np

import datasets


lowerCAmelCase_     						=				'''
Returns the rate at which the input predicted strings exactly match their references, ignoring any strings input as part of the regexes_to_ignore list.
'''

lowerCAmelCase_     						=				'''
Args:
    predictions: List of predicted texts.
    references: List of reference texts.
    regexes_to_ignore: List, defaults to None. Regex expressions of characters to
        ignore when calculating the exact matches. Note: these regexes are removed
        from the input data before the changes based on the options below (e.g. ignore_case,
        ignore_punctuation, ignore_numbers) are applied.
    ignore_case: Boolean, defaults to False. If true, turns everything
        to lowercase so that capitalization differences are ignored.
    ignore_punctuation: Boolean, defaults to False. If true, removes all punctuation before
        comparing predictions and references.
    ignore_numbers: Boolean, defaults to False. If true, removes all punctuation before
        comparing predictions and references.
Returns:
    exact_match: Dictionary containing exact_match rate. Possible values are between 0.0 and 100.0, inclusive.
Examples:
    >>> exact_match = datasets.load_metric("exact_match")
    >>> refs = ["the cat", "theater", "YELLING", "agent007"]
    >>> preds = ["cat?", "theater", "yelling", "agent"]
    >>> results = exact_match.compute(references=refs, predictions=preds)
    >>> print(round(results["exact_match"], 1))
    25.0

    >>> exact_match = datasets.load_metric("exact_match")
    >>> refs = ["the cat", "theater", "YELLING", "agent007"]
    >>> preds = ["cat?", "theater", "yelling", "agent"]
    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell"], ignore_case=True, ignore_punctuation=True)
    >>> print(round(results["exact_match"], 1))
    50.0


    >>> exact_match = datasets.load_metric("exact_match")
    >>> refs = ["the cat", "theater", "YELLING", "agent007"]
    >>> preds = ["cat?", "theater", "yelling", "agent"]
    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell", "YELL"], ignore_case=True, ignore_punctuation=True)
    >>> print(round(results["exact_match"], 1))
    75.0

    >>> exact_match = datasets.load_metric("exact_match")
    >>> refs = ["the cat", "theater", "YELLING", "agent007"]
    >>> preds = ["cat?", "theater", "yelling", "agent"]
    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell", "YELL"], ignore_case=True, ignore_punctuation=True, ignore_numbers=True)
    >>> print(round(results["exact_match"], 1))
    100.0

    >>> exact_match = datasets.load_metric("exact_match")
    >>> refs = ["The cat sat on the mat.", "Theaters are great.", "It\'s like comparing oranges and apples."]
    >>> preds = ["The cat sat on the mat?", "Theaters are great.", "It\'s like comparing apples and oranges."]
    >>> results = exact_match.compute(references=refs, predictions=preds)
    >>> print(round(results["exact_match"], 1))
    33.3

'''

lowerCAmelCase_     						=				'''
'''

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






 def 						_UpperCamelCase (self       :  Optional[Any]    )       ->   Dict:






    """simple docstring"""


    return datasets.MetricInfo(
        description=_DESCRIPTION    ,		citation=_CITATION    ,		inputs_description=_KWARGS_DESCRIPTION    ,		features=datasets.Features(
            {
                'predictions': datasets.Value('string'    ,		id='sequence'    ),
                'references': datasets.Value('string'    ,		id='sequence'    ),
            }    )    ,		reference_urls=[]    ,		)






 def 						_UpperCamelCase (self       :  List[str]    ,		a       :  str    ,		a       :  Tuple    ,		a       :  Tuple=None    ,		a       :  Dict=False    ,		a       :  Dict=False    ,		a       :  List[str]=False    ,		)       ->   int:






    """simple docstring"""


    if regexes_to_ignore is not None:
       for s in regexes_to_ignore:
          A__       =     np.array([re.sub(a    ,		''    ,		a    ) for x in predictions]    )
          A__       =     np.array([re.sub(a    ,		''    ,		a    ) for x in references]    )
    else:
       A__       =     np.asarray(a    )
       A__       =     np.asarray(a    )

    if ignore_case:
       A__       =     np.char.lower(a    )
       A__       =     np.char.lower(a    )

    if ignore_punctuation:
       A__       =     string.punctuation.maketrans(''    ,		''    ,		string.punctuation    )
       A__       =     np.char.translate(a    ,		table=a    )
       A__       =     np.char.translate(a    ,		table=a    )

    if ignore_numbers:
       A__       =     string.digits.maketrans(''    ,		''    ,		string.digits    )
       A__       =     np.char.translate(a    ,		table=a    )
       A__       =     np.char.translate(a    ,		table=a    )

    A__       =     predictions == references

    return {"exact_match": np.mean(a    ) * 1_00}


