
import os
import pickle
import unittest

from transformers import AutoTokenizer
from transformers.models.bert.tokenization_bert import BertTokenizer
from transformers.models.bert_japanese.tokenization_bert_japanese import (
    VOCAB_FILES_NAMES,
    BertJapaneseTokenizer,
    CharacterTokenizer,
    JumanppTokenizer,
    MecabTokenizer,
    SudachiTokenizer,
    WordpieceTokenizer,
)
from transformers.testing_utils import custom_tokenizers, require_jumanpp, require_sudachi

from ...test_tokenization_common import TokenizerTesterMixin







@custom_tokenizers
class 			__A( lowercase__  ,   unittest.TestCase			):
				snake_case_						   =    BertJapaneseTokenizer
				snake_case_						   =    False
				snake_case_						   =    True




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      List[str]:


								'''simple docstring'''




								super().setUp()

								__a										=    [
								    '[UNK]',
								    '[CLS]',
								    '[SEP]',
								    'こんにちは',
								    'こん',
								    'にちは',
								    'ばんは',
								    '##こん',
								    '##にちは',
								    '##ばんは',
								    '世界',
								    '##世界',
								    '、',
								    '##、',
								    '。',
								    '##。',
								]

								__a										=    os.path.join(self.tmpdirname		,     VOCAB_FILES_NAMES['''vocab_file''']				)
								with open(self.vocab_file		,     '''w'''		,     encoding='''utf-8'''				) as vocab_writer:
												vocab_writer.write(''''''.join([x + '''\n''' for x in vocab_tokens]				)				)




				def 				SCREAMING_SNAKE_CASE_		(     self		,     _snake_case				)    ->      Optional[int]:


								'''simple docstring'''




								__a										=    'こんにちは、世界。 \nこんばんは、世界。'
								__a										=    'こんにちは 、 世界 。 こんばんは 、 世界 。'
								return input_text, output_text




				def 				SCREAMING_SNAKE_CASE_		(     self		,     _snake_case				)    ->      int:


								'''simple docstring'''




								__a										=    self.get_input_output_texts(SCREAMING_SNAKE_CASE__				)
								__a										=    tokenizer.encode(SCREAMING_SNAKE_CASE__		,     add_special_tokens=SCREAMING_SNAKE_CASE__				)
								__a										=    tokenizer.decode(SCREAMING_SNAKE_CASE__		,     clean_up_tokenization_spaces=SCREAMING_SNAKE_CASE__				)
								return text, ids




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Dict:


								'''simple docstring'''




								pass  # TODO add if relevant




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Tuple:


								'''simple docstring'''




								pass  # TODO add if relevant




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Optional[Any]:


								'''simple docstring'''




								pass  # TODO add if relevant




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Any:


								'''simple docstring'''




								__a										=    self.tokenizer_class(self.vocab_file				)

								__a										=    tokenizer.tokenize('''こんにちは、世界。\nこんばんは、世界。'''				)
								self.assertListEqual(SCREAMING_SNAKE_CASE__		,     ['''こんにちは''', '''、''', '''世界''', '''。''', '''こん''', '''##ばんは''', '''、''', '''世界''', '''。''']				)
								self.assertListEqual(tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE__				)		,     [3, 12, 10, 14, 4, 9, 12, 10, 14]				)




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      List[str]:


								'''simple docstring'''




								__a										=    self.tokenizer_class(self.vocab_file		,     word_tokenizer_type='''mecab'''				)
								self.assertIsNotNone(SCREAMING_SNAKE_CASE__				)

								__a										=    'こんにちは、世界。\nこんばんは、世界。'
								__a										=    tokenizer.tokenize(SCREAMING_SNAKE_CASE__				)
								self.assertListEqual(SCREAMING_SNAKE_CASE__		,     ['''こんにちは''', '''、''', '''世界''', '''。''', '''こん''', '''##ばんは''', '''、''', '''世界''', '''。''']				)
								self.assertListEqual(tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE__				)		,     [3, 12, 10, 14, 4, 9, 12, 10, 14]				)

								__a										=    os.path.join(self.tmpdirname		,     '''tokenizer.bin'''				)
								with open(SCREAMING_SNAKE_CASE__		,     '''wb'''				) as handle:
												pickle.dump(SCREAMING_SNAKE_CASE__		,     SCREAMING_SNAKE_CASE__				)

								with open(SCREAMING_SNAKE_CASE__		,     '''rb'''				) as handle:
												__a										=    pickle.load(SCREAMING_SNAKE_CASE__				)

								__a										=    tokenizer_new.tokenize(SCREAMING_SNAKE_CASE__				)

								self.assertListEqual(SCREAMING_SNAKE_CASE__		,     SCREAMING_SNAKE_CASE__				)




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Union[str, Any]:


								'''simple docstring'''




								__a										=    MecabTokenizer(mecab_dic='''ipadic'''				)

								self.assertListEqual(
								    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''				)		,     ['''アップルストア''', '''で''', '''iPhone''', '''8''', '''が''', '''発売''', '''さ''', '''れ''', '''た''', '''。''']		,     )




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      List[Any]:


								'''simple docstring'''




								try:
												__a										=    MecabTokenizer(mecab_dic='''unidic_lite'''				)
								except ModuleNotFoundError:
												return

								self.assertListEqual(
								    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''				)		,     ['''アップル''', '''ストア''', '''で''', '''iPhone''', '''8''', '''が''', '''発売''', '''さ''', '''れ''', '''た''', '''。''']		,     )




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Optional[int]:


								'''simple docstring'''




								try:
												__a										=    MecabTokenizer(mecab_dic='''unidic'''				)
								except ModuleNotFoundError:
												return

								self.assertListEqual(
								    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''				)		,     ['''アップル''', '''ストア''', '''で''', '''iPhone''', '''8''', '''が''', '''発売''', '''さ''', '''れ''', '''た''', '''。''']		,     )




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Any:


								'''simple docstring'''




								__a										=    MecabTokenizer(do_lower_case=SCREAMING_SNAKE_CASE__		,     mecab_dic='''ipadic'''				)

								self.assertListEqual(
								    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''				)		,     ['''アップルストア''', '''で''', '''iphone''', '''8''', '''が''', '''発売''', '''さ''', '''れ''', '''た''', '''。''']		,     )




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Union[str, Any]:


								'''simple docstring'''




								try:
												__a										=    MecabTokenizer(
												    do_lower_case=SCREAMING_SNAKE_CASE__		,     normalize_text=SCREAMING_SNAKE_CASE__		,     mecab_option='''-d /usr/local/lib/mecab/dic/jumandic'''				)
								except RuntimeError:
												# if dict doesn't exist in the system, previous code raises this error.
												return

								self.assertListEqual(
								    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''				)		,     ['''ｱｯﾌﾟﾙストア''', '''で''', '''iPhone''', '''８''', '''が''', '''発売''', '''さ''', '''れた''', '''\u3000''', '''。''']		,     )




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Any:


								'''simple docstring'''




								__a										=    MecabTokenizer(normalize_text=SCREAMING_SNAKE_CASE__		,     mecab_dic='''ipadic'''				)

								self.assertListEqual(
								    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''				)		,     ['''ｱｯﾌﾟﾙストア''', '''で''', '''iPhone''', '''８''', '''が''', '''発売''', '''さ''', '''れ''', '''た''', '''　''', '''。''']		,     )




				@require_sudachi
				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      str:


								'''simple docstring'''




								__a										=    self.tokenizer_class(self.vocab_file		,     word_tokenizer_type='''sudachi'''				)
								self.assertIsNotNone(SCREAMING_SNAKE_CASE__				)

								__a										=    'こんにちは、世界。\nこんばんは、世界。'
								__a										=    tokenizer.tokenize(SCREAMING_SNAKE_CASE__				)
								self.assertListEqual(SCREAMING_SNAKE_CASE__		,     ['''こんにちは''', '''、''', '''世界''', '''。''', '''こん''', '''##ばんは''', '''、''', '''世界''', '''。''']				)
								self.assertListEqual(tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE__				)		,     [3, 12, 10, 14, 4, 9, 12, 10, 14]				)

								__a										=    os.path.join(self.tmpdirname		,     '''tokenizer.bin'''				)
								with open(SCREAMING_SNAKE_CASE__		,     '''wb'''				) as handle:
												pickle.dump(SCREAMING_SNAKE_CASE__		,     SCREAMING_SNAKE_CASE__				)

								with open(SCREAMING_SNAKE_CASE__		,     '''rb'''				) as handle:
												__a										=    pickle.load(SCREAMING_SNAKE_CASE__				)

								__a										=    tokenizer_new.tokenize(SCREAMING_SNAKE_CASE__				)

								self.assertListEqual(SCREAMING_SNAKE_CASE__		,     SCREAMING_SNAKE_CASE__				)




				@require_sudachi
				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      List[str]:


								'''simple docstring'''




								__a										=    SudachiTokenizer(sudachi_dict_type='''core'''				)

								self.assertListEqual(
								    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''				)		,     [''' ''', '''\t''', '''アップル''', '''ストア''', '''で''', '''iPhone''', '''8''', ''' ''', '''が''', ''' ''', ''' ''', '''\n ''', '''発売''', '''さ''', '''れ''', '''た''', ''' ''', '''。''', ''' ''', ''' ''']		,     )




				@require_sudachi
				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Union[str, Any]:


								'''simple docstring'''




								__a										=    SudachiTokenizer(sudachi_dict_type='''core'''		,     sudachi_split_mode='''A'''				)

								self.assertListEqual(tokenizer.tokenize('''外国人参政権'''				)		,     ['''外国''', '''人''', '''参政''', '''権''']				)




				@require_sudachi
				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Tuple:


								'''simple docstring'''




								__a										=    SudachiTokenizer(sudachi_dict_type='''core'''		,     sudachi_split_mode='''B'''				)

								self.assertListEqual(tokenizer.tokenize('''外国人参政権'''				)		,     ['''外国人''', '''参政権''']				)




				@require_sudachi
				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      List[str]:


								'''simple docstring'''




								__a										=    SudachiTokenizer(sudachi_dict_type='''core'''		,     sudachi_split_mode='''C'''				)

								self.assertListEqual(tokenizer.tokenize('''外国人参政権'''				)		,     ['''外国人参政権''']				)




				@require_sudachi
				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Union[str, Any]:


								'''simple docstring'''




								__a										=    SudachiTokenizer(do_lower_case=SCREAMING_SNAKE_CASE__		,     sudachi_dict_type='''core'''				)

								self.assertListEqual(
								    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''				)		,     [''' ''', '''\t''', '''アップル''', '''ストア''', '''で''', '''iphone''', '''8''', ''' ''', '''が''', ''' ''', ''' ''', '''\n ''', '''発売''', '''さ''', '''れ''', '''た''', ''' ''', '''。''', ''' ''', ''' ''']		,     )




				@require_sudachi
				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Optional[Any]:


								'''simple docstring'''




								__a										=    SudachiTokenizer(normalize_text=SCREAMING_SNAKE_CASE__		,     sudachi_dict_type='''core'''				)

								self.assertListEqual(
								    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''				)		,     [''' ''', '''\t''', '''ｱｯﾌﾟﾙ''', '''ストア''', '''で''', '''iPhone''', '''８''', ''' ''', '''が''', ''' ''', ''' ''', '''\n ''', '''発売''', '''さ''', '''れ''', '''た''', '''\u3000''', '''。''', ''' ''', ''' ''']		,     )




				@require_sudachi
				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      List[str]:


								'''simple docstring'''




								__a										=    SudachiTokenizer(trim_whitespace=SCREAMING_SNAKE_CASE__		,     sudachi_dict_type='''core'''				)

								self.assertListEqual(
								    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''				)		,     ['''アップル''', '''ストア''', '''で''', '''iPhone''', '''8''', '''が''', '''発売''', '''さ''', '''れ''', '''た''', '''。''']		,     )




				@require_jumanpp
				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Optional[Any]:


								'''simple docstring'''




								__a										=    self.tokenizer_class(self.vocab_file		,     word_tokenizer_type='''jumanpp'''				)
								self.assertIsNotNone(SCREAMING_SNAKE_CASE__				)

								__a										=    'こんにちは、世界。\nこんばんは、世界。'
								__a										=    tokenizer.tokenize(SCREAMING_SNAKE_CASE__				)
								self.assertListEqual(SCREAMING_SNAKE_CASE__		,     ['''こんにちは''', '''、''', '''世界''', '''。''', '''こん''', '''##ばんは''', '''、''', '''世界''', '''。''']				)
								self.assertListEqual(tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE__				)		,     [3, 12, 10, 14, 4, 9, 12, 10, 14]				)

								__a										=    os.path.join(self.tmpdirname		,     '''tokenizer.bin'''				)
								with open(SCREAMING_SNAKE_CASE__		,     '''wb'''				) as handle:
												pickle.dump(SCREAMING_SNAKE_CASE__		,     SCREAMING_SNAKE_CASE__				)

								with open(SCREAMING_SNAKE_CASE__		,     '''rb'''				) as handle:
												__a										=    pickle.load(SCREAMING_SNAKE_CASE__				)

								__a										=    tokenizer_new.tokenize(SCREAMING_SNAKE_CASE__				)

								self.assertListEqual(SCREAMING_SNAKE_CASE__		,     SCREAMING_SNAKE_CASE__				)




				@require_jumanpp
				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Optional[int]:


								'''simple docstring'''




								__a										=    JumanppTokenizer()

								self.assertListEqual(
								    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''				)		,     ['''アップル''', '''ストア''', '''で''', '''iPhone''', '''8''', '''\u3000''', '''が''', '''\u3000''', '''\u3000''', '''\u3000''', '''発売''', '''さ''', '''れた''', '''\u3000''', '''。''']		,     )




				@require_jumanpp
				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Optional[Any]:


								'''simple docstring'''




								__a										=    JumanppTokenizer(do_lower_case=SCREAMING_SNAKE_CASE__				)

								self.assertListEqual(
								    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''				)		,     ['''アップル''', '''ストア''', '''で''', '''iphone''', '''8''', '''\u3000''', '''が''', '''\u3000''', '''\u3000''', '''\u3000''', '''発売''', '''さ''', '''れた''', '''\u3000''', '''。''']		,     )




				@require_jumanpp
				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      List[Any]:


								'''simple docstring'''




								__a										=    JumanppTokenizer(normalize_text=SCREAMING_SNAKE_CASE__				)

								self.assertListEqual(
								    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''				)		,     ['''ｱ''', '''ｯ''', '''ﾌ''', '''ﾟ''', '''ﾙ''', '''ストア''', '''で''', '''iPhone''', '''８''', '''\u3000''', '''が''', '''\u3000''', '''\u3000''', '''\u3000''', '''発売''', '''さ''', '''れた''', '''\u3000''', '''。''']		,     )




				@require_jumanpp
				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      int:


								'''simple docstring'''




								__a										=    JumanppTokenizer(trim_whitespace=SCREAMING_SNAKE_CASE__				)

								self.assertListEqual(
								    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''				)		,     ['''アップル''', '''ストア''', '''で''', '''iPhone''', '''8''', '''が''', '''発売''', '''さ''', '''れた''', '''。''']		,     )




				@require_jumanpp
				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      List[str]:


								'''simple docstring'''




								__a										=    JumanppTokenizer()

								self.assertListEqual(
								    tokenizer.tokenize('''ありがとうございますm(_ _)ｍ見つけるのが大変です。'''				)		,     ['''ありがとう''', '''ございます''', '''m(_ _)m''', '''見つける''', '''の''', '''が''', '''大変です''', '''。''']		,     )




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Any:


								'''simple docstring'''




								__a										=    ['[UNK]', '[CLS]', '[SEP]', 'こんにちは', 'こん', 'にちは', 'ばんは', '##こん', '##にちは', '##ばんは']

								__a										=    {}
								for i, token in enumerate(SCREAMING_SNAKE_CASE__				):
												__a										=    i
								__a										=    WordpieceTokenizer(vocab=SCREAMING_SNAKE_CASE__		,     unk_token='''[UNK]'''				)

								self.assertListEqual(tokenizer.tokenize(''''''				)		,     []				)

								self.assertListEqual(tokenizer.tokenize('''こんにちは'''				)		,     ['''こんにちは''']				)

								self.assertListEqual(tokenizer.tokenize('''こんばんは'''				)		,     ['''こん''', '''##ばんは''']				)

								self.assertListEqual(tokenizer.tokenize('''こんばんは こんばんにちは こんにちは'''				)		,     ['''こん''', '''##ばんは''', '''[UNK]''', '''こんにちは''']				)




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      List[str]:


								'''simple docstring'''




								__a										=    BertJapaneseTokenizer.from_pretrained('''nlp-waseda/roberta-base-japanese-with-auto-jumanpp'''				)
								__a										=    tokenizer.subword_tokenizer

								__a										=    subword_tokenizer.tokenize('''国境 の 長い トンネル を 抜ける と 雪国 であった 。'''				)
								self.assertListEqual(SCREAMING_SNAKE_CASE__		,     ['''▁国境''', '''▁の''', '''▁長い''', '''▁トンネル''', '''▁を''', '''▁抜ける''', '''▁と''', '''▁雪''', '''国''', '''▁であった''', '''▁。''']				)

								__a										=    subword_tokenizer.tokenize('''こんばんは こんばん にち は こんにちは'''				)
								self.assertListEqual(SCREAMING_SNAKE_CASE__		,     ['''▁こん''', '''ばん''', '''は''', '''▁こん''', '''ばん''', '''▁に''', '''ち''', '''▁は''', '''▁こんにちは''']				)




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Tuple:


								'''simple docstring'''




								__a										=    self.tokenizer_class.from_pretrained('''cl-tohoku/bert-base-japanese'''				)

								__a										=    tokenizer.encode('''ありがとう。'''		,     add_special_tokens=SCREAMING_SNAKE_CASE__				)
								__a										=    tokenizer.encode('''どういたしまして。'''		,     add_special_tokens=SCREAMING_SNAKE_CASE__				)

								__a										=    tokenizer.build_inputs_with_special_tokens(SCREAMING_SNAKE_CASE__				)
								__a										=    tokenizer.build_inputs_with_special_tokens(SCREAMING_SNAKE_CASE__		,     SCREAMING_SNAKE_CASE__				)

								# 2 is for "[CLS]", 3 is for "[SEP]"
								assert encoded_sentence == [2] + text + [3]
								assert encoded_pair == [2] + text + [3] + text_a + [3]







