File size: 8,629 Bytes
6c30bf6 b446608 6c30bf6 cb9efc0 b446608 6c30bf6 cb9efc0 b446608 6c30bf6 cb9efc0 6c30bf6 cb9efc0 6c30bf6 049deae cb9efc0 6c30bf6 b446608 6c30bf6 049deae 6c30bf6 b446608 6c30bf6 b446608 6c30bf6 b446608 cb9efc0 b446608 049deae b446608 6c30bf6 b446608 6c30bf6 b446608 |
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 |
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""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}")
|