Datasets 文档

Builder 类

Hugging Face's logo
加入 Hugging Face 社区

并获得增强的文档体验

开始使用

Builder 类

Builders

🤗 Datasets 在数据集构建过程中依赖于两个主要类:DatasetBuilderBuilderConfig

class datasets.DatasetBuilder

< >

( cache_dir: typing.Optional[str] = None dataset_name: typing.Optional[str] = None config_name: typing.Optional[str] = None hash: typing.Optional[str] = None base_path: typing.Optional[str] = None info: typing.Optional[datasets.info.DatasetInfo] = None features: typing.Optional[datasets.features.features.Features] = None token: typing.Union[bool, str, NoneType] = None repo_id: typing.Optional[str] = None data_files: typing.Union[str, list, dict, datasets.data_files.DataFilesDict, NoneType] = None data_dir: typing.Optional[str] = None storage_options: typing.Optional[dict] = None writer_batch_size: typing.Optional[int] = None config_id: typing.Optional[str] = None **config_kwargs )

参数

  • cache_dir (str, optional) — 用于缓存数据的目录。默认为 "~/.cache/huggingface/datasets"
  • dataset_name (str, optional) — 数据集的名称,如果与 builder 的名称不同。对于打包的 builder(如 csv、imagefolder、audiofolder 等),它有助于反映使用相同打包 builder 的数据集之间的差异。
  • config_name (str, optional) — 数据集配置的名称。它会影响在磁盘上生成的数据。不同的配置将有自己的子目录和版本。如果未提供,则使用默认配置(如果存在)。

    在 2.3.0 中添加

    参数 name 已重命名为 config_name

  • hash (str, optional) — 特定于数据集 builder 代码的哈希值。用于在数据集 builder 代码更新时更新缓存目录(以避免重用旧数据)。典型的缓存目录(在 self._relative_data_dir 中定义)是 name/version/hash/
  • base_path (str, optional) — 用于下载文件的相对路径的基路径。这可能是一个远程 URL。
  • features (Features, optional) — 用于此数据集的特征类型。例如,可以用于更改数据集的 Features 类型。
  • token (strbool, optional) — 用于 Datasets Hub 上远程文件的 Bearer token。如果为 True,则将从 "~/.huggingface" 获取 token。
  • repo_id (str, optional) — 数据集仓库的 ID。用于区分名称相同但来自不同命名空间的 builder,例如 “rajpurkar/squad” 和 “lhoestq/squad” 的 repo ID。在后者中,builder 名称将是 “lhoestq___squad”。
  • data_files (strSequenceMapping, optional) — 源数据文件的路径。对于需要用户指定数据文件的 builder,如 “csv” 或 “json”。它们可以是本地文件或远程文件。为了方便起见,您可以使用 DataFilesDict
  • data_dir (str, optional) — 包含源数据文件的目录。仅当未传递 data_files 时使用,在这种情况下,它等同于将 data_dir 中的 "**" 传递给 data_files。对于需要手动下载的 builder,它必须是包含手动下载数据的本地目录的路径。
  • storage_options (dict, optional) — 传递给数据集文件系统后端的键/值对,如果有的话。
  • writer_batch_size (int, optional) — ArrowWriter 使用的批次大小。它定义了在写入之前保存在内存中的样本数量,也是 arrow 块的长度。None 表示 ArrowWriter 将使用其默认值。
  • **config_kwargs (其他关键字参数) — 传递给相应的 builder 配置类的关键字参数,设置在类属性 DatasetBuilder.BUILDER_CONFIG_CLASS 上。builder 配置类是 BuilderConfig 或其子类。

所有数据集的抽象基类。

DatasetBuilder 有 3 个关键方法

一些 DatasetBuilder 通过定义 BuilderConfig 子类并在构造函数中接受配置对象(或名称)来公开数据集的多个变体。可配置的数据集在 DatasetBuilder.builder_configs() 中公开预定义的配置集。

as_dataset

< >

( split: typing.Union[str, datasets.splits.Split, list[str], list[datasets.splits.Split], NoneType] = None run_post_process = True verification_mode: typing.Union[datasets.utils.info_utils.VerificationMode, str, NoneType] = None in_memory = False )

参数

  • split (datasets.Split) — 要返回的数据子集。
  • run_post_process (bool, 默认为 True) — 是否运行后处理数据集转换和/或添加索引。
  • verification_mode (VerificationModestr, 默认为 BASIC_CHECKS) — 确定对下载/处理的数据集信息(校验和/大小/分割/…)运行哪些检查的验证模式。

    在 2.9.1 中添加

  • in_memory (bool, 默认为 False) — 是否将数据复制到内存中。

