"""simple docstring"""





import json
from typing import TYPE_CHECKING, List, Optional, Tuple

from tokenizers import pre_tokenizers

from ...tokenization_utils_base import BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging


if TYPE_CHECKING:
				from transformers.pipelines.conversational import Conversation


__A     :   Union[str, Any]  =				logging.get_logger(__name__)

__A     :   Optional[int]  =				{'''tokenizer_file''': '''tokenizer.json'''}

__A     :   Optional[int]  =				{
    '''tokenizer_file''': {
        '''bigscience/tokenizer''': '''https://huggingface.co/bigscience/tokenizer/blob/main/tokenizer.json''',
        '''bigscience/bloom-560m''': '''https://huggingface.co/bigscience/bloom-560m/blob/main/tokenizer.json''',
        '''bigscience/bloom-1b1''': '''https://huggingface.co/bigscience/bloom-1b1/blob/main/tokenizer.json''',
        '''bigscience/bloom-1b7''': '''https://huggingface.co/bigscience/bloom-1b7/blob/main/tokenizer.json''',
        '''bigscience/bloom-3b''': '''https://huggingface.co/bigscience/bloom-3b/blob/main/tokenizer.json''',
        '''bigscience/bloom-7b1''': '''https://huggingface.co/bigscience/bloom-7b1/blob/main/tokenizer.json''',
        '''bigscience/bloom''': '''https://huggingface.co/bigscience/bloom/blob/main/tokenizer.json''',
    },
}
class  _snake_case     (					__UpperCAmelCase		):
						snake_case__			  =			VOCAB_FILES_NAMES
						snake_case__			  =			PRETRAINED_VOCAB_FILES_MAP
						snake_case__			  =			['''input_ids''', '''attention_mask''']
						snake_case__			  =			None






						def __init__(       self      :			int							,					UpperCAmelCase      :			str=None							,					UpperCAmelCase      :			List[Any]=None							,					UpperCAmelCase      :			List[str]=None							,					UpperCAmelCase      :			List[Any]="<unk>"							,					UpperCAmelCase      :			List[str]="<s>"							,					UpperCAmelCase      :			Union[str, Any]="</s>"							,					UpperCAmelCase      :			Dict="<pad>"							,					UpperCAmelCase      :			str=False							,					UpperCAmelCase      :			Optional[int]=False							,					**UpperCAmelCase      :			Union[str, Any]							,					):
													super().__init__(
													    __SCREAMING_SNAKE_CASE							,					__SCREAMING_SNAKE_CASE							,					tokenizer_file=__SCREAMING_SNAKE_CASE							,					unk_token=__SCREAMING_SNAKE_CASE							,					bos_token=__SCREAMING_SNAKE_CASE							,					eos_token=__SCREAMING_SNAKE_CASE							,					pad_token=__SCREAMING_SNAKE_CASE							,					add_prefix_space=__SCREAMING_SNAKE_CASE							,					clean_up_tokenization_spaces=__SCREAMING_SNAKE_CASE							,					**__SCREAMING_SNAKE_CASE							,					)
													__lowerCamelCase					:		Optional[int]		   =     json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__()    )
													if pre_tok_state.get("add_prefix_space"							,					__SCREAMING_SNAKE_CASE    ) != add_prefix_space:
																				__lowerCamelCase					:		Any		   =     getattr(__SCREAMING_SNAKE_CASE							,					pre_tok_state.pop("type"    )    )
																				__lowerCamelCase					:		int		   =     add_prefix_space
																				__lowerCamelCase					:		Any		   =     pre_tok_class(**__SCREAMING_SNAKE_CASE    )

													__lowerCamelCase					:		Optional[int]		   =     add_prefix_space






						def       lowerCamelCase__     (       self      :			Dict							,					*UpperCAmelCase      :			str							,					**UpperCAmelCase      :			Tuple    ):
													__lowerCamelCase					:		Optional[Any]		   =     kwargs.get("is_split_into_words"							,					__SCREAMING_SNAKE_CASE    )
													if not (self.add_prefix_space or not is_split_into_words):
																				raise Exception(
																				    F"""You need to instantiate {self.__class__.__name__} with add_prefix_space=True to use it with"""
																				    " pretokenized inputs."    )

													return super()._batch_encode_plus(*__SCREAMING_SNAKE_CASE							,					**__SCREAMING_SNAKE_CASE    )






						def       lowerCamelCase__     (       self      :			str							,					*UpperCAmelCase      :			List[Any]							,					**UpperCAmelCase      :			Union[str, Any]    ):
													__lowerCamelCase					:		List[str]		   =     kwargs.get("is_split_into_words"							,					__SCREAMING_SNAKE_CASE    )

													if not (self.add_prefix_space or not is_split_into_words):
																				raise Exception(
																				    F"""You need to instantiate {self.__class__.__name__} with add_prefix_space=True to use it with"""
																				    " pretokenized inputs."    )

													return super()._encode_plus(*__SCREAMING_SNAKE_CASE							,					**__SCREAMING_SNAKE_CASE    )






						def       lowerCamelCase__     (       self      :			Any							,					UpperCAmelCase      :			str							,					UpperCAmelCase      :			Optional[str] = None    ):
													__lowerCamelCase					:		Any		   =     self._tokenizer.model.save(__SCREAMING_SNAKE_CASE							,					name=__SCREAMING_SNAKE_CASE    )
													return tuple(__SCREAMING_SNAKE_CASE    )







						def       lowerCamelCase__     (       self      :			Any							,					UpperCAmelCase      :			"Conversation"    ):
													__lowerCamelCase					:		Union[str, Any]		   =     []
													for is_user, text in conversation.iter_texts():
																				input_ids.extend(self.encode(__SCREAMING_SNAKE_CASE							,					add_special_tokens=__SCREAMING_SNAKE_CASE    ) + [self.eos_token_id]    )

													if len(__SCREAMING_SNAKE_CASE    ) > self.model_max_length:
																				__lowerCamelCase					:		int		   =     input_ids[-self.model_max_length :]
													return input_ids
