code: 
  
  
  '''simple docstring'''
  
  
  
  
  from typing import Dict, Tuple, overload
  
  import torch
  import torch.types
  from torch import nn
  
  from . import residue_constants as rc
  from .rigid_utils import Rigid, Rotation
  from .tensor_utils import batched_gather
  
  
  
  
  
  @overload
  def 							a_       (						lowercase							,						lowercase							,						lowercase    )			->torch.Tensor:
  
  
  
  
  
  
      '''simple docstring'''
  
      ...
  
  
  
  
  
  @overload
  def 							a_       (						lowercase							,						lowercase							,						lowercase    )			->Tuple[torch.Tensor, torch.Tensor]:
  
  
  
  
  
  
      '''simple docstring'''
  
      ...
  
  
  
  
  
  def 							a_       (						lowercase							,						lowercase							,						lowercase    )			->Any:
  
  
  
  
  
  
      '''simple docstring'''
  
      __lowerCamelCase		:      List[Any]											=					aatype == rc.restype_order["G"]
      __lowerCamelCase		:      Dict											=					rc.atom_order["CA"]
      __lowerCamelCase		:      Optional[Any]											=					rc.atom_order["CB"]
      __lowerCamelCase		:      List[str]											=					torch.where(
          is_gly[..., None].expand(*((-1,) * len(is_gly.shape    ))							,						3    )							,						all_atom_positions[..., ca_idx, :]							,						all_atom_positions[..., cb_idx, :]							,						)
  
      if all_atom_masks is not None:
          __lowerCamelCase		:      Union[str, Any]											=					torch.where(
              lowercase							,						all_atom_masks[..., ca_idx]							,						all_atom_masks[..., cb_idx]							,						)
          return pseudo_beta, pseudo_beta_mask
      else:
          return pseudo_beta
  
  
  
  
  
  def 							a_       (						lowercase							,						lowercase    )			->torch.Tensor:
  
  
  
  
  
  
      '''simple docstring'''
  
      __lowerCamelCase		:      Dict											=					batched_gather(
          lowercase							,						batch["residx_atom37_to_atom14"]							,						dim=-2							,						no_batch_dims=len(atomaa.shape[:-2]    )							,						)
  
      __lowerCamelCase		:      Any											=					atomaa_data * batch["atom37_atom_exists"][..., None]
  
      return atomaa_data
  
  
  
  
  
  def 							a_       (						lowercase    )			->torch.Tensor:
  
  
  
  
  
  
      '''simple docstring'''
  
      __lowerCamelCase		:      int											=					template_feats["template_aatype"]
      __lowerCamelCase		:      Optional[int]											=					template_feats["template_torsion_angles_sin_cos"]
      __lowerCamelCase		:      int											=					template_feats["template_alt_torsion_angles_sin_cos"]
      __lowerCamelCase		:      str											=					template_feats["template_torsion_angles_mask"]
      __lowerCamelCase		:      Any											=					torch.cat(
          [
              nn.functional.one_hot(lowercase							,						22    ),
              torsion_angles_sin_cos.reshape(*torsion_angles_sin_cos.shape[:-2]							,						14    ),
              alt_torsion_angles_sin_cos.reshape(*alt_torsion_angles_sin_cos.shape[:-2]							,						14    ),
              torsion_angles_mask,
          ]							,						dim=-1							,						)
  
      return template_angle_feat
  
  
  
  
  
  def 							a_       (						lowercase							,						lowercase							,						lowercase							,						lowercase							,						lowercase = False							,						lowercase = 1E-20							,						lowercase = 1E8							,						)			->torch.Tensor:
  
  
  
  
  
  
      '''simple docstring'''
  
      __lowerCamelCase		:      str											=					batch["template_pseudo_beta_mask"]
      __lowerCamelCase		:      List[Any]											=					template_mask[..., None] * template_mask[..., None, :]
  
      # Compute distogram (this seems to differ slightly from Alg. 5)
      __lowerCamelCase		:      Any											=					batch["template_pseudo_beta"]
      __lowerCamelCase		:      Union[str, Any]											=					torch.sum((tpb[..., None, :] - tpb[..., None, :, :]) ** 2							,						dim=-1							,						keepdim=lowercase    )
      __lowerCamelCase		:      List[str]											=					torch.linspace(lowercase							,						lowercase							,						lowercase							,						device=tpb.device    ) ** 2
      __lowerCamelCase		:      List[Any]											=					torch.cat([lower[1:], lower.new_tensor([inf]    )]							,						dim=-1    )
      __lowerCamelCase		:      str											=					((dgram > lower) * (dgram < upper)).type(dgram.dtype    )
  
      __lowerCamelCase		:      Optional[int]											=					[dgram, template_mask_ad[..., None]]
  
      __lowerCamelCase		:      List[str]											=					nn.functional.one_hot(
          batch["template_aatype"]							,						rc.restype_num + 2							,						)
  
      __lowerCamelCase		:      Dict											=					batch["template_aatype"].shape[-1]
      to_concat.append(aatype_one_hot[..., None, :, :].expand(*aatype_one_hot.shape[:-2]							,						lowercase							,						-1							,						-1    )    )
      to_concat.append(aatype_one_hot[..., None, :].expand(*aatype_one_hot.shape[:-2]							,						-1							,						lowercase							,						-1    )    )
  
      __lowerCamelCase						,					__lowerCamelCase						,					__lowerCamelCase		:      Tuple											=					[rc.atom_order[a] for a in ["N", "CA", "C"]]
      __lowerCamelCase		:      Tuple											=					Rigid.make_transform_from_reference(
          n_xyz=batch["template_all_atom_positions"][..., n, :]							,						ca_xyz=batch["template_all_atom_positions"][..., ca, :]							,						c_xyz=batch["template_all_atom_positions"][..., c, :]							,						eps=lowercase							,						)
      __lowerCamelCase		:      Optional[int]											=					rigids.get_trans()[..., None, :, :]
      __lowerCamelCase		:      Dict											=					rigids[..., None].invert_apply(lowercase    )
  
      __lowerCamelCase		:      Any											=					torch.rsqrt(eps + torch.sum(rigid_vec**2							,						dim=-1    )    )
  
      __lowerCamelCase		:      Dict											=					batch["template_all_atom_mask"]
      __lowerCamelCase		:      Tuple											=					t_aa_masks[..., n] * t_aa_masks[..., ca] * t_aa_masks[..., c]
      __lowerCamelCase		:      List[Any]											=					template_mask[..., None] * template_mask[..., None, :]
  
      __lowerCamelCase		:      List[Any]											=					inv_distance_scalar * template_mask_ad
      __lowerCamelCase		:      Union[str, Any]											=					rigid_vec * inv_distance_scalar[..., None]
  
      if not use_unit_vector:
          __lowerCamelCase		:      List[Any]											=					unit_vector * 0.0
  
      to_concat.extend(torch.unbind(unit_vector[..., None, :]							,						dim=-1    )    )
      to_concat.append(template_mask_ad[..., None]    )
  
      __lowerCamelCase		:      List[Any]											=					torch.cat(lowercase							,						dim=-1    )
      __lowerCamelCase		:      Optional[Any]											=					act * template_mask_ad[..., None]
  
      return act
  
  
  
  
  
  def 							a_       (						lowercase    )			->torch.Tensor:
  
  
  
  
  
  
      '''simple docstring'''
  
      __lowerCamelCase		:      Tuple											=					nn.functional.one_hot(batch["extra_msa"]							,						23    )
      __lowerCamelCase		:      Dict											=					[
          msa_ahot,
          batch["extra_has_deletion"].unsqueeze(-1    ),
          batch["extra_deletion_value"].unsqueeze(-1    ),
      ]
      return torch.cat(lowercase							,						dim=-1    )
  
  
  
  
  
  def 							a_       (						lowercase							,						lowercase							,						lowercase							,						lowercase							,						)			->Rigid:
  
  
  
  
  
  
      '''simple docstring'''
  
      __lowerCamelCase		:      Tuple											=					rrgdf[aatype, ...]
  
      # [*, N, 8] transformations, i.e.
      #   One [*, N, 8, 3, 3] rotation matrix and
      #   One [*, N, 8, 3]    translation matrix
      __lowerCamelCase		:      Optional[Any]											=					r.from_tensor_axa(lowercase    )
  
      __lowerCamelCase		:      int											=					alpha.new_zeros((*((1,) * len(alpha.shape[:-1]    )), 2)    )
      __lowerCamelCase		:      Union[str, Any]											=					1
  
      # [*, N, 8, 2]
      __lowerCamelCase		:      List[Any]											=					torch.cat([bb_rot.expand(*alpha.shape[:-2]							,						-1							,						-1    ), alpha]							,						dim=-2    )
  
      # [*, N, 8, 3, 3]
      # Produces rotation matrices of the form:
      # [
      #   [1, 0  , 0  ],
      #   [0, a_2,-a_1],
      #   [0, a_1, a_2]
      # ]
      # This follows the original code rather than the supplement, which uses
      # different indices.
  
      __lowerCamelCase		:      Tuple											=					alpha.new_zeros(default_r.get_rots().get_rot_mats().shape    )
      __lowerCamelCase		:      List[str]											=					1
      __lowerCamelCase		:      Tuple											=					alpha[..., 1]
      __lowerCamelCase		:      List[Any]											=					-alpha[..., 0]
      __lowerCamelCase		:      str											=					alpha
  
      __lowerCamelCase		:      Tuple											=					default_r.compose(Rigid(Rotation(rot_mats=lowercase    )							,						lowercase    )    )
  
      __lowerCamelCase		:      Tuple											=					all_frames[..., 5]
      __lowerCamelCase		:      Optional[int]											=					all_frames[..., 6]
      __lowerCamelCase		:      Dict											=					all_frames[..., 7]
  
      __lowerCamelCase		:      str											=					all_frames[..., 4]
      __lowerCamelCase		:      Dict											=					chia_frame_to_bb.compose(lowercase    )
      __lowerCamelCase		:      Optional[int]											=					chia_frame_to_bb.compose(lowercase    )
      __lowerCamelCase		:      Optional[int]											=					chia_frame_to_bb.compose(lowercase    )
  
      __lowerCamelCase		:      Dict											=					Rigid.cat(
          [
              all_frames[..., :5],
              chia_frame_to_bb.unsqueeze(-1    ),
              chia_frame_to_bb.unsqueeze(-1    ),
              chia_frame_to_bb.unsqueeze(-1    ),
          ]							,						dim=-1							,						)
  
      __lowerCamelCase		:      Optional[int]											=					r[..., None].compose(lowercase    )
  
      return all_frames_to_global
  
  
  
  
  
  def 							a_       (						lowercase							,						lowercase							,						lowercase							,						lowercase							,						lowercase							,						lowercase							,						)			->torch.Tensor:
  
  
  
  
  
  
      '''simple docstring'''
  
      __lowerCamelCase		:      Any											=					group_idx[aatype, ...]
  
      # [*, N, 14, 8]
      __lowerCamelCase		:      int											=					nn.functional.one_hot(
          lowercase							,						num_classes=default_frames.shape[-3]							,						)
  
      # [*, N, 14, 8]
      __lowerCamelCase		:      List[str]											=					r[..., None, :] * group_mask_one_hot
  
      # [*, N, 14]
      __lowerCamelCase		:      Any											=					t_atoms_to_global.map_tensor_fn(lambda lowercase    : torch.sum(lowercase							,						dim=-1    )    )
  
      # [*, N, 14, 1]
      __lowerCamelCase		:      List[Any]											=					atom_mask[aatype, ...].unsqueeze(-1    )
  
      # [*, N, 14, 3]
      __lowerCamelCase		:      List[str]											=					lit_positions[aatype, ...]
      __lowerCamelCase		:      Dict											=					t_atoms_to_global.apply(lowercase    )
      __lowerCamelCase		:      str											=					pred_positions * atom_mask
  
      return pred_positions
  
  
  
  
  
  