@custom_tokenizers
class 			__A( lowercase__  ,   unittest.TestCase			):
				snake_case_						   =    BertJapaneseTokenizer
				snake_case_						   =    False




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Any:


								'''simple docstring'''




								super().setUp()

								__a										=    ['[UNK]', '[CLS]', '[SEP]', 'こ', 'ん', 'に', 'ち', 'は', 'ば', '世', '界', '、', '。']

								__a										=    os.path.join(self.tmpdirname		,     VOCAB_FILES_NAMES['''vocab_file''']				)
								with open(self.vocab_file		,     '''w'''		,     encoding='''utf-8'''				) as vocab_writer:
												vocab_writer.write(''''''.join([x + '''\n''' for x in vocab_tokens]				)				)




				def 				SCREAMING_SNAKE_CASE_		(     self		,     **_snake_case				)    ->      Tuple:


								'''simple docstring'''




								return BertJapaneseTokenizer.from_pretrained(self.tmpdirname		,     subword_tokenizer_type='''character'''		,     **SCREAMING_SNAKE_CASE__				)




				def 				SCREAMING_SNAKE_CASE_		(     self		,     _snake_case				)    ->      List[str]:


								'''simple docstring'''




								__a										=    'こんにちは、世界。 \nこんばんは、世界。'
								__a										=    'こ ん に ち は 、 世 界 。 こ ん ば ん は 、 世 界 。'
								return input_text, output_text




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      List[str]:


								'''simple docstring'''




								pass  # TODO add if relevant




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      List[str]:


								'''simple docstring'''




								pass  # TODO add if relevant




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Tuple:


								'''simple docstring'''




								pass  # TODO add if relevant




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Dict:


								'''simple docstring'''




								__a										=    self.tokenizer_class(self.vocab_file		,     subword_tokenizer_type='''character'''				)

								__a										=    tokenizer.tokenize('''こんにちは、世界。 \nこんばんは、世界。'''				)
								self.assertListEqual(
								    SCREAMING_SNAKE_CASE__		,     ['''こ''', '''ん''', '''に''', '''ち''', '''は''', '''、''', '''世''', '''界''', '''。''', '''こ''', '''ん''', '''ば''', '''ん''', '''は''', '''、''', '''世''', '''界''', '''。''']				)
								self.assertListEqual(
								    tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE__				)		,     [3, 4, 5, 6, 7, 11, 9, 10, 12, 3, 4, 8, 4, 7, 11, 9, 10, 12]				)




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Optional[Any]:


								'''simple docstring'''




								__a										=    ['[UNK]', '[CLS]', '[SEP]', 'こ', 'ん', 'に', 'ち', 'は', 'ば', '世', '界', '、', '。']

								__a										=    {}
								for i, token in enumerate(SCREAMING_SNAKE_CASE__				):
												__a										=    i
								__a										=    CharacterTokenizer(vocab=SCREAMING_SNAKE_CASE__		,     unk_token='''[UNK]'''				)

								self.assertListEqual(tokenizer.tokenize(''''''				)		,     []				)

								self.assertListEqual(tokenizer.tokenize('''こんにちは'''				)		,     ['''こ''', '''ん''', '''に''', '''ち''', '''は''']				)

								self.assertListEqual(tokenizer.tokenize('''こんにちほ'''				)		,     ['''こ''', '''ん''', '''に''', '''ち''', '''[UNK]''']				)




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Optional[Any]:


								'''simple docstring'''




								__a										=    self.tokenizer_class.from_pretrained('''cl-tohoku/bert-base-japanese-char'''				)

								__a										=    tokenizer.encode('''ありがとう。'''		,     add_special_tokens=SCREAMING_SNAKE_CASE__				)
								__a										=    tokenizer.encode('''どういたしまして。'''		,     add_special_tokens=SCREAMING_SNAKE_CASE__				)

								__a										=    tokenizer.build_inputs_with_special_tokens(SCREAMING_SNAKE_CASE__				)
								__a										=    tokenizer.build_inputs_with_special_tokens(SCREAMING_SNAKE_CASE__		,     SCREAMING_SNAKE_CASE__				)

								# 2 is for "[CLS]", 3 is for "[SEP]"
								assert encoded_sentence == [2] + text + [3]
								assert encoded_pair == [2] + text + [3] + text_a + [3]







