
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        snake_case__    (A__ ,     unittest.TestCase		):







						"""simple docstring"""




						__lowerCAmelCase					:Any      =					BertJapaneseTokenizer
						__lowerCAmelCase					:List[Any]      =					False
						__lowerCAmelCase					:Dict      =					True

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Optional[Any]:
									"""simple docstring"""




									super().setUp()

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

									a__       :						Any							=  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 ,       __lowercase  ) ->				Any:
									"""simple docstring"""




									a__       :						Dict							=  """こんにちは、世界。 \nこんばんは、世界。"""
									a__       :						List[Any]							=  """こんにちは 、 世界 。 こんばんは 、 世界 。"""
									return input_text, output_text

						def 							SCREAMING_SNAKE_CASE__(       self ,       __lowercase  ) ->				Tuple:
									"""simple docstring"""




									a__       :						int							=  self.get_input_output_texts(__lowercase  )
									a__       :						str							=  tokenizer.encode(__lowercase ,       add_special_tokens=__lowercase  )
									a__       :						Tuple							=  tokenizer.decode(__lowercase ,       clean_up_tokenization_spaces=__lowercase  )
									return text, ids

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Optional[Any]:
									"""simple docstring"""




									pass  # TODO add if relevant

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Optional[int]:
									"""simple docstring"""




									pass  # TODO add if relevant

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				str:
									"""simple docstring"""




									pass  # TODO add if relevant

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				List[Any]:
									"""simple docstring"""




									a__       :						Union[str, Any]							=  self.tokenizer_class(self.vocab_file  )

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

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Optional[int]:
									"""simple docstring"""




									a__       :						Any							=  self.tokenizer_class(self.vocab_file ,       word_tokenizer_type="""mecab"""  )
									self.assertIsNotNone(__lowercase  )

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

									a__       :						Dict							=  os.path.join(self.tmpdirname ,       """tokenizer.bin"""  )
									with open(__lowercase ,       """wb"""  ) as handle:
												pickle.dump(__lowercase ,       __lowercase  )

									with open(__lowercase ,       """rb"""  ) as handle:
												a__       :						Optional[Any]							=  pickle.load(__lowercase  )

									a__       :						Union[str, Any]							=  tokenizer_new.tokenize(__lowercase  )

									self.assertListEqual(__lowercase ,       __lowercase  )

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Tuple:
									"""simple docstring"""




									a__       :						Dict							=  MecabTokenizer(mecab_dic="""ipadic"""  )

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

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Optional[int]:
									"""simple docstring"""




									try:
												a__       :						List[Any]							=  MecabTokenizer(mecab_dic="""unidic_lite"""  )
									except ModuleNotFoundError:
												return

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

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				List[str]:
									"""simple docstring"""




									try:
												a__       :						Tuple							=  MecabTokenizer(mecab_dic="""unidic"""  )
									except ModuleNotFoundError:
												return

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

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				List[Any]:
									"""simple docstring"""




									a__       :						List[Any]							=  MecabTokenizer(do_lower_case=__lowercase ,       mecab_dic="""ipadic"""  )

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

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Union[str, Any]:
									"""simple docstring"""




									try:
												a__       :						Union[str, Any]							=  MecabTokenizer(
												    do_lower_case=__lowercase ,       normalize_text=__lowercase ,       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  ) ->				Dict:
									"""simple docstring"""




									a__       :						List[Any]							=  MecabTokenizer(normalize_text=__lowercase ,       mecab_dic="""ipadic"""  )

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

						@require_sudachi
						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Any:
									"""simple docstring"""




									a__       :						str							=  self.tokenizer_class(self.vocab_file ,       word_tokenizer_type="""sudachi"""  )
									self.assertIsNotNone(__lowercase  )

									a__       :						Tuple							=  """こんにちは、世界。\nこんばんは、世界。"""
									a__       :						Tuple							=  tokenizer.tokenize(__lowercase  )
									self.assertListEqual(__lowercase ,       ["""こんにちは""", """、""", """世界""", """。""", """こん""", """##ばんは""", """、""", """世界""", """。"""]  )
									self.assertListEqual(tokenizer.convert_tokens_to_ids(__lowercase  ) ,       [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(__lowercase ,       """wb"""  ) as handle:
												pickle.dump(__lowercase ,       __lowercase  )

									with open(__lowercase ,       """rb"""  ) as handle:
												a__       :						Dict							=  pickle.load(__lowercase  )

									a__       :						str							=  tokenizer_new.tokenize(__lowercase  )

									self.assertListEqual(__lowercase ,       __lowercase  )

						@require_sudachi
						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				int:
									"""simple docstring"""




									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  ) ->				List[str]:
									"""simple docstring"""




									a__       :						Optional[int]							=  SudachiTokenizer(sudachi_dict_type="""core""" ,       sudachi_split_mode="""A"""  )

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

						@require_sudachi
						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				List[str]:
									"""simple docstring"""




									a__       :						Union[str, Any]							=  SudachiTokenizer(sudachi_dict_type="""core""" ,       sudachi_split_mode="""B"""  )

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

						@require_sudachi
						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Any:
									"""simple docstring"""




									a__       :						Any							=  SudachiTokenizer(sudachi_dict_type="""core""" ,       sudachi_split_mode="""C"""  )

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

						@require_sudachi
						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				List[str]:
									"""simple docstring"""




									a__       :						str							=  SudachiTokenizer(do_lower_case=__lowercase ,       sudachi_dict_type="""core"""  )

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

						@require_sudachi
						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Dict:
									"""simple docstring"""




									a__       :						Optional[int]							=  SudachiTokenizer(normalize_text=__lowercase ,       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__       :						Tuple							=  SudachiTokenizer(trim_whitespace=__lowercase ,       sudachi_dict_type="""core"""  )

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

						@require_jumanpp
						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				str:
									"""simple docstring"""




									a__       :						Optional[int]							=  self.tokenizer_class(self.vocab_file ,       word_tokenizer_type="""jumanpp"""  )
									self.assertIsNotNone(__lowercase  )

									a__       :						Dict							=  """こんにちは、世界。\nこんばんは、世界。"""
									a__       :						Optional[int]							=  tokenizer.tokenize(__lowercase  )
									self.assertListEqual(__lowercase ,       ["""こんにちは""", """、""", """世界""", """。""", """こん""", """##ばんは""", """、""", """世界""", """。"""]  )
									self.assertListEqual(tokenizer.convert_tokens_to_ids(__lowercase  ) ,       [3, 1_2, 1_0, 1_4, 4, 9, 1_2, 1_0, 1_4]  )

									a__       :						str							=  os.path.join(self.tmpdirname ,       """tokenizer.bin"""  )
									with open(__lowercase ,       """wb"""  ) as handle:
												pickle.dump(__lowercase ,       __lowercase  )

									with open(__lowercase ,       """rb"""  ) as handle:
												a__       :						Optional[int]							=  pickle.load(__lowercase  )

									a__       :						Optional[int]							=  tokenizer_new.tokenize(__lowercase  )

									self.assertListEqual(__lowercase ,       __lowercase  )

						@require_jumanpp
						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				str:
									"""simple docstring"""




									a__       :						int							=  JumanppTokenizer()

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

						@require_jumanpp
						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				int:
									"""simple docstring"""




									a__       :						List[Any]							=  JumanppTokenizer(do_lower_case=__lowercase  )

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

						@require_jumanpp
						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				List[str]:
									"""simple docstring"""




									a__       :						Optional[Any]							=  JumanppTokenizer(normalize_text=__lowercase  )

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

						@require_jumanpp
						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				List[str]:
									"""simple docstring"""




									a__       :						List[str]							=  JumanppTokenizer(trim_whitespace=__lowercase  )

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

						@require_jumanpp
						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Optional[int]:
									"""simple docstring"""




									a__       :						Any							=  JumanppTokenizer()

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

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Union[str, Any]:
									"""simple docstring"""




									a__       :						List[str]							=  ["""[UNK]""", """[CLS]""", """[SEP]""", """こんにちは""", """こん""", """にちは""", """ばんは""", """##こん""", """##にちは""", """##ばんは"""]

									a__       :						str							=  {}
									for i, token in enumerate(__lowercase  ):
												a__       :						Optional[Any]							=  i
									a__       :						List[Any]							=  WordpieceTokenizer(vocab=__lowercase ,       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[Any]:
									"""simple docstring"""




									a__       :						List[Any]							=  BertJapaneseTokenizer.from_pretrained("""nlp-waseda/roberta-base-japanese-with-auto-jumanpp"""  )
									a__       :						Any							=  tokenizer.subword_tokenizer

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

									a__       :						Union[str, Any]							=  subword_tokenizer.tokenize("""こんばんは こんばん にち は こんにちは"""  )
									self.assertListEqual(__lowercase ,       ["""▁こん""", """ばん""", """は""", """▁こん""", """ばん""", """▁に""", """ち""", """▁は""", """▁こんにちは"""]  )

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Optional[int]:
									"""simple docstring"""




									a__       :						Any							=  self.tokenizer_class.from_pretrained("""cl-tohoku/bert-base-japanese"""  )

									a__       :						Optional[int]							=  tokenizer.encode("""ありがとう。""" ,       add_special_tokens=__lowercase  )
									a__       :						Dict							=  tokenizer.encode("""どういたしまして。""" ,       add_special_tokens=__lowercase  )

									a__       :						Tuple							=  tokenizer.build_inputs_with_special_tokens(__lowercase  )
									a__       :						Union[str, Any]							=  tokenizer.build_inputs_with_special_tokens(__lowercase ,       __lowercase  )

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







						"""simple docstring"""




						__lowerCAmelCase					:List[Any]      =					BertJapaneseTokenizer
						__lowerCAmelCase					:List[Any]      =					False

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Union[str, Any]:
									"""simple docstring"""




									super().setUp()

									a__       :						Dict							=  ["""[UNK]""", """[CLS]""", """[SEP]""", """こ""", """ん""", """に""", """ち""", """は""", """ば""", """世""", """界""", """、""", """。"""]

									a__       :						int							=  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 ,       **__lowercase  ) ->				Tuple:
									"""simple docstring"""




									return BertJapaneseTokenizer.from_pretrained(self.tmpdirname ,       subword_tokenizer_type="""character""" ,       **__lowercase  )

						def 							SCREAMING_SNAKE_CASE__(       self ,       __lowercase  ) ->				Any:
									"""simple docstring"""




									a__       :						str							=  """こんにちは、世界。 \nこんばんは、世界。"""
									a__       :						Optional[Any]							=  """こ ん に ち は 、 世 界 。 こ ん ば ん は 、 世 界 。"""
									return input_text, output_text

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Any:
									"""simple docstring"""




									pass  # TODO add if relevant

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Any:
									"""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  ) ->				int:
									"""simple docstring"""




									a__       :						Optional[int]							=  self.tokenizer_class(self.vocab_file ,       subword_tokenizer_type="""character"""  )

									a__       :						Dict							=  tokenizer.tokenize("""こんにちは、世界。 \nこんばんは、世界。"""  )
									self.assertListEqual(
									    __lowercase ,       ["""こ""", """ん""", """に""", """ち""", """は""", """、""", """世""", """界""", """。""", """こ""", """ん""", """ば""", """ん""", """は""", """、""", """世""", """界""", """。"""]  )
									self.assertListEqual(
									    tokenizer.convert_tokens_to_ids(__lowercase  ) ,       [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  ) ->				Union[str, Any]:
									"""simple docstring"""




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

									a__       :						List[str]							=  {}
									for i, token in enumerate(__lowercase  ):
												a__       :						Optional[Any]							=  i
									a__       :						Dict							=  CharacterTokenizer(vocab=__lowercase ,       unk_token="""[UNK]"""  )

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

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

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

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				str:
									"""simple docstring"""




									a__       :						int							=  self.tokenizer_class.from_pretrained("""cl-tohoku/bert-base-japanese-char"""  )

									a__       :						Optional[int]							=  tokenizer.encode("""ありがとう。""" ,       add_special_tokens=__lowercase  )
									a__       :						List[str]							=  tokenizer.encode("""どういたしまして。""" ,       add_special_tokens=__lowercase  )

									a__       :						Optional[int]							=  tokenizer.build_inputs_with_special_tokens(__lowercase  )
									a__       :						List[str]							=  tokenizer.build_inputs_with_special_tokens(__lowercase ,       __lowercase  )

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







						"""simple docstring"""




						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Tuple:
									"""simple docstring"""




									a__       :						Tuple							=  """cl-tohoku/bert-base-japanese"""
									a__       :						int							=  AutoTokenizer.from_pretrained(__lowercase  )
									self.assertIsInstance(__lowercase ,       __lowercase  )




class        snake_case__    (unittest.TestCase		):







						"""simple docstring"""




						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Union[str, Any]:
									"""simple docstring"""




									a__       :						Any							=  """cl-tohoku/bert-base-japanese"""
									with self.assertLogs("""transformers""" ,       level="""WARNING"""  ) as cm:
												BertTokenizer.from_pretrained(__lowercase  )
												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__       :						int							=  """bert-base-cased"""
									with self.assertLogs("""transformers""" ,       level="""WARNING"""  ) as cm:
												BertJapaneseTokenizer.from_pretrained(__lowercase  )
												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."""  )  )