返回指定子集的数据集。

示例

>>> from datasets import load_dataset_builder
>>> builder = load_dataset_builder('cornell-movie-review-data/rotten_tomatoes')
>>> builder.download_and_prepare()
>>> ds = builder.as_dataset(split='train')
>>> ds
Dataset({
    features: ['text', 'label'],
    num_rows: 8530
})

download_and_prepare

< >

( output_dir: typing.Optional[str] = None download_config: typing.Optional[datasets.download.download_config.DownloadConfig] = None download_mode: typing.Union[datasets.download.download_manager.DownloadMode, str, NoneType] = None verification_mode: typing.Union[datasets.utils.info_utils.VerificationMode, str, NoneType] = None dl_manager: typing.Optional[datasets.download.download_manager.DownloadManager] = None base_path: typing.Optional[str] = None file_format: str = 'arrow' max_shard_size: typing.Union[str, int, NoneType] = None num_proc: typing.Optional[int] = None storage_options: typing.Optional[dict] = None **download_and_prepare_kwargs )

参数

  • output_dir (str, optional) — 数据集的输出目录。默认为此 builder 的 cache_dir,它默认在 ~/.cache/huggingface/datasets 中。

    在 2.5.0 中添加

  • download_config (DownloadConfig, optional) — 特定的下载配置参数。
  • download_mode (DownloadModestr, optional) — 选择下载/生成模式,默认为 REUSE_DATASET_IF_EXISTS
  • verification_mode (VerificationModestr, 默认为 BASIC_CHECKS) — 确定对下载/处理的数据集信息(校验和/大小/分割/…)运行哪些检查的验证模式。

    在 2.9.1 中添加

  • dl_manager (DownloadManager, optional) — 要使用的特定 DownloadManger
  • base_path (str, optional) — 用于下载文件的相对路径的基路径。这可以是一个远程 URL。如果未指定,则使用 base_path 属性(self.base_path)的值。
  • file_format (str, optional) — 数据集将被写入的数据文件的格式。支持的格式:“arrow”,“parquet”。默认为 “arrow” 格式。如果格式为 “parquet”,则图像和音频数据将嵌入到 Parquet 文件中,而不是指向本地文件。

    在 2.5.0 中添加

  • max_shard_size (Union[str, int], optional) — 每个分片写入的最大字节数,默认为 “500MB”。大小基于未压缩数据的大小,因此实际上您的分片文件可能小于 max_shard_size,这要归功于 Parquet 的压缩。

    在 2.5.0 中添加

  • num_proc (int, optional, 默认为 None) — 在本地下载和生成数据集时使用的进程数。多进程默认禁用。

    在 2.7.0 中添加

  • storage_options (dict, optional) — 传递给缓存文件系统后端的键/值对,如果有的话。

    在 2.5.0 中添加

  • **download_and_prepare_kwargs (其他关键字参数) — 关键字参数。

下载并准备数据集以供读取。

示例

下载并准备数据集为 Arrow 文件,可以使用 builder.as_dataset() 加载为 Dataset。

>>> from datasets import load_dataset_builder
>>> builder = load_dataset_builder("cornell-movie-review-data/rotten_tomatoes")
>>> builder.download_and_prepare()

下载并准备数据集为本地分片 Parquet 文件。

>>> from datasets import load_dataset_builder
>>> builder = load_dataset_builder("cornell-movie-review-data/rotten_tomatoes")
>>> builder.download_and_prepare("./output_dir", file_format="parquet")

下载并准备数据集为云存储中的分片 Parquet 文件。

>>> from datasets import load_dataset_builder
>>> storage_options = {"key": aws_access_key_id, "secret": aws_secret_access_key}
>>> builder = load_dataset_builder("cornell-movie-review-data/rotten_tomatoes")
>>> builder.download_and_prepare("s3://my-bucket/my_rotten_tomatoes", storage_options=storage_options, file_format="parquet")

get_imported_module_dir

< >

( )

返回此类或子类的模块路径。

class datasets.GeneratorBasedBuilder

< >

