





'''simple docstring'''







import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow


if is_torch_available():
   import torch

   from transformers import XLMRobertaModel
@require_sentencepiece
@require_tokenizers
@require_torch
class 			_lowercase						(       unittest.TestCase					):







     @slow
     def     UpperCamelCase			( self    ) ->	int:
      snake_case				=			XLMRobertaModel.from_pretrained('''xlm-roberta-base'''    )
      snake_case				=			torch.tensor([[0, 5_81, 1_02_69, 83, 9_99_42, 1_36, 6_07_42, 23, 70, 8_05_83, 1_82_76, 2]]    )
      # The dog is cute and lives in the garden house

      snake_case				=			torch.Size((1, 12, 7_68)    )  # batch_size, sequence_length, embedding_vector_dim
      snake_case				=			torch.tensor(
          [[-0.0_1_0_1, 0.1_2_1_8, -0.0_8_0_3, 0.0_8_0_1, 0.1_3_2_7, 0.0_7_7_6, -0.1_2_1_5, 0.2_3_8_3, 0.3_3_3_8, 0.3_1_0_6, 0.0_3_0_0, 0.0_2_5_2]]    )
      #  xlmr = torch.hub.load('pytorch/fairseq', 'xlmr.base')
      #  xlmr.eval()
      #  expected_output_values_last_dim = xlmr.extract_features(input_ids[0])[:, :, -1]
      with torch.no_grad():
       snake_case				=			model(A__    )['''last_hidden_state'''].detach()
      self.assertEqual(output.shape    ,   A__    )
      # compare the actual values for a slice of last dim
      self.assertTrue(torch.allclose(output[:, :, -1]    ,   A__    ,   atol=1e-3    )    )







     @slow
     def     UpperCamelCase			( self    ) ->	Optional[int]:
      snake_case				=			XLMRobertaModel.from_pretrained('''xlm-roberta-large'''    )
      snake_case				=			torch.tensor([[0, 5_81, 1_02_69, 83, 9_99_42, 1_36, 6_07_42, 23, 70, 8_05_83, 1_82_76, 2]]    )
      # The dog is cute and lives in the garden house

      snake_case				=			torch.Size((1, 12, 10_24)    )  # batch_size, sequence_length, embedding_vector_dim
      snake_case				=			torch.tensor(
          [[-0.0_6_9_9, -0.0_3_1_8, 0.0_7_0_5, -0.1_2_4_1, 0.0_9_9_9, -0.0_5_2_0, 0.1_0_0_4, -0.1_8_3_8, -0.4_7_0_4, 0.1_4_3_7, 0.0_8_2_1, 0.0_1_2_6]]    )
      #  xlmr = torch.hub.load('pytorch/fairseq', 'xlmr.large')
      #  xlmr.eval()
      #  expected_output_values_last_dim = xlmr.extract_features(input_ids[0])[:, :, -1]
      with torch.no_grad():
       snake_case				=			model(A__    )['''last_hidden_state'''].detach()
      self.assertEqual(output.shape    ,   A__    )
      # compare the actual values for a slice of last dim
      self.assertTrue(torch.allclose(output[:, :, -1]    ,   A__    ,   atol=1e-3    )    )








'''simple docstring'''







from collections import Counter
from pathlib import Path
from typing import Optional, Tuple

import yaml
class 			_lowercase						(       yaml.SafeLoader					):







     def     UpperCamelCase			( self    ,   A__    ) ->	List[str]:
      snake_case				=			[self.constructed_objects[key_node] for key_node, _ in node.value]
      snake_case				=			[tuple(A__    ) if isinstance(A__    ,   A__    ) else key for key in keys]
      snake_case				=			Counter(A__    )
      snake_case				=			[key for key in counter if counter[key] > 1]
      if duplicate_keys:
       raise TypeError(F"""Got duplicate yaml keys: {duplicate_keys}"""    )







     def     UpperCamelCase			( self    ,   A__    ,   A__=False    ) ->	List[Any]:
      snake_case				=			super().construct_mapping(A__    ,   deep=A__    )
      self._check_no_duplicates_on_constructed_node(A__    )
      return mapping




