






import functools
import operator

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


__lowerCamelCase	:		Tuple										=   logging.get_logger(__name__)

__lowerCamelCase	:		Optional[int]										=   {
    """facebook/wav2vec2-base-960h""": """https://huggingface.co/facebook/wav2vec2-base-960h/resolve/main/config.json""",
    # See all Wav2Vec2 models at https://huggingface.co/models?filter=wav2vec2
}







class  _lowercase   (   _A						):
						_a							:						int										=							'wav2vec2'
						def __init__(     self				,			a=3_2				,			a=7_6_8				,			a=1_2				,			a=1_2				,			a=3_0_7_2				,			a="gelu"				,			a=0.1				,			a=0.1				,			a=0.1				,			a=0.0				,			a=0.0				,			a=0.1				,			a=0.1				,			a=0.02				,			a=1e-5				,			a="group"				,			a="gelu"				,			a=(5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2)				,			a=(5, 2, 2, 2, 2, 2, 2)				,			a=(1_0, 3, 3, 3, 3, 2, 2)				,			a=False				,			a=1_2_8				,			a=1_6				,			a=False				,			a=True				,			a=0.05				,			a=1_0				,			a=2				,			a=0.0				,			a=1_0				,			a=0				,			a=3_2_0				,			a=2				,			a=0.1				,			a=1_0_0				,			a=2_5_6				,			a=2_5_6				,			a=0.1				,			a="sum"				,			a=False				,			a=False				,			a=2_5_6				,			a=(5_1_2, 5_1_2, 5_1_2, 5_1_2, 1_5_0_0)				,			a=(5, 3, 3, 1, 1)				,			a=(1, 2, 3, 1, 1)				,			a=5_1_2				,			a=0				,			a=1				,			a=2				,			a=False				,			a=3				,			a=2				,			a=3				,			a=None				,			a=None				,			**a				,			):
							super().__init__(**a				,			pad_token_id=a				,			bos_token_id=a				,			eos_token_id=a   )
							snake_case__  :    str							       =hidden_size
							snake_case__  :    int							       =feat_extract_norm
							snake_case__  :    List[str]							       =feat_extract_activation
							snake_case__  :    int							       =list(a   )
							snake_case__  :    Tuple							       =list(a   )
							snake_case__  :    Any							       =list(a   )
							snake_case__  :    Dict							       =conv_bias
							snake_case__  :    List[Any]							       =num_conv_pos_embeddings
							snake_case__  :    int							       =num_conv_pos_embedding_groups
							snake_case__  :    Union[str, Any]							       =len(self.conv_dim   )
							snake_case__  :    Optional[Any]							       =num_hidden_layers
							snake_case__  :    Tuple							       =intermediate_size
							snake_case__  :    List[str]							       =hidden_act
							snake_case__  :    Optional[int]							       =num_attention_heads
							snake_case__  :    Tuple							       =hidden_dropout
							snake_case__  :    str							       =attention_dropout
							snake_case__  :    Tuple							       =activation_dropout
							snake_case__  :    Optional[Any]							       =feat_proj_dropout
							snake_case__  :    List[Any]							       =final_dropout
							snake_case__  :    Dict							       =layerdrop
							snake_case__  :    Any							       =layer_norm_eps
							snake_case__  :    Optional[Any]							       =initializer_range
							snake_case__  :    Dict							       =vocab_size
							snake_case__  :    Optional[Any]							       =do_stable_layer_norm
							snake_case__  :    Any							       =use_weighted_layer_sum

							if (
							    (len(self.conv_stride   ) != self.num_feat_extract_layers)
							    or (len(self.conv_kernel   ) != self.num_feat_extract_layers)
							    or (len(self.conv_dim   ) != self.num_feat_extract_layers)
							):
								raise ValueError(
								    """Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =="""
								    """ `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ="""
								    F" {len(self.conv_dim   )}`, `len(config.conv_stride) = {len(self.conv_stride   )}`,"
								    F" `len(config.conv_kernel) = {len(self.conv_kernel   )}`."   )

							# fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
							snake_case__  :    Dict							       =apply_spec_augment
							snake_case__  :    Optional[Any]							       =mask_time_prob
							snake_case__  :    Dict							       =mask_time_length
							snake_case__  :    str							       =mask_time_min_masks
							snake_case__  :    int							       =mask_feature_prob
							snake_case__  :    List[str]							       =mask_feature_length
							snake_case__  :    Union[str, Any]							       =mask_feature_min_masks

							# parameters for pretraining with codevector quantized representations
							snake_case__  :    int							       =num_codevectors_per_group
							snake_case__  :    Tuple							       =num_codevector_groups
							snake_case__  :    Tuple							       =contrastive_logits_temperature
							snake_case__  :    Union[str, Any]							       =feat_quantizer_dropout
							snake_case__  :    Optional[Any]							       =num_negatives
							snake_case__  :    Dict							       =codevector_dim
							snake_case__  :    Optional[int]							       =proj_codevector_dim
							snake_case__  :    Optional[int]							       =diversity_loss_weight

							# ctc loss
							snake_case__  :    Any							       =ctc_loss_reduction
							snake_case__  :    List[str]							       =ctc_zero_infinity

							# adapter
							snake_case__  :    Any							       =add_adapter
							snake_case__  :    int							       =adapter_kernel_size
							snake_case__  :    Any							       =adapter_stride
							snake_case__  :    Tuple							       =num_adapter_layers
							snake_case__  :    Tuple							       =output_hidden_size or hidden_size
							snake_case__  :    str							       =adapter_attn_dim

							# SequenceClassification-specific parameter. Feel free to ignore for other classes.
							snake_case__  :    Tuple							       =classifier_proj_size

							# XVector-specific parameters. Feel free to ignore for other classes.
							snake_case__  :    Union[str, Any]							       =list(a   )
							snake_case__  :    Optional[Any]							       =list(a   )
							snake_case__  :    Optional[Any]							       =list(a   )
							snake_case__  :    Tuple							       =xvector_output_dim



						@property
						def 						lowercase__					(     self   ):
							return functools.reduce(operator.mul				,			self.conv_stride				,			1   )













