






import json
import os
import unittest

from transformers.models.ctrl.tokenization_ctrl import VOCAB_FILES_NAMES, CTRLTokenizer

from ...test_tokenization_common import TokenizerTesterMixin



class 							SCREAMING_SNAKE_CASE__						(    UpperCamelCase_			,       unittest.TestCase						):





					"""simple docstring"""






					a_     =		CTRLTokenizer
					a_     =		False
					a_     =		False



					def 	_lowercase					( self					:  List[Any]	):
						super().setUp()

						# Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
						snake_case__			:				Optional[Any]       =  ["adapt", "re@@", "a@@", "apt", "c@@", "t", "<unk>"]
						snake_case__			:				Any       =  dict(zip(__A							,		range(len(__A	)	)	)	)
						snake_case__			:				int       =  ["#version: 0.2", "a p", "ap t</w>", "r e", "a d", "ad apt</w>", ""]
						snake_case__			:				Dict       =  {"unk_token": "<unk>"}

						snake_case__			:				List[Any]       =  os.path.join(self.tmpdirname							,		VOCAB_FILES_NAMES["vocab_file"]	)
						snake_case__			:				int       =  os.path.join(self.tmpdirname							,		VOCAB_FILES_NAMES["merges_file"]	)
						with open(self.vocab_file							,		"w"							,		encoding="utf-8"	) as fp:
							fp.write(json.dumps(__A	) + "\n"	)
						with open(self.merges_file							,		"w"							,		encoding="utf-8"	) as fp:
							fp.write("\n".join(__A	)	)



					def 	_lowercase					( self					:  str							,		**__A					:  List[Any]	):
						kwargs.update(self.special_tokens_map	)
						return CTRLTokenizer.from_pretrained(self.tmpdirname							,		**__A	)



					def 	_lowercase					( self					:  Optional[Any]							,		__A					:  Tuple	):
						snake_case__			:				str       =  "adapt react readapt apt"
						snake_case__			:				Optional[int]       =  "adapt react readapt apt"
						return input_text, output_text






					def 	_lowercase					( self					:  int	):
						snake_case__			:				str       =  CTRLTokenizer(self.vocab_file							,		self.merges_file							,		**self.special_tokens_map	)
						snake_case__			:				Optional[Any]       =  "adapt react readapt apt"
						snake_case__			:				Dict       =  "adapt re@@ a@@ c@@ t re@@ adapt apt".split()
						snake_case__			:				Optional[int]       =  tokenizer.tokenize(__A	)
						self.assertListEqual(__A							,		__A	)

						snake_case__			:				Union[str, Any]       =  tokens + [tokenizer.unk_token]

						snake_case__			:				List[Any]       =  [0, 1, 2, 4, 5, 1, 0, 3, 6]
						self.assertListEqual(tokenizer.convert_tokens_to_ids(__A	)							,		__A	)











import os
import unittest

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

from ...test_tokenization_common import TokenizerTesterMixin



class 							SCREAMING_SNAKE_CASE__						(    UpperCamelCase_			,       unittest.TestCase						):





					"""simple docstring"""






					a_     =		PhobertTokenizer
					a_     =		False



					def 	_lowercase					( self					:  List[str]	):
						super().setUp()

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

						snake_case__			:				Tuple       =  os.path.join(self.tmpdirname							,		VOCAB_FILES_NAMES["vocab_file"]	)
						snake_case__			:				Union[str, Any]       =  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(__A	)	)



					def 	_lowercase					( self					:  List[str]							,		**__A					:  Any	):
						kwargs.update(self.special_tokens_map	)
						return PhobertTokenizer.from_pretrained(self.tmpdirname							,		**__A	)



					def 	_lowercase					( self					:  Tuple							,		__A					:  List[Any]	):
						snake_case__			:				str       =  "Tôi là VinAI Research"
						snake_case__			:				int       =  "T<unk> i <unk> <unk> <unk> <unk> <unk> <unk> I Re<unk> e<unk> <unk> <unk> <unk>"
						return input_text, output_text






					def 	_lowercase					( self					:  Optional[int]	):
						snake_case__			:				int       =  PhobertTokenizer(self.vocab_file							,		self.merges_file							,		**self.special_tokens_map	)
						snake_case__			:				Tuple       =  "Tôi là VinAI Research"
						snake_case__			:				List[Any]       =  "T@@ ô@@ i l@@ à V@@ i@@ n@@ A@@ I R@@ e@@ s@@ e@@ a@@ r@@ c@@ h".split()
						snake_case__			:				int       =  tokenizer.tokenize(__A	)
						print(__A	)
						self.assertListEqual(__A							,		__A	)

						snake_case__			:				Any       =  tokens + [tokenizer.unk_token]

						snake_case__			:				Any       =  [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(__A	)							,		__A	)



