'''simple docstring'''






import unittest

from transformers import EsmConfig, is_torch_available
from transformers.testing_utils import TestCasePlus, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
   import torch

   from transformers.models.esm.modeling_esmfold import EsmForProteinFolding







class lowercase_       :







   """simple docstring"""

   def __init__(      self      :			List[str], UpperCamelCase__      :			Dict, UpperCamelCase__      :			Dict=13, UpperCamelCase__      :			Union[str, Any]=7, UpperCamelCase__      :			List[str]=False, UpperCamelCase__      :			List[Any]=True, UpperCamelCase__      :			str=False, UpperCamelCase__      :			Tuple=False, UpperCamelCase__      :			str=19, UpperCamelCase__      :			Tuple=32, UpperCamelCase__      :			Optional[Any]=5, UpperCamelCase__      :			int=4, UpperCamelCase__      :			str=37, UpperCamelCase__      :			List[str]="gelu", UpperCamelCase__      :			Union[str, Any]=0.1, UpperCamelCase__      :			List[Any]=0.1, UpperCamelCase__      :			int=5_12, UpperCamelCase__      :			int=16, UpperCamelCase__      :			str=2, UpperCamelCase__      :			Any=0.02, UpperCamelCase__      :			Any=3, UpperCamelCase__      :			Any=4, UpperCamelCase__      :			Union[str, Any]=None, )  ->			Tuple:
        _A    		=  parent
        _A    		=  batch_size
        _A    		=  seq_length
        _A    		=  is_training
        _A    		=  use_input_mask
        _A    		=  use_token_type_ids
        _A    		=  use_labels
        _A    		=  vocab_size
        _A    		=  hidden_size
        _A    		=  num_hidden_layers
        _A    		=  num_attention_heads
        _A    		=  intermediate_size
        _A    		=  hidden_act
        _A    		=  hidden_dropout_prob
        _A    		=  attention_probs_dropout_prob
        _A    		=  max_position_embeddings
        _A    		=  type_vocab_size
        _A    		=  type_sequence_label_size
        _A    		=  initializer_range
        _A    		=  num_labels
        _A    		=  num_choices
        _A    		=  scope
   def 	__UpperCAmelCase   (      self      :			Tuple     )  ->			List[Any]:
        _A    		=  ids_tensor([self.batch_size, self.seq_length], self.vocab_size     )

        _A    		=  None
        if self.use_input_mask:
             _A    		=  random_attention_mask([self.batch_size, self.seq_length]     )

        _A    		=  None
        _A    		=  None
        _A    		=  None
        if self.use_labels:
             _A    		=  ids_tensor([self.batch_size], self.type_sequence_label_size     )
             _A    		=  ids_tensor([self.batch_size, self.seq_length], self.num_labels     )
             _A    		=  ids_tensor([self.batch_size], self.num_choices     )

        _A    		=  self.get_config()

        return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels
   def 	__UpperCAmelCase   (      self      :			str     )  ->			Dict:
        _A    		=  EsmConfig(
            vocab_size=33, hidden_size=self.hidden_size, pad_token_id=1, num_hidden_layers=self.num_hidden_layers, num_attention_heads=self.num_attention_heads, intermediate_size=self.intermediate_size, hidden_act=self.hidden_act, hidden_dropout_prob=self.hidden_dropout_prob, attention_probs_dropout_prob=self.attention_probs_dropout_prob, max_position_embeddings=self.max_position_embeddings, type_vocab_size=self.type_vocab_size, initializer_range=self.initializer_range, is_folding_model=UpperCamelCase__, esmfold_config={'trunk': {'num_blocks': 2}, 'fp16_esm': False}, )
        return config
   def 	__UpperCAmelCase   (      self      :			Dict, UpperCamelCase__      :			Union[str, Any], UpperCamelCase__      :			Optional[int], UpperCamelCase__      :			str, UpperCamelCase__      :			Dict, UpperCamelCase__      :			List[Any], UpperCamelCase__      :			int     )  ->			List[str]:
        _A    		=  EsmForProteinFolding(config=UpperCamelCase__     ).float()
        model.to(UpperCamelCase__     )
        model.eval()
        _A    		=  model(UpperCamelCase__, attention_mask=UpperCamelCase__     )
        _A    		=  model(UpperCamelCase__     )
        _A    		=  model(UpperCamelCase__     )

        self.parent.assertEqual(result.positions.shape, (8, self.batch_size, self.seq_length, 14, 3)     )
        self.parent.assertEqual(result.angles.shape, (8, self.batch_size, self.seq_length, 7, 2)     )

   def 	__UpperCAmelCase   (      self      :			Any     )  ->			Optional[int]:
        _A    		=  self.prepare_config_and_inputs()
        (
            (
            _A
        )		,       (
            _A
        )		,       (
            _A
        )		,       (
            _A
        )		,       (
            _A
        )		,       (
            _A
        )		,       
        )    		=  config_and_inputs
        _A    		=  {'input_ids': input_ids, 'attention_mask': input_mask}
        return config, inputs_dict







