





import shutil
import tempfile
import unittest

from transformers import (
    SPIECE_UNDERLINE,
    AddedToken,
    BatchEncoding,
    NllbTokenizer,
    NllbTokenizerFast,
    is_torch_available,
)
from transformers.testing_utils import (
    get_tests_dir,
    nested_simplify,
    require_sentencepiece,
    require_tokenizers,
    require_torch,
)

from ...test_tokenization_common import TokenizerTesterMixin


SCREAMING_SNAKE_CASE__							:      List[Any]         =    get_tests_dir("""fixtures/test_sentencepiece.model""")


if is_torch_available():
  from transformers.models.mam_aaa.modeling_mam_aaa import shift_tokens_right

SCREAMING_SNAKE_CASE__							:      Optional[int]         =    2_5_6_0_4_7
SCREAMING_SNAKE_CASE__							:      List[Any]         =    2_5_6_1_4_5







@require_sentencepiece
@require_tokenizers
class 	__lowerCAmelCase      (       _UpperCamelCase		,unittest.TestCase	):
   _UpperCamelCase			:    Optional[Any]  		=					NllbTokenizer
   _UpperCamelCase			:    Tuple  		=					NllbTokenizerFast
   _UpperCamelCase			:    Optional[int]  		=					True
   _UpperCamelCase			:    Dict  		=					True
   _UpperCamelCase			:    Union[str, Any]  		=					{}





   def 						_snake_case			(			self   )					->	Optional[Any]:
      """simple docstring"""





      super().setUp()

      # We have a SentencePiece fixture for testing
      a__						:    Dict   		=	NllbTokenizer(snake_case       ,      keep_accents=snake_case   )
      tokenizer.save_pretrained(self.tmpdirname   )





   def 						_snake_case			(			self   )					->	str:
      """simple docstring"""





      a__						:    Tuple   		=	NllbTokenizer(snake_case       ,      keep_accents=snake_case   )

      a__						:    Union[str, Any]   		=	tokenizer.tokenize("This is a test"   )
      self.assertListEqual(snake_case       ,      ["▁This", "▁is", "▁a", "▁t", "est"]   )

      self.assertListEqual(
          tokenizer.convert_tokens_to_ids(snake_case   )       ,      [value + tokenizer.fairseq_offset for value in [285, 46, 10, 170, 382]]       ,      )

      a__						:    int   		=	tokenizer.tokenize("I was born in 92000, and this is falsé."   )
      self.assertListEqual(
          snake_case       ,      [
              SPIECE_UNDERLINE + "I",
              SPIECE_UNDERLINE + "was",
              SPIECE_UNDERLINE + "b",
              "or",
              "n",
              SPIECE_UNDERLINE + "in",
              SPIECE_UNDERLINE + "",
              "9",
              "2",
              "0",
              "0",
              "0",
              ",",
              SPIECE_UNDERLINE + "and",
              SPIECE_UNDERLINE + "this",
              SPIECE_UNDERLINE + "is",
              SPIECE_UNDERLINE + "f",
              "al",
              "s",
              "é",
              ".",
          ]       ,      )
      a__						:    Optional[Any]   		=	tokenizer.convert_tokens_to_ids(snake_case   )
      self.assertListEqual(
          snake_case       ,      [
              value + tokenizer.fairseq_offset
              for value in [8, 21, 84, 55, 24, 19, 7, 2, 602, 347, 347, 347, 3, 12, 66, 46, 72, 80, 6, 2, 4]
          ]       ,      )

      a__						:    Tuple   		=	tokenizer.convert_ids_to_tokens(snake_case   )
      self.assertListEqual(
          snake_case       ,      [
              SPIECE_UNDERLINE + "I",
              SPIECE_UNDERLINE + "was",
              SPIECE_UNDERLINE + "b",
              "or",
              "n",
              SPIECE_UNDERLINE + "in",
              SPIECE_UNDERLINE + "",
              "<unk>",
              "2",
              "0",
              "0",
              "0",
              ",",
              SPIECE_UNDERLINE + "and",
              SPIECE_UNDERLINE + "this",
              SPIECE_UNDERLINE + "is",
              SPIECE_UNDERLINE + "f",
              "al",
              "s",
              "<unk>",
              ".",
          ]       ,      )





   def 						_snake_case			(			self   )					->	Optional[int]:
      """simple docstring"""





      a__						:    Optional[int]   		=	(self.rust_tokenizer_class, "hf-internal-testing/tiny-random-nllb", {})
      for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
         with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})"""   ):
            a__						:    str   		=	self.rust_tokenizer_class.from_pretrained(snake_case       ,      **snake_case   )
            a__						:    Optional[int]   		=	self.tokenizer_class.from_pretrained(snake_case       ,      **snake_case   )

            a__						:    Dict   		=	tempfile.mkdtemp()

            a__						:    str   		=	tokenizer_r.save_pretrained(snake_case   )
            a__						:    Any   		=	tokenizer_p.save_pretrained(snake_case   )

            # Checks it save with the same files + the tokenizer.json file for the fast one
            self.assertTrue(any("tokenizer.json" in f for f in tokenizer_r_files   )   )
            a__						:    Dict   		=	tuple(f for f in tokenizer_r_files if "tokenizer.json" not in f   )
            self.assertSequenceEqual(snake_case       ,      snake_case   )

            # Checks everything loads correctly in the same way
            a__						:    Optional[Any]   		=	tokenizer_r.from_pretrained(snake_case   )
            a__						:    Optional[Any]   		=	tokenizer_p.from_pretrained(snake_case   )

            # Check special tokens are set accordingly on Rust and Python
            for key in tokenizer_pp.special_tokens_map:
               self.assertTrue(hasattr(snake_case       ,      snake_case   )   )

            shutil.rmtree(snake_case   )

            # Save tokenizer rust, legacy_format=True
            a__						:    Optional[Any]   		=	tempfile.mkdtemp()

            a__						:    str   		=	tokenizer_r.save_pretrained(snake_case       ,      legacy_format=snake_case   )
            a__						:    List[Any]   		=	tokenizer_p.save_pretrained(snake_case   )

            # Checks it save with the same files
            self.assertSequenceEqual(snake_case       ,      snake_case   )

            # Checks everything loads correctly in the same way
            a__						:    Optional[Any]   		=	tokenizer_r.from_pretrained(snake_case   )
            a__						:    Any   		=	tokenizer_p.from_pretrained(snake_case   )

            # Check special tokens are set accordingly on Rust and Python
            for key in tokenizer_pp.special_tokens_map:
               self.assertTrue(hasattr(snake_case       ,      snake_case   )   )

            shutil.rmtree(snake_case   )

            # Save tokenizer rust, legacy_format=False
            a__						:    str   		=	tempfile.mkdtemp()

            a__						:    Optional[int]   		=	tokenizer_r.save_pretrained(snake_case       ,      legacy_format=snake_case   )
            a__						:    str   		=	tokenizer_p.save_pretrained(snake_case   )

            # Checks it saved the tokenizer.json file
            self.assertTrue(any("tokenizer.json" in f for f in tokenizer_r_files   )   )

            # Checks everything loads correctly in the same way
            a__						:    List[Any]   		=	tokenizer_r.from_pretrained(snake_case   )
            a__						:    Any   		=	tokenizer_p.from_pretrained(snake_case   )

            # Check special tokens are set accordingly on Rust and Python
            for key in tokenizer_pp.special_tokens_map:
               self.assertTrue(hasattr(snake_case       ,      snake_case   )   )

            shutil.rmtree(snake_case   )





   @require_torch
   def 						_snake_case			(			self   )					->	str:
      """simple docstring"""





      if not self.test_seqaseq:
         return

      a__						:    str   		=	self.get_tokenizers()
      for tokenizer in tokenizers:
         with self.subTest(F"""{tokenizer.__class__.__name__}"""   ):
            # Longer text that will definitely require truncation.
            a__						:    Any   		=	[
                " UN Chief Says There Is No Military Solution in Syria",
                " Secretary-General Ban Ki-moon says his response to Russia's stepped up military support for"
                " Syria is that 'there is no military solution' to the nearly five-year conflict and more weapons"
                " will only worsen the violence and misery for millions of people.",
            ]
            a__						:    List[str]   		=	[
                "Şeful ONU declară că nu există o soluţie militară în Siria",
                "Secretarul General Ban Ki-moon declară că răspunsul său la intensificarea sprijinului militar al"
                " Rusiei pentru Siria este că \"nu există o soluţie militară\" la conflictul de aproape cinci ani şi"
                " că noi arme nu vor face decât să înrăutăţească violenţele şi mizeria pentru milioane de oameni.",
            ]
            try:
               a__						:    str   		=	tokenizer.prepare_seqaseq_batch(
                   src_texts=snake_case       ,      tgt_texts=snake_case       ,      max_length=3       ,      max_target_length=10       ,      return_tensors="pt"       ,      src_lang="eng_Latn"       ,      tgt_lang="ron_Latn"       ,      )
            except NotImplementedError:
               return
            self.assertEqual(batch.input_ids.shape[1]       ,      3   )
            self.assertEqual(batch.labels.shape[1]       ,      10   )
            # max_target_length will default to max_length if not specified
            a__						:    Optional[Any]   		=	tokenizer.prepare_seqaseq_batch(
                snake_case       ,      tgt_texts=snake_case       ,      max_length=3       ,      return_tensors="pt"   )
            self.assertEqual(batch.input_ids.shape[1]       ,      3   )
            self.assertEqual(batch.labels.shape[1]       ,      3   )

            a__						:    Any   		=	tokenizer.prepare_seqaseq_batch(
                src_texts=snake_case       ,      max_length=3       ,      max_target_length=10       ,      return_tensors="pt"   )
            self.assertEqual(batch_encoder_only.input_ids.shape[1]       ,      3   )
            self.assertEqual(batch_encoder_only.attention_mask.shape[1]       ,      3   )
            self.assertNotIn("decoder_input_ids"       ,      snake_case   )





   @unittest.skip("Unfortunately way too slow to build a BPE with SentencePiece."   )
   def 						_snake_case			(			self   )					->	Dict:
      """simple docstring"""





      pass





   def 						_snake_case			(			self   )					->	List[str]:
      """simple docstring"""





      for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
         with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})"""   ):
            a__						:    List[str]   		=	[AddedToken("<special>"       ,      lstrip=snake_case   )]

            a__						:    List[Any]   		=	self.rust_tokenizer_class.from_pretrained(
                snake_case       ,      additional_special_tokens=snake_case       ,      **snake_case   )
            a__						:    List[str]   		=	tokenizer_r.encode("Hey this is a <special> token"   )

            a__						:    Tuple   		=	tokenizer_r.encode("<special>"       ,      add_special_tokens=snake_case   )[0]

            self.assertTrue(special_token_id in r_output   )

            if self.test_slow_tokenizer:
               a__						:    Union[str, Any]   		=	self.rust_tokenizer_class.from_pretrained(
                   snake_case       ,      additional_special_tokens=snake_case       ,      **snake_case       ,      )
               a__						:    Optional[Any]   		=	self.tokenizer_class.from_pretrained(
                   snake_case       ,      additional_special_tokens=snake_case       ,      **snake_case   )

               a__						:    int   		=	tokenizer_p.encode("Hey this is a <special> token"   )

               a__						:    Optional[Any]   		=	tokenizer_cr.encode("Hey this is a <special> token"   )

               self.assertEqual(snake_case       ,      snake_case   )
               self.assertEqual(snake_case       ,      snake_case   )
               self.assertTrue(special_token_id in p_output   )
               self.assertTrue(special_token_id in cr_output   )







