/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__/splits.cpython-36.pyc (22522B)
3 <%Eg[V@s\dZddlZddlZddlZddlmZmZddlmZm Z m Z m Z ddl m Z mZddlmZddlmZeGd d d ZeGd d d ZGd ddejdZGdddeZGdddedZeZGdddeZGdddeZGdddeZGdddeZGdddZej ddd gZ!Gd!d"d"Z"Gd#d$d$e#Z$eGd%d&d&Z%dS)'zSplits related API.N) dataclassfield)DictListOptionalUnion)FileInstructionsmake_file_instructions) _split_re)NonMutableDictc@s>eZdZUdZedZedZedZe ee ddZ dS) SplitInforNcCst|j|gt|jd}|jS)z/Returns the list of dict(filename, take, skip).)name split_infos instruction)r dataset_namestrrfile_instructions)self instructionsr9/usr/local/lib/python3.6/site-packages/datasets/splits.pyr%s zSplitInfo.file_instructions) __name__ __module__ __qualname__rr num_bytesint num_examplesrrpropertyrrrrrr s  r c@s.eZdZUdZeeddZeddZdS) SubSplitInfozWrapper around a sub split info. This class expose info on the subsplit: ``` ds, info = datasets.load_dataset(..., split='train[75%:]', with_info=True) info.splits['train[75%:]'].num_examples ``` cCs|jjS)z.Returns the number of example in the subsplit.)rr)rrrrr=szSubSplitInfo.num_examplescCs|jjS)z/Returns the list of dict(filename, take, skip).)rr)rrrrrBszSubSplitInfo.file_instructionsN) rrr__doc__r rrrrrrrrr 1s  r c@s@eZdZdZejddZddZddZdd Z d d d Z d S) SplitBaseaAbstract base class for Split compositionality. See the [guide on splits](/docs/datasets/loading#slice-splits) for more information. There are three parts to the composition: 1) The splits are composed (defined, merged, split,...) together before calling the `.as_dataset()` function. This is done with the `__add__`, `__getitem__`, which return a tree of `SplitBase` (whose leaf are the `NamedSplit` objects) ``` split = datasets.Split.TRAIN + datasets.Split.TEST.subsplit(datasets.percent[:50]) ``` 2) The `SplitBase` is forwarded to the `.as_dataset()` function to be resolved into actual read instruction. This is done by the `.get_read_instruction()` method which takes the real dataset splits (name, number of shards,...) and parse the tree to return a `SplitReadInstruction()` object ``` read_instruction = split.get_read_instruction(self.info.splits) ``` 3) The `SplitReadInstruction` is then used in the `tf.data.Dataset` pipeline to define which files to read and how to skip examples within file. cCs tddS)zParse the descriptor tree and compile all read instructions together. Args: split_dict: `dict`, The `dict[split_name, SplitInfo]` of the dataset Returns: split_read_instruction: `SplitReadInstruction` zAbstract methodN)NotImplementedError)r split_dictrrrget_read_instructionjs zSplitBase.get_read_instructioncCst|ttfrdStddS)z*Equality: datasets.Split.TRAIN == 'train'.Fz6Equality is not implemented between merged/sub splits.N) isinstance NamedSplitrr#)rotherrrr__eq__vszSplitBase.__eq__cCs |j| S)z+InEquality: datasets.Split.TRAIN != 'test'.)r))rr(rrr__ne__|szSplitBase.__ne__cCs t||S)z4Merging: datasets.Split.TRAIN + datasets.Split.TEST.) _SplitMerged)rr(rrr__add__szSplitBase.__add__Nc stdd||||fDdkr&tdt|tr6|}nt|trF|}nt|trT|}|p^|p^|sptd|ddd}|rd |kod knstd |d |fd d t|D}t|djd |d<||tfdd|DS|rt |S|rt|fdd |D}d }d }g}x*|D]"} || 7}|j t|||}q4Wt|djd |d<||tfdd|DStddS)a6Divides this split into subsplits. There are 3 ways to define subsplits, which correspond to the 3 arguments `k` (get `k` even subsplits), `percent` (get a slice of the dataset with `datasets.percent`), and `weighted` (get subsplits with proportions specified by `weighted`). Example:: ``` # 50% train, 50% test train, test = split.subsplit(k=2) # 50% train, 25% test, 25% validation train, test, validation = split.subsplit(weighted=[2, 1, 1]) # Extract last 20% subsplit = split.subsplit(datasets.percent[-20:]) ``` Warning: k and weighted will be converted into percent which mean that values below the percent will be rounded up or down. The final split may be bigger to deal with remainders. For instance: ``` train, test, valid = split.subsplit(k=3) # 33%, 33%, 34% s1, s2, s3, s4 = split.subsplit(weighted=[2, 2, 1, 1]) # 33%, 33%, 16%, 18% ``` Args: arg: If no kwargs are given, `arg` will be interpreted as one of `k`, `percent`, or `weighted` depending on the type. For example: ``` split.subsplit(10) # Equivalent to split.subsplit(k=10) split.subsplit(datasets.percent[:-20]) # percent=datasets.percent[:-20] split.subsplit([1, 1, 2]) # weighted=[1, 1, 2] ``` k: `int` If set, subdivide the split into `k` equal parts. percent: `datasets.percent slice`, return a single subsplit corresponding to a slice of the original split. For example: `split.subsplit(datasets.percent[-20:]) # Last 20% of the dataset`. weighted: `list[int]`, return a list of subsplits whose proportions match the normalized sum of the list. For example: `split.subsplit(weighted=[1, 1, 2]) # 25%, 25%, 50%`. Returns: A subsplit or list of subsplits extracted from this split object. css|]}t|VqdS)N)bool).0xrrr sz%SplitBase.subsplit..rz,Only one argument of subsplit should be set.zInvalid split argument zg. Only list, slice and int supported. One of k, weighted or percent should be set to a non empty value.cSs(tdd|Dgttdks$tdS)Ncss |]}tt|jdVqdS)dN)listrangeindices)r.srrrr0szESplitBase.subsplit..assert_slices_coverage..r1)sumr2r3AssertionError)slicesrrrassert_slices_coveragesz2SplitBase.subsplit..assert_slices_coveragerr1z,Subsplit k should be between 0 and 100, got cs"g|]}t||dqS)r)slice)r.i)shiftrr sz&SplitBase.subsplit..c3s|]}t|VqdS)N) _SubSplit)r.r5)rrrr0scsg|]}d|qS)r1r)r.r/)totalrrr=sc3s|]}t|VqdS)N)r>)r.r5)rrrr0szCould not determine the splitNr@r@r@) r6 ValueErrorr&rr:r2r3starttupler>append) rargkpercentZweightedr9r8rBstopvr)rr<r?rsubsplitsH2       zSplitBase.subsplit)NNNN) rrrr!abcabstractmethodr%r)r*r,rJrrrrr"Hs  r") metaclassc@seZdZddZdS)PercentSliceMetacCst|tstd||S)Nz7datasets.percent should only be called with slice, not )r&r:rA)cls slice_valuerrr __getitem__s zPercentSliceMeta.__getitem__N)rrrrQrrrrrNsrNc@seZdZdZdS) PercentSlicezSyntactic sugar for defining slice subsplits: `datasets.percent[75:-5]`. See the [guide on splits](/docs/datasets/loading#slice-splits) for more information. N)rrrr!rrrrrRsrRc@s(eZdZdZddZddZddZdS) r+z0Represent two split descriptors merged together.cCs||_||_dS)N)_split1_split2)rZsplit1Zsplit2rrr__init__ sz_SplitMerged.__init__cCs |jj|}|jj|}||S)N)rSr%rT)rr$Zread_instruction1Zread_instruction2rrrr%s  z!_SplitMerged.get_read_instructioncCsdt|jdt|jdS)N(z + ))reprrSrT)rrrr__repr__sz_SplitMerged.__repr__N)rrrr!rUr%rYrrrrr+ sr+c@s(eZdZdZddZddZddZdS) r>z,Represent a sub split of a split descriptor.cCs||_||_dS)N)_split _slice_value)rsplitrPrrrrUsz_SubSplit.__init__cCs|jj||jS)N)rZr%r[)rr$rrrr% sz_SubSplit.get_read_instructioncCsjd}|jjdk r|d7}|j|jjdkr,dn|jj|jjdkrBdn|jj|jjd}t|jd|dS)Nz{start}:{stop}z:{step}r)rBrHstepz(datasets.percent[z]))r[r]formatrBrHrXrZ)rZ slice_strrrrrY#s  z_SubSplit.__repr__N)rrrr!rUr%rYrrrrr>sr>c@sHeZdZdZddZddZddZdd Zd d Zd d Z ddZ dS)r'agDescriptor corresponding to a named split (train, test, ...). Example:: Each descriptor can be composed with other using addition or slice. Ex:: split = datasets.Split.TRAIN.subsplit(datasets.percent[0:25]) + datasets.Split.TEST The resulting split will correspond to 25% of the train split merged with 100% of the test split. Warning: A split cannot be added twice, so the following will fail:: split = ( datasets.Split.TRAIN.subsplit(datasets.percent[:25]) + datasets.Split.TRAIN.subsplit(datasets.percent[75:]) ) # Error split = datasets.Split.TEST + datasets.Split.ALL # Error Warning: The slices can be applied only one time. So the following are valid:: split = ( datasets.Split.TRAIN.subsplit(datasets.percent[:25]) + datasets.Split.TEST.subsplit(datasets.percent[:50]) ) split = (datasets.Split.TRAIN + datasets.Split.TEST).subsplit(datasets.percent[:50]) But not:: train = datasets.Split.TRAIN test = datasets.Split.TEST split = train.subsplit(datasets.percent[:25]).subsplit(datasets.percent[:25]) split = (train.subsplit(datasets.percent[:25]) + test).subsplit(datasets.percent[:50]) cCsN||_dd|jdD}x.|D]&}tjt|s tdtd|dq WdS)NcSsg|]}|jddqS)[r)r\)r.split_instructionrrrr=Wsz'NamedSplit.__init__..+zSplit name should match 'z ' but got 'z'.)_namer\rematchr rA)rrZsplit_names_from_instructionZ split_namerrrrUUs   zNamedSplit.__init__cCs|jS)N)rb)rrrr__str__\szNamedSplit.__str__cCsd|jdS)Nz NamedSplit(rW)rb)rrrrrY_szNamedSplit.__repr__cCsPt|tr|j|jkSt|tr$dSt|tr8|j|kStd|d|dS)z*Equality: datasets.Split.TRAIN == 'train'.Fz%Equality not supported between split z and N)r&r'rbr"rrA)rr(rrrr)bs     zNamedSplit.__eq__cCs |j|jkS)N)rb)rr(rrr__lt__mszNamedSplit.__lt__cCs t|jS)N)hashrb)rrrr__hash__pszNamedSplit.__hash__cCst||jS)N)SplitReadInstructionrb)rr$rrrr%sszNamedSplit.get_read_instructionN) rrrr!rUrerYr)rfrhr%rrrrr'/s$ r'cs0eZdZdZfddZddZddZZS) NamedSplitAllz?Split corresponding to the union of all defined dataset splits.cstjddS)Nall)superrU)r) __class__rrrUzszNamedSplitAll.__init__cCsdS)NzNamedSplitAll()r)rrrrrY}szNamedSplitAll.__repr__cCsdd|jD}t|tS)NcSsg|] }t|qSr)ri)r.r5rrrr=sz6NamedSplitAll.get_read_instruction..)valuesr6ri)rr$Zread_instructionsrrrr%sz"NamedSplitAll.get_read_instruction)rrrr!rUrYr% __classcell__rr)rmrrjws rjc@s6eZdZdZedZedZedZeZ ddZ dS)Splita#`Enum` for dataset splits. Datasets are typically split into different subsets to be used at various stages of training and evaluation. - `TRAIN`: the training data. - `VALIDATION`: the validation data. If present, this is typically used as evaluation data while iterating on a model (e.g. changing hyperparameters, model architecture, etc.). - `TEST`: the testing data. This is the data to report metrics on. Typically you do not want to use this during model iteration as you may overfit to it. - `ALL`: the union of all defined dataset splits. Note: All splits, including compositions inherit from `datasets.SplitBase` See the :doc:`guide on splits ` for more information. Example: ```py >>> datasets.SplitGenerator( ... name=datasets.Split.TRAIN, ... gen_kwargs={"split_key": "train", "files": dl_manager.download_and extract(url)}, ... ), ... datasets.SplitGenerator( ... name=datasets.Split.VALIDATION, ... gen_kwargs={"split_key": "validation", "files": dl_manager.download_and extract(url)}, ... ), ... datasets.SplitGenerator( ... name=datasets.Split.TEST, ... gen_kwargs={"split_key": "test", "files": dl_manager.download_and extract(url)}, ... ) ``` ZtraintestZ validationcCs|dkrtSt|S)z9Create a custom split with datasets.Split('custom_name').rk)rjr')rOrrrr__new__sz Split.__new__N) rrrr!r'ZTRAINZTESTZ VALIDATIONrjALLrrrrrrrps #rpSlicedSplitInfo split_inforPc@s:eZdZdZd ddZddZddZd d Zd d ZdS)riaObject containing the reading instruction for the dataset. Similarly to `SplitDescriptor` nodes, this object can be composed with itself, but the resolution happens instantaneously, instead of keeping track of the tree, such as all instructions are compiled and flattened in a single SplitReadInstruction object containing the list of files and slice to use. Once resolved, the instructions can be accessed with: ``` read_instructions.get_list_sliced_split_info() # List of splits to use ``` NcCs&tdd|_|r"|jt|dddS)Nz?Overlap between splits. Split {key} has been added with itself.) error_msg)rurP)r _splitsaddrt)rrurrrrUs zSplitReadInstruction.__init__cCs||j|jj<dS)z,Add a SlicedSplitInfo the read instructions.N)rwrur)rZ sliced_splitrrrrxszSplitReadInstruction.addcCs&t}|jj|j|jj|j|S)zMerging split together.)rirwupdate)rr(r`rrrr,szSplitReadInstruction.__add__cCs\t}xP|jjD]B}|jdk r4td|jjd|j}||d<|jt f|qW|S)z Sub-splits.NzTrying to slice Split z which has already been slicedrP) rirwrnrPrArur_asdictrxrt)rrPr`rIrrrrQs z SplitReadInstruction.__getitem__cCstt|jjdddS)NcSs|jjS)N)rur)r/rrrszASplitReadInstruction.get_list_sliced_split_info..)key)r2sortedrwrn)rrrrget_list_sliced_split_infosz/SplitReadInstruction.get_list_sliced_split_info)N) rrrr!rUrxr,rQr~rrrrris    ricseZdZdZddfdd Zeeefdfdd Zeeefe d fd d Z e d fd d Z e ddZ edeeefeedddZddZddZZS) SplitDictzSplit info object.N)rcstj||||_dS)N)rlrUr)rrargskwargs)rmrrrUszSplitDict.__init__)r|cs<t||krtjt|St|j|j|d}t|SdS)N)rrr)rrlrQr rrnr )rr|r)rmrrrQs zSplitDict.__getitem__)r|valuecsL||jkr"td|d|jd||kr:td|dtj||dS)Nz!Cannot add elem. (key mismatch: 'z' != 'z')zSplit z already present)rrArl __setitem__)rr|r)rmrrr s  zSplitDict.__setitem__)rucs8|j|krtd|jd|j|_tj|j|dS)zAdd the split info.zSplit z already presentN)rrArrlr)rru)rmrrrxs z SplitDict.addcCstdd|jDS)z$Return the total number of examples.css|] }|jVqdS)N)r)r.r5rrrr0sz/SplitDict.total_num_examples..)r6rn)rrrrtotal_num_examplesszSplitDict.total_num_examples)rrcCslt|trt|j}|dkr2|r.|ddnd}||d}x*|D]"}t|trZtf|}|j|qBW|S)zIReturns a new SplitDict initialized from a Dict or List of `split_infos`.Nrr)r)r&dictr2rnr rx)rOrrr$rurrrfrom_split_dicts      zSplitDict.from_split_dictcCstdd|jDdddS)z0Returns a list of SplitInfo protos that we have.css|] }|VqdS)Nr)r.r5rrrr02sz*SplitDict.to_split_dict..cSs|jS)N)r)r5rrrr{2sz)SplitDict.to_split_dict..)r|)r}rn)rrrr to_split_dict/szSplitDict.to_split_dictcCstj|j|jS)N)rrrr)rrrrcopy4szSplitDict.copy)N)rrrr!rUrr"rrQr rrxrr classmethodrrrrrrrorr)rmrrs   rc@s:eZdZUdZeeedZe eddZ e  ddZ dS)SplitGeneratoraDefines the split information for the generator. This should be used as returned value of :meth:`GeneratorBasedBuilder._split_generators`. See :meth:`GeneratorBasedBuilder._split_generators` for more info and example of usage. Args: name (str): Name of the Split for which the generator will create the examples. **gen_kwargs: Keyword arguments to forward to the :meth:`DatasetBuilder._generate_examples` method of the builder. Example: ```py >>> datasets.SplitGenerator( ... name=datasets.Split.TRAIN, ... gen_kwargs={"split_key": "train", "files": dl_manager.download_and_extract(url)}, ... ) ``` )default_factoryF)initcCs(t|j|_t|jt|jd|_dS)N)r)rrr'r ru)rrrr __post_init__Us  zSplitGenerator.__post_init__N) rrrr!rrrrZ gen_kwargsrrur rrrrrr8s r)&r!rK collectionsrcZ dataclassesrrtypingrrrrZ arrow_readerr r Znamingr Zutils.py_utilsr r r ABCMetar"typerNrRrGr+r>r'rjrp namedtuplertrirrrrrrrs6  , H07B