

import json
import os
import tempfile

import datasets
from utils import generate_example_dataset, get_duration


lowerCamelCase						=		5_0000
lowerCamelCase						=		5000

lowerCamelCase,       lowerCamelCase						=		os.path.split(__file__)
lowerCamelCase						=		os.path.join(RESULTS_BASEPATH, '''results''', RESULTS_FILENAME.replace('''.py''', '''.json'''))






@get_duration
def 					lowerCamelCase_   (	_a     ,       _a	):




		"""simple docstring"""






		for i in range(_a	):
				lowerCAmelCase__       :      Tuple   					= dataset[i]






@get_duration
def 					lowerCamelCase_   (	_a     ,       _a     ,       _a	):




		"""simple docstring"""






		for i in range(0     ,       len(_a	)     ,       _a	):
				lowerCAmelCase__       :      Optional[int]   					= dataset[i : i + batch_size]






@get_duration
def 					lowerCamelCase_   (	_a     ,       _a     ,       _a	):




		"""simple docstring"""






		with dataset.formatted_as(type=_a	):
				for i in range(_a	):
						lowerCAmelCase__       :      Any   					= dataset[i]






@get_duration
def 					lowerCamelCase_   (	_a     ,       _a     ,       _a     ,       _a	):




		"""simple docstring"""






		with dataset.formatted_as(type=_a	):
				for i in range(0     ,       _a     ,       _a	):
						lowerCAmelCase__       :      Optional[int]   					= dataset[i : i + batch_size]






def 					lowerCamelCase_   (	):




		"""simple docstring"""






		lowerCAmelCase__       :      int   					= {'''num examples''': SPEED_TEST_N_EXAMPLES}
		lowerCAmelCase__       :      Optional[int]   					= [
		    (read, {'''length''': SMALL_TEST}),
		    (read, {'''length''': SPEED_TEST_N_EXAMPLES}),
		    (read_batch, {'''length''': SPEED_TEST_N_EXAMPLES, '''batch_size''': 10}),
		    (read_batch, {'''length''': SPEED_TEST_N_EXAMPLES, '''batch_size''': 100}),
		    (read_batch, {'''length''': SPEED_TEST_N_EXAMPLES, '''batch_size''': 1_000}),
		    (read_formatted, {'''type''': '''numpy''', '''length''': SMALL_TEST}),
		    (read_formatted, {'''type''': '''pandas''', '''length''': SMALL_TEST}),
		    (read_formatted, {'''type''': '''torch''', '''length''': SMALL_TEST}),
		    (read_formatted, {'''type''': '''tensorflow''', '''length''': SMALL_TEST}),
		    (read_formatted_batch, {'''type''': '''numpy''', '''length''': SMALL_TEST, '''batch_size''': 10}),
		    (read_formatted_batch, {'''type''': '''numpy''', '''length''': SMALL_TEST, '''batch_size''': 1_000}),
		]

		lowerCAmelCase__       :      Optional[Any]   					= [
		    (read, {'''length''': SMALL_TEST}),
		    (read, {'''length''': SPEED_TEST_N_EXAMPLES}),
		    (read_batch, {'''length''': SPEED_TEST_N_EXAMPLES, '''batch_size''': 10}),
		    (read_batch, {'''length''': SPEED_TEST_N_EXAMPLES, '''batch_size''': 100}),
		    (read_batch, {'''length''': SPEED_TEST_N_EXAMPLES, '''batch_size''': 1_000}),
		    (read_formatted, {'''type''': '''numpy''', '''length''': SMALL_TEST}),
		    (read_formatted_batch, {'''type''': '''numpy''', '''length''': SMALL_TEST, '''batch_size''': 10}),
		    (read_formatted_batch, {'''type''': '''numpy''', '''length''': SMALL_TEST, '''batch_size''': 1_000}),
		]
		with tempfile.TemporaryDirectory() as tmp_dir:
				print('''generating dataset'''	)
				lowerCAmelCase__       :      int   					= datasets.Features(
				    {'''list''': datasets.Sequence(datasets.Value('''float32'''	)	), '''numbers''': datasets.Value('''float32'''	)}	)
				lowerCAmelCase__       :      Any   					= generate_example_dataset(
				    os.path.join(_a     ,       '''dataset.arrow'''	)     ,       _a     ,       num_examples=_a     ,       seq_shapes={'''list''': (100,)}     ,       )
				print('''first set of iterations'''	)
				for func, kwargs in functions:
						print(func.__name__     ,       str(_a	)	)
						lowerCAmelCase__       :      Any   					= func(_a     ,       **_a	)

				print('''shuffling dataset'''	)
				lowerCAmelCase__       :      Union[str, Any]   					= dataset.shuffle()
				print('''Second set of iterations (after shuffling'''	)
				for func, kwargs in functions_shuffled:
						print('''shuffled '''     ,       func.__name__     ,       str(_a	)	)
						lowerCAmelCase__       :      str   					= func(
						    _a     ,       **_a	)

		with open(_a     ,       '''wb'''	) as f:
				f.write(json.dumps(_a	).encode('''utf-8'''	)	)


