Upload loaders.py with huggingface_hub
Browse files59 unmodified lines606162636465664 unmodified lines71727374757677787980818283848586878889909130 unmodified lines12212312412512612712812913013113213313413513618 unmodified lines15515615715815916085 unmodified lines24624724824925025159 unmodified lines# loader may ingore this. In any case, the recipe, will limit the number of instances in the returned# stream, after load is complete.loader_limit: int = Nonepassclass LoadHF(Loader):4 unmodified linesdata_files: Optional[Union[str, Sequence[str], Mapping[str, Union[str, Sequence[str]]]]] = Nonestreaming: bool = Truedef process(self):try:with tempfile.TemporaryDirectory() as dir_to_be_deleted:dataset = hf_load_dataset(self.path,name=self.name,data_dir=self.data_dir,data_files=self.data_files,streaming=self.streaming,cache_dir=None if self.streaming else dir_to_be_deleted,split=self.split,trust_remote_code=settings.allow_unverified_code,)if self.split is not None:dataset = {self.split: dataset}except (30 unmodified linesfiles: Dict[str, str]chunksize: int = 1000def load_csv(self, file):for chunk in pd.read_csv(file, chunksize=self.chunksize):for _index, row in chunk.iterrows():yield row.to_dict()def process(self):return MultiStream({name: Stream(generator=self.load_csv, gen_kwargs={"file": file})for name, file in self.files.items()})18 unmodified lines"Please obtain kaggle credentials https://christianjmills.com/posts/kaggle-obtain-api-key-tutorial/ and save them to local ./kaggle.json file")def prepare(self):super().prepare()from opendatasets import download85 unmodified linesassert (self.aws_secret_access_key is not None), f"Please set {self.aws_secret_access_key_env} environmental variable"def process(self):cos = ibm_boto3.resource(59 unmodified lines606162636465664 unmodified lines71727374757677787980818283848586878889909192939495969730 unmodified lines12812913013113213313413513613713813914014114214314414514614714814915018 unmodified lines16917017117217317417517617785 unmodified lines26326426526626726826927059 unmodified lines# loader may ingore this. In any case, the recipe, will limit the number of instances in the returned# stream, after load is complete.loader_limit: int = Nonestreaming: bool = Falseclass LoadHF(Loader):4 unmodified linesdata_files: Optional[Union[str, Sequence[str], Mapping[str, Union[str, Sequence[str]]]]] = Nonestreaming: bool = Falsedef process(self):try:with tempfile.TemporaryDirectory() as dir_to_be_deleted:try:dataset = hf_load_dataset(self.path,name=self.name,data_dir=self.data_dir,data_files=self.data_files,streaming=self.streaming,cache_dir=None if self.streaming else dir_to_be_deleted,split=self.split,trust_remote_code=settings.allow_unverified_code,)except ValueError as e:if "trust_remote_code" in str(e):raise ValueError(f"{self.__class__.__name__} cannot run remote code from huggingface without setting unitxt.settings.allow_unverified_code=True or by setting environment vairable: UNITXT_ALLOW_UNVERIFIED_CODE.") from eif self.split is not None:dataset = {self.split: dataset}except (30 unmodified linesfiles: Dict[str, str]chunksize: int = 1000def stream_csv(self, file):for chunk in pd.read_csv(file, chunksize=self.chunksize):for _index, row in chunk.iterrows():yield row.to_dict()def process(self):if self.streaming:return MultiStream({name: Stream(generator=self.stream_csv, gen_kwargs={"file": file})for name, file in self.files.items()})return MultiStream({name: pd.read_csv(file).to_dict("records")for name, file in self.files.items()})18 unmodified lines"Please obtain kaggle credentials https://christianjmills.com/posts/kaggle-obtain-api-key-tutorial/ and save them to local ./kaggle.json file")if self.streaming:raise NotImplementedError("LoadFromKaggle cannot load with streaming.")def prepare(self):super().prepare()from opendatasets import download85 unmodified linesassert (self.aws_secret_access_key is not None), f"Please set {self.aws_secret_access_key_env} environmental variable"if self.streaming:raise NotImplementedError("LoadFromKaggle cannot load with streaming.")def process(self):cos = ibm_boto3.resource(
loaders.py+33-14