import sacrebleu as scb
from packaging import version
from sacrebleu import CHRF

import datasets


__lowerCamelCase	:		Dict										=   """\
@inproceedings{popovic-2015-chrf,
    title = \"chr{F}: character n-gram {F}-score for automatic {MT} evaluation\",
    author = \"Popovi{\'c}, Maja\",
    booktitle = \"Proceedings of the Tenth Workshop on Statistical Machine Translation\",
    month = sep,
    year = \"2015\",
    address = \"Lisbon, Portugal\",
    publisher = \"Association for Computational Linguistics\",
    url = \"https://aclanthology.org/W15-3049\",
    doi = \"10.18653/v1/W15-3049\",
    pages = \"392--395\",
}
@inproceedings{popovic-2017-chrf,
    title = \"chr{F}++: words helping character n-grams\",
    author = \"Popovi{\'c}, Maja\",
    booktitle = \"Proceedings of the Second Conference on Machine Translation\",
    month = sep,
    year = \"2017\",
    address = \"Copenhagen, Denmark\",
    publisher = \"Association for Computational Linguistics\",
    url = \"https://aclanthology.org/W17-4770\",
    doi = \"10.18653/v1/W17-4770\",
    pages = \"612--618\",
}
@inproceedings{post-2018-call,
    title = \"A Call for Clarity in Reporting {BLEU} Scores\",
    author = \"Post, Matt\",
    booktitle = \"Proceedings of the Third Conference on Machine Translation: Research Papers\",
    month = oct,
    year = \"2018\",
    address = \"Belgium, Brussels\",
    publisher = \"Association for Computational Linguistics\",
    url = \"https://www.aclweb.org/anthology/W18-6319\",
    pages = \"186--191\",
}
"""

__lowerCamelCase	:		Optional[int]										=   """\
ChrF and ChrF++ are two MT evaluation metrics. They both use the F-score statistic for character n-gram matches,
and ChrF++ adds word n-grams as well which correlates more strongly with direct assessment. We use the implementation
that is already present in sacrebleu.

The implementation here is slightly different from sacrebleu in terms of the required input format. The length of
the references and hypotheses lists need to be the same, so you may need to transpose your references compared to
sacrebleu's required input format. See https://github.com/huggingface/datasets/issues/3154#issuecomment-950746534

See the README.md file at https://github.com/mjpost/sacreBLEU#chrf--chrf for more information.
"""

