Datasets:

File size: 4,786 Bytes
ede3d9b
 
b30dfd8
78295a5
187035b
 
 
 
b30dfd8
78295a5
 
3dd70c8
 
7c4b309
187035b
ede3d9b
fcd3ae9
c55975e
 
 
 
 
 
 
 
fcd3ae9
a22e20f
e55621c
 
2750d92
e55621c
024c7ef
e55621c
 
 
ee97cee
624a033
93cc5d2
8852620
e55621c
bdfbf26
2750d92
bdfbf26
 
d182e55
 
 
 
 
 
 
024c7ef
d182e55
 
 
ee97cee
624a033
93cc5d2
8852620
d182e55
 
 
 
 
 
 
 
 
4cdab72
 
 
24a46eb
4cdab72
 
8852620
4cdab72
 
 
6a1a223
 
 
 
 
 
 
 
4cdab72
 
 
 
 
d182e55
 
 
 
 
 
 
 
 
 
 
024c7ef
d182e55
 
 
2780dc9
624a033
93cc5d2
8852620
d182e55
 
 
 
 
fcd3ae9
d182e55
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import datasets
import pandas as pd

# Dataset metadata
_CITATION = """"""
_DESCRIPTION = """"""
_HOMEPAGE = ""
_LICENSE = ""

# Updated URLs to dynamically handle task names
_URLS = {
    "train": "data/LongConL-tasks-subsample/{task_name}/{task_name}_subsample_train.csv",
    "validation": "data/LongConL-tasks-subsample/{task_name}/{task_name}_subsample_val.csv",
    "test": "data/codebook_swap/{task_name}_1990_2000.csv",
}

TASK_NAMES = [
    "ATS-Jurisdiction", "ATS-FavorableJudgment", "Chevron-Agency", "Chevron-ChevCited", 
    "Chevron-Dec.Ov.", "Chevron-Deference", "Chevron-Outcome", "Chevron-Subject", 
    "CoA-casetyp1", "CoA-direct1", "CoA-geniss", "CoA-typeiss", 
    "DC-casetype", "DC-category", "DC-libcon", 
    "JRC-AREA1", "JRC-CERT", "JRC-REVERSD", 
    "SC-decisionDirection", "SC-issueArea", "SC-partyWinning", 
    "SC-petitioner", "SC-precedentAlteration", 
    "SSC-ca_disp", "SSC-ca_uscty", "SSC-death_c", "SSC-p1_persn"
]

_CONFIGS = {
    task_name: {
        "description": f"{task_name} specific legal opinions",  # Dynamic description based on task name
        "features": {
            "idx": datasets.Value("string"),
            "Citation": datasets.Value("string"),
            "Full Case Name": datasets.Value("string"),
            "Opinion Text": datasets.Value("string"),
            "Numerical Label": datasets.Value("string"),  # Will be optional for some tasks
            #"Text Label": datasets.Value("string"), # Will be optional for some tasks
            #"DC Numerical Label": datasets.Value("string")
            #"Syllabus": datasets.Value("string") # Will be optional for some tasks
        },
    }
    for task_name in TASK_NAMES
}


class LongConLDataset(datasets.GeneratorBasedBuilder):
    """Legal opinion classification dataset for LongConL tasks"""

    def _info(self):
        """Return dataset information."""
        features = datasets.Features({
            "idx": datasets.Value("string"),
            "Citation": datasets.Value("string"),
            "Full Case Name": datasets.Value("string"),
            "Opinion Text": datasets.Value("string"),
            "Numerical Label": datasets.Value("string"),  # Will be optional for some tasks
            #"Text Label": datasets.Value("string"), # Will be optional for some tasks
            #"DC Numerical Label": datasets.Value("string")
            #"Syllabus": datasets.Value("string") # Will be optional for some tasks
        })
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=features,
            homepage=_HOMEPAGE,
            citation=_CITATION,
            license=_LICENSE,
        )

    def _split_generators(self, dl_manager):
        """Split the dataset into train, validation, and test."""
        task_name = self.config.name  # Get the current task name from the config
        valid_task_name = task_name.replace("-", "_")  # Replace hyphens with underscores

        # Update URLs with the valid task name
        urls = {key: val.format(task_name=valid_task_name) for key, val in _URLS.items()}  
        downloaded_files = dl_manager.download_and_extract(urls)

        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={"file_path": downloaded_files["train"]},
            ),
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                gen_kwargs={"file_path": downloaded_files["validation"]},
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={"file_path": downloaded_files["test"]},
            ),
        ]

    def _generate_examples(self, file_path):
        """Generate examples from the dataset CSV."""
        data = pd.read_csv(file_path)
        print("Data loaded from file:", file_path)
        print(data.head())  # Display first few rows
        data_dict = data.to_dict(orient="records")
        print(f"Number of examples to generate: {len(data_dict)}")

        for id_, row in enumerate(data_dict):
            yield id_, {
                "idx": row["idx"],
                "Citation": row["Citation"],
                "Full Case Name": row["Full Case Name"],
                "Opinion Text": row["Opinion Text"],
                "Numerical Label": row.get("Numerical Label", None),  # Use .get() to handle missing keys
                #"Text Label": row["Text Label"],
                #"DC Numerical Label": row["DC Numerical Label"]
                #"Syllabus": row["Syllabus"]
            }

    # Use a dynamic config
    BUILDER_CONFIGS = [
        datasets.BuilderConfig(name=task_name, version=datasets.Version("1.0.0"), description=task_name)
        for task_name in TASK_NAMES
    ]