@custom_tokenizers
class 			__A( unittest.TestCase			):




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      List[str]:


								'''simple docstring'''




								__a										=    'cl-tohoku/bert-base-japanese'
								__a										=    AutoTokenizer.from_pretrained(SCREAMING_SNAKE_CASE__				)
								self.assertIsInstance(SCREAMING_SNAKE_CASE__		,     SCREAMING_SNAKE_CASE__				)







class 			__A( unittest.TestCase			):




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Optional[Any]:


								'''simple docstring'''




								__a										=    'cl-tohoku/bert-base-japanese'
								with self.assertLogs('''transformers'''		,     level='''WARNING'''				) as cm:
												BertTokenizer.from_pretrained(SCREAMING_SNAKE_CASE__				)
												self.assertTrue(
												    cm.records[0].message.startswith(
												        '''The tokenizer class you load from this checkpoint is not the same type as the class this function'''
												        ''' is called from.'''				)				)
								__a										=    'bert-base-cased'
								with self.assertLogs('''transformers'''		,     level='''WARNING'''				) as cm:
												BertJapaneseTokenizer.from_pretrained(SCREAMING_SNAKE_CASE__				)
												self.assertTrue(
												    cm.records[0].message.startswith(
												        '''The tokenizer class you load from this checkpoint is not the same type as the class this function'''
												        ''' is called from.'''				)				)



