Datasets:

srzhang commited on
Commit
b30dfd8
·
1 Parent(s): d8f57bc
Files changed (1) hide show
  1. LongConL.py +67 -31
LongConL.py CHANGED
@@ -1,63 +1,99 @@
1
  import datasets
2
- import os
3
  import pandas as pd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  class LongConLDataset(datasets.GeneratorBasedBuilder):
6
- """Legal opinion classification dataset for LongConL tasks."""
7
 
8
- # List of tasks (add more as needed)
9
  BUILDER_CONFIGS = [
10
  datasets.BuilderConfig(
11
- name=task_name, version=datasets.Version("1.0.0"), description=f"Task: {task_name}"
12
  )
13
- for task_name in ["ATS-Jurisdiction", "ATS-FavorableJudgment"]
14
  ]
15
 
16
  def _info(self):
17
- """Return dataset information."""
18
- features = datasets.Features({
19
- "Citation": datasets.Value("string"),
20
- "Case Name": datasets.Value("string"),
21
- "Opinion Text": datasets.Value("string"),
22
- "Numerical Label": datasets.Value("string"),
23
- "Text Label": datasets.Value("string"),
24
- })
25
  return datasets.DatasetInfo(
26
- description="Legal classification tasks dataset",
27
- features=features,
28
- homepage="https://huggingface.co/datasets/LongConL",
29
- citation="",
 
30
  )
31
 
32
  def _split_generators(self, dl_manager):
33
- """Split the dataset into train, validation, and test."""
34
- task_name = self.config.name # Dynamically get the current task name
35
- base_dir = f"data/LongConL-tasks/{task_name}"
36
-
37
  return [
38
- datasets.SplitGenerator(
39
  name=datasets.Split.TRAIN,
40
- gen_kwargs={"file_path": f"{base_dir}/train.csv"},
41
  ),
42
- datasets.SplitGenerator(
43
  name=datasets.Split.VALIDATION,
44
- gen_kwargs={"file_path": f"{base_dir}/validation.csv"},
45
  ),
46
- datasets.SplitGenerator(
47
  name=datasets.Split.TEST,
48
- gen_kwargs={"file_path": f"{base_dir}/test.csv"},
49
  ),
50
  ]
51
 
52
  def _generate_examples(self, file_path):
53
- """Generate examples from a CSV file."""
54
  data = pd.read_csv(file_path)
55
- for id_, row in data.iterrows():
56
- yield id_, {
 
 
57
  "Citation": row["Citation"],
58
  "Case Name": row["Case Name"],
59
  "Opinion Text": row["Opinion Text"],
60
- "Numerical Label": row.get("Numerical Label", None), # Optional column
61
  "Text Label": row["Text Label"],
62
  }
63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import datasets
2
+ from datasets import DatasetInfo, Features, Value, Sequence, SplitGenerator
3
  import pandas as pd
4
+ from pathlib import Path
5
+
6
+ # Constants for the dataset
7
+ _CITATION = """"""
8
+ _DESCRIPTION = """Legal opinion classification dataset containing multiple tasks."""
9
+ _HOMEPAGE = "https://huggingface.co/datasets/reglab/LongConL"
10
+
11
+ # Define your configurations for each task dynamically
12
+ TASKS = ["ATS-Jurisdiction"] # Add all task names here
13
+
14
+ # Configs for each task
15
+ _CONFIGS = {
16
+ task: {
17
+ "description": f"Task: {task}",
18
+ "features": Features({
19
+ "Citation": Value("string"),
20
+ "Case Name": Value("string"),
21
+ "Opinion Text": Value("string"),
22
+ "Numerical Label": Value("string"), # Assuming labels are strings, adjust if different
23
+ "Text Label": Value("string"),
24
+ }),
25
+ "license": None,
26
+ }
27
+ for task in TASKS
28
+ }
29
+
30
 
31
  class LongConLDataset(datasets.GeneratorBasedBuilder):
32
+ """Legal classification tasks for LongConL"""
33
 
34
+ # Define configurations for each task in the dataset
35
  BUILDER_CONFIGS = [
36
  datasets.BuilderConfig(
37
+ name=task, version=datasets.Version("1.0.0"), description=f"Task: {task}",
38
  )
39
+ for task in _CONFIGS
40
  ]
41
 
42
  def _info(self):
43
+ """Return dataset information with task-specific features."""
 
 
 
 
 
 
 
44
  return datasets.DatasetInfo(
45
+ description=_DESCRIPTION,
46
+ features=_CONFIGS[self.config.name]["features"],
47
+ homepage=_HOMEPAGE,
48
+ citation=_CITATION,
49
+ license=_CONFIGS[self.config.name]["license"],
50
  )
51
 
52
  def _split_generators(self, dl_manager):
53
+ """Return SplitGenerators based on the task name."""
54
+ task_name = self.config.name
55
+ base_dir = Path(f"data/LongConL-tasks/{task_name}") # Path to task-specific directory
56
+
57
  return [
58
+ SplitGenerator(
59
  name=datasets.Split.TRAIN,
60
+ gen_kwargs={"file_path": base_dir / "train.csv"},
61
  ),
62
+ SplitGenerator(
63
  name=datasets.Split.VALIDATION,
64
+ gen_kwargs={"file_path": base_dir / "validation.csv"},
65
  ),
66
+ SplitGenerator(
67
  name=datasets.Split.TEST,
68
+ gen_kwargs={"file_path": base_dir / "test.csv"},
69
  ),
70
  ]
71
 
72
  def _generate_examples(self, file_path):
73
+ """Yields examples from the CSV files."""
74
  data = pd.read_csv(file_path)
75
+
76
+ # Iterate through each row and yield as example
77
+ for idx, row in data.iterrows():
78
+ yield idx, {
79
  "Citation": row["Citation"],
80
  "Case Name": row["Case Name"],
81
  "Opinion Text": row["Opinion Text"],
82
+ "Numerical Label": row.get("Numerical Label", None), # Optional column for tasks that may not have it
83
  "Text Label": row["Text Label"],
84
  }
85
 
86
+
87
+ # Example usage
88
+ if __name__ == "__main__":
89
+ # Load a specific task dataset by task name
90
+ dataset = datasets.load_dataset("reglab/LongConL", name="ATS-Jurisdiction")
91
+
92
+ # Access train, validation, and test splits
93
+ train_dataset = dataset["train"]
94
+ validation_dataset = dataset["validation"]
95
+ test_dataset = dataset["test"]
96
+
97
+ # Print some examples
98
+ print(train_dataset)
99
+