"""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_bridgeimportload_dataset_from_hub,binary_to_plaid_samplefromplaid.examples.configimport_HF_REPOSclass_LazyDatasets:""" Lazy-loaded example datasets for PLAID. Access datasets lazily: download and convert only on first access, then cache. """def__init__(self):self._cache:dict[str,Dataset]={}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:ds_stream=load_dataset_from_hub(hf_repo,split="all_samples",streaming=True)samples=[]for_inrange(2):hf_sample=next(iter(ds_stream))samples.append(binary_to_plaid_sample(hf_sample))dataset=Dataset(samples=samples)self._cache[ex_name]=datasetreturndatasetexceptExceptionase:# pragma: no coverraiseRuntimeError(f"Failed to download or convert dataset '{hf_repo}'.")fromedef_make_example(ex_name,hf_repo):defprop(self):returnself._load_dataset(ex_name,hf_repo)returnproperty(prop)# Generate propertiesforex_name,hf_repoin_HF_REPOS.items():setattr(_LazyDatasets,ex_name,_make_example(ex_name,hf_repo))# Generate class