Fix TOO MANY REQUESTS error
#2
by albertvillanova HF Staff - opened
107 unmodified lines1081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391 unmodified line1411421431441451461471481491501511521 unmodified line154155156157158159160107 unmodified linesdl_dir = dl_manager.download_and_extract(_URLs)dataset_dir = os.path.join(dl_dir, "datasets", "TwADR-L")# dataset supports k-foldssplits = []for split_name in [datasets.Split.TRAIN,datasets.Split.VALIDATION,datasets.Split.TEST,]:for fold_filepath in glob.glob(os.path.join(dataset_dir, f"TwADR-L.fold-*.{split_name}.txt")):fold_id = re.search("TwADR-L\.fold-(\d)\.", fold_filepath).group(1)split_id = f"{split_name}_{fold_id}"splits.append(datasets.SplitGenerator(name=split_id,gen_kwargs={"filepath": fold_filepath, "split_id": split_id},))return splitsdef _generate_examples(self, filepath, split_id):with open(filepath, "r", encoding="latin-1") as f:for i, line in enumerate(f):id = f"{split_id}_{i}"cui, medical_concept, social_media_text = line.strip().split("\t")if self.config.schema == "source":yield id, {"cui": cui,"medical_concept": medical_concept,"social_media_text": social_media_text,1 unmodified lineelif self.config.schema == "bigbio_kb":text_type = "social_media_text"offset = (0, len(social_media_text))yield id, {"id": id,"document_id": id,"passages": [{"id": f"{id}_passage","type": text_type,"text": [social_media_text],"offsets": [offset],1 unmodified line],"entities": [{"id": f"{id}_entity","type": text_type,"text": [social_media_text],"offsets": [offset],107 unmodified lines1081091101111121131141151161171181191201211221231241251261271281291301311321331341 unmodified line1361371381391401411421431441451461471 unmodified line149150151152153154155107 unmodified linesdl_dir = dl_manager.download_and_extract(_URLs)dataset_dir = os.path.join(dl_dir, "datasets", "TwADR-L")# dataset supports k-foldssplits_names = ["train", "validation", "test"]fold_ids = range(10)return [datasets.SplitGenerator(name=f"{split_name}_{fold_id}",gen_kwargs={"filepath": os.path.join(dataset_dir, f"TwADR-L.fold-{fold_id}.{split_name}.txt"),"split_id": f"{split_name}_{fold_id}",},)for split_name in splits_namesfor fold_id in fold_ids]def _generate_examples(self, filepath, split_id):with open(filepath, "r", encoding="latin-1") as f:for i, line in enumerate(f):guid = f"{split_id}_{i}"cui, medical_concept, social_media_text = line.strip().split("\t")if self.config.schema == "source":yield guid, {"cui": cui,"medical_concept": medical_concept,"social_media_text": social_media_text,1 unmodified lineelif self.config.schema == "bigbio_kb":text_type = "social_media_text"offset = (0, len(social_media_text))yield guid, {"id": guid,"document_id": guid,"passages": [{"id": f"{guid}_passage","type": text_type,"text": [social_media_text],"offsets": [offset],1 unmodified line],"entities": [{"id": f"{guid}_entity","type": text_type,"text": [social_media_text],"offsets": [offset],
twadrl.py+20-25