__lowerCamelCase	:		List[str]										=   """
Produces ChrF(++) scores for hypotheses given reference translations.

Args:
    predictions (list of str): The predicted sentences.
    references (list of list of str): The references. There should be one reference sub-list for each prediction sentence.
    char_order (int): Character n-gram order. Defaults to `6`.
    word_order (int): Word n-gram order. If equals to `2`, the metric is referred to as chrF++. Defaults to `0`.
    beta (int): Determine the importance of recall w.r.t precision. Defaults to `2`.
    lowercase (bool): if `True`, enables case-insensitivity. Defaults to `False`.
    whitespace (bool): If `True`, include whitespaces when extracting character n-grams.
    eps_smoothing (bool): If `True`, applies epsilon smoothing similar
    to reference chrF++.py, NLTK and Moses implementations. If `False`,
    it takes into account effective match order similar to sacreBLEU < 2.0.0. Defaults to `False`.

Returns:
    'score' (float): The chrF (chrF++) score,
    'char_order' (int): The character n-gram order,
    'word_order' (int): The word n-gram order. If equals to 2, the metric is referred to as chrF++,
    'beta' (int): Determine the importance of recall w.r.t precision

Examples:
    Example 1--a simple example of calculating chrF:
        >>> prediction = [\"The relationship between cats and dogs is not exactly friendly.\", \"a good bookshop is just a genteel black hole that knows how to read.\"]
        >>> reference = [[\"The relationship between dogs and cats is not exactly friendly.\"], [\"A good bookshop is just a genteel Black Hole that knows how to read.\"]]
        >>> chrf = datasets.load_metric(\"chrf\")
        >>> results = chrf.compute(predictions=prediction, references=reference)
        >>> print(results)
        {'score': 84.64214891738334, 'char_order': 6, 'word_order': 0, 'beta': 2}

    Example 2--the same example, but with the argument word_order=2, to calculate chrF++ instead of chrF:
        >>> prediction = [\"The relationship between cats and dogs is not exactly friendly.\", \"a good bookshop is just a genteel black hole that knows how to read.\"]
        >>> reference = [[\"The relationship between dogs and cats is not exactly friendly.\"], [\"A good bookshop is just a genteel Black Hole that knows how to read.\"]]
        >>> chrf = datasets.load_metric(\"chrf\")
        >>> results = chrf.compute(predictions=prediction,
        ...                         references=reference,
        ...                         word_order=2)
        >>> print(results)
        {'score': 82.87263732906315, 'char_order': 6, 'word_order': 2, 'beta': 2}

    Example 3--the same chrF++ example as above, but with `lowercase=True` to normalize all case:
        >>> prediction = [\"The relationship between cats and dogs is not exactly friendly.\", \"a good bookshop is just a genteel black hole that knows how to read.\"]
        >>> reference = [[\"The relationship between dogs and cats is not exactly friendly.\"], [\"A good bookshop is just a genteel Black Hole that knows how to read.\"]]
        >>> chrf = datasets.load_metric(\"chrf\")
        >>> results = chrf.compute(predictions=prediction,
        ...                         references=reference,
        ...                         word_order=2,
        ...                         lowercase=True)
        >>> print(results)
        {'score': 92.12853119829202, 'char_order': 6, 'word_order': 2, 'beta': 2}
"""







@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION						,				_KWARGS_DESCRIPTION						)
class  _lowercase   (   datasets.Metric						):
      def 						lowercase__					(     self   ):
       if version.parse(scb.__version__   ) < version.parse("""1.4.12"""   ):
        raise ImportWarning(
            """To use `sacrebleu`, the module `sacrebleu>=1.4.12` is required, and the current version of `sacrebleu` doesn't match this condition.\n"""
            """You can install it with `pip install \"sacrebleu>=1.4.12\"`."""   )
       return datasets.MetricInfo(
           description=_DESCRIPTION				,			citation=_CITATION				,			homepage="""https://github.com/mjpost/sacreBLEU#chrf--chrf"""				,			inputs_description=_KWARGS_DESCRIPTION				,			features=datasets.Features(
               {
                   """predictions""": datasets.Value("""string"""				,			id="""sequence"""   ),
                   """references""": datasets.Sequence(datasets.Value("""string"""				,			id="""sequence"""   )				,			id="""references"""   ),
               }   )				,			codebase_urls=["""https://github.com/mjpost/sacreBLEU#chrf--chrf"""]				,			reference_urls=[
               """https://github.com/m-popovic/chrF""",
           ]				,			)



      def 						lowercase__					(     self				,			a				,			a				,			a = CHRF.CHAR_ORDER				,			a = CHRF.WORD_ORDER				,			a = CHRF.BETA				,			a = False				,			a = False				,			a = False				,			):
       snake_case__  :    str							       =len(references[0]   )
       if any(len(a   ) != references_per_prediction for refs in references   ):
        raise ValueError("""Sacrebleu requires the same number of references for each prediction"""   )
       snake_case__  :    List[Any]							       =[[refs[i] for refs in references] for i in range(a   )]

       snake_case__  :    int							       =CHRF(a				,			a				,			a				,			a				,			a				,			a   )
       snake_case__  :    int							       =sb_chrf.corpus_score(a				,			a   )

       return {
           "score": output.score,
           "char_order": output.char_order,
           "word_order": output.word_order,
           "beta": output.beta,
       }





