


"""simple docstring"""






import sacrebleu as scb
from packaging import version
from sacrebleu import TER

import datasets


UpperCamelCase__				:Tuple			   =	"""\
@inproceedings{snover-etal-2006-study,
    title = \"A Study of Translation Edit Rate with Targeted Human Annotation\",
    author = \"Snover, Matthew  and
      Dorr, Bonnie  and
      Schwartz, Rich  and
      Micciulla, Linnea  and
      Makhoul, John\",
    booktitle = \"Proceedings of the 7th Conference of the Association for Machine Translation in the Americas: Technical Papers\",
    month = aug # \" 8-12\",
    year = \"2006\",
    address = \"Cambridge, Massachusetts, USA\",
    publisher = \"Association for Machine Translation in the Americas\",
    url = \"https://aclanthology.org/2006.amta-papers.25\",
    pages = \"223--231\",
}
@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\",
}
"""

UpperCamelCase__				:Optional[int]			   =	"""\
TER (Translation Edit Rate, also called Translation Error Rate) is a metric to quantify the edit operations that a
hypothesis requires to match a reference translation. We use the implementation that is already present in sacrebleu
(https://github.com/mjpost/sacreBLEU#ter), which in turn is inspired by the TERCOM implementation, which can be found
here: https://github.com/jhclark/tercom.

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#ter for more information.
"""

UpperCamelCase__				:List[str]			   =	"""
Produces TER scores alongside the number of edits and reference length.

Args:
    predictions (list of str): The system stream (a sequence of segments).
    references (list of list of str): A list of one or more reference streams (each a sequence of segments).
    normalized (boolean): If `True`, applies basic tokenization and normalization to sentences. Defaults to `False`.
    ignore_punct (boolean): If `True`, applies basic tokenization and normalization to sentences. Defaults to `False`.
    support_zh_ja_chars (boolean): If `True`, tokenization/normalization supports processing of Chinese characters,
                                    as well as Japanese Kanji, Hiragana, Katakana, and Phonetic Extensions of Katakana.
                                    Only applies if `normalized = True`. Defaults to `False`.
    case_sensitive (boolean): If `False`, makes all predictions and references lowercase to ignore differences in case. Defaults to `False`.

Returns:
    \'score\' (float): TER score (num_edits / sum_ref_lengths * 100)
    \'num_edits\' (int): The cumulative number of edits
    \'ref_length\' (float): The cumulative average reference length

Examples:
    Example 1:
        >>> predictions = [\"does this sentence match??\",
        ...                     \"what about this sentence?\",
        ...                     \"What did the TER metric user say to the developer?\"]
        >>> references = [[\"does this sentence match\", \"does this sentence match!?!\"],
        ...             [\"wHaT aBoUt ThIs SeNtEnCe?\", \"wHaT aBoUt ThIs SeNtEnCe?\"],
        ...             [\"Your jokes are...\", \"...TERrible\"]]
        >>> ter = datasets.load_metric(\"ter\")
        >>> results = ter.compute(predictions=predictions,
        ...                         references=references,
        ...                         case_sensitive=True)
        >>> print(results)
        {\'score\': 150.0, \'num_edits\': 15, \'ref_length\': 10.0}

    Example 2:
        >>> predictions = [\"does this sentence match??\",
        ...                     \"what about this sentence?\"]
        >>> references = [[\"does this sentence match\", \"does this sentence match!?!\"],
        ...             [\"wHaT aBoUt ThIs SeNtEnCe?\", \"wHaT aBoUt ThIs SeNtEnCe?\"]]
        >>> ter = datasets.load_metric(\"ter\")
        >>> results = ter.compute(predictions=predictions,
        ...                         references=references,
        ...                         case_sensitive=True)
        >>> print(results)
        {\'score\': 62.5, \'num_edits\': 5, \'ref_length\': 8.0}

    Example 3:
        >>> predictions = [\"does this sentence match??\",
        ...                     \"what about this sentence?\"]
        >>> references = [[\"does this sentence match\", \"does this sentence match!?!\"],
        ...             [\"wHaT aBoUt ThIs SeNtEnCe?\", \"wHaT aBoUt ThIs SeNtEnCe?\"]]
        >>> ter = datasets.load_metric(\"ter\")
        >>> results = ter.compute(predictions=predictions,
        ...                         references=references,
        ...                         normalized=True,
        ...                         case_sensitive=True)
        >>> print(results)
        {\'score\': 57.14285714285714, \'num_edits\': 6, \'ref_length\': 10.5}

    Example 4:
        >>> predictions = [\"does this sentence match??\",
        ...                     \"what about this sentence?\"]
        >>> references = [[\"does this sentence match\", \"does this sentence match!?!\"],
        ...             [\"wHaT aBoUt ThIs SeNtEnCe?\", \"wHaT aBoUt ThIs SeNtEnCe?\"]]
        >>> ter = datasets.load_metric(\"ter\")
        >>> results = ter.compute(predictions=predictions,
        ...                         references=references,
        ...                         ignore_punct=True,
        ...                         case_sensitive=False)
        >>> print(results)
        {\'score\': 0.0, \'num_edits\': 0, \'ref_length\': 8.0}

    Example 5:
        >>> predictions = [\"does this sentence match??\",
        ...                    \"what about this sentence?\",
        ...                    \"What did the TER metric user say to the developer?\"]
        >>> references = [[\"does this sentence match\", \"does this sentence match!?!\"],
        ...             [\"wHaT aBoUt ThIs SeNtEnCe?\", \"wHaT aBoUt ThIs SeNtEnCe?\"],
        ...             [\"Your jokes are...\", \"...TERrible\"]]
        >>> ter = datasets.load_metric(\"ter\")
        >>> results = ter.compute(predictions=predictions,
        ...                         references=references,
        ...                         ignore_punct=True,
        ...                         case_sensitive=False)
        >>> print(results)
        {\'score\': 100.0, \'num_edits\': 10, \'ref_length\': 10.0}
"""






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

		"""simple docstring"""





		def   _UpperCamelCase( self   )      ->	int:

					"""simple docstring"""



					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='''http://www.cs.umd.edu/~snover/tercom/'''					,				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#ter''']					,				reference_urls=[
					        '''https://github.com/jhclark/tercom''',
					    ]					,				)





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

					"""simple docstring"""



					_UpperCamelCase					:int					     =	len(references[0]   )
					if any(len(__lowerCamelCase   ) != references_per_prediction for refs in references   ):
								raise ValueError('''Sacrebleu requires the same number of references for each prediction'''   )
					_UpperCamelCase					:Optional[int]					     =	[[refs[i] for refs in references] for i in range(__lowerCamelCase   )]

					_UpperCamelCase					:List[Any]					     =	TER(
					    normalized=__lowerCamelCase					,				no_punct=__lowerCamelCase					,				asian_support=__lowerCamelCase					,				case_sensitive=__lowerCamelCase					,				)
					_UpperCamelCase					:List[str]					     =	sb_ter.corpus_score(__lowerCamelCase					,				__lowerCamelCase   )

					return {"score": output.score, "num_edits": output.num_edits, "ref_length": output.ref_length}