@require_torch
class lowercase_       (		_UpperCamelCase    ,    _UpperCamelCase    ,    unittest.TestCase			):







   """simple docstring"""

   __lowerCAmelCase         =   False

   __lowerCAmelCase         =   (EsmForProteinFolding,) if is_torch_available() else ()
   __lowerCAmelCase         =   ()
   __lowerCAmelCase         =   {} if is_torch_available() else {}
   __lowerCAmelCase         =   False
   def 	__UpperCAmelCase   (      self      :			List[str]     )  ->			Dict:
        _A    		=  EsmFoldModelTester(self     )
        _A    		=  ConfigTester(self, config_class=UpperCamelCase__, hidden_size=37     )
   def 	__UpperCAmelCase   (      self      :			List[Any]     )  ->			Optional[Any]:
        self.config_tester.run_common_tests()
   def 	__UpperCAmelCase   (      self      :			Optional[int]     )  ->			str:
        _A    		=  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*UpperCamelCase__     )
   @unittest.skip('Does not support attention outputs'     )
   def 	__UpperCAmelCase   (      self      :			Optional[Any]     )  ->			Tuple:
        pass
   @unittest.skip
   def 	__UpperCAmelCase   (      self      :			Tuple     )  ->			Union[str, Any]:
        pass
   @unittest.skip('Esm does not support embedding resizing'     )
   def 	__UpperCAmelCase   (      self      :			Union[str, Any]     )  ->			Any:
        pass
   @unittest.skip('Esm does not support embedding resizing'     )
   def 	__UpperCAmelCase   (      self      :			str     )  ->			Any:
        pass
   @unittest.skip('ESMFold does not support passing input embeds!'     )
   def 	__UpperCAmelCase   (      self      :			Tuple     )  ->			Tuple:
        pass
   @unittest.skip('ESMFold does not support head pruning.'     )
   def 	__UpperCAmelCase   (      self      :			str     )  ->			Optional[Any]:
        pass
   @unittest.skip('ESMFold does not support head pruning.'     )
   def 	__UpperCAmelCase   (      self      :			Any     )  ->			Union[str, Any]:
        pass
   @unittest.skip('ESMFold does not support head pruning.'     )
   def 	__UpperCAmelCase   (      self      :			str     )  ->			Optional[int]:
        pass
   @unittest.skip('ESMFold does not support head pruning.'     )
   def 	__UpperCAmelCase   (      self      :			Dict     )  ->			int:
        pass
   @unittest.skip('ESMFold does not support head pruning.'     )
   def 	__UpperCAmelCase   (      self      :			Dict     )  ->			Optional[int]:
        pass
   @unittest.skip('ESMFold does not output hidden states in the normal way.'     )
   def 	__UpperCAmelCase   (      self      :			Tuple     )  ->			Union[str, Any]:
        pass
   @unittest.skip('ESMfold does not output hidden states in the normal way.'     )
   def 	__UpperCAmelCase   (      self      :			Tuple     )  ->			Optional[Any]:
        pass
   @unittest.skip('ESMFold only has one output format.'     )
   def 	__UpperCAmelCase   (      self      :			Tuple     )  ->			Any:
        pass
   @unittest.skip('This test doesn\'t work for ESMFold and doesn\'t test core functionality'     )
   def 	__UpperCAmelCase   (      self      :			List[str]     )  ->			Union[str, Any]:
        pass
   @unittest.skip('ESMFold does not support input chunking.'     )
   def 	__UpperCAmelCase   (      self      :			int     )  ->			int:
        pass
   @unittest.skip('ESMFold doesn\'t respect you and it certainly doesn\'t respect your initialization arguments.'     )
   def 	__UpperCAmelCase   (      self      :			Optional[int]     )  ->			str:
        pass
   @unittest.skip('ESMFold doesn\'t support torchscript compilation.'     )
   def 	__UpperCAmelCase   (      self      :			str     )  ->			str:
        pass
   @unittest.skip('ESMFold doesn\'t support torchscript compilation.'     )
   def 	__UpperCAmelCase   (      self      :			str     )  ->			Tuple:
        pass
   @unittest.skip('ESMFold doesn\'t support torchscript compilation.'     )
   def 	__UpperCAmelCase   (      self      :			List[Any]     )  ->			Optional[Any]:
        pass
   @unittest.skip('ESMFold doesn\'t support data parallel.'     )
   def 	__UpperCAmelCase   (      self      :			Tuple     )  ->			Optional[int]:
        pass

   @unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.'     )
   def 	__UpperCAmelCase   (      self      :			Union[str, Any]     )  ->			List[Any]:
        pass