style_context: 
  
  
  '''simple docstring'''
  
  
  
  
  import unittest
  
  from transformers import ErnieMTokenizer
  from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow
  
  from ...test_tokenization_common import TokenizerTesterMixin
  
  
  __lowercase  :      Any      		=				get_tests_dir("""fixtures/spiece.model""")
  
  
  
  
  
  @require_sentencepiece
  @require_tokenizers
  class _snake_case   ( a__    ,   unittest.TestCase   ):
  							"""simple docstring"""
  
  
  
  
  
  							__a												=     ErnieMTokenizer
  							__a												=     False
  							__a												=     True
  							__a												=     False
  							__a												=     False
  
  
  
  
  
  
  
  							def 		__SCREAMING_SNAKE_CASE(   self	)     ->Union[str, Any]:
  
  
  
  											"""simple docstring"""
  
  
  
  
  
  
  
  											super().setUp()
  
  											# We have a SentencePiece fixture for testing
  											__lowerCamelCase		:      Optional[int]											=					ErnieMTokenizer(__A			,				unk_token="<unk>"			,				pad_token="<pad>"	)
  											tokenizer.save_pretrained(self.tmpdirname	)
  
  
  
  
  
  
  
  							def 		__SCREAMING_SNAKE_CASE(   self			,				__A	)     ->Optional[int]:
  
  
  
  											"""simple docstring"""
  
  
  
  
  
  
  
  											__lowerCamelCase		:      Optional[int]											=					"this is a test"
  											__lowerCamelCase		:      List[str]											=					"this is a test"
  											return input_text, output_text
  
  
  
  
  
  
  
  							def 		__SCREAMING_SNAKE_CASE(   self	)     ->Tuple:
  
  
  
  											"""simple docstring"""
  
  
  
  
  
  
  
  											__lowerCamelCase		:      Any											=					"<pad>"
  											__lowerCamelCase		:      Any											=					0
  
  											self.assertEqual(self.get_tokenizer()._convert_token_to_id(__A	)			,				__A	)
  											self.assertEqual(self.get_tokenizer()._convert_id_to_token(__A	)			,				__A	)
  
  
  
  
  
  
  
  							def 		__SCREAMING_SNAKE_CASE(   self	)     ->Optional[Any]:
  
  
  
  											"""simple docstring"""
  
  
  
  
  
  
  
  											__lowerCamelCase		:      Union[str, Any]											=					list(self.get_tokenizer().get_vocab().keys()	)
  
  											self.assertEqual(vocab_keys[0]			,				"<pad>"	)
  											self.assertEqual(vocab_keys[1]			,				"<unk>"	)
  											self.assertEqual(vocab_keys[-1]			,				"▁eloquent"	)
  											self.assertEqual(len(__A	)			,				30000	)
  
  
  
  
  
  
  
  							def 		__SCREAMING_SNAKE_CASE(   self	)     ->Dict:
  
  
  
  											"""simple docstring"""
  
  
  
  
  
  
  
  											self.assertEqual(self.get_tokenizer().vocab_size			,				30000	)
  
  
  
  
  
  
  
  							def 		__SCREAMING_SNAKE_CASE(   self	)     ->int:
  
  
  
  											"""simple docstring"""
  
  
  
  
  
  
  
  											if not self.test_rust_tokenizer:
  															return
  
  											__lowerCamelCase		:      Union[str, Any]											=					self.get_tokenizer()
  											__lowerCamelCase		:      Optional[Any]											=					self.get_rust_tokenizer()
  
  											__lowerCamelCase		:      Dict											=					"I was born in 92000, and this is falsé."
  
  											__lowerCamelCase		:      str											=					tokenizer.tokenize(__A	)
  											__lowerCamelCase		:      str											=					rust_tokenizer.tokenize(__A	)
  											self.assertListEqual(__A			,				__A	)
  
  											__lowerCamelCase		:      Tuple											=					tokenizer.encode(__A			,				add_special_tokens=__A	)
  											__lowerCamelCase		:      Tuple											=					rust_tokenizer.encode(__A			,				add_special_tokens=__A	)
  											self.assertListEqual(__A			,				__A	)
  
  											__lowerCamelCase		:      Optional[int]											=					self.get_rust_tokenizer()
  											__lowerCamelCase		:      Dict											=					tokenizer.encode(__A	)
  											__lowerCamelCase		:      List[str]											=					rust_tokenizer.encode(__A	)
  											self.assertListEqual(__A			,				__A	)
  
  
  
  
  
  
  
  							def 		__SCREAMING_SNAKE_CASE(   self	)     ->Optional[int]:
  
  
  
  											"""simple docstring"""
  
  
  
  
  
  
  
  											__lowerCamelCase		:      Tuple											=					ErnieMTokenizer(__A			,				do_lower_case=__A			,				unk_token="<unk>"			,				pad_token="<pad>"	)
  
  											__lowerCamelCase		:      Optional[Any]											=					tokenizer.tokenize("This is a test"	)
  											self.assertListEqual(__A			,				["▁this", "▁is", "▁a", "▁test"]	)
  
  											self.assertListEqual(tokenizer.convert_tokens_to_ids(__A	)			,				[48, 25, 21, 1289]	)
  
  											__lowerCamelCase		:      Any											=					tokenizer.tokenize("I was born in 92000, and this is falsé."	)
  											# ErnieMTokenizer(paddlenlp implementation) outputs '9' instead of '_9' so to mimic that '_9' is changed to '9'
  											self.assertListEqual(
  											    __A			,				["▁i", "▁was", "▁born", "▁in", "9", "2000", ",", "▁and", "▁this", "▁is", "▁fal", "s", "é", "."]	)
  											__lowerCamelCase		:      Optional[int]											=					tokenizer.convert_tokens_to_ids(__A	)
  											self.assertListEqual(__A			,				[31, 23, 386, 19, 518, 3050, 15, 17, 48, 25, 8256, 18, 1, 9]	)
  
  											__lowerCamelCase		:      Dict											=					tokenizer.convert_ids_to_tokens(__A	)
  											self.assertListEqual(
  											    __A			,				["▁i", "▁was", "▁born", "▁in", "9", "2000", ",", "▁and", "▁this", "▁is", "▁fal", "s", "<unk>", "."]			,				)
  
  
  
  
  
  
  
  							def 		__SCREAMING_SNAKE_CASE(   self	)     ->Tuple:
  
  
  
  											"""simple docstring"""
  
  
  
  
  
  
  
  											__lowerCamelCase		:      Union[str, Any]											=					ErnieMTokenizer(__A			,				unk_token="<unk>"			,				pad_token="<pad>"	)
  
  											__lowerCamelCase		:      int											=					tokenizer.encode("sequence builders"	)
  											__lowerCamelCase		:      List[Any]											=					tokenizer.encode("multi-sequence build"	)
  
  											__lowerCamelCase		:      Tuple											=					tokenizer.build_inputs_with_special_tokens(__A	)
  											__lowerCamelCase		:      Optional[int]											=					tokenizer.build_inputs_with_special_tokens(__A			,				__A	)
  
  											assert encoded_sentence == [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id]
  											assert encoded_pair == [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id] + [
  											    tokenizer.sep_token_id
  											] + text_a + [tokenizer.sep_token_id]
  
  
  
  
  
  
  
  							@slow
  							def 		__SCREAMING_SNAKE_CASE(   self	)     ->int:
  
  
  
  											"""simple docstring"""
  
  
  
  
  
  
  
  											__lowerCamelCase		:      Tuple											=					{"input_ids": [[0, 11062, 82772, 7, 15, 82772, 538, 51529, 237, 17198, 1290, 206, 9, 215175, 1314, 136, 17198, 1290, 206, 9, 56359, 42, 122009, 9, 16466, 16, 87344, 4537, 9, 4717, 78381, 6, 159958, 7, 15, 24480, 618, 4, 527, 22693, 9, 304, 4, 2777, 24480, 9874, 4, 43523, 594, 4, 803, 18392, 33189, 18, 4, 43523, 24447, 5, 5, 5, 16, 100, 24955, 83658, 9626, 144057, 15, 839, 22335, 16, 136, 24955, 83658, 83479, 15, 39102, 724, 16, 678, 645, 6460, 1328, 4589, 42, 122009, 115774, 23, 3559, 1328, 46876, 7, 136, 53894, 1940, 42227, 41159, 17721, 823, 425, 4, 27512, 98722, 206, 136, 5531, 4970, 919, 17336, 5, 2], [0, 20080, 618, 83, 82775, 47, 479, 9, 1517, 73, 53894, 333, 80581, 110117, 18811, 5256, 1295, 51, 152526, 297, 7986, 390, 124416, 538, 35431, 214, 98, 15044, 25737, 136, 7108, 43701, 23, 756, 135355, 7, 5, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 581, 63773, 119455, 6, 147797, 88203, 7, 645, 70, 21, 3285, 10269, 5, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]}
  											# fmt: on
  
  											self.tokenizer_integration_test_util(
  											    expected_encoding=__A			,				model_name="susnato/ernie-m-base_pytorch"			,				sequences=[
  											        "Transformers (formerly known as pytorch-transformers and pytorch-pretrained-bert) provides "
  											        "general-purpose architectures (BERT, GPT-2, RoBERTa, XLM, DistilBert, XLNet...) for Natural "
  											        "Language Understanding (NLU) and Natural Language Generation (NLG) with over32+ pretrained "
  											        "models in100+ languages and deep interoperability between Jax, PyTorch and TensorFlow.",
  											        "BERT is designed to pre-train deep bidirectional representations from unlabeled text by jointly "
  											        "conditioning on both left and right context in all layers.",
  											        "The quick brown fox jumps over the lazy dog.",
  											    ]			,				)
  
  
  
  
  
  