


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  SCREAMING_SNAKE_CASE__  (				lowercase__						,    unittest.TestCase			):
      snake_case__				:     int        =						BertJapaneseTokenizer
      snake_case__				:     Optional[int]        =						False
      snake_case__				:     Union[str, Any]        =						True
      def        SCREAMING_SNAKE_CASE							(       self				:       Tuple     )		->			List[str]:
             super().setUp()

             a_					:		Optional[Any]							=  [
                 '[UNK]',
                 '[CLS]',
                 '[SEP]',
                 'こんにちは',
                 'こん',
                 'にちは',
                 'ばんは',
                 '##こん',
                 '##にちは',
                 '##ばんは',
                 '世界',
                 '##世界',
                 '、',
                 '##、',
                 '。',
                 '##。',
             ]

             a_					:		Dict							=  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				:       str     ,							SCREAMING_SNAKE_CASE__				:       List[Any]     )		->			Optional[int]:
             a_					:		Optional[int]							=  'こんにちは、世界。 \nこんばんは、世界。'
             a_					:		Optional[Any]							=  'こんにちは 、 世界 。 こんばんは 、 世界 。'
             return input_text, output_text
      def        SCREAMING_SNAKE_CASE							(       self				:       Dict     ,							SCREAMING_SNAKE_CASE__				:       List[str]     )		->			int:
             a_							,		a_					:		int							=  self.get_input_output_texts(SCREAMING_SNAKE_CASE__     )
             a_					:		List[Any]							=  tokenizer.encode(SCREAMING_SNAKE_CASE__     ,							add_special_tokens=SCREAMING_SNAKE_CASE__     )
             a_					:		Tuple							=  tokenizer.decode(SCREAMING_SNAKE_CASE__     ,							clean_up_tokenization_spaces=SCREAMING_SNAKE_CASE__     )
             return text, ids
      def        SCREAMING_SNAKE_CASE							(       self				:       Optional[int]     )		->			Dict:
             pass  # TODO add if relevant
      def        SCREAMING_SNAKE_CASE							(       self				:       List[str]     )		->			Tuple:
             pass  # TODO add if relevant
      def        SCREAMING_SNAKE_CASE							(       self				:       List[Any]     )		->			Optional[Any]:
             pass  # TODO add if relevant
      def        SCREAMING_SNAKE_CASE							(       self				:       Any     )		->			Any:
             a_					:		Union[str, Any]							=  self.tokenizer_class(self.vocab_file     )

             a_					:		str							=  tokenizer.tokenize('こんにちは、世界。\nこんばんは、世界。'     )
             self.assertListEqual(SCREAMING_SNAKE_CASE__     ,							['こんにちは', '、', '世界', '。', 'こん', '##ばんは', '、', '世界', '。']     )
             self.assertListEqual(tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE__     )     ,							[3, 1_2, 1_0, 1_4, 4, 9, 1_2, 1_0, 1_4]     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Optional[int]     )		->			List[str]:
             a_					:		str							=  self.tokenizer_class(self.vocab_file     ,							word_tokenizer_type='mecab'     )
             self.assertIsNotNone(SCREAMING_SNAKE_CASE__     )

             a_					:		str							=  'こんにちは、世界。\nこんばんは、世界。'
             a_					:		List[Any]							=  tokenizer.tokenize(SCREAMING_SNAKE_CASE__     )
             self.assertListEqual(SCREAMING_SNAKE_CASE__     ,							['こんにちは', '、', '世界', '。', 'こん', '##ばんは', '、', '世界', '。']     )
             self.assertListEqual(tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE__     )     ,							[3, 1_2, 1_0, 1_4, 4, 9, 1_2, 1_0, 1_4]     )

             a_					:		Optional[int]							=  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_					:		Union[str, Any]							=  pickle.load(SCREAMING_SNAKE_CASE__     )

             a_					:		List[Any]							=  tokenizer_new.tokenize(SCREAMING_SNAKE_CASE__     )

             self.assertListEqual(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Tuple     )		->			Union[str, Any]:
             a_					:		List[str]							=  MecabTokenizer(mecab_dic='ipadic'     )

             self.assertListEqual(
                 tokenizer.tokenize(' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '     )     ,							['アップルストア', 'で', 'iPhone', '8', 'が', '発売', 'さ', 'れ', 'た', '。']     ,							)
      def        SCREAMING_SNAKE_CASE							(       self				:       Union[str, Any]     )		->			List[Any]:
             try:
                    a_					:		List[str]							=  MecabTokenizer(mecab_dic='unidic_lite'     )
             except ModuleNotFoundError:
                    return

             self.assertListEqual(
                 tokenizer.tokenize(' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '     )     ,							['アップル', 'ストア', 'で', 'iPhone', '8', 'が', '発売', 'さ', 'れ', 'た', '。']     ,							)
      def        SCREAMING_SNAKE_CASE							(       self				:       Tuple     )		->			Optional[int]:
             try:
                    a_					:		Union[str, Any]							=  MecabTokenizer(mecab_dic='unidic'     )
             except ModuleNotFoundError:
                    return

             self.assertListEqual(
                 tokenizer.tokenize(' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '     )     ,							['アップル', 'ストア', 'で', 'iPhone', '8', 'が', '発売', 'さ', 'れ', 'た', '。']     ,							)
      def        SCREAMING_SNAKE_CASE							(       self				:       str     )		->			Any:
             a_					:		Optional[Any]							=  MecabTokenizer(do_lower_case=SCREAMING_SNAKE_CASE__     ,							mecab_dic='ipadic'     )

             self.assertListEqual(
                 tokenizer.tokenize(' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '     )     ,							['アップルストア', 'で', 'iphone', '8', 'が', '発売', 'さ', 'れ', 'た', '。']     ,							)
      def        SCREAMING_SNAKE_CASE							(       self				:       Optional[int]     )		->			Union[str, Any]:
             try:
                    a_					:		Any							=  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				:       List[str]     )		->			Any:
             a_					:		int							=  MecabTokenizer(normalize_text=SCREAMING_SNAKE_CASE__     ,							mecab_dic='ipadic'     )

             self.assertListEqual(
                 tokenizer.tokenize(' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '     )     ,							['ｱｯﾌﾟﾙストア', 'で', 'iPhone', '８', 'が', '発売', 'さ', 'れ', 'た', '　', '。']     ,							)
      @require_sudachi
      def        SCREAMING_SNAKE_CASE							(       self				:       Optional[int]     )		->			str:
             a_					:		List[str]							=  self.tokenizer_class(self.vocab_file     ,							word_tokenizer_type='sudachi'     )
             self.assertIsNotNone(SCREAMING_SNAKE_CASE__     )

             a_					:		List[str]							=  'こんにちは、世界。\nこんばんは、世界。'
             a_					:		Dict							=  tokenizer.tokenize(SCREAMING_SNAKE_CASE__     )
             self.assertListEqual(SCREAMING_SNAKE_CASE__     ,							['こんにちは', '、', '世界', '。', 'こん', '##ばんは', '、', '世界', '。']     )
             self.assertListEqual(tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE__     )     ,							[3, 1_2, 1_0, 1_4, 4, 9, 1_2, 1_0, 1_4]     )

             a_					:		int							=  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_					:		Union[str, Any]							=  pickle.load(SCREAMING_SNAKE_CASE__     )

             a_					:		Optional[Any]							=  tokenizer_new.tokenize(SCREAMING_SNAKE_CASE__     )

             self.assertListEqual(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     )
      @require_sudachi
      def        SCREAMING_SNAKE_CASE							(       self				:       int     )		->			List[str]:
             a_					:		List[str]							=  SudachiTokenizer(sudachi_dict_type='core'     )

             self.assertListEqual(
                 tokenizer.tokenize(' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '     )     ,							[' ', '\t', 'アップル', 'ストア', 'で', 'iPhone', '8', ' ', 'が', ' ', ' ', '\n ', '発売', 'さ', 'れ', 'た', ' ', '。', ' ', ' ']     ,							)
      @require_sudachi
      def        SCREAMING_SNAKE_CASE							(       self				:       Tuple     )		->			Union[str, Any]:
             a_					:		List[Any]							=  SudachiTokenizer(sudachi_dict_type='core'     ,							sudachi_split_mode='A'     )

             self.assertListEqual(tokenizer.tokenize('外国人参政権'     )     ,							['外国', '人', '参政', '権']     )
      @require_sudachi
      def        SCREAMING_SNAKE_CASE							(       self				:       Union[str, Any]     )		->			Tuple:
             a_					:		Tuple							=  SudachiTokenizer(sudachi_dict_type='core'     ,							sudachi_split_mode='B'     )

             self.assertListEqual(tokenizer.tokenize('外国人参政権'     )     ,							['外国人', '参政権']     )
      @require_sudachi
      def        SCREAMING_SNAKE_CASE							(       self				:       str     )		->			List[str]:
             a_					:		Union[str, Any]							=  SudachiTokenizer(sudachi_dict_type='core'     ,							sudachi_split_mode='C'     )

             self.assertListEqual(tokenizer.tokenize('外国人参政権'     )     ,							['外国人参政権']     )
      @require_sudachi
      def        SCREAMING_SNAKE_CASE							(       self				:       List[Any]     )		->			Union[str, Any]:
             a_					:		Dict							=  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				:       Union[str, Any]     )		->			Optional[Any]:
             a_					:		Any							=  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				:       Tuple     )		->			List[str]:
             a_					:		int							=  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				:       Tuple     )		->			Optional[Any]:
             a_					:		Tuple							=  self.tokenizer_class(self.vocab_file     ,							word_tokenizer_type='jumanpp'     )
             self.assertIsNotNone(SCREAMING_SNAKE_CASE__     )

             a_					:		Any							=  'こんにちは、世界。\nこんばんは、世界。'
             a_					:		List[Any]							=  tokenizer.tokenize(SCREAMING_SNAKE_CASE__     )
             self.assertListEqual(SCREAMING_SNAKE_CASE__     ,							['こんにちは', '、', '世界', '。', 'こん', '##ばんは', '、', '世界', '。']     )
             self.assertListEqual(tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE__     )     ,							[3, 1_2, 1_0, 1_4, 4, 9, 1_2, 1_0, 1_4]     )

             a_					:		Optional[int]							=  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_					:		Optional[Any]							=  pickle.load(SCREAMING_SNAKE_CASE__     )

             a_					:		Tuple							=  tokenizer_new.tokenize(SCREAMING_SNAKE_CASE__     )

             self.assertListEqual(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     )
      @require_jumanpp
      def        SCREAMING_SNAKE_CASE							(       self				:       Union[str, Any]     )		->			Optional[int]:
             a_					:		Optional[Any]							=  JumanppTokenizer()

             self.assertListEqual(
                 tokenizer.tokenize(' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '     )     ,							['アップル', 'ストア', 'で', 'iPhone', '8', '\u3000', 'が', '\u3000', '\u3000', '\u3000', '発売', 'さ', 'れた', '\u3000', '。']     ,							)
      @require_jumanpp
      def        SCREAMING_SNAKE_CASE							(       self				:       Any     )		->			Optional[Any]:
             a_					:		Union[str, Any]							=  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]     )		->			List[Any]:
             a_					:		Optional[int]							=  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				:       Any     )		->			int:
             a_					:		Dict							=  JumanppTokenizer(trim_whitespace=SCREAMING_SNAKE_CASE__     )

             self.assertListEqual(
                 tokenizer.tokenize(' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '     )     ,							['アップル', 'ストア', 'で', 'iPhone', '8', 'が', '発売', 'さ', 'れた', '。']     ,							)
      @require_jumanpp
      def        SCREAMING_SNAKE_CASE							(       self				:       Any     )		->			List[str]:
             a_					:		str							=  JumanppTokenizer()

             self.assertListEqual(
                 tokenizer.tokenize('ありがとうございますm(_ _)ｍ見つけるのが大変です。'     )     ,							['ありがとう', 'ございます', 'm(_ _)m', '見つける', 'の', 'が', '大変です', '。']     ,							)
      def        SCREAMING_SNAKE_CASE							(       self				:       Dict     )		->			Any:
             a_					:		Tuple							=  ['[UNK]', '[CLS]', '[SEP]', 'こんにちは', 'こん', 'にちは', 'ばんは', '##こん', '##にちは', '##ばんは']

             a_					:		List[Any]							=  {}
             for i, token in enumerate(SCREAMING_SNAKE_CASE__     ):
                    a_					:		List[str]							=  i
             a_					:		Dict							=  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				:       Union[str, Any]     )		->			List[str]:
             a_					:		List[str]							=  BertJapaneseTokenizer.from_pretrained('nlp-waseda/roberta-base-japanese-with-auto-jumanpp'     )
             a_					:		List[str]							=  tokenizer.subword_tokenizer

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

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

      def        SCREAMING_SNAKE_CASE							(       self				:       Tuple     )		->			Tuple:
             a_					:		Optional[Any]							=  self.tokenizer_class.from_pretrained('cl-tohoku/bert-base-japanese'     )

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

             a_					:		int							=  tokenizer.build_inputs_with_special_tokens(SCREAMING_SNAKE_CASE__     )
             a_					:		List[Any]							=  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  SCREAMING_SNAKE_CASE__  (				lowercase__						,    unittest.TestCase			):
      snake_case__				:     Optional[int]        =						BertJapaneseTokenizer
      snake_case__				:     str        =						False
      def        SCREAMING_SNAKE_CASE							(       self				:       str     )		->			Any:
             super().setUp()

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

             a_					:		str							=  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				:       str     ,							**SCREAMING_SNAKE_CASE__				:       Optional[int]     )		->			Tuple:
             return BertJapaneseTokenizer.from_pretrained(self.tmpdirname     ,							subword_tokenizer_type='character'     ,							**SCREAMING_SNAKE_CASE__     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Dict     ,							SCREAMING_SNAKE_CASE__				:       List[str]     )		->			List[str]:
             a_					:		List[Any]							=  'こんにちは、世界。 \nこんばんは、世界。'
             a_					:		Optional[Any]							=  'こ ん に ち は 、 世 界 。 こ ん ば ん は 、 世 界 。'
             return input_text, output_text
      def        SCREAMING_SNAKE_CASE							(       self				:       Any     )		->			List[str]:
             pass  # TODO add if relevant
      def        SCREAMING_SNAKE_CASE							(       self				:       List[Any]     )		->			List[str]:
             pass  # TODO add if relevant
      def        SCREAMING_SNAKE_CASE							(       self				:       Optional[Any]     )		->			Tuple:
             pass  # TODO add if relevant
      def        SCREAMING_SNAKE_CASE							(       self				:       Optional[Any]     )		->			Dict:
             a_					:		Optional[int]							=  self.tokenizer_class(self.vocab_file     ,							subword_tokenizer_type='character'     )

             a_					:		Any							=  tokenizer.tokenize('こんにちは、世界。 \nこんばんは、世界。'     )
             self.assertListEqual(
                 SCREAMING_SNAKE_CASE__     ,							['こ', 'ん', 'に', 'ち', 'は', '、', '世', '界', '。', 'こ', 'ん', 'ば', 'ん', 'は', '、', '世', '界', '。']     )
             self.assertListEqual(
                 tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE__     )     ,							[3, 4, 5, 6, 7, 1_1, 9, 1_0, 1_2, 3, 4, 8, 4, 7, 1_1, 9, 1_0, 1_2]     )
      def        SCREAMING_SNAKE_CASE							(       self				:       str     )		->			Optional[Any]:
             a_					:		Dict							=  ['[UNK]', '[CLS]', '[SEP]', 'こ', 'ん', 'に', 'ち', 'は', 'ば', '世', '界', '、', '。']

             a_					:		Dict							=  {}
             for i, token in enumerate(SCREAMING_SNAKE_CASE__     ):
                    a_					:		str							=  i
             a_					:		Optional[Any]							=  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				:       str     )		->			Optional[Any]:
             a_					:		Union[str, Any]							=  self.tokenizer_class.from_pretrained('cl-tohoku/bert-base-japanese-char'     )

             a_					:		Optional[Any]							=  tokenizer.encode('ありがとう。'     ,							add_special_tokens=SCREAMING_SNAKE_CASE__     )
             a_					:		List[Any]							=  tokenizer.encode('どういたしまして。'     ,							add_special_tokens=SCREAMING_SNAKE_CASE__     )

             a_					:		Union[str, Any]							=  tokenizer.build_inputs_with_special_tokens(SCREAMING_SNAKE_CASE__     )
             a_					:		Union[str, Any]							=  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  SCREAMING_SNAKE_CASE__  (				unittest.TestCase			):
      def        SCREAMING_SNAKE_CASE							(       self				:       str     )		->			List[str]:
             a_					:		int							=  'cl-tohoku/bert-base-japanese'
             a_					:		Optional[Any]							=  AutoTokenizer.from_pretrained(SCREAMING_SNAKE_CASE__     )
             self.assertIsInstance(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     )
