

'''simple docstring'''


import json
from typing import Iterator, List, Union

from tokenizers import AddedToken, Regex, Tokenizer, decoders, normalizers, pre_tokenizers, trainers
from tokenizers.implementations.base_tokenizer import BaseTokenizer
from tokenizers.models import Unigram
from tokenizers.processors import TemplateProcessing
class    _SCREAMING_SNAKE_CASE							(		SCREAMING_SNAKE_CASE	):


			'''simple docstring'''





			def __init__(   self							:						Dict ,      lowercase							:						str = "▁" ,      lowercase							:						bool = True ,      lowercase							:						Union[str, AddedToken] = "<unk>" ,      lowercase							:						Union[str, AddedToken] = "</s>" ,      lowercase							:						Union[str, AddedToken] = "<pad>" ,      )							->    Optional[Any]:

									'''simple docstring'''







									UpperCamelCase__         = {
									    """pad""": {"""id""": 0, """token""": pad_token},
									    """eos""": {"""id""": 1, """token""": eos_token},
									    """unk""": {"""id""": 2, """token""": unk_token},
									}

									UpperCamelCase__         = [None] * len(self.special_tokens			)
									for token_dict in self.special_tokens.values():
															UpperCamelCase__         = token_dict["""token"""]

									UpperCamelCase__         = Tokenizer(Unigram()			)

									UpperCamelCase__         = normalizers.Sequence(
									    [
									        normalizers.Nmt(),
									        normalizers.NFKC(),
									        normalizers.Replace(Regex(""" {2,}"""			) ,      """ """			),
									        normalizers.Lowercase(),
									    ]			)
									UpperCamelCase__         = pre_tokenizers.Sequence(
									    [
									        pre_tokenizers.Metaspace(replacement=lowercase ,      add_prefix_space=lowercase			),
									        pre_tokenizers.Digits(individual_digits=lowercase			),
									        pre_tokenizers.Punctuation(),
									    ]			)
									UpperCamelCase__         = decoders.Metaspace(replacement=lowercase ,      add_prefix_space=lowercase			)

									UpperCamelCase__         = TemplateProcessing(
									    single=f"$A {self.special_tokens['eos']['token']}" ,      special_tokens=[(self.special_tokens["""eos"""]["""token"""], self.special_tokens["""eos"""]["""id"""])] ,      )

									UpperCamelCase__         = {
									    """model""": """SentencePieceUnigram""",
									    """replacement""": replacement,
									    """add_prefix_space""": add_prefix_space,
									}

									super().__init__(lowercase ,      lowercase			)






			def 				A      (   self							:						Tuple ,      lowercase							:						Union[str, List[str]] ,      lowercase							:						int = 8_0_0_0 ,      lowercase							:						bool = True ,      )							->    Any:

									'''simple docstring'''







									UpperCamelCase__         = trainers.UnigramTrainer(
									    vocab_size=lowercase ,      special_tokens=self.special_tokens_list ,      show_progress=lowercase ,      )

									if isinstance(lowercase ,      lowercase			):
															UpperCamelCase__         = [files]
									self._tokenizer.train(lowercase ,      trainer=lowercase			)

									self.add_unk_id()






			def 				A      (   self							:						Dict ,      lowercase							:						Union[Iterator[str], Iterator[Iterator[str]]] ,      lowercase							:						int = 8_0_0_0 ,      lowercase							:						bool = True ,      )							->    str:

									'''simple docstring'''







									UpperCamelCase__         = trainers.UnigramTrainer(
									    vocab_size=lowercase ,      special_tokens=self.special_tokens_list ,      show_progress=lowercase ,      )

									self._tokenizer.train_from_iterator(lowercase ,      trainer=lowercase			)

									self.add_unk_id()







			def 				A      (   self							:						Tuple			)							->    List[Any]:

									'''simple docstring'''







									UpperCamelCase__         = json.loads(self._tokenizer.to_str()			)

									UpperCamelCase__         = self.special_tokens["""unk"""]["""id"""]

									UpperCamelCase__         = Tokenizer.from_str(json.dumps(lowercase			)			)








'''simple docstring'''


import logging
import os
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

from tqdm import auto as tqdm_lib


lowerCamelCase_				: Any    	=							{
    '''debug''': logging.DEBUG,
    '''info''': logging.INFO,
    '''warning''': logging.WARNING,
    '''error''': logging.ERROR,
    '''critical''': logging.CRITICAL,
}

lowerCamelCase_				: Optional[int]    	=							logging.WARNING







