




import warnings
from typing import Dict

import numpy as np

from ..utils import ExplicitEnum, add_end_docstrings, is_tf_available, is_torch_available
from .base import PIPELINE_INIT_ARGS, GenericTensor, Pipeline


if is_tf_available():
		from ..models.auto.modeling_tf_auto import TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING

if is_torch_available():
		from ..models.auto.modeling_auto import MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING



def       UpperCAmelCase       (     _snake_case							):
							return 1.0 / (1.0 + np.exp(-_outputs							))



def       UpperCAmelCase       (     _snake_case							):
							lowerCAmelCase   =		np.max(_outputs						, axis=-1						, keepdims=_snake_case							)
							lowerCAmelCase   =		np.exp(_outputs - maxes							)
							return shifted_exp / shifted_exp.sum(axis=-1						, keepdims=_snake_case							)


class 							__UpperCamelCase			( __UpperCAmelCase  ):





				'''simple docstring'''



				__a							: Optional[int]										="""sigmoid"""
				__a							: List[Any]										="""softmax"""
				__a							: Dict										="""none"""




@add_end_docstrings(
    __UpperCAmelCase     ,					r"""
        return_all_scores (`bool`, *optional*, defaults to `False`):
            Whether to return all prediction scores or just the one of the predicted class.
        function_to_apply (`str`, *optional*, defaults to `\"default\"`):
            The function to apply to the model outputs in order to retrieve the scores. Accepts four different values:

            - `\"default\"`: if the model has a single label, will apply the sigmoid function on the output. If the model
              has several labels, will apply the softmax function on the output.
            - `\"sigmoid\"`: Applies the sigmoid function on the output.
            - `\"softmax\"`: Applies the softmax function on the output.
            - `\"none\"`: Does not apply any function on the output.
    """     ,					)