import sacrebleu as scb
from packaging import version
from sacrebleu import TER

import datasets


_lowercase		:				Any      		="\\n@inproceedings{snover-etal-2006-study,\n    title = \"A Study of Translation Edit Rate with Targeted Human Annotation\",\n    author = \"Snover, Matthew  and\n      Dorr, Bonnie  and\n      Schwartz, Rich  and\n      Micciulla, Linnea  and\n      Makhoul, John\",\n    booktitle = \"Proceedings of the 7th Conference of the Association for Machine Translation in the Americas: Technical Papers\",\n    month = aug # \" 8-12\",\n    year = \"2006\",\n    address = \"Cambridge, Massachusetts, USA\",\n    publisher = \"Association for Machine Translation in the Americas\",\n    url = \"https://aclanthology.org/2006.amta-papers.25\",\n    pages = \"223--231\",\n}\n@inproceedings{post-2018-call,\n    title = \"A Call for Clarity in Reporting {BLEU} Scores\",\n    author = \"Post, Matt\",\n    booktitle = \"Proceedings of the Third Conference on Machine Translation: Research Papers\",\n    month = oct,\n    year = \"2018\",\n    address = \"Belgium, Brussels\",\n    publisher = \"Association for Computational Linguistics\",\n    url = \"https://www.aclweb.org/anthology/W18-6319\",\n    pages = \"186--191\",\n}\n"

