






"""simple docstring"""







import io
import os
import unicodedata
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import PreTrainedTokenizer
from ...utils import logging


_lowerCAmelCase            =	logging.get_logger(__name__)

_lowerCAmelCase            =	'▁'

_lowerCAmelCase            =	{'vocab_file': 'vocab.txt', 'sentencepiece_model_ckpt': 'sentencepiece.bpe.model'}

_lowerCAmelCase            =	{
    'sentencepiece_model_file': 'sentencepiece.bpe.model',
    'vocab_file': 'vocab.txt',
}

_lowerCAmelCase            =	{
    'vocab_file': {
        'ernie-m-base': 'https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/vocab.txt',
        'ernie-m-large': 'https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/vocab.txt',
    },
    'sentencepiece_model_file': {
        'ernie-m-base': 'https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/sentencepiece.bpe.model',
        'ernie-m-large': 'https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/sentencepiece.bpe.model',
    },
}

_lowerCAmelCase            =	{
    'ernie-m-base': 5_14,
    'ernie-m-large': 5_14,
}

_lowerCAmelCase            =	{
    'ernie-m-base': {'do_lower_case': False},
    'ernie-m-large': {'do_lower_case': False},
}


class      UpperCamelCase		(__snake_case     ):
						_SCREAMING_SNAKE_CASE  : List[str]												=		["input_ids"]

						_SCREAMING_SNAKE_CASE  : Tuple												=		VOCAB_FILES_NAMES
						_SCREAMING_SNAKE_CASE  : Union[str, Any]												=		PRETRAINED_INIT_CONFIGURATION
						_SCREAMING_SNAKE_CASE  : Tuple												=		PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
						_SCREAMING_SNAKE_CASE  : Optional[Any]												=		PRETRAINED_VOCAB_FILES_MAP
						_SCREAMING_SNAKE_CASE  : int												=		RESOURCE_FILES_NAMES






						def __init__(		self  :Any			, __magic_name__  :List[str]			, __magic_name__  :Tuple=None			, __magic_name__  :Dict=False			, __magic_name__  :int="utf8"			, __magic_name__  :str="[UNK]"			, __magic_name__  :List[str]="[SEP]"			, __magic_name__  :Optional[int]="[PAD]"			, __magic_name__  :str="[CLS]"			, __magic_name__  :Tuple="[MASK]"			, __magic_name__  :Optional[Dict[str, Any]] = None			, **__magic_name__  :str			, )      ->None:
										# Mask token behave like a normal word, i.e. include the space before it and
										# is included in the raw text, there should be a match in a non-normalized sentence.

										lowercase    :      int       = {} if sp_model_kwargs is None else sp_model_kwargs
										super().__init__(
										    do_lower_case=__magic_name__			, unk_token=__magic_name__			, sep_token=__magic_name__			, pad_token=__magic_name__			, cls_token=__magic_name__			, mask_token=__magic_name__			, vocab_file=__magic_name__			, encoding=__magic_name__			, sp_model_kwargs=self.sp_model_kwargs			, **__magic_name__			, )
										lowercase    :      str       = do_lower_case
										lowercase    :      int       = sentencepiece_model_ckpt
										lowercase    :      List[Any]       = spm.SentencePieceProcessor(**self.sp_model_kwargs				)
										self.sp_model.Load(__magic_name__				)

										# to mimic paddlenlp.transformers.ernie_m.tokenizer.ErnieMTokenizer functioning
										if vocab_file is not None:
														lowercase    :      Dict       = self.load_vocab(filepath=__magic_name__				)
										else:
														lowercase    :      Optional[int]       = {self.sp_model.id_to_piece(__magic_name__				): id for id in range(self.sp_model.get_piece_size()				)}
										lowercase    :      int       = {v: k for k, v in self.vocab.items()}






						def      __snake_case      (		self  :Any			, __magic_name__  :str				)      ->Optional[Any]:
										if text is None:
														return None

										lowercase    :      Optional[int]       = self.tokenize(__magic_name__				)
										lowercase      ,      lowercase    :      List[Any]       = """""", []

										for i, ch in enumerate(__magic_name__				):
														if ch in self.SP_CHAR_MAPPING:
																		lowercase    :      Tuple       = self.SP_CHAR_MAPPING.get(__magic_name__				)
														else:
																		lowercase    :      List[str]       = unicodedata.normalize("""NFKC"""			, __magic_name__				)
														if self.is_whitespace(__magic_name__				):
																		continue
														normalized_text += ch
														char_mapping.extend([i] * len(__magic_name__				)				)

										lowercase      ,      lowercase      ,      lowercase    :      str       = normalized_text, [], 0

										if self.do_lower_case:
														lowercase    :      Optional[Any]       = text.lower()

										for token in split_tokens:
														if token[:1] == "▁":
																		lowercase    :      Optional[Any]       = token[1:]
														lowercase    :      int       = text[offset:].index(__magic_name__				) + offset
														lowercase    :      Dict       = start + len(__magic_name__				)

														token_mapping.append((char_mapping[start], char_mapping[end - 1] + 1)				)
														lowercase    :      str       = end
										return token_mapping






						@property
						def      __snake_case      (		self  :str				)      ->Union[str, Any]:
										return len(self.vocab				)






						def      __snake_case      (		self  :Optional[int]				)      ->Optional[int]:
										return dict(self.vocab			, **self.added_tokens_encoder				)






						def __getstate__(		self  :Any				)      ->Optional[Any]:
										lowercase    :      Optional[Any]       = self.__dict__.copy()
										lowercase    :      str       = None
										return state






						def __setstate__(		self  :Any			, __magic_name__  :Optional[Any]				)      ->Union[str, Any]:
										lowercase    :      int       = d

										# for backward compatibility
										if not hasattr(self			, """sp_model_kwargs"""				):
														lowercase    :      Optional[Any]       = {}

										lowercase    :      Any       = spm.SentencePieceProcessor(**self.sp_model_kwargs				)
										self.sp_model.Load(self.sentencepiece_model_ckpt				)






						def      __snake_case      (		self  :Optional[Any]			, __magic_name__  :Optional[Any]				)      ->Dict:
										return "".join((self.SP_CHAR_MAPPING.get(__magic_name__			, __magic_name__				) for c in text)				)






						def      __snake_case      (		self  :Optional[Any]			, __magic_name__  :List[Any]			, __magic_name__  :str=False			, __magic_name__  :List[Any]=64			, __magic_name__  :Tuple=0.1				)      ->Optional[int]:

										if self.sp_model_kwargs.get("""enable_sampling"""				) is True:
														lowercase    :      str       = True
										if self.sp_model_kwargs.get("""alpha"""				) is not None:
														lowercase    :      Union[str, Any]       = self.sp_model_kwargs.get("""alpha"""				)
										if self.sp_model_kwargs.get("""nbest_size"""				) is not None:
														lowercase    :      Optional[Any]       = self.sp_model_kwargs.get("""nbest_size"""				)

										if not enable_sampling:
														lowercase    :      Optional[int]       = self.sp_model.EncodeAsPieces(__magic_name__				)
										else:
														lowercase    :      Dict       = self.sp_model.SampleEncodeAsPieces(__magic_name__			, __magic_name__			, __magic_name__				)
										lowercase    :      List[Any]       = []
										for pi, piece in enumerate(__magic_name__				):
														if piece == SPIECE_UNDERLINE:
																		if not pieces[pi + 1].startswith(__magic_name__				) and pi != 0:
																						new_pieces.append(__magic_name__				)
																						continue
																		else:
																						continue
														lowercase    :      Tuple       = 0
														for i, chunk in enumerate(__magic_name__				):
																		if chunk == SPIECE_UNDERLINE:
																						continue
																		if self.is_ch_char(__magic_name__				) or self.is_punct(__magic_name__				):
																						if i > lst_i and piece[lst_i:i] != SPIECE_UNDERLINE:
																										new_pieces.append(piece[lst_i:i]				)
																						new_pieces.append(__magic_name__				)
																						lowercase    :      Dict       = i + 1
																		elif chunk.isdigit() and i > 0 and not piece[i - 1].isdigit():
																						if i > lst_i and piece[lst_i:i] != SPIECE_UNDERLINE:
																										new_pieces.append(piece[lst_i:i]				)
																						lowercase    :      int       = i
																		elif not chunk.isdigit() and i > 0 and piece[i - 1].isdigit():
																						if i > lst_i and piece[lst_i:i] != SPIECE_UNDERLINE:
																										new_pieces.append(piece[lst_i:i]				)
																						lowercase    :      Dict       = i
														if len(__magic_name__				) > lst_i:
																		new_pieces.append(piece[lst_i:]				)
										return new_pieces






						def      __snake_case      (		self  :Tuple			, __magic_name__  :str				)      ->List[str]:
										lowercase    :      Optional[Any]       = """""".join(__magic_name__				).replace(__magic_name__			, """ """				).strip()
										return out_string






						def      __snake_case      (		self  :Any			, __magic_name__  :str				)      ->List[str]:
										lowercase    :      List[str]       = self.convert_ids_to_tokens(__magic_name__				)
										lowercase    :      List[str]       = """""".join(__magic_name__				).replace(__magic_name__			, """ """				).strip()
										return out_string






						def      __snake_case      (		self  :List[Any]			, __magic_name__  :int				)      ->Dict:
										return self.vocab.get(__magic_name__			, self.vocab.get(self.unk_token				)				)






						def      __snake_case      (		self  :Tuple			, __magic_name__  :List[str]				)      ->List[str]:
										return self.reverse_vocab.get(__magic_name__			, self.unk_token				)






						def      __snake_case      (		self  :Union[str, Any]			, __magic_name__  :Tuple			, __magic_name__  :str=None				)      ->Optional[Any]:
										if token_ids_a is None:
														return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
										lowercase    :      Any       = [self.cls_token_id]
										lowercase    :      Dict       = [self.sep_token_id]
										return _cls + token_ids_a + _sep + _sep + token_ids_a + _sep






						def      __snake_case      (		self  :Optional[Any]			, __magic_name__  :Any			, __magic_name__  :Any=None				)      ->Optional[Any]:
										if offset_mapping_a is None:
														return [(0, 0)] + offset_mapping_a + [(0, 0)]

										return [(0, 0)] + offset_mapping_a + [(0, 0), (0, 0)] + offset_mapping_a + [(0, 0)]






						def      __snake_case      (		self  :List[Any]			, __magic_name__  :Optional[int]			, __magic_name__  :int=None			, __magic_name__  :str=False				)      ->str:

										if already_has_special_tokens:
														if token_ids_a is not None:
																		raise ValueError(
																		    """You should not supply a second sequence if the provided sequence of """
																		    """ids is already formatted with special tokens for the model."""				)
														return [1 if x in [self.sep_token_id, self.cls_token_id] else 0 for x in token_ids_a]

										if token_ids_a is not None:
														return [1] + ([0] * len(__magic_name__				)) + [1, 1] + ([0] * len(__magic_name__				)) + [1]
										return [1] + ([0] * len(__magic_name__				)) + [1]






						def      __snake_case      (		self  :Tuple			, __magic_name__  :List[int]			, __magic_name__  :Optional[List[int]] = None				)      ->List[int]:
										# called when `add_special_tokens` is True, so align with `build_inputs_with_special_tokens` method
										if token_ids_a is None:
														# [CLS] X [SEP]
														return (len(__magic_name__				) + 2) * [0]

										# [CLS] A [SEP] [SEP] B [SEP]
										return [0] * (len(__magic_name__				) + 1) + [1] * (len(__magic_name__				) + 3)






						def      __snake_case      (		self  :List[str]			, __magic_name__  :Union[str, Any]				)      ->List[Any]:
										if "\u4e00" <= char <= "\u9fff":
														return True
										return False






						def      __snake_case      (		self  :Optional[int]			, __magic_name__  :List[Any]				)      ->Any:
										if ("a" <= char <= "z") or ("A" <= char <= "Z"):
														return True
										return False






						def      __snake_case      (		self  :Tuple			, __magic_name__  :int				)      ->List[str]:
										if char in ",;:.?!~，；：。？！《》【】":
														return True
										return False






						def      __snake_case      (		self  :Dict			, __magic_name__  :Optional[int]				)      ->Optional[int]:
										if char == " " or char == "\t" or char == "\n" or char == "\r":
														return True
										if len(__magic_name__				) == 1:
														lowercase    :      List[str]       = unicodedata.category(__magic_name__				)
														if cat == "Zs":
																		return True
										return False






						def      __snake_case      (		self  :Any			, __magic_name__  :Union[str, Any]				)      ->Optional[int]:
										lowercase    :      List[str]       = {}
										with io.open(__magic_name__			, """r"""			, encoding="""utf-8"""				) as f:
														for index, line in enumerate(__magic_name__				):
																		lowercase    :      str       = line.rstrip("""\n"""				)
																		lowercase    :      List[str]       = int(__magic_name__				)

										return token_to_idx






						def      __snake_case      (		self  :Any			, __magic_name__  :str			, __magic_name__  :Optional[str] = None				)      ->Tuple[str]:
										lowercase    :      Dict       = 0
										if os.path.isdir(__magic_name__				):
														lowercase    :      Optional[Any]       = os.path.join(
														    __magic_name__			, (filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""vocab_file"""]				)
										else:
														lowercase    :      Tuple       = (filename_prefix + """-""" if filename_prefix else """""") + save_directory
										with open(__magic_name__			, """w"""			, encoding="""utf-8"""				) as writer:
														for token, token_index in sorted(self.vocab.items()			, key=lambda __magic_name__				: kv[1]				):
																		if index != token_index:
																						logger.warning(
																						    f"""Saving vocabulary to {vocab_file}: vocabulary indices are not consecutive."""
																						    """ Please check that the vocabulary is not corrupted!"""				)
																						lowercase    :      Optional[int]       = token_index
																		writer.write(token + """\n"""				)
																		index += 1

										lowercase    :      Dict       = os.path.join(__magic_name__			, """sentencepiece.bpe.model"""				)
										with open(__magic_name__			, """wb"""				) as fi:
														lowercase    :      Any       = self.sp_model.serialized_model_proto()
														fi.write(__magic_name__				)

										return (vocab_file,)








"""simple docstring"""







import math
import random


def      UpperCamelCase       ( _A  ,				_A = False )     ->       float:
				if deriv:
								return value * (1 - value)
				return 1 / (1 + math.exp(-value ))


# Initial Value
_lowerCAmelCase            =	0.02


def      UpperCamelCase       ( _A  ,				_A )     ->       float:
				lowercase    :      Any       = float(2 * (random.randint(1  ,				100 )) - 1 )

				for _ in range(_A ):
								# Forward propagation
								lowercase    :      Dict       = sigmoid_function(INITIAL_VALUE * weight )
								# How much did we miss?
								lowercase    :      Any       = (expected / 100) - layer_a
								# Error delta
								lowercase    :      Dict       = layer_1_error * sigmoid_function(_A  ,				_A )
								# Update weight
								weight += INITIAL_VALUE * layer_1_delta

				return layer_a * 100


if __name__ == "__main__":
				import doctest

				doctest.testmod()

				_lowerCAmelCase            =	int(input('Expected value: '))
				_lowerCAmelCase            =	int(input('Number of propagations: '))
				print(forward_propagation(expected, number_propagations))
