'''simple docstring'''




import unittest

from transformers.utils.backbone_utils import (
    BackboneMixin,
    get_aligned_output_features_output_indices,
    verify_out_features_out_indices,
)




class        a__ (  unittest.TestCase					):






     def   SCREAMING_SNAKE_CASE__  (					self						:						Tuple       ):





         """simple docstring"""



         __lowerCamelCase            =    ['''a''', '''b''', '''c''']

         # Defaults to last layer if both are None
         __lowerCamelCase      ,    __lowerCamelCase            =    get_aligned_output_features_output_indices(__UpperCAmelCase    ,							__UpperCAmelCase    ,							__UpperCAmelCase       )
         self.assertEqual(__UpperCAmelCase    ,							['''c''']       )
         self.assertEqual(__UpperCAmelCase    ,							[2]       )

         # Out indices set to match out features
         __lowerCamelCase      ,    __lowerCamelCase            =    get_aligned_output_features_output_indices(['''a''', '''c''']    ,							__UpperCAmelCase    ,							__UpperCAmelCase       )
         self.assertEqual(__UpperCAmelCase    ,							['''a''', '''c''']       )
         self.assertEqual(__UpperCAmelCase    ,							[0, 2]       )

         # Out features set to match out indices
         __lowerCamelCase      ,    __lowerCamelCase            =    get_aligned_output_features_output_indices(__UpperCAmelCase    ,							[0, 2]    ,							__UpperCAmelCase       )
         self.assertEqual(__UpperCAmelCase    ,							['''a''', '''c''']       )
         self.assertEqual(__UpperCAmelCase    ,							[0, 2]       )

         # Out features selected from negative indices
         __lowerCamelCase      ,    __lowerCamelCase            =    get_aligned_output_features_output_indices(__UpperCAmelCase    ,							[-3, -1]    ,							__UpperCAmelCase       )
         self.assertEqual(__UpperCAmelCase    ,							['''a''', '''c''']       )
         self.assertEqual(__UpperCAmelCase    ,							[-3, -1]       )






     def   SCREAMING_SNAKE_CASE__  (					self						:						Dict       ):





         """simple docstring"""



         with self.assertRaises(__UpperCAmelCase       ):
             verify_out_features_out_indices(['''a''', '''b''']    ,							(0, 1)    ,							__UpperCAmelCase       )

         # Out features must be a list
         with self.assertRaises(__UpperCAmelCase       ):
             verify_out_features_out_indices(('''a''', '''b''')    ,							(0, 1)    ,							['''a''', '''b''']       )

         # Out features must be a subset of stage names
         with self.assertRaises(__UpperCAmelCase       ):
             verify_out_features_out_indices(['''a''', '''b''']    ,							(0, 1)    ,							['''a''']       )

         # Out indices must be a list or tuple
         with self.assertRaises(__UpperCAmelCase       ):
             verify_out_features_out_indices(__UpperCAmelCase    ,							0    ,							['''a''', '''b''']       )

         # Out indices must be a subset of stage names
         with self.assertRaises(__UpperCAmelCase       ):
             verify_out_features_out_indices(__UpperCAmelCase    ,							(0, 1)    ,							['''a''']       )

         # Out features and out indices must be the same length
         with self.assertRaises(__UpperCAmelCase       ):
             verify_out_features_out_indices(['''a''', '''b''']    ,							(0,)    ,							['''a''', '''b''', '''c''']       )

         # Out features should match out indices
         with self.assertRaises(__UpperCAmelCase       ):
             verify_out_features_out_indices(['''a''', '''b''']    ,							(0, 2)    ,							['''a''', '''b''', '''c''']       )

         # Out features and out indices should be in order
         with self.assertRaises(__UpperCAmelCase       ):
             verify_out_features_out_indices(['''b''', '''a''']    ,							(0, 1)    ,							['''a''', '''b''']       )

         # Check passes with valid inputs
         verify_out_features_out_indices(['''a''', '''b''', '''d''']    ,							(0, 1, -1)    ,							['''a''', '''b''', '''c''', '''d''']       )






     def   SCREAMING_SNAKE_CASE__  (					self						:						Dict       ):





         """simple docstring"""



         __lowerCamelCase            =    BackboneMixin()

         __lowerCamelCase            =    ['''a''', '''b''', '''c''']
         __lowerCamelCase            =    ['''a''', '''c''']
         __lowerCamelCase            =    [0, 2]

         # Check that the output features and indices are set correctly
         self.assertEqual(backbone.out_features    ,							['''a''', '''c''']       )
         self.assertEqual(backbone.out_indices    ,							[0, 2]       )

         # Check out features and indices are updated correctly
         __lowerCamelCase            =    ['''a''', '''b''']
         self.assertEqual(backbone.out_features    ,							['''a''', '''b''']       )
         self.assertEqual(backbone.out_indices    ,							[0, 1]       )

         __lowerCamelCase            =    [-3, -1]
         self.assertEqual(backbone.out_features    ,							['''a''', '''c''']       )
         self.assertEqual(backbone.out_indices    ,							[-3, -1]       )