@require_torch
@require_sentencepiece
@require_tokenizers
class 	__lowerCAmelCase      (       unittest.TestCase	):
   _UpperCamelCase			:    Any  		=					"""facebook/nllb-200-distilled-600M"""
   _UpperCamelCase			:    Any  		=					[
       """ UN Chief Says There Is No Military Solution in Syria""",
       """ Secretary-General Ban Ki-moon says his response to Russia's stepped up military support for Syria is that \"there is no military solution\" to the nearly five-year conflict and more weapons will only worsen the violence and misery for millions of people.""",
   ]
   _UpperCamelCase			:    Union[str, Any]  		=					[
       """Şeful ONU declară că nu există o soluţie militară în Siria""",
       """Secretarul General Ban Ki-moon declară că răspunsul său la intensificarea sprijinului militar al Rusiei"""
       """ pentru Siria este că \"nu există o soluţie militară\" la conflictul de aproape cinci ani şi că noi arme nu vor"""
       """ face decât să înrăutăţească violenţele şi mizeria pentru milioane de oameni.""",
   ]
   _UpperCamelCase			:    Union[str, Any]  		=					[
       256047,
       16297,
       134408,
       8165,
       248066,
       14734,
       950,
       1135,
       105721,
       3573,
       83,
       27352,
       108,
       49486,
       2,
   ]





   @classmethod
   def 						_snake_case			(			cls   )					->	Optional[Any]:
      """simple docstring"""





      a__						:    NllbTokenizer   		=	NllbTokenizer.from_pretrained(
          cls.checkpoint_name       ,      src_lang="eng_Latn"       ,      tgt_lang="ron_Latn"   )
      a__						:    Any   		=	1
      return cls





   def 						_snake_case			(			self   )					->	Tuple:
      """simple docstring"""





      self.assertEqual(self.tokenizer.fairseq_tokens_to_ids["ace_Arab"]       ,      256_001   )
      self.assertEqual(self.tokenizer.fairseq_tokens_to_ids["ace_Latn"]       ,      256_002   )
      self.assertEqual(self.tokenizer.fairseq_tokens_to_ids["fra_Latn"]       ,      256_057   )





   def 						_snake_case			(			self   )					->	Optional[Any]:
      """simple docstring"""





      a__						:    Any   		=	self.tokenizer.batch_encode_plus(self.src_text   ).input_ids[0]
      self.assertListEqual(self.expected_src_tokens       ,      snake_case   )





   def 						_snake_case			(			self   )					->	int:
      """simple docstring"""





      self.assertIn(snake_case       ,      self.tokenizer.all_special_ids   )
      # fmt: off
      a__						:    Any   		=	[RO_CODE, 4_254, 98_068, 112_923, 39_072, 3_909, 713, 102_767, 26, 17_314, 35_642, 14_683, 33_118, 2_022, 66_987, 2, 256_047]
      # fmt: on

      a__						:    Tuple   		=	self.tokenizer.decode(snake_case       ,      skip_special_tokens=snake_case   )
      a__						:    Optional[Any]   		=	self.tokenizer.decode(generated_ids[1:]       ,      skip_special_tokens=snake_case   )
      self.assertEqual(snake_case       ,      snake_case   )
      self.assertNotIn(self.tokenizer.eos_token       ,      snake_case   )





   def 						_snake_case			(			self   )					->	Optional[Any]:
      """simple docstring"""





      a__						:    str   		=	["this is gunna be a long sentence " * 20]
      assert isinstance(src_text[0]       ,      snake_case   )
      a__						:    Union[str, Any]   		=	10
      a__						:    str   		=	self.tokenizer(snake_case       ,      max_length=snake_case       ,      truncation=snake_case   ).input_ids[0]
      self.assertEqual(ids[-1]       ,      2   )
      self.assertEqual(ids[0]       ,      snake_case   )
      self.assertEqual(len(snake_case   )       ,      snake_case   )





   def 						_snake_case			(			self   )					->	Union[str, Any]:
      """simple docstring"""





      self.assertListEqual(self.tokenizer.convert_tokens_to_ids(["<mask>", "ar_AR"]   )       ,      [256_203, 3]   )





   def 						_snake_case			(			self   )					->	List[str]:
      """simple docstring"""





      a__						:    List[Any]   		=	tempfile.mkdtemp()
      a__						:    int   		=	self.tokenizer.fairseq_tokens_to_ids
      self.tokenizer.save_pretrained(snake_case   )
      a__						:    Tuple   		=	NllbTokenizer.from_pretrained(snake_case   )
      self.assertDictEqual(new_tok.fairseq_tokens_to_ids       ,      snake_case   )





   @require_torch
   def 						_snake_case			(			self   )					->	List[Any]:
      """simple docstring"""





      a__						:    int   		=	self.tokenizer(
          self.src_text       ,      text_target=self.tgt_text       ,      padding=snake_case       ,      truncation=snake_case       ,      max_length=len(self.expected_src_tokens   )       ,      return_tensors="pt"       ,      )
      a__						:    Any   		=	shift_tokens_right(
          batch["labels"]       ,      self.tokenizer.pad_token_id       ,      self.tokenizer.lang_code_to_id["ron_Latn"]   )

      self.assertIsInstance(snake_case       ,      snake_case   )

      self.assertEqual((2, 15)       ,      batch.input_ids.shape   )
      self.assertEqual((2, 15)       ,      batch.attention_mask.shape   )
      a__						:    int   		=	batch.input_ids.tolist()[0]
      self.assertListEqual(self.expected_src_tokens       ,      snake_case   )
      self.assertEqual(snake_case       ,      batch.decoder_input_ids[0, 0]   )  # EOS
      # Test that special tokens are reset
      self.assertEqual(self.tokenizer.prefix_tokens       ,      [EN_CODE]   )
      self.assertEqual(self.tokenizer.suffix_tokens       ,      [self.tokenizer.eos_token_id]   )





   def 						_snake_case			(			self   )					->	Optional[int]:
      """simple docstring"""





      a__						:    Optional[Any]   		=	self.tokenizer(self.src_text       ,      padding=snake_case       ,      truncation=snake_case       ,      max_length=3       ,      return_tensors="pt"   )
      a__						:    Dict   		=	self.tokenizer(
          text_target=self.tgt_text       ,      padding=snake_case       ,      truncation=snake_case       ,      max_length=10       ,      return_tensors="pt"   )
      a__						:    Tuple   		=	targets["input_ids"]
      a__						:    str   		=	shift_tokens_right(
          snake_case       ,      self.tokenizer.pad_token_id       ,      decoder_start_token_id=self.tokenizer.lang_code_to_id[self.tokenizer.tgt_lang]       ,      )

      self.assertEqual(batch.input_ids.shape[1]       ,      3   )
      self.assertEqual(batch.decoder_input_ids.shape[1]       ,      10   )





   @require_torch
   def 						_snake_case			(			self   )					->	Dict:
      """simple docstring"""





      a__						:    Optional[Any]   		=	self.tokenizer._build_translation_inputs(
          "A test"       ,      return_tensors="pt"       ,      src_lang="eng_Latn"       ,      tgt_lang="fra_Latn"   )

      self.assertEqual(
          nested_simplify(snake_case   )       ,      {
              # A, test, EOS, en_XX
              "input_ids": [[256_047, 70, 7_356, 2]],
              "attention_mask": [[1, 1, 1, 1]],
              # ar_AR
              "forced_bos_token_id": 256_057,
          }       ,      )





   @require_torch
   def 						_snake_case			(			self   )					->	str:
      """simple docstring"""





      a__						:    Any   		=	True
      a__						:    Any   		=	self.tokenizer(
          "UN Chief says there is no military solution in Syria"       ,      src_lang="eng_Latn"       ,      tgt_lang="fra_Latn"   )
      self.assertEqual(
          inputs.input_ids       ,      [16_297, 134_408, 25_653, 6_370, 248, 254, 103_929, 94_995, 108, 49_486, 2, 256_047]   )

      a__						:    Tuple   		=	False
      a__						:    Optional[Any]   		=	self.tokenizer(
          "UN Chief says there is no military solution in Syria"       ,      src_lang="eng_Latn"       ,      tgt_lang="fra_Latn"   )
      self.assertEqual(
          inputs.input_ids       ,      [256_047, 16_297, 134_408, 25_653, 6_370, 248, 254, 103_929, 94_995, 108, 49_486, 2]   )








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

import datasets


SCREAMING_SNAKE_CASE__							:      List[Any]         =    """\
@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\",
}
"""

SCREAMING_SNAKE_CASE__							:      Optional[Any]         =    """\
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.
"""

SCREAMING_SNAKE_CASE__							:      int         =    """
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 	__lowerCAmelCase      (       datasets.Metric	):





   def 						_snake_case			(			self   )					->	Optional[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 						_snake_case			(			self       ,      snake_case       ,      snake_case       ,      snake_case = False       ,      snake_case = False       ,      snake_case = False       ,      snake_case = False       ,      )					->	Optional[Any]:
      """simple docstring"""





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

      a__						:    Optional[Any]   		=	TER(
          normalized=snake_case       ,      no_punct=snake_case       ,      asian_support=snake_case       ,      case_sensitive=snake_case       ,      )
      a__						:    Union[str, Any]   		=	sb_ter.corpus_score(snake_case       ,      snake_case   )

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

