Datasets:

srzhang commited on
Commit
ede3d9b
·
1 Parent(s): dec5be8
Files changed (1) hide show
  1. LongConL.py +97 -0
LongConL.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+ import pandas as pd
3
+
4
+ # Dataset metadata
5
+ _CITATION = """"""
6
+ _DESCRIPTION = """"""
7
+ _HOMEPAGE = ""
8
+ _LICENSE = ""
9
+
10
+ # URLs for the dataset (since it's hosted on Hugging Face, you'll load directly from there)
11
+ _URLS = {
12
+ "train": "data/LongConL-tasks/train.csv",
13
+ "validation": "data/LongConL-tasks/validation.csv",
14
+ "test": "data/LongConL-tasks/test.csv",
15
+ "all": "data/LongConL-tasks/{task_name}.csv"
16
+ }
17
+
18
+ # Configuration for tasks
19
+ _CONFIGS = {
20
+ "default": {
21
+ "description": "Legal opinion classification tasks",
22
+ "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
+ "license": None,
30
+ }
31
+ }
32
+
33
+ class LongConLDataset(datasets.GeneratorBasedBuilder):
34
+ """Legal opinion classification dataset for LongConL tasks"""
35
+
36
+ # Set up the dataset configurations
37
+ BUILDER_CONFIGS = [
38
+ datasets.BuilderConfig(
39
+ name=task_name, version=datasets.Version("1.0.0"), description=task_name
40
+ )
41
+ for task_name in _CONFIGS
42
+ ]
43
+
44
+ def _info(self):
45
+ """Return dataset information."""
46
+ features = datasets.Features(_CONFIGS["default"]["features"])
47
+ return datasets.DatasetInfo(
48
+ description=_DESCRIPTION,
49
+ features=features,
50
+ homepage=_HOMEPAGE,
51
+ citation=_CITATION,
52
+ license=_LICENSE,
53
+ )
54
+
55
+ def _split_generators(self, dl_manager):
56
+ """Split the dataset into train, validation, and test."""
57
+ downloaded_files = dl_manager.download_and_extract(_URLS)
58
+ return [
59
+ datasets.SplitGenerator(
60
+ name=datasets.Split.TRAIN,
61
+ gen_kwargs={
62
+ "file_path": downloaded_files["train"],
63
+ },
64
+ ),
65
+ datasets.SplitGenerator(
66
+ name=datasets.Split.VALIDATION,
67
+ gen_kwargs={
68
+ "file_path": downloaded_files["validation"],
69
+ },
70
+ ),
71
+ ]
72
+
73
+ def _generate_examples(self, file_path):
74
+ """Generate examples from the dataset CSV."""
75
+ data = pd.read_csv(file_path)
76
+ data_dict = data.to_dict(orient="records")
77
+
78
+ for id_, row in enumerate(data_dict):
79
+ # Check if the CSV has the 'Numerical Label' column
80
+ if "Numerical Label" in row:
81
+ yield id_, {
82
+ "Citation": row["Citation"],
83
+ "Case Name": row["Case Name"],
84
+ "Opinion Text": row["Opinion Text"],
85
+ "Numerical Label": row["Numerical Label"],
86
+ "Text Label": row["Text Label"],
87
+ }
88
+ else:
89
+ # Handle the case where Numerical Label column is missing
90
+ yield id_, {
91
+ "Citation": row["Citation"],
92
+ "Case Name": row["Case Name"],
93
+ "Opinion Text": row["Opinion Text"],
94
+ "Numerical Label": None, # Set to None if missing
95
+ "Text Label": row["Text Label"],
96
+ }
97
+