class 							__UpperCamelCase			( __UpperCAmelCase  ):





				'''simple docstring'''



				__a							: Optional[Any]										=False
				__a							: Any										=ClassificationFunction.NONE



				def __init__( self       , **UpperCAmelCase_						):
											super().__init__(**UpperCAmelCase_						)

											self.check_model_type(
											    TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING
											    if self.framework == '''tf'''
											    else MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING						)



				def       __snake_case		( self       , UpperCAmelCase_=None       , UpperCAmelCase_=None       , UpperCAmelCase_=""       , **UpperCAmelCase_						):
											# Using "" as default argument because we're going to use `top_k=None` in user code to declare
											# "No top_k"
											lowerCAmelCase   =		tokenizer_kwargs

											lowerCAmelCase   =		{}
											if hasattr(self.model.config       , '''return_all_scores'''						) and return_all_scores is None:
																		lowerCAmelCase   =		self.model.config.return_all_scores

											if isinstance(UpperCAmelCase_       , UpperCAmelCase_						) or top_k is None:
																		lowerCAmelCase   =		top_k
																		lowerCAmelCase   =		False
											elif return_all_scores is not None:
																		warnings.warn(
																		    '''`return_all_scores` is now deprecated,  if want a similar functionality use `top_k=None` instead of'''
																		    ''' `return_all_scores=True` or `top_k=1` instead of `return_all_scores=False`.'''       , UpperCAmelCase_       , )
																		if return_all_scores:
																									lowerCAmelCase   =		None
																		else:
																									lowerCAmelCase   =		1

											if isinstance(UpperCAmelCase_       , UpperCAmelCase_						):
																		lowerCAmelCase   =		ClassificationFunction[function_to_apply.upper()]

											if function_to_apply is not None:
																		lowerCAmelCase   =		function_to_apply
											return preprocess_params, {}, postprocess_params



				def __call__( self       , *UpperCAmelCase_       , **UpperCAmelCase_						):
											lowerCAmelCase   =		super().__call__(*UpperCAmelCase_       , **UpperCAmelCase_						)
											# TODO try and retrieve it in a nicer way from _sanitize_parameters.
											lowerCAmelCase   =		'''top_k''' not in kwargs
											if isinstance(args[0]       , UpperCAmelCase_						) and _legacy:
																		# This pipeline is odd, and return a list when single item is run
																		return [result]
											else:
																		return result



				def       __snake_case		( self       , UpperCAmelCase_       , **UpperCAmelCase_						):
											lowerCAmelCase   =		self.framework
											if isinstance(UpperCAmelCase_       , UpperCAmelCase_						):
																		return self.tokenizer(**UpperCAmelCase_       , return_tensors=UpperCAmelCase_       , **UpperCAmelCase_						)
											elif isinstance(UpperCAmelCase_       , UpperCAmelCase_						) and len(UpperCAmelCase_						) == 1 and isinstance(inputs[0]       , UpperCAmelCase_						) and len(inputs[0]						) == 2:
																		# It used to be valid to use a list of list of list for text pairs, keeping this path for BC
																		return self.tokenizer(
																		    text=inputs[0][0]       , text_pair=inputs[0][1]       , return_tensors=UpperCAmelCase_       , **UpperCAmelCase_						)
											elif isinstance(UpperCAmelCase_       , UpperCAmelCase_						):
																		# This is likely an invalid usage of the pipeline attempting to pass text pairs.
																		raise ValueError(
																		    '''The pipeline received invalid inputs, if you are trying to send text pairs, you can try to send a'''
																		    ''' dictionary `{"text": "My text", "text_pair": "My pair"}` in order to send a text pair.'''						)
											return self.tokenizer(UpperCAmelCase_       , return_tensors=UpperCAmelCase_       , **UpperCAmelCase_						)



				def       __snake_case		( self       , UpperCAmelCase_						):
											return self.model(**UpperCAmelCase_						)






				def       __snake_case		( self       , UpperCAmelCase_       , UpperCAmelCase_=None       , UpperCAmelCase_=1       , UpperCAmelCase_=True						):
											# `_legacy` is used to determine if we're running the naked pipeline and in backward
											# compatibility mode, or if running the pipeline with `pipeline(..., top_k=1)` we're running
											# the more natural result containing the list.
											# Default value before `set_parameters`
											if function_to_apply is None:
																		if self.model.config.problem_type == "multi_label_classification" or self.model.config.num_labels == 1:
																									lowerCAmelCase   =		ClassificationFunction.SIGMOID
																		elif self.model.config.problem_type == "single_label_classification" or self.model.config.num_labels > 1:
																									lowerCAmelCase   =		ClassificationFunction.SOFTMAX
																		elif hasattr(self.model.config       , '''function_to_apply'''						) and function_to_apply is None:
																									lowerCAmelCase   =		self.model.config.function_to_apply
																		else:
																									lowerCAmelCase   =		ClassificationFunction.NONE

											lowerCAmelCase   =		model_outputs['''logits'''][0]
											lowerCAmelCase   =		outputs.numpy()

											if function_to_apply == ClassificationFunction.SIGMOID:
																		lowerCAmelCase   =		sigmoid(UpperCAmelCase_						)
											elif function_to_apply == ClassificationFunction.SOFTMAX:
																		lowerCAmelCase   =		softmax(UpperCAmelCase_						)
											elif function_to_apply == ClassificationFunction.NONE:
																		lowerCAmelCase   =		outputs
											else:
																		raise ValueError(F"""Unrecognized `function_to_apply` argument: {function_to_apply}"""						)

											if top_k == 1 and _legacy:
																		return {"label": self.model.config.idalabel[scores.argmax().item()], "score": scores.max().item()}

											lowerCAmelCase   =		[
											    {'''label''': self.model.config.idalabel[i], '''score''': score.item()} for i, score in enumerate(UpperCAmelCase_						)
											]
											if not _legacy:
																		dict_scores.sort(key=lambda UpperCAmelCase_						: x["score"]       , reverse=UpperCAmelCase_						)
																		if top_k is not None:
																									lowerCAmelCase   =		dict_scores[:top_k]
											return dict_scores









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 							__UpperCamelCase			( __UpperCAmelCase     ,					unittest.TestCase  ):





				'''simple docstring'''



				__a							: Any										=BertJapaneseTokenizer
				__a							: Optional[int]										=False
				__a							: int										=True



				def       __snake_case		( self						):
											super().setUp()

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

											lowerCAmelCase   =		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       __snake_case		( self       , UpperCAmelCase_						):
											lowerCAmelCase   =		'''こんにちは、世界。 \nこんばんは、世界。'''
											lowerCAmelCase   =		'''こんにちは 、 世界 。 こんばんは 、 世界 。'''
											return input_text, output_text



				def       __snake_case		( self       , UpperCAmelCase_						):
											lowerCAmelCase   ,     lowerCAmelCase   =		self.get_input_output_texts(UpperCAmelCase_						)
											lowerCAmelCase   =		tokenizer.encode(UpperCAmelCase_       , add_special_tokens=UpperCAmelCase_						)
											lowerCAmelCase   =		tokenizer.decode(UpperCAmelCase_       , clean_up_tokenization_spaces=UpperCAmelCase_						)
											return text, ids



				def       __snake_case		( self						):
											pass  # TODO add if relevant



				def       __snake_case		( self						):
											pass  # TODO add if relevant



				def       __snake_case		( self						):
											pass  # TODO add if relevant



				def       __snake_case		( self						):
											lowerCAmelCase   =		self.tokenizer_class(self.vocab_file						)

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



				def       __snake_case		( self						):
											lowerCAmelCase   =		self.tokenizer_class(self.vocab_file       , word_tokenizer_type='''mecab'''						)
											self.assertIsNotNone(UpperCAmelCase_						)

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

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

											with open(UpperCAmelCase_       , '''rb'''						) as handle:
																		lowerCAmelCase   =		pickle.load(UpperCAmelCase_						)

											lowerCAmelCase   =		tokenizer_new.tokenize(UpperCAmelCase_						)

											self.assertListEqual(UpperCAmelCase_       , UpperCAmelCase_						)



				def       __snake_case		( self						):
											lowerCAmelCase   =		MecabTokenizer(mecab_dic='''ipadic'''						)

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



				def       __snake_case		( self						):
											try:
																		lowerCAmelCase   =		MecabTokenizer(mecab_dic='''unidic_lite'''						)
											except ModuleNotFoundError:
																		return

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



				def       __snake_case		( self						):
											try:
																		lowerCAmelCase   =		MecabTokenizer(mecab_dic='''unidic'''						)
											except ModuleNotFoundError:
																		return

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



				def       __snake_case		( self						):
											lowerCAmelCase   =		MecabTokenizer(do_lower_case=UpperCAmelCase_       , mecab_dic='''ipadic'''						)

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



				def       __snake_case		( self						):
											try:
																		lowerCAmelCase   =		MecabTokenizer(
																		    do_lower_case=UpperCAmelCase_       , normalize_text=UpperCAmelCase_       , 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       __snake_case		( self						):
											lowerCAmelCase   =		MecabTokenizer(normalize_text=UpperCAmelCase_       , mecab_dic='''ipadic'''						)

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



				@require_sudachi
				def       __snake_case		( self						):
											lowerCAmelCase   =		self.tokenizer_class(self.vocab_file       , word_tokenizer_type='''sudachi'''						)
											self.assertIsNotNone(UpperCAmelCase_						)

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

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

											with open(UpperCAmelCase_       , '''rb'''						) as handle:
																		lowerCAmelCase   =		pickle.load(UpperCAmelCase_						)

											lowerCAmelCase   =		tokenizer_new.tokenize(UpperCAmelCase_						)

											self.assertListEqual(UpperCAmelCase_       , UpperCAmelCase_						)



				@require_sudachi
				def       __snake_case		( self						):
											lowerCAmelCase   =		SudachiTokenizer(sudachi_dict_type='''core'''						)

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



				@require_sudachi
				def       __snake_case		( self						):
											lowerCAmelCase   =		SudachiTokenizer(sudachi_dict_type='''core'''       , sudachi_split_mode='''A'''						)

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



				@require_sudachi
				def       __snake_case		( self						):
											lowerCAmelCase   =		SudachiTokenizer(sudachi_dict_type='''core'''       , sudachi_split_mode='''B'''						)

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



				@require_sudachi
				def       __snake_case		( self						):
											lowerCAmelCase   =		SudachiTokenizer(sudachi_dict_type='''core'''       , sudachi_split_mode='''C'''						)

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



				@require_sudachi
				def       __snake_case		( self						):
											lowerCAmelCase   =		SudachiTokenizer(do_lower_case=UpperCAmelCase_       , sudachi_dict_type='''core'''						)

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



				@require_sudachi
				def       __snake_case		( self						):
											lowerCAmelCase   =		SudachiTokenizer(normalize_text=UpperCAmelCase_       , sudachi_dict_type='''core'''						)

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



				@require_sudachi
				def       __snake_case		( self						):
											lowerCAmelCase   =		SudachiTokenizer(trim_whitespace=UpperCAmelCase_       , sudachi_dict_type='''core'''						)

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



				@require_jumanpp
				def       __snake_case		( self						):
											lowerCAmelCase   =		self.tokenizer_class(self.vocab_file       , word_tokenizer_type='''jumanpp'''						)
											self.assertIsNotNone(UpperCAmelCase_						)

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

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

											with open(UpperCAmelCase_       , '''rb'''						) as handle:
																		lowerCAmelCase   =		pickle.load(UpperCAmelCase_						)

											lowerCAmelCase   =		tokenizer_new.tokenize(UpperCAmelCase_						)

											self.assertListEqual(UpperCAmelCase_       , UpperCAmelCase_						)



				@require_jumanpp
				def       __snake_case		( self						):
											lowerCAmelCase   =		JumanppTokenizer()

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



				@require_jumanpp
				def       __snake_case		( self						):
											lowerCAmelCase   =		JumanppTokenizer(do_lower_case=UpperCAmelCase_						)

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



				@require_jumanpp
				def       __snake_case		( self						):
											lowerCAmelCase   =		JumanppTokenizer(normalize_text=UpperCAmelCase_						)

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



				@require_jumanpp
				def       __snake_case		( self						):
											lowerCAmelCase   =		JumanppTokenizer(trim_whitespace=UpperCAmelCase_						)

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



				@require_jumanpp
				def       __snake_case		( self						):
											lowerCAmelCase   =		JumanppTokenizer()

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



				def       __snake_case		( self						):
											lowerCAmelCase   =		['''[UNK]''', '''[CLS]''', '''[SEP]''', '''こんにちは''', '''こん''', '''にちは''', '''ばんは''', '''##こん''', '''##にちは''', '''##ばんは''']

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

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

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

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

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



				def       __snake_case		( self						):
											lowerCAmelCase   =		BertJapaneseTokenizer.from_pretrained('''nlp-waseda/roberta-base-japanese-with-auto-jumanpp'''						)
											lowerCAmelCase   =		tokenizer.subword_tokenizer

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

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






				def       __snake_case		( self						):
											lowerCAmelCase   =		self.tokenizer_class.from_pretrained('''cl-tohoku/bert-base-japanese'''						)

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

											lowerCAmelCase   =		tokenizer.build_inputs_with_special_tokens(UpperCAmelCase_						)
											lowerCAmelCase   =		tokenizer.build_inputs_with_special_tokens(UpperCAmelCase_       , UpperCAmelCase_						)

											# 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 							__UpperCamelCase			( __UpperCAmelCase     ,					unittest.TestCase  ):





				'''simple docstring'''



				__a							: Union[str, Any]										=BertJapaneseTokenizer
				__a							: Optional[int]										=False



				def       __snake_case		( self						):
											super().setUp()

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

											lowerCAmelCase   =		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       __snake_case		( self       , **UpperCAmelCase_						):
											return BertJapaneseTokenizer.from_pretrained(self.tmpdirname       , subword_tokenizer_type='''character'''       , **UpperCAmelCase_						)



				def       __snake_case		( self       , UpperCAmelCase_						):
											lowerCAmelCase   =		'''こんにちは、世界。 \nこんばんは、世界。'''
											lowerCAmelCase   =		'''こ ん に ち は 、 世 界 。 こ ん ば ん は 、 世 界 。'''
											return input_text, output_text



				def       __snake_case		( self						):
											pass  # TODO add if relevant



				def       __snake_case		( self						):
											pass  # TODO add if relevant



				def       __snake_case		( self						):
											pass  # TODO add if relevant



				def       __snake_case		( self						):
											lowerCAmelCase   =		self.tokenizer_class(self.vocab_file       , subword_tokenizer_type='''character'''						)

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



				def       __snake_case		( self						):
											lowerCAmelCase   =		['''[UNK]''', '''[CLS]''', '''[SEP]''', '''こ''', '''ん''', '''に''', '''ち''', '''は''', '''ば''', '''世''', '''界''', '''、''', '''。''']

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

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

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

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






				def       __snake_case		( self						):
											lowerCAmelCase   =		self.tokenizer_class.from_pretrained('''cl-tohoku/bert-base-japanese-char'''						)

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

											lowerCAmelCase   =		tokenizer.build_inputs_with_special_tokens(UpperCAmelCase_						)
											lowerCAmelCase   =		tokenizer.build_inputs_with_special_tokens(UpperCAmelCase_       , UpperCAmelCase_						)

											# 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 							__UpperCamelCase			( unittest.TestCase  ):





				'''simple docstring'''



				def       __snake_case		( self						):
											lowerCAmelCase   =		'''cl-tohoku/bert-base-japanese'''
											lowerCAmelCase   =		AutoTokenizer.from_pretrained(UpperCAmelCase_						)
											self.assertIsInstance(UpperCAmelCase_       , UpperCAmelCase_						)




class 							__UpperCamelCase			( unittest.TestCase  ):





				'''simple docstring'''



				def       __snake_case		( self						):
											lowerCAmelCase   =		'''cl-tohoku/bert-base-japanese'''
											with self.assertLogs('''transformers'''       , level='''WARNING'''						) as cm:
																		BertTokenizer.from_pretrained(UpperCAmelCase_						)
																		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.'''						)						)
											lowerCAmelCase   =		'''bert-base-cased'''
											with self.assertLogs('''transformers'''       , level='''WARNING'''						) as cm:
																		BertJapaneseTokenizer.from_pretrained(UpperCAmelCase_						)
																		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.'''						)						)



