Skill Tracer
Skills › Scientific Agent Skills › hugging-science › using-datasets.md

using-datasets.md

100 lines · skills/hugging-science/references/using-datasets.md at 5f2bc03

Open on GitHub
1# Using scientific datasets from the catalog
2
3A dataset entry points to a Hub repository, which may contain CSV/Parquet,
4FASTA, HDF5, Zarr, or an author's custom layout. `load_dataset` does not make all
5of these formats interchangeable. Inspect the card and file manifest before any
6large download. Record repository commit, selected files, config and split.
7

Using scientific datasets from the catalog

A dataset entry points to a Hub repository, which may contain CSV/Parquet, FASTA, HDF5, Zarr, or an author's custom layout. load_dataset does not make all of these formats interchangeable. Inspect the card and file manifest before any large download. Record repository commit, selected files, config and split.

Raw lines 1 to 7
8## Install and authenticate
9
10Use an active virtual environment or separate project; the combined tested stack
11is in [using-models.md](using-models.md). Datasets 5.0.1 requires Hub below 2.0.
13```bash
14uv pip install 'datasets==5.0.1' 'huggingface-hub<2' python-dotenv
15```
17Load `.env` before Hub-dependent imports if the project uses `HF_TOKEN`; keep
18`.env` gitignored. Public metadata/data often needs no token. Gated access still
19requires the repository's terms/access approval; setting a token does not grant it.

Install and authenticate

Use an active virtual environment or separate project; the combined tested stack is in using-models.md. Datasets 5.0.1 requires Hub below 2.0.

uv pip install 'datasets==5.0.1' 'huggingface-hub<2' python-dotenv

Load .env before Hub-dependent imports if the project uses HF_TOKEN; keep .env gitignored. Public metadata/data often needs no token. Gated access still requires the repository's terms/access approval; setting a token does not grant it.

Raw lines 8 to 20
21## Discover metadata before rows
23```python
24from dotenv import load_dotenv
25load_dotenv()
26from datasets import get_dataset_config_names, get_dataset_split_names
27from huggingface_hub import HfApi
29repo = "opig/OAS"
30revision = HfApi().dataset_info(repo).sha
31configs = get_dataset_config_names(repo, revision=revision)
32print(configs)
33print(get_dataset_split_names(repo, config_name="paired", revision=revision))
34```
36The OAS card currently declares `default` and `paired` configs. Its `paired`
37config points to `paired/*.csv`; species is `meta_Species`, not `species`.
38The generic code `ex.get("species") == "human"` silently discards every row.
40Illustrative remote streaming (card/source verified; no large OAS shard fetched):
42```python
43from datasets import Dataset, load_dataset
45ds = load_dataset(repo, name="paired", revision=revision, split="train", streaming=True)
46sample = next(iter(ds))
47print(sample.keys())
48if "meta_Species" not in sample:
49 raise ValueError("OAS schema changed; inspect the selected configuration")
50human_only = ds.filter(lambda ex: ex["meta_Species"] == "human")
51subset = Dataset.from_list(list(human_only.take(100)))
52if not len(subset):
53 raise ValueError("No matching records in the selected data")
54```
56`streaming=True` with `split` returns an `IterableDataset`; without `split` it
57returns a split mapping. `filter` is lazy and does not imply server-side filtering:
58reading 100 matches may scan many rows. Only call `Dataset.from_list` on a bounded
59subset. Local synthetic CSV tests exercise this loading/filtering/materialization
60pattern. They do not establish remote shard performance or scientific suitability.

Discover metadata before rows

from dotenv import load_dotenv
load_dotenv()
from datasets import get_dataset_config_names, get_dataset_split_names
from huggingface_hub import HfApi

repo = "opig/OAS"
revision = HfApi().dataset_info(repo).sha
configs = get_dataset_config_names(repo, revision=revision)
print(configs)
print(get_dataset_split_names(repo, config_name="paired", revision=revision))