def    __UpperCamelCase	(	a    : str     ) ->Tuple[Optional[str], str]:
 snake_case				=			list(readme_content.splitlines()     )
 if full_content and full_content[0] == "---" and "---" in full_content[1:]:
  snake_case				=			full_content[1:].index('''---'''     ) + 1
  snake_case				=			'''\n'''.join(full_content[1:sep_idx]     )
  return yamlblock, "\n".join(full_content[sep_idx + 1 :]     )

 return None, "\n".join(a     )
class 			_lowercase						(       __a					):
     # class attributes
     _UpperCAmelCase										=					{'''train_eval_index'''}  # train-eval-index in the YAML metadata







     @classmethod
     def     UpperCamelCase			( cls    ,   A__    ) ->	"DatasetMetadata":
      with open(A__    ,   encoding='''utf-8'''    ) as readme_file:
       snake_case				,		snake_case				=			_split_yaml_from_readme(readme_file.read()    )
      if yaml_string is not None:
       return cls.from_yaml_string(A__    )
      else:
       return cls()







     def     UpperCamelCase			( self    ,   A__    ) ->	str:
      if path.exists():
       with open(A__    ,   encoding='''utf-8'''    ) as readme_file:
        snake_case				=			readme_file.read()
      else:
       snake_case				=			None
      snake_case				=			self._to_readme(A__    )
      with open(A__    ,   '''w'''    ,   encoding='''utf-8'''    ) as readme_file:
       readme_file.write(A__    )







     def     UpperCamelCase			( self    ,   A__ = None    ) ->	str:
      if readme_content is not None:
       snake_case				,		snake_case				=			_split_yaml_from_readme(A__    )
       snake_case				=			'''---\n''' + self.to_yaml_string() + '''---\n''' + content
      else:
       snake_case				=			'''---\n''' + self.to_yaml_string() + '''---\n'''
      return full_content







     @classmethod
     def     UpperCamelCase			( cls    ,   A__    ) ->	"DatasetMetadata":
      snake_case				=			yaml.load(A__    ,   Loader=_NoDuplicateSafeLoader    ) or {}

      # Convert the YAML keys to DatasetMetadata fields
      snake_case				=			{
          (key.replace('''-'''    ,   '''_'''    ) if key.replace('''-'''    ,   '''_'''    ) in cls._FIELDS_WITH_DASHES else key): value
          for key, value in metadata_dict.items()
      }
      return cls(**A__    )







     def     UpperCamelCase			( self    ) ->	str:
      return yaml.safe_dump(
          {
              (key.replace('''_'''    ,   '''-'''    ) if key in self._FIELDS_WITH_DASHES else key): value
              for key, value in self.items()
          }    ,   sort_keys=A__    ,   allow_unicode=A__    ,   encoding='''utf-8'''    ,   ).decode('''utf-8'''    )




_lowercase       						=			{
    'image-classification': [],
    'translation': [],
    'image-segmentation': [],
    'fill-mask': [],
    'automatic-speech-recognition': [],
    'token-classification': [],
    'sentence-similarity': [],
    'audio-classification': [],
    'question-answering': [],
    'summarization': [],
    'zero-shot-classification': [],
    'table-to-text': [],
    'feature-extraction': [],
    'other': [],
    'multiple-choice': [],
    'text-classification': [],
    'text-to-image': [],
    'text2text-generation': [],
    'zero-shot-image-classification': [],
    'tabular-classification': [],
    'tabular-regression': [],
    'image-to-image': [],
    'tabular-to-text': [],
    'unconditional-image-generation': [],
    'text-retrieval': [],
    'text-to-speech': [],
    'object-detection': [],
    'audio-to-audio': [],
    'text-generation': [],
    'conversational': [],
    'table-question-answering': [],
    'visual-question-answering': [],
    'image-to-text': [],
    'reinforcement-learning': [],
    'voice-activity-detection': [],
    'time-series-forecasting': [],
    'document-question-answering': [],
}


if __name__ == "__main__":
   from argparse import ArgumentParser

   _lowercase       						=			ArgumentParser(usage='Validate the yaml metadata block of a README.md file.')
   ap.add_argument('readme_filepath')
   _lowercase       						=			ap.parse_args()

   _lowercase       						=			Path(args.readme_filepath)
   _lowercase       						=			DatasetMetadata.from_readme(readme_filepath)
   print(dataset_metadata)
   dataset_metadata.to_readme(readme_filepath)