from collections import OrderedDict

from ...utils import logging
from .auto_factory import _BaseAutoModelClass, _LazyAutoMapping, auto_class_update
from .configuration_auto import CONFIG_MAPPING_NAMES


UpperCAmelCase_      : Union[str, Any]  					=       logging.get_logger(__name__)


UpperCAmelCase_      : List[str]  					=       OrderedDict(
    [
        # Base model mapping
        ('albert', 'FlaxAlbertModel'),
        ('bart', 'FlaxBartModel'),
        ('beit', 'FlaxBeitModel'),
        ('bert', 'FlaxBertModel'),
        ('big_bird', 'FlaxBigBirdModel'),
        ('blenderbot', 'FlaxBlenderbotModel'),
        ('blenderbot-small', 'FlaxBlenderbotSmallModel'),
        ('clip', 'FlaxCLIPModel'),
        ('distilbert', 'FlaxDistilBertModel'),
        ('electra', 'FlaxElectraModel'),
        ('gpt-sw3', 'FlaxGPT2Model'),
        ('gpt2', 'FlaxGPT2Model'),
        ('gpt_neo', 'FlaxGPTNeoModel'),
        ('gptj', 'FlaxGPTJModel'),
        ('longt5', 'FlaxLongT5Model'),
        ('marian', 'FlaxMarianModel'),
        ('mbart', 'FlaxMBartModel'),
        ('mt5', 'FlaxMT5Model'),
        ('opt', 'FlaxOPTModel'),
        ('pegasus', 'FlaxPegasusModel'),
        ('regnet', 'FlaxRegNetModel'),
        ('resnet', 'FlaxResNetModel'),
        ('roberta', 'FlaxRobertaModel'),
        ('roberta-prelayernorm', 'FlaxRobertaPreLayerNormModel'),
        ('roformer', 'FlaxRoFormerModel'),
        ('t5', 'FlaxT5Model'),
        ('vision-text-dual-encoder', 'FlaxVisionTextDualEncoderModel'),
        ('vit', 'FlaxViTModel'),
        ('wav2vec2', 'FlaxWav2Vec2Model'),
        ('whisper', 'FlaxWhisperModel'),
        ('xglm', 'FlaxXGLMModel'),
        ('xlm-roberta', 'FlaxXLMRobertaModel'),
    ]
)

