Nodes/ComfyUI-huggingface_dataset/πŸ€— Dataset Take
ComfyUI Node

πŸ€— Dataset Take

Keep the first N rows β€” your streaming dataset's best friend

By StableLlamaΒ·Created a day agoΒ·Updated a day agoΒ· 1
πŸ€— Dataset Take
  • dataset
  • dataset
β—„n100β–Ί

You almost never want all fifty million rows. You want a few thousand to test a pipeline, a hundred to eyeball, ten to debug a node. πŸ€— Dataset Take is the "keep the first N and drop the rest" node, and it's the single most useful thing to drop in front of a big streaming load - it's how you make a lazy dataset actually lazy instead of a download-the-whole-world event.

How it works

It's datasets.Dataset.take (and IterableDataset.take) as a node. Two inputs:

  • dataset - what to trim.
  • n - how many leading rows to keep (default 100).

One output: a dataset limited to its first n rows. That's the whole node, and it's worth more than it looks because of when it matters.

The streaming story is the real story

With the loader's streaming on, Take is what keeps your graph fast. Feed a lazy IterableDataset into Take(50), then into πŸ€— Dataset To Data List / To LIST, and only those fifty rows ever get fetched from the Hub - the rest of the corpus is never downloaded. The README's own example workflow (imdb_streaming_skip_take) is exactly this pattern. Without a Take (or the loader's limit widget), even a "small" materialization of a streaming dataset can pull far more than you meant.

On a fully-loaded dataset Take is simpler: it's just a cap, a cheap way to bound how many rows your downstream loop processes. Pair it with Skip and you get a middle window (Skip(500) β†’ Take(100)); pair it with Shuffle and you get a pseudo-random sample; pair it with Sort and you get "top N by column" - sort first, then take.

Gotchas

Take keeps the first N in the current order, whatever that order is - unshuffled Hub data is usually in whatever order the author pushed it, so if you want a representative slice, shuffle (with a seed) before you take. And remember Take is positional, not selective: if you want specific rows, that's Select Rows' job (loaded-only); Take is for the front of the stream, which is why it's the streaming-safe one.

Installing it

Part of StableLlama/ComfyUI-huggingface_dataset. ComfyUI-Manager β†’ search "Hugging Face dataset", or:

cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-huggingface_dataset
pip install -r requirements.txt

Restart ComfyUI. Only runtime dependency is datasets, installed for you by Manager.

CategoryHugging Face πŸ€—

Inputs (2)

NameTypeDefaultDescription
datasetHUGGINGFACE_DATASETInput dataset to keep rows from (from the πŸ€— Dataset Loader or another dataset node).
nINT1001–2147483647Number of leading rows to keep.

Outputs (1)

NameTypeDescription
datasetHUGGINGFACE_DATASETThe dataset limited to its first n rows.