"""Examples for PLAID `Dataset` objects."""# -*- coding: utf-8 -*-## This file is subject to the terms and conditions defined in# file 'LICENSE.txt', which is part of this source code package.##fromplaidimportDatasetfromplaid.bridges.huggingface_bridgeimportstreamed_huggingface_dataset_to_plaidfromplaid.examples.configimport_HF_REPOS
[docs]class_LazyDatasets:""" Lazy-loaded example datasets for PLAID. Access datasets lazily: download and convert only on first access, then cache. """def__init__(self):
[docs]def_load_dataset(self,ex_name:str,hf_repo:str)->Dataset:""" Generic helper to lazily load a HuggingFace dataset and convert it to PLAID. Args: ex_name (str): Example name. hf_repo (str): HuggingFace dataset repository name in the PLAID-datasets community. Returns: Dataset: The PLAID dataset. Raises: RuntimeError: If the dataset cannot be downloaded or converted. """ifex_nameinself._cache:returnself._cache[ex_name]try:dataset,_=streamed_huggingface_dataset_to_plaid(hf_repo,2)self._cache[ex_name]=datasetreturndatasetexceptExceptionase:# pragma: no coverraiseRuntimeError(f"Failed to download or convert dataset '{hf_repo}'.")frome