UpperCAmelCase_      : str  					=       OrderedDict(
    [
        # Model for pre-training mapping
        ('albert', 'FlaxAlbertForPreTraining'),
        ('bart', 'FlaxBartForConditionalGeneration'),
        ('bert', 'FlaxBertForPreTraining'),
        ('big_bird', 'FlaxBigBirdForPreTraining'),
        ('electra', 'FlaxElectraForPreTraining'),
        ('longt5', 'FlaxLongT5ForConditionalGeneration'),
        ('mbart', 'FlaxMBartForConditionalGeneration'),
        ('mt5', 'FlaxMT5ForConditionalGeneration'),
        ('roberta', 'FlaxRobertaForMaskedLM'),
        ('roberta-prelayernorm', 'FlaxRobertaPreLayerNormForMaskedLM'),
        ('roformer', 'FlaxRoFormerForMaskedLM'),
        ('t5', 'FlaxT5ForConditionalGeneration'),
        ('wav2vec2', 'FlaxWav2Vec2ForPreTraining'),
        ('whisper', 'FlaxWhisperForConditionalGeneration'),
        ('xlm-roberta', 'FlaxXLMRobertaForMaskedLM'),
    ]
)

UpperCAmelCase_      : Dict  					=       OrderedDict(
    [
        # Model for Masked LM mapping
        ('albert', 'FlaxAlbertForMaskedLM'),
        ('bart', 'FlaxBartForConditionalGeneration'),
        ('bert', 'FlaxBertForMaskedLM'),
        ('big_bird', 'FlaxBigBirdForMaskedLM'),
        ('distilbert', 'FlaxDistilBertForMaskedLM'),
        ('electra', 'FlaxElectraForMaskedLM'),
        ('mbart', 'FlaxMBartForConditionalGeneration'),
        ('roberta', 'FlaxRobertaForMaskedLM'),
        ('roberta-prelayernorm', 'FlaxRobertaPreLayerNormForMaskedLM'),
        ('roformer', 'FlaxRoFormerForMaskedLM'),
        ('xlm-roberta', 'FlaxXLMRobertaForMaskedLM'),
    ]
)