@require_torch
class lowercase_       (		_UpperCamelCase			):







   """simple docstring"""

   @slow
   def 	__UpperCAmelCase   (      self      :			Union[str, Any]     )  ->			str:
        _A    		=  EsmForProteinFolding.from_pretrained('facebook/esmfold_v1'     ).float()
        model.eval()
        _A    		=  torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]     )
        _A    		=  model(UpperCamelCase__     )['positions']
        _A    		=  torch.tensor([2.5_828, 0.7_993, -10.9_334], dtype=torch.floataa     )
        self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0], UpperCamelCase__, atol=1e-4     )     )




'''simple docstring'''






from typing import Dict, List

from nltk.translate import gleu_score

import datasets
from datasets import MetricInfo


_UpperCAmelCase    :     Any         =       '''\
@misc{wu2016googles,
      title={Google\'s Neural Machine Translation System: Bridging the Gap between Human and Machine Translation},
      author={Yonghui Wu and Mike Schuster and Zhifeng Chen and Quoc V. Le and Mohammad Norouzi and Wolfgang Macherey
              and Maxim Krikun and Yuan Cao and Qin Gao and Klaus Macherey and Jeff Klingner and Apurva Shah and Melvin
              Johnson and Xiaobing Liu and Łukasz Kaiser and Stephan Gouws and Yoshikiyo Kato and Taku Kudo and Hideto
              Kazawa and Keith Stevens and George Kurian and Nishant Patil and Wei Wang and Cliff Young and
              Jason Smith and Jason Riesa and Alex Rudnick and Oriol Vinyals and Greg Corrado and Macduff Hughes
              and Jeffrey Dean},
      year={2016},
      eprint={1609.08144},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}
'''

_UpperCAmelCase    :     str         =       '''\
The BLEU score has some undesirable properties when used for single
sentences, as it was designed to be a corpus measure. We therefore
use a slightly different score for our RL experiments which we call
the \'GLEU score\'. For the GLEU score, we record all sub-sequences of
1, 2, 3 or 4 tokens in output and target sequence (n-grams). We then
compute a recall, which is the ratio of the number of matching n-grams
to the number of total n-grams in the target (ground truth) sequence,
and a precision, which is the ratio of the number of matching n-grams
to the number of total n-grams in the generated output sequence. Then
GLEU score is simply the minimum of recall and precision. This GLEU
score\'s range is always between 0 (no matches) and 1 (all match) and
it is symmetrical when switching output and target. According to
our experiments, GLEU score correlates quite well with the BLEU
metric on a corpus level but does not have its drawbacks for our per
sentence reward objective.
'''

