Update msmarco-passage.py
Browse files- msmarco-passage.py +18 -20
msmarco-passage.py
CHANGED
|
@@ -75,30 +75,28 @@ class MsMarcoPassage(datasets.GeneratorBasedBuilder):
|
|
| 75 |
)
|
| 76 |
|
| 77 |
def _split_generators(self, dl_manager):
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
| 79 |
splits = [
|
| 80 |
datasets.SplitGenerator(
|
| 81 |
-
name=
|
| 82 |
gen_kwargs={
|
| 83 |
-
"
|
| 84 |
},
|
| 85 |
-
)
|
| 86 |
-
datasets.SplitGenerator(
|
| 87 |
-
name='dev',
|
| 88 |
-
gen_kwargs={
|
| 89 |
-
"filepath": downloaded_files["dev"],
|
| 90 |
-
},
|
| 91 |
-
),
|
| 92 |
]
|
| 93 |
return splits
|
| 94 |
-
|
| 95 |
-
def _generate_examples(self,
|
| 96 |
"""Yields examples."""
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
data
|
| 102 |
-
|
| 103 |
-
data
|
| 104 |
-
|
|
|
|
|
|
| 75 |
)
|
| 76 |
|
| 77 |
def _split_generators(self, dl_manager):
|
| 78 |
+
if self.config.data_files:
|
| 79 |
+
downloaded_files = self.config.data_files
|
| 80 |
+
else:
|
| 81 |
+
downloaded_files = dl_manager.download_and_extract(_DATASET_URLS)
|
| 82 |
splits = [
|
| 83 |
datasets.SplitGenerator(
|
| 84 |
+
name=split,
|
| 85 |
gen_kwargs={
|
| 86 |
+
"files": [downloaded_files[split]] if isinstance(downloaded_files[split], str) else downloaded_files[split],
|
| 87 |
},
|
| 88 |
+
) for split in downloaded_files
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
]
|
| 90 |
return splits
|
| 91 |
+
|
| 92 |
+
def _generate_examples(self, files):
|
| 93 |
"""Yields examples."""
|
| 94 |
+
for filepath in files:
|
| 95 |
+
with open(filepath, encoding="utf-8") as f:
|
| 96 |
+
for line in f:
|
| 97 |
+
data = json.loads(line)
|
| 98 |
+
if data.get('negative_passages') is None:
|
| 99 |
+
data['negative_passages'] = []
|
| 100 |
+
if data.get('positive_passages') is None:
|
| 101 |
+
data['positive_passages'] = []
|
| 102 |
+
yield data['query_id'], data
|