UpperCAmelCase_      : Optional[Any]  					=       OrderedDict(
    [
        # Model for Seq2Seq Causal LM mapping
        ('bart', 'FlaxBartForConditionalGeneration'),
        ('blenderbot', 'FlaxBlenderbotForConditionalGeneration'),
        ('blenderbot-small', 'FlaxBlenderbotSmallForConditionalGeneration'),
        ('encoder-decoder', 'FlaxEncoderDecoderModel'),
        ('longt5', 'FlaxLongT5ForConditionalGeneration'),
        ('marian', 'FlaxMarianMTModel'),
        ('mbart', 'FlaxMBartForConditionalGeneration'),
        ('mt5', 'FlaxMT5ForConditionalGeneration'),
        ('pegasus', 'FlaxPegasusForConditionalGeneration'),
        ('t5', 'FlaxT5ForConditionalGeneration'),
    ]
)

UpperCAmelCase_      : List[str]  					=       OrderedDict(
    [
        # Model for Image-classsification
        ('beit', 'FlaxBeitForImageClassification'),
        ('regnet', 'FlaxRegNetForImageClassification'),
        ('resnet', 'FlaxResNetForImageClassification'),
        ('vit', 'FlaxViTForImageClassification'),
    ]
)

UpperCAmelCase_      : int  					=       OrderedDict(
    [
        ('vision-encoder-decoder', 'FlaxVisionEncoderDecoderModel'),
    ]
)