_UpperCAmelCase    :     Union[str, Any]         =       '''\
Computes corpus-level Google BLEU (GLEU) score of translated segments against one or more references.
Instead of averaging the sentence level GLEU scores (i.e. macro-average precision), Wu et al. (2016) sum up the matching
tokens and the max of hypothesis and reference tokens for each sentence, then compute using the aggregate values.

Args:
    predictions (list of str): list of translations to score.
        Each translation should be tokenized into a list of tokens.
    references (list of list of str): list of lists of references for each translation.
        Each reference should be tokenized into a list of tokens.
    min_len (int): The minimum order of n-gram this function should extract. Defaults to 1.
    max_len (int): The maximum order of n-gram this function should extract. Defaults to 4.

Returns:
    \'google_bleu\': google_bleu score

Examples:
    Example 1:
        >>> hyp1 = [\'It\', \'is\', \'a\', \'guide\', \'to\', \'action\', \'which\',
        ...         \'ensures\', \'that\', \'the\', \'rubber\', \'duck\', \'always\',
        ...         \'disobeys\', \'the\', \'commands\', \'of\', \'the\', \'cat\']
        >>> ref1a = [\'It\', \'is\', \'the\', \'guiding\', \'principle\', \'which\',
        ...          \'guarantees\', \'the\', \'rubber\', \'duck\', \'forces\', \'never\',
        ...          \'being\', \'under\', \'the\', \'command\', \'of\', \'the\', \'cat\']

        >>> hyp2 = [\'he\', \'read\', \'the\', \'book\', \'because\', \'he\', \'was\',
        ...         \'interested\', \'in\', \'world\', \'history\']
        >>> ref2a = [\'he\', \'was\', \'interested\', \'in\', \'world\', \'history\',
        ...          \'because\', \'he\', \'read\', \'the\', \'book\']

        >>> list_of_references = [[ref1a], [ref2a]]
        >>> hypotheses = [hyp1, hyp2]
        >>> google_bleu = datasets.load_metric("google_bleu")
        >>> results = google_bleu.compute(predictions=hypotheses, references=list_of_references)
        >>> print(round(results["google_bleu"], 2))
        0.44

    Example 2:
        >>> hyp1 = [\'It\', \'is\', \'a\', \'guide\', \'to\', \'action\', \'which\',
        ...         \'ensures\', \'that\', \'the\', \'rubber\', \'duck\', \'always\',
        ...         \'disobeys\', \'the\', \'commands\', \'of\', \'the\', \'cat\']
        >>> ref1a = [\'It\', \'is\', \'the\', \'guiding\', \'principle\', \'which\',
        ...          \'guarantees\', \'the\', \'rubber\', \'duck\', \'forces\', \'never\',
        ...          \'being\', \'under\', \'the\', \'command\', \'of\', \'the\', \'cat\']
        >>> ref1b = [\'It\', \'is\', \'a\', \'guide\', \'to\', \'action\', \'that\',
        ...          \'ensures\', \'that\', \'the\', \'rubber\', \'duck\', \'will\', \'never\',
        ...          \'heed\', \'the\', \'cat\', \'commands\']
        >>> ref1c = [\'It\', \'is\', \'the\', \'practical\', \'guide\', \'for\', \'the\',
        ...          \'rubber\', \'duck\', \'army\', \'never\', \'to\', \'heed\', \'the\', \'directions\',
        ...          \'of\', \'the\', \'cat\']

        >>> hyp2 = [\'he\', \'read\', \'the\', \'book\', \'because\', \'he\', \'was\',
        ...         \'interested\', \'in\', \'world\', \'history\']
        >>> ref2a = [\'he\', \'was\', \'interested\', \'in\', \'world\', \'history\',
        ...          \'because\', \'he\', \'read\', \'the\', \'book\']

        >>> list_of_references = [[ref1a, ref1b, ref1c], [ref2a]]
        >>> hypotheses = [hyp1, hyp2]
        >>> google_bleu = datasets.load_metric("google_bleu")
        >>> results = google_bleu.compute(predictions=hypotheses, references=list_of_references)
        >>> print(round(results["google_bleu"], 2))
        0.61

    Example 3:
        >>> hyp1 = [\'It\', \'is\', \'a\', \'guide\', \'to\', \'action\', \'which\',
        ...         \'ensures\', \'that\', \'the\', \'rubber\', \'duck\', \'always\',
        ...         \'disobeys\', \'the\', \'commands\', \'of\', \'the\', \'cat\']
        >>> ref1a = [\'It\', \'is\', \'the\', \'guiding\', \'principle\', \'which\',
        ...          \'guarantees\', \'the\', \'rubber\', \'duck\', \'forces\', \'never\',
        ...          \'being\', \'under\', \'the\', \'command\', \'of\', \'the\', \'cat\']
        >>> ref1b = [\'It\', \'is\', \'a\', \'guide\', \'to\', \'action\', \'that\',
        ...          \'ensures\', \'that\', \'the\', \'rubber\', \'duck\', \'will\', \'never\',
        ...          \'heed\', \'the\', \'cat\', \'commands\']
        >>> ref1c = [\'It\', \'is\', \'the\', \'practical\', \'guide\', \'for\', \'the\',
        ...          \'rubber\', \'duck\', \'army\', \'never\', \'to\', \'heed\', \'the\', \'directions\',
        ...          \'of\', \'the\', \'cat\']

        >>> hyp2 = [\'he\', \'read\', \'the\', \'book\', \'because\', \'he\', \'was\',
        ...         \'interested\', \'in\', \'world\', \'history\']
        >>> ref2a = [\'he\', \'was\', \'interested\', \'in\', \'world\', \'history\',
        ...          \'because\', \'he\', \'read\', \'the\', \'book\']

        >>> list_of_references = [[ref1a, ref1b, ref1c], [ref2a]]
        >>> hypotheses = [hyp1, hyp2]
        >>> google_bleu = datasets.load_metric("google_bleu")
        >>> results = google_bleu.compute(predictions=hypotheses, references=list_of_references, min_len=2)
        >>> print(round(results["google_bleu"], 2))
        0.53

    Example 4:
        >>> hyp1 = [\'It\', \'is\', \'a\', \'guide\', \'to\', \'action\', \'which\',
        ...         \'ensures\', \'that\', \'the\', \'rubber\', \'duck\', \'always\',
        ...         \'disobeys\', \'the\', \'commands\', \'of\', \'the\', \'cat\']
        >>> ref1a = [\'It\', \'is\', \'the\', \'guiding\', \'principle\', \'which\',
        ...          \'guarantees\', \'the\', \'rubber\', \'duck\', \'forces\', \'never\',
        ...          \'being\', \'under\', \'the\', \'command\', \'of\', \'the\', \'cat\']
        >>> ref1b = [\'It\', \'is\', \'a\', \'guide\', \'to\', \'action\', \'that\',
        ...          \'ensures\', \'that\', \'the\', \'rubber\', \'duck\', \'will\', \'never\',
        ...          \'heed\', \'the\', \'cat\', \'commands\']
        >>> ref1c = [\'It\', \'is\', \'the\', \'practical\', \'guide\', \'for\', \'the\',
        ...          \'rubber\', \'duck\', \'army\', \'never\', \'to\', \'heed\', \'the\', \'directions\',
        ...          \'of\', \'the\', \'cat\']

        >>> hyp2 = [\'he\', \'read\', \'the\', \'book\', \'because\', \'he\', \'was\',
        ...         \'interested\', \'in\', \'world\', \'history\']
        >>> ref2a = [\'he\', \'was\', \'interested\', \'in\', \'world\', \'history\',
        ...          \'because\', \'he\', \'read\', \'the\', \'book\']

        >>> list_of_references = [[ref1a, ref1b, ref1c], [ref2a]]
        >>> hypotheses = [hyp1, hyp2]
        >>> google_bleu = datasets.load_metric("google_bleu")
        >>> results = google_bleu.compute(predictions=hypotheses,references=list_of_references, min_len=2, max_len=6)
        >>> print(round(results["google_bleu"], 2))
        0.4
'''







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







   """simple docstring"""

   def 	__UpperCAmelCase   (      self      :			List[Any]     )  ->			MetricInfo:
        return datasets.MetricInfo(
            description=_DESCRIPTION, citation=_CITATION, inputs_description=_KWARGS_DESCRIPTION, features=datasets.Features(
                {
                    'predictions': datasets.Sequence(datasets.Value('string', id='token'     ), id='sequence'     ),
                    'references': datasets.Sequence(
                        datasets.Sequence(datasets.Value('string', id='token'     ), id='sequence'     ), id='references'     ),
                }     ), )

   def 	__UpperCAmelCase   (      self      :			Dict, UpperCamelCase__      :			List[List[List[str]]], UpperCamelCase__      :			List[List[str]], UpperCamelCase__      :			int = 1, UpperCamelCase__      :			int = 4, )  ->			Dict[str, float]:
        return {
            "google_bleu": gleu_score.corpus_gleu(
                list_of_references=UpperCamelCase__, hypotheses=UpperCamelCase__, min_len=UpperCamelCase__, max_len=UpperCamelCase__     )
        }