( cache_dir: typing.Optional[str] = None dataset_name: typing.Optional[str] = None config_name: typing.Optional[str] = None hash: typing.Optional[str] = None base_path: typing.Optional[str] = None info: typing.Optional[datasets.info.DatasetInfo] = None features: typing.Optional[datasets.features.features.Features] = None token: typing.Union[bool, str, NoneType] = None repo_id: typing.Optional[str] = None data_files: typing.Union[str, list, dict, datasets.data_files.DataFilesDict, NoneType] = None data_dir: typing.Optional[str] = None storage_options: typing.Optional[dict] = None writer_batch_size: typing.Optional[int] = None config_id: typing.Optional[str] = None **config_kwargs )

基于 dict 生成器的数据集的基类。

GeneratorBasedBuilder 是一个方便类,它抽象了 DatasetBuilder 的大部分数据写入和读取工作。它期望子类实现跨数据集分割的特征字典生成器(_split_generators)。有关详细信息,请参阅方法文档字符串。

class datasets.ArrowBasedBuilder

< >

( cache_dir: typing.Optional[str] = None dataset_name: typing.Optional[str] = None config_name: typing.Optional[str] = None hash: typing.Optional[str] = None base_path: typing.Optional[str] = None info: typing.Optional[datasets.info.DatasetInfo] = None features: typing.Optional[datasets.features.features.Features] = None token: typing.Union[bool, str, NoneType] = None repo_id: typing.Optional[str] = None data_files: typing.Union[str, list, dict, datasets.data_files.DataFilesDict, NoneType] = None data_dir: typing.Optional[str] = None storage_options: typing.Optional[dict] = None writer_batch_size: typing.Optional[int] = None config_id: typing.Optional[str] = None **config_kwargs )

Base class for datasets with data generation based on Arrow loading functions (CSV/JSON/Parquet).

class datasets.BuilderConfig

< >

( name: str = 'default' version: typing.Union[datasets.utils.version.Version, str, NoneType] = 0.0.0 data_dir: typing.Optional[str] = None data_files: typing.Union[datasets.data_files.DataFilesDict, datasets.data_files.DataFilesPatternsDict, NoneType] = None description: typing.Optional[str] = None )

参数

  • name (str, defaults to default) — 配置的名称。
  • version (Versionstr, defaults to 0.0.0) — 配置的版本。
  • data_dir (str, optional) — 包含源数据的目录的路径。
  • data_files (DataFilesDictDataFilesPatternsDictNoneType, defaults to None) — 源数据文件的路径。
  • description (str, optional) — 配置的人类可读描述。

DatasetBuilder 数据配置的基类。

具有数据配置选项的 DatasetBuilder 子类应继承自 BuilderConfig 并添加自己的属性。

create_config_id

< >

( config_kwargs: dict custom_features: typing.Optional[datasets.features.features.Features] = None )

配置 ID 用于构建缓存目录。默认情况下,它等于配置名称。但是,配置名称不足以唯一标识正在生成的数据集,因为它没有考虑到

  • 可以用来覆盖属性的配置 kwargs
  • 用于写入数据集的自定义特征
  • json/text/csv/pandas 数据集的 data_files

因此,配置 ID 只是配置名称,后面可能带有基于这些内容的后缀。

下载

class datasets.DownloadManager

< >

( dataset_name: typing.Optional[str] = None data_dir: typing.Optional[str] = None download_config: typing.Optional[datasets.download.download_config.DownloadConfig] = None base_path: typing.Optional[str] = None record_checksums = True )

下载

< >

( url_or_urls ) strlistdict

参数

  • url_or_urls (strlistdict) — 要下载的 URL 或 listdict。每个 URL 都是一个 str

返回

strlistdict

与给定的输入 url_or_urls 匹配的下载路径。

下载给定的 URL。

默认情况下,下载只使用一个进程。传递自定义的 download_config.num_proc 来改变此行为。

示例

>>> downloaded_files = dl_manager.download('https://storage.googleapis.com/seldon-datasets/sentence_polarity_v1/rt-polaritydata.tar.gz')

download_and_extract

< >

( url_or_urls ) 解压后的路径(s)

参数

  • url_or_urls (strlistdict) — 要下载和解压的 URL 或 listdict。每个 URL 都是一个 str

返回

解压后的路径(s)

str,给定 URL 的解压路径。

下载并解压给定的 url_or_urls

大致相当于

extracted_paths = dl_manager.extract(dl_manager.download(url_or_urls))

extract

< >

( path_or_paths ) 解压后的路径(s)

参数

  • path_or_paths (路径或 listdict) — 要解压的文件路径。每个路径都是一个 str

返回

解压后的路径(s)

