Commit
·
26e5e47
1
Parent(s):
d8115c8
Update MultiLegalNeg.py
Browse files- MultiLegalNeg.py +31 -32
MultiLegalNeg.py
CHANGED
|
@@ -26,19 +26,7 @@ _URL = {
|
|
| 26 |
'data/'
|
| 27 |
}
|
| 28 |
_LANGUAGES = [
|
| 29 |
-
"
|
| 30 |
-
]
|
| 31 |
-
|
| 32 |
-
_ENGLISH = [
|
| 33 |
-
"sherlock", "bioscope", "sfu"
|
| 34 |
-
]
|
| 35 |
-
|
| 36 |
-
_SHERLOCKS = [
|
| 37 |
-
"dev", "test_cardboard_GOLD", "test_circle_GOLD", "training"
|
| 38 |
-
]
|
| 39 |
-
|
| 40 |
-
_BIOSCOPES = [
|
| 41 |
-
"abstracts", "full_papers"
|
| 42 |
]
|
| 43 |
|
| 44 |
|
|
@@ -90,6 +78,8 @@ class MultiLegalNeg(datasets.GeneratorBasedBuilder):
|
|
| 90 |
)
|
| 91 |
|
| 92 |
def _split_generators(self, dl_manager):
|
|
|
|
|
|
|
| 93 |
data_files = {
|
| 94 |
"train": [
|
| 95 |
"data/train/it_train.jsonl.xz",
|
|
@@ -119,24 +109,33 @@ class MultiLegalNeg(datasets.GeneratorBasedBuilder):
|
|
| 119 |
"data/validation/en_bioscope_validation.jsonl.xz"
|
| 120 |
]
|
| 121 |
}
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
return self.DatasetSplitGenerator(
|
| 135 |
-
name=split,
|
| 136 |
-
gen_kwargs={"data": data},
|
| 137 |
-
)
|
| 138 |
|
| 139 |
def _generate_examples(self, data):
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
'data/'
|
| 27 |
}
|
| 28 |
_LANGUAGES = [
|
| 29 |
+
"de", "fr", "it", "swiss", "en"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
]
|
| 31 |
|
| 32 |
|
|
|
|
| 78 |
)
|
| 79 |
|
| 80 |
def _split_generators(self, dl_manager):
|
| 81 |
+
languages = _LANGUAGES if self.config.language == "all" else [self.config.language]
|
| 82 |
+
|
| 83 |
data_files = {
|
| 84 |
"train": [
|
| 85 |
"data/train/it_train.jsonl.xz",
|
|
|
|
| 109 |
"data/validation/en_bioscope_validation.jsonl.xz"
|
| 110 |
]
|
| 111 |
}
|
| 112 |
+
|
| 113 |
+
split_generators = []
|
| 114 |
+
for split in data_files.keys():
|
| 115 |
+
filepaths = []
|
| 116 |
+
for file_name in data_files[split]:
|
| 117 |
+
try:
|
| 118 |
+
filepaths.append(dl_manager.download((f'{file_name}')))
|
| 119 |
+
except:
|
| 120 |
+
break
|
| 121 |
+
split_generators.append(datasets.SplitGenerator(name=split, gen_kwargs={'filepaths': filepaths}))
|
| 122 |
+
|
| 123 |
+
return split_generators
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
def _generate_examples(self, data):
|
| 126 |
+
id_ = 0
|
| 127 |
+
for filepath in filepaths:
|
| 128 |
+
if filepath:
|
| 129 |
+
logger.info("Generating examples from = %s", filepath)
|
| 130 |
+
try:
|
| 131 |
+
with xz.open(open(filepath,'rb'), 'rt', encoding='utf-8') as f:
|
| 132 |
+
json_list = list(f)
|
| 133 |
+
|
| 134 |
+
for json_str in json_list:
|
| 135 |
+
example = json.loads(json_str)
|
| 136 |
+
if example is not None and isinstance(example, dict):
|
| 137 |
+
yield id_, example
|
| 138 |
+
id_ +=1
|
| 139 |
+
|
| 140 |
+
except Exception:
|
| 141 |
+
logger.exception("Error while processing file %s", filepath)
|