



"""simple docstring"""







import functools
import operator

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


lowercase__		:    Optional[int]				   =     logging.get_logger(__name__)

lowercase__		:    List[Any]				   =     {
    """microsoft/unispeech-large-1500h-cv""": (
        """https://huggingface.co/microsoft/unispeech-large-1500h-cv/resolve/main/config.json"""
    ),
    # See all UniSpeech models at https://huggingface.co/models?filter=unispeech
}







class 				UpperCamelCase__       (     lowercase_  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE      =					"""unispeech"""



      def __init__(				self    :				str   ,      SCREAMING_SNAKE_CASE_    :				List[Any]=3_2   ,      SCREAMING_SNAKE_CASE_    :				Dict=7_6_8   ,      SCREAMING_SNAKE_CASE_    :				Tuple=1_2   ,      SCREAMING_SNAKE_CASE_    :				int=1_2   ,      SCREAMING_SNAKE_CASE_    :				Optional[int]=3_0_7_2   ,      SCREAMING_SNAKE_CASE_    :				Dict="gelu"   ,      SCREAMING_SNAKE_CASE_    :				Union[str, Any]=0.1   ,      SCREAMING_SNAKE_CASE_    :				Tuple=0.1   ,      SCREAMING_SNAKE_CASE_    :				List[Any]=0.1   ,      SCREAMING_SNAKE_CASE_    :				str=0.0   ,      SCREAMING_SNAKE_CASE_    :				Optional[int]=0.0   ,      SCREAMING_SNAKE_CASE_    :				List[Any]=0.1   ,      SCREAMING_SNAKE_CASE_    :				Union[str, Any]=0.1   ,      SCREAMING_SNAKE_CASE_    :				str=0.02   ,      SCREAMING_SNAKE_CASE_    :				Tuple=1E-5   ,      SCREAMING_SNAKE_CASE_    :				Any="group"   ,      SCREAMING_SNAKE_CASE_    :				str="gelu"   ,      SCREAMING_SNAKE_CASE_    :				List[str]=(5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2)   ,      SCREAMING_SNAKE_CASE_    :				List[Any]=(5, 2, 2, 2, 2, 2, 2)   ,      SCREAMING_SNAKE_CASE_    :				int=(1_0, 3, 3, 3, 3, 2, 2)   ,      SCREAMING_SNAKE_CASE_    :				Optional[int]=False   ,      SCREAMING_SNAKE_CASE_    :				Union[str, Any]=1_2_8   ,      SCREAMING_SNAKE_CASE_    :				List[str]=1_6   ,      SCREAMING_SNAKE_CASE_    :				int=False   ,      SCREAMING_SNAKE_CASE_    :				List[Any]=True   ,      SCREAMING_SNAKE_CASE_    :				List[str]=0.05   ,      SCREAMING_SNAKE_CASE_    :				Optional[int]=1_0   ,      SCREAMING_SNAKE_CASE_    :				Tuple=2   ,      SCREAMING_SNAKE_CASE_    :				int=0.0   ,      SCREAMING_SNAKE_CASE_    :				Any=1_0   ,      SCREAMING_SNAKE_CASE_    :				Any=0   ,      SCREAMING_SNAKE_CASE_    :				List[str]=3_2_0   ,      SCREAMING_SNAKE_CASE_    :				List[str]=2   ,      SCREAMING_SNAKE_CASE_    :				Any=0.1   ,      SCREAMING_SNAKE_CASE_    :				Any=1_0_0   ,      SCREAMING_SNAKE_CASE_    :				Optional[Any]=2_5_6   ,      SCREAMING_SNAKE_CASE_    :				str=2_5_6   ,      SCREAMING_SNAKE_CASE_    :				Tuple=0.1   ,      SCREAMING_SNAKE_CASE_    :				Optional[int]="mean"   ,      SCREAMING_SNAKE_CASE_    :				List[str]=False   ,      SCREAMING_SNAKE_CASE_    :				Dict=False   ,      SCREAMING_SNAKE_CASE_    :				int=2_5_6   ,      SCREAMING_SNAKE_CASE_    :				int=8_0   ,      SCREAMING_SNAKE_CASE_    :				List[Any]=0   ,      SCREAMING_SNAKE_CASE_    :				Optional[Any]=1   ,      SCREAMING_SNAKE_CASE_    :				List[str]=2   ,      SCREAMING_SNAKE_CASE_    :				Dict=0.5   ,      **SCREAMING_SNAKE_CASE_    :				Any   ,      ):
        super().__init__(**SCREAMING_SNAKE_CASE_   ,      pad_token_id=SCREAMING_SNAKE_CASE_   ,      bos_token_id=SCREAMING_SNAKE_CASE_   ,      eos_token_id=SCREAMING_SNAKE_CASE_	)
        lowerCAmelCase_       :    Dict								=			hidden_size
        lowerCAmelCase_       :    int								=			feat_extract_norm
        lowerCAmelCase_       :    List[str]								=			feat_extract_activation
        lowerCAmelCase_       :    List[Any]								=			list(SCREAMING_SNAKE_CASE_	)
        lowerCAmelCase_       :    Optional[Any]								=			list(SCREAMING_SNAKE_CASE_	)
        lowerCAmelCase_       :    Any								=			list(SCREAMING_SNAKE_CASE_	)
        lowerCAmelCase_       :    Optional[int]								=			conv_bias
        lowerCAmelCase_       :    Optional[Any]								=			num_conv_pos_embeddings
        lowerCAmelCase_       :    Any								=			num_conv_pos_embedding_groups
        lowerCAmelCase_       :    Optional[Any]								=			len(self.conv_dim	)
        lowerCAmelCase_       :    Optional[int]								=			num_hidden_layers
        lowerCAmelCase_       :    Any								=			intermediate_size
        lowerCAmelCase_       :    Dict								=			hidden_act
        lowerCAmelCase_       :    Union[str, Any]								=			num_attention_heads
        lowerCAmelCase_       :    str								=			hidden_dropout
        lowerCAmelCase_       :    str								=			attention_dropout
        lowerCAmelCase_       :    Tuple								=			activation_dropout
        lowerCAmelCase_       :    str								=			feat_proj_dropout
        lowerCAmelCase_       :    Optional[Any]								=			final_dropout
        lowerCAmelCase_       :    int								=			layerdrop
        lowerCAmelCase_       :    List[str]								=			layer_norm_eps
        lowerCAmelCase_       :    Optional[int]								=			initializer_range
        lowerCAmelCase_       :    Dict								=			num_ctc_classes
        lowerCAmelCase_       :    str								=			vocab_size
        lowerCAmelCase_       :    Union[str, Any]								=			do_stable_layer_norm
        lowerCAmelCase_       :    Any								=			use_weighted_layer_sum
        lowerCAmelCase_       :    str								=			classifier_proj_size

        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
        lowerCAmelCase_       :    Tuple								=			apply_spec_augment
        lowerCAmelCase_       :    str								=			mask_time_prob
        lowerCAmelCase_       :    Optional[int]								=			mask_time_length
        lowerCAmelCase_       :    Tuple								=			mask_time_min_masks
        lowerCAmelCase_       :    int								=			mask_feature_prob
        lowerCAmelCase_       :    Dict								=			mask_feature_length
        lowerCAmelCase_       :    Dict								=			mask_feature_min_masks

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

        # ctc loss
        lowerCAmelCase_       :    Dict								=			ctc_loss_reduction
        lowerCAmelCase_       :    Optional[Any]								=			ctc_zero_infinity

        # pretraining loss
        lowerCAmelCase_       :    Optional[int]								=			replace_prob





      @property
      def 					SCREAMING_SNAKE_CASE__			(				self    :				List[Any]	):
        return functools.reduce(operator.mul   ,      self.conv_stride   ,      1	)










"""simple docstring"""







import os

from bleurt import score  # From: git+https://github.com/google-research/bleurt.git

import datasets


lowercase__		:    Tuple				   =     datasets.logging.get_logger(__name__)


lowercase__		:    List[Any]				   =     """\
@inproceedings{bleurt,
  title={BLEURT: Learning Robust Metrics for Text Generation},
  author={Thibault Sellam and Dipanjan Das and Ankur P. Parikh},
  booktitle={ACL},
  year={2020},
  url={https://arxiv.org/abs/2004.04696}
}
"""

lowercase__		:    Tuple				   =     """\
BLEURT a learnt evaluation metric for Natural Language Generation. It is built using multiple phases of transfer learning starting from a pretrained BERT model (Devlin et al. 2018)
and then employing another pre-training phrase using synthetic data. Finally it is trained on WMT human annotations. You may run BLEURT out-of-the-box or fine-tune
it for your specific application (the latter is expected to perform better).

See the project's README at https://github.com/google-research/bleurt#readme for more information.
"""

lowercase__		:    List[Any]				   =     """
BLEURT score.

Args:
    `predictions` (list of str): prediction/candidate sentences
    `references` (list of str): reference sentences
    `checkpoint` BLEURT checkpoint. Will default to BLEURT-tiny if None.

Returns:
    'scores': List of scores.
Examples:

    >>> predictions = [\"hello there\", \"general kenobi\"]
    >>> references = [\"hello there\", \"general kenobi\"]
    >>> bleurt = datasets.load_metric(\"bleurt\")
    >>> results = bleurt.compute(predictions=predictions, references=references)
    >>> print([round(v, 2) for v in results[\"scores\"]])
    [1.03, 1.04]
"""

lowercase__		:    List[Any]				   =     {
    """bleurt-tiny-128""": """https://storage.googleapis.com/bleurt-oss/bleurt-tiny-128.zip""",
    """bleurt-tiny-512""": """https://storage.googleapis.com/bleurt-oss/bleurt-tiny-512.zip""",
    """bleurt-base-128""": """https://storage.googleapis.com/bleurt-oss/bleurt-base-128.zip""",
    """bleurt-base-512""": """https://storage.googleapis.com/bleurt-oss/bleurt-base-512.zip""",
    """bleurt-large-128""": """https://storage.googleapis.com/bleurt-oss/bleurt-large-128.zip""",
    """bleurt-large-512""": """https://storage.googleapis.com/bleurt-oss/bleurt-large-512.zip""",
    """BLEURT-20-D3""": """https://storage.googleapis.com/bleurt-oss-21/BLEURT-20-D3.zip""",
    """BLEURT-20-D6""": """https://storage.googleapis.com/bleurt-oss-21/BLEURT-20-D6.zip""",
    """BLEURT-20-D12""": """https://storage.googleapis.com/bleurt-oss-21/BLEURT-20-D12.zip""",
    """BLEURT-20""": """https://storage.googleapis.com/bleurt-oss-21/BLEURT-20.zip""",
}







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




      """simple docstring"""




      def 					SCREAMING_SNAKE_CASE__			(				self    :				List[str]	):
        return datasets.MetricInfo(
            description=_DESCRIPTION   ,      citation=_CITATION   ,      homepage='https://github.com/google-research/bleurt'   ,      inputs_description=_KWARGS_DESCRIPTION   ,      features=datasets.Features(
                {
                    'predictions': datasets.Value('string'   ,      id='sequence'	),
                    'references': datasets.Value('string'   ,      id='sequence'	),
                }	)   ,      codebase_urls=['https://github.com/google-research/bleurt']   ,      reference_urls=['https://github.com/google-research/bleurt', 'https://arxiv.org/abs/2004.04696']   ,      )



      def 					SCREAMING_SNAKE_CASE__			(				self    :				str   ,      SCREAMING_SNAKE_CASE_    :				str	):
        # check that config name specifies a valid BLEURT model
        if self.config_name == "default":
          logger.warning(
              'Using default BLEURT-Base checkpoint for sequence maximum length 128. '
              'You can use a bigger model for better results with e.g.: datasets.load_metric(\'bleurt\', \'bleurt-large-512\').'	)
          lowerCAmelCase_       :    List[Any]								=			'bleurt-base-128'

        if self.config_name.lower() in CHECKPOINT_URLS:
          lowerCAmelCase_       :    List[Any]								=			self.config_name.lower()

        elif self.config_name.upper() in CHECKPOINT_URLS:
          lowerCAmelCase_       :    Tuple								=			self.config_name.upper()

        else:
          raise KeyError(
              F"{self.config_name} model not found. You should supply the name of a model checkpoint for bleurt in {CHECKPOINT_URLS.keys()}"	)

        # download the model checkpoint specified by self.config_name and set up the scorer
        lowerCAmelCase_       :    List[Any]								=			dl_manager.download_and_extract(CHECKPOINT_URLS[checkpoint_name]	)
        lowerCAmelCase_       :    List[str]								=			score.BleurtScorer(os.path.join(SCREAMING_SNAKE_CASE_   ,      SCREAMING_SNAKE_CASE_	)	)





      def 					SCREAMING_SNAKE_CASE__			(				self    :				str   ,      SCREAMING_SNAKE_CASE_    :				List[Any]   ,      SCREAMING_SNAKE_CASE_    :				Any	):
        lowerCAmelCase_       :    Tuple								=			self.scorer.score(references=SCREAMING_SNAKE_CASE_   ,      candidates=SCREAMING_SNAKE_CASE_	)
        return {"scores": scores}





