File size: 6,425 Bytes
01691bd
 
 
 
 
 
 
 
 
e03db34
 
 
 
 
 
 
 
 
 
 
01691bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import json
import datasets
from pathlib import Path


_DESCRIPTION = "OpenExempt is a diagnostic benchmark for legal reasoning in language models."
_HOMEPAGE = "https://github.com/servantez/OpenExempt"
_LICENSE = "CC BY 4.0"
_VERSION = datasets.Version("1.0.0")
_CITATION = """
@misc{servantez2026openexemptdiagnosticbenchmarklegal,
      title={OpenExempt: A Diagnostic Benchmark for Legal Reasoning and a Framework for Creating Custom Benchmarks on Demand}, 
      author={Sergio Servantez and Sarah B. Lawsky and Rajiv Jain and Daniel W. Linna Jr. and Kristian Hammond},
      year={2026},
      eprint={2601.13183},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/2601.13183}, 
}
"""

_SUITES = {
    "advanced_competency": {
        "archive": "data/advanced_competency.tar.gz",
        "description": "Advanced Competency Suite."
    },
    "basic_competency": {
        "archive": "data/basic_competency.tar.gz",
        "description": "Basic Competency Suite."
    },
    "intermediate_competency": {
        "archive": "data/intermediate_competency.tar.gz",
        "description": "Intermediate Competency Suite."
    },
    "asset_scaling": {
        "archive": "data/asset_scaling.tar.gz",
        "description": "Asset Scaling Suite."
    },
    "temporal_reasoning": {
        "archive": "data/temporal_reasoning.tar.gz",
        "description": "Temporal Reasoning Suite."
    },
    "reasoning_decomposition": {
        "archive": "data/reasoning_decomposition.tar.gz",
        "description": "Reasoning Decomposition Suite."
    },
    "baseline_robustness": {
        "archive": "data/baseline_robustness.tar.gz",
        "description": "Baseline Robustness Suite."
    },
    "distractor_robustness": {
        "archive": "data/distractor_robustness.tar.gz",
        "description": "Distractor Robustness Suite."
    },
    "obfuscation_robustness": {
        "archive": "data/obfuscation_robustness.tar.gz",
        "description": "Obfuscation Robustness Suite."
    },
    "sycophancy_robustness": {
        "archive": "data/sycophancy_robustness.tar.gz",
        "description": "Sycophancy Robustness Suite."
    },
}

def read_json(path: Path):
    with path.open("r", encoding="utf-8") as file:
        return json.load(file)

def read_jsonl_file(path: Path):
    with path.open("r", encoding="utf-8") as file:
        return [json.loads(line) for line in file if line.strip()]

class OpenExemptConfig(datasets.BuilderConfig):

    def __init__(self, suite, **kwargs):
        if suite == "all":
            description = _DESCRIPTION
            archives = [info["archive"] for info in _SUITES.values()]
        else:
            info = _SUITES[suite]
            description = f"OpenExempt: {info['description']}"
            archives = [info["archive"]]
        super(OpenExemptConfig, self).__init__(
            name=suite, 
            description=description,
            version=_VERSION,
            **kwargs)
        self.suite = suite
        self.archives = archives
        
class OpenExempt(datasets.GeneratorBasedBuilder):
    BUILDER_CONFIG_CLASS = OpenExemptConfig
    BUILDER_CONFIGS = [
        OpenExemptConfig(suite=suite) 
        for suite in ["all"] + list(_SUITES.keys())
    ]
    DEFAULT_CONFIG_NAME = "all"

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
            features=datasets.Features(
                {
                    "id": datasets.Value("string"),
                    "prompt": datasets.Value("string"),
                    "solution": datasets.Value("string"),
                    "config": datasets.Value("string"),
                    "case": datasets.Value("string")
                }
            ),
        )

    def _split_generators(self, dl_manager):
        extracted_paths = dl_manager.download_and_extract(self.config.archives)
        dataset_dirs = []
        for extracted_path in extracted_paths:
            suite_dir = next(Path(extracted_path).iterdir())
            for dataset_dir in suite_dir.iterdir():
                if dataset_dir.is_dir():
                    dataset_dirs.append(str(dataset_dir))
        return [
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                gen_kwargs={
                    "dataset_dirs": dataset_dirs,
                    "split": "dev",
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={
                    "dataset_dirs": dataset_dirs,
                    "split": "test",
                },
            ),
        ]

    def _generate_examples(self, dataset_dirs, split):
        for dataset_dir in dataset_dirs:
            dataset_dir = Path(dataset_dir)

            config = read_json(dataset_dir / "config.json")
            shared = read_json(dataset_dir / "shared.json")
            examples = read_jsonl_file(dataset_dir / f"{split}.jsonl")
            case_file_name = 'cases' if split == 'test' else f'{split}_cases'
            cases = read_jsonl_file(dataset_dir / f'{case_file_name}.jsonl')

            if len(examples) != len(cases):
                raise ValueError(f"Number of examples and cases do not match for dataset: {dataset_dir}")
            for example, case in zip(examples, cases):
                uid = example["uid"]
                prompt_inputs = [
                    shared["instruction"], 
                    shared["meta_instruction"], 
                    shared["response_format"], 
                    example["facts"], 
                    example.get("solved_steps"), # Solved steps can be omitted
                    shared["statutes"],
                    shared["format_reminder"]
                ]
                prompt = '\n\n'.join(filter(None, prompt_inputs))
                solution = example["solution"]
                if isinstance(solution, dict):
                    solution = json.dumps(solution, sort_keys=True)
                
                yield uid, {
                    "id": uid,
                    "prompt": prompt,
                    "solution": solution,
                    "config": json.dumps(config, sort_keys=True),
                    "case": json.dumps(case, sort_keys=True)
                }