{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "5d3c22fa-b62f-4828-bb55-60640e1a393c",
"metadata": {},
"outputs": [],
"source": [
"!pip install datasets"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9f6e89ca-43c5-409c-987e-94b6a1c89082",
"metadata": {},
"outputs": [],
"source": [
"# 测试 datasets 正确性\n",
"!datasets-cli test /workspace/data/MNBVC-core --data_dir=/workspace/data/MNBVC-core --save_info --all_configs"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "2cb2a5cf-43b1-4372-8583-bd37455406a0",
"metadata": {},
"outputs": [],
"source": [
"from datasets import load_from_disk,load_dataset_builder, get_dataset_split_names, get_dataset_config_names\n",
"\n",
"DATASET='/workspace/data/MNBVC-core'\n",
"CONFIGURATION='qa_mfa'"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "ddadbe3a-5b78-4b22-8d5a-fb82b42dd01f",
"metadata": {},
"outputs": [
{
"ename": "FileNotFoundError",
"evalue": "Directory /workspace/data/MNBVC-core is neither a `Dataset` directory nor a `DatasetDict` directory.",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[15], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m ds \u001b[38;5;241m=\u001b[39m \u001b[43mload_from_disk\u001b[49m\u001b[43m(\u001b[49m\u001b[43mDATASET\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m/opt/conda/envs/envd/lib/python3.10/site-packages/datasets/load.py:2252\u001b[0m, in \u001b[0;36mload_from_disk\u001b[0;34m(dataset_path, fs, keep_in_memory, storage_options)\u001b[0m\n\u001b[1;32m 2250\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m DatasetDict\u001b[38;5;241m.\u001b[39mload_from_disk(dataset_path, keep_in_memory\u001b[38;5;241m=\u001b[39mkeep_in_memory, storage_options\u001b[38;5;241m=\u001b[39mstorage_options)\n\u001b[1;32m 2251\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m-> 2252\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mFileNotFoundError\u001b[39;00m(\n\u001b[1;32m 2253\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDirectory \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mdataset_path\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m is neither a `Dataset` directory nor a `DatasetDict` directory.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 2254\u001b[0m )\n",
"\u001b[0;31mFileNotFoundError\u001b[0m: Directory /workspace/data/MNBVC-core is neither a `Dataset` directory nor a `DatasetDict` directory."
]
}
],
"source": [
"ds = load_from_disk(DATASET)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "5fe8f56e-019f-475d-811a-f707450934e2",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Help on function load_from_disk in module datasets.load:\n",
"\n",
"load_from_disk(dataset_path: str, fs='deprecated', keep_in_memory: Optional[bool] = None, storage_options: Optional[dict] = None) -> Union[datasets.arrow_dataset.Dataset, datasets.dataset_dict.DatasetDict]\n",
" Loads a dataset that was previously saved using [`~Dataset.save_to_disk`] from a dataset directory, or\n",
" from a filesystem using any implementation of `fsspec.spec.AbstractFileSystem`.\n",
" \n",
" Args:\n",
" dataset_path (`str`):\n",
" Path (e.g. `\"dataset/train\"`) or remote URI (e.g.\n",
" `\"s3://my-bucket/dataset/train\"`) of the [`Dataset`] or [`DatasetDict`] directory where the dataset will be\n",
" loaded from.\n",
" fs (`~filesystems.S3FileSystem` or `fsspec.spec.AbstractFileSystem`, *optional*):\n",
" Instance of the remote filesystem used to download the files from.\n",
" \n",
" \n",
" \n",
" `fs` was deprecated in version 2.9.0 and will be removed in 3.0.0.\n",
" Please use `storage_options` instead, e.g. `storage_options=fs.storage_options`.\n",
" \n",
" \n",
" \n",
" keep_in_memory (`bool`, defaults to `None`):\n",
" Whether to copy the dataset in-memory. If `None`, the dataset\n",
" will not be copied in-memory unless explicitly enabled by setting `datasets.config.IN_MEMORY_MAX_SIZE` to\n",
" nonzero. See more details in the [improve performance](../cache#improve-performance) section.\n",
" \n",
" storage_options (`dict`, *optional*):\n",
" Key/value pairs to be passed on to the file-system backend, if any.\n",
" \n",
" \n",
" \n",
" Returns:\n",
" [`Dataset`] or [`DatasetDict`]:\n",
" - If `dataset_path` is a path of a dataset directory: the dataset requested.\n",
" - If `dataset_path` is a path of a dataset dict directory, a [`DatasetDict`] with each split.\n",
" \n",
" Example:\n",
" \n",
" ```py\n",
" >>> from datasets import load_from_disk\n",
" >>> ds = load_from_disk('path/to/dataset/directory')\n",
" ```\n",
"\n"
]
}
],
"source": [
"help(load_from_disk)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6a2a08b1-0f99-4944-bc6d-98d288f6e366",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}