"""simple docstring"""





import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_funnel import FunnelTokenizer


__A  =				logging.get_logger(__name__)

__A  =				{'''vocab_file''': '''vocab.txt''', '''tokenizer_file''': '''tokenizer.json'''}

__A  =				[
    '''small''',
    '''small-base''',
    '''medium''',
    '''medium-base''',
    '''intermediate''',
    '''intermediate-base''',
    '''large''',
    '''large-base''',
    '''xlarge''',
    '''xlarge-base''',
]

__A  =				{
    '''vocab_file''': {
        '''funnel-transformer/small''': '''https://huggingface.co/funnel-transformer/small/resolve/main/vocab.txt''',
        '''funnel-transformer/small-base''': '''https://huggingface.co/funnel-transformer/small-base/resolve/main/vocab.txt''',
        '''funnel-transformer/medium''': '''https://huggingface.co/funnel-transformer/medium/resolve/main/vocab.txt''',
        '''funnel-transformer/medium-base''': (
            '''https://huggingface.co/funnel-transformer/medium-base/resolve/main/vocab.txt'''
        ),
        '''funnel-transformer/intermediate''': (
            '''https://huggingface.co/funnel-transformer/intermediate/resolve/main/vocab.txt'''
        ),
        '''funnel-transformer/intermediate-base''': (
            '''https://huggingface.co/funnel-transformer/intermediate-base/resolve/main/vocab.txt'''
        ),
        '''funnel-transformer/large''': '''https://huggingface.co/funnel-transformer/large/resolve/main/vocab.txt''',
        '''funnel-transformer/large-base''': '''https://huggingface.co/funnel-transformer/large-base/resolve/main/vocab.txt''',
        '''funnel-transformer/xlarge''': '''https://huggingface.co/funnel-transformer/xlarge/resolve/main/vocab.txt''',
        '''funnel-transformer/xlarge-base''': (
            '''https://huggingface.co/funnel-transformer/xlarge-base/resolve/main/vocab.txt'''
        ),
    },
    '''tokenizer_file''': {
        '''funnel-transformer/small''': '''https://huggingface.co/funnel-transformer/small/resolve/main/tokenizer.json''',
        '''funnel-transformer/small-base''': (
            '''https://huggingface.co/funnel-transformer/small-base/resolve/main/tokenizer.json'''
        ),
        '''funnel-transformer/medium''': '''https://huggingface.co/funnel-transformer/medium/resolve/main/tokenizer.json''',
        '''funnel-transformer/medium-base''': (
            '''https://huggingface.co/funnel-transformer/medium-base/resolve/main/tokenizer.json'''
        ),
        '''funnel-transformer/intermediate''': (
            '''https://huggingface.co/funnel-transformer/intermediate/resolve/main/tokenizer.json'''
        ),
        '''funnel-transformer/intermediate-base''': (
            '''https://huggingface.co/funnel-transformer/intermediate-base/resolve/main/tokenizer.json'''
        ),
        '''funnel-transformer/large''': '''https://huggingface.co/funnel-transformer/large/resolve/main/tokenizer.json''',
        '''funnel-transformer/large-base''': (
            '''https://huggingface.co/funnel-transformer/large-base/resolve/main/tokenizer.json'''
        ),
        '''funnel-transformer/xlarge''': '''https://huggingface.co/funnel-transformer/xlarge/resolve/main/tokenizer.json''',
        '''funnel-transformer/xlarge-base''': (
            '''https://huggingface.co/funnel-transformer/xlarge-base/resolve/main/tokenizer.json'''
        ),
    },
}
__A  =				{F"""funnel-transformer/{name}""": 512 for name in _model_names}
__A  =				{F"""funnel-transformer/{name}""": {'''do_lower_case''': True} for name in _model_names}
class  _snake_case     (					a__		):
						snake_case__			  =			VOCAB_FILES_NAMES
						snake_case__			  =			PRETRAINED_VOCAB_FILES_MAP
						snake_case__			  =			PRETRAINED_INIT_CONFIGURATION
						snake_case__			  =			FunnelTokenizer
						snake_case__			  =			PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
						snake_case__			  =			2






						def __init__(       self      :			List[Any]							,					UpperCAmelCase      :			List[str]=None							,					UpperCAmelCase      :			Optional[int]=None							,					UpperCAmelCase      :			List[Any]=True							,					UpperCAmelCase      :			int="<unk>"							,					UpperCAmelCase      :			List[Any]="<sep>"							,					UpperCAmelCase      :			List[str]="<pad>"							,					UpperCAmelCase      :			Union[str, Any]="<cls>"							,					UpperCAmelCase      :			int="<mask>"							,					UpperCAmelCase      :			List[str]="<s>"							,					UpperCAmelCase      :			Union[str, Any]="</s>"							,					UpperCAmelCase      :			List[Any]=True							,					UpperCAmelCase      :			Tuple=True							,					UpperCAmelCase      :			int=None							,					UpperCAmelCase      :			int="##"							,					**UpperCAmelCase      :			Dict							,					):
													super().__init__(
													    UpperCAmelCase							,					tokenizer_file=UpperCAmelCase							,					do_lower_case=UpperCAmelCase							,					unk_token=UpperCAmelCase							,					sep_token=UpperCAmelCase							,					pad_token=UpperCAmelCase							,					cls_token=UpperCAmelCase							,					mask_token=UpperCAmelCase							,					bos_token=UpperCAmelCase							,					eos_token=UpperCAmelCase							,					clean_text=UpperCAmelCase							,					tokenize_chinese_chars=UpperCAmelCase							,					strip_accents=UpperCAmelCase							,					wordpieces_prefix=UpperCAmelCase							,					**UpperCAmelCase							,					)

													__lowerCamelCase					:		List[Any]		   =     json.loads(self.backend_tokenizer.normalizer.__getstate__()    )
													if (
													    normalizer_state.get("lowercase"							,					UpperCAmelCase    ) != do_lower_case
													    or normalizer_state.get("strip_accents"							,					UpperCAmelCase    ) != strip_accents
													    or normalizer_state.get("handle_chinese_chars"							,					UpperCAmelCase    ) != tokenize_chinese_chars
													):
																				__lowerCamelCase					:		Tuple		   =     getattr(UpperCAmelCase							,					normalizer_state.pop("type"    )    )
																				__lowerCamelCase					:		Optional[int]		   =     do_lower_case
																				__lowerCamelCase					:		Union[str, Any]		   =     strip_accents
																				__lowerCamelCase					:		Optional[Any]		   =     tokenize_chinese_chars
																				__lowerCamelCase					:		Optional[Any]		   =     normalizer_class(**UpperCAmelCase    )

													__lowerCamelCase					:		List[Any]		   =     do_lower_case






						def       lowerCamelCase__     (       self      :			Union[str, Any]							,					UpperCAmelCase      :			Union[str, Any]							,					UpperCAmelCase      :			Tuple=None    ):
													__lowerCamelCase					:		List[Any]		   =     [self.cls_token_id] + token_ids_a + [self.sep_token_id]

													if token_ids_a:
																				output += token_ids_a + [self.sep_token_id]

													return output






						def       lowerCamelCase__     (       self      :			Dict							,					UpperCAmelCase      :			List[int]							,					UpperCAmelCase      :			Optional[List[int]] = None    ):
													__lowerCamelCase					:		Tuple		   =     [self.sep_token_id]
													__lowerCamelCase					:		int		   =     [self.cls_token_id]
													if token_ids_a is None:
																				return len(cls    ) * [self.cls_token_type_id] + len(token_ids_a + sep    ) * [0]
													return len(cls    ) * [self.cls_token_type_id] + len(token_ids_a + sep    ) * [0] + len(token_ids_a + sep    ) * [1]







						def       lowerCamelCase__     (       self      :			Tuple							,					UpperCAmelCase      :			str							,					UpperCAmelCase      :			Optional[str] = None    ):
													__lowerCamelCase					:		List[Any]		   =     self._tokenizer.model.save(UpperCAmelCase							,					name=UpperCAmelCase    )
													return tuple(UpperCAmelCase    )