_lowercase		:				str      		="\\nTER (Translation Edit Rate, also called Translation Error Rate) is a metric to quantify the edit operations that a\nhypothesis requires to match a reference translation. We use the implementation that is already present in sacrebleu\n(https://github.com/mjpost/sacreBLEU#ter), which in turn is inspired by the TERCOM implementation, which can be found\nhere: https://github.com/jhclark/tercom.\n\nThe implementation here is slightly different from sacrebleu in terms of the required input format. The length of\nthe references and hypotheses lists need to be the same, so you may need to transpose your references compared to\nsacrebleu's required input format. See https://github.com/huggingface/datasets/issues/3154#issuecomment-950746534\n\nSee the README.md file at https://github.com/mjpost/sacreBLEU#ter for more information.\n"

_lowercase		:				Optional[Any]      		="\nProduces TER scores alongside the number of edits and reference length.\n\nArgs:\n    predictions (list of str): The system stream (a sequence of segments).\n    references (list of list of str): A list of one or more reference streams (each a sequence of segments).\n    normalized (boolean): If `True`, applies basic tokenization and normalization to sentences. Defaults to `False`.\n    ignore_punct (boolean): If `True`, applies basic tokenization and normalization to sentences. Defaults to `False`.\n    support_zh_ja_chars (boolean): If `True`, tokenization/normalization supports processing of Chinese characters,\n                                    as well as Japanese Kanji, Hiragana, Katakana, and Phonetic Extensions of Katakana.\n                                    Only applies if `normalized = True`. Defaults to `False`.\n    case_sensitive (boolean): If `False`, makes all predictions and references lowercase to ignore differences in case. Defaults to `False`.\n\nReturns:\n    'score' (float): TER score (num_edits / sum_ref_lengths * 100)\n    'num_edits' (int): The cumulative number of edits\n    'ref_length' (float): The cumulative average reference length\n\nExamples:\n    Example 1:\n        >>> predictions = [\"does this sentence match??\",\n        ...                     \"what about this sentence?\",\n        ...                     \"What did the TER metric user say to the developer?\"]\n        >>> references = [[\"does this sentence match\", \"does this sentence match!?!\"],\n        ...             [\"wHaT aBoUt ThIs SeNtEnCe?\", \"wHaT aBoUt ThIs SeNtEnCe?\"],\n        ...             [\"Your jokes are...\", \"...TERrible\"]]\n        >>> ter = datasets.load_metric(\"ter\")\n        >>> results = ter.compute(predictions=predictions,\n        ...                         references=references,\n        ...                         case_sensitive=True)\n        >>> print(results)\n        {'score': 150.0, 'num_edits': 15, 'ref_length': 10.0}\n\n    Example 2:\n        >>> predictions = [\"does this sentence match??\",\n        ...                     \"what about this sentence?\"]\n        >>> references = [[\"does this sentence match\", \"does this sentence match!?!\"],\n        ...             [\"wHaT aBoUt ThIs SeNtEnCe?\", \"wHaT aBoUt ThIs SeNtEnCe?\"]]\n        >>> ter = datasets.load_metric(\"ter\")\n        >>> results = ter.compute(predictions=predictions,\n        ...                         references=references,\n        ...                         case_sensitive=True)\n        >>> print(results)\n        {'score': 62.5, 'num_edits': 5, 'ref_length': 8.0}\n\n    Example 3:\n        >>> predictions = [\"does this sentence match??\",\n        ...                     \"what about this sentence?\"]\n        >>> references = [[\"does this sentence match\", \"does this sentence match!?!\"],\n        ...             [\"wHaT aBoUt ThIs SeNtEnCe?\", \"wHaT aBoUt ThIs SeNtEnCe?\"]]\n        >>> ter = datasets.load_metric(\"ter\")\n        >>> results = ter.compute(predictions=predictions,\n        ...                         references=references,\n        ...                         normalized=True,\n        ...                         case_sensitive=True)\n        >>> print(results)\n        {'score': 57.14285714285714, 'num_edits': 6, 'ref_length': 10.5}\n\n    Example 4:\n        >>> predictions = [\"does this sentence match??\",\n        ...                     \"what about this sentence?\"]\n        >>> references = [[\"does this sentence match\", \"does this sentence match!?!\"],\n        ...             [\"wHaT aBoUt ThIs SeNtEnCe?\", \"wHaT aBoUt ThIs SeNtEnCe?\"]]\n        >>> ter = datasets.load_metric(\"ter\")\n        >>> results = ter.compute(predictions=predictions,\n        ...                         references=references,\n        ...                         ignore_punct=True,\n        ...                         case_sensitive=False)\n        >>> print(results)\n        {'score': 0.0, 'num_edits': 0, 'ref_length': 8.0}\n\n    Example 5:\n        >>> predictions = [\"does this sentence match??\",\n        ...                    \"what about this sentence?\",\n        ...                    \"What did the TER metric user say to the developer?\"]\n        >>> references = [[\"does this sentence match\", \"does this sentence match!?!\"],\n        ...             [\"wHaT aBoUt ThIs SeNtEnCe?\", \"wHaT aBoUt ThIs SeNtEnCe?\"],\n        ...             [\"Your jokes are...\", \"...TERrible\"]]\n        >>> ter = datasets.load_metric(\"ter\")\n        >>> results = ter.compute(predictions=predictions,\n        ...                         references=references,\n        ...                         ignore_punct=True,\n        ...                         case_sensitive=False)\n        >>> print(results)\n        {'score': 100.0, 'num_edits': 10, 'ref_length': 10.0}\n"

