
'''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


lowercase			:				int    		=			logging.get_logger(__name__)

lowercase			:				List[Any]    		=			{'vocab_file': 'vocab.txt', 'tokenizer_file': 'tokenizer.json'}

lowercase			:				Dict    		=			[
    'small',
    'small-base',
    'medium',
    'medium-base',
    'intermediate',
    'intermediate-base',
    'large',
    'large-base',
    'xlarge',
    'xlarge-base',
]

lowercase			:				Dict    		=			{
    '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'
        ),
    },
}
lowercase			:				Union[str, Any]    		=			{f'''funnel-transformer/{name}''': 5_12 for name in _model_names}
lowercase			:				Optional[Any]    		=			{f'''funnel-transformer/{name}''': {'do_lower_case': True} for name in _model_names}





class  A				(							__snake_case						):
     __magic_name__						=		VOCAB_FILES_NAMES
     __magic_name__						=		PRETRAINED_VOCAB_FILES_MAP
     __magic_name__						=		PRETRAINED_INIT_CONFIGURATION
     __magic_name__						=		FunnelTokenizer
     __magic_name__						=		PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     __magic_name__						=		2





     def __init__(							self						,			SCREAMING_SNAKE_CASE=None						,			SCREAMING_SNAKE_CASE=None						,			SCREAMING_SNAKE_CASE=True						,			SCREAMING_SNAKE_CASE="<unk>"						,			SCREAMING_SNAKE_CASE="<sep>"						,			SCREAMING_SNAKE_CASE="<pad>"						,			SCREAMING_SNAKE_CASE="<cls>"						,			SCREAMING_SNAKE_CASE="<mask>"						,			SCREAMING_SNAKE_CASE="<s>"						,			SCREAMING_SNAKE_CASE="</s>"						,			SCREAMING_SNAKE_CASE=True						,			SCREAMING_SNAKE_CASE=True						,			SCREAMING_SNAKE_CASE=None						,			SCREAMING_SNAKE_CASE="##"						,			**SCREAMING_SNAKE_CASE						,			) ->				Tuple:






         """simple docstring"""






         super().__init__(
             SCREAMING_SNAKE_CASE						,			tokenizer_file=SCREAMING_SNAKE_CASE						,			do_lower_case=SCREAMING_SNAKE_CASE						,			unk_token=SCREAMING_SNAKE_CASE						,			sep_token=SCREAMING_SNAKE_CASE						,			pad_token=SCREAMING_SNAKE_CASE						,			cls_token=SCREAMING_SNAKE_CASE						,			mask_token=SCREAMING_SNAKE_CASE						,			bos_token=SCREAMING_SNAKE_CASE						,			eos_token=SCREAMING_SNAKE_CASE						,			clean_text=SCREAMING_SNAKE_CASE						,			tokenize_chinese_chars=SCREAMING_SNAKE_CASE						,			strip_accents=SCREAMING_SNAKE_CASE						,			wordpieces_prefix=SCREAMING_SNAKE_CASE						,			**SCREAMING_SNAKE_CASE						,			)

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

         A       :   int					=						do_lower_case





     def 				__lowerCAmelCase							(							self						,			SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE=None	) ->				Union[str, Any]:






         """simple docstring"""






         A       :   Optional[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						,			SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE = None	) ->				List[int]:






         """simple docstring"""






         A       :   List[Any]					=						[self.sep_token_id]
         A       :   Tuple					=						[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						,			SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE = None	) ->				Tuple[str]:






         """simple docstring"""






         A       :   Tuple					=						self._tokenizer.model.save(SCREAMING_SNAKE_CASE						,			name=SCREAMING_SNAKE_CASE	)
         return tuple(SCREAMING_SNAKE_CASE	)







import os
from collections import namedtuple

import pytest

from datasets import ClassLabel, Features, Sequence, Value
from datasets.commands.test import TestCommand
from datasets.info import DatasetInfo, DatasetInfosDict


A_       : Any         =			namedtuple(
    '_TestCommandArgs',
    [
        'dataset',
        'name',
        'cache_dir',
        'data_dir',
        'all_configs',
        'save_infos',
        'ignore_verifications',
        'force_redownload',
        'clear_cache',
    ],
    defaults=[None, None, None, False, False, False, False, False],
)

def 						UpperCamelCase					(lowercase_: Any    ,      lowercase_: List[str]					)     ->      Optional[int]:
	return (abs(source - target					) / target) < 0.01


@pytest.mark.integration
def 						UpperCamelCase					(lowercase_: str					)     ->      str:
	A__							:    List[str]        =		_TestCommandArgs(dataset=lowercase_    ,      all_configs=lowercase_    ,      save_infos=lowercase_					)
	A__							:    int        =		TestCommand(*lowercase_					)
	test_command.run()
	A__							:    Optional[Any]        =		os.path.join(lowercase_    ,      """README.md"""					)
	assert os.path.exists(lowercase_					)
	A__							:    Dict        =		DatasetInfosDict.from_directory(lowercase_					)
	A__							:    str        =		DatasetInfosDict(
	    {
	        """default""": DatasetInfo(
	            features=Features(
	                {
	                    """tokens""": Sequence(Value("""string"""					)					),
	                    """ner_tags""": Sequence(
	                        ClassLabel(names=["""O""", """B-PER""", """I-PER""", """B-ORG""", """I-ORG""", """B-LOC""", """I-LOC"""]					)					),
	                    """langs""": Sequence(Value("""string"""					)					),
	                    """spans""": Sequence(Value("""string"""					)					),
	                }					)    ,      splits=[
	                {
	                    """name""": """train""",
	                    """num_bytes""": 2351563,
	                    """num_examples""": 10000,
	                },
	                {
	                    """name""": """validation""",
	                    """num_bytes""": 238418,
	                    """num_examples""": 1000,
	                },
	            ]    ,      download_size=3940680    ,      dataset_size=2589981    ,      )
	    }					)
	assert dataset_infos.keys() == expected_dataset_infos.keys()
	for key in DatasetInfo._INCLUDED_INFO_IN_YAML:
		A__   ,   A__							:    Optional[Any]        =		getattr(dataset_infos["""default"""]    ,      lowercase_					), getattr(expected_dataset_infos["""default"""]    ,      lowercase_					)
		if key == "num_bytes":
			assert is_apercent_close(lowercase_    ,      lowercase_					)
		elif key == "splits":
			assert list(lowercase_					) == list(lowercase_					)
			for split in result:
				assert result[split].name == expected[split].name
				assert result[split].num_examples == expected[split].num_examples
				assert is_apercent_close(result[split].num_bytes    ,      expected[split].num_bytes					)
		else:
			result == expected