str,与给定的 input path_or_paths 匹配的解压路径。

解压给定的路径。

示例

>>> downloaded_files = dl_manager.download('https://storage.googleapis.com/seldon-datasets/sentence_polarity_v1/rt-polaritydata.tar.gz')
>>> extracted_files = dl_manager.extract(downloaded_files)

iter_archive

< >

( path_or_buf: typing.Union[str, _io.BufferedReader] ) tuple[str, io.BufferedReader]

参数

  • path_or_buf (strio.BufferedReader) — 归档路径或归档二进制文件对象。

产生

tuple[str, io.BufferedReader]

迭代归档内的文件。

示例

>>> archive = dl_manager.download('https://storage.googleapis.com/seldon-datasets/sentence_polarity_v1/rt-polaritydata.tar.gz')
>>> files = dl_manager.iter_archive(archive)

iter_files

< >

( paths: typing.Union[str, list[str]] ) str

参数

  • paths (strlist of str) — 根路径。

产生

字符串

迭代文件路径。

示例

>>> files = dl_manager.download_and_extract('https://huggingface.co/datasets/AI-Lab-Makerere/beans/resolve/main/data/train.zip')
>>> files = dl_manager.iter_files(files)

class datasets.StreamingDownloadManager

< >

( dataset_name: typing.Optional[str] = None data_dir: typing.Optional[str] = None download_config: typing.Optional[datasets.download.download_config.DownloadConfig] = None base_path: typing.Optional[str] = None )

Download manager that uses the ”::” separator to navigate through (possibly remote) compressed archives. Contrary to the regular DownloadManager, the download and extract methods don’t actually download nor extract data, but they rather return the path or url that could be opened using the xopen function which extends the built-in open function to stream data from remote files。

下载

< >

( url_or_urls ) url(s)

参数

  • url_or_urls (strlistdict) — 用于流式传输数据的文件的 URL(s)。每个 url 都是一个 str

返回

url(s)

(strlistdict),用于流式传输数据的 URL(s),与给定的输入 url_or_urls 匹配。

为流式传输文件准备 URL(s)(添加解压协议)。

示例

>>> downloaded_files = dl_manager.download('https://storage.googleapis.com/seldon-datasets/sentence_polarity_v1/rt-polaritydata.tar.gz')

download_and_extract

This is the lazy version of DownloadManager.download for streaming.

( url_or_urls ) url(s)

参数

返回

url(s)

(strlistdict),用于流式传输数据的 URL(s),与给定的输入 url_or_urls 匹配。

为流式传输准备给定的 url_or_urls(添加解压协议)。

This is the lazy version of DownloadManager.download_and_extract for streaming.

Is equivalent to

urls = dl_manager.extract(dl_manager.download(url_or_urls))

extract

< >

( url_or_urls ) url(s)

参数

  • url_or_urls (strlistdict) — 用于流式传输数据的 URL(s)。每个 url 都是一个 str

返回

url(s)

(strlistdict),用于流式传输数据的 URL(s),与给定的输入 url_or_urls 匹配。

为给定的 url(s) 添加流式传输的解压协议。

This is the lazy version of DownloadManager.extract for streaming.

示例

>>> downloaded_files = dl_manager.download('https://storage.googleapis.com/seldon-datasets/sentence_polarity_v1/rt-polaritydata.tar.gz')
>>> extracted_files = dl_manager.extract(downloaded_files)

iter_archive

< >

( urlpath_or_buf: typing.Union[str, _io.BufferedReader] ) tuple[str, io.BufferedReader]

参数

  • urlpath_or_buf (strio.BufferedReader) — 归档路径或归档二进制文件对象。

产生

tuple[str, io.BufferedReader]

迭代归档内的文件。

示例

>>> archive = dl_manager.download('https://storage.googleapis.com/seldon-datasets/sentence_polarity_v1/rt-polaritydata.tar.gz')
>>> files = dl_manager.iter_archive(archive)

iter_files

< >

( urlpaths: typing.Union[str, list[str]] ) str

参数

  • urlpaths (strlist of str) — 根路径。

产生

字符串

迭代文件。

示例

>>> files = dl_manager.download_and_extract('https://huggingface.co/datasets/AI-Lab-Makerere/beans/resolve/main/data/train.zip')
>>> files = dl_manager.iter_files(files)

class datasets.DownloadConfig

< >