'''simple docstring'''





from typing import List, Optional

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


__lowerCamelCase												=						logging.get_logger(__name__)

__lowerCamelCase												=						{
    '''huggingface/autoformer-tourism-monthly''': '''https://huggingface.co/huggingface/autoformer-tourism-monthly/resolve/main/config.json''',
}




class 				UpperCAmelCase			(			_snake_case						):
 UpperCAmelCase				=					"autoformer"
 UpperCAmelCase				=					{
     "hidden_size": "d_model",
     "num_attention_heads": "encoder_attention_heads",
     "num_hidden_layers": "encoder_layers",
 }


 def __init__(      self							:	List[str]			,       __lowerCamelCase							:	Optional[int] = None			,       __lowerCamelCase							:	Optional[int] = None			,       __lowerCamelCase							:	str = "student_t"			,       __lowerCamelCase							:	str = "nll"			,       __lowerCamelCase							:	int = 1			,       __lowerCamelCase							:	List[int] = [1, 2, 3, 4, 5, 6, 7]			,       __lowerCamelCase							:	bool = True			,       __lowerCamelCase							:	int = 0			,       __lowerCamelCase							:	int = 0			,       __lowerCamelCase							:	int = 0			,       __lowerCamelCase							:	int = 0			,       __lowerCamelCase							:	Optional[List[int]] = None			,       __lowerCamelCase							:	Optional[List[int]] = None			,       __lowerCamelCase							:	int = 6_4			,       __lowerCamelCase							:	int = 2			,       __lowerCamelCase							:	int = 2			,       __lowerCamelCase							:	int = 2			,       __lowerCamelCase							:	int = 2			,       __lowerCamelCase							:	int = 3_2			,       __lowerCamelCase							:	int = 3_2			,       __lowerCamelCase							:	str = "gelu"			,       __lowerCamelCase							:	float = 0.1			,       __lowerCamelCase							:	float = 0.1			,       __lowerCamelCase							:	float = 0.1			,       __lowerCamelCase							:	float = 0.1			,       __lowerCamelCase							:	float = 0.1			,       __lowerCamelCase							:	int = 1_0_0			,       __lowerCamelCase							:	float = 0.02			,       __lowerCamelCase							:	bool = True			,       __lowerCamelCase							:	Optional[int]=True			,       __lowerCamelCase							:	int = 1_0			,       __lowerCamelCase							:	int = 2_5			,       __lowerCamelCase							:	int = 3			,       **__lowerCamelCase							:	int			,       ):
    # time series specific configuration
    UpperCAmelCase__	:Any      =      prediction_length
    UpperCAmelCase__	:Optional[int]      =      context_length if context_length is not None else prediction_length
    UpperCAmelCase__	:int      =      distribution_output
    UpperCAmelCase__	:str      =      loss
    UpperCAmelCase__	:Tuple      =      input_size
    UpperCAmelCase__	:Optional[int]      =      num_time_features
    UpperCAmelCase__	:List[Any]      =      lags_sequence
    UpperCAmelCase__	:Any      =      scaling
    UpperCAmelCase__	:Union[str, Any]      =      num_dynamic_real_features
    UpperCAmelCase__	:Dict      =      num_static_real_features
    UpperCAmelCase__	:Optional[int]      =      num_static_categorical_features
    if cardinality is not None and num_static_categorical_features > 0:
       if len(__lowerCamelCase ) != num_static_categorical_features:
          raise ValueError(
              '''The cardinality should be a list of the same length as `num_static_categorical_features`''' )
       UpperCAmelCase__	:Any      =      cardinality
    else:
       UpperCAmelCase__	:Dict      =      [0]
    if embedding_dimension is not None and num_static_categorical_features > 0:
       if len(__lowerCamelCase ) != num_static_categorical_features:
          raise ValueError(
              '''The embedding dimension should be a list of the same length as `num_static_categorical_features`''' )
       UpperCAmelCase__	:List[str]      =      embedding_dimension
    else:
       UpperCAmelCase__	:int      =      [min(5_0			,       (cat + 1) // 2 ) for cat in self.cardinality]
    UpperCAmelCase__	:Optional[Any]      =      num_parallel_samples

    # Transformer architecture configuration
    UpperCAmelCase__	:Optional[Any]      =      input_size * len(self.lags_sequence ) + self._number_of_features
    UpperCAmelCase__	:Optional[Any]      =      d_model
    UpperCAmelCase__	:Any      =      encoder_attention_heads
    UpperCAmelCase__	:Any      =      decoder_attention_heads
    UpperCAmelCase__	:int      =      encoder_ffn_dim
    UpperCAmelCase__	:Union[str, Any]      =      decoder_ffn_dim
    UpperCAmelCase__	:Optional[Any]      =      encoder_layers
    UpperCAmelCase__	:str      =      decoder_layers

    UpperCAmelCase__	:Optional[Any]      =      dropout
    UpperCAmelCase__	:str      =      attention_dropout
    UpperCAmelCase__	:int      =      activation_dropout
    UpperCAmelCase__	:Optional[Any]      =      encoder_layerdrop
    UpperCAmelCase__	:Dict      =      decoder_layerdrop

    UpperCAmelCase__	:Union[str, Any]      =      activation_function
    UpperCAmelCase__	:List[Any]      =      init_std

    UpperCAmelCase__	:List[str]      =      use_cache

    # Autoformer
    UpperCAmelCase__	:List[str]      =      label_length
    UpperCAmelCase__	:Dict      =      moving_average
    UpperCAmelCase__	:str      =      autocorrelation_factor

    super().__init__(is_encoder_decoder=__lowerCamelCase			,       **__lowerCamelCase )





 @property
 def        __SCREAMING_SNAKE_CASE					(      self							:	int ):
    return (
        sum(self.embedding_dimension )
        + self.num_dynamic_real_features
        + self.num_time_features
        + self.num_static_real_features
        + self.input_size * 2  # the log1p(abs(loc)) and log(scale) features
    )