UpperCAmelCase_      : List[str]  					=       OrderedDict(
    [
        # Model for Causal LM mapping
        ('bart', 'FlaxBartForCausalLM'),
        ('bert', 'FlaxBertForCausalLM'),
        ('big_bird', 'FlaxBigBirdForCausalLM'),
        ('electra', 'FlaxElectraForCausalLM'),
        ('gpt-sw3', 'FlaxGPT2LMHeadModel'),
        ('gpt2', 'FlaxGPT2LMHeadModel'),
        ('gpt_neo', 'FlaxGPTNeoForCausalLM'),
        ('gptj', 'FlaxGPTJForCausalLM'),
        ('opt', 'FlaxOPTForCausalLM'),
        ('roberta', 'FlaxRobertaForCausalLM'),
        ('roberta-prelayernorm', 'FlaxRobertaPreLayerNormForCausalLM'),
        ('xglm', 'FlaxXGLMForCausalLM'),
        ('xlm-roberta', 'FlaxXLMRobertaForCausalLM'),
    ]
)

UpperCAmelCase_      : List[str]  					=       OrderedDict(
    [
        # Model for Sequence Classification mapping
        ('albert', 'FlaxAlbertForSequenceClassification'),
        ('bart', 'FlaxBartForSequenceClassification'),
        ('bert', 'FlaxBertForSequenceClassification'),
        ('big_bird', 'FlaxBigBirdForSequenceClassification'),
        ('distilbert', 'FlaxDistilBertForSequenceClassification'),
        ('electra', 'FlaxElectraForSequenceClassification'),
        ('mbart', 'FlaxMBartForSequenceClassification'),
        ('roberta', 'FlaxRobertaForSequenceClassification'),
        ('roberta-prelayernorm', 'FlaxRobertaPreLayerNormForSequenceClassification'),
        ('roformer', 'FlaxRoFormerForSequenceClassification'),
        ('xlm-roberta', 'FlaxXLMRobertaForSequenceClassification'),
    ]
)

UpperCAmelCase_      : List[str]  					=       OrderedDict(
    [
        # Model for Question Answering mapping
        ('albert', 'FlaxAlbertForQuestionAnswering'),
        ('bart', 'FlaxBartForQuestionAnswering'),
        ('bert', 'FlaxBertForQuestionAnswering'),
        ('big_bird', 'FlaxBigBirdForQuestionAnswering'),
        ('distilbert', 'FlaxDistilBertForQuestionAnswering'),
        ('electra', 'FlaxElectraForQuestionAnswering'),
        ('mbart', 'FlaxMBartForQuestionAnswering'),
        ('roberta', 'FlaxRobertaForQuestionAnswering'),
        ('roberta-prelayernorm', 'FlaxRobertaPreLayerNormForQuestionAnswering'),
        ('roformer', 'FlaxRoFormerForQuestionAnswering'),
        ('xlm-roberta', 'FlaxXLMRobertaForQuestionAnswering'),
    ]
)

UpperCAmelCase_      : Union[str, Any]  					=       OrderedDict(
    [
        # Model for Token Classification mapping
        ('albert', 'FlaxAlbertForTokenClassification'),
        ('bert', 'FlaxBertForTokenClassification'),
        ('big_bird', 'FlaxBigBirdForTokenClassification'),
        ('distilbert', 'FlaxDistilBertForTokenClassification'),
        ('electra', 'FlaxElectraForTokenClassification'),
        ('roberta', 'FlaxRobertaForTokenClassification'),
        ('roberta-prelayernorm', 'FlaxRobertaPreLayerNormForTokenClassification'),
        ('roformer', 'FlaxRoFormerForTokenClassification'),
        ('xlm-roberta', 'FlaxXLMRobertaForTokenClassification'),
    ]
)

UpperCAmelCase_      : Dict  					=       OrderedDict(
    [
        # Model for Multiple Choice mapping
        ('albert', 'FlaxAlbertForMultipleChoice'),
        ('bert', 'FlaxBertForMultipleChoice'),
        ('big_bird', 'FlaxBigBirdForMultipleChoice'),
        ('distilbert', 'FlaxDistilBertForMultipleChoice'),
        ('electra', 'FlaxElectraForMultipleChoice'),
        ('roberta', 'FlaxRobertaForMultipleChoice'),
        ('roberta-prelayernorm', 'FlaxRobertaPreLayerNormForMultipleChoice'),
        ('roformer', 'FlaxRoFormerForMultipleChoice'),
        ('xlm-roberta', 'FlaxXLMRobertaForMultipleChoice'),
    ]
)

UpperCAmelCase_      : List[str]  					=       OrderedDict(
    [
        ('bert', 'FlaxBertForNextSentencePrediction'),
    ]
)

UpperCAmelCase_      : Dict  					=       OrderedDict(
    [
        ('speech-encoder-decoder', 'FlaxSpeechEncoderDecoderModel'),
        ('whisper', 'FlaxWhisperForConditionalGeneration'),
    ]
)

UpperCAmelCase_      : Union[str, Any]  					=       OrderedDict(
    [
        ('whisper', 'FlaxWhisperForAudioClassification'),
    ]
)