if __name__ == "__main__":  # useful to run the profiler
		benchmark_iterating()








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


lowerCamelCase						=		logging.get_logger(__name__)

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

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

lowerCamelCase						=		{
    '''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'''
        ),
    },
}
lowerCamelCase						=		{f'''funnel-transformer/{name}''': 512 for name in _model_names}
lowerCamelCase						=		{f'''funnel-transformer/{name}''': {'''do_lower_case''': True} for name in _model_names}





class  _a							(    _lowercase):
	_a  :  Tuple				   =							VOCAB_FILES_NAMES
	_a  :  Dict				   =							PRETRAINED_VOCAB_FILES_MAP
	_a  :  Dict				   =							PRETRAINED_INIT_CONFIGURATION
	_a  :  Union[str, Any]				   =							FunnelTokenizer
	_a  :  int				   =							PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
	_a  :  int				   =							2




	def __init__( self						:		List[Any]		, _SCREAMING_SNAKE_CASE						:		str=None		, _SCREAMING_SNAKE_CASE						:		str=None		, _SCREAMING_SNAKE_CASE						:		Any=True		, _SCREAMING_SNAKE_CASE						:		Any="<unk>"		, _SCREAMING_SNAKE_CASE						:		Dict="<sep>"		, _SCREAMING_SNAKE_CASE						:		Optional[int]="<pad>"		, _SCREAMING_SNAKE_CASE						:		str="<cls>"		, _SCREAMING_SNAKE_CASE						:		List[str]="<mask>"		, _SCREAMING_SNAKE_CASE						:		Optional[int]="<s>"		, _SCREAMING_SNAKE_CASE						:		Dict="</s>"		, _SCREAMING_SNAKE_CASE						:		Any=True		, _SCREAMING_SNAKE_CASE						:		Dict=True		, _SCREAMING_SNAKE_CASE						:		Tuple=None		, _SCREAMING_SNAKE_CASE						:		str="##"		, **_SCREAMING_SNAKE_CASE						:		List[str]		, )->	List[str]:
			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		, )

			lowerCAmelCase__       :      Any   					= 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
			):
					lowerCAmelCase__       :      int   					= getattr(_SCREAMING_SNAKE_CASE		, normalizer_state.pop('''type'''		)		)
					lowerCAmelCase__       :      Dict   					= do_lower_case
					lowerCAmelCase__       :      str   					= strip_accents
					lowerCAmelCase__       :      Dict   					= tokenize_chinese_chars
					lowerCAmelCase__       :      str   					= normalizer_class(**_SCREAMING_SNAKE_CASE		)

			lowerCAmelCase__       :      List[Any]   					= do_lower_case




	def 							UpperCAmelCase__( self						:		Any		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]=None		)->	Optional[int]:
			lowerCAmelCase__       :      Tuple   					= [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 							UpperCAmelCase__( self						:		Optional[Any]		, _SCREAMING_SNAKE_CASE						:		List[int]		, _SCREAMING_SNAKE_CASE						:		Optional[List[int]] = None		)->	List[int]:
			lowerCAmelCase__       :      str   					= [self.sep_token_id]
			lowerCAmelCase__       :      Optional[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 							UpperCAmelCase__( self						:		str		, _SCREAMING_SNAKE_CASE						:		str		, _SCREAMING_SNAKE_CASE						:		Optional[str] = None		)->	Tuple[str]:
			lowerCAmelCase__       :      Any   					= self._tokenizer.model.save(_SCREAMING_SNAKE_CASE		, name=_SCREAMING_SNAKE_CASE		)
			return tuple(_SCREAMING_SNAKE_CASE		)