@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION ,     _KWARGS_DESCRIPTION		)
class        snake_case__    (datasets.Metric		):







						"""simple docstring"""




						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Tuple:
									"""simple docstring"""




									if version.parse(scb.__version__  ) < version.parse("""1.4.12"""  ):
												raise ImportWarning(
												    """To use `sacrebleu`, the module `sacrebleu>=1.4.12` is required, and the current version of `sacrebleu` doesn't match this condition.\n"""
												    """You can install it with `pip install \"sacrebleu>=1.4.12\"`."""  )
									return datasets.MetricInfo(
									    description=_DESCRIPTION ,       citation=_CITATION ,       homepage="""http://www.cs.umd.edu/~snover/tercom/""" ,       inputs_description=_KWARGS_DESCRIPTION ,       features=datasets.Features(
									        {
									            """predictions""": datasets.Value("""string""" ,       id="""sequence"""  ),
									            """references""": datasets.Sequence(datasets.Value("""string""" ,       id="""sequence"""  ) ,       id="""references"""  ),
									        }  ) ,       codebase_urls=["""https://github.com/mjpost/sacreBLEU#ter"""] ,       reference_urls=[
									        """https://github.com/jhclark/tercom""",
									    ] ,       )

						def 							SCREAMING_SNAKE_CASE__(       self ,       __lowercase ,       __lowercase ,       __lowercase = False ,       __lowercase = False ,       __lowercase = False ,       __lowercase = False ,       ) ->				Any:
									"""simple docstring"""




									a__       :						Any							=  len(references[0]  )
									if any(len(__lowercase  ) != references_per_prediction for refs in references  ):
												raise ValueError("""Sacrebleu requires the same number of references for each prediction"""  )
									a__       :						str							=  [[refs[i] for refs in references] for i in range(__lowercase  )]

									a__       :						int							=  TER(
									    normalized=__lowercase ,       no_punct=__lowercase ,       asian_support=__lowercase ,       case_sensitive=__lowercase ,       )
									a__       :						Optional[int]							=  sb_ter.corpus_score(__lowercase ,       __lowercase  )

									return {"score": output.score, "num_edits": output.num_edits, "ref_length": output.ref_length}