"""simple docstring"""




import os
import unittest

from transformers.models.phobert.tokenization_phobert import VOCAB_FILES_NAMES, PhobertTokenizer

from ...test_tokenization_common import TokenizerTesterMixin





class  lowerCamelCase    (A__      ,unittest.TestCase      ):
			lowerCamelCase__ :		List[str]       		=				PhobertTokenizer
			lowerCamelCase__ :		Union[str, Any]       		=				False

			def        SCREAMING_SNAKE_CASE					(       self					:    int							) ->     Any:
						super().setUp()

						# Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
						SCREAMING_SNAKE_CASE__										=   ["""T@@""", """i""", """I""", """R@@""", """r""", """e@@"""]
						SCREAMING_SNAKE_CASE__										=   dict(zip(__UpperCAmelCase     ,					range(len(__UpperCAmelCase							)							)							)							)
						SCREAMING_SNAKE_CASE__										=   ["""#version: 0.2""", """l à</w>"""]
						SCREAMING_SNAKE_CASE__										=   {"""unk_token""": """<unk>"""}

						SCREAMING_SNAKE_CASE__										=   os.path.join(self.tmpdirname     ,					VOCAB_FILES_NAMES["""vocab_file"""]							)
						SCREAMING_SNAKE_CASE__										=   os.path.join(self.tmpdirname     ,					VOCAB_FILES_NAMES["""merges_file"""]							)

						with open(self.vocab_file     ,					"""w"""     ,					encoding="""utf-8"""							) as fp:
									for token in vocab_tokens:
												fp.write(F"""{token} {vocab_tokens[token]}\n"""							)
						with open(self.merges_file     ,					"""w"""     ,					encoding="""utf-8"""							) as fp:
									fp.write("""\n""".join(__UpperCAmelCase							)							)

			def        SCREAMING_SNAKE_CASE					(       self					:    List[Any]     ,					**__UpperCAmelCase					:    int							) ->     Optional[int]:
						kwargs.update(self.special_tokens_map							)
						return PhobertTokenizer.from_pretrained(self.tmpdirname     ,					**__UpperCAmelCase							)

			def        SCREAMING_SNAKE_CASE					(       self					:    Dict     ,					__UpperCAmelCase					:    int							) ->     Optional[Any]:
						SCREAMING_SNAKE_CASE__										=   """Tôi là VinAI Research"""
						SCREAMING_SNAKE_CASE__										=   """T<unk> i <unk> <unk> <unk> <unk> <unk> <unk> I Re<unk> e<unk> <unk> <unk> <unk>"""
						return input_text, output_text





			def        SCREAMING_SNAKE_CASE					(       self					:    Optional[int]							) ->     int:
						SCREAMING_SNAKE_CASE__										=   PhobertTokenizer(self.vocab_file     ,					self.merges_file     ,					**self.special_tokens_map							)
						SCREAMING_SNAKE_CASE__										=   """Tôi là VinAI Research"""
						SCREAMING_SNAKE_CASE__										=   """T@@ ô@@ i l@@ à V@@ i@@ n@@ A@@ I R@@ e@@ s@@ e@@ a@@ r@@ c@@ h""".split()
						SCREAMING_SNAKE_CASE__										=   tokenizer.tokenize(__UpperCAmelCase							)
						print(__UpperCAmelCase							)
						self.assertListEqual(__UpperCAmelCase     ,					__UpperCAmelCase							)

						SCREAMING_SNAKE_CASE__										=   tokens + [tokenizer.unk_token]

						SCREAMING_SNAKE_CASE__										=   [4, 3, 5, 3, 3, 3, 3, 3, 3, 6, 7, 9, 3, 9, 3, 3, 3, 3, 3]
						self.assertListEqual(tokenizer.convert_tokens_to_ids(__UpperCAmelCase							)     ,					__UpperCAmelCase							)