( cache_dir: typing.Union[str, pathlib.Path, NoneType] = None force_download: bool = False resume_download: bool = False local_files_only: bool = False proxies: typing.Optional[dict] = None user_agent: typing.Optional[str] = None extract_compressed_file: bool = False force_extract: bool = False delete_extracted: bool = False extract_on_the_fly: bool = False use_etag: bool = True num_proc: typing.Optional[int] = None max_retries: int = 1 token: typing.Union[str, bool, NoneType] = None storage_options: dict = <factory> download_desc: typing.Optional[str] = None disable_tqdm: bool = False )

参数

  • cache_dir (strPath, optional) — 指定一个缓存目录来保存文件(覆盖默认缓存目录)。
  • force_download (bool, defaults to False) — 如果为 True,即使文件已缓存,也会重新下载。
  • resume_download (bool, defaults to False) — 如果为 True,则在找到不完整的文件时恢复下载。
  • proxies (dict, optional) —
  • user_agent (str, optional) — 在远程请求中附加到 user-agent 的可选字符串或 dict。
  • extract_compressed_file (bool, defaults to False) — 如果为 True 且路径指向 zip 或 tar 文件,则在归档旁边的一个文件夹中解压该压缩文件。
  • force_extract (bool, defaults to False) — 如果 extract_compressed_fileTrue 且归档已被解压,则重新解压归档并覆盖解压的文件夹。
  • delete_extracted (bool, defaults to False) — 是否删除(或保留)解压的文件。
  • extract_on_the_fly (bool, defaults to False) — 如果为 True,则在读取压缩文件时对其进行解压。
  • use_etag (bool, defaults to True) — 是否使用 ETag HTTP 响应头验证缓存的文件。
  • num_proc (int, optional) — 并行下载文件的进程数。
  • max_retries (int, default to 1) — 发生故障时重试 HTTP 请求的次数。
  • token (strbool, optional) — 用于 Datasets Hub 上远程文件的 Bearer token 的可选字符串或布尔值。如果为 True 或未指定,将从 ~/.huggingface 获取 token。
  • storage_options (dict, optional) — 传递给数据集文件系统后端的键/值对,如果有的话。
  • download_desc (str, optional) — 在下载文件时与进度条一起显示的描述。
  • disable_tqdm (bool, defaults to False) — 是否禁用单个文件下载进度条

用于我们的缓存路径管理器的配置。

class datasets.DownloadMode

< >

( value names = None module = None qualname = None type = None start = 1 )

用于处理预先存在的下载和数据的 Enum

默认模式是 REUSE_DATASET_IF_EXISTS,它将重用原始下载和准备好的数据集(如果存在)。

生成模式

下载 数据集
REUSE_DATASET_IF_EXISTS (默认) 重用 重用
REUSE_CACHE_IF_EXISTS 重用 新鲜
FORCE_REDOWNLOAD 新鲜 新鲜

验证

class datasets.VerificationMode

< >

( value names = None module = None qualname = None type = None start = 1 )

指定要运行哪些验证检查的 Enum

默认模式是 BASIC_CHECKS,它只执行基本的检查以避免在首次生成/下载数据集时减慢速度。

验证模式

验证检查
ALL_CHECKS 分割检查和下载文件的有效性(文件数量、校验和)
BASIC_CHECKS (默认) ALL_CHECKS 相同,但不检查下载的文件
NO_CHECKS

Splits

class datasets.SplitGenerator

< >

( name: str gen_kwargs: dict = <factory> )

参数

  • name (str) — Generator 将用于创建示例的 Split 的名称。
  • **gen_kwargs (additional keyword arguments) — 转发给 builder 的 DatasetBuilder._generate_examples 方法的关键字参数。

定义生成器的分割信息。

这应该是 GeneratorBasedBuilder._split_generators 返回的值。有关更多信息和用法示例,请参阅 GeneratorBasedBuilder._split_generators

示例

>>> datasets.SplitGenerator(
...     name=datasets.Split.TRAIN,
...     gen_kwargs={"split_key": "train", "files": dl_manager.download_and_extract(url)},
... )

class datasets.Split

< >

( name )

Enum,用于数据集拆分。

数据集通常会分成不同的子集,用于训练和评估的各个阶段。

  • TRAIN:训练数据。
  • VALIDATION:验证数据。如果存在,通常在迭代模型时(例如更改超参数、模型架构等)用作评估数据。
  • TEST:测试数据。这是报告指标的数据。通常不希望在模型迭代中使用它,因为你可能会对其进行过度拟合。
  • ALL:所有已定义数据集拆分的并集。

