|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import datasets |
|
import pandas as pd |
|
|
|
|
|
_CITATION = """""" |
|
_DESCRIPTION = """""" |
|
_HOMEPAGE = "" |
|
_LICENSE = "" |
|
_URLS = { |
|
"qa": { |
|
"train": "data/qa/train.csv", |
|
"validation": "data/qa/validation.csv", |
|
"test": "data/qa/test.csv", |
|
"all": "data/qa/qa.csv", |
|
}, |
|
"passages": { |
|
"train": "data/passages/train.tsv", |
|
"validation": "data/passages/validation.tsv", |
|
"test": "data/passages/test.tsv", |
|
"all": "data/passages/passages.tsv" |
|
}, |
|
} |
|
|
|
_CONFIGS = {} |
|
|
|
_CONFIGS["qa"] = { |
|
"description": "Answer bar exam questions", |
|
"features": { |
|
"idx": datasets.Value("string"), |
|
"dataset": datasets.Value("string"), |
|
"example_id": datasets.Value("string"), |
|
"prompt_id": datasets.Value("string"), |
|
"source": datasets.Value("string"), |
|
"subject": datasets.Value("string"), |
|
"question_number": datasets.Value("string"), |
|
"prompt": datasets.Value("string"), |
|
"question": datasets.Value("string"), |
|
"choice_a": datasets.Value("string"), |
|
"choice_b": datasets.Value("string"), |
|
"choice_c": datasets.Value("string"), |
|
"choice_d": datasets.Value("string"), |
|
"answer": datasets.Value("string"), |
|
"gold_passage": datasets.Value("string"), |
|
"gold_idx": datasets.Value("string"), |
|
}, |
|
"license": None, |
|
} |
|
|
|
_CONFIGS["passages"] = { |
|
"description": "Passage corpus of bar exam question explanations, Wex definitions and primary sources, and caselaw", |
|
"features": { |
|
"idx": datasets.Value("string"), |
|
"source": datasets.Value("string"), |
|
"faiss_id": datasets.Value("string"), |
|
"case_id": datasets.Value("string"), |
|
"absolute_paragraph_id": datasets.Value("string"), |
|
"opinion_id": datasets.Value("string"), |
|
"relative_paragraph_id": datasets.Value("string"), |
|
"text": datasets.Value("string"), |
|
}, |
|
"license": None, |
|
} |
|
|
|
|
|
class BarExamQA(datasets.GeneratorBasedBuilder): |
|
"""Legal retrieval/QA dataset for the multistate bar exam""" |
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig( |
|
name=task, version=datasets.Version("1.0.0"), description=task, |
|
) |
|
for task in _CONFIGS |
|
] |
|
|
|
|
|
def _info(self): |
|
features = _CONFIGS[self.config.name]["features"] |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features(features), |
|
homepage=_HOMEPAGE, |
|
citation=_CITATION, |
|
license=_CONFIGS[self.config.name]["license"], |
|
) |
|
|
|
|
|
def _split_generators(self, dl_manager): |
|
downloaded_file_dir = dl_manager.download_and_extract(_URLS[self.config.name]) |
|
splits = [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"fpath": downloaded_file_dir["train"], |
|
"name": self.config.name, |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
gen_kwargs={ |
|
"fpath": downloaded_file_dir["validation"], |
|
"name": self.config.name, |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs={ |
|
"fpath": downloaded_file_dir["test"], |
|
"name": self.config.name, |
|
}, |
|
), |
|
] |
|
return splits |
|
|
|
|
|
def _generate_examples(self, fpath, name): |
|
"""Yields examples as (key, example) tuples.""" |
|
if name in ["qa"]: |
|
data = pd.read_csv(fpath) |
|
data = data.to_dict(orient="records") |
|
for id_line, example in enumerate(data): |
|
yield id_line, example |
|
|
|
if name in ["passages"]: |
|
data = pd.read_csv(fpath, sep='\t') |
|
data = data.to_dict(orient="records") |
|
for id_line, example in enumerate(data): |
|
yield id_line, example |
|
|