






'''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 enum
import os
from hashlib import shaaaa
from typing import Optional

from .. import config
from .logging import get_logger


lowerCamelCase_				: Any    	=							get_logger(__name__)
class    _SCREAMING_SNAKE_CASE							(		enum.Enum	):


			'''simple docstring'''





			__a							:							Tuple					     =					"all_checks"
			__a							:							List[Any]					     =					"basic_checks"
			__a							:							Dict					     =					"no_checks"
class    _SCREAMING_SNAKE_CASE							(		SCREAMING_SNAKE_CASE	):


			'''simple docstring'''





class    _SCREAMING_SNAKE_CASE							(		SCREAMING_SNAKE_CASE	):


			'''simple docstring'''





class    _SCREAMING_SNAKE_CASE							(		SCREAMING_SNAKE_CASE	):


			'''simple docstring'''





class    _SCREAMING_SNAKE_CASE							(		SCREAMING_SNAKE_CASE	):


			'''simple docstring'''












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





						if expected_checksums is None:
												logger.info("""Unable to verify checksums."""					)
												return
						if len(set(_A					) - set(_A					)					) > 0:
												raise ExpectedMoreDownloadedFiles(str(set(_A					) - set(_A					)					)					)
						if len(set(_A					) - set(_A					)					) > 0:
												raise UnexpectedDownloadedFile(str(set(_A					) - set(_A					)					)					)
						UpperCamelCase__         = [url for url in expected_checksums if expected_checksums[url] != recorded_checksums[url]]
						UpperCamelCase__         = """ for """ + verification_name if verification_name is not None else """"""
						if len(_A					) > 0:
												raise NonMatchingChecksumError(
												    f"Checksums didn't match{for_verification_name}:\n"
												    f"{bad_urls}\n"
												    """Set `verification_mode='no_checks'` to skip checksums verification and ignore this error"""					)
						logger.info("""All the checksums matched successfully""" + for_verification_name					)
class    _SCREAMING_SNAKE_CASE							(		SCREAMING_SNAKE_CASE	):


			'''simple docstring'''





class    _SCREAMING_SNAKE_CASE							(		SCREAMING_SNAKE_CASE	):


			'''simple docstring'''





class    _SCREAMING_SNAKE_CASE							(		SCREAMING_SNAKE_CASE	):


			'''simple docstring'''





class    _SCREAMING_SNAKE_CASE							(		SCREAMING_SNAKE_CASE	):


			'''simple docstring'''












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





						if expected_splits is None:
												logger.info("""Unable to verify splits sizes."""					)
												return
						if len(set(_A					) - set(_A					)					) > 0:
												raise ExpectedMoreSplits(str(set(_A					) - set(_A					)					)					)
						if len(set(_A					) - set(_A					)					) > 0:
												raise UnexpectedSplits(str(set(_A					) - set(_A					)					)					)
						UpperCamelCase__         = [
						    {"""expected""": expected_splits[name], """recorded""": recorded_splits[name]}
						    for name in expected_splits
						    if expected_splits[name].num_examples != recorded_splits[name].num_examples
						]
						if len(_A					) > 0:
												raise NonMatchingSplitsSizesError(str(_A					)					)
						logger.info("""All the splits matched successfully."""					)







def 	__magic_name__( _A						,      _A = True					):
						'''simple docstring'''





						if record_checksum:
												UpperCamelCase__         = shaaaa()
												with open(_A						,      """rb"""					) as f:
																		for chunk in iter(lambda: f.read(1 << 20					)						,      B""""""					):
																								m.update(_A					)
																		UpperCamelCase__         = m.hexdigest()
						else:
												UpperCamelCase__         = None
						return {"num_bytes": os.path.getsize(_A					), "checksum": checksum}







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





						if dataset_size and config.IN_MEMORY_MAX_SIZE:
												return dataset_size < config.IN_MEMORY_MAX_SIZE
						else:
												return False