所有拆分(包括组合)都继承自 datasets.SplitBase

有关拆分的更多信息,请参阅 指南

示例

>>> 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)},
... )

class datasets.NamedSplit

< >

( name )

对应于命名拆分(train、test 等)的描述符。

示例

每个描述符都可以使用加法或切片与其他描述符组合

split = datasets.Split.TRAIN.subsplit(datasets.percent[0:25]) + datasets.Split.TEST

结果拆分将对应于 25% 的 train 拆分与 100% 的 test 拆分合并。

一个拆分不能添加两次,所以以下操作会失败

split = (
        datasets.Split.TRAIN.subsplit(datasets.percent[:25]) +
        datasets.Split.TRAIN.subsplit(datasets.percent[75:])
)  # Error
split = datasets.Split.TEST + datasets.Split.ALL  # Error

切片只能应用一次。所以以下操作是有效的

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])

但这无效

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])

class datasets.NamedSplitAll

< >

( )

对应于所有已定义数据集拆分的并集的拆分。

class datasets.ReadInstruction

< >

( split_name rounding = None from_ = None to = None unit = None )

数据集的读取指令。

示例

# The following lines are equivalent:
ds = datasets.load_dataset('ylecun/mnist', split='test[:33%]')
ds = datasets.load_dataset('ylecun/mnist', split=datasets.ReadInstruction.from_spec('test[:33%]'))
ds = datasets.load_dataset('ylecun/mnist', split=datasets.ReadInstruction('test', to=33, unit='%'))
ds = datasets.load_dataset('ylecun/mnist', split=datasets.ReadInstruction(
'test', from_=0, to=33, unit='%'))

# The following lines are equivalent:
ds = datasets.load_dataset('ylecun/mnist', split='test[:33%]+train[1:-1]')
ds = datasets.load_dataset('ylecun/mnist', split=datasets.ReadInstruction.from_spec(
'test[:33%]+train[1:-1]'))
ds = datasets.load_dataset('ylecun/mnist', split=(
datasets.ReadInstruction('test', to=33, unit='%') +
datasets.ReadInstruction('train', from_=1, to=-1, unit='abs')))

# The following lines are equivalent:
ds = datasets.load_dataset('ylecun/mnist', split='test[:33%](pct1_dropremainder)')
ds = datasets.load_dataset('ylecun/mnist', split=datasets.ReadInstruction.from_spec(
'test[:33%](pct1_dropremainder)'))
ds = datasets.load_dataset('ylecun/mnist', split=datasets.ReadInstruction(
'test', from_=0, to=33, unit='%', rounding="pct1_dropremainder"))

# 10-fold validation:
tests = datasets.load_dataset(
'ylecun/mnist',
[datasets.ReadInstruction('train', from_=k, to=k+10, unit='%')
for k in range(0, 100, 10)])
trains = datasets.load_dataset(
'ylecun/mnist',
[datasets.ReadInstruction('train', to=k, unit='%') + datasets.ReadInstruction('train', from_=k+10, unit='%')
for k in range(0, 100, 10)])

from_spec

< >

( spec )

参数

  • spec (str) — 拆分(和/或可选切片)读取 + 可选的百分比单位四舍五入。 可以指定切片,使用绝对数字(int)或百分比(int)。

从字符串规范创建 ReadInstruction 实例。

示例

test: test split.
test + validation: test split + validation split.
test[10:]: test split, minus its first 10 records.
test[:10%]: first 10% records of test split.
test[:20%](pct1_dropremainder): first 10% records, rounded with the pct1_dropremainder rounding.
test[:-5%]+train[40%:60%]: first 95% of test + middle 20% of train.

to_absolute

< >

( name2len )

参数

  • name2len (dict) — 将拆分名称与示例数量相关联。

将指令转换为绝对指令列表。

这些绝对指令随后将相加。

Version

class datasets.Version

< >

( version_str: str description: typing.Optional[str] = None major: typing.Union[str, int, NoneType] = None minor: typing.Union[str, int, NoneType] = None patch: typing.Union[str, int, NoneType] = None )

参数

  • version_str (str) — 数据集的版本。
  • description (str) — 此版本中的新内容说明。
  • major (str) —
  • minor (str) —
  • patch (str) —

数据集版本 MAJOR.MINOR.PATCH

示例

>>> VERSION = datasets.Version("1.0.0")
在 GitHub 上更新

© . This site is unofficial and not affiliated with Hugging Face, Inc.