
import json
import os
import tempfile

import transformers

import datasets
from utils import generate_example_dataset, get_duration


lowerCamelCase__	=							50_0000

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


@get_duration
def 							__A(lowerCAmelCase						,  **lowerCAmelCase )		->				List[Any]:

		"""simple docstring"""






		_UpperCamelCase						    =	dataset.map(**lowerCAmelCase )


@get_duration
def 							__A(lowerCAmelCase						,  **lowerCAmelCase )		->				int:

		"""simple docstring"""






		_UpperCamelCase						    =	dataset.filter(**lowerCAmelCase )


def 							__A()		->				List[str]:

		"""simple docstring"""






		_UpperCamelCase						    =	{"""num examples""": SPEED_TEST_N_EXAMPLES}
		with tempfile.TemporaryDirectory() as tmp_dir:
				_UpperCamelCase						    =	datasets.Features({"""text""": datasets.Value("""string""" ), """numbers""": datasets.Value("""float32""" )} )
				_UpperCamelCase						    =	generate_example_dataset(
				    os.path.join(lowerCAmelCase						,  """dataset.arrow""" )						,  lowerCAmelCase						,  num_examples=lowerCAmelCase )

				_UpperCamelCase						    =	transformers.AutoTokenizer.from_pretrained("""bert-base-cased"""						,  use_fast=lowerCAmelCase )

				def tokenize(lowerCAmelCase ):
						return tokenizer(examples["""text"""] )

				_UpperCamelCase						    =	map(lowerCAmelCase )

				_UpperCamelCase						    =	map(lowerCAmelCase						,  batched=lowerCAmelCase )

				_UpperCamelCase						    =	map(lowerCAmelCase						,  function=lambda lowerCAmelCase : None						,  batched=lowerCAmelCase )

				with dataset.formatted_as(type="""numpy""" ):
						_UpperCamelCase						    =	map(lowerCAmelCase						,  function=lambda lowerCAmelCase : None						,  batched=lowerCAmelCase )

				with dataset.formatted_as(type="""pandas""" ):
						_UpperCamelCase						    =	map(lowerCAmelCase						,  function=lambda lowerCAmelCase : None						,  batched=lowerCAmelCase )

				with dataset.formatted_as(type="""torch"""						,  columns="""numbers""" ):
						_UpperCamelCase						    =	map(lowerCAmelCase						,  function=lambda lowerCAmelCase : None						,  batched=lowerCAmelCase )

				with dataset.formatted_as(type="""tensorflow"""						,  columns="""numbers""" ):
						_UpperCamelCase						    =	map(lowerCAmelCase						,  function=lambda lowerCAmelCase : None						,  batched=lowerCAmelCase )

				_UpperCamelCase						    =	map(lowerCAmelCase						,  function=lowerCAmelCase						,  batched=lowerCAmelCase )

				_UpperCamelCase						    =	filter(lowerCAmelCase )

				# Activate later when tokenizer support batched inputs
				# with dataset.formatted_as(type='numpy'):
				#     times[func.__name__ + " fast-tokenizer batched numpy"] = func(dataset, function=tokenize, batched=True)

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


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





from typing import TYPE_CHECKING

from ....utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowerCamelCase__	=							{
    "configuration_mctct": ["MCTCT_PRETRAINED_CONFIG_ARCHIVE_MAP", "MCTCTConfig"],
    "feature_extraction_mctct": ["MCTCTFeatureExtractor"],
    "processing_mctct": ["MCTCTProcessor"],
}


try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowerCamelCase__	=							[
		    "MCTCT_PRETRAINED_MODEL_ARCHIVE_LIST",
		    "MCTCTForCTC",
		    "MCTCTModel",
		    "MCTCTPreTrainedModel",
		]


if TYPE_CHECKING:
		from .configuration_mctct import MCTCT_PRETRAINED_CONFIG_ARCHIVE_MAP, MCTCTConfig
		from .feature_extraction_mctct import MCTCTFeatureExtractor
		from .processing_mctct import MCTCTProcessor

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_mctct import MCTCT_PRETRAINED_MODEL_ARCHIVE_LIST, MCTCTForCTC, MCTCTModel, MCTCTPreTrainedModel

else:
		import sys

		lowerCamelCase__	=							_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)