The OAS card currently declares default and paired configs. Its paired config points to paired/*.csv; species is meta_Species, not species. The generic code ex.get("species") == "human" silently discards every row.

Illustrative remote streaming (card/source verified; no large OAS shard fetched):

from datasets import Dataset, load_dataset

ds = load_dataset(repo, name="paired", revision=revision, split="train", streaming=True)
sample = next(iter(ds))
print(sample.keys())
if "meta_Species" not in sample:
    raise ValueError("OAS schema changed; inspect the selected configuration")
human_only = ds.filter(lambda ex: ex["meta_Species"] == "human")
subset = Dataset.from_list(list(human_only.take(100)))
if not len(subset):
    raise ValueError("No matching records in the selected data")

streaming=True with split returns an IterableDataset; without split it returns a split mapping. filter is lazy and does not imply server-side filtering: reading 100 matches may scan many rows. Only call Dataset.from_list on a bounded subset. Local synthetic CSV tests exercise this loading/filtering/materialization pattern. They do not establish remote shard performance or scientific suitability.

Raw lines 21 to 61
62## OpenGenome2 is not a safe default full download
64[OpenGenome2](https://huggingface.co/datasets/arcinstitute/opengenome2) contains
658.8 trillion base pairs, with raw FASTA and preprocessed JSONL that can include
66special tokens and phylogenetic tags. Its manifest includes multipart compressed
67FASTA files such as `.fasta.gz.aa`. Its JSONL directory also includes complete `.jsonl.gz` shards; select those explicitly when using the JSON loader. The multipart FASTA files are pieces of a compressed
68stream, not individually decodable shards. Do not pass a broad wildcard over all
69parts to `load_dataset` or assume `streaming=True` reassembles them.
71Choose a documented, complete file or explicitly reconstruct the selected ordered
72parts after budgeting disk/network. Use the JSON loader for complete JSONL,
73sequence tools for FASTA, and verify the actual JSON field names before tokenizing.
74No whole-repository `load_dataset("arcinstitute/opengenome2")` shortcut is
75validated here. Keep assembly/accession provenance for downstream contamination checks.

OpenGenome2 is not a safe default full download

OpenGenome2 contains 8.8 trillion base pairs, with raw FASTA and preprocessed JSONL that can include special tokens and phylogenetic tags. Its manifest includes multipart compressed FASTA files such as .fasta.gz.aa. Its JSONL directory also includes complete .jsonl.gz shards; select those explicitly when using the JSON loader. The multipart FASTA files are pieces of a compressed stream, not individually decodable shards. Do not pass a broad wildcard over all parts to load_dataset or assume streaming=True reassembles them.

Choose a documented, complete file or explicitly reconstruct the selected ordered parts after budgeting disk/network. Use the JSON loader for complete JSONL, sequence tools for FASTA, and verify the actual JSON field names before tokenizing. No whole-repository load_dataset("arcinstitute/opengenome2") shortcut is validated here. Keep assembly/accession provenance for downstream contamination checks.

Raw lines 62 to 76
77## Schema and split checks
79- DNA/protein alphabets, ambiguity codes and special tokens must match the model.
80 Evo2 uses its native tokenizer; do not assume an `AutoTokenizer` exists.
81- `Merck/TEDDY` is a **model/code repository**, not a dataset config named
82 `single_cell`. Follow its documented AnnData preprocessing.
83- Materials rows may serialize structures/CIFs; scientific imaging may use FITS,
84 DICOM or NIfTI. The Hub `mmu_legacysurvey_dr10_south_21` release is HATS/Parquet
85 with image-array fields; it is not a directory of FITS images.
86- Inspect shapes, dtypes, units, coordinate systems and missingness before batching.
87 A generic image decoder is not a scientific format validator.
88- Names such as `train` may describe storage layout only. Preserve donor, patient,
89 species, scaffold, chromosome or time groups as the scientific evaluation needs;
90 prevent near-duplicate and pretraining overlap from inflating reported performance.
91- Current Datasets does not execute dataset loading scripts. Adding
92 `trust_remote_code=True` cannot revive a legacy scripted loader; use maintained
93 standard files or the author's separately reviewed reader.
94- Pin licenses, preprocessing and tokenizer revisions alongside the data. Scientific
95 catalog inclusion does not establish consent, clinical suitability or commercial rights.
97Sources: [loading](https://huggingface.co/docs/datasets/loading),
98[streaming](https://huggingface.co/docs/datasets/stream),
99[OAS card](https://huggingface.co/datasets/opig/OAS),
100[Datasets 5.0.1 loader](https://github.com/huggingface/datasets/blob/5.0.1/src/datasets/load.py).

Schema and split checks

  • DNA/protein alphabets, ambiguity codes and special tokens must match the model. Evo2 uses its native tokenizer; do not assume an AutoTokenizer exists.
  • Merck/TEDDY is a model/code repository, not a dataset config named single_cell. Follow its documented AnnData preprocessing.
  • Materials rows may serialize structures/CIFs; scientific imaging may use FITS, DICOM or NIfTI. The Hub mmu_legacysurvey_dr10_south_21 release is HATS/Parquet with image-array fields; it is not a directory of FITS images.
  • Inspect shapes, dtypes, units, coordinate systems and missingness before batching. A generic image decoder is not a scientific format validator.
  • Names such as train may describe storage layout only. Preserve donor, patient, species, scaffold, chromosome or time groups as the scientific evaluation needs; prevent near-duplicate and pretraining overlap from inflating reported performance.
  • Current Datasets does not execute dataset loading scripts. Adding trust_remote_code=True cannot revive a legacy scripted loader; use maintained standard files or the author's separately reviewed reader.
  • Pin licenses, preprocessing and tokenizer revisions alongside the data. Scientific catalog inclusion does not establish consent, clinical suitability or commercial rights.

Sources: loading, streaming, OAS card, Datasets 5.0.1 loader.

Raw lines 77 to 100