Fix TOO MANY REQUESTS error
#2
by
albertvillanova
HF Staff
- opened
twadrl.py
CHANGED
|
@@ -108,32 +108,27 @@ class TwADRL(datasets.GeneratorBasedBuilder):
|
|
| 108 |
dl_dir = dl_manager.download_and_extract(_URLs)
|
| 109 |
dataset_dir = os.path.join(dl_dir, "datasets", "TwADR-L")
|
| 110 |
# dataset supports k-folds
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
datasets.
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
name=split_id,
|
| 125 |
-
gen_kwargs={"filepath": fold_filepath, "split_id": split_id},
|
| 126 |
-
)
|
| 127 |
-
)
|
| 128 |
-
return splits
|
| 129 |
|
| 130 |
def _generate_examples(self, filepath, split_id):
|
| 131 |
with open(filepath, "r", encoding="latin-1") as f:
|
| 132 |
for i, line in enumerate(f):
|
| 133 |
-
|
| 134 |
cui, medical_concept, social_media_text = line.strip().split("\t")
|
| 135 |
if self.config.schema == "source":
|
| 136 |
-
yield
|
| 137 |
"cui": cui,
|
| 138 |
"medical_concept": medical_concept,
|
| 139 |
"social_media_text": social_media_text,
|
|
@@ -141,12 +136,12 @@ class TwADRL(datasets.GeneratorBasedBuilder):
|
|
| 141 |
elif self.config.schema == "bigbio_kb":
|
| 142 |
text_type = "social_media_text"
|
| 143 |
offset = (0, len(social_media_text))
|
| 144 |
-
yield
|
| 145 |
-
"id":
|
| 146 |
-
"document_id":
|
| 147 |
"passages": [
|
| 148 |
{
|
| 149 |
-
"id": f"{
|
| 150 |
"type": text_type,
|
| 151 |
"text": [social_media_text],
|
| 152 |
"offsets": [offset],
|
|
@@ -154,7 +149,7 @@ class TwADRL(datasets.GeneratorBasedBuilder):
|
|
| 154 |
],
|
| 155 |
"entities": [
|
| 156 |
{
|
| 157 |
-
"id": f"{
|
| 158 |
"type": text_type,
|
| 159 |
"text": [social_media_text],
|
| 160 |
"offsets": [offset],
|
|
|
|
| 108 |
dl_dir = dl_manager.download_and_extract(_URLs)
|
| 109 |
dataset_dir = os.path.join(dl_dir, "datasets", "TwADR-L")
|
| 110 |
# dataset supports k-folds
|
| 111 |
+
splits_names = ["train", "validation", "test"]
|
| 112 |
+
fold_ids = range(10)
|
| 113 |
+
return [
|
| 114 |
+
datasets.SplitGenerator(
|
| 115 |
+
name=f"{split_name}_{fold_id}",
|
| 116 |
+
gen_kwargs={
|
| 117 |
+
"filepath": os.path.join(dataset_dir, f"TwADR-L.fold-{fold_id}.{split_name}.txt"),
|
| 118 |
+
"split_id": f"{split_name}_{fold_id}",
|
| 119 |
+
},
|
| 120 |
+
)
|
| 121 |
+
for split_name in splits_names
|
| 122 |
+
for fold_id in fold_ids
|
| 123 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
def _generate_examples(self, filepath, split_id):
|
| 126 |
with open(filepath, "r", encoding="latin-1") as f:
|
| 127 |
for i, line in enumerate(f):
|
| 128 |
+
guid = f"{split_id}_{i}"
|
| 129 |
cui, medical_concept, social_media_text = line.strip().split("\t")
|
| 130 |
if self.config.schema == "source":
|
| 131 |
+
yield guid, {
|
| 132 |
"cui": cui,
|
| 133 |
"medical_concept": medical_concept,
|
| 134 |
"social_media_text": social_media_text,
|
|
|
|
| 136 |
elif self.config.schema == "bigbio_kb":
|
| 137 |
text_type = "social_media_text"
|
| 138 |
offset = (0, len(social_media_text))
|
| 139 |
+
yield guid, {
|
| 140 |
+
"id": guid,
|
| 141 |
+
"document_id": guid,
|
| 142 |
"passages": [
|
| 143 |
{
|
| 144 |
+
"id": f"{guid}_passage",
|
| 145 |
"type": text_type,
|
| 146 |
"text": [social_media_text],
|
| 147 |
"offsets": [offset],
|
|
|
|
| 149 |
],
|
| 150 |
"entities": [
|
| 151 |
{
|
| 152 |
+
"id": f"{guid}_entity",
|
| 153 |
"type": text_type,
|
| 154 |
"text": [social_media_text],
|
| 155 |
"offsets": [offset],
|