Datasets:
Update README.md
Browse files
README.md
CHANGED
|
@@ -1097,27 +1097,34 @@ Example (inside a `.tar` shard):
|
|
| 1097 |
You can load the WebDataset directly with Hugging Face’s `datasets` library:
|
| 1098 |
|
| 1099 |
```python
|
| 1100 |
-
import
|
| 1101 |
-
from
|
| 1102 |
-
|
| 1103 |
-
|
|
|
|
|
|
|
| 1104 |
|
| 1105 |
-
|
| 1106 |
-
|
| 1107 |
-
|
| 1108 |
-
|
| 1109 |
-
|
| 1110 |
-
paths = yaml.load(open(data_file_path, "r"), Loader=yaml.FullLoader)
|
| 1111 |
|
| 1112 |
-
|
| 1113 |
|
| 1114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1115 |
audio = sample['flac']
|
| 1116 |
print(sample['metadata.json'])
|
| 1117 |
Audio(audio['array'], rate=audio['sampling_rate'])
|
| 1118 |
````
|
| 1119 |
|
| 1120 |
-
Replace `
|
| 1121 |
|
| 1122 |
-----
|
| 1123 |
|
|
|
|
| 1097 |
You can load the WebDataset directly with Hugging Face’s `datasets` library:
|
| 1098 |
|
| 1099 |
```python
|
| 1100 |
+
from datasets import load_dataset
|
| 1101 |
+
from huggingface_hub import list_repo_files
|
| 1102 |
+
|
| 1103 |
+
repo_id = "sarulab-speech/yodas2_sidon"
|
| 1104 |
+
subset="en000"
|
| 1105 |
+
all_files = list_repo_files(repo_id, repo_type="dataset")
|
| 1106 |
|
| 1107 |
+
urls = [
|
| 1108 |
+
f"https://huggingface.co/datasets/{repo_id}/resolve/main/{f}"
|
| 1109 |
+
for f in sorted(all_files)
|
| 1110 |
+
if f.endswith(".tar.gz") and f.startswith(subset)
|
| 1111 |
+
]
|
|
|
|
| 1112 |
|
| 1113 |
+
print(f"Found {len(urls)} shards.")
|
| 1114 |
|
| 1115 |
+
dataset = load_dataset(
|
| 1116 |
+
"webdataset",
|
| 1117 |
+
data_files={"train": urls},
|
| 1118 |
+
streaming=True
|
| 1119 |
+
)['train']
|
| 1120 |
+
from IPython.display import Audio
|
| 1121 |
+
sample = next(iter(dataset))
|
| 1122 |
audio = sample['flac']
|
| 1123 |
print(sample['metadata.json'])
|
| 1124 |
Audio(audio['array'], rate=audio['sampling_rate'])
|
| 1125 |
````
|
| 1126 |
|
| 1127 |
+
Replace `subset` with the desired subset.
|
| 1128 |
|
| 1129 |
-----
|
| 1130 |
|