script
Browse files- LongConL.py +67 -34
LongConL.py
CHANGED
|
@@ -1,48 +1,75 @@
|
|
| 1 |
-
# LongConL dataset script
|
| 2 |
import datasets
|
| 3 |
import pandas as pd
|
| 4 |
|
| 5 |
-
|
| 6 |
_CITATION = """"""
|
| 7 |
_DESCRIPTION = """"""
|
| 8 |
_HOMEPAGE = ""
|
| 9 |
_LICENSE = ""
|
| 10 |
_URLS = {
|
| 11 |
-
"
|
| 12 |
-
"train": "data/
|
| 13 |
-
"validation": "data/
|
| 14 |
-
"test": "data/
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
}
|
| 17 |
|
| 18 |
-
_CONFIGS = {
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
},
|
| 30 |
-
"license": None,
|
| 31 |
}
|
| 32 |
|
| 33 |
|
| 34 |
-
class
|
| 35 |
-
"""
|
| 36 |
-
|
| 37 |
BUILDER_CONFIGS = [
|
| 38 |
datasets.BuilderConfig(
|
| 39 |
name=task, version=datasets.Version("1.0.0"), description=task,
|
| 40 |
)
|
| 41 |
for task in _CONFIGS
|
| 42 |
]
|
| 43 |
-
|
| 44 |
def _info(self):
|
| 45 |
-
"""Returns the dataset's metadata."""
|
| 46 |
features = _CONFIGS[self.config.name]["features"]
|
| 47 |
return datasets.DatasetInfo(
|
| 48 |
description=_DESCRIPTION,
|
|
@@ -53,10 +80,10 @@ class LongConL(datasets.GeneratorBasedBuilder):
|
|
| 53 |
)
|
| 54 |
|
| 55 |
def _split_generators(self, dl_manager):
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
datasets.SplitGenerator(
|
| 61 |
name=datasets.Split.TRAIN,
|
| 62 |
gen_kwargs={
|
|
@@ -79,12 +106,18 @@ class LongConL(datasets.GeneratorBasedBuilder):
|
|
| 79 |
},
|
| 80 |
),
|
| 81 |
]
|
| 82 |
-
return splits
|
| 83 |
|
| 84 |
def _generate_examples(self, fpath, name):
|
| 85 |
-
"""Yields examples
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
|
|
|
|
|
|
| 1 |
import datasets
|
| 2 |
import pandas as pd
|
| 3 |
|
|
|
|
| 4 |
_CITATION = """"""
|
| 5 |
_DESCRIPTION = """"""
|
| 6 |
_HOMEPAGE = ""
|
| 7 |
_LICENSE = ""
|
| 8 |
_URLS = {
|
| 9 |
+
"qa": {
|
| 10 |
+
"train": "data/qa/train.csv",
|
| 11 |
+
"validation": "data/qa/validation.csv",
|
| 12 |
+
"test": "data/qa/test.csv",
|
| 13 |
+
"all": "data/qa/qa.csv",
|
| 14 |
+
},
|
| 15 |
+
"passages": {
|
| 16 |
+
"train": "data/passages/train.tsv",
|
| 17 |
+
"validation": "data/passages/validation.tsv",
|
| 18 |
+
"test": "data/passages/test.tsv",
|
| 19 |
+
"all": "data/passages/passages.tsv"
|
| 20 |
+
},
|
| 21 |
}
|
| 22 |
|
| 23 |
+
_CONFIGS = {
|
| 24 |
+
"qa": {
|
| 25 |
+
"description": "Answer bar exam questions",
|
| 26 |
+
"features": {
|
| 27 |
+
"idx": datasets.Value("string"),
|
| 28 |
+
"dataset": datasets.Value("string"),
|
| 29 |
+
"example_id": datasets.Value("string"),
|
| 30 |
+
"prompt_id": datasets.Value("string"),
|
| 31 |
+
"source": datasets.Value("string"),
|
| 32 |
+
"subject": datasets.Value("string"),
|
| 33 |
+
"question_number": datasets.Value("string"),
|
| 34 |
+
"prompt": datasets.Value("string"),
|
| 35 |
+
"question": datasets.Value("string"),
|
| 36 |
+
"choice_a": datasets.Value("string"),
|
| 37 |
+
"choice_b": datasets.Value("string"),
|
| 38 |
+
"choice_c": datasets.Value("string"),
|
| 39 |
+
"choice_d": datasets.Value("string"),
|
| 40 |
+
"answer": datasets.Value("string"),
|
| 41 |
+
"gold_passage": datasets.Value("string"),
|
| 42 |
+
"gold_idx": datasets.Value("string"),
|
| 43 |
+
},
|
| 44 |
+
"license": None,
|
| 45 |
+
},
|
| 46 |
+
"passages": {
|
| 47 |
+
"description": "Passage corpus of bar exam question explanations, Wex definitions and primary sources, and caselaw",
|
| 48 |
+
"features": {
|
| 49 |
+
"idx": datasets.Value("string"),
|
| 50 |
+
"source": datasets.Value("string"),
|
| 51 |
+
"faiss_id": datasets.Value("string"),
|
| 52 |
+
"case_id": datasets.Value("string"),
|
| 53 |
+
"absolute_paragraph_id": datasets.Value("string"),
|
| 54 |
+
"opinion_id": datasets.Value("string"),
|
| 55 |
+
"relative_paragraph_id": datasets.Value("string"),
|
| 56 |
+
"text": datasets.Value("string"),
|
| 57 |
+
},
|
| 58 |
+
"license": None,
|
| 59 |
},
|
|
|
|
| 60 |
}
|
| 61 |
|
| 62 |
|
| 63 |
+
class LongConLDataset(datasets.GeneratorBasedBuilder):
|
| 64 |
+
"""Dataset for LongConL."""
|
|
|
|
| 65 |
BUILDER_CONFIGS = [
|
| 66 |
datasets.BuilderConfig(
|
| 67 |
name=task, version=datasets.Version("1.0.0"), description=task,
|
| 68 |
)
|
| 69 |
for task in _CONFIGS
|
| 70 |
]
|
| 71 |
+
|
| 72 |
def _info(self):
|
|
|
|
| 73 |
features = _CONFIGS[self.config.name]["features"]
|
| 74 |
return datasets.DatasetInfo(
|
| 75 |
description=_DESCRIPTION,
|
|
|
|
| 80 |
)
|
| 81 |
|
| 82 |
def _split_generators(self, dl_manager):
|
| 83 |
+
# Added use_auth_token to download_and_extract method
|
| 84 |
+
download_options = {"use_auth_token": self._kwargs.get("use_auth_token")}
|
| 85 |
+
downloaded_file_dir = dl_manager.download_and_extract(_URLS[self.config.name], download_options=download_options)
|
| 86 |
+
return [
|
| 87 |
datasets.SplitGenerator(
|
| 88 |
name=datasets.Split.TRAIN,
|
| 89 |
gen_kwargs={
|
|
|
|
| 106 |
},
|
| 107 |
),
|
| 108 |
]
|
|
|
|
| 109 |
|
| 110 |
def _generate_examples(self, fpath, name):
|
| 111 |
+
"""Yields examples as (key, example) tuples."""
|
| 112 |
+
if name in ["qa"]:
|
| 113 |
+
data = pd.read_csv(fpath)
|
| 114 |
+
data = data.to_dict(orient="records")
|
| 115 |
+
for id_line, example in enumerate(data):
|
| 116 |
+
yield id_line, example
|
| 117 |
+
|
| 118 |
+
if name in ["passages"]:
|
| 119 |
+
data = pd.read_csv(fpath, sep='\t')
|
| 120 |
+
data = data.to_dict(orient="records")
|
| 121 |
+
for id_line, example in enumerate(data):
|
| 122 |
+
yield id_line, example
|
| 123 |
|