|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""BSARD: A Statutory Article Retrieval Dataset in French""" |
|
|
|
import csv |
|
import json |
|
import datasets |
|
|
|
|
|
_CITATION = """\ |
|
@inproceedings{louis-spanakis-2022-statutory, |
|
title = "A Statutory Article Retrieval Dataset in {F}rench", |
|
author = "Louis, Antoine and Spanakis, Gerasimos", |
|
booktitle = "Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)", |
|
month = may, |
|
year = "2022", |
|
address = "Dublin, Ireland", |
|
publisher = "Association for Computational Linguistics", |
|
url = "https://aclanthology.org/2022.acl-long.468", |
|
doi = "10.18653/v1/2022.acl-long.468", |
|
pages = "6789--6803", |
|
} |
|
""" |
|
_DESCRIPTION = """\ |
|
The Belgian Statutory Article Retrieval Dataset (BSARD) is a French native dataset for studying legal information retrieval. |
|
BSARD consists of more than 22,600 statutory articles from Belgian law and about 1,100 legal questions posed by Belgian citizens |
|
and labeled by experienced jurists with relevant articles from the corpus. |
|
""" |
|
_HOMEPAGE = "https://github.com/maastrichtlawtech/bsard" |
|
_LICENSE = "CC BY-NC-SA 4.0" |
|
_URLS = { |
|
"corpus": "https://huggingface.co/datasets/maastrichtlawtech/bsard/resolve/main/articles.csv", |
|
"test-questions": "https://huggingface.co/datasets/maastrichtlawtech/bsard/resolve/main/questions_test.csv", |
|
"train-questions": "https://huggingface.co/datasets/maastrichtlawtech/bsard/resolve/main/questions_train.csv", |
|
"synthetic-questions": "https://huggingface.co/datasets/maastrichtlawtech/bsard/resolve/main/questions_synthetic.csv", |
|
"train-negatives": "https://huggingface.co/datasets/maastrichtlawtech/bsard/resolve/main/negatives/bm25_negatives_train.json", |
|
"synthetic-negatives": "https://huggingface.co/datasets/maastrichtlawtech/bsard/resolve/main/negatives/bm25_negatives_synthetic.json", |
|
} |
|
|
|
|
|
class BSARD(datasets.GeneratorBasedBuilder): |
|
"""BSARD: A Statutory Article Retrieval Dataset in French""" |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig(name="corpus", version=VERSION, description="Knowledge corpus of statutory articles"), |
|
datasets.BuilderConfig(name="questions", version=VERSION, description="Questions labeled with relevant articles"), |
|
datasets.BuilderConfig(name="negatives", version=VERSION, description="Questions labeled with (hard to tell) irrelevant articles"), |
|
] |
|
DEFAULT_CONFIG_NAME = "questions" |
|
|
|
def _info(self): |
|
if self.config.name == "corpus": |
|
features = { |
|
"id": datasets.Value("int32"), |
|
"article": datasets.Value("string"), |
|
"reference": datasets.Value("string"), |
|
"law_type": datasets.Value("string"), |
|
"description": datasets.Value("string"), |
|
"code": datasets.Value("string"), |
|
"book": datasets.Value("string"), |
|
"part": datasets.Value("string"), |
|
"act": datasets.Value("string"), |
|
"chapter": datasets.Value("string"), |
|
"section": datasets.Value("string"), |
|
"subsection": datasets.Value("string"), |
|
} |
|
elif self.config.name == "questions": |
|
features = { |
|
"id": datasets.Value("int32"), |
|
"question": datasets.Value("string"), |
|
"article_ids": datasets.Sequence(datasets.Value("int32")), |
|
"category": datasets.Value("string"), |
|
"subcategory": datasets.Value("string"), |
|
"extra_description": datasets.Value("string"), |
|
} |
|
elif self.config.name == "negatives": |
|
features = { |
|
"question_id": datasets.Value("int32"), |
|
"article_ids": datasets.Sequence(datasets.Value("int32")), |
|
} |
|
else: |
|
raise ValueError(f"Unknown config name {self.config.name}") |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features(features), |
|
supervised_keys=None, |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
if self.config.name == "corpus": |
|
dl_path = dl_manager.download_and_extract(_URLS["corpus"]) |
|
return [datasets.SplitGenerator(name="corpus", gen_kwargs={"filepath": dl_path})] |
|
elif self.config.name == "questions": |
|
splits = ["train-questions", "test-questions", "synthetic-questions"] |
|
dl_paths = dl_manager.download_and_extract({split: _URLS[split] for split in splits}) |
|
return [ |
|
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": dl_paths["train-questions"], "split": "train"}), |
|
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": dl_paths["test-questions"], "split": "test"}), |
|
datasets.SplitGenerator(name="synthetic", gen_kwargs={"filepath": dl_paths["synthetic-questions"], "split": "synthetic"}), |
|
] |
|
elif self.config.name == "negatives": |
|
splits = ["train-negatives", "synthetic-negatives"] |
|
dl_paths = dl_manager.download_and_extract({split: _URLS[split] for split in splits}) |
|
return [ |
|
datasets.SplitGenerator(name="train", gen_kwargs={"filepath": dl_paths["train-negatives"], "split": "train"}), |
|
datasets.SplitGenerator(name="synthetic", gen_kwargs={"filepath": dl_paths["synthetic-negatives"], "split": "synthetic"}), |
|
] |
|
else: |
|
raise ValueError(f"Unknown config name {self.config.name}") |
|
|
|
|
|
def _generate_examples(self, filepath, split=None): |
|
if self.config.name in ["corpus", "questions"]: |
|
with open(filepath, encoding="utf-8") as f: |
|
data = csv.DictReader(f) |
|
for key, row in enumerate(data): |
|
if self.config.name == "corpus": |
|
features = { |
|
"id": int(row["id"]), |
|
"article": row["article"], |
|
"reference": row["reference"], |
|
"law_type": row["law_type"], |
|
"description": row["description"], |
|
"code": row["code"], |
|
"book": row["book"], |
|
"part": row["part"], |
|
"act": row["act"], |
|
"chapter": row["chapter"], |
|
"section": row["section"], |
|
"subsection": row["subsection"], |
|
} |
|
elif self.config.name == "questions": |
|
features = { |
|
"id": int(row["id"]), |
|
"question": row["question"], |
|
"article_ids": [int(num) for num in row["article_ids"].split(",")], |
|
"category": "" if split == "synthetic" else row["category"], |
|
"subcategory": "" if split == "synthetic" else row["subcategory"], |
|
"extra_description": "" if split == "synthetic" else row["extra_description"], |
|
} |
|
else: |
|
raise ValueError(f"Unknown config name {self.config.name}") |
|
yield key, features |
|
elif self.config.name == "negatives": |
|
with open(filepath, encoding="utf-8") as f: |
|
data = json.load(f) |
|
for key, (qid, article_ids) in enumerate(data.items()): |
|
features = { |
|
"question_id": int(qid), |
|
"article_ids": article_ids, |
|
} |
|
yield key, features |
|
else: |
|
raise ValueError(f"Unknown config name {self.config.name}") |
|
|