class  SCREAMING_SNAKE_CASE__  (				unittest.TestCase			):
      def        SCREAMING_SNAKE_CASE							(       self				:       str     )		->			Optional[Any]:
             a_					:		List[str]							=  '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_					:		Tuple							=  '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.'     )     )






"""simple docstring"""







import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
		import torch

		from transformers.generation import DisjunctiveConstraint




@require_torch
class  UpperCamelCase_	( unittest.TestCase):

	"""simple docstring"""





	def   UpperCAmelCase_      ( self			:				Optional[int]   )       ->	List[str]:
						# For consistency across different places the DisjunctiveConstraint is called,
						# dc.token_ids is a list of integers. It is also initialized only by integers.

						__SCREAMING_SNAKE_CASE						   =				[[1, 2, 4], [1, 2, 3, 4]]
						__SCREAMING_SNAKE_CASE						   =				DisjunctiveConstraint(UpperCAmelCase__   )
						self.assertTrue(isinstance(dc.token_ids			,			UpperCAmelCase__   )   )

						with self.assertRaises(UpperCAmelCase__   ):
											DisjunctiveConstraint(torch.LongTensor([[1, 2, 4], [1, 2, 3]]   )   )

						with self.assertRaises(UpperCAmelCase__   ):
											DisjunctiveConstraint([torch.LongTensor([1, 2, 4]   ), torch.LongTensor([1, 2, 3, 4, 5]   )]   )




	def   UpperCAmelCase_      ( self			:				Any   )       ->	int:
						# We can't have constraints that are complete subsets of another. This leads to a preverse
						# interpretation of "constraint fulfillment": does generating [1,2,3] fulfill the constraint?
						# It would mean that it generated [1,2] which fulfills it, but it's in the middle of potentially
						# fulfilling [1,2,3,4]. If we believe that [1,2,3] does fulfill the constraint, then the algorithm
						# will necessarily never reach [1,2,3,4], giving users a false sense of control (better to just not allow it).
						__SCREAMING_SNAKE_CASE						   =				[[1, 2], [1, 2, 3, 4]]

						with self.assertRaises(UpperCAmelCase__   ):
											DisjunctiveConstraint(UpperCAmelCase__   )  # fails here




	def   UpperCAmelCase_      ( self			:				List[Any]   )       ->	Any:
						__SCREAMING_SNAKE_CASE						   =				[[1, 2, 3], [1, 2, 4]]

						__SCREAMING_SNAKE_CASE						   =				DisjunctiveConstraint(UpperCAmelCase__   )

						__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				dc.update(1   )
						__SCREAMING_SNAKE_CASE						   =				stepped is True and completed is False and reset is False
						self.assertTrue(UpperCAmelCase__   )
						self.assertTrue(not dc.completed   )
						self.assertTrue(dc.current_seq == [1]   )

						__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				dc.update(2   )
						__SCREAMING_SNAKE_CASE						   =				stepped is True and completed is False and reset is False
						self.assertTrue(UpperCAmelCase__   )
						self.assertTrue(not dc.completed   )
						self.assertTrue(dc.current_seq == [1, 2]   )

						__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				dc.update(3   )
						__SCREAMING_SNAKE_CASE						   =				stepped is True and completed is True and reset is False
						self.assertTrue(UpperCAmelCase__   )
						self.assertTrue(dc.completed   )  # Completed!
						self.assertTrue(dc.current_seq == [1, 2, 3]   )




	def   UpperCAmelCase_      ( self			:				str   )       ->	List[str]:
						__SCREAMING_SNAKE_CASE						   =				[[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

						__SCREAMING_SNAKE_CASE						   =				DisjunctiveConstraint(UpperCAmelCase__   )

						__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				dc.update(1   )
						self.assertTrue(not dc.completed   )
						self.assertTrue(dc.current_seq == [1]   )

						__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				dc.update(2   )
						self.assertTrue(not dc.completed   )
						self.assertTrue(dc.current_seq == [1, 2]   )

						__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				dc.update(4   )
						self.assertTrue(not dc.completed   )
						self.assertTrue(dc.current_seq == [1, 2, 4]   )

						__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				dc.update(5   )
						self.assertTrue(dc.completed   )  # Completed!
						self.assertTrue(dc.current_seq == [1, 2, 4, 5]   )

						dc.reset()

						__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				dc.update(1   )
						self.assertTrue(not dc.completed   )
						self.assertTrue(dc.remaining() == 3   )
						self.assertTrue(dc.current_seq == [1]   )

						__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				dc.update(2   )
						self.assertTrue(not dc.completed   )
						self.assertTrue(dc.remaining() == 2   )
						self.assertTrue(dc.current_seq == [1, 2]   )

						__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				dc.update(5   )
						self.assertTrue(dc.completed   )  # Completed!
						self.assertTrue(dc.remaining() == 0   )
						self.assertTrue(dc.current_seq == [1, 2, 5]   )
