Datasets:

srzhang commited on
Commit
d8f57bc
·
1 Parent(s): 96f5093
Files changed (3) hide show
  1. LongConL.py +30 -72
  2. __init__.py +2 -0
  3. load-data.py +5 -6
LongConL.py CHANGED
@@ -1,105 +1,63 @@
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
- # Configuration for tasks
18
- _CONFIGS = {
19
- "default": {
20
- "description": "Legal opinion classification tasks",
21
- "features": {
22
- "Citation": datasets.Value("string"),
23
- "Case Name": datasets.Value("string"),
24
- "Opinion Text": datasets.Value("string"),
25
- "Numerical Label": datasets.Value("string"), # Will be optional for some tasks
26
- "Text Label": datasets.Value("string"),
27
- },
28
- "license": None,
29
- }
30
- }
31
-
32
  class LongConLDataset(datasets.GeneratorBasedBuilder):
33
- """Legal opinion classification dataset for LongConL tasks"""
34
 
35
- # Set up the dataset configurations
36
  BUILDER_CONFIGS = [
37
  datasets.BuilderConfig(
38
- name=task_name, version=datasets.Version("1.0.0"), description=task_name
39
  )
40
- for task_name in _CONFIGS # Assuming _CONFIGS contains all task names
41
  ]
42
 
43
  def _info(self):
44
  """Return dataset information."""
45
- features = datasets.Features(_CONFIGS["default"]["features"])
 
 
 
 
 
 
46
  return datasets.DatasetInfo(
47
- description=_DESCRIPTION,
48
  features=features,
49
- homepage=_HOMEPAGE,
50
- citation=_CITATION,
51
- license=_LICENSE,
52
  )
53
 
54
  def _split_generators(self, dl_manager):
55
  """Split the dataset into train, validation, and test."""
56
- task_name = self.config.name # Get the current task name from the config
57
- urls = {key: val.format(task_name=task_name) for key, val in _URLS.items()} # Update URLs with the task name
58
- downloaded_files = dl_manager.download_and_extract(urls)
59
-
60
  return [
61
  datasets.SplitGenerator(
62
  name=datasets.Split.TRAIN,
63
- gen_kwargs={
64
- "file_path": downloaded_files["train"],
65
- },
66
  ),
67
  datasets.SplitGenerator(
68
  name=datasets.Split.VALIDATION,
69
- gen_kwargs={
70
- "file_path": downloaded_files["validation"],
71
- },
72
  ),
73
  datasets.SplitGenerator(
74
  name=datasets.Split.TEST,
75
- gen_kwargs={
76
- "file_path": downloaded_files["test"],
77
- },
78
  ),
79
  ]
80
 
81
  def _generate_examples(self, file_path):
82
- """Generate examples from the dataset CSV."""
83
  data = pd.read_csv(file_path)
84
- data_dict = data.to_dict(orient="records")
85
-
86
- for id_, row in enumerate(data_dict):
87
- # Check if the CSV has the 'Numerical Label' column
88
- if "Numerical Label" in row:
89
- yield id_, {
90
- "Citation": row["Citation"],
91
- "Case Name": row["Case Name"],
92
- "Opinion Text": row["Opinion Text"],
93
- "Numerical Label": row["Numerical Label"],
94
- "Text Label": row["Text Label"],
95
- }
96
- else:
97
- # Handle the case where Numerical Label column is missing
98
- yield id_, {
99
- "Citation": row["Citation"],
100
- "Case Name": row["Case Name"],
101
- "Opinion Text": row["Opinion Text"],
102
- "Numerical Label": None, # Set to None if missing
103
- "Text Label": row["Text Label"],
104
- }
105
 
 
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
 
__init__.py CHANGED
@@ -0,0 +1,2 @@
 
 
 
1
+ from .LongConL import LongConLDataset
2
+
load-data.py CHANGED
@@ -1,23 +1,22 @@
1
  from datasets import load_dataset
2
- from LongConL import LongConLDataset # Import the dataset class
3
  from huggingface_hub import login
4
 
5
  # Login to Hugging Face using your token
6
- login(token="") # Replace with your actual token
7
 
8
  # Specify the task name you want to load
9
- task_name = "ATS-Jurisdiction" # Replace with your desired task
10
 
11
  try:
12
- # Load the dataset
13
- dataset = load_dataset(LongConLDataset, name=task_name)
14
 
15
  # Access train, validation, and test splits
16
  train_dataset = dataset['train']
17
  validation_dataset = dataset['validation']
18
  test_dataset = dataset['test']
19
 
20
- # Now you can use these datasets as needed
21
  print("Train Dataset:", train_dataset)
22
  print("Validation Dataset:", validation_dataset)
23
  print("Test Dataset:", test_dataset)
 
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)