script
Browse files- LongConL.py +44 -89
LongConL.py
CHANGED
|
@@ -1,123 +1,78 @@
|
|
| 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 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 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 |
-
"""
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
return datasets.DatasetInfo(
|
| 75 |
description=_DESCRIPTION,
|
| 76 |
-
features=
|
| 77 |
homepage=_HOMEPAGE,
|
| 78 |
citation=_CITATION,
|
| 79 |
-
license=
|
| 80 |
)
|
| 81 |
|
| 82 |
def _split_generators(self, dl_manager):
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
| 86 |
return [
|
| 87 |
datasets.SplitGenerator(
|
| 88 |
name=datasets.Split.TRAIN,
|
| 89 |
-
gen_kwargs={
|
| 90 |
-
"fpath": downloaded_file_dir["train"],
|
| 91 |
-
"name": self.config.name,
|
| 92 |
-
},
|
| 93 |
),
|
| 94 |
datasets.SplitGenerator(
|
| 95 |
name=datasets.Split.VALIDATION,
|
| 96 |
-
gen_kwargs={
|
| 97 |
-
"fpath": downloaded_file_dir["validation"],
|
| 98 |
-
"name": self.config.name,
|
| 99 |
-
},
|
| 100 |
),
|
| 101 |
datasets.SplitGenerator(
|
| 102 |
name=datasets.Split.TEST,
|
| 103 |
-
gen_kwargs={
|
| 104 |
-
"fpath": downloaded_file_dir["test"],
|
| 105 |
-
"name": self.config.name,
|
| 106 |
-
},
|
| 107 |
),
|
| 108 |
]
|
| 109 |
|
| 110 |
-
def _generate_examples(self,
|
| 111 |
-
"""
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|
|
|
|
| 1 |
import datasets
|
| 2 |
import pandas as pd
|
| 3 |
|
| 4 |
+
# Dataset metadata
|
| 5 |
_CITATION = """"""
|
| 6 |
_DESCRIPTION = """"""
|
| 7 |
_HOMEPAGE = ""
|
| 8 |
_LICENSE = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
# Updated URLs to dynamically handle task names
|
| 11 |
+
_URLS = {
|
| 12 |
+
"train": "data/LongConL-tasks/{task_name}/train.csv",
|
| 13 |
+
"validation": "data/LongConL-tasks/{task_name}/validation.csv",
|
| 14 |
+
"test": "data/LongConL-tasks/{task_name}/test.csv",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
}
|
| 16 |
|
|
|
|
| 17 |
class LongConLDataset(datasets.GeneratorBasedBuilder):
|
| 18 |
+
"""Legal opinion classification dataset for LongConL tasks"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
def _info(self):
|
| 21 |
+
"""Return dataset information."""
|
| 22 |
+
features = datasets.Features({
|
| 23 |
+
"Citation": datasets.Value("string"),
|
| 24 |
+
"Case Name": datasets.Value("string"),
|
| 25 |
+
"Opinion Text": datasets.Value("string"),
|
| 26 |
+
"Numerical Label": datasets.Value("string"), # Will be optional for some tasks
|
| 27 |
+
"Text Label": datasets.Value("string"),
|
| 28 |
+
})
|
| 29 |
return datasets.DatasetInfo(
|
| 30 |
description=_DESCRIPTION,
|
| 31 |
+
features=features,
|
| 32 |
homepage=_HOMEPAGE,
|
| 33 |
citation=_CITATION,
|
| 34 |
+
license=_LICENSE,
|
| 35 |
)
|
| 36 |
|
| 37 |
def _split_generators(self, dl_manager):
|
| 38 |
+
"""Split the dataset into train, validation, and test."""
|
| 39 |
+
task_name = self.config.name # Get the current task name from the config
|
| 40 |
+
urls = {key: val.format(task_name=task_name) for key, val in _URLS.items()} # Update URLs with the task name
|
| 41 |
+
downloaded_files = dl_manager.download_and_extract(urls)
|
| 42 |
+
|
| 43 |
return [
|
| 44 |
datasets.SplitGenerator(
|
| 45 |
name=datasets.Split.TRAIN,
|
| 46 |
+
gen_kwargs={"file_path": downloaded_files["train"]},
|
|
|
|
|
|
|
|
|
|
| 47 |
),
|
| 48 |
datasets.SplitGenerator(
|
| 49 |
name=datasets.Split.VALIDATION,
|
| 50 |
+
gen_kwargs={"file_path": downloaded_files["validation"]},
|
|
|
|
|
|
|
|
|
|
| 51 |
),
|
| 52 |
datasets.SplitGenerator(
|
| 53 |
name=datasets.Split.TEST,
|
| 54 |
+
gen_kwargs={"file_path": downloaded_files["test"]},
|
|
|
|
|
|
|
|
|
|
| 55 |
),
|
| 56 |
]
|
| 57 |
|
| 58 |
+
def _generate_examples(self, file_path):
|
| 59 |
+
"""Generate examples from the dataset CSV."""
|
| 60 |
+
data = pd.read_csv(file_path)
|
| 61 |
+
data_dict = data.to_dict(orient="records")
|
| 62 |
+
|
| 63 |
+
for id_, row in enumerate(data_dict):
|
| 64 |
+
yield id_, {
|
| 65 |
+
"Citation": row["Citation"],
|
| 66 |
+
"Case Name": row["Case Name"],
|
| 67 |
+
"Opinion Text": row["Opinion Text"],
|
| 68 |
+
"Numerical Label": row.get("Numerical Label", None), # Use .get() to handle missing keys
|
| 69 |
+
"Text Label": row["Text Label"],
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
# Use a dynamic config
|
| 73 |
+
BUILDER_CONFIGS = [
|
| 74 |
+
datasets.BuilderConfig(name=task_name, version=datasets.Version("1.0.0"), description=task_name)
|
| 75 |
+
for task_name in ["ATS-Jurisdiction", "Other-Task-Name-1", "Other-Task-Name-2"] # Add your task names here
|
| 76 |
+
]
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|