def 	__magic_name__( ):
						'''simple docstring'''





						UpperCamelCase__         = os.getenv("""DATASETS_VERBOSITY"""						,      _A					)
						if env_level_str:
												if env_level_str in log_levels:
																		return log_levels[env_level_str]
												else:
																		logging.getLogger().warning(
																		    f"Unknown option DATASETS_VERBOSITY={env_level_str}, "
																		    f"has to be one of: { ', '.join(log_levels.keys()					) }"					)
						return _default_log_level







def 	__magic_name__( ):
						'''simple docstring'''





						return __name__.split("""."""					)[0]







def 	__magic_name__( ):
						'''simple docstring'''





						return logging.getLogger(_get_library_name()					)







def 	__magic_name__( ):
						'''simple docstring'''





						UpperCamelCase__         = _get_library_root_logger()
						library_root_logger.setLevel(_get_default_logging_level()					)







def 	__magic_name__( ):
						'''simple docstring'''





						UpperCamelCase__         = _get_library_root_logger()
						library_root_logger.setLevel(logging.NOTSET					)







def 	__magic_name__( _A = None					):
						'''simple docstring'''





						if name is None:
												UpperCamelCase__         = _get_library_name()
						return logging.getLogger(_A					)







def 	__magic_name__( ):
						'''simple docstring'''





						return _get_library_root_logger().getEffectiveLevel()







def 	__magic_name__( _A					):
						'''simple docstring'''





						_get_library_root_logger().setLevel(_A					)







def 	__magic_name__( ):
						'''simple docstring'''





						return set_verbosity(_A					)







def 	__magic_name__( ):
						'''simple docstring'''





						return set_verbosity(_A					)







def 	__magic_name__( ):
						'''simple docstring'''





						return set_verbosity(_A					)







def 	__magic_name__( ):
						'''simple docstring'''





						return set_verbosity(_A					)







def 	__magic_name__( ):
						'''simple docstring'''





						UpperCamelCase__         = False







def 	__magic_name__( ):
						'''simple docstring'''





						UpperCamelCase__         = True


# Configure the library root logger at the module level (singleton-like)
_configure_library_root_logger()
class    _SCREAMING_SNAKE_CASE							:


			'''simple docstring'''





			def __init__(   self							:						int ,      *lowercase							:						Any ,      **lowercase							:						int			)							->    List[Any]:  # pylint: disable=unused-argument

									'''simple docstring'''







									UpperCamelCase__         = args[0] if args else None






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

									'''simple docstring'''







									return iter(self._iterator			)






			def __getattr__(   self							:						Optional[int] ,      lowercase							:						Tuple			)							->    int:

									'''simple docstring'''







									def empty_fn(*lowercase							:						List[Any] ,      **lowercase							:						Dict			):  # pylint: disable=unused-argument
															return

									return empty_fn






			def __enter__(   self							:						Dict			)							->    Tuple:

									'''simple docstring'''







									return self







			def __exit__(   self							:						Tuple ,      lowercase							:						Optional[Any] ,      lowercase							:						Any ,      lowercase							:						int			)							->    Any:

									'''simple docstring'''







									return
lowerCamelCase_				: str    	=							True
class    _SCREAMING_SNAKE_CASE							:


			'''simple docstring'''





			def __call__(   self							:						List[Any] ,      *lowercase							:						str ,      lowercase							:						Optional[int]=False ,      **lowercase							:						Optional[int]			)							->    Optional[int]:

									'''simple docstring'''







									if _tqdm_active and not disable:
															return tqdm_lib.tqdm(*lowercase ,      **lowercase			)
									else:
															return EmptyTqdm(*lowercase ,      **lowercase			)






			def 				A      (   self							:						Optional[Any] ,      *lowercase							:						Tuple ,      **lowercase							:						Any			)							->    Any:

									'''simple docstring'''







									UpperCamelCase__         = None
									if _tqdm_active:
															return tqdm_lib.tqdm.set_lock(*lowercase ,      **lowercase			)







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

									'''simple docstring'''







									if _tqdm_active:
															return tqdm_lib.tqdm.get_lock()
lowerCamelCase_				: int    	=							_tqdm_cls()







def 	__magic_name__( ):
						'''simple docstring'''





						global _tqdm_active
						return bool(_tqdm_active					)







def 	__magic_name__( ):
						'''simple docstring'''





						global _tqdm_active
						UpperCamelCase__         = True







def 	__magic_name__( ):
						'''simple docstring'''





						global _tqdm_active
						UpperCamelCase__         = False
