Datasets:

srzhang commited on
Commit
187035b
·
1 Parent(s): b30dfd8
Files changed (3) hide show
  1. LongConL.py +58 -67
  2. __init__.py +1 -1
  3. load-data.py +1 -23
LongConL.py CHANGED
@@ -1,99 +1,90 @@
 
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
 
 
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
+ "LongConL": {
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
 
18
+ _CONFIGS = {}
19
 
20
+ # Adding a config for each task in your dataset
21
+ _CONFIGS["LongConL"] = {
22
+ "description": "Legal dataset containing various classification tasks.",
23
+ "features": {
24
+ "Citation": datasets.Value("string"),
25
+ "Case Name": datasets.Value("string"),
26
+ "Opinion Text": datasets.Value("string"),
27
+ "Numerical Label": datasets.Value("string"), # Change to int32 if necessary
28
+ "Text Label": datasets.Value("string"),
29
+ },
30
+ "license": None,
31
+ }
32
 
33
+
34
+ class LongConL(datasets.GeneratorBasedBuilder):
35
+ """LongConL legal annotation dataset for multiple tasks."""
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,
49
+ features=datasets.Features(features),
50
  homepage=_HOMEPAGE,
51
  citation=_CITATION,
52
  license=_CONFIGS[self.config.name]["license"],
53
  )
54
 
55
  def _split_generators(self, dl_manager):
56
+ """Returns SplitGenerators for train, validation, and test sets."""
57
+ downloaded_file_dir = dl_manager.download_and_extract(_URLS["LongConL"])
58
+
59
+ splits = [
60
+ datasets.SplitGenerator(
 
61
  name=datasets.Split.TRAIN,
62
+ gen_kwargs={
63
+ "fpath": downloaded_file_dir["train"],
64
+ "name": self.config.name,
65
+ },
66
  ),
67
+ datasets.SplitGenerator(
68
  name=datasets.Split.VALIDATION,
69
+ gen_kwargs={
70
+ "fpath": downloaded_file_dir["validation"],
71
+ "name": self.config.name,
72
+ },
73
  ),
74
+ datasets.SplitGenerator(
75
  name=datasets.Split.TEST,
76
+ gen_kwargs={
77
+ "fpath": downloaded_file_dir["test"],
78
+ "name": self.config.name,
79
+ },
80
  ),
81
  ]
82
+ return splits
83
 
84
+ def _generate_examples(self, fpath, name):
85
+ """Yields examples from each split as (key, example) tuples."""
86
+ data = pd.read_csv(fpath)
87
+ data = data.to_dict(orient="records")
88
+ for id_line, example in enumerate(data):
89
+ yield id_line, example
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
 
__init__.py CHANGED
@@ -1,2 +1,2 @@
1
- from .LongConL import LongConLDataset
2
 
 
1
+
2
 
load-data.py CHANGED
@@ -1,26 +1,4 @@
1
  from datasets import load_dataset
2
- from huggingface_hub import login
3
 
4
- # Login to Hugging Face using your token
5
- login(token="")
6
-
7
- # Specify the task name you want to load
8
- task_name = "ATS-Jurisdiction" # Replace with the task you want
9
-
10
- try:
11
- # Load the dataset with the dynamic task name
12
- dataset = load_dataset("reglab/LongConL", name=task_name) # Using dynamic task name
13
-
14
- # Access train, validation, and test splits
15
- train_dataset = dataset['train']
16
- validation_dataset = dataset['validation']
17
- test_dataset = dataset['test']
18
-
19
- # Use the datasets as needed
20
- print("Train Dataset:", train_dataset)
21
- print("Validation Dataset:", validation_dataset)
22
- print("Test Dataset:", test_dataset)
23
-
24
- except Exception as e:
25
- print(f"An error occurred: {e}")
26
 
 
1
  from datasets import load_dataset
 
2
 
3
+ dataset = load_dataset("reglab/LongConL", use_auth_token=your_token)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4