





import json
import os
import unittest

from transformers.models.gptsan_japanese.tokenization_gptsan_japanese import (
    VOCAB_FILES_NAMES,
    GPTSanJapaneseTokenizer,
)
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin



@require_tokenizers
class    _SCREAMING_SNAKE_CASE						(	__SCREAMING_SNAKE_CASE    ,							unittest.TestCase    ):







 '''simple docstring'''
 lowercase_		=			GPTSanJapaneseTokenizer
 lowercase_		=			False
 lowercase_		=			{"do_clean_text": False, "add_prefix_space": False}

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



   '''simple docstring'''



   super().setUp()

   # fmt: off
   lowerCamelCase__:      List[str]			  =["こん", "こんに", "にちは", "ばんは", "世界,㔺界", "、", "。", "<BR>", "<SP>", "<TAB>", "<URL>", "<EMAIL>", "<TEL>", "<DATE>", "<PRICE>", "<BLOCK>", "<KIGOU>", "<U2000U2BFF>", "<|emoji1|>", "<unk>", "<|bagoftoken|>", "<|endoftext|>"]
   # fmt: on
   lowerCamelCase__:      Dict			  ={"emoji": {"\ud83d\ude00": "<|emoji1|>"}, "emoji_inv": {"<|emoji1|>": "\ud83d\ude00"}}  # 😀
   lowerCamelCase__:      List[str]			  ={"unk_token": "<unk>"}

   lowerCamelCase__:      int			  =os.path.join(self.tmpdirname       , VOCAB_FILES_NAMES["vocab_file"])
   lowerCamelCase__:      str			  =os.path.join(self.tmpdirname       , VOCAB_FILES_NAMES["emoji_file"])
   with open(self.vocab_file       , "w"       , encoding="utf-8") as vocab_writer:
     vocab_writer.write("".join([x + "\n" for x in vocab_tokens]))
   with open(self.emoji_file       , "w") as emoji_writer:
     emoji_writer.write(json.dumps(UpperCAmelCase_))

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



   '''simple docstring'''



   kwargs.update(self.special_tokens_map)
   return GPTSanJapaneseTokenizer.from_pretrained(self.tmpdirname       , **UpperCAmelCase_)

 def 							SCREAMING_SNAKE_CASE_					(self				:   List[Any]       , UpperCAmelCase_				:   Optional[int])       ->Any:



   '''simple docstring'''



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

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



   '''simple docstring'''



   lowerCamelCase__  ,					lowerCamelCase__:      Optional[Any]			  =self.get_input_output_texts(UpperCAmelCase_)
   lowerCamelCase__:      Optional[int]			  =tokenizer.encode(UpperCAmelCase_       , add_special_tokens=UpperCAmelCase_)
   lowerCamelCase__:      Union[str, Any]			  =tokenizer.decode(UpperCAmelCase_       , clean_up_tokenization_spaces=UpperCAmelCase_)
   return text, ids

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



   '''simple docstring'''



   pass  # TODO add if relevant

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



   '''simple docstring'''



   pass  # TODO add if relevant

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



   '''simple docstring'''



   pass  # TODO add if relevant

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



   '''simple docstring'''



   lowerCamelCase__:      Optional[int]			  =self.get_tokenizer()

   # Testing tokenization
   lowerCamelCase__:      int			  ="こんにちは、世界。　こんばんは、㔺界。"
   lowerCamelCase__:      Optional[Any]			  =["こん", "にちは", "、", "世界", "。", "<SP>", "こん", "ばんは", "、", "㔺界", "。"]
   lowerCamelCase__:      Optional[Any]			  =tokenizer.tokenize(UpperCAmelCase_)
   self.assertListEqual(UpperCAmelCase_       , UpperCAmelCase_)

   # Testing conversion to ids without special tokens
   lowerCamelCase__:      Optional[Any]			  =[0, 2, 5, 4, 6, 8, 0, 3, 5, 4, 6]
   lowerCamelCase__:      Tuple			  =tokenizer.convert_tokens_to_ids(UpperCAmelCase_)
   self.assertListEqual(UpperCAmelCase_       , UpperCAmelCase_)

   # Testing conversion to ids with special tokens
   lowerCamelCase__:      Union[str, Any]			  =tokens + [tokenizer.unk_token]
   lowerCamelCase__:      Optional[int]			  =[0, 2, 5, 4, 6, 8, 0, 3, 5, 4, 6, 19]
   lowerCamelCase__:      Tuple			  =tokenizer.convert_tokens_to_ids(UpperCAmelCase_)
   self.assertListEqual(UpperCAmelCase_       , UpperCAmelCase_)

 def 							SCREAMING_SNAKE_CASE_					(self				:   int)       ->str:



   '''simple docstring'''



   lowerCamelCase__:      Optional[Any]			  =self.get_tokenizer()

   # Testing tokenization
   lowerCamelCase__:      List[Any]			  ="こんにちは、<|bagoftoken|>世界。こんばんは、<|bagoftoken|>㔺界。"
   lowerCamelCase__:      List[str]			  ="こんにちは、、、、世界。こんばんは、、、、世界。"
   lowerCamelCase__:      Union[str, Any]			  =tokenizer.encode(UpperCAmelCase_)
   lowerCamelCase__:      Dict			  =tokenizer.decode(UpperCAmelCase_)
   self.assertEqual(UpperCAmelCase_       , UpperCAmelCase_)

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



   '''simple docstring'''



   lowerCamelCase__:      Union[str, Any]			  =self.tokenizer_class.from_pretrained("Tanrei/GPTSAN-japanese")

   # Testing tokenization
   lowerCamelCase__:      Any			  ="こんにちは、世界。"
   lowerCamelCase__:      Tuple			  ="こんばんは、㔺界。😀"
   lowerCamelCase__:      List[str]			  ="こんにちは、世界。こんばんは、世界。😀"
   lowerCamelCase__:      Dict			  =tokenizer.encode(prefix_text + input_text)
   lowerCamelCase__:      List[Any]			  =tokenizer.encode(""       , prefix_text=prefix_text + input_text)
   lowerCamelCase__:      List[str]			  =tokenizer.encode(UpperCAmelCase_       , prefix_text=UpperCAmelCase_)
   lowerCamelCase__:      Tuple			  =tokenizer.decode(UpperCAmelCase_)
   lowerCamelCase__:      Tuple			  =tokenizer.decode(UpperCAmelCase_)
   lowerCamelCase__:      Any			  =tokenizer.decode(UpperCAmelCase_)
   self.assertEqual(UpperCAmelCase_       , UpperCAmelCase_)
   self.assertEqual(UpperCAmelCase_       , UpperCAmelCase_)
   self.assertEqual(UpperCAmelCase_       , UpperCAmelCase_)

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



   '''simple docstring'''



   lowerCamelCase__:      List[str]			  =self.tokenizer_class.from_pretrained("Tanrei/GPTSAN-japanese")

   # Testing tokenization
   lowerCamelCase__:      List[str]			  ="こんにちは、世界。"
   lowerCamelCase__:      Dict			  ="こんばんは、㔺界。😀"

   lowerCamelCase__:      List[str]			  =len(tokenizer.encode(UpperCAmelCase_)) - 2
   lowerCamelCase__:      int			  =len(tokenizer.encode(UpperCAmelCase_)) - 2

   lowerCamelCase__:      List[Any]			  =[1] + [0] * (len_prefix + len_text + 1)
   lowerCamelCase__:      int			  =[1] * (len_prefix + len_text + 1) + [0]
   lowerCamelCase__:      Union[str, Any]			  =[1] + [1] * (len_prefix) + [0] * (len_text + 1)

   lowerCamelCase__:      Optional[int]			  =tokenizer(prefix_text + input_text).token_type_ids
   lowerCamelCase__:      List[str]			  =tokenizer(""       , prefix_text=prefix_text + input_text).token_type_ids
   lowerCamelCase__:      List[Any]			  =tokenizer(UpperCAmelCase_       , prefix_text=UpperCAmelCase_).token_type_ids
   self.assertListEqual(UpperCAmelCase_       , UpperCAmelCase_)
   self.assertListEqual(UpperCAmelCase_       , UpperCAmelCase_)
   self.assertListEqual(UpperCAmelCase_       , UpperCAmelCase_)

 @slow
 def 							SCREAMING_SNAKE_CASE_					(self				:   Tuple)       ->Dict:



   '''simple docstring'''



   lowerCamelCase__:      List[Any]			  =self.tokenizer_class.from_pretrained("Tanrei/GPTSAN-japanese")

   lowerCamelCase__:      List[Any]			  =tokenizer.encode("あンいワ")
   lowerCamelCase__:      Optional[int]			  =tokenizer.encode(""       , prefix_text="あンいワ")
   lowerCamelCase__:      List[Any]			  =tokenizer.encode("いワ"       , prefix_text="あン")

   self.assertEqual(tokenizer.decode(UpperCAmelCase_)       , tokenizer.decode(UpperCAmelCase_))
   self.assertEqual(tokenizer.decode(UpperCAmelCase_)       , tokenizer.decode(UpperCAmelCase_))
   self.assertNotEqual(UpperCAmelCase_       , UpperCAmelCase_)
   self.assertNotEqual(UpperCAmelCase_       , UpperCAmelCase_)
   self.assertEqual(x_token_a[1]       , x_token_a[-1])  # SEG token
   self.assertEqual(x_token_a[1]       , x_token_a[3])  # SEG token

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



   '''simple docstring'''



   lowerCamelCase__:      Dict			  =self.tokenizer_class.from_pretrained("Tanrei/GPTSAN-japanese")

   lowerCamelCase__:      List[Any]			  =[["武田信玄", "は、"], ["織田信長", "の配下の、"]]
   lowerCamelCase__:      Union[str, Any]			  =tokenizer(UpperCAmelCase_       , padding=UpperCAmelCase_)
   lowerCamelCase__:      Optional[int]			  =tokenizer.batch_encode_plus(UpperCAmelCase_       , padding=UpperCAmelCase_)

   # fmt: off
   lowerCamelCase__:      Any			  =[[35_993, 8_640, 25_948, 35_998, 30_647, 35_675, 35_999, 35_999], [35_993, 10_382, 9_868, 35_998, 30_646, 9_459, 30_646, 35_675]]
   lowerCamelCase__:      Optional[Any]			  =[[1, 1, 1, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, 0, 0]]
   lowerCamelCase__:      List[Any]			  =[[1, 1, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1]]
   # fmt: on
   self.assertListEqual(x_token.input_ids       , UpperCAmelCase_)
   self.assertListEqual(x_token.token_type_ids       , UpperCAmelCase_)
   self.assertListEqual(x_token.attention_mask       , UpperCAmelCase_)
   self.assertListEqual(x_token_a.input_ids       , UpperCAmelCase_)
   self.assertListEqual(x_token_a.token_type_ids       , UpperCAmelCase_)
   self.assertListEqual(x_token_a.attention_mask       , UpperCAmelCase_)

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



   '''simple docstring'''



   pass







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



   '''simple docstring'''



   pass








import functools
import operator

from ...configuration_utils import PretrainedConfig
from ...utils import logging


__A									=				logging.get_logger(__name__)

__A									=				{
    "microsoft/unispeech-large-1500h-cv": (
        "https://huggingface.co/microsoft/unispeech-large-1500h-cv/resolve/main/config.json"
    ),
    # See all UniSpeech models at https://huggingface.co/models?filter=unispeech
}



class    _SCREAMING_SNAKE_CASE						(	__SCREAMING_SNAKE_CASE    ):







 '''simple docstring'''
 lowercase_		=			"unispeech"

 def __init__(self				:   Any       , UpperCAmelCase_				:   Any=32       , UpperCAmelCase_				:   List[str]=768       , UpperCAmelCase_				:   Any=12       , UpperCAmelCase_				:   Union[str, Any]=12       , UpperCAmelCase_				:   Optional[Any]=3_072       , UpperCAmelCase_				:   List[Any]="gelu"       , UpperCAmelCase_				:   int=0.1       , UpperCAmelCase_				:   Optional[int]=0.1       , UpperCAmelCase_				:   int=0.1       , UpperCAmelCase_				:   Any=0.0       , UpperCAmelCase_				:   str=0.0       , UpperCAmelCase_				:   Dict=0.1       , UpperCAmelCase_				:   Optional[int]=0.1       , UpperCAmelCase_				:   Optional[Any]=0.02       , UpperCAmelCase_				:   Union[str, Any]=1E-5       , UpperCAmelCase_				:   str="group"       , UpperCAmelCase_				:   List[Any]="gelu"       , UpperCAmelCase_				:   Tuple=(512, 512, 512, 512, 512, 512, 512)       , UpperCAmelCase_				:   str=(5, 2, 2, 2, 2, 2, 2)       , UpperCAmelCase_				:   Any=(10, 3, 3, 3, 3, 2, 2)       , UpperCAmelCase_				:   Optional[Any]=False       , UpperCAmelCase_				:   str=128       , UpperCAmelCase_				:   int=16       , UpperCAmelCase_				:   Dict=False       , UpperCAmelCase_				:   Optional[int]=True       , UpperCAmelCase_				:   Dict=0.05       , UpperCAmelCase_				:   Optional[int]=10       , UpperCAmelCase_				:   Tuple=2       , UpperCAmelCase_				:   Union[str, Any]=0.0       , UpperCAmelCase_				:   int=10       , UpperCAmelCase_				:   List[Any]=0       , UpperCAmelCase_				:   Optional[Any]=320       , UpperCAmelCase_				:   int=2       , UpperCAmelCase_				:   Union[str, Any]=0.1       , UpperCAmelCase_				:   str=100       , UpperCAmelCase_				:   Any=256       , UpperCAmelCase_				:   int=256       , UpperCAmelCase_				:   Optional[Any]=0.1       , UpperCAmelCase_				:   str="mean"       , UpperCAmelCase_				:   Union[str, Any]=False       , UpperCAmelCase_				:   List[str]=False       , UpperCAmelCase_				:   List[Any]=256       , UpperCAmelCase_				:   Optional[int]=80       , UpperCAmelCase_				:   Optional[int]=0       , UpperCAmelCase_				:   Optional[Any]=1       , UpperCAmelCase_				:   Union[str, Any]=2       , UpperCAmelCase_				:   Dict=0.5       , **UpperCAmelCase_				:   Optional[int]       , )       ->str:



   '''simple docstring'''



   super().__init__(**UpperCAmelCase_       , pad_token_id=UpperCAmelCase_       , bos_token_id=UpperCAmelCase_       , eos_token_id=UpperCAmelCase_)
   lowerCamelCase__:      Union[str, Any]			  =hidden_size
   lowerCamelCase__:      List[str]			  =feat_extract_norm
   lowerCamelCase__:      Dict			  =feat_extract_activation
   lowerCamelCase__:      Optional[Any]			  =list(UpperCAmelCase_)
   lowerCamelCase__:      Any			  =list(UpperCAmelCase_)
   lowerCamelCase__:      Union[str, Any]			  =list(UpperCAmelCase_)
   lowerCamelCase__:      Dict			  =conv_bias
   lowerCamelCase__:      Optional[Any]			  =num_conv_pos_embeddings
   lowerCamelCase__:      Dict			  =num_conv_pos_embedding_groups
   lowerCamelCase__:      int			  =len(self.conv_dim)
   lowerCamelCase__:      Union[str, Any]			  =num_hidden_layers
   lowerCamelCase__:      Union[str, Any]			  =intermediate_size
   lowerCamelCase__:      Dict			  =hidden_act
   lowerCamelCase__:      List[Any]			  =num_attention_heads
   lowerCamelCase__:      Dict			  =hidden_dropout
   lowerCamelCase__:      Optional[Any]			  =attention_dropout
   lowerCamelCase__:      Optional[Any]			  =activation_dropout
   lowerCamelCase__:      Tuple			  =feat_proj_dropout
   lowerCamelCase__:      int			  =final_dropout
   lowerCamelCase__:      Optional[Any]			  =layerdrop
   lowerCamelCase__:      Dict			  =layer_norm_eps
   lowerCamelCase__:      Optional[Any]			  =initializer_range
   lowerCamelCase__:      int			  =num_ctc_classes
   lowerCamelCase__:      Tuple			  =vocab_size
   lowerCamelCase__:      Dict			  =do_stable_layer_norm
   lowerCamelCase__:      List[Any]			  =use_weighted_layer_sum
   lowerCamelCase__:      Dict			  =classifier_proj_size

   if (
       (len(self.conv_stride) != self.num_feat_extract_layers)
       or (len(self.conv_kernel) != self.num_feat_extract_layers)
       or (len(self.conv_dim) != self.num_feat_extract_layers)
   ):
     raise ValueError(
         "Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =="
         " `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ="
         F""" {len(self.conv_dim)}`, `len(config.conv_stride) = {len(self.conv_stride)}`,"""
         F""" `len(config.conv_kernel) = {len(self.conv_kernel)}`.""")

   # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
   lowerCamelCase__:      int			  =apply_spec_augment
   lowerCamelCase__:      List[str]			  =mask_time_prob
   lowerCamelCase__:      Union[str, Any]			  =mask_time_length
   lowerCamelCase__:      List[Any]			  =mask_time_min_masks
   lowerCamelCase__:      Any			  =mask_feature_prob
   lowerCamelCase__:      Optional[Any]			  =mask_feature_length
   lowerCamelCase__:      List[str]			  =mask_feature_min_masks

   # parameters for pretraining with codevector quantized representations
   lowerCamelCase__:      Optional[Any]			  =num_codevectors_per_group
   lowerCamelCase__:      str			  =num_codevector_groups
   lowerCamelCase__:      Tuple			  =contrastive_logits_temperature
   lowerCamelCase__:      int			  =feat_quantizer_dropout
   lowerCamelCase__:      Any			  =num_negatives
   lowerCamelCase__:      List[str]			  =codevector_dim
   lowerCamelCase__:      Union[str, Any]			  =proj_codevector_dim
   lowerCamelCase__:      Any			  =diversity_loss_weight

   # ctc loss
   lowerCamelCase__:      Any			  =ctc_loss_reduction
   lowerCamelCase__:      Dict			  =ctc_zero_infinity

   # pretraining loss
   lowerCamelCase__:      Dict			  =replace_prob







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



   '''simple docstring'''



   return functools.reduce(operator.mul       , self.conv_stride       , 1)