UpperCAmelCase_      : Any  					=       _LazyAutoMapping(CONFIG_MAPPING_NAMES, FLAX_MODEL_MAPPING_NAMES)
UpperCAmelCase_      : int  					=       _LazyAutoMapping(CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_PRETRAINING_MAPPING_NAMES)
UpperCAmelCase_      : Dict  					=       _LazyAutoMapping(CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_MASKED_LM_MAPPING_NAMES)
UpperCAmelCase_      : List[Any]  					=       _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES
)
UpperCAmelCase_      : int  					=       _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES
)
UpperCAmelCase_      : Any  					=       _LazyAutoMapping(CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES)
UpperCAmelCase_      : int  					=       _LazyAutoMapping(CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_CAUSAL_LM_MAPPING_NAMES)
UpperCAmelCase_      : Dict  					=       _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES
)
UpperCAmelCase_      : Optional[int]  					=       _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES
)
UpperCAmelCase_      : List[Any]  					=       _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES
)
UpperCAmelCase_      : int  					=       _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_MULTIPLE_CHOICE_MAPPING_NAMES
)
UpperCAmelCase_      : Tuple  					=       _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING_NAMES
)
UpperCAmelCase_      : Tuple  					=       _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES
)
UpperCAmelCase_      : Optional[Any]  					=       _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES
)
class  SCREAMING_SNAKE_CASE__  (				_BaseAutoModelClass			):
      snake_case__				:     List[Any]        =						FLAX_MODEL_MAPPING
UpperCAmelCase_      : Tuple  					=       auto_class_update(FlaxAutoModel)
class  SCREAMING_SNAKE_CASE__  (				_BaseAutoModelClass			):
      snake_case__				:     Any        =						FLAX_MODEL_FOR_PRETRAINING_MAPPING
UpperCAmelCase_      : Optional[Any]  					=       auto_class_update(FlaxAutoModelForPreTraining, head_doc='pretraining')
class  SCREAMING_SNAKE_CASE__  (				_BaseAutoModelClass			):
      snake_case__				:     List[Any]        =						FLAX_MODEL_FOR_CAUSAL_LM_MAPPING
UpperCAmelCase_      : Optional[Any]  					=       auto_class_update(FlaxAutoModelForCausalLM, head_doc='causal language modeling')
class  SCREAMING_SNAKE_CASE__  (				_BaseAutoModelClass			):
      snake_case__				:     Optional[Any]        =						FLAX_MODEL_FOR_MASKED_LM_MAPPING
UpperCAmelCase_      : Union[str, Any]  					=       auto_class_update(FlaxAutoModelForMaskedLM, head_doc='masked language modeling')
class  SCREAMING_SNAKE_CASE__  (				_BaseAutoModelClass			):
      snake_case__				:     Tuple        =						FLAX_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
UpperCAmelCase_      : Optional[int]  					=       auto_class_update(
    FlaxAutoModelForSeqaSeqLM, head_doc='sequence-to-sequence language modeling', checkpoint_for_example='t5-base'
)
class  SCREAMING_SNAKE_CASE__  (				_BaseAutoModelClass			):
      snake_case__				:     Tuple        =						FLAX_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING
UpperCAmelCase_      : Optional[Any]  					=       auto_class_update(
    FlaxAutoModelForSequenceClassification, head_doc='sequence classification'
)
class  SCREAMING_SNAKE_CASE__  (				_BaseAutoModelClass			):
      snake_case__				:     Tuple        =						FLAX_MODEL_FOR_QUESTION_ANSWERING_MAPPING
UpperCAmelCase_      : str  					=       auto_class_update(FlaxAutoModelForQuestionAnswering, head_doc='question answering')
class  SCREAMING_SNAKE_CASE__  (				_BaseAutoModelClass			):
      snake_case__				:     List[str]        =						FLAX_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING
UpperCAmelCase_      : Tuple  					=       auto_class_update(
    FlaxAutoModelForTokenClassification, head_doc='token classification'
)
class  SCREAMING_SNAKE_CASE__  (				_BaseAutoModelClass			):
      snake_case__				:     Dict        =						FLAX_MODEL_FOR_MULTIPLE_CHOICE_MAPPING
UpperCAmelCase_      : int  					=       auto_class_update(FlaxAutoModelForMultipleChoice, head_doc='multiple choice')
class  SCREAMING_SNAKE_CASE__  (				_BaseAutoModelClass			):
      snake_case__				:     Optional[int]        =						FLAX_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING
UpperCAmelCase_      : Dict  					=       auto_class_update(
    FlaxAutoModelForNextSentencePrediction, head_doc='next sentence prediction'
)
class  SCREAMING_SNAKE_CASE__  (				_BaseAutoModelClass			):
      snake_case__				:     Dict        =						FLAX_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
UpperCAmelCase_      : str  					=       auto_class_update(
    FlaxAutoModelForImageClassification, head_doc='image classification'
)
class  SCREAMING_SNAKE_CASE__  (				_BaseAutoModelClass			):
      snake_case__				:     Optional[Any]        =						FLAX_MODEL_FOR_VISION_2_SEQ_MAPPING
UpperCAmelCase_      : Tuple  					=       auto_class_update(FlaxAutoModelForVisionaSeq, head_doc='vision-to-text modeling')
class  SCREAMING_SNAKE_CASE__  (				_BaseAutoModelClass			):
      snake_case__				:     Optional[int]        =						FLAX_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING
UpperCAmelCase_      : Union[str, Any]  					=       auto_class_update(
    FlaxAutoModelForSpeechSeqaSeq, head_doc='sequence-to-sequence speech-to-text modeling'
)


