longcon
Browse files- LongConL.py +101 -1
LongConL.py
CHANGED
|
@@ -78,7 +78,107 @@ class LongConLDataset(datasets.GeneratorBasedBuilder):
|
|
| 78 |
print(data.head()) # Display first few rows
|
| 79 |
|
| 80 |
# Check if the DataFrame is empty or has the correct columns
|
| 81 |
-
if data.empty:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
print(f"Warning: No data found in {file_path}")
|
| 83 |
return # Early exit if there's no data
|
| 84 |
|
|
|
|
| 78 |
print(data.head()) # Display first few rows
|
| 79 |
|
| 80 |
# Check if the DataFrame is empty or has the correct columns
|
| 81 |
+
if data.empty:import datasets
|
| 82 |
+
import pandas as pd
|
| 83 |
+
|
| 84 |
+
# Dataset metadata
|
| 85 |
+
_CITATION = """"""
|
| 86 |
+
_DESCRIPTION = """"""
|
| 87 |
+
_HOMEPAGE = ""
|
| 88 |
+
_LICENSE = ""
|
| 89 |
+
|
| 90 |
+
# Updated URLs to dynamically handle task names
|
| 91 |
+
_URLS = {
|
| 92 |
+
"train": "data/LongConL-tasks/{task_name}/train.csv",
|
| 93 |
+
"validation": "data/LongConL-tasks/{task_name}/validation.csv",
|
| 94 |
+
"test": "data/LongConL-tasks/{task_name}/test.csv",
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
TASK_NAMES = ["ATS-Jurisdiction", "ATS-FavorableJudgment"] # Add more task names as needed
|
| 98 |
+
|
| 99 |
+
_CONFIGS = {
|
| 100 |
+
task_name: {
|
| 101 |
+
"description": f"{task_name} specific legal opinions", # Dynamic description based on task name
|
| 102 |
+
"features": {
|
| 103 |
+
"Citation": datasets.Value("string"),
|
| 104 |
+
"Full Case Name": datasets.Value("string"),
|
| 105 |
+
"Opinion Text": datasets.Value("string"),
|
| 106 |
+
"Numerical Label": datasets.Value("string"), # Will be optional for some tasks
|
| 107 |
+
"Text Label": datasets.Value("string"),
|
| 108 |
+
},
|
| 109 |
+
}
|
| 110 |
+
for task_name in TASK_NAMES
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
class LongConLDataset(datasets.GeneratorBasedBuilder):
|
| 116 |
+
"""Legal opinion classification dataset for LongConL tasks"""
|
| 117 |
+
|
| 118 |
+
def _info(self):
|
| 119 |
+
"""Return dataset information."""
|
| 120 |
+
features = datasets.Features({
|
| 121 |
+
"Citation": datasets.Value("string"),
|
| 122 |
+
"Full Case Name": datasets.Value("string"),
|
| 123 |
+
"Opinion Text": datasets.Value("string"),
|
| 124 |
+
"Numerical Label": datasets.Value("string"), # Will be optional for some tasks
|
| 125 |
+
"Text Label": datasets.Value("string"),
|
| 126 |
+
})
|
| 127 |
+
return datasets.DatasetInfo(
|
| 128 |
+
description=_DESCRIPTION,
|
| 129 |
+
features=features,
|
| 130 |
+
homepage=_HOMEPAGE,
|
| 131 |
+
citation=_CITATION,
|
| 132 |
+
license=_LICENSE,
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
def _split_generators(self, dl_manager):
|
| 136 |
+
"""Split the dataset into train, validation, and test."""
|
| 137 |
+
task_name = self.config.name # Get the current task name from the config
|
| 138 |
+
urls = {key: val.format(task_name=task_name) for key, val in _URLS.items()} # Update URLs with the task name
|
| 139 |
+
downloaded_files = dl_manager.download_and_extract(urls)
|
| 140 |
+
|
| 141 |
+
return [
|
| 142 |
+
datasets.SplitGenerator(
|
| 143 |
+
name=datasets.Split.TRAIN,
|
| 144 |
+
gen_kwargs={"file_path": downloaded_files["train"]},
|
| 145 |
+
),
|
| 146 |
+
datasets.SplitGenerator(
|
| 147 |
+
name=datasets.Split.VALIDATION,
|
| 148 |
+
gen_kwargs={"file_path": downloaded_files["validation"]},
|
| 149 |
+
),
|
| 150 |
+
datasets.SplitGenerator(
|
| 151 |
+
name=datasets.Split.TEST,
|
| 152 |
+
gen_kwargs={"file_path": downloaded_files["test"]},
|
| 153 |
+
),
|
| 154 |
+
]
|
| 155 |
+
|
| 156 |
+
def _generate_examples(self, file_path):
|
| 157 |
+
"""Generate examples from the dataset CSV."""
|
| 158 |
+
data = pd.read_csv(file_path)
|
| 159 |
+
print("Data loaded from file:", file_path)
|
| 160 |
+
print(data.head()) # Display first few rows
|
| 161 |
+
data_dict = data.to_dict(orient="records")
|
| 162 |
+
print(f"Number of examples to generate: {len(data_dict)}")
|
| 163 |
+
|
| 164 |
+
for id_, row in enumerate(data_dict):
|
| 165 |
+
yield id_, {
|
| 166 |
+
"Citation": row["Citation"],
|
| 167 |
+
"Full Case Name": row["Full Case Name"],
|
| 168 |
+
"Opinion Text": row["Opinion Text"],
|
| 169 |
+
"Numerical Label": row.get("Numerical Label", None), # Use .get() to handle missing keys
|
| 170 |
+
"Text Label": row["Text Label"],
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
# Use a dynamic config
|
| 176 |
+
BUILDER_CONFIGS = [
|
| 177 |
+
datasets.BuilderConfig(name=task_name, version=datasets.Version("1.0.0"), description=task_name)
|
| 178 |
+
for task_name in ["ATS-Jurisdiction", "ATS-FavorableJudgment","JRC-AREA1","DC-category", "SC-issueArea","SSC-ca_disp", "Chevron-Agency","CoA-geniss"] # Add your task names here
|
| 179 |
+
]
|
| 180 |
+
|
| 181 |
+
|
| 182 |
print(f"Warning: No data found in {file_path}")
|
| 183 |
return # Early exit if there's no data
|
| 184 |
|