/usr/local/lib/python3.6/site-packages/datasets/__pycache__
NameSizeModeActions
arrow_dataset.cpython-36.pyc1898500644editdlrm
arrow_reader.cpython-36.pyc224830644editdlrm
arrow_writer.cpython-36.pyc221100644editdlrm
builder.cpython-36.pyc527790644editdlrm
combine.cpython-36.pyc55080644editdlrm
config.cpython-36.pyc51810644editdlrm
dataset_dict.cpython-36.pyc833190644editdlrm
data_files.cpython-36.pyc301530644editdlrm
fingerprint.cpython-36.pyc189790644editdlrm
info.cpython-36.pyc173590644editdlrm
inspect.cpython-36.pyc185830644editdlrm
iterable_dataset.cpython-36.pyc629320644editdlrm
keyhash.cpython-36.pyc33410644editdlrm
load.cpython-36.pyc629220644editdlrm
metric.cpython-36.pyc232170644editdlrm
naming.cpython-36.pyc25710644editdlrm
search.cpython-36.pyc313390644editdlrm
splits.cpython-36.pyc225220644editdlrm
streaming.cpython-36.pyc41190644editdlrm
table.cpython-36.pyc796120644editdlrm
__init__.cpython-36.pyc22820644editdlrm
Edit: /usr/local/lib/python3.6/site-packages/datasets/__pycache__/load.cpython-36.pyc (62922B)
3 <%EgR@s~dZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z ddlmZmZmZmZmZmZmZmZddlZddlZddlmZmZdd lmZdd lmZdd l m!Z!dd l"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*dd l+m,Z,m-Z-ddl.m/Z/ddl0m1Z1ddl2m3Z3m4Z4m5Z5ddl6m7Z7ddl8m9Z9m:Z:ddl;mm?Z?ddl@mAZAddlBmCZCmDZDmEZEmFZFddlGmHZHddlImJZJddlKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUddlVmWZWddlXmYZYddlZm[Z[ddl\m]Z]ddl^m_Z_e[e`ZaebeCjcdgZdejedfefeee effd d!d"Zgdjeeee!eeAfd$d%d&Zheefefd'd(d)Ziefefd*d+d,Zjefefeefefefeffee/eeefeffd-d.d/Zkefefefefeeefeffeeefeffee1efd0d1d2Zlefeeefeffeeefeffefefefe1eefeffd3d4d5Zmdke%eeeneffeeefeffd6d7d8Zoe%eeeneffeeefeffd6d9d:Zpe Gd;d<d<Zqe Gd=d>d>ZrGd?d@d@ZsGdAdBdBZtGdCdDdDesZuGdEdFdFetZvGdGdHdHetZwGdIdJdJesZxGdKdLdLesZyGdMdNdNesZzGdOdPdPesZ{GdQdRdResZ|GdSdTdTesZ}GdUdVdVetZ~dlefeeefe_fee/ee1eefeefeeeeefe$feqdWdXdYZdmefeeefe_fee/ee1eeferdZd[d\Zdnefeefeeeefeefenee/ee1eeefe_feAd^ d_d`Zdoefeefeefeeefeefeefeefeeffffeefee7ee/ee1eeefe_feeeneffe!da dbdcZdpefeefeefeeefeefeefeefeeffffeeefeHfeefee7ee/ee1eneeneneeefe_feeeneffeeefeJfenee,ee-e?fdddedfZdqefeeneee,fdgdhdiZdS)rzAccess datasets.N)Counter) dataclass)Path)DictListMappingOptionalSequenceTupleTypeUnion)HfApiHfFolder)config)Dataset)DatasetBuilder)DEFAULT_PATTERNS_ALL DataFilesDict DataFilesList'get_data_patterns_in_dataset_repositoryget_data_patterns_locally+get_metadata_patterns_in_dataset_repositoryget_metadata_patterns_locallysanitize_patterns) DatasetDictIterableDatasetDict)DownloadConfig) DownloadMode)StreamingDownloadManagerxglobxjoin)Features)extract_path_from_uriis_remote_filesystem) DatasetInfoDatasetInfosDict)IterableDataset)Metric)_EXTENSION_TO_MODULE_MODULE_SUPPORTS_METADATA_PACKAGED_DATASETS_MODULES_hash_python_lines)Split) TaskTemplate) OfflineModeIsEnabled!_raise_if_offline_mode_is_enabled cached_path head_hf_s3 hf_github_url hf_hub_urlinit_hf_modulesis_relative_pathrelative_to_absolute_pathurl_or_path_join)FileLock)is_small_dataset) get_logger) get_imports)Versionzip)namehf_modules_cachec Cs^t|}tjj||}tj|ddtjjtjj|dsZttjj|ddWdQRX|S)a] Create a module with name `name` in which you can add dynamic modules such as metrics or datasets. The module can be imported using its name. The module is created in the HF_MODULE_CACHE directory by default (~/.cache/huggingface/modules) but it can be overriden by specifying a path to another directory in `hf_modules_cache`. T)exist_okz __init__.pywN)r5ospathjoinmakedirsexistsopen)r?r@dynamic_modules_pathrJ7/usr/local/lib/python3.6/site-packages/datasets/load.pyinit_dynamic_modulesWs  rLT)returncCsxtj|}|rt}nt}d}xV|jjD]H\}}tj|r(t||r(tj |rPq(|}tj |}|dk r(||kr(Pq(W|S)zImport a module at module_path and return its main class: - a DatasetBuilder if dataset is True - a Metric if dataset is False N) importlib import_modulerr(__dict__itemsinspectisclass issubclass isabstract getmodule) module_pathdatasetmoduleZ main_cls_typeZmodule_main_clsr?objZ obj_modulerJrJrKimport_main_classis   r[) file_pathsrMc Csg}x<|D]4}tjj|r4|jtt|jdq |j|q Wg}x2|D]*}t|dd}|j|j WdQRXqLWt |S)zt Convert a list of scripts or text files provided in file_paths into a hashed filename in a repeatable way. z *.[pP][yY]zutf-8)encodingN) rCrDisdirextendlistrrglobappendrH readlinesr,)r\Z to_use_files file_pathlinesfrJrJrK files_to_hashs   rg)r? resource_typec CsBtj r>tjr>yt||d|dkdWntk r<YnXdS)z1Update the download count of a dataset or metric.z.pyrX)filenamerXN)rHF_DATASETS_OFFLINEZHF_UPDATE_DOWNLOAD_COUNTSr2 Exception)r?rhrJrJrKincrease_load_counts rl)r? base_pathimportsdownload_configrMc Csg}g}|j}|jdkr d|_x|D]\}}}} |dkrJ|j||fq&||krttd|d|d|d|d |d krt||d } n|d kr|} ntd t| |d } | dk rtjj| | } |j|| fq&Wi} xR|D]J\} }yt j | }Wqt k r(| | ks|| kr$|| | <YqXqW| rt | dkrFdnd}t | dkr\dnd}t d|d|ddj| d|ddj| j d |S)a Download additional module for a module .py at URL (or local path) /.py The imports must have been parsed first using ``get_imports``. If some modules need to be installed with pip, an error is raised showing how to install them. This function return the list of downloaded modules as tuples (import_name, module_file_path). The downloaded modules can then be moved into an importable directory with ``_copy_script_and_other_resources_in_importable_dir``. NzDownloading extra moduleslibraryz Error in the z script, importing relative z module but z: is the name of the script. Please change relative import zl to another name and add a '# From: URL_OR_PATH' comment pointing to the original relative import file path.Zinternalz.pyZexternalzWrong import_type)ror dependencies dependencyZthemitzTo be able to use z$, you need to install the following z: z, z. Please install z using 'pip install  z' for instance')copy download_descrb ValueErrorr8r1rCrDrErNrO ImportErrorlenvalues)r?rmrnro local_importsZlibrary_importsZ import_type import_name import_pathZ sub_directoryZurl_or_filenameZlocal_import_pathZneeds_to_be_installedZlibrary_import_nameZlibrary_import_pathlibZ_depencencies_strZ _them_strrJrJrK_download_additional_modulessH   6r)r?importable_directory_pathsubdirectory_nameoriginal_local_pathr{additional_files download_moderMc!Cs,tjj||}tjj||d}|d} t| |tjkrTtjj|rTtj|tj |ddtjj|d} tjj| st | dWdQRXtj |ddtjj|d} tjj| st | dWdQRXtjj|stj ||tjj |dd } tjj| s:||d } t | dd d } t j| | WdQRXx|D]\}}tjj|rtjj||d}tjj|stj ||nFtjj|rtjj||}tjj|stj||ntd |q@WxL|D]D\}}tjj||}tjj| s tj|| rtj ||qW|SQRXdS)aCopy a script and its required imports to an importable directory Args: name (str): name of the resource to load importable_directory_path (str): path to the loadable folder in the dynamic modules directory subdirectory_name (str): name of the subdirectory in importable_directory_path in which to place the script original_local_path (str): local path to the resource script local_imports (List[Tuple[str, str]]): list of (destination_filename, import_file_to_copy) additional_files (List[Tuple[str, str]]): list of (destination_filename, additional_file_to_copy) download_mode (Optional[DownloadMode]): download mode Return: importable_local_file: path to an importable module with importlib.import_module z.pyz.lockT)rAz __init__.pyrBNrz.json)zoriginal file pathzlocal file pathzutf-8)r]zError with local import at )rCrDrEr9rFORCE_REDOWNLOADrGshutilrmtreerFrHcopyfilesplitextjsondumpisfiler^copytreeOSErrorfilecmpcmp)r?rrrr{rrZimportable_subdirectoryimportable_local_fileZ lock_pathZinit_file_path meta_pathmetaZ meta_filer|r}Zfull_path_local_import file_nameZ original_pathZdestination_additional_pathrJrJrK2_copy_script_and_other_resources_in_importable_dirsN            r) local_pathr{rrImodule_namespacer?rrMc Cstjj|||jdd}t|jdddt|jdjddt|gdd|D}t |j dd ||||||d } t j d | d jtjj |||jdd||j ddg} | |fS)N/z--T)parentsrAz __init__.py)rAcSsg|] }|dqS)rrJ).0locrJrJrK Asz+_create_importable_file..r)r?rrrr{rrz#Created importable dataset file at .r)rCrDrEreplacermkdirparenttouchrgrsplitloggerdebugbasename) rr{rrIrr?rrhashrrWrJrJrK_create_importable_file5s  *r)data_files_listuse_auth_tokenrMcCs^tdd|dtjD}|rZx8|jD],\}}|tkrBt|S|dkr*t||dSq*WdS)aInfer module (and builder kwargs) from list of data files. Args: data_files_list (DataFilesList): List of data files. use_auth_token (bool or str, optional): Whether to use token or token to authenticate on the Hugging Face Hub for private remote files. Returns: tuple[str, str]: Tuple with - inferred module name - builder kwargs css*|]"}t|jD]}|ddVqqdS)rN)rsuffixes)rfilepathsuffixrJrJrK bsz.infer_module_for_data_files..Nr>)r)rrZ*DATA_FILES_MAX_NUMBER_FOR_MODULE_INFERENCE most_commonr)'infer_module_for_data_files_in_archives)rrextensions_counterext_rJrJrKinfer_module_for_data_filesRsrcCsg}d}xf|D]^}t|jdr|d7}|tjkr4Pttj|d}|ddt|d|dd tjD7}qWt d d |D}|r|j ddd}|t krt |Sd S) aInfer module (and builder kwargs) from list of archive data files. Args: data_files_list (DataFilesList): List of data files. use_auth_token (bool or str, optional): Whether to use token or token to authenticate on the Hugging Face Hub for private remote files. Returns: tuple[str, str]: Tuple with - inferred module name - builder kwargs rz.ziprz**cSsg|]}|jddqS)z::r)r)rrfrJrJrKrsz;infer_module_for_data_files_in_archives..T) recursiverNcss*|]"}t|jD]}|ddVqqdS)rN)rr)rrrrJrJrKrsz:infer_module_for_data_files_in_archives..) strendswithrZ2GLOBBED_DATA_FILES_MAX_NUMBER_FOR_MODULE_INFERENCEr!rextractr Z3ARCHIVED_DATA_FILES_MAX_NUMBER_FOR_MODULE_INFERENCErrr))rrZarchived_filesZarchive_files_counterrZ extractedrrrJrJrKrns"  rc@seZdZUeeedS) DatasetModuleN)__name__ __module__ __qualname__rrWrdictbuilder_kwargsrJrJrJrKrs rc@seZdZUeedS) MetricModuleN)rrrrrWrrJrJrJrKrs rc@seZdZedddZdS)_DatasetModuleFactory)rMcCstdS)N)NotImplementedError)selfrJrJrK get_modulesz _DatasetModuleFactory.get_moduleN)rrrrrrJrJrJrKrsrc@seZdZedddZdS)_MetricModuleFactory)rMcCstdS)N)r)rrJrJrKrsz_MetricModuleFactory.get_moduleN)rrrrrrJrJrJrKrsrc@sveZdZdZdeeeeefeeee eedddZ eeedddZ eeedd d Z e d d d ZdS)GithubDatasetModuleFactoryz Get the module of a dataset from GitHub (legacy). The dataset script is downloaded from GitHub. This class will eventually be removed and a HubDatasetModuleFactory will be used instead. N)r?revisionrorrIcCsd||_||_|r|jnt|_|jjdkr4d|j_||_||_|jjddksTt t |dddS)NrrrX)rh) r?rrurro max_retriesrrIcountAssertionErrorrl)rr?rrorrIrJrJrK__init__s z#GithubDatasetModuleFactory.__init__)rrMcCs<t|j|jd|d}|jj}|jdkr0d|_t||dS)Nz.py)rDr?rzDownloading builder script)ro)r3r?rorurvr1)rrrdrorJrJrKdownload_loading_scripts   z2GithubDatasetModuleFactory.download_loading_scriptc CsVt|jtj|d}|jj}|jdkr,d|_y t||dStt fk rPdSXdS)N)rDr?rzDownloading metadata)ro) r3r?rDATASETDICT_INFOS_FILENAMErorurvr1FileNotFoundErrorConnectionError)rr dataset_infosrorJrJrKdownload_dataset_infos_files  z6GithubDatasetModuleFactory.download_dataset_infos_file)rMc Cs |j}y|j|}WnRtk rf|dk st|j|jd|dd}|jj}|jdkr2d|_t||dS)Nz.pyF)rDr?rrXzDownloading builder script)ro)r3r?rorurvr1)rrrdrorJrJrKrs   z1GithubMetricModuleFactory.download_loading_script)rMcCs|j}y|j|}|j}WnRtk rl|dk sBtjdddk rFn"d}|j|}tjd|jdYnXt|}t |jt |jd|dd||j d}|j r|j nt }t||g|d |j|jd \}}tjt||S) Nrrz-Couldn't find a directory or a metric named 'zH' in this version. It was picked from the main branch on github instead.rF)rDr?rrX)r?rmrnrometrics)rr{rrIrr?r)rrrrCrrrr?r<rr3rorIrLrrrNrr)rrrrnr{rIrWrrJrJrKrs8    z$GithubMetricModuleFactory.get_module)NNNN)rrrrrrr r=rrrrrrrJrJrJrKrs0 rc@s@eZdZdZd eeeeeeedddZe dddZ dS) LocalMetricModuleFactoryzRGet the module of a local metric. The metric script is loaded from a local script.N)rDrorrIcCs.||_t|j|_|pt|_||_||_dS)N)rDrstemr?rrorrI)rrDrorrIrJrJrKrFs   z!LocalMetricModuleFactory.__init__)rMc Csnt|j}t|jtt|jj||jd}|jr6|jnt }t |j|g|d|j|j d\}}t j t||S)N)r?rmrnror)rr{rrIrr?r)r<rDrr?rrrrorIrLrrrNrr)rrnr{rIrWrrJrJrKrSs"  z#LocalMetricModuleFactory.get_module)NNN) rrrrrrrrrrrrJrJrJrKrCs "rc@s@eZdZdZd eeeeeeedddZe dddZ dS) #LocalDatasetModuleFactoryWithScriptzTGet the module of a local dataset. The dataset script is loaded from a local script.N)rDrorrIcCs.||_t|j|_|pt|_||_||_dS)N)rDrrr?rrorrI)rrDrorrIrJrJrKros   z,LocalDatasetModuleFactoryWithScript.__init__)rMc Cst|jjtj}t|j}t|jtt|jj||j d}|j rTtjt|fgng}|j rd|j nt }t |j|||d|j|jd\}}tj|tt|jjd}t|||S)N)r?rmrnror)rr{rrIrr?r)rrm)rrDrrrr<rr?rrois_filerIrLrrrNrr) rrrnr{rrIrWrrrJrJrKr|s(  z.LocalDatasetModuleFactoryWithScript.get_module)NNN) rrrrrrrrrrrrJrJrJrKrls "rc@sJeZdZdZd eeeeeeeefee dddZ e dddZ dS) &LocalDatasetModuleFactoryWithoutScriptzGet the module of a dataset loaded from the user's data files. The dataset builder module to use is inferred from the data files extensions.N)rDdata_dir data_filesrcCsF|rtjj|rtd|||_t|j|_||_||_||_ dS)Nz;`data_dir` must be relative to a dataset directory's root: ) rCrDisabsrwrrr?rrr)rrDrrrrJrJrKrs z/LocalDatasetModuleFactoryWithoutScript.__init__)rMcCs|jrtjj|j|jn|j}|jdk r2t|jn|jdk rDt|nt|}tj||t d}dd|j D}t t t t|jddkrtd|tt|j\}}|std|j|jdko|tko|tkrRy t|}Wntk rd}YnX|dk rRtj||d}x0|D](} t|| ||| j|j|| <q&Wt|\} } | |tjj|j|jd |}tjjtjj|jtjrttjj|jtjd d } tj | } WdQRXtt| |d <t!j"| |d |d <t#| | |S)N)rmallowed_extensionscSsi|]\}}t||qSrJ)r)rkeyrrJrJrK szELocalDatasetModuleFactoryWithoutScript.get_module..rrz=Couldn't infer the same data file format for all splits. Got z)No data files or dataset script found in )rm)rr config_namermzutf-8)r]rinfo)$rrCrDrErrrrfrom_local_or_remoteALL_ALLOWED_EXTENSIONSrQrysetr`r>rzrwnextiterrr*rrrorigin_metadatar+rrrrrHrloadr% from_dictr)rrmpatternsr module_names module_namermetadata_patternsmetadata_filesrrWrrfrrJrJrKrsL         z1LocalDatasetModuleFactoryWithoutScript.get_module)NNN) rrrrrrr rrrrrrrJrJrJrKrs , rc@sPeZdZdZd eeeeeeeefee ee dddZ e dddZ dS) PackagedDatasetModuleFactoryz`Get the dataset builder module from the ones that are packaged with the library: csv, json, etc.N)r?rrrorcCs.||_||_||_||_||_t|dddS)NrX)rh)r?rrrorrl)rr?rrrorrJrJrKrs z%PackagedDatasetModuleFactory.__init__)rMc Cs|jdk rtt|jjn ttj}|jdk r>t|jn|jdk rPt|nt|}tj||j j |d}|jdkr|j t kr|t kry t|}Wntk rd}YnX|dk rtj||j j |d}x.|D]&}t|||||j|j||<qWt|j \}}||d} t||| S)N)rrm)rr)rrrresolverrrrrrorr?r*rrrrrr+r) rrmrrrrrrWrrrJrJrKrs.*     z'PackagedDatasetModuleFactory.get_module)NNNN)rrrrrrr rrrrrrrrJrJrJrKrs 2 rc @s^eZdZdZd eeeeefeeeeeee fee ee dddZ e dddZdS) $HubDatasetModuleFactoryWithoutScriptz Get the module of a dataset loaded from data files of a dataset repository. The dataset builder module to use is inferred from the data files extensions. N)r?rrrrorcCsN||_||_||_||_|p t|_||_|jjddks>tt |dddS)NrrrX)rh) r?rrrrrorrrrl)rr?rrrrorrJrJrKrs  z-HubDatasetModuleFactoryWithoutScript.__init__)rMcsntjjtr$jjrtjnd}njj}ttjj j j |rF|nddd}j dk rdt j n t|j}tj||jtd}fdd|jD}tttt|jddkrtd |tt|j\}}|std j j dkr|tkr|tkryt|j}Wntk r:d}YnX|dk rt j||jd } x0|D](} t || | || j!| j!|| <q^Wt"|\} } | |j j#d d t$j dj dj d|}jj%} | j&dkrd| _&yjt't$j tj(j djd}t)|dd}t*j+|}WdQRXtt||d<t,j-||d|d<Wntk r`YnXt.| | |S)Nzno-tokengY@)rtokentimeout) dataset_informrcs"i|]\}}t|jjd|qS))r)rror)rrr)rrJrKrDszCHubDatasetModuleFactoryWithoutScript.get_module..rrz=Couldn't infer the same data file format for all splits. Got z)No data files or dataset script found in )rrmrz--r)r)rrrrmrepo_idzDownloading metadata)rozutf-8)r]rr)/ isinstancerorboolr get_tokenr r HF_ENDPOINTrr?rrrrrrZ from_hf_reporrQryrr`r>rzrwrrrr*rrrrr+rr4rurvr1rrHrrr%rr)rrZhfh_dataset_inforrrrrrrrrWrrorrfrrJ)rrKr.sn                z/HubDatasetModuleFactoryWithoutScript.get_module)NNNNN)rrrrrrr r=rrrrrrrrJrJrJrKrs@ rc@sjeZdZdZd eeeeefeeee eedddZ edddZ edd d Z e dd d ZdS)!HubDatasetModuleFactoryWithScriptz~Get the module of a dataset from a dataset repository. The dataset script comes from the script inside the dataset repository.N)r?rrorrIcCsH||_||_|pt|_||_||_|jjddks8tt|dddS)NrrrX)rh) r?rrrorrIrrrl)rr?rrorrIrJrJrKrys z*HubDatasetModuleFactoryWithScript.__init__)rMcCsHt|j|jjddd|jd}|jj}|jdkr.zDataset z is not cached in cs&t|jjdddjjS)Nrrz.pyr)rr?rstatst_mtime) module_hash)rrrJrK_get_modification_timeszECachedDatasetModuleFactory.get_module.._get_modification_time)rrz3Using the latest cached version of the module from z (last modified on z() since it couldn't be found locally at rz&, or remotely on the Hugging Face Hub.)rrrr)rIrLrCrDrEr?rr^listdirrsortedtimectimerrjrrrrrNrr)rrIhashesr rZ warning_msgrWrrJ)rrrKrs, .    z%CachedDatasetModuleFactory.get_module)N) rrrrrrrrrrJrJrJrKrsrc@s4eZdZdZd eeedddZedddZdS) CachedMetricModuleFactoryz Get the module of a metric that has been loaded once already and cached. The script that is loaded from the cache is the most recent one with a matching name. N)r?rIcCs$||_||_|jjddks tdS)Nrr)r?rIrr)rr?rIrJrJrKrsz"CachedMetricModuleFactory.__init__)rMcsjr jnt}tjj|djtjjrDddtjDnd}|sbtdjd|fdd}t ||dd}t j d tjj|d t j ||d jd djtjj|dj|jg}tjt||S)NrcSsg|]}t|dkr|qS)r)ry)rrrJrJrKr sz8CachedMetricModuleFactory.get_module..zMetric z is not cached in cst|jdjjS)Nz.py)rr?rr)r )rrrJrKr szDCachedMetricModuleFactory.get_module.._get_modification_time)rrz3Using the latest cached version of the module from z (last modified on z() since it couldn't be found locally at z&, or remotely on the Hugging Face Hub.rr)rIrLrCrDrEr?r^r rr rrr rrrNrr)rrIrr rrWrJ)rrrKrs 0 z$CachedMetricModuleFactory.get_module)N) rrrrrrrrrrJrJrJrKrsr)rDrrorrIrrrMc!Ks|dkrtf|}t|ptj}d|_d|_|tjk|_ttdd|j t j dj dd%}|j dsp|d}t jj||} |tkrt|||||djS|j |rt jj|rt|||d jStd t|nt jj| rt| ||d jSt jj|rt||||d jSt|r|jddkryt|jdd krft|||||d jS|jddkrttj} yJt |j!t"r|j!rt#j$nd} n|j!} | j%||| r| nddd} Wnt&k r} zt | t't(j)j*t(j)j+frt+d|dt,| j-dndt.| krPd|d}t|rH|d|dn|nFdt.| krd|d}|r|d|dn|}t|dn| WYdd} ~ XnX|dd| j/Dkrt0|||||d jSt1||||||djSWnt&k r}zyt2||djSt&k r}zft |t'rHt+d|d |dt |trtd t| d!|d"t,|j-d#|d|dWYdd}~XnXWYdd}~XnXntd t| d$dS)&av Download/extract/cache a dataset module. Dataset codes are cached inside the the dynamic modules cache to allow easy import (avoid ugly sys.path tweaks). Args: path (str): Path or name of the dataset. Depending on ``path``, the dataset builder that is used comes from a generic dataset script (JSON, CSV, Parquet, text etc.) or from the dataset script (a python file) inside the dataset directory. For local datasets: - if ``path`` is a local directory (containing data files only) -> load a generic dataset builder (csv, json, text etc.) based on the content of the directory e.g. ``'./path/to/directory/with/my/csv/data'``. - if ``path`` is a local dataset script or a directory containing a local dataset script (if the script has the same name as the directory): -> load the dataset builder from the dataset script e.g. ``'./dataset/squad'`` or ``'./dataset/squad/squad.py'``. For datasets on the Hugging Face Hub (list all available datasets and ids with ``datasets.list_datasets()``) - if ``path`` is a dataset repository on the HF hub (containing data files only) -> load a generic dataset builder (csv, text etc.) based on the content of the repository e.g. ``'username/dataset_name'``, a dataset repository on the HF hub containing your data files. - if ``path`` is a dataset repository on the HF hub with a dataset script (if the script has the same name as the directory) -> load the dataset builder from the dataset script in the dataset repository e.g. ``glue``, ``squad``, ``'username/dataset_name'``, a dataset repository on the HF hub containing a dataset script `'dataset_name.py'`. revision (:class:`~utils.Version` or :obj:`str`, optional): Version of the dataset script to load: - For datasets in the `huggingface/datasets` library on GitHub like "squad", the default version of the module is the local version of the lib. You can specify a different version from your local version of the lib (e.g. "main" or "1.2.0") but it might cause compatibility issues. - For community datasets like "lhoestq/squad" that have their own git repository on the Datasets Hub, the default version "main" corresponds to the "main" branch. You can specify a different version that the default "main" by using a commit sha or a git tag of the dataset repository. download_config (:class:`DownloadConfig`, optional): Specific download configuration parameters. download_mode (:class:`DownloadMode`, default ``REUSE_DATASET_IF_EXISTS``): Download/generate mode. dynamic_modules_path (Optional str, defaults to HF_MODULES_CACHE / "datasets_modules", i.e. ~/.cache/huggingface/modules/datasets_modules): Optional path to the directory in which the dynamic modules are saved. It must have been initialized with :obj:`init_dynamic_modules`. By default the datasets and metrics are stored inside the `datasets_modules` module. data_dir (:obj:`str`, optional): Directory with the data files. Used only if `data_files` is not specified, in which case it's equal to passing `os.path.join(data_dir, "**")` as `data_files`. data_files (:obj:`Union[Dict, List, str]`, optional): Defining the data_files of the dataset configuration. **download_kwargs (additional keyword arguments): optional attributes for DownloadConfig() which will override the attributes in download_config if supplied. Returns: DatasetModule NTcSs|S)NrJ)xrJrJrKcsz(dataset_module_factory..rrz.py)rrror)rrIz"Couldn't find a dataset script at )rrrr)rrorrIzno-tokengY@)rrrrzCouldn't reach 'z' on the Hub ()Z404z Dataset 'z' doesn't exist on the Hubz at revision ''Z401z. If the repo is private, make sure you are authenticated with `use_auth_token=True` after logging in with `huggingface-cli login`.cSsg|] }|jqSrJ)Z rfilename)rZsiblingrJrJrKrsz*dataset_module_factory..)rrrror)rIz0Couln't reach the Hugging Face Hub for dataset 'z': z8 or any data file in the same directory. Couldn't find 'z"' on the Hugging Face Hub either: z: z( or any data file in the same directory.r)3rrREUSE_DATASET_IF_EXISTSextract_compressed_file force_extractrZforce_downloadr`filterrrCseprrrDrEr+rrrrrr7r^rr6rr0rr rrrrrrrrrkr/requests exceptionsConnectTimeoutrtyperrZsiblingsrrr)rDrrorrIrrdownload_kwargsri combined_pathZhf_apirremsge1e2rJrJrKdataset_module_factory"s:  &               &,r$)rDrrorrIrMc Ks|dkrtf|}t|ptj}d|_d|_ttdd|jtj dj dd}|j dsd|d}tj j ||}|j |rtj j|rt|||djStd t|ntj j|rt|||djSt|o|jdd kryt|||||d jStk r}zjyt||d jStk rp} z4t|tsD|dtd t|d |ddWYdd} ~ XnXWYdd}~XnXntd t|ddS)a Download/extract/cache a metric module. Metrics codes are cached inside the the dynamic modules cache to allow easy import (avoid ugly sys.path tweaks). Args: path (str): Path or name of the metric script. - if ``path`` is a local metric script or a directory containing a local metric script (if the script has the same name as the directory): -> load the module from the metric script e.g. ``'./metrics/accuracy'`` or ``'./metrics/accuracy/accuracy.py'``. - if ``path`` is a metric on the Hugging Face Hub (ex: `glue`, `squad`) -> load the module from the metric script in the github repository at huggingface/datasets e.g. ``'accuracy'`` or ``'rouge'``. revision (Optional ``Union[str, datasets.Version]``): If specified, the module will be loaded from the datasets repository at this version. By default: - it is set to the local version of the lib. - it will also try to load it from the main branch if it's not available at the local version of the lib. Specifying a version that is different from your local version of the lib might cause compatibility issues. download_config (:class:`DownloadConfig`, optional): Specific download configuration parameters. download_mode (:class:`DownloadMode`, default ``REUSE_DATASET_IF_EXISTS``): Download/generate mode. dynamic_modules_path (Optional str, defaults to HF_MODULES_CACHE / "datasets_modules", i.e. ~/.cache/huggingface/modules/datasets_modules): Optional path to the directory in which the dynamic modules are saved. It must have been initialized with :obj:`init_dynamic_modules`. By default, the datasets and metrics are stored inside the `datasets_modules` module. **download_kwargs (additional keyword arguments): optional attributes for DownloadConfig() which will override the attributes in download_config if supplied. Returns: MetricModule NTcSs|S)NrJ)rrJrJrKrsz'metric_module_factory..rrz.py)rrIz!Couldn't find a metric script at r)rrorrI)rIz . Metric 'z/' doesn't exist on the Hugging Face Hub either.rr)rrrrrr`rrrCrrrrDrErrrrr7r6rrrkrr) rDrrorrIrrirr"r#rJrJrKmetric_module_factorysF) &      *r%F) rDr process_id num_process cache_dir experiment_idkeep_in_memoryrorrrMc  KsXt|p tj}t|| ||dj} t| dd} | f||||||d| } | j|d| S)ayLoad a `datasets.Metric`. Args: path (``str``): path to the metric processing script with the metric builder. Can be either: - a local path to processing script or the directory containing the script (if the script has the same name as the directory), e.g. ``'./metrics/rouge'`` or ``'./metrics/rogue/rouge.py'`` - a metric identifier on the HuggingFace datasets repo (list all available metrics with ``datasets.list_metrics()``) e.g. ``'rouge'`` or ``'bleu'`` config_name (:obj:`str`, optional): selecting a configuration for the metric (e.g. the GLUE metric has a configuration for each subset) process_id (:obj:`int`, optional): for distributed evaluation: id of the process num_process (:obj:`int`, optional): for distributed evaluation: total number of processes cache_dir (Optional str): path to store the temporary predictions and references (default to `~/.cache/huggingface/metrics/`) experiment_id (``str``): A specific experiment id. This is used if several distributed evaluations share the same file system. This is useful to compute metrics in distributed setups (in particular non-additive metrics like F1). keep_in_memory (bool): Whether to store the temporary results in memory (defaults to False) download_config (Optional ``datasets.DownloadConfig``: specific download configuration parameters. download_mode (:class:`DownloadMode`, default ``REUSE_DATASET_IF_EXISTS``): Download/generate mode. revision (Optional ``Union[str, datasets.Version]``): if specified, the module will be loaded from the datasets repository at this version. By default it is set to the local version of the lib. Specifying a version that is different from your local version of the lib might cause compatibility issues. Returns: `datasets.Metric` Example: ```py >>> from datasets import load_metric >>> accuracy = load_metric('accuracy') >>> accuracy.compute(references=[1, 0], predictions=[1, 1]) {'accuracy': 0.5} ``` )rrorF)rX)rr&r'r(r*r))ro)rrr%rWr[download_and_prepare)rDrr&r'r(r)r*rorrZmetric_init_kwargsZ metric_moduleZ metric_clsrrJrJrK load_metric<s0  r,) rDr?rrr(featuresrorrrrMc  st|p tj}| dk r.|r"|jnt}| |_t|||||d} t| j} | j} | j d|}| j d|}| j d}t kr|dkrdd}fdd t D}|r|d |d d 7}t || f||||||| d | | }|S)aaLoad a dataset builder from the Hugging Face Hub, or a local dataset. A dataset builder can be used to inspect general information that is required to build a dataset (cache directory, config, dataset info, etc.) without downloading the dataset itself. You can find the list of datasets on the Hub at https://huggingface.co/datasets or with ``datasets.list_datasets()``. A dataset is a directory that contains: - some data files in generic formats (JSON, CSV, Parquet, text, etc.) - and optionally a dataset script, if it requires some code to read the data files. This is used to load any kind of formats or structures. Note that dataset scripts can also download and read data files from anywhere - in case your data files already exist online. Args: path (:obj:`str`): Path or name of the dataset. Depending on ``path``, the dataset builder that is used comes from a generic dataset script (JSON, CSV, Parquet, text etc.) or from the dataset script (a python file) inside the dataset directory. For local datasets: - if ``path`` is a local directory (containing data files only) -> load a generic dataset builder (csv, json, text etc.) based on the content of the directory e.g. ``'./path/to/directory/with/my/csv/data'``. - if ``path`` is a local dataset script or a directory containing a local dataset script (if the script has the same name as the directory): -> load the dataset builder from the dataset script e.g. ``'./dataset/squad'`` or ``'./dataset/squad/squad.py'``. For datasets on the Hugging Face Hub (list all available datasets and ids with ``datasets.list_datasets()``) - if ``path`` is a dataset repository on the HF hub (containing data files only) -> load a generic dataset builder (csv, text etc.) based on the content of the repository e.g. ``'username/dataset_name'``, a dataset repository on the HF hub containing your data files. - if ``path`` is a dataset repository on the HF hub with a dataset script (if the script has the same name as the directory) -> load the dataset builder from the dataset script in the dataset repository e.g. ``glue``, ``squad``, ``'username/dataset_name'``, a dataset repository on the HF hub containing a dataset script `'dataset_name.py'`. name (:obj:`str`, optional): Defining the name of the dataset configuration. data_dir (:obj:`str`, optional): Defining the data_dir of the dataset configuration. If specified for the generic builders (csv, text etc.) or the Hub datasets and `data_files` is None, the behavior is equal to passing `os.path.join(data_dir, **)` as `data_files` to reference all the files in a directory. data_files (:obj:`str` or :obj:`Sequence` or :obj:`Mapping`, optional): Path(s) to source data file(s). cache_dir (:obj:`str`, optional): Directory to read/write data. Defaults to "~/.cache/huggingface/datasets". features (:class:`Features`, optional): Set the features type to use for this dataset. download_config (:class:`~utils.DownloadConfig`, optional): Specific download configuration parameters. download_mode (:class:`DownloadMode`, default ``REUSE_DATASET_IF_EXISTS``): Download/generate mode. revision (:class:`~utils.Version` or :obj:`str`, optional): Version of the dataset script to load: - For datasets in the `huggingface/datasets` library on GitHub like "squad", the default version of the module is the local version of the lib. You can specify a different version from your local version of the lib (e.g. "main" or "1.2.0") but it might cause compatibility issues. - For community datasets like "lhoestq/squad" that have their own git repository on the Datasets Hub, the default version "main" corresponds to the "main" branch. You can specify a different version that the default "main" by using a commit sha or a git tag of the dataset repository. use_auth_token (``str`` or :obj:`bool`, optional): Optional string or boolean to use as Bearer token for remote files on the Datasets Hub. If True, will get token from `"~/.huggingface"`. **config_kwargs (additional keyword arguments): Keyword arguments to be passed to the :class:`BuilderConfig` and used in the :class:`DatasetBuilder`. Returns: :class:`DatasetBuilder` Passing `use_auth_token=True` is required when you want to access a private dataset. Example: ```py >>> from datasets import load_dataset_builder >>> ds_builder = load_dataset_builder('rotten_tomatoes') >>> ds_builder.info.features {'label': ClassLabel(num_classes=2, names=['neg', 'pos'], id=None), 'text': Value(dtype='string', id=None)} ``` N)rrorrrrrrz.Please specify the data files to load for the z dataset builder.csg|]}t|kr|qSrJ)r))r extension)rDrJrKrsz(load_dataset_builder..z9 For example `data_files={"train": "path/to/data/train/*.rz"}`)r(rrrrr-r) rrrurrr$r[rWrpopr+r)rw)rDr?rrr(r-rorrr config_kwargsZdataset_moduleZ builder_clsrrr error_msgZexample_extensionsbuilder_instancerJ)rDrKload_dataset_buildersBW     r3)rDr?rrrr(r-rorignore_verificationsr* save_infosrrtask streamingrMc Kst|tjjrtdt|p"tj}| p,| } tf||||||||| | d |}|rb|j|dS|t k}|j ||| || d| dk r| n t |j j } |j|| | d}|dk r|j|}| r|j|S)a7%Load a dataset from the Hugging Face Hub, or a local dataset. You can find the list of datasets on the Hub at https://huggingface.co/datasets or with ``datasets.list_datasets()``. A dataset is a directory that contains: - some data files in generic formats (JSON, CSV, Parquet, text, etc.) - and optionally a dataset script, if it requires some code to read the data files. This is used to load any kind of formats or structures. Note that dataset scripts can also download and read data files from anywhere - in case your data files already exist online. This function does the following under the hood: 1. Download and import in the library the dataset script from ``path`` if it's not already cached inside the library. If the dataset has no dataset script, then a generic dataset script is imported instead (JSON, CSV, Parquet, text, etc.) Dataset scripts are small python scripts that define dataset builders. They define the citation, info and format of the dataset, contain the path or URL to the original data files and the code to load examples from the original data files. You can find some of the scripts here: https://github.com/huggingface/datasets/tree/main/datasets You can find the complete list of datasets in the Datasets Hub at https://huggingface.co/datasets 2. Run the dataset script which will: * Download the dataset file from the original URL (see the script) if it's not already available locally or cached. * Process and cache the dataset in typed Arrow tables for caching. Arrow table are arbitrarily long, typed tables which can store nested objects and be mapped to numpy/pandas/python generic types. They can be directly accessed from disk, loaded in RAM or even streamed over the web. 3. Return a dataset built from the requested splits in ``split`` (default: all). It also allows to load a dataset from a local directory or a dataset repository on the Hugging Face Hub without dataset script. In this case, it automatically loads all the data files from the directory or the dataset repository. Args: path (:obj:`str`): Path or name of the dataset. Depending on ``path``, the dataset builder that is used comes from a generic dataset script (JSON, CSV, Parquet, text etc.) or from the dataset script (a python file) inside the dataset directory. For local datasets: - if ``path`` is a local directory (containing data files only) -> load a generic dataset builder (csv, json, text etc.) based on the content of the directory e.g. ``'./path/to/directory/with/my/csv/data'``. - if ``path`` is a local dataset script or a directory containing a local dataset script (if the script has the same name as the directory): -> load the dataset builder from the dataset script e.g. ``'./dataset/squad'`` or ``'./dataset/squad/squad.py'``. For datasets on the Hugging Face Hub (list all available datasets and ids with ``datasets.list_datasets()``) - if ``path`` is a dataset repository on the HF hub (containing data files only) -> load a generic dataset builder (csv, text etc.) based on the content of the repository e.g. ``'username/dataset_name'``, a dataset repository on the HF hub containing your data files. - if ``path`` is a dataset repository on the HF hub with a dataset script (if the script has the same name as the directory) -> load the dataset builder from the dataset script in the dataset repository e.g. ``glue``, ``squad``, ``'username/dataset_name'``, a dataset repository on the HF hub containing a dataset script `'dataset_name.py'`. name (:obj:`str`, optional): Defining the name of the dataset configuration. data_dir (:obj:`str`, optional): Defining the data_dir of the dataset configuration. If specified for the generic builders (csv, text etc.) or the Hub datasets and `data_files` is None, the behavior is equal to passing `os.path.join(data_dir, **)` as `data_files` to reference all the files in a directory. data_files (:obj:`str` or :obj:`Sequence` or :obj:`Mapping`, optional): Path(s) to source data file(s). split (:class:`Split` or :obj:`str`): Which split of the data to load. If None, will return a `dict` with all splits (typically `datasets.Split.TRAIN` and `datasets.Split.TEST`). If given, will return a single Dataset. Splits can be combined and specified like in tensorflow-datasets. cache_dir (:obj:`str`, optional): Directory to read/write data. Defaults to "~/.cache/huggingface/datasets". features (:class:`Features`, optional): Set the features type to use for this dataset. download_config (:class:`~utils.DownloadConfig`, optional): Specific download configuration parameters. download_mode (:class:`DownloadMode`, default ``REUSE_DATASET_IF_EXISTS``): Download/generate mode. ignore_verifications (:obj:`bool`, default ``False``): Ignore the verifications of the downloaded/processed dataset information (checksums/size/splits/...). keep_in_memory (:obj:`bool`, default ``None``): Whether to copy the dataset in-memory. If `None`, the dataset will not be copied in-memory unless explicitly enabled by setting `datasets.config.IN_MEMORY_MAX_SIZE` to nonzero. See more details in the :ref:`load_dataset_enhancing_performance` section. save_infos (:obj:`bool`, default ``False``): Save the dataset information (checksums/size/splits/...). revision (:class:`~utils.Version` or :obj:`str`, optional): Version of the dataset script to load: - For datasets in the `huggingface/datasets` library on GitHub like "squad", the default version of the module is the local version of the lib. You can specify a different version from your local version of the lib (e.g. "main" or "1.2.0") but it might cause compatibility issues. - For community datasets like "lhoestq/squad" that have their own git repository on the Datasets Hub, the default version "main" corresponds to the "main" branch. You can specify a different version that the default "main" by using a commit sha or a git tag of the dataset repository. use_auth_token (``str`` or :obj:`bool`, optional): Optional string or boolean to use as Bearer token for remote files on the Datasets Hub. If True, will get token from `"~/.huggingface"`. task (``str``): The task to prepare the dataset for during training and evaluation. Casts the dataset's :class:`Features` to standardized column names and types as detailed in :py:mod:`datasets.tasks`. streaming (:obj:`bool`, default ``False``): If set to True, don't download the data files. Instead, it streams the data progressively while iterating on the dataset. An IterableDataset or IterableDatasetDict is returned instead in this case. Note that streaming works for datasets that use data formats that support being iterated over like txt, csv, jsonl for example. Json files may be downloaded completely. Also streaming from remote zip or gzip files is supported but other compressed formats like rar and xz are not yet supported. The tgz format doesn't allow streaming. **config_kwargs (additional keyword arguments): Keyword arguments to be passed to the :class:`BuilderConfig` and used in the :class:`DatasetBuilder`. Returns: :class:`Dataset` or :class:`DatasetDict`: - if `split` is not None: the dataset requested, - if `split` is None, a ``datasets.DatasetDict`` with each split. or :class:`IterableDataset` or :class:`IterableDatasetDict`: if streaming=True - if `split` is not None: the dataset requested, - if `split` is None, a ``datasets.streaming.IterableDatasetDict`` with each split. Passing `use_auth_token=True` is required when you want to access a private dataset. Example: Load a dataset from the Hugging Face Hub: ```py >>> from datasets import load_dataset >>> ds = load_dataset('rotten_tomatoes', split='train') # Map data files to splits >>> data_files = {'train': 'train.csv', 'test': 'test.csv'} >>> ds = load_dataset('namespace/your_dataset_name', data_files=data_files) ``` Load a local dataset: ```py # Load a CSV file >>> from datasets import load_dataset >>> ds = load_dataset('csv', data_files='path/to/local/my_dataset.csv') # Load a JSON file >>> from datasets import load_dataset >>> ds = load_dataset('json', data_files='path/to/local/my_dataset.json') # Load from a local loading script >>> from datasets import load_dataset >>> ds = load_dataset('path/to/local/loading_script/loading_script.py', split='train') ``` Load an [`~datasets.IterableDataset`]: ```py >>> from datasets import load_dataset >>> ds = load_dataset('rotten_tomatoes', split='train', streaming=True) ``` Load an image dataset with the `ImageFolder` dataset builder: ```py >>> from datasets import load_dataset >>> ds = load_dataset('imagefolder', data_dir='/path/to/images', split='train') ``` zjYou are trying to load a dataset that was saved using `save_to_disk`. Please use `load_from_disk` instead.) rDr?rrr(r-rorrr)r)rorr4try_from_hf_gcsrN)rr4Z in_memory)rrZDATASET_STATE_JSON_FILENAMErGrwrrr3Zas_streaming_datasetr+r+r:rZ dataset_sizeZ as_datasetZprepare_for_taskZ _save_infos)rDr?rrrr(r-rorr4r*r5rrr6r7r0r2r8ZdsrJrJrK load_datasetsD-  r9) dataset_pathr*rMcCst|rt|}ntjd}|}|j|s:td|d|jt|tj j r`t j |||dS|jt|tj j rtj |||dStd|ddS)a Loads a dataset that was previously saved using :meth:`Dataset.save_to_disk` from a dataset directory, or from a filesystem using either :class:`datasets.filesystems.S3FileSystem` or any implementation of ``fsspec.spec.AbstractFileSystem``. Args: dataset_path (:obj:`str`): Path (e.g. `"dataset/train"`) or remote URI (e.g. `"s3://my-bucket/dataset/train"`) of the Dataset or DatasetDict directory where the dataset will be loaded from. fs (:class:`~filesystems.S3FileSystem` or ``fsspec.spec.AbstractFileSystem``, optional, default ``None``): Instance of of the remote filesystem used to download the files from. keep_in_memory (:obj:`bool`, default ``None``): Whether to copy the dataset in-memory. If `None`, the dataset will not be copied in-memory unless explicitly enabled by setting `datasets.config.IN_MEMORY_MAX_SIZE` to nonzero. See more details in the :ref:`load_dataset_enhancing_performance` section. Returns: :class:`Dataset` or :class:`DatasetDict`: - If `dataset_path` is a path of a dataset directory: the dataset requested. - If `dataset_path` is a path of a dataset dict directory: a ``datasets.DatasetDict`` with each split. Example: ```py >>> from datasets import load_from_disk >>> ds = load_from_disk('path/to/dataset/directory') ``` filez Directory z not found)r*z= is neither a dataset directory nor a dataset dict directory.N)r$r#fsspec filesystemrGrrrrZDATASET_INFO_FILENAMEas_posixrload_from_diskZDATASETDICT_JSON_FILENAMEr)r:fsr*Zdest_dataset_pathrJrJrKr?s   r?)T)N)NNNNNN)NNNN) NrrNNFNNN) NNNNNNNNN)NNNNNNNNFNFNNNF)NN)rrrNrRrrCrr  collectionsrZ dataclassesrpathlibrtypingrrrrr r r r r<rZhuggingface_hubr rrrZ arrow_datasetrZbuilderrrrrrrrrrrZ dataset_dictrrZdownload.download_configrZdownload.download_managerrZ#download.streaming_download_managerrr r!r-r"Z filesystemsr#r$rr%r&Ziterable_datasetr'rr(Zpackaged_modulesr)r*r+r,splitsr-tasksr.Zutils.file_utilsr/r0r1r2r3r4r5r6r7r8Zutils.filelockr9Zutils.info_utilsr:Z utils.loggingr;Zutils.py_utilsr<Z utils.versionr=rrr`keysrZMODULE_NAME_FOR_DYNAMIC_MODULESrrLr[rgrlrrrrrrrrrrrrrrrrrrrrr$r%intr,r3r9r?rJrJrJrKs   (   (        0     $$ >O"WC).G4aI9,<>$Q6;lzR