






import itertools
from dataclasses import dataclass
from typing import Any, Callable, Dict, List, Optional, Union

import pandas as pd
import pyarrow as pa

import datasets
import datasets.config
from datasets.features.features import require_storage_cast
from datasets.table import table_cast
from datasets.utils.py_utils import Literal


__UpperCAmelCase							:   int							=  datasets.utils.logging.get_logger(__name__)

__UpperCAmelCase							:   List[Any]							=  ["names", "prefix"]
__UpperCAmelCase							:   Dict							=  ["warn_bad_lines", "error_bad_lines", "mangle_dupe_cols"]
__UpperCAmelCase							:   Optional[int]							=  ["encoding_errors", "on_bad_lines"]
__UpperCAmelCase							:   Optional[int]							=  ["date_format"]


@dataclass
class 					_snake_case						(			datasets.BuilderConfig ):
	_A          =   ","
	_A          =   None
	_A          =   "infer"
	_A          =   None
	_A          =   None
	_A          =   None
	_A          =   None
	_A          =   None
	_A          =   True
	_A          =   None
	_A          =   None
	_A          =   None
	_A          =   None
	_A          =   False
	_A          =   None
	_A          =   None
	_A          =   None
	_A          =   True
	_A          =   True
	_A          =   False
	_A          =   True
	_A          =   None
	_A          =   "."
	_A          =   None
	_A          =   '"'
	_A          =   0
	_A          =   None
	_A          =   None
	_A          =   None
	_A          =   None
	_A          =   True
	_A          =   True
	_A          =   0
	_A          =   True
	_A          =   False
	_A          =   None
	_A          =   10000
	_A          =   None
	_A          =   "strict"
	_A          =   "error"
	_A          =   None






	def    lowerCAmelCase_							(		self       )						->    str:
					if self.delimiter is not None:
									snake_case__      :str         =   self.delimiter
					if self.column_names is not None:
									snake_case__      :List[str]         =   self.column_names






	@property
	def    lowerCAmelCase_							(		self       )						->    List[Any]:
					snake_case__      :str         =   {
					    "sep": self.sep,
					    "header": self.header,
					    "names": self.names,
					    "index_col": self.index_col,
					    "usecols": self.usecols,
					    "prefix": self.prefix,
					    "mangle_dupe_cols": self.mangle_dupe_cols,
					    "engine": self.engine,
					    "converters": self.converters,
					    "true_values": self.true_values,
					    "false_values": self.false_values,
					    "skipinitialspace": self.skipinitialspace,
					    "skiprows": self.skiprows,
					    "nrows": self.nrows,
					    "na_values": self.na_values,
					    "keep_default_na": self.keep_default_na,
					    "na_filter": self.na_filter,
					    "verbose": self.verbose,
					    "skip_blank_lines": self.skip_blank_lines,
					    "thousands": self.thousands,
					    "decimal": self.decimal,
					    "lineterminator": self.lineterminator,
					    "quotechar": self.quotechar,
					    "quoting": self.quoting,
					    "escapechar": self.escapechar,
					    "comment": self.comment,
					    "encoding": self.encoding,
					    "dialect": self.dialect,
					    "error_bad_lines": self.error_bad_lines,
					    "warn_bad_lines": self.warn_bad_lines,
					    "skipfooter": self.skipfooter,
					    "doublequote": self.doublequote,
					    "memory_map": self.memory_map,
					    "float_precision": self.float_precision,
					    "chunksize": self.chunksize,
					    "encoding_errors": self.encoding_errors,
					    "on_bad_lines": self.on_bad_lines,
					    "date_format": self.date_format,
					}

					# some kwargs must not be passed if they don't have a default value
					# some others are deprecated and we can also not pass them if they are the default value
					for pd_read_csv_parameter in _PANDAS_READ_CSV_NO_DEFAULT_PARAMETERS + _PANDAS_READ_CSV_DEPRECATED_PARAMETERS:
									if pd_read_csv_kwargs[pd_read_csv_parameter] == getattr(CsvConfig()					,UpperCamelCase       ):
													del pd_read_csv_kwargs[pd_read_csv_parameter]

        # Remove 2.0 new arguments
					if not (datasets.config.PANDAS_VERSION.major >= 2):
									for pd_read_csv_parameter in _PANDAS_READ_CSV_NEW_2_0_0_PARAMETERS:
													del pd_read_csv_kwargs[pd_read_csv_parameter]

        # Remove 1.3 new arguments
					if not (datasets.config.PANDAS_VERSION.major >= 1 and datasets.config.PANDAS_VERSION.minor >= 3):
									for pd_read_csv_parameter in _PANDAS_READ_CSV_NEW_1_3_0_PARAMETERS:
													del pd_read_csv_kwargs[pd_read_csv_parameter]

					return pd_read_csv_kwargs




class 					_snake_case						(			datasets.ArrowBasedBuilder ):
	_A          =   CsvConfig






	def    lowerCAmelCase_							(		self       )						->    Tuple:
					return datasets.DatasetInfo(features=self.config.features       )






	def    lowerCAmelCase_							(		self					,UpperCamelCase       )						->    List[Any]:
					if not self.config.data_files:
									raise ValueError(f'At least one data file must be specified, but got data_files={self.config.data_files}'       )
					snake_case__      :Optional[int]         =   dl_manager.download_and_extract(self.config.data_files       )
					if isinstance(UpperCamelCase					,(str, list, tuple)       ):
									snake_case__      :Dict         =   data_files
									if isinstance(UpperCamelCase					,UpperCamelCase       ):
													snake_case__      :Dict         =   [files]
									snake_case__      :Dict         =   [dl_manager.iter_files(UpperCamelCase       ) for file in files]
									return [datasets.SplitGenerator(name=datasets.Split.TRAIN					,gen_kwargs={"files": files}       )]
					snake_case__      :List[Any]         =   []
					for split_name, files in data_files.items():
									if isinstance(UpperCamelCase					,UpperCamelCase       ):
													snake_case__      :int         =   [files]
									snake_case__      :Union[str, Any]         =   [dl_manager.iter_files(UpperCamelCase       ) for file in files]
									splits.append(datasets.SplitGenerator(name=UpperCamelCase					,gen_kwargs={"files": files}       )       )
					return splits






	def    lowerCAmelCase_							(		self					,UpperCamelCase       )						->    pa.Table:
					if self.config.features is not None:
									snake_case__      :str         =   self.config.features.arrow_schema
									if all(not require_storage_cast(UpperCamelCase       ) for feature in self.config.features.values()       ):
													# cheaper cast
													snake_case__      :List[Any]         =   pa.Table.from_arrays([pa_table[field.name] for field in schema]					,schema=UpperCamelCase       )
									else:
													# more expensive cast; allows str <-> int/float or str to Audio for example
													snake_case__      :Optional[int]         =   table_cast(UpperCamelCase					,UpperCamelCase       )
					return pa_table






	def    lowerCAmelCase_							(		self					,UpperCamelCase       )						->    Optional[int]:
					snake_case__      :Dict         =   self.config.features.arrow_schema if self.config.features else None
					# dtype allows reading an int column as str
					snake_case__      :str         =   (
					    {
					        name: dtype.to_pandas_dtype() if not require_storage_cast(UpperCamelCase       ) else object
					        for name, dtype, feature in zip(schema.names					,schema.types					,self.config.features.values()       )
					    }
					    if schema is not None
					    else None
					)
					for file_idx, file in enumerate(itertools.chain.from_iterable(UpperCamelCase       )       ):
									snake_case__      :Optional[Any]         =   pd.read_csv(UpperCamelCase					,iterator=UpperCamelCase					,dtype=UpperCamelCase					,**self.config.pd_read_csv_kwargs       )
									try:
													for batch_idx, df in enumerate(UpperCamelCase       ):
																	snake_case__      :Union[str, Any]         =   pa.Table.from_pandas(UpperCamelCase       )
																	# Uncomment for debugging (will print the Arrow table size and elements)
																	# logger.warning(f"pa_table: {pa_table} num rows: {pa_table.num_rows}")
																	# logger.warning('\n'.join(str(pa_table.slice(i, 1).to_pydict()) for i in range(pa_table.num_rows)))
																	yield (file_idx, batch_idx), self._cast_table(UpperCamelCase       )
									except ValueError as e:
													logger.error(f'Failed to read file \'{file}\' with error {type(UpperCamelCase       )}: {e}'       )
													raise







from typing import List, Optional, Tuple

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_herbert import HerbertTokenizer


__UpperCAmelCase							:   str							=  logging.get_logger(__name__)

__UpperCAmelCase							:   List[Any]							=  {"vocab_file": "vocab.json", "merges_file": "merges.txt", "tokenizer_file": "tokenizer.json"}

__UpperCAmelCase							:   List[Any]							=  {
    "vocab_file": {
        "allegro/herbert-base-cased": "https://huggingface.co/allegro/herbert-base-cased/resolve/main/vocab.json"
    },
    "merges_file": {
        "allegro/herbert-base-cased": "https://huggingface.co/allegro/herbert-base-cased/resolve/main/merges.txt"
    },
}

__UpperCAmelCase							:   str							=  {"allegro/herbert-base-cased": 5_1_4}
__UpperCAmelCase							:   List[str]							=  {}


class 					_snake_case						(			_A ):
	_A          =   VOCAB_FILES_NAMES
	_A          =   PRETRAINED_VOCAB_FILES_MAP
	_A          =   PRETRAINED_INIT_CONFIGURATION
	_A          =   PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
	_A          =   HerbertTokenizer






	def __init__(		self					,UpperCamelCase=None					,UpperCamelCase=None					,UpperCamelCase=None					,UpperCamelCase="<s>"					,UpperCamelCase="<unk>"					,UpperCamelCase="<pad>"					,UpperCamelCase="<mask>"					,UpperCamelCase="</s>"					,**UpperCamelCase					,)						->    Dict:
					super().__init__(
					    UpperCamelCase					,UpperCamelCase					,tokenizer_file=UpperCamelCase					,cls_token=UpperCamelCase					,unk_token=UpperCamelCase					,pad_token=UpperCamelCase					,mask_token=UpperCamelCase					,sep_token=UpperCamelCase					,**UpperCamelCase					,)






	def    lowerCAmelCase_							(		self					,UpperCamelCase					,UpperCamelCase = None       )						->    List[int]:
					snake_case__      :Optional[int]         =   [self.cls_token_id]
					snake_case__      :Any         =   [self.sep_token_id]
					if token_ids_a is None:
									return cls + token_ids_a + sep

					return cls + token_ids_a + sep + token_ids_a + sep






	def    lowerCAmelCase_							(		self					,UpperCamelCase					,UpperCamelCase = None					,UpperCamelCase = False       )						->    List[int]:
					if already_has_special_tokens:
									return super().get_special_tokens_mask(
									    token_ids_a=UpperCamelCase					,token_ids_a=UpperCamelCase					,already_has_special_tokens=UpperCamelCase       )

					if token_ids_a is None:
									return [1] + ([0] * len(UpperCamelCase       )) + [1]
					return [1] + ([0] * len(UpperCamelCase       )) + [1] + ([0] * len(UpperCamelCase       )) + [1]






	def    lowerCAmelCase_							(		self					,UpperCamelCase					,UpperCamelCase = None       )						->    List[int]:
					snake_case__      :Any         =   [self.sep_token_id]
					snake_case__      :Union[str, Any]         =   [self.cls_token_id]

					if token_ids_a is None:
									return len(cls + token_ids_a + sep       ) * [0]
					return len(cls + token_ids_a + sep       ) * [0] + len(token_ids_a + sep       ) * [1]






	def    lowerCAmelCase_							(		self					,UpperCamelCase					,UpperCamelCase = None       )						->    Tuple[str]:
					snake_case__      :List[str]         =   self._tokenizer.model.save(UpperCamelCase					,name=UpperCamelCase       )
					return tuple(